add supplier invoice number
This commit is contained in:
@@ -40,7 +40,6 @@ Content-Type: application/json
|
||||
|
||||
{
|
||||
"date" : "{{date}}",
|
||||
"coaBayarID" : {{coaBayarID}},
|
||||
"dryRun" : "N"
|
||||
}
|
||||
|
||||
|
||||
@@ -254,6 +254,8 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
$cicilanKe = ((int) $kontrak["PurchaseOrderAssetContractInstallmentPaid"]) + 1;
|
||||
$totalCicilan = (int) $kontrak["PurchaseOrderAssetContractInstallmentNumber"];
|
||||
$periode = date("Y-m", strtotime($date));
|
||||
$invoiceNumber = $kontrak["SupplierInvoiceNumber"] ?? "";
|
||||
$invoiceID = (int) ($kontrak["SupplierInvoiceID"] ?? 0);
|
||||
|
||||
// Validasi: branchCode harus ada
|
||||
if ($branchCode == "") {
|
||||
@@ -290,6 +292,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
"kontrakID" => $contractID,
|
||||
"branchCode" => $branchCode,
|
||||
"namaKontrak" => $namaKontrak,
|
||||
"invoiceNumber" => $invoiceNumber,
|
||||
"jumlah" => $jumlah,
|
||||
"coaHutangID" => $coaHutangID,
|
||||
"coaBayarID" => $coaBayarID,
|
||||
@@ -299,8 +302,8 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
}
|
||||
|
||||
// Susun title dan description jurnal
|
||||
$title = "PI Cicilan Aset - {$nomorPO}";
|
||||
$description = "Jurnal cicilan ke-{$cicilanKe} dari {$totalCicilan} | {$namaKontrak} | Periode {$periode}";
|
||||
$title = "PI Cicilan Aset - {$invoiceNumber}";
|
||||
$description = "Jurnal cicilan ke-{$cicilanKe} dari {$totalCicilan} | {$namaKontrak} | PO: {$nomorPO} | Periode {$periode}";
|
||||
|
||||
// Ambil periodeID dari tanggal
|
||||
$periodeID = $this->getPeriodeIDByDate($date);
|
||||
@@ -314,7 +317,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
}
|
||||
|
||||
// Ambil jurnalTypeID untuk tipe PAYMENT
|
||||
$jurnalTypeID = $this->getJurnalTypeID("PAYMENT");
|
||||
$jurnalTypeID = $this->getJurnalTypeID("PAYMENTINV");
|
||||
if ($jurnalTypeID <= 0) {
|
||||
$dilewati[] = [
|
||||
"kontrakID" => $contractID,
|
||||
@@ -341,7 +344,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
"description" => $descHutang,
|
||||
"debit" => $jumlah,
|
||||
"credit" => 0,
|
||||
"addonValue" => (string) $contractID,
|
||||
"addonValue" => $invoiceNumber,
|
||||
"mItemID" => $itemID,
|
||||
"addonCode" => "PIINSTALMENT"
|
||||
],
|
||||
@@ -350,7 +353,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
"description" => $descBayar,
|
||||
"debit" => 0,
|
||||
"credit" => $jumlah,
|
||||
"addonValue" => (string) $contractID,
|
||||
"addonValue" => $invoiceNumber,
|
||||
"mItemID" => $itemID,
|
||||
"addonCode" => "PIINSTALMENT"
|
||||
]
|
||||
@@ -787,6 +790,8 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
{
|
||||
$sql = "SELECT
|
||||
c.PurchaseOrderAssetContractID,
|
||||
si.SupplierInvoiceID,
|
||||
si.SupplierInvoiceNumber,
|
||||
c.PurchaseOrderAssetContractPurchaseOrderID,
|
||||
c.PurchaseOrderAssetContractName,
|
||||
c.PurchaseOrderAssetContractStartDate,
|
||||
@@ -840,6 +845,35 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
LEFT JOIN warehouse wh
|
||||
ON wh.WarehouseID = po.PurchaseOrderWarehouseID
|
||||
|
||||
-- Ambil 1 item PO pertama sebagai referensi baris jurnal
|
||||
LEFT JOIN (
|
||||
SELECT ps0.*
|
||||
FROM purchase_order_summary ps0
|
||||
JOIN (
|
||||
SELECT
|
||||
PurchaseOrderSummaryPurchaseOrderID,
|
||||
MIN(PurchaseOrderSummaryID) AS PurchaseOrderSummaryID
|
||||
FROM purchase_order_summary
|
||||
WHERE PurchaseOrderSummaryIsActive = 'Y'
|
||||
GROUP BY PurchaseOrderSummaryPurchaseOrderID
|
||||
) psx
|
||||
ON psx.PurchaseOrderSummaryID = ps0.PurchaseOrderSummaryID
|
||||
) ps
|
||||
ON ps.PurchaseOrderSummaryPurchaseOrderID = po.PurchaseOrderID
|
||||
|
||||
-- Hubungkan dengan detail supplier_invoice_detail terlebih dahulu
|
||||
JOIN supplier_invoice_detail sid
|
||||
ON sid.SupplierInvoiceDetailPurchaseOrderID = po.PurchaseOrderID
|
||||
AND sid.SupplierInvoiceDetailPurchaseOrderSummaryID = ps.PurchaseOrderSummaryID
|
||||
AND sid.SupplierInvoiceDetailIsActive = 'Y'
|
||||
|
||||
-- Baru hubungkan ke header supplier_invoice untuk mengambil nomor invoice
|
||||
JOIN supplier_invoice si
|
||||
ON si.SupplierInvoiceID = sid.SupplierInvoiceDetailSupplierInvoiceID
|
||||
AND si.SupplierInvoiceDate >= DATE(?)
|
||||
AND si.SupplierInvoiceDate <= DATE(?)
|
||||
AND si.SupplierInvoiceIsActive = 'Y'
|
||||
|
||||
-- Pastikan barang sudah diterima (receive order confirmed)
|
||||
JOIN (
|
||||
SELECT
|
||||
@@ -866,22 +900,6 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
ON m_branch_companydetail.M_BranchCompanyDetailM_BranchCode = m_branch.M_BranchCode
|
||||
AND m_branch_companydetail.M_BranchCompanyDetailIsActive = 'Y'
|
||||
|
||||
-- Ambil 1 item PO pertama sebagai referensi baris jurnal
|
||||
LEFT JOIN (
|
||||
SELECT ps0.*
|
||||
FROM purchase_order_summary ps0
|
||||
JOIN (
|
||||
SELECT
|
||||
PurchaseOrderSummaryPurchaseOrderID,
|
||||
MIN(PurchaseOrderSummaryID) AS PurchaseOrderSummaryID
|
||||
FROM purchase_order_summary
|
||||
WHERE PurchaseOrderSummaryIsActive = 'Y'
|
||||
GROUP BY PurchaseOrderSummaryPurchaseOrderID
|
||||
) psx
|
||||
ON psx.PurchaseOrderSummaryID = ps0.PurchaseOrderSummaryID
|
||||
) ps
|
||||
ON ps.PurchaseOrderSummaryPurchaseOrderID = po.PurchaseOrderID
|
||||
|
||||
-- COA jurnal diambil dari item -> fa_class
|
||||
LEFT JOIN m_item mi
|
||||
ON mi.M_ItemID = ps.PurchaseOrderSummaryItemID
|
||||
@@ -913,9 +931,23 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
||||
)
|
||||
-- Tanggal jatuh tempo cicilan sudah tiba
|
||||
AND IFNULL(c.PurchaseOrderAssetContractInstallmentDate, 1) <= ?
|
||||
-- Pastikan belum pernah dibuatkan jurnal untuk invoice cicilan ini
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM jurnal_addon ja
|
||||
JOIN jurnal j ON j.jurnalID = ja.jurnalAddOnJurnalID
|
||||
WHERE ja.jurnalAddOnCode = 'PIINSTALMENT'
|
||||
AND ja.jurnalAddOnValue = si.SupplierInvoiceNumber
|
||||
)
|
||||
ORDER BY c.PurchaseOrderAssetContractID ASC";
|
||||
|
||||
$qry = $this->db->query($sql, [$endDate, $startDate, (int) date("d", strtotime($endDate))]);
|
||||
$qry = $this->db->query($sql, [
|
||||
$startDate,
|
||||
$endDate,
|
||||
$endDate,
|
||||
$startDate,
|
||||
(int) date("d", strtotime($endDate))
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Gagal mengambil data purchase_order_asset_contract.");
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user