Implements route to pay insurance subscription
This commit is contained in:
parent
f4deb3b3ae
commit
2e74d48523
|
@ -3,11 +3,11 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\InsuranceEvent;
|
||||
use App\Events\InsuranceSubscriptionAccepted;
|
||||
use App\InsuranceSubscriptionAffiliation;
|
||||
use App\InsuranceSubscriptionState;
|
||||
use App\Models\CountriesCurrency;
|
||||
use App\Models\Identification;
|
||||
use App\Models\NhInsurance;
|
||||
use App\Models\NhInsurancesHavingRight;
|
||||
use App\Models\NhInsurancesSubscription;
|
||||
use App\Models\NhInsurancesSubscriptionsHistory;
|
||||
|
@ -95,692 +95,4 @@ class InsuranceController extends Controller
|
|||
return $this->successResponse($insurances);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/insurances/subscriptions/bonus-amount",
|
||||
* summary="Calculer le montant de la prime",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(property="subscription_id",
|
||||
* type="integer",
|
||||
* example = 2,
|
||||
* description="ID de la souscription"
|
||||
* ),
|
||||
* @OA\Property(property="network_id",
|
||||
* type="integer",
|
||||
* example = 250,
|
||||
* description="ID du reseau de l'assureur"
|
||||
* ),
|
||||
* @OA\Property(property="month_price_id",
|
||||
* type="integer",
|
||||
* example=2,
|
||||
* description="ID de la grille de prix choisit lors de la souscription"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="beneficiaries",
|
||||
* description="Listes de quelques infos sur les beneficiaires ou ayants droit",
|
||||
* example = {{"birthdate":"1998-10-05","affiliation":"CHILD"}}
|
||||
* ),
|
||||
* ),
|
||||
* example = {"subscription_id":7,"network_id":250,"month_price_id":3,"beneficiaries":{{"birthdate":"1998-10-05","affiliation":"CHILD"}}}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":{"bonus_amount":75000,"bonus_amount_formatted":"75 000FCFA"},"error":null},
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function calculateBonusAmount(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'subscription_id' => 'nullable|integer|exists:nh_insurances_subscriptions,id',
|
||||
'network_id' => 'required_without:subscription_id|integer|exists:networks,id',
|
||||
'month_price_id' => 'required_without:subscription_id|integer|exists:nh_months_prices_grid,id',
|
||||
'beneficiaries' => 'nullable|array',
|
||||
'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today',
|
||||
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE'
|
||||
]);
|
||||
|
||||
if ($request->has('subscription_id')) {
|
||||
$subscription = NhInsurancesSubscription::findOrFail($request->input('subscription_id'));
|
||||
$networkConfig = $subscription->nhNetworkConfig;
|
||||
$monthPrice = $networkConfig->monthsPricesGrid()->where('number_of_months', $subscription->number_of_months)->first();
|
||||
|
||||
$beneficiaries = array_merge($subscription->beneficiaries->toArray(), $request->input('beneficiaries'));
|
||||
} else {
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
|
||||
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
|
||||
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
||||
|
||||
$monthPrice = $networkConfig->monthsPricesGrid()->where('id', $request->input('month_price_id'))->first();
|
||||
|
||||
$beneficiaries = $request->input('beneficiaries');
|
||||
}
|
||||
|
||||
if (!isset($monthPrice))
|
||||
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
|
||||
|
||||
$bonus = $monthPrice->min_amount;
|
||||
foreach ($beneficiaries as $b) {
|
||||
$bonus += $this->calculateBeneficiaryBonusAmount(new NhInsurancesHavingRight($b), $networkConfig->yearsPricesGrid, $monthPrice);
|
||||
}
|
||||
|
||||
return $this->successResponse([
|
||||
'bonus_amount' => $bonus,
|
||||
'bonus_amount_formatted' => $this->toMoneyWithNetwork($bonus, $request->input('network_id'))
|
||||
]);
|
||||
}
|
||||
|
||||
// Caculer le montant de la prime d'un ayant droit ou beneficiaire
|
||||
private function calculateBeneficiaryBonusAmount(NhInsurancesHavingRight $beneficiary, Collection $yearsPricesGrid,
|
||||
NhMonthsPricesGrid $monthPrice)
|
||||
{
|
||||
$bonus = 0;
|
||||
if ($beneficiary->affiliation == 'CHILD') {
|
||||
$age = date_diff(date_create($beneficiary->birthdate), date_create('now'))->y;
|
||||
$levels = $yearsPricesGrid->filter(function ($level) use ($age) {
|
||||
return $level->min_age <= $age && $level->max_age >= $age;
|
||||
});
|
||||
|
||||
foreach ($levels as $level) {
|
||||
$bonus += (100 + $level->markup_percentage) * $monthPrice->min_amount / 100;
|
||||
}
|
||||
} else {
|
||||
$bonus = $monthPrice->min_amount;
|
||||
}
|
||||
|
||||
return $bonus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/insurances/subscriptions",
|
||||
* summary="Souscrire à une assurance",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/subscribe_incurance"),
|
||||
* example = {"network_id":250,"user_id":20,"password" : "1234", "month_price_id":3,"beneficiaries":{{"lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05",
|
||||
* "affiliation":"CHILD","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png","marriage_certificate_doc":"mariage.png",
|
||||
* "id_document_type":"CNI","id_document_front":"cni_front.jpg","id_document_back":"cni_front.jpg"}}}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function subscribe(Request $request)
|
||||
{
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="subscribe_incurance",
|
||||
* title = "Souscription à une assurance",
|
||||
* required={"network_id", "user_id" , "password", "month_price_id", "beneficiaries"},
|
||||
* @OA\Property(property="network_id",
|
||||
* type="integer",
|
||||
* example = 250,
|
||||
* description="ID du reseau de l'assureur"
|
||||
* ),
|
||||
* @OA\Property(property="user_id",
|
||||
* type="integer",
|
||||
* example=300,
|
||||
* description="ID l'utilisateur identifié"
|
||||
* ),
|
||||
* @OA\Property(property="password",
|
||||
* type="string",
|
||||
* example="20214666",
|
||||
* description="Mot de passe de l'utilisateur identifié"
|
||||
* ),
|
||||
* @OA\Property(property="month_price_id",
|
||||
* type="integer",
|
||||
* example=2,
|
||||
* description="ID de la grille de prix choisit lors de la souscription"
|
||||
* ),
|
||||
* @OA\Property(property="beneficiaries",
|
||||
* type="array",
|
||||
* description="Listes des beneficiaires ou ayants droit",
|
||||
* @OA\Items(ref="#/components/schemas/beneficiaries")
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="beneficiaries",
|
||||
* title = "Beneficiaires ou ayants droit",
|
||||
* required={"lastname","gender", "birthdate", "affiliation" },
|
||||
* @OA\Property(property="lastname",
|
||||
* type="string",
|
||||
* example = "Djery",
|
||||
* description="Noms"
|
||||
* ),
|
||||
* @OA\Property(property="firstname",
|
||||
* type="string",
|
||||
* example="DI",
|
||||
* description="Prenoms"
|
||||
* ),
|
||||
* @OA\Property(property="gender",
|
||||
* type="string",
|
||||
* enum = {"M" ,"F"},
|
||||
* example= "M",
|
||||
* description="Sexe"
|
||||
* ),
|
||||
* @OA\Property(property="birthdate",
|
||||
* type="string",
|
||||
* example= "2001-10-05",
|
||||
* description="Date de naissance"
|
||||
* ),
|
||||
* @OA\Property(property="affiliation",
|
||||
* type="string",
|
||||
* enum = {"CHILD" ,"SPOUSE"},
|
||||
* example= "CHILD",
|
||||
* description="Affiliation"
|
||||
* ),
|
||||
* @OA\Property(property="birthdate_proof",
|
||||
* type="string",
|
||||
* enum = {"CERTIFIED_COPY" ,"CERTIFICATE"},
|
||||
* example="CERTIFIED_COPY",
|
||||
* description="Copie légalisée acte de naissance ou certificat de naissance"
|
||||
* ),
|
||||
* @OA\Property(property="birthdate_proof_doc",
|
||||
* type="string",
|
||||
* example="birthdate_proof_doc.jpg",
|
||||
* description="Copie légalisée acte de naissance ou certificat de naissance"
|
||||
* ),
|
||||
* @OA\Property(property="justice_doc",
|
||||
* type="string",
|
||||
* example="justice_doc.jpg",
|
||||
* description="Une page document de justice si enfant adopté ou sous tutelle"
|
||||
* ),
|
||||
* @OA\Property(property="marriage_certificate_doc",
|
||||
* type="string",
|
||||
* example="marriage_certificate_doc.jpg",
|
||||
* description="Une page de l'acte de mariage"
|
||||
* ),
|
||||
* @OA\Property(property="id_document_type",
|
||||
* type="string",
|
||||
* example="CNI",
|
||||
* description="Type de piece d'identité cni , carte sejour, permis"
|
||||
* ),
|
||||
* @OA\Property(property="id_document_front",
|
||||
* type="string",
|
||||
* example="id_document_front.jpg",
|
||||
* description="Pièce identité recto"
|
||||
* ),
|
||||
* @OA\Property(property="id_document_back",
|
||||
* type="string",
|
||||
* example="id_document_back.jpg",
|
||||
* description="Pièce identité verso"
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
$this->validate($request, [
|
||||
'network_id' => 'required|integer|exists:networks,id',
|
||||
'user_id' => 'required|integer|exists:users,id',
|
||||
'password' => 'required|string',
|
||||
'month_price_id' => 'required|integer|exists:nh_months_prices_grid,id',
|
||||
'beneficiaries' => 'nullable|array',
|
||||
'beneficiaries.*.lastname' => 'required|string',
|
||||
'beneficiaries.*.gender' => 'required|in:M,F',
|
||||
'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today',
|
||||
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE',
|
||||
'beneficiaries.*.birthdate_proof' => 'required_if:beneficiaries.*.affiliation,CHILD|in:CERTIFIED_COPY,CERTIFICATE',
|
||||
'beneficiaries.*.birthdate_proof_doc' => 'required_if:beneficiaries.*.affiliation,CHILD|string',
|
||||
'beneficiaries.*.justice_doc' => 'nullable|string',
|
||||
'beneficiaries.*.marriage_certificate_doc' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_type' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_front' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_back' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
]);
|
||||
|
||||
$identification = Identification::where('id_user', $request->input('user_id'))->first();
|
||||
if (!isset($identification) || $identification->status == 0)
|
||||
return $this->errorResponse(trans('errors.user_identification_required'));
|
||||
|
||||
if (!$this->checkPassword($request->password, $identification->user->encrypted_password, $identification->user->salt))
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
|
||||
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
|
||||
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
|
||||
$insuredAge = date_diff(date_create($identification->birth_date), date_create('now'))->y;
|
||||
if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) {
|
||||
return $this->errorResponse(trans('errors.minimal_age_required'));
|
||||
}
|
||||
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
|
||||
if (sizeof($request->input('beneficiaries')) > $networkConfig->max_number_of_beneficiaries)
|
||||
return $this->errorResponse(trans('errors.number_of_beneficiaries_exceeded'));
|
||||
|
||||
$monthPrice = $networkConfig->monthsPricesGrid()->where('id', $request->input('month_price_id'))->first();
|
||||
if (!isset($monthPrice))
|
||||
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$datetime = $this->getCurrentTimeByCountryCode($networkConfig->network->country->code_country);
|
||||
$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->bonus_amount = $monthPrice->min_amount;
|
||||
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($subscription, $request, $networkConfig, $monthPrice, $datetime);
|
||||
|
||||
$subscription->total_bonus_amount = ($subscription->bonus_amount + $beneficiariesBonus);
|
||||
$subscription->created_at = $subscription->updated_at = $datetime;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'ADD',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'insurance_subscription' => json_encode($subscription),
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription'), trans('messages.insurance_subscription_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $identification->gender), 'insurance_name' => $networkConfig->network->name])));
|
||||
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.insurance_subscription_successful'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/insurances/subscriptions/upload-images",
|
||||
* summary="Uploader les images de la souscription à l'assurance",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="multipart/form-data",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="files[]",
|
||||
* description = "Liste des documents à uploader",
|
||||
* type="array",
|
||||
* @OA\Items(type="string", format="binary")
|
||||
* )
|
||||
* ),
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function uploadImages(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'files' => 'required',
|
||||
'files.*' => 'mimes:jpeg,png,jpg,jpeg|max:10240' // 10 Mb
|
||||
]);
|
||||
|
||||
$files = [];
|
||||
if ($request->hasfile('files')) {
|
||||
foreach ($request->file('files') as $file) {
|
||||
$filename = $this->uploadImage($file, 'NH', 'insurances-subscriptions-docs');
|
||||
array_push($files, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->successResponse($files);
|
||||
}
|
||||
|
||||
public function validateSubscription($id, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'agent_id' => 'required|integer|exists:agents,id'
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
$subscription->state = InsuranceSubscriptionState::ACCEPTED;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'EDIT',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'agent_id' => $request->input('agent_id'),
|
||||
'insurance_subscription' => json_encode($subscription)
|
||||
]);
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_accepted'), trans('messages.insurance_subscription_accepted_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'user_code' => $subscription->user->user_code, 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name]), trans('messages.insurance_subscription_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id])));
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.successful_transaction'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function rejectSubscription($id, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'agent_id' => 'required|integer|exists:agents,id',
|
||||
'reason' => 'required'
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
$subscription->reason = $request->input('reason');
|
||||
$subscription->state = InsuranceSubscriptionState::REJECTED;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'EDIT',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'agent_id' => $request->input('agent_id'),
|
||||
'insurance_subscription' => json_encode($subscription)
|
||||
]);
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_rejected'), trans('messages.insurance_subscription_rejected_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'reason' => $request->input('reason'), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name]), trans('messages.insurance_subscription_rejected_notification', ['subscription_id' => $subscription->insurance_subscription_id])));
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.successful_transaction'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/insurances/subscriptions",
|
||||
* summary="Afficher la liste des souscriptions d'assurances ( par utilisateur , par type)",
|
||||
* tags={"Souscriptions à 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="type",
|
||||
* name="type",
|
||||
* description="Type de souscription",
|
||||
* in="query",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* enum={"ALL","EDITABLE"}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {
|
||||
* "status" : 200,
|
||||
* "response" : {{"id":1,"insurance_subscription_id":"BOKWRWZ245JX","network_id":250,"user_id":321,"number_of_months":3,
|
||||
* "bonus_amount":"150\u202f000\u00a0FCFA","number_of_beneficiaries":2,"total_bonus_amount":"495\u202f000\u00a0FCFA","state":"EN COURS DE VALIDATION",
|
||||
* "created_at":"2021-10-29T14:26:05.000000Z","updated_at":"2021-10-29T14:26:05.000000Z","start_at":null,"end_at":null,"reason":null,
|
||||
* "beneficiaries":{{"id":1,"insurance_subscription_id":"BOKWRWZ245JX","lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05T00:00:00.000000Z",
|
||||
* "affiliation":"CHILD","bonus_amount":"195\u202f000\u00a0FCFA","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png",
|
||||
* "marriage_certificate_doc":null,"id_document_type":null,"id_document_front":null,"id_document_back":null,"deleted_at":null,"created_at":"2021-10-29T14:26:05.000000Z",
|
||||
* "updated_at":"2021-10-29T14:26:05.000000Z","affiliation_tr":"ENFANT"}}}},
|
||||
* "error":null
|
||||
* }
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function getSubscriptions(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user_id' => 'nullable|integer|exists:users,id',
|
||||
'type' => 'nullable|in:ALL,EDITABLE'
|
||||
]);
|
||||
$user = User::findOrFail($request->input('user_id'));
|
||||
$currency_code = $user->network->country->currency_code;
|
||||
|
||||
$query = NhInsurancesSubscription::with(['network:id,name', 'beneficiaries']);
|
||||
|
||||
if ($request->has('user_id')) {
|
||||
$query = $query->where('user_id', $request->input('user_id'));
|
||||
}
|
||||
if ($request->has('type')) {
|
||||
$type = $request->input('type');
|
||||
if ($type == 'EDITABLE') {
|
||||
$query = $query->whereIn('state', [InsuranceSubscriptionState::UNDER_VALIDATION, InsuranceSubscriptionState::ACCEPTED]);
|
||||
}
|
||||
}
|
||||
|
||||
$subscriptions = $query->get();
|
||||
foreach ($subscriptions as $subscription) {
|
||||
$subscription->state = trans('states.' . $subscription->state);
|
||||
$subscription->bonus_amount = $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency_code);
|
||||
$subscription->total_bonus_amount = $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency_code);
|
||||
foreach ($subscription->beneficiaries as $b) {
|
||||
$b->bonus_amount = $this->toMoneyWithCurrencyCode($b->bonus_amount, $currency_code);
|
||||
}
|
||||
}
|
||||
return $this->successResponse($subscriptions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* path="/insurances/subscriptions/{id}",
|
||||
* summary="Ajouter des ayants droits ou beneficiaires à une souscription",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\Parameter(
|
||||
* parameter="id",
|
||||
* name="id",
|
||||
* description="ID de la souscription",
|
||||
* 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(ref="#/components/schemas/add_beneficiaries"),
|
||||
* example = {"password" : "1234", "beneficiaries":{{"lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05",
|
||||
* "affiliation":"CHILD","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png","marriage_certificate_doc":"mariage.png",
|
||||
* "id_document_type":"CNI","id_document_front":"cni_front.jpg","id_document_back":"cni_front.jpg"}}}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function addBeneficiaries(Request $request, $id)
|
||||
{
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="add_beneficiaries",
|
||||
* title = "Ajouter des beneficiaires à une assurance",
|
||||
* required={"password", "beneficiaries"},
|
||||
* @OA\Property(property="password",
|
||||
* type="string",
|
||||
* example="2021469",
|
||||
* description="Mot de passe de l'utilisateur assuré"
|
||||
* ),
|
||||
* @OA\Property(property="beneficiaries",
|
||||
* type="array",
|
||||
* description="Listes des beneficiaires ou ayants droit",
|
||||
* @OA\Items(ref="#/components/schemas/beneficiaries")
|
||||
* )
|
||||
* )
|
||||
*
|
||||
*/
|
||||
$this->validate($request, [
|
||||
'password' => 'required|string',
|
||||
'beneficiaries' => 'nullable|array',
|
||||
'beneficiaries.*.lastname' => 'required|string',
|
||||
'beneficiaries.*.gender' => 'required|in:M,F',
|
||||
'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today',
|
||||
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE',
|
||||
'beneficiaries.*.birthdate_proof' => 'required_if:beneficiaries.*.affiliation,CHILD|in:CERTIFIED_COPY,CERTIFICATE',
|
||||
'beneficiaries.*.birthdate_proof_doc' => 'required_if:beneficiaries.*.affiliation,CHILD|string',
|
||||
'beneficiaries.*.justice_doc' => 'nullable|string',
|
||||
'beneficiaries.*.marriage_certificate_doc' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_type' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_front' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_back' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
]);
|
||||
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
if (!in_array($subscription->state, [InsuranceSubscriptionState::UNDER_VALIDATION, InsuranceSubscriptionState::ACCEPTED])) {
|
||||
return $this->errorResponse(trans('errors.subscription_cannot_be_updated'));
|
||||
}
|
||||
$user = $subscription->user;
|
||||
$identification = $subscription->user->identification;
|
||||
|
||||
if (!isset($identification) || $identification->status == 0)
|
||||
return $this->errorResponse(trans('errors.user_identification_required'));
|
||||
|
||||
if (!$this->checkPassword($request->password, $user->encrypted_password, $user->salt))
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
|
||||
$nbOfBeneficiaries = $subscription->beneficiaries()->count();
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $subscription->network_id)->first();
|
||||
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', $subscription->number_of_months)->first();
|
||||
if (!isset($monthPrice))
|
||||
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$datetime = $this->getCurrentTimeByCountryCode($networkConfig->network->country->code_country);
|
||||
$subscription->number_of_beneficiaries += sizeof($request->input('beneficiaries'));
|
||||
|
||||
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($subscription, $request, $networkConfig, $monthPrice, $datetime);
|
||||
|
||||
$subscription->total_bonus_amount += $beneficiariesBonus;
|
||||
$subscription->created_at = $subscription->updated_at = $datetime;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'EDIT',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'insurance_subscription' => json_encode($subscription),
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_updated'), trans('messages.insurance_subscription_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $identification->gender), 'insurance_name' => $networkConfig->network->name])));
|
||||
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.insurance_subscription_updated_successful'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function generateSubscriptionID(): string
|
||||
{
|
||||
do {
|
||||
$code = $this->generateTransactionCode();
|
||||
$codeCorrect = NhInsurancesSubscription::where('insurance_subscription_id', $code)->count() < 0;
|
||||
} while ($codeCorrect);
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
||||
private function storeBeneficiariesAndGetBonus(NhInsurancesSubscription $subscription, Request $request,
|
||||
$networkConfig, NhMonthsPricesGrid $monthPrice, string $datetime)
|
||||
{
|
||||
$subscription->state = InsuranceSubscriptionState::UNDER_VALIDATION;
|
||||
|
||||
$beneficiariesBonus = 0;
|
||||
foreach ($request->input('beneficiaries') as $b) {
|
||||
$beneficiary = new NhInsurancesHavingRight($b);
|
||||
$beneficiary->insurance_subscription_id = $subscription->insurance_subscription_id;
|
||||
$beneficiary->bonus_amount = $this->calculateBeneficiaryBonusAmount($beneficiary, $networkConfig->yearsPricesGrid, $monthPrice);
|
||||
$beneficiariesBonus += $beneficiary->bonus_amount;
|
||||
if ($beneficiary->affiliation == InsuranceSubscriptionAffiliation::CHILD) {
|
||||
$beneficiary->marriage_certificate_doc = null;
|
||||
$beneficiary->id_document_type = null;
|
||||
$beneficiary->id_document_back = null;
|
||||
$beneficiary->id_document_front = null;
|
||||
} else {
|
||||
$beneficiary->justice_doc = null;
|
||||
$beneficiary->birthdate_proof_doc = null;
|
||||
$beneficiary->birthdate_proof = null;
|
||||
}
|
||||
$beneficiary->created_at = $beneficiary->updated_at = $datetime;
|
||||
$beneficiary->save();
|
||||
}
|
||||
return $beneficiariesBonus;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,859 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\InsuranceEvent;
|
||||
use App\InsuranceSubscriptionAffiliation;
|
||||
use App\InsuranceSubscriptionState;
|
||||
use App\Models\AgentPlus;
|
||||
use App\Models\CountriesCurrency;
|
||||
use App\Models\Identification;
|
||||
use App\Models\NhInsurance;
|
||||
use App\Models\NhInsurancesHavingRight;
|
||||
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 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 InsuranceSubscriptionController extends Controller
|
||||
{
|
||||
use Helper;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/insurances/subscriptions/bonus-amount",
|
||||
* summary="Calculer le montant de la prime",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(property="subscription_id",
|
||||
* type="integer",
|
||||
* example = 2,
|
||||
* description="ID de la souscription"
|
||||
* ),
|
||||
* @OA\Property(property="network_id",
|
||||
* type="integer",
|
||||
* example = 250,
|
||||
* description="ID du reseau de l'assureur"
|
||||
* ),
|
||||
* @OA\Property(property="month_price_id",
|
||||
* type="integer",
|
||||
* example=2,
|
||||
* description="ID de la grille de prix choisit lors de la souscription"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="beneficiaries",
|
||||
* description="Listes de quelques infos sur les beneficiaires ou ayants droit",
|
||||
* example = {{"birthdate":"1998-10-05","affiliation":"CHILD"}}
|
||||
* ),
|
||||
* ),
|
||||
* example = {"subscription_id":7,"network_id":250,"month_price_id":3,"beneficiaries":{{"birthdate":"1998-10-05","affiliation":"CHILD"}}}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":{"bonus_amount":75000,"bonus_amount_formatted":"75 000FCFA"},"error":null},
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function calculateBonusAmount(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'subscription_id' => 'nullable|integer|exists:nh_insurances_subscriptions,id',
|
||||
'network_id' => 'required_without:subscription_id|integer|exists:networks,id',
|
||||
'month_price_id' => 'required_without:subscription_id|integer|exists:nh_months_prices_grid,id',
|
||||
'beneficiaries' => 'nullable|array',
|
||||
'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today',
|
||||
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE'
|
||||
]);
|
||||
|
||||
if ($request->has('subscription_id')) {
|
||||
$subscription = NhInsurancesSubscription::findOrFail($request->input('subscription_id'));
|
||||
$networkConfig = $subscription->nhNetworkConfig;
|
||||
$monthPrice = $networkConfig->monthsPricesGrid()->where('number_of_months', $subscription->number_of_months)->first();
|
||||
|
||||
$beneficiaries = array_merge($subscription->beneficiaries->toArray(), $request->input('beneficiaries'));
|
||||
} else {
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
|
||||
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
|
||||
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
||||
|
||||
$monthPrice = $networkConfig->monthsPricesGrid()->where('id', $request->input('month_price_id'))->first();
|
||||
|
||||
$beneficiaries = $request->input('beneficiaries');
|
||||
}
|
||||
|
||||
if (!isset($monthPrice))
|
||||
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
|
||||
|
||||
$bonus = $monthPrice->min_amount;
|
||||
foreach ($beneficiaries as $b) {
|
||||
$bonus += $this->calculateBeneficiaryBonusAmount(new NhInsurancesHavingRight($b), $networkConfig->yearsPricesGrid, $monthPrice);
|
||||
}
|
||||
|
||||
return $this->successResponse([
|
||||
'bonus_amount' => $bonus,
|
||||
'bonus_amount_formatted' => $this->toMoneyWithNetwork($bonus, $request->input('network_id'))
|
||||
]);
|
||||
}
|
||||
|
||||
// Caculer le montant de la prime d'un ayant droit ou beneficiaire
|
||||
private function calculateBeneficiaryBonusAmount(NhInsurancesHavingRight $beneficiary, Collection $yearsPricesGrid,
|
||||
NhMonthsPricesGrid $monthPrice)
|
||||
{
|
||||
$bonus = 0;
|
||||
if ($beneficiary->affiliation == 'CHILD') {
|
||||
$age = date_diff(date_create($beneficiary->birthdate), date_create('now'))->y;
|
||||
$levels = $yearsPricesGrid->filter(function ($level) use ($age) {
|
||||
return $level->min_age <= $age && $level->max_age >= $age;
|
||||
});
|
||||
|
||||
foreach ($levels as $level) {
|
||||
$bonus += (100 + $level->markup_percentage) * $monthPrice->min_amount / 100;
|
||||
}
|
||||
} else {
|
||||
$bonus = $monthPrice->min_amount;
|
||||
}
|
||||
|
||||
return $bonus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/insurances/subscriptions",
|
||||
* summary="Souscrire à une assurance",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/subscribe_incurance"),
|
||||
* example = {"network_id":250,"user_id":20,"password" : "1234", "month_price_id":3,"beneficiaries":{{"lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05",
|
||||
* "affiliation":"CHILD","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png","marriage_certificate_doc":"mariage.png",
|
||||
* "id_document_type":"CNI","id_document_front":"cni_front.jpg","id_document_back":"cni_front.jpg"}}}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function subscribe(Request $request)
|
||||
{
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="subscribe_incurance",
|
||||
* title = "Souscription à une assurance",
|
||||
* required={"network_id", "user_id" , "password", "month_price_id", "beneficiaries"},
|
||||
* @OA\Property(property="network_id",
|
||||
* type="integer",
|
||||
* example = 250,
|
||||
* description="ID du reseau de l'assureur"
|
||||
* ),
|
||||
* @OA\Property(property="user_id",
|
||||
* type="integer",
|
||||
* example=300,
|
||||
* description="ID l'utilisateur identifié"
|
||||
* ),
|
||||
* @OA\Property(property="password",
|
||||
* type="string",
|
||||
* example="20214666",
|
||||
* description="Mot de passe de l'utilisateur identifié"
|
||||
* ),
|
||||
* @OA\Property(property="month_price_id",
|
||||
* type="integer",
|
||||
* example=2,
|
||||
* description="ID de la grille de prix choisit lors de la souscription"
|
||||
* ),
|
||||
* @OA\Property(property="beneficiaries",
|
||||
* type="array",
|
||||
* description="Listes des beneficiaires ou ayants droit",
|
||||
* @OA\Items(ref="#/components/schemas/beneficiaries")
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @OA\Schema(
|
||||
* schema="beneficiaries",
|
||||
* title = "Beneficiaires ou ayants droit",
|
||||
* required={"lastname","gender", "birthdate", "affiliation" },
|
||||
* @OA\Property(property="lastname",
|
||||
* type="string",
|
||||
* example = "Djery",
|
||||
* description="Noms"
|
||||
* ),
|
||||
* @OA\Property(property="firstname",
|
||||
* type="string",
|
||||
* example="DI",
|
||||
* description="Prenoms"
|
||||
* ),
|
||||
* @OA\Property(property="gender",
|
||||
* type="string",
|
||||
* enum = {"M" ,"F"},
|
||||
* example= "M",
|
||||
* description="Sexe"
|
||||
* ),
|
||||
* @OA\Property(property="birthdate",
|
||||
* type="string",
|
||||
* example= "2001-10-05",
|
||||
* description="Date de naissance"
|
||||
* ),
|
||||
* @OA\Property(property="affiliation",
|
||||
* type="string",
|
||||
* enum = {"CHILD" ,"SPOUSE"},
|
||||
* example= "CHILD",
|
||||
* description="Affiliation"
|
||||
* ),
|
||||
* @OA\Property(property="birthdate_proof",
|
||||
* type="string",
|
||||
* enum = {"CERTIFIED_COPY" ,"CERTIFICATE"},
|
||||
* example="CERTIFIED_COPY",
|
||||
* description="Copie légalisée acte de naissance ou certificat de naissance"
|
||||
* ),
|
||||
* @OA\Property(property="birthdate_proof_doc",
|
||||
* type="string",
|
||||
* example="birthdate_proof_doc.jpg",
|
||||
* description="Copie légalisée acte de naissance ou certificat de naissance"
|
||||
* ),
|
||||
* @OA\Property(property="justice_doc",
|
||||
* type="string",
|
||||
* example="justice_doc.jpg",
|
||||
* description="Une page document de justice si enfant adopté ou sous tutelle"
|
||||
* ),
|
||||
* @OA\Property(property="marriage_certificate_doc",
|
||||
* type="string",
|
||||
* example="marriage_certificate_doc.jpg",
|
||||
* description="Une page de l'acte de mariage"
|
||||
* ),
|
||||
* @OA\Property(property="id_document_type",
|
||||
* type="string",
|
||||
* example="CNI",
|
||||
* description="Type de piece d'identité cni , carte sejour, permis"
|
||||
* ),
|
||||
* @OA\Property(property="id_document_front",
|
||||
* type="string",
|
||||
* example="id_document_front.jpg",
|
||||
* description="Pièce identité recto"
|
||||
* ),
|
||||
* @OA\Property(property="id_document_back",
|
||||
* type="string",
|
||||
* example="id_document_back.jpg",
|
||||
* description="Pièce identité verso"
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
$this->validate($request, [
|
||||
'network_id' => 'required|integer|exists:networks,id',
|
||||
'user_id' => 'required|integer|exists:users,id',
|
||||
'password' => 'required|string',
|
||||
'month_price_id' => 'required|integer|exists:nh_months_prices_grid,id',
|
||||
'beneficiaries' => 'nullable|array',
|
||||
'beneficiaries.*.lastname' => 'required|string',
|
||||
'beneficiaries.*.gender' => 'required|in:M,F',
|
||||
'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today',
|
||||
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE',
|
||||
'beneficiaries.*.birthdate_proof' => 'required_if:beneficiaries.*.affiliation,CHILD|in:CERTIFIED_COPY,CERTIFICATE',
|
||||
'beneficiaries.*.birthdate_proof_doc' => 'required_if:beneficiaries.*.affiliation,CHILD|string',
|
||||
'beneficiaries.*.justice_doc' => 'nullable|string',
|
||||
'beneficiaries.*.marriage_certificate_doc' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_type' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_front' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_back' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
]);
|
||||
|
||||
$identification = Identification::where('id_user', $request->input('user_id'))->first();
|
||||
if (!isset($identification) || $identification->status == 0)
|
||||
return $this->errorResponse(trans('errors.user_identification_required'));
|
||||
|
||||
if (!$this->checkPassword($request->password, $identification->user->encrypted_password, $identification->user->salt))
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
|
||||
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
|
||||
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::AWAITING_FURTHER_INFORMATION])->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
|
||||
$insuredAge = date_diff(date_create($identification->birth_date), date_create('now'))->y;
|
||||
if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) {
|
||||
return $this->errorResponse(trans('errors.minimal_age_required'));
|
||||
}
|
||||
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $request->input('network_id'))->first();
|
||||
if (sizeof($request->input('beneficiaries')) > $networkConfig->max_number_of_beneficiaries)
|
||||
return $this->errorResponse(trans('errors.number_of_beneficiaries_exceeded'));
|
||||
|
||||
$monthPrice = $networkConfig->monthsPricesGrid()->where('id', $request->input('month_price_id'))->first();
|
||||
if (!isset($monthPrice))
|
||||
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$datetime = $this->getCurrentTimeByCountryCode($networkConfig->network->country->code_country);
|
||||
$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->bonus_amount = $monthPrice->min_amount;
|
||||
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($subscription, $request, $networkConfig, $monthPrice, $datetime);
|
||||
|
||||
$subscription->total_bonus_amount = ($subscription->bonus_amount + $beneficiariesBonus);
|
||||
$subscription->created_at = $subscription->updated_at = $datetime;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'ADD',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'insurance_subscription' => json_encode($subscription),
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription'), trans('messages.insurance_subscription_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $identification->gender), 'insurance_name' => $networkConfig->network->name])));
|
||||
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.insurance_subscription_successful'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function generateSubscriptionID(): string
|
||||
{
|
||||
do {
|
||||
$code = $this->generateTransactionCode();
|
||||
$codeCorrect = NhInsurancesSubscription::where('insurance_subscription_id', $code)->count() < 0;
|
||||
} while ($codeCorrect);
|
||||
return $code;
|
||||
}
|
||||
|
||||
private function storeBeneficiariesAndGetBonus(NhInsurancesSubscription $subscription, Request $request,
|
||||
$networkConfig, NhMonthsPricesGrid $monthPrice, string $datetime)
|
||||
{
|
||||
$subscription->state = InsuranceSubscriptionState::UNDER_VALIDATION;
|
||||
|
||||
$beneficiariesBonus = 0;
|
||||
foreach ($request->input('beneficiaries') as $b) {
|
||||
$beneficiary = new NhInsurancesHavingRight($b);
|
||||
$beneficiary->insurance_subscription_id = $subscription->insurance_subscription_id;
|
||||
$beneficiary->bonus_amount = $this->calculateBeneficiaryBonusAmount($beneficiary, $networkConfig->yearsPricesGrid, $monthPrice);
|
||||
$beneficiariesBonus += $beneficiary->bonus_amount;
|
||||
if ($beneficiary->affiliation == InsuranceSubscriptionAffiliation::CHILD) {
|
||||
$beneficiary->marriage_certificate_doc = null;
|
||||
$beneficiary->id_document_type = null;
|
||||
$beneficiary->id_document_back = null;
|
||||
$beneficiary->id_document_front = null;
|
||||
} else {
|
||||
$beneficiary->justice_doc = null;
|
||||
$beneficiary->birthdate_proof_doc = null;
|
||||
$beneficiary->birthdate_proof = null;
|
||||
}
|
||||
$beneficiary->created_at = $beneficiary->updated_at = $datetime;
|
||||
$beneficiary->save();
|
||||
}
|
||||
return $beneficiariesBonus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/insurances/subscriptions/upload-images",
|
||||
* summary="Uploader les images de la souscription à l'assurance",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\RequestBody(
|
||||
* description="Corps de la requete",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="multipart/form-data",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="files[]",
|
||||
* description = "Liste des documents à uploader",
|
||||
* type="array",
|
||||
* @OA\Items(type="string", format="binary")
|
||||
* )
|
||||
* ),
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function uploadImages(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'files' => 'required',
|
||||
'files.*' => 'mimes:jpeg,png,jpg,jpeg|max:10240' // 10 Mb
|
||||
]);
|
||||
|
||||
$files = [];
|
||||
if ($request->hasfile('files')) {
|
||||
foreach ($request->file('files') as $file) {
|
||||
$filename = $this->uploadImage($file, 'NH', 'insurances-subscriptions-docs');
|
||||
array_push($files, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->successResponse($files);
|
||||
}
|
||||
|
||||
public function validateSubscription($id, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'nh_validating_agent_id' => 'required_without:agent_id|nullable|integer|exists:nh_validating_agents,id',
|
||||
'agent_id' => 'required_without:nh_validating_agent_id|nullable|integer|exists:agents,id',
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
$datetime = $this->getCurrentTimeByCountryCode($subscription->network->country->code_country);
|
||||
|
||||
$subscription->state = InsuranceSubscriptionState::ACCEPTED;
|
||||
$subscription->updated_at = $datetime;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'EDIT',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'agent_id' => $request->input('agent_id'),
|
||||
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
||||
'insurance_subscription' => json_encode($subscription),
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_accepted'), trans('messages.insurance_subscription_accepted_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name]), trans('messages.insurance_subscription_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id])));
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.successful_transaction'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function rejectSubscription($id, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'nh_validating_agent_id' => 'required_without:agent_id|nullable|integer|exists:nh_validating_agents,id',
|
||||
'agent_id' => 'required_without:nh_validating_agent_id|nullable|integer|exists:agents,id',
|
||||
'reason' => 'required'
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
$datetime = $this->getCurrentTimeByCountryCode($subscription->network->country->code_country);
|
||||
|
||||
$subscription->reason = $request->input('reason');
|
||||
$subscription->state = InsuranceSubscriptionState::REJECTED;
|
||||
$subscription->updated_at = $datetime;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'EDIT',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'agent_id' => $request->input('agent_id'),
|
||||
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
||||
'insurance_subscription' => json_encode($subscription),
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_rejected'), trans('messages.insurance_subscription_rejected_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'reason' => $request->input('reason'), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name]), trans('messages.insurance_subscription_rejected_notification', ['subscription_id' => $subscription->insurance_subscription_id])));
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.successful_transaction'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* path="/insurances/subscriptions/{id}/pay",
|
||||
* summary="Activer et payer son assurance",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\Parameter(
|
||||
* parameter="id",
|
||||
* name="id",
|
||||
* description="ID de la souscription",
|
||||
* 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}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function paySubscription($id, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'password' => 'required|string',
|
||||
]);
|
||||
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
if ($subscription->state != InsuranceSubscriptionState::ACCEPTED) {
|
||||
return $this->errorResponse(trans('errors.subscription_cannot_be_paid'));
|
||||
}
|
||||
$insurance = NhInsurance::where('insurance_subscription_id', $subscription->insurance_subscription_id)->first();
|
||||
if (isset($insurance)) {
|
||||
return $this->errorResponse(trans('errors.subscription_be_already_paid'));
|
||||
}
|
||||
|
||||
$user = $subscription->user;
|
||||
if (!$this->checkPassword($request->password, $user->encrypted_password, $user->salt)) {
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
}
|
||||
|
||||
if ($user->balance_nano_health < $subscription->total_bonus_amount) {
|
||||
return $this->errorResponse(trans('errors.insufficient_balance'));
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$datetime = $this->getCurrentTimeByCountryCode($subscription->network->country->code_country);
|
||||
|
||||
$hyperviseur = AgentPlus::where('category', 'hyper')->where('network_id', $subscription->network_id)->firstOrFail();
|
||||
$walletHyperviseur = Wallet::where('id_networkAgent', $hyperviseur->network_agent_id)->firstOrFail();
|
||||
$walletHyperviseur->balance_princ += $subscription->total_bonus_amount;
|
||||
$walletHyperviseur->save();
|
||||
|
||||
$user->balance_nano_health -= $subscription->total_bonus_amount;
|
||||
$user->save();
|
||||
|
||||
$insuredId = $this->generateInsuredID();
|
||||
|
||||
NhInsurance::create([
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insured_id' => $insuredId,
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
'start_at' => $datetime,
|
||||
'end_at' => DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $subscription->number_of_months . 'months')
|
||||
]);
|
||||
|
||||
NhInsurancesPayment::create([
|
||||
'insured_id' => $insuredId,
|
||||
'amount' => $subscription->total_bonus_amount,
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
|
||||
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->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'insured_id' => $insuredId, 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name, 'months' => $subscription->number_of_months])));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private function generateInsuredID(): string
|
||||
{
|
||||
do {
|
||||
$code = $this->generateTransactionCode();
|
||||
$codeCorrect = NhInsurance::where('insured_id', $code)->count() < 0;
|
||||
} while ($codeCorrect);
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/insurances/subscriptions",
|
||||
* summary="Afficher la liste des souscriptions d'assurances ( par utilisateur , par type)",
|
||||
* tags={"Souscriptions à 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="type",
|
||||
* name="type",
|
||||
* description="Type de souscription",
|
||||
* in="query",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* enum={"ALL","EDITABLE"}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {
|
||||
* "status" : 200,
|
||||
* "response" : {{"id":1,"insurance_subscription_id":"BOKWRWZ245JX","network_id":250,"user_id":321,"number_of_months":3,
|
||||
* "bonus_amount":"150\u202f000\u00a0FCFA","number_of_beneficiaries":2,"total_bonus_amount":"495\u202f000\u00a0FCFA","state":"EN COURS DE VALIDATION",
|
||||
* "created_at":"2021-10-29T14:26:05.000000Z","updated_at":"2021-10-29T14:26:05.000000Z","start_at":null,"end_at":null,"reason":null,
|
||||
* "beneficiaries":{{"id":1,"insurance_subscription_id":"BOKWRWZ245JX","lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05T00:00:00.000000Z",
|
||||
* "affiliation":"CHILD","bonus_amount":"195\u202f000\u00a0FCFA","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png",
|
||||
* "marriage_certificate_doc":null,"id_document_type":null,"id_document_front":null,"id_document_back":null,"deleted_at":null,"created_at":"2021-10-29T14:26:05.000000Z",
|
||||
* "updated_at":"2021-10-29T14:26:05.000000Z","affiliation_tr":"ENFANT"}}}},
|
||||
* "error":null
|
||||
* }
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function getSubscriptions(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user_id' => 'nullable|integer|exists:users,id',
|
||||
'type' => 'nullable|in:ALL,EDITABLE'
|
||||
]);
|
||||
$user = User::findOrFail($request->input('user_id'));
|
||||
$currency_code = $user->network->country->currency_code;
|
||||
|
||||
$query = NhInsurancesSubscription::with(['network:id,name', 'beneficiaries']);
|
||||
|
||||
if ($request->has('user_id')) {
|
||||
$query = $query->where('user_id', $request->input('user_id'));
|
||||
}
|
||||
if ($request->has('type')) {
|
||||
$type = $request->input('type');
|
||||
if ($type == 'EDITABLE') {
|
||||
$query = $query->whereIn('state', [InsuranceSubscriptionState::UNDER_VALIDATION, InsuranceSubscriptionState::ACCEPTED]);
|
||||
}
|
||||
}
|
||||
|
||||
$subscriptions = $query->get();
|
||||
foreach ($subscriptions as $subscription) {
|
||||
$subscription->state = trans('states.' . $subscription->state);
|
||||
$subscription->bonus_amount = $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency_code);
|
||||
$subscription->total_bonus_amount = $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency_code);
|
||||
foreach ($subscription->beneficiaries as $b) {
|
||||
$b->bonus_amount = $this->toMoneyWithCurrencyCode($b->bonus_amount, $currency_code);
|
||||
}
|
||||
}
|
||||
return $this->successResponse($subscriptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* path="/insurances/subscriptions/{id}",
|
||||
* summary="Ajouter des ayants droits ou beneficiaires à une souscription",
|
||||
* tags={"Souscriptions à l'assurance"},
|
||||
* security={{"api_key":{}}},
|
||||
* @OA\Parameter(
|
||||
* parameter="id",
|
||||
* name="id",
|
||||
* description="ID de la souscription",
|
||||
* 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(ref="#/components/schemas/add_beneficiaries"),
|
||||
* example = {"password" : "1234", "beneficiaries":{{"lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05",
|
||||
* "affiliation":"CHILD","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png","marriage_certificate_doc":"mariage.png",
|
||||
* "id_document_type":"CNI","id_document_front":"cni_front.jpg","id_document_back":"cni_front.jpg"}}}
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="OK",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/ApiResponse",
|
||||
* example = {"status":200,"response":"Transaction réussie","error":null}
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function addBeneficiaries(Request $request, $id)
|
||||
{
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="add_beneficiaries",
|
||||
* title = "Ajouter des beneficiaires à une assurance",
|
||||
* required={"password", "beneficiaries"},
|
||||
* @OA\Property(property="password",
|
||||
* type="string",
|
||||
* example="2021469",
|
||||
* description="Mot de passe de l'utilisateur assuré"
|
||||
* ),
|
||||
* @OA\Property(property="beneficiaries",
|
||||
* type="array",
|
||||
* description="Listes des beneficiaires ou ayants droit",
|
||||
* @OA\Items(ref="#/components/schemas/beneficiaries")
|
||||
* )
|
||||
* )
|
||||
*
|
||||
*/
|
||||
$this->validate($request, [
|
||||
'password' => 'required|string',
|
||||
'beneficiaries' => 'nullable|array',
|
||||
'beneficiaries.*.lastname' => 'required|string',
|
||||
'beneficiaries.*.gender' => 'required|in:M,F',
|
||||
'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today',
|
||||
'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE',
|
||||
'beneficiaries.*.birthdate_proof' => 'required_if:beneficiaries.*.affiliation,CHILD|in:CERTIFIED_COPY,CERTIFICATE',
|
||||
'beneficiaries.*.birthdate_proof_doc' => 'required_if:beneficiaries.*.affiliation,CHILD|string',
|
||||
'beneficiaries.*.justice_doc' => 'nullable|string',
|
||||
'beneficiaries.*.marriage_certificate_doc' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_type' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_front' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
'beneficiaries.*.id_document_back' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
|
||||
]);
|
||||
|
||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||
if (!in_array($subscription->state, [InsuranceSubscriptionState::ACCEPTED])) {
|
||||
return $this->errorResponse(trans('errors.subscription_cannot_be_updated'));
|
||||
}
|
||||
$user = $subscription->user;
|
||||
$identification = $subscription->user->identification;
|
||||
|
||||
if (!isset($identification) || $identification->status == 0)
|
||||
return $this->errorResponse(trans('errors.user_identification_required'));
|
||||
|
||||
if (!$this->checkPassword($request->password, $user->encrypted_password, $user->salt))
|
||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||
|
||||
$nbOfBeneficiaries = $subscription->beneficiaries()->count();
|
||||
$networkConfig = NhNetworksConfig::where('network_id', $subscription->network_id)->first();
|
||||
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', $subscription->number_of_months)->first();
|
||||
if (!isset($monthPrice))
|
||||
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$datetime = $this->getCurrentTimeByCountryCode($networkConfig->network->country->code_country);
|
||||
$subscription->number_of_beneficiaries += sizeof($request->input('beneficiaries'));
|
||||
|
||||
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($subscription, $request, $networkConfig, $monthPrice, $datetime);
|
||||
|
||||
$subscription->total_bonus_amount += $beneficiariesBonus;
|
||||
$subscription->created_at = $subscription->updated_at = $datetime;
|
||||
$subscription->save();
|
||||
|
||||
NhInsurancesSubscriptionsHistory::create([
|
||||
'action' => 'EDIT',
|
||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||
'insurance_subscription_state' => $subscription->state,
|
||||
'insurance_subscription' => json_encode($subscription),
|
||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||
]);
|
||||
|
||||
Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_updated'), trans('messages.insurance_subscription_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id,
|
||||
'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||
'gender' => trans('states.' . $identification->gender), 'insurance_name' => $networkConfig->network->name])));
|
||||
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.insurance_subscription_updated_successful'));
|
||||
} catch (Throwable $e) {
|
||||
Log::error($e->getMessage() . '\n' . $e->getTraceAsString());
|
||||
DB::rollBack();
|
||||
return $this->errorResponse(trans('errors.unexpected_error'), 500);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
abstract class InsuranceState
|
||||
{
|
||||
const PAID = 'PAID';
|
||||
const UNDER_STOPPING = 'UNDER_STOPPING';
|
||||
const STOPPED = 'STOPPED';
|
||||
}
|
|
@ -5,9 +5,7 @@ namespace App;
|
|||
abstract class InsuranceSubscriptionState
|
||||
{
|
||||
const UNDER_VALIDATION = 'UNDER_VALIDATION';
|
||||
const AWAITING_FURTHER_INFORMATION = 'AWAITING_FURTHER_INFORMATION';
|
||||
const ACCEPTED = 'ACCEPTED';
|
||||
const REJECTED = 'REJECTED';
|
||||
const CURRENT = 'CURRENT';
|
||||
const UNDER_STOPPING = 'UNDER_STOPPING';
|
||||
const STOPPED = 'STOPPED';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class AgentPlus
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $uid
|
||||
* @property string $firstname
|
||||
* @property string $adresse
|
||||
* @property string $lastname
|
||||
* @property string $email
|
||||
* @property float $longitude
|
||||
* @property float $latitude
|
||||
* @property string $phone
|
||||
* @property int $active
|
||||
* @property Carbon $created
|
||||
* @property Carbon $openHours
|
||||
* @property Carbon $closeHours
|
||||
* @property float $solde
|
||||
* @property int $etat
|
||||
* @property string $network
|
||||
* @property string $country
|
||||
* @property string $code_parrain
|
||||
* @property string $category
|
||||
* @property string $code_membre
|
||||
* @property int $number_geoBysuper
|
||||
* @property int $network_id
|
||||
* @property string $code_dial
|
||||
* @property string $transactionNumber
|
||||
* @property int $network_agent_id
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class AgentPlus extends Model
|
||||
{
|
||||
public $incrementing = false;
|
||||
public $timestamps = false;
|
||||
protected $table = 'agent_plus';
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'longitude' => 'float',
|
||||
'latitude' => 'float',
|
||||
'active' => 'int',
|
||||
'solde' => 'float',
|
||||
'etat' => 'int',
|
||||
'number_geoBysuper' => 'int',
|
||||
'network_id' => 'int',
|
||||
'network_agent_id' => 'int'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'created',
|
||||
'openHours',
|
||||
'closeHours'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'uid',
|
||||
'firstname',
|
||||
'adresse',
|
||||
'lastname',
|
||||
'email',
|
||||
'longitude',
|
||||
'latitude',
|
||||
'phone',
|
||||
'active',
|
||||
'created',
|
||||
'openHours',
|
||||
'closeHours',
|
||||
'solde',
|
||||
'etat',
|
||||
'network',
|
||||
'country',
|
||||
'code_parrain',
|
||||
'category',
|
||||
'code_membre',
|
||||
'number_geoBysuper',
|
||||
'network_id',
|
||||
'code_dial',
|
||||
'transactionNumber',
|
||||
'network_agent_id'
|
||||
];
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class NhInsurance
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $insurance_subscription_id
|
||||
* @property string $insured_id
|
||||
* @property Carbon|null $start_at
|
||||
* @property Carbon|null $end_at
|
||||
* @property string $state
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class NhInsurance extends Model
|
||||
{
|
||||
protected $table = 'nh_insurances';
|
||||
|
||||
protected $dates = [
|
||||
'start_at',
|
||||
'end_at'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'insurance_subscription_id',
|
||||
'insured_id',
|
||||
'start_at',
|
||||
'end_at',
|
||||
'state'
|
||||
];
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class NhInsurancesPayment
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $insured_id
|
||||
* @property float $amount
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class NhInsurancesPayment extends Model
|
||||
{
|
||||
protected $table = 'nh_insurances_payments';
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'float'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'insured_id',
|
||||
'amount'
|
||||
];
|
||||
}
|
|
@ -16,6 +16,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property string $action
|
||||
* @property string $insurance_subscription_id
|
||||
* @property int|null $agent_id
|
||||
* @property int|null $nh_validating_agent_id
|
||||
* @property string $insurance_subscription_state
|
||||
* @property string $insurance_subscription
|
||||
* @property Carbon $created_at
|
||||
|
@ -28,13 +29,15 @@ class NhInsurancesSubscriptionsHistory extends Model
|
|||
protected $table = 'nh_insurances_subscriptions_history';
|
||||
|
||||
protected $casts = [
|
||||
'agent_id' => 'int'
|
||||
'agent_id' => 'int',
|
||||
'nh_validating_agent_id' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'action',
|
||||
'insurance_subscription_id',
|
||||
'agent_id',
|
||||
'nh_validating_agent_id',
|
||||
'insurance_subscription_state',
|
||||
'insurance_subscription'
|
||||
];
|
||||
|
|
|
@ -21,14 +21,15 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property string|null $password
|
||||
* @property string|null $salt
|
||||
* @property string $token
|
||||
* @property string $role
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class NhValidatingDoctor extends Model
|
||||
class NhValidatingAgent extends Model
|
||||
{
|
||||
protected $table = 'nh_validating_doctors';
|
||||
protected $table = 'nh_validating_agents';
|
||||
|
||||
protected $casts = [
|
||||
'nh_network_config_id' => 'int'
|
|
@ -35,6 +35,7 @@ use Laravel\Lumen\Auth\Authorizable;
|
|||
* @property int $group_id
|
||||
* @property float $balance_credit
|
||||
* @property float $balance_epargne
|
||||
* @property float $balance_nano_health
|
||||
* @property Carbon|null $date_adhesion
|
||||
* @property int|null $id_bank_country
|
||||
* @property string|null $iban
|
||||
|
@ -55,6 +56,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
'group_id' => 'int',
|
||||
'balance_credit' => 'float',
|
||||
'balance_epargne' => 'float',
|
||||
'balance_nano_health' => 'float',
|
||||
'id_bank_country' => 'int'
|
||||
];
|
||||
|
||||
|
@ -99,6 +101,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||
'group_id',
|
||||
'balance_credit',
|
||||
'balance_epargne',
|
||||
'balance_nano_health' => 'float',
|
||||
'date_adhesion',
|
||||
'id_bank_country',
|
||||
'iban'
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Wallet
|
||||
*
|
||||
* @property int $id
|
||||
* @property float $balance_princ
|
||||
* @property float $balance_com
|
||||
* @property int $id_networkAgent
|
||||
* @property Carbon $created_date
|
||||
*
|
||||
* @property NetworksAgent $networks_agent
|
||||
* @property Collection|WalletTransaction[] $wallet_transactions
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Wallet extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'wallets';
|
||||
protected $casts = [
|
||||
'balance_princ' => 'float',
|
||||
'balance_com' => 'float',
|
||||
'id_networkAgent' => 'int'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'created_date'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'balance_princ',
|
||||
'balance_com',
|
||||
'id_networkAgent',
|
||||
'created_date'
|
||||
];
|
||||
|
||||
public function networks_agent()
|
||||
{
|
||||
return $this->belongsTo(NetworksAgent::class, 'id_networkAgent');
|
||||
}
|
||||
|
||||
public function wallet_transactions()
|
||||
{
|
||||
return $this->hasMany(WalletTransaction::class, 'id_wallet');
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -8,6 +8,8 @@ use App\Models\CountriesCurrency;
|
|||
use App\Models\Country;
|
||||
use Brick\Money\Context\AutoContext;
|
||||
use Brick\Money\Money;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
@ -117,8 +119,8 @@ trait Helper
|
|||
// Obtenir l'heure en fonction du code du pays de l'utilisateur
|
||||
public function getCurrentTimeByCountryCode($country_code = 'GA')
|
||||
{
|
||||
$timezone = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $country_code);
|
||||
$date = (sizeof($timezone) > 0) ? new \DateTime('now', new \DateTimeZone($timezone[0])) : new \DateTime();
|
||||
$timezone = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code);
|
||||
$date = (sizeof($timezone) > 0) ? new DateTime('now', new DateTimeZone($timezone[0])) : new \DateTime();
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@ class UpdateActorInNhInsurancesSubscriptionsHistoryTable extends Migration
|
|||
{
|
||||
Schema::table('nh_insurances_subscriptions_history', function (Blueprint $table) {
|
||||
$table->dropColumn('nh_validating_doctor_id');
|
||||
if (!Schema::hasColumn('nh_insurances_subscriptions_history', 'agent_id')) {
|
||||
$table->integer('agent_id')->nullable()->after('insurance_subscription_id')
|
||||
->comment("ID de l'agent acteur de l'operation");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class RenameNhValidatingDoctorsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
Schema::rename('nh_validating_doctors', 'nh_validating_agents');
|
||||
|
||||
Schema::table('nh_validating_agents', function (Blueprint $table) {
|
||||
$table->enum('role', ['DOCTOR', 'AGENT'])->default('DOCTOR')->after('token');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
Schema::rename('nh_validating_agents', 'nh_validating_doctors');
|
||||
Schema::table('nh_validating_agents', function (Blueprint $table) {
|
||||
$table->dropColumn('role');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddNhValidatingAgentIdInNhInsurancesSubscriptionsHistoryTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_insurances_subscriptions_history', function (Blueprint $table) {
|
||||
$table->integer('nh_validating_agent_id')->nullable()->after('agent_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('nh_insurances_subscriptions_history', function (Blueprint $table) {
|
||||
$table->dropColumn('nh_validating_agent_id');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateNhInsurancesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('nh_insurances', function (Blueprint $table) {
|
||||
$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->enum('state', ['PAID', 'UNDER_STOPPING', 'STOPPED', 'ENDED'])->default('PAID');
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('nh_insurances');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateNhInsurancesSubscriptionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('nh_insurances_subscriptions', function (Blueprint $table) {
|
||||
$table->dropColumn(['start_at', 'end_at']);
|
||||
DB::statement("ALTER TABLE nh_insurances_subscriptions MODIFY state
|
||||
ENUM('UNDER_VALIDATION', 'ACCEPTED', 'REJECTED', 'AWAITING_FURTHER_INFORMATION') DEFAULT 'UNDER_VALIDATION' NOT NULL;");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('nh_insurances_subscriptions', function (Blueprint $table) {
|
||||
$table->dateTime('start_at')->nullable()->comment("Date de debut de l'assurance");
|
||||
$table->dateTime('end_at')->nullable()->comment("Date d'echeance");
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBalanceNanoHealthInUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->decimal('balance_nano_health', 10, 2)->default(0)->after('balance_epargne');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('balance_nano_health');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateAgentPlusView extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::statement("CREATE OR REPLACE VIEW `agent_plus` AS
|
||||
SELECT
|
||||
`ag`.`id` AS `id`,
|
||||
`ag`.`uid` AS `uid`,
|
||||
`ag`.`firstname` AS `firstname`,
|
||||
`ag`.`adresse` AS `adresse`,
|
||||
`ag`.`lastname` AS `lastname`,
|
||||
`ag`.`email` AS `email`,
|
||||
`ag`.`encrypted_password` AS `encrypted_password`,
|
||||
`ag`.`salt` AS `salt`,
|
||||
`ag`.`longitude` AS `longitude`,
|
||||
`ag`.`latitude` AS `latitude`,
|
||||
`na`.`phone` AS `phone`,
|
||||
`ag`.`active` AS `active`,
|
||||
`ag`.`date_created` AS `created`,
|
||||
`ag`.`open_hours` AS `openHours`,
|
||||
`ag`.`close_hours` AS `closeHours`,
|
||||
`na`.`solde` AS `solde`,
|
||||
`na`.`etat` AS `etat`,
|
||||
`ne`.`name` AS `network`,
|
||||
`cti`.`name` AS `country`,
|
||||
`cg`.`code_parrain` AS `code_parrain`,
|
||||
`cg`.`category` AS `category`,
|
||||
`cg`.`code_membre` AS `code_membre`,
|
||||
`ag`.`number_geoBysuper` AS `number_geoBysuper`,
|
||||
`ag`.`number_super` AS `number_super`,
|
||||
`ne`.`id` AS `network_id`,
|
||||
`ne`.`country_id` AS `country_id`,
|
||||
`cti`.`code_dial` AS `code_dial`,
|
||||
`na`.`transactionNumber` AS `transactionNumber`,
|
||||
`na`.`id` AS `network_agent_id`
|
||||
FROM
|
||||
((((`agents` `ag`
|
||||
JOIN `networks_agents` `na` ON ((`na`.`agent_id` = `ag`.`id`)))
|
||||
JOIN `networks` `ne` ON ((`ne`.`id` = `na`.`network_id`)))
|
||||
JOIN `countries` `cti` ON ((`cti`.`id` = `ne`.`country_id`)))
|
||||
JOIN `codeGenerer` `cg` ON ((`cg`.`id` = `na`.`codeGenerer_id`)));");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateNhInsurancesPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('nh_insurances_payments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('insured_id')->comment("Numero de l'assuré");
|
||||
$table->decimal('amount', 10, 2)->comment("Montant payé");
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('nh_insurances_payments');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateNhInfosInsurancesView extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::statement("CREATE OR REPLACE VIEW nh_infos_insurances AS
|
||||
SELECT nhi.* ,u.lastname , u.phone , u.email , nis.network_id, nis.user_id, nis.number_of_months, nis.bonus_amount , nis.number_of_beneficiaries , nis.total_bonus_amount,
|
||||
cc.currency_code FROM nh_insurances nhi JOIN nh_insurances_subscriptions nis on nhi.insurance_subscription_id = nis.insurance_subscription_id
|
||||
JOIN users u ON nis.user_id = u.id JOIN networks n on nis.network_id = n.id JOIN countries_currencies cc on n.country_id = cc.id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -27,5 +27,7 @@ return [
|
|||
'incorrect_selected_amount' => 'The amount selected is incorrect',
|
||||
'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",
|
||||
"subscription_cannot_be_updated" => "This subscription request cannot be modified"
|
||||
"subscription_cannot_be_updated" => "This subscription request cannot be modified",
|
||||
"subscription_cannot_be_paid" => "This subscription request cannot be paid",
|
||||
'subscription_be_already_paid' => "This subscription has already been paid. You can just renew it"
|
||||
];
|
||||
|
|
|
@ -33,7 +33,6 @@ Your application has been accepted.
|
|||
Application information :
|
||||
- ID: :subscription_id
|
||||
- Name of the insurance: :insurance_name
|
||||
- Policyholder number: :user_code
|
||||
- Amount to be paid: :bonus_amount
|
||||
- Number of beneficiaries : :number_of_beneficiaries
|
||||
|
||||
|
@ -55,5 +54,17 @@ Your application has been rejected.
|
|||
'insurance_subscription_rejected_notification' => "Your :subscription_id application has been rejected",
|
||||
"insurance_subscription_successful" => "Insurance subscription successful",
|
||||
'insurance_subscription_updated' => "Insurance subscription update",
|
||||
"insurance_subscription_updated_successful" => "Insurance subscription update successful"
|
||||
"insurance_subscription_updated_successful" => "Insurance subscription update successful",
|
||||
'insurance_subscription_paid' => "Insurance subscription paid",
|
||||
'insurance_subscription_paid_mail' => ":gender :name ,
|
||||
|
||||
Your insurance has been validated.
|
||||
Insurance information :
|
||||
- ID: :subscription_id
|
||||
- Insurance number: :insured_id
|
||||
- Insurance name: :insurance_name
|
||||
- Amount: :bonus_amount
|
||||
- Number of beneficiaries : :number_of_beneficiaries
|
||||
- Number of months: :months
|
||||
",
|
||||
];
|
||||
|
|
|
@ -3,14 +3,14 @@ return [
|
|||
"UNDER_VALIDATION" => "UNDER VALIDATION",
|
||||
"ACCEPTED" => "ACCEPTED",
|
||||
"REJECTED" => "REJECTED",
|
||||
"CURRENT" => "CURRENT",
|
||||
"PAID" => "PAID",
|
||||
"UNDER_STOPPING" => "UNDER STOPPING",
|
||||
"STOPPED" => "STOPPED",
|
||||
"CHILD" => "CHILD",
|
||||
"SPOUSE" => "SPOUSE",
|
||||
"M" => "Mr",
|
||||
"F" => "Mrs",
|
||||
"TRAITEE" => "TREATED",
|
||||
"groupe" => 'GROUP',
|
||||
"AWAITING_FURTHER_INFORMATION" => "AWAITING FURTHER INFORMATION",
|
||||
"ENDED" => 'ENDED',
|
||||
"individuel" => "INDIVIDUAL"
|
||||
];
|
||||
|
|
|
@ -27,5 +27,7 @@ return [
|
|||
'incorrect_selected_amount' => 'Le montant choisi est incorrect',
|
||||
'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",
|
||||
"subscription_cannot_be_updated" => "Cette demande de souscription ne peut etre modifiée"
|
||||
"subscription_cannot_be_updated" => "Cette demande de souscription ne peut etre modifiée",
|
||||
"subscription_cannot_be_paid" => "Cette demande de souscription ne peut etre payée",
|
||||
'subscription_be_already_paid' => "Cette souscription a déjà été payée. Vous pouvez juste la renouveler"
|
||||
];
|
||||
|
|
|
@ -33,7 +33,6 @@ Votre demande de souscription a été acceptée.
|
|||
Informations de la demande :
|
||||
- ID : :subscription_id
|
||||
- Nom de l'assurance : :insurance_name
|
||||
- Numéro d'assuré : :user_code
|
||||
- Montant à payer : :bonus_amount
|
||||
- Nombre d'ayants droit : :number_of_beneficiaries
|
||||
|
||||
|
@ -55,5 +54,17 @@ Votre demande de souscription a été rejetée.
|
|||
'insurance_subscription_rejected_notification' => "Votre demande de souscription :subscription_id a été rejetée.",
|
||||
"insurance_subscription_successful" => "Souscription à l'assurance réussie",
|
||||
'insurance_subscription_updated' => "Mise à jour de la souscription à l'assurance",
|
||||
"insurance_subscription_updated_successful" => "Mise à jour de la souscription à l'assurance réussie"
|
||||
"insurance_subscription_updated_successful" => "Mise à jour de la souscription à l'assurance réussie",
|
||||
'insurance_subscription_paid' => "Souscription à l'assurance payée",
|
||||
'insurance_subscription_paid_mail' => ":gender :name ,
|
||||
|
||||
Votre assurance a été validée.
|
||||
Informations de l'assurance :
|
||||
- ID : :subscription_id
|
||||
- Numéro d'assuré : :insured_id
|
||||
- Nom de l'assurance : :insurance_name
|
||||
- Montant : :bonus_amount
|
||||
- Nombre d'ayants droit : :number_of_beneficiaries
|
||||
- Nombre de mois : :months
|
||||
",
|
||||
];
|
||||
|
|
|
@ -3,14 +3,14 @@ return [
|
|||
"UNDER_VALIDATION" => "EN COURS DE VALIDATION",
|
||||
"ACCEPTED" => "ACCEPTÉE",
|
||||
"REJECTED" => "REJETÉE",
|
||||
"CURRENT" => "EN COURS",
|
||||
"PAID" => "PAYÉE",
|
||||
"UNDER_STOPPING" => "EN COURS D'ARRÊT",
|
||||
"STOPPED" => "ARRÊTÉE",
|
||||
"CHILD" => "ENFANT",
|
||||
"SPOUSE" => "CONJOINT",
|
||||
"M" => "M",
|
||||
"F" => "Mme",
|
||||
"TRAITEE" => "TRAITÉE",
|
||||
"groupe" => 'GROUPE',
|
||||
"AWAITING_FURTHER_INFORMATION" => "EN ATTENTE D'INFORMATIONS COMPLÉMENTAIRES",
|
||||
"ENDED" => 'TERMINÉE',
|
||||
"individuel" => "INDIVIDUEL"
|
||||
];
|
||||
|
|
|
@ -17,13 +17,14 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
|
|||
$router->group(['prefix' => '/insurances'], function () use ($router) {
|
||||
$router->get('', 'InsuranceController@getInsurances');
|
||||
$router->group(['prefix' => '/subscriptions'], function () use ($router) {
|
||||
$router->post('bonus-amount', 'InsuranceController@calculateBonusAmount');
|
||||
$router->post('upload-images', 'InsuranceController@uploadImages');
|
||||
$router->post('', 'InsuranceController@subscribe');
|
||||
$router->put('{id}/validate', 'InsuranceController@validateSubscription');
|
||||
$router->put('{id}/reject', 'InsuranceController@rejectSubscription');
|
||||
$router->get('', 'InsuranceController@getSubscriptions');
|
||||
$router->put('{id}', 'InsuranceController@addBeneficiaries');
|
||||
$router->post('bonus-amount', 'InsuranceSubscriptionController@calculateBonusAmount');
|
||||
$router->post('upload-images', 'InsuranceSubscriptionController@uploadImages');
|
||||
$router->post('', 'InsuranceSubscriptionController@subscribe');
|
||||
$router->put('{id}/validate', 'InsuranceSubscriptionController@validateSubscription');
|
||||
$router->put('{id}/reject', 'InsuranceSubscriptionController@rejectSubscription');
|
||||
$router->put('{id}/pay', 'InsuranceSubscriptionController@paySubscription');
|
||||
$router->get('', 'InsuranceSubscriptionController@getSubscriptions');
|
||||
$router->put('{id}', 'InsuranceSubscriptionController@addBeneficiaries');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue