diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index d6bd17c5..a282a33f 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -13,6 +13,7 @@ use App\Http\Requests\Acars\PrefileRequest; use App\Http\Requests\Acars\RouteRequest; use App\Http\Requests\Acars\UpdateRequest; use App\Http\Resources\AcarsRoute as AcarsRouteResource; +use App\Http\Resources\JournalTransaction as JournalTransactionResource; use App\Http\Resources\Pirep as PirepResource; use App\Http\Resources\PirepComment as PirepCommentResource; use App\Models\Acars; @@ -23,7 +24,9 @@ use App\Models\Enums\PirepStatus; use App\Models\Pirep; use App\Models\PirepComment; use App\Repositories\AcarsRepository; +use App\Repositories\JournalRepository; use App\Repositories\PirepRepository; +use App\Services\FinanceService; use App\Services\GeoService; use App\Services\PIREPService; use App\Services\UserService; @@ -33,29 +36,37 @@ use Log; class PirepController extends RestController { - protected $acarsRepo, - $geoSvc, - $pirepRepo, - $pirepSvc, - $userSvc; + private $acarsRepo, + $financeSvc, + $geoSvc, + $journalRepo, + $pirepRepo, + $pirepSvc, + $userSvc; /** * PirepController constructor. * @param AcarsRepository $acarsRepo + * @param FinanceService $financeSvc * @param GeoService $geoSvc + * @param JournalRepository $journalRepo * @param PirepRepository $pirepRepo * @param PIREPService $pirepSvc * @param UserService $userSvc */ public function __construct( AcarsRepository $acarsRepo, + FinanceService $financeSvc, GeoService $geoSvc, + JournalRepository $journalRepo, PirepRepository $pirepRepo, PIREPService $pirepSvc, UserService $userSvc ) { $this->acarsRepo = $acarsRepo; + $this->financeSvc = $financeSvc; $this->geoSvc = $geoSvc; + $this->journalRepo = $journalRepo; $this->pirepRepo = $pirepRepo; $this->pirepSvc = $pirepSvc; $this->userSvc = $userSvc; @@ -436,6 +447,37 @@ class PirepController extends RestController return new PirepCommentResource($comment); } + /** + * @param $id + * @param Request $request + * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection + */ + public function finances_get($id, Request $request) + { + $pirep = $this->pirepRepo->find($id); + $transactions = $this->journalRepo->getAllForObject($pirep); + return JournalTransactionResource::collection($transactions); + } + + /** + * @param $id + * @param Request $request + * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection + * @throws \UnexpectedValueException + * @throws \InvalidArgumentException + * @throws \Exception + * @throws \Prettus\Validator\Exceptions\ValidatorException + */ + public function finances_recalculate($id, Request $request) + { + $pirep = $this->pirepRepo->find($id); + $this->financeSvc->processFinancesForPirep($pirep); + + $pirep->refresh(); + $transactions = $this->journalRepo->getAllForObject($pirep); + return JournalTransactionResource::collection($transactions['transactions']); + } + /** * @param $id * @param Request $request diff --git a/app/Http/Resources/JournalTransaction.php b/app/Http/Resources/JournalTransaction.php new file mode 100644 index 00000000..edadba6e --- /dev/null +++ b/app/Http/Resources/JournalTransaction.php @@ -0,0 +1,14 @@ + ['api.auth']], function () Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post'); Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel'); + Route::get('pireps/{pirep_id}/finances', 'PirepController@finances_get'); + Route::post('pireps/{pirep_id}/finances/recalculate', 'PirepController@finances_recalculate'); + Route::get('pireps/{pirep_id}/route', 'PirepController@route_get'); Route::post('pireps/{pirep_id}/route', 'PirepController@route_post'); Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete'); diff --git a/resources/views/admin/pireps/edit.blade.php b/resources/views/admin/pireps/edit.blade.php index 677154c9..5ec937cc 100644 --- a/resources/views/admin/pireps/edit.blade.php +++ b/resources/views/admin/pireps/edit.blade.php @@ -44,6 +44,11 @@