Fix insurance subscription flow
This commit is contained in:
parent
408b38a840
commit
70c01135e6
|
@ -3,13 +3,14 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Events\InsuranceEvent;
|
use App\Events\InsuranceEvent;
|
||||||
use App\InsurancePaymentReason;
|
use App\InsuranceAction;
|
||||||
use App\InsuranceState;
|
use App\InsuranceState;
|
||||||
use App\InsuranceSubscriptionAffiliation;
|
use App\InsuranceSubscriptionAffiliation;
|
||||||
use App\InsuranceSubscriptionState;
|
use App\InsuranceSubscriptionState;
|
||||||
use App\Models\AgentPlus;
|
use App\Models\AgentPlus;
|
||||||
use App\Models\CountriesCurrency;
|
use App\Models\CountriesCurrency;
|
||||||
use App\Models\Identification;
|
use App\Models\Identification;
|
||||||
|
use App\Models\NhHavingRight;
|
||||||
use App\Models\NhInsurance;
|
use App\Models\NhInsurance;
|
||||||
use App\Models\NhInsurancesHavingRight;
|
use App\Models\NhInsurancesHavingRight;
|
||||||
use App\Models\NhInsurancesPayment;
|
use App\Models\NhInsurancesPayment;
|
||||||
|
@ -121,7 +122,7 @@ class InsuranceSubscriptionController extends Controller
|
||||||
|
|
||||||
$bonus = $monthPrice->min_amount;
|
$bonus = $monthPrice->min_amount;
|
||||||
foreach ($beneficiaries as $b) {
|
foreach ($beneficiaries as $b) {
|
||||||
$bonus += $this->calculateBeneficiaryBonusAmount(new NhInsurancesHavingRight($b), $networkConfig->yearsPricesGrid, $monthPrice);
|
$bonus += $this->calculateBeneficiaryBonusAmount(new NhHavingRight($b), $networkConfig->yearsPricesGrid, $monthPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->successResponse([
|
return $this->successResponse([
|
||||||
|
@ -291,7 +292,7 @@ class InsuranceSubscriptionController extends Controller
|
||||||
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
return $this->errorResponse(trans('errors.nano_health_not_activated'));
|
||||||
|
|
||||||
$currentSubscription = NhInsurancesSubscription::where('network_id', $request->input('network_id'))->where('user_id', $request->input('user_id'))
|
$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();
|
->whereNotIn('state', [InsuranceSubscriptionState::REJECTED])->first();
|
||||||
|
|
||||||
if (isset($currentSubscription)) {
|
if (isset($currentSubscription)) {
|
||||||
return $this->errorResponse(trans('errors.cannot_subscribe_again', ['state' => mb_strtolower(trans('states.' . $currentSubscription->state), 'UTF-8')]));
|
return $this->errorResponse(trans('errors.cannot_subscribe_again', ['state' => mb_strtolower(trans('states.' . $currentSubscription->state), 'UTF-8')]));
|
||||||
|
@ -319,6 +320,9 @@ class InsuranceSubscriptionController extends Controller
|
||||||
$subscription->insurance_subscription_id = $this->generateSubscriptionID();
|
$subscription->insurance_subscription_id = $this->generateSubscriptionID();
|
||||||
$subscription->number_of_months = $monthPrice->number_of_months;
|
$subscription->number_of_months = $monthPrice->number_of_months;
|
||||||
$subscription->bonus_amount = $monthPrice->min_amount;
|
$subscription->bonus_amount = $monthPrice->min_amount;
|
||||||
|
$subscription->insurance_action = InsuranceAction::ACTIVATION;
|
||||||
|
$subscription->save();
|
||||||
|
|
||||||
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($subscription, $request, $networkConfig, $monthPrice, $datetime);
|
$beneficiariesBonus = $this->storeBeneficiariesAndGetBonus($subscription, $request, $networkConfig, $monthPrice, $datetime);
|
||||||
|
|
||||||
$subscription->total_bonus_amount = ($subscription->bonus_amount + $beneficiariesBonus);
|
$subscription->total_bonus_amount = ($subscription->bonus_amount + $beneficiariesBonus);
|
||||||
|
@ -329,7 +333,6 @@ class InsuranceSubscriptionController extends Controller
|
||||||
'action' => 'ADD',
|
'action' => 'ADD',
|
||||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||||
'insurance_subscription_state' => $subscription->state,
|
'insurance_subscription_state' => $subscription->state,
|
||||||
'insurance_subscription' => json_encode($subscription),
|
|
||||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -419,7 +422,7 @@ class InsuranceSubscriptionController extends Controller
|
||||||
'insurance_subscription_state' => $subscription->state,
|
'insurance_subscription_state' => $subscription->state,
|
||||||
'agent_id' => $request->input('agent_id'),
|
'agent_id' => $request->input('agent_id'),
|
||||||
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
||||||
'insurance_subscription' => json_encode($subscription),
|
|
||||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -477,7 +480,7 @@ class InsuranceSubscriptionController extends Controller
|
||||||
'insurance_subscription_state' => $subscription->state,
|
'insurance_subscription_state' => $subscription->state,
|
||||||
'agent_id' => $request->input('agent_id'),
|
'agent_id' => $request->input('agent_id'),
|
||||||
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
'nh_validating_agent_id' => $request->input('nh_validating_agent_id'),
|
||||||
'insurance_subscription' => json_encode($subscription),
|
|
||||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -540,14 +543,11 @@ class InsuranceSubscriptionController extends Controller
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$subscription = NhInsurancesSubscription::findOrFail($id);
|
$subscription = NhInsurancesSubscription::findOrFail($id);
|
||||||
if ($subscription->state != InsuranceSubscriptionState::ACCEPTED || isset($subscription->payment)) {
|
if ($subscription->state != InsuranceSubscriptionState::ACCEPTED) {
|
||||||
return $this->errorResponse(trans('errors.subscription_cannot_be_paid'));
|
return $this->errorResponse(trans('errors.subscription_cannot_be_paid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$currency = $this->getNetworkCurrency($subscription->network_id);
|
if (isset($subscription->payment)) {
|
||||||
|
|
||||||
$insurance = NhInsurance::where('insurance_subscription_id', $subscription->insurance_subscription_id)->first();
|
|
||||||
if (isset($insurance) && $insurance->state == InsuranceState::PAID) {
|
|
||||||
return $this->errorResponse(trans('errors.subscription_be_already_paid'));
|
return $this->errorResponse(trans('errors.subscription_be_already_paid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,10 +556,9 @@ class InsuranceSubscriptionController extends Controller
|
||||||
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
return $this->errorResponse(trans('messages.incorrect_user_password'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currency = $this->getNetworkCurrency($subscription->network_id);
|
||||||
|
|
||||||
$amountToPaid = $subscription->total_bonus_amount;
|
$amountToPaid = $subscription->total_bonus_amount;
|
||||||
if (isset($insurance) && $insurance->state == InsuranceState::ADDITION_OF_BENEFICIARY) {
|
|
||||||
$amountToPaid = $insurance->remaining_amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->wallet->balance < $amountToPaid) {
|
if ($user->wallet->balance < $amountToPaid) {
|
||||||
$amount = $amountToPaid - $user->wallet->balance;
|
$amount = $amountToPaid - $user->wallet->balance;
|
||||||
|
@ -581,23 +580,48 @@ class InsuranceSubscriptionController extends Controller
|
||||||
$user->wallet->save();
|
$user->wallet->save();
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
if (isset($insurance) && $insurance->state == InsuranceState::ADDITION_OF_BENEFICIARY) {
|
if ($subscription->insurance_action == InsuranceAction::ACTIVATION) {
|
||||||
$insurance->state = InsuranceState::PAID;
|
|
||||||
$insurance->remaining_amount = 0;
|
|
||||||
$insurance->save();
|
|
||||||
$reason = InsurancePaymentReason::ADDITION_OF_BENEFICIARY;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$insuredId = $this->generateInsuredID();
|
$insuredId = $this->generateInsuredID();
|
||||||
$insurance = NhInsurance::create([
|
$insurance = NhInsurance::create([
|
||||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
'network_id' => $subscription->network_id,
|
||||||
|
'user_id' => $subscription->user_id,
|
||||||
'insured_id' => $insuredId,
|
'insured_id' => $insuredId,
|
||||||
|
'number_of_months' => $subscription->number_of_months,
|
||||||
|
'total_bonus_amount' => $subscription->total_bonus_amount,
|
||||||
|
'number_of_beneficiaries' => $subscription->number_of_beneficiaries,
|
||||||
|
'bonus_amount' => $subscription->bonus_amount,
|
||||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
'state' => InsuranceState::PAID,
|
'state' => InsuranceState::PAID,
|
||||||
'start_at' => $datetime,
|
'start_at' => $datetime,
|
||||||
'end_at' => DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $subscription->number_of_months . 'months')
|
'end_at' => DateTime::createFromFormat('Y-m-d H:i:s', $datetime)->modify('+' . $subscription->number_of_months . 'months')
|
||||||
]);
|
]);
|
||||||
$reason = InsurancePaymentReason::ACTIVATION;
|
foreach ($subscription->beneficiaries as $b) {
|
||||||
|
NhInsurancesHavingRight::create([
|
||||||
|
'insurance_id' => $insurance->id,
|
||||||
|
'having_right_id' => $b->id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$insurance = NhInsurance::where('network_id', $subscription->network_id)->where('user_id', $subscription->user_id)
|
||||||
|
->where('state', InsuranceState::PAID)->first();
|
||||||
|
if (!isset($insurance)) {
|
||||||
|
DB::rollBack();
|
||||||
|
return $this->errorResponse(trans('errors.not_insured'), 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subscription->insurance_action == InsuranceAction::ADDITION_OF_BENEFICIARY) {
|
||||||
|
$insurance->total_bonus_amount += $amountToPaid;
|
||||||
|
$insurance->number_of_beneficiaries += $subscription->number_of_beneficiaries;
|
||||||
|
$insurance->updated_at = $datetime;
|
||||||
|
$insurance->save();
|
||||||
|
|
||||||
|
foreach ($subscription->beneficiaries as $b) {
|
||||||
|
NhInsurancesHavingRight::create([
|
||||||
|
'insurance_id' => $insurance->id,
|
||||||
|
'having_right_id' => $b->id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -605,8 +629,7 @@ class InsuranceSubscriptionController extends Controller
|
||||||
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
'insurance_subscription_id' => $subscription->insurance_subscription_id,
|
||||||
'insured_id' => $insurance->insured_id,
|
'insured_id' => $insurance->insured_id,
|
||||||
'amount' => $amountToPaid,
|
'amount' => $amountToPaid,
|
||||||
'reason' => $reason,
|
'reason' => $subscription->insurance_action,
|
||||||
'insurance_details' => json_encode($insurance),
|
|
||||||
'created_at' => $datetime, 'updated_at' => $datetime,
|
'created_at' => $datetime, 'updated_at' => $datetime,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -705,6 +728,7 @@ class InsuranceSubscriptionController extends Controller
|
||||||
$subscriptions = $query->get();
|
$subscriptions = $query->get();
|
||||||
foreach ($subscriptions as $subscription) {
|
foreach ($subscriptions as $subscription) {
|
||||||
$subscription->state = trans('states.' . $subscription->state);
|
$subscription->state = trans('states.' . $subscription->state);
|
||||||
|
$subscription->insurance_action = trans('states.' . $subscription->insurance_action);
|
||||||
$subscription->bonus_amount = $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency_code);
|
$subscription->bonus_amount = $this->toMoneyWithCurrencyCode($subscription->bonus_amount, $currency_code);
|
||||||
$subscription->total_bonus_amount = $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency_code);
|
$subscription->total_bonus_amount = $this->toMoneyWithCurrencyCode($subscription->total_bonus_amount, $currency_code);
|
||||||
foreach ($subscription->beneficiaries as $b) {
|
foreach ($subscription->beneficiaries as $b) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
abstract class InsurancePaymentReason
|
abstract class InsuranceAction
|
||||||
{
|
{
|
||||||
const ACTIVATION = 'ACTIVATION';
|
const ACTIVATION = 'ACTIVATION';
|
||||||
const RENEWAL = 'RENEWAL';
|
const RENEWAL = 'RENEWAL';
|
|
@ -7,6 +7,4 @@ abstract class InsuranceState
|
||||||
const PAID = 'PAID';
|
const PAID = 'PAID';
|
||||||
const UNDER_STOPPING = 'UNDER_STOPPING';
|
const UNDER_STOPPING = 'UNDER_STOPPING';
|
||||||
const STOPPED = 'STOPPED';
|
const STOPPED = 'STOPPED';
|
||||||
const ADDITION_OF_BENEFICIARY = 'ADDITION_OF_BENEFICIARY';
|
|
||||||
const DELETION_OF_BENEFICIARY = 'DELETION_OF_BENEFICIARY';
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class NhInsurancesHavingRight
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property string $lastname
|
||||||
|
* @property string|null $firstname
|
||||||
|
* @property string $gender
|
||||||
|
* @property Carbon $birthdate
|
||||||
|
* @property string $affiliation
|
||||||
|
* @property float $bonus_amount
|
||||||
|
* @property string|null $birthdate_proof
|
||||||
|
* @property string|null $birthdate_proof_doc
|
||||||
|
* @property string|null $justice_doc
|
||||||
|
* @property string|null $marriage_certificate_doc
|
||||||
|
* @property string|null $id_document_type
|
||||||
|
* @property string|null $id_document_front
|
||||||
|
* @property string|null $id_document_back
|
||||||
|
* @property string|null $deleted_at
|
||||||
|
* @property Carbon $created_at
|
||||||
|
* @property Carbon $updated_at
|
||||||
|
*
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class NhHavingRight extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'nh_having_rights';
|
||||||
|
protected $appends = ['affiliation_tr'];
|
||||||
|
|
||||||
|
protected $dates = [
|
||||||
|
'birthdate'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'lastname',
|
||||||
|
'firstname',
|
||||||
|
'gender',
|
||||||
|
'birthdate',
|
||||||
|
'affiliation',
|
||||||
|
'bonus_amount',
|
||||||
|
'birthdate_proof',
|
||||||
|
'birthdate_proof_doc',
|
||||||
|
'justice_doc',
|
||||||
|
'marriage_certificate_doc',
|
||||||
|
'id_document_type',
|
||||||
|
'id_document_front',
|
||||||
|
'id_document_back'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getAffiliationTrAttribute()
|
||||||
|
{
|
||||||
|
return trans('states.' . $this->attributes['affiliation']);
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,12 +13,16 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* Class NhInsurance
|
* Class NhInsurance
|
||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $insurance_subscription_id
|
* @property int $network_id
|
||||||
|
* @property int $user_id
|
||||||
* @property string $insured_id
|
* @property string $insured_id
|
||||||
|
* @property int $number_of_months
|
||||||
|
* @property float $bonus_amount
|
||||||
|
* @property int $number_of_beneficiaries
|
||||||
|
* @property float $total_bonus_amount
|
||||||
* @property Carbon|null $start_at
|
* @property Carbon|null $start_at
|
||||||
* @property Carbon|null $end_at
|
* @property Carbon|null $end_at
|
||||||
* @property string $state
|
* @property string $state
|
||||||
* @property float $remaining_amount
|
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
|
@ -34,16 +38,40 @@ class NhInsurance extends Model
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'insurance_subscription_id',
|
'network_id',
|
||||||
|
'user_id',
|
||||||
'insured_id',
|
'insured_id',
|
||||||
|
'number_of_months',
|
||||||
|
'total_bonus_amount',
|
||||||
|
'number_of_beneficiaries',
|
||||||
|
'bonus_amount',
|
||||||
'start_at',
|
'start_at',
|
||||||
'end_at',
|
'end_at',
|
||||||
'state',
|
'state',
|
||||||
'remaining_amount'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function subscription()
|
public function network()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(NhInsurancesSubscription::class, 'insurance_subscription_id', 'insurance_subscription_id');
|
return $this->belongsTo(Network::class, 'network_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function beneficiaries()
|
||||||
|
{
|
||||||
|
return $this->hasManyThrough(NhHavingRight::class, NhInsurancesHavingRight::class, 'insurance_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nhNetworkConfig()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(NhNetworksConfig::class, 'network_id', 'network_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function payment()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(NhInsurancesPayment::class, 'id', 'insurance_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,38 +8,27 @@ namespace App\Models;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class NhInsurancesHavingRight
|
* Class NhInsurancesHavingRight
|
||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $insurance_subscription_id
|
* @property int $insurance_subscription_id
|
||||||
* @property string $lastname
|
* @property int $insurance_id
|
||||||
* @property string|null $firstname
|
* @property int $having_right_id
|
||||||
* @property string $gender
|
* @property Carbon $deleted_at
|
||||||
* @property Carbon $birthdate
|
|
||||||
* @property string $affiliation
|
|
||||||
* @property float $bonus_amount
|
|
||||||
* @property string|null $birthdate_proof
|
|
||||||
* @property string|null $birthdate_proof_doc
|
|
||||||
* @property string|null $justice_doc
|
|
||||||
* @property string|null $marriage_certificate_doc
|
|
||||||
* @property string|null $id_document_type
|
|
||||||
* @property string|null $id_document_front
|
|
||||||
* @property string|null $id_document_back
|
|
||||||
* @property string|null $deleted_at
|
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
* @package App\Models
|
* @package App\Models
|
||||||
*/
|
*/
|
||||||
class NhInsurancesHavingRight extends Model
|
class NhInsurancesHavingRight extends Pivot
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $table = 'nh_insurances_having_rights';
|
protected $table = 'nh_insurances_having_rights';
|
||||||
protected $appends = ['affiliation_tr'];
|
|
||||||
|
|
||||||
protected $dates = [
|
protected $dates = [
|
||||||
'birthdate'
|
'birthdate'
|
||||||
|
@ -47,23 +36,7 @@ class NhInsurancesHavingRight extends Model
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'insurance_subscription_id',
|
'insurance_subscription_id',
|
||||||
'lastname',
|
'insurance_id',
|
||||||
'firstname',
|
'having_right_id',
|
||||||
'gender',
|
|
||||||
'birthdate',
|
|
||||||
'affiliation',
|
|
||||||
'bonus_amount',
|
|
||||||
'birthdate_proof',
|
|
||||||
'birthdate_proof_doc',
|
|
||||||
'justice_doc',
|
|
||||||
'marriage_certificate_doc',
|
|
||||||
'id_document_type',
|
|
||||||
'id_document_front',
|
|
||||||
'id_document_back'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getAffiliationTrAttribute()
|
|
||||||
{
|
|
||||||
return trans('states.' . $this->attributes['affiliation']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property string $insured_id
|
* @property string $insured_id
|
||||||
* @property float $amount
|
* @property float $amount
|
||||||
* @property string $reason
|
* @property string $reason
|
||||||
* @property string $insurance_details
|
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
|
@ -35,7 +34,6 @@ class NhInsurancesPayment extends Model
|
||||||
'insurance_subscription_id',
|
'insurance_subscription_id',
|
||||||
'insured_id',
|
'insured_id',
|
||||||
'amount',
|
'amount',
|
||||||
'reason',
|
'reason'
|
||||||
'insurance_details'
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property int $number_of_beneficiaries
|
* @property int $number_of_beneficiaries
|
||||||
* @property float $total_bonus_amount
|
* @property float $total_bonus_amount
|
||||||
* @property string $state
|
* @property string $state
|
||||||
|
* @property string $insurance_action
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
|
@ -38,7 +39,8 @@ class NhInsurancesSubscription extends Model
|
||||||
'total_bonus_amount',
|
'total_bonus_amount',
|
||||||
'number_of_beneficiaries',
|
'number_of_beneficiaries',
|
||||||
'bonus_amount',
|
'bonus_amount',
|
||||||
'state'
|
'state',
|
||||||
|
'insurance_action'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function network()
|
public function network()
|
||||||
|
@ -53,7 +55,7 @@ class NhInsurancesSubscription extends Model
|
||||||
|
|
||||||
public function beneficiaries()
|
public function beneficiaries()
|
||||||
{
|
{
|
||||||
return $this->hasMany(NhInsurancesHavingRight::class, 'insurance_subscription_id', 'insurance_subscription_id');
|
return $this->hasManyThrough(NhHavingRight::class, NhInsurancesHavingRight::class, 'insurance_subscription_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nhNetworkConfig()
|
public function nhNetworkConfig()
|
||||||
|
|
|
@ -18,7 +18,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property int|null $agent_id
|
* @property int|null $agent_id
|
||||||
* @property int|null $nh_validating_agent_id
|
* @property int|null $nh_validating_agent_id
|
||||||
* @property string $insurance_subscription_state
|
* @property string $insurance_subscription_state
|
||||||
* @property string $insurance_subscription
|
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
|
@ -38,7 +37,6 @@ class NhInsurancesSubscriptionsHistory extends Model
|
||||||
'insurance_subscription_id',
|
'insurance_subscription_id',
|
||||||
'agent_id',
|
'agent_id',
|
||||||
'nh_validating_agent_id',
|
'nh_validating_agent_id',
|
||||||
'insurance_subscription_state',
|
'insurance_subscription_state'
|
||||||
'insurance_subscription'
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ use App\InsuranceSubscriptionAffiliation;
|
||||||
use App\InsuranceSubscriptionState;
|
use App\InsuranceSubscriptionState;
|
||||||
use App\Models\CountriesCurrency;
|
use App\Models\CountriesCurrency;
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
|
use App\Models\NhHavingRight;
|
||||||
use App\Models\NhInsurance;
|
use App\Models\NhInsurance;
|
||||||
use App\Models\NhInsurancesHavingRight;
|
use App\Models\NhInsurancesHavingRight;
|
||||||
use App\Models\NhInsurancesSubscription;
|
use App\Models\NhInsurancesSubscription;
|
||||||
|
@ -96,7 +97,7 @@ trait Helper
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caculer le montant de la prime d'un ayant droit ou beneficiaire
|
// Caculer le montant de la prime d'un ayant droit ou beneficiaire
|
||||||
public function calculateBeneficiaryBonusAmount(NhInsurancesHavingRight $beneficiary, Collection $yearsPricesGrid,
|
public function calculateBeneficiaryBonusAmount(NhHavingRight $beneficiary, Collection $yearsPricesGrid,
|
||||||
NhMonthsPricesGrid $monthPrice)
|
NhMonthsPricesGrid $monthPrice)
|
||||||
{
|
{
|
||||||
$bonus = 0;
|
$bonus = 0;
|
||||||
|
@ -124,8 +125,7 @@ trait Helper
|
||||||
|
|
||||||
$beneficiariesBonus = 0;
|
$beneficiariesBonus = 0;
|
||||||
foreach ($request->input('beneficiaries') as $b) {
|
foreach ($request->input('beneficiaries') as $b) {
|
||||||
$beneficiary = new NhInsurancesHavingRight($b);
|
$beneficiary = new NhHavingRight($b);
|
||||||
$beneficiary->insurance_subscription_id = $subscription->insurance_subscription_id;
|
|
||||||
$beneficiary->bonus_amount = $this->calculateBeneficiaryBonusAmount($beneficiary, $networkConfig->yearsPricesGrid, $monthPrice);
|
$beneficiary->bonus_amount = $this->calculateBeneficiaryBonusAmount($beneficiary, $networkConfig->yearsPricesGrid, $monthPrice);
|
||||||
$beneficiariesBonus += $beneficiary->bonus_amount;
|
$beneficiariesBonus += $beneficiary->bonus_amount;
|
||||||
if ($beneficiary->affiliation == InsuranceSubscriptionAffiliation::CHILD) {
|
if ($beneficiary->affiliation == InsuranceSubscriptionAffiliation::CHILD) {
|
||||||
|
@ -140,6 +140,10 @@ trait Helper
|
||||||
}
|
}
|
||||||
$beneficiary->created_at = $beneficiary->updated_at = $datetime;
|
$beneficiary->created_at = $beneficiary->updated_at = $datetime;
|
||||||
$beneficiary->save();
|
$beneficiary->save();
|
||||||
|
NhInsurancesHavingRight::create([
|
||||||
|
'insurance_subscription_id' => $subscription->id,
|
||||||
|
'having_right_id' => $beneficiary->id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
return $beneficiariesBonus;
|
return $beneficiariesBonus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class RenameNhInsurancesHavingRightsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::rename('nh_insurances_having_rights', 'nh_having_rights');
|
||||||
|
|
||||||
|
Schema::table('nh_having_rights', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('insurance_subscription_id');
|
||||||
|
$table->dropColumn('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::rename('nh_having_rights', 'nh_insurances_having_rights');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateNhInsurancesHavingRightsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('nh_insurances_having_rights', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->integer('insurance_id')->nullable();
|
||||||
|
$table->integer('insurance_subscription_id')->nullable();
|
||||||
|
$table->integer('having_right_id');
|
||||||
|
$table->softDeletes();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('nh_insurances_having_rights');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddInsuranceActionInNhInsurancesSubscriptionsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances_subscriptions', function (Blueprint $table) {
|
||||||
|
$table->enum('insurance_action', ['ACTIVATION', 'ADDITION_OF_BENEFICIARY', 'DELETION_OF_BENEFICIARY'])->default('ACTIVATION')
|
||||||
|
->comment("Action que l'utilisateur souhaite effectuer sur son assurance")->after('state');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances_subscriptions', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('insurance_action');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class UpdateNhInfosInsurancesSubscriptionsView extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
DB::statement("CREATE OR REPLACE VIEW nh_infos_insurances_subscriptions AS
|
||||||
|
SELECT nhis.* , cc.currency_code , u.lastname , u.phone, u.email FROM nh_insurances_subscriptions nhis JOIN networks n ON nhis.network_id = n.id
|
||||||
|
JOIN countries_currencies cc ON n.country_id = cc.id JOIN users u ON nhis.user_id = u.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class UpdateNhInsurancesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('insurance_subscription_id', 'remaining_amount');
|
||||||
|
$table->integer('network_id')->after('id');
|
||||||
|
$table->integer('user_id')->after('network_id');
|
||||||
|
$table->integer('number_of_months')->comment("Durée de couverture en mois")->after('insured_id');
|
||||||
|
$table->decimal('bonus_amount', 10, 2)->comment("Montant de la prime pour la durée de couverture choisi")->after('number_of_months');
|
||||||
|
$table->integer('number_of_beneficiaries')->after('bonus_amount');
|
||||||
|
$table->decimal('total_bonus_amount', 12, 2)->default(0)->comment("Montant total de la prime (assuré + ayants droit)")->after('number_of_beneficiaries');
|
||||||
|
DB::statement("ALTER TABLE nh_insurances MODIFY state
|
||||||
|
ENUM('PAID', 'UNDER_STOPPING', 'STOPPED') DEFAULT 'PAID' NOT NULL;");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['network_id', 'user_id', 'number_of_months', 'bonus_amount', 'number_of_beneficiaries', 'total_bonus_amount']);
|
||||||
|
$table->string('insurance_subscription_id')->after('id');
|
||||||
|
$table->decimal('remaining_amount');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class RemoveUneccessaryStuffInNhInsurancesPaymentsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances_payments', function (Blueprint $table) {
|
||||||
|
$table->string('insurance_subscription_id')->nullable()->change();
|
||||||
|
$table->string('reason')->default(null)->nullable()->change();
|
||||||
|
$table->dropColumn('insurance_details');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('nh_insurances_subscriptions_history', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('insurance_subscription');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('nh_insurances_payments', function (Blueprint $table) {
|
||||||
|
$table->text('insurance_details');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('nh_insurances_subscriptions_history', function (Blueprint $table) {
|
||||||
|
$table->text('insurance_subscription');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class UpdateNhInfosInsurancesView 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 , cc.currency_code FROM nh_insurances nhi
|
||||||
|
JOIN users u ON nhi.user_id = u.id JOIN networks n on nhi.network_id = n.id JOIN countries_currencies cc on n.country_id = cc.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ return [
|
||||||
'cannot_subscribe_again' => "You can no longer subscribe to this insurance. You already have a request :state",
|
'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_cannot_be_paid" => "This subscription request cannot be paid",
|
||||||
'subscription_be_already_paid' => "This subscription has already been paid. You can just renew it",
|
'subscription_be_already_paid' => "This subscription has already been paid",
|
||||||
"subscription_cannot_be_submitted" => "Your previous application is being validated. You cannot submit another one at this time",
|
"subscription_cannot_be_submitted" => "Your previous application is being validated. You cannot submit another one at this time",
|
||||||
|
"not_insured" => "You are not insured",
|
||||||
];
|
];
|
||||||
|
|
|
@ -13,5 +13,6 @@ return [
|
||||||
"AWAITING_FURTHER_INFORMATION" => "AWAITING FURTHER INFORMATION",
|
"AWAITING_FURTHER_INFORMATION" => "AWAITING FURTHER INFORMATION",
|
||||||
"ENDED" => 'ENDED',
|
"ENDED" => 'ENDED',
|
||||||
"ADDITION_OF_BENEFICIARY" => "ADDITION OF BENEFICIARY",
|
"ADDITION_OF_BENEFICIARY" => "ADDITION OF BENEFICIARY",
|
||||||
"DELETION_OF_BENEFICIARY" => "DELETION OF BENEFICIARY"
|
"DELETION_OF_BENEFICIARY" => "DELETION OF BENEFICIARY",
|
||||||
|
"ACTIVATION" => "INSURANCE ACTIVATION"
|
||||||
];
|
];
|
||||||
|
|
|
@ -29,6 +29,7 @@ return [
|
||||||
'cannot_subscribe_again' => "Vous ne pouvez plus souscrire à cette assurance. Vous avez déjà une demande :state",
|
'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_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",
|
'subscription_be_already_paid' => "Cette souscription a déjà été payée",
|
||||||
"subscription_cannot_be_submitted" => "Votre demande précedente est en cours de validation. Vous ne pouvez pas en soumettre une autre pour l'instant",
|
"subscription_cannot_be_submitted" => "Votre demande précedente est en cours de validation. Vous ne pouvez pas en soumettre une autre pour l'instant",
|
||||||
|
"not_insured" => "Vous n'êtes pas assuré",
|
||||||
];
|
];
|
||||||
|
|
|
@ -13,5 +13,6 @@ return [
|
||||||
"AWAITING_FURTHER_INFORMATION" => "EN ATTENTE D'INFORMATIONS COMPLÉMENTAIRES",
|
"AWAITING_FURTHER_INFORMATION" => "EN ATTENTE D'INFORMATIONS COMPLÉMENTAIRES",
|
||||||
"ENDED" => 'TERMINÉE',
|
"ENDED" => 'TERMINÉE',
|
||||||
"ADDITION_OF_BENEFICIARY" => "AJOUT D'AYANT DROIT",
|
"ADDITION_OF_BENEFICIARY" => "AJOUT D'AYANT DROIT",
|
||||||
"DELETION_OF_BENEFICIARY" => "SUPPRESSION D'AYANT DROIT"
|
"DELETION_OF_BENEFICIARY" => "SUPPRESSION D'AYANT DROIT",
|
||||||
|
"ACTIVATION" => "ACTIVATION DE L'ASSURANCE"
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue