16 Commits

Author SHA1 Message Date
64f434cd78 feature: po pay downpayment 2026-07-20 13:13:59 +07:00
Hanan Askarim
61e2e4f2ec add keterangan untuk http pi instalment 2026-07-15 10:48:53 +07:00
Hanan Askarim
79fd2864cc update penomoran dari fn fungsi 2026-07-15 10:48:53 +07:00
Hanan Askarim
344c5d42e6 fix http pembayaran 2026-07-15 10:48:53 +07:00
Hanan Askarim
f30c6dbb60 add supplier invoice number 2026-07-15 10:48:53 +07:00
Hanan Askarim
2d072fad16 gabungkan fungsi get data dengan create jurnal 2026-07-15 10:48:53 +07:00
Hanan Askarim
aef86b7acf add pengambilan co dari fa_class 2026-07-15 10:48:53 +07:00
Hanan Askarim
efdf8af569 add pembuatan jurnal pi cicilan order asset 2026-07-15 10:48:53 +07:00
Hanan Askarim
712cbbb80b fix query get cicilan dan insert supplier invoice 2026-07-15 10:48:53 +07:00
Hanan Askarim
977694905c add generate po contract 2026-07-15 10:48:53 +07:00
ee3748066e feature: receive item order asset & insert jurnal faktur asset 2026-07-15 10:43:56 +07:00
709dfdae33 update: api purchase order asset & receive order asset 2026-07-13 09:08:43 +07:00
e62ec1d994 feature: file receiveItemAset & change some query purchaseorderasest 2026-07-10 15:49:00 +07:00
34fb944e6e add: inventaris item coa mapping API 2026-07-10 08:30:36 +07:00
17445d9534 add: inventaris coa mapping API 2026-07-10 08:30:36 +07:00
17423ac0b5 change table asset attachment into contract_asset_attachment 2026-07-10 08:30:12 +07:00
11 changed files with 5549 additions and 1817 deletions

View File

@@ -0,0 +1,113 @@
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTk1LjEyMi4yMzUiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzNy4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM3LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNi0wNCAxMzoyMDowNSIsIk1fU2F0ZWxsaXRlSUQiOjB9.hm6JtstjaQOzb7oDSXQ-oMWuX_jFQZH-HDr3r3OzPac"
@host = accone.aplikasi.web.id/one-api
###
// create inventaris coa mapping
POST https://{{host}}/map/InventarisCoaMapping/createInvCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisGolID": 1,
"CoaInventarisID": 101,
"CoaHutangID": 102,
"CoaPembelianID": 103,
"CoaBebanPenyusutanID": 104,
"CoaAkumulasiPenyusutanID": 105,
"CoaLabaPelepasanID": 106,
"CoaRugiPelepasanID": 107
}
###
// get inventaris coa mapping by ID
POST https://{{host}}/map/InventarisCoaMapping/getInvCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisCoaMappingID": 1
}
###
// edit inventaris coa mapping
POST https://{{host}}/map/InventarisCoaMapping/editInvCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisCoaMappingID": 1,
"M_InventarisGolID": 2,
"CoaInventarisID": 201,
"CoaHutangID": 202,
"CoaPembelianID": 203,
"CoaBebanPenyusutanID": 204,
"CoaAkumulasiPenyusutanID": 205,
"CoaLabaPelepasanID": 206,
"CoaRugiPelepasanID": 207
}
###
// delete inventaris coa mapping
POST https://{{host}}/map/InventarisCoaMapping/deleteInvCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisCoaMappingID": 1
}
###
// create inventaris item coa mapping
POST https://{{host}}/map/InventarisCoaMapping/createInvItemCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_ItemID": 10,
"CoaInventarisID": 201,
"CoaHutangID": 202,
"CoaPembelianID": 203,
"CoaBebanPenyusutanID": 204,
"CoaAkumulasiPenyusutanID": 205,
"CoaLabaPelepasanID": 206,
"CoaRugiPelepasanID": 207
}
###
// get inventaris item coa mapping by ID
POST https://{{host}}/map/InventarisCoaMapping/getInvItemCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisItemCoaMappingID": 1
}
###
// edit inventaris item coa mapping
POST https://{{host}}/map/InventarisCoaMapping/editInvItemCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisItemCoaMappingID": 1,
"M_ItemID": 11,
"CoaInventarisID": 301,
"CoaHutangID": 302,
"CoaPembelianID": 303,
"CoaBebanPenyusutanID": 304,
"CoaAkumulasiPenyusutanID": 305,
"CoaLabaPelepasanID": 306,
"CoaRugiPelepasanID": 307
}
###
// delete inventaris item coa mapping
POST https://{{host}}/map/InventarisCoaMapping/deleteInvItemCoaMapping/
Content-Type: application/json
{
"token": {{token}},
"M_InventarisItemCoaMappingID": 1
}

View File

@@ -0,0 +1,624 @@
<?php
class InventarisCoaMapping extends MY_Controller
{
var $db;
public function index()
{
echo "Inventaris COA Mapping API";
}
public function __construct()
{
parent::__construct();
}
## QUERY ##
public function getListCoa()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$para = $this->sys_input;
$keyword = "%" . $para['keyword'] . "%";
$sql = "SELECT
coaID,
coaAccountNo,
coaDescription
FROM coa
WHERE coaIsInput = 'Y'
AND (
coaDescription LIKE ?
OR coaAccountNo LIKE ?
)
AND coaIsActive = 'Y'
LIMIT 15";
$que = $this->db->query($sql, [$keyword, $keyword]);
if (!$que) {
throw new Exception('failed to query data inventaris gol', 1);
}
$data = $que->result_array();
$this->sys_ok($data);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getListInventarisGol()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$sql = "SELECT
M_InventarisGolID,
M_InventarisGolCode,
M_InventarisGolName
FROM m_inventaris_gol gol
WHERE gol.M_InventarisGolIsActive = 'Y'
AND NOT EXISTS (
SELECT 1
FROM m_inventaris_coa_mapping m
WHERE m.M_InventarisCoaMappingM_InventarisGolID = gol.M_InventarisGolID
AND m.M_InventarisCoaMappingIsActive = 'Y'
);";
$que = $this->db->query($sql);
if (!$que) {
throw new Exception('failed to query data inventaris gol', 1);
}
$data = $que->result_array();
$output = [
'records' => $data,
'total' => count($data)
];
$this->sys_ok($output);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getListInventorygolMapping()
{
try {
if (!$this->isLogin) {
throw new Exception('invalid token');
}
$para = $this->sys_input;
$keyword = "%" . $para['keyword'] . "%";
$limit = 10;
$offset = 0;
if ($para['currpage'] > 0) {
$offset = ($para['currpage'] - 1) * $limit;
}
$sql = "SELECT
M_InventarisGolID,
M_InventarisGolCode,
M_InventarisGolName,
M_InventarisCoaMappingID,
M_InventarisCoaMappingCoaInventarisID,
coaInv.coaAccountNo AS CoaInventarisAccountNo,
coaInv.coaDescription AS CoaInventarisDescription,
M_InventarisCoaMappingCoaHutangID,
coaHtg.coaAccountNo AS CoaHutangAccountNo,
coaHtg.coaDescription AS CoaHutangDescription,
M_InventarisCoaMappingCoaBebanPenyusutanID,
coaBbn.coaAccountNo AS CoaBebanPenyusutanAccountNo,
coaBbn.coaDescription AS CoaBebanPenyusutanDescription,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID,
coaAkm.coaAccountNo AS CoaAkumulasiPenyusutanAccountNo,
coaAkm.coaDescription AS CoaAkumulasiPenyusutanDescription,
M_InventarisCoaMappingCoaLabaPelepasanID,
coaLab.coaAccountNo AS CoaLabaPelepasanAccountNo,
coaLab.coaDescription AS CoaLabaPelepasanDescription,
M_InventarisCoaMappingCoaRugiPelepasanID,
coaRug.coaAccountNo AS CoaRugiPelepasanAccountNo,
coaRug.coaDescription AS CoaRugiPelepasanDescription
FROM m_inventaris_gol
JOIN m_inventaris_coa_mapping
ON M_InventarisCoaMappingM_InventarisGolID = M_InventarisGolID
AND M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisGolIsActive = 'Y'
AND M_InventarisGolName LIKE ?
LEFT JOIN coa AS coaInv
ON M_InventarisCoaMappingCoaInventarisID = coaInv.coaID
LEFT JOIN coa AS coaHtg
ON M_InventarisCoaMappingCoaHutangID = coaHtg.coaID
LEFT JOIN coa AS coaBbn
ON M_InventarisCoaMappingCoaBebanPenyusutanID = coaBbn.coaID
LEFT JOIN coa AS coaAkm
ON M_InventarisCoaMappingCoaAkumulasiPenyusutanID = coaAkm.coaID
LEFT JOIN coa AS coaLab
ON M_InventarisCoaMappingCoaLabaPelepasanID = coaLab.coaID
LEFT JOIN coa AS coaRug
ON M_InventarisCoaMappingCoaRugiPelepasanID = coaRug.coaID
WHERE M_InventarisGolIsActive = 'Y'";
$sql_data = $sql . " ORDER BY M_InventarisGolID LIMIT ? OFFSET ? ";
$que = $this->db->query($sql_data, [
$keyword,
$limit,
$offset
]);
if (!$que) {
throw new Exception('failed to query data mapping coa inventaris golongan', 1);
}
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
$que_total = $this->db->query($sql_total, [$keyword]);
if (!$que_total) {
throw new Exception('failed to get total rows data', 1);
}
$this->sys_ok([
"records" => $que->result_array(),
"total" => $que_total->row_array()['total']
]);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getInvCoaMappingDetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
$sql = "SELECT
M_InventarisCoaMappingID,
M_InventarisCoaMappingM_InventarisGolID,
M_InventarisCoaMappingCoaInventarisID,
M_InventarisCoaMappingCoaHutangID,
M_InventarisCoaMappingCoaPembelianID,
M_InventarisCoaMappingCoaBebanPenyusutanID,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisCoaMappingCoaLabaPelepasanID,
M_InventarisCoaMappingCoaRugiPelepasanID,
M_InventarisCoaMappingCreatedUserID,
M_InventarisCoaMappingCreated,
M_InventarisCoaMappingLastUpdated
FROM m_inventaris_coa_mapping
WHERE M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisCoaMappingID']]);
if (!$query) {
$this->sys_error_db("[Error] get data m_inventaris_coa_mapping");
exit;
}
$data = $query->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## MUTATIONS ##
public function createInvCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$user = $this->sys_user;
$sql = "INSERT INTO m_inventaris_coa_mapping (
M_InventarisCoaMappingM_InventarisGolID,
M_InventarisCoaMappingCoaInventarisID,
M_InventarisCoaMappingCoaHutangID,
M_InventarisCoaMappingCoaPembelianID,
M_InventarisCoaMappingCoaBebanPenyusutanID,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisCoaMappingCoaLabaPelepasanID,
M_InventarisCoaMappingCoaRugiPelepasanID,
M_InventarisCoaMappingCreatedUserID,
M_InventarisCoaMappingCreated,
M_InventarisCoaMappingLastUpdated
) VALUES (?,?,?,?,?,?,?,?,?,NOW(),NOW())";
$query = $this->db->query($sql, [
$para['M_InventarisGolID'],
$para['CoaInventarisID'],
$para['CoaHutangID'],
$para['CoaPembelianID'],
$para['CoaBebanPenyusutanID'],
$para['CoaAkumulasiPenyusutanID'],
$para['CoaLabaPelepasanID'],
$para['CoaRugiPelepasanID'],
$user['M_UserID']
]);
if (!$query) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] insert into table m_inventaris_coa_mapping");
exit;
}
$insertID = $this->db->insert_id();
$this->db->trans_commit();
$this->sys_ok($insertID);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
public function editInvCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$user = $this->sys_user;
$sql = "UPDATE m_inventaris_coa_mapping SET
M_InventarisCoaMappingM_InventarisGolID = ?,
M_InventarisCoaMappingCoaInventarisID = ?,
M_InventarisCoaMappingCoaHutangID = ?,
M_InventarisCoaMappingCoaPembelianID = ?,
M_InventarisCoaMappingCoaBebanPenyusutanID = ?,
M_InventarisCoaMappingCoaAkumulasiPenyusutanID = ?,
M_InventarisCoaMappingCoaLabaPelepasanID = ?,
M_InventarisCoaMappingCoaRugiPelepasanID = ?,
M_InventarisCoaMappingLastUpdated = NOW()
WHERE M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisCoaMappingID = ?";
$query = $this->db->query($sql, [
$para['M_InventarisGolID'],
$para['CoaInventarisID'],
$para['CoaHutangID'],
$para['CoaPembelianID'],
$para['CoaBebanPenyusutanID'],
$para['CoaAkumulasiPenyusutanID'],
$para['CoaLabaPelepasanID'],
$para['CoaRugiPelepasanID'],
$para['M_InventarisCoaMappingID']
]);
if (!$query) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] update table m_inventaris_coa_mapping");
exit;
}
$this->db->trans_commit();
$this->sys_ok("[Success] update data inventaris coa mapping");
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
public function deleteInvCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$sql = "UPDATE m_inventaris_coa_mapping SET
M_InventarisCoaMappingIsActive = 'N',
M_InventarisCoaMappingLastUpdated = NOW()
WHERE M_InventarisCoaMappingIsActive = 'Y'
AND M_InventarisCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisCoaMappingID']]);
if (!$query) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] soft delete data m_inventaris_coa_mapping");
exit;
}
$this->db->trans_commit();
$this->sys_ok("[Success] delete data inventaris coa mapping");
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## QUERY ITEM ##
public function getListItemInventaris()
{
try {
if (!$this->isLogin) {
throw new Exception('Invalid token');
}
$para = $this->sys_input;
$sql = "SELECT
M_ItemID,
M_ItemCode,
M_ItemDesc,
M_ItemM_InventarisGolID AS itemGolID,
IFNULL(M_InventarisItemCoaMappingID, 0) AS itemCoaMapID,
M_InventarisItemCoaMappingCoaInventarisID,
coaInv.coaAccountNo AS CoaInventarisAccountNo,
coaInv.coaDescription AS CoaInventarisDescription,
M_InventarisItemCoaMappingCoaHutangID,
coaHtg.coaAccountNo AS CoaHutangAccountNo,
coaHtg.coaDescription AS CoaHutangDescription,
M_InventarisItemCoaMappingCoaBebanPenyusutanID,
coaBbn.coaAccountNo AS CoaBebanPenyusutanAccountNo,
coaBbn.coaDescription AS CoaBebanPenyusutanDescription,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
coaAkm.coaAccountNo AS CoaAkumulasiPenyusutanAccountNo,
coaAkm.coaDescription AS CoaAkumulasiPenyusutanDescription,
M_InventarisItemCoaMappingCoaLabaPelepasanID,
coaLab.coaAccountNo AS CoaLabaPelepasanAccountNo,
coaLab.coaDescription AS CoaLabaPelepasanDescription,
M_InventarisItemCoaMappingCoaRugiPelepasanID,
coaRug.coaAccountNo AS CoaRugiPelepasanAccountNo,
coaRug.coaDescription AS CoaRugiPelepasanDescription
FROM m_item
LEFT JOIN m_inventaris_item_coa_mapping
ON M_ItemID = M_InventarisItemCoaMappingM_ItemID
AND M_InventarisItemCoaMappingIsActive = 'Y'
LEFT JOIN coa AS coaInv
ON M_InventarisItemCoaMappingCoaInventarisID = coaInv.coaID
LEFT JOIN coa AS coaHtg
ON M_InventarisItemCoaMappingCoaHutangID = coaHtg.coaID
LEFT JOIN coa AS coaBbn
ON M_InventarisItemCoaMappingCoaBebanPenyusutanID = coaBbn.coaID
LEFT JOIN coa AS coaAkm
ON M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID = coaAkm.coaID
LEFT JOIN coa AS coaLab
ON M_InventarisItemCoaMappingCoaLabaPelepasanID = coaLab.coaID
LEFT JOIN coa AS coaRug
ON M_InventarisItemCoaMappingCoaRugiPelepasanID = coaRug.coaID
WHERE M_ItemItem_CategoryID = 2
AND M_ItemM_InventarisGolID = ?
AND M_ItemIsActive = 'Y'";
$que = $this->db->query($sql, [
$para['golID']
]);
if (!$que) {
throw new Exception('failed to query data inventaris gol', 1);
}
$data = $que->result_array();
$output = [
'records' => $data,
'total' => count($data)
];
$this->sys_ok($output);
} catch (Exception $e) {
$msg = '[Error] ' . $e->getMessage();
$code = $e->getCode();
if ($code == 0) {
$this->sys_error($msg);
} else {
$this->sys_error_db($msg);
}
exit;
}
}
public function getInvItemCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$para = $this->sys_input;
$sql = "SELECT
M_InventarisItemCoaMappingID,
M_InventarisItemCoaMappingM_ItemID,
M_InventarisItemCoaMappingCoaInventarisID,
M_InventarisItemCoaMappingCoaHutangID,
M_InventarisItemCoaMappingCoaPembelianID,
M_InventarisItemCoaMappingCoaBebanPenyusutanID,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisItemCoaMappingCoaLabaPelepasanID,
M_InventarisItemCoaMappingCoaRugiPelepasanID,
M_InventarisItemCoaMappingCreatedUserID,
M_InventarisItemCoaMappingCreated,
M_InventarisItemCoaMappingLastUpdated
FROM m_inventaris_item_coa_mapping
WHERE M_InventarisItemCoaMappingIsActive = 'Y'
AND M_InventarisItemCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisItemCoaMappingID']]);
if (!$query) {
$this->sys_error_db("[Error] get data m_inventaris_item_coa_mapping");
exit;
}
$data = $query->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
## MUTATIONS ITEM ##
public function createInvItemCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$user = $this->sys_user;
$sql = "INSERT INTO m_inventaris_item_coa_mapping (
M_InventarisItemCoaMappingM_ItemID,
M_InventarisItemCoaMappingCoaInventarisID,
M_InventarisItemCoaMappingCoaHutangID,
M_InventarisItemCoaMappingCoaPembelianID,
M_InventarisItemCoaMappingCoaBebanPenyusutanID,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
M_InventarisItemCoaMappingCoaLabaPelepasanID,
M_InventarisItemCoaMappingCoaRugiPelepasanID,
M_InventarisItemCoaMappingCreatedUserID,
M_InventarisItemCoaMappingCreated,
M_InventarisItemCoaMappingLastUpdated
) VALUES (?,?,?,?,?,?,?,?,?,NOW(),NOW())";
$query = $this->db->query($sql, [
$para['M_ItemID'],
$para['CoaInventarisID'],
$para['CoaHutangID'],
$para['CoaPembelianID'],
$para['CoaBebanPenyusutanID'],
$para['CoaAkumulasiPenyusutanID'],
$para['CoaLabaPelepasanID'],
$para['CoaRugiPelepasanID'],
$user['M_UserID']
]);
if (!$query) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] insert into table m_inventaris_item_coa_mapping");
exit;
}
$insertID = $this->db->insert_id();
$this->db->trans_commit();
$this->sys_ok("[Success] insert coa item");
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
public function editInvItemCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$user = $this->sys_user;
$sql = "UPDATE m_inventaris_item_coa_mapping SET
M_InventarisItemCoaMappingM_ItemID = ?,
M_InventarisItemCoaMappingCoaInventarisID = ?,
M_InventarisItemCoaMappingCoaHutangID = ?,
M_InventarisItemCoaMappingCoaPembelianID = ?,
M_InventarisItemCoaMappingCoaBebanPenyusutanID = ?,
M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID = ?,
M_InventarisItemCoaMappingCoaLabaPelepasanID = ?,
M_InventarisItemCoaMappingCoaRugiPelepasanID = ?,
M_InventarisItemCoaMappingLastUpdated = NOW()
WHERE M_InventarisItemCoaMappingIsActive = 'Y'
AND M_InventarisItemCoaMappingID = ?";
$query = $this->db->query($sql, [
$para['M_ItemID'],
$para['CoaInventarisID'],
$para['CoaHutangID'],
$para['CoaPembelianID'],
$para['CoaBebanPenyusutanID'],
$para['CoaAkumulasiPenyusutanID'],
$para['CoaLabaPelepasanID'],
$para['CoaRugiPelepasanID'],
$para['M_InventarisItemCoaMappingID']
]);
if (!$query) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] update table m_inventaris_item_coa_mapping");
exit;
}
$this->db->trans_commit();
$this->sys_ok("[Success] update data inventaris item coa mapping");
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
public function deleteInvItemCoaMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$sql = "UPDATE m_inventaris_item_coa_mapping SET
M_InventarisItemCoaMappingIsActive = 'N',
M_InventarisItemCoaMappingLastUpdated = NOW()
WHERE M_InventarisItemCoaMappingIsActive = 'Y'
AND M_InventarisItemCoaMappingID = ?";
$query = $this->db->query($sql, [$para['M_InventarisItemCoaMappingID']]);
if (!$query) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] soft delete data m_inventaris_item_coa_mapping");
exit;
}
$this->db->trans_commit();
$this->sys_ok("[Success] delete data inventaris item coa mapping");
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
}

View File

@@ -496,6 +496,7 @@ class Fakturv4 extends MY_Controller
ELSE '' ELSE ''
END as WarehouseName, END as WarehouseName,
ReceiveOrderPoID, ReceiveOrderPoID,
ReceiveOrderPoTypePurchase,
PurchaseOrderItemCategoryID PurchaseOrderItemCategoryID
FROM supplier_invoice FROM supplier_invoice
JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID JOIN supplier_invoice_detail ON SupplierInvoiceID = SupplierInvoiceDetailSupplierInvoiceID
@@ -588,12 +589,11 @@ class Fakturv4 extends MY_Controller
'P' 'P'
) AS DiscountType, ) AS DiscountType,
SupplierInvoiceReceiveOrderPoID, SupplierInvoiceReceiveOrderPoID,
ReceiveOrderPoNumber ReceiveOrderPoNumber,
ReceiveOrderPoTypePurchase AS typePurchase
FROM supplier_invoice FROM supplier_invoice
JOIN supplier ON SupplierInvoiceSupplierID = SupplierID JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN receive_order_po ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID JOIN receive_order_po ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID
-- JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
-- AND PurchaseOrderIsActive = 'Y'
WHERE SupplierInvoiceIsActive = 'Y' WHERE SupplierInvoiceIsActive = 'Y'
AND SupplierInvoiceID = ?"; AND SupplierInvoiceID = ?";
$que = $this->db->query($sql, $para['SInvoiceID']); $que = $this->db->query($sql, $para['SInvoiceID']);
@@ -601,6 +601,7 @@ class Fakturv4 extends MY_Controller
$this->sys_error_db('[Error] get detail data invoice'); $this->sys_error_db('[Error] get detail data invoice');
exit; exit;
} }
$data = $que->row_array();
$sqldet = "SELECT $sqldet = "SELECT
SupplierInvoiceDetailID, SupplierInvoiceDetailID,
@@ -636,7 +637,30 @@ class Fakturv4 extends MY_Controller
exit; exit;
} }
$data = $que->result_array()[0]; if (isset($data['typePurchase']) && $data['typePurchase'] == 'aset') {
$sql_dp = "SELECT
IFNULL(SupplierDownpaymentAmount, 0) AS dp_amount
FROM supplier_invoice
JOIN receive_order_po
ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID
JOIN purchase_order_asset_contract
ON PurchaseOrderAssetContractReceiveOrderPoID = ReceiveOrderPoID
AND PurchaseOrderAssetContractIsActive = 'Y'
JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderAssetContractPurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
WHERE SupplierInvoiceID = ?";
$que_dp = $this->db->query($sql_dp, [
$para['SInvoiceID']
]);
if (!$que_dp) {
$this->sys_error_db("[Error] get info contract asset");
exit;
}
$dp_amount = $que_dp->row_array()['dp_amount'];
$data['dp_amount'] = $dp_amount;
}
$data['detail'] = $quedet->result_array(); $data['detail'] = $quedet->result_array();
$result = $data; $result = $data;
@@ -1317,7 +1341,8 @@ class Fakturv4 extends MY_Controller
supplier_invoice_detail.*, supplier_invoice_detail.*,
ReceiveOrderPoNumber, ReceiveOrderPoNumber,
ReceiveOrderPoM_BranchCode, ReceiveOrderPoM_BranchCode,
ReceiveOrderPoS_RegionalID ReceiveOrderPoS_RegionalID,
ReceiveOrderPoTypePurchase AS typePurchase
FROM supplier_invoice FROM supplier_invoice
JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierInvoiceID JOIN supplier_invoice_detail ON SupplierInvoiceDetailSupplierInvoiceID = SupplierInvoiceID
AND SupplierInvoiceDetailIsActive = 'Y' AND SupplierInvoiceDetailIsActive = 'Y'
@@ -1453,7 +1478,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,13 +1489,14 @@ 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 #
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
if ($ship_cost > 0.00) {
$queryshipcost = $this->db->query($sqlcoa, ['5320700001']); $queryshipcost = $this->db->query($sqlcoa, ['5320700001']);
if (!$queryshipcost) { if (!$queryshipcost) {
$this->db->trans_rollback(); $this->db->trans_rollback();
@@ -1480,7 +1505,6 @@ class Fakturv4 extends MY_Controller
} }
$coashipcost = $queryshipcost->result_array()[0]; $coashipcost = $queryshipcost->result_array()[0];
if ($ship_cost > 0.00) {
$insertcost = $this->InsertJurnalTx( $insertcost = $this->InsertJurnalTx(
$jurnalID, $jurnalID,
$coashipcost['coaID'], $coashipcost['coaID'],
@@ -1496,6 +1520,63 @@ class Fakturv4 extends MY_Controller
} }
} }
/* Insert jurnal tx for down payment asset */
// ----------------------------------------------------------------------------------------
if (isset($invoice[0]['typePurchase']) && $invoice[0]['typePurchase'] == 'aset') {
$sql_dpasset = "SELECT
PurchaseOrderAssetContractID,
PurchaseOrderAssetContractName,
SupplierDownpaymentAmount,
coaID,
coaDescription
FROM purchase_order_asset_contract
JOIN purchase_order ON PurchaseOrderID = PurchaseOrderAssetContractPurchaseOrderID
JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
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['SupplierDownpaymentAmount'], 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,40 +1684,8 @@ 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']);
} }
@@ -1717,6 +1766,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 {

View File

@@ -66,6 +66,40 @@ class PurchaseOrderAset extends MY_Controller {
} }
} }
public function getListGudang() {
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$user = $this->sys_user;
$para = $this->sys_input;
$sql = "SELECT
WarehouseID,
WarehouseCode,
WarehouseName
FROM warehouse
WHERE WarehouseIsActive = 'Y'
AND WarehouseS_RegionalID = ?
AND WarehouseM_BranchID = ?
AND WarehouseIsTransit = 'N'";
$que = $this->db->query($sql, [
$user['S_RegionalID'], $para['M_BranchID']
]);
if (!$que) {
$this->sys_error_db("[Error] failed get list gudang");
exit;
}
$data = $que->result_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$this->sys_error($exc->getMessage());
}
}
public function searchRequestAset() { public function searchRequestAset() {
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
@@ -81,16 +115,13 @@ class PurchaseOrderAset extends MY_Controller {
} }
$limit = 10; $limit = 10;
$offset = 0;
if ($para['currpage'] > 0) {
$offset = ($para['currpage'] - 1) * $limit;
}
$sql = "SELECT $sql = "SELECT
PurchaseRequestID, PurchaseRequestID,
PurchaseRequestNumber, PurchaseRequestNumber,
PurchaseRequestDetailID, PurchaseRequestDetailID,
PurchaseRequestFlagID, PurchaseRequestFlagID,
M_BranchID,
PurchaseRequestFlagM_BranchCode AS BranchCode, PurchaseRequestFlagM_BranchCode AS BranchCode,
PurchaseRequestItemCategoryID AS ItemCategoryID, PurchaseRequestItemCategoryID AS ItemCategoryID,
PurchaseRequestFlagQtyRest - PurchaseRequestFlagQtyProses AS UnprocessFlagQty, PurchaseRequestFlagQtyRest - PurchaseRequestFlagQtyProses AS UnprocessFlagQty,
@@ -102,24 +133,26 @@ class PurchaseOrderAset extends MY_Controller {
M_ItemDesc, M_ItemDesc,
ItemUnitID, ItemUnitID,
ItemUnitName, ItemUnitName,
SupplierPricePrice as SupplierPrice SupplierPricePrice as SupplierPrice,
M_UserUsername AS Requestedby
FROM purchase_request FROM purchase_request
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
AND PurchaseRequestDetailIsActive = 'Y' AND PurchaseRequestDetailIsActive = 'Y'
AND PurchaseRequestM_BranchCode = ?
AND PurchaseRequestItemCategoryID = '3' -- id category item asset AND PurchaseRequestItemCategoryID = '3' -- id category item asset
AND PurchaseRequestNumber LIKE ? JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
AND (PurchaseRequestNumber LIKE ? OR M_ItemDesc LIKE ?)
JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
AND PurchaseRequestFlagStatus = 'PO' AND PurchaseRequestFlagStatus = 'PO'
AND PurchaseRequestFlagIsActive = 'Y' AND PurchaseRequestFlagIsActive = 'Y'
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID JOIN m_branch ON M_BranchCode = PurchaseRequestFlagM_BranchCode
AND M_BranchID = ?
AND M_BranchIsActive = 'Y'
JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID
JOIN supplier_price ON SupplierPriceSupplierID = ? JOIN supplier_price ON SupplierPriceSupplierID = ?
AND SupplierPriceM_ItemID = M_ItemID AND SupplierPriceM_ItemID = M_ItemID
AND SupplierPriceItemUnitID = ItemUnitID AND SupplierPriceItemUnitID = ItemUnitID
AND SupplierPriceIsActive = 'Y' AND SupplierPriceIsActive = 'Y'
JOIN m_branch ON M_BranchCode = PurchaseRequestFlagM_BranchCode JOIN m_user ON M_UserID = PurchaseRequestRequestedBy
AND M_BranchIsActive = 'Y'
WHERE NOT EXISTS ( WHERE NOT EXISTS (
SELECT 1 SELECT 1
FROM purchase_order_detail FROM purchase_order_detail
@@ -130,10 +163,10 @@ class PurchaseOrderAset extends MY_Controller {
WHERE PurchaseOrderDetailPurchaseRequestDetailID = PurchaseRequestDetailID WHERE PurchaseOrderDetailPurchaseRequestDetailID = PurchaseRequestDetailID
)"; )";
$sql_data = $sql . " LIMIT ? OFFSET ? "; $sql_data = $sql . " LIMIT ? ";
$que_data = $this->db->query($sql_data, [ $que_data = $this->db->query($sql_data, [
$para['branchcode'], $keyword, $para['supplierID'], $keyword, $keyword, $para['branchID'], $para['supplierID'],
$limit, $offset $limit
]); ]);
if (!$que_data) { if (!$que_data) {
$this->sys_error_db("[Error] get daftar request data"); $this->sys_error_db("[Error] get daftar request data");
@@ -143,7 +176,7 @@ class PurchaseOrderAset extends MY_Controller {
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x"; $sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
$que_total = $this->db->query($sql_total, [ $que_total = $this->db->query($sql_total, [
$para['branchcode'], $keyword, $para['supplierID'] $keyword, $keyword, $para['branchID'], $para['supplierID']
]); ]);
if (!$que_total) { if (!$que_total) {
$this->sys_error_db("[Error] get total request aset"); $this->sys_error_db("[Error] get total request aset");
@@ -188,16 +221,34 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderS_RegionalID, PurchaseOrderS_RegionalID,
PurchaseOrderApprovedManagerUserID AS verifiedby, PurchaseOrderApprovedManagerUserID AS verifiedby,
IFNULL(PurchaseOrderApprovedUserID, 0) AS approvedby, IFNULL(PurchaseOrderApprovedUserID, 0) AS approvedby,
PurchaseOrderAssetContractID, PurchaseOrderAssetContractID AS contractID,
PurchaseOrderAssetContractName AS contractName, PurchaseOrderAssetContractName AS contractName,
PurchaseOrderAssetContractDate AS contractDate,
PurchaseOrderAssetContractStartDate AS contractStart, PurchaseOrderAssetContractStartDate AS contractStart,
PurchaseOrderAssetContractEndDate AS contractEnd, PurchaseOrderAssetContractEndDate AS contractEnd,
IFNULL(attach.AttachmentCount, 0) AS AttachmentCount,
SupplierID, SupplierID,
SupplierName SupplierName,
SupplierDownpaymentID
FROM purchase_order FROM purchase_order
JOIN supplier ON SupplierID = PurchaseOrderSupplierID JOIN supplier ON SupplierID = PurchaseOrderSupplierID
JOIN purchase_order_asset_contract JOIN purchase_order_asset_contract
ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID
LEFT JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
LEFT JOIN (
SELECT
ContractAssetAttachmentPurchaseOrderID,
ContractAssetAttachmentPurchaseOrderAssetContractID,
COUNT(*) AS AttachmentCount
FROM contract_asset_attachment
WHERE ContractAssetAttachmentIsActive = 'Y'
GROUP BY
ContractAssetAttachmentPurchaseOrderID,
ContractAssetAttachmentPurchaseOrderAssetContractID
) attach ON attach.ContractAssetAttachmentPurchaseOrderID = PurchaseOrderID
AND attach.ContractAssetAttachmentPurchaseOrderAssetContractID = PurchaseOrderAssetContractID
WHERE PurchaseOrderIsActive = 'Y' WHERE PurchaseOrderIsActive = 'Y'
AND PurchaseOrderItemCategoryID = '3' AND PurchaseOrderItemCategoryID = '3'
AND PurchaseOrderS_RegionalID = ? AND PurchaseOrderS_RegionalID = ?
@@ -255,14 +306,13 @@ class PurchaseOrderAset extends MY_Controller {
$para = $this->sys_input; $para = $this->sys_input;
$sql = "SELECT $sql = "SELECT
PurchaseOrderAssetAttachmentID AS attach_id, ContractAssetAttachmentID AS attach_id,
PurchaseOrderAssetAttachmentName AS img_url, ContractAssetAttachmentFileName AS img_url,
PurchaseOrderAssetAttachmentCreated AS created ContractAssetAttachmentDate AS created
FROM purchase_order_asset_attachment FROM contract_asset_attachment
WHERE PurchaseOrderAssetAttachmentIsActive = 'Y' WHERE ContractAssetAttachmentIsActive = 'Y'
AND PurchaseOrderAssetAttachmentContractID = ? AND ContractAssetAttachmentPurchaseOrderAssetContractID = ?
AND PurchaseOrderAssetAttachmentPurchaseOrderID = ? AND ContractAssetAttachmentPurchaseOrderID = ?";
AND PurchaseOrderAssetAttachmentType = 'order'";
$que = $this->db->query($sql, [ $que = $this->db->query($sql, [
$para['contractID'], $para['poID'] $para['contractID'], $para['poID']
]); ]);
@@ -361,7 +411,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
@@ -369,7 +419,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
@@ -379,6 +429,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,
@@ -391,11 +443,16 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderAssetContractInstallmentPayAmount AS installmentPayAmount, PurchaseOrderAssetContractInstallmentPayAmount AS installmentPayAmount,
PurchaseOrderAssetContractInstallmentDownPaymentType AS installmentDownPaymentType, PurchaseOrderAssetContractInstallmentDownPaymentType AS installmentDownPaymentType,
PurchaseOrderAssetContractInstallmentDownPayment AS installmentDownPayment, PurchaseOrderAssetContractInstallmentDownPayment AS installmentDownPayment,
PurchaseOrderApprovedManagerUserID AS verifiedby PurchaseOrderApprovedManagerUserID AS verifiedby,
SupplierDownpaymentID
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
LEFT JOIN supplier_downpayment
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
AND SupplierDownpaymentIsActive = 'Y'
WHERE PurchaseOrderIsActive = 'Y' WHERE PurchaseOrderIsActive = 'Y'
AND PurchaseOrderID = ?"; AND PurchaseOrderID = ?";
$que_poasset = $this->db->query($sql_poasset, [$para['poID']]); $que_poasset = $this->db->query($sql_poasset, [$para['poID']]);
@@ -428,6 +485,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']);
@@ -445,8 +503,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']);
@@ -460,6 +521,28 @@ class PurchaseOrderAset extends MY_Controller {
} }
} }
public function getUserApproveLevel() {
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$user = $this->sys_user;
$sql = "SELECT M_UserM_ApproveLevelID FROM m_user
WHERE M_UserIsActive = 'Y' AND M_UserID = ? ";
$que = $this->db->query($sql, [$user['M_UserID']]);
if (!$que) {
$this->sys_error_db("[Error] failed get approval level user");
exit;
}
$data = $que->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$this->sys_error($exc->getMessage());
}
}
## MUTATIONS ## ## MUTATIONS ##
public function createPoAsset() { public function createPoAsset() {
try { try {
@@ -517,6 +600,7 @@ class PurchaseOrderAset extends MY_Controller {
$summary_subtotal = floatval($para['summary']['subtotal']); $summary_subtotal = floatval($para['summary']['subtotal']);
$summary_diskon = floatval($para['summary']['diskon']); $summary_diskon = floatval($para['summary']['diskon']);
$summary_pajak = floatval($para['summary']['pajak']); $summary_pajak = floatval($para['summary']['pajak']);
$summary_downpayment = floatval($para['summary']['downpayment']);
$summary_total = floatval($para['summary']['total']); $summary_total = floatval($para['summary']['total']);
$sql_po = "INSERT INTO purchase_order ( $sql_po = "INSERT INTO purchase_order (
@@ -530,17 +614,20 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderTaxPercentPpn, PurchaseOrderTaxPercentPpn,
PurchaseOrderDiscountPercent, PurchaseOrderDiscountPercent,
PurchaseOrderDiscountAmount, PurchaseOrderDiscountAmount,
PurchaseOrderWarehouseType,
PurchaseOrderWarehouseID,
PurchaseOrderNote, PurchaseOrderNote,
PurchaseOrderSubTotal, PurchaseOrderSubTotal,
PurchaseOrderTaxAmountPpn, PurchaseOrderTaxAmountPpn,
PurchaseOrderGrandTotal, PurchaseOrderGrandTotal,
PurchaseOrderUserID, PurchaseOrderUserID,
PurchaseOrderCreated PurchaseOrderCreated
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())"; ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
$que_po = $this->db->query($sql_po, [ $que_po = $this->db->query($sql_po, [
$numpd, '3', $para['podate'], $para['reference'], $para['supplierID'], $numpd, '3', $para['podate'], $para['reference'], $para['supplierID'],
$user['S_RegionalID'], $taxtype, $taxpercent, $discpercent, $summary_diskon, $user['S_RegionalID'], $taxtype, $taxpercent, $discpercent, $summary_diskon,
$para['catatan'], $summary_subtotal, $summary_pajak, $summary_total, $user['M_UserID'] 'single', $para['gudangID'], $para['catatan'], $summary_subtotal,
$summary_pajak, $summary_total, $user['M_UserID']
]); ]);
if (!$que_po) { if (!$que_po) {
$this->db->trans_rollback(); $this->db->trans_rollback();
@@ -613,15 +700,16 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderDetailQty, PurchaseOrderDetailQty,
PurchaseOrderDetailPrice, PurchaseOrderDetailPrice,
PurchaseOrderDetailTotal, PurchaseOrderDetailTotal,
PurchaseOrderDetailWarehouseID,
PurchaseOrderDetailUserID, PurchaseOrderDetailUserID,
PurchaseOrderDetailCreatedUserID, PurchaseOrderDetailCreatedUserID,
PurchaseOrderDetailCreated PurchaseOrderDetailCreated
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())"; ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
$que_detail = $this->db->query($sql_detail, [ $que_detail = $this->db->query($sql_detail, [
$PurchaseOrderID, $obj['PurchaseSummaryID'], $obj['PurchaseRequestID'], $PurchaseOrderID, $obj['PurchaseSummaryID'], $obj['PurchaseRequestID'],
$obj['PurchaseRequestDetailID'], $obj['PurchaseRequestFlagID'], $obj['PurchaseRequestDetailID'], $obj['PurchaseRequestFlagID'],
$obj['M_ItemID'], $obj['ItemUnitID'], $obj['OriginalQty'], $obj['RequestQty'], $obj['M_ItemID'], $obj['ItemUnitID'], $obj['OriginalQty'], $obj['RequestQty'],
$obj['SupplierPrice'], $total, $user['M_UserID'], $user['M_UserID'] $obj['SupplierPrice'], $total, $para['gudangID'], $user['M_UserID'], $user['M_UserID']
]); ]);
if (!$que_detail) { if (!$que_detail) {
$this->db->trans_rollback(); $this->db->trans_rollback();
@@ -683,6 +771,33 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
# INSERT into table supplier_downpayment #
$sql_dp = "INSERT INTO supplier_downpayment (
SupplierDownpaymentPurchasOrderID,
SupplierDownpaymentSupplierID,
SupplierDownpaymentAmount,
SupplierDownpaymentDate,
SupplierDownpaymentDueDate,
SupplierDownpaymentStatus,
SupplierDownpaymentCreatedUserID,
SupplierDownpaymentLastUpdatedUserID
) VALUES (?,?,?,?,?,?,?,?)";
$que_dp = $this->db->query($sql_dp, [
$PurchaseOrderID,
$para['supplierID'],
$summary_downpayment ?: 0.00,
$para['contractStart'],
$para['contractStart'],
'Draft',
$user['M_UserID'],
$user['M_UserID']
]);
if (!$que_dp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed insert supplier downpayment");
exit;
}
$this->insertLog( $this->insertLog(
$PurchaseOrderID, 'CREATE', $para, '', $PurchaseOrderID, 'CREATE', $para, '',
[], $user['M_UserID'], 'create purchase order asset' [], $user['M_UserID'], 'create purchase order asset'
@@ -724,6 +839,7 @@ class PurchaseOrderAset extends MY_Controller {
$summary_subtotal = floatval($para['summary']['subtotal']); $summary_subtotal = floatval($para['summary']['subtotal']);
$summary_diskon = floatval($para['summary']['diskon']); $summary_diskon = floatval($para['summary']['diskon']);
$summary_pajak = floatval($para['summary']['pajak']); $summary_pajak = floatval($para['summary']['pajak']);
$summary_downpayment = floatval($para['summary']['downpayment']);
$summary_total = floatval($para['summary']['total']); $summary_total = floatval($para['summary']['total']);
# update po header # # update po header #
@@ -736,6 +852,8 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderTaxPercentPpn = ?, PurchaseOrderTaxPercentPpn = ?,
PurchaseOrderDiscountPercent = ?, PurchaseOrderDiscountPercent = ?,
PurchaseOrderDiscountAmount = ?, PurchaseOrderDiscountAmount = ?,
PurchaseOrderWarehouseType = ?,
PurchaseOrderWarehouseID = ?,
PurchaseOrderNote = ?, PurchaseOrderNote = ?,
PurchaseOrderSubTotal = ?, PurchaseOrderSubTotal = ?,
PurchaseOrderTaxAmountPpn = ?, PurchaseOrderTaxAmountPpn = ?,
@@ -745,8 +863,8 @@ class PurchaseOrderAset extends MY_Controller {
AND PurchaseOrderIsActive = 'Y'"; AND PurchaseOrderIsActive = 'Y'";
$que_po = $this->db->query($sql_po, [ $que_po = $this->db->query($sql_po, [
$para['podate'], $para['reference'], $para['supplierID'], $user['S_RegionalID'], $para['podate'], $para['reference'], $para['supplierID'], $user['S_RegionalID'],
$taxtype, $taxpercent, $discpercent, $summary_diskon, $para['catatan'], $taxtype, $taxpercent, $discpercent, $summary_diskon, 'single', $para['gudangID'],
$summary_subtotal, $summary_pajak, $summary_total, $para['PurchaseOrderID'] $para['catatan'], $summary_subtotal, $summary_pajak, $summary_total, $para['PurchaseOrderID']
]); ]);
if (!$que_po) { if (!$que_po) {
$this->db->trans_rollback(); $this->db->trans_rollback();
@@ -790,6 +908,29 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
## UPDATE existing downpayment ##
$sql = "UPDATE supplier_downpayment SET
SupplierDownpaymentAmount = ?,
SupplierDownpaymentDate = ?,
SupplierDownpaymentDueDate = ?,
SupplierDownpaymentStatus = ?,
SupplierDownpaymentLastUpdatedUserID = ?
WHERE SupplierDownpaymentID = ?
AND SupplierDownpaymentIsActive = 'Y'";
$que = $this->db->query($sql, [
$summary_downpayment ?: 0.00,
$para['contractStart'],
$para['contractStart'],
'Draft',
$user['M_UserID'],
$para['SupplierDownpaymentID']
]);
if (!$que) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed update supplier downpayment");
exit;
}
# 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'
@@ -875,15 +1016,16 @@ class PurchaseOrderAset extends MY_Controller {
PurchaseOrderDetailQty, PurchaseOrderDetailQty,
PurchaseOrderDetailPrice, PurchaseOrderDetailPrice,
PurchaseOrderDetailTotal, PurchaseOrderDetailTotal,
PurchaseOrderDetailWarehouseID,
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'],
$obj['M_ItemID'], $obj['ItemUnitID'], $obj['OriginalQty'], $obj['RequestQty'], $obj['M_ItemID'], $obj['ItemUnitID'], $obj['OriginalQty'], $obj['RequestQty'],
$obj['SupplierPrice'], $total, $user['M_UserID'], $user['M_UserID'] $obj['SupplierPrice'], $total, $para['gudangID'], $user['M_UserID'], $user['M_UserID']
]); ]);
if (!$que_detail) { if (!$que_detail) {
$this->db->trans_rollback(); $this->db->trans_rollback();
@@ -1002,6 +1144,34 @@ class PurchaseOrderAset extends MY_Controller {
exit; exit;
} }
$sql_delattac = "UPDATE contract_asset_attachment SET
ContractAssetAttachmentIsActive = 'N'
WHERE ContractAssetAttachmentPurchaseOrderAssetContractID = ?
AND ContractAssetAttachmentPurchaseOrderID = ?";
$que_delattac = $this->db->query($sql_delattac, [
$para['contractID'], $para['poID']
]);
if (!$que_delattac) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed soft delete data attachment");
exit;
}
/* soft delete supplier_downpayment */
$sql_deldp = "UPDATE supplier_downpayment SET
SupplierDownpaymentIsActive = 'N',
SupplierDownpaymentLastUpdatedUserID = ?
WHERE SupplierDownpaymentID = ?
AND SupplierDownpaymentIsActive = 'Y'";
$que_deldp = $this->db->query($sql_deldp, [
$user['M_UserID'], $para['SupplierDownpaymentID']
]);
if (!$que_deldp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed soft delete supplier downpayment");
exit;
}
/* soft delete purchase order */ /* soft delete purchase order */
$sql_delorder = "UPDATE purchase_order SET $sql_delorder = "UPDATE purchase_order SET
PurchaseOrderIsActive = 'N', PurchaseOrderIsActive = 'N',
@@ -1028,7 +1198,6 @@ class PurchaseOrderAset extends MY_Controller {
} }
} }
// upload file
public function uploadAttachment() { public function uploadAttachment() {
try { try {
if (!$this->isLogin) { if (!$this->isLogin) {
@@ -1071,19 +1240,34 @@ class PurchaseOrderAset extends MY_Controller {
$upload_data = $this->upload->data(); $upload_data = $this->upload->data();
$filename = $upload_data['file_name']; $filename = $upload_data['file_name'];
$sql_insert = "INSERT INTO purchase_order_asset_attachment ( $sql_insert = "INSERT INTO contract_asset_attachment (
PurchaseOrderAssetAttachmentContractID, ContractAssetAttachmentPurchaseOrderAssetContractID,
PurchaseOrderAssetAttachmentPurchaseOrderID, ContractAssetAttachmentPurchaseOrderID,
PurchaseOrderAssetAttachmentName, ContractAssetAttachmentFileName,
PurchaseOrderAssetAttachmentType, ContractAssetAttachmentDate,
PurchaseOrderAssetAttachmentCreated ContractAssetAttachmentCreated
) VALUES (?,?,?,?,NOW())"; ) VALUES (?,?,?,?,NOW())";
$que_insert = $this->db->query($sql_insert, [ $que_insert = $this->db->query($sql_insert, [
$para['contractID'], $para['poID'], $filename, 'order' $para['contractID'], $para['poID'],
$filename, $para['contractDate']
]); ]);
if (!$que_insert) { if (!$que_insert) {
$this->db->trans_rollback(); $this->db->trans_rollback();
$this->sys_error_db("[Error] failed insert attachment table purchase order asset attachment"); $this->sys_error_db("[Error] failed insert attachment table contract asset attachment");
exit;
}
$attachmentID = $this->db->insert_id();
$sql_contract = "UPDATE purchase_order_asset_contract SET
PurchaseOrderAssetContractTAssetAttachmentID = ?
WHERE PurchaseOrderAssetContractID = ?
AND PurchaseOrderAssetContractPurchaseOrderID = ?";
$que_contract = $this->db->query($sql_contract, [
$attachmentID, $para['contractID'], $para['poID']
]);
if (!$que_contract) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed update attachmentid into asset contract table");
exit; exit;
} }
} else { } else {
@@ -1168,28 +1352,6 @@ class PurchaseOrderAset extends MY_Controller {
} }
} }
public function getUserApproveLevel() {
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$user = $this->sys_user;
$sql = "SELECT M_UserM_ApproveLevelID FROM m_user
WHERE M_UserIsActive = 'Y' AND M_UserID = ? ";
$que = $this->db->query($sql, [$user['M_UserID']]);
if (!$que) {
$this->sys_error_db("[Error] failed get approval level user");
exit;
}
$data = $que->row_array();
$this->sys_ok($data);
} catch (Exception $exc) {
$this->sys_error($exc->getMessage());
}
}
private function insertLog($poID, $type, $prm, $dataBefore, $dataAfter, $userID, $desc = '') { private function insertLog($poID, $type, $prm, $dataBefore, $dataAfter, $userID, $desc = '') {
$sql = "INSERT INTO acc_one_log.purchase_order_log ( $sql = "INSERT INTO acc_one_log.purchase_order_log (
PurchaseOrderLogPurchaseOrderID, PurchaseOrderLogPurchaseOrderID,

File diff suppressed because it is too large Load Diff

View File

@@ -426,7 +426,7 @@ class ReceiveItemPoV2 extends MY_Controller {
AND ReceiveOrderPoIDate BETWEEN DATE(?) AND DATE(?) AND ReceiveOrderPoIDate BETWEEN DATE(?) AND DATE(?)
AND ReceiveOrderPoS_RegionalID = ? AND ReceiveOrderPoS_RegionalID = ?
AND ReceiveOrderPoM_BranchCode LIKE ? AND ReceiveOrderPoM_BranchCode LIKE ?
AND ReceiveOrderPoID NOT IN ( AND ReceiveOrderPoID IN (
SELECT DISTINCT ReceiveOrderPoDetailReceiveOrderPoID SELECT DISTINCT ReceiveOrderPoDetailReceiveOrderPoID
FROM receive_order_po_detail FROM receive_order_po_detail
JOIN purchase_order ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID JOIN purchase_order ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID

View File

@@ -28,29 +28,66 @@ class Billv2 extends MY_Controller {
$offset = ($params['currentpage'] - 1) * $limit; $offset = ($params['currentpage'] - 1) * $limit;
} }
$sql_base = "SELECT // ── UNION base — invoice branch + downpayment branch ────
SupplierPaymentID, $sql_base = "
SupplierPaymentDate, SELECT
SupplierPaymentNumber, sp.SupplierPaymentID,
SupplierPaymentAmount, sp.SupplierPaymentDate,
SupplierPaymentStatus, sp.SupplierPaymentNumber,
SupplierPaymentIsVerif, sp.SupplierPaymentAmount,
SupplierPaymentIsApproved, sp.SupplierPaymentStatus,
SupplierInvoiceID, sp.SupplierPaymentIsVerif,
SupplierInvoiceNumber, sp.SupplierPaymentIsApproved,
SupplierInvoiceDraftPaymentDate, sp.SupplierPaymentIsActive,
SupplierCode, si.SupplierInvoiceID,
SupplierName si.SupplierInvoiceNumber,
FROM supplier_payment si.SupplierInvoiceDraftPaymentDate,
JOIN supplier_invoice ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID sup.SupplierCode,
sup.SupplierName,
'INVOICE' AS type
FROM supplier_payment sp
JOIN supplier_invoice si
ON si.SupplierInvoiceID = sp.SupplierPaymentSupplierInvoiceID
JOIN supplier sup
ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE sp.SupplierPaymentSupplierInvoiceID > 0
UNION ALL
SELECT
sp.SupplierPaymentID,
sp.SupplierPaymentDate,
sp.SupplierPaymentNumber,
sp.SupplierPaymentAmount,
sp.SupplierPaymentStatus,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsActive,
dp.SupplierDownpaymentID * -1 AS SupplierInvoiceID,
CONCAT('DP-', po.PurchaseOrderNumber) AS SupplierInvoiceNumber,
dp.SupplierDownpaymentDueDate AS SupplierInvoiceDraftPaymentDate,
dp_sup.SupplierCode AS SupplierCode,
dp_sup.SupplierName AS SupplierName,
'DP' AS type
FROM supplier_payment sp
JOIN supplier_downpayment dp
ON dp.SupplierDownpaymentID = sp.SupplierPaymentSupplierDownpaymentID
JOIN supplier dp_sup
ON dp_sup.SupplierID = dp.SupplierDownpaymentSupplierID
JOIN purchase_order po
ON po.PurchaseOrderID = dp.SupplierDownpaymentPurchasOrderID
WHERE sp.SupplierPaymentSupplierDownpaymentID IS NOT NULL";
// ── Outer: common filters + ordering + pagination ───────
$sql_data = "
SELECT * FROM ($sql_base) AS combined
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentNumber LIKE ? AND SupplierPaymentNumber LIKE ?
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?)) AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?))
AND (SupplierPaymentStatus = ? OR ? = 'All') AND (SupplierPaymentStatus = ? OR ? = 'All')
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID ORDER BY SupplierPaymentID DESC
WHERE SupplierPaymentIsActive = 'Y' LIMIT ? OFFSET ?";
ORDER BY SupplierPaymentID DESC";
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
$que_data = $this->db->query($sql_data, [ $que_data = $this->db->query($sql_data, [
$keyword, $params['startdate'], $params['enddate'], $keyword, $params['startdate'], $params['enddate'],
$params['status'], $params['status'], $limit, $offset $params['status'], $params['status'], $limit, $offset
@@ -59,7 +96,14 @@ class Billv2 extends MY_Controller {
throw new Exception("[Error] failed get data supplier payment", 2); throw new Exception("[Error] failed get data supplier payment", 2);
} }
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x"; // ── COUNT — wrap UNION in outer filter ──────────────────
$sql_total = "
SELECT COUNT(*) AS total FROM ($sql_base) AS combined
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentNumber LIKE ?
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?))
AND (SupplierPaymentStatus = ? OR ? = 'All')";
$que_total = $this->db->query($sql_total, [ $que_total = $this->db->query($sql_total, [
$keyword, $params['startdate'], $params['enddate'], $keyword, $params['startdate'], $params['enddate'],
$params['status'], $params['status'] $params['status'], $params['status']
@@ -70,7 +114,7 @@ class Billv2 extends MY_Controller {
$output = [ $output = [
"records" => $que_data->result_array(), "records" => $que_data->result_array(),
"total" =>$que_total->row_array()['total'] "total" => $que_total->row_array()['total']
]; ];
$this->sys_ok($output); $this->sys_ok($output);
@@ -96,28 +140,39 @@ class Billv2 extends MY_Controller {
$para = $this->sys_input; $para = $this->sys_input;
$sql = "SELECT // ── Detect payment type ──────────────────────────────────
SupplierInvoiceID, $sql_type = "SELECT
SupplierInvoiceRefNumber, SupplierPaymentSupplierInvoiceID,
SupplierInvoiceDeliveryOrderNumber, SupplierPaymentSupplierDownpaymentID
SupplierInvoiceSupplierInvoiceNumber,
SupplierInvoiceSupplierInvoiceDate,
SupplierInvoiceSubTotal,
SupplierInvoiceTaxPercentPph,
SupplierInvoiceTaxPercentPpn,
SupplierInvoiceTaxAmountPpn,
SupplierInvoiceDiscountAmount,
SupplierInvoiceDiscountPercent,
SupplierInvoiceShippingCost,
SupplierInvoiceGrandTotal,
SupplierInvoiceAdjustmentAmount,
SupplierInvoiceAdjustmentNote,
SupplierInvoiceNote,
IF (SupplierInvoiceDiscountAmount > 0, 'R', 'P') AS DiscountType
FROM supplier_payment FROM supplier_payment
JOIN supplier_invoice ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID WHERE SupplierPaymentID = ? AND SupplierPaymentIsActive = 'Y'";
AND SupplierPaymentID = ?
AND SupplierPaymentIsActive = 'Y'"; $que_type = $this->db->query($sql_type, [$para['paymentID']]);
if (!$que_type) {
throw new Exception("[Error] failed get payment header", 2);
}
$payment = $que_type->row_array();
if (!$payment) {
throw new Exception("[Error] payment not found", 2);
}
// ── INVOICE branch ──────────────────────────────────────
if ($payment['SupplierPaymentSupplierInvoiceID'] > 0) {
$sql = "SELECT
si.SupplierInvoiceSubTotal,
si.SupplierInvoiceShippingCost,
si.SupplierInvoiceDiscountPercent,
si.SupplierInvoiceDiscountAmount,
si.SupplierInvoiceTaxPercentPpn,
si.SupplierInvoiceTaxAmountPpn,
si.SupplierInvoiceGrandTotal,
si.SupplierInvoiceID,
'INVOICE' AS type
FROM supplier_payment sp
JOIN supplier_invoice si
ON si.SupplierInvoiceID = sp.SupplierPaymentSupplierInvoiceID
WHERE sp.SupplierPaymentID = ? AND sp.SupplierPaymentIsActive = 'Y'";
$que = $this->db->query($sql, [$para['paymentID']]); $que = $this->db->query($sql, [$para['paymentID']]);
if (!$que) { if (!$que) {
throw new Exception("[Error] failed get row data", 2); throw new Exception("[Error] failed get row data", 2);
@@ -125,33 +180,21 @@ class Billv2 extends MY_Controller {
$data = $que->row_array(); $data = $que->row_array();
$sql_detail = "SELECT $sql_detail = "SELECT
SupplierInvoiceDetailID, M_ItemDesc,
SupplierInvoiceDetailSupplierInvoiceID,
SupplierInvoiceDetailPurchaseOrderID,
SupplierInvoiceDetailPurchaseOrderSummaryID,
SupplierInvoiceDetailReceiveOrderPoID,
SupplierInvoiceDetailReceiveOrderPoDetailID,
SupplierInvoiceDetailItemID,
SupplierInvoiceDetailItemUnitID,
SupplierInvoiceDetailDescription,
SupplierInvoiceDetailQty, SupplierInvoiceDetailQty,
SupplierInvoiceDetailPrice, SupplierInvoiceDetailPrice,
SupplierInvoiceDetailDiscountPercent,
SupplierInvoiceDetailDiscountDiscountRupiah,
SupplierInvoiceDetailDiscountDiscountType,
SupplierInvoiceDetailDiscountAmount, SupplierInvoiceDetailDiscountAmount,
(SupplierInvoiceDetailPrice - SupplierInvoiceDetailDiscountAmount) AS DiscountedPrice, (SupplierInvoiceDetailPrice - SupplierInvoiceDetailDiscountAmount) AS DiscountedPrice,
SupplierInvoiceDetailDiscountPoProrata, SupplierInvoiceDetailTotal
SupplierInvoiceDetailTotal,
M_ItemCode,
M_ItemDesc
FROM supplier_payment_detail FROM supplier_payment_detail
JOIN supplier_invoice_detail ON SupplierInvoiceDetailIsActive = 'Y' JOIN supplier_invoice_detail
ON SupplierInvoiceDetailIsActive = 'Y'
AND SupplierPaymentDetailSupplierPaymentID = ? AND SupplierPaymentDetailSupplierPaymentID = ?
AND SupplierInvoiceDetailSupplierInvoiceID = ? AND SupplierInvoiceDetailSupplierInvoiceID = ?
JOIN m_item ON M_ItemID = SupplierInvoiceDetailItemID JOIN m_item
AND M_ItemIsActive = 'Y' ON M_ItemID = SupplierInvoiceDetailItemID AND M_ItemIsActive = 'Y'
GROUP BY SupplierInvoiceDetailID"; GROUP BY SupplierInvoiceDetailID";
$que_detail = $this->db->query($sql_detail, [ $que_detail = $this->db->query($sql_detail, [
$para['paymentID'], $data['SupplierInvoiceID'] $para['paymentID'], $data['SupplierInvoiceID']
]); ]);
@@ -159,8 +202,62 @@ class Billv2 extends MY_Controller {
throw new Exception("[Error] failed to get item payments", 2); throw new Exception("[Error] failed to get item payments", 2);
} }
unset($data['SupplierInvoiceID']);
$data['detail'] = $que_detail->result_array(); $data['detail'] = $que_detail->result_array();
// ── DOWNPAYMENT branch ──────────────────────────────────
} else {
$sql = "SELECT
dp.SupplierDownpaymentPurchasOrderID,
dp.SupplierDownpaymentAmount AS SupplierInvoiceSubTotal,
0 AS SupplierInvoiceShippingCost,
0 AS SupplierInvoiceDiscountPercent,
0 AS SupplierInvoiceDiscountAmount,
0 AS SupplierInvoiceTaxPercentPpn,
0 AS SupplierInvoiceTaxAmountPpn,
dp.SupplierDownpaymentAmount AS SupplierInvoiceGrandTotal,
'DP' AS type
FROM supplier_payment sp
JOIN supplier_downpayment dp
ON dp.SupplierDownpaymentID = sp.SupplierPaymentSupplierDownpaymentID
WHERE sp.SupplierPaymentID = ? AND sp.SupplierPaymentIsActive = 'Y'";
$que = $this->db->query($sql, [$para['paymentID']]);
if (!$que) {
throw new Exception("[Error] failed get DP row data", 2);
}
$data = $que->row_array();
$sql_detail = "SELECT
CONCAT('DP-', M_ItemDesc) AS M_ItemDesc,
PurchaseOrderDetailQty AS SupplierInvoiceDetailQty,
PurchaseOrderDetailPrice AS SupplierInvoiceDetailPrice,
PurchaseOrderSummaryDiscountAmount AS SupplierInvoiceDetailDiscountAmount,
(PurchaseOrderDetailPrice - PurchaseOrderSummaryDiscountAmount) AS DiscountedPrice,
PurchaseOrderSummaryTotal AS SupplierInvoiceDetailTotal
FROM supplier_downpayment
JOIN purchase_order
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderID
JOIN purchase_order_detail
ON PurchaseOrderDetailPurchaseOrderID = PurchaseOrderID
AND PurchaseOrderDetailIsActive = 'Y'
JOIN purchase_order_summary
ON PurchaseOrderSummaryID = PurchaseOrderDetailPurchaseSummaryID
AND PurchaseOrderSummaryIsActive = 'Y'
JOIN m_item
ON M_ItemID = PurchaseOrderDetailItemID
WHERE SupplierDownpaymentPurchasOrderID = ?";
$que_detail = $this->db->query($sql_detail, [
$data['SupplierDownpaymentPurchasOrderID']
]);
if (!$que_detail) {
throw new Exception('failed to get dp detail', 2);
}
$data['detail'] = $que_detail->result_array();
}
$this->sys_ok($data); $this->sys_ok($data);
} catch (Exception $exc) { } catch (Exception $exc) {
$message = $exc->getMessage(); $message = $exc->getMessage();

View File

@@ -12,8 +12,9 @@ class Bill extends MY_Controller
$this->db_onedev = $this->load->database("onedev", true); $this->db_onedev = $this->load->database("onedev", true);
} }
public function add_notes($orderid){ public function add_notes($orderid)
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id, {
$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,
@@ -35,32 +36,93 @@ class Bill extends MY_Controller
CONCAT('Verified by : ',b.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')) as d_verif CONCAT('Verified by : ',b.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')) as d_verif
FROM supplier_payment FROM supplier_payment
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y' JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
LEFT JOIN coa ON SupplierPaymentCoaID = coaID LEFT JOIN coa
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID LEFT JOIN m_user n
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID ON SupplierPaymentUserID = n.M_UserID
LEFT JOIN m_user b ON SupplierPaymentVerifUserID = b.M_UserID LEFT JOIN m_user c
WHERE ON SupplierPaymentConfirmUserID = c.M_UserID
SupplierPaymentSupplierInvoiceID = {$orderid} LEFT JOIN m_user a
AND ON SupplierPaymentApprovedUserID = a.M_UserID
SupplierPaymentIsActive = 'Y' LEFT JOIN m_user b
ON SupplierPaymentVerifUserID = b.M_UserID
WHERE SupplierPaymentSupplierInvoiceID = {$orderid}
AND 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 { } else {
$this->sys_error_db("get notes", $this->db_onedev); $this->sys_error_db("get notes", $this->db_onedev);
exit; exit;
} }
} }
public function add_tagihans($orderid){
public function add_notes_downpayment($orderid)
{
$sql = "SELECT SupplierPaymentSupplierDownpaymentID AS note_order_id,
SupplierPaymentID AS note_id,
SupplierDownpaymentID AS detail_id,
SupplierPaymentDate AS note_date,
SupplierPaymentNumber AS note_number,
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') AS paymenttypes_name,
SUM(SupplierDownpaymentAmount) AS note_amount,
n.M_UserUsername AS note_user,
SupplierDownpaymentIsActive AS note_active,
'N' AS show_detail,
SupplierPaymentNote AS keterangan,
SupplierPaymentCoaID,
coaID,
coaDescription,
SupplierPaymentIsConfirm,
CONCAT(
'Confirmed by : ',c.M_UserUsername, ' ',
DATE_FORMAT(SupplierPaymentConfirmDate, '%d-%m-%Y %H:%i')
) AS d_confirm,
SupplierPaymentIsApproved,
CONCAT(
'Approved by : ',a.M_UserUsername, ' ',
DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')
) AS d_approved,
CONCAT(
'Verified by : ',b.M_UserUsername, ' ',
DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')
) AS d_verif
FROM supplier_payment
JOIN supplier_downpayment
ON SupplierDownpaymentID = SupplierPaymentSupplierDownpaymentID
AND SupplierDownpaymentIsActive = 'Y'
LEFT JOIN coa
ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user n
ON SupplierPaymentUserID = n.M_UserID
LEFT JOIN m_user c
ON SupplierPaymentConfirmUserID = c.M_UserID
LEFT JOIN m_user a
ON SupplierPaymentApprovedUserID = a.M_UserID
LEFT JOIN m_user b
ON SupplierPaymentVerifUserID = b.M_UserID
WHERE SupplierPaymentSupplierDownpaymentID = {$orderid}
AND SupplierPaymentIsActive = 'Y'
GROUP BY SupplierPaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows ?: [];
} else {
$this->sys_error_db("get DP notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid)
{
$sql = "SELECT SupplierInvoiceID as tagihan_id, $sql = "SELECT SupplierInvoiceID as tagihan_id,
PurchaseOrderNumber as tagihan_number, PurchaseOrderNumber as tagihan_number,
jurnalTxDescription as pasien, jurnalTxDescription as pasien,
@@ -73,25 +135,37 @@ class Bill extends MY_Controller
jurnalTxID SupplierInvoiceDetailID, jurnalTxID SupplierInvoiceDetailID,
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
FROM supplier_invoice FROM supplier_invoice
JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID JOIN purchase_order
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563 JOIN jurnal_addon
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceIsActive = 'Y' ON jurnalAddOnValue = SupplierInvoiceNumber
LEFT JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID AND SupplierPaymentDetailIsActive = 'Y' JOIN jurnal_tx
ON jurnalTxJurnalID = jurnalAddOnJurnalID
AND jurnalTxCredit <> 0
AND jurnalTxCoaID <> 563
LEFT JOIN supplier_payment
ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
AND SupplierInvoiceIsActive = 'Y'
LEFT JOIN supplier_payment_detail
ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID
AND SupplierPaymentDetailIsActive = 'Y'
WHERE SupplierInvoiceID = ? WHERE SupplierInvoiceID = ?
GROUP BY jurnalTxID"; GROUP BY jurnalTxID";
$query = $this->db_onedev->query($sql, [$orderid]); $query = $this->db_onedev->query($sql, [$orderid]);
if ($query) { if ($query) {
$rows = $query->result_array(); $rows = $query->result_array();
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 add_tests($orderid){
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id, public function add_tests($orderid)
{
$sql = "SELECT
SupplierPaymentSupplierInvoiceID as note_order_id,
SupplierPaymentID as note_id, SupplierPaymentID as note_id,
SupplierPaymentDate as note_date, SupplierPaymentDate as note_date,
SupplierPaymentNumber as note_number, SupplierPaymentNumber as note_number,
@@ -103,33 +177,37 @@ class Bill extends MY_Controller
SupplierInvoiceDetailTotal, SupplierInvoiceDetailTotal,
SupplierPaymentDetailAmount SupplierPaymentDetailAmount
FROM supplier_payment FROM supplier_payment
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID JOIN supplier_payment_detail
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID LEFT JOIN supplier_invoice_detail
JOIN coa ON SupplierPaymentCoaID = coaID ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID LEFT JOIN purchase_order
WHERE ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
SupplierPaymentID = {$orderid} JOIN coa
ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user
ON SupplierPaymentDetailUserID = M_UserID
WHERE 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()
public function search_old()
{ {
//# cek token valid
if (! $this->isLogin) { if (! $this->isLogin) {
$this->sys_error("Invalid Token"); $this->sys_error("Invalid Token");
exit; exit;
} }
$prm = $this->sys_input; $prm = $this->sys_input;
$supplier = $prm["supplier"]; $supplier = $prm["supplier"];
$search = $prm["search"]; $search = $prm["search"];
@@ -139,117 +217,407 @@ class Bill extends MY_Controller
$regionalid = $this->sys_user['S_RegionalID']; $regionalid = $this->sys_user['S_RegionalID'];
$number_limit = 10; $number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ; $number_offset = ((int)$prm['current_page'] - 1) * $number_limit;
$where = "SupplierInvoiceIsActive = 'Y' // ── WHERE ────────────────────────────────────────────────
AND SupplierPaymentIsApproved = 'Y' $where = " si.SupplierInvoiceIsActive = 'Y'
AND SupplierPaymentIsVerif = 'Y' AND sp.SupplierPaymentIsApproved = 'Y'
AND SupplierPaymentIsConfirm = '{$status}' AND sp.SupplierPaymentIsVerif = 'Y'
AND (SupplierInvoiceNumber LIKE '%{$search}%' OR SupplierInvoiceSupplierInvoiceNumber LIKE '%{$search}%') AND sp.SupplierPaymentIsConfirm = ?
AND SupplierName LIKE '%{$supplier}%' AND (si.SupplierInvoiceNumber LIKE ?
AND ReceiveOrderPoS_RegionalID = {$regionalid} OR si.SupplierInvoiceSupplierInvoiceNumber LIKE ?)
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'"; AND sup.SupplierName LIKE ?
AND rop.ReceiveOrderPoS_RegionalID = ?
AND si.SupplierInvoiceDraftPaymentDate BETWEEN ? AND ? ";
$where_params = [
$status,
'%' . $search . '%',
'%' . $search . '%',
'%' . $supplier . '%',
$regionalid,
$startdate,
$enddate,
];
// ── COUNT ────────────────────────────────────────────────
$sql_count = "
SELECT count(*) as total
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN receive_order_po rop ON rop.ReceiveOrderPoID = si.SupplierInvoiceReceiveOrderPoID
LEFT JOIN supplier_payment sp
ON sp.SupplierPaymentSupplierInvoiceID = si.SupplierInvoiceID
AND sp.SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier sup ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE $where";
$query = $this->db_onedev->query($sql_count, $where_params);
$sql = " SELECT count(*) as total
FROM supplier_invoice
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
WHERE
$where
";
// echo $sql;
$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;
} }
// ── DATA — only columns the frontend actually reads ──────
$sql_data = "
SELECT
si.SupplierInvoiceID,
si.SupplierInvoiceNumber,
si.SupplierInvoiceDraftPaymentDate,
si.SupplierInvoiceIsLunas AS flaglunas,
si.SupplierInvoiceSupplierInvoiceNumber,
DATE_FORMAT(
IFNULL(si.SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y'
) AS tanggalinvoice,
sup.SupplierName,
sp.SupplierPaymentID,
sp.SupplierPaymentIsConfirm,
IFNULL(sp.SupplierPaymentCashierNumber,'') AS SupplierPaymentCashierNumber,
DATE_FORMAT(
si.SupplierInvoiceDraftPaymentDate,'%d-%m-%Y'
) AS tanggalbayar,
0 AS totalbill,
0 AS paid,
0 AS unpaid,
'' AS SupplierPaymentNumber,
0 AS SupplierPaymentAmount,
'' AS SupplierPaymentDate,
'' AS notes,
'' AS tagihans,
0 AS xrounding,
'' AS chex
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN receive_order_po rop ON rop.ReceiveOrderPoID = si.SupplierInvoiceReceiveOrderPoID
LEFT JOIN supplier_payment sp
ON sp.SupplierPaymentSupplierInvoiceID = si.SupplierInvoiceID
AND sp.SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier sup ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE $where
GROUP BY si.SupplierInvoiceID
ORDER BY si.SupplierInvoiceID ASC
LIMIT ? OFFSET ?";
$sql = "SELECT supplier_invoice.*, $data_params = array_merge($where_params, [$number_limit, $number_offset]);
SupplierName, $query = $this->db_onedev->query($sql_data, $data_params);
'' M_MouName,
0 as totalbill,
0 as paid,
0 as unpaid,
SupplierInvoiceIsLunas as flaglunas,
'' as SupplierPaymentNumber,
0 as SupplierPaymentAmount,
'' as SupplierPaymentDate,
'' as SupplierInvoiceIssueRefNumber,
'' as notes,
'' as tagihans,
'N' as isbillterpusat,
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice,
SupplierPaymentID,
SupplierPaymentIsConfirm,
DATE_FORMAT(IFNULL(SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y') as tanggalinvoice,
0 xrounding,
'' chex,
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
FROM supplier_invoice
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
WHERE
$where
GROUP BY SupplierInvoiceID
ORDER BY SupplierInvoiceID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array(); $rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = false;
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill // ── ENRICH ───────────────────────────────────────────────
FROM supplier_invoice if ($rows) {
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber foreach ($rows as $k => $v) {
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563 $rows[$k]['chex'] = false;
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']} $inv_id = $v['SupplierInvoiceID'];
GROUP BY SupplierInvoiceID")->row();
$amount = $s_payment->SupplierPaymentAmount ? $s_payment->SupplierPaymentAmount : "0.00"; $s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
GROUP_CONCAT(
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
SEPARATOR ', '
) as SupplierPaymentDate
FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentSupplierInvoiceID = ?",
[$inv_id]
)->row();
$s_jurnal = $this->db_onedev->query("
SELECT SUM(jurnalTxCredit) totalbill
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN jurnal_tx jt
ON jt.jurnalTxJurnalID = ja.jurnalAddOnJurnalID
AND jt.jurnalTxCredit <> 0
AND jt.jurnalTxCoaID <> 563
WHERE si.SupplierInvoiceID = ?
GROUP BY si.SupplierInvoiceID",
[$inv_id]
)->row();
$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]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber; $rows[$k]['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($inv_id);
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']); $rows[$k]['tagihans'] = $this->add_tagihans($inv_id);
} }
} }
$result = array("total" => $tot_page, "records" => $rows);
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
public function search()
{
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;
$number_offset = ((int)$prm['current_page'] - 1) * $number_limit;
// ── INVOICE branch WHERE ─────────────────────────────────
$inv_where = " si.SupplierInvoiceIsActive = 'Y'
AND rop.ReceiveOrderPoS_RegionalID = ? ";
$inv_params = [$regionalid];
// ── DOWNPAYMENT branch WHERE ─────────────────────────────
$dp_where = " dp.SupplierDownpaymentIsActive = 'Y'
AND po.PurchaseOrderS_RegionalID = ? ";
$dp_params = [$regionalid];
// ── UNION base ───────────────────────────────────────────
$sql_base = "
SELECT
si.SupplierInvoiceID,
si.SupplierInvoiceNumber,
si.SupplierInvoiceDraftPaymentDate,
si.SupplierInvoiceDraftPaymentDate AS filter_date,
si.SupplierInvoiceIsLunas AS flaglunas,
si.SupplierInvoiceSupplierInvoiceNumber,
DATE_FORMAT(
IFNULL(si.SupplierInvoiceSupplierInvoiceDate,''),'%d-%m-%Y'
) AS tanggalinvoice,
sup.SupplierName,
sp.SupplierPaymentID,
sp.SupplierPaymentIsConfirm,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsActive,
IFNULL(sp.SupplierPaymentCashierNumber,'') AS SupplierPaymentCashierNumber,
DATE_FORMAT(
si.SupplierInvoiceDraftPaymentDate,'%d-%m-%Y'
) AS tanggalbayar,
0 AS totalbill,
0 AS paid,
0 AS unpaid,
'' AS SupplierPaymentNumber,
0 AS SupplierPaymentAmount,
'' AS SupplierPaymentDate,
'' AS notes,
'' AS tagihans,
0 AS xrounding,
'' AS chex,
'INVOICE' AS type
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN receive_order_po rop ON rop.ReceiveOrderPoID = si.SupplierInvoiceReceiveOrderPoID
LEFT JOIN supplier_payment sp
ON sp.SupplierPaymentSupplierInvoiceID = si.SupplierInvoiceID
AND sp.SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier sup ON sup.SupplierID = si.SupplierInvoiceSupplierID
WHERE $inv_where
GROUP BY si.SupplierInvoiceID
UNION ALL
SELECT
dp.SupplierDownpaymentID * -1 AS SupplierInvoiceID,
CONCAT('DP-', po.PurchaseOrderNumber) AS SupplierInvoiceNumber,
dp.SupplierDownpaymentDueDate AS SupplierInvoiceDraftPaymentDate,
dp.SupplierDownpaymentDueDate AS filter_date,
dp.SupplierDownpaymentIsLunas AS flaglunas,
'' AS SupplierInvoiceSupplierInvoiceNumber,
DATE_FORMAT(dp.SupplierDownpaymentDate,'%d-%m-%Y') AS tanggalinvoice,
dp_sup.SupplierName AS SupplierName,
sp.SupplierPaymentID,
sp.SupplierPaymentIsConfirm,
sp.SupplierPaymentIsApproved,
sp.SupplierPaymentIsVerif,
sp.SupplierPaymentIsActive,
IFNULL(sp.SupplierPaymentCashierNumber,'') AS SupplierPaymentCashierNumber,
DATE_FORMAT(
dp.SupplierDownpaymentDueDate,'%d-%m-%Y'
) AS tanggalbayar,
dp.SupplierDownpaymentAmount AS totalbill,
CASE WHEN dp.SupplierDownpaymentStatus = 'Paid'
THEN dp.SupplierDownpaymentAmount
ELSE 0 END AS paid,
CASE WHEN dp.SupplierDownpaymentStatus = 'Paid'
THEN 0
ELSE dp.SupplierDownpaymentAmount END AS unpaid,
'' AS SupplierPaymentNumber,
0 AS SupplierPaymentAmount,
'' AS SupplierPaymentDate,
'' AS notes,
'' AS tagihans,
0 AS xrounding,
'' AS chex,
'DP' AS type
FROM supplier_payment sp
JOIN supplier_downpayment dp
ON dp.SupplierDownpaymentID = sp.SupplierPaymentSupplierDownpaymentID
JOIN supplier dp_sup
ON dp_sup.SupplierID = dp.SupplierDownpaymentSupplierID
JOIN purchase_order po
ON po.PurchaseOrderID = dp.SupplierDownpaymentPurchasOrderID
WHERE $dp_where";
// ── Outer common filters ─────────────────────────────────
$outer_where = " SupplierPaymentIsActive = 'Y'
AND SupplierPaymentIsApproved = 'Y'
AND SupplierPaymentIsVerif = 'Y'
AND SupplierPaymentIsConfirm = ?
AND (SupplierInvoiceNumber LIKE ? OR SupplierInvoiceSupplierInvoiceNumber LIKE ?)
AND SupplierName LIKE ?
AND filter_date BETWEEN ? AND ? ";
$outer_params = [
$status,
'%' . $search . '%',
'%' . $search . '%',
'%' . $supplier . '%',
$startdate,
$enddate,
];
// ── COUNT ────────────────────────────────────────────────
$sql_count = "
SELECT COUNT(*) AS total
FROM ($sql_base) AS combined
WHERE $outer_where";
$count_params = array_merge($inv_params, $dp_params, $outer_params);
$query = $this->db_onedev->query($sql_count, $count_params);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("supplier payment count", $this->db_onedev);
exit;
}
// ── DATA ─────────────────────────────────────────────────
$sql_data = "
SELECT * FROM ($sql_base) AS combined
WHERE $outer_where
ORDER BY SupplierInvoiceID ASC
LIMIT ? OFFSET ?";
$data_params = array_merge($inv_params, $dp_params, $outer_params, [$number_limit, $number_offset]);
$query = $this->db_onedev->query($sql_data, $data_params);
$rows = $query->result_array();
// ── ENRICH ───────────────────────────────────────────────
if ($rows) {
foreach ($rows as $k => $v) {
// ── Downpayment branch ──────────────────────────
if ($v['type'] === 'DP') {
$rows[$k]['chex'] = false;
$dp_id = abs($v['SupplierInvoiceID']);
$s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
GROUP_CONCAT(
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
SEPARATOR ', '
) as SupplierPaymentDate
FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentSupplierDownpaymentID = ?",
[$dp_id]
)->row();
$amount = $s_payment->SupplierPaymentAmount
? $s_payment->SupplierPaymentAmount
: "0.00";
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber;
$rows[$k]['SupplierPaymentAmount'] = $amount;
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
$rows[$k]['paid'] = $amount;
$rows[$k]['notes'] = $this->add_notes_downpayment($dp_id);
$rows[$k]['tagihans'] = [];
continue;
}
// ── Invoice branch ──────────────────────────────
$rows[$k]['chex'] = false;
$inv_id = $v['SupplierInvoiceID'];
$s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
GROUP_CONCAT(
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
SEPARATOR ', '
) as SupplierPaymentDate
FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentSupplierInvoiceID = ?",
[$inv_id]
)->row();
$s_jurnal = $this->db_onedev->query("
SELECT SUM(jurnalTxCredit) totalbill
FROM supplier_invoice si
JOIN jurnal_addon ja ON ja.jurnalAddOnValue = si.SupplierInvoiceNumber
JOIN jurnal_tx jt
ON jt.jurnalTxJurnalID = ja.jurnalAddOnJurnalID
AND jt.jurnalTxCredit <> 0
AND jt.jurnalTxCoaID <> 563
WHERE si.SupplierInvoiceID = ?
GROUP BY si.SupplierInvoiceID",
[$inv_id]
)->row();
$amount = $s_payment->SupplierPaymentAmount
? $s_payment->SupplierPaymentAmount
: "0.00";
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber;
$rows[$k]['SupplierPaymentAmount'] = $amount;
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
$rows[$k]['paid'] = $amount;
$rows[$k]['totalbill'] = $s_jurnal->totalbill
? $s_jurnal->totalbill
: "0.00";
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
$rows[$k]['notes'] = $this->add_notes($inv_id);
$rows[$k]['tagihans'] = $this->add_tagihans($inv_id);
}
}
$result = array("total" => $tot_page, "records" => $rows);
$this->sys_ok($result);
exit;
}
} }

View File

@@ -70,6 +70,19 @@ class PaymentV2 extends MY_Controller
} }
# UPDATE status lunas supplier invoice # # UPDATE status lunas supplier invoice #
if ($param['type'] == 'DP') {
$sql_updatedp = "UPDATE supplier_downpayment
SET SupplierDownpaymentIsLunas = 'Y'
WHERE SupplierDownpaymentID = ?";
$que_updatedp = $this->db->query($sql_updatedp, [
abs($param['SupplierInvoiceID'])
]);
if (!$que_updatedp) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] update status lunas downpayment");
exit;
}
} else {
$sql_suppinvoice = "UPDATE supplier_invoice $sql_suppinvoice = "UPDATE supplier_invoice
SET SupplierInvoiceIsLunas = 'Y' SET SupplierInvoiceIsLunas = 'Y'
WHERE SupplierInvoiceID = ?"; WHERE SupplierInvoiceID = ?";
@@ -79,6 +92,7 @@ class PaymentV2 extends MY_Controller
$this->sys_error_db("[Error] update status lunas invoice"); $this->sys_error_db("[Error] update status lunas invoice");
exit; exit;
} }
}
# GET Latest data supplier payment # # GET Latest data supplier payment #
$sql_suppayment = "SELECT * FROM supplier_payment WHERE SupplierPaymentID = ?"; $sql_suppayment = "SELECT * FROM supplier_payment WHERE SupplierPaymentID = ?";
@@ -89,7 +103,23 @@ class PaymentV2 extends MY_Controller
exit; exit;
} }
$suppayment_header = $que_suppayment->row_array(); $suppayment_header = $que_suppayment->row_array();
$suppayment_detail = [];
if ($param['type'] == 'DP') {
$sql_suppaymentdetail = "SELECT supplier_downpayment.*
FROM supplier_payment
JOIN supplier_downpayment
ON SupplierPaymentSupplierDownpaymentID = SupplierDownpaymentID
AND SupplierDownpaymentIsActive = 'Y'
WHERE SupplierPaymentID = ?";
$que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]);
if (!$que_suppaymentdetail) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] get data latest supplier downpayment");
exit;
}
$suppayment_detail = $que_suppaymentdetail->result_array();
} else {
$sql_suppaymentdetail = "SELECT * FROM supplier_payment_detail $sql_suppaymentdetail = "SELECT * FROM supplier_payment_detail
WHERE SupplierPaymentDetailSupplierPaymentID = ?"; WHERE SupplierPaymentDetailSupplierPaymentID = ?";
$que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]); $que_suppaymentdetail = $this->db->query($sql_suppaymentdetail, [$param['orderid']]);
@@ -99,6 +129,7 @@ class PaymentV2 extends MY_Controller
exit; exit;
} }
$suppayment_detail = $que_suppaymentdetail->result_array(); $suppayment_detail = $que_suppaymentdetail->result_array();
}
$data_log = [ $data_log = [
"header" => $suppayment_header, "header" => $suppayment_header,
@@ -121,6 +152,52 @@ class PaymentV2 extends MY_Controller
# INSERT JURNAL # # INSERT JURNAL #
$detail_transac = []; $detail_transac = [];
if ($param['type'] == "DP") {
$sql_coaDP = "SELECT
coaID,
coaDescription,
SupplierDownpaymentAmount,
M_ItemID,
SupplierPaymentNumber,
M_ItemID
FROM supplier_payment
JOIN supplier_downpayment
ON SupplierDownpaymentID = SupplierPaymentSupplierDownpaymentID
AND SupplierDownpaymentIsActive = 'Y'
JOIN purchase_order_detail
ON SupplierDownpaymentPurchasOrderID = PurchaseOrderDetailPurchaseOrderID
AND PurchaseOrderDetailIsActive = 'Y'
JOIN m_item
ON M_ItemID = PurchaseOrderDetailItemID
AND M_ItemIsActive = 'Y'
JOIN fa_class
ON Fa_ClassID = M_ItemFa_ClassID
AND M_ItemIsActive = 'Y'
JOIN coa
ON coaID = Fa_ClassDownPaymentCoaID
AND coaIsActive = 'Y'
WHERE SupplierPaymentID = ?";
$que_coaDP = $this->db->query($sql_coaDP, [
$param['orderid']
]);
if (!$que_coaDP) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] get data hutang item");
exit;
}
$data_dp = $que_coaDP->result_array();
foreach ($data_dp as $key => $dp) {
$detail_transac[] = [
"coaID" => $dp['coaID'],
"coaDescription" => $dp['coaDescription'],
"debit" => $dp['SupplierDownpaymentAmount'],
"credit" => 0,
"addoncode" => "DP-JFA",
"addonvalue" => $dp['SupplierPaymentNumber'],
"addonitemid" => $dp['M_ItemID']
];
}
} else {
# GET data hutang # # GET data hutang #
$sql_datahutang = "SELECT $sql_datahutang = "SELECT
SupplierPaymentNumber AS addonvalue, SupplierPaymentNumber AS addonvalue,
@@ -154,6 +231,7 @@ class PaymentV2 extends MY_Controller
"addonitemid" => $debt['SupplierInvoiceDetailItemID'] "addonitemid" => $debt['SupplierInvoiceDetailItemID']
]; ];
} }
}
# GET data bayar # # GET data bayar #
$sql_databayar = "SELECT $sql_databayar = "SELECT

View File

@@ -6,14 +6,16 @@ class Bill extends MY_Controller
{ {
echo "Bill API"; echo "Bill API";
} }
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->db_onedev = $this->load->database("onedev", true); $this->db_onedev = $this->load->database("onedev", true);
} }
public function add_notes($orderid){ public function add_notes($orderid)
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id, {
$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,
@@ -48,19 +50,72 @@ class Bill extends MY_Controller
$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 { } else {
$this->sys_error_db("get notes", $this->db_onedev); $this->sys_error_db("get notes", $this->db_onedev);
exit; exit;
} }
} }
public function add_tagihans($orderid){
public function add_notes_downpayment($orderid)
{
$sql = "SELECT SupplierPaymentSupplierDownpaymentID AS note_order_id,
SupplierPaymentID AS note_id,
SupplierDownpaymentID AS detail_id,
SupplierPaymentDate AS note_date,
SupplierPaymentNumber AS note_number,
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') AS paymenttypes_name,
SUM(SupplierDownpaymentAmount) AS note_amount,
n.M_UserUsername AS note_user,
SupplierDownpaymentIsActive AS note_active,
'N' AS show_detail,
SupplierPaymentNote AS keterangan,
SupplierPaymentCoaID,
coaID,
coaDescription,
SupplierPaymentIsConfirm,
CONCAT(
'Confirmed by : ',c.M_UserUsername, ' ',
DATE_FORMAT(SupplierPaymentConfirmDate, '%d-%m-%Y %H:%i')
) AS d_confirm,
SupplierPaymentIsApproved,
CONCAT(
'Approved by : ',a.M_UserUsername, ' ',
DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')
) AS d_approved,
CONCAT(
'Verified by : ',b.M_UserUsername, ' ',
DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')
) AS d_verif
FROM supplier_payment
JOIN supplier_downpayment
ON SupplierDownpaymentID = SupplierPaymentSupplierDownpaymentID
AND SupplierDownpaymentIsActive = 'Y'
LEFT JOIN coa ON SupplierPaymentCoaID = coaID
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID
LEFT JOIN m_user b ON SupplierPaymentVerifUserID = b.M_UserID
WHERE SupplierPaymentSupplierDownpaymentID = {$orderid}
AND SupplierPaymentIsActive = 'Y'
GROUP BY SupplierPaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows ?: [];
} else {
$this->sys_error_db("get DP notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid)
{
$sql = "SELECT SupplierInvoiceID as tagihan_id, $sql = "SELECT SupplierInvoiceID as tagihan_id,
PurchaseOrderNumber as tagihan_number, PurchaseOrderNumber as tagihan_number,
jurnalTxDescription as pasien, jurnalTxDescription as pasien,
@@ -89,13 +144,14 @@ class Bill extends MY_Controller
if ($query) { if ($query) {
$rows = $query->result_array(); $rows = $query->result_array();
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 add_tests($orderid){
public function add_tests($orderid)
{
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id, $sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
SupplierPaymentID as note_id, SupplierPaymentID as note_id,
SupplierPaymentDate as note_date, SupplierPaymentDate as note_date,
@@ -119,22 +175,23 @@ class Bill extends MY_Controller
$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()
public function search_old()
{ {
//# cek token valid //# cek token valid
if (! $this->isLogin) { if (! $this->isLogin) {
$this->sys_error("Invalid Token"); $this->sys_error("Invalid Token");
exit; exit;
} }
$prm = $this->sys_input; $prm = $this->sys_input;
$supplier = $prm["supplier"]; $supplier = $prm["supplier"];
$search = $prm["search"]; $search = $prm["search"];
@@ -144,7 +201,7 @@ class Bill extends MY_Controller
$regionalid = $this->sys_user['S_RegionalID']; $regionalid = $this->sys_user['S_RegionalID'];
$number_limit = 10; $number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ; $number_offset = ($prm['current_page'] - 1) * $number_limit;
$where = "SupplierInvoiceIsActive = 'Y' $where = "SupplierInvoiceIsActive = 'Y'
AND SupplierInvoiceStatus = 'Approved' AND SupplierInvoiceStatus = 'Approved'
@@ -174,7 +231,7 @@ class Bill extends MY_Controller
$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;
@@ -216,8 +273,8 @@ class Bill extends MY_Controller
//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,
@@ -243,15 +300,278 @@ class Bill extends MY_Controller
$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()); $result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query());
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
/**
* search — unified invoice + downpayment list:
* - Only columns the frontend actually reads (no wildcard, no dead aliases)
* - UNION ALL merges supplier_invoice and supplier_downpayment
* - DP rows enriched via SupplierPaymentSupplierDownpaymentID FK
* - All queries use PDO parameterised placeholders
*/
public function search()
{
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;
$number_offset = ((int)$prm['current_page'] - 1) * $number_limit;
// ── INVOICE WHERE ──────────────────────────────────────────
$inv_where = " SupplierInvoiceIsActive = 'Y'
AND SupplierInvoiceStatus = 'Approved'
AND SupplierInvoiceGrandTotal > 0
AND SupplierInvoiceIsInstallment = 'N'
AND IF(SupplierPaymentID IS NULL,'N','Y') = ?
AND SupplierInvoiceNumber LIKE ?
AND SupplierName LIKE ?
AND ReceiveOrderPoS_RegionalID = ?
AND SupplierInvoiceDraftPaymentDate BETWEEN ? AND ? ";
$inv_params = [
$status,
'%' . $search . '%',
'%' . $supplier . '%',
$regionalid,
$startdate,
$enddate,
];
// ── DOWNPAYMENT WHERE ──────────────────────────────────────
$dp_where = " SupplierDownpaymentIsActive = 'Y'
AND IF(SupplierDownpaymentStatus = 'Paid','Y','N') = ?
AND PurchaseOrderNumber LIKE ?
AND SupplierName LIKE ?
AND PurchaseOrderS_RegionalID = ?
AND SupplierDownpaymentDueDate BETWEEN ? AND ? ";
$dp_params = [
$status,
'%' . $search . '%',
'%' . $supplier . '%',
$regionalid,
$startdate,
$enddate,
];
// ── COUNT query — UNION of both sources ────────────────────
$sql_count = "SELECT SUM(cnt) as total FROM (
SELECT count(*) as cnt
FROM supplier_invoice
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
LEFT JOIN supplier_payment
ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID
AND SupplierPaymentIsActive = 'Y'
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
WHERE $inv_where
UNION ALL
SELECT count(*) as cnt
FROM supplier_downpayment
JOIN purchase_order ON PurchaseOrderID = SupplierDownpaymentPurchasOrderID
JOIN supplier ON SupplierID = SupplierDownpaymentSupplierID
WHERE $dp_where
) AS combined";
$count_params = array_merge($inv_params, $dp_params);
$query = $this->db_onedev->query($sql_count, $count_params);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("payment instructions count", $this->db_onedev);
exit;
}
// ── DATA query — UNION with identical columns ──────────────
$sql_data = "
SELECT * FROM (
SELECT
SupplierInvoiceID,
SupplierInvoiceNumber,
SupplierInvoiceDraftPaymentDate,
SupplierInvoiceIsLunas as flaglunas,
SupplierName,
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved,
IFNULL(SupplierPaymentCashierNumber,'') as SupplierPaymentCashierNumber,
0 as totalbill,
0 as paid,
0 as unpaid,
0 as SupplierPaymentID,
'' as SupplierPaymentNumber,
0 as SupplierPaymentAmount,
'' as SupplierPaymentDate,
'' as notes,
'' as tagihans,
'INVOICE' as type
FROM supplier_invoice
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
LEFT JOIN supplier_payment
ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
AND SupplierPaymentIsActive = 'Y'
WHERE $inv_where
GROUP BY SupplierInvoiceID
UNION ALL
SELECT
SupplierDownpaymentID * -1 as SupplierInvoiceID,
CONCAT('DP-', PurchaseOrderNumber) as SupplierInvoiceNumber,
SupplierDownpaymentDueDate as SupplierInvoiceDraftPaymentDate,
SupplierDownpaymentIsLunas as flaglunas,
SupplierName,
DATE_FORMAT(SupplierDownpaymentDueDate,'%d-%m-%Y') as tanggalbayar,
'N' as SupplierPaymentIsApproved,
'' as SupplierPaymentCashierNumber,
SupplierDownpaymentAmount as totalbill,
CASE WHEN SupplierDownpaymentStatus = 'Paid'
THEN SupplierDownpaymentAmount
ELSE 0 END as paid,
CASE WHEN SupplierDownpaymentStatus = 'Paid'
THEN 0
ELSE SupplierDownpaymentAmount END as unpaid,
0 as SupplierPaymentID,
'' as SupplierPaymentNumber,
0 as SupplierPaymentAmount,
'' as SupplierPaymentDate,
'' as notes,
'' as tagihans,
'DP' as type
FROM supplier_downpayment
JOIN purchase_order ON PurchaseOrderID = SupplierDownpaymentPurchasOrderID
JOIN supplier ON SupplierID = SupplierDownpaymentSupplierID
WHERE $dp_where
) AS combined
ORDER BY SupplierInvoiceID ASC
LIMIT ? OFFSET ?";
$data_params = array_merge($inv_params, $dp_params, [$number_limit, $number_offset]);
$query = $this->db_onedev->query($sql_data, $data_params);
$rows = $query->result_array();
// ── ENRICH — per-row sub-queries ───────────────────────────
if ($rows) {
foreach ($rows as $k => $v) {
// ── Downpayment branch ──────────────────────────
if ($v['type'] === 'DP') {
$dp_id = abs($v['SupplierInvoiceID']);
$s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
IFNULL(SupplierPaymentID,0) as SupplierPaymentID,
GROUP_CONCAT(
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
SEPARATOR ', '
) as SupplierPaymentDate
FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentSupplierDownpaymentID = ?",
[$dp_id]
)->row();
$amount = $s_payment->SupplierPaymentAmount
? $s_payment->SupplierPaymentAmount
: "0.00";
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID
? $s_payment->SupplierPaymentID
: '0';
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber
? $s_payment->SupplierPaymentNumber
: '';
$rows[$k]['SupplierPaymentAmount'] = $amount;
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
$rows[$k]['paid'] = $amount;
$rows[$k]['notes'] = $this->add_notes_downpayment($dp_id);
$rows[$k]['tagihans'] = [];
// totalbill, unpaid already correct from UNION CASE
continue;
}
// ── Invoice branch ───────────────────────────────
$inv_id = $v['SupplierInvoiceID'];
$s_payment = $this->db_onedev->query("
SELECT
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
IFNULL(SupplierPaymentID,0) as SupplierPaymentID,
GROUP_CONCAT(
DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y')
SEPARATOR ', '
) as SupplierPaymentDate
FROM supplier_payment
WHERE SupplierPaymentIsActive = 'Y'
AND SupplierPaymentSupplierInvoiceID = ?",
[$inv_id]
)->row();
$s_jurnal = $this->db_onedev->query("
SELECT SUM(jurnalTxCredit) totalbill
FROM supplier_invoice
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
JOIN jurnal_tx
ON jurnalTxJurnalID = jurnalAddOnJurnalID
AND jurnalTxCredit <> 0
AND jurnalTxCoaID <> 563
WHERE SupplierInvoiceID = ?
GROUP BY SupplierInvoiceID",
[$inv_id]
)->row();
$amount = $s_payment->SupplierPaymentAmount
? $s_payment->SupplierPaymentAmount
: "0.00";
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID
? $s_payment->SupplierPaymentID
: '0';
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber
? $s_payment->SupplierPaymentNumber
: '';
$rows[$k]['SupplierPaymentAmount'] = $amount;
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
$rows[$k]['paid'] = $amount;
$rows[$k]['totalbill'] = $s_jurnal->totalbill
? $s_jurnal->totalbill
: "0.00";
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
$rows[$k]['notes'] = $this->add_notes($inv_id);
$rows[$k]['tagihans'] = $this->add_tagihans($inv_id);
}
}
$result = array("total" => $tot_page, "records" => $rows);
$this->sys_ok($result);
exit;
}
} }

View File

@@ -39,24 +39,31 @@ class Payment extends MY_Controller
0 as leftvalue, 0 as leftvalue,
0 as rightvalue 0 as rightvalue
FROM m_paymenttype WHERE coaIsActive = 'Y'"; FROM m_paymenttype WHERE coaIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array(); $que = $this->db_onedev->query($query);
foreach($rows as $k => $v){ if (!$que) {
$rows[$k]['selected_card'] = array('id'=>0,'name'=>''); $this->sys_error_db("failed to query tipe");
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>''); exit;
$rows[$k]['selected_account'] = array('id'=>0,'name'=>''); }
if($v['chex'] == 'N') $rows = $que->result_array();
foreach ($rows as $k => $v) {
$rows[$k]['selected_card'] = array('id' => 0, 'name' => '');
$rows[$k]['selected_edc'] = array('id' => 0, 'name' => '');
$rows[$k]['selected_account'] = array('id' => 0, 'name' => '');
if ($v['chex'] == 'N')
$rows[$k]['chex'] = false; $rows[$k]['chex'] = false;
else else
$rows[$k]['chex'] = true; $rows[$k]['chex'] = true;
} }
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
function selectpaymenttypeold(){
function selectpaymenttypeold()
{
try { try {
//# cek token valid //# cek token valid
@@ -65,7 +72,7 @@ class Payment extends MY_Controller
exit; exit;
} }
$rows = []; $rows = [];
$query ="SELECT * FROM m_paymenttype $query = "SELECT * FROM m_paymenttype
WHERE WHERE
coaIsActive = 'Y'"; coaIsActive = 'Y'";
//echo $query; //echo $query;
@@ -73,19 +80,18 @@ class Payment extends MY_Controller
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
} catch (Exception $exc) {
} catch(Exception $exc) {
$message = $exc->getMessage(); $message = $exc->getMessage();
$this->sys_error($message); $this->sys_error($message);
} }
} }
function selectpaymenttype(){
function selectpaymenttype()
{
try { try {
//# cek token valid //# cek token valid
@@ -97,7 +103,7 @@ class Payment extends MY_Controller
$regionalid = $this->sys_user['S_RegionalID']; $regionalid = $this->sys_user['S_RegionalID'];
$prm = $this->sys_input; $prm = $this->sys_input;
$search = $prm["search"]; $search = $prm["search"];
$query ="SELECT coaID, $query = "SELECT coaID,
coaAccountNo, coaAccountNo,
coaDescription, coaDescription,
coaSubDescription coaSubDescription
@@ -130,19 +136,18 @@ ORDER BY coaAccountNo ASC";
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
} catch (Exception $exc) {
} catch(Exception $exc) {
$message = $exc->getMessage(); $message = $exc->getMessage();
$this->sys_error($message); $this->sys_error($message);
} }
} }
function selectbank(){
function selectbank()
{
try { try {
//# cek token valid //# cek token valid
@@ -151,30 +156,34 @@ ORDER BY coaAccountNo ASC";
exit; exit;
} }
$rows = []; $rows = [];
$query =" SELECT * $query = " SELECT *
FROM nat_bank FROM nat_bank
WHERE WHERE
Nat_BankIsActive = 'Y' Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC ORDER BY Nat_BankCode DESC
"; ";
//echo $query; //echo $query;
$rows['banks'] = $this->db_onedev->query($query)->result_array(); $que = $this->db_onedev->query($query);
if (!$que) {
$this->sys_error_db("failed");
exit;
}
$rows['banks'] = $que->result_array();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
} catch (Exception $exc) {
} catch(Exception $exc) {
$message = $exc->getMessage(); $message = $exc->getMessage();
$this->sys_error($message); $this->sys_error($message);
} }
} }
function selectaccount(){
function selectaccount()
{
try { try {
//# cek token valid //# cek token valid
@@ -183,29 +192,32 @@ ORDER BY coaAccountNo ASC";
exit; exit;
} }
$rows = []; $rows = [];
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName $query = " SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
FROM m_bank_account FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE WHERE
M_BankAccountIsActive = 'Y' M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC"; ORDER BY Nat_BankCode DESC";
//echo $query; //echo $query;
$rows['accounts'] = $this->db_onedev->query($query)->result_array(); $que = $this->db_onedev->query($query);
if (!$que) {
$this->sys_error_db("failed");
exit;
}
$rows['accounts'] = $que->result_array();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
} catch (Exception $exc) {
} catch(Exception $exc) {
$message = $exc->getMessage(); $message = $exc->getMessage();
$this->sys_error($message); $this->sys_error($message);
} }
} }
function lookup_banks() function lookup_banks()
{ {
//# cek token valid //# cek token valid
@@ -218,10 +230,15 @@ ORDER BY coaAccountNo ASC";
WHERE WHERE
Nat_BankIsActive = 'Y' Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC"; ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array(); $que = $this->db_onedev->query($query);
if (!$que) {
$this->sys_error_db("failed to query tipe");
exit;
}
$rows = $que->result_array();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
@@ -241,19 +258,22 @@ ORDER BY coaAccountNo ASC";
WHERE WHERE
M_BankAccountIsActive = 'Y' M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC"; ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array(); $que = $this->db_onedev->query($query);
if (!$que) {
$this->sys_error_db("failed to query tipe");
exit;
}
$rows = $que->result_array();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => $rows, "records" => $rows,
); );
$this->sys_ok($result); $this->sys_ok($result);
exit;
} }
function searchcard()
{
function searchcard(){
if (! $this->isLogin) { if (! $this->isLogin) {
$this->sys_error("Invalid Token"); $this->sys_error("Invalid Token");
exit; exit;
@@ -261,19 +281,18 @@ ORDER BY coaAccountNo ASC";
$prm = $this->sys_input; $prm = $this->sys_input;
$max_rst = 12; $max_rst = 12;
$tot_count =0; $tot_count = 0;
$q = [ $q = [
'search' => '%' 'search' => '%'
]; ];
if ($prm['search'] != '') if ($prm['search'] != '') {
{
$q['search'] = "%{$prm['search']}%"; $q['search'] = "%{$prm['search']}%";
} }
// QUERY TOTAL // QUERY TOTAL
if($prm['search'] != ''){ if ($prm['search'] != '') {
$sql = " $sql = "
SELECT count(*) as total SELECT count(*) as total
FROM nat_bank FROM nat_bank
@@ -282,8 +301,7 @@ ORDER BY coaAccountNo ASC";
AND Nat_BankIsActive = 'Y' AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC ORDER BY Nat_BankName DESC
"; ";
} } else {
else{
$sql = " $sql = "
SELECT count(*) as total SELECT count(*) as total
FROM nat_bank FROM nat_bank
@@ -292,16 +310,15 @@ ORDER BY coaAccountNo ASC";
ORDER BY Nat_BankName DESC ORDER BY Nat_BankName DESC
"; ";
} }
$query = $this->db_onedev->query($sql,$q['search']); $query = $this->db_onedev->query($sql, $q['search']);
//echo $query; //echo $query;
if ($query) { if ($query) {
$tot_count = $query->result_array()[0]["total"]; $tot_count = $query->result_array()[0]["total"];
} } else {
else { $this->sys_error_db("m_city count", $this->db_onedev);
$this->sys_error_db("m_city count",$this->db_onedev);
exit; exit;
} }
if($prm['search'] != ''){ if ($prm['search'] != '') {
$sql = " $sql = "
SELECT Nat_BankID as id, Nat_BankName as name SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank FROM nat_bank
@@ -310,8 +327,7 @@ ORDER BY coaAccountNo ASC";
AND Nat_BankIsActive = 'Y' AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC ORDER BY Nat_BankName DESC
"; ";
} } else {
else{
$sql = " $sql = "
SELECT Nat_BankID as id, Nat_BankName as name SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank FROM nat_bank
@@ -328,14 +344,12 @@ ORDER BY coaAccountNo ASC";
//echo $this->db_onedev->last_query(); //echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result); $this->sys_ok($result);
} } else {
else { $this->sys_error_db("m_city rows", $this->db_onedev);
$this->sys_error_db("m_city rows",$this->db_onedev);
exit; exit;
} }
} }
function pay() function pay()
{ {
//# cek token valid //# cek token valid
@@ -353,9 +367,11 @@ ORDER BY coaAccountNo ASC";
$sql = "INSERT INTO supplier_payment $sql = "INSERT INTO supplier_payment
(SupplierPaymentSupplierInvoiceID,SupplierPaymentDate,SupplierPaymentCreated,SupplierPaymentUserID) (SupplierPaymentSupplierInvoiceID,SupplierPaymentDate,SupplierPaymentCreated,SupplierPaymentUserID)
VALUES (?,CURDATE(),NOW(),?)"; VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql, $query = $this->db_onedev->query(
$sql,
array( array(
$orderid, $xuserid $orderid,
$xuserid
) )
); );
@@ -366,44 +382,41 @@ ORDER BY coaAccountNo ASC";
$headerid = $this->db_onedev->insert_id(); $headerid = $this->db_onedev->insert_id();
//echo $headerid; //echo $headerid;
foreach($payments as $k => $v){ foreach ($payments as $k => $v) {
if($v['chex']){ if ($v['chex']) {
$actual = 0; $actual = 0;
$change = 0; $change = 0;
$amount = $v['leftvalue']; $amount = $v['leftvalue'];
if($v['code'] == 'CASH'){ if ($v['code'] == 'CASH') {
$actual = $v['leftvalue']; $actual = $v['leftvalue'];
$change = $v['rightvalue']; $change = $v['rightvalue'];
if($actual > 0){ if ($actual > 0) {
$amount = intval($v['leftvalue']) - intval($v['rightvalue']); $amount = intval($v['leftvalue']) - intval($v['rightvalue']);
} } else {
else{
$amount = $actual; $amount = $actual;
} }
$sql = "CALL `sp_bill_payment_add_cash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")"; $sql = "CALL `sp_bill_payment_add_cash`(" . $orderid . "," . $amount . "," . $amount . "," . $headerid . "," . $v['id'] . "," . $xuserid . ")";
$query = $this->db_onedev->query($sql); $query = $this->db_onedev->query($sql);
if (!$query) { if (!$query) {
$this->sys_error_db("supplier_payment_detail cash insert"); $this->sys_error_db("supplier_payment_detail cash insert");
exit; exit;
} }
} else {
} if (intval($v['leftvalue']) > 0) {
else{
if(intval($v['leftvalue']) > 0){
$actual = 0; $actual = 0;
$change = 0; $change = 0;
$amount = $v['leftvalue']; $amount = $v['leftvalue'];
$selected_card = 0; $selected_card = 0;
$selected_edc = 0; $selected_edc = 0;
$selected_account = 0; $selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){ if ($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER') {
$selected_card = $v['selected_card']['id']; $selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id']; $selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id']; $selected_account = $v['selected_account']['id'];
} }
$sql = "CALL `sp_bill_payment_add_noncash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")"; $sql = "CALL `sp_bill_payment_add_noncash`(" . $orderid . "," . $amount . "," . $amount . "," . $headerid . "," . $v['id'] . "," . $xuserid . "," . $selected_card . "," . $selected_edc . "," . $selected_account . ")";
//echo $sql; //echo $sql;
$query = $this->db_onedev->query($sql); $query = $this->db_onedev->query($sql);
@@ -434,20 +447,120 @@ ORDER BY coaAccountNo ASC";
FROM m_paymenttype WHERE coaIsActive = 'Y'"; FROM m_paymenttype WHERE coaIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array(); $rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){ foreach ($rows as $k => $v) {
if($v['chex'] == 'N') if ($v['chex'] == 'N')
$rows[$k]['chex'] = false; $rows[$k]['chex'] = false;
else else
$rows[$k]['chex'] = true; $rows[$k]['chex'] = true;
} }
$xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row(); $xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => array('types'=>$rows,'data'=>$xdata) "records" => array('types' => $rows, 'data' => $xdata)
); );
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
function payDownpayment()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$supllierDPID = abs($prm['orderid']); // SupplierDownpaymentID sent as orderid
$this->db_onedev->trans_begin();
$xnumber = $this->db_onedev->query(
"SELECT `fn_numbering`('PINV') as numberx"
)->row()->numberx;
// Insert payment header (SupplierInvoiceID = 0, linked via Downpayment FK)
$sql = "INSERT INTO supplier_payment (
SupplierPaymentSupplierInvoiceID,
SupplierPaymentSupplierDownpaymentID,
SupplierPaymentNumber,
SupplierPaymentDate,
SupplierPaymentAmount,
SupplierPaymentCoaID,
SupplierPaymentNote,
SupplierPaymentCreated,
SupplierPaymentUserID
) VALUES (0, ?, ?, CURDATE(), ?, ?, ?, NOW(), ?)";
$que = $this->db_onedev->query($sql, [
$supllierDPID,
$xnumber,
$prm['amount'],
$prm['paymenttype'],
$prm['keterangan'],
$xuserid
]);
if (!$que) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("supplier_payment insert for DP");
exit;
}
$headerid = $this->db_onedev->insert_id();
// Mark downpayment as paid
$sql_dp = "UPDATE supplier_downpayment SET
SupplierDownpaymentDueDate = ?,
SupplierDownpaymentStatus = 'Paid',
SupplierDownpaymentDate = CURDATE(),
SupplierDownpaymentLastUpdatedUserID = ?
WHERE SupplierDownpaymentID = ?
AND SupplierDownpaymentIsActive = 'Y'
AND SupplierDownpaymentStatus != 'Paid'";
$que_dp = $this->db_onedev->query($sql_dp, [
$prm['tanggalbayar'],
$xuserid,
$supllierDPID
]);
if (!$que_dp) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("supplier_downpayment update status");
exit;
}
// Audit
$sql_audit = "SELECT * FROM supplier_payment
JOIN m_user ON M_UserID = SupplierPaymentUserID
WHERE SupplierPaymentID = ?";
$que_audit = $this->db_onedev->query($sql_audit, [$headerid]);
$row = $que_audit->row_array();
$data = array("header" => $row, "details" => []);
$message = "Nomor Pembayaran DP: " . $row["SupplierPaymentNumber"]
. " berhasil dibuat oleh " . $row["M_UserUsername"];
$this->insert_act_log(
"PF",
"NEW",
$message,
$headerid,
$this->safeJsonEncode($data),
$xuserid
);
$this->db_onedev->trans_commit();
$xdata = $this->db_onedev->query(
"SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx
FROM supplier_payment WHERE SupplierPaymentID = ?",
[$headerid]
)->row();
$result = array(
"total" => 1,
"records" => array('data' => $xdata)
);
$this->sys_ok($result);
exit;
}
function paymanual() function paymanual()
{ {
//# cek token valid //# cek token valid
@@ -479,15 +592,9 @@ ORDER BY coaAccountNo ASC";
SupplierPaymentNote, SupplierPaymentNote,
SupplierPaymentCreated, SupplierPaymentCreated,
SupplierPaymentUserID) SupplierPaymentUserID)
VALUES (?, VALUES (?,?,CURDATE(),?,?,?,NOW(),?)";
?, $query = $this->db_onedev->query(
CURDATE(), $sql,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array( array(
$orderid, $orderid,
$xnumber, $xnumber,
@@ -501,7 +608,7 @@ ORDER BY coaAccountNo ASC";
if (!$query) { if (!$query) {
$this->sys_error_db("supplier_payment insert"); $this->sys_error_db("supplier_payment insert");
exit; exit;
} else{ } else {
$sqlbill = "UPDATE supplier_invoice SET $sqlbill = "UPDATE supplier_invoice SET
SupplierInvoiceDraftPaymentDate = '{$tanggalbayar}' SupplierInvoiceDraftPaymentDate = '{$tanggalbayar}'
WHERE SupplierInvoiceID = $orderid"; WHERE SupplierInvoiceID = $orderid";
@@ -513,8 +620,8 @@ ORDER BY coaAccountNo ASC";
//echo $headerid; //echo $headerid;
foreach($bills as $k => $v){ foreach ($bills as $k => $v) {
if($v['tagihan_bayar'] > 0){ if ($v['tagihan_bayar'] > 0) {
$SupplierInvoiceDetailID = $v['SupplierInvoiceDetailID']; $SupplierInvoiceDetailID = $v['SupplierInvoiceDetailID'];
$tagihan_bayar = $v['tagihan_bayar']; $tagihan_bayar = $v['tagihan_bayar'];
$SupplierInvoiceDetailPurchaseOrderID = $v['SupplierInvoiceDetailPurchaseOrderID']; $SupplierInvoiceDetailPurchaseOrderID = $v['SupplierInvoiceDetailPurchaseOrderID'];
@@ -537,7 +644,7 @@ ORDER BY coaAccountNo ASC";
if (!$query) { if (!$query) {
$this->sys_error_db("supplier_payment_detail cash insert"); $this->sys_error_db("supplier_payment_detail cash insert");
exit; exit;
}else{ } else {
$sqlbilldetail = "UPDATE supplier_invoice_detail SET $sqlbilldetail = "UPDATE supplier_invoice_detail SET
SupplierInvoiceDetailUnpaid = SupplierInvoiceDetailUnpaid - $tagihan_bayar SupplierInvoiceDetailUnpaid = SupplierInvoiceDetailUnpaid - $tagihan_bayar
WHERE SupplierInvoiceDetailID = $SupplierInvoiceDetailID"; WHERE SupplierInvoiceDetailID = $SupplierInvoiceDetailID";
@@ -593,10 +700,9 @@ ORDER BY coaAccountNo ASC";
*/ */
} }
} }
} }
$sql = "SELECT * FROM supplier_payment $sql = "SELECT * FROM supplier_payment
JOIN m_user ON M_UserID = SupplierPaymentUserID JOIN m_user ON M_UserID = SupplierPaymentUserID
WHERE SupplierPaymentID = ?"; WHERE SupplierPaymentID = ?";
@@ -608,19 +714,22 @@ ORDER BY coaAccountNo ASC";
$query = $this->db_onedev->query($sql, [$headerid]); $query = $this->db_onedev->query($sql, [$headerid]);
$rows = $query->row_array(); $rows = $query->row_array();
$data = array("header" => $row, $data = array(
"details" => $rows); "header" => $row,
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." berhasil dibuat oleh " . $row["M_UserUsername"]; "details" => $rows
);
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . " berhasil dibuat oleh " . $row["M_UserUsername"];
$this->insert_act_log("PF", "NEW", $message, $headerid, $this->safeJsonEncode($data), $xuserid); $this->insert_act_log("PF", "NEW", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
$xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row(); $xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => array('data'=>$xdata) "records" => array('data' => $xdata)
); );
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
function editpaymanual() function editpaymanual()
{ {
//# cek token valid //# cek token valid
@@ -656,19 +765,22 @@ ORDER BY coaAccountNo ASC";
$query = $this->db_onedev->query($sql, [$headerid]); $query = $this->db_onedev->query($sql, [$headerid]);
$rows = $query->row_array(); $rows = $query->row_array();
$data = array("header" => $row, $data = array(
"details" => $rows); "header" => $row,
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." berhasil diubah oleh " . $row["M_UserUsername"]; "details" => $rows
);
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . " berhasil diubah oleh " . $row["M_UserUsername"];
$this->insert_act_log("PF", "NEW", $message, $headerid, $this->safeJsonEncode($data), $xuserid); $this->insert_act_log("PF", "NEW", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
$xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row(); $xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row();
$result = array( $result = array(
"total" => count($rows) , "total" => count($rows),
"records" => array('data'=>$xdata) "records" => array('data' => $xdata)
); );
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
function delete_note() function delete_note()
{ {
//# cek token valid //# cek token valid
@@ -694,8 +806,10 @@ ORDER BY coaAccountNo ASC";
$query = $this->db_onedev->query($sql, [$headerid]); $query = $this->db_onedev->query($sql, [$headerid]);
$rows = $query->row_array(); $rows = $query->row_array();
$data = array("header" => $row, $data = array(
"details" => $rows); "header" => $row,
"details" => $rows
);
$sql = "UPDATE supplier_payment $sql = "UPDATE supplier_payment
SET SupplierPaymentIsActive = 'N' SET SupplierPaymentIsActive = 'N'
@@ -737,15 +851,16 @@ ORDER BY coaAccountNo ASC";
exit; exit;
} }
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." telah dihapus oleh " . $row["M_UserUsername"]; $message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . " telah dihapus oleh " . $row["M_UserUsername"];
$this->insert_act_log("PF", "DELETE", $message, $headerid, $this->safeJsonEncode($data), $xuserid); $this->insert_act_log("PF", "DELETE", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
$result = array( $result = array(
"total" => 1 , "total" => 1,
"records" => array('prm'=>$prm) "records" => array('prm' => $prm)
); );
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
function edit_note() function edit_note()
{ {
//# cek token valid //# cek token valid
@@ -779,13 +894,13 @@ ORDER BY coaAccountNo ASC";
} }
$row = $query->row_array(); $row = $query->row_array();
if($row["SupplierPaymentAmount"]!= $amount_new) { if ($row["SupplierPaymentAmount"] != $amount_new) {
$messages_log[] = "Perubahan pembayaran : " . $row["SupplierPaymentAmount"] . " menjadi " . $amount_new; $messages_log[] = "Perubahan pembayaran : " . $row["SupplierPaymentAmount"] . " menjadi " . $amount_new;
} }
if($row["SupplierPaymentNote"]!= $keterangan) { if ($row["SupplierPaymentNote"] != $keterangan) {
$messages_log[] = "Perubahan keterangan : " . $row["SupplierPaymentNote"] . " menjadi " . $keterangan; $messages_log[] = "Perubahan keterangan : " . $row["SupplierPaymentNote"] . " menjadi " . $keterangan;
} }
if($row["SupplierPaymentCoaID"]!= $paymenttype) { if ($row["SupplierPaymentCoaID"] != $paymenttype) {
$messages_log[] = "Perubahan tipe pembayaran id : " . $row["SupplierPaymentCoaID"] . " menjadi " . $paymenttype; $messages_log[] = "Perubahan tipe pembayaran id : " . $row["SupplierPaymentCoaID"] . " menjadi " . $paymenttype;
} }
@@ -834,22 +949,23 @@ ORDER BY coaAccountNo ASC";
$this->sys_error_db("supplier_invoice_detail edit"); $this->sys_error_db("supplier_invoice_detail edit");
exit; exit;
} }
if(count($messages_log) > 0) { if (count($messages_log) > 0) {
$message = "Perubahan Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . "\n"; $message = "Perubahan Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . "\n";
$message .= implode("\n", $messages_log); $message .= implode("\n", $messages_log);
}else{ } else {
$message = "Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . " tanpa perubahan"; $message = "Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . " tanpa perubahan";
} }
$datas_log = $this->convertNumericValuesToStrings($datas_log); $datas_log = $this->convertNumericValuesToStrings($datas_log);
$this->insert_act_log("PF", "EDIT", $message, $id, $this->safeJsonEncode($datas_log), $xuserid); $this->insert_act_log("PF", "EDIT", $message, $id, $this->safeJsonEncode($datas_log), $xuserid);
$result = array( $result = array(
"total" => 1 , "total" => 1,
"records" => array('prm'=>$prm) "records" => array('prm' => $prm)
); );
$this->sys_ok($result); $this->sys_ok($result);
exit; exit;
} }
function insert_act_log($code, $status, $description, $refId, $data, $userId) function insert_act_log($code, $status, $description, $refId, $data, $userId)
{ {
$sql = "INSERT INTO user_activity( $sql = "INSERT INTO user_activity(
@@ -867,7 +983,9 @@ ORDER BY coaAccountNo ASC";
exit; exit;
} }
} }
private function safeJsonEncode($data) {
private function safeJsonEncode($data)
{
// Coba encode data ke JSON // Coba encode data ke JSON
$jsonData = json_encode($data); $jsonData = json_encode($data);
@@ -894,7 +1012,8 @@ ORDER BY coaAccountNo ASC";
} }
// Fungsi untuk memperbaiki masalah encoding JSON // Fungsi untuk memperbaiki masalah encoding JSON
private function fixJsonEncodeIssues($data, $errorMsg) { private function fixJsonEncodeIssues($data, $errorMsg)
{
// Buat salinan data untuk dimodifikasi // Buat salinan data untuk dimodifikasi
$fixedData = $data; $fixedData = $data;
@@ -917,7 +1036,8 @@ ORDER BY coaAccountNo ASC";
} }
// Perbaiki masalah karakter UTF-8 // Perbaiki masalah karakter UTF-8
private function fixUTF8Issues($data) { private function fixUTF8Issues($data)
{
if (is_string($data)) { if (is_string($data)) {
return mb_convert_encoding($data, 'UTF-8', 'UTF-8'); return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
} else if (is_array($data)) { } else if (is_array($data)) {
@@ -929,7 +1049,8 @@ ORDER BY coaAccountNo ASC";
} }
// Perbaiki masalah nilai Infinity atau NaN // Perbaiki masalah nilai Infinity atau NaN
private function fixInfNanIssues($data) { private function fixInfNanIssues($data)
{
if (is_array($data)) { if (is_array($data)) {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if (is_float($value) && (is_nan($value) || is_infinite($value))) { if (is_float($value) && (is_nan($value) || is_infinite($value))) {
@@ -943,7 +1064,8 @@ ORDER BY coaAccountNo ASC";
} }
// Perbaiki masalah referensi recursif // Perbaiki masalah referensi recursif
private function fixRecursiveReferences($data, $depth = 0) { private function fixRecursiveReferences($data, $depth = 0)
{
// Batasi kedalaman rekursi untuk menghindari infinite loop // Batasi kedalaman rekursi untuk menghindari infinite loop
if ($depth > 50) { if ($depth > 50) {
return "[MAX_DEPTH_REACHED]"; return "[MAX_DEPTH_REACHED]";
@@ -965,7 +1087,8 @@ ORDER BY coaAccountNo ASC";
} }
// Cari dan konversi numerik ke string secara rekursif // Cari dan konversi numerik ke string secara rekursif
private function convertNumericValuesToStrings($data) { private function convertNumericValuesToStrings($data)
{
if (is_array($data)) { if (is_array($data)) {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if (is_array($value)) { if (is_array($value)) {