Fix bugs and allow user to specify quantity while execute consultation

This commit is contained in:
Djery-Tom 2022-04-12 10:49:54 +01:00
parent 7453db6d9c
commit dbea781ac6
6 changed files with 61 additions and 9 deletions

View File

@ -176,7 +176,8 @@ class Kernel extends ConsoleKernel
DB::beginTransaction();
$datetime = new DateTime();
$insurances = NhInfosInsurances::with(['network:id,name', 'user.identification', 'monthsGrid'])->whereIn('state', [InsuranceState::PAID, InsuranceState::PARTIALLY_PAID])->where('end_at', '<=', $datetime)->get();
$insurances = NhInsurance::with(['network:id,name', 'user.identification', 'monthsGrid'])->whereIn('state', [InsuranceState::PAID, InsuranceState::PARTIALLY_PAID])
->where('end_at', '<=', $datetime)->get();
NhInsurance::whereIn('state', [InsuranceState::PAID, InsuranceState::PARTIALLY_PAID])->where('end_at', '<=', $datetime)->update([
'state' => InsuranceState::EXPIRED

View File

@ -928,11 +928,12 @@ class HealthCareSheetController extends Controller
'prescriptions' => 'required_without:exams|array',
'prescriptions.*.id' => 'required|integer|exists:nh_medical_prescriptions,id',
'prescriptions.*.unit_price' => 'required|numeric',
'prescriptions.*.quantity' => 'nullable|integer|min:1',
'exams' => 'required_without:prescriptions|array',
'exams.*.id' => 'required|integer|exists:nh_exams,id',
'exams.*.quantity' => 'required|integer|min:1',
'exams.*.unit_quantity' => 'nullable|integer|min:1',
'exams.*.unit_price' => 'nullable|numeric',
'exams.*.unit_price' => 'nullable|numeric|min:1',
]);
$prescriptions = $request->input('prescriptions', []);
@ -1009,6 +1010,17 @@ class HealthCareSheetController extends Controller
DB::rollback();
return $this->errorResponse(__('errors.prescription_already_invoiced', ['id' => $itemIndex + 1]));
}
if (isset($prescriptions[$itemIndex]['quantity'])) {
$quantity_to_bill = $item->quantity - ($item->billed_quantity ?? 0);
if ($prescriptions[$itemIndex]['quantity'] > $quantity_to_bill) {
DB::rollback();
return $this->errorResponse(__('errors.prescription_ordered_quantity_must_not_greater_than_ordered_quantity',
['id' => $itemIndex + 1, 'quantity' => $quantity_to_bill]));
}
$item->quantity = $prescriptions[$itemIndex]['quantity'];
$i->billed_quantity += $item->quantity;
}
$item->unit_price = $prescriptions[$itemIndex]['unit_price'];
}
@ -1022,13 +1034,13 @@ 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'])) {
if ($i->act->billing_type == ActBillingType::UNIT_PRICE && !isset($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'])) {
if (!isset($exams[$itemIndex]['unit_price'])) {
DB::rollBack();
return $this->errorResponse(trans('errors.act_unit_price_required', ['act_name' => $i->act->name]));
}
@ -1046,9 +1058,14 @@ class HealthCareSheetController extends Controller
$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->billed_quantity = null;
$item->push();
$i->billed = true;
if (!empty($i->billed_quantity) && $i->billed_quantity != $i->quantity) {
$i->billed = false;
} else {
$i->billed = true;
}
$i->save();
@ -1742,7 +1759,7 @@ class HealthCareSheetController extends Controller
'exams.*.act_id' => 'required_with:exams.*.id|integer|exists:nh_acts,id',
'exams.*.description' => 'required_with:exams.*.id|string',
'exams.*.quantity' => 'nullable|integer',
'exams.*.unit_price' => 'nullable|numeric',
'exams.*.unit_price' => 'nullable|numeric|min:1',
'exams.*.unit_quantity' => 'nullable|integer|min:1',
'exams.*.to_delete' => 'nullable|boolean',
]);
@ -1916,10 +1933,10 @@ class HealthCareSheetController extends Controller
$exam->description = !empty($p['description']) ? $p['description'] : $exam->description;
} else {
$exam->quantity = !empty($p['quantity']) ? $p['quantity'] : $exam->quantity;
if (!empty($p['unit_price'])) {
if (isset($p['unit_price'])) {
$exam->unit_price = $p['unit_price'];
}
if (!empty($p['unit_quantity'])) {
if (isset($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);

View File

@ -438,7 +438,7 @@ trait Helper
])));
}
$invoices = NhInsurancesInvoice::with(['insurance'])->where('state', InsuranceInvoiceState::UNPAID)
$invoices = NhInsurancesInvoice::whereHas('insurance')->with(['insurance'])->where('state', InsuranceInvoiceState::UNPAID)
->whereDate('payment_deadline', Carbon::now()->subDay())->get();
foreach ($invoices as $invoice) {

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddBilledQuantityToNhMedicalPrescriptions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('nh_medical_prescriptions', function (Blueprint $table) {
$table->tinyInteger('billed_quantity')->nullable()->after('quantity');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nh_medical_prescriptions', function (Blueprint $table) {
$table->dropColumn('billed_quantity');
});
}
}

View File

@ -68,4 +68,5 @@ return [
'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",
'prescription_ordered_quantity_must_not_greater_than_ordered_quantity' => "Prescription quantity :id must not be greater than :quantity"
];

View File

@ -68,4 +68,5 @@ return [
'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",
'prescription_ordered_quantity_must_not_greater_than_ordered_quantity' => "La quantité de la prescription :id ne doit pas être supérieure à :quantity"
];