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];
|
$coapph = $quepph->result_array()[0];
|
||||||
|
|
||||||
$pphval = doubleval($invoice[0]['SupplierInvoiceTaxAmountPph']);
|
$pphval = doubleval($invoice[0]['SupplierInvoiceTaxAmountPph']);
|
||||||
|
|
||||||
if ($pphval > 0.00) {
|
if ($pphval > 0.00) {
|
||||||
$insertpph = $this->InsertJurnalTx(
|
$insertpph = $this->InsertJurnalTx(
|
||||||
$jurnalID,
|
$jurnalID,
|
||||||
@@ -1465,22 +1464,22 @@ class Fakturv4 extends MY_Controller
|
|||||||
);
|
);
|
||||||
if (!$insertpph['status']) {
|
if (!$insertpph['status']) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db($insertpajak['msg']);
|
$this->sys_error_db($insertpph['msg']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# insert shipping cost ke jurnal #
|
# 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) {
|
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(
|
$insertcost = $this->InsertJurnalTx(
|
||||||
$jurnalID,
|
$jurnalID,
|
||||||
$coashipcost['coaID'],
|
$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)
|
// insert jurnal tx hutang per item (kredit)
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
foreach ($invoice as $key => $inv) {
|
foreach ($invoice as $key => $inv) {
|
||||||
@@ -1603,52 +1653,20 @@ class Fakturv4 extends MY_Controller
|
|||||||
$this->sys_error_db($status['msg']);
|
$this->sys_error_db($status['msg']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} else if ($item['M_ItemItem_CategoryID'] == '3' && !empty($item['M_ItemFa_ClassID'])) {
|
} else if ($item['M_ItemItem_CategoryID'] == '3') {
|
||||||
$sqlsgp = "SELECT * FROM fa_class WHERE Fa_ClassID = ? AND Fa_ClassIsActive = 'Y'";
|
$this->InsertJurnalTxAsset($jurnalID, $item['M_ItemID'], $inv, $user['M_UserID']);
|
||||||
$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'] == '4') {
|
} else if ($item['M_ItemItem_CategoryID'] == '4') {
|
||||||
$this->InsertJurnalTxJasa($jurnalID, $item['M_ItemID'], $inv, $user['M_UserID']);
|
$this->InsertJurnalTxJasa($jurnalID, $item['M_ItemID'], $inv, $user['M_UserID']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sqlinvgr = "INSERT INTO jurnal_addon (
|
$sqlinvgr = "INSERT INTO jurnal_addon (
|
||||||
jurnalAddOnJurnalID,
|
jurnalAddOnJurnalID,
|
||||||
jurnalAddOnCode,
|
jurnalAddOnCode,
|
||||||
jurnalAddOnValue,
|
jurnalAddOnValue,
|
||||||
jurnalAddOnCreated,
|
jurnalAddOnCreated,
|
||||||
jurnalAddOnCreatedUserID
|
jurnalAddOnCreatedUserID
|
||||||
) VALUES (?,?,?,NOW(),?)";
|
) VALUES (?,?,?,NOW(),?)";
|
||||||
$queinvgr = $this->db->query($sqlinvgr, [
|
$queinvgr = $this->db->query($sqlinvgr, [
|
||||||
$jurnalID,
|
$jurnalID,
|
||||||
'INVGR',
|
'INVGR',
|
||||||
@@ -1674,13 +1692,13 @@ class Fakturv4 extends MY_Controller
|
|||||||
private function InsertJurnalTxJasa($jurnalID, $itemid, $invoice, $userid)
|
private function InsertJurnalTxJasa($jurnalID, $itemid, $invoice, $userid)
|
||||||
{
|
{
|
||||||
$sql_coa = "SELECT
|
$sql_coa = "SELECT
|
||||||
JasaCoaMapHutangCoaID,
|
JasaCoaMapHutangCoaID,
|
||||||
JasaCoaMapHutangCoaNo,
|
JasaCoaMapHutangCoaNo,
|
||||||
JasaCoaMapHutangCoaDesc
|
JasaCoaMapHutangCoaDesc
|
||||||
FROM jasa_coa_map
|
FROM jasa_coa_map
|
||||||
JOIN coa ON coaID = JasaCoaMapHutangCoaID
|
JOIN coa ON coaID = JasaCoaMapHutangCoaID
|
||||||
AND coaIsActive = 'Y'
|
AND coaIsActive = 'Y'
|
||||||
WHERE JasaCoaMapM_ItemID = ?";
|
WHERE JasaCoaMapM_ItemID = ?";
|
||||||
$que_coa = $this->db->query($sql_coa, [$itemid]);
|
$que_coa = $this->db->query($sql_coa, [$itemid]);
|
||||||
if (!$que_coa) {
|
if (!$que_coa) {
|
||||||
$this->db->trans_rollback();
|
$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
|
function InsertJurnalTx($jurnalID, $coaID, $desc, $userID, $debit = 0, $kredit = 0): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
PurchaseOrderGrandTotal AS grandtotal,
|
PurchaseOrderGrandTotal AS grandtotal,
|
||||||
CASE
|
CASE
|
||||||
WHEN PurchaseOrderTaxPpnType = 'P' THEN 'percent'
|
WHEN PurchaseOrderTaxPpnType = 'P' THEN 'percent'
|
||||||
ELSE 'absolute'
|
ELSE 'nominal'
|
||||||
END AS typepajak,
|
END AS typepajak,
|
||||||
CASE
|
CASE
|
||||||
WHEN PurchaseOrderTaxPpnType = 'P' THEN PurchaseOrderTaxPercentPpn
|
WHEN PurchaseOrderTaxPpnType = 'P' THEN PurchaseOrderTaxPercentPpn
|
||||||
@@ -415,7 +415,7 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
END AS valuepajak,
|
END AS valuepajak,
|
||||||
CASE
|
CASE
|
||||||
WHEN PurchaseOrderDiscountPercent > 0.00 THEN 'percent'
|
WHEN PurchaseOrderDiscountPercent > 0.00 THEN 'percent'
|
||||||
ELSE 'absolute'
|
ELSE 'nominal'
|
||||||
END AS typediskon,
|
END AS typediskon,
|
||||||
CASE
|
CASE
|
||||||
WHEN PurchaseOrderDiscountPercent > 0.00 THEN PurchaseOrderDiscountPercent
|
WHEN PurchaseOrderDiscountPercent > 0.00 THEN PurchaseOrderDiscountPercent
|
||||||
@@ -425,6 +425,8 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
PurchaseOrderGrandTotal AS grandtotal,
|
PurchaseOrderGrandTotal AS grandtotal,
|
||||||
SupplierID AS supplierID,
|
SupplierID AS supplierID,
|
||||||
SupplierName,
|
SupplierName,
|
||||||
|
WarehouseID AS gudangID,
|
||||||
|
WarehouseM_BranchID AS branchID,
|
||||||
PurchaseOrderAssetContractID,
|
PurchaseOrderAssetContractID,
|
||||||
PurchaseOrderAssetContractTAssetAttachmentID AS assetAttachmentID,
|
PurchaseOrderAssetContractTAssetAttachmentID AS assetAttachmentID,
|
||||||
PurchaseOrderAssetContractName AS contractName,
|
PurchaseOrderAssetContractName AS contractName,
|
||||||
@@ -440,6 +442,7 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
PurchaseOrderApprovedManagerUserID AS verifiedby
|
PurchaseOrderApprovedManagerUserID AS verifiedby
|
||||||
FROM purchase_order
|
FROM purchase_order
|
||||||
JOIN supplier ON SupplierID = PurchaseOrderSupplierID
|
JOIN supplier ON SupplierID = PurchaseOrderSupplierID
|
||||||
|
JOIN warehouse ON WarehouseID = PurchaseOrderWarehouseID
|
||||||
JOIN purchase_order_asset_contract
|
JOIN purchase_order_asset_contract
|
||||||
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
|
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
|
||||||
WHERE PurchaseOrderIsActive = 'Y'
|
WHERE PurchaseOrderIsActive = 'Y'
|
||||||
@@ -474,6 +477,7 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$subtotal = floatval($datapo['subtotal']);
|
$subtotal = floatval($datapo['subtotal']);
|
||||||
|
$downpayment = floatval($datapo['installmentDownPayment']);
|
||||||
$grandtotal = floatval($datapo['grandtotal']);
|
$grandtotal = floatval($datapo['grandtotal']);
|
||||||
|
|
||||||
$valuediskon = floatval($datapo['valuediskon']);
|
$valuediskon = floatval($datapo['valuediskon']);
|
||||||
@@ -491,8 +495,11 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
"subtotal" => $subtotal,
|
"subtotal" => $subtotal,
|
||||||
"diskon" => $valuediskon,
|
"diskon" => $valuediskon,
|
||||||
"pajak" => $valuepajak,
|
"pajak" => $valuepajak,
|
||||||
|
"downpayment" => $downpayment,
|
||||||
|
"total_before_downpayment" => $downpayment + $grandtotal,
|
||||||
"total" => $grandtotal
|
"total" => $grandtotal
|
||||||
];
|
];
|
||||||
|
|
||||||
/* map summary to purchase order */
|
/* map summary to purchase order */
|
||||||
$datapo['valuepajak'] = floatval($datapo['valuepajak']);
|
$datapo['valuepajak'] = floatval($datapo['valuepajak']);
|
||||||
$datapo['valuediskon'] = floatval($datapo['valuediskon']);
|
$datapo['valuediskon'] = floatval($datapo['valuediskon']);
|
||||||
@@ -830,20 +837,20 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
|
|
||||||
# update purchase_order_asset_contract #
|
# update purchase_order_asset_contract #
|
||||||
$sql_contract = "UPDATE purchase_order_asset_contract SET
|
$sql_contract = "UPDATE purchase_order_asset_contract SET
|
||||||
PurchaseOrderAssetContractTAssetAttachmentID = ?,
|
PurchaseOrderAssetContractTAssetAttachmentID = ?,
|
||||||
PurchaseOrderAssetContractName = ?,
|
PurchaseOrderAssetContractName = ?,
|
||||||
PurchaseOrderAssetContractDate = ?,
|
PurchaseOrderAssetContractDate = ?,
|
||||||
PurchaseOrderAssetContractStartDate = ?,
|
PurchaseOrderAssetContractStartDate = ?,
|
||||||
PurchaseOrderAssetContractEndDate = ?,
|
PurchaseOrderAssetContractEndDate = ?,
|
||||||
PurchaseOrderAssetContractDuration = ?,
|
PurchaseOrderAssetContractDuration = ?,
|
||||||
PurchaseOrderAssetContractInstallmentNumber = ?,
|
PurchaseOrderAssetContractInstallmentNumber = ?,
|
||||||
PurchaseOrderAssetContractInstallmentDate = ?,
|
PurchaseOrderAssetContractInstallmentDate = ?,
|
||||||
PurchaseOrderAssetContractInstallmentPayAmount = ?,
|
PurchaseOrderAssetContractInstallmentPayAmount = ?,
|
||||||
PurchaseOrderAssetContractInstallmentDownPaymentType = ?,
|
PurchaseOrderAssetContractInstallmentDownPaymentType = ?,
|
||||||
PurchaseOrderAssetContractInstallmentDownPayment = ?,
|
PurchaseOrderAssetContractInstallmentDownPayment = ?,
|
||||||
PurchaseOrderAssetContractLastUpdated = NOW()
|
PurchaseOrderAssetContractLastUpdated = NOW()
|
||||||
WHERE PurchaseOrderAssetContractID = ?
|
WHERE PurchaseOrderAssetContractID = ?
|
||||||
AND PurchaseOrderAssetContractIsActive = 'Y'";
|
AND PurchaseOrderAssetContractIsActive = 'Y'";
|
||||||
$que_contract = $this->db->query($sql_contract, [
|
$que_contract = $this->db->query($sql_contract, [
|
||||||
$para['assetAttachmentID'],
|
$para['assetAttachmentID'],
|
||||||
$para['contractName'],
|
$para['contractName'],
|
||||||
@@ -866,9 +873,9 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
|
|
||||||
# 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'
|
||||||
WHERE PurchaseOrderSummaryPurchaseOrderID = ?
|
WHERE PurchaseOrderSummaryPurchaseOrderID = ?
|
||||||
AND PurchaseOrderSummaryIsActive = 'Y'";
|
AND PurchaseOrderSummaryIsActive = 'Y'";
|
||||||
$que_active = $this->db->query($sql_active, [$para['PurchaseOrderID']]);
|
$que_active = $this->db->query($sql_active, [$para['PurchaseOrderID']]);
|
||||||
if (!$que_active) {
|
if (!$que_active) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
@@ -889,19 +896,19 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql_summary = "INSERT INTO purchase_order_summary (
|
$sql_summary = "INSERT INTO purchase_order_summary (
|
||||||
PurchaseOrderSummaryPurchaseOrderID,
|
PurchaseOrderSummaryPurchaseOrderID,
|
||||||
PurchaseOrderSummaryItemID,
|
PurchaseOrderSummaryItemID,
|
||||||
PurchaseOrderSummaryItemUnitID,
|
PurchaseOrderSummaryItemUnitID,
|
||||||
PurchaseOrderSummaryQty,
|
PurchaseOrderSummaryQty,
|
||||||
PurchaseOrderSummaryPrice,
|
PurchaseOrderSummaryPrice,
|
||||||
PurchaseOrderSummaryTotal,
|
PurchaseOrderSummaryTotal,
|
||||||
PurchaseOrderSummaryDiscountRupiah,
|
PurchaseOrderSummaryDiscountRupiah,
|
||||||
PurchaseOrderSummaryDiscountPercent,
|
PurchaseOrderSummaryDiscountPercent,
|
||||||
PurchaseOrderSummaryDiscountAmount,
|
PurchaseOrderSummaryDiscountAmount,
|
||||||
PurchaseOrderSummaryDiscountType,
|
PurchaseOrderSummaryDiscountType,
|
||||||
PurchaseOrderSummaryCreatedUserID,
|
PurchaseOrderSummaryCreatedUserID,
|
||||||
PurchaseOrderSummaryCreated
|
PurchaseOrderSummaryCreated
|
||||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||||
$que_summary = $this->db->query($sql_summary, [
|
$que_summary = $this->db->query($sql_summary, [
|
||||||
$para['PurchaseOrderID'], $obj['M_ItemID'], $obj['ItemUnitID'],
|
$para['PurchaseOrderID'], $obj['M_ItemID'], $obj['ItemUnitID'],
|
||||||
$obj['RequestQty'], $obj['SupplierPrice'], $obj['TempTotal'],
|
$obj['RequestQty'], $obj['SupplierPrice'], $obj['TempTotal'],
|
||||||
@@ -923,9 +930,9 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
|
|
||||||
# update status po detail isActive to 'N' #
|
# update status po detail isActive to 'N' #
|
||||||
$sql_active = "UPDATE purchase_order_detail SET
|
$sql_active = "UPDATE purchase_order_detail SET
|
||||||
PurchaseOrderDetailIsActive = 'N'
|
PurchaseOrderDetailIsActive = 'N'
|
||||||
WHERE PurchaseOrderDetailPurchaseOrderID = ?
|
WHERE PurchaseOrderDetailPurchaseOrderID = ?
|
||||||
AND PurchaseOrderDetailIsActive = 'Y'";
|
AND PurchaseOrderDetailIsActive = 'Y'";
|
||||||
$que_active = $this->db->query($sql_active, [$para['PurchaseOrderID']]);
|
$que_active = $this->db->query($sql_active, [$para['PurchaseOrderID']]);
|
||||||
if (!$que_active) {
|
if (!$que_active) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
@@ -938,22 +945,22 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
$total = floatval($obj['SupplierPrice']) * floatval($obj['RequestQty']);
|
$total = floatval($obj['SupplierPrice']) * floatval($obj['RequestQty']);
|
||||||
|
|
||||||
$sql_detail = "INSERT INTO purchase_order_detail (
|
$sql_detail = "INSERT INTO purchase_order_detail (
|
||||||
PurchaseOrderDetailPurchaseOrderID,
|
PurchaseOrderDetailPurchaseOrderID,
|
||||||
PurchaseOrderDetailPurchaseSummaryID,
|
PurchaseOrderDetailPurchaseSummaryID,
|
||||||
PurchaseOrderDetailPurchaseRequestID,
|
PurchaseOrderDetailPurchaseRequestID,
|
||||||
PurchaseOrderDetailPurchaseRequestDetailID,
|
PurchaseOrderDetailPurchaseRequestDetailID,
|
||||||
PurchaseOrderDetailPurchaseRequestFlagID,
|
PurchaseOrderDetailPurchaseRequestFlagID,
|
||||||
PurchaseOrderDetailItemID,
|
PurchaseOrderDetailItemID,
|
||||||
PurchaseOrderDetailItemUnitID,
|
PurchaseOrderDetailItemUnitID,
|
||||||
PurchaseOrderDetailRequestQty,
|
PurchaseOrderDetailRequestQty,
|
||||||
PurchaseOrderDetailQty,
|
PurchaseOrderDetailQty,
|
||||||
PurchaseOrderDetailPrice,
|
PurchaseOrderDetailPrice,
|
||||||
PurchaseOrderDetailTotal,
|
PurchaseOrderDetailTotal,
|
||||||
PurchaseOrderWarehouseID,
|
PurchaseOrderWarehouseID,
|
||||||
PurchaseOrderDetailUserID,
|
PurchaseOrderDetailUserID,
|
||||||
PurchaseOrderDetailCreatedUserID,
|
PurchaseOrderDetailCreatedUserID,
|
||||||
PurchaseOrderDetailCreated
|
PurchaseOrderDetailCreated
|
||||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
|
||||||
$que_detail = $this->db->query($sql_detail, [
|
$que_detail = $this->db->query($sql_detail, [
|
||||||
$para['PurchaseOrderID'], $obj['PurchaseSummaryID'], $obj['PurchaseRequestID'],
|
$para['PurchaseOrderID'], $obj['PurchaseSummaryID'], $obj['PurchaseRequestID'],
|
||||||
$obj['PurchaseRequestDetailID'], $obj['PurchaseRequestFlagID'],
|
$obj['PurchaseRequestDetailID'], $obj['PurchaseRequestFlagID'],
|
||||||
@@ -967,8 +974,8 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql_flag = "UPDATE purchase_request_flag SET
|
$sql_flag = "UPDATE purchase_request_flag SET
|
||||||
PurchaseRequestFlagQtyProses = ?
|
PurchaseRequestFlagQtyProses = ?
|
||||||
WHERE PurchaseRequestFlagID = ?";
|
WHERE PurchaseRequestFlagID = ?";
|
||||||
$que_flag = $this->db->query($sql_flag, [
|
$que_flag = $this->db->query($sql_flag, [
|
||||||
$obj['RequestQty'], $obj['PurchaseRequestFlagID']
|
$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");
|
$this->sys_error_db("[Error] failed insert attachment table contract asset attachment");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
$attachmentID = $this->db->insert_id();
|
||||||
|
|
||||||
$sql_contract = "UPDATE purchase_order_asset_contract SET
|
$sql_contract = "UPDATE purchase_order_asset_contract SET
|
||||||
PurchaseOrderAssetContractTAssetAttachmentID = ?
|
PurchaseOrderAssetContractTAssetAttachmentID = ?
|
||||||
WHERE PurchaseOrderAssetContractID = ?
|
WHERE PurchaseOrderAssetContractID = ?
|
||||||
AND PurchaseOrderAssetContractPurchaseOrderID = ?";
|
AND PurchaseOrderAssetContractPurchaseOrderID = ?";
|
||||||
$que_contract = $this->db->query($sql_contract, [
|
$que_contract = $this->db->query($sql_contract, [
|
||||||
$para['contractID'], $para['poID']
|
$attachmentID, $para['contractID'], $para['poID']
|
||||||
]);
|
]);
|
||||||
if (!$que_contract) {
|
if (!$que_contract) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
@@ -1290,4 +1298,8 @@ class PurchaseOrderAset extends MY_Controller {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function generateDownPaymentPI() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,54 +300,66 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql_base = "SELECT DISTINCT
|
$sql_base = "SELECT DISTINCT
|
||||||
ReceiveOrderPoID,
|
ReceiveOrderPoID,
|
||||||
ReceiveOrderPoNumber,
|
ReceiveOrderPoNumber,
|
||||||
ReceiveOrderPoIDate,
|
ReceiveOrderPoIDate,
|
||||||
ReceiveOrderPoRefNumber,
|
ReceiveOrderPoRefNumber,
|
||||||
ReceiveOrderPoNote,
|
ReceiveOrderPoNote,
|
||||||
ReceiveOrderPoConfirmed,
|
ReceiveOrderPoConfirmed,
|
||||||
SupplierID,
|
SupplierID,
|
||||||
SupplierName,
|
SupplierName,
|
||||||
PurchaseOrderID,
|
PurchaseOrderID,
|
||||||
PurchaseOrderNumber
|
PurchaseOrderNumber,
|
||||||
FROM receive_order_po
|
PurchaseOrderAssetContractID,
|
||||||
JOIN receive_order_po_detail
|
PurchaseOrderAssetContractName
|
||||||
ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
|
FROM receive_order_po
|
||||||
AND ReceiveOrderPoIDate BETWEEN DATE(?) AND DATE(?)
|
JOIN receive_order_po_detail
|
||||||
AND (ReceiveOrderPoConfirmed = ? OR 'X' = ?)
|
ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||||
AND ReceiveOrderPoNumber LIKE ?
|
AND ReceiveOrderPoIDate BETWEEN DATE(?) AND DATE(?)
|
||||||
AND ReceiveOrderPoDetailIsActive = 'Y'
|
AND (ReceiveOrderPoConfirmed = ? OR 'X' = ?)
|
||||||
JOIN purchase_order
|
AND ReceiveOrderPoNumber LIKE ?
|
||||||
ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
|
AND ReceiveOrderPoDetailIsActive = 'Y'
|
||||||
AND PurchaseOrderItemCategoryID = 3 -- Filter category here
|
JOIN purchase_order
|
||||||
JOIN m_branch
|
ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
|
||||||
ON M_BranchCode = ReceiveOrderPoM_BranchCode
|
AND PurchaseOrderItemCategoryID = 3 -- Filter category here
|
||||||
AND ReceiveOrderPoM_BranchCode = ?
|
JOIN purchase_order_asset_contract
|
||||||
JOIN supplier
|
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
|
||||||
ON ReceiveOrderPoSupplierID = SupplierID
|
AND PurchaseOrderAssetContractIsActive = 'Y'
|
||||||
WHERE ReceiveOrderPoIsActive = 'Y'
|
JOIN m_branch
|
||||||
ORDER BY ReceiveOrderPoID DESC ";
|
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 ? ";
|
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
|
||||||
$que_data = $this->db->query($sql_data, [
|
$que_data = $this->db->query($sql_data, [
|
||||||
$para['startdate'], $para['enddate'],
|
$para['startdate'],
|
||||||
$confirmed, $confirmed, $keyword,
|
$para['enddate'],
|
||||||
$user['M_BranchCode'], $limit, $offset
|
$confirmed,
|
||||||
|
$confirmed,
|
||||||
|
$keyword,
|
||||||
|
$user['M_BranchCode'],
|
||||||
|
$limit,
|
||||||
|
$offset
|
||||||
]);
|
]);
|
||||||
if (!$que_data) {
|
if (!$que_data) {
|
||||||
$this->sys_error_db("[Error] failed to get data receive order");
|
throw new Exception('failed to get data receive order', 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$data = $que_data->result_array();
|
$data = $que_data->result_array();
|
||||||
|
|
||||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x";
|
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x";
|
||||||
$que_total = $this->db->query($sql_total, [
|
$que_total = $this->db->query($sql_total, [
|
||||||
$para['startdate'], $para['enddate'],
|
$para['startdate'],
|
||||||
$confirmed, $confirmed, $keyword, $user['M_BranchCode']
|
$para['enddate'],
|
||||||
|
$confirmed,
|
||||||
|
$confirmed,
|
||||||
|
$keyword,
|
||||||
|
$user['M_BranchCode']
|
||||||
]);
|
]);
|
||||||
if (!$que_total) {
|
if (!$que_total) {
|
||||||
$this->sys_error_db("[Error] failed to get total data receive order");
|
throw new Exception('failed to get total data receive order', 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$total = $que_total->row_array()['total'];
|
$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 ##
|
## MUTATION ##
|
||||||
public function generatePOItemReceive()
|
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()
|
public function deleteReceiveOrder()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -908,8 +1237,8 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
$itemdata = $que_itemdata->row_array();
|
$itemdata = $que_itemdata->row_array();
|
||||||
|
|
||||||
/* cek kategori item */
|
/* cek kategori item */
|
||||||
if (empty($itemdata['M_ItemItem_CategoryID'])) {
|
if (empty($itemdata['M_ItemFa_ClassID'])) {
|
||||||
$desc = "kategori item {$itemdata['M_ItemDesc']} tidak ditemukan pada ";
|
$desc = "FA class {$itemdata['M_ItemDesc']} tidak ditemukan pada ";
|
||||||
$desc .= "PO {$elem['PurchaseOrderNumber']}";
|
$desc .= "PO {$elem['PurchaseOrderNumber']}";
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
throw new Exception($desc, 1);
|
throw new Exception($desc, 1);
|
||||||
@@ -954,8 +1283,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
]);
|
]);
|
||||||
if (!$que_jurnaltx) {
|
if (!$que_jurnaltx) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] failed insert jurnaltx {$itemdata['M_ItemDesc']}");
|
throw new Exception("[Error] failed insert jurnaltx {$itemdata['M_ItemDesc']}", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$jurnalTXID = $this->db->insert_id();
|
$jurnalTXID = $this->db->insert_id();
|
||||||
|
|
||||||
@@ -978,8 +1306,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
]);
|
]);
|
||||||
if (!$que_jurnaladdon) {
|
if (!$que_jurnaladdon) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] failed insert jurnal addon {$itemdata['M_ItemDesc']}");
|
throw new Exception("[Error] failed insert jurnal addon {$itemdata['M_ItemDesc']}", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* INSERT table jurnal tx kredit diskon per item */
|
/* 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]);
|
$que_qtypo = $this->db->query($sql_qtypo, [$roID]);
|
||||||
if (!$que_qtypo) {
|
if (!$que_qtypo) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] get detail qty & price po");
|
throw new Exception("[Error] get detail qty & price po", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$data_po = $que_qtypo->row_array();
|
$data_po = $que_qtypo->row_array();
|
||||||
/* kalkulasi diskon per item */
|
/* kalkulasi diskon per item */
|
||||||
@@ -1023,8 +1349,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
$que_coadiskon = $this->db->query($sql_coadiskon, ['2190100001']);
|
$que_coadiskon = $this->db->query($sql_coadiskon, ['2190100001']);
|
||||||
if (!$que_coadiskon) {
|
if (!$que_coadiskon) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] failed get account diskon");
|
throw new Exception("[Error] failed get account diskon", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$coa_diskon = $que_coadiskon->row_array();
|
$coa_diskon = $que_coadiskon->row_array();
|
||||||
foreach ($input_diskon as $key => $val) {
|
foreach ($input_diskon as $key => $val) {
|
||||||
@@ -1041,8 +1366,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
]);
|
]);
|
||||||
if (!$que_jurnaltx) {
|
if (!$que_jurnaltx) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] failed insert jurnal tx diskon");
|
throw new Exception("[Error] failed insert jurnal tx diskon", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$jurnalTXID_diskon = $this->db->insert_id();
|
$jurnalTXID_diskon = $this->db->insert_id();
|
||||||
|
|
||||||
@@ -1050,41 +1374,40 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
$jurnalID,
|
$jurnalID,
|
||||||
$jurnalTXID_diskon,
|
$jurnalTXID_diskon,
|
||||||
$elem['PurchaseOrderNumber'],
|
$elem['PurchaseOrderNumber'],
|
||||||
|
$elem['ReceiveOrderPoItemID'],
|
||||||
$user['M_UserID']
|
$user['M_UserID']
|
||||||
]);
|
]);
|
||||||
if (!$que_jurnaladdon) {
|
if (!$que_jurnaladdon) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] failed insert jurnal addon diskon");
|
throw new Exception("[Error] failed insert jurnal addon diskon", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save diskon prorata item */
|
/* save diskon prorata item */
|
||||||
$sql_saveprorate = "UPDATE receive_order_po_detail SET
|
$sql_saveprorate = "UPDATE receive_order_po_detail SET
|
||||||
ReceiveOrderPoDetailDiskonPoProrata = ?
|
ReceiveOrderPoDetailDiskonPoProrata = ?
|
||||||
WHERE ReceiveOrderPoDetailID = ?";
|
WHERE ReceiveOrderPoDetailID = ?";
|
||||||
$que_saveprorate = $this->db->query($sql_saveprorate, [
|
$que_saveprorate = $this->db->query($sql_saveprorate, [
|
||||||
$diskon_prorata_item,
|
$diskon_prorata_item,
|
||||||
$elem['ReceiveOrderPoDetailID']
|
$elem['ReceiveOrderPoDetailID']
|
||||||
]);
|
]);
|
||||||
if (!$que_saveprorate) {
|
if (!$que_saveprorate) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] save diskon prorate");
|
throw new Exception("[Error] save diskon prorate", 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# INSERT jurnal tx for GRNI #
|
# INSERT jurnal tx for GRNI #
|
||||||
$total_grni = round($total_debet - ($total_diskonitem + $total_diskonpo), 2);
|
$total_grni = round($total_debet - ($total_diskonitem + $total_diskonpo), 2);
|
||||||
$sql_grni = "INSERT INTO jurnal_tx (
|
$sql_grni = "INSERT INTO jurnal_tx (
|
||||||
jurnalTxJurnalID,
|
jurnalTxJurnalID,
|
||||||
jurnalTxCoaID,
|
jurnalTxCoaID,
|
||||||
jurnalTxDescription,
|
jurnalTxDescription,
|
||||||
jurnalTxDebit,
|
jurnalTxDebit,
|
||||||
jurnalTxCredit,
|
jurnalTxCredit,
|
||||||
jurnalTxM_UserID
|
jurnalTxM_UserID
|
||||||
) SELECT ?, coaID, coaDescription, 0, ?, ?
|
) SELECT ?, coaID, coaDescription, 0, ?, ?
|
||||||
FROM coa WHERE coaAccountNo = '2110100030' LIMIT 1";
|
FROM coa WHERE coaAccountNo = '2110100030' LIMIT 1";
|
||||||
$que_grni = $this->db->query($sql_grni, [
|
$que_grni = $this->db->query($sql_grni, [
|
||||||
$jurnalID,
|
$jurnalID,
|
||||||
$total_grni,
|
$total_grni,
|
||||||
@@ -1092,19 +1415,18 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
]);
|
]);
|
||||||
if (!$que_grni) {
|
if (!$que_grni) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] insert jurnal tx GRNI");
|
throw new Exception('insert jurnal tx GRNI', 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$jurnalTXID_GRNI = $this->db->insert_id();
|
$jurnalTXID_GRNI = $this->db->insert_id();
|
||||||
|
|
||||||
$sql_addon_grni = "INSERT INTO jurnal_addon (
|
$sql_addon_grni = "INSERT INTO jurnal_addon (
|
||||||
jurnalAddOnJurnalID,
|
jurnalAddOnJurnalID,
|
||||||
jurnalAddOnJurnalTxID,
|
jurnalAddOnJurnalTxID,
|
||||||
jurnalAddOnCode,
|
jurnalAddOnCode,
|
||||||
jurnalAddOnValue,
|
jurnalAddOnValue,
|
||||||
jurnalAddOnCreated,
|
jurnalAddOnCreated,
|
||||||
jurnalAddOnCreatedUserID
|
jurnalAddOnCreatedUserID
|
||||||
) VALUES (?,?,'RONUMB',?,NOW(),?)";
|
) VALUES (?,?,'RONUMB',?,NOW(),?)";
|
||||||
$que_addon_grni = $this->db->query($sql_addon_grni, [
|
$que_addon_grni = $this->db->query($sql_addon_grni, [
|
||||||
$jurnalID,
|
$jurnalID,
|
||||||
$jurnalTXID_GRNI,
|
$jurnalTXID_GRNI,
|
||||||
@@ -1113,12 +1435,11 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
]);
|
]);
|
||||||
if (!$que_addon_grni) {
|
if (!$que_addon_grni) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] insert jurnal addon GRNI");
|
throw new Exception('insert jurnal addon GRNI', 1);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate purchase invoice
|
/* generate purchase invoice */
|
||||||
// still debatable
|
$this->generatePurchaseInvoice($user, $roID, $total_grni, $total_diskonpo);
|
||||||
|
|
||||||
$this->db->trans_commit();
|
$this->db->trans_commit();
|
||||||
$this->sys_ok("[Success] order received");
|
$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()
|
public function uploadAttachment()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -1169,7 +1641,7 @@ class ReceiveItemPOAsset extends MY_Controller
|
|||||||
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
||||||
|
|
||||||
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
$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;
|
$config['file_name'] = $new_filename;
|
||||||
$this->upload->initialize($config);
|
$this->upload->initialize($config);
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
<?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()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->db_onedev = $this->load->database("onedev", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add_notes($orderid){
|
public function __construct()
|
||||||
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
{
|
||||||
|
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,
|
SupplierPaymentID as note_id,
|
||||||
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||||
SupplierPaymentDate as note_date,
|
SupplierPaymentDate as note_date,
|
||||||
@@ -45,23 +47,24 @@ class Bill extends MY_Controller
|
|||||||
AND
|
AND
|
||||||
SupplierPaymentIsActive = 'Y'
|
SupplierPaymentIsActive = 'Y'
|
||||||
GROUP BY SupplierPaymentID";
|
GROUP BY SupplierPaymentID";
|
||||||
$query = $this->db_onedev->query($sql);
|
$query = $this->db_onedev->query($sql);
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$rows = $query->result_array();
|
$rows = $query->result_array();
|
||||||
if($rows){
|
if ($rows) {
|
||||||
foreach($rows as $k => $v){
|
foreach ($rows as $k => $v) {
|
||||||
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
|
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $rows;
|
return $rows;
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
public function add_tagihans($orderid)
|
||||||
$this->sys_error_db("get notes", $this->db_onedev);
|
{
|
||||||
exit;
|
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
||||||
}
|
|
||||||
}
|
|
||||||
public function add_tagihans($orderid){
|
|
||||||
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
|
||||||
PurchaseOrderNumber as tagihan_number,
|
PurchaseOrderNumber as tagihan_number,
|
||||||
jurnalTxDescription as pasien,
|
jurnalTxDescription as pasien,
|
||||||
jurnalTxCredit as tagihan_total,
|
jurnalTxCredit as tagihan_total,
|
||||||
@@ -85,18 +88,19 @@ class Bill extends MY_Controller
|
|||||||
SupplierInvoiceID = {$orderid}
|
SupplierInvoiceID = {$orderid}
|
||||||
GROUP BY jurnalTxID
|
GROUP BY jurnalTxID
|
||||||
";
|
";
|
||||||
$query = $this->db_onedev->query($sql);
|
$query = $this->db_onedev->query($sql);
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$rows = $query->result_array();
|
$rows = $query->result_array();
|
||||||
return $rows;
|
return $rows;
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
public function add_tests($orderid)
|
||||||
$this->sys_error_db("get notes", $this->db_onedev);
|
{
|
||||||
exit;
|
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||||
}
|
|
||||||
}
|
|
||||||
public function add_tests($orderid){
|
|
||||||
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
|
||||||
SupplierPaymentID as note_id,
|
SupplierPaymentID as note_id,
|
||||||
SupplierPaymentDate as note_date,
|
SupplierPaymentDate as note_date,
|
||||||
SupplierPaymentNumber as note_number,
|
SupplierPaymentNumber as note_number,
|
||||||
@@ -116,37 +120,37 @@ class Bill extends MY_Controller
|
|||||||
WHERE
|
WHERE
|
||||||
SupplierPaymentID = {$orderid}
|
SupplierPaymentID = {$orderid}
|
||||||
GROUP BY SupplierPaymentDetailID";
|
GROUP BY SupplierPaymentDetailID";
|
||||||
$query = $this->db_onedev->query($sql);
|
$query = $this->db_onedev->query($sql);
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$rows = $query->result_array();
|
$rows = $query->result_array();
|
||||||
if($rows){
|
if ($rows) {
|
||||||
}
|
}
|
||||||
return $rows;
|
return $rows;
|
||||||
|
} else {
|
||||||
} else {
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
$this->sys_error_db("get notes", $this->db_onedev);
|
exit;
|
||||||
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 search()
|
||||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
{
|
||||||
|
//# 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 SupplierInvoiceStatus = 'Approved'
|
||||||
AND SupplierInvoiceGrandTotal > 0
|
AND SupplierInvoiceGrandTotal > 0
|
||||||
AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}'
|
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
|
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'
|
||||||
@@ -166,22 +170,22 @@ class Bill extends MY_Controller
|
|||||||
WHERE
|
WHERE
|
||||||
$where
|
$where
|
||||||
";
|
";
|
||||||
// echo $sql;
|
// echo $sql;
|
||||||
$query = $this->db_onedev->query($sql, $sql_param);
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
|
||||||
|
|
||||||
$tot_count = 0;
|
$tot_count = 0;
|
||||||
$tot_page = 0;
|
$tot_page = 0;
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$tot_count = $query->result_array()[0]["total"];
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
$tot_page = ceil($tot_count/$number_limit);
|
$tot_page = ceil($tot_count / $number_limit);
|
||||||
} else {
|
} else {
|
||||||
$this->sys_error_db("supplier_invoice count", $this->db_onedev);
|
$this->sys_error_db("supplier_invoice count", $this->db_onedev);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$sql = "SELECT supplier_invoice.*,
|
$sql = "SELECT supplier_invoice.*,
|
||||||
SupplierName,
|
SupplierName,
|
||||||
'' M_MouName,
|
'' M_MouName,
|
||||||
0 as totalbill,
|
0 as totalbill,
|
||||||
@@ -213,45 +217,42 @@ class Bill extends MY_Controller
|
|||||||
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';
|
||||||
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber ? $s_payment->SupplierPaymentNumber : '';
|
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber ? $s_payment->SupplierPaymentNumber : '';
|
||||||
$rows[$k]['SupplierPaymentAmount'] = $amount;
|
$rows[$k]['SupplierPaymentAmount'] = $amount;
|
||||||
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
|
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
|
||||||
$rows[$k]['paid'] = $amount;
|
$rows[$k]['paid'] = $amount;
|
||||||
$rows[$k]['totalbill'] = $s_jurnal->totalbill ? $s_jurnal->totalbill : "0.00";
|
$rows[$k]['totalbill'] = $s_jurnal->totalbill ? $s_jurnal->totalbill : "0.00";
|
||||||
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
|
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
|
||||||
|
|
||||||
$rows[$k]['notes'] = $this->add_notes($v['SupplierInvoiceID']);
|
$rows[$k]['notes'] = $this->add_notes($v['SupplierInvoiceID']);
|
||||||
$rows[$k]['tagihans'] = $this->add_tagihans($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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$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