add supplier invoice number
This commit is contained in:
@@ -40,7 +40,6 @@ Content-Type: application/json
|
|||||||
|
|
||||||
{
|
{
|
||||||
"date" : "{{date}}",
|
"date" : "{{date}}",
|
||||||
"coaBayarID" : {{coaBayarID}},
|
|
||||||
"dryRun" : "N"
|
"dryRun" : "N"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -254,6 +254,8 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
$cicilanKe = ((int) $kontrak["PurchaseOrderAssetContractInstallmentPaid"]) + 1;
|
$cicilanKe = ((int) $kontrak["PurchaseOrderAssetContractInstallmentPaid"]) + 1;
|
||||||
$totalCicilan = (int) $kontrak["PurchaseOrderAssetContractInstallmentNumber"];
|
$totalCicilan = (int) $kontrak["PurchaseOrderAssetContractInstallmentNumber"];
|
||||||
$periode = date("Y-m", strtotime($date));
|
$periode = date("Y-m", strtotime($date));
|
||||||
|
$invoiceNumber = $kontrak["SupplierInvoiceNumber"] ?? "";
|
||||||
|
$invoiceID = (int) ($kontrak["SupplierInvoiceID"] ?? 0);
|
||||||
|
|
||||||
// Validasi: branchCode harus ada
|
// Validasi: branchCode harus ada
|
||||||
if ($branchCode == "") {
|
if ($branchCode == "") {
|
||||||
@@ -290,6 +292,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
"kontrakID" => $contractID,
|
"kontrakID" => $contractID,
|
||||||
"branchCode" => $branchCode,
|
"branchCode" => $branchCode,
|
||||||
"namaKontrak" => $namaKontrak,
|
"namaKontrak" => $namaKontrak,
|
||||||
|
"invoiceNumber" => $invoiceNumber,
|
||||||
"jumlah" => $jumlah,
|
"jumlah" => $jumlah,
|
||||||
"coaHutangID" => $coaHutangID,
|
"coaHutangID" => $coaHutangID,
|
||||||
"coaBayarID" => $coaBayarID,
|
"coaBayarID" => $coaBayarID,
|
||||||
@@ -299,8 +302,8 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Susun title dan description jurnal
|
// Susun title dan description jurnal
|
||||||
$title = "PI Cicilan Aset - {$nomorPO}";
|
$title = "PI Cicilan Aset - {$invoiceNumber}";
|
||||||
$description = "Jurnal cicilan ke-{$cicilanKe} dari {$totalCicilan} | {$namaKontrak} | Periode {$periode}";
|
$description = "Jurnal cicilan ke-{$cicilanKe} dari {$totalCicilan} | {$namaKontrak} | PO: {$nomorPO} | Periode {$periode}";
|
||||||
|
|
||||||
// Ambil periodeID dari tanggal
|
// Ambil periodeID dari tanggal
|
||||||
$periodeID = $this->getPeriodeIDByDate($date);
|
$periodeID = $this->getPeriodeIDByDate($date);
|
||||||
@@ -314,7 +317,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ambil jurnalTypeID untuk tipe PAYMENT
|
// Ambil jurnalTypeID untuk tipe PAYMENT
|
||||||
$jurnalTypeID = $this->getJurnalTypeID("PAYMENT");
|
$jurnalTypeID = $this->getJurnalTypeID("PAYMENTINV");
|
||||||
if ($jurnalTypeID <= 0) {
|
if ($jurnalTypeID <= 0) {
|
||||||
$dilewati[] = [
|
$dilewati[] = [
|
||||||
"kontrakID" => $contractID,
|
"kontrakID" => $contractID,
|
||||||
@@ -341,7 +344,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
"description" => $descHutang,
|
"description" => $descHutang,
|
||||||
"debit" => $jumlah,
|
"debit" => $jumlah,
|
||||||
"credit" => 0,
|
"credit" => 0,
|
||||||
"addonValue" => (string) $contractID,
|
"addonValue" => $invoiceNumber,
|
||||||
"mItemID" => $itemID,
|
"mItemID" => $itemID,
|
||||||
"addonCode" => "PIINSTALMENT"
|
"addonCode" => "PIINSTALMENT"
|
||||||
],
|
],
|
||||||
@@ -350,7 +353,7 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
"description" => $descBayar,
|
"description" => $descBayar,
|
||||||
"debit" => 0,
|
"debit" => 0,
|
||||||
"credit" => $jumlah,
|
"credit" => $jumlah,
|
||||||
"addonValue" => (string) $contractID,
|
"addonValue" => $invoiceNumber,
|
||||||
"mItemID" => $itemID,
|
"mItemID" => $itemID,
|
||||||
"addonCode" => "PIINSTALMENT"
|
"addonCode" => "PIINSTALMENT"
|
||||||
]
|
]
|
||||||
@@ -787,6 +790,8 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
{
|
{
|
||||||
$sql = "SELECT
|
$sql = "SELECT
|
||||||
c.PurchaseOrderAssetContractID,
|
c.PurchaseOrderAssetContractID,
|
||||||
|
si.SupplierInvoiceID,
|
||||||
|
si.SupplierInvoiceNumber,
|
||||||
c.PurchaseOrderAssetContractPurchaseOrderID,
|
c.PurchaseOrderAssetContractPurchaseOrderID,
|
||||||
c.PurchaseOrderAssetContractName,
|
c.PurchaseOrderAssetContractName,
|
||||||
c.PurchaseOrderAssetContractStartDate,
|
c.PurchaseOrderAssetContractStartDate,
|
||||||
@@ -840,6 +845,35 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
LEFT JOIN warehouse wh
|
LEFT JOIN warehouse wh
|
||||||
ON wh.WarehouseID = po.PurchaseOrderWarehouseID
|
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)
|
-- Pastikan barang sudah diterima (receive order confirmed)
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
@@ -866,22 +900,6 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
ON m_branch_companydetail.M_BranchCompanyDetailM_BranchCode = m_branch.M_BranchCode
|
ON m_branch_companydetail.M_BranchCompanyDetailM_BranchCode = m_branch.M_BranchCode
|
||||||
AND m_branch_companydetail.M_BranchCompanyDetailIsActive = 'Y'
|
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
|
-- COA jurnal diambil dari item -> fa_class
|
||||||
LEFT JOIN m_item mi
|
LEFT JOIN m_item mi
|
||||||
ON mi.M_ItemID = ps.PurchaseOrderSummaryItemID
|
ON mi.M_ItemID = ps.PurchaseOrderSummaryItemID
|
||||||
@@ -913,9 +931,23 @@ class JurnalPiCicilanOrderAset extends MY_Controller
|
|||||||
)
|
)
|
||||||
-- Tanggal jatuh tempo cicilan sudah tiba
|
-- Tanggal jatuh tempo cicilan sudah tiba
|
||||||
AND IFNULL(c.PurchaseOrderAssetContractInstallmentDate, 1) <= ?
|
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";
|
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) {
|
if (!$qry) {
|
||||||
$this->sys_error_db("Gagal mengambil data purchase_order_asset_contract.");
|
$this->sys_error_db("Gagal mengambil data purchase_order_asset_contract.");
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in New Issue
Block a user