Add insurance remains amount in insurance infos

This commit is contained in:
Djery-Tom 2022-05-04 16:16:20 +01:00
parent f195609da4
commit 06d52089f1
5 changed files with 38 additions and 7 deletions

View File

@ -407,6 +407,9 @@ class Hyperviseur_dash extends CI_Controller
$data['beneficiaries'] = $this->nano_health_model->getInsuranceBeneficiaries($data['insurance']->id ?? null);
$data['user'] = $this->db->get_where('user_infos',['user_id' => $data['insurance']->user_id ?? null])->first_row();
$data['payments'] = $this->nano_health_model->getInsurancePaymentTransactions($data['insurance']->id ?? null);
// Le montant payé de toutes les factures de l'assurance
$data['insurance_invoices_total_paid_amount'] = $this->nano_health_model->getInsuranceInvoiceTotalPaidAmount($data['insurance']->id ?? null) ?? 0;
$data['insurance_invoices_total_amount'] = $this->nano_health_model->getInsuranceInvoiceTotalAmount($data['insurance']->id ?? null) ?? 0;
$data['invoices'] = $this->nano_health_model->getInsuranceInvoices($this->input->get('id'));
$data['deletion_of_beneficiaries'] = $this->nano_health_model->getBeneficiariesDeletionHistory($data['insurance']->id ?? null);

View File

@ -940,5 +940,6 @@ $lang['EXPIRED'] = 'EXPIRED';
$lang['SUSPENDED'] = "SUSPENDED";
$lang['billed_quantity'] = "Billed quantity";
$lang['ceiling'] = "Ceiling";
$lang['note_config_wallet_agent_remove_cash'] = "The hypervisor's commission is the amount remaining in the client's commission once the agent's and supervisor's commissions are removed"
$lang['note_config_wallet_agent_remove_cash'] = "The hypervisor's commission is the amount remaining in the client's commission once the agent's and supervisor's commissions are removed";
$lang['UNPAID'] = "Unpaid";
?>

View File

@ -949,5 +949,6 @@ $lang['SUSPENDED'] = "SUSPENDU";
$lang['EXPIRED'] = 'EXPIRÉE';
$lang['billed_quantity'] = "Quantité facturée";
$lang['ceiling'] = "Plafond";
$lang['note_config_wallet_agent_remove_cash'] = "La commission de l'hyperviseur est le montant restant de la commission client une fois qu'on a retiré les commissions de l'agent et du superviseur"
$lang['note_config_wallet_agent_remove_cash'] = "La commission de l'hyperviseur est le montant restant de la commission client une fois qu'on a retiré les commissions de l'agent et du superviseur";
$lang['UNPAID'] = "Non Payée";
?>

View File

@ -71,16 +71,29 @@ class Nano_health_model extends CI_Model
}
public function getInsuranceInvoices($insuredId , $state = null){
$query = $this->db->select('i.* , is.insurance_subscription_id')
$query = $this->db->select('i.* , is.insurance_subscription_id, SUM(p.amount) as paid_amount')
->from('nh_insurances_invoices i')->join('nh_insurances in', 'in.id = i.insurance_id')
->join('nh_insurances_subscriptions is', 'is.id = i.subscription_id','left')
->join('nh_insurances_payments p', 'i.id = p.invoice_id','left')
->where('in.insured_id',$insuredId);
if(!empty($state)){
$query =$query->where('i.state',$state);
}
return $query->order_by('i.created_at','desc')->get();
return $query->group_by('i.id')->order_by('i.created_at','desc')->get();
}
public function getInsuranceInvoiceTotalPaidAmount($insuredId){
return $this->db->select('SUM(p.amount) as total_paid_amount')
->from('nh_insurances_invoices i')->join('nh_insurances in', 'in.id = i.insurance_id')
->join('nh_insurances_payments p', 'i.id = p.invoice_id')
->where('i.insurance_id',$insuredId)->group_by('i.id')->get()->row_array()['total_paid_amount'];
}
public function getInsuranceInvoiceTotalAmount($insuredId){
return $this->db->select('SUM(i.amount) as total_amount')
->from('nh_insurances_invoices i')->join('nh_insurances in', 'in.id = i.insurance_id')
->where('i.insurance_id',$insuredId)->group_by('i.id')->get()->row_array()['total_amount'];
}
public function getSubscriptionBeneficiaries($subscriptionId){

View File

@ -157,9 +157,8 @@
</div>
</div>
<div class="row">
<div class="col-lg-6 col-xs-6">
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-aqua-active">
<div class="inner">
<h3 style="white-space: pre-wrap; font-size: 1.9em;"><?= $this->lang->line($insurance->state) ?></h3>
@ -170,6 +169,17 @@
</div>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-aqua-active">
<div class="inner">
<h3 style="white-space: pre-wrap; font-size: 1.9em;"><?= Money::of(round(($insurance_invoices_total_amount - $insurance_invoices_total_paid_amount) , 2), $insurance->currency_code, $this->context)->formatTo('fr_FR') ?></h3>
<p><?= $this->lang->line('remaining_amount') ?></p>
</div>
<div class="icon">
<i class="ion ion-cash"></i>
</div>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-aqua-active">
<div class="inner">
@ -332,6 +342,7 @@
<th>ID</th>
<th><?= $this->lang->line('souscription_id'); ?></th>
<th><?= $this->lang->line('Montant'); ?></th>
<th><?= $this->lang->line('remaining_amount'); ?></th>
<th><?= $this->lang->line('reason'); ?></th>
<th><?= $this->lang->line('state'); ?></th>
<th>Date</th>
@ -342,11 +353,13 @@
if (isset($invoices)) {
foreach ($invoices->result() as $i => $row) {
$amount = Money::of(round($row->amount, 2), $insurance->currency_code, $this->context)->formatTo('fr_FR');
$remaining_amount = Money::of(round($row->amount - $row->paid_amount, 2), $insurance->currency_code, $this->context)->formatTo('fr_FR');
echo "<tr>
<td>" . $row->invoice_id . "</td>
<td>" . $row->insurance_subscription_id . "</td>
<td>" . $amount . "</td>
<td>" . $remaining_amount . "</td>
<td>" . $this->lang->line($row->reason). "</td>
<td>" . $this->lang->line($row->state). "</td>
<td>" . $row->created_at. "</td>";
@ -667,7 +680,7 @@
{
order: [[1, 'asc']],
"columnDefs": [{
"targets": [5],
"targets": [6],
// "orderable": false,
render: $.fn.dataTable.render.moment('YYYY-MM-DD HH:mm:ss', 'D MMMM YYYY HH:mm:ss', format)
}],