feature: po pay downpayment

This commit is contained in:
2026-07-20 13:13:59 +07:00
parent 61e2e4f2ec
commit 64f434cd78
10 changed files with 2842 additions and 1485 deletions

View File

@@ -1,8 +1,10 @@
<?php <?php
class InventarisCoaMapping extends MY_Controller { class InventarisCoaMapping extends MY_Controller
{
var $db; var $db;
public function index() { public function index()
{
echo "Inventaris COA Mapping API"; echo "Inventaris COA Mapping API";
} }
@@ -11,8 +13,226 @@ class InventarisCoaMapping extends MY_Controller {
parent::__construct(); parent::__construct();
} }
## QUERY ##
public function getListCoa()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$para = $this->sys_input;
$keyword = "%" . $para['keyword'] . "%";
$sql = "SELECT
coaID,
coaAccountNo,
coaDescription
FROM coa
WHERE coaIsInput = 'Y'
AND (
coaDescription LIKE ?
OR coaAccountNo LIKE ?
)
AND coaIsActive = 'Y'
LIMIT 15";
$que = $this->db->query($sql, [$keyword, $keyword]);
if (!$que) {
throw new Exception('failed to query data inventaris gol', 1);
}
$data = $que->result_array();
$this->sys_ok($data);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getListInventarisGol()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$sql = "SELECT
M_InventarisGolID,
M_InventarisGolCode,
M_InventarisGolName
FROM m_inventaris_gol gol
WHERE gol.M_InventarisGolIsActive = 'Y'
AND NOT EXISTS (
SELECT 1
FROM m_inventaris_coa_mapping m
WHERE m.M_InventarisCoaMappingM_InventarisGolID = gol.M_InventarisGolID
AND m.M_InventarisCoaMappingIsActive = 'Y'
);";
$que = $this->db->query($sql);
if (!$que) {
throw new Exception('failed to query data inventaris gol', 1);
}
$data = $que->result_array();
$output = [
'records' => $data,
'total' => count($data)
];
$this->sys_ok($output);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getListInventorygolMapping()
{
try {
if (!$this->isLogin) {
throw new Exception('invalid token');
}
$para = $this->sys_input;
$keyword = "%" . $para['keyword'] . "%";
$limit = 10;
$offset = 0;
if ($para['currpage'] > 0) {
$offset = ($para['currpage'] - 1) * $limit;
}
$sql = "SELECT
M_InventarisGolID,
M_InventarisGolCode,
M_InventarisGolName,
M_InventarisCoaMappingID,
M_InventarisCoaMappingCoaInventarisID,
coaInv.coaAccountNo AS CoaInventarisAccountNo,
coaInv.coaDescription AS CoaInventarisDescription,
M_InventarisCoaMappingCoaHutangID,
coaHtg.coaAccountNo AS CoaHutangAccountNo,
coaHtg.coaDescription AS CoaHutangDescription,
M_InventarisCoaMappingCoaBebanPenyusutanID,
coaBbn.coaAccountNo AS CoaBebanPenyusutanAccountNo,
coaBbn.coaDescription AS CoaBebanPenyusutanDescription,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID,
coaAkm.coaAccountNo AS CoaAkumulasiPenyusutanAccountNo,
coaAkm.coaDescription AS CoaAkumulasiPenyusutanDescription,
M_InventarisCoaMappingCoaLabaPelepasanID,
coaLab.coaAccountNo AS CoaLabaPelepasanAccountNo,
coaLab.coaDescription AS CoaLabaPelepasanDescription,
M_InventarisCoaMappingCoaRugiPelepasanID,
coaRug.coaAccountNo AS CoaRugiPelepasanAccountNo,
coaRug.coaDescription AS CoaRugiPelepasanDescription
FROM m_inventaris_gol
JOIN m_inventaris_coa_mapping
ON M_InventarisCoaMappingM_InventarisGolID = M_InventarisGolID
AND M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisGolIsActive = 'Y'
AND M_InventarisGolName LIKE ?
LEFT JOIN coa AS coaInv
ON M_InventarisCoaMappingCoaInventarisID = coaInv.coaID
LEFT JOIN coa AS coaHtg
ON M_InventarisCoaMappingCoaHutangID = coaHtg.coaID
LEFT JOIN coa AS coaBbn
ON M_InventarisCoaMappingCoaBebanPenyusutanID = coaBbn.coaID
LEFT JOIN coa AS coaAkm
ON M_InventarisCoaMappingCoaAkumulasiPenyusutanID = coaAkm.coaID
LEFT JOIN coa AS coaLab
ON M_InventarisCoaMappingCoaLabaPelepasanID = coaLab.coaID
LEFT JOIN coa AS coaRug
ON M_InventarisCoaMappingCoaRugiPelepasanID = coaRug.coaID
WHERE M_InventarisGolIsActive = 'Y'";
$sql_data = $sql . " ORDER BY M_InventarisGolID LIMIT ? OFFSET ? ";
$que = $this->db->query($sql_data, [
$keyword,
$limit,
$offset
]);
if (!$que) {
throw new Exception('failed to query data mapping coa inventaris golongan', 1);
}
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
$que_total = $this->db->query($sql_total, [$keyword]);
if (!$que_total) {
throw new Exception('failed to get total rows data', 1);
}
$this->sys_ok([
"records" => $que->result_array(),
"total" => $que_total->row_array()['total']
]);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getInvCoaMappingDetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
$sql = "SELECT
M_InventarisCoaMappingID,
M_InventarisCoaMappingM_InventarisGolID,
M_InventarisCoaMappingCoaInventarisID,
M_InventarisCoaMappingCoaHutangID,
M_InventarisCoaMappingCoaPembelianID,
M_InventarisCoaMappingCoaBebanPenyusutanID,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisCoaMappingCoaLabaPelepasanID,
M_InventarisCoaMappingCoaRugiPelepasanID,
M_InventarisCoaMappingCreatedUserID,
M_InventarisCoaMappingCreated,
M_InventarisCoaMappingLastUpdated
FROM m_inventaris_coa_mapping
WHERE M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisCoaMappingID']]);
if (!$query) {
$this->sys_error_db("[Error] get data m_inventaris_coa_mapping");
exit;
}
$data = $query->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## MUTATIONS ## ## MUTATIONS ##
public function createInvCoaMapping() { public function createInvCoaMapping()
{
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
$this->sys_error("invalid token"); $this->sys_error("invalid token");
@@ -64,48 +284,8 @@ class InventarisCoaMapping extends MY_Controller {
} }
} }
## QUERY ## public function editInvCoaMapping()
public function getInvCoaMapping() { {
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
$sql = "SELECT
M_InventarisCoaMappingID,
M_InventarisCoaMappingM_InventarisGolID,
M_InventarisCoaMappingCoaInventarisID,
M_InventarisCoaMappingCoaHutangID,
M_InventarisCoaMappingCoaPembelianID,
M_InventarisCoaMappingCoaBebanPenyusutanID,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisCoaMappingCoaLabaPelepasanID,
M_InventarisCoaMappingCoaRugiPelepasanID,
M_InventarisCoaMappingCreatedUserID,
M_InventarisCoaMappingCreated,
M_InventarisCoaMappingLastUpdated
FROM m_inventaris_coa_mapping
WHERE M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisCoaMappingID']]);
if (!$query) {
$this->sys_error_db("[Error] get data m_inventaris_coa_mapping");
exit;
}
$data = $query->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## MUTATIONS ##
public function editInvCoaMapping() {
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
$this->sys_error("invalid token"); $this->sys_error("invalid token");
@@ -154,7 +334,8 @@ class InventarisCoaMapping extends MY_Controller {
} }
} }
public function deleteInvCoaMapping() { public function deleteInvCoaMapping()
{
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
$this->sys_error("invalid token"); $this->sys_error("invalid token");
@@ -185,8 +366,129 @@ class InventarisCoaMapping extends MY_Controller {
} }
} }
## QUERY ITEM ##
public function getListItemInventaris()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$para = $this->sys_input;
$sql = "SELECT
M_ItemID,
M_ItemCode,
M_ItemDesc,
M_ItemM_InventarisGolID AS itemGolID,
IFNULL(M_InventarisItemCoaMappingID, 0) AS itemCoaMapID,
M_InventarisItemCoaMappingCoaInventarisID,
coaInv.coaAccountNo AS CoaInventarisAccountNo,
coaInv.coaDescription AS CoaInventarisDescription,
M_InventarisItemCoaMappingCoaHutangID,
coaHtg.coaAccountNo AS CoaHutangAccountNo,
coaHtg.coaDescription AS CoaHutangDescription,
M_InventarisItemCoaMappingCoaBebanPenyusutanID,
coaBbn.coaAccountNo AS CoaBebanPenyusutanAccountNo,
coaBbn.coaDescription AS CoaBebanPenyusutanDescription,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
coaAkm.coaAccountNo AS CoaAkumulasiPenyusutanAccountNo,
coaAkm.coaDescription AS CoaAkumulasiPenyusutanDescription,
M_InventarisItemCoaMappingCoaLabaPelepasanID,
coaLab.coaAccountNo AS CoaLabaPelepasanAccountNo,
coaLab.coaDescription AS CoaLabaPelepasanDescription,
M_InventarisItemCoaMappingCoaRugiPelepasanID,
coaRug.coaAccountNo AS CoaRugiPelepasanAccountNo,
coaRug.coaDescription AS CoaRugiPelepasanDescription
FROM m_item
LEFT JOIN m_inventaris_item_coa_mapping
ON M_ItemID = M_InventarisItemCoaMappingM_ItemID
AND M_InventarisItemCoaMappingIsActive = 'Y'
LEFT JOIN coa AS coaInv
ON M_InventarisItemCoaMappingCoaInventarisID = coaInv.coaID
LEFT JOIN coa AS coaHtg
ON M_InventarisItemCoaMappingCoaHutangID = coaHtg.coaID
LEFT JOIN coa AS coaBbn
ON M_InventarisItemCoaMappingCoaBebanPenyusutanID = coaBbn.coaID
LEFT JOIN coa AS coaAkm
ON M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID = coaAkm.coaID
LEFT JOIN coa AS coaLab
ON M_InventarisItemCoaMappingCoaLabaPelepasanID = coaLab.coaID
LEFT JOIN coa AS coaRug
ON M_InventarisItemCoaMappingCoaRugiPelepasanID = coaRug.coaID
WHERE M_ItemItem_CategoryID = 2
AND M_ItemM_InventarisGolID = ?
AND M_ItemIsActive = 'Y'";
$que = $this->db->query($sql, [
$para['golID']
]);
if (!$que) {
throw new Exception('failed to query data inventaris gol', 1);
}
$data = $que->result_array();
$output = [
'records' => $data,
'total' => count($data)
];
$this->sys_ok($output);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getInvItemCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
$sql = "SELECT
M_InventarisItemCoaMappingID,
M_InventarisItemCoaMappingM_ItemID,
M_InventarisItemCoaMappingCoaInventarisID,
M_InventarisItemCoaMappingCoaHutangID,
M_InventarisItemCoaMappingCoaPembelianID,
M_InventarisItemCoaMappingCoaBebanPenyusutanID,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisItemCoaMappingCoaLabaPelepasanID,
M_InventarisItemCoaMappingCoaRugiPelepasanID,
M_InventarisItemCoaMappingCreatedUserID,
M_InventarisItemCoaMappingCreated,
M_InventarisItemCoaMappingLastUpdated
FROM m_inventaris_item_coa_mapping
WHERE M_InventarisItemCoaMappingIsActive = 'Y'
AND M_InventarisItemCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisItemCoaMappingID']]);
if (!$query) {
$this->sys_error_db("[Error] get data m_inventaris_item_coa_mapping");
exit;
}
$data = $query->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## MUTATIONS ITEM ## ## MUTATIONS ITEM ##
public function createInvItemCoaMapping() { public function createInvItemCoaMapping()
{
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
$this->sys_error("invalid token"); $this->sys_error("invalid token");
@@ -231,55 +533,15 @@ class InventarisCoaMapping extends MY_Controller {
$insertID = $this->db->insert_id(); $insertID = $this->db->insert_id();
$this->db->trans_commit(); $this->db->trans_commit();
$this->sys_ok($insertID); $this->sys_ok("[Success] insert coa item");
} catch (Exception $exc) { } catch (Exception $exc) {
$msg = $exc->getMessage(); $msg = $exc->getMessage();
$this->sys_error($msg); $this->sys_error($msg);
} }
} }
## QUERY ITEM ## public function editInvItemCoaMapping()
public function getInvItemCoaMapping() { {
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
$sql = "SELECT
M_InventarisItemCoaMappingID,
M_InventarisItemCoaMappingM_ItemID,
M_InventarisItemCoaMappingCoaInventarisID,
M_InventarisItemCoaMappingCoaHutangID,
M_InventarisItemCoaMappingCoaPembelianID,
M_InventarisItemCoaMappingCoaBebanPenyusutanID,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisItemCoaMappingCoaLabaPelepasanID,
M_InventarisItemCoaMappingCoaRugiPelepasanID,
M_InventarisItemCoaMappingCreatedUserID,
M_InventarisItemCoaMappingCreated,
M_InventarisItemCoaMappingLastUpdated
FROM m_inventaris_item_coa_mapping
WHERE M_InventarisItemCoaMappingIsActive = 'Y'
AND M_InventarisItemCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisItemCoaMappingID']]);
if (!$query) {
$this->sys_error_db("[Error] get data m_inventaris_item_coa_mapping");
exit;
}
$data = $query->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## MUTATIONS ITEM ##
public function editInvItemCoaMapping() {
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
$this->sys_error("invalid token"); $this->sys_error("invalid token");
@@ -328,7 +590,8 @@ class InventarisCoaMapping extends MY_Controller {
} }
} }
public function deleteInvItemCoaMapping() { public function deleteInvItemCoaMapping()
{
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
$this->sys_error("invalid token"); $this->sys_error("invalid token");

View File

@@ -496,6 +496,7 @@ class Fakturv4 extends MY_Controller
ELSE '' ELSE ''
END as WarehouseName, END as WarehouseName,
ReceiveOrderPoID, ReceiveOrderPoID,
ReceiveOrderPoTypePurchase,
PurchaseOrderItemCategoryID PurchaseOrderItemCategoryID
FROM supplier_invoice FROM supplier_invoice
JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID
@@ -588,12 +589,11 @@ class Fakturv4 extends MY_Controller
'P' 'P'
) AS DiscountType, ) AS DiscountType,
SupplierInvoiceReceiveOrderPoID, SupplierInvoiceReceiveOrderPoID,
ReceiveOrderPoNumber ReceiveOrderPoNumber,
ReceiveOrderPoTypePurchase AS typePurchase
FROM supplier_invoice FROM supplier_invoice
JOIN supplier ON SupplierInvoiceSupplierID = SupplierID JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN receive_order_po ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID JOIN receive_order_po ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID
-- JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
-- AND PurchaseOrderIsActive = 'Y'
WHERE SupplierInvoiceIsActive = 'Y' WHERE SupplierInvoiceIsActive = 'Y'
AND SupplierInvoiceID = ?"; AND SupplierInvoiceID = ?";
$que = $this->db->query($sql, $para['SInvoiceID']); $que = $this->db->query($sql, $para['SInvoiceID']);
@@ -601,6 +601,7 @@ class Fakturv4 extends MY_Controller
$this->sys_error_db('[Error] get detail data invoice'); $this->sys_error_db('[Error] get detail data invoice');
exit; exit;
} }
$data = $que->row_array();
$sqldet = "SELECT $sqldet = "SELECT
SupplierInvoiceDetailID, SupplierInvoiceDetailID,
@@ -636,7 +637,30 @@ class Fakturv4 extends MY_Controller
exit; exit;
} }
$data = $que->result_array()[0]; if (isset($data['typePurchase']) && $data['typePurchase'] == 'aset') {
$sql_dp = "SELECT
IFNULL(SupplierDownpaymentAmount, 0) AS dp_amount
FROM supplier_invoice
JOIN receive_order_po
ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID
JOIN purchase_order_asset_contract
ON PurchaseOrderAssetContractReceiveOrderPoID = ReceiveOrderPoID
AND PurchaseOrderAssetContractIsActive = 'Y'
JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderAssetContractPurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
WHERE SupplierInvoiceID = ?";
$que_dp = $this->db->query($sql_dp, [
$para['SInvoiceID']
]);
if (!$que_dp) {
$this->sys_error_db("[Error] get info contract asset");
exit;
}
$dp_amount = $que_dp->row_array()['dp_amount'];
$data['dp_amount'] = $dp_amount;
}
$data['detail'] = $quedet->result_array(); $data['detail'] = $quedet->result_array();
$result = $data; $result = $data;
@@ -1317,7 +1341,8 @@ class Fakturv4 extends MY_Controller
supplier_invoice_detail.*, supplier_invoice_detail.*,
ReceiveOrderPoNumber, ReceiveOrderPoNumber,
ReceiveOrderPoM_BranchCode, ReceiveOrderPoM_BranchCode,
ReceiveOrderPoS_RegionalID ReceiveOrderPoS_RegionalID,
ReceiveOrderPoTypePurchase AS typePurchase
FROM supplier_invoice FROM supplier_invoice
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierInvoiceID JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierInvoiceID
AND SupplierInvoiceDetailIsActive = 'Y' AND SupplierInvoiceDetailIsActive = 'Y'
@@ -1497,52 +1522,58 @@ class Fakturv4 extends MY_Controller
/* Insert jurnal tx for down payment asset */ /* Insert jurnal tx for down payment asset */
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
$sql_dpasset = "SELECT if (isset($invoice[0]['typePurchase']) && $invoice[0]['typePurchase'] == 'aset') {
PurchaseOrderAssetContractID, $sql_dpasset = "SELECT
PurchaseOrderAssetContractName, PurchaseOrderAssetContractID,
PurchaseOrderAssetContractInstallmentDownPayment, PurchaseOrderAssetContractName,
coaID, SupplierDownpaymentAmount,
coaDescription coaID,
FROM purchase_order_asset_contract coaDescription
JOIN purchase_order ON PurchaseOrderID = PurchaseOrderAssetContractPurchaseOrderID FROM purchase_order_asset_contract
JOIN purchase_order_detail ON PurchaseOrderID = PurchaseOrderDetailPurchaseOrderID JOIN purchase_order ON PurchaseOrderID = PurchaseOrderAssetContractPurchaseOrderID
AND PurchaseOrderDetailIsActive = 'Y' JOIN supplier_downpayment
JOIN m_item ON M_ItemID = PurchaseOrderDetailItemID ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
AND M_ItemItem_CategoryID = 3 AND SupplierDownpaymentIsActive = 'Y'
JOIN fa_class ON Fa_ClassID = M_ItemFa_ClassID JOIN purchase_order_detail
AND Fa_ClassIsActive = 'Y' ON PurchaseOrderID = PurchaseOrderDetailPurchaseOrderID
JOIN coa ON coaID = Fa_ClassDownPaymentCoaID AND PurchaseOrderDetailIsActive = 'Y'
AND coaIsActive = 'Y' JOIN m_item ON M_ItemID = PurchaseOrderDetailItemID
WHERE PurchaseOrderAssetContractReceiveOrderPoID = ? AND M_ItemItem_CategoryID = 3
AND PurchaseOrderAssetContractIsActive = 'Y' JOIN fa_class ON Fa_ClassID = M_ItemFa_ClassID
LIMIT 1"; AND Fa_ClassIsActive = 'Y'
$que_dpasset = $this->db->query($sql_dpasset, [ JOIN coa ON coaID = Fa_ClassDownPaymentCoaID
$invoice[0]['SupplierInvoiceReceiveOrderPoID'] AND coaIsActive = 'Y'
]); WHERE PurchaseOrderAssetContractReceiveOrderPoID = ?
if (!$que_dpasset) { AND PurchaseOrderAssetContractIsActive = 'Y'
$this->db->trans_rollback(); LIMIT 1";
$this->sys_error_db("[Error] query dp asset not error"); $que_dpasset = $this->db->query($sql_dpasset, [
exit; $invoice[0]['SupplierInvoiceReceiveOrderPoID']
} ]);
$dpasset_coa = $que_dpasset->row_array(); if (!$que_dpasset) {
if (!empty($dpasset_coa)) { $this->db->trans_rollback();
$totalDP = round($dpasset_coa['PurchaseOrderAssetContractInstallmentDownPayment'], 2); $this->sys_error_db("[Error] query dp asset not error");
if ($totalDP > 0) { exit;
$insert_dp = $this->InsertJurnalTx( }
$jurnalID, $dpasset_coa = $que_dpasset->row_array();
$dpasset_coa['coaID'], if (!empty($dpasset_coa)) {
$dpasset_coa['coaDescription'], $totalDP = round($dpasset_coa['SupplierDownpaymentAmount'], 2);
$user['M_UserID'], if ($totalDP > 0) {
0, $insert_dp = $this->InsertJurnalTx(
$totalDP $jurnalID,
); $dpasset_coa['coaID'],
if (!$insert_dp['status']) { $dpasset_coa['coaDescription'],
$this->db->trans_rollback(); $user['M_UserID'],
$this->sys_error_db($insert_dp['msg']); 0,
exit; $totalDP
} );
if (!$insert_dp['status']) {
$this->db->trans_rollback();
$this->sys_error_db($insert_dp['msg']);
exit;
}
$invoice = $this->CalcProrateDownPaymentAsset($invoice, $totalDP); $invoice = $this->CalcProrateDownPaymentAsset($invoice, $totalDP);
}
} }
} }

View File

@@ -228,11 +228,15 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderAssetContractEndDate AS contractEnd, PurchaseOrderAssetContractEndDate AS contractEnd,
IFNULL(attach.AttachmentCount, 0) AS AttachmentCount, IFNULL(attach.AttachmentCount, 0) AS AttachmentCount,
SupplierID, SupplierID,
SupplierName SupplierName,
SupplierDownpaymentID
FROM purchase_order FROM purchase_order
JOIN supplier ON SupplierID = PurchaseOrderSupplierID JOIN supplier ON SupplierID = PurchaseOrderSupplierID
JOIN purchase_order_asset_contract JOIN purchase_order_asset_contract
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
LEFT JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
ContractAssetAttachmentPurchaseOrderID, ContractAssetAttachmentPurchaseOrderID,
@@ -398,55 +402,59 @@ class PurchaseOrderAset extends MY_Controller {
# get data from purchase order # # get data from purchase order #
$sql_poasset = "SELECT $sql_poasset = "SELECT
PurchaseOrderID, PurchaseOrderID,
PurchaseOrderDate AS podate, PurchaseOrderDate AS podate,
PurchaseOrderNote AS catatan, PurchaseOrderNote AS catatan,
PurchaseOrderNumber, PurchaseOrderNumber,
PurchaseOrderStatus, PurchaseOrderStatus,
PurchaseOrderRefNumber AS reference, PurchaseOrderRefNumber AS reference,
PurchaseOrderGrandTotal AS grandtotal, PurchaseOrderGrandTotal AS grandtotal,
CASE CASE
WHEN PurchaseOrderTaxPpnType = 'P' THEN 'percent' WHEN PurchaseOrderTaxPpnType = 'P' THEN 'percent'
ELSE 'nominal' ELSE 'nominal'
END AS typepajak, END AS typepajak,
CASE CASE
WHEN PurchaseOrderTaxPpnType = 'P' THEN PurchaseOrderTaxPercentPpn WHEN PurchaseOrderTaxPpnType = 'P' THEN PurchaseOrderTaxPercentPpn
ELSE PurchaseOrderTaxAmountPpn ELSE PurchaseOrderTaxAmountPpn
END AS valuepajak, END AS valuepajak,
CASE CASE
WHEN PurchaseOrderDiscountPercent > 0.00 THEN 'percent' WHEN PurchaseOrderDiscountPercent > 0.00 THEN 'percent'
ELSE 'nominal' ELSE 'nominal'
END AS typediskon, END AS typediskon,
CASE CASE
WHEN PurchaseOrderDiscountPercent > 0.00 THEN PurchaseOrderDiscountPercent WHEN PurchaseOrderDiscountPercent > 0.00 THEN PurchaseOrderDiscountPercent
ELSE PurchaseOrderDiscountAmount ELSE PurchaseOrderDiscountAmount
END AS valuediskon, END AS valuediskon,
PurchaseOrderSubTotal AS subtotal, PurchaseOrderSubTotal AS subtotal,
PurchaseOrderGrandTotal AS grandtotal, PurchaseOrderGrandTotal AS grandtotal,
SupplierID AS supplierID, SupplierID AS supplierID,
SupplierName, SupplierName,
WarehouseID AS gudangID, WarehouseID AS gudangID,
WarehouseM_BranchID AS branchID, WarehouseM_BranchID AS branchID,
PurchaseOrderAssetContractID, PurchaseOrderAssetContractID,
PurchaseOrderAssetContractTAssetAttachmentID AS assetAttachmentID, PurchaseOrderAssetContractTAssetAttachmentID AS assetAttachmentID,
PurchaseOrderAssetContractName AS contractName, PurchaseOrderAssetContractName AS contractName,
PurchaseOrderAssetContractDate AS contractDate, PurchaseOrderAssetContractDate AS contractDate,
PurchaseOrderAssetContractStartDate AS contractStart, PurchaseOrderAssetContractStartDate AS contractStart,
PurchaseOrderAssetContractEndDate AS contractEnd, PurchaseOrderAssetContractEndDate AS contractEnd,
PurchaseOrderAssetContractDuration AS contractDuration, PurchaseOrderAssetContractDuration AS contractDuration,
PurchaseOrderAssetContractInstallmentNumber AS installmentNumber, PurchaseOrderAssetContractInstallmentNumber AS installmentNumber,
PurchaseOrderAssetContractInstallmentDate AS installmentDate, PurchaseOrderAssetContractInstallmentDate AS installmentDate,
PurchaseOrderAssetContractInstallmentPayAmount AS installmentPayAmount, PurchaseOrderAssetContractInstallmentPayAmount AS installmentPayAmount,
PurchaseOrderAssetContractInstallmentDownPaymentType AS installmentDownPaymentType, PurchaseOrderAssetContractInstallmentDownPaymentType AS installmentDownPaymentType,
PurchaseOrderAssetContractInstallmentDownPayment AS installmentDownPayment, PurchaseOrderAssetContractInstallmentDownPayment AS installmentDownPayment,
PurchaseOrderApprovedManagerUserID AS verifiedby PurchaseOrderApprovedManagerUserID AS verifiedby,
FROM purchase_order SupplierDownpaymentID
JOIN supplier ON SupplierID = PurchaseOrderSupplierID FROM purchase_order
JOIN warehouse ON WarehouseID = PurchaseOrderWarehouseID JOIN supplier ON SupplierID = PurchaseOrderSupplierID
JOIN purchase_order_asset_contract JOIN warehouse ON WarehouseID = PurchaseOrderWarehouseID
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID JOIN purchase_order_asset_contract
WHERE PurchaseOrderIsActive = 'Y' ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
AND PurchaseOrderID = ?"; LEFT JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
WHERE PurchaseOrderIsActive = 'Y'
AND PurchaseOrderID = ?";
$que_poasset = $this->db->query($sql_poasset, [$para['poID']]); $que_poasset = $this->db->query($sql_poasset, [$para['poID']]);
if (!$que_poasset) { if (!$que_poasset) {
$this->sys_error_db("[Error] failed get data from purchase order"); $this->sys_error_db("[Error] failed get data from purchase order");
@@ -592,6 +600,7 @@ class PurchaseOrderAset extends MY_Controller {
$summary_subtotal = floatval($para['summary']['subtotal']); $summary_subtotal = floatval($para['summary']['subtotal']);
$summary_diskon = floatval($para['summary']['diskon']); $summary_diskon = floatval($para['summary']['diskon']);
$summary_pajak = floatval($para['summary']['pajak']); $summary_pajak = floatval($para['summary']['pajak']);
$summary_downpayment = floatval($para['summary']['downpayment']);
$summary_total = floatval($para['summary']['total']); $summary_total = floatval($para['summary']['total']);
$sql_po = "INSERT INTO purchase_order ( $sql_po = "INSERT INTO purchase_order (
@@ -762,6 +771,33 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
# INSERT into table supplier_downpayment #
$sql_dp = "INSERT INTO supplier_downpayment (
SupplierDownpaymentPurchasOrderID,
SupplierDownpaymentSupplierID,
SupplierDownpaymentAmount,
SupplierDownpaymentDate,
SupplierDownpaymentDueDate,
SupplierDownpaymentStatus,
SupplierDownpaymentCreatedUserID,
SupplierDownpaymentLastUpdatedUserID
) VALUES (?,?,?,?,?,?,?,?)";
$que_dp = $this->db->query($sql_dp, [
$PurchaseOrderID,
$para['supplierID'],
$summary_downpayment ?: 0.00,
$para['contractStart'],
$para['contractStart'],
'Draft',
$user['M_UserID'],
$user['M_UserID']
]);
if (!$que_dp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed insert supplier downpayment");
exit;
}
$this->insertLog( $this->insertLog(
$PurchaseOrderID, 'CREATE', $para, '', $PurchaseOrderID, 'CREATE', $para, '',
[], $user['M_UserID'], 'create purchase order asset' [], $user['M_UserID'], 'create purchase order asset'
@@ -803,6 +839,7 @@ class PurchaseOrderAset extends MY_Controller {
$summary_subtotal = floatval($para['summary']['subtotal']); $summary_subtotal = floatval($para['summary']['subtotal']);
$summary_diskon = floatval($para['summary']['diskon']); $summary_diskon = floatval($para['summary']['diskon']);
$summary_pajak = floatval($para['summary']['pajak']); $summary_pajak = floatval($para['summary']['pajak']);
$summary_downpayment = floatval($para['summary']['downpayment']);
$summary_total = floatval($para['summary']['total']); $summary_total = floatval($para['summary']['total']);
# update po header # # update po header #
@@ -871,6 +908,29 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
## UPDATE existing downpayment ##
$sql = "UPDATE supplier_downpayment SET
SupplierDownpaymentAmount = ?,
SupplierDownpaymentDate = ?,
SupplierDownpaymentDueDate = ?,
SupplierDownpaymentStatus = ?,
SupplierDownpaymentLastUpdatedUserID = ?
WHERE SupplierDownpaymentID = ?
AND SupplierDownpaymentIsActive = 'Y'";
$que = $this->db->query($sql, [
$summary_downpayment ?: 0.00,
$para['contractStart'],
$para['contractStart'],
'Draft',
$user['M_UserID'],
$para['SupplierDownpaymentID']
]);
if (!$que) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed update supplier downpayment");
exit;
}
# update status old po summary isActive to 'N' # # update status old po summary isActive to 'N' #
$sql_active = "UPDATE purchase_order_summary SET $sql_active = "UPDATE purchase_order_summary SET
PurchaseOrderSummaryIsActive = 'N' PurchaseOrderSummaryIsActive = 'N'
@@ -956,7 +1016,7 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderDetailQty, PurchaseOrderDetailQty,
PurchaseOrderDetailPrice, PurchaseOrderDetailPrice,
PurchaseOrderDetailTotal, PurchaseOrderDetailTotal,
PurchaseOrderWarehouseID, PurchaseOrderDetailWarehouseID,
PurchaseOrderDetailUserID, PurchaseOrderDetailUserID,
PurchaseOrderDetailCreatedUserID, PurchaseOrderDetailCreatedUserID,
PurchaseOrderDetailCreated PurchaseOrderDetailCreated
@@ -1097,6 +1157,21 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
/* soft delete supplier_downpayment */
$sql_deldp = "UPDATE supplier_downpayment SET
SupplierDownpaymentIsActive = 'N',
SupplierDownpaymentLastUpdatedUserID = ?
WHERE SupplierDownpaymentID = ?
AND SupplierDownpaymentIsActive = 'Y'";
$que_deldp = $this->db->query($sql_deldp, [
$user['M_UserID'], $para['SupplierDownpaymentID']
]);
if (!$que_deldp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed soft delete supplier downpayment");
exit;
}
/* soft delete purchase order */ /* soft delete purchase order */
$sql_delorder = "UPDATE purchase_order SET $sql_delorder = "UPDATE purchase_order SET
PurchaseOrderIsActive = 'N', PurchaseOrderIsActive = 'N',
@@ -1298,8 +1373,4 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
} }
private function generateDownPaymentPI() {
}
} }

View File

@@ -693,8 +693,9 @@ class ReceiveItemPOAsset extends MY_Controller
ReceiveOrderPoNote, ReceiveOrderPoNote,
ReceiveOrderPoRefNumber, ReceiveOrderPoRefNumber,
ReceiveOrderPoDONumber, ReceiveOrderPoDONumber,
ReceiveOrderPoTypePurchase,
ReceiveOrderPoCreatedUserID ReceiveOrderPoCreatedUserID
) VALUE (?,?,?,?,?,?,?,?,?,?,?,?)"; ) VALUE (?,?,?,?,?,?,?,?,?,?,?,?,?)";
$queInsRO = $this->db->query($sqlInsRO, [ $queInsRO = $this->db->query($sqlInsRO, [
$numGR, $numGR,
$param['supplier'], $param['supplier'],
@@ -707,6 +708,7 @@ class ReceiveItemPOAsset extends MY_Controller
$param['catatan'], $param['catatan'],
$param['reference'], $param['reference'],
$param['reference'], $param['reference'],
'aset',
$user['M_UserID'] $user['M_UserID']
]); ]);
if (!$queInsRO) { if (!$queInsRO) {
@@ -1465,12 +1467,15 @@ class ReceiveItemPOAsset extends MY_Controller
PurchaseOrderID, PurchaseOrderID,
PurchaseOrderTaxPpnType AS tax_type, PurchaseOrderTaxPpnType AS tax_type,
PurchaseOrderTaxPercentPpn AS tax_percent, PurchaseOrderTaxPercentPpn AS tax_percent,
PurchaseOrderTaxAmountPpn AS tax_amount PurchaseOrderTaxAmountPpn AS tax_amount,
IFNULL(SupplierDownpaymentAmount, 0) AS downpayment_amount
FROM receive_order_po FROM receive_order_po
JOIN receive_order_po_detail ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID JOIN receive_order_po_detail ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
AND ReceiveOrderPoDetailIsActive = 'Y' AND ReceiveOrderPoDetailIsActive = 'Y'
AND ReceiveOrderPoIsActive = 'Y' AND ReceiveOrderPoIsActive = 'Y'
JOIN purchase_order ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID JOIN purchase_order ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
LEFT JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
WHERE ReceiveOrderPoID = ?"; WHERE ReceiveOrderPoID = ?";
$que_dataro = $this->db->query($sql_dataro, [$roID]); $que_dataro = $this->db->query($sql_dataro, [$roID]);
if (!$que_dataro) { if (!$que_dataro) {
@@ -1510,6 +1515,8 @@ class ReceiveItemPOAsset extends MY_Controller
$donumber = $data_ro['ReceiveOrderPoDONumber']; $donumber = $data_ro['ReceiveOrderPoDONumber'];
} }
$addedtax = round(($grni + $data_ro['tax_amount']), 2);
$grandtotal = round(($addedtax - $data_ro['downpayment_amount']), 2);
$sql_insert_pi = "INSERT INTO supplier_invoice ( $sql_insert_pi = "INSERT INTO supplier_invoice (
SupplierInvoiceNumber, SupplierInvoiceNumber,
SupplierInvoiceReceiveOrderPoID, SupplierInvoiceReceiveOrderPoID,
@@ -1542,8 +1549,8 @@ class ReceiveItemPOAsset extends MY_Controller
$diskonPO, $diskonPO,
$data_ro['tax_percent'], $data_ro['tax_percent'],
$data_ro['tax_amount'], $data_ro['tax_amount'],
$grni, $grandtotal,
$grni, $grandtotal,
$data_ro['ReceiveOrderPoNote'], $data_ro['ReceiveOrderPoNote'],
$user['M_UserID'], $user['M_UserID'],
$user['M_UserID'] $user['M_UserID']

View File

@@ -28,29 +28,66 @@ class Billv2 extends MY_Controller {
$offset = ($params['currentpage'] - 1) * $limit; $offset = ($params['currentpage'] - 1) * $limit;
} }
$sql_base = "SELECT // ── UNION base — invoice branch + downpayment branch ────
SupplierPaymentID, $sql_base = "
SupplierPaymentDate, SELECT
SupplierPaymentNumber, sp.SupplierPaymentID,
SupplierPaymentAmount, sp.SupplierPaymentDate,
SupplierPaymentStatus, sp.SupplierPaymentNumber,
SupplierPaymentIsVerif, sp.SupplierPaymentAmount,
SupplierPaymentIsApproved, sp.SupplierPaymentStatus,
SupplierInvoiceID, sp.SupplierPaymentIsVerif,
SupplierInvoiceNumber, sp.SupplierPaymentIsApproved,
SupplierInvoiceDraftPaymentDate, sp.SupplierPaymentIsActive,
SupplierCode, si.SupplierInvoiceID,
SupplierName si.SupplierInvoiceNumber,
FROM supplier_payment si.SupplierInvoiceDraftPaymentDate,
JOIN supplier_invoice ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID sup.SupplierCode,
AND SupplierPaymentNumber LIKE ? sup.SupplierName,
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?)) 'INVOICE' AS type
AND (SupplierPaymentStatus = ? OR ? = 'All') FROM supplier_payment sp
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID JOIN supplier_invoice si
WHERE SupplierPaymentIsActive = 'Y' ON si.SupplierInvoiceID = sp.SupplierPaymentSupplierInvoiceID
ORDER BY SupplierPaymentID DESC"; JOIN supplier sup
ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE sp.SupplierPaymentSupplierInvoiceID > 0
UNION ALL
SELECT
sp.SupplierPaymentID,
sp.SupplierPaymentDate,
sp.SupplierPaymentNumber,
sp.SupplierPaymentAmount,
sp.SupplierPaymentStatus,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsActive,
dp.SupplierDownpaymentID * -1 AS SupplierInvoiceID,
CONCAT('DP-', po.PurchaseOrderNumber) AS SupplierInvoiceNumber,
dp.SupplierDownpaymentDueDate AS SupplierInvoiceDraftPaymentDate,
dp_sup.SupplierCode AS SupplierCode,
dp_sup.SupplierName AS SupplierName,
'DP' AS type
FROM supplier_payment sp
JOIN supplier_downpayment dp
ON dp.SupplierDownpaymentID = sp.SupplierPaymentSupplierDownpaymentID
JOIN supplier dp_sup
ON dp_sup.SupplierID = dp.SupplierDownpaymentSupplierID
JOIN purchase_order po
ON po.PurchaseOrderID = dp.SupplierDownpaymentPurchasOrderID
WHERE sp.SupplierPaymentSupplierDownpaymentID IS NOT NULL";
// ── Outer: common filters + ordering + pagination ───────
$sql_data = "
SELECT * FROM ($sql_base) AS combined
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentNumber LIKE ?
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?))
AND (SupplierPaymentStatus = ? OR ? = 'All')
ORDER BY SupplierPaymentID DESC
LIMIT ? OFFSET ?";
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
$que_data = $this->db->query($sql_data, [ $que_data = $this->db->query($sql_data, [
$keyword, $params['startdate'], $params['enddate'], $keyword, $params['startdate'], $params['enddate'],
$params['status'], $params['status'], $limit, $offset $params['status'], $params['status'], $limit, $offset
@@ -59,7 +96,14 @@ class Billv2 extends MY_Controller {
throw new Exception("[Error] failed get data supplier payment", 2); throw new Exception("[Error] failed get data supplier payment", 2);
} }
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x"; // ── COUNT — wrap UNION in outer filter ──────────────────
$sql_total = "
SELECT COUNT(*) AS total FROM ($sql_base) AS combined
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentNumber LIKE ?
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?))
AND (SupplierPaymentStatus = ? OR ? = 'All')";
$que_total = $this->db->query($sql_total, [ $que_total = $this->db->query($sql_total, [
$keyword, $params['startdate'], $params['enddate'], $keyword, $params['startdate'], $params['enddate'],
$params['status'], $params['status'] $params['status'], $params['status']
@@ -70,9 +114,9 @@ class Billv2 extends MY_Controller {
$output = [ $output = [
"records" => $que_data->result_array(), "records" => $que_data->result_array(),
"total" =>$que_total->row_array()['total'] "total" => $que_total->row_array()['total']
]; ];
$this->sys_ok($output); $this->sys_ok($output);
exit; exit;
} catch (Exception $exc) { } catch (Exception $exc) {
@@ -96,70 +140,123 @@ class Billv2 extends MY_Controller {
$para = $this->sys_input; $para = $this->sys_input;
$sql = "SELECT // ── Detect payment type ──────────────────────────────────
SupplierInvoiceID, $sql_type = "SELECT
SupplierInvoiceRefNumber, SupplierPaymentSupplierInvoiceID,
SupplierInvoiceDeliveryOrderNumber, SupplierPaymentSupplierDownpaymentID
SupplierInvoiceSupplierInvoiceNumber, FROM supplier_payment
SupplierInvoiceSupplierInvoiceDate, WHERE SupplierPaymentID = ? AND SupplierPaymentIsActive = 'Y'";
SupplierInvoiceSubTotal,
SupplierInvoiceTaxPercentPph,
SupplierInvoiceTaxPercentPpn,
SupplierInvoiceTaxAmountPpn,
SupplierInvoiceDiscountAmount,
SupplierInvoiceDiscountPercent,
SupplierInvoiceShippingCost,
SupplierInvoiceGrandTotal,
SupplierInvoiceAdjustmentAmount,
SupplierInvoiceAdjustmentNote,
SupplierInvoiceNote,
IF (SupplierInvoiceDiscountAmount > 0, 'R', 'P') AS DiscountType
FROM supplier_payment
JOIN supplier_invoice ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
AND SupplierPaymentID = ?
AND SupplierPaymentIsActive = 'Y'";
$que = $this->db->query($sql, [$para['paymentID']]);
if (!$que) {
throw new Exception("[Error] failed get row data", 2);
}
$data = $que->row_array();
$sql_detail = "SELECT $que_type = $this->db->query($sql_type, [$para['paymentID']]);
SupplierInvoiceDetailID, if (!$que_type) {
SupplierInvoiceDetailSupplierInvoiceID, throw new Exception("[Error] failed get payment header", 2);
SupplierInvoiceDetailPurchaseOrderID, }
SupplierInvoiceDetailPurchaseOrderSummaryID, $payment = $que_type->row_array();
SupplierInvoiceDetailReceiveOrderPoID, if (!$payment) {
SupplierInvoiceDetailReceiveOrderPoDetailID, throw new Exception("[Error] payment not found", 2);
SupplierInvoiceDetailItemID,
SupplierInvoiceDetailItemUnitID,
SupplierInvoiceDetailDescription,
SupplierInvoiceDetailQty,
SupplierInvoiceDetailPrice,
SupplierInvoiceDetailDiscountPercent,
SupplierInvoiceDetailDiscountDiscountRupiah,
SupplierInvoiceDetailDiscountDiscountType,
SupplierInvoiceDetailDiscountAmount,
(SupplierInvoiceDetailPrice - SupplierInvoiceDetailDiscountAmount) AS DiscountedPrice,
SupplierInvoiceDetailDiscountPoProrata,
SupplierInvoiceDetailTotal,
M_ItemCode,
M_ItemDesc
FROM supplier_payment_detail
JOIN supplier_invoice_detail ON SupplierInvoiceDetailIsActive = 'Y'
AND SupplierPaymentDetailSupplierPaymentID = ?
AND SupplierInvoiceDetailSupplierInvoiceID = ?
JOIN m_item ON M_ItemID = SupplierInvoiceDetailItemID
AND M_ItemIsActive = 'Y'
GROUP BY SupplierInvoiceDetailID";
$que_detail = $this->db->query($sql_detail, [
$para['paymentID'], $data['SupplierInvoiceID']
]);
if (!$que_detail) {
throw new Exception("[Error] failed to get item payments", 2);
} }
$data['detail'] = $que_detail->result_array(); // ── INVOICE branch ──────────────────────────────────────
if ($payment['SupplierPaymentSupplierInvoiceID'] > 0) {
$sql = "SELECT
si.SupplierInvoiceSubTotal,
si.SupplierInvoiceShippingCost,
si.SupplierInvoiceDiscountPercent,
si.SupplierInvoiceDiscountAmount,
si.SupplierInvoiceTaxPercentPpn,
si.SupplierInvoiceTaxAmountPpn,
si.SupplierInvoiceGrandTotal,
si.SupplierInvoiceID,
'INVOICE' AS type
FROM supplier_payment sp
JOIN supplier_invoice si
ON si.SupplierInvoiceID = sp.SupplierPaymentSupplierInvoiceID
WHERE sp.SupplierPaymentID = ? AND sp.SupplierPaymentIsActive = 'Y'";
$que = $this->db->query($sql, [$para['paymentID']]);
if (!$que) {
throw new Exception("[Error] failed get row data", 2);
}
$data = $que->row_array();
$sql_detail = "SELECT
M_ItemDesc,
SupplierInvoiceDetailQty,
SupplierInvoiceDetailPrice,
SupplierInvoiceDetailDiscountAmount,
(SupplierInvoiceDetailPrice - SupplierInvoiceDetailDiscountAmount) AS DiscountedPrice,
SupplierInvoiceDetailTotal
FROM supplier_payment_detail
JOIN supplier_invoice_detail
ON SupplierInvoiceDetailIsActive = 'Y'
AND SupplierPaymentDetailSupplierPaymentID = ?
AND SupplierInvoiceDetailSupplierInvoiceID = ?
JOIN m_item
ON M_ItemID = SupplierInvoiceDetailItemID AND M_ItemIsActive = 'Y'
GROUP BY SupplierInvoiceDetailID";
$que_detail = $this->db->query($sql_detail, [
$para['paymentID'], $data['SupplierInvoiceID']
]);
if (!$que_detail) {
throw new Exception("[Error] failed to get item payments", 2);
}
unset($data['SupplierInvoiceID']);
$data['detail'] = $que_detail->result_array();
// ── DOWNPAYMENT branch ──────────────────────────────────
} else {
$sql = "SELECT
dp.SupplierDownpaymentPurchasOrderID,
dp.SupplierDownpaymentAmount AS SupplierInvoiceSubTotal,
0 AS SupplierInvoiceShippingCost,
0 AS SupplierInvoiceDiscountPercent,
0 AS SupplierInvoiceDiscountAmount,
0 AS SupplierInvoiceTaxPercentPpn,
0 AS SupplierInvoiceTaxAmountPpn,
dp.SupplierDownpaymentAmount AS SupplierInvoiceGrandTotal,
'DP' AS type
FROM supplier_payment sp
JOIN supplier_downpayment dp
ON dp.SupplierDownpaymentID = sp.SupplierPaymentSupplierDownpaymentID
WHERE sp.SupplierPaymentID = ? AND sp.SupplierPaymentIsActive = 'Y'";
$que = $this->db->query($sql, [$para['paymentID']]);
if (!$que) {
throw new Exception("[Error] failed get DP row data", 2);
}
$data = $que->row_array();
$sql_detail = "SELECT
CONCAT('DP-', M_ItemDesc) AS M_ItemDesc,
PurchaseOrderDetailQty AS SupplierInvoiceDetailQty,
PurchaseOrderDetailPrice AS SupplierInvoiceDetailPrice,
PurchaseOrderSummaryDiscountAmount AS SupplierInvoiceDetailDiscountAmount,
(PurchaseOrderDetailPrice - PurchaseOrderSummaryDiscountAmount) AS DiscountedPrice,
PurchaseOrderSummaryTotal AS SupplierInvoiceDetailTotal
FROM supplier_downpayment
JOIN purchase_order
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
JOIN purchase_order_detail
ON PurchaseOrderDetailPurchaseOrderID = PurchaseOrderID
AND PurchaseOrderDetailIsActive = 'Y'
JOIN purchase_order_summary
ON PurchaseOrderSummaryID = PurchaseOrderDetailPurchaseSummaryID
AND PurchaseOrderSummaryIsActive = 'Y'
JOIN m_item
ON M_ItemID = PurchaseOrderDetailItemID
WHERE SupplierDownpaymentPurchasOrderID = ?";
$que_detail = $this->db->query($sql_detail, [
$data['SupplierDownpaymentPurchasOrderID']
]);
if (!$que_detail) {
throw new Exception('failed to get dp detail', 2);
}
$data['detail'] = $que_detail->result_array();
}
$this->sys_ok($data); $this->sys_ok($data);
} catch (Exception $exc) { } catch (Exception $exc) {
@@ -214,12 +311,12 @@ class Billv2 extends MY_Controller {
$user = $this->sys_user; $user = $this->sys_user;
if ($para['userlevel'] == '1') { if ($para['userlevel'] == '1') {
$sql = "UPDATE supplier_payment SET $sql = "UPDATE supplier_payment SET
SupplierPaymentIsVerif = 'Y', SupplierPaymentIsVerif = 'Y',
SupplierPaymentStatus = 'Verified', SupplierPaymentStatus = 'Verified',
SupplierPaymentVerifUserID = ?, SupplierPaymentVerifUserID = ?,
SupplierPaymentVerifDate = NOW() SupplierPaymentVerifDate = NOW()
WHERE SupplierPaymentID = ? WHERE SupplierPaymentID = ?
AND SupplierPaymentIsActive = 'Y'"; AND SupplierPaymentIsActive = 'Y'";
$query = $this->db->query($sql, [ $query = $this->db->query($sql, [
$user['M_UserID'], $para['paymentID'] $user['M_UserID'], $para['paymentID']
@@ -231,12 +328,12 @@ class Billv2 extends MY_Controller {
} }
if ($para['userlevel'] == '2') { if ($para['userlevel'] == '2') {
$sql = "UPDATE supplier_payment SET $sql = "UPDATE supplier_payment SET
SupplierPaymentIsApproved = 'Y', SupplierPaymentIsApproved = 'Y',
SupplierPaymentStatus = 'Approved', SupplierPaymentStatus = 'Approved',
SupplierPaymentApprovedUserID = ?, SupplierPaymentApprovedUserID = ?,
SupplierPaymentApprovedDate = NOW() SupplierPaymentApprovedDate = NOW()
WHERE SupplierPaymentID = ? WHERE SupplierPaymentID = ?
AND SupplierPaymentIsActive = 'Y'"; AND SupplierPaymentIsActive = 'Y'";
$query = $this->db->query($sql, [ $query = $this->db->query($sql, [
$user['M_UserID'], $para['paymentID'] $user['M_UserID'], $para['paymentID']
@@ -261,4 +358,4 @@ class Billv2 extends MY_Controller {
exit; exit;
} }
} }
} }

View File

@@ -1,19 +1,20 @@
<?php <?php
class Bill extends MY_Controller class Bill extends MY_Controller
{ {
var $db_onedev; var $db_onedev;
public function index() public function index()
{ {
echo "Bill API"; echo "Bill API";
} }
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->db_onedev = $this->load->database("onedev", true); $this->db_onedev = $this->load->database("onedev", true);
} }
public function add_notes($orderid){ public function add_notes($orderid)
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id, {
$sql = "SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
SupplierPaymentID as note_id, SupplierPaymentID as note_id,
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id, SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
SupplierPaymentDate as note_date, SupplierPaymentDate as note_date,
@@ -33,223 +34,590 @@ class Bill extends MY_Controller
SupplierPaymentIsApproved, SupplierPaymentIsApproved,
CONCAT('Approved by : ',a.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')) as d_approved, 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 CONCAT('Verified by : ',b.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')) as d_verif
FROM supplier_payment FROM supplier_payment
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y' JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
LEFT JOIN coa ON SupplierPaymentCoaID = coaID LEFT JOIN coa
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID LEFT JOIN m_user n
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID ON SupplierPaymentUserID = n.M_UserID
LEFT JOIN m_user b ON SupplierPaymentVerifUserID = b.M_UserID LEFT JOIN m_user c
WHERE ON SupplierPaymentConfirmUserID = c.M_UserID
SupplierPaymentSupplierInvoiceID = {$orderid} LEFT JOIN m_user a
AND ON SupplierPaymentApprovedUserID = a.M_UserID
SupplierPaymentIsActive = 'Y' LEFT JOIN m_user b
GROUP BY SupplierPaymentID"; ON SupplierPaymentVerifUserID = b.M_UserID
$query = $this->db_onedev->query($sql); WHERE SupplierPaymentSupplierInvoiceID = {$orderid}
if ($query) { AND SupplierPaymentIsActive = 'Y'
$rows = $query->result_array(); GROUP BY SupplierPaymentID";
if($rows){ $query = $this->db_onedev->query($sql);
foreach($rows as $k => $v){ if ($query) {
$rows[$k]['tests'] = $this->add_tests($v['note_id']); $rows = $query->result_array();
} if ($rows) {
} foreach ($rows as $k => $v) {
return $rows; $rows[$k]['tests'] = $this->add_tests($v['note_id']);
}
} else { }
$this->sys_error_db("get notes", $this->db_onedev); return $rows;
exit; } else {
} $this->sys_error_db("get notes", $this->db_onedev);
} exit;
public function add_tagihans($orderid){
$sql = "SELECT SupplierInvoiceID as tagihan_id,
PurchaseOrderNumber as tagihan_number,
jurnalTxDescription as pasien,
jurnalTxCredit as tagihan_total,
IF(SupplierPaymentDetailID IS NULL , jurnalTxCredit, jurnalTxCredit - SUM(SupplierPaymentDetailAmount)) as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
SupplierInvoiceIsActive as tagihan_active,
'N' as show_detail,
jurnalTxID SupplierInvoiceDetailID,
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
FROM supplier_invoice
JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceIsActive = 'Y'
LEFT JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID AND SupplierPaymentDetailIsActive = 'Y'
WHERE SupplierInvoiceID = ?
GROUP BY jurnalTxID";
$query = $this->db_onedev->query($sql, [$orderid]);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid){
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
SupplierPaymentID as note_id,
SupplierPaymentDate as note_date,
SupplierPaymentNumber as note_number,
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
SUM(SupplierPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
SupplierPaymentDetailIsActive as note_active,
PurchaseOrderNumber,
SupplierInvoiceDetailTotal,
SupplierPaymentDetailAmount
FROM supplier_payment
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
JOIN coa ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID
WHERE
SupplierPaymentID = {$orderid}
GROUP BY SupplierPaymentDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
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; public function add_notes_downpayment($orderid)
$number_offset = ($prm['current_page'] - 1) * $number_limit ; {
$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;
}
}
$where = "SupplierInvoiceIsActive = 'Y' public function add_tagihans($orderid)
AND SupplierPaymentIsApproved = 'Y' {
AND SupplierPaymentIsVerif = 'Y' $sql = "SELECT SupplierInvoiceID as tagihan_id,
AND SupplierPaymentIsConfirm = '{$status}' PurchaseOrderNumber as tagihan_number,
AND (SupplierInvoiceNumber LIKE '%{$search}%' OR SupplierInvoiceSupplierInvoiceNumber LIKE '%{$search}%') jurnalTxDescription as pasien,
AND SupplierName LIKE '%{$supplier}%' jurnalTxCredit as tagihan_total,
AND ReceiveOrderPoS_RegionalID = {$regionalid} IF(SupplierPaymentDetailID IS NULL , jurnalTxCredit, jurnalTxCredit - SUM(SupplierPaymentDetailAmount)) as tagihan_tagihan,
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'"; 0 as tagihan_bayar,
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
SupplierInvoiceIsActive as tagihan_active,
'N' as show_detail,
jurnalTxID SupplierInvoiceDetailID,
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
FROM supplier_invoice
JOIN purchase_order
ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
JOIN jurnal_addon
ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN jurnal_tx
ON jurnalTxJurnalID = jurnalAddOnJurnalID
AND jurnalTxCredit <> 0
AND jurnalTxCoaID <> 563
LEFT JOIN supplier_payment
ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
AND SupplierInvoiceIsActive = 'Y'
LEFT JOIN supplier_payment_detail
ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID
AND SupplierPaymentDetailIsActive = 'Y'
WHERE SupplierInvoiceID = ?
GROUP BY jurnalTxID";
$query = $this->db_onedev->query($sql, [$orderid]);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid)
{
$sql = "SELECT
SupplierPaymentSupplierInvoiceID as note_order_id,
SupplierPaymentID as note_id,
SupplierPaymentDate as note_date,
SupplierPaymentNumber as note_number,
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
SUM(SupplierPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
SupplierPaymentDetailIsActive as note_active,
PurchaseOrderNumber,
SupplierInvoiceDetailTotal,
SupplierPaymentDetailAmount
FROM supplier_payment
JOIN supplier_payment_detail
ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
LEFT JOIN supplier_invoice_detail
ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
LEFT JOIN purchase_order
ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
JOIN coa
ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user
ON SupplierPaymentDetailUserID = M_UserID
WHERE SupplierPaymentID = {$orderid}
GROUP BY SupplierPaymentDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if ($rows) {
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search_old()
{
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'];
$sql = " SELECT count(*) as total $number_limit = 10;
FROM supplier_invoice $number_offset = ((int)$prm['current_page'] - 1) * $number_limit;
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);
// ── WHERE ────────────────────────────────────────────────
$where = " si.SupplierInvoiceIsActive = 'Y'
AND sp.SupplierPaymentIsApproved = 'Y'
AND sp.SupplierPaymentIsVerif = 'Y'
AND sp.SupplierPaymentIsConfirm = ?
AND (si.SupplierInvoiceNumber LIKE ?
OR si.SupplierInvoiceSupplierInvoiceNumber LIKE ?)
AND sup.SupplierName LIKE ?
AND rop.ReceiveOrderPoS_RegionalID = ?
AND si.SupplierInvoiceDraftPaymentDate BETWEEN ? AND ? ";
$tot_count = 0; $where_params = [
$tot_page = 0; $status,
if ($query) { '%' . $search . '%',
$tot_count = $query->result_array()[0]["total"]; '%' . $search . '%',
$tot_page = ceil($tot_count/$number_limit); '%' . $supplier . '%',
} else { $regionalid,
$this->sys_error_db("supplier_invoice count", $this->db_onedev); $startdate,
exit; $enddate,
} ];
// ── COUNT ────────────────────────────────────────────────
$sql_count = "
SELECT count(*) as total
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN receive_order_po rop ON rop.ReceiveOrderPoID = si.SupplierInvoiceReceiveOrderPoID
LEFT JOIN supplier_payment sp
ON sp.SupplierPaymentSupplierInvoiceID = si.SupplierInvoiceID
AND sp.SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier sup ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE $where";
$sql = "SELECT supplier_invoice.*, $query = $this->db_onedev->query($sql_count, $where_params);
SupplierName,
'' M_MouName,
0 as totalbill,
0 as paid,
0 as unpaid,
SupplierInvoiceIsLunas as flaglunas,
'' 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,
SupplierPaymentID,
SupplierPaymentIsConfirm,
DATE_FORMAT(IFNULL(SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y') as tanggalinvoice,
0 xrounding,
'' chex,
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
$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("supplier_invoice count", $this->db_onedev);
exit;
}
FROM supplier_invoice // ── DATA — only columns the frontend actually reads ──────
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID $sql_data = "
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber SELECT
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID si.SupplierInvoiceID,
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y' si.SupplierInvoiceNumber,
WHERE si.SupplierInvoiceDraftPaymentDate,
$where si.SupplierInvoiceIsLunas AS flaglunas,
GROUP BY SupplierInvoiceID si.SupplierInvoiceSupplierInvoiceNumber,
ORDER BY SupplierInvoiceID ASC DATE_FORMAT(
limit $number_limit offset $number_offset"; IFNULL(si.SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y'
//echo $sql; ) AS tanggalinvoice,
$query = $this->db_onedev->query($sql, $sql_param); sup.SupplierName,
$rows = $query->result_array(); sp.SupplierPaymentID,
if($rows){ sp.SupplierPaymentIsConfirm,
foreach($rows as $k => $v){ IFNULL(sp.SupplierPaymentCashierNumber,'') AS SupplierPaymentCashierNumber,
$rows[$k]['chex'] = false; DATE_FORMAT(
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber, si.SupplierInvoiceDraftPaymentDate,'%d-%m-%Y'
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount, ) AS tanggalbayar,
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate 0 AS totalbill,
FROM supplier_payment 0 AS paid,
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row(); 0 AS unpaid,
'' AS SupplierPaymentNumber,
0 AS SupplierPaymentAmount,
'' AS SupplierPaymentDate,
'' AS notes,
'' AS tagihans,
0 AS xrounding,
'' AS chex
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN receive_order_po rop ON rop.ReceiveOrderPoID = si.SupplierInvoiceReceiveOrderPoID
LEFT JOIN supplier_payment sp
ON sp.SupplierPaymentSupplierInvoiceID = si.SupplierInvoiceID
AND sp.SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier sup ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE $where
GROUP BY si.SupplierInvoiceID
ORDER BY si.SupplierInvoiceID ASC
LIMIT ? OFFSET ?";
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill $data_params = array_merge($where_params, [$number_limit, $number_offset]);
FROM supplier_invoice $query = $this->db_onedev->query($sql_data, $data_params);
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber $rows = $query->result_array();
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]['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($v['SupplierInvoiceID']); // ── ENRICH ───────────────────────────────────────────────
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']); if ($rows) {
foreach ($rows as $k => $v) {
$rows[$k]['chex'] = false;
$inv_id = $v['SupplierInvoiceID'];
} $s_payment = $this->db_onedev->query("
} SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
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 si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN jurnal_tx jt
ON jt.jurnalTxJurnalID = ja.jurnalAddOnJurnalID
AND jt.jurnalTxCredit <> 0
AND jt.jurnalTxCoaID <> 563
WHERE si.SupplierInvoiceID = ?
GROUP BY si.SupplierInvoiceID",
[$inv_id]
)->row();
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query()); $amount = $s_payment->SupplierPaymentAmount
$this->sys_ok($result); ? $s_payment->SupplierPaymentAmount
exit; : "0.00";
} $unpaid = (float)$s_jurnal->totalbill - (float)$amount;
$rows[$k]['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;
}
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 branch WHERE ─────────────────────────────────
$inv_where = " si.SupplierInvoiceIsActive = 'Y'
AND rop.ReceiveOrderPoS_RegionalID = ? ";
$inv_params = [$regionalid];
// ── DOWNPAYMENT branch WHERE ─────────────────────────────
$dp_where = " dp.SupplierDownpaymentIsActive = 'Y'
AND po.PurchaseOrderS_RegionalID = ? ";
$dp_params = [$regionalid];
// ── UNION base ───────────────────────────────────────────
$sql_base = "
SELECT
si.SupplierInvoiceID,
si.SupplierInvoiceNumber,
si.SupplierInvoiceDraftPaymentDate,
si.SupplierInvoiceDraftPaymentDate AS filter_date,
si.SupplierInvoiceIsLunas AS flaglunas,
si.SupplierInvoiceSupplierInvoiceNumber,
DATE_FORMAT(
IFNULL(si.SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y'
) AS tanggalinvoice,
sup.SupplierName,
sp.SupplierPaymentID,
sp.SupplierPaymentIsConfirm,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsActive,
IFNULL(sp.SupplierPaymentCashierNumber,'') AS SupplierPaymentCashierNumber,
DATE_FORMAT(
si.SupplierInvoiceDraftPaymentDate,'%d-%m-%Y'
) AS tanggalbayar,
0 AS totalbill,
0 AS paid,
0 AS unpaid,
'' AS SupplierPaymentNumber,
0 AS SupplierPaymentAmount,
'' AS SupplierPaymentDate,
'' AS notes,
'' AS tagihans,
0 AS xrounding,
'' AS chex,
'INVOICE' AS type
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN receive_order_po rop ON rop.ReceiveOrderPoID = si.SupplierInvoiceReceiveOrderPoID
LEFT JOIN supplier_payment sp
ON sp.SupplierPaymentSupplierInvoiceID = si.SupplierInvoiceID
AND sp.SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier sup ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE $inv_where
GROUP BY si.SupplierInvoiceID
UNION ALL
SELECT
dp.SupplierDownpaymentID * -1 AS SupplierInvoiceID,
CONCAT('DP-', po.PurchaseOrderNumber) AS SupplierInvoiceNumber,
dp.SupplierDownpaymentDueDate AS SupplierInvoiceDraftPaymentDate,
dp.SupplierDownpaymentDueDate AS filter_date,
dp.SupplierDownpaymentIsLunas AS flaglunas,
'' AS SupplierInvoiceSupplierInvoiceNumber,
DATE_FORMAT(dp.SupplierDownpaymentDate,'%d-%m-%Y') AS tanggalinvoice,
dp_sup.SupplierName AS SupplierName,
sp.SupplierPaymentID,
sp.SupplierPaymentIsConfirm,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsActive,
IFNULL(sp.SupplierPaymentCashierNumber,'') AS SupplierPaymentCashierNumber,
DATE_FORMAT(
dp.SupplierDownpaymentDueDate,'%d-%m-%Y'
) AS tanggalbayar,
dp.SupplierDownpaymentAmount AS totalbill,
CASE WHEN dp.SupplierDownpaymentStatus = 'Paid'
THEN dp.SupplierDownpaymentAmount
ELSE 0 END AS paid,
CASE WHEN dp.SupplierDownpaymentStatus = 'Paid'
THEN 0
ELSE dp.SupplierDownpaymentAmount END AS unpaid,
'' AS SupplierPaymentNumber,
0 AS SupplierPaymentAmount,
'' AS SupplierPaymentDate,
'' AS notes,
'' AS tagihans,
0 AS xrounding,
'' AS chex,
'DP' AS type
FROM supplier_payment sp
JOIN supplier_downpayment dp
ON dp.SupplierDownpaymentID = sp.SupplierPaymentSupplierDownpaymentID
JOIN supplier dp_sup
ON dp_sup.SupplierID = dp.SupplierDownpaymentSupplierID
JOIN purchase_order po
ON po.PurchaseOrderID = dp.SupplierDownpaymentPurchasOrderID
WHERE $dp_where";
// ── Outer common filters ─────────────────────────────────
$outer_where = " SupplierPaymentIsActive = 'Y'
AND SupplierPaymentIsApproved = 'Y'
AND SupplierPaymentIsVerif = 'Y'
AND SupplierPaymentIsConfirm = ?
AND (SupplierInvoiceNumber LIKE ? OR SupplierInvoiceSupplierInvoiceNumber LIKE ?)
AND SupplierName LIKE ?
AND filter_date BETWEEN ? AND ? ";
$outer_params = [
$status,
'%' . $search . '%',
'%' . $search . '%',
'%' . $supplier . '%',
$startdate,
$enddate,
];
// ── COUNT ────────────────────────────────────────────────
$sql_count = "
SELECT COUNT(*) AS total
FROM ($sql_base) AS combined
WHERE $outer_where";
$count_params = array_merge($inv_params, $dp_params, $outer_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("supplier payment count", $this->db_onedev);
exit;
}
// ── DATA ─────────────────────────────────────────────────
$sql_data = "
SELECT * FROM ($sql_base) AS combined
WHERE $outer_where
ORDER BY SupplierInvoiceID ASC
LIMIT ? OFFSET ?";
$data_params = array_merge($inv_params, $dp_params, $outer_params, [$number_limit, $number_offset]);
$query = $this->db_onedev->query($sql_data, $data_params);
$rows = $query->result_array();
// ── ENRICH ───────────────────────────────────────────────
if ($rows) {
foreach ($rows as $k => $v) {
// ── Downpayment branch ──────────────────────────
if ($v['type'] === 'DP') {
$rows[$k]['chex'] = false;
$dp_id = abs($v['SupplierInvoiceID']);
$s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
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]['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'] = [];
continue;
}
// ── Invoice branch ──────────────────────────────
$rows[$k]['chex'] = false;
$inv_id = $v['SupplierInvoiceID'];
$s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
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 si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN jurnal_tx jt
ON jt.jurnalTxJurnalID = ja.jurnalAddOnJurnalID
AND jt.jurnalTxCredit <> 0
AND jt.jurnalTxCoaID <> 563
WHERE si.SupplierInvoiceID = ?
GROUP BY si.SupplierInvoiceID",
[$inv_id]
)->row();
$amount = $s_payment->SupplierPaymentAmount
? $s_payment->SupplierPaymentAmount
: "0.00";
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
$rows[$k]['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;
}
} }

View File

@@ -70,14 +70,28 @@ class PaymentV2 extends MY_Controller
} }
# UPDATE status lunas supplier invoice # # UPDATE status lunas supplier invoice #
$sql_suppinvoice = "UPDATE supplier_invoice if ($param['type'] == 'DP') {
SET SupplierInvoiceIsLunas = 'Y' $sql_updatedp = "UPDATE supplier_downpayment
WHERE SupplierInvoiceID = ?"; SET SupplierDownpaymentIsLunas = 'Y'
$que_suppinvoice = $this->db->query($sql_suppinvoice, [$param['SupplierInvoiceID']]); WHERE SupplierDownpaymentID = ?";
if (!$que_suppinvoice) { $que_updatedp = $this->db->query($sql_updatedp, [
$this->db->trans_rollback(); abs($param['SupplierInvoiceID'])
$this->sys_error_db("[Error] update status lunas invoice"); ]);
exit; if (!$que_updatedp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] update status lunas downpayment");
exit;
}
} else {
$sql_suppinvoice = "UPDATE supplier_invoice
SET SupplierInvoiceIsLunas = 'Y'
WHERE SupplierInvoiceID = ?";
$que_suppinvoice = $this->db->query($sql_suppinvoice, [$param['SupplierInvoiceID']]);
if (!$que_suppinvoice) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] update status lunas invoice");
exit;
}
} }
# GET Latest data supplier payment # # GET Latest data supplier payment #
@@ -89,16 +103,33 @@ class PaymentV2 extends MY_Controller
exit; exit;
} }
$suppayment_header = $que_suppayment->row_array(); $suppayment_header = $que_suppayment->row_array();
$suppayment_detail = [];
$sql_suppaymentdetail = "SELECT * FROM supplier_payment_detail if ($param['type'] == 'DP') {
$sql_suppaymentdetail = "SELECT supplier_downpayment.*
FROM supplier_payment
JOIN supplier_downpayment
ON SupplierPaymentSupplierDownpaymentID = SupplierDownpaymentID
AND SupplierDownpaymentIsActive = 'Y'
WHERE SupplierPaymentID = ?";
$que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]);
if (!$que_suppaymentdetail) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] get data latest supplier downpayment");
exit;
}
$suppayment_detail = $que_suppaymentdetail->result_array();
} else {
$sql_suppaymentdetail = "SELECT * FROM supplier_payment_detail
WHERE SupplierPaymentDetailSupplierPaymentID = ?"; WHERE SupplierPaymentDetailSupplierPaymentID = ?";
$que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]); $que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]);
if (!$que_suppaymentdetail) { if (!$que_suppaymentdetail) {
$this->db->trans_rollback(); $this->db->trans_rollback();
$this->sys_error_db("[Error] get data latest supplier payment detail"); $this->sys_error_db("[Error] get data latest supplier payment detail");
exit; exit;
}
$suppayment_detail = $que_suppaymentdetail->result_array();
} }
$suppayment_detail = $que_suppaymentdetail->result_array();
$data_log = [ $data_log = [
"header" => $suppayment_header, "header" => $suppayment_header,
@@ -121,38 +152,85 @@ class PaymentV2 extends MY_Controller
# INSERT JURNAL # # INSERT JURNAL #
$detail_transac = []; $detail_transac = [];
# GET data hutang # if ($param['type'] == "DP") {
$sql_datahutang = "SELECT $sql_coaDP = "SELECT
SupplierPaymentNumber AS addonvalue, coaID,
SupplierPaymentDetailID, coaDescription,
jurnalTxCoaID AS coaID, SupplierDownpaymentAmount,
jurnalTxDescription AS coaDescription, M_ItemID,
SupplierPaymentDetailAmount, SupplierPaymentNumber,
SupplierInvoiceDetailItemID M_ItemID
FROM supplier_payment FROM supplier_payment
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID JOIN supplier_downpayment
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierPaymentSupplierInvoiceID ON SupplierDownpaymentID = SupplierPaymentSupplierDownpaymentID
AND SupplierInvoiceDetailIsActive = 'Y' AND SupplierDownpaymentIsActive = 'Y'
JOIN jurnal_tx ON SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID JOIN purchase_order_detail
WHERE SupplierPaymentID = ? ON SupplierDownpaymentPurchasOrderID = PurchaseOrderDetailPurchaseOrderID
AND SupplierPaymentDetailIsActive = 'Y'"; AND PurchaseOrderDetailIsActive = 'Y'
$que_datahutang = $this->db->query($sql_datahutang, [$param['orderid']]); JOIN m_item
if (!$que_datahutang) { ON M_ItemID = PurchaseOrderDetailItemID
$this->db->trans_rollback(); AND M_ItemIsActive = 'Y'
$this->sys_error_db("[Error] get data hutang item"); JOIN fa_class
exit; ON Fa_ClassID = M_ItemFa_ClassID
} AND M_ItemIsActive = 'Y'
$data_hutang = $que_datahutang->result_array(); JOIN coa
foreach ($data_hutang as $key => $debt) { ON coaID = Fa_ClassDownPaymentCoaID
$detail_transac[] = [ AND coaIsActive = 'Y'
"coaID" => $debt['coaID'], WHERE SupplierPaymentID = ?";
"coaDescription" => $debt['coaDescription'], $que_coaDP = $this->db->query($sql_coaDP, [
"debit" => $debt['SupplierPaymentDetailAmount'], $param['orderid']
"credit" => 0, ]);
"addoncode" => "JFA", if (!$que_coaDP) {
"addonvalue" => $debt['addonvalue'], $this->db->trans_rollback();
"addonitemid" => $debt['SupplierInvoiceDetailItemID'] $this->sys_error_db("[Error] get data hutang item");
]; exit;
}
$data_dp = $que_coaDP->result_array();
foreach ($data_dp as $key => $dp) {
$detail_transac[] = [
"coaID" => $dp['coaID'],
"coaDescription" => $dp['coaDescription'],
"debit" => $dp['SupplierDownpaymentAmount'],
"credit" => 0,
"addoncode" => "DP-JFA",
"addonvalue" => $dp['SupplierPaymentNumber'],
"addonitemid" => $dp['M_ItemID']
];
}
} else {
# GET data hutang #
$sql_datahutang = "SELECT
SupplierPaymentNumber AS addonvalue,
SupplierPaymentDetailID,
jurnalTxCoaID AS coaID,
jurnalTxDescription AS coaDescription,
SupplierPaymentDetailAmount,
SupplierInvoiceDetailItemID
FROM supplier_payment
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierPaymentSupplierInvoiceID
AND SupplierInvoiceDetailIsActive = 'Y'
JOIN jurnal_tx ON SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID
WHERE SupplierPaymentID = ?
AND SupplierPaymentDetailIsActive = 'Y'";
$que_datahutang = $this->db->query($sql_datahutang, [$param['orderid']]);
if (!$que_datahutang) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] get data hutang item");
exit;
}
$data_hutang = $que_datahutang->result_array();
foreach ($data_hutang as $key => $debt) {
$detail_transac[] = [
"coaID" => $debt['coaID'],
"coaDescription" => $debt['coaDescription'],
"debit" => $debt['SupplierPaymentDetailAmount'],
"credit" => 0,
"addoncode" => "JFA",
"addonvalue" => $debt['addonvalue'],
"addonitemid" => $debt['SupplierInvoiceDetailItemID']
];
}
} }
# GET data bayar # # GET data bayar #

View File

@@ -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) public function add_tagihans($orderid)
{ {
$sql = "SELECT SupplierInvoiceID as tagihan_id, $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 //# cek token valid
if (! $this->isLogin) { if (! $this->isLogin) {
$this->sys_error("Invalid Token"); $this->sys_error("Invalid Token");
exit; exit;
} }
$prm = $this->sys_input; $prm = $this->sys_input;
$supplier = $prm["supplier"]; $supplier = $prm["supplier"];
$search = $prm["search"]; $search = $prm["search"];
@@ -151,25 +204,25 @@ class Bill extends MY_Controller
$number_offset = ($prm['current_page'] - 1) * $number_limit; $number_offset = ($prm['current_page'] - 1) * $number_limit;
$where = "SupplierInvoiceIsActive = 'Y' $where = "SupplierInvoiceIsActive = 'Y'
AND SupplierInvoiceStatus = 'Approved' AND SupplierInvoiceStatus = 'Approved'
AND SupplierInvoiceGrandTotal > 0 AND SupplierInvoiceGrandTotal > 0
AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}' AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}'
AND (SupplierInvoiceNumber LIKE '%{$search}%' AND SupplierName LIKE '%{$supplier}%') AND (SupplierInvoiceNumber LIKE '%{$search}%' AND SupplierName LIKE '%{$supplier}%')
AND ReceiveOrderPoS_RegionalID = {$regionalid} AND ReceiveOrderPoS_RegionalID = {$regionalid}
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'"; AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'";
$sql = " SELECT count(*) as total $sql = " SELECT count(*) as total
FROM supplier_invoice FROM supplier_invoice
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y' LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
WHERE WHERE
$where $where
"; ";
// echo $sql; // echo $sql;
$query = $this->db_onedev->query($sql, $sql_param); $query = $this->db_onedev->query($sql, $sql_param);
@@ -186,55 +239,55 @@ class Bill extends MY_Controller
$sql = "SELECT supplier_invoice.*, $sql = "SELECT supplier_invoice.*,
SupplierName, SupplierName,
'' M_MouName, '' M_MouName,
0 as totalbill, 0 as totalbill,
0 as paid, 0 as paid,
0 as unpaid, 0 as unpaid,
SupplierInvoiceIsLunas as flaglunas, SupplierInvoiceIsLunas as flaglunas,
0 as SupplierPaymentID, 0 as SupplierPaymentID,
'' as SupplierPaymentNumber, '' as SupplierPaymentNumber,
0 as SupplierPaymentAmount, 0 as SupplierPaymentAmount,
'' as SupplierPaymentDate, '' as SupplierPaymentDate,
'' as SupplierInvoiceIssueRefNumber, '' as SupplierInvoiceIssueRefNumber,
'' as notes, '' as notes,
'' as tagihans, '' as tagihans,
'N' as isbillterpusat, 'N' as isbillterpusat,
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar, DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext, DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice, IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice,
IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved, IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved,
IFNULL(SupplierPaymentIsVerif,'N') as SupplierPaymentIsVerif, IFNULL(SupplierPaymentIsVerif,'N') as SupplierPaymentIsVerif,
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
FROM supplier_invoice FROM supplier_invoice
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y' LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
WHERE WHERE
$where $where
GROUP BY SupplierInvoiceID GROUP BY SupplierInvoiceID
ORDER BY SupplierInvoiceID ASC ORDER BY SupplierInvoiceID ASC
limit $number_limit offset $number_offset"; limit $number_limit offset $number_offset";
//echo $sql; //echo $sql;
$query = $this->db_onedev->query($sql, $sql_param); $query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array(); $rows = $query->result_array();
if ($rows) { if ($rows) {
foreach ($rows as $k => $v) { foreach ($rows as $k => $v) {
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber, $s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount, SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
IFNULL(SupplierPaymentID,0) SupplierPaymentID, IFNULL(SupplierPaymentID,0) SupplierPaymentID,
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
FROM supplier_payment FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row(); WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill $s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill
FROM supplier_invoice FROM supplier_invoice
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563 JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']} WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']}
GROUP BY SupplierInvoiceID")->row(); GROUP BY SupplierInvoiceID")->row();
$amount = $s_payment->SupplierPaymentAmount ? $s_payment->SupplierPaymentAmount : "0.00"; $amount = $s_payment->SupplierPaymentAmount ? $s_payment->SupplierPaymentAmount : "0.00";
$unpaid = (float)$s_jurnal->totalbill - (float)$amount; $unpaid = (float)$s_jurnal->totalbill - (float)$amount;
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID ? $s_payment->SupplierPaymentID : '0'; $rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID ? $s_payment->SupplierPaymentID : '0';
@@ -255,4 +308,270 @@ class Bill extends MY_Controller
$this->sys_ok($result); $this->sys_ok($result);
exit; 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;
}
} }

File diff suppressed because it is too large Load Diff