Setup insurance waiting_days(delai de carence) and replace number_of_months to months_grid_id
This commit is contained in:
parent
aff5c3eaae
commit
72338c4c1f
|
@ -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) {
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,6 @@ abstract class InsuranceSubscriptionState
|
|||
const ACCEPTED = 'ACCEPTED';
|
||||
const REJECTED = 'REJECTED';
|
||||
const INVOICE_ISSUED = 'INVOICE_ISSUED';
|
||||
const ACCEPTED_MODIFIED = 'ACCEPTED_MODIFIED';
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class NhPricesGrid
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $nh_network_config_id
|
||||
* @property float $min_age
|
||||
* @property float $max_age
|
||||
* @property float $markup_percentage
|
||||
* @property float $min_amount
|
||||
* @property float $number_of_months
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $created_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class NhPricesGrid extends Model
|
||||
{
|
||||
protected $table = 'nh_prices_grid';
|
||||
public $incrementing = false;
|
||||
|
||||
protected $casts = [
|
||||
'id' => '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'
|
||||
];
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddNewRoleToNhValidatingAgents extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_validating_agents', function (Blueprint $table) {
|
||||
//
|
||||
DB::statement("alter table nh_validating_agents modify role enum ('DOCTOR', 'AGENT', 'CONTROLLER') default 'DOCTOR' not null;");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('nh_validating_agents', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddStateAndReasonToNhInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_invoices', function (Blueprint $table) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateNhInfosInvoicesView extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::statement("CREATE OR REPLACE VIEW nh_infos_invoices AS
|
||||
SELECT nhi.*,
|
||||
ag.lastname as institution_name,
|
||||
ag.code_membre as institution_code,
|
||||
ag.network_id as network_id,
|
||||
cc.currency_code
|
||||
FROM nh_invoices nhi
|
||||
INNER JOIN agent_plus ag ON ag.network_agent_id = nhi.network_agent_id
|
||||
INNER JOIN countries_currencies cc ON cc.id = ag.country_id
|
||||
ORDER BY nhi.created_at DESC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddPasswordValidationInNhNetworksConfigs extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_networks_configs', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('nh_networks_configs', 'password_validation')) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddFileUrlToNhHealthCareSheets extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_health_care_sheets', function (Blueprint $table) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddWaitingPeriodPaymentPeriodAndPaymentDurationToNhMonthsPricesGrid extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_months_prices_grid', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateMarkupPercentageToNhYearsPricesGrid extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_years_prices_grid', function (Blueprint $table) {
|
||||
$table->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();
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddMonthsGridIdToNhInsurancesAndNhInsurancesSubscriptionsTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_insurances', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateNhInfosInsurancesView2 extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::statement("CREATE OR REPLACE VIEW nh_infos_insurances AS
|
||||
SELECT nhi.* , nmpg.number_of_months, nmpg.payment_period , nmpg.payment_duration_months , u.lastname , u.phone , u.email , cc.currency_code FROM nh_insurances nhi
|
||||
JOIN nh_months_prices_grid nmpg on nhi.months_grid_id = nmpg.id
|
||||
JOIN users u ON nhi.user_id = u.id JOIN networks n on nhi.network_id = n.id JOIN countries_currencies cc on n.country_id = cc.id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateNhInfosInsurancesSubscriptionsView2 extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::statement("CREATE OR REPLACE VIEW nh_infos_insurances_subscriptions AS
|
||||
SELECT nhis.* , cc.currency_code , nmpg.number_of_months, nmpg.payment_period , nmpg.payment_duration_months , u.lastname , u.phone, u.email FROM nh_insurances_subscriptions nhis JOIN networks n ON nhis.network_id = n.id
|
||||
JOIN nh_months_prices_grid nmpg on nhis.months_grid_id = nmpg.id
|
||||
JOIN countries_currencies cc ON n.country_id = cc.id JOIN users u ON nhis.user_id = u.id;");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -58,5 +58,7 @@ return [
|
|||
Reste : :remaining",
|
||||
"execution_rule" => "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"
|
||||
];
|
||||
|
|
|
@ -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",
|
||||
];
|
||||
|
|
|
@ -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"
|
||||
];
|
||||
|
|
|
@ -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",
|
||||
];
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue