diff --git a/app/Events/InsuranceEvent.php b/app/Events/InsuranceEvent.php index f8740f2..423c78e 100644 --- a/app/Events/InsuranceEvent.php +++ b/app/Events/InsuranceEvent.php @@ -19,8 +19,8 @@ class InsuranceEvent extends Event * * @return void */ - public function __construct(NhInsurancesSubscription $subscription, string $mailTitle, string $mailMessage, - string $notification = null) + public function __construct($subscription, string $mailTitle, string $mailMessage, + string $notification = null) { // $this->subscription = $subscription; diff --git a/app/Exceptions/AppException.php b/app/Exceptions/AppException.php new file mode 100644 index 0000000..0d45cbe --- /dev/null +++ b/app/Exceptions/AppException.php @@ -0,0 +1,25 @@ +code}]: {$this->message}\n"; + } + +} diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index c1c1395..b4c14bb 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -136,11 +136,16 @@ class Handler extends ExceptionHandler return $this->errorResponse($message, $code); } - if (env('APP_DEBUG', false)) { + if ($exception instanceof AppException) { + return $this->errorResponse($exception->getMessage(), $exception->getCode()); + } + + + if (config('services.app_debug')) { return parent::render($request, $exception); } - return $this->errorResponse(trans('errors.unexpected_error'), - Response::HTTP_INTERNAL_SERVER_ERROR); + return $this->errorResponse($exception->getMessage() ?? trans('errors.unexpected_error'), + $exception->getCode() ?? Response::HTTP_INTERNAL_SERVER_ERROR); } } diff --git a/app/Http/Controllers/AuthorizationCareRequestController.php b/app/Http/Controllers/AuthorizationCareRequestController.php index 2079726..acb45a6 100755 --- a/app/Http/Controllers/AuthorizationCareRequestController.php +++ b/app/Http/Controllers/AuthorizationCareRequestController.php @@ -96,6 +96,7 @@ class AuthorizationCareRequestController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function store(Request $request) { @@ -114,8 +115,7 @@ class AuthorizationCareRequestController extends Controller } $user = $insurance->user; - if (!checkPassword($password, $user->encrypted_password, $user->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); + $this->userCredentialsVerification($user, $request->input('password')); $beneficiary_id = $request->input('beneficiary_id'); if (!empty($beneficiary_id)) { diff --git a/app/Http/Controllers/HealthCareSheetController.php b/app/Http/Controllers/HealthCareSheetController.php index 52d5e2c..5a852c2 100755 --- a/app/Http/Controllers/HealthCareSheetController.php +++ b/app/Http/Controllers/HealthCareSheetController.php @@ -529,6 +529,7 @@ class HealthCareSheetController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function storeHealthCareSheetConsultation(Request $request) { @@ -629,9 +630,7 @@ class HealthCareSheetController extends Controller return $this->errorResponse(trans('errors.not_insured')); } - $agent = AgentPlus::where('network_agent_id', $request->input('network_agent_id'))->first(); - if (!checkPassword($request->input('password'), $agent->encrypted_password, $agent->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); + $this->agentCredentialsVerification($request->input('network_agent_id'), $request->input('password')); $beneficiary_id = $request->input('beneficiary_id'); if (!empty($beneficiary_id)) { @@ -845,6 +844,7 @@ class HealthCareSheetController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function storeHealthCareSheetExecution(Request $request) { @@ -892,10 +892,7 @@ class HealthCareSheetController extends Controller return $this->errorResponse("Cette feuille de soin ne provient pas d'une consultation"); } - $agent = AgentPlus::where('network_agent_id', $request->input('network_agent_id'))->first(); - if (!checkPassword($request->input('password'), $agent->encrypted_password, $agent->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); - + $this->agentCredentialsVerification($request->input('network_agent_id'), $request->input('password')); $nhConfig = NhNetworksConfig::where('network_id', $sheet->insurance->network_id)->first(); if (!isset($nhConfig)) { @@ -1523,6 +1520,7 @@ class HealthCareSheetController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function updateHealthCareSheet(Request $request, $id) { @@ -1669,10 +1667,7 @@ class HealthCareSheetController extends Controller return $this->errorResponse(__('errors.unauthorized_to_update_sheet'), 403); } - $agent = AgentPlus::where('network_agent_id', $request->input('network_agent_id'))->first(); - if (!checkPassword($request->input('password'), $agent->encrypted_password, $agent->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); - + $this->agentCredentialsVerification($request->input('network_agent_id'), $request->input('password')); $beneficiary_id = $request->input('beneficiary_id'); if (!empty($beneficiary_id)) { diff --git a/app/Http/Controllers/InsuranceController.php b/app/Http/Controllers/InsuranceController.php index a7c80fa..0f57ac7 100644 --- a/app/Http/Controllers/InsuranceController.php +++ b/app/Http/Controllers/InsuranceController.php @@ -6,13 +6,18 @@ use App\Events\InsuranceEvent; use App\InsuranceAction; use App\InsuranceState; use App\InsuranceSubscriptionState; +use App\Models\AgentPlus; use App\Models\CountriesCurrency; use App\Models\NhInsurance; use App\Models\NhInsurancesHavingRight; +use App\Models\NhInsurancesPayment; use App\Models\NhInsurancesSubscription; use App\Models\NhInsurancesSubscriptionsHistory; use App\Models\NhNetworksConfig; +use App\Models\Wallet; use App\Traits\Helper; +use DateTime; +use Exception; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; @@ -235,6 +240,7 @@ class InsuranceController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function addBeneficiaries(Request $request, $id) { @@ -273,20 +279,11 @@ class InsuranceController extends Controller ]); $insurance = NhInsurance::findOrFail($id); - $latestSubscription = NhInsurancesSubscription::where('network_id', $request->input('network_id'))->where('user_id', $request->input('user_id')) - ->whereIn('state', [InsuranceSubscriptionState::UNDER_VALIDATION, InsuranceSubscriptionState::AWAITING_FURTHER_INFORMATION])->orderBy('created_at', 'DESC')->first(); - - if (isset($latestSubscription)) { - return $this->errorResponse(trans('errors.subscription_cannot_be_submitted', ['state' => mb_strtolower(trans('states.' . $latestSubscription->state), 'UTF-8')])); - } + $this->insuranceVerification($insurance); + $this->latestSubscriptionVerification($request->input('network_id'), $request->input('user_id')); $user = $insurance->user; $identification = $insurance->user->identification; - - if (!isset($identification) || $identification->status == 0) - return $this->errorResponse(trans('errors.user_identification_required')); - - if (!checkPassword($request->password, $user->encrypted_password, $user->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); + $this->userCredentialsVerification($user, $request->input('password')); $nbOfBeneficiaries = $insurance->beneficiaries()->count(); $networkConfig = NhNetworksConfig::where('network_id', $insurance->network_id)->first(); @@ -315,7 +312,7 @@ class InsuranceController extends Controller // Ajouter les nouveaux ayant droit $beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($newSubscription, $request, $networkConfig, $monthPrice, $datetime); - $newSubscription->total_bonus_amount = $beneficiariesBonus; + $newSubscription->total_bonus_amount = ($newSubscription->bonus_amount + $beneficiariesBonus); $newSubscription->created_at = $newSubscription->updated_at = $datetime; $newSubscription->save(); @@ -375,6 +372,7 @@ class InsuranceController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function deleteBeneficiaries(Request $request, $id) { @@ -403,14 +401,9 @@ class InsuranceController extends Controller ]); $insurance = NhInsurance::findOrFail($id); + $this->insuranceVerification($insurance); $user = $insurance->user; - $identification = $insurance->user->identification; - - if (!isset($identification) || $identification->status == 0) - return $this->errorResponse(trans('errors.user_identification_required')); - - if (!checkPassword($request->password, $user->encrypted_password, $user->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); + $this->userCredentialsVerification($user, $request->input('password')); $current_beneficiaries_ids = array_map(function ($b) { return $b['id']; @@ -486,10 +479,11 @@ class InsuranceController extends Controller * description="OK", * @OA\JsonContent( * ref="#/components/schemas/ApiResponse", - * example = {"status":200,"response":"Suprresion réussie","error":null} + * example = {"status":200,"response":"Operation réussie","error":null} * ) * ) * ) + * @throws Exception */ public function stopInsurance(Request $request, $id) { @@ -498,22 +492,11 @@ class InsuranceController extends Controller ]); $insurance = NhInsurance::findOrFail($id); - $latestSubscription = NhInsurancesSubscription::where('network_id', $insurance->network_id)->where('user_id', $insurance->user_id) - ->whereIn('state', [InsuranceSubscriptionState::UNDER_VALIDATION, InsuranceSubscriptionState::AWAITING_FURTHER_INFORMATION])->orderBy('created_at', 'DESC')->first(); - - if (isset($latestSubscription)) { - return $this->errorResponse(trans('errors.subscription_cannot_be_submitted', ['state' => mb_strtolower(trans('states.' . $latestSubscription->state), 'UTF-8')])); - } - $user = $insurance->user; $identification = $insurance->user->identification; - - if (!isset($identification) || $identification->status == 0) - return $this->errorResponse(trans('errors.user_identification_required')); - - if (!checkPassword($request->password, $user->encrypted_password, $user->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); - + $this->userCredentialsVerification($user, $request->input('password')); + $this->insuranceVerification($insurance); + $this->latestSubscriptionVerification($insurance->network_id, $insurance->user_id); try { DB::beginTransaction(); $datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country); @@ -545,4 +528,139 @@ class InsuranceController extends Controller } } + /** + * @OA\Put( + * path="/insurances/{id}/renew", + * summary="Renouveller son assurance", + * tags={"Assurances"}, + * security={{"api_key":{}}}, + * @OA\Parameter( + * parameter="id", + * name="id", + * description="ID de l'assurance", + * 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", + * description = "Mot de passe", + * type="string", + * example= "12345" + * ), + * ), + * ), + * ), + * @OA\Response( + * response=200, + * description="OK", + * @OA\JsonContent( + * ref="#/components/schemas/ApiResponse", + * example = {"status":200,"response":"Operation réussie","error":null} + * ) + * ) + * ) + * @throws Exception + */ + public function renewInsurance(Request $request, $id) + { + $this->validate($request, [ + 'password' => 'required|string', + ]); + + $insurance = NhInsurance::findOrFail($id); + if ($insurance->state != InsuranceState::STOPPED) { + return $this->errorResponse(__('errors.cannot_renew_insurance')); + } + + $user = $insurance->user; + $this->userCredentialsVerification($user, $request->input('password')); + + $networkConfig = NhNetworksConfig::where('network_id', $insurance->network_id)->first(); + if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante') + return $this->errorResponse(trans('errors.nano_health_not_activated')); + + // Verification de l'age du beneficiaire + $insuredAge = date_diff(date_create($user->identification->birth_date), date_create('now'))->y; + if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) { + return $this->errorResponse(trans('errors.minimal_age_required')); + } + + if (sizeof($insurance->beneficiaries) > $networkConfig->max_number_of_beneficiaries) + return $this->errorResponse(trans('errors.number_of_beneficiaries_exceeded')); + + $monthPrice = $networkConfig->monthsPricesGrid()->where('nh_network_config_id', $networkConfig->id) + ->where('number_of_months', $insurance->number_of_months)->first(); + if (!isset($monthPrice)) + return $this->errorResponse(trans('errors.incorrect_selected_amount')); + + $currency = $this->getNetworkCurrency($insurance->network_id); + + try { + DB::beginTransaction(); + + $bonus_amount = $monthPrice->min_amount; // Montant de la prime de l'assuré principal + $beneficiaries_bonus_amount = 0; // Montant total de la prime des ayant droits + foreach ($insurance->beneficiaries as $beneficiary) { + $amount = $this->calculateBeneficiaryBonusAmount($beneficiary, $networkConfig->yearsPricesGrid, $monthPrice); + $beneficiaries_bonus_amount += $amount; + $beneficiary->bonus_amount = $amount; + $beneficiary->save(); + } + + $amountToPaid = $bonus_amount + $beneficiaries_bonus_amount; + if ($user->wallet->balance < $amountToPaid) { + $amount = $amountToPaid - $user->wallet->balance; + return $this->errorResponse(trans('errors.insufficient_balance', ['amount' => $this->toMoneyWithCurrencyCode($amount, $currency)])); + } + + $datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country); + + $hyperviseur = AgentPlus::where('category', 'hyper')->where('network_id', $insurance->network_id)->firstOrFail(); + $walletHyperviseur = Wallet::where('id_networkAgent', $hyperviseur->network_agent_id)->firstOrFail(); + $walletHyperviseur->balance_princ += $amountToPaid; + $walletHyperviseur->save(); + + $user->balance_nano_health += $amountToPaid; + $user->wallet->balance -= $amountToPaid; + $user->wallet->save(); + $user->save(); + + $insurance->update([ + 'number_of_beneficiaries' => sizeof($insurance->beneficiaries), + 'total_bonus_amount' => $amountToPaid, + 'bonus_amount' => $bonus_amount, + 'updated_at' => $datetime, + 'state' => InsuranceState::PAID, + 'start_at' => $datetime, + 'end_at' => DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $insurance->number_of_months . 'months') + ]); + + NhInsurancesPayment::create([ + 'insured_id' => $insurance->insured_id, + 'amount' => $amountToPaid, + 'reason' => InsuranceAction::RENEWAL, + 'created_at' => $datetime, 'updated_at' => $datetime, + ]); + + Event::dispatch(new InsuranceEvent($insurance, trans('messages.insurance_renew'), trans('messages.insurance_renew_mail', ['name' => $user->lastname, 'insured_id' => $insurance->insured_id, + 'bonus_amount' => $this->toMoneyWithCurrencyCode($bonus_amount, $currency), 'total_bonus_amount' => $this->toMoneyWithCurrencyCode($amountToPaid, $currency), 'number_of_beneficiaries' => $insurance->number_of_beneficiaries, + 'gender' => trans('states.' . $user->identification->gender), 'insurance_name' => $insurance->network->name, 'months' => $insurance->number_of_months]))); + 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); + } + } } diff --git a/app/Http/Controllers/InsuranceSubscriptionController.php b/app/Http/Controllers/InsuranceSubscriptionController.php index 88a4c19..3ad608b 100644 --- a/app/Http/Controllers/InsuranceSubscriptionController.php +++ b/app/Http/Controllers/InsuranceSubscriptionController.php @@ -156,6 +156,7 @@ class InsuranceSubscriptionController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function subscribe(Request $request) { @@ -279,23 +280,15 @@ class InsuranceSubscriptionController extends Controller '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 (!checkPassword($request->password, $identification->user->encrypted_password, $identification->user->salt)) - return $this->errorResponse(trans('messages.incorrect_user_password')); + $user = User::findOrFail($request->input('user_id')); + $identification = $user->identification; + $this->userCredentialsVerification($user, $request->input('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')); - $latestSubscription = NhInsurancesSubscription::where('network_id', $request->input('network_id'))->where('user_id', $request->input('user_id')) - ->whereNotIn('state', [InsuranceSubscriptionState::REJECTED])->orderBy('created_at', 'DESC')->first(); - - if (isset($latestSubscription)) { - return $this->errorResponse(trans('errors.cannot_subscribe_again', ['state' => mb_strtolower(trans('states.' . $latestSubscription->state), 'UTF-8')])); - } + $this->latestSubscriptionVerification($request->input('network_id'), $request->input('user_id')); // Verification de l'age du beneficiaire $insuredAge = date_diff(date_create($identification->birth_date), date_create('now'))->y; @@ -303,7 +296,6 @@ class InsuranceSubscriptionController extends Controller 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')); @@ -550,6 +542,7 @@ class InsuranceSubscriptionController extends Controller * ) * ) * ) + * @throws \App\Exceptions\AppException */ public function paySubscription($id, Request $request) { @@ -567,9 +560,7 @@ class InsuranceSubscriptionController extends Controller } $user = $subscription->user; - if (!checkPassword($request->password, $user->encrypted_password, $user->salt)) { - return $this->errorResponse(trans('messages.incorrect_user_password')); - } + $this->userCredentialsVerification($user, $request->input('password')); $currency = $this->getNetworkCurrency($subscription->network_id); @@ -651,7 +642,7 @@ class InsuranceSubscriptionController extends Controller Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_paid'), trans('messages.insurance_subscription_paid_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id, - 'bonus_amount' => $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency), 'insured_id' => $insurance->insured_id, 'number_of_beneficiaries' => $subscription->number_of_beneficiaries, + 'bonus_amount' => $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency), 'total_bonus_amount' => $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency), 'insured_id' => $insurance->insured_id, 'number_of_beneficiaries' => $subscription->number_of_beneficiaries, 'gender' => trans('states.' . $subscription->user->identification->gender), 'insurance_name' => $subscription->network->name, 'months' => $subscription->number_of_months]))); DB::commit(); return $this->successResponse(trans('messages.insurance_subscription_paid')); diff --git a/app/Traits/Helper.php b/app/Traits/Helper.php index fd24a32..ecff006 100644 --- a/app/Traits/Helper.php +++ b/app/Traits/Helper.php @@ -4,9 +4,12 @@ namespace App\Traits; +use App\Exceptions\AppException; use App\HealthCareSheetType; +use App\InsuranceState; use App\InsuranceSubscriptionAffiliation; use App\InsuranceSubscriptionState; +use App\Models\AgentPlus; use App\Models\CountriesCurrency; use App\Models\Country; use App\Models\NhHavingRight; @@ -16,10 +19,12 @@ use App\Models\NhInsurance; use App\Models\NhInsurancesHavingRight; use App\Models\NhInsurancesSubscription; use App\Models\NhMonthsPricesGrid; +use App\Models\User; use Brick\Money\Context\AutoContext; use Brick\Money\Money; use DateTime; use DateTimeZone; +use Exception; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; @@ -198,4 +203,49 @@ trait Helper $sheet->insurer_amount = $insurerAmount; $sheet->insured_amount = $insuredAmount; } + + /** + * @throws AppException + */ + public function insuranceVerification(NhInsurance $insurance) + { + if ($insurance->state != InsuranceState::PAID) { + throw new AppException(__('errors.insurance_expired', ['state' => mb_strtolower(trans('states.' . $insurance->state), 'UTF-8')]), 400); + } + } + + /** + * @throws AppException + */ + public function latestSubscriptionVerification($network_id, $user_id) + { + $latestSubscription = NhInsurancesSubscription::where('network_id', $network_id)->where('user_id', $user_id) + ->whereIn('state', [InsuranceSubscriptionState::UNDER_VALIDATION, InsuranceSubscriptionState::AWAITING_FURTHER_INFORMATION])->orderBy('created_at', 'DESC')->first(); + + if (isset($latestSubscription)) { + throw new AppException(trans('errors.subscription_cannot_be_submitted', ['state' => mb_strtolower(trans('states.' . $latestSubscription->state), 'UTF-8')])); + } + } + + /** + * @throws AppException + */ + public function userCredentialsVerification(User $user, $password) + { + if (!isset($user->identification) || $user->identification->status == 0) + throw new AppException(trans('errors.user_identification_required')); + + if (!checkPassword($password, $user->encrypted_password, $user->salt)) + throw new AppException(trans('messages.incorrect_user_password')); + } + + /** + * @throws AppException + */ + public function agentCredentialsVerification($network_agent_id, $password) + { + $agent = AgentPlus::where('network_agent_id', $network_agent_id)->first(); + if (!checkPassword($password, $agent->encrypted_password, $agent->salt)) + throw new AppException(trans('messages.incorrect_user_password')); + } } diff --git a/config/services.php b/config/services.php index 6f959ad..a412a9b 100755 --- a/config/services.php +++ b/config/services.php @@ -6,5 +6,6 @@ return [ 'base_uri' => env('NOTIFICATION_SERVICE_URL'), 'key' => env('NOTIFICATION_SERVICE_KEY') ], - 'app_url' => env('APP_URL') + 'app_url' => env('APP_URL'), + 'app_debug' => env('APP_DEBUG', false) ]; diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index 4799d27..7d4fd78 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -11,7 +11,7 @@ return [ 'failed_transaction' => 'Failed transaction', 'user_phone_not_exist' => 'This customer number does not exist', 'wallet_not_defined' => 'This recipient wallet code does not exist', - 'insufficient_balance' => 'The balance is insufficient to complete this transaction. You will need to charge :amount', + 'insufficient_balance' => 'Your balance is insufficient to complete this transaction. You will need to charge :amount', 'no_ilink_network' => 'Sorry, there is no iLink World network in your country', 'wallet_country_not_match' => 'This recipient wallet code is not registered in the country :country', 'no_bank_card_attached' => 'No bank card is attached to your account', @@ -30,7 +30,7 @@ return [ "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", - "subscription_cannot_be_submitted" => "Your previous application :state . You cannot submit another one at this time", + "subscription_cannot_be_submitted" => "Your previous application is :state . You cannot submit another one at this time", "not_insured" => "You are not insured", 'drug_device_already_exists' => "This drug / device code already exists", "beneficiary_not_found" => "This beneficiary does not exist", @@ -45,5 +45,7 @@ return [ "unauthorized_to_update_sheet" => "You are not authorized to modify this care sheet", "beneficiary_not_part_in_insurance" => "Beneficiary number :id is not part of this insurance", 'act_application_already_pending' => "You already have an application pending for this act", - 'insurance_not_in_order' => "This insurance is not in order" + 'insurance_not_in_order' => "This insurance is not in order", + "insurance_expired" => "Your insurance is :state. You cannot perform this operation", + 'cannot_renew_insurance' => "Your insurance is not stopped, you cannot renew it" ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 9037366..2711178 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -160,4 +160,16 @@ Your request to stop your insurance has been accepted. - Amount to be paid: :bonus_amount - Number of beneficiaries : :number_of_beneficiaries ", + 'insurance_renew' => "Insurance renewed", + 'insurance_renew_mail' => ":gender :name , + +Your insurance has been renewed. + Insurance information : + - Insured number: :insured_id + - Insurance name: :insurance_name + - Basic insurance premium amount: :bonus_amount + - Total premium amount: :total_bonus_amount + - Number of beneficiaries : :number_of_beneficiaries + - Number of months: :months + ", ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 2cdc952..012ebab 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -11,7 +11,7 @@ return [ 'failed_transaction' => 'Transaction échouée', 'user_phone_not_exist' => 'Ce numéro client n\'existe pas', 'wallet_not_defined' => 'Ce code wallet destinataire n\'existe pas', - 'insufficient_balance' => 'Le solde est insuffisant pour effectuer cette transaction. Vous devrez recharger :amount', + 'insufficient_balance' => 'Votre solde est insuffisant pour effectuer cette transaction. Vous devrez recharger :amount', 'no_ilink_network' => 'Désolé , il n\'existe pas de reseau iLink World dans votre pays', 'wallet_country_not_match' => 'Ce code wallet destinataire n\'est pas enregistré dans le pays :country', 'no_bank_card_attached' => 'Aucune carte bancaire n\'est rattachée à votre compte', @@ -30,7 +30,7 @@ return [ "subscription_cannot_be_updated" => "Cette demande de souscription ne peut être modifiée", "subscription_cannot_be_paid" => "Cette demande de souscription ne peut être payée", 'subscription_be_already_paid' => "Cette souscription a déjà été payée", - "subscription_cannot_be_submitted" => "Votre demande précédente :state. Vous ne pouvez pas en soumettre une autre pour l'instant", + "subscription_cannot_be_submitted" => "Votre demande précédente est :state. Vous ne pouvez pas en soumettre une autre pour l'instant", "not_insured" => "Vous n'êtes pas assuré", 'drug_device_already_exists' => "Ce code médicament / appareillage existe deja", "beneficiary_not_found" => "Ce bénéficiaire n'existe pas", @@ -45,5 +45,7 @@ return [ "unauthorized_to_update_sheet" => "Vous n'êtes pas autorisé à modifier cette feuille de soins", "beneficiary_not_part_in_insurance" => "Le bénéficiaire numéro :id ne fait pas partie de cette assurance", 'act_application_already_pending' => "Vous avez deja une demande en cours de validation pour cet acte.", - 'insurance_not_in_order' => "Cette assurance n'est pas en règle" + 'insurance_not_in_order' => "Cette assurance n'est pas en règle", + "insurance_expired" => "Votre assurance est :state. Vous ne pouvez pas effectuer cette opération", + 'cannot_renew_insurance' => "Votre assurance n'est pas en arrêt , vous ne pouvez pas la renouveler" ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index 8ceded7..bd56fd8 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -63,7 +63,8 @@ Votre assurance a été validée. - ID : :subscription_id - Numéro d'assuré : :insured_id - Nom de l'assurance : :insurance_name - - Montant : :bonus_amount + - Montant de la prime de base d'assuré : :bonus_amount + - Montant total de la prime : :total_bonus_amount - Nombre d'ayants droit : :number_of_beneficiaries - Nombre de mois : :months ", @@ -176,4 +177,16 @@ Votre demande d'arrêt de votre assurance a été acceptée. - Montant à payer : :bonus_amount - Nombre d'ayants droit : :number_of_beneficiaries ", + 'insurance_renew' => "Assurance renouvelée", + 'insurance_renew_mail' => ":gender :name , + +Votre assurance a été renouvelée. + Informations de l'assurance : + - Numéro d'assuré : :insured_id + - Nom de l'assurance : :insurance_name + - Montant de la prime de base d'assuré : :bonus_amount + - Montant total de la prime : :total_bonus_amount + - Nombre d'ayants droit : :number_of_beneficiaries + - Nombre de mois : :months + ", ]; diff --git a/routes/web.php b/routes/web.php index 82704dd..df36c3a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,6 +20,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route $router->put('{id}/add-beneficiaries', 'InsuranceController@addBeneficiaries'); $router->put('{id}/delete-beneficiaries', 'InsuranceController@deleteBeneficiaries'); $router->put('{id}/stop', 'InsuranceController@stopInsurance'); + $router->put('{id}/renew', 'InsuranceController@renewInsurance'); // Subscriptions $router->group(['prefix' => '/subscriptions'], function () use ($router) {