From 72338c4c1f42bf0204c950a6d94365cb74096876 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Tue, 29 Mar 2022 00:49:57 +0100 Subject: [PATCH] Setup insurance waiting_days(delai de carence) and replace number_of_months to months_grid_id --- app/Console/Kernel.php | 6 +- .../Controllers/HealthCareSheetController.php | 90 +----- app/Http/Controllers/InsuranceController.php | 28 +- .../InsuranceSubscriptionController.php | 21 +- app/Http/Controllers/InsuredController.php | 15 +- app/Http/Controllers/InvoiceController.php | 266 +++++++++++++++++- app/InsuranceSubscriptionState.php | 2 + app/Models/NhInsurance.php | 9 +- app/Models/NhInsurancesSubscription.php | 9 +- app/Models/NhInvoice.php | 10 + app/Models/NhPricesGrid.php | 50 ---- app/Traits/Helper.php | 104 ++++++- ...nh_infos_insurances_subscriptions_view.php | 1 + ...205552_update_nh_infos_insurances_view.php | 1 + ...2_add_new_role_to_nh_validating_agents.php | 34 +++ ..._state_and_reason_to_nh_invoices_table.php | 36 +++ ...5_070335_update_nh_infos_invoices_view.php | 38 +++ ...word_validation_in_nh_networks_configs.php | 35 +++ ..._add_file_url_to_nh_health_care_sheets.php | 32 +++ ...ment_duration_to_nh_months_prices_grid.php | 43 +++ ...kup_percentage_to_nh_years_prices_grid.php | 35 +++ ...and_nh_insurances_subscriptions_tables.php | 44 +++ ...64749_update_nh_infos_insurances_view2.php | 32 +++ ...h_infos_insurances_subscriptions_view2.php | 32 +++ resources/lang/en/errors.php | 4 +- resources/lang/en/messages.php | 5 +- resources/lang/fr/errors.php | 4 +- resources/lang/fr/messages.php | 3 + routes/web.php | 1 + 29 files changed, 816 insertions(+), 174 deletions(-) delete mode 100644 app/Models/NhPricesGrid.php create mode 100644 database/migrations/2022_03_10_150702_add_new_role_to_nh_validating_agents.php create mode 100644 database/migrations/2022_03_15_063317_add_state_and_reason_to_nh_invoices_table.php create mode 100644 database/migrations/2022_03_15_070335_update_nh_infos_invoices_view.php create mode 100644 database/migrations/2022_03_25_074904_add_password_validation_in_nh_networks_configs.php create mode 100644 database/migrations/2022_03_25_075235_add_file_url_to_nh_health_care_sheets.php create mode 100644 database/migrations/2022_03_25_115643_add_waiting_period_payment_period_and_payment_duration_to_nh_months_prices_grid.php create mode 100644 database/migrations/2022_03_25_150821_update_markup_percentage_to_nh_years_prices_grid.php create mode 100644 database/migrations/2022_03_28_140904_add_months_grid_id_to_nh_insurances_and_nh_insurances_subscriptions_tables.php create mode 100644 database/migrations/2022_03_28_164749_update_nh_infos_insurances_view2.php create mode 100644 database/migrations/2022_03_28_200507_update_nh_infos_insurances_subscriptions_view2.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 9f763f0..edc6f69 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -122,7 +122,7 @@ class Kernel extends ConsoleKernel $invoice->amount = $this->toMoneyWithCurrencyCode($invoice->amount, $country->currency_code); $invoice->insured_amount = $this->toMoneyWithCurrencyCode($invoice->insured_amount, $country->currency_code); $invoice->insurer_amount = $this->toMoneyWithCurrencyCode($invoice->insurer_amount, $country->currency_code); - $invoice->home_visit_fees = $this->toMoneyWithCurrencyCode($invoice->home_visit_fees, $country->currency_code); +// $invoice->home_visit_fees = $this->toMoneyWithCurrencyCode($invoice->home_visit_fees, $country->currency_code); $ids = array_map(function ($r) { return $r['id']; @@ -171,7 +171,7 @@ class Kernel extends ConsoleKernel DB::beginTransaction(); $datetime = new DateTime(); - $insurances = NhInfosInsurances::with(['network:id,name', 'user.identification'])->where('state', InsuranceState::PAID)->where('end_at', '<=', $datetime)->get(); + $insurances = NhInfosInsurances::with(['network:id,name', 'user.identification', 'monthsGrid'])->where('state', InsuranceState::PAID)->where('end_at', '<=', $datetime)->get(); NhInsurance::where('state', InsuranceState::PAID)->where('end_at', '<=', $datetime)->update([ 'state' => InsuranceState::EXPIRED @@ -184,7 +184,7 @@ class Kernel extends ConsoleKernel $message = trans('messages.insurance_expired_mail', ['name' => $i->lastname, 'insured_id' => $i->insured_id, 'bonus_amount' => $this->toMoneyWithCurrencyCode($i->bonus_amount, $i->currency_code), 'total_bonus_amount' => $this->toMoneyWithCurrencyCode($i->total_bonus_amount, $i->currency_code), 'number_of_beneficiaries' => $i->number_of_beneficiaries, 'gender' => trans('states.' . $i->user->identification->gender), - 'insurance_name' => $i->network->name, 'months' => $i->number_of_months]); + 'insurance_name' => $i->network->name, 'months' => $i->monthsGrid->number_of_months]); $recipients = [preg_replace("/\s+/", "", $i->email)]; // Supprimer les espaces dans le mail Mail::mailer('smtp')->raw($message, function ($message) use ($recipients, $title) { diff --git a/app/Http/Controllers/HealthCareSheetController.php b/app/Http/Controllers/HealthCareSheetController.php index 78f33ef..a5754af 100755 --- a/app/Http/Controllers/HealthCareSheetController.php +++ b/app/Http/Controllers/HealthCareSheetController.php @@ -762,47 +762,6 @@ class HealthCareSheetController extends Controller } - /** - * @throws AppException - */ - // Verification de la limite de couverture - private function verifyInsuranceCoverageAmount(NhNetworksConfig $nhConfig, NhInsurance $insurance, NhHealthCareSheet $sheet, NhHavingRight $beneficiary = null, - $currency_code = 'XAF', $currentInsuranceAmount = 0) // Current Insurance Amount en cas de mise à jour de la feuille de soins pour ne pas prendre en compte la couverture deja affecté - { - $insurance_coverage_amount = isset($beneficiary) ? $beneficiary->insurance_coverage_amount : $insurance->insurance_coverage_amount; - $insurance_amount = $sheet->insurance_amount; - $monthPrice = $nhConfig->monthsPricesGrid()->where('nh_network_config_id', $nhConfig->id) - ->where('number_of_months', $insurance->number_of_months)->first(); - - if (!isset($monthPrice)) - throw new AppException(trans('errors.month_price_grid_not_found')); - - if (!$nhConfig->family_coverage_sharing) { - $total_insurance_amount = $insurance_coverage_amount + $insurance_amount - $currentInsuranceAmount; - if ($total_insurance_amount > $monthPrice->max_insurance_coverage_amount) { - DB::rollBack(); - throw new AppException(trans('errors.insurance_coverage_amount_exceeded', [ - 'consumption' => $this->toMoneyWithCurrencyCode($insurance_coverage_amount, $currency_code), - 'remaining' => $this->toMoneyWithCurrencyCode($monthPrice->max_insurance_coverage_amount - $insurance_coverage_amount, $currency_code), - ])); - } - } else { - // Montant de l'assurance deja consomé à date - $family_consumed_amount = $insurance->insurance_coverage_amount; - foreach ($insurance->beneficiaries as $b) { - $family_consumed_amount += $b->insurance_coverage_amount; - } - $total_insurance_amount = $family_consumed_amount + $insurance_amount - $currentInsuranceAmount; - $family_limit_amount = $monthPrice->max_insurance_coverage_amount * ($insurance->number_of_beneficiaries + 1); - if ($total_insurance_amount > $family_limit_amount) { - DB::rollBack(); - throw new AppException(trans('errors.insurance_coverage_amount_exceeded', [ - 'consumption' => $this->toMoneyWithCurrencyCode($family_consumed_amount, $currency_code), - 'remaining' => $this->toMoneyWithCurrencyCode($family_limit_amount - $family_consumed_amount, $currency_code), - ])); - } - } - } private function useAuthorizationRequest($act_id, $insurance_id, $beneficiary_id, $sheet_id, $datetime): void { @@ -819,19 +778,6 @@ class HealthCareSheetController extends Controller ]); } - private function updateInsuranceCoverageAmount(NhHealthCareSheet $sheet, NhInsurance $insurance, $datetime, - NhHavingRight $beneficiary = null, $currentInsuranceAmount = 0): void - { // Current Insurance Amount en cas de mise à jour de la feuille de soins pour ne pas prendre en compte la couverture deja affecté) - $sheet->insurance_consumed_at = $datetime; - if (!empty($beneficiary)) { - $beneficiary->insurance_coverage_amount += ($sheet->insurance_amount - $currentInsuranceAmount); - $beneficiary->save(); - } else { - $insurance->insurance_coverage_amount += ($sheet->insurance_amount - $currentInsuranceAmount); - $insurance->save(); - } - $sheet->save(); - } /** * @OA\Post( @@ -1495,30 +1441,6 @@ class HealthCareSheetController extends Controller } } - private function getConfigInsuranceParts(NhNetworksConfig $nhConfig, $care_condition): stdClass - { - $insuredPart = 0; - $insurerPart = 0; - switch ($care_condition) { - case 'CURRENT_AFFECTION': - $insurerPart = $nhConfig->current_affection_percentage_insurer / 100; - $insuredPart = $nhConfig->current_affection_percentage_insured / 100; - break; - case 'LONG_TERM_AFFECTION': - $insurerPart = $nhConfig->long_term_affection_percentage_insurer / 100; - $insuredPart = $nhConfig->long_term_affection_percentage_insured / 100; - break; - case 'EXONERATION': - $insurerPart = $nhConfig->exoneration_percentage_insurer / 100; - $insuredPart = $nhConfig->exoneration_percentage_insured / 100; - break; - } - $result = new stdClass(); - $result->insured_part = $insuredPart; - $result->insurer_part = $insurerPart; - return $result; - } - /** * @OA\Put( * path="/health-care-sheets/{id}", @@ -1972,15 +1894,6 @@ class HealthCareSheetController extends Controller } } - private function generateSheetID(): string - { - do { - $code = generateTransactionCode(); - $codeCorrect = NhHealthCareSheet::where('health_care_sheet_id', $code)->count() < 0; - } while ($codeCorrect); - return $code; - } - /** * @param $sheet * @return void @@ -2184,8 +2097,7 @@ class HealthCareSheetController extends Controller return $this->errorResponse(trans('errors.nano_health_not_activated')); } - $monthPrice = $nhConfig->monthsPricesGrid()->where('nh_network_config_id', $nhConfig->id) - ->where('number_of_months', $insurance->number_of_months)->first(); + $monthPrice = $insurance->monthsGrid; if (!isset($monthPrice)) return $this->errorResponse(trans('errors.month_price_grid_not_found')); diff --git a/app/Http/Controllers/InsuranceController.php b/app/Http/Controllers/InsuranceController.php index d58c9b1..6258ae2 100644 --- a/app/Http/Controllers/InsuranceController.php +++ b/app/Http/Controllers/InsuranceController.php @@ -228,7 +228,7 @@ class InsuranceController extends Controller $array = $pagination ? $insurances->items() : $insurances; foreach ($array as $insurance) { - $monthPrice = $insurance->nhNetworkConfig->monthsPricesGrid()->where('number_of_months', $insurance->number_of_months)->first(); + $monthPrice = $insurance->monthsGrid; $insurance->state = trans('states.' . $insurance->state); @@ -345,9 +345,7 @@ class InsuranceController extends Controller if ((sizeof($request->input('beneficiaries', [])) + $nbOfBeneficiaries) > $networkConfig->max_number_of_beneficiaries) return $this->errorResponse(trans('errors.number_of_beneficiaries_exceeded')); - $monthPrice = $networkConfig->monthsPricesGrid()->where('number_of_months', $insurance->number_of_months)->first(); - if (!isset($monthPrice)) - return $this->errorResponse(trans('errors.incorrect_selected_amount')); + $monthPrice = $insurance->monthsGrid; try { DB::beginTransaction(); @@ -358,7 +356,7 @@ class InsuranceController extends Controller 'user_id' => $insurance->user_id, 'insurance_subscription_id' => $this->generateSubscriptionID(), 'number_of_beneficiaries' => sizeof($request->input('beneficiaries', [])), - 'number_of_months' => $monthPrice->number_of_months, + 'months_grid_id' => $monthPrice->id, 'bonus_amount' => $monthPrice->min_amount, 'insurance_action' => InsuranceAction::ADDITION_OF_BENEFICIARY, 'state' => InsuranceSubscriptionState::UNDER_VALIDATION, @@ -561,7 +559,7 @@ class InsuranceController extends Controller 'user_id' => $insurance->user_id, 'insurance_subscription_id' => $this->generateSubscriptionID(), 'number_of_beneficiaries' => $insurance->number_of_beneficiaries, - 'number_of_months' => $insurance->number_of_months, + 'months_grid_id' => $insurance->months_grid_id, 'bonus_amount' => $insurance->bonus_amount, 'total_bonus_amount' => $insurance->total_bonus_amount, 'insurance_action' => InsuranceAction::STOP_INSURANCE, @@ -659,10 +657,7 @@ class InsuranceController extends Controller if (sizeof($insurance->beneficiaries) > $networkConfig->max_number_of_beneficiaries) return $this->errorResponse(trans('errors.number_of_beneficiaries_exceeded')); - $monthPrice = $networkConfig->monthsPricesGrid()->where('nh_network_config_id', $networkConfig->id) - ->where('number_of_months', $insurance->number_of_months)->first(); - if (!isset($monthPrice)) - return $this->errorResponse(trans('errors.incorrect_selected_amount')); + $monthPrice = $insurance->monthsGrid; $currency = $this->getNetworkCurrency($insurance->network_id); @@ -696,6 +691,13 @@ class InsuranceController extends Controller $user->wallet->save(); $user->save(); + if (empty($monthPrice->waiting_period_days)) { + $start_at = $datetime; + } else { + $start_at = $this->addDaysToDateTime($datetime, $monthPrice->waiting_period_days); + } + $end_at = $this->addMonthsToDateTime($start_at, $monthPrice->number_of_months); + $insurance->update([ 'number_of_beneficiaries' => sizeof($insurance->beneficiaries), 'total_bonus_amount' => $amountToPaid, @@ -703,8 +705,8 @@ class InsuranceController extends Controller 'insurance_coverage_amount' => 0, 'updated_at' => $datetime, 'state' => InsuranceState::PAID, - 'start_at' => $datetime, - 'end_at' => DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $insurance->number_of_months . 'months') + 'start_at' => $start_at, + 'end_at' => $end_at ]); // Reinitialiser les montants de couvertures de l'assurance $insurance->beneficiaries->each->update([ @@ -720,7 +722,7 @@ class InsuranceController extends Controller Event::dispatch(new InsuranceEvent($insurance, trans('messages.insurance_renew'), trans('messages.insurance_renew_mail', ['name' => $user->lastname, 'insured_id' => $insurance->insured_id, 'bonus_amount' => $this->toMoneyWithCurrencyCode($bonus_amount, $currency), 'total_bonus_amount' => $this->toMoneyWithCurrencyCode($amountToPaid, $currency), 'number_of_beneficiaries' => $insurance->number_of_beneficiaries, - 'gender' => trans('states.' . $user->identification->gender), 'insurance_name' => $insurance->network->name, 'months' => $insurance->number_of_months]))); + 'gender' => trans('states.' . $user->identification->gender), 'insurance_name' => $insurance->network->name, 'months' => $monthPrice->number_of_months]))); DB::commit(); return $this->successResponse(trans('messages.insurance_renew_paid')); } catch (Throwable $e) { diff --git a/app/Http/Controllers/InsuranceSubscriptionController.php b/app/Http/Controllers/InsuranceSubscriptionController.php index 6914c56..41fc3d3 100644 --- a/app/Http/Controllers/InsuranceSubscriptionController.php +++ b/app/Http/Controllers/InsuranceSubscriptionController.php @@ -21,6 +21,7 @@ use App\Models\NhNetworksConfig; use App\Models\User; use App\Models\Wallet; use App\Traits\Helper; +use Carbon\Carbon; use DateTime; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\Request; @@ -110,13 +111,13 @@ class InsuranceSubscriptionController extends Controller if (!empty($subscription_id)) { $subscription = NhInsurancesSubscription::findOrFail($subscription_id); $networkConfig = $subscription->nhNetworkConfig; - $monthPrice = $networkConfig->monthsPricesGrid()->where('number_of_months', $subscription->number_of_months)->first(); + $monthPrice = $subscription->monthsGrid; $beneficiaries = array_merge($subscription->beneficiaries->toArray(), $request->input('beneficiaries', [])); } elseif (!empty($insurance_id)) { $insurance = NhInsurance::findOrFail($insurance_id); $networkConfig = $insurance->nhNetworkConfig; - $monthPrice = $networkConfig->monthsPricesGrid()->where('number_of_months', $insurance->number_of_months)->first(); + $monthPrice = $insurance->monthsGrid; $beneficiaries = array_merge($insurance->beneficiaries->toArray(), $request->input('beneficiaries', [])); } else { @@ -326,7 +327,7 @@ class InsuranceSubscriptionController extends Controller $subscription = new NhInsurancesSubscription($request->all()); $subscription->number_of_beneficiaries = sizeof($request->input('beneficiaries', [])); $subscription->insurance_subscription_id = $this->generateSubscriptionID(); - $subscription->number_of_months = $monthPrice->number_of_months; + $subscription->months_grid_id = $monthPrice->id; $subscription->bonus_amount = $monthPrice->min_amount; $subscription->insurance_action = InsuranceAction::ACTIVATION; $subscription->save(); @@ -605,18 +606,24 @@ class InsuranceSubscriptionController extends Controller if ($subscription->insurance_action == InsuranceAction::ACTIVATION) { $insuredId = $this->generateInsuredID(); + if (empty($subscription->monthsGrid->waiting_period_days)) { + $start_at = $datetime; + } else { + $start_at = $this->addDaysToDateTime($datetime, $subscription->monthsGrid->waiting_period_days); + } + $end_at = $this->addMonthsToDateTime($start_at, $subscription->monthsGrid->number_of_months); $insurance = NhInsurance::create([ 'network_id' => $subscription->network_id, 'user_id' => $subscription->user_id, 'insured_id' => $insuredId, - 'number_of_months' => $subscription->number_of_months, + 'months_grid_id' => $subscription->months_grid_id, 'total_bonus_amount' => $subscription->total_bonus_amount, 'number_of_beneficiaries' => $subscription->number_of_beneficiaries, 'bonus_amount' => $subscription->bonus_amount, 'created_at' => $datetime, 'updated_at' => $datetime, 'state' => InsuranceState::PAID, - 'start_at' => $datetime, - 'end_at' => DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $subscription->number_of_months . 'months') + 'start_at' => $start_at, + 'end_at' => $end_at ]); foreach ($subscription->beneficiaries as $b) { NhInsurancesHavingRight::create([ @@ -660,7 +667,7 @@ class InsuranceSubscriptionController extends Controller 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, - 'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name, 'months' => $subscription->number_of_months]))); + 'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name, 'months' => $subscription->monthsGrid->number_of_months]))); DB::commit(); return $this->successResponse(trans('messages.insurance_subscription_paid')); } catch (Throwable $e) { diff --git a/app/Http/Controllers/InsuredController.php b/app/Http/Controllers/InsuredController.php index 5819376..8d3f01d 100755 --- a/app/Http/Controllers/InsuredController.php +++ b/app/Http/Controllers/InsuredController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers; +use App\InsuranceState; +use App\Models\CountriesCurrency; use App\Models\Network; use App\Models\NhInsurance; use App\Models\User; @@ -87,9 +89,16 @@ class InsuredController extends Controller $name = $request->input('name'); $phone = $request->input('phone'); $network_id = $request->input('network_id'); - $currency_code = $this->getNetworkCurrency($network_id); + $network = Network::find($network_id); + if (!isset($network)) { + return $this->errorResponse(trans('errors.network_not_found')); + } - $q = NhInsurance::with(['user:id,firstname,lastname,phone,email', 'network:id,name', 'beneficiaries', 'nhNetworkConfig'])->where('network_id', $network_id); + $currency_code = $network->country->currency_code; + $datetime = $this->getCurrentTimeByCountryCode($network->country->code_country); + + $q = NhInsurance::with(['user:id,firstname,lastname,phone,email', 'network:id,name', 'beneficiaries', 'nhNetworkConfig', 'monthsGrid'])->where('network_id', $network_id) + ->where('state', InsuranceState::PAID)->where('start_at', '<=', $datetime); if (!empty($insured_id)) { $q = $q->where('insured_id', $insured_id); @@ -109,7 +118,7 @@ class InsuredController extends Controller $insured = $q->get(); foreach ($insured as $i) { - $monthPrice = $i->nhNetworkConfig->monthsPricesGrid()->where('number_of_months', $i->number_of_months)->first(); + $monthPrice = $i->monthsGrid; $i->insurance_consumed_amount = $this->toMoneyWithCurrencyCode($i->insurance_coverage_amount, $currency_code); $i->insurance_remaining_amount = $this->toMoneyWithCurrencyCode(($monthPrice->max_insurance_coverage_amount ?? 0) - $i->insurance_coverage_amount, $currency_code); foreach ($i->beneficiaries as $b) { diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 6b182da..2878624 100755 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -4,11 +4,15 @@ namespace App\Http\Controllers; use App\BillingPeriodType; +use App\HealthCareSheetType; use App\InsuranceState; use App\InsuranceSubscriptionState; use App\Models\AgentPlus; use App\Models\CountriesCurrency; use App\Models\NhHealthCareSheet; +use App\Models\NhHealthCareSheetsExam; +use App\Models\NhHealthCareSheetsPerformance; +use App\Models\NhHealthCareSheetsPrescription; use App\Models\NhInfosInsurances; use App\Models\NhInfosInvoice; use App\Models\NhInsurance; @@ -20,6 +24,9 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; +use stdClass; +use Throwable; + class InvoiceController extends Controller { /** @@ -127,7 +134,7 @@ class InvoiceController extends Controller $invoice->amount = $this->toMoneyWithCurrencyCode($invoice->amount, $country->currency_code); $invoice->insured_amount = $this->toMoneyWithCurrencyCode($invoice->insured_amount, $country->currency_code); $invoice->insurer_amount = $this->toMoneyWithCurrencyCode($invoice->insurer_amount, $country->currency_code); - $invoice->home_visit_fees = $this->toMoneyWithCurrencyCode($invoice->home_visit_fees, $country->currency_code); +// $invoice->home_visit_fees = $this->toMoneyWithCurrencyCode($invoice->home_visit_fees, $country->currency_code); $ids = array_map(function ($r) { return $r['id']; @@ -268,4 +275,261 @@ class InvoiceController extends Controller } return $this->successResponse($invoices); } + + public function treatInvoice(Request $request, $id) + { + $this->validate($request, [ + 'validating_agent_id' => 'required|integer|exists:nh_validating_agents,id', + 'reason' => 'required_if:action,REJECT|string', + 'action' => 'required|in:ACCEPT,REJECT,ACCEPT_AND_UPDATE', + 'sheets' => 'required_if:action,ACCEPT_AND_UPDATE|array' + ]); + + $action = $request->input('action'); + $validating_agent_id = $request->input('validating_agent_id'); + $reason = $request->input('reason'); + $invoice = NhInvoice::find($id); + if (!isset($invoice)) { + return $this->errorResponse(trans('errors.invoice_not_found')); + } + $invoice->validating_agent_id = $validating_agent_id; + + $datetime = $this->getCurrentTime($invoice->institution->country_id); + + try { + DB::beginTransaction(); + if ($action == 'ACCEPT') { + $invoice->state = InsuranceSubscriptionState::ACCEPTED; + $message = trans('messages.invoice_accepted'); + } else if ($action == 'REJECT') { + $invoice->state = InsuranceSubscriptionState::REJECTED; + $invoice->reason = $reason; + $message = trans('messages.invoice_rejected'); + } else { + + $agent = $invoice->institution; + $network_id = $agent->network_id; + $hyper = AgentPlus::where('network_id', $network_id)->where('category', 'hyper')->first(); + $nhConfig = NhNetworksConfig::where('network_id', $network_id)->first(); + if (!isset($nhConfig)) { + return $this->errorResponse(trans('errors.nano_health_not_activated')); + } + + $invoice->state = InsuranceSubscriptionState::ACCEPTED_MODIFIED; + $invoice->reason = $reason; + $invoiceClone = $invoice->replicate(); + $invoiceClone->state = InsuranceSubscriptionState::ACCEPTED; + $invoiceClone->created_at = $invoiceClone->updated_at = $datetime; + $invoiceClone->push(); + + + $currency_code = $this->getNetworkCurrency($network_id); + + $totalInsurerAmount = 0; + $totalInsuredAmount = 0; + $sheetsCloned = []; + + // Fusionner les ids des feuilles de soins existantes et celle modifiées + $sheets = $request->input('sheets'); + $sheetsIds = array_map(function ($r) { + return $r['sheet_id']; + }, $sheets); + + $invoiceSheetIds = $invoice->sheets()->pluck('id'); + foreach ($invoiceSheetIds as $id) { + if (!in_array($id, $sheetsIds)) { + $sheets[] = ['sheet_id' => $id]; + } + } + + foreach ($sheets as $s) { + $sheet = NhHealthCareSheet::findOrFail($s['sheet_id']); + $parts = $this->getConfigInsuranceParts($nhConfig, $sheet->care_condition); + + $sheetClone = $sheet->replicate(); + $sheetClone->health_care_sheet_id .= '/AM'; + $sheetClone->invoice_id = $invoiceClone->id; + $sheetClone->created_at = $sheetClone->updated_at = $datetime; + $sheetClone->push(); + + + $performances = $s['prestations'] ?? []; + $exams = $s['exams'] ?? []; + $prescriptions = $s['prescriptions'] ?? []; + + $performancesIds = array_map(function ($r) { + return $r['id']; + }, $performances); + + $prescriptionsIds = array_map(function ($r) { + return $r['id']; + }, $prescriptions); + + $examsIds = array_map(function ($r) { + return $r['id']; + }, $exams); + + + #Clone relations + $sheet->setRelations([]); + $sheet->load('performances', 'prescriptions', 'exams'); + foreach ($sheet->getRelations() as $relation => $items) { + foreach ($items as $i) { + $item = $i->replicate(); + + if ($sheetClone->type == HealthCareSheetType::CONSULTATION) { + if ($relation == 'performances') { + if (in_array($i->id, $performancesIds)) { + $itemIndex = array_search($i->id, $performancesIds); + $delete = $performances[$itemIndex]['to_delete'] ?? false; + Log::error(json_encode([$i->id, $itemIndex, $delete])); + if ($delete) { + continue; + } + $fees = !empty($performances[$itemIndex]['home_visit_fees']) ? $performances[$itemIndex]['home_visit_fees'] : 0; + $item->amount = $performances[$itemIndex]['amount']; + $item->home_visit_fees = $fees != 0 ? $fees : null; + $item->moderator_ticket = $parts->insured_part * ($item->amount + $fees); + $item->insurance_amount = $parts->insurer_part * ($item->amount + $fees); + } + } + + } + + + if ($relation == 'prescriptions') { + if (in_array($i->id, $prescriptionsIds)) { + $itemIndex = array_search($i->id, $prescriptionsIds); + $delete = $prescriptions[$itemIndex]['to_delete'] ?? false; + if ($delete) { + continue; + } + + if ($sheetClone->type == HealthCareSheetType::CONSULTATION) { + $item->dosage = $prescriptions[$itemIndex]['dosage']; + $item->quantity = $prescriptions[$itemIndex]['quantity']; + } else { + $item->unit_price = $prescriptions[$itemIndex]['unit_price']; + $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); + } + } + } + + if ($relation == 'exams') { + if (in_array($i->id, $examsIds)) { + $itemIndex = array_search($i->id, $examsIds); + $delete = $exams[$itemIndex]['to_delete'] ?? false; + if ($delete) { + continue; + } + + if ($sheetClone->type == HealthCareSheetType::CONSULTATION) { + $item->description = $exams[$itemIndex]['description']; + $item->quantity = $exams[$itemIndex]['quantity']; + } else { + $item->unit_price = $exams[$itemIndex]['unit_price']; + $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); + } + } + + } + + unset($item->laravel_through_key); + $item->created_at = $item->updated_at = $datetime; + $item->push(); + + if ($relation == 'performances') { + NhHealthCareSheetsPerformance::create([ + 'sheet_id' => $sheetClone->id, + 'performance_id' => $item->id, + 'created_at' => $datetime, 'updated_at' => $datetime, + ]); + } + + if ($relation == 'prescriptions') { + NhHealthCareSheetsPrescription::create([ + 'sheet_id' => $sheetClone->id, + 'prescription_id' => $item->id, + 'created_at' => $datetime, 'updated_at' => $datetime, + ]); + } + + if ($relation == 'exams') { + NhHealthCareSheetsExam::create([ + 'sheet_id' => $sheetClone->id, + 'exam_id' => $item->id, + 'created_at' => $datetime, 'updated_at' => $datetime, + ]); + } + } + } + + // Calculer les parts de l'assurance et l'assuré pour cette feuille de soins + $this->calculateInsuranceAmounts($sheetClone); + + // Retirer la couverture d'assurance précedement octroyée + $beneficiary = $sheetClone->beneficiary; + if ($beneficiary) { + $beneficiary->insurance_coverage_amount -= $sheet->insurance_amount; + $beneficiary->save(); + } else { + $sheetClone->insurance->insurance_coverage_amount -= $sheet->insurance_amount; + $sheetClone->insurance->save(); + } + + // Verification de la limite de couverture + $this->verifyInsuranceCoverageAmount($nhConfig, $sheetClone->insurance, $sheetClone, $beneficiary ?? null, $currency_code); + // Mettre à jour la couverture d'assurance de l'assuré + $this->updateInsuranceCoverageAmount($sheetClone, $sheetClone->insurance, $datetime, $beneficiary ?? null); + + + $totalInsuredAmount += $sheetClone->insured_amount; + $totalInsurerAmount += $sheetClone->insurance_amount; + $sheetClone->date = $sheetClone->created_at->format('d/m/Y'); + $sheetsCloned[] = $sheetClone; + } + + $directoryName = '/invoices-docs/'; + $filename = $invoiceClone->period_start_at->format('dmY') . '_' . $invoiceClone->period_end_at->format('dmY') . '_' . $agent->code_membre . '_AM_' . time() . '.pdf'; + + + $invoiceClone->invoice_id .= '/AM'; + $invoiceClone->reason = null; + $invoiceClone->old_invoice_id = $invoice->id; + $invoiceClone->amount = $totalInsuredAmount + $totalInsurerAmount; + $invoiceClone->insured_amount = $totalInsuredAmount; + $invoiceClone->insurer_amount = $totalInsurerAmount; + $invoiceClone->file_url = config('services.app_url') . $directoryName . $filename; + $invoiceClone->save(); + + // Generer le PDF de la nouvelle facture + + $invoiceClone->amount = $this->toMoneyWithCurrencyCode($invoiceClone->amount, $currency_code); + $invoiceClone->insured_amount = $this->toMoneyWithCurrencyCode($invoiceClone->insured_amount, $currency_code); + $invoiceClone->insurer_amount = $this->toMoneyWithCurrencyCode($invoiceClone->insurer_amount, $currency_code); + $invoiceClone->sheets = $sheetsCloned; + $invoiceClone->agent = $agent; + $invoiceClone->hyper = $hyper; + $invoiceClone->period = $invoiceClone->period_start_at->format('d/m/Y') . ' ' . trans('messages.to') . ' ' . $invoiceClone->period_end_at->format('d/m/Y'); + + $title = $agent->lastname . ' - ' . trans('messages.invoice') . ' ' . $invoice->invoice_id; + $message = __('messages.generated_invoice_mail', ['agent' => $agent->lastname, 'period' => $invoice->period]); + + $file = PDF::loadView('emails.invoice', $invoiceClone->toArray())->setPaper('a4', 'landscape')->setWarnings(false)->save(public_path($directoryName . $filename)); + + $message = trans('messages.invoice_accepted_updated'); + } + $invoice->updated_at = $datetime; + $invoice->save(); + DB::commit(); + return $this->successResponse($message); + + } catch (Throwable $e) { + Log::error($e->getMessage() . '\n' . $e->getTraceAsString()); + DB::rollBack(); + return $this->errorResponse(trans('errors.unexpected_error'), 500); + } + } } diff --git a/app/InsuranceSubscriptionState.php b/app/InsuranceSubscriptionState.php index ccbf3c5..14a583c 100644 --- a/app/InsuranceSubscriptionState.php +++ b/app/InsuranceSubscriptionState.php @@ -9,4 +9,6 @@ abstract class InsuranceSubscriptionState const ACCEPTED = 'ACCEPTED'; const REJECTED = 'REJECTED'; const INVOICE_ISSUED = 'INVOICE_ISSUED'; + const ACCEPTED_MODIFIED = 'ACCEPTED_MODIFIED'; + } diff --git a/app/Models/NhInsurance.php b/app/Models/NhInsurance.php index a696551..383adfa 100644 --- a/app/Models/NhInsurance.php +++ b/app/Models/NhInsurance.php @@ -16,7 +16,7 @@ use Illuminate\Database\Eloquent\Model; * @property int $network_id * @property int $user_id * @property string $insured_id - * @property int $number_of_months + * @property int $months_grid_id * @property float $bonus_amount * @property int $number_of_beneficiaries * @property float $total_bonus_amount @@ -42,7 +42,7 @@ class NhInsurance extends Model 'network_id', 'user_id', 'insured_id', - 'number_of_months', + 'months_grid_id', 'total_bonus_amount', 'insurance_coverage_amount', 'number_of_beneficiaries', @@ -62,6 +62,11 @@ class NhInsurance extends Model return $this->belongsTo(User::class, 'user_id'); } + public function monthsGrid() + { + return $this->belongsTo(NhMonthsPricesGrid::class, 'months_grid_id'); + } + public function beneficiaries() { return $this->hasManyThrough(NhHavingRight::class, NhInsurancesHavingRight::class, diff --git a/app/Models/NhInsurancesSubscription.php b/app/Models/NhInsurancesSubscription.php index 2ffb9bc..b9e1c2b 100644 --- a/app/Models/NhInsurancesSubscription.php +++ b/app/Models/NhInsurancesSubscription.php @@ -16,7 +16,7 @@ use Illuminate\Database\Eloquent\Model; * @property string $insurance_subscription_id * @property int $network_id * @property int $user_id - * @property int $number_of_months + * @property int $months_grid_id * @property float $bonus_amount * @property int $number_of_beneficiaries * @property float $total_bonus_amount @@ -35,7 +35,7 @@ class NhInsurancesSubscription extends Model 'insurance_subscription_id', 'network_id', 'user_id', - 'number_of_months', + 'months_grid_id', 'total_bonus_amount', 'number_of_beneficiaries', 'bonus_amount', @@ -53,6 +53,11 @@ class NhInsurancesSubscription extends Model return $this->belongsTo(User::class, 'user_id'); } + public function monthsGrid() + { + return $this->belongsTo(NhMonthsPricesGrid::class, 'months_grid_id'); + } + public function beneficiaries() { return $this->hasManyThrough(NhHavingRight::class, NhInsurancesHavingRight::class, diff --git a/app/Models/NhInvoice.php b/app/Models/NhInvoice.php index c674c93..563bb99 100644 --- a/app/Models/NhInvoice.php +++ b/app/Models/NhInvoice.php @@ -51,4 +51,14 @@ class NhInvoice extends Model 'created_at', 'updated_at' ]; + + public function institution() + { + return $this->belongsTo(AgentPlus::class, 'network_agent_id', 'network_agent_id'); + } + + public function sheets() + { + return $this->hasMany(NhHealthCareSheet::class, 'invoice_id'); + } } diff --git a/app/Models/NhPricesGrid.php b/app/Models/NhPricesGrid.php deleted file mode 100644 index 7bd573b..0000000 --- a/app/Models/NhPricesGrid.php +++ /dev/null @@ -1,50 +0,0 @@ - 'int', - 'nh_network_config_id' => 'int', - 'min_age' => 'float', - 'max_age' => 'float', - 'markup_percentage' => 'float', - 'min_amount' => 'float', - 'number_of_months' => 'float' - ]; - - protected $fillable = [ - 'nh_network_config_id', - 'min_age', - 'max_age', - 'markup_percentage', - 'min_amount', - 'number_of_months' - ]; -} diff --git a/app/Traits/Helper.php b/app/Traits/Helper.php index 272d406..54ade10 100644 --- a/app/Traits/Helper.php +++ b/app/Traits/Helper.php @@ -37,6 +37,16 @@ use stdClass; trait Helper { + public function addDaysToDateTime($datetime, $days) + { + return DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $days . 'days'); + } + + public function addMonthsToDateTime($datetime, $months) + { + return DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $months . 'months'); + } + public function getNetworkCurrency($networkId) { $currency = collect(DB::select('SELECT cu.code FROM networks n INNER JOIN countries c ON c.id = n.country_id INNER JOIN currencies cu ON cu.id = c.idCurrency @@ -119,7 +129,7 @@ trait Helper }); foreach ($levels as $level) { - $bonus += (100 + $level->markup_percentage) * $monthPrice->min_amount / 100; + $bonus += round(((100 + $level->markup_percentage) * $monthPrice->min_amount / 100)); } } else { $bonus = $monthPrice->min_amount; @@ -251,4 +261,96 @@ trait Helper $sheet->insured_amount = $insuredAmount; $sheet->save(); } + + public function generateSheetID(): string + { + do { + $code = generateTransactionCode(); + $codeCorrect = NhHealthCareSheet::where('health_care_sheet_id', $code)->count() < 0; + } while ($codeCorrect); + return $code; + } + + public function getConfigInsuranceParts(NhNetworksConfig $nhConfig, $care_condition): stdClass + { + $insuredPart = 0; + $insurerPart = 0; + switch ($care_condition) { + case 'CURRENT_AFFECTION': + $insurerPart = $nhConfig->current_affection_percentage_insurer / 100; + $insuredPart = $nhConfig->current_affection_percentage_insured / 100; + break; + case 'LONG_TERM_AFFECTION': + $insurerPart = $nhConfig->long_term_affection_percentage_insurer / 100; + $insuredPart = $nhConfig->long_term_affection_percentage_insured / 100; + break; + case 'EXONERATION': + $insurerPart = $nhConfig->exoneration_percentage_insurer / 100; + $insuredPart = $nhConfig->exoneration_percentage_insured / 100; + break; + } + $result = new stdClass(); + $result->insured_part = $insuredPart; + $result->insurer_part = $insurerPart; + return $result; + } + + + /** + * @throws AppException + */ + // Verification de la limite de couverture + public function verifyInsuranceCoverageAmount(NhNetworksConfig $nhConfig, NhInsurance $insurance, NhHealthCareSheet $sheet, NhHavingRight $beneficiary = null, + $currency_code = 'XAF', $currentInsuranceAmount = 0) // Current Insurance Amount en cas de mise à jour de la feuille de soins pour ne pas prendre en compte la couverture deja affecté + { + $insurance_coverage_amount = isset($beneficiary) ? $beneficiary->insurance_coverage_amount : $insurance->insurance_coverage_amount; + $insurance_amount = $sheet->insurance_amount; + $monthPrice = $insurance->monthsGrid; + + if (!isset($monthPrice)) + throw new AppException(trans('errors.month_price_grid_not_found')); + + if (!$nhConfig->family_coverage_sharing) { + $total_insurance_amount = $insurance_coverage_amount + $insurance_amount - $currentInsuranceAmount; + if ($total_insurance_amount > $monthPrice->max_insurance_coverage_amount) { + DB::rollBack(); + throw new AppException(trans('errors.insurance_coverage_amount_exceeded', [ + 'consumption' => $this->toMoneyWithCurrencyCode($insurance_coverage_amount, $currency_code), + 'remaining' => $this->toMoneyWithCurrencyCode($monthPrice->max_insurance_coverage_amount - $insurance_coverage_amount, $currency_code), + ])); + } + } else { + // Montant de l'assurance deja consomé à date + $family_consumed_amount = $insurance->insurance_coverage_amount; + foreach ($insurance->beneficiaries as $b) { + $family_consumed_amount += $b->insurance_coverage_amount; + } + $total_insurance_amount = $family_consumed_amount + $insurance_amount - $currentInsuranceAmount; + $family_limit_amount = $monthPrice->max_insurance_coverage_amount * ($insurance->number_of_beneficiaries + 1); + if ($total_insurance_amount > $family_limit_amount) { + DB::rollBack(); + throw new AppException(trans('errors.insurance_coverage_amount_exceeded', [ + 'consumption' => $this->toMoneyWithCurrencyCode($family_consumed_amount, $currency_code), + 'remaining' => $this->toMoneyWithCurrencyCode($family_limit_amount - $family_consumed_amount, $currency_code), + ])); + } + } + } + + + public function updateInsuranceCoverageAmount(NhHealthCareSheet $sheet, NhInsurance $insurance, $datetime, + NhHavingRight $beneficiary = null, $currentInsuranceAmount = 0): void + { // Current Insurance Amount en cas de mise à jour de la feuille de soins pour ne pas prendre en compte la couverture deja affecté) + $sheet->insurance_consumed_at = $datetime; + if (!empty($beneficiary)) { + $beneficiary->insurance_coverage_amount += ($sheet->insurance_amount - $currentInsuranceAmount); + $beneficiary->save(); + } else { + $insurance->insurance_coverage_amount += ($sheet->insurance_amount - $currentInsuranceAmount); + $insurance->save(); + } + $sheet->save(); + } + + } diff --git a/database/migrations/2021_11_10_155041_update_nh_infos_insurances_subscriptions_view.php b/database/migrations/2021_11_10_155041_update_nh_infos_insurances_subscriptions_view.php index 7fb081f..749946f 100644 --- a/database/migrations/2021_11_10_155041_update_nh_infos_insurances_subscriptions_view.php +++ b/database/migrations/2021_11_10_155041_update_nh_infos_insurances_subscriptions_view.php @@ -2,6 +2,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class UpdateNhInfosInsurancesSubscriptionsView extends Migration diff --git a/database/migrations/2021_11_11_205552_update_nh_infos_insurances_view.php b/database/migrations/2021_11_11_205552_update_nh_infos_insurances_view.php index d7f6da8..7461c66 100644 --- a/database/migrations/2021_11_11_205552_update_nh_infos_insurances_view.php +++ b/database/migrations/2021_11_11_205552_update_nh_infos_insurances_view.php @@ -2,6 +2,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class UpdateNhInfosInsurancesView extends Migration diff --git a/database/migrations/2022_03_10_150702_add_new_role_to_nh_validating_agents.php b/database/migrations/2022_03_10_150702_add_new_role_to_nh_validating_agents.php new file mode 100644 index 0000000..8ee1bc6 --- /dev/null +++ b/database/migrations/2022_03_10_150702_add_new_role_to_nh_validating_agents.php @@ -0,0 +1,34 @@ +enum('state', ['UNDER_VALIDATION', 'ACCEPTED', 'REJECTED', 'ACCEPTED_MODIFIED'])->default('UNDER_VALIDATION') + ->after('period_end_at'); + $table->text('reason')->nullable()->after('state')->comment("Raison de rejet ou de modification"); + $table->integer('validating_agent_id')->nullable()->after('reason'); + $table->integer('old_invoice_id')->nullable()->after('validating_agent_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_invoices', function (Blueprint $table) { + $table->dropColumn(['state', 'reason', 'old_invoice_id', 'validating_agent_id']); + }); + } +} diff --git a/database/migrations/2022_03_15_070335_update_nh_infos_invoices_view.php b/database/migrations/2022_03_15_070335_update_nh_infos_invoices_view.php new file mode 100644 index 0000000..075ecef --- /dev/null +++ b/database/migrations/2022_03_15_070335_update_nh_infos_invoices_view.php @@ -0,0 +1,38 @@ +enum('password_validation', ['MIN', 'MAX'])->default('MAX')->after('family_coverage_sharing') + ->comment('Paramétre de la validation par mot de passe chez les assurés et prestataires pour toute action'); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_networks_configs', function (Blueprint $table) { + $table->dropColumn(['password_validation']); + }); + } +} diff --git a/database/migrations/2022_03_25_075235_add_file_url_to_nh_health_care_sheets.php b/database/migrations/2022_03_25_075235_add_file_url_to_nh_health_care_sheets.php new file mode 100644 index 0000000..182d935 --- /dev/null +++ b/database/migrations/2022_03_25_075235_add_file_url_to_nh_health_care_sheets.php @@ -0,0 +1,32 @@ +string('file_url')->nullable()->after('insurance_consumed_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_health_care_sheets', function (Blueprint $table) { + $table->dropColumn(['file_url']); + }); + } +} diff --git a/database/migrations/2022_03_25_115643_add_waiting_period_payment_period_and_payment_duration_to_nh_months_prices_grid.php b/database/migrations/2022_03_25_115643_add_waiting_period_payment_period_and_payment_duration_to_nh_months_prices_grid.php new file mode 100644 index 0000000..1dfc03b --- /dev/null +++ b/database/migrations/2022_03_25_115643_add_waiting_period_payment_period_and_payment_duration_to_nh_months_prices_grid.php @@ -0,0 +1,43 @@ +unsignedTinyInteger('waiting_period_days')->nullable()->after('max_insurance_coverage_amount') + ->comment('Delai de carence en jours'); + $table->enum('payment_period', ['ONE_TIME', 'DAILY', 'MONTHLY'])->default('ONE_TIME')->after('waiting_period_days') + ->comment('Periode de paiement'); + $table->unsignedTinyInteger('payment_duration_months')->nullable()->after('payment_period') + ->comment('Durée en moins du paiement'); + $table->unsignedTinyInteger('number_of_fractions')->default(1)->after('payment_duration_months') + ->comment('Nombre de fractions de paiement'); + + $table->unique(['nh_network_config_id', 'number_of_months', 'min_amount', 'max_insurance_coverage_amount', 'waiting_period_days', 'payment_period', + 'payment_duration_months'], 'uq_management_rule'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_months_prices_grid', function (Blueprint $table) { + $table->dropColumn(['waiting_period_days', 'payment_period', 'payment_duration_months', 'number_of_fractions']); + $table->dropUnique('uq_management_rule'); + }); + } +} diff --git a/database/migrations/2022_03_25_150821_update_markup_percentage_to_nh_years_prices_grid.php b/database/migrations/2022_03_25_150821_update_markup_percentage_to_nh_years_prices_grid.php new file mode 100644 index 0000000..3179f32 --- /dev/null +++ b/database/migrations/2022_03_25_150821_update_markup_percentage_to_nh_years_prices_grid.php @@ -0,0 +1,35 @@ +decimal('markup_percentage', 15, 12)->default(0) + ->comment('Pourcentage de majoration')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_years_prices_grid', function (Blueprint $table) { + $table->decimal('markup_percentage', 3, 0)->default(0) + ->comment('Pourcentage de majoration')->change(); + + }); + } +} diff --git a/database/migrations/2022_03_28_140904_add_months_grid_id_to_nh_insurances_and_nh_insurances_subscriptions_tables.php b/database/migrations/2022_03_28_140904_add_months_grid_id_to_nh_insurances_and_nh_insurances_subscriptions_tables.php new file mode 100644 index 0000000..a55e5e0 --- /dev/null +++ b/database/migrations/2022_03_28_140904_add_months_grid_id_to_nh_insurances_and_nh_insurances_subscriptions_tables.php @@ -0,0 +1,44 @@ +integer('months_grid_id')->after('insured_id'); + $table->dropColumn(['number_of_months']); + }); + + Schema::table('nh_insurances_subscriptions', function (Blueprint $table) { + $table->integer('months_grid_id')->after('user_id'); + $table->dropColumn(['number_of_months']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_insurances', function (Blueprint $table) { + $table->dropColumn(['months_grid_id']); + $table->decimal('number_of_months', 2, 0)->default(0)->after('insured_id'); + }); + + Schema::table('nh_insurances_subscriptions', function (Blueprint $table) { + $table->dropColumn(['months_grid_id']); + $table->decimal('number_of_months', 2, 0)->default(0)->after('user_id'); + }); + } +} diff --git a/database/migrations/2022_03_28_164749_update_nh_infos_insurances_view2.php b/database/migrations/2022_03_28_164749_update_nh_infos_insurances_view2.php new file mode 100644 index 0000000..b752985 --- /dev/null +++ b/database/migrations/2022_03_28_164749_update_nh_infos_insurances_view2.php @@ -0,0 +1,32 @@ + "An execution can only be made on examinations or medical prescriptions.", "sheet_not_accepted" => "This treatment sheet has not been accepted", - "sheet_not_comes_from_consultation" => "This health care sheet is not from a consultation" + "sheet_not_comes_from_consultation" => "This health care sheet is not from a consultation", + 'invoice_not_found' => "The invoice does not exist", + 'network_not_found' => "The network does not exist" ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 1ed1eb4..bb73457 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -119,7 +119,7 @@ A new consultation or prescription has been made with your insurance. 'total_amount' => 'Total Amount', 'insured_part' => 'Insured Part', 'total_insured_part' => 'Total Insured Part', - 'insurance_part' => 'Insurance_part', + 'insurance_part' => 'Insurance Part', 'total_insurance_part' => 'Total Insurance Part', 'to' => 'to', 'invoice' => 'Invoice', @@ -186,4 +186,7 @@ Your insurance has expired. - Number of beneficiaries : :number_of_beneficiaries - Number of months: :months ", + 'invoice_accepted' => "Invoice accepted", + 'invoice_rejected' => "Invoice rejected", + 'invoice_accepted_updated' => "Invoice accepted modified", ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index d3a1f3f..441e631 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -58,5 +58,7 @@ return [ Reste : :remaining", "execution_rule" => "Une exécution ne peut être faite que sur les examens ou sur les prescriptions médicales.", "sheet_not_accepted" => "Cette feuille de soins n'a pas été acceptée", - "sheet_not_comes_from_consultation" => "Cette feuille de soins ne provient pas d'une consultation" + "sheet_not_comes_from_consultation" => "Cette feuille de soins ne provient pas d'une consultation", + 'invoice_not_found' => "La facture n'existe pas", + 'network_not_found' => "Le réseau n'existe pas" ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index 9b69b28..b476727 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -203,4 +203,7 @@ Votre assurance est arrivée à échéance. - Nombre d'ayants droit : :number_of_beneficiaries - Nombre de mois : :months ", + 'invoice_accepted' => "Facture acceptée", + 'invoice_rejected' => "Facture refusée", + 'invoice_accepted_updated' => "Facture acceptée modifiée", ]; diff --git a/routes/web.php b/routes/web.php index 510c590..b5883b9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,6 +58,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route $router->put('health-care-sheets/{id}', 'HealthCareSheetController@updateHealthCareSheet'); $router->get('invoices', 'InvoiceController@getInvoices'); + $router->put('invoices/{id}', 'InvoiceController@treatInvoice'); $router->get('generate-invoice', 'InvoiceController@generateInvoice'); $router->get('authorizations-care-requests', 'AuthorizationCareRequestController@getAll');