238 lines
7.8 KiB
PHP
238 lines
7.8 KiB
PHP
<?php
|
|
|
|
class PurchaseOrderAset extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function index()
|
|
{
|
|
echo "Purchase Order Aset API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
## QUERY ##
|
|
public function getListSupplier()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
throw new Exception('Invalid token');
|
|
}
|
|
|
|
$sql = "SELECT
|
|
SupplierID,
|
|
SupplierName
|
|
FROM supplier
|
|
WHERE SupplierIsActive = 'Y'";
|
|
$que = $this->db->query($sql, []);
|
|
if (!$que) {
|
|
throw new Exception('failed to query list supplier', 1);
|
|
}
|
|
|
|
$data = $que->result_array();
|
|
$this->sys_ok($data);
|
|
} catch (Exception $exc) {
|
|
$msg = '[Error] ' . $exc->getMessage();
|
|
$code = $exc->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($msg);
|
|
} else {
|
|
$this->sys_error_db($msg);
|
|
}
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function getListCabang()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
throw new Exception('Invalid token');
|
|
}
|
|
|
|
$user = $this->sys_user;
|
|
$sql = "SELECT
|
|
M_BranchID,
|
|
M_BranchCode,
|
|
M_BranchName
|
|
FROM m_branch
|
|
WHERE M_BranchIsActive = 'Y'
|
|
AND M_BranchS_RegionalID = ?";
|
|
$que = $this->db->query($sql, [$user['S_RegionalID']]);
|
|
if (!$que) {
|
|
throw new Exception('failed to query list cabang', 1);
|
|
}
|
|
$data = $que->result_array();
|
|
|
|
$this->sys_ok($data);
|
|
} catch (Exception $exc) {
|
|
$msg = '[Error] ' . $exc->getMessage();
|
|
$code = $exc->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($msg);
|
|
} else {
|
|
$this->sys_error_db($msg);
|
|
}
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function searchRequestAset()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
throw new Exception('Invalid token');
|
|
}
|
|
|
|
$para = $this->sys_input;
|
|
|
|
$keyword = "%";
|
|
if ($para['search'] != '') {
|
|
$keyword .= $para['search'] . "%";
|
|
}
|
|
|
|
$limit = 10;
|
|
$offset = 0;
|
|
if ($para['currpage'] > 0) {
|
|
$offset = ($para['currpage'] - 1) * $limit;
|
|
}
|
|
|
|
$sql = "SELECT
|
|
PurchaseRequestID,
|
|
PurchaseRequestNumber,
|
|
PurchaseRequestDetailID,
|
|
PurchaseRequestFlagID,
|
|
PurchaseRequestFlagM_BranchCode AS BranchCode,
|
|
PurchaseRequestItemCategoryID AS ItemCategoryID,
|
|
PurchaseRequestFlagQtyRest - PurchaseRequestFlagQtyProses AS UnprocessFlagQty,
|
|
PurchaseRequestDetailQty AS RequestQty,
|
|
PurchaseRequestDetailQty AS OriginalQty,
|
|
M_BranchName,
|
|
M_ItemID,
|
|
M_ItemCode,
|
|
M_ItemDesc,
|
|
ItemUnitID,
|
|
ItemUnitName,
|
|
SupplierPricePrice as SupplierPrice
|
|
FROM purchase_request
|
|
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
|
AND PurchaseRequestDetailIsActive = 'Y'
|
|
AND PurchaseRequestM_BranchCode = ?
|
|
AND PurchaseRequestItemCategoryID = '3' -- id category item asset
|
|
AND PurchaseRequestNumber LIKE ?
|
|
JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
|
AND PurchaseRequestFlagStatus = 'PO'
|
|
AND PurchaseRequestFlagIsActive = 'Y'
|
|
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
|
JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID
|
|
JOIN supplier_price ON SupplierPriceSupplierID = ?
|
|
AND SupplierPriceM_ItemID = M_ItemID
|
|
AND SupplierPriceItemUnitID = ItemUnitID
|
|
AND SupplierPriceIsActive = 'Y'
|
|
JOIN m_branch ON M_BranchCode = PurchaseRequestFlagM_BranchCode
|
|
AND M_BranchIsActive = 'Y'
|
|
WHERE NOT EXISTS (
|
|
SELECT 1
|
|
FROM purchase_order_detail
|
|
JOIN purchase_order ON PurchaseOrderDetailPurchaseOrderID = PurchaseOrderID
|
|
AND PurchaseOrderStatus = 'Approved'
|
|
AND PurchaseOrderIsActive = 'Y'
|
|
AND PurchaseOrderDetailIsActive = 'Y'
|
|
WHERE PurchaseOrderDetailPurchaseRequestDetailID = PurchaseRequestDetailID
|
|
)";
|
|
|
|
$sql_data = $sql . " LIMIT ? OFFSET ? ";
|
|
$que_data = $this->db->query($sql_data, [
|
|
$para['branchcode'],
|
|
$keyword,
|
|
$para['supplierID'],
|
|
$limit,
|
|
$offset
|
|
]);
|
|
if (!$que_data) {
|
|
throw new Exception('failed to query data request order aset', 1);
|
|
}
|
|
$data = $que_data->result_array();
|
|
|
|
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
|
$que_total = $this->db->query($sql_total, [
|
|
$para['branchcode'],
|
|
$keyword,
|
|
$para['supplierID']
|
|
]);
|
|
if (!$que_total) {
|
|
throw new Exception('failed to query total request order aset', 1);
|
|
}
|
|
$total = $que_total->row_array()['total'];
|
|
|
|
$out = [
|
|
"records" => $data,
|
|
"total" => $total
|
|
];
|
|
|
|
$this->sys_ok($out);
|
|
} catch (Exception $exc) {
|
|
$msg = '[Error] ' . $exc->getMessage();
|
|
$code = $exc->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($msg);
|
|
} else {
|
|
$this->sys_error_db($msg);
|
|
}
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function getUserApproveLevel()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
throw new Exception('Invalid token');
|
|
}
|
|
|
|
$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) {
|
|
throw new Exception('failed to query approval level', 1);
|
|
}
|
|
$data = $que->row_array();
|
|
|
|
$this->sys_ok($data);
|
|
} catch (Exception $exc) {
|
|
$msg = '[Error] ' . $exc->getMessage();
|
|
$code = $exc->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($msg);
|
|
} else {
|
|
$this->sys_error_db($msg);
|
|
}
|
|
exit;
|
|
}
|
|
}
|
|
|
|
## MUTATIONS ##
|
|
public function insertPurchaseOrderAsset()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
throw new Exception('Invalid token');
|
|
}
|
|
} catch (Exception $e) {
|
|
$msg = '[Error] ' . $e->getMessage();
|
|
$code = $e->getCode();
|
|
if ($code == 0) {
|
|
$this->sys_error($msg);
|
|
} else {
|
|
$this->sys_error_db($msg);
|
|
}
|
|
exit;
|
|
}
|
|
}
|
|
}
|