Add unit_quantity to nh exams

This commit is contained in:
Djery-Tom 2022-04-07 16:46:46 +01:00
parent 9e15c3b39b
commit 5bd371c119
5 changed files with 36 additions and 8 deletions

View File

@ -901,10 +901,20 @@ class HealthCareSheetController extends Controller
* example = 2, * example = 2,
* description="ID de l'operation" * description="ID de l'operation"
* ), * ),
* @OA\Property(property="quantity",
* type="int",
* example=5,
* description="Quantité"
* ),
* @OA\Property(property="unit_price", * @OA\Property(property="unit_price",
* type="float", * type="float",
* example= 5000, * example= 5000,
* description="Prix unitaire" * 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', 'prescriptions.*.unit_price' => 'required|numeric',
'exams' => 'required_without:prescriptions|array', 'exams' => 'required_without:prescriptions|array',
'exams.*.id' => 'required|integer|exists:nh_exams,id', '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', 'exams.*.unit_price' => 'nullable|numeric',
]); ]);
@ -1011,6 +1022,11 @@ class HealthCareSheetController extends Controller
return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => $itemIndex + 1])); return $this->errorResponse(__('errors.exam_already_invoiced', ['id' => $itemIndex + 1]));
} }
// Fetch exam unit price // 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 ($i->act->billing_type == ActBillingType::FREE) {
if (empty($exams[$itemIndex]['unit_price'])) { if (empty($exams[$itemIndex]['unit_price'])) {
DB::rollBack(); DB::rollBack();
@ -1021,12 +1037,13 @@ class HealthCareSheetController extends Controller
$item->unit_price = $i->act->amount; $item->unit_price = $i->act->amount;
} }
$item->quantity = $exams[$itemIndex]['quantity']; $item->quantity = $exams[$itemIndex]['quantity'];
$item->unit_quantity = $exams[$itemIndex]['unit_quantity'];
} }
unset($item->laravel_through_key); unset($item->laravel_through_key);
$item->insured_paid_amount = $parts->insured_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->insurer_paid_amount = $parts->insurer_part * $item->unit_price * ($item->quantity ?? 1) * ($item->unit_quantity ?? 1);
$item->created_at = $item->updated_at = $datetime; $item->created_at = $item->updated_at = $datetime;
$item->billed = true; $item->billed = true;
$item->push(); $item->push();
@ -1263,8 +1280,8 @@ class HealthCareSheetController extends Controller
if (!empty($state) && $state == 'TO_BILL') { if (!empty($state) && $state == 'TO_BILL') {
// Liste des feuilles de soins a afficher pour l'execution // Liste des feuilles de soins a afficher pour l'execution
$query = NhInfosHealthCareSheets::with(['performances.act:id,code,name', 'exams' => function ($q) { $query = NhInfosHealthCareSheets::with(['performances.act:id,code,name,type,billing_type,unit_value,amount', 'exams' => function ($q) {
return $q->with(['act:id,code,name'])->where('billed', 0); return $q->with(['act:id,code,name,type,billing_type,unit_value,amount'])->where('billed', 0);
}, 'prescriptions' => function ($q) { }, 'prescriptions' => function ($q) {
return $q->with(['drug_or_device:id,name'])->where('billed', 0); return $q->with(['drug_or_device:id,name'])->where('billed', 0);
}])->where('state', InsuranceSubscriptionState::ACCEPTED) }])->where('state', InsuranceSubscriptionState::ACCEPTED)
@ -1726,6 +1743,7 @@ class HealthCareSheetController extends Controller
'exams.*.description' => 'required_with:exams.*.id|string', 'exams.*.description' => 'required_with:exams.*.id|string',
'exams.*.quantity' => 'required_with:exams.*.id|integer', 'exams.*.quantity' => 'required_with:exams.*.id|integer',
'exams.*.unit_price' => 'nullable|numeric', 'exams.*.unit_price' => 'nullable|numeric',
'exams.*.unit_quantity' => 'nullable|integer|min:1',
'exams.*.to_delete' => 'nullable|boolean', 'exams.*.to_delete' => 'nullable|boolean',
]); ]);
@ -1900,9 +1918,12 @@ class HealthCareSheetController extends Controller
$exam->quantity = !empty($p['quantity']) ? $p['quantity'] : $exam->quantity; $exam->quantity = !empty($p['quantity']) ? $p['quantity'] : $exam->quantity;
if (!empty($p['unit_price'])) { if (!empty($p['unit_price'])) {
$exam->unit_price = $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->updated_at = $datetime;
$exam->save(); $exam->save();
@ -2120,6 +2141,7 @@ class HealthCareSheetController extends Controller
'exams' => 'required_if:act_type,EXAM|array', 'exams' => 'required_if:act_type,EXAM|array',
'exams.*.quantity' => 'required|integer|min:1', 'exams.*.quantity' => 'required|integer|min:1',
'exams.*.unit_price' => 'required|numeric', 'exams.*.unit_price' => 'required|numeric',
'exams.*.unit_quantity' => 'nullable|integer|min:1',
]); ]);
$beneficiary = NhHavingRight::find($request->input('beneficiary_id')); $beneficiary = NhHavingRight::find($request->input('beneficiary_id'));
@ -2159,7 +2181,7 @@ class HealthCareSheetController extends Controller
break; break;
case 'EXAM': case 'EXAM':
foreach ($exams as $e) { 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); $act = NhExam::find($act_id);
break; break;

View File

@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\Model;
* @property string $description * @property string $description
* @property int $quantity * @property int $quantity
* @property float $unit_price * @property float $unit_price
* @property int $unit_quantity
* @property float $insured_paid_amount * @property float $insured_paid_amount
* @property float $insurer_paid_amount * @property float $insurer_paid_amount
* @property int $billed * @property int $billed
@ -43,6 +44,7 @@ class NhExam extends Model
'description', 'description',
'quantity', 'quantity',
'unit_price', 'unit_price',
'unit_quantity',
'insured_paid_amount', 'insured_paid_amount',
'insurer_paid_amount', 'insurer_paid_amount',
'billed' 'billed'

View File

@ -15,6 +15,7 @@ class AddNullableToNhExamsQuantity extends Migration
{ {
Schema::table('nh_exams', function (Blueprint $table) { Schema::table('nh_exams', function (Blueprint $table) {
$table->unsignedInteger('quantity')->nullable()->change(); $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) { Schema::table('nh_exams', function (Blueprint $table) {
$table->unsignedInteger('quantity')->change(); $table->unsignedInteger('quantity')->change();
$table->dropColumn(['unit_quantity']);
}); });
} }
} }

View File

@ -67,4 +67,5 @@ return [
'act_amount_required' => "The amount is required for the act :act_name", '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_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_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",
]; ];

View File

@ -67,4 +67,5 @@ return [
'act_amount_required' => "Le montant est requis pour l'acte :act_name", '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_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_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",
]; ];