From 0b94af8a266da926630ba254ded777386c3ba4b6 Mon Sep 17 00:00:00 2001 From: Sendi Pebriyan Date: Wed, 5 Aug 2026 13:35:26 +0700 Subject: [PATCH] update total invoice --- .vscode/settings.json | 3 +++ application/controllers/Generateinvoice.php | 8 ++++++-- application/controllers/Invoices.php | 7 +++++-- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1a6a2b7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.language.colorizedBracketPairs": [] +} diff --git a/application/controllers/Generateinvoice.php b/application/controllers/Generateinvoice.php index 20d8f72..9814a48 100644 --- a/application/controllers/Generateinvoice.php +++ b/application/controllers/Generateinvoice.php @@ -88,12 +88,16 @@ class Generateinvoice extends CI_Controller { // ========================= $total = (float)$invi['total']; - $this->db->select_sum('sisa_piutang'); + // ================= AMBIL TUNGGAKAN ================= + $this->db->select_sum('total'); + $this->db->select_sum('total_bayar'); $this->db->where('customer_id', $invi['customer_id']); $this->db->where('status !=', 'paid'); $this->db->where('id !=', $invoice_id); // exclude invoice sekarang - $tunggakan = $this->db->get('invoices')->row()->sisa_piutang ?? 0; + $row = $this->db->get('invoices')->row(); + + $tunggakan = ($row->total ?? 0) - ($row->total_bayar ?? 0); // Ngambil Data Tunggakan bulan lalu jika ada. $keteranganlain = 'Akumulasi Tunggakan Invoice Bulan Lalu'; diff --git a/application/controllers/Invoices.php b/application/controllers/Invoices.php index c356043..bf359aa 100644 --- a/application/controllers/Invoices.php +++ b/application/controllers/Invoices.php @@ -510,12 +510,15 @@ class Invoices extends CI_Controller { } // ================= AMBIL TUNGGAKAN ================= - $this->db->select_sum('sisa_piutang'); + $this->db->select_sum('total'); + $this->db->select_sum('total_bayar'); $this->db->where('customer_id', $data->customer_id); $this->db->where('status !=', 'paid'); $this->db->where('id !=', $id); // exclude invoice sekarang - $tunggakan = $this->db->get('invoices')->row()->sisa_piutang ?? 0; + $row = $this->db->get('invoices')->row(); + + $tunggakan = ($row->total ?? 0) - ($row->total_bayar ?? 0); // ================= MASUKKAN KE DATA ================= $data->tunggakan = (int)$tunggakan;