add: updateApprovalPO api in purchase order aset

This commit is contained in:
2026-07-09 11:09:44 +07:00
parent 7e88cf247b
commit 752c372c2f
2 changed files with 77 additions and 0 deletions

View File

@@ -1102,6 +1102,72 @@ class PurchaseOrderAset extends MY_Controller {
}
}
public function updateApprovalPO() {
try {
if (!$this->isLogin) {
$this->sys_error("invalid token");
exit;
}
$this->db->trans_begin();
$para = $this->sys_input;
$user = $this->sys_user;
$approvelevel = $para['approvelevel'];
/* request purchase order */
if ($approvelevel == '0') {
$sql = "UPDATE purchase_order SET
PurchaseOrderStatus = 'Pending',
PurchaseOrderLastUpdated = NOW()
WHERE PurchaseOrderID = ?
AND PurchaseOrderIsActive = 'Y'";
$que = $this->db->query($sql, [$para['poID']]);
if (!$que) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed update table purchase order request");
exit;
}
}
/* verifikasi oleh manager */
if ($approvelevel == '1') {
$sql = "UPDATE purchase_order SET
PurchaseOrderApprovedManagerUserID = ?,
PurchaseOrderLastUpdated = NOW()
WHERE PurchaseOrderID = ?
AND PurchaseOrderIsActive = 'Y'";
$que = $this->db->query($sql, [$user['M_UserID'], $para['poID']]);
if (!$que) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed update table purchase order verif");
exit;
}
}
/* approval oleh kepala regional */
if ($approvelevel == '2') {
$sql = "UPDATE purchase_order SET
PurchaseOrderStatus = 'Approved',
PurchaseOrderLastUpdated = NOW(),
PurchaseOrderApprovedUserID = ?
WHERE PurchaseOrderID = ?
AND PurchaseOrderIsActive = 'Y'";
$que = $this->db->query($sql, [$user['M_UserID'], $para['poID']]);
if (!$que) {
$this->db->trans_rollback();
$this->sys_error_db("[Error] failed update table purchase order approve");
exit;
}
}
$this->db->trans_commit();
$this->sys_ok("[Success] success update status PO Asset");
} catch (Exception $exc) {
$msg = $exc->getMessage();
$this->sys_error($msg);
}
}
public function getUserApproveLevel() {
try {
if (!$this->isLogin) {