feature: receive item order asset & insert jurnal faktur asset
This commit is contained in:
@@ -1453,7 +1453,6 @@ class Fakturv4 extends MY_Controller
|
||||
$coapph = $quepph->result_array()[0];
|
||||
|
||||
$pphval = doubleval($invoice[0]['SupplierInvoiceTaxAmountPph']);
|
||||
|
||||
if ($pphval > 0.00) {
|
||||
$insertpph = $this->InsertJurnalTx(
|
||||
$jurnalID,
|
||||
@@ -1465,22 +1464,22 @@ class Fakturv4 extends MY_Controller
|
||||
);
|
||||
if (!$insertpph['status']) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db($insertpajak['msg']);
|
||||
$this->sys_error_db($insertpph['msg']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
# insert shipping cost ke jurnal #
|
||||
// ----------------------------------------------------------------------------------------
|
||||
$queryshipcost = $this->db->query($sqlcoa, ['5320700001']);
|
||||
if (!$queryshipcost) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get coa cost ");
|
||||
exit;
|
||||
}
|
||||
$coashipcost = $queryshipcost->result_array()[0];
|
||||
|
||||
if ($ship_cost > 0.00) {
|
||||
$queryshipcost = $this->db->query($sqlcoa, ['5320700001']);
|
||||
if (!$queryshipcost) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get coa cost ");
|
||||
exit;
|
||||
}
|
||||
$coashipcost = $queryshipcost->result_array()[0];
|
||||
|
||||
$insertcost = $this->InsertJurnalTx(
|
||||
$jurnalID,
|
||||
$coashipcost['coaID'],
|
||||
@@ -1496,6 +1495,57 @@ 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;
|
||||
}
|
||||
|
||||
$invoice = $this->CalcProrateDownPaymentAsset($invoice, $totalDP);
|
||||
}
|
||||
}
|
||||
|
||||
// insert jurnal tx hutang per item (kredit)
|
||||
// ----------------------------------------------------------------------------------------
|
||||
foreach ($invoice as $key => $inv) {
|
||||
@@ -1603,52 +1653,20 @@ class Fakturv4 extends MY_Controller
|
||||
$this->sys_error_db($status['msg']);
|
||||
exit;
|
||||
}
|
||||
} else if ($item['M_ItemItem_CategoryID'] == '3' && !empty($item['M_ItemFa_ClassID'])) {
|
||||
$sqlsgp = "SELECT * FROM fa_class WHERE Fa_ClassID = ? AND Fa_ClassIsActive = 'Y'";
|
||||
$quesgp = $this->db->query($sqlsgp, [$item['M_ItemFa_ClassID']]);
|
||||
if (!$quesgp) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get map_nat_subgroup");
|
||||
exit;
|
||||
}
|
||||
$itemGroup = $quesgp->row_array();
|
||||
|
||||
if (empty($itemGroup)) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] fa class item tidak ditemukan / belum dimapping");
|
||||
exit;
|
||||
}
|
||||
|
||||
$price = (doubleval($inv['SupplierInvoiceDetailTotal']) - doubleval($inv['SupplierInvoiceDetailDiscountPoProrata']));
|
||||
// $taxPPH = doubleval($inv['SupplierInvoiceTaxPercentPph']) * $price / 100;
|
||||
$taxPPN = doubleval($inv['SupplierInvoiceTaxPercentPpn']) * $price / 100;
|
||||
|
||||
$kredit = round($price + $taxPPN, 2);
|
||||
|
||||
$status = $this->InsertJurnalTx(
|
||||
$jurnalID,
|
||||
$itemGroup['Fa_ClassCoaID'],
|
||||
$itemGroup['Fa_ClassCoaDesc'],
|
||||
$user['M_UserID'],
|
||||
0,
|
||||
$kredit
|
||||
);
|
||||
if (!$status) {
|
||||
$this->sys_error_db($status['msg']);
|
||||
exit;
|
||||
}
|
||||
} else if ($item['M_ItemItem_CategoryID'] == '3') {
|
||||
$this->InsertJurnalTxAsset($jurnalID, $item['M_ItemID'], $inv, $user['M_UserID']);
|
||||
} else if ($item['M_ItemItem_CategoryID'] == '4') {
|
||||
$this->InsertJurnalTxJasa($jurnalID, $item['M_ItemID'], $inv, $user['M_UserID']);
|
||||
}
|
||||
}
|
||||
|
||||
$sqlinvgr = "INSERT INTO jurnal_addon (
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES (?,?,?,NOW(),?)";
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES (?,?,?,NOW(),?)";
|
||||
$queinvgr = $this->db->query($sqlinvgr, [
|
||||
$jurnalID,
|
||||
'INVGR',
|
||||
@@ -1674,13 +1692,13 @@ class Fakturv4 extends MY_Controller
|
||||
private function InsertJurnalTxJasa($jurnalID, $itemid, $invoice, $userid)
|
||||
{
|
||||
$sql_coa = "SELECT
|
||||
JasaCoaMapHutangCoaID,
|
||||
JasaCoaMapHutangCoaNo,
|
||||
JasaCoaMapHutangCoaDesc
|
||||
FROM jasa_coa_map
|
||||
JOIN coa ON coaID = JasaCoaMapHutangCoaID
|
||||
AND coaIsActive = 'Y'
|
||||
WHERE JasaCoaMapM_ItemID = ?";
|
||||
JasaCoaMapHutangCoaID,
|
||||
JasaCoaMapHutangCoaNo,
|
||||
JasaCoaMapHutangCoaDesc
|
||||
FROM jasa_coa_map
|
||||
JOIN coa ON coaID = JasaCoaMapHutangCoaID
|
||||
AND coaIsActive = 'Y'
|
||||
WHERE JasaCoaMapM_ItemID = ?";
|
||||
$que_coa = $this->db->query($sql_coa, [$itemid]);
|
||||
if (!$que_coa) {
|
||||
$this->db->trans_rollback();
|
||||
@@ -1717,6 +1735,93 @@ class Fakturv4 extends MY_Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function InsertJurnalTxAsset($jurnalID, $itemid, $invoice, $userid)
|
||||
{
|
||||
$sql_coa = "SELECT
|
||||
Fa_ClassHutangCoaID,
|
||||
Fa_ClassHutangCoaAccountNo,
|
||||
Fa_ClassHutangCoaDesc
|
||||
FROM m_item
|
||||
JOIN fa_class ON Fa_ClassID = M_ItemFa_ClassID
|
||||
WHERE M_ItemID = ?";
|
||||
$que_coa = $this->db->query($sql_coa, $itemid);
|
||||
if (!$que_coa) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] failed get coa hutang asset");
|
||||
exit;
|
||||
}
|
||||
$coaasset = $que_coa->row_array();
|
||||
if ($que_coa->num_rows() <= 0) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] aset debt coa not found");
|
||||
exit;
|
||||
}
|
||||
|
||||
$invtotal = doubleval($invoice['SupplierInvoiceDetailTotal']);
|
||||
$disprorata = doubleval($invoice['SupplierInvoiceDetailDiscountPoProrata']);
|
||||
|
||||
$price = $invtotal - $disprorata;
|
||||
$taxPPN = doubleval($invoice['SupplierInvoiceTaxPercentPpn']) * $price / 100;
|
||||
$kredit = round($price + $taxPPN, 2);
|
||||
$finalValue = round($kredit - doubleval($invoice['dpReduction']), 2);
|
||||
|
||||
$insert = $this->InsertJurnalTx(
|
||||
$jurnalID,
|
||||
$coaasset['Fa_ClassHutangCoaID'],
|
||||
$coaasset['Fa_ClassHutangCoaDesc'],
|
||||
$userid,
|
||||
0,
|
||||
$finalValue
|
||||
);
|
||||
if (!$insert) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db($insert['msg']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function CalcProrateDownPaymentAsset($items, $dpAmount)
|
||||
{
|
||||
$totalKredit = 0;
|
||||
foreach ($items as $key => $value) {
|
||||
$invtotal = doubleval($value['SupplierInvoiceDetailTotal']);
|
||||
$disprorata = doubleval($value['SupplierInvoiceDetailDiscountPoProrata']);
|
||||
|
||||
$price = $invtotal - $disprorata;
|
||||
$taxPPN = doubleval($value['SupplierInvoiceTaxPercentPpn']) * $price / 100;
|
||||
$kredit = round($price + $taxPPN, 2);
|
||||
$totalKredit = $totalKredit + $kredit;
|
||||
|
||||
$items[$key]['kredit'] = $kredit;
|
||||
}
|
||||
|
||||
if ($totalKredit <= 0) {
|
||||
foreach ($items as $key => $value) {
|
||||
$items[$key]['dpReduction'] = 0;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
$runningReduction = 0;
|
||||
end($items);
|
||||
$lastKey = key($items);
|
||||
reset($items);
|
||||
|
||||
foreach ($items as $key => $value) {
|
||||
if ($key === $lastKey) {
|
||||
$reduction = round($dpAmount - $runningReduction, 2);
|
||||
} else {
|
||||
$ratio = $value['kredit'] / $totalKredit;
|
||||
$reduction = round($dpAmount * $ratio, 2);
|
||||
$runningReduction += $reduction;
|
||||
}
|
||||
|
||||
$items[$key]['dpReduction'] = $reduction;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
function InsertJurnalTx($jurnalID, $coaID, $desc, $userID, $debit = 0, $kredit = 0): array
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -407,7 +407,7 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
PurchaseOrderGrandTotal AS grandtotal,
|
||||
CASE
|
||||
WHEN PurchaseOrderTaxPpnType = 'P' THEN 'percent'
|
||||
ELSE 'absolute'
|
||||
ELSE 'nominal'
|
||||
END AS typepajak,
|
||||
CASE
|
||||
WHEN PurchaseOrderTaxPpnType = 'P' THEN PurchaseOrderTaxPercentPpn
|
||||
@@ -415,7 +415,7 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
END AS valuepajak,
|
||||
CASE
|
||||
WHEN PurchaseOrderDiscountPercent > 0.00 THEN 'percent'
|
||||
ELSE 'absolute'
|
||||
ELSE 'nominal'
|
||||
END AS typediskon,
|
||||
CASE
|
||||
WHEN PurchaseOrderDiscountPercent > 0.00 THEN PurchaseOrderDiscountPercent
|
||||
@@ -425,6 +425,8 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
PurchaseOrderGrandTotal AS grandtotal,
|
||||
SupplierID AS supplierID,
|
||||
SupplierName,
|
||||
WarehouseID AS gudangID,
|
||||
WarehouseM_BranchID AS branchID,
|
||||
PurchaseOrderAssetContractID,
|
||||
PurchaseOrderAssetContractTAssetAttachmentID AS assetAttachmentID,
|
||||
PurchaseOrderAssetContractName AS contractName,
|
||||
@@ -440,6 +442,7 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
PurchaseOrderApprovedManagerUserID AS verifiedby
|
||||
FROM purchase_order
|
||||
JOIN supplier ON SupplierID = PurchaseOrderSupplierID
|
||||
JOIN warehouse ON WarehouseID = PurchaseOrderWarehouseID
|
||||
JOIN purchase_order_asset_contract
|
||||
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
|
||||
WHERE PurchaseOrderIsActive = 'Y'
|
||||
@@ -474,6 +477,7 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
}
|
||||
|
||||
$subtotal = floatval($datapo['subtotal']);
|
||||
$downpayment = floatval($datapo['installmentDownPayment']);
|
||||
$grandtotal = floatval($datapo['grandtotal']);
|
||||
|
||||
$valuediskon = floatval($datapo['valuediskon']);
|
||||
@@ -491,8 +495,11 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
"subtotal" => $subtotal,
|
||||
"diskon" => $valuediskon,
|
||||
"pajak" => $valuepajak,
|
||||
"downpayment" => $downpayment,
|
||||
"total_before_downpayment" => $downpayment + $grandtotal,
|
||||
"total" => $grandtotal
|
||||
];
|
||||
|
||||
/* map summary to purchase order */
|
||||
$datapo['valuepajak'] = floatval($datapo['valuepajak']);
|
||||
$datapo['valuediskon'] = floatval($datapo['valuediskon']);
|
||||
@@ -830,20 +837,20 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
|
||||
# update purchase_order_asset_contract #
|
||||
$sql_contract = "UPDATE purchase_order_asset_contract SET
|
||||
PurchaseOrderAssetContractTAssetAttachmentID = ?,
|
||||
PurchaseOrderAssetContractName = ?,
|
||||
PurchaseOrderAssetContractDate = ?,
|
||||
PurchaseOrderAssetContractStartDate = ?,
|
||||
PurchaseOrderAssetContractEndDate = ?,
|
||||
PurchaseOrderAssetContractDuration = ?,
|
||||
PurchaseOrderAssetContractInstallmentNumber = ?,
|
||||
PurchaseOrderAssetContractInstallmentDate = ?,
|
||||
PurchaseOrderAssetContractInstallmentPayAmount = ?,
|
||||
PurchaseOrderAssetContractInstallmentDownPaymentType = ?,
|
||||
PurchaseOrderAssetContractInstallmentDownPayment = ?,
|
||||
PurchaseOrderAssetContractLastUpdated = NOW()
|
||||
WHERE PurchaseOrderAssetContractID = ?
|
||||
AND PurchaseOrderAssetContractIsActive = 'Y'";
|
||||
PurchaseOrderAssetContractTAssetAttachmentID = ?,
|
||||
PurchaseOrderAssetContractName = ?,
|
||||
PurchaseOrderAssetContractDate = ?,
|
||||
PurchaseOrderAssetContractStartDate = ?,
|
||||
PurchaseOrderAssetContractEndDate = ?,
|
||||
PurchaseOrderAssetContractDuration = ?,
|
||||
PurchaseOrderAssetContractInstallmentNumber = ?,
|
||||
PurchaseOrderAssetContractInstallmentDate = ?,
|
||||
PurchaseOrderAssetContractInstallmentPayAmount = ?,
|
||||
PurchaseOrderAssetContractInstallmentDownPaymentType = ?,
|
||||
PurchaseOrderAssetContractInstallmentDownPayment = ?,
|
||||
PurchaseOrderAssetContractLastUpdated = NOW()
|
||||
WHERE PurchaseOrderAssetContractID = ?
|
||||
AND PurchaseOrderAssetContractIsActive = 'Y'";
|
||||
$que_contract = $this->db->query($sql_contract, [
|
||||
$para['assetAttachmentID'],
|
||||
$para['contractName'],
|
||||
@@ -866,9 +873,9 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
|
||||
# update status old po summary isActive to 'N' #
|
||||
$sql_active = "UPDATE purchase_order_summary SET
|
||||
PurchaseOrderSummaryIsActive = 'N'
|
||||
WHERE PurchaseOrderSummaryPurchaseOrderID = ?
|
||||
AND PurchaseOrderSummaryIsActive = 'Y'";
|
||||
PurchaseOrderSummaryIsActive = 'N'
|
||||
WHERE PurchaseOrderSummaryPurchaseOrderID = ?
|
||||
AND PurchaseOrderSummaryIsActive = 'Y'";
|
||||
$que_active = $this->db->query($sql_active, [$para['PurchaseOrderID']]);
|
||||
if (!$que_active) {
|
||||
$this->db->trans_rollback();
|
||||
@@ -889,19 +896,19 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
}
|
||||
|
||||
$sql_summary = "INSERT INTO purchase_order_summary (
|
||||
PurchaseOrderSummaryPurchaseOrderID,
|
||||
PurchaseOrderSummaryItemID,
|
||||
PurchaseOrderSummaryItemUnitID,
|
||||
PurchaseOrderSummaryQty,
|
||||
PurchaseOrderSummaryPrice,
|
||||
PurchaseOrderSummaryTotal,
|
||||
PurchaseOrderSummaryDiscountRupiah,
|
||||
PurchaseOrderSummaryDiscountPercent,
|
||||
PurchaseOrderSummaryDiscountAmount,
|
||||
PurchaseOrderSummaryDiscountType,
|
||||
PurchaseOrderSummaryCreatedUserID,
|
||||
PurchaseOrderSummaryCreated
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||
PurchaseOrderSummaryPurchaseOrderID,
|
||||
PurchaseOrderSummaryItemID,
|
||||
PurchaseOrderSummaryItemUnitID,
|
||||
PurchaseOrderSummaryQty,
|
||||
PurchaseOrderSummaryPrice,
|
||||
PurchaseOrderSummaryTotal,
|
||||
PurchaseOrderSummaryDiscountRupiah,
|
||||
PurchaseOrderSummaryDiscountPercent,
|
||||
PurchaseOrderSummaryDiscountAmount,
|
||||
PurchaseOrderSummaryDiscountType,
|
||||
PurchaseOrderSummaryCreatedUserID,
|
||||
PurchaseOrderSummaryCreated
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||
$que_summary = $this->db->query($sql_summary, [
|
||||
$para['PurchaseOrderID'], $obj['M_ItemID'], $obj['ItemUnitID'],
|
||||
$obj['RequestQty'], $obj['SupplierPrice'], $obj['TempTotal'],
|
||||
@@ -923,9 +930,9 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
|
||||
# update status po detail isActive to 'N' #
|
||||
$sql_active = "UPDATE purchase_order_detail SET
|
||||
PurchaseOrderDetailIsActive = 'N'
|
||||
WHERE PurchaseOrderDetailPurchaseOrderID = ?
|
||||
AND PurchaseOrderDetailIsActive = 'Y'";
|
||||
PurchaseOrderDetailIsActive = 'N'
|
||||
WHERE PurchaseOrderDetailPurchaseOrderID = ?
|
||||
AND PurchaseOrderDetailIsActive = 'Y'";
|
||||
$que_active = $this->db->query($sql_active, [$para['PurchaseOrderID']]);
|
||||
if (!$que_active) {
|
||||
$this->db->trans_rollback();
|
||||
@@ -938,22 +945,22 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
$total = floatval($obj['SupplierPrice']) * floatval($obj['RequestQty']);
|
||||
|
||||
$sql_detail = "INSERT INTO purchase_order_detail (
|
||||
PurchaseOrderDetailPurchaseOrderID,
|
||||
PurchaseOrderDetailPurchaseSummaryID,
|
||||
PurchaseOrderDetailPurchaseRequestID,
|
||||
PurchaseOrderDetailPurchaseRequestDetailID,
|
||||
PurchaseOrderDetailPurchaseRequestFlagID,
|
||||
PurchaseOrderDetailItemID,
|
||||
PurchaseOrderDetailItemUnitID,
|
||||
PurchaseOrderDetailRequestQty,
|
||||
PurchaseOrderDetailQty,
|
||||
PurchaseOrderDetailPrice,
|
||||
PurchaseOrderDetailTotal,
|
||||
PurchaseOrderWarehouseID,
|
||||
PurchaseOrderDetailUserID,
|
||||
PurchaseOrderDetailCreatedUserID,
|
||||
PurchaseOrderDetailCreated
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||
PurchaseOrderDetailPurchaseOrderID,
|
||||
PurchaseOrderDetailPurchaseSummaryID,
|
||||
PurchaseOrderDetailPurchaseRequestID,
|
||||
PurchaseOrderDetailPurchaseRequestDetailID,
|
||||
PurchaseOrderDetailPurchaseRequestFlagID,
|
||||
PurchaseOrderDetailItemID,
|
||||
PurchaseOrderDetailItemUnitID,
|
||||
PurchaseOrderDetailRequestQty,
|
||||
PurchaseOrderDetailQty,
|
||||
PurchaseOrderDetailPrice,
|
||||
PurchaseOrderDetailTotal,
|
||||
PurchaseOrderWarehouseID,
|
||||
PurchaseOrderDetailUserID,
|
||||
PurchaseOrderDetailCreatedUserID,
|
||||
PurchaseOrderDetailCreated
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||
$que_detail = $this->db->query($sql_detail, [
|
||||
$para['PurchaseOrderID'], $obj['PurchaseSummaryID'], $obj['PurchaseRequestID'],
|
||||
$obj['PurchaseRequestDetailID'], $obj['PurchaseRequestFlagID'],
|
||||
@@ -967,8 +974,8 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
}
|
||||
|
||||
$sql_flag = "UPDATE purchase_request_flag SET
|
||||
PurchaseRequestFlagQtyProses = ?
|
||||
WHERE PurchaseRequestFlagID = ?";
|
||||
PurchaseRequestFlagQtyProses = ?
|
||||
WHERE PurchaseRequestFlagID = ?";
|
||||
$que_flag = $this->db->query($sql_flag, [
|
||||
$obj['RequestQty'], $obj['PurchaseRequestFlagID']
|
||||
]);
|
||||
@@ -1174,13 +1181,14 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
$this->sys_error_db("[Error] failed insert attachment table contract asset attachment");
|
||||
exit;
|
||||
}
|
||||
$attachmentID = $this->db->insert_id();
|
||||
|
||||
$sql_contract = "UPDATE purchase_order_asset_contract SET
|
||||
PurchaseOrderAssetContractTAssetAttachmentID = ?
|
||||
WHERE PurchaseOrderAssetContractID = ?
|
||||
AND PurchaseOrderAssetContractPurchaseOrderID = ?";
|
||||
$que_contract = $this->db->query($sql_contract, [
|
||||
$para['contractID'], $para['poID']
|
||||
$attachmentID, $para['contractID'], $para['poID']
|
||||
]);
|
||||
if (!$que_contract) {
|
||||
$this->db->trans_rollback();
|
||||
@@ -1290,4 +1298,8 @@ class PurchaseOrderAset extends MY_Controller {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function generateDownPaymentPI() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,54 +300,66 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
}
|
||||
|
||||
$sql_base = "SELECT DISTINCT
|
||||
ReceiveOrderPoID,
|
||||
ReceiveOrderPoNumber,
|
||||
ReceiveOrderPoIDate,
|
||||
ReceiveOrderPoRefNumber,
|
||||
ReceiveOrderPoNote,
|
||||
ReceiveOrderPoConfirmed,
|
||||
SupplierID,
|
||||
SupplierName,
|
||||
PurchaseOrderID,
|
||||
PurchaseOrderNumber
|
||||
FROM receive_order_po
|
||||
JOIN receive_order_po_detail
|
||||
ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||
AND ReceiveOrderPoIDate BETWEEN DATE(?) AND DATE(?)
|
||||
AND (ReceiveOrderPoConfirmed = ? OR 'X' = ?)
|
||||
AND ReceiveOrderPoNumber LIKE ?
|
||||
AND ReceiveOrderPoDetailIsActive = 'Y'
|
||||
JOIN purchase_order
|
||||
ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
|
||||
AND PurchaseOrderItemCategoryID = 3 -- Filter category here
|
||||
JOIN m_branch
|
||||
ON M_BranchCode = ReceiveOrderPoM_BranchCode
|
||||
AND ReceiveOrderPoM_BranchCode = ?
|
||||
JOIN supplier
|
||||
ON ReceiveOrderPoSupplierID = SupplierID
|
||||
WHERE ReceiveOrderPoIsActive = 'Y'
|
||||
ORDER BY ReceiveOrderPoID DESC ";
|
||||
ReceiveOrderPoID,
|
||||
ReceiveOrderPoNumber,
|
||||
ReceiveOrderPoIDate,
|
||||
ReceiveOrderPoRefNumber,
|
||||
ReceiveOrderPoNote,
|
||||
ReceiveOrderPoConfirmed,
|
||||
SupplierID,
|
||||
SupplierName,
|
||||
PurchaseOrderID,
|
||||
PurchaseOrderNumber,
|
||||
PurchaseOrderAssetContractID,
|
||||
PurchaseOrderAssetContractName
|
||||
FROM receive_order_po
|
||||
JOIN receive_order_po_detail
|
||||
ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||
AND ReceiveOrderPoIDate BETWEEN DATE(?) AND DATE(?)
|
||||
AND (ReceiveOrderPoConfirmed = ? OR 'X' = ?)
|
||||
AND ReceiveOrderPoNumber LIKE ?
|
||||
AND ReceiveOrderPoDetailIsActive = 'Y'
|
||||
JOIN purchase_order
|
||||
ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
|
||||
AND PurchaseOrderItemCategoryID = 3 -- Filter category here
|
||||
JOIN purchase_order_asset_contract
|
||||
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
|
||||
AND PurchaseOrderAssetContractIsActive = 'Y'
|
||||
JOIN m_branch
|
||||
ON M_BranchCode = ReceiveOrderPoM_BranchCode
|
||||
AND ReceiveOrderPoM_BranchCode = ?
|
||||
JOIN supplier
|
||||
ON ReceiveOrderPoSupplierID = SupplierID
|
||||
WHERE ReceiveOrderPoIsActive = 'Y'
|
||||
ORDER BY ReceiveOrderPoID DESC";
|
||||
|
||||
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
|
||||
$que_data = $this->db->query($sql_data, [
|
||||
$para['startdate'], $para['enddate'],
|
||||
$confirmed, $confirmed, $keyword,
|
||||
$user['M_BranchCode'], $limit, $offset
|
||||
$para['startdate'],
|
||||
$para['enddate'],
|
||||
$confirmed,
|
||||
$confirmed,
|
||||
$keyword,
|
||||
$user['M_BranchCode'],
|
||||
$limit,
|
||||
$offset
|
||||
]);
|
||||
if (!$que_data) {
|
||||
$this->sys_error_db("[Error] failed to get data receive order");
|
||||
exit;
|
||||
throw new Exception('failed to get data receive order', 1);
|
||||
}
|
||||
$data = $que_data->result_array();
|
||||
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x";
|
||||
$que_total = $this->db->query($sql_total, [
|
||||
$para['startdate'], $para['enddate'],
|
||||
$confirmed, $confirmed, $keyword, $user['M_BranchCode']
|
||||
$para['startdate'],
|
||||
$para['enddate'],
|
||||
$confirmed,
|
||||
$confirmed,
|
||||
$keyword,
|
||||
$user['M_BranchCode']
|
||||
]);
|
||||
if (!$que_total) {
|
||||
$this->sys_error_db("[Error] failed to get total data receive order");
|
||||
exit;
|
||||
throw new Exception('failed to get total data receive order', 1);
|
||||
}
|
||||
$total = $que_total->row_array()['total'];
|
||||
|
||||
@@ -369,6 +381,149 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getListAttachment()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
|
||||
$sql = "SELECT
|
||||
ReceiveOrderPoDocumentID AS attach_id,
|
||||
ReceiveOrderPoDocumentFile AS img_url,
|
||||
ReceiveOrderPoDocumentCreated AS created
|
||||
FROM receive_order_po_document
|
||||
WHERE ReceiveOrderPoDocumentIsActive = 'Y'
|
||||
AND ReceiveOrderPoDocumentReceiveOrderPoID = ?
|
||||
AND ReceiveOrderPoDocumentType = 'aset'";
|
||||
$que = $this->db->query($sql, [$para['roID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] failed get data attachment");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$msg = $exc->getMessage();
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDetailDataROAsset()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
|
||||
$sql_header = "SELECT
|
||||
ReceiveOrderPoID,
|
||||
ReceiveOrderPoNumber,
|
||||
ReceiveOrderPoIDate AS date,
|
||||
ReceiveOrderPoSupplierID AS supplier,
|
||||
ReceiveOrderPoRefNumber AS reference,
|
||||
'' AS ponumber,
|
||||
M_BranchID AS branchID,
|
||||
ReceiveOrderPoWarehouseID AS gudangID,
|
||||
ReceiveOrderShippingCostIsPaid AS shippingIsPaid,
|
||||
ReceiveOrderShippingCostAmount AS shipping,
|
||||
ReceiveOrderPoNote AS catatan
|
||||
FROM receive_order_po
|
||||
JOIN m_branch
|
||||
ON M_BranchCode = ReceiveOrderPoM_BranchCode
|
||||
WHERE ReceiveOrderPoID = ?
|
||||
AND ReceiveOrderPoIsActive = 'Y'";
|
||||
$que_header = $this->db->query($sql_header, [$para['roid']]);
|
||||
if (!$que_header) {
|
||||
$this->sys_error_db("[Error] failed get header data RO");
|
||||
exit;
|
||||
}
|
||||
$header = $que_header->row_array();
|
||||
|
||||
$sql_detail = "SELECT
|
||||
M_ItemID,
|
||||
M_ItemCode,
|
||||
M_ItemDesc,
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ReceiveOrderPoDetailID,
|
||||
ReceiveOrderPoDetailPurchaseOrderID AS PurchaseOrderID,
|
||||
ReceiveOrderPoDetailPurchaseOrderDetailID AS PODetailID,
|
||||
ReceiveOrderPoDetailPurchaseOrderSummaryID AS POSummaryID,
|
||||
ReceiveOrderPoDetailPoItemReceiveID AS PoItemReceiveID,
|
||||
ReceiveOrderPoDetailQty AS qty,
|
||||
ReceiveOrderPoDetailPrice AS price,
|
||||
PurchaseOrderNumber
|
||||
FROM receive_order_po_detail
|
||||
JOIN purchase_order
|
||||
ON PurchaseOrderID = ReceiveOrderPoDetailPurchaseOrderID
|
||||
JOIN m_item ON M_ItemID = ReceiveOrderPoItemID
|
||||
JOIN itemunit ON ItemUnitID = ReceiveOrderPoItemUnitID
|
||||
WHERE ReceiveOrderPoDetailReceiveOrderPoID = ?
|
||||
AND ReceiveOrderPoDetailIsActive = 'Y'";
|
||||
$que_detail = $this->db->query($sql_detail, [$para['roid']]);
|
||||
if (!$que_detail) {
|
||||
$this->sys_error_db("[Error] failed to get detail data ro");
|
||||
exit;
|
||||
}
|
||||
$detail = $que_detail->result_array();
|
||||
|
||||
$uniquePoNumbers = [];
|
||||
foreach ($detail as $obj) {
|
||||
$poNumber = $obj['PurchaseOrderNumber'];
|
||||
if ($poNumber !== null && $poNumber !== '' && !in_array($poNumber, $uniquePoNumbers, true)) {
|
||||
$uniquePoNumbers[] = $poNumber;
|
||||
}
|
||||
}
|
||||
$header['ponumber'] = implode(', ', $uniquePoNumbers);
|
||||
|
||||
foreach ($detail as $key => $obj) {
|
||||
$sql_inspeksi = "SELECT
|
||||
ReceiveOrderPoInspeksiID AS inspeksiID,
|
||||
ReceiveOrderPoInspeksiReceiveOrderPoDetailID AS roID,
|
||||
ReceiveOrderPoInspeksiQtyPesan AS qty_po,
|
||||
ReceiveOrderPoInspeksiQtyActual AS qty_ro,
|
||||
ReceiveOrderPoInspeksiDatePesan AS date_po,
|
||||
ReceiveOrderPoInspeksiDateActual AS date_ro,
|
||||
ReceiveOrderPoInspeksiKeadaanKemasan AS condt_kemasan,
|
||||
ReceiveOrderPoInspeksiKeadaanKemasanNote AS catatan_kemasan,
|
||||
ReceiveOrderPoInspeksiKondisiPengiriman AS condt_pengiriman,
|
||||
ReceiveOrderPoInspeksiKondisiPengirimanNote AS catatan_kirim,
|
||||
ReceiveOrderPoInspeksiSimpulan AS summary,
|
||||
ReceiveOrderPoInspeksiCatatan AS catatan,
|
||||
ReceiveOrderPoInspeksiStaffPenerimaID AS pemeriksa,
|
||||
ReceiveOrderPoInspeksiPengirim AS pengirim
|
||||
FROM receive_order_po_inspeksi
|
||||
WHERE ReceiveOrderPoInspeksiReceiveOrderPoDetailID = ?
|
||||
AND ReceiveOrderPoInspeksiIsActive = 'Y'";
|
||||
$que_inspeksi = $this->db->query($sql_inspeksi, [
|
||||
$obj['ReceiveOrderPoDetailID']
|
||||
]);
|
||||
if (!$que_inspeksi) {
|
||||
$this->sys_error_db("[Error] failed to get data inspeksi ro");
|
||||
exit;
|
||||
}
|
||||
|
||||
$detail[$key]['inspeksi'] = $que_inspeksi->row_array();
|
||||
}
|
||||
|
||||
$this->sys_ok([
|
||||
"header" => $header,
|
||||
"detail" => $detail
|
||||
]);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
## MUTATION ##
|
||||
public function generatePOItemReceive()
|
||||
{
|
||||
@@ -671,6 +826,180 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function editReceivedOrder()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
throw new Exception('invalid token');
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
if (empty($param['ReceiveOrderPoID'])) {
|
||||
throw new Exception('ReceiveOrderPoID is required');
|
||||
}
|
||||
if (!isset($param['detail']) || !is_array($param['detail'])) {
|
||||
throw new Exception('detail is required');
|
||||
}
|
||||
|
||||
$roID = $param['ReceiveOrderPoID'];
|
||||
|
||||
# update receive order header #
|
||||
$sqlHeader = "UPDATE receive_order_po SET
|
||||
ReceiveOrderPoNumber = ?,
|
||||
ReceiveOrderPoSupplierID = ?,
|
||||
ReceiveOrderPoIDate = ?,
|
||||
ReceiveOrderPoWarehouseID = ?,
|
||||
ReceiveOrderPoM_BranchCode = ?,
|
||||
ReceiveOrderPoS_RegionalID = ?,
|
||||
ReceiveOrderShippingCostAmount = ?,
|
||||
ReceiveOrderShippingCostIsPaid = ?,
|
||||
ReceiveOrderPoNote = ?,
|
||||
ReceiveOrderPoRefNumber = ?,
|
||||
ReceiveOrderPoDONumber = ?
|
||||
WHERE ReceiveOrderPoID = ?
|
||||
AND ReceiveOrderPoIsActive = 'Y'";
|
||||
$queHeader = $this->db->query($sqlHeader, [
|
||||
$param['ReceiveOrderPoNumber'],
|
||||
$param['supplier'],
|
||||
$param['date'],
|
||||
$param['gudangID'],
|
||||
$user['M_BranchCode'],
|
||||
$user['S_RegionalID'],
|
||||
$param['shipping'],
|
||||
$param['shippingIsPaid'],
|
||||
$param['catatan'],
|
||||
$param['reference'],
|
||||
$param['reference'],
|
||||
$roID
|
||||
]);
|
||||
if (!$queHeader) {
|
||||
throw new Exception('failed to update table receive order po', 1);
|
||||
}
|
||||
|
||||
# soft delete the existing receive order details #
|
||||
$sqlDetailInactive = "UPDATE receive_order_po_detail SET
|
||||
ReceiveOrderPoDetailIsActive = 'N',
|
||||
ReceiveOrderPoDetailDeletedUserID = ?,
|
||||
ReceiveOrderPoDetailDeleted = NOW()
|
||||
WHERE ReceiveOrderPoDetailReceiveOrderPoID = ?
|
||||
AND ReceiveOrderPoDetailIsActive = 'Y'";
|
||||
$queDetailInactive = $this->db->query($sqlDetailInactive, [
|
||||
$user['M_UserID'],
|
||||
$roID
|
||||
]);
|
||||
if (!$queDetailInactive) {
|
||||
throw new Exception('failed to soft delete receive order po detail', 1);
|
||||
}
|
||||
|
||||
# soft delete the inspections belonging to the existing details #
|
||||
$sqlInspeksiInactive = "UPDATE receive_order_po_inspeksi
|
||||
JOIN receive_order_po_detail
|
||||
ON ReceiveOrderPoDetailID = ReceiveOrderPoInspeksiReceiveOrderPoDetailID
|
||||
SET ReceiveOrderPoInspeksiIsActive = 'N',
|
||||
ReceiveOrderPoInspeksiUserID = ?,
|
||||
ReceiveOrderPoInspeksiDeleted = NOW()
|
||||
WHERE ReceiveOrderPoDetailReceiveOrderPoID = ?
|
||||
AND ReceiveOrderPoInspeksiIsActive = 'Y'";
|
||||
$queInspeksiInactive = $this->db->query($sqlInspeksiInactive, [
|
||||
$user['M_UserID'],
|
||||
$roID
|
||||
]);
|
||||
if (!$queInspeksiInactive) {
|
||||
throw new Exception('failed to soft delete receive order po inspeksi', 1);
|
||||
}
|
||||
|
||||
# re-insert receive order details and their inspection forms #
|
||||
foreach ($param['detail'] as $obj) {
|
||||
if (!isset($obj['inspeksi']) || !is_array($obj['inspeksi'])) {
|
||||
throw new Exception("inspection data is required for item {$obj['M_ItemDesc']}");
|
||||
}
|
||||
|
||||
$sqlDetail = "INSERT INTO receive_order_po_detail (
|
||||
ReceiveOrderPoDetailReceiveOrderPoID,
|
||||
ReceiveOrderPoDetailPurchaseOrderID,
|
||||
ReceiveOrderPoDetailPurchaseOrderSummaryID,
|
||||
ReceiveOrderPoDetailPurchaseOrderDetailID,
|
||||
ReceiveOrderPoDetailPoItemReceiveID,
|
||||
ReceiveOrderPoDetailQty,
|
||||
ReceiveOrderPoDetailPrice,
|
||||
ReceiveOrderPoDetailTotal,
|
||||
ReceiveOrderPoItemID,
|
||||
ReceiveOrderPoItemUnitID,
|
||||
ReceiveOrderPoDetailCreatedUserID
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
|
||||
$queDetail = $this->db->query($sqlDetail, [
|
||||
$roID,
|
||||
$obj['PurchaseOrderID'],
|
||||
$obj['POSummaryID'],
|
||||
$obj['PODetailID'],
|
||||
$obj['PoItemReceiveID'],
|
||||
$obj['qty'],
|
||||
$obj['price'],
|
||||
(doubleval($obj['price']) * intval($obj['qty'])),
|
||||
$obj['M_ItemID'],
|
||||
$obj['ItemUnitID'],
|
||||
$user['M_UserID']
|
||||
]);
|
||||
if (!$queDetail) {
|
||||
throw new Exception('failed to insert table receive order po detail', 1);
|
||||
}
|
||||
$roDetailID = $this->db->insert_id();
|
||||
|
||||
$inspeksi = $obj['inspeksi'];
|
||||
$sqlInspeksi = "INSERT INTO receive_order_po_inspeksi (
|
||||
ReceiveOrderPoInspeksiReceiveOrderPoDetailID,
|
||||
ReceiveOrderPoInspeksiQtyPesan,
|
||||
ReceiveOrderPoInspeksiQtyActual,
|
||||
ReceiveOrderPoInspeksiDatePesan,
|
||||
ReceiveOrderPoInspeksiDateActual,
|
||||
ReceiveOrderPoInspeksiKeadaanKemasan,
|
||||
ReceiveOrderPoInspeksiKeadaanKemasanNote,
|
||||
ReceiveOrderPoInspeksiKondisiPengiriman,
|
||||
ReceiveOrderPoInspeksiKondisiPengirimanNote,
|
||||
ReceiveOrderPoInspeksiSimpulan,
|
||||
ReceiveOrderPoInspeksiCatatan,
|
||||
ReceiveOrderPoInspeksiStaffPenerimaID,
|
||||
ReceiveOrderPoInspeksiPengirim,
|
||||
ReceiveOrderPoInspeksiUserID
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
$queInspeksi = $this->db->query($sqlInspeksi, [
|
||||
$roDetailID,
|
||||
$inspeksi['qty_po'],
|
||||
$inspeksi['qty_ro'],
|
||||
$inspeksi['date_po'],
|
||||
$inspeksi['date_ro'],
|
||||
$inspeksi['condt_kemasan'],
|
||||
$inspeksi['catatan_kemasan'],
|
||||
$inspeksi['condt_pengiriman'],
|
||||
$inspeksi['catatan_kirim'],
|
||||
$inspeksi['summary'],
|
||||
$inspeksi['catatan'],
|
||||
$inspeksi['pemeriksa'],
|
||||
$inspeksi['pengirim'],
|
||||
$user['M_UserID']
|
||||
]);
|
||||
if (!$queInspeksi) {
|
||||
throw new Exception('failed to insert table receive order po inspeksi', 1);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('[Success] edit receive order asset');
|
||||
} catch (Exception $e) {
|
||||
$this->db->trans_rollback();
|
||||
$msg = '[Error] ' . $e->getMessage();
|
||||
if ($e->getCode() == 1) {
|
||||
$this->sys_error_db($msg);
|
||||
} else {
|
||||
$this->sys_error($msg);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteReceiveOrder()
|
||||
{
|
||||
try {
|
||||
@@ -908,8 +1237,8 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
$itemdata = $que_itemdata->row_array();
|
||||
|
||||
/* cek kategori item */
|
||||
if (empty($itemdata['M_ItemItem_CategoryID'])) {
|
||||
$desc = "kategori item {$itemdata['M_ItemDesc']} tidak ditemukan pada ";
|
||||
if (empty($itemdata['M_ItemFa_ClassID'])) {
|
||||
$desc = "FA class {$itemdata['M_ItemDesc']} tidak ditemukan pada ";
|
||||
$desc .= "PO {$elem['PurchaseOrderNumber']}";
|
||||
$this->db->trans_rollback();
|
||||
throw new Exception($desc, 1);
|
||||
@@ -954,8 +1283,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
]);
|
||||
if (!$que_jurnaltx) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] failed insert jurnaltx {$itemdata['M_ItemDesc']}");
|
||||
exit;
|
||||
throw new Exception("[Error] failed insert jurnaltx {$itemdata['M_ItemDesc']}", 1);
|
||||
}
|
||||
$jurnalTXID = $this->db->insert_id();
|
||||
|
||||
@@ -978,8 +1306,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
]);
|
||||
if (!$que_jurnaladdon) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] failed insert jurnal addon {$itemdata['M_ItemDesc']}");
|
||||
exit;
|
||||
throw new Exception("[Error] failed insert jurnal addon {$itemdata['M_ItemDesc']}", 1);
|
||||
}
|
||||
|
||||
/* INSERT table jurnal tx kredit diskon per item */
|
||||
@@ -999,8 +1326,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
$que_qtypo = $this->db->query($sql_qtypo, [$roID]);
|
||||
if (!$que_qtypo) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get detail qty & price po");
|
||||
exit;
|
||||
throw new Exception("[Error] get detail qty & price po", 1);
|
||||
}
|
||||
$data_po = $que_qtypo->row_array();
|
||||
/* kalkulasi diskon per item */
|
||||
@@ -1023,8 +1349,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
$que_coadiskon = $this->db->query($sql_coadiskon, ['2190100001']);
|
||||
if (!$que_coadiskon) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] failed get account diskon");
|
||||
exit;
|
||||
throw new Exception("[Error] failed get account diskon", 1);
|
||||
}
|
||||
$coa_diskon = $que_coadiskon->row_array();
|
||||
foreach ($input_diskon as $key => $val) {
|
||||
@@ -1041,8 +1366,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
]);
|
||||
if (!$que_jurnaltx) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] failed insert jurnal tx diskon");
|
||||
exit;
|
||||
throw new Exception("[Error] failed insert jurnal tx diskon", 1);
|
||||
}
|
||||
$jurnalTXID_diskon = $this->db->insert_id();
|
||||
|
||||
@@ -1050,41 +1374,40 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
$jurnalID,
|
||||
$jurnalTXID_diskon,
|
||||
$elem['PurchaseOrderNumber'],
|
||||
$elem['ReceiveOrderPoItemID'],
|
||||
$user['M_UserID']
|
||||
]);
|
||||
if (!$que_jurnaladdon) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] failed insert jurnal addon diskon");
|
||||
exit;
|
||||
throw new Exception("[Error] failed insert jurnal addon diskon", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* save diskon prorata item */
|
||||
$sql_saveprorate = "UPDATE receive_order_po_detail SET
|
||||
ReceiveOrderPoDetailDiskonPoProrata = ?
|
||||
WHERE ReceiveOrderPoDetailID = ?";
|
||||
ReceiveOrderPoDetailDiskonPoProrata = ?
|
||||
WHERE ReceiveOrderPoDetailID = ?";
|
||||
$que_saveprorate = $this->db->query($sql_saveprorate, [
|
||||
$diskon_prorata_item,
|
||||
$elem['ReceiveOrderPoDetailID']
|
||||
]);
|
||||
if (!$que_saveprorate) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] save diskon prorate");
|
||||
exit;
|
||||
throw new Exception("[Error] save diskon prorate", 1);
|
||||
}
|
||||
}
|
||||
|
||||
# INSERT jurnal tx for GRNI #
|
||||
$total_grni = round($total_debet - ($total_diskonitem + $total_diskonpo), 2);
|
||||
$sql_grni = "INSERT INTO jurnal_tx (
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID
|
||||
) SELECT ?, coaID, coaDescription, 0, ?, ?
|
||||
FROM coa WHERE coaAccountNo = '2110100030' LIMIT 1";
|
||||
jurnalTxJurnalID,
|
||||
jurnalTxCoaID,
|
||||
jurnalTxDescription,
|
||||
jurnalTxDebit,
|
||||
jurnalTxCredit,
|
||||
jurnalTxM_UserID
|
||||
) SELECT ?, coaID, coaDescription, 0, ?, ?
|
||||
FROM coa WHERE coaAccountNo = '2110100030' LIMIT 1";
|
||||
$que_grni = $this->db->query($sql_grni, [
|
||||
$jurnalID,
|
||||
$total_grni,
|
||||
@@ -1092,19 +1415,18 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
]);
|
||||
if (!$que_grni) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal tx GRNI");
|
||||
exit;
|
||||
throw new Exception('insert jurnal tx GRNI', 1);
|
||||
}
|
||||
$jurnalTXID_GRNI = $this->db->insert_id();
|
||||
|
||||
$sql_addon_grni = "INSERT INTO jurnal_addon (
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnJurnalTxID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES (?,?,'RONUMB',?,NOW(),?)";
|
||||
jurnalAddOnJurnalID,
|
||||
jurnalAddOnJurnalTxID,
|
||||
jurnalAddOnCode,
|
||||
jurnalAddOnValue,
|
||||
jurnalAddOnCreated,
|
||||
jurnalAddOnCreatedUserID
|
||||
) VALUES (?,?,'RONUMB',?,NOW(),?)";
|
||||
$que_addon_grni = $this->db->query($sql_addon_grni, [
|
||||
$jurnalID,
|
||||
$jurnalTXID_GRNI,
|
||||
@@ -1113,12 +1435,11 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
]);
|
||||
if (!$que_addon_grni) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] insert jurnal addon GRNI");
|
||||
exit;
|
||||
throw new Exception('insert jurnal addon GRNI', 1);
|
||||
}
|
||||
|
||||
// generate purchase invoice
|
||||
// still debatable
|
||||
/* generate purchase invoice */
|
||||
$this->generatePurchaseInvoice($user, $roID, $total_grni, $total_diskonpo);
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success] order received");
|
||||
@@ -1134,6 +1455,157 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function generatePurchaseInvoice($user, $roID, $grni, $diskonPO)
|
||||
{
|
||||
$num_pi = $this->generateNoLogistik($user, 'PI');
|
||||
|
||||
# prepare data #
|
||||
$sql_dataro = "SELECT DISTINCT
|
||||
receive_order_po.* ,
|
||||
PurchaseOrderID,
|
||||
PurchaseOrderTaxPpnType AS tax_type,
|
||||
PurchaseOrderTaxPercentPpn AS tax_percent,
|
||||
PurchaseOrderTaxAmountPpn AS tax_amount
|
||||
FROM receive_order_po
|
||||
JOIN receive_order_po_detail ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||
AND ReceiveOrderPoDetailIsActive = 'Y'
|
||||
AND ReceiveOrderPoIsActive = 'Y'
|
||||
JOIN purchase_order ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
|
||||
WHERE ReceiveOrderPoID = ?";
|
||||
$que_dataro = $this->db->query($sql_dataro, [$roID]);
|
||||
if (!$que_dataro) {
|
||||
$this->db->trans_rollback();
|
||||
throw new Exception('failed get current data for generate PI', 1);
|
||||
}
|
||||
$data_ro = $que_dataro->row_array();
|
||||
|
||||
$sql_detailro = "SELECT
|
||||
receive_order_po_detail.*,
|
||||
M_ItemDesc,
|
||||
PurchaseOrderSummaryDiscountType AS DiscountType,
|
||||
PurchaseOrderSummaryDiscountRupiah AS DiscountRupiah,
|
||||
PurchaseOrderSummaryDiscountPercent AS DiscountPercent,
|
||||
PurchaseOrderSummaryDiscountAmount as DiscountPerItem
|
||||
FROM receive_order_po_detail
|
||||
JOIN m_item ON M_ItemID = ReceiveOrderPoItemID AND M_ItemIsActive = 'Y'
|
||||
JOIN purchase_order_summary ON ReceiveOrderPoDetailPurchaseOrderSummaryID = PurchaseOrderSummaryID
|
||||
WHERE ReceiveOrderPoDetailIsActive = 'Y'
|
||||
AND ReceiveOrderPoDetailReceiveOrderPoID = ?";
|
||||
$que_detailro = $this->db->query($sql_detailro, [$roID]);
|
||||
if (!$que_detailro) {
|
||||
$this->db->trans_rollback();
|
||||
throw new Exception('failed to get data detail ro for generate PI', 1);
|
||||
}
|
||||
$detail_ro = $que_detailro->result_array();
|
||||
|
||||
# INSERT header supplier invoice #
|
||||
$due_date = new DateTime($data_ro['ReceiveOrderPoIDate']);
|
||||
$due_date->add(new DateInterval('P7D'));
|
||||
$due_date = $due_date->format('Y-m-d');
|
||||
|
||||
$subtotal = round(($grni + $diskonPO), 2);
|
||||
|
||||
$donumber = "-";
|
||||
if ($data_ro['ReceiveOrderPoDONumber'] != '') {
|
||||
$donumber = $data_ro['ReceiveOrderPoDONumber'];
|
||||
}
|
||||
|
||||
$sql_insert_pi = "INSERT INTO supplier_invoice (
|
||||
SupplierInvoiceNumber,
|
||||
SupplierInvoiceReceiveOrderPoID,
|
||||
SupplierInvoiceDate,
|
||||
SupplierInvoiceDueDate,
|
||||
SupplierInvoiceSupplierID,
|
||||
SupplierInvoiceRefNumber,
|
||||
SupplierInvoiceDeliveryOrderNumber,
|
||||
SupplierInvoiceSubTotal,
|
||||
SupplierInvoiceDiscountPercent,
|
||||
SupplierInvoiceDiscountAmount,
|
||||
SupplierInvoiceTaxPercentPpn,
|
||||
SupplierInvoiceTaxAmountPpn,
|
||||
SupplierInvoiceGrandTotal,
|
||||
SupplierInvoiceUnpaid,
|
||||
SupplierInvoiceNote,
|
||||
SupplierInvoiceReceiveDate,
|
||||
SupplierInvoiceReceivedBy,
|
||||
SupplierInvoiceCreatedUserID
|
||||
) VALUES (?,?,NOW(),?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?,?)";
|
||||
$que_insert_pi = $this->db->query($sql_insert_pi, [
|
||||
$num_pi,
|
||||
$data_ro['ReceiveOrderPoID'],
|
||||
$due_date,
|
||||
$data_ro['ReceiveOrderPoSupplierID'],
|
||||
$data_ro['ReceiveOrderPoNumber'],
|
||||
$donumber,
|
||||
$subtotal,
|
||||
0.00,
|
||||
$diskonPO,
|
||||
$data_ro['tax_percent'],
|
||||
$data_ro['tax_amount'],
|
||||
$grni,
|
||||
$grni,
|
||||
$data_ro['ReceiveOrderPoNote'],
|
||||
$user['M_UserID'],
|
||||
$user['M_UserID']
|
||||
]);
|
||||
if (!$que_insert_pi) {
|
||||
$this->db->trans_rollback();
|
||||
throw new Exception('failed insert data into table PI', 1);
|
||||
}
|
||||
$Pinvoice_ID = $this->db->insert_id();
|
||||
|
||||
# INSERT supplier invoice detail #
|
||||
$sql_ins_itemPI = "INSERT INTO supplier_invoice_detail (
|
||||
SupplierInvoiceDetailSupplierInvoiceID,
|
||||
SupplierInvoiceDetailPurchaseOrderID,
|
||||
SupplierInvoiceDetailPurchaseOrderSummaryID,
|
||||
SupplierInvoiceDetailReceiveOrderPoID,
|
||||
SupplierInvoiceDetailReceiveOrderPoDetailID,
|
||||
SupplierInvoiceDetailItemID,
|
||||
SupplierInvoiceDetailItemUnitID,
|
||||
SupplierInvoiceDetailDescription,
|
||||
SupplierInvoiceDetailQty,
|
||||
SupplierInvoiceDetailPrice,
|
||||
SupplierInvoiceDetailDiscountPercent,
|
||||
SupplierInvoiceDetailDiscountDiscountRupiah,
|
||||
SupplierInvoiceDetailDiscountDiscountType,
|
||||
SupplierInvoiceDetailDiscountPoProrata,
|
||||
SupplierInvoiceDetailDiscountAmount,
|
||||
SupplierInvoiceDetailTotal,
|
||||
SupplierInvoiceDetailUnpaid,
|
||||
SupplierInvoiceDetailCreatedUserID
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
foreach ($detail_ro as $key => $elem) {
|
||||
$itemprice = doubleval($elem['ReceiveOrderPoDetailPrice']) - doubleval($elem['DiscountPerItem']);
|
||||
$totalprice = round($itemprice * intval($elem['ReceiveOrderPoDetailQty']), 2);
|
||||
|
||||
$que_ins_itemPI = $this->db->query($sql_ins_itemPI, [
|
||||
$Pinvoice_ID,
|
||||
$elem['ReceiveOrderPoDetailPurchaseOrderID'],
|
||||
$elem['ReceiveOrderPoDetailPurchaseOrderSummaryID'],
|
||||
$elem['ReceiveOrderPoDetailReceiveOrderPoID'],
|
||||
$elem['ReceiveOrderPoDetailID'],
|
||||
$elem['ReceiveOrderPoItemID'],
|
||||
$elem['ReceiveOrderPoItemUnitID'],
|
||||
$elem['M_ItemDesc'],
|
||||
$elem['ReceiveOrderPoDetailQty'],
|
||||
$elem['ReceiveOrderPoDetailPrice'],
|
||||
$elem['DiscountPercent'],
|
||||
$elem['DiscountRupiah'],
|
||||
$elem['DiscountType'],
|
||||
$elem['ReceiveOrderPoDetailDiskonPoProrata'],
|
||||
$elem['DiscountPerItem'],
|
||||
$totalprice,
|
||||
$totalprice,
|
||||
$user['M_UserID']
|
||||
]);
|
||||
if (!$que_ins_itemPI) {
|
||||
$this->db->trans_rollback();
|
||||
throw new Exception('failed insert table detail PI', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadAttachment()
|
||||
{
|
||||
try {
|
||||
@@ -1169,7 +1641,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
||||
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
||||
|
||||
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
||||
$new_filename = "PO" . date("YmdHis") . "_" . $para['ponumber'] . "." . $ext;
|
||||
$new_filename = "PO" . date("YmdHis") . "_" . $para['ronumber'] . "." . $ext;
|
||||
$config['file_name'] = $new_filename;
|
||||
$this->upload->initialize($config);
|
||||
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
class Bill extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Bill API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Bill API";
|
||||
}
|
||||
|
||||
public function add_notes($orderid){
|
||||
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function add_notes($orderid)
|
||||
{
|
||||
$sql = "SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
@@ -45,23 +47,24 @@ class Bill extends MY_Controller
|
||||
AND
|
||||
SupplierPaymentIsActive = 'Y'
|
||||
GROUP BY SupplierPaymentID";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
if ($rows) {
|
||||
foreach ($rows as $k => $v) {
|
||||
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
} else {
|
||||
$this->sys_error_db("get notes", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("get notes", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
public function add_tagihans($orderid){
|
||||
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
||||
public function add_tagihans($orderid)
|
||||
{
|
||||
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
||||
PurchaseOrderNumber as tagihan_number,
|
||||
jurnalTxDescription as pasien,
|
||||
jurnalTxCredit as tagihan_total,
|
||||
@@ -85,18 +88,19 @@ class Bill extends MY_Controller
|
||||
SupplierInvoiceID = {$orderid}
|
||||
GROUP BY jurnalTxID
|
||||
";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
return $rows;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
return $rows;
|
||||
} else {
|
||||
$this->sys_error_db("get notes", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("get notes", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
public function add_tests($orderid){
|
||||
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
public function add_tests($orderid)
|
||||
{
|
||||
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||
SupplierPaymentID as note_id,
|
||||
SupplierPaymentDate as note_date,
|
||||
SupplierPaymentNumber as note_number,
|
||||
@@ -116,37 +120,37 @@ class Bill extends MY_Controller
|
||||
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;
|
||||
$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;
|
||||
}
|
||||
$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 = ($prm['current_page'] - 1) * $number_limit ;
|
||||
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'];
|
||||
|
||||
$where = "SupplierInvoiceIsActive = 'Y'
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
||||
|
||||
$where = "SupplierInvoiceIsActive = 'Y'
|
||||
AND SupplierInvoiceStatus = 'Approved'
|
||||
AND SupplierInvoiceGrandTotal > 0
|
||||
AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}'
|
||||
@@ -157,7 +161,7 @@ class Bill extends MY_Controller
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||
@@ -166,22 +170,22 @@ class Bill extends MY_Controller
|
||||
WHERE
|
||||
$where
|
||||
";
|
||||
// echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
// echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
|
||||
$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;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT supplier_invoice.*,
|
||||
$sql = "SELECT supplier_invoice.*,
|
||||
SupplierName,
|
||||
'' M_MouName,
|
||||
0 as totalbill,
|
||||
@@ -213,45 +217,42 @@ class Bill extends MY_Controller
|
||||
GROUP BY SupplierInvoiceID
|
||||
ORDER BY SupplierInvoiceID ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
$rows = $query->result_array();
|
||||
if ($rows) {
|
||||
foreach ($rows as $k => $v) {
|
||||
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||
IFNULL(SupplierPaymentID,0) SupplierPaymentID,
|
||||
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
|
||||
FROM supplier_payment
|
||||
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
|
||||
|
||||
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill
|
||||
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill
|
||||
FROM supplier_invoice
|
||||
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']}
|
||||
GROUP BY SupplierInvoiceID")->row();
|
||||
$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, '.', '');
|
||||
$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($v['SupplierInvoiceID']);
|
||||
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
$rows[$k]['notes'] = $this->add_notes($v['SupplierInvoiceID']);
|
||||
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user