feature: payment instruction & cashier case cicilan dan downpayment

This commit is contained in:
2026-07-21 15:21:24 +07:00
parent 64f434cd78
commit e1feaa68a8
9 changed files with 1930 additions and 1388 deletions

View File

@@ -28,7 +28,7 @@ class Billv2 extends MY_Controller {
$offset = ($params['currentpage'] - 1) * $limit;
}
// ── UNION base — invoice branch + downpayment branch ────
// ── UNION base — invoice + downpayment + installment ───
$sql_base = "
SELECT
sp.SupplierPaymentID,
@@ -76,7 +76,33 @@ class Billv2 extends MY_Controller {
ON dp_sup.SupplierID = dp.SupplierDownpaymentSupplierID
JOIN purchase_order po
ON po.PurchaseOrderID = dp.SupplierDownpaymentPurchasOrderID
WHERE sp.SupplierPaymentSupplierDownpaymentID IS NOT NULL";
WHERE sp.SupplierPaymentSupplierDownpaymentID IS NOT NULL
UNION ALL
SELECT
sp.SupplierPaymentID,
sp.SupplierPaymentDate,
sp.SupplierPaymentNumber,
sp.SupplierPaymentAmount,
sp.SupplierPaymentStatus,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsActive,
0 AS SupplierInvoiceID,
CONCAT('INST-', si_inst.SupplierInvoiceNumber) AS SupplierInvoiceNumber,
inst.SupplierInstallmentDueDate AS SupplierInvoiceDraftPaymentDate,
inst_sup.SupplierCode AS SupplierCode,
inst_sup.SupplierName AS SupplierName,
'INSTALLMENT' AS type
FROM supplier_payment sp
JOIN supplier_installment inst
ON inst.SupplierInstallmentID = sp.SupplierPaymentSupplierInstallmentID
JOIN supplier_invoice si_inst
ON si_inst.SupplierInvoiceID = inst.SupplierInstallmentSupplierInvoiceID
JOIN supplier inst_sup
ON inst_sup.SupplierID = inst.SupplierInstallmentSupplierID
WHERE sp.SupplierPaymentSupplierInstallmentID IS NOT NULL";
// ── Outer: common filters + ordering + pagination ───────
$sql_data = "
@@ -97,8 +123,7 @@ class Billv2 extends MY_Controller {
}
// ── COUNT — wrap UNION in outer filter ──────────────────
$sql_total = "
SELECT COUNT(*) AS total FROM ($sql_base) AS combined
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS combined
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentNumber LIKE ?
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?))
@@ -118,7 +143,6 @@ class Billv2 extends MY_Controller {
];
$this->sys_ok($output);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$code = $exc->getCode();
@@ -143,7 +167,8 @@ class Billv2 extends MY_Controller {
// ── Detect payment type ──────────────────────────────────
$sql_type = "SELECT
SupplierPaymentSupplierInvoiceID,
SupplierPaymentSupplierDownpaymentID
SupplierPaymentSupplierDownpaymentID,
SupplierPaymentSupplierInstallmentID
FROM supplier_payment
WHERE SupplierPaymentID = ? AND SupplierPaymentIsActive = 'Y'";
@@ -206,7 +231,7 @@ class Billv2 extends MY_Controller {
$data['detail'] = $que_detail->result_array();
// ── DOWNPAYMENT branch ──────────────────────────────────
} else {
} elseif ($payment['SupplierPaymentSupplierDownpaymentID'] > 0) {
$sql = "SELECT
dp.SupplierDownpaymentPurchasOrderID,
dp.SupplierDownpaymentAmount AS SupplierInvoiceSubTotal,
@@ -255,6 +280,51 @@ class Billv2 extends MY_Controller {
throw new Exception('failed to get dp detail', 2);
}
$data['detail'] = $que_detail->result_array();
} else {
$sql = "SELECT
inst.SupplierInstallmentAmount AS SupplierInvoiceSubTotal,
0 AS SupplierInvoiceShippingCost,
0 AS SupplierInvoiceDiscountPercent,
0 AS SupplierInvoiceDiscountAmount,
0 AS SupplierInvoiceTaxPercentPpn,
0 AS SupplierInvoiceTaxAmountPpn,
inst.SupplierInstallmentAmount AS SupplierInvoiceGrandTotal,
si.SupplierInvoiceID,
'INSTALLMENT' AS type
FROM supplier_payment sp
JOIN supplier_installment inst
ON inst.SupplierInstallmentID = sp.SupplierPaymentSupplierInstallmentID
JOIN supplier_invoice si
ON si.SupplierInvoiceID = inst.SupplierInstallmentSupplierInvoiceID
WHERE sp.SupplierPaymentID = ? AND sp.SupplierPaymentIsActive = 'Y'";
$que = $this->db->query($sql, [$para['paymentID']]);
if (!$que) {
throw new Exception("[Error] failed get Installment row data", 2);
}
$data = $que->row_array();
$sql_detail = "SELECT
M_ItemDesc,
SupplierInvoiceDetailQty,
SupplierInvoiceDetailPrice,
SupplierInvoiceDetailDiscountAmount,
(SupplierInvoiceDetailPrice - SupplierInvoiceDetailDiscountAmount) AS DiscountedPrice,
SupplierInvoiceDetailTotal
FROM supplier_invoice_detail
JOIN m_item
ON M_ItemID = SupplierInvoiceDetailItemID AND M_ItemIsActive = 'Y'
WHERE SupplierInvoiceDetailSupplierInvoiceID = ?
AND SupplierInvoiceDetailIsActive = 'Y'
GROUP BY SupplierInvoiceDetailID";
$que_detail = $this->db->query($sql_detail, [$data['SupplierInvoiceID']]);
if (!$que_detail) {
throw new Exception("[Error] failed to get installment item payments", 2);
}
unset($data['SupplierInvoiceID']);
$data['detail'] = $que_detail->result_array();
}