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