Improve GET /insurances

This commit is contained in:
Djery-Tom 2022-02-09 12:29:25 +01:00
parent a75b0d434d
commit 97640800fb
4 changed files with 20 additions and 33 deletions

View File

@ -138,15 +138,15 @@ class AuthorizationCareRequestController extends Controller
$datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country); $datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country);
DB::beginTransaction(); DB::beginTransaction();
NhAuthorizationOfCareRequest::create([ $authRequest = NhAuthorizationOfCareRequest::create([
'request_id' => $this->generateRequestID(), 'request_id' => $this->generateRequestID(),
'insurance_id' => $insurance->id, 'insurance_id' => $insurance->id,
'beneficiary_id' => $beneficiary_id, 'beneficiary_id' => $beneficiary_id,
'to' => isset($beneficiary) ? 'HAVING_RIGHT' : 'INSURED', 'to' => isset($beneficiary) ? 'HAVING_RIGHT' : 'INSURED',
'act_id' => $act_id, 'act_id' => $act_id,
'state' => InsuranceSubscriptionState::UNDER_VALIDATION, 'state' => InsuranceSubscriptionState::UNDER_VALIDATION,
'created_at' => $datetime, 'updated_at' => $datetime
]); ]);
$authRequest->created_at = $authRequest->updated_at = $datetime;
DB::commit(); DB::commit();
$recipients = array_map(function ($email) { $recipients = array_map(function ($email) {

View File

@ -443,12 +443,6 @@ class HealthCareSheetController extends Controller
* type="integer", * type="integer",
* example= 4 * example= 4
* ), * ),
* @OA\Property(
* property="patient_lastname",
* description = "Nom du patient",
* type="string",
* example= "Tom"
* ),
* @OA\Property( * @OA\Property(
* property="patient_firstname", * property="patient_firstname",
* description = "Prenom du patient", * description = "Prenom du patient",
@ -674,9 +668,11 @@ class HealthCareSheetController extends Controller
'accident_date' => (!empty($accident_date)) ? $accident_date : null, 'accident_date' => (!empty($accident_date)) ? $accident_date : null,
'pregnancy_start_at' => (!empty($pregnancy_start_at)) ? $pregnancy_start_at : null, 'pregnancy_start_at' => (!empty($pregnancy_start_at)) ? $pregnancy_start_at : null,
'pregnancy_end_at' => (!empty($pregnancy_end_at)) ? $pregnancy_end_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) { foreach ($request->input('performances', []) as $p) {
$fees = !empty($p['home_visit_fees']) ? $p['home_visit_fees'] : 0; $fees = !empty($p['home_visit_fees']) ? $p['home_visit_fees'] : 0;
$performance = NhPerformance::create([ $performance = NhPerformance::create([

View File

@ -138,18 +138,7 @@ class InsuranceController extends Controller
* required=false, * required=false,
* @OA\Schema( * @OA\Schema(
* type="string", * type="string",
* enum={"ALL","EDITABLE"} * enum={"ALL","EDITABLE","STOPPED"}
* )
* ),
* @OA\Parameter(
* parameter="state",
* name="state",
* description="Etat d'assurance",
* in="query",
* required=false,
* @OA\Schema(
* type="string",
* enum={"STOPPED","PAID"}
* ) * )
* ), * ),
* @OA\Response( * @OA\Response(
@ -177,13 +166,11 @@ class InsuranceController extends Controller
{ {
$this->validate($request, [ $this->validate($request, [
'user_id' => 'required|integer|exists:users,id', 'user_id' => 'required|integer|exists:users,id',
'type' => 'nullable|in:ALL,EDITABLE', 'type' => 'nullable|in:ALL,EDITABLE|STOPPED',
'state' => 'nullable|in:PAID,STOPPED'
]); ]);
$userId = $request->input('user_id'); $userId = $request->input('user_id');
$type = $request->input('type'); $type = $request->input('type');
$state = $request->input('state');
$query = NhInsurance::with(['network:id,name', 'beneficiaries'])->where('user_id', $userId); $query = NhInsurance::with(['network:id,name', 'beneficiaries'])->where('user_id', $userId);
@ -191,8 +178,13 @@ class InsuranceController extends Controller
$query = $query->where('state', $state); $query = $query->where('state', $state);
} }
if ($request->has('type') && $type == 'EDITABLE') { if (!empty($type)) {
$query = $query->whereIn('state', [InsuranceState::PAID]); 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(); $insurances = $query->orderBy('created_at', 'DESC')->get();
@ -329,7 +321,7 @@ class InsuranceController extends Controller
// Ajouter les nouveaux ayant droit // Ajouter les nouveaux ayant droit
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($newSubscription, $request, $networkConfig, $monthPrice, $datetime); $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->created_at = $newSubscription->updated_at = $datetime;
$newSubscription->save(); $newSubscription->save();
@ -528,10 +520,9 @@ class InsuranceController extends Controller
'total_bonus_amount' => $insurance->total_bonus_amount, 'total_bonus_amount' => $insurance->total_bonus_amount,
'insurance_action' => InsuranceAction::STOP_INSURANCE, 'insurance_action' => InsuranceAction::STOP_INSURANCE,
'state' => InsuranceSubscriptionState::UNDER_VALIDATION, '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, 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, '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]))); 'gender' => trans('states.' . $identification->gender), 'insurance_name' => $insurance->network->name])));

View File

@ -632,14 +632,14 @@ class InsuranceSubscriptionController extends Controller
} }
NhInsurancesPayment::create([ $payment = NhInsurancesPayment::create([
'insurance_subscription_id' => $subscription->insurance_subscription_id, 'insurance_subscription_id' => $subscription->insurance_subscription_id,
'insured_id' => $insurance->insured_id, 'insured_id' => $insurance->insured_id,
'amount' => $amountToPaid, 'amount' => $amountToPaid,
'reason' => $subscription->insurance_action, '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, 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, '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,