From 97640800fbce8e7a35ea0af3e434dcb2fb782eec Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 9 Feb 2022 12:29:25 +0100 Subject: [PATCH] Improve GET /insurances --- .../AuthorizationCareRequestController.php | 4 +-- .../Controllers/HealthCareSheetController.php | 10 ++---- app/Http/Controllers/InsuranceController.php | 33 +++++++------------ .../InsuranceSubscriptionController.php | 6 ++-- 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/AuthorizationCareRequestController.php b/app/Http/Controllers/AuthorizationCareRequestController.php index 3273e0b..dcb4326 100755 --- a/app/Http/Controllers/AuthorizationCareRequestController.php +++ b/app/Http/Controllers/AuthorizationCareRequestController.php @@ -138,15 +138,15 @@ class AuthorizationCareRequestController extends Controller $datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country); DB::beginTransaction(); - NhAuthorizationOfCareRequest::create([ + $authRequest = NhAuthorizationOfCareRequest::create([ 'request_id' => $this->generateRequestID(), 'insurance_id' => $insurance->id, 'beneficiary_id' => $beneficiary_id, 'to' => isset($beneficiary) ? 'HAVING_RIGHT' : 'INSURED', 'act_id' => $act_id, 'state' => InsuranceSubscriptionState::UNDER_VALIDATION, - 'created_at' => $datetime, 'updated_at' => $datetime ]); + $authRequest->created_at = $authRequest->updated_at = $datetime; DB::commit(); $recipients = array_map(function ($email) { diff --git a/app/Http/Controllers/HealthCareSheetController.php b/app/Http/Controllers/HealthCareSheetController.php index 851da69..fa9b2a9 100755 --- a/app/Http/Controllers/HealthCareSheetController.php +++ b/app/Http/Controllers/HealthCareSheetController.php @@ -443,12 +443,6 @@ class HealthCareSheetController extends Controller * type="integer", * example= 4 * ), - * @OA\Property( - * property="patient_lastname", - * description = "Nom du patient", - * type="string", - * example= "Tom" - * ), * @OA\Property( * property="patient_firstname", * description = "Prenom du patient", @@ -674,9 +668,11 @@ class HealthCareSheetController extends Controller 'accident_date' => (!empty($accident_date)) ? $accident_date : null, 'pregnancy_start_at' => (!empty($pregnancy_start_at)) ? $pregnancy_start_at : null, 'pregnancy_end_at' => (!empty($pregnancy_end_at)) ? $pregnancy_end_at : null, - 'created_at' => $datetime, 'updated_at' => $datetime ]); + $healthCareSheet->created_at = $healthCareSheet->udpated_at = $datetime; + $healthCareSheet->save(); + foreach ($request->input('performances', []) as $p) { $fees = !empty($p['home_visit_fees']) ? $p['home_visit_fees'] : 0; $performance = NhPerformance::create([ diff --git a/app/Http/Controllers/InsuranceController.php b/app/Http/Controllers/InsuranceController.php index 5ad9f51..bd9d807 100644 --- a/app/Http/Controllers/InsuranceController.php +++ b/app/Http/Controllers/InsuranceController.php @@ -138,18 +138,7 @@ class InsuranceController extends Controller * required=false, * @OA\Schema( * type="string", - * enum={"ALL","EDITABLE"} - * ) - * ), - * @OA\Parameter( - * parameter="state", - * name="state", - * description="Etat d'assurance", - * in="query", - * required=false, - * @OA\Schema( - * type="string", - * enum={"STOPPED","PAID"} + * enum={"ALL","EDITABLE","STOPPED"} * ) * ), * @OA\Response( @@ -177,13 +166,11 @@ class InsuranceController extends Controller { $this->validate($request, [ 'user_id' => 'required|integer|exists:users,id', - 'type' => 'nullable|in:ALL,EDITABLE', - 'state' => 'nullable|in:PAID,STOPPED' + 'type' => 'nullable|in:ALL,EDITABLE|STOPPED', ]); $userId = $request->input('user_id'); $type = $request->input('type'); - $state = $request->input('state'); $query = NhInsurance::with(['network:id,name', 'beneficiaries'])->where('user_id', $userId); @@ -191,8 +178,13 @@ class InsuranceController extends Controller $query = $query->where('state', $state); } - if ($request->has('type') && $type == 'EDITABLE') { - $query = $query->whereIn('state', [InsuranceState::PAID]); + if (!empty($type)) { + if ($type == 'EDITABLE') { + $query = $query->whereIn('state', [InsuranceState::PAID]); + } + if ($type == 'STOPPED') { + $query = $query->where('state', InsuranceState::STOPPED); + } } $insurances = $query->orderBy('created_at', 'DESC')->get(); @@ -329,7 +321,7 @@ class InsuranceController extends Controller // Ajouter les nouveaux ayant droit $beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($newSubscription, $request, $networkConfig, $monthPrice, $datetime); - $newSubscription->total_bonus_amount = ($newSubscription->bonus_amount + $beneficiariesBonus); + $newSubscription->total_bonus_amount = $beneficiariesBonus; // Le total contient uniquement le montant la prime des ayants droits en cas $newSubscription->created_at = $newSubscription->updated_at = $datetime; $newSubscription->save(); @@ -528,10 +520,9 @@ class InsuranceController extends Controller 'total_bonus_amount' => $insurance->total_bonus_amount, 'insurance_action' => InsuranceAction::STOP_INSURANCE, 'state' => InsuranceSubscriptionState::UNDER_VALIDATION, - 'created_at' => $datetime, 'updated_at' => $datetime ]); - - + $newSubscription->created_at = $newSubscription->updated_at = $datetime; + $newSubscription->save(); Event::dispatch(new InsuranceEvent($newSubscription, trans('messages.insurance_stop'), trans('messages.insurance_stop_mail', ['name' => $newSubscription->user->lastname, 'subscription_id' => $newSubscription->insurance_subscription_id, 'bonus_amount' => $this->toMoneyWithNetwork($newSubscription->total_bonus_amount, $newSubscription->network_id), 'number_of_beneficiaries' => $newSubscription->number_of_beneficiaries, 'gender' => trans('states.' . $identification->gender), 'insurance_name' => $insurance->network->name]))); diff --git a/app/Http/Controllers/InsuranceSubscriptionController.php b/app/Http/Controllers/InsuranceSubscriptionController.php index 3ad608b..e55a5e0 100644 --- a/app/Http/Controllers/InsuranceSubscriptionController.php +++ b/app/Http/Controllers/InsuranceSubscriptionController.php @@ -632,14 +632,14 @@ class InsuranceSubscriptionController extends Controller } - NhInsurancesPayment::create([ + $payment = NhInsurancesPayment::create([ 'insurance_subscription_id' => $subscription->insurance_subscription_id, 'insured_id' => $insurance->insured_id, 'amount' => $amountToPaid, 'reason' => $subscription->insurance_action, - 'created_at' => $datetime, 'updated_at' => $datetime, ]); - + $payment->created_at = $payment->updated_at = $datetime; + $payment->save(); Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_paid'), trans('messages.insurance_subscription_paid_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id, 'bonus_amount' => $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency), 'total_bonus_amount' => $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency), 'insured_id' => $insurance->insured_id, 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,