From fc9947bce424b1e81c07f53d8c40ac4aeede378d Mon Sep 17 00:00:00 2001 From: bintanghr Date: Thu, 9 Jul 2026 10:11:28 +0700 Subject: [PATCH] add: getDaftarPoAset api --- .../mockup/purchase/order/PurchaseOrder.http | 14 ++++ .../purchase/order/PurchaseOrderAset.php | 83 +++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/application/controllers/mockup/purchase/order/PurchaseOrder.http b/application/controllers/mockup/purchase/order/PurchaseOrder.http index 667ede9..c410aca 100644 --- a/application/controllers/mockup/purchase/order/PurchaseOrder.http +++ b/application/controllers/mockup/purchase/order/PurchaseOrder.http @@ -172,6 +172,20 @@ Content-Type: application/json "ID": "" } +### +// listing po asset +POST https://{{host}}/mockup/purchase/order/PurchaseOrderAset/getDaftarPoAset/ +Content-Type: application/json + +{ + "token": {{token}}, + "search": "", + "currpage": 1, + "startdate": "2026-01-01", + "enddate": "2026-12-31", + "status": "All" +} + ### // create po asset POST https://{{host}}/mockup/purchase/order/PurchaseOrderAset/createPoAsset/ diff --git a/application/controllers/mockup/purchase/order/PurchaseOrderAset.php b/application/controllers/mockup/purchase/order/PurchaseOrderAset.php index 227a914..411bff6 100644 --- a/application/controllers/mockup/purchase/order/PurchaseOrderAset.php +++ b/application/controllers/mockup/purchase/order/PurchaseOrderAset.php @@ -185,6 +185,89 @@ class PurchaseOrderAset extends MY_Controller } } + public function getDaftarPoAset() { + try { + if (!$this->isLogin) { + $this->sys_error("invalid token"); + exit; + } + + $para = $this->sys_input; + $user = $this->sys_user; + + $keyword = "%"; + if ($para['search'] != '') { + $keyword .= $para['search'] . "%"; + } + + $sql_base = "SELECT + PurchaseOrderID, + PurchaseOrderDate, + PurchaseOrderNote, + PurchaseOrderNumber, + PurchaseOrderStatus, + PurchaseOrderRefNumber, + PurchaseOrderGrandTotal, + PurchaseOrderS_RegionalID, + PurchaseOrderApprovedManagerUserID AS verifiedby, + IFNULL(PurchaseOrderApprovedUserID, 0) AS approvedby, + PurchaseOrderAssetContractID, + PurchaseOrderAssetContractName AS contractName, + PurchaseOrderAssetContractStartDate AS contractStart, + PurchaseOrderAssetContractEndDate AS contractEnd, + SupplierID, + SupplierName + FROM purchase_order + JOIN supplier ON SupplierID = PurchaseOrderSupplierID + JOIN purchase_order_asset_contract + ON PurchaseOrderAssetContractPurchaseOrderID = PurchaseOrderID + WHERE PurchaseOrderIsActive = 'Y' + AND PurchaseOrderItemCategoryID = '3' + AND PurchaseOrderS_RegionalID = ? + AND PurchaseOrderDate BETWEEN DATE(?) AND DATE(?) + AND (PurchaseOrderStatus = ? OR 'All' = ?) + AND PurchaseOrderNumber LIKE ?"; + + $limit = 10; + $offset = 0; + if ($para['currpage'] > 0) { + $offset = ($para['currpage'] - 1) * $limit; + } + + $sql_data = $sql_base . " LIMIT ? OFFSET ?"; + $que_data = $this->db->query($sql_data, [ + $user['S_RegionalID'], $para['startdate'], $para['enddate'], + $para['status'], $para['status'], $keyword, $limit, $offset + ]); + if (!$que_data) { + $this->sys_error_db("[Error] failed get data listing PO asset"); + exit; + } + $data_services = $que_data->result_array(); + + $sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x"; + $que_total = $this->db->query($sql_total, [ + $user['S_RegionalID'], $para['startdate'], $para['enddate'], + $para['status'], $para['status'], $keyword + ]); + if (!$que_total) { + $this->sys_error_db("[Error] failed get total data listing PO asset"); + exit; + } + $total_services = $que_total->row_array()['total']; + + $output = [ + "records" => $data_services, + "total" => $total_services + ]; + + $this->sys_ok($output); + } catch (Exception $exc) { + $msg = $exc->getMessage(); + $this->sys_error($msg); + } + } + ## MUTATIONS ## public function createPoAsset() { try {