Implements daily verification to expire insurance if end_date is reach
This commit is contained in:
parent
f351fe5ada
commit
b988f4cf0a
|
@ -3,10 +3,13 @@
|
|||
namespace App\Console;
|
||||
|
||||
use App\BillingPeriodType;
|
||||
use App\InsuranceState;
|
||||
use App\InsuranceSubscriptionState;
|
||||
use App\Models\AgentPlus;
|
||||
use App\Models\CountriesCurrency;
|
||||
use App\Models\NhHealthCareSheet;
|
||||
use App\Models\NhInfosInsurances;
|
||||
use App\Models\NhInsurance;
|
||||
use App\Models\NhInvoice;
|
||||
use App\Models\NhNetworksConfig;
|
||||
use App\Traits\Helper;
|
||||
|
@ -163,5 +166,40 @@ class Kernel extends ConsoleKernel
|
|||
}
|
||||
Log::info('-------- Weekly Invoice Generation End ' . $date->format("d/m/Y") . '-----------');
|
||||
})->weekly()->runInBackground();
|
||||
|
||||
// Verifier les assurances qui ont expiré chaque jour à minuit
|
||||
$schedule->call(function () {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$datetime = new DateTime();
|
||||
$insurances = NhInfosInsurances::with(['network:id,name', 'user.identification'])->where('state', InsuranceState::PAID)->where('end_at', '<=', $datetime)->get();
|
||||
|
||||
NhInsurance::where('state', InsuranceState::PAID)->where('end_at', '<=', $datetime)->update([
|
||||
'state' => InsuranceState::EXPIRED
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
$title = trans('messages.insurance_expired');
|
||||
foreach ($insurances as $i) {
|
||||
$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]);
|
||||
|
||||
$recipients = [preg_replace("/\s+/", "", $i->email)]; // Supprimer les espaces dans le mail
|
||||
Mail::mailer('smtp')->raw($message, function ($message) use ($recipients, $title) {
|
||||
$message->subject($title)
|
||||
->to($recipients);
|
||||
});
|
||||
}
|
||||
|
||||
} catch (\Throwable $t) {
|
||||
DB::rollBack();
|
||||
Log::error('-------- Mail not sent notify expired insurance-----------');
|
||||
Log::error($t->getMessage() . " :\n" . $t->getTraceAsString());
|
||||
}
|
||||
})->daily()->runInBackground();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ class InsuranceController extends Controller
|
|||
$query = $query->whereIn('state', [InsuranceState::PAID]);
|
||||
}
|
||||
if ($type == 'STOPPED') {
|
||||
$query = $query->where('state', InsuranceState::STOPPED);
|
||||
$query = $query->whereIn('state', [InsuranceState::STOPPED, InsuranceState::EXPIRED]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -593,7 +593,7 @@ class InsuranceController extends Controller
|
|||
]);
|
||||
|
||||
$insurance = NhInsurance::findOrFail($id);
|
||||
if ($insurance->state != InsuranceState::STOPPED) {
|
||||
if (!in_array($insurance->state, [InsuranceState::STOPPED, InsuranceState::EXPIRED])) {
|
||||
return $this->errorResponse(__('errors.cannot_renew_insurance'));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,14 @@ namespace App\Http\Controllers;
|
|||
|
||||
|
||||
use App\BillingPeriodType;
|
||||
use App\InsuranceState;
|
||||
use App\InsuranceSubscriptionState;
|
||||
use App\Models\AgentPlus;
|
||||
use App\Models\CountriesCurrency;
|
||||
use App\Models\NhHealthCareSheet;
|
||||
use App\Models\NhInfosInsurances;
|
||||
use App\Models\NhInfosInvoice;
|
||||
use App\Models\NhInsurance;
|
||||
use App\Models\NhInvoice;
|
||||
use App\Models\NhNetworksConfig;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
|
|
|
@ -7,4 +7,5 @@ abstract class InsuranceState
|
|||
const PAID = 'PAID';
|
||||
const UNDER_STOPPING = 'UNDER_STOPPING';
|
||||
const STOPPED = 'STOPPED';
|
||||
const EXPIRED = 'EXPIRED';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NhInfosInsurances extends Model
|
||||
{
|
||||
protected $table = 'nh_infos_insurances';
|
||||
|
||||
// protected $dates = [
|
||||
// 'start_at',
|
||||
// 'end_at'
|
||||
// ];
|
||||
|
||||
public function network()
|
||||
{
|
||||
return $this->belongsTo(Network::class, 'network_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
|
@ -17,8 +17,8 @@ class CreateNhInsurancesTable extends Migration
|
|||
$table->id();
|
||||
$table->string('insurance_subscription_id')->unique()->comment("ID de la souscription");
|
||||
$table->string('insured_id')->unique()->comment("Numero de l'assuré");
|
||||
$table->dateTime('start_at')->nullable()->comment("Date de debut de l'assurance");
|
||||
$table->dateTime('end_at')->nullable()->comment("Date d'echeance");
|
||||
$table->date('start_at')->nullable()->comment("Date de debut de l'assurance");
|
||||
$table->date('end_at')->nullable()->comment("Date d'echeance");
|
||||
$table->enum('state', ['PAID', 'UNDER_STOPPING', 'STOPPED', 'ENDED'])->default('PAID');
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent();
|
||||
|
|
|
@ -22,7 +22,7 @@ class UpdateNhInsurancesTable extends Migration
|
|||
$table->integer('number_of_beneficiaries')->after('bonus_amount');
|
||||
$table->decimal('total_bonus_amount', 12, 2)->default(0)->comment("Montant total de la prime (assuré + ayants droit)")->after('number_of_beneficiaries');
|
||||
DB::statement("ALTER TABLE nh_insurances MODIFY state
|
||||
ENUM('PAID', 'UNDER_STOPPING', 'STOPPED') DEFAULT 'PAID' NOT NULL;");
|
||||
ENUM('PAID', 'UNDER_STOPPING', 'STOPPED', 'EXPIRED') DEFAULT 'PAID' NOT NULL;");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -173,5 +173,17 @@ Your insurance has been renewed.
|
|||
- Number of months: :months
|
||||
",
|
||||
'insurance_renew_paid' => "Insurance renewal paid",
|
||||
"invoice_generated" => "Invoice has been generated"
|
||||
"invoice_generated" => "Invoice has been generated",
|
||||
'insurance_expired' => "Insurance expired",
|
||||
'insurance_expired_mail' => ":gender :name ,
|
||||
|
||||
Your insurance has expired.
|
||||
Insurance information :
|
||||
- Insured number: :insured_id
|
||||
- Insurance name: :insurance_name
|
||||
- Basic insurance premium amount: :bonus_amount
|
||||
- Total premium amount: :total_bonus_amount
|
||||
- Number of beneficiaries : :number_of_beneficiaries
|
||||
- Number of months: :months
|
||||
",
|
||||
];
|
||||
|
|
|
@ -27,5 +27,6 @@ return [
|
|||
'INSURED' => 'PRINCIPAL INSURED',
|
||||
'INVOICE_ISSUED' => 'INVOICE ISSUED',
|
||||
'STOP_INSURANCE' => "STOP INSURANCE",
|
||||
'USED' => 'USED'
|
||||
'USED' => 'USED',
|
||||
'EXPIRED' => 'EXPIRED'
|
||||
];
|
||||
|
|
|
@ -190,5 +190,17 @@ Votre assurance a été renouvelée.
|
|||
- Nombre de mois : :months
|
||||
",
|
||||
'insurance_renew_paid' => "Renouvellement de l'assurance payée",
|
||||
"invoice_generated" => "La facture a été générée"
|
||||
"invoice_generated" => "La facture a été générée",
|
||||
'insurance_expired' => "Assurance arrivée à échéance",
|
||||
'insurance_expired_mail' => ":gender :name ,
|
||||
|
||||
Votre assurance est arrivée à échéance.
|
||||
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
|
||||
",
|
||||
];
|
||||
|
|
|
@ -27,5 +27,6 @@ return [
|
|||
'INSURED' => 'ASSURÉ PRINCIPAL',
|
||||
'INVOICE_ISSUED' => 'FACTURE ÉMISE',
|
||||
'STOP_INSURANCE' => "ARRÊT DE L'ASSURANCE",
|
||||
'USED' => 'UTILISÉE'
|
||||
'USED' => 'UTILISÉE',
|
||||
'EXPIRED' => 'EXPIRÉE'
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue