Improve insurance subscription
This commit is contained in:
parent
8ea7dbc255
commit
c83feab3c0
|
@ -346,6 +346,13 @@ class InsuranceController extends Controller
|
||||||
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
|
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
|
||||||
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
||||||
|
|
||||||
|
$currentSubscription = NhInsurancesSubscription::where('network_id', $request->input('network_id'))->where('user_id', $request->input('user_id'))
|
||||||
|
->whereNotIn('state', [InsuranceSubscriptionState::REJECTED, InsuranceSubscriptionState::STOPPED])->first();
|
||||||
|
|
||||||
|
if (isset($currentSubscription)) {
|
||||||
|
return $this->errorResponse(trans('errors.cannot_subscribe_again', ['state' => mb_strtolower(trans('states.' . $currentSubscription->state), 'UTF-8')]));
|
||||||
|
}
|
||||||
|
|
||||||
// Verification de l'age du beneficiaire
|
// Verification de l'age du beneficiaire
|
||||||
$insuredAge = date_diff(date_create($identification->birth_date), date_create('now'))->y;
|
$insuredAge = date_diff(date_create($identification->birth_date), date_create('now'))->y;
|
||||||
if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) {
|
if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) {
|
||||||
|
@ -362,13 +369,13 @@ class InsuranceController extends Controller
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
$datetime = $this->getCurrentTimeByCountryCode($networkConfig->network->country->code_country);
|
||||||
$subscription = new NhInsurancesSubscription($request->all());
|
$subscription = new NhInsurancesSubscription($request->all());
|
||||||
$subscription->number_of_beneficiaries = sizeof($request->input('beneficiaries'));
|
$subscription->number_of_beneficiaries = sizeof($request->input('beneficiaries'));
|
||||||
$subscription->insurance_subscription_id = $this->generateSubscriptionID();
|
$subscription->insurance_subscription_id = $this->generateSubscriptionID();
|
||||||
$subscription->number_of_months = $monthPrice->number_of_months;
|
$subscription->number_of_months = $monthPrice->number_of_months;
|
||||||
$subscription->bonus_amount = $monthPrice->min_amount;
|
$subscription->bonus_amount = $monthPrice->min_amount;
|
||||||
$subscription->state = InsuranceSubscriptionState::UNDER_VALIDATION;
|
$subscription->state = InsuranceSubscriptionState::UNDER_VALIDATION;
|
||||||
$subscription->save();
|
|
||||||
|
|
||||||
$beneficiariesBonus = 0;
|
$beneficiariesBonus = 0;
|
||||||
foreach ($request->input('beneficiaries') as $b) {
|
foreach ($request->input('beneficiaries') as $b) {
|
||||||
|
@ -386,17 +393,20 @@ class InsuranceController extends Controller
|
||||||
$beneficiary->birthdate_proof_doc = null;
|
$beneficiary->birthdate_proof_doc = null;
|
||||||
$beneficiary->birthdate_proof = null;
|
$beneficiary->birthdate_proof = null;
|
||||||
}
|
}
|
||||||
|
$beneficiary->created_at = $beneficiary->updated_at = $datetime;
|
||||||
$beneficiary->save();
|
$beneficiary->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscription->total_bonus_amount = ($subscription->bonus_amount + $beneficiariesBonus);
|
$subscription->total_bonus_amount = ($subscription->bonus_amount + $beneficiariesBonus);
|
||||||
|
$subscription->created_at = $subscription->updated_at = $datetime;
|
||||||
$subscription->save();
|
$subscription->save();
|
||||||
|
|
||||||
NhInsurancesSubscriptionsHistory::create([
|
NhInsurancesSubscriptionsHistory::create([
|
||||||
'action' => 'ADD',
|
'action' => 'ADD',
|
||||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||||
'insurance_subscription_state' => $subscription->state,
|
'insurance_subscription_state' => $subscription->state,
|
||||||
'insurance_subscription' => json_encode($subscription)
|
'insurance_subscription' => json_encode($subscription),
|
||||||
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
@ -448,7 +458,7 @@ class InsuranceController extends Controller
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'files' => 'required',
|
'files' => 'required',
|
||||||
'files.*' => 'mimes:jpeg,png,jpg,jpeg|max:8192'
|
'files.*' => 'mimes:jpeg,png,jpg,jpeg|max:10240' // 10 Mb
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$files = [];
|
$files = [];
|
||||||
|
@ -528,6 +538,51 @@ class InsuranceController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/insurances/subscriptions",
|
||||||
|
* summary="Afficher la liste des souscriptions d'assurances ( par utilisateur )",
|
||||||
|
* tags={"Assurances"},
|
||||||
|
* 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\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="OK",
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* ref="#/components/schemas/ApiResponse",
|
||||||
|
* example = {
|
||||||
|
* "status" : 200,
|
||||||
|
* "response" : {{"id":250,"name":"Cnamgs-pharmacies", "age_limit_of_insured_and_spouse" : 30 ,
|
||||||
|
* "age_limit_of_child_beneficiary": 25 , "max_number_of_beneficiaries":"5", "months_prices":{{"id": 1,"number_of_months":"3","min_amount":"150000 XAF"}}}},
|
||||||
|
* "error":null
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function getSubscriptions(Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'user_id' => 'nullable|integer|exists:users,id'
|
||||||
|
]);
|
||||||
|
$subscriptions = NhInsurancesSubscription::with(['beneficiaries'])->where('user_id', $request->input('user_id'))->get();
|
||||||
|
foreach ($subscriptions as $subscription) {
|
||||||
|
$subscription->state = trans('states.' . $subscription->state);
|
||||||
|
$subscription->bonus_amount = trans('states.' . $subscription->state);
|
||||||
|
}
|
||||||
|
return $this->successResponse($subscriptions);
|
||||||
|
}
|
||||||
|
|
||||||
private function generateSubscriptionID(): string
|
private function generateSubscriptionID(): string
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -55,18 +55,14 @@ class NotifyUser
|
||||||
$body = new stdClass();
|
$body = new stdClass();
|
||||||
$body->user_code = $user->user_code;
|
$body->user_code = $user->user_code;
|
||||||
$body->message = $event->notification;
|
$body->message = $event->notification;
|
||||||
|
$body->date = $subscription->created_at ?? date('Y-m-d H:i:s');
|
||||||
|
|
||||||
$data = new stdClass();
|
$data = new stdClass();
|
||||||
$data->screen = "notificationview";
|
$data->screen = "notificationview";
|
||||||
$data->data = new stdClass();
|
$data->data = new stdClass();
|
||||||
$data->data->subscription_id = $data->data->id = $subscription->id;
|
$data->data->subscription_id = $data->data->id = $subscription->id;
|
||||||
$body->data = $data;
|
$body->data = $data;
|
||||||
|
|
||||||
try {
|
|
||||||
$body->date = $this->getCurrentTimeByCountryCode($user->network->country->code_country);
|
|
||||||
} catch (Throwable $t) {
|
|
||||||
Log::error($t->getMessage());
|
|
||||||
$body->date = date('Y-m-d H:i:s');
|
|
||||||
}
|
|
||||||
$client->request('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers]);
|
$client->request('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers]);
|
||||||
}
|
}
|
||||||
} catch (Throwable $t) {
|
} catch (Throwable $t) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ class NhInsurancesHavingRight extends Model
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $table = 'nh_insurances_having_rights';
|
protected $table = 'nh_insurances_having_rights';
|
||||||
|
protected $appends = ['affiliation_tr'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'bonus_amount' => 'float'
|
'bonus_amount' => 'float'
|
||||||
|
@ -64,4 +65,9 @@ class NhInsurancesHavingRight extends Model
|
||||||
'id_document_front',
|
'id_document_front',
|
||||||
'id_document_back'
|
'id_document_back'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function getAffiliationTrAttribute()
|
||||||
|
{
|
||||||
|
return trans('states.' . $this->attributes['affiliation']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,4 +55,9 @@ class NhInsurancesSubscription extends Model
|
||||||
return $this->belongsTo(User::class, 'user_id');
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function beneficiaries()
|
||||||
|
{
|
||||||
|
return $this->hasMany(NhInsurancesHavingRight::class, 'insurance_subscription_id', 'insurance_subscription_id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,11 @@ class NhNetworksConfig extends Model
|
||||||
return $this->hasOne(ConfigWallet::class, 'id_network', 'network_id');
|
return $this->hasOne(ConfigWallet::class, 'id_network', 'network_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function network()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Network::class, 'network_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function monthsPricesGrid()
|
public function monthsPricesGrid()
|
||||||
{
|
{
|
||||||
return $this->hasMany(NhMonthsPricesGrid::class, 'nh_network_config_id', 'id');
|
return $this->hasMany(NhMonthsPricesGrid::class, 'nh_network_config_id', 'id');
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Brick\Money\Context\AutoContext;
|
||||||
use Brick\Money\Money;
|
use Brick\Money\Money;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
trait Helper
|
trait Helper
|
||||||
|
|
|
@ -25,5 +25,6 @@ return [
|
||||||
'nano_health_not_activated' => "Nano health is not activated for this network",
|
'nano_health_not_activated' => "Nano health is not activated for this network",
|
||||||
'number_of_beneficiaries_exceeded' => 'The number of beneficiaries is greater than the authorized limit',
|
'number_of_beneficiaries_exceeded' => 'The number of beneficiaries is greater than the authorized limit',
|
||||||
'incorrect_selected_amount' => 'The amount selected is incorrect',
|
'incorrect_selected_amount' => 'The amount selected is incorrect',
|
||||||
'minimal_age_required' => "Your age is above the age limit required to subscribe to this insurance"
|
'minimal_age_required' => "Your age is above the age limit required to subscribe to this insurance",
|
||||||
|
'cannot_subscribe_again' => "You can no longer subscribe to this insurance. You already have a request :state"
|
||||||
];
|
];
|
||||||
|
|
|
@ -50,5 +50,5 @@ Your application has been rejected.
|
||||||
|
|
||||||
Reason for rejection: :reason ",
|
Reason for rejection: :reason ",
|
||||||
'insurance_subscription_rejected_notification' => "Your :subscription_id application has been rejected",
|
'insurance_subscription_rejected_notification' => "Your :subscription_id application has been rejected",
|
||||||
"insurance_subscription_successful" => "Insurance subscription submitted"
|
"insurance_subscription_successful" => "Insurance subscription successful"
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
"UNDER_VALIDATION" => "CURRENT",
|
"UNDER_VALIDATION" => "UNDER VALIDATION",
|
||||||
"CASSE" => "BROKEN",
|
"ACCEPTED" => "ACCEPTED",
|
||||||
"EN_ATTENTE_DE_VALIDATION" => "PENDING VALIDATION",
|
"REJECTED" => "REJECTED",
|
||||||
"REMBOURSE" => "REFUNDED",
|
"CURRENT" => "CURRENT",
|
||||||
"NON_VALIDE" => "INVALID",
|
"UNDER_STOPPING" => "UNDER STOPPING",
|
||||||
"VALIDE" => "VALID",
|
"STOPPED" => "STOPPED",
|
||||||
"SIMPLE" => "SIMPLE",
|
"CHILD" => "CHILD",
|
||||||
|
"SPOUSE" => "SPOUSE",
|
||||||
"BLOQUE" => "BLOCKED",
|
"BLOQUE" => "BLOCKED",
|
||||||
"NON_TRAITEE" => "NOT TREATED",
|
"NON_TRAITEE" => "NOT TREATED",
|
||||||
"TRAITEE" => "TREATED",
|
"TRAITEE" => "TREATED",
|
||||||
|
|
|
@ -25,5 +25,6 @@ return [
|
||||||
'nano_health_not_activated' => "Le nano santé n'est pas activé pour ce réseau",
|
'nano_health_not_activated' => "Le nano santé n'est pas activé pour ce réseau",
|
||||||
'number_of_beneficiaries_exceeded' => "Le nombre d'ayant droit est superieur à la limite autorisée",
|
'number_of_beneficiaries_exceeded' => "Le nombre d'ayant droit est superieur à la limite autorisée",
|
||||||
'incorrect_selected_amount' => 'Le montant choisi est incorrect',
|
'incorrect_selected_amount' => 'Le montant choisi est incorrect',
|
||||||
'minimal_age_required' => "Votre âge est supérieur à l'âge limite requis pour souscrire à cette assurance"
|
'minimal_age_required' => "Votre âge est supérieur à l'âge limite requis pour souscrire à cette assurance",
|
||||||
|
'cannot_subscribe_again' => "Vous ne pouvez plus souscrire à cette assurance. Vous avez déjà une demande :state"
|
||||||
];
|
];
|
||||||
|
|
|
@ -50,5 +50,5 @@ Votre demande de souscription a été rejetée.
|
||||||
|
|
||||||
Motif du rejet : :reason ",
|
Motif du rejet : :reason ",
|
||||||
'insurance_subscription_rejected_notification' => "Votre demande de souscription :subscription_id a été rejetée.",
|
'insurance_subscription_rejected_notification' => "Votre demande de souscription :subscription_id a été rejetée.",
|
||||||
"insurance_subscription_successful" => "Souscription à l'assurance envoyée"
|
"insurance_subscription_successful" => "Souscription à l'assurance réussie"
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
"EN_COURS" => "EN COURS",
|
"UNDER_VALIDATION" => "EN COURS DE VALIDATION",
|
||||||
"CASSE" => "CASSÉE",
|
"ACCEPTED" => "ACCEPTÉE",
|
||||||
"EN_ATTENTE_DE_VALIDATION" => "EN ATTENTE DE VALIDATION",
|
"REJECTED" => "REJETÉE",
|
||||||
"REMBOURSE" => "REMBOURSE",
|
"CURRENT" => "EN COURS",
|
||||||
"NON_VALIDE" => "NON VALIDE",
|
"UNDER_STOPPING" => "EN COURS D'ARRÊT",
|
||||||
"VALIDE" => "VALIDE",
|
"STOPPED" => "ARRÊTÉE",
|
||||||
"SIMPLE" => "SIMPLE",
|
"CHILD" => "ENFANT",
|
||||||
|
"SPOUSE" => "CONJOINT",
|
||||||
"BLOQUE" => "BLOQUÉE",
|
"BLOQUE" => "BLOQUÉE",
|
||||||
"NON_TRAITEE" => "NON_TRAITÉE",
|
"NON_TRAITEE" => "NON_TRAITÉE",
|
||||||
"TRAITEE" => "TRAITÉE",
|
"TRAITEE" => "TRAITÉE",
|
||||||
|
|
|
@ -22,6 +22,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
|
||||||
$router->post('', 'InsuranceController@subscribe');
|
$router->post('', 'InsuranceController@subscribe');
|
||||||
$router->put('{id}/validate', 'InsuranceController@validateSubscription');
|
$router->put('{id}/validate', 'InsuranceController@validateSubscription');
|
||||||
$router->put('{id}/reject', 'InsuranceController@rejectSubscription');
|
$router->put('{id}/reject', 'InsuranceController@rejectSubscription');
|
||||||
|
$router->get('', 'InsuranceController@getSubscriptions');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue