feature: po pay downpayment
This commit is contained in:
@@ -62,6 +62,58 @@ class Bill extends MY_Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function add_notes_downpayment($orderid)
|
||||
{
|
||||
$sql = "SELECT SupplierPaymentSupplierDownpaymentID AS note_order_id,
|
||||
SupplierPaymentID AS note_id,
|
||||
SupplierDownpaymentID AS detail_id,
|
||||
SupplierPaymentDate AS note_date,
|
||||
SupplierPaymentNumber AS note_number,
|
||||
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') AS paymenttypes_name,
|
||||
SUM(SupplierDownpaymentAmount) AS note_amount,
|
||||
n.M_UserUsername AS note_user,
|
||||
SupplierDownpaymentIsActive AS note_active,
|
||||
'N' AS show_detail,
|
||||
SupplierPaymentNote AS keterangan,
|
||||
SupplierPaymentCoaID,
|
||||
coaID,
|
||||
coaDescription,
|
||||
SupplierPaymentIsConfirm,
|
||||
CONCAT(
|
||||
'Confirmed by : ',c.M_UserUsername, ' ',
|
||||
DATE_FORMAT(SupplierPaymentConfirmDate, '%d-%m-%Y %H:%i')
|
||||
) AS d_confirm,
|
||||
SupplierPaymentIsApproved,
|
||||
CONCAT(
|
||||
'Approved by : ',a.M_UserUsername, ' ',
|
||||
DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')
|
||||
) AS d_approved,
|
||||
CONCAT(
|
||||
'Verified by : ',b.M_UserUsername, ' ',
|
||||
DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')
|
||||
) AS d_verif
|
||||
FROM supplier_payment
|
||||
JOIN supplier_downpayment
|
||||
ON SupplierDownpaymentID = SupplierPaymentSupplierDownpaymentID
|
||||
AND SupplierDownpaymentIsActive = 'Y'
|
||||
LEFT JOIN coa ON SupplierPaymentCoaID = coaID
|
||||
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID
|
||||
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID
|
||||
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID
|
||||
LEFT JOIN m_user b ON SupplierPaymentVerifUserID = b.M_UserID
|
||||
WHERE SupplierPaymentSupplierDownpaymentID = {$orderid}
|
||||
AND SupplierPaymentIsActive = 'Y'
|
||||
GROUP BY SupplierPaymentID";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
return $rows ?: [];
|
||||
} else {
|
||||
$this->sys_error_db("get DP notes", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function add_tagihans($orderid)
|
||||
{
|
||||
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
||||
@@ -132,13 +184,14 @@ class Bill extends MY_Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function search()
|
||||
public function search_old()
|
||||
{
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$supplier = $prm["supplier"];
|
||||
$search = $prm["search"];
|
||||
@@ -151,25 +204,25 @@ class Bill extends MY_Controller
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
|
||||
$where = "SupplierInvoiceIsActive = 'Y'
|
||||
AND SupplierInvoiceStatus = 'Approved'
|
||||
AND SupplierInvoiceGrandTotal > 0
|
||||
AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}'
|
||||
AND (SupplierInvoiceNumber LIKE '%{$search}%' AND SupplierName LIKE '%{$supplier}%')
|
||||
AND ReceiveOrderPoS_RegionalID = {$regionalid}
|
||||
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
AND SupplierInvoiceStatus = 'Approved'
|
||||
AND SupplierInvoiceGrandTotal > 0
|
||||
AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}'
|
||||
AND (SupplierInvoiceNumber LIKE '%{$search}%' AND SupplierName LIKE '%{$supplier}%')
|
||||
AND ReceiveOrderPoS_RegionalID = {$regionalid}
|
||||
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
WHERE
|
||||
$where
|
||||
";
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
WHERE
|
||||
$where
|
||||
";
|
||||
// echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
@@ -186,55 +239,55 @@ class Bill extends MY_Controller
|
||||
|
||||
|
||||
$sql = "SELECT supplier_invoice.*,
|
||||
SupplierName,
|
||||
'' M_MouName,
|
||||
0 as totalbill,
|
||||
0 as paid,
|
||||
0 as unpaid,
|
||||
SupplierInvoiceIsLunas as flaglunas,
|
||||
0 as SupplierPaymentID,
|
||||
'' as SupplierPaymentNumber,
|
||||
0 as SupplierPaymentAmount,
|
||||
'' as SupplierPaymentDate,
|
||||
'' as SupplierInvoiceIssueRefNumber,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'N' as isbillterpusat,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
|
||||
IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice,
|
||||
IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved,
|
||||
IFNULL(SupplierPaymentIsVerif,'N') as SupplierPaymentIsVerif,
|
||||
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
|
||||
SupplierName,
|
||||
'' M_MouName,
|
||||
0 as totalbill,
|
||||
0 as paid,
|
||||
0 as unpaid,
|
||||
SupplierInvoiceIsLunas as flaglunas,
|
||||
0 as SupplierPaymentID,
|
||||
'' as SupplierPaymentNumber,
|
||||
0 as SupplierPaymentAmount,
|
||||
'' as SupplierPaymentDate,
|
||||
'' as SupplierInvoiceIssueRefNumber,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'N' as isbillterpusat,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
|
||||
IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice,
|
||||
IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved,
|
||||
IFNULL(SupplierPaymentIsVerif,'N') as SupplierPaymentIsVerif,
|
||||
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
|
||||
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
WHERE
|
||||
$where
|
||||
GROUP BY SupplierInvoiceID
|
||||
ORDER BY SupplierInvoiceID ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
WHERE
|
||||
$where
|
||||
GROUP BY SupplierInvoiceID
|
||||
ORDER BY SupplierInvoiceID ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
$rows = $query->result_array();
|
||||
if ($rows) {
|
||||
foreach ($rows as $k => $v) {
|
||||
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
IFNULL(SupplierPaymentID,0) SupplierPaymentID,
|
||||
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
|
||||
FROM supplier_payment
|
||||
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
IFNULL(SupplierPaymentID,0) SupplierPaymentID,
|
||||
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
|
||||
FROM supplier_payment
|
||||
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
|
||||
|
||||
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']}
|
||||
GROUP BY SupplierInvoiceID")->row();
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']}
|
||||
GROUP BY SupplierInvoiceID")->row();
|
||||
$amount = $s_payment->SupplierPaymentAmount ? $s_payment->SupplierPaymentAmount : "0.00";
|
||||
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
|
||||
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID ? $s_payment->SupplierPaymentID : '0';
|
||||
@@ -255,4 +308,270 @@ class Bill extends MY_Controller
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* search — unified invoice + downpayment list:
|
||||
* - Only columns the frontend actually reads (no wildcard, no dead aliases)
|
||||
* - UNION ALL merges supplier_invoice and supplier_downpayment
|
||||
* - DP rows enriched via SupplierPaymentSupplierDownpaymentID FK
|
||||
* - All queries use PDO parameterised placeholders
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$supplier = $prm["supplier"];
|
||||
$search = $prm["search"];
|
||||
$status = $prm["status"];
|
||||
$startdate = $prm["startdate"];
|
||||
$enddate = $prm["enddate"];
|
||||
$regionalid = $this->sys_user['S_RegionalID'];
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ((int)$prm['current_page'] - 1) * $number_limit;
|
||||
|
||||
// ── INVOICE WHERE ──────────────────────────────────────────
|
||||
$inv_where = " SupplierInvoiceIsActive = 'Y'
|
||||
AND SupplierInvoiceStatus = 'Approved'
|
||||
AND SupplierInvoiceGrandTotal > 0
|
||||
AND SupplierInvoiceIsInstallment = 'N'
|
||||
AND IF(SupplierPaymentID IS NULL,'N','Y') = ?
|
||||
AND SupplierInvoiceNumber LIKE ?
|
||||
AND SupplierName LIKE ?
|
||||
AND ReceiveOrderPoS_RegionalID = ?
|
||||
AND SupplierInvoiceDraftPaymentDate BETWEEN ? AND ? ";
|
||||
|
||||
$inv_params = [
|
||||
$status,
|
||||
'%' . $search . '%',
|
||||
'%' . $supplier . '%',
|
||||
$regionalid,
|
||||
$startdate,
|
||||
$enddate,
|
||||
];
|
||||
|
||||
// ── DOWNPAYMENT WHERE ──────────────────────────────────────
|
||||
$dp_where = " SupplierDownpaymentIsActive = 'Y'
|
||||
AND IF(SupplierDownpaymentStatus = 'Paid','Y','N') = ?
|
||||
AND PurchaseOrderNumber LIKE ?
|
||||
AND SupplierName LIKE ?
|
||||
AND PurchaseOrderS_RegionalID = ?
|
||||
AND SupplierDownpaymentDueDate BETWEEN ? AND ? ";
|
||||
|
||||
$dp_params = [
|
||||
$status,
|
||||
'%' . $search . '%',
|
||||
'%' . $supplier . '%',
|
||||
$regionalid,
|
||||
$startdate,
|
||||
$enddate,
|
||||
];
|
||||
|
||||
// ── COUNT query — UNION of both sources ────────────────────
|
||||
$sql_count = "SELECT SUM(cnt) as total FROM (
|
||||
SELECT count(*) as cnt
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
LEFT JOIN supplier_payment
|
||||
ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||
AND SupplierPaymentIsActive = 'Y'
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
WHERE $inv_where
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT count(*) as cnt
|
||||
FROM supplier_downpayment
|
||||
JOIN purchase_order ON PurchaseOrderID = SupplierDownpaymentPurchasOrderID
|
||||
JOIN supplier ON SupplierID = SupplierDownpaymentSupplierID
|
||||
WHERE $dp_where
|
||||
) AS combined";
|
||||
|
||||
$count_params = array_merge($inv_params, $dp_params);
|
||||
$query = $this->db_onedev->query($sql_count, $count_params);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("payment instructions count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── DATA query — UNION with identical columns ──────────────
|
||||
$sql_data = "
|
||||
SELECT * FROM (
|
||||
SELECT
|
||||
SupplierInvoiceID,
|
||||
SupplierInvoiceNumber,
|
||||
SupplierInvoiceDraftPaymentDate,
|
||||
SupplierInvoiceIsLunas as flaglunas,
|
||||
SupplierName,
|
||||
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
|
||||
IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved,
|
||||
IFNULL(SupplierPaymentCashierNumber,'') as SupplierPaymentCashierNumber,
|
||||
0 as totalbill,
|
||||
0 as paid,
|
||||
0 as unpaid,
|
||||
0 as SupplierPaymentID,
|
||||
'' as SupplierPaymentNumber,
|
||||
0 as SupplierPaymentAmount,
|
||||
'' as SupplierPaymentDate,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'INVOICE' as type
|
||||
FROM supplier_invoice
|
||||
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||
LEFT JOIN supplier_payment
|
||||
ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
|
||||
AND SupplierPaymentIsActive = 'Y'
|
||||
WHERE $inv_where
|
||||
GROUP BY SupplierInvoiceID
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
SupplierDownpaymentID * -1 as SupplierInvoiceID,
|
||||
CONCAT('DP-', PurchaseOrderNumber) as SupplierInvoiceNumber,
|
||||
SupplierDownpaymentDueDate as SupplierInvoiceDraftPaymentDate,
|
||||
SupplierDownpaymentIsLunas as flaglunas,
|
||||
SupplierName,
|
||||
DATE_FORMAT(SupplierDownpaymentDueDate,'%d-%m-%Y') as tanggalbayar,
|
||||
'N' as SupplierPaymentIsApproved,
|
||||
'' as SupplierPaymentCashierNumber,
|
||||
SupplierDownpaymentAmount as totalbill,
|
||||
CASE WHEN SupplierDownpaymentStatus = 'Paid'
|
||||
THEN SupplierDownpaymentAmount
|
||||
ELSE 0 END as paid,
|
||||
CASE WHEN SupplierDownpaymentStatus = 'Paid'
|
||||
THEN 0
|
||||
ELSE SupplierDownpaymentAmount END as unpaid,
|
||||
0 as SupplierPaymentID,
|
||||
'' as SupplierPaymentNumber,
|
||||
0 as SupplierPaymentAmount,
|
||||
'' as SupplierPaymentDate,
|
||||
'' as notes,
|
||||
'' as tagihans,
|
||||
'DP' as type
|
||||
FROM supplier_downpayment
|
||||
JOIN purchase_order ON PurchaseOrderID = SupplierDownpaymentPurchasOrderID
|
||||
JOIN supplier ON SupplierID = SupplierDownpaymentSupplierID
|
||||
WHERE $dp_where
|
||||
) AS combined
|
||||
ORDER BY SupplierInvoiceID ASC
|
||||
LIMIT ? OFFSET ?";
|
||||
|
||||
$data_params = array_merge($inv_params, $dp_params, [$number_limit, $number_offset]);
|
||||
$query = $this->db_onedev->query($sql_data, $data_params);
|
||||
$rows = $query->result_array();
|
||||
|
||||
// ── ENRICH — per-row sub-queries ───────────────────────────
|
||||
if ($rows) {
|
||||
foreach ($rows as $k => $v) {
|
||||
|
||||
// ── Downpayment branch ──────────────────────────
|
||||
if ($v['type'] === 'DP') {
|
||||
$dp_id = abs($v['SupplierInvoiceID']);
|
||||
|
||||
$s_payment = $this->db_onedev->query("
|
||||
SELECT
|
||||
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
IFNULL(SupplierPaymentID,0) as SupplierPaymentID,
|
||||
GROUP_CONCAT(
|
||||
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
|
||||
SEPARATOR ', '
|
||||
) as SupplierPaymentDate
|
||||
FROM supplier_payment
|
||||
WHERE SupplierPaymentIsActive = 'Y'
|
||||
AND SupplierPaymentSupplierDownpaymentID = ?",
|
||||
[$dp_id]
|
||||
)->row();
|
||||
|
||||
$amount = $s_payment->SupplierPaymentAmount
|
||||
? $s_payment->SupplierPaymentAmount
|
||||
: "0.00";
|
||||
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID
|
||||
? $s_payment->SupplierPaymentID
|
||||
: '0';
|
||||
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber
|
||||
? $s_payment->SupplierPaymentNumber
|
||||
: '';
|
||||
$rows[$k]['SupplierPaymentAmount'] = $amount;
|
||||
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
|
||||
$rows[$k]['paid'] = $amount;
|
||||
$rows[$k]['notes'] = $this->add_notes_downpayment($dp_id);
|
||||
$rows[$k]['tagihans'] = [];
|
||||
// totalbill, unpaid already correct from UNION CASE
|
||||
continue;
|
||||
}
|
||||
|
||||
// ── Invoice branch ───────────────────────────────
|
||||
$inv_id = $v['SupplierInvoiceID'];
|
||||
|
||||
$s_payment = $this->db_onedev->query("
|
||||
SELECT
|
||||
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
IFNULL(SupplierPaymentID,0) as SupplierPaymentID,
|
||||
GROUP_CONCAT(
|
||||
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
|
||||
SEPARATOR ', '
|
||||
) as SupplierPaymentDate
|
||||
FROM supplier_payment
|
||||
WHERE SupplierPaymentIsActive = 'Y'
|
||||
AND SupplierPaymentSupplierInvoiceID = ?",
|
||||
[$inv_id]
|
||||
)->row();
|
||||
|
||||
$s_jurnal = $this->db_onedev->query("
|
||||
SELECT SUM(jurnalTxCredit) totalbill
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx
|
||||
ON jurnalTxJurnalID = jurnalAddOnJurnalID
|
||||
AND jurnalTxCredit <> 0
|
||||
AND jurnalTxCoaID <> 563
|
||||
WHERE SupplierInvoiceID = ?
|
||||
GROUP BY SupplierInvoiceID",
|
||||
[$inv_id]
|
||||
)->row();
|
||||
|
||||
$amount = $s_payment->SupplierPaymentAmount
|
||||
? $s_payment->SupplierPaymentAmount
|
||||
: "0.00";
|
||||
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
|
||||
|
||||
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID
|
||||
? $s_payment->SupplierPaymentID
|
||||
: '0';
|
||||
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber
|
||||
? $s_payment->SupplierPaymentNumber
|
||||
: '';
|
||||
$rows[$k]['SupplierPaymentAmount'] = $amount;
|
||||
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
|
||||
$rows[$k]['paid'] = $amount;
|
||||
$rows[$k]['totalbill'] = $s_jurnal->totalbill
|
||||
? $s_jurnal->totalbill
|
||||
: "0.00";
|
||||
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
|
||||
|
||||
$rows[$k]['notes'] = $this->add_notes($inv_id);
|
||||
$rows[$k]['tagihans'] = $this->add_tagihans($inv_id);
|
||||
}
|
||||
}
|
||||
|
||||
$result = array("total" => $tot_page, "records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user