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 {
|
||||
|
||||
Reference in New Issue
Block a user