From 06d52089f1d2a9656c1615944fc9c2d460631ced Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 4 May 2022 16:16:20 +0100 Subject: [PATCH] Add insurance remains amount in insurance infos --- application/controllers/Hyperviseur_dash.php | 3 +++ application/language/english/message_lang.php | 3 ++- application/language/french/message_lang.php | 3 ++- application/models/Nano_health_model.php | 17 +++++++++++++++-- .../nano_health/hyper/infos_insurance.php | 19 ++++++++++++++++--- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/application/controllers/Hyperviseur_dash.php b/application/controllers/Hyperviseur_dash.php index 97ae1f77..34e9915e 100755 --- a/application/controllers/Hyperviseur_dash.php +++ b/application/controllers/Hyperviseur_dash.php @@ -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); diff --git a/application/language/english/message_lang.php b/application/language/english/message_lang.php index 15e7d2c0..aac8f746 100755 --- a/application/language/english/message_lang.php +++ b/application/language/english/message_lang.php @@ -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"; ?> diff --git a/application/language/french/message_lang.php b/application/language/french/message_lang.php index 705b5c2f..6750cde0 100755 --- a/application/language/french/message_lang.php +++ b/application/language/french/message_lang.php @@ -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"; ?> diff --git a/application/models/Nano_health_model.php b/application/models/Nano_health_model.php index f3210cec..4b0de147 100644 --- a/application/models/Nano_health_model.php +++ b/application/models/Nano_health_model.php @@ -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){ diff --git a/application/views/nano_health/hyper/infos_insurance.php b/application/views/nano_health/hyper/infos_insurance.php index 17c8bbb7..d809f60d 100755 --- a/application/views/nano_health/hyper/infos_insurance.php +++ b/application/views/nano_health/hyper/infos_insurance.php @@ -157,9 +157,8 @@ -
-
+

lang->line($insurance->state) ?>

@@ -170,6 +169,17 @@
+
+
+
+

currency_code, $this->context)->formatTo('fr_FR') ?>

+

lang->line('remaining_amount') ?>

+
+
+ +
+
+
@@ -332,6 +342,7 @@ ID lang->line('souscription_id'); ?> lang->line('Montant'); ?> + lang->line('remaining_amount'); ?> lang->line('reason'); ?> lang->line('state'); ?> Date @@ -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 " " . $row->invoice_id . " " . $row->insurance_subscription_id . " " . $amount . " + " . $remaining_amount . " " . $this->lang->line($row->reason). " " . $this->lang->line($row->state). " " . $row->created_at. ""; @@ -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) }],