diff --git a/app/Http/Controllers/HealthCareSheetController.php b/app/Http/Controllers/HealthCareSheetController.php index 7013b98..8ca4c88 100755 --- a/app/Http/Controllers/HealthCareSheetController.php +++ b/app/Http/Controllers/HealthCareSheetController.php @@ -901,10 +901,20 @@ class HealthCareSheetController extends Controller * example = 2, * description="ID de l'operation" * ), + * @OA\Property(property="quantity", + * type="int", + * example=5, + * description="Quantité" + * ), * @OA\Property(property="unit_price", * type="float", * example= 5000, * description="Prix unitaire" + * ), + * @OA\Property(property="unit_quantity", + * type="int", + * example=5, + * description="Quantité de l'unité (pour les actes a prix unitaire)" * ) * ) */ @@ -920,7 +930,8 @@ class HealthCareSheetController extends Controller 'prescriptions.*.unit_price' => 'required|numeric', 'exams' => 'required_without:prescriptions|array', 'exams.*.id' => 'required|integer|exists:nh_exams,id', - 'exams.*.quantity' => 'required|numeric|min:1', + 'exams.*.quantity' => 'required|integer|min:1', + 'exams.*.unit_quantity' => 'nullable|integer|min:1', 'exams.*.unit_price' => 'nullable|numeric', ]); @@ -1011,6 +1022,11 @@ class HealthCareSheetController extends Controller return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => $itemIndex + 1])); } // Fetch exam unit price + if ($i->act->billing_type == ActBillingType::UNIT_PRICE && empty($exams[$itemIndex]['unit_quantity'])) { + DB::rollBack(); + return $this->errorResponse(trans('errors.act_unit_quantity_required', ['act_name' => $i->act->name])); + } + if ($i->act->billing_type == ActBillingType::FREE) { if (empty($exams[$itemIndex]['unit_price'])) { DB::rollBack(); @@ -1021,12 +1037,13 @@ class HealthCareSheetController extends Controller $item->unit_price = $i->act->amount; } $item->quantity = $exams[$itemIndex]['quantity']; + $item->unit_quantity = $exams[$itemIndex]['unit_quantity']; } unset($item->laravel_through_key); - $item->insured_paid_amount = $parts->insured_part * $item->unit_price * ($item->quantity ?? 1); - $item->insurer_paid_amount = $parts->insurer_part * $item->unit_price * ($item->quantity ?? 1); + $item->insured_paid_amount = $parts->insured_part * $item->unit_price * ($item->quantity ?? 1) * ($item->unit_quantity ?? 1); + $item->insurer_paid_amount = $parts->insurer_part * $item->unit_price * ($item->quantity ?? 1) * ($item->unit_quantity ?? 1); $item->created_at = $item->updated_at = $datetime; $item->billed = true; $item->push(); @@ -1263,8 +1280,8 @@ class HealthCareSheetController extends Controller if (!empty($state) && $state == 'TO_BILL') { // Liste des feuilles de soins a afficher pour l'execution - $query = NhInfosHealthCareSheets::with(['performances.act:id,code,name', 'exams' => function ($q) { - return $q->with(['act:id,code,name'])->where('billed', 0); + $query = NhInfosHealthCareSheets::with(['performances.act:id,code,name,type,billing_type,unit_value,amount', 'exams' => function ($q) { + return $q->with(['act:id,code,name,type,billing_type,unit_value,amount'])->where('billed', 0); }, 'prescriptions' => function ($q) { return $q->with(['drug_or_device:id,name'])->where('billed', 0); }])->where('state', InsuranceSubscriptionState::ACCEPTED) @@ -1726,6 +1743,7 @@ class HealthCareSheetController extends Controller 'exams.*.description' => 'required_with:exams.*.id|string', 'exams.*.quantity' => 'required_with:exams.*.id|integer', 'exams.*.unit_price' => 'nullable|numeric', + 'exams.*.unit_quantity' => 'nullable|integer|min:1', 'exams.*.to_delete' => 'nullable|boolean', ]); @@ -1900,9 +1918,12 @@ class HealthCareSheetController extends Controller $exam->quantity = !empty($p['quantity']) ? $p['quantity'] : $exam->quantity; if (!empty($p['unit_price'])) { $exam->unit_price = $p['unit_price']; - $exam->insured_paid_amount = $parts->insured_part * $exam->unit_price * ($exam->quantity ?? 1); - $exam->insurer_paid_amount = $parts->insurer_part * $exam->unit_price * ($exam->quantity ?? 1); } + if (!empty($p['unit_quantity'])) { + $exam->unit_quantity = $p['unit_quantity']; + } + $exam->insured_paid_amount = $parts->insured_part * $exam->unit_price * ($exam->quantity ?? 1) * ($exam->unit_quantity ?? 1); + $exam->insurer_paid_amount = $parts->insurer_part * $exam->unit_price * ($exam->quantity ?? 1) * ($exam->unit_quantity ?? 1); } $exam->updated_at = $datetime; $exam->save(); @@ -2120,6 +2141,7 @@ class HealthCareSheetController extends Controller 'exams' => 'required_if:act_type,EXAM|array', 'exams.*.quantity' => 'required|integer|min:1', 'exams.*.unit_price' => 'required|numeric', + 'exams.*.unit_quantity' => 'nullable|integer|min:1', ]); $beneficiary = NhHavingRight::find($request->input('beneficiary_id')); @@ -2159,7 +2181,7 @@ class HealthCareSheetController extends Controller break; case 'EXAM': foreach ($exams as $e) { - $insurance_amount += ($parts->insurer_part * $e['unit_price'] * $e['quantity']); + $insurance_amount += ($parts->insurer_part * $e['unit_price'] * $e['quantity'] * ($e['unit_quantity'] ?? 1)); } $act = NhExam::find($act_id); break; diff --git a/app/Models/NhExam.php b/app/Models/NhExam.php index 0d3008f..784e21e 100644 --- a/app/Models/NhExam.php +++ b/app/Models/NhExam.php @@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\Model; * @property string $description * @property int $quantity * @property float $unit_price + * @property int $unit_quantity * @property float $insured_paid_amount * @property float $insurer_paid_amount * @property int $billed @@ -43,6 +44,7 @@ class NhExam extends Model 'description', 'quantity', 'unit_price', + 'unit_quantity', 'insured_paid_amount', 'insurer_paid_amount', 'billed' diff --git a/database/migrations/2022_04_07_120405_add_nullable_to_nh_exams_quantity.php b/database/migrations/2022_04_07_120405_add_nullable_to_nh_exams_quantity.php index 421c705..d9abe0a 100644 --- a/database/migrations/2022_04_07_120405_add_nullable_to_nh_exams_quantity.php +++ b/database/migrations/2022_04_07_120405_add_nullable_to_nh_exams_quantity.php @@ -15,6 +15,7 @@ class AddNullableToNhExamsQuantity extends Migration { Schema::table('nh_exams', function (Blueprint $table) { $table->unsignedInteger('quantity')->nullable()->change(); + $table->unsignedInteger('unit_quantity')->nullable()->after('unit_price'); }); } @@ -27,6 +28,7 @@ class AddNullableToNhExamsQuantity extends Migration { Schema::table('nh_exams', function (Blueprint $table) { $table->unsignedInteger('quantity')->change(); + $table->dropColumn(['unit_quantity']); }); } } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index a89a37b..bf83a2f 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -67,4 +67,5 @@ return [ 'act_amount_required' => "The amount is required for the act :act_name", 'act_quantity_required' => "The quantity is required for the act :act_name", 'act_authorization_request_required' => "An authorization is required to apply the act :act_name", + 'act_unit_quantity_required' => "The unit quantity is required for the act :act_name", ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 081a4b0..cf30507 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -67,4 +67,5 @@ return [ 'act_amount_required' => "Le montant est requis pour l'acte :act_name", 'act_quantity_required' => "La quantité est requise pour l'acte :act_name", 'act_authorization_request_required' => "Une autorisation est requise pour appliquer l'acte :act_name", + 'act_unit_quantity_required' => "La quantité de l'unité est requise pour l'acte :act_name", ];