@ -103,11 +103,12 @@ class InsuranceInvoiceController extends Controller
* example = {
* " status " : 200 ,
* " response " : {{ " id " : 1 , " invoice_id " : " SFSF6565656 " , " insurance_id " : 5 , " subscription_id " : 2 , " amount " : " 495 \ u202f000 FCFA " , " next_payment_deadline " : " 2022-04-08 17:31:52 " , " next_payment_reminder " : " 2022-04-05 17:31:52 " , " state " : " NON PAY \ u00c9E " ,
* " reason " : " ACTIVATION DE L'ASSURANCE " , " created_at " : " 2022-03-29T16:31:52.000000Z " , " updated_at " : " 2022-03-29T16:31:52.000000Z " , " insurance " : { " id " : 5 , " network_id " : 250 , " user_id " : 349 , " insured_id " : " 5DSTKZ7PQZX4 " ,
* " months_grid_id " : 77 , " bonus_amount " : " 150000.00 " , " number_of_beneficiaries " : 2 , " total_bonus_amount " : " 495000.00 " , " insurance_coverage_amount " : " 0.00 " , " start_at " : null , " end_at " : null , " state " : " UNDER_ACTIVATION " ,
* " reason " : " ACTIVATION DE L'ASSURANCE " , " created_at " : " 2022-03-29T16:31:52.000000Z " , " updated_at " : " 2022-03-29T16:31:52.000000Z " , " insurance " : { " id " : 5 , " network_id " : 250 , " user_id " : 349 , " insured_id " : " 5DSTKZ7PQZX4 " , " remaining_amount " : " 0 FCFA " ,
" paid_amount " : " 495 000 FCFA " , " months_grid_id " : 77 , " bonus_amount " : " 150000.00 " , " number_of_beneficiaries " : 2 , " total_bonus_amount " : " 495000.00 " , " insurance_coverage_amount " : " 0.00 " , " start_at " : null , " end_at " : null , " state " : " UNDER_ACTIVATION " ,
* " deadlines " : 1 , " amount_last_payment " : " 495000.00 " , " amount_per_split " : " 495000.00 " , " paid_deadlines " : 0 , " created_at " : " 2022-03-29T16:31:52.000000Z " , " updated_at " : " 2022-03-29T16:31:52.000000Z " },
* " subscription " : { " id " : 2 , " insurance_subscription_id " : " CX36UNA2VVOP " , " network_id " : 250 , " user_id " : 349 , " months_grid_id " : 77 , " bonus_amount " : " 150000.00 " , " number_of_beneficiaries " : 2 , "
* total_bonus_amount " : " 495000.00 " , " state " : " ACCEPTED " , " insurance_action " : " ACTIVATION " , " created_at " : " 2021 - 11 - 10 T16 : 52 : 32.000000 Z " , " updated_at " : " 2022 - 03 - 29 T17 : 31 : 52.000000 Z " , " reason " :null}}},
* total_bonus_amount " : " 495000.00 " , " state " : " ACCEPTED " , " insurance_action " : " ACTIVATION " , " created_at " : " 2021 - 11 - 10 T16 : 52 : 32.000000 Z " , " updated_at " : " 2022 - 03 - 29 T17 : 31 : 52.000000 Z " , " reason " :null}, " payments " : { { " id " : 8, " payment_id " : " RRS63SV7VP " , " invoice_id " : 7,
* " amount " : " 200 000 FCFA " , " created_at " : " 2022-04-29T16:09:59.000000Z " , " updated_at " : " 2022-04-29T16:09:59.000000Z " }}}},
* " error " : null
* }
* )
@ -126,7 +127,7 @@ class InsuranceInvoiceController extends Controller
$currency_code = $user -> network -> country -> currency_code ;
$pagination = $request -> input ( 'pagination' );
$state = $request -> input ( 'state' );
$datetime = $this -> getCurrentTimeByCountryCode ( $user -> network -> country -> code_country );
// $datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country);
$query = NhInsurancesInvoice :: with ([ 'insurance' , 'subscription' ])
-> whereHas ( 'insurance' , function ( $q ) use ( $user_id ) {
@ -140,6 +141,8 @@ class InsuranceInvoiceController extends Controller
// } else {
$query = $query -> where ( 'state' , $state );
// }
} else {
$query = $query -> with ([ 'payments' ]);
}
if ( $pagination ) {
@ -150,9 +153,18 @@ class InsuranceInvoiceController extends Controller
$array = $pagination ? $invoices -> items () : $invoices ;
foreach ( $array as $invoice ) {
$paid_amount = floatval ( $invoice -> paid_amount_non_formatted );
$invoice -> state = trans ( 'states.' . $invoice -> state );
$invoice -> reason = trans ( 'states.' . $invoice -> reason );
$invoice -> remaining_amount = $this -> toMoneyWithCurrencyCode ( $invoice -> amount - $paid_amount , $currency_code );
$invoice -> paid_amount = $this -> toMoneyWithCurrencyCode ( $paid_amount , $currency_code );
$invoice -> amount = $this -> toMoneyWithCurrencyCode ( $invoice -> amount , $currency_code );
if ( empty ( $state )) {
foreach ( $invoice -> payments as $payment ) {
$payment -> amount = $this -> toMoneyWithCurrencyCode ( $payment -> amount , $currency_code );
}
}
}
return $this -> successResponse ( $invoices );
}
@ -191,7 +203,7 @@ class InsuranceInvoiceController extends Controller
* description = " Montant à payer "
* )
* ),
* example = { " password " : " adbc1215448 " }
* example = { " password " : " adbc1215448 " , " amount " : 50000 }
* )
* ),
* @ OA\Response (
@ -273,10 +285,15 @@ class InsuranceInvoiceController extends Controller
'amount' => $amountToPaid
]);
// Calcul de l'equivalence en nombre d'echeance
$paid_deadlines = $amountToPaid < $invoice -> amount_per_split ? 1 : intval ( $amountToPaid / $invoice -> amount_per_split );
$invoice -> paid_deadlines += $paid_deadlines ;
$invoice -> next_payment_deadlines_to_paid -= $paid_deadlines ;
// Calcul de l'équivalence en nombre d'échéance
if (( $total_remains_amount - $amountToPaid ) == 0 ) {
$invoice -> paid_deadlines = $invoice -> deadlines ;
$invoice -> next_payment_deadlines_to_paid = 0 ;
} else {
$paid_deadlines = $amountToPaid < $invoice -> amount_per_split ? 1 : intval ( $amountToPaid / $invoice -> amount_per_split );
$invoice -> paid_deadlines += $paid_deadlines ;
$invoice -> next_payment_deadlines_to_paid -= $paid_deadlines ;
}
if ( $invoice -> next_payment_deadlines_to_paid < 0 ) {
$invoice -> next_payment_deadlines_to_paid = 0 ;
@ -335,7 +352,7 @@ class InsuranceInvoiceController extends Controller
trans ( 'messages.insurance_paid_mail' , [ 'name' => $invoice -> insurance -> user -> lastname , 'insured_id' => $invoice -> insurance -> insured_id ,
'bonus_amount' => $this -> toMoneyWithCurrencyCode ( $invoice -> insurance -> bonus_amount , $currency ), 'total_bonus_amount' => $this -> toMoneyWithCurrencyCode ( $invoice -> insurance -> total_bonus_amount , $currency ), 'number_of_beneficiaries' => $invoice -> insurance -> number_of_beneficiaries ,
'gender' => trans ( 'states.' . $invoice -> insurance -> user -> identification -> gender ), 'insurance_name' => $invoice -> insurance -> network -> name , 'months' => $invoice -> insurance -> monthsGrid -> number_of_months , 'invoice_id' => $invoice -> invoice_id ,
'amount' => $this -> toMoneyWithCurrencyCode ( $ invoice-> amount, $currency ), 'paid_amount' => $this -> toMoneyWithCurrencyCode ( $total_paid_amount + $amountToPaid , $currency ), 'remains_amount' => $this -> toMoneyWithCurrencyCode ( $total_remains_amount - $amountToPaid , $currency ),
'amount' => $this -> toMoneyWithCurrencyCode ( $ amountToPaid , $currency ), 'paid_amount' => $this -> toMoneyWithCurrencyCode ( $total_paid_amount + $amountToPaid , $currency ), 'remains_amount' => $this -> toMoneyWithCurrencyCode ( $total_remains_amount - $amountToPaid , $currency ),
'payment_period' => trans ( 'states.' . $invoice -> insurance -> monthsGrid -> payment_period ), 'reason' => trans ( 'states.' . $invoice -> reason ), 'title' => $isPartialPayment ? trans ( 'messages.insurance_partially_paid_title' ) : trans ( 'messages.insurance_fully_paid_title' ),
'waiting_days' => empty ( $invoice -> insurance -> monthsGrid -> waiting_period_days ) ? trans ( 'messages.none' ) : trans ( 'messages.n_days' , [ 'n' => $invoice -> insurance -> monthsGrid -> waiting_period_days ]),
'start_at' => $invoice -> insurance -> start_at , 'payment_id' => $payment -> payment_id