Add NhInsuranceInvoice for partial payment
This commit is contained in:
parent
72338c4c1f
commit
04b815b767
|
@ -0,0 +1,297 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Events\InsuranceEvent;
|
||||||
|
use App\InsuranceAction;
|
||||||
|
use App\InsuranceInvoiceState;
|
||||||
|
use App\InsuranceState;
|
||||||
|
use App\InsuranceSubscriptionAffiliation;
|
||||||
|
use App\InsuranceSubscriptionState;
|
||||||
|
use App\Models\AgentPlus;
|
||||||
|
use App\Models\CountriesCurrency;
|
||||||
|
use App\Models\Identification;
|
||||||
|
use App\Models\NhHavingRight;
|
||||||
|
use App\Models\NhInsurance;
|
||||||
|
use App\Models\NhInsurancesHavingRight;
|
||||||
|
use App\Models\NhInsurancesInvoice;
|
||||||
|
use App\Models\NhInsurancesPayment;
|
||||||
|
use App\Models\NhInsurancesSubscription;
|
||||||
|
use App\Models\NhInsurancesSubscriptionsHistory;
|
||||||
|
use App\Models\NhMonthsPricesGrid;
|
||||||
|
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;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class InsuranceInvoiceController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/insurances/invoices",
|
||||||
|
* summary="Afficher la liste des factures",
|
||||||
|
* tags={"Factures de l'assurance"},
|
||||||
|
* security={{"api_key":{}}},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="user_id",
|
||||||
|
* name="user_id",
|
||||||
|
* description="ID de l'utilisateur",
|
||||||
|
* in="query",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="integer",
|
||||||
|
* default=325
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="state",
|
||||||
|
* name="state",
|
||||||
|
* description="Etat de la facture",
|
||||||
|
* in="query",
|
||||||
|
* required=false,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* enum={"PAID","UNPAID","TO_PAID"}
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="page",
|
||||||
|
* name="page",
|
||||||
|
* description="Page",
|
||||||
|
* in="query",
|
||||||
|
* required=false,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="integer"
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="perPage",
|
||||||
|
* name="perPage",
|
||||||
|
* description="Pas de pagination",
|
||||||
|
* in="query",
|
||||||
|
* required=false,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="integer"
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="pagination",
|
||||||
|
* name="pagination",
|
||||||
|
* description="pagination",
|
||||||
|
* in="query",
|
||||||
|
* required=false,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="boolean",
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="OK",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* ref="#/components/schemas/ApiResponse",
|
||||||
|
* example = {
|
||||||
|
* "status" : 200,
|
||||||
|
* "response" : {{"id":1,"invoice_id":"SFSF6565656","insurance_id":5,"subscription_id":2,"amount":"495\u202f000 FCFA","payment_deadline":"2022-04-08 17:31:52","payment_reminder":"2022-04-05 17:31:52","state":"NON PAY\u00c9E",
|
||||||
|
* "reason":"ACTIVATION DE L'ASSURANCE","created_at":"2022-03-29T16:31:52.000000Z","updated_at":"2022-03-29T16:31:52.000000Z","insurance":{"id":5,"network_id":250,"user_id":349,"insured_id":"5DSTKZ7PQZX4",
|
||||||
|
* "months_grid_id":77,"bonus_amount":"150000.00","number_of_beneficiaries":2,"total_bonus_amount":"495000.00","insurance_coverage_amount":"0.00","start_at":null,"end_at":null,"state":"UNDER_ACTIVATION",
|
||||||
|
* "deadlines":1,"amount_last_payment":"495000.00","amount_per_split":"495000.00","paid_deadlines":0,"created_at":"2022-03-29T16:31:52.000000Z","updated_at":"2022-03-29T16:31:52.000000Z"},
|
||||||
|
* "subscription":{"id":2,"insurance_subscription_id":"CX36UNA2VVOP","network_id":250,"user_id":349,"months_grid_id":77,"bonus_amount":"150000.00","number_of_beneficiaries":2,"
|
||||||
|
* total_bonus_amount":"495000.00","state":"ACCEPTED","insurance_action":"ACTIVATION","created_at":"2021-11-10T16:52:32.000000Z","updated_at":"2022-03-29T17:31:52.000000Z","reason":null}}},
|
||||||
|
* "error":null
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function getInvoices(Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'user_id' => 'required|integer|exists:users,id',
|
||||||
|
'state' => 'nullable|in:PAID,UNPAID,TO_PAID',
|
||||||
|
'pagination' => 'nullable|boolean'
|
||||||
|
]);
|
||||||
|
$user_id = $request->input('user_id');
|
||||||
|
$user = User::findOrFail($user_id);
|
||||||
|
$currency_code = $user->network->country->currency_code;
|
||||||
|
$pagination = $request->input('pagination');
|
||||||
|
$state = $request->input('state');
|
||||||
|
$datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country);
|
||||||
|
|
||||||
|
$query = NhInsurancesInvoice::with(['insurance', 'subscription'])
|
||||||
|
->whereHas('insurance', function ($q) use ($user_id) {
|
||||||
|
return $q->where('user_id', $user_id);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!empty($state)) {
|
||||||
|
if ($state == 'TO_PAID') {
|
||||||
|
$query = $query->where('state', InsuranceInvoiceState::UNPAID)
|
||||||
|
->where('payment_deadline', '<', $datetime);
|
||||||
|
} else {
|
||||||
|
$query = $query->where('state', $state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pagination) {
|
||||||
|
$invoices = $query->paginate($request->input('perPage', 10));
|
||||||
|
} else {
|
||||||
|
$invoices = $query->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
$array = $pagination ? $invoices->items() : $invoices;
|
||||||
|
foreach ($array as $invoice) {
|
||||||
|
$invoice->state = trans('states.' . $invoice->state);
|
||||||
|
$invoice->reason = trans('states.' . $invoice->reason);
|
||||||
|
$invoice->amount = $this->toMoneyWithCurrencyCode($invoice->amount, $currency_code);
|
||||||
|
}
|
||||||
|
return $this->successResponse($invoices);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Put(
|
||||||
|
* path="/insurances/invoices/{id}/pay",
|
||||||
|
* summary="Payer la facture de l'assurance",
|
||||||
|
* tags={"Factures de l'assurance"},
|
||||||
|
* security={{"api_key":{}}},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* parameter="id",
|
||||||
|
* name="id",
|
||||||
|
* description="ID de la facture",
|
||||||
|
* in="path",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="integer",
|
||||||
|
* default=12
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\RequestBody(
|
||||||
|
* description="Corps de la requete",
|
||||||
|
* required=true,
|
||||||
|
* @OA\MediaType(
|
||||||
|
* mediaType="application/json",
|
||||||
|
* @OA\Schema(
|
||||||
|
* @OA\Property(property="password",
|
||||||
|
* type="string",
|
||||||
|
* example = "addfdf21",
|
||||||
|
* description="Mot de passe de l'utilisateur"
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* example = {"password":"adbc1215448"}
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="OK",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* ref="#/components/schemas/ApiResponse",
|
||||||
|
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* @throws \App\Exceptions\AppException
|
||||||
|
*/
|
||||||
|
public function payInvoice($id, Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'password' => 'required|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$invoice = NhInsurancesInvoice::findOrFail($id);
|
||||||
|
$datetime = $this->getCurrentTimeByCountryCode($invoice->insurance->network->country->code_country);
|
||||||
|
|
||||||
|
if ($invoice->state == InsuranceInvoiceState::PAID) {
|
||||||
|
return $this->errorResponse(trans('errors.invoice_already_paid'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($invoice->payment_deadline < $datetime) {
|
||||||
|
return $this->errorResponse(trans('errors.payment_deadline_reached'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $invoice->insurance->user;
|
||||||
|
$this->userCredentialsVerification($user, $request->input('password'));
|
||||||
|
|
||||||
|
$currency = $this->getNetworkCurrency($invoice->insurance->network_id);
|
||||||
|
|
||||||
|
$amountToPaid = $invoice->amount;
|
||||||
|
|
||||||
|
if ($user->wallet->balance < $amountToPaid) {
|
||||||
|
$amount = $amountToPaid - $user->wallet->balance;
|
||||||
|
return $this->errorResponse(trans('errors.insufficient_balance', ['amount' => $this->toMoneyWithCurrencyCode($amount, $currency)]));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$hyperviseur = AgentPlus::where('category', 'hyper')->where('network_id', $invoice->insurance->network_id)->firstOrFail();
|
||||||
|
$walletHyperviseur = Wallet::where('id_networkAgent', $hyperviseur->network_agent_id)->firstOrFail();
|
||||||
|
$walletHyperviseur->balance_princ += $amountToPaid;
|
||||||
|
$walletHyperviseur->save();
|
||||||
|
|
||||||
|
$user->balance_nano_health += $amountToPaid;
|
||||||
|
$user->wallet->balance -= $amountToPaid;
|
||||||
|
$user->wallet->save();
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$invoice->update(['state' => InsuranceInvoiceState::PAID, 'updated_at' => $datetime]);
|
||||||
|
$invoice->insurance->paid_deadlines++;
|
||||||
|
$isPartialPayment = true;
|
||||||
|
if ($invoice->insurance->paid_deadlines == $invoice->insurance->deadlines) {
|
||||||
|
$invoice->insurance->state = InsuranceState::PAID;
|
||||||
|
$isPartialPayment = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($invoice->insurance->state == InsuranceState::PAID) {
|
||||||
|
|
||||||
|
if ($invoice->reason == InsuranceAction::ADDITION_OF_BENEFICIARY) {
|
||||||
|
$invoice->insurance->bonus_amount = $invoice->subscription->bonus_amount;
|
||||||
|
$invoice->insurance->total_bonus_amount += $invoice->subscription->total_bonus_amount;
|
||||||
|
$invoice->insurance->number_of_beneficiaries += $invoice->subscription->number_of_beneficiaries;
|
||||||
|
$invoice->insurance->updated_at = $datetime;
|
||||||
|
$invoice->insurance->save();
|
||||||
|
|
||||||
|
foreach ($invoice->subscription->beneficiaries as $b) {
|
||||||
|
NhInsurancesHavingRight::create([
|
||||||
|
'insurance_id' => $invoice->insurance->id,
|
||||||
|
'having_right_id' => $b->id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($invoice->reason, [InsuranceAction::ACTIVATION, InsuranceAction::RENEWAL])) {
|
||||||
|
if (empty($invoice->insurance->monthsGrid->waiting_period_days)) {
|
||||||
|
$start_at = $datetime;
|
||||||
|
} else {
|
||||||
|
$start_at = $this->addDaysToDateTime($datetime, $invoice->insurance->monthsGrid->waiting_period_days);
|
||||||
|
}
|
||||||
|
$end_at = $this->addMonthsToDateTime($start_at->format('Y-m-d H:i:s'), $invoice->insurance->monthsGrid->number_of_months);
|
||||||
|
$invoice->insurance->start_at = $start_at;
|
||||||
|
$invoice->insurance->end_at = $end_at;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoice->insurance->save();
|
||||||
|
|
||||||
|
Event::dispatch(new InsuranceEvent($invoice->insurance, $isPartialPayment ? trans('messages.insurance_partially_paid') : trans('messages.insurance_subscription_paid'),
|
||||||
|
trans('messages.insurance_paid_mail', ['name' => $invoice->insurance->user->lastname, 'insured_id' => $invoice->insurance->insured_id,
|
||||||
|
'bonus_amount' => $this->toMoneyWithCurrencyCode($invoice->insurance->bonus_amount, $currency), 'total_bonus_amount' => $this->toMoneyWithCurrencyCode($invoice->insurance->total_bonus_amount, $currency), 'number_of_beneficiaries' => $invoice->insurance->number_of_beneficiaries,
|
||||||
|
'gender' => trans('states.' . $invoice->insurance->user->identification->gender), 'insurance_name' => $invoice->insurance->network->name, 'months' => $invoice->insurance->monthsGrid->number_of_months, 'invoice_id' => $invoice->invoice_id,
|
||||||
|
'amount' => $this->toMoneyWithCurrencyCode($invoice->amount, $currency), 'paid_deadlines' => $invoice->insurance->paid_deadlines, 'remains_deadlines' => $invoice->insurance->deadlines - $invoice->insurance->paid_deadlines,
|
||||||
|
'reason' => trans('states.' . $invoice->reason), 'title' => $isPartialPayment ? trans('messages.insurance_partially_paid_title') : trans('messages.insurance_fully_paid_title')])));
|
||||||
|
DB::commit();
|
||||||
|
return $this->successResponse(trans('messages.insurance_subscription_paid'));
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||||
|
DB::rollBack();
|
||||||
|
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Events\InsuranceEvent;
|
use App\Events\InsuranceEvent;
|
||||||
use App\InsuranceAction;
|
use App\InsuranceAction;
|
||||||
|
use App\InsuranceInvoiceState;
|
||||||
use App\InsuranceState;
|
use App\InsuranceState;
|
||||||
use App\InsuranceSubscriptionAffiliation;
|
use App\InsuranceSubscriptionAffiliation;
|
||||||
use App\InsuranceSubscriptionState;
|
use App\InsuranceSubscriptionState;
|
||||||
|
@ -13,6 +14,7 @@ use App\Models\Identification;
|
||||||
use App\Models\NhHavingRight;
|
use App\Models\NhHavingRight;
|
||||||
use App\Models\NhInsurance;
|
use App\Models\NhInsurance;
|
||||||
use App\Models\NhInsurancesHavingRight;
|
use App\Models\NhInsurancesHavingRight;
|
||||||
|
use App\Models\NhInsurancesInvoice;
|
||||||
use App\Models\NhInsurancesPayment;
|
use App\Models\NhInsurancesPayment;
|
||||||
use App\Models\NhInsurancesSubscription;
|
use App\Models\NhInsurancesSubscription;
|
||||||
use App\Models\NhInsurancesSubscriptionsHistory;
|
use App\Models\NhInsurancesSubscriptionsHistory;
|
||||||
|
@ -438,6 +440,73 @@ class InsuranceSubscriptionController extends Controller
|
||||||
$notification = trans('messages.insurance_stop_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id]);
|
$notification = trans('messages.insurance_stop_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id]);
|
||||||
$mail = trans('messages.insurance_stop_accepted_mail', $mail_data);
|
$mail = trans('messages.insurance_stop_accepted_mail', $mail_data);
|
||||||
} else {
|
} else {
|
||||||
|
$amount_per_split = round($subscription->total_bonus_amount / $subscription->monthsGrid->number_of_fractions);
|
||||||
|
$amount_last_payment = $subscription->total_bonus_amount - ($amount_per_split * ($subscription->monthsGrid->number_of_fractions - 1));
|
||||||
|
|
||||||
|
if ($subscription->insurance_action == InsuranceAction::ACTIVATION) {
|
||||||
|
$insuredId = $this->generateInsuredID();
|
||||||
|
$insurance = NhInsurance::create([
|
||||||
|
'network_id' => $subscription->network_id,
|
||||||
|
'user_id' => $subscription->user_id,
|
||||||
|
'insured_id' => $insuredId,
|
||||||
|
'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::UNDER_ACTIVATION,
|
||||||
|
'deadlines' => $subscription->monthsGrid->number_of_fractions,
|
||||||
|
'paid_deadlines' => 0,
|
||||||
|
'amount_per_split' => $amount_per_split,
|
||||||
|
'amount_last_payment' => $amount_last_payment
|
||||||
|
]);
|
||||||
|
foreach ($subscription->beneficiaries as $b) {
|
||||||
|
NhInsurancesHavingRight::create([
|
||||||
|
'insurance_id' => $insurance->id,
|
||||||
|
'having_right_id' => $b->id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
// Generer la 1ere facture
|
||||||
|
NhInsurancesInvoice::create([
|
||||||
|
'invoice_id' => $this->generateInsuranceInvoiceID(),
|
||||||
|
'insurance_id' => $insurance->id,
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
|
'amount' => $amount_per_split,
|
||||||
|
'payment_deadline' => $this->addDaysToDateTime($datetime, 10), // 1 semaine + 3 jours
|
||||||
|
'payment_reminder' => $this->addDaysToDateTime($datetime, 7),
|
||||||
|
'state' => InsuranceInvoiceState::UNPAID,
|
||||||
|
'reason' => $subscription->insurance_action
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subscription->insurance_action == InsuranceAction::ADDITION_OF_BENEFICIARY) {
|
||||||
|
$insurance = NhInsurance::where('user_id', $subscription->user_id)->where('network_id', $subscription->network_id)->where('state', InsuranceState::PAID)->first();
|
||||||
|
if (!isset($insurance)) {
|
||||||
|
DB::rollBack();
|
||||||
|
return $this->errorResponse(trans('errors.not_insured'), 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insurance->update([
|
||||||
|
'state' => InsuranceState::UNDER_ADDING_BENEFICIARY,
|
||||||
|
'deadlines' => $subscription->monthsGrid->number_of_fractions,
|
||||||
|
'paid_deadlines' => 0,
|
||||||
|
'amount_per_split' => $amount_per_split,
|
||||||
|
'amount_last_payment' => $amount_last_payment,
|
||||||
|
'updated_at' => $datetime,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Generer la 1ere facture
|
||||||
|
NhInsurancesInvoice::create([
|
||||||
|
'invoice_id' => $this->generateInsuranceInvoiceID(),
|
||||||
|
'insurance_id' => $insurance->id,
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
|
'amount' => $amount_per_split,
|
||||||
|
'payment_deadline' => $this->addDaysToDateTime($datetime, 10), // 1 semaine + 3 jours
|
||||||
|
'payment_reminder' => $this->addDaysToDateTime($datetime, 7),
|
||||||
|
'state' => InsuranceInvoiceState::UNPAID,
|
||||||
|
'reason' => $subscription->insurance_action
|
||||||
|
]);
|
||||||
|
}
|
||||||
$message = trans('messages.insurance_subscription_accepted');
|
$message = trans('messages.insurance_subscription_accepted');
|
||||||
$notification = trans('messages.insurance_subscription_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id]);
|
$notification = trans('messages.insurance_subscription_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id]);
|
||||||
$mail = trans('messages.insurance_subscription_accepted_mail', $mail_data);
|
$mail = trans('messages.insurance_subscription_accepted_mail', $mail_data);
|
||||||
|
@ -449,7 +518,6 @@ class InsuranceSubscriptionController extends Controller
|
||||||
'insurance_subscription_state' => $subscription->state,
|
'insurance_subscription_state' => $subscription->state,
|
||||||
'agent_id' => $request->input('agent_id'),
|
'agent_id' => $request->input('agent_id'),
|
||||||
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
||||||
|
|
||||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
abstract class InsuranceInvoiceState
|
||||||
|
{
|
||||||
|
const PAID = 'PAID';
|
||||||
|
const UNPAID = 'UNPAID';
|
||||||
|
|
||||||
|
}
|
|
@ -8,4 +8,7 @@ abstract class InsuranceState
|
||||||
const UNDER_STOPPING = 'UNDER_STOPPING';
|
const UNDER_STOPPING = 'UNDER_STOPPING';
|
||||||
const STOPPED = 'STOPPED';
|
const STOPPED = 'STOPPED';
|
||||||
const EXPIRED = 'EXPIRED';
|
const EXPIRED = 'EXPIRED';
|
||||||
|
const UNDER_ACTIVATION = 'UNDER_ACTIVATION';
|
||||||
|
const UNDER_RENEW = 'UNDER_RENEW';
|
||||||
|
const UNDER_ADDING_BENEFICIARY = 'UNDER_ADDING_BENEFICIARY';
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,10 @@ class NhInsurance extends Model
|
||||||
'start_at',
|
'start_at',
|
||||||
'end_at',
|
'end_at',
|
||||||
'state',
|
'state',
|
||||||
|
'deadlines',
|
||||||
|
'paid_deadlines',
|
||||||
|
'amount_per_split',
|
||||||
|
'amount_last_payment'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function network()
|
public function network()
|
||||||
|
@ -82,4 +86,10 @@ class NhInsurance extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsTo(NhInsurancesPayment::class, 'id', 'insurance_id');
|
return $this->belongsTo(NhInsurancesPayment::class, 'id', 'insurance_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function invoices()
|
||||||
|
{
|
||||||
|
return $this->hasMany(NhInsurancesInvoice::class, 'id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class NhInsurancesInvoice
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property string $invoice_id
|
||||||
|
* @property int $insurance_id
|
||||||
|
* @property int $subscription_id
|
||||||
|
* @property float $amount
|
||||||
|
* @property Carbon $payment_deadline
|
||||||
|
* @property Carbon $payment_reminder
|
||||||
|
* @property string $state
|
||||||
|
* @property string $reason
|
||||||
|
* @property Carbon|null $created_at
|
||||||
|
* @property Carbon|null $updated_at
|
||||||
|
*
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class NhInsurancesInvoice extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'nh_insurances_invoices';
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'insurance_id' => 'int',
|
||||||
|
'subscription_id' => 'int',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'invoice_id',
|
||||||
|
'insurance_id',
|
||||||
|
'subscription_id',
|
||||||
|
'amount',
|
||||||
|
'payment_deadline',
|
||||||
|
'payment_reminder',
|
||||||
|
'state',
|
||||||
|
'reason'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function insurance()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(NhInsurance::class, 'insurance_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function subscription()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(NhInsurancesSubscription::class, 'subscription_id');
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ use App\Models\NhHealthCareSheet;
|
||||||
use App\Models\NhInfosHealthCareSheets;
|
use App\Models\NhInfosHealthCareSheets;
|
||||||
use App\Models\NhInsurance;
|
use App\Models\NhInsurance;
|
||||||
use App\Models\NhInsurancesHavingRight;
|
use App\Models\NhInsurancesHavingRight;
|
||||||
|
use App\Models\NhInsurancesInvoice;
|
||||||
use App\Models\NhInsurancesSubscription;
|
use App\Models\NhInsurancesSubscription;
|
||||||
use App\Models\NhMonthsPricesGrid;
|
use App\Models\NhMonthsPricesGrid;
|
||||||
use App\Models\NhNetworksConfig;
|
use App\Models\NhNetworksConfig;
|
||||||
|
@ -353,4 +354,14 @@ trait Helper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function generateInsuranceInvoiceID(): string
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
$code = generateTransactionCode();
|
||||||
|
$codeCorrect = NhInsurancesInvoice::where('invoice_id', $code)->count() < 0;
|
||||||
|
} while ($codeCorrect);
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class CreateNhNetworksConfigsTable extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->integer('network_id');
|
$table->integer('network_id');
|
||||||
$table->enum('provider_billing_period', ['WEEKLY', 'BIMONTHLY', 'MONTHLY'])->default('WEEKLY')->comment('Période de facturation des prestataires : hebdomadaire ou bimensuel ,mensuel ');
|
$table->enum('provider_billing_period', ['WEEKLY', 'BIMONTHLY', 'MONTHLY'])->default('WEEKLY')->comment('Période de facturation des prestataires : hebdomadaire ou bimensuel ,mensuel ');
|
||||||
$table->decimal('max_number_of_beneficiaries', 1, 0)->default(0)->comment('Nombre d’ayant droit maximum : un nombre à un chiffre');
|
$table->decimal('max_number_of_beneficiaries', 4, 0)->default(0)->comment('Nombre d’ayant droit maximum : un nombre à un chiffre');
|
||||||
$table->decimal('age_limit_of_child_beneficiary', 2, 0)->default(0)->comment('Age limite de l’ayant droit enfant : un nombre à 2 chiffres');
|
$table->decimal('age_limit_of_child_beneficiary', 2, 0)->default(0)->comment('Age limite de l’ayant droit enfant : un nombre à 2 chiffres');
|
||||||
// $table->decimal('coverage_limit_per_insured_per_year', 10, 2)->default(0)->comment("Limite de la couverture par assuré par an");
|
// $table->decimal('coverage_limit_per_insured_per_year', 10, 2)->default(0)->comment("Limite de la couverture par assuré par an");
|
||||||
$table->decimal('current_affection_percentage_insurer', 3, 0)->default(0)->comment("Affection courante: % part assureur");
|
$table->decimal('current_affection_percentage_insurer', 3, 0)->default(0)->comment("Affection courante: % part assureur");
|
||||||
|
|
|
@ -15,7 +15,7 @@ class UpdateNhInfosInsurancesView2 extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
DB::statement("CREATE OR REPLACE VIEW nh_infos_insurances AS
|
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
|
SELECT nhi.* , nmpg.number_of_months, nmpg.payment_period , nmpg.payment_duration_months , nmpg.number_of_fractions, 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 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");
|
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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class UpdateNhInfosInsurancesSubscriptionsView2 extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
DB::statement("CREATE OR REPLACE VIEW nh_infos_insurances_subscriptions AS
|
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
|
SELECT nhis.* , cc.currency_code , nmpg.number_of_months, nmpg.payment_period , nmpg.payment_duration_months , nmpg.number_of_fractions , 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 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;");
|
JOIN countries_currencies cc ON n.country_id = cc.id JOIN users u ON nhis.user_id = u.id;");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateNhInsurancesInvoicesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('nh_insurances_invoices', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('invoice_id');
|
||||||
|
$table->integer('insurance_id');
|
||||||
|
$table->integer('subscription_id')->nullable();
|
||||||
|
$table->decimal('amount', 10);
|
||||||
|
$table->dateTime('payment_deadline');
|
||||||
|
$table->dateTime('payment_reminder');
|
||||||
|
$table->enum('state', ['PAID', 'UNPAID'])->default('UNPAID');
|
||||||
|
$table->string('reason');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('nh_insurances_invoices');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class UpdateStateAndAddPaymentSplitDetailsToNhInsurances extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances', function (Blueprint $table) {
|
||||||
|
DB::statement("alter table nh_insurances
|
||||||
|
modify state enum ('PAID', 'UNDER_STOPPING', 'STOPPED', 'EXPIRED', 'UNDER_ACTIVATION', 'UNDER_RENEW','UNDER_ADDING_BENEFICIARY') default 'PAID' not null;");
|
||||||
|
|
||||||
|
$table->unsignedInteger('deadlines')->default(0)->comment("Nombre total d'écheances")
|
||||||
|
->after('state');
|
||||||
|
$table->unsignedInteger('paid_deadlines')->default(0)->comment("Nombre d'écheances payées")
|
||||||
|
->after('deadlines');
|
||||||
|
$table->decimal('amount_per_split', 10)->default(0)->comment("Montant par echeance")
|
||||||
|
->after('paid_deadlines');
|
||||||
|
$table->decimal('amount_last_payment', 10)->default(0)->comment("Montant de la derniere echeance")
|
||||||
|
->after('amount_per_split');
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['deadlines', 'paid_deadlines', 'amount_per_split', 'amount_last_payment']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,5 +60,7 @@ return [
|
||||||
"sheet_not_accepted" => "This treatment sheet has not been accepted",
|
"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",
|
'invoice_not_found' => "The invoice does not exist",
|
||||||
'network_not_found' => "The network does not exist"
|
'network_not_found' => "The network does not exist",
|
||||||
|
'invoice_already_paid' => 'This invoice has already been paid',
|
||||||
|
'payment_deadline_reached' => 'The payment deadline has already passed',
|
||||||
];
|
];
|
||||||
|
|
|
@ -189,4 +189,26 @@ Your insurance has expired.
|
||||||
'invoice_accepted' => "Invoice accepted",
|
'invoice_accepted' => "Invoice accepted",
|
||||||
'invoice_rejected' => "Invoice rejected",
|
'invoice_rejected' => "Invoice rejected",
|
||||||
'invoice_accepted_updated' => "Invoice accepted modified",
|
'invoice_accepted_updated' => "Invoice accepted modified",
|
||||||
|
'insurance_partially_paid' => "Partial payment of insurance",
|
||||||
|
'insurance_paid_mail' => ":gender :name ,
|
||||||
|
|
||||||
|
:title
|
||||||
|
|
||||||
|
Payment information :
|
||||||
|
- ID: :invoice_id
|
||||||
|
- Amount: :amount
|
||||||
|
- Number of paid installments: :paid_deadlines
|
||||||
|
- Number of remaining deadlines: :remains_deadlines :remains_deadlines
|
||||||
|
- Reason: :reason
|
||||||
|
|
||||||
|
Insurance information :
|
||||||
|
- Insured number: :insured_id
|
||||||
|
- Name of the insurance: :insurance_name
|
||||||
|
- Basic insurance premium amount: :bonus_amount
|
||||||
|
- Total premium amount: :total_bonus_amount
|
||||||
|
- Number of beneficiaries : :number_of_beneficiaries
|
||||||
|
- Number of months: :months
|
||||||
|
",
|
||||||
|
'insurance_partially_paid_title' => "Your insurance has been partially paid",
|
||||||
|
'insurance_fully_paid_title' => "Your insurance has been paid in full."
|
||||||
];
|
];
|
||||||
|
|
|
@ -28,5 +28,6 @@ return [
|
||||||
'INVOICE_ISSUED' => 'INVOICE ISSUED',
|
'INVOICE_ISSUED' => 'INVOICE ISSUED',
|
||||||
'STOP_INSURANCE' => "STOP INSURANCE",
|
'STOP_INSURANCE' => "STOP INSURANCE",
|
||||||
'USED' => 'USED',
|
'USED' => 'USED',
|
||||||
'EXPIRED' => 'EXPIRED'
|
'EXPIRED' => 'EXPIRED',
|
||||||
|
"UNPAID" => "UNPAID",
|
||||||
];
|
];
|
||||||
|
|
|
@ -60,5 +60,7 @@ return [
|
||||||
"sheet_not_accepted" => "Cette feuille de soins n'a pas été acceptée",
|
"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",
|
'invoice_not_found' => "La facture n'existe pas",
|
||||||
'network_not_found' => "Le réseau n'existe pas"
|
'network_not_found' => "Le réseau n'existe pas",
|
||||||
|
'invoice_already_paid' => 'Cette facture a déjà été payée',
|
||||||
|
'payment_deadline_reached' => 'Le délai de paiement est déjà passé',
|
||||||
];
|
];
|
||||||
|
|
|
@ -206,4 +206,26 @@ Votre assurance est arrivée à échéance.
|
||||||
'invoice_accepted' => "Facture acceptée",
|
'invoice_accepted' => "Facture acceptée",
|
||||||
'invoice_rejected' => "Facture refusée",
|
'invoice_rejected' => "Facture refusée",
|
||||||
'invoice_accepted_updated' => "Facture acceptée modifiée",
|
'invoice_accepted_updated' => "Facture acceptée modifiée",
|
||||||
|
'insurance_partially_paid' => "Paiement partiel de l'assurance",
|
||||||
|
'insurance_paid_mail' => ":gender :name ,
|
||||||
|
|
||||||
|
:title
|
||||||
|
|
||||||
|
Informations sur le paiement :
|
||||||
|
- ID : :invoice_id
|
||||||
|
- Montant : :amount
|
||||||
|
- Nombre d'échéances payées : :paid_deadlines
|
||||||
|
- Nombre d'échéances restantes : :remains_deadlines
|
||||||
|
- Motif : :reason
|
||||||
|
|
||||||
|
Informations de l'assurance :
|
||||||
|
- Numéro d'assuré : :insured_id
|
||||||
|
- Nom de l'assurance : :insurance_name
|
||||||
|
- Montant de la prime de base d'assuré : :bonus_amount
|
||||||
|
- Montant total de la prime : :total_bonus_amount
|
||||||
|
- Nombre d'ayants droit : :number_of_beneficiaries
|
||||||
|
- Nombre de mois : :months
|
||||||
|
",
|
||||||
|
'insurance_partially_paid_title' => "Votre assurance a été payée partiellement.",
|
||||||
|
'insurance_fully_paid_title' => "Votre assurance a été payée complétement."
|
||||||
];
|
];
|
||||||
|
|
|
@ -28,5 +28,6 @@ return [
|
||||||
'INVOICE_ISSUED' => 'FACTURE ÉMISE',
|
'INVOICE_ISSUED' => 'FACTURE ÉMISE',
|
||||||
'STOP_INSURANCE' => "ARRÊT DE L'ASSURANCE",
|
'STOP_INSURANCE' => "ARRÊT DE L'ASSURANCE",
|
||||||
'USED' => 'UTILISÉE',
|
'USED' => 'UTILISÉE',
|
||||||
'EXPIRED' => 'EXPIRÉE'
|
'EXPIRED' => 'EXPIRÉE',
|
||||||
|
"UNPAID" => "NON PAYÉE",
|
||||||
];
|
];
|
||||||
|
|
|
@ -35,6 +35,12 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
|
||||||
$router->put('{id}/pay', 'InsuranceSubscriptionController@paySubscription');
|
$router->put('{id}/pay', 'InsuranceSubscriptionController@paySubscription');
|
||||||
$router->get('', 'InsuranceSubscriptionController@getSubscriptions');
|
$router->get('', 'InsuranceSubscriptionController@getSubscriptions');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Factures
|
||||||
|
$router->group(['prefix' => '/invoices'], function () use ($router) {
|
||||||
|
$router->get('', 'InsuranceInvoiceController@getInvoices');
|
||||||
|
$router->put('{id}/pay', 'InsuranceInvoiceController@payInvoice');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Insurances routes
|
// Insurances routes
|
||||||
|
|
Loading…
Reference in New Issue