diff --git a/app/Http/Controllers/Api/CMMSController.php b/app/Http/Controllers/Api/CMMSController.php index 0d4ce917..0bfa6577 100644 --- a/app/Http/Controllers/Api/CMMSController.php +++ b/app/Http/Controllers/Api/CMMSController.php @@ -7,6 +7,7 @@ use App\Models\CMMS_Form; use App\Models\CMMS_Forms_histories; use App\Models\CMMS_Province; use App\Models\CmmsDemo; +use App\Services\FMSService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -18,7 +19,7 @@ use Illuminate\Support\Facades\Http; class CMMSController extends Controller { - public function getVehicleActivity(Request $request) + public function getVehicleActivity(Request $request, FMSService $FMSService) { if (!$request->machineCode || !$request->startDT || !$request->endDT || !$request->minStopDuration) { @@ -26,22 +27,8 @@ class CMMSController extends Controller 'message' => 'error' ]); } - - $r = $request->machineCode; - $s = $request->startDT; - $e = $request->endDT; - $d = $request->minStopDuration; - $url = 'http://fms.141.ir/api/RMS/GetVehicleActivity?'; - $query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}"; - $full_url = $url . $query; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $full_url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, - "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $server_output = curl_exec($ch); + $server_output = $FMSService->getVehicleActivity($request); $d = json_decode($server_output, true); @@ -58,7 +45,7 @@ class CMMSController extends Controller } - public function getVehicleLastPoints(Request $request) + public function getVehicleLastPoints(Request $request, FMSService $FMSService) { if (!$request->machineCode) { @@ -66,19 +53,8 @@ class CMMSController extends Controller 'message' => 'error' ]); } - - $r = $request->machineCode; - $url = 'http://fms.141.ir/api/RMS/GetVehicleLastPoints?'; - $query = "username=RMS&password=XSW@1qaz&machineCodes={$r}"; - $full_url = $url . $query; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $full_url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, - "username=RMS&password=XSW@1qaz&machineCode={$r}"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $server_output = curl_exec($ch); + $server_output = $FMSService->getVehicleLastPoints($request); $d = json_decode($server_output, true); return $d; @@ -95,7 +71,7 @@ class CMMSController extends Controller } - public function getVehicleActivitySummary(Request $request) + public function getVehicleActivitySummary(Request $request, FMSService $FMSService) { if (!$request->machineCode || !$request->startDT || !$request->endDT) { @@ -103,21 +79,8 @@ class CMMSController extends Controller 'message' => 'error' ]); } - - $r = $request->machineCode; - $s = $request->startDT; - $e = $request->endDT; - $url = 'http://fms.141.ir/api/RMS/GetVehicleActivitySummary?'; - $query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}"; - $full_url = $url . $query; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $full_url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, - "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $server_output = curl_exec($ch); + $server_output = $FMSService->getVehicleActivitySummary($request); $d = json_decode($server_output, true); @@ -135,17 +98,9 @@ class CMMSController extends Controller } - public function getVehicleData(Request $request) - { - $r = $request->machine; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL,"http://fms.141.ir/api/RMS/GetVehicleLastPoints?username=RMS&password=XSW@1qaz&machineCodes={$r}"); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, - "username=RMS&password=XSW@1qaz&machineCodes={$r}"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $server_output = curl_exec($ch); + public function getVehicleData(Request $request, FMSService $FMSService) + { + $server_output = $FMSService->getVehicleData($request); $d = json_decode($server_output); diff --git a/app/Http/Controllers/CoridorsController.php b/app/Http/Controllers/CoridorsController.php index 28afdaad..7de405a9 100644 --- a/app/Http/Controllers/CoridorsController.php +++ b/app/Http/Controllers/CoridorsController.php @@ -3,10 +3,12 @@ namespace App\Http\Controllers; use App\Models\Coridor; +use App\Models\RoadPatrol; use App\Models\RoutePath; use App\Models\RoadItemsProject; use App\Models\InfoItem; +use App\Services\NominatimService; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; @@ -484,7 +486,7 @@ class CoridorsController extends Controller return 0; } - public function axisReportByLatAndLng(Request $request) + public function axisReportByLatAndLng(Request $request, NominatimService $nominatimService) { if (! $request->type) { return response()->json([ @@ -496,7 +498,7 @@ class CoridorsController extends Controller $date_from = $request->date_from; $info_id = $request->daily_activity; $roadObservedTypes = $request->road_type; - $idArrays = self::getIDFromNominatim($request->slng, $request->slat, $request->dlng, $request->dlat); + $idArrays = $nominatimService->getIDFromNominatim($request->slng, $request->slat, $request->dlng, $request->dlat); $typeArrays = $request->type; $contractStatusArrays = $request->contract_status ?? []; $projectTypeArrays = $request->project_type ?? []; @@ -514,13 +516,13 @@ class CoridorsController extends Controller } if ( in_array(2, $typeArrays) ) { - $roadPatrolProject = RoadPatrolProject::where(function($query) use($idArrays){ + $roadPatrolProject = RoadPatrol::where(function($query) use($idArrays){ $query->whereIn("start_way_id", $idArrays) ->orWhereIn("end_way_id", $idArrays); }) ->whereBetween('created_at', [$date_from . ' 00:00:00', $date_to . ' 23:59:59']) ->whereNotNull('start_lat') - ->select('start_lat', 'start_lng', 'id') + ->select('start_lat', 'start_lon', 'id') ->get(); } @@ -686,7 +688,7 @@ class CoridorsController extends Controller } - public function axisReportExcelRedirector(Request $request) + public function axisReportExcelRedirector(Request $request, NominatimService $nominatimService) { if (! $request->type) { return response()->json([ @@ -698,7 +700,7 @@ class CoridorsController extends Controller $date_from = $request->date_from; $info_id = $request->daily_activity; $roadObservedTypes = $request->road_type; - $idArrays = self::getIDFromNominatim($request->slng, $request->slat, $request->dlng, $request->dlat); + $idArrays = $nominatimService->getIDFromNominatim($request->slng, $request->slat, $request->dlng, $request->dlat); $typeArrays = $request->type; $contractStatusArrays = $request->contract_status ?? []; $projectTypeArrays = $request->project_type ?? []; diff --git a/app/Models/Accident.php b/app/Models/Accident.php index fa769bf2..8221365b 100644 --- a/app/Models/Accident.php +++ b/app/Models/Accident.php @@ -2,12 +2,13 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Traits\ReceiptReportAble; class Accident extends Model { - use ReceiptReportAble; + use ReceiptReportAble, HasFactory; public static function boot() { parent::boot(); diff --git a/app/Models/ContractSubItems.php b/app/Models/ContractSubItems.php index 74170e0a..540280e5 100644 --- a/app/Models/ContractSubItems.php +++ b/app/Models/ContractSubItems.php @@ -2,13 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Models\ContractSubItemsHistory; use App\Http\Controllers\Api\ContractSubItemsController; class ContractSubItems extends Model { - + use HasFactory; public static function boot() { parent::boot(); diff --git a/app/Models/Contracts.php b/app/Models/Contracts.php index 485ade7a..364c2711 100644 --- a/app/Models/Contracts.php +++ b/app/Models/Contracts.php @@ -2,13 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Models\Province; use Illuminate\Http\Request; class Contracts extends Model { - + use HasFactory; public static function boot() { parent::boot(); diff --git a/app/Services/FMSService.php b/app/Services/FMSService.php new file mode 100644 index 00000000..d8b6f73d --- /dev/null +++ b/app/Services/FMSService.php @@ -0,0 +1,98 @@ +machineCode; + $s = $request->startDT; + $e = $request->endDT; + $d = $request->minStopDuration; + $url = 'http://fms.141.ir/api/RMS/GetVehicleActivity?'; + $query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}"; + $full_url = $url . $query; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $full_url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, + "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + return curl_exec($ch); + } + + return json_encode([ + 'ResultCode' => 0 + ]); + } + + public function getVehicleData(Request $request) + { + if (App::isProduction()) { + $r = $request->machine; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "http://fms.141.ir/api/RMS/GetVehicleLastPoints?username=RMS&password=XSW@1qaz&machineCodes={$r}"); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, + "username=RMS&password=XSW@1qaz&machineCodes={$r}"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + return curl_exec($ch); + } + + $output = (object)['ResultCode' => 0]; + + return json_encode([ + [$output] + ]); + } + + public function getVehicleLastPoints(Request $request) + { + if (App::isProduction()) { + $r = $request->machineCode; + $url = 'http://fms.141.ir/api/RMS/GetVehicleLastPoints?'; + $query = "username=RMS&password=XSW@1qaz&machineCodes={$r}"; + $full_url = $url . $query; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $full_url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, + "username=RMS&password=XSW@1qaz&machineCode={$r}"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + return curl_exec($ch); + } + + return json_encode([ + 'ResultCode' => 0 + ]); + } + + public function getVehicleActivitySummary(Request $request) + { + if (App::isProduction()) { + $r = $request->machineCode; + $s = $request->startDT; + $e = $request->endDT; + $url = 'http://fms.141.ir/api/RMS/GetVehicleActivitySummary?'; + $query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}"; + $full_url = $url . $query; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $full_url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, + "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + return curl_exec($ch); + } + + return json_encode([ + 'ResultCode' => 0 + ]); + } +} \ No newline at end of file diff --git a/app/Services/NominatimService.php b/app/Services/NominatimService.php index a14ebe9a..58815f48 100644 --- a/app/Services/NominatimService.php +++ b/app/Services/NominatimService.php @@ -30,4 +30,36 @@ class NominatimService return 0; } + + function getIDFromNominatim($s_lng, $s_lat, $d_lng, $d_lat) + { + if (App::isProduction()) + { + $url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true"; + $arrContextOptions = array( + "ssl" => array( + "verify_peer" => false, + "verify_peer_name" => false, + ), + ); + $result = file_get_contents($url, false, stream_context_create($arrContextOptions)); + $result = json_decode($result); + if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) { + // if(){ + $ways = $result->routes[1]->legs[0]->steps; + // } + } else + $ways = $result->routes[0]->legs[0]->steps; + $ids = array(); + foreach ($ways as $key => $value) { + if (!in_array($value->name, $ids)) { + $ids[] = $value->name; + } + } + + return $ids; + } + + return [1, 2, 3]; + } } diff --git a/bootstrap/cache/services.php b/bootstrap/cache/services.php index 5b656a52..1ae78e1a 100755 --- a/bootstrap/cache/services.php +++ b/bootstrap/cache/services.php @@ -44,7 +44,6 @@ 40 => 'App\\Providers\\RouteServiceProvider', 41 => 'App\\Providers\\TelescopeServiceProvider', 42 => 'Barryvdh\\Debugbar\\ServiceProvider', - 43 => 'App\\Providers\\NikarayanServiceProvider', ), 'eager' => array ( @@ -77,7 +76,6 @@ 26 => 'App\\Providers\\RouteServiceProvider', 27 => 'App\\Providers\\TelescopeServiceProvider', 28 => 'Barryvdh\\Debugbar\\ServiceProvider', - 29 => 'App\\Providers\\NikarayanServiceProvider', ), 'deferred' => array ( diff --git a/database/factories/AccidentFactory.php b/database/factories/AccidentFactory.php new file mode 100644 index 00000000..73cb66c3 --- /dev/null +++ b/database/factories/AccidentFactory.php @@ -0,0 +1,23 @@ + + */ +class AccidentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'police_serial' => $this->faker->name + ]; + } +} diff --git a/database/factories/ContractSubItemsFactory.php b/database/factories/ContractSubItemsFactory.php new file mode 100644 index 00000000..03cd41a8 --- /dev/null +++ b/database/factories/ContractSubItemsFactory.php @@ -0,0 +1,27 @@ + + */ +class ContractSubItemsFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'project_title' => $this->faker->name, + 'province_id' => Province::factory(), + 'contract_id' => Contracts::factory(), + ]; + } +} diff --git a/database/factories/ContractsFactory.php b/database/factories/ContractsFactory.php new file mode 100644 index 00000000..603518df --- /dev/null +++ b/database/factories/ContractsFactory.php @@ -0,0 +1,25 @@ + + */ +class ContractsFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'title' => $this->faker->name, + 'province_id' => Province::factory(), + ]; + } +} diff --git a/routes/api.php b/routes/api.php index 0e11d877..38b2ce1d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,8 @@ get('bi/total-length-damaged-axes', 'Api\BiContro -Route::get('axis-report', 'CoridorsController@axisReportByLatAndLng'); +Route::get('axis-report', 'CoridorsController@axisReportByLatAndLng')->name('api.axis-report'); // Route::get('axis-report/single', 'CoridorsController@getAxisReportDataFromID'); // Route::post('change', function () { // $data = App\Models\UserActivityLog::create([ diff --git a/tests/Feature/Coridors/AxisReportByLatAndLngTest.php b/tests/Feature/Coridors/AxisReportByLatAndLngTest.php new file mode 100644 index 00000000..add85dec --- /dev/null +++ b/tests/Feature/Coridors/AxisReportByLatAndLngTest.php @@ -0,0 +1,248 @@ +getJson(route('api.axis-report')); + + $response->assertStatus(400) + ->assertExactJson([ + 'status' => 'error', + 'message' => ' لطفا یک گزینه از فیلتر ها را انتخاب نمایید.' + ]); + } + + public function test_filtering_road_item_works_properly(): void + { + RoadItemsProject::factory() + ->sequence( + ["id" => 1, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 1, 'start_way_id' => 1, 'end_way_id' => 2], + ["id" => 2, 'created_at' => '2025-05-03 12:25:00', 'info_id' => 2, 'start_way_id' => 5, 'end_way_id' => 3], + ["id" => 3, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 5, 'start_way_id' => 9, 'end_way_id' => 4], + ["id" => 4, 'created_at' => '2026-05-03 12:25:00', 'info_id' => 6, 'start_way_id' => 2, 'end_way_id' => 1], + ["id" => 5, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 1, 'start_way_id' => 6, 'end_way_id' => 6], + ["id" => 6, 'created_at' => '2026-08-03 12:25:00', 'info_id' => 9, 'start_way_id' => 16, 'end_way_id' => 7], + ["id" => 7, 'created_at' => '2022-05-03 12:25:00', 'info_id' => 2, 'start_way_id' => 35, 'end_way_id' => 9], + ) + ->count(7) + ->create(); + + $this->mock(NominatimService::class, function (MockInterface $mock) { + $mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]); + }); + + $response = $this->getJson(route('api.axis-report', [ + 'date_to' => '2023-07-26', + 'date_from' => '2021-07-26', + 'daily_activity' => [1, 2], + 'road_type' => 'test', + 'slng' => '12', + 'slat' => '12', + 'dlng' => '13', + 'dlat' => '13', + 'type' => [1], +// 'contract_status' => '', +// 'project_type' => '', + ])); + + $response->assertStatus(200) + ->assertExactJson([ + 'status' => 'success', + 'data' => [ + "roadObserved" => null, + "roadPatrolProject" => null, + "contractSubItems" => null, + 'roadItemsProject' => [ + [ + "start_lat" => "0.0000000000", + "start_lng" => "0.0000000000", + "id" => 1 + ] + ] + ] + ]); + } + + public function test_filtering_road_patrol_works_properly(): void + { + RoadPatrol::factory() + ->sequence( + ["id" => 1, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 1, 'start_way_id' => 1, 'end_way_id' => 2], + ["id" => 2, 'created_at' => '2025-05-03 12:25:00', 'start_lat' => 2, 'start_way_id' => 5, 'end_way_id' => 3], + ["id" => 3, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 5, 'start_way_id' => 9, 'end_way_id' => 4], + ["id" => 4, 'created_at' => '2026-05-03 12:25:00', 'start_lat' => 6, 'start_way_id' => 2, 'end_way_id' => 1], + ["id" => 5, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 1, 'start_way_id' => 6, 'end_way_id' => 6], + ["id" => 6, 'created_at' => '2026-08-03 12:25:00', 'start_lat' => 9, 'start_way_id' => 16, 'end_way_id' => 7], + ["id" => 7, 'created_at' => '2022-05-03 12:25:00', 'start_lat' => 2, 'start_way_id' => 35, 'end_way_id' => 9], + ) + ->count(7) + ->create(); + + $this->mock(NominatimService::class, function (MockInterface $mock) { + $mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]); + }); + + $response = $this->getJson(route('api.axis-report', [ + 'date_to' => '2023-07-26', + 'date_from' => '2021-07-26', +// 'daily_activity' => [1, 2], + 'road_type' => 'test', + 'slng' => '12', + 'slat' => '12', + 'dlng' => '13', + 'dlat' => '13', + 'type' => [2], +// 'contract_status' => '', +// 'project_type' => '', + ])); + + $response->assertStatus(200) + ->assertExactJson([ + 'status' => 'success', + 'data' => [ + "roadObserved" => null, + "roadItemsProject" => null, + "contractSubItems" => null, + 'roadPatrolProject' => [ + [ + "start_lat" => 1, + "start_lon" => 0, + "id" => 1 + ] + ] + ] + ]); + } + + public function test_filtering_road_observed_works_properly(): void + { + RoadObserved::factory() + ->sequence( + ["id" => 1, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 1, 'observed_way_id' => 1, 'fk_FeatureType' => 'test', 'rms_status' => 1], + ["id" => 2, 'created_at' => '2025-05-03 12:25:00', 'handling_way_id' => 2, 'observed_way_id' => 5, 'fk_FeatureType' => 'fake'], + ["id" => 3, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 5, 'observed_way_id' => 9, 'fk_FeatureType' => 'fake'], + ["id" => 4, 'created_at' => '2026-05-03 12:25:00', 'handling_way_id' => 6, 'observed_way_id' => 2, 'fk_FeatureType' => 'fake'], + ["id" => 5, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 1, 'observed_way_id' => 6, 'fk_FeatureType' => 'fake'], + ["id" => 6, 'created_at' => '2026-08-03 12:25:00', 'handling_way_id' => 9, 'observed_way_id' => 16, 'fk_FeatureType' => 'fake'], + ["id" => 7, 'created_at' => '2022-05-03 12:25:00', 'handling_way_id' => 2, 'observed_way_id' => 35, 'fk_FeatureType' => 'fake'], + ) + ->count(7) + ->create(); + + $this->mock(NominatimService::class, function (MockInterface $mock) { + $mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]); + }); + + $response = $this->getJson(route('api.axis-report', [ + 'date_to' => '2023-07-26', + 'date_from' => '2021-07-26', +// 'daily_activity' => [1, 2], + 'road_type' => ['test'], + 'slng' => '12', + 'slat' => '12', + 'dlng' => '13', + 'dlat' => '13', + 'type' => [4], +// 'contract_status' => '', +// 'project_type' => '', + ])); + + $response->assertStatus(200) + ->assertExactJson([ + 'status' => 'success', + 'data' => [ + "roadItemsProject" => null, + "roadPatrolProject" => null, + "contractSubItems" => null, + 'roadObserved' => [ + [ + "start_lat" => null, + "start_lng" => null, + "id" => 1 + ] + ] + ] + ]); + } + + public function test_filtering_contract_sub_items_works_properly(): void + { + $user = User::factory()->create(); + + LogList::factory()->create(['log_unique_code' => 1005]); + LogList::factory()->create(['log_unique_code' => 1006]); + LogList::factory()->create(['log_unique_code' => 1001]); + + $this->actingAs($user); + + ContractSubItems::factory() + ->sequence( + ["id" => 1, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 1, 'end_way_id' => 2], + ["id" => 2, 'contract_date_from_parent_contract' => '2025-05-03 12:25:00', 'start_way_id' => 5, 'end_way_id' => 3], + ["id" => 3, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 9, 'end_way_id' => 4], + ["id" => 4, 'contract_date_from_parent_contract' => '2026-05-03 12:25:00', 'start_way_id' => 2, 'end_way_id' => 1], + ["id" => 5, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 6, 'end_way_id' => 6], + ["id" => 6, 'contract_date_from_parent_contract' => '2026-08-03 12:25:00', 'start_way_id' => 16, 'end_way_id' => 7], + ["id" => 7, 'contract_date_from_parent_contract' => '2022-05-03 12:25:00', 'start_way_id' => 35, 'end_way_id' => 9], + ) + ->count(7) + ->create(); + + $this->mock(NominatimService::class, function (MockInterface $mock) { + $mock->shouldReceive('getIDFromNominatim')->andReturn([1, 2, 3]); + }); + + $response = $this->getJson(route('api.axis-report', [ + 'date_to' => '2023-07-26', + 'date_from' => '2021-07-26', +// 'daily_activity' => [1, 2], + 'road_type' => ['test'], + 'slng' => '12', + 'slat' => '12', + 'dlng' => '13', + 'dlat' => '13', + 'type' => [3], +// 'contract_status' => '', +// 'project_type' => '', + ])); + + $response->assertStatus(200) + ->assertExactJson([ + 'status' => 'success', + 'data' => [ + "roadItemsProject" => null, + "roadPatrolProject" => null, + "roadObserved" => null, + 'contractSubItems' => [ + [ + "start_lat" => null, + "start_lng" => null, + "id" => 1 + ] + ] + ] + ]); + } +} diff --git a/tests/Feature/Receipt/CallPaymentStatusTest.php b/tests/Feature/Receipt/CallPaymentStatusTest.php new file mode 100644 index 00000000..18eaeac1 --- /dev/null +++ b/tests/Feature/Receipt/CallPaymentStatusTest.php @@ -0,0 +1,135 @@ +create(); + + LogList::factory()->create(['log_unique_code' => 1130]); + + $accident = Accident::factory()->create([ + 'final_amount' => $this->faker->numerify('##') + ]); + + $this->mock(PaymentService::class, function (MockInterface $mock) { + $mock->shouldReceive('callPaymentStatusBillApi')->andReturn(json_encode(['isPayed' => 1])); + }); + + $response = $this->actingAs($user)->postJson("/v2/receipt/call-payment-status/{$accident->id}"); + + $response->assertStatus(200) + ->assertExactJson([ + "accident_date" => $accident->accident_date, + "accident_time" => $accident->accident_time, + "accident_type" => $accident->accident_type, + "accident_type_fa" => $accident->accident_type_fa, + "axis_name" => $accident->axis_name, + "bill_code" => $accident->bill_code, + "city_fa" => $accident->city_fa, + "city_id" => $accident->city_id, + "created_at" => $accident->created_at, + "damage_picture1" => $accident->damage_picture1, + "damage_picture2" => $accident->damage_picture2, + "deposit_daghi_amount" => 0, + "deposit_daghi_image" => $accident->deposit_daghi_image, + "deposit_date" => $accident->deposit_date, + "deposit_insurance_amount" => 0, + "deposit_insurance_image" => $accident->deposit_insurance_image, + "driver_name" => $accident->driver_name, + "driver_national_code" => $accident->driver_national_code, + "driver_phone_number" => $accident->driver_phone_number, + "final_amount" => $accident->final_amount, + "id" => $accident->id, + "lat" => $accident->lat, + "lng" => $accident->lng, + "ojrate_nasb" => $accident->ojrate_nasb, + "plaque" => $accident->plaque, + "police_file" => $accident->police_file, + "police_file_date" => $accident->police_file_date, + "police_serial" => $accident->police_serial, + "province_fa" => $accident->province_fa, + "province_id" => $accident->province_id, + "report_base" => $accident->report_base, + "status" => 0, + "status_fa" => $accident->status_fa, + "status_history" => '0', + "sum" => $accident->sum, + "support_description" => $accident->support_description, + "updated_at" => $accident->updated_at, + "user_id" => $accident->user_id, + "way_id" => $accident->way_id + ]); + } + + public function test_payment_status_works_properly(): void + { + $user = User::factory()->create(); + + LogList::factory()->create(['log_unique_code' => 1130]); + + $accident = Accident::factory()->create([ + 'final_amount' => $this->faker->numerify('0') + ]); + + $response = $this->actingAs($user)->postJson("/v2/receipt/call-payment-status/{$accident->id}"); + + $response->assertStatus(200) + ->assertExactJson([ + "accident_date" => $accident->accident_date, + "accident_time" => $accident->accident_time, + "accident_type" => $accident->accident_type, + "accident_type_fa" => $accident->accident_type_fa, + "axis_name" => $accident->axis_name, + "bill_code" => $accident->bill_code, + "city_fa" => $accident->city_fa, + "city_id" => $accident->city_id, + "created_at" => $accident->created_at, + "damage_picture1" => $accident->damage_picture1, + "damage_picture2" => $accident->damage_picture2, + "deposit_daghi_amount" => 0, + "deposit_daghi_image" => $accident->deposit_daghi_image, + "deposit_date" => $accident->deposit_date, + "deposit_insurance_amount" => 0, + "deposit_insurance_image" => $accident->deposit_insurance_image, + "driver_name" => $accident->driver_name, + "driver_national_code" => $accident->driver_national_code, + "driver_phone_number" => $accident->driver_phone_number, + "final_amount" => $accident->final_amount, + "id" => $accident->id, + "lat" => $accident->lat, + "lng" => $accident->lng, + "ojrate_nasb" => $accident->ojrate_nasb, + "plaque" => $accident->plaque, + "police_file" => $accident->police_file, + "police_file_date" => $accident->police_file_date, + "police_serial" => $accident->police_serial, + "province_fa" => $accident->province_fa, + "province_id" => $accident->province_id, + "report_base" => $accident->report_base, + "status" => 0, + "status_fa" => $accident->status_fa, + "status_history" => '0', + "sum" => $accident->sum, + "support_description" => $accident->support_description, + "updated_at" => $accident->updated_at, + "user_id" => $accident->user_id, + "way_id" => $accident->way_id + ]); + } +} diff --git a/tests/Feature/Receipt/InvoiceBillTest.php b/tests/Feature/Receipt/InvoiceBillTest.php new file mode 100644 index 00000000..db234d8b --- /dev/null +++ b/tests/Feature/Receipt/InvoiceBillTest.php @@ -0,0 +1,86 @@ +create(); + + LogList::factory()->create(['log_unique_code' => 1129]); + + $accident = Accident::factory()->create([ + 'sum' => $this->faker->numberBetween(21, 100), + 'deposit_insurance_amount' => $this->faker->numberBetween(1, 10), + 'deposit_daghi_amount' => $this->faker->numberBetween(1, 10), + ]); + + $final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount); + + $this->mock(PaymentService::class, function (MockInterface $mock) { + $mock->shouldReceive('invoiceBillApi')->andReturn(0); + }); + + Sms::shouldReceive('sendSms'); + + $response = $this->actingAs($user)->postJson("/v2/receipt/invoice-bill/{$accident->id}"); + + $response->assertStatus(200) + ->assertExactJson([ + "accident_date" => $accident->accident_date, + "accident_time" => $accident->accident_time, + "accident_type" => $accident->accident_type, + "accident_type_fa" => $accident->accident_type_fa, + "axis_name" => $accident->axis_name, + "bill_code" => 0, + "city_fa" => $accident->city_fa, + "city_id" => $accident->city_id, + "created_at" => $accident->created_at, + "damage_picture1" => $accident->damage_picture1, + "damage_picture2" => $accident->damage_picture2, + "deposit_daghi_amount" => $accident->deposit_daghi_amount, + "deposit_daghi_image" => $accident->deposit_daghi_image, + "deposit_date" => $accident->deposit_date, + "deposit_insurance_amount" => $accident->deposit_insurance_amount, + "deposit_insurance_image" => $accident->deposit_insurance_image, + "driver_name" => $accident->driver_name, + "driver_national_code" => $accident->driver_national_code, + "driver_phone_number" => $accident->driver_phone_number, + "final_amount" => $final_amount, + "id" => $accident->id, + "lat" => $accident->lat, + "lng" => $accident->lng, + "ojrate_nasb" => $accident->ojrate_nasb, + "plaque" => $accident->plaque, + "police_file" => $accident->police_file, + "police_file_date" => $accident->police_file_date, + "police_serial" => $accident->police_serial, + "province_fa" => $accident->province_fa, + "province_id" => $accident->province_id, + "report_base" => $accident->report_base, + "status" => 0, + "status_fa" => $accident->status_fa, + "status_history" => '0', + "sum" => $accident->sum, + "support_description" => $accident->support_description, + "updated_at" => $accident->updated_at, + "user_id" => $accident->user_id, + "way_id" => $accident->way_id + ]); + } +}