first commit -> move some files from one-api
This commit is contained in:
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Cashier API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT prd.*,
|
||||
ure.M_UserFullName AS M_RequesterFullName,
|
||||
uap.M_UserFullName AS M_ApproverFullName,
|
||||
uco.M_UserFullName AS M_ConfirmerFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 30;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
// Validasi token
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function paidRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Paid',
|
||||
PurchaseRequestDirectTotalPaid = {$payload['PRPaid']},
|
||||
PurchaseRequestPaidDate = NOW(),
|
||||
PurchaseRequestPaidBy = {$userId},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Approved'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
ure.M_UserFullName AS M_RequesterFullName,
|
||||
uap.M_UserFullName AS M_ApproverFullName,
|
||||
uco.M_UserFullName AS M_ConfirmerFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND prd.PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function realitationRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Received',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Ordered'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Completed',
|
||||
PurchaseRequestDirectTotalRealitation = {$payload["PRRealitation"]},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Paid'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
ure.M_UserFullName AS M_RequesterFullName,
|
||||
uap.M_UserFullName AS M_ApproverFullName,
|
||||
uco.M_UserFullName AS M_ConfirmerFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND prd.PurchaseRequestDirectID = {$payload["PRID"]}";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,805 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirect extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Requester API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
/* if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$startdate = $payload["startdate"];
|
||||
$enddate = $payload["enddate"];
|
||||
|
||||
$query = "SELECT pv.*,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
CONCAT(cs.coaAccountNo, ' | ', cs.coaDescription) as CoaSource,
|
||||
-- CONCAT(ce.coaAccountNo, ' | ', ce.coaDescription) as CoaExpense,
|
||||
CONCAT(ct.coaAccountNo, ' | ', ct.coaDescription) as CoaTemporary,
|
||||
cs.coaDescription coaDescriptionSource,
|
||||
-- ce.coaDescription coaDescriptionExpense,
|
||||
ct.coaDescription coaDescriptionTemporary,
|
||||
cs.coaAccountNo coaAccountNoSource,
|
||||
-- ce.coaAccountNo coaAccountNoExpense,
|
||||
ct.coaAccountNo coaAccountNoTemporary
|
||||
FROM payment_voucher as pv
|
||||
LEFT JOIN m_branch ON M_BranchCode = PaymentVoucherM_BranchCode
|
||||
JOIN coa cs ON cs.coaID = PaymentVoucherCoaSourceID
|
||||
-- JOIN coa ce ON ce.coaID = PaymentVoucherCoaExpenseID
|
||||
JOIN coa ct ON ct.coaID = PaymentVoucherCoaTemporaryID
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND DATE(PaymentVoucherDate) BETWEEN '{$startdate}' AND '{$enddate}'
|
||||
AND (PaymentVoucherNumber LIKE '%" . $payload["search"] . "%')";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM payment_voucher as pv
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND DATE(PaymentVoucherDate) BETWEEN '{$startdate}' AND '{$enddate}'
|
||||
AND (PaymentVoucherNumber LIKE '%" . $payload["search"] . "%')";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PaymentVoucherDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PaymentVoucherDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"] !== 'All') {
|
||||
$query .= " AND PaymentVoucherStatus = '{$payload["status"]}'";
|
||||
$queryCount .= " AND PaymentVoucherStatus = '{$payload["status"]}'";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PaymentVoucherDate DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
/* if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM payment_voucher_detail
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT payment_voucher_detail.*,
|
||||
ROW_NUMBER() OVER(ORDER BY PaymentVoucherDetailID) RowNumber,
|
||||
PurchaseRequestDirectID,
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectAccountFilled
|
||||
FROM payment_voucher_detail
|
||||
LEFT JOIN purchase_request_direct ON PurchaseRequestDirectID = PaymentVoucherDetailPurchaseRequestDirectID
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function voucherDetailItem() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
|
||||
$sql = "SELECT
|
||||
PurchaseDirectCategoryID,
|
||||
PurchaseDirectCategoryName,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectDetailID,
|
||||
PurchaseRequestDirectDetailItemUnitID,
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
PurchaseRequestDirectDetailPurchaseRequestDirectID,
|
||||
IFNULL(PurchaseRequestDirectDetailAccount, '') as account_number,
|
||||
'' as err_message
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN purchase_direct_category ON PurchaseDirectCategoryID = PurchaseRequestDirectDetailPurchaseRequestDirectCategoryID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = ?";
|
||||
$que = $this->db->query($sql, [$para['PRDirectID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get detail item voucher purchase request direct");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND (M_BranchCode LIKE '%" . $payload["search"] . "%' OR M_BranchName LIKE '%" . $payload["search"] . "%')
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getCoa()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$query = "SELECT * FROM coa
|
||||
WHERE coaIsActive = 'Y' AND coaIsInput = 'Y'
|
||||
AND (coaAccountNo LIKE '%" . $payload["search"] . "%' OR coaDescription LIKE '%" . $payload["search"] . "%')
|
||||
ORDER BY coaAccountNo ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getPurchase()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$query = "SELECT prd.*, u.M_UserUsername as user_request
|
||||
FROM purchase_request_direct prd
|
||||
JOIN m_user u ON prd.PurchaseRequestCreatedUserID = u.M_UserID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND prd.PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'
|
||||
AND prd.PurchaseRequestDirectID not in (
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y')
|
||||
ORDER BY prd.PurchaseRequestDirectNumber ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getTotalApproved()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$total = 0;
|
||||
$query = "SELECT COUNT(*) as total
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'
|
||||
AND PurchaseRequestDirectID not in (
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y')";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $total,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$pdSql = "SELECT `fn_numbering`('PV') AS PV";
|
||||
$exec = $this->db->query($pdSql, []);
|
||||
$pd = "";
|
||||
$dateNow = date('Y-m-d');
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$pd = $exec->result_array()[0]["PV"];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO payment_voucher(
|
||||
PaymentVoucherDate,
|
||||
PaymentVoucherNumber,
|
||||
PaymentVoucherM_BranchCode,
|
||||
PaymentVoucherCoaSourceID,
|
||||
PaymentVoucherCoaExpenseID,
|
||||
PaymentVoucherCoaTemporaryID,
|
||||
PaymentVoucherTotal,
|
||||
PaymentVoucherStatus,
|
||||
PaymentVoucherUserID,
|
||||
PaymentVoucherCreated,
|
||||
PaymentVoucherLastUpdated)
|
||||
VALUES ('{$dateNow}',
|
||||
'{$pd}',
|
||||
'{$payload['BranchCode']}',
|
||||
'{$payload['CoaSourceID']}',
|
||||
'{$payload['CoaExpenseID']}',
|
||||
'{$payload['CoaTemporaryID']}',
|
||||
'{$payload['total']}',
|
||||
'Draft',
|
||||
{$userId},
|
||||
now(),
|
||||
now())";
|
||||
$exec = $this->db->query($sql);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db->insert_id();
|
||||
foreach ($payload['details'] as $k => $v) {
|
||||
$sql = "INSERT INTO payment_voucher_detail(
|
||||
PaymentVoucherDetailPaymentVoucherID,
|
||||
PaymentVoucherDetailPurchaseRequestDirectID,
|
||||
PaymentVoucherDetailTotal,
|
||||
PaymentVoucherDetailUserID,
|
||||
PaymentVoucherDetailCreated,
|
||||
PaymentVoucherDetailLastUpdated)
|
||||
VALUES ('{$last_id}',
|
||||
'{$v['PurchaseRequestDirectID']}',
|
||||
'{$v['PurchaseRequestDirectTotalRealitation']}',
|
||||
{$userId},
|
||||
now(),
|
||||
now())";
|
||||
$exec = $this->db->query($sql);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM payment_voucher WHERE PaymentVoucherNumber = '{$pd}' AND PaymentVoucherIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherM_BranchCode = '{$payload['BranchCode']}',
|
||||
PaymentVoucherCoaSourceID = '{$payload['CoaSourceID']}',
|
||||
PaymentVoucherCoaExpenseID = '{$payload['CoaExpenseID']}',
|
||||
PaymentVoucherCoaTemporaryID = '{$payload['CoaTemporaryID']}',
|
||||
PaymentVoucherTotal = '{$payload['total']}',
|
||||
PaymentVoucherUserID = {$userId},
|
||||
PaymentVoucherLastUpdated = now()
|
||||
WHERE PaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM payment_voucher_detail WHERE PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
foreach ($payload['details'] as $k => $v) {
|
||||
$sql = "INSERT INTO payment_voucher_detail(
|
||||
PaymentVoucherDetailPaymentVoucherID,
|
||||
PaymentVoucherDetailPurchaseRequestDirectID,
|
||||
PaymentVoucherDetailTotal,
|
||||
PaymentVoucherDetailUserID,
|
||||
PaymentVoucherDetailCreated,
|
||||
PaymentVoucherDetailLastUpdated)
|
||||
VALUES ('{$payload['ID']}',
|
||||
'{$v['PurchaseRequestDirectID']}',
|
||||
'{$v['PurchaseRequestDirectTotalRealitation']}',
|
||||
{$userId},
|
||||
now(),
|
||||
now())";
|
||||
$exec = $this->db->query($sql);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newUpdate = "SELECT * FROM payment_voucher WHERE PaymentVoucherID = {$payload['ID']} AND PaymentVoucherIsActive = 'Y'";
|
||||
$records = $this->db->query($newUpdate, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
/* if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherIsActive = 'N'
|
||||
WHERE PaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE payment_voucher_detail SET
|
||||
PaymentVoucherDetailIsActive = 'N'
|
||||
WHERE PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function orderRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE payment_voucher_detail SET
|
||||
PaymentVoucherDetailLastUpdated = NOW(),
|
||||
PaymentVoucherDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PaymentVoucherDetailPaymentVoucherID = {$payload["ID"]}
|
||||
AND PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailStatus = 'Pending'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order payment voucher error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PaymentVoucherID = {$payload["ID"]}
|
||||
AND PaymentVoucherIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order payment voucher error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$sql = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PaymentVoucherNumber) RowNumber
|
||||
FROM payment_voucher
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND PaymentVoucherUserID = {$userId}
|
||||
AND PaymentVoucherID = {$payload["ID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
$row = [];
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order payment voucher error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$row = $exec->result_array();
|
||||
}
|
||||
$result = array("total" => 1, "records" => $row);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveAccountDetail() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($param['detail'] as $key => $obj) {
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAccount = ?,
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = ?,
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW()
|
||||
WHERE PurchaseRequestDirectDetailID = ? ";
|
||||
$que = $this->db->query($sql, [
|
||||
$obj['account_number'], $userId,
|
||||
$obj['PurchaseRequestDirectDetailID']
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update account item voucher", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sqlheader = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectAccountFilled = 'Y'
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$queheader = $this->db->query($sqlheader, [$param['PRDID']]);
|
||||
if (!$queheader) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update header status account is filled", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success]");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getPurchaseUpdate()
|
||||
{
|
||||
try {
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// }
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT *, 'N' as flag_isadd
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
// exit;
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$PurchaseRequestDirectID = $v["PurchaseRequestDirectID"];
|
||||
$sql = "SELECT *
|
||||
FROM payment_voucher_detail
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPurchaseRequestDirectID = {$PurchaseRequestDirectID}";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if ($qry) {
|
||||
$rows_detail = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows_detail);
|
||||
// exit;
|
||||
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$k]['flag_isadd'] = 'Y';
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getPurchaseUpdateNew()
|
||||
{
|
||||
try {
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// }
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT *, 'N' as flag_isadd
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'
|
||||
AND PurchaseRequestDirectID not in (
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID
|
||||
from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y' AND
|
||||
PaymentVoucherDetailPaymentVoucherID <> '{$payload["ID"]}' AND
|
||||
PaymentVoucherM_BranchCode = '{$payload["branchcode"]}'
|
||||
|
||||
union
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID
|
||||
from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y' AND
|
||||
PaymentVoucherDetailPaymentVoucherID = '{$payload["ID"]}' AND
|
||||
PaymentVoucherM_BranchCode = '{$payload["branchcode"]}'
|
||||
|
||||
|
||||
)
|
||||
UNION
|
||||
SELECT purchase_request_direct.*, 'Y' as flag_isadd
|
||||
FROM payment_voucher_detail
|
||||
JOIN purchase_request_direct ON PurchaseRequestDirectID = PaymentVoucherDetailPurchaseRequestDirectID
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y' AND PaymentVoucherDetailPaymentVoucherID = '{$payload["ID"]}'";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function moveToKasir() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherStatus = 'Draft'
|
||||
WHERE PaymentVoucherID = ?";
|
||||
$que = $this->db->query($sql, $param['ID']);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] edit voucher status to draft");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirectAdjusment extends MY_Controller {
|
||||
var $db;
|
||||
public function index() {
|
||||
echo "Purchase Request Direct Adjustment";
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = '%';
|
||||
if ($param['search'] != '') {
|
||||
$keyword = $param['search'] . '%';
|
||||
}
|
||||
|
||||
$sql = "SELECT pv.* ,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
CONCAT(cs.coaAccountNo, ' | ', cs.coaDescription) as CoaSource,
|
||||
CONCAT(ct.coaAccountNo, ' | ', ct.coaDescription) as CoaTemporary,
|
||||
cs.coaDescription coaDescriptionSource,
|
||||
ct.coaDescription coaDescriptionTemporary,
|
||||
cs.coaAccountNo coaAccountNoSource,
|
||||
ct.coaAccountNo coaAccountNoTemporary
|
||||
FROM payment_voucher as pv
|
||||
LEFT JOIN m_branch ON M_BranchCode = PaymentVoucherM_BranchCode
|
||||
JOIN coa cs ON cs.coaID = PaymentVoucherCoaSourceID
|
||||
JOIN coa ct ON ct.coaID = PaymentVoucherCoaTemporaryID
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND DATE(PaymentVoucherDate) BETWEEN DATE(?) AND DATE(?)
|
||||
AND PaymentVoucherNumber LIKE ?";
|
||||
$que = $this->db->query($sql, [$param['startdate'], $param['enddate'], $keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get data voucher");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
$result = array(
|
||||
'records' => $data
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql = "SELECT payment_voucher_detail.*,
|
||||
ROW_NUMBER() OVER(ORDER BY PaymentVoucherDetailID) RowNumber,
|
||||
PurchaseRequestDirectID,
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectAdjustment,
|
||||
PurchaseRequestDirectAdjustmentAccount,
|
||||
PurchaseRequestDirectAccountFilled
|
||||
FROM payment_voucher_detail
|
||||
LEFT JOIN purchase_request_direct ON PurchaseRequestDirectID = PaymentVoucherDetailPurchaseRequestDirectID
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPaymentVoucherID = ?";
|
||||
$que = $this->db->query($sql, [$param['ID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get data voucher");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
'records' => $que->result_array()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateAdjustment() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectAdjustment = ?,
|
||||
PurchaseRequestDirectAdjustmentAccount = ?,
|
||||
PurchaseRequestLastUpdatedUserID = ?,
|
||||
PurchaseRequestLastUpdated = NOW()
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$que = $this->db->query($sql, [
|
||||
$param['price_adj'], $param['account_adj'],
|
||||
$user['M_UserID'], $param['prd_id']
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data voucher");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('success');
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRealisasi() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherRealitationApproved = 'Y'
|
||||
WHERE PaymentVoucherID = ?";
|
||||
$que = $this->db->query($sql, [$param['ID']]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] aprrove realisasi");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success approve realisasi");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getListAccount() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaAccountNo LIKE '111%'
|
||||
ORDER BY coaAccountNo ASC";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listing of accounts");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
43
application/controllers/mockup/purchase/faktur/Faktur.http
Normal file
43
application/controllers/mockup/purchase/faktur/Faktur.http
Normal file
@@ -0,0 +1,43 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/faktur/Faktur
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MiIsIk1fVXNlclVzZXJuYW1lIjoia2FjYWJhZGl0eWEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjb25lLXB1cmNoYXNlLXJlcXVlc3Qta2FjYWIiLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJLYWNhYiBBZGl0eWEiLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjEyMCIsIk1fVXNlckxvY2F0aW9uSUQiOiIzOSIsIk1fVXNlckxvY2F0aW9uRmxhZyI6IkIiLCJTX1JlZ2lvbmFsTmFtZSI6IlN1cmFiYXlhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI2IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBBZGl0eWF3YXJtYW4iLCJNX0JyYW5jaENvZGUiOiJMQSIsIk1fQnJhbmNoSUQiOiIxNCIsImxvZ2luTGV2ZWwiOiJicmFuY2giLCJNX0JyYW5jaENvbXBhbnlJRCI6IjEiLCJNX0JyYW5jaENvbXBhbnlOYW1lIjoiUFQgUFJBTUlUQSIsImlwIjoiMTM5LjAuOTcuMTA4IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFgxMTsgTGludXggeDg2XzY0OyBydjoxMzkuMCkgR2Vja29cLzIwMTAwMTAxIEZpcmVmb3hcLzEzOS4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDctMDEgMTQ6MjQ6MzciLCJNX1NhdGVsbGl0ZUlEIjowfQ.NCSVDCZiAFZJIB8KkekX-Jw9ANZD5cpH7xfec7q7jrg"
|
||||
|
||||
### Lookup RO
|
||||
POST {{host}}/LookupRO
|
||||
|
||||
{
|
||||
"poID":"15",
|
||||
"supplierID":"3",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Lookup Item RO
|
||||
POST {{host}}/LookupItemRO
|
||||
|
||||
{
|
||||
"poID":"15",
|
||||
"roID":"16",
|
||||
"name":"",
|
||||
"currpage":1,
|
||||
"token" : {{token}}
|
||||
}
|
||||
|
||||
### Lookup List RO
|
||||
POST {{host}}/LookupListFaktur
|
||||
|
||||
{
|
||||
"page":1,
|
||||
"nomor":"",
|
||||
"status":"All",
|
||||
"enddate":"2025-07-01",
|
||||
"date":"2025-07-01",
|
||||
"supplier":"0",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Lookup PO
|
||||
POST {{host}}/LookupPO
|
||||
|
||||
{
|
||||
"supID" : 6,
|
||||
"token" : {{token}}
|
||||
}
|
||||
1550
application/controllers/mockup/purchase/faktur/Faktur.php
Normal file
1550
application/controllers/mockup/purchase/faktur/Faktur.php
Normal file
File diff suppressed because it is too large
Load Diff
1582
application/controllers/mockup/purchase/faktur/Fakturv2.php
Normal file
1582
application/controllers/mockup/purchase/faktur/Fakturv2.php
Normal file
File diff suppressed because it is too large
Load Diff
1704
application/controllers/mockup/purchase/faktur/Fakturv3.php
Normal file
1704
application/controllers/mockup/purchase/faktur/Fakturv3.php
Normal file
File diff suppressed because it is too large
Load Diff
1786
application/controllers/mockup/purchase/faktur/Fakturv4.php
Normal file
1786
application/controllers/mockup/purchase/faktur/Fakturv4.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,644 @@
|
||||
<?php
|
||||
class PurchaseRequestListing extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "LISTING PURCHASE REQUEST";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list_purchaserequest_old19Juni2025()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$startdate = $para["startdate"];
|
||||
$enddate = $para["enddate"];
|
||||
$regional = $para["regional"];
|
||||
|
||||
$branch = $para['branch'];
|
||||
$cabang = "";
|
||||
if ($branch == "ALL" || $branch == "") {
|
||||
$cabang = "%%";
|
||||
} else {
|
||||
$cabang = "%" . $branch . "%";
|
||||
}
|
||||
|
||||
$f_stat = [];
|
||||
$status = $para["status"];
|
||||
switch ($status) {
|
||||
case 'READ':
|
||||
$f_stat = ["Read", "X"];
|
||||
break;
|
||||
case 'NEW':
|
||||
$f_stat = ["Approved", "X"];
|
||||
break;
|
||||
default:
|
||||
$f_stat = ["Approved", "Read"];
|
||||
break;
|
||||
}
|
||||
|
||||
$currpage = $para["currpage"];
|
||||
$page = 0;
|
||||
$limit = 10;
|
||||
if ($currpage > 0) {
|
||||
$page = ($currpage - 1) * $limit;
|
||||
}
|
||||
|
||||
$sqltotal = "SELECT COUNT(DISTINCT PurchaseRequestDetailID) as total
|
||||
FROM purchase_request
|
||||
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
LEFT JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND WarehouseIsActive = 'Y'
|
||||
AND (WarehouseIsTransit != 'Y' OR WarehouseIsTransit IS NULL)
|
||||
LEFT JOIN stock ON StockItemId = M_ItemID
|
||||
AND StockWarehouseID = warehouse.WarehouseID
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))
|
||||
-- GROUP BY PurchaseRequestDetailID
|
||||
ORDER BY
|
||||
PurchaseRequestDetailStatus ASC,
|
||||
PurchaseRequestDetailID DESC,
|
||||
PurchaseRequestDate DESC,
|
||||
PurchaseRequestFlagID DESC
|
||||
";
|
||||
$qrytot = $this->db->query($sqltotal, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang
|
||||
]);
|
||||
$total = $qrytot->result_array()[0]['total'];
|
||||
|
||||
$sqldata = "SELECT
|
||||
COALESCE(PurchaseRequestFlagID, 'new') as PurchaseRequestFlagID,
|
||||
PurchaseRequestDate, PurchaseRequestNumber,
|
||||
S_RegionalID, S_RegionalName,
|
||||
COALESCE(M_BranchCode, '') AS M_BranchCode,
|
||||
COALESCE(M_BranchName, '') AS M_BranchName,
|
||||
PurchaseRequestDetailID, M_ItemID,
|
||||
PurchaseRequestDetailIsCito,
|
||||
M_ItemDesc, PurchaseRequestDetailQty,
|
||||
COALESCE(SUM(CASE WHEN warehouse.WarehouseID IS NOT NULL AND stock.StockItemId IS NOT NULL THEN stock.StockQty ELSE 0 END), 0) as StockQty,
|
||||
COALESCE(warehouse.WarehouseID, '') as StockWarehouseID,
|
||||
PurchaseRequestDetailStatus,
|
||||
COALESCE(PurchaseRequestFlagStatus, '') as PurchaseRequestFlagStatus
|
||||
FROM purchase_request
|
||||
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
LEFT JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND WarehouseIsActive = 'Y'
|
||||
AND (WarehouseIsTransit != 'Y' OR WarehouseIsTransit IS NULL)
|
||||
LEFT JOIN stock ON StockItemId = M_ItemID
|
||||
AND StockWarehouseID = warehouse.WarehouseID
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))
|
||||
GROUP BY PurchaseRequestDetailID
|
||||
ORDER BY PurchaseRequestDetailStatus ASC,
|
||||
PurchaseRequestDetailID DESC,
|
||||
PurchaseRequestDate DESC,
|
||||
PurchaseRequestFlagID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qrydata = $this->db->query($sqldata, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$limit,
|
||||
$page
|
||||
]);
|
||||
$data = $qrydata->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"total" => $total
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refactor 18 Juni 2025 by Mario
|
||||
* Whats new:
|
||||
* > Perhitungan stok mempertimbangkan:
|
||||
* > - Stock hanya diambil dari gudang regional
|
||||
* > - Stock hanya diambil dari gudang default (untuk handle kasus jakarta ada 2 gudang regional)
|
||||
* > - Mempertimbangkan unitItem sebelum menjumlahkan kuantitas stok karena ada PR dengan unit berbeda
|
||||
* > - Menghitung stok dengan subquery daripada join
|
||||
* > - Memperhatikan StockED untuk ItemCategoryID == 1 (Persediaan), jika ItemID dan ItemUnitID sama maka jumlah semua stok dari Gudang Regional selama StockED >= hari ini
|
||||
*/
|
||||
public function list_purchaserequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$startdate = $para["startdate"];
|
||||
$enddate = $para["enddate"];
|
||||
$regional = $para["regional"];
|
||||
|
||||
$branch = $para['branch'];
|
||||
$cabang = "";
|
||||
if ($branch == "ALL" || $branch == "") {
|
||||
$cabang = "%%";
|
||||
} else {
|
||||
$cabang = "%" . $branch . "%";
|
||||
}
|
||||
|
||||
$f_stat = [];
|
||||
$status = $para["status"];
|
||||
switch ($status) {
|
||||
case 'READ':
|
||||
$f_stat = ["Read", "X"];
|
||||
break;
|
||||
case 'NEW':
|
||||
$f_stat = ["Approved", "X"];
|
||||
break;
|
||||
default:
|
||||
$f_stat = ["Approved", "Read"];
|
||||
break;
|
||||
}
|
||||
|
||||
$currpage = $para["currpage"];
|
||||
$page = 0;
|
||||
$limit = 10;
|
||||
if ($currpage > 0) {
|
||||
$page = ($currpage - 1) * $limit;
|
||||
}
|
||||
|
||||
$sqltotal = "SELECT COUNT(DISTINCT PurchaseRequestDetailID) as total
|
||||
FROM purchase_request_detail
|
||||
JOIN purchase_request ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
LEFT JOIN itemunit unit_req ON unit_req.ItemUnitID = PurchaseRequestDetailItemUnitID
|
||||
AND unit_req.ItemUnitIsActive = 'Y'
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))";
|
||||
$qrytot = $this->db->query($sqltotal, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang
|
||||
]);
|
||||
$total = $qrytot->result_array()[0]['total'];
|
||||
|
||||
$sqldata = "SELECT
|
||||
COALESCE(PurchaseRequestFlagID, 'new') as PurchaseRequestFlagID,
|
||||
PurchaseRequestDate, PurchaseRequestNumber,
|
||||
S_RegionalID, S_RegionalName,
|
||||
COALESCE(M_BranchCode, '') AS M_BranchCode,
|
||||
COALESCE(M_BranchName, '') AS M_BranchName,
|
||||
PurchaseRequestDetailID, M_ItemID,
|
||||
PurchaseRequestDetailIsCito,
|
||||
M_ItemDesc, PurchaseRequestDetailQty,
|
||||
unit_req.ItemUnitName AS UnitRequest,
|
||||
unit_req.ItemUnitID AS UnitIDRequest,
|
||||
PurchaseRequestDetailStatus,
|
||||
COALESCE(PurchaseRequestFlagStatus, '') as PurchaseRequestFlagStatus
|
||||
FROM purchase_request_detail
|
||||
JOIN purchase_request ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
JOIN itemunit unit_req ON unit_req.ItemUnitID = PurchaseRequestDetailItemUnitID
|
||||
AND unit_req.ItemUnitIsActive = 'Y'
|
||||
LEFT JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND WarehouseIsActive = 'Y'
|
||||
AND (WarehouseIsTransit != 'Y' OR WarehouseIsTransit IS NULL)
|
||||
AND WarehouseM_BranchID = 0
|
||||
AND WarehouseIsDefault = 'Y'
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))
|
||||
ORDER BY PurchaseRequestDetailStatus ASC,
|
||||
PurchaseRequestDetailID DESC,
|
||||
PurchaseRequestDate DESC,
|
||||
PurchaseRequestFlagID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qrydata = $this->db->query($sqldata, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$limit,
|
||||
$page
|
||||
]);
|
||||
if (!$qrydata) {
|
||||
throw new Exception(json_encode($this->db->error()));
|
||||
}
|
||||
|
||||
// TODO: Hapus Last Query jika tidak diperlukan
|
||||
// $lastQuery = $this->db->last_query();
|
||||
$data = $qrydata->result_array();
|
||||
|
||||
// For each PR Detail, fetch the stock data across all units
|
||||
foreach ($data as &$row) {
|
||||
$stockSql = "SELECT
|
||||
SUM(s.StockQty) as QtyTotal,
|
||||
u.ItemUnitName,
|
||||
s.StockItemUnitID
|
||||
FROM stock s
|
||||
JOIN warehouse w ON s.StockWarehouseID = w.WarehouseID
|
||||
JOIN itemunit u ON s.StockItemUnitID = u.ItemUnitID
|
||||
WHERE s.StockItemId = ?
|
||||
AND w.WarehouseS_RegionalID = ?
|
||||
AND w.WarehouseIsActive = 'Y'
|
||||
AND (w.WarehouseIsTransit != 'Y' OR w.WarehouseIsTransit IS NULL)
|
||||
AND w.WarehouseM_BranchID = 0
|
||||
AND w.WarehouseIsDefault = 'Y'
|
||||
AND (
|
||||
? != 1
|
||||
OR (? = 1 AND (s.StockED IS NULL OR s.StockED >= CURDATE()))
|
||||
)
|
||||
GROUP BY s.StockItemUnitID, u.ItemUnitName";
|
||||
|
||||
$stockQry = $this->db->query($stockSql, [
|
||||
$row['M_ItemID'],
|
||||
$row['S_RegionalID'],
|
||||
$row['PurchaseRequestItemCategoryID'] ?? 0,
|
||||
$row['PurchaseRequestItemCategoryID'] ?? 0
|
||||
]);
|
||||
|
||||
if (!$stockQry) {
|
||||
throw new Exception(json_encode($this->db->error()));
|
||||
}
|
||||
|
||||
// Kalau item belum ada di stock, returnnya []
|
||||
|
||||
$row['StockQtyArray'] = $stockQry->result_array();
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
// "lastQuery" => $lastQuery,
|
||||
"total" => $total
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function listing_regional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = "%" . $prm['search'] . "%";
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y' AND S_RegionalName LIKE ?";
|
||||
$query = $this->db->query($sql, [$search]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get listing regional");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function listing_branch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regID = $prm['regionalID'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchS_RegionalID = ? AND M_BranchIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$regID]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get branch based on regional");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"result" => $rows,
|
||||
"total" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function insertstatus()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$reqnumber = $prm['reqnumber'];
|
||||
$reqdetailid = $prm['reqdetailid'];
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchcode = $prm['branchcode'];
|
||||
$qty = $prm['qty'];
|
||||
$stock = $prm['stock'];
|
||||
$status = $prm['status'];
|
||||
$UnitIDRequest = $prm['UnitIDRequest'];
|
||||
|
||||
/* Validasi ItemUnit Request dengan Stock */
|
||||
$stock = $this->calculateStockByItemUnitReq($stock, $UnitIDRequest);
|
||||
|
||||
$sqlin = "INSERT INTO purchase_request_flag (
|
||||
PurchaseRequestFlagPurchaseRequestDetailID,
|
||||
PurchaseRequestFlagS_RegionalID,
|
||||
PurchaseRequestFlagM_BranchCode,
|
||||
PurchaseRequestFlagQty,
|
||||
PurchaseRequestFlagQtyRest,
|
||||
PurchaseRequestFlagStatus,
|
||||
PurchaseRequestFlagUserID,
|
||||
PurchaseRequestFlagCreated
|
||||
) VALUES (?,?,?,?,?,?,?,NOW())";
|
||||
$query = $this->db->query($sqlin, [
|
||||
$reqdetailid,
|
||||
$regionalid,
|
||||
$branchcode,
|
||||
$qty,
|
||||
$qty,
|
||||
$status,
|
||||
$userid
|
||||
]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert status request");
|
||||
exit;
|
||||
}
|
||||
|
||||
$reqflagid = $this->db->insert_id();
|
||||
$sqlget = "SELECT * FROM purchase_request_flag WHERE PurchaseRequestFlagID = ?";
|
||||
$queget = $this->db->query($sqlget, [$reqdetailid]);
|
||||
if (!$queget) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error get latest inserted flag");
|
||||
exit;
|
||||
}
|
||||
$data = $queget->result_array()[0];
|
||||
$json = json_encode($data);
|
||||
|
||||
$sqlog = "INSERT INTO acc_one_log.purchaserequestflag_log (
|
||||
PurchaseRequestFlagLogPurchaseRequestFlagID,
|
||||
PurchaseRequestFlagLogStatus,
|
||||
PurchaseRequestFlagLogQty,
|
||||
PurchaseRequestFlagLogStock,
|
||||
PurchaseRequestFlagLogJson,
|
||||
PurchaseRequestFlagLogUserID,
|
||||
PurchaseRequestFlagLogCreated
|
||||
) VALUES (?, ?, ?, ?, ?, ?, NOW())";
|
||||
$quelog = $this->db->query($sqlog, [$reqflagid, $status, $qty, $stock, $json, $userid]);
|
||||
if (!$quelog) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert log purchase request flag");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlread = "UPDATE purchase_request_detail SET
|
||||
PurchaseRequestDetailStatus = 'Read'
|
||||
WHERE PurchaseRequestDetailID = ?";
|
||||
$queread = $this->db->query($sqlread, [$reqdetailid]);
|
||||
if (!$queread) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update status purchase request detail to read");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlpart = "UPDATE purchase_request SET
|
||||
PurchaseRequestStatus = 'Partial'
|
||||
WHERE PurchaseRequestRefNumber = ?";
|
||||
$quepart = $this->db->query($sqlpart, [$reqnumber]);
|
||||
if (!$quepart) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update status purchase request to partial");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success insert status request");
|
||||
|
||||
} catch (\Throwable $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changestatus()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$reqnumber = $prm['reqnumber'];
|
||||
$reqflagid = $prm['requestflagid'];
|
||||
$reqdetailid = $prm['reqdetailid'];
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchcode = $prm['branchcode'];
|
||||
$reqqty = $prm['qty'];
|
||||
$reqstock = $prm['stock'];
|
||||
$reqstatus = $prm['status'];
|
||||
$UnitIDRequest = $prm['UnitIDRequest'];
|
||||
|
||||
/* Validasi ItemUnit Request dengan Stock */
|
||||
$stock = $this->calculateStockByItemUnitReq($reqstock, $UnitIDRequest);
|
||||
|
||||
$sqlcha = "UPDATE purchase_request_flag SET
|
||||
PurchaseRequestFlagPurchaseRequestDetailID = ?,
|
||||
PurchaseRequestFlagS_RegionalID = ?,
|
||||
PurchaseRequestFlagM_BranchCode = ?,
|
||||
PurchaseRequestFlagQty = ?,
|
||||
PurchaseRequestFlagQtyRest = ?,
|
||||
PurchaseRequestFlagStatus = ?,
|
||||
PurchaseRequestFlagUserID = ?,
|
||||
PurchaseRequestFlagLastUpdated = NOW()
|
||||
WHERE PurchaseRequestFlagID = ?";
|
||||
$query = $this->db->query($sqlcha, [
|
||||
$reqdetailid,
|
||||
$regionalid,
|
||||
$branchcode,
|
||||
$reqqty,
|
||||
$reqqty,
|
||||
$reqstatus,
|
||||
$userid,
|
||||
$reqflagid
|
||||
]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update status flag requset");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlget = "SELECT * FROM purchase_request_flag WHERE PurchaseRequestFlagID = ?";
|
||||
$queget = $this->db->query($sqlget, [$reqflagid]);
|
||||
if (!$queget) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error get data change");
|
||||
exit;
|
||||
}
|
||||
$data = $queget->result_array()[0];
|
||||
$json = json_encode($data);
|
||||
|
||||
$sqlog = "INSERT INTO acc_one_log.purchaserequestflag_log (
|
||||
PurchaseRequestFlagLogPurchaseRequestFlagID,
|
||||
PurchaseRequestFlagLogStatus,
|
||||
PurchaseRequestFlagLogQty,
|
||||
PurchaseRequestFlagLogStock,
|
||||
PurchaseRequestFlagLogJson,
|
||||
PurchaseRequestFlagLogUserID,
|
||||
PurchaseRequestFlagLogCreated
|
||||
) VALUES (?, ?, ?, ?, ?, ?, NOW())";
|
||||
$quelog = $this->db->query($sqlog, [$reqflagid, $reqstatus, $reqqty, $stock, $json, $userid]);
|
||||
if (!$quelog) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert log purchase request flag");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success");
|
||||
} catch (\Throwable $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
private function calculateStockByItemUnitReq(array $stock, string $UnitIDRequest): int
|
||||
{
|
||||
// Cek $stock empty array atau tidak, jika iya $stok = 0
|
||||
if (!is_array($stock) || empty($stock)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Cari object di $stock di mana StockItemUnitID == $UnitIDRequest,
|
||||
// Jika tidak ada, set $stock = 0
|
||||
$equivalentStock = array_filter($stock, function ($item) use ($UnitIDRequest) {
|
||||
return $item['StockItemUnitID'] == $UnitIDRequest;
|
||||
});
|
||||
|
||||
if (empty($equivalentStock)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return array_values($equivalentStock)[0]['QtyTotal'] ?? 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestApprovedDate = NOW(),
|
||||
PurchaseRequestApprovedBy = {$userId},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
|
||||
$PRDTotal = $payload['PRDAmount'] * $price;
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirect extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestDirectApprovedDate = NOW(),
|
||||
PurchaseRequestDirectApprovedBy = {$userId},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
/* $price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
*/
|
||||
|
||||
$PRDTotal = $payload['PRDAmount'] * $payload['PRDPrice'];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailRealitationPrice = {$payload['PRDPrice']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase_request_direct request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,910 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirectApproved extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?;";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalStart = $approvalLevel[0]['M_ApproveLevelStartTotal'];
|
||||
$totalEnd = $approvalLevel[0]['M_ApproveLevelEndTotal'];
|
||||
$query = "SELECT prd.*, mu.M_UserUsername as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = '{$payload["status"]}'";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = '{$payload["status"]}'";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 5;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ItemUnitID,
|
||||
ItemUnitName,
|
||||
PurchaseDirectCategoryCode,
|
||||
PurchaseDirectCategoryName,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber,
|
||||
'' as isAttachemnt,
|
||||
'' as dataAttachment
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN purchase_direct_category ON PurchaseDirectCategoryID = PurchaseRequestDirectDetailPurchaseRequestDirectCategoryID
|
||||
LEFT JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC, PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
if ($value['PurchaseDirectCategoryName'] !== "BBM") {
|
||||
$rows[$key]['PurchaseRequestDirectDetailAmount'] = intval($value['PurchaseRequestDirectDetailAmount']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailAmountRequest'] = intval($value['PurchaseRequestDirectDetailAmountRequest']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailEstimationPrice'] = intval($value['PurchaseRequestDirectDetailEstimationPrice']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailRealitationPrice'] = intval($value['PurchaseRequestDirectDetailRealitationPrice']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailTotalEstimationPrice'] = intval($value['PurchaseRequestDirectDetailTotalEstimationPrice']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailTotalRealitationPrice'] = intval($value['PurchaseRequestDirectDetailTotalRealitationPrice']);
|
||||
}
|
||||
|
||||
$sql = "SELECT PurchaseDirectAttachmentID,
|
||||
PurchaseDirectAttachmentPurchaseRequestDirectDetailID,
|
||||
PurchaseDirectAttachmentName
|
||||
FROM purchase_direct_attachment
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
AND PurchaseDirectAttachmentPurchaseRequestDirectDetailID = ?";
|
||||
$qry = $this->db->query($sql, [$value['PurchaseRequestDirectDetailID']]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_direct_attachment", $this->db);
|
||||
exit;
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rowsdata = $qry->result_array();
|
||||
|
||||
if (count($rowsdata) > 0) {
|
||||
$rows[$key]['isAttachemnt'] = true;
|
||||
$rows[$key]['dataAttachment'] = $rowsdata;
|
||||
} else {
|
||||
$rows[$key]['isAttachemnt'] = false;
|
||||
$rows[$key]['dataAttachment'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getlevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} else {
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $approvalLevel,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestDirectApprovedDate = NOW(),
|
||||
PurchaseRequestDirectApprovedBy = {$userId},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Notification
|
||||
$this->readNotif("A", $userId, $payload['PRID']);
|
||||
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di approved";
|
||||
$this->insert_act_log("PRD", "Approved", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Notification
|
||||
$this->readNotif("R", $userId, $payload['PRID']);
|
||||
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di reject";
|
||||
$this->insert_act_log("PRD", "Reject", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function unApproveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Approved'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("unapprove request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Notification
|
||||
$this->readNotif("U", $userId, $payload['PRID']);
|
||||
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di unappprove";
|
||||
$this->insert_act_log("PRD", "Unapprove", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
/* $price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
*/
|
||||
|
||||
// $PRDTotal = $payload['PRDAmount'] * $payload['PRDPrice'];
|
||||
$PRDTotal = $payload['PRDTotal'];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailRealitationPrice = {$payload['PRDPrice']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase_request_direct request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
private function safeJsonEncode($data)
|
||||
{
|
||||
// Coba encode data ke JSON
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Cek apakah terjadi error saat encode
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errorMsg = json_last_error_msg();
|
||||
error_log("JSON encode error: " . $errorMsg);
|
||||
|
||||
// Lakukan sanitasi dan perbaikan data
|
||||
$fixedData = $this->fixJsonEncodeIssues($data, $errorMsg);
|
||||
|
||||
// Coba encode lagi setelah diperbaiki
|
||||
$jsonData = json_encode($fixedData);
|
||||
|
||||
// Jika masih error, log dan kembalikan objek kosong
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("Failed to fix JSON encode issues: " . json_last_error_msg());
|
||||
// Kembalikan objek kosong jika masih gagal
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Fungsi untuk memperbaiki masalah encoding JSON
|
||||
private function fixJsonEncodeIssues($data, $errorMsg)
|
||||
{
|
||||
// Buat salinan data untuk dimodifikasi
|
||||
$fixedData = $data;
|
||||
|
||||
// Tangani berbagai jenis error
|
||||
if (strpos($errorMsg, 'Malformed UTF-8') !== false) {
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
$fixedData = $this->fixUTF8Issues($fixedData);
|
||||
} else if (strpos($errorMsg, 'Inf and NaN cannot be JSON encoded') !== false) {
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
$fixedData = $this->fixInfNanIssues($fixedData);
|
||||
} else {
|
||||
// Konversi semua nilai numerik menjadi string untuk menghindari masalah presisi
|
||||
$fixedData = $this->convertNumericValuesToStrings($fixedData);
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
$fixedData = $this->fixRecursiveReferences($fixedData);
|
||||
}
|
||||
|
||||
return $fixedData;
|
||||
}
|
||||
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
private function fixUTF8Issues($data)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->fixUTF8Issues($value);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
private function fixInfNanIssues($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_float($value) && (is_nan($value) || is_infinite($value))) {
|
||||
$data[$key] = (string)$value; // Konversi ke string
|
||||
} else if (is_array($value)) {
|
||||
$data[$key] = $this->fixInfNanIssues($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
private function fixRecursiveReferences($data, $depth = 0)
|
||||
{
|
||||
// Batasi kedalaman rekursi untuk menghindari infinite loop
|
||||
if ($depth > 50) {
|
||||
return "[MAX_DEPTH_REACHED]";
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = $this->fixRecursiveReferences($value, $depth + 1);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Cari dan konversi numerik ke string secara rekursif
|
||||
private function convertNumericValuesToStrings($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->convertNumericValuesToStrings($value);
|
||||
} else if (is_numeric($value)) {
|
||||
$data[$key] = (string)$value;
|
||||
} else if (is_bool($value)) {
|
||||
$data[$key] = $value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function insert_act_log($code, $status, $description, $refId, $data, $userId)
|
||||
{
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated)
|
||||
VALUES (?,?,?,?,?,?,?)";
|
||||
$query = $this->db->query($sql, [$code, $status, $description, $refId, $data, $userId, date("Y-m-d H:i:s")]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("user activity", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// read notification
|
||||
function readNotif($type, $userId, $refID)
|
||||
{
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
// cari user penerima notifikasi
|
||||
if ($type == "U") {
|
||||
$sql_get = "SELECT PurchaseRequestDirectID,
|
||||
M_UserID,
|
||||
M_UserUsername,
|
||||
NotificationID,
|
||||
NotificationDetailID,
|
||||
NotificationDetailStatus,
|
||||
NotificationDetailM_UserID,
|
||||
NotificationDetailM_ApproveLevelID
|
||||
FROM purchase_request_direct
|
||||
JOIN notification ON NotificationRefID = PurchaseRequestDirectID
|
||||
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||
AND NotificationDetailStatus = 'read'
|
||||
JOIN m_user ON NotificationUserID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
WHERE PurchaseRequestDirectID = ?
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql_get, [$refID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select user notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rowsuser = $qry->result_array();
|
||||
} else {
|
||||
$sql_get = "SELECT PurchaseRequestDirectID,
|
||||
M_UserID,
|
||||
M_UserUsername,
|
||||
NotificationID,
|
||||
NotificationDetailID,
|
||||
NotificationDetailStatus,
|
||||
NotificationDetailM_UserID,
|
||||
NotificationDetailM_ApproveLevelID
|
||||
FROM purchase_request_direct
|
||||
JOIN notification ON NotificationRefID = PurchaseRequestDirectID
|
||||
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||
AND NotificationDetailStatus = 'unread'
|
||||
JOIN m_user ON NotificationUserID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
WHERE PurchaseRequestDirectID = ?
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql_get, [$refID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select user notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rowsuser = $qry->result_array();
|
||||
}
|
||||
|
||||
|
||||
foreach ($rowsuser as $user) {
|
||||
|
||||
if ($type == "A") {
|
||||
// verifikasi manager
|
||||
$sql = "UPDATE notification_detail SET
|
||||
NotificationDetailStatus = 'read',
|
||||
NotificationDetailLastUpdated = NOW(),
|
||||
NotificationDetailUserID = ?
|
||||
WHERE NotificationDetailNotificationID = ?";
|
||||
$qry = $this->db->query($sql, [$userId, $user["NotificationID"]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
} else if ($type == "R") {
|
||||
$sql = "UPDATE notification_detail SET
|
||||
NotificationDetailStatus = 'read',
|
||||
NotificationDetailLastUpdated = NOW(),
|
||||
NotificationDetailUserID = ?
|
||||
WHERE NotificationDetailNotificationID = ?";
|
||||
$qry = $this->db->query($sql, [$userId, $user["NotificationID"]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
} else if ($type == "U") {
|
||||
$sql = "UPDATE notification_detail SET
|
||||
NotificationDetailStatus = 'unread',
|
||||
NotificationDetailLastUpdated = NOW(),
|
||||
NotificationDetailUserID = ?
|
||||
WHERE NotificationDetailNotificationID = ?";
|
||||
$qry = $this->db->query($sql, [$userId, $user["NotificationID"]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,815 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirectApprovedNota extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?;";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalStart = $approvalLevel[0]['M_ApproveLevelStartTotal'];
|
||||
$totalEnd = $approvalLevel[0]['M_ApproveLevelEndTotal'];
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectID IN (
|
||||
SELECT PurchaseRequestDirectDetailPurchaseRequestDirectID
|
||||
FROM purchase_direct_attachment
|
||||
JOIN purchase_request_direct_detail ON PurchaseDirectAttachmentPurchaseRequestDirectDetailID = PurchaseRequestDirectDetailID
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
)
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectID IN (
|
||||
SELECT PurchaseRequestDirectDetailPurchaseRequestDirectID
|
||||
FROM purchase_direct_attachment
|
||||
JOIN purchase_request_direct_detail ON PurchaseDirectAttachmentPurchaseRequestDirectDetailID = PurchaseRequestDirectDetailID
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
)
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber,
|
||||
'' as isAttachemnt,
|
||||
'' as dataAttachment
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql = "SELECT PurchaseDirectAttachmentID,
|
||||
PurchaseDirectAttachmentPurchaseRequestDirectDetailID,
|
||||
PurchaseDirectAttachmentName
|
||||
FROM purchase_direct_attachment
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
AND PurchaseDirectAttachmentPurchaseRequestDirectDetailID = ?";
|
||||
$qry = $this->db->query($sql, [$value['PurchaseRequestDirectDetailID']]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_direct_attachment", $this->db);
|
||||
exit;
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rowsdata = $qry->result_array();
|
||||
|
||||
if (count($rowsdata) > 0) {
|
||||
$rows[$key]['isAttachemnt'] = true;
|
||||
$rows[$key]['dataAttachment'] = $rowsdata;
|
||||
} else {
|
||||
$rows[$key]['isAttachemnt'] = false;
|
||||
$rows[$key]['dataAttachment'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getlevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} else {
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $approvalLevel,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestDirectApprovedDate = NOW(),
|
||||
PurchaseRequestDirectApprovedBy = {$userId},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di approved";
|
||||
$this->insert_act_log("PRD", "Approved", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequestNota()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNotaStatus = 'Approved',
|
||||
PurchaseRequestDirectNotaApprovedDate = NOW(),
|
||||
PurchaseRequestDirectNotaApprovedBy = {$userId},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectNotaStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$messages = "Purchase Request Direct Nota dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di approved";
|
||||
$this->insert_act_log("PRD", "Approved", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestDirectNotaStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di reject";
|
||||
$this->insert_act_log("PRD", "Reject", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
/* $price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
*/
|
||||
|
||||
$PRDTotal = $payload['PRDAmount'] * $payload['PRDPrice'];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailRealitationPrice = {$payload['PRDPrice']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase_request_direct request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
private function safeJsonEncode($data)
|
||||
{
|
||||
// Coba encode data ke JSON
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Cek apakah terjadi error saat encode
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errorMsg = json_last_error_msg();
|
||||
error_log("JSON encode error: " . $errorMsg);
|
||||
|
||||
// Lakukan sanitasi dan perbaikan data
|
||||
$fixedData = $this->fixJsonEncodeIssues($data, $errorMsg);
|
||||
|
||||
// Coba encode lagi setelah diperbaiki
|
||||
$jsonData = json_encode($fixedData);
|
||||
|
||||
// Jika masih error, log dan kembalikan objek kosong
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("Failed to fix JSON encode issues: " . json_last_error_msg());
|
||||
// Kembalikan objek kosong jika masih gagal
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Fungsi untuk memperbaiki masalah encoding JSON
|
||||
private function fixJsonEncodeIssues($data, $errorMsg)
|
||||
{
|
||||
// Buat salinan data untuk dimodifikasi
|
||||
$fixedData = $data;
|
||||
|
||||
// Tangani berbagai jenis error
|
||||
if (strpos($errorMsg, 'Malformed UTF-8') !== false) {
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
$fixedData = $this->fixUTF8Issues($fixedData);
|
||||
} else if (strpos($errorMsg, 'Inf and NaN cannot be JSON encoded') !== false) {
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
$fixedData = $this->fixInfNanIssues($fixedData);
|
||||
} else {
|
||||
// Konversi semua nilai numerik menjadi string untuk menghindari masalah presisi
|
||||
$fixedData = $this->convertNumericValuesToStrings($fixedData);
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
$fixedData = $this->fixRecursiveReferences($fixedData);
|
||||
}
|
||||
|
||||
return $fixedData;
|
||||
}
|
||||
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
private function fixUTF8Issues($data)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->fixUTF8Issues($value);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
private function fixInfNanIssues($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_float($value) && (is_nan($value) || is_infinite($value))) {
|
||||
$data[$key] = (string)$value; // Konversi ke string
|
||||
} else if (is_array($value)) {
|
||||
$data[$key] = $this->fixInfNanIssues($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
private function fixRecursiveReferences($data, $depth = 0)
|
||||
{
|
||||
// Batasi kedalaman rekursi untuk menghindari infinite loop
|
||||
if ($depth > 50) {
|
||||
return "[MAX_DEPTH_REACHED]";
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = $this->fixRecursiveReferences($value, $depth + 1);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Cari dan konversi numerik ke string secara rekursif
|
||||
private function convertNumericValuesToStrings($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->convertNumericValuesToStrings($value);
|
||||
} else if (is_numeric($value)) {
|
||||
$data[$key] = (string)$value;
|
||||
} else if (is_bool($value)) {
|
||||
$data[$key] = $value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function insert_act_log($code, $status, $description, $refId, $data, $userId)
|
||||
{
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated)
|
||||
VALUES (?,?,?,?,?,?,?)";
|
||||
$query = $this->db->query($sql, [$code, $status, $description, $refId, $data, $userId, date("Y-m-d H:i:s")]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("user activity", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
213
application/controllers/mockup/purchase/order/PurchaseOrder.http
Normal file
213
application/controllers/mockup/purchase/order/PurchaseOrder.http
Normal file
@@ -0,0 +1,213 @@
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTk1LjEyMi4yMzUiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzNy4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM3LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNi0wNCAxMzoyMDowNSIsIk1fU2F0ZWxsaXRlSUQiOjB9.hm6JtstjaQOzb7oDSXQ-oMWuX_jFQZH-HDr3r3OzPac"
|
||||
|
||||
@host = accone.aplikasi.web.id/one-api
|
||||
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/index/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0"
|
||||
}
|
||||
|
||||
###
|
||||
// listing data
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/search/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"currentPage": 1,
|
||||
"search": "",
|
||||
"startDate": "2025-06-04",
|
||||
"endDate": "2025-06-04",
|
||||
"status": "All",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get supplier
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getSupplier/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get warehouse
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "",
|
||||
"regionalId": 8,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item old
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItem_old/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search":"",
|
||||
"currentPage":1,
|
||||
"supplierID":"3",
|
||||
"itemCategoryID":"1",
|
||||
"regionalId":"6",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItem_new/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search":"",
|
||||
"currentPage":1,
|
||||
"supplierID":"7",
|
||||
"itemCategoryID":"1",
|
||||
"regionalId":"6",
|
||||
"token": {{token}}
|
||||
}
|
||||
###
|
||||
// get item
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItem/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search":"",
|
||||
"currentPage":1,
|
||||
"supplierID":"7",
|
||||
"itemCategoryID":"1",
|
||||
"regionalId":"6",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item update
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItemUpdate/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"POID": 89,
|
||||
"token": {{ token }}
|
||||
}
|
||||
|
||||
###
|
||||
// save order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/saveOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTk1LjEyMS4xOTgiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzOS4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM5LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNi0yNCAxMzoyMDo0MiIsIk1fU2F0ZWxsaXRlSUQiOjB9.8aaMsJjOaczgBzjx7wOBzQ6l8qDlPBACwxjOVUMZGx0","Date":"2025-06-24","RefNumber":"23123","SupplierID":"7","ItemCategoryID":"1","TaxPercent":0,"PaymentTerm":0,"DiscountPercent":0,"DiscountAmount":0,"WarehouseType":"Single","WarehouseID":"49","Note":"","SubTotal":12417736.5,"TaxPercentPph":0,"TaxPercentPpn":0,"TaxAmount":0,"TaxAmountPph":0,"TaxAmountPpn":0,"GrandTotal":12417736.5,"ShippingCost":0,"ShippingCostStatus":true,"Summary":[{"keyID":"10_33","M_ItemID":"10","PurchaseOrderID":0,"PurchaseOrderSummaryID":0,"M_ItemCode":null,"M_ItemDesc":"ELECSYS T PSA - 4641655190","discount":"0","discountType":"R","PoItemUnitID":"33","ItemUnitCode":"UI230033","PoItemUnitName":"DUS","TotalPoQty":3,"Price":4139245.5,"RealPrice":4139245.5,"PriceAfterDiscount":4139245.5,"Total":12417736.5,"Details":[{"PurchaseRequestFlagID":"192","BranchCode":"LE","UnprocessFlagQty":"3","PurchaseRequestDetailID":"296","PurchaseRequestID":"172","RequestQty":"3","M_ItemID":"10","M_ItemCode":null,"M_ItemDesc":"ELECSYS T PSA - 4641655190","ReqItemUnitID":"12","ReqItemUnitName":"KIT","PoItemUnitID":"33","PoItemUnitName":"DUS","Price":"4139245.5","S_RegionalName":"Surabaya Raya","S_RegionalID":"6","WarehouseID":"44","WarehouseName":"WH034 Gudang Cabang 1 - Pramita Ngagel Jaya","M_BranchName":"Pramita Ngagel Jaya","M_BranchID":"13","PurchaseRequestNumber":"PR25060081","discount":"0","discountType":"R","PoQty":1,"UnitReqPoConvertStatus":"success","UnitReqPoConvertMsg":"Berhasil mapping konversi Req 3 ke PO 1 DUS","Total":4139245.5,"keyID":"10_","DefaultPurchase":{"ItemUnitID":"33","ItemUnitCode":"UI230033","ItemUnitName":"DUS","ItemUnitMapIsPurchase":"Y","ItemUnitMapMin":"0","ItemUnitMapM_ItemID":"10","UnitConvertAmount":"10","SupplierPricePrice":"4139245.5","isPurchased":"Y"},"warehouse":{"WarehouseID":"49","WarehouseCode":"WH039","WarehouseName":"WH039 Gudang Cabang 1 - Pramita HR. Muhammad","WarehouseType":"B","WarehouseIsDefault":"Y","WarehouseS_RegionalID":"6","WarehouseM_BranchID":"18","S_RegionalID":"6","S_RegionalName":"Surabaya Raya"}},{"PurchaseRequestFlagID":"191","BranchCode":"LE","UnprocessFlagQty":"10","PurchaseRequestDetailID":"297","PurchaseRequestID":"173","RequestQty":"12","M_ItemID":"10","M_ItemCode":null,"M_ItemDesc":"ELECSYS T PSA - 4641655190","ReqItemUnitID":"12","ReqItemUnitName":"KIT","PoItemUnitID":"33","PoItemUnitName":"DUS","Price":"4139245.5","S_RegionalName":"Surabaya Raya","S_RegionalID":"6","WarehouseID":"44","WarehouseName":"WH034 Gudang Cabang 1 - Pramita Ngagel Jaya","M_BranchName":"Pramita Ngagel Jaya","M_BranchID":"13","PurchaseRequestNumber":"PR25060082","discount":"0","discountType":"R","PoQty":2,"UnitReqPoConvertStatus":"success","UnitReqPoConvertMsg":"Berhasil mapping konversi Req 12 ke PO 2 DUS","Total":8278491,"keyID":"10_","DefaultPurchase":{"ItemUnitID":"33","ItemUnitCode":"UI230033","ItemUnitName":"DUS","ItemUnitMapIsPurchase":"Y","ItemUnitMapMin":"0","ItemUnitMapM_ItemID":"10","UnitConvertAmount":"10","SupplierPricePrice":"4139245.5","isPurchased":"Y"},"warehouse":{"WarehouseID":"49","WarehouseCode":"WH039","WarehouseName":"WH039 Gudang Cabang 1 - Pramita HR. Muhammad","WarehouseType":"B","WarehouseIsDefault":"Y","WarehouseS_RegionalID":"6","WarehouseM_BranchID":"18","S_RegionalID":"6","S_RegionalName":"Surabaya Raya"}}]}]}
|
||||
|
||||
###
|
||||
// update order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/updateOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"ID": "",
|
||||
"Date": "",
|
||||
"RefNumber": "",
|
||||
"SupplierID": "",
|
||||
"TaxPercentPph": "",
|
||||
"TaxPercentPpn": "",
|
||||
"PaymentTerm": "",
|
||||
"DiscountPercent": "",
|
||||
"DiscountAmount": "",
|
||||
"WarehouseType": "",
|
||||
"WarehouseID": "",
|
||||
"Note": "",
|
||||
"SubTotal": "",
|
||||
"TaxAmount": "",
|
||||
"GrandTotal": "",
|
||||
"Details": [
|
||||
{
|
||||
"PurchaseRequestID": "",
|
||||
"PurchaseRequestDetailID": "",
|
||||
"PurchaseRequestFlagID": "",
|
||||
"ItemID": "",
|
||||
"RequestQty": "",
|
||||
"Qty": "",
|
||||
"Price": "",
|
||||
"Total": "",
|
||||
"WarehouseID": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
###
|
||||
// delete order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/deleteOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseOrderId": 48,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item update
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItemUpdate/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0",
|
||||
"supplierID": "1",
|
||||
"regionalId": "8",
|
||||
"search": ""
|
||||
}
|
||||
|
||||
###
|
||||
// request order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/requestOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0",
|
||||
"ID": ""
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return True karena UnitRequest = UnitPurchase
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [288, 289],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return True karena ada konversi dan RequestQty kelipatan UnitConvertAmount
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [288, 289, 290],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return False karena ada item yang tidak ada unitconvertnya
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [288, 289, 295],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return False karena ada item yang RequestQty bukan kelipatan UnitConvertAmount
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [291,292],
|
||||
"token": {{token}}
|
||||
}
|
||||
2432
application/controllers/mockup/purchase/order/PurchaseOrder.php
Normal file
2432
application/controllers/mockup/purchase/order/PurchaseOrder.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
<?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) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
SupplierID,
|
||||
SupplierName
|
||||
FROM supplier
|
||||
WHERE SupplierIsActive = 'Y'";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get data supplier");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getListCabang() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$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) {
|
||||
$this->sys_error_db("[Error] failed get list cabang");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function searchRequestAset() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$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) {
|
||||
$this->sys_error_db("[Error] get daftar request data");
|
||||
exit;
|
||||
}
|
||||
$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) {
|
||||
$this->sys_error_db("[Error] get total request aset");
|
||||
exit;
|
||||
}
|
||||
$total = $que_total->row_array()['total'];
|
||||
|
||||
$out = [
|
||||
"records" => $data,
|
||||
"total" => $total
|
||||
];
|
||||
|
||||
$this->sys_ok($out);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2936
application/controllers/mockup/purchase/order/PurchaseOrderV2.php
Normal file
2936
application/controllers/mockup/purchase/order/PurchaseOrderV2.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/ListingSuratJalan/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM1NCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtbWF0cmFtYW4iLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjLW9uZS1qdXJuYWxcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJNX1VzZXJMb2NhdGlvbklEIjoiMTIiLCJNX1VzZXJMb2NhdGlvbkZsYWciOiJCIiwiU19SZWdpb25hbE5hbWUiOiJKYWthcnRhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI4IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBNYXRyYW1hbiIsIk1fQnJhbmNoQ29kZSI6IkJBIiwiTV9CcmFuY2hJRCI6IjIzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMC45Ny42NCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEzNC4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTAzLTEyIDEzOjM3OjQ2IiwiTV9TYXRlbGxpdGVJRCI6MH0.i4gLQdofhvPCKYd5uHuEsYI0y_rova7BIjjAc4tbP3I",
|
||||
"startdate": "2025-03-01",
|
||||
"enddate": "2025-03-13",
|
||||
"branchcode": "ALL",
|
||||
"status": "All",
|
||||
"search": "",
|
||||
"currpage": 1
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/GetTFDataDetail/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM1NCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtbWF0cmFtYW4iLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjLW9uZS1qdXJuYWxcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJNX1VzZXJMb2NhdGlvbklEIjoiMTIiLCJNX1VzZXJMb2NhdGlvbkZsYWciOiJCIiwiU19SZWdpb25hbE5hbWUiOiJKYWthcnRhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI4IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBNYXRyYW1hbiIsIk1fQnJhbmNoQ29kZSI6IkJBIiwiTV9CcmFuY2hJRCI6IjIzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMC45Ny42NCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEzNC4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTAzLTEyIDEzOjM3OjQ2IiwiTV9TYXRlbGxpdGVJRCI6MH0.i4gLQdofhvPCKYd5uHuEsYI0y_rova7BIjjAc4tbP3I",
|
||||
"SuratJalanID": 2,
|
||||
"currpagedetail": 1
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/UpdateSuratJalan/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM1NCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtbWF0cmFtYW4iLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjLW9uZS1qdXJuYWxcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJNX1VzZXJMb2NhdGlvbklEIjoiMTIiLCJNX1VzZXJMb2NhdGlvbkZsYWciOiJCIiwiU19SZWdpb25hbE5hbWUiOiJKYWthcnRhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI4IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBNYXRyYW1hbiIsIk1fQnJhbmNoQ29kZSI6IkJBIiwiTV9CcmFuY2hJRCI6IjIzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMC45Ny42NCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEzNC4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTAzLTEyIDEzOjM3OjQ2IiwiTV9TYXRlbGxpdGVJRCI6MH0.i4gLQdofhvPCKYd5uHuEsYI0y_rova7BIjjAc4tbP3I",
|
||||
"suratJalanID": "23",
|
||||
"goodTransferID": "20",
|
||||
"notereceive": "tess",
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/GenerateJurnal/6
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/requester/PurchaseRequestPersediaan
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxNDkuMTEzLjEwMi4yOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChYMTE7IExpbnV4IHg4Nl82NDsgcnY6MTM3LjApIEdlY2tvXC8yMDEwMDEwMSBGaXJlZm94XC8xMzcuMCIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTA2LTEwIDA4OjUyOjIwIiwiTV9TYXRlbGxpdGVJRCI6MH0.C1y8mxuCzwJOXHuKFNk5mpkJ72lY2GFTjOlZ9Tx5AWc"
|
||||
|
||||
### Save and Request Purchase (Create with Pending status)
|
||||
POST {{host}}/saveAndDoPurchaseRequest
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"itemcategory": "1",
|
||||
"PRDateUse": "2025-06-15",
|
||||
"PRRegional": "REG001",
|
||||
"PRBranch": "BR001",
|
||||
"PRDescription": "Urgent office supplies needed",
|
||||
"items": [
|
||||
{
|
||||
"itemId": 101,
|
||||
"itemCode": "ITM001",
|
||||
"itemDesc": "Printer Paper A4",
|
||||
"unitId": 1,
|
||||
"unitCode": "BOX",
|
||||
"unitName": "Box",
|
||||
"qty": 5,
|
||||
"detailId": 0
|
||||
},
|
||||
{
|
||||
"itemId": 102,
|
||||
"itemCode": "ITM002",
|
||||
"itemDesc": "Stapler",
|
||||
"unitId": 2,
|
||||
"unitCode": "PCS",
|
||||
"unitName": "Pieces",
|
||||
"qty": 10,
|
||||
"detailId": 0
|
||||
}
|
||||
],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### For comparison: Regular Save Purchase Request
|
||||
POST {{host}}/savePurchaseRequest
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer YOUR_AUTH_TOKEN_HERE
|
||||
|
||||
{
|
||||
"itemcategory": "1",
|
||||
"PRDateUse": "2025-06-15",
|
||||
"PRRegional": "REG001",
|
||||
"PRBranch": "BR001",
|
||||
"PRDescription": "Regular office supplies order",
|
||||
"items": [
|
||||
{
|
||||
"itemId": 101,
|
||||
"itemCode": "ITM001",
|
||||
"itemDesc": "Printer Paper A4",
|
||||
"unitId": 1,
|
||||
"unitCode": "BOX",
|
||||
"unitName": "Box",
|
||||
"qty": 5,
|
||||
"detailId": 0
|
||||
}
|
||||
],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### For comparison: Update Purchase Request with Pending status
|
||||
POST http://localhost/accone/BE/purchase/requester/PurchaseRequestPersediaan/updatePurchaseRequest
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer YOUR_AUTH_TOKEN_HERE
|
||||
|
||||
{
|
||||
"PRID": 123,
|
||||
"PRNumber": "PR202506-001",
|
||||
"itemtype": "1",
|
||||
"PRDateUse": "2025-06-15",
|
||||
"PRRegional": "REG001",
|
||||
"PRBranch": "BR001",
|
||||
"PRDescription": "Updated office supplies",
|
||||
"act": "pending",
|
||||
"items": [
|
||||
{
|
||||
"itemId": 101,
|
||||
"itemCode": "ITM001",
|
||||
"itemDesc": "Printer Paper A4",
|
||||
"unitId": 1,
|
||||
"unitCode": "BOX",
|
||||
"unitName": "Box",
|
||||
"qty": 10,
|
||||
"detailId": 456
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Requester API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$pdSql = "SELECT `fn_numbering`('PD') AS PD";
|
||||
$exec = $this->db->query($pdSql, []);
|
||||
$pd = "";
|
||||
$dateNow = date('Y-m-d');
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$pd = $exec->result_array()[0]["PD"];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO purchase_request_direct(
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectDate,
|
||||
PurchaseRequestDirectDateUse,
|
||||
PurchaseRequestDirectM_BranchCode,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectNote,
|
||||
PurchaseRequestDirectTotalEstimation,
|
||||
PurchaseRequestDirectTotalPaid,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectStatus,
|
||||
PurchaseRequestApprovedDate,
|
||||
PurchaseRequestApprovedBy,
|
||||
PurchaseRequestConfirmedDate,
|
||||
PurchaseRequestConfirmedBy,
|
||||
PurchaseRequestPaidDate,
|
||||
PurchaseRequestPaidBy,
|
||||
PurchaseRequestDirectIsActive,
|
||||
PurchaseRequestCreated,
|
||||
PurchaseRequestLastUpdated,
|
||||
PurchaseRequestDeleted,
|
||||
PurchaseRequestCreatedUserID,
|
||||
PurchaseRequestLastUpdatedUserID,
|
||||
PurchaseRequestDeletedUserID
|
||||
) VALUES ('{$pd}', '{$dateNow}', '{$payload['PRDateUse']}', '{$payload['PRBranch']}', '{$payload['PRDescription']}', NULL, 0, 0, 0, 'Draft', NULL, NULL, NULL, NULL, NULL, NULL, 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectNumber = '{$pd}' AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectDateUse = '{$payload['PRDateUse']}',
|
||||
PurchaseRequestDirectM_BranchCode = '{$payload['PRBranch']}',
|
||||
PurchaseRequestDirectDescription = '{$payload['PRDescription']}',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newUpdate = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = {$payload['PRID']} AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newUpdate, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDeleted = NOW(),
|
||||
PurchaseRequestDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload['PRDAmountRequest']) * intval($payload['PRDEstimationPrice']);
|
||||
|
||||
$query = "SELECT COUNT(*) as exist
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDescription = '{$payload['PRDDescriptionDetail']}'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exist = $this->db->query($query, []);
|
||||
if ($exist) {
|
||||
$row = $exist->row()->exist;
|
||||
} else {
|
||||
$this->sys_error_db("exist error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row == 0) {
|
||||
$sql = "INSERT INTO purchase_request_direct_detail(
|
||||
PurchaseRequestDirectDetailPurchaseRequestDirectID,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectDetailAmountRequest,
|
||||
PurchaseRequestDirectDetailAmount,
|
||||
PurchaseRequestDirectDetailEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice,
|
||||
PurchaseRequestDirectDetailStatus,
|
||||
PurchaseRequestDirectDetailIsActive,
|
||||
PurchaseRequestDirectDetailCreated,
|
||||
PurchaseRequestDirectDetailLastUpdated,
|
||||
PurchaseRequestDirectDetailDeleted,
|
||||
PurchaseRequestDirectDetailCreatedUserID,
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID,
|
||||
PurchaseRequestDirectDetailDeletedUserID
|
||||
) VALUES ({$payload['PRID']}, '{$payload['PRDDescriptionDetail']}', {$payload['PRDAmountRequest']}, NULL, {$payload['PRDEstimationPrice']}, {$PRDTotalPrice}, NULL, 'Pending', 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($row != 0) {
|
||||
array_push($errors, array('msg' => 'Data sudah ada'));
|
||||
}
|
||||
|
||||
$result = array("total" => -1, "errors" => $errors, "records" => array('status' => 'ERROR'));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload["PRDAmountRequest"]) * intval($payload["PRDEstimationPrice"]);
|
||||
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDescription = '{$payload["PRDDescriptionDetail"]}',
|
||||
PurchaseRequestDirectDetailAmountRequest = {$payload["PRDAmountRequest"]},
|
||||
PurchaseRequestDirectDetailEstimationPrice = {$payload["PRDEstimationPrice"]},
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice = {$PRDTotalPrice},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request update error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => $payload["PRDID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectDetailIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request delete error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function orderRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailStatus = 'Pending'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$sql = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectNumber) RowNumber
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
$row = [];
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$row = $exec->result_array();
|
||||
}
|
||||
$result = array("total" => 1, "records" => $row);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,951 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirect extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Requester API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
LEFT JOIN s_regional ON S_RegionalID = PurchaseRequestDirectS_RegionalID
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestDirectM_BranchCode
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
LEFT JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ItemUnitID,
|
||||
ItemUnitName,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
LEFT JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegionalBranchByUser()
|
||||
{
|
||||
try {
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$pdSql = "SELECT `fn_numbering`('PD') AS PD";
|
||||
$exec = $this->db->query($pdSql, []);
|
||||
$pd = "";
|
||||
$dateNow = date('Y-m-d');
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$pd = $exec->result_array()[0]["PD"];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO purchase_request_direct(
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectDate,
|
||||
PurchaseRequestDirectDateUse,
|
||||
PurchaseRequestDirectS_RegionalID,
|
||||
PurchaseRequestDirectM_BranchCode,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectNote,
|
||||
PurchaseRequestDirectTotalEstimation,
|
||||
PurchaseRequestDirectTotalPaid,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectStatus,
|
||||
PurchaseRequestDirectApprovedDate,
|
||||
PurchaseRequestDirectApprovedBy,
|
||||
PurchaseRequestConfirmedDate,
|
||||
PurchaseRequestConfirmedBy,
|
||||
PurchaseRequestPaidDate,
|
||||
PurchaseRequestPaidBy,
|
||||
PurchaseRequestDirectIsActive,
|
||||
PurchaseRequestCreated,
|
||||
PurchaseRequestLastUpdated,
|
||||
PurchaseRequestDeleted,
|
||||
PurchaseRequestCreatedUserID,
|
||||
PurchaseRequestLastUpdatedUserID,
|
||||
PurchaseRequestDeletedUserID
|
||||
) VALUES ('{$pd}', '{$dateNow}', '{$payload['PRDateUse']}', '{$payload['PRRegional']}', '{$payload['PRBranch']}', '{$payload['PRDescription']}', NULL, 0, 0, 0, 'Draft', NULL, NULL, NULL, NULL, NULL, NULL, 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$prId = $this->db->insert_id();
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = '{$prId}' AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$sql = "SELECT * FROM purchase_request_direct
|
||||
JOIN m_user ON M_UserID = PurchaseRequestCreatedUserID
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
$row = $query->row_array();
|
||||
$data = array("header" => $row);
|
||||
$message = "Nomor PRD: " . $row["PurchaseRequestDirectNumber"] . " berhasil dibuat oleh " . $row["M_UserUsername"];
|
||||
$this->insert_act_log("PRD", "NEW", $message, $prId, $this->safeJsonEncode($data), $userId);
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$messages_log = [];
|
||||
$datas_log = [];
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$prDateUse = isset($payload["PRDateUse"]) ? $payload["PRDateUse"] : "";
|
||||
$prId = isset($payload["PRID"]) ? $payload["PRID"] : "";
|
||||
$prDateUse = date("Y-m-d", strtotime($prDateUse));
|
||||
if ($prDateUse == "" || $prDateUse == null) {
|
||||
$this->sys_error("Invalid PR Date Use");
|
||||
exit;
|
||||
}
|
||||
$prDescription = isset($payload["PRDescription"]) ? $payload["PRDescription"] : "";
|
||||
$PRBranch = isset($payload["PRBranch"]) ? $payload["PRBranch"] : "";
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request direct", $this->db);
|
||||
exit;
|
||||
}
|
||||
$row = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $row;
|
||||
|
||||
if ($row["PurchaseRequestDirectDateUse"] != $prDateUse) {
|
||||
$messages_log[] = "Perubahan tanggal PR: " . $row["PurchaseRequestDirectDateUse"] . " menjadi " . $prDateUse;
|
||||
}
|
||||
if ($row["PurchaseRequestDirectDescription"] != $prDescription) {
|
||||
$messages_log[] = "Perubahan keterangan PR: " . $row["PurchaseRequestDirectDescription"] . " menjadi " . $prDescription;
|
||||
}
|
||||
if ($row["PurchaseRequestDirectM_BranchCode"] != $PRBranch) {
|
||||
$messages_log[] = "Perubahan kode cabang PR: " . $row["PurchaseRequestDirectM_BranchCode"] . " menjadi " . $PRBranch;
|
||||
}
|
||||
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectDateUse = '{$payload['PRDateUse']}',
|
||||
PurchaseRequestDirectM_BranchCode = '{$payload['PRBranch']}',
|
||||
PurchaseRequestDirectDescription = '{$payload['PRDescription']}',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newUpdate = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = {$payload['PRID']} AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newUpdate, [])->result_array();
|
||||
|
||||
if (count($messages_log) > 0) {
|
||||
$message = "Perubahan PR Pembelian Langsung: " . $prNumber . "\n";
|
||||
$message .= implode("\n", $messages_log);
|
||||
} else {
|
||||
$message = "PR Pembelian Langsung: " . $prNumber . " tanpa perubahan";
|
||||
}
|
||||
|
||||
$datas_log = $this->convertNumericValuesToStrings($datas_log);
|
||||
$this->insert_act_log("PRNP", "Update", $message, $prId, $this->safeJsonEncode($datas_log), $userId);
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$prId = $payload['PRID'];
|
||||
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON ItemUnitID = PurchaseRequestDirectDetailItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDeleted = NOW(),
|
||||
PurchaseRequestDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectDetailIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$messages = "Purchase Request Pembelian langsung dengan kode " . $header["PurchaseRequestDirectNumber"] . " sudah dihapus";
|
||||
$this->insert_act_log("PRNP", "Delete", $messages, $prId, $this->safeJsonEncode($datas_log), $userId);
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload['PRDAmountRequest']) * intval($payload['PRDEstimationPrice']);
|
||||
|
||||
$query = "SELECT COUNT(*) as exist
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDescription = '{$payload['PRDDescriptionDetail']}'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exist = $this->db->query($query, []);
|
||||
if ($exist) {
|
||||
$row = $exist->row()->exist;
|
||||
} else {
|
||||
$this->sys_error_db("exist error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row == 0) {
|
||||
$sql = "INSERT INTO purchase_request_direct_detail(
|
||||
PurchaseRequestDirectDetailPurchaseRequestDirectID,
|
||||
PurchaseRequestDirectDetailItemUnitID,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectDetailAmountRequest,
|
||||
PurchaseRequestDirectDetailAmount,
|
||||
PurchaseRequestDirectDetailEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice,
|
||||
PurchaseRequestDirectDetailStatus,
|
||||
PurchaseRequestDirectDetailIsActive,
|
||||
PurchaseRequestDirectDetailCreated,
|
||||
PurchaseRequestDirectDetailLastUpdated,
|
||||
PurchaseRequestDirectDetailDeleted,
|
||||
PurchaseRequestDirectDetailCreatedUserID,
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID,
|
||||
PurchaseRequestDirectDetailDeletedUserID
|
||||
) VALUES ({$payload['PRID']}, {$payload['PRDItemUnitID']}, '{$payload['PRDDescriptionDetail']}', {$payload['PRDAmountRequest']}, NULL, {$payload['PRDEstimationPrice']}, {$PRDTotalPrice}, NULL, 'Pending', 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
$prId = $payload['PRID'];
|
||||
$sql = "SELECT * FROM purchase_request_direct
|
||||
JOIN m_user ON M_UserID = PurchaseRequestCreatedUserID
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
$row = $query->row_array();
|
||||
|
||||
$sql = "SELECT * FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ?";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
$rows = $query->row_array();
|
||||
|
||||
$data = array(
|
||||
"header" => $row,
|
||||
"details" => $rows
|
||||
);
|
||||
$message = "Penambahan Item Nomor PRD: " . $row["PurchaseRequestDirectNumber"] . " oleh " . $row["M_UserUsername"]
|
||||
. " Item : " . $payload['PRDDescriptionDetail'] . " jumlah : " . $payload['PRDAmountRequest'] . "harga : " . $payload['PRDAmountRequest'];
|
||||
$this->insert_act_log("PRD", "NEW", $message, $prId, $this->safeJsonEncode($data), $userId);
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($row != 0) {
|
||||
array_push($errors, array('msg' => 'Data sudah ada'));
|
||||
}
|
||||
|
||||
$result = array("total" => -1, "errors" => $errors, "records" => array('status' => 'ERROR'));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload["PRDAmountRequest"]) * intval($payload["PRDEstimationPrice"]);
|
||||
|
||||
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailItemUnitID = {$payload["PRDItemUnitID"]},
|
||||
PurchaseRequestDirectDescription = '{$payload["PRDDescriptionDetail"]}',
|
||||
PurchaseRequestDirectDetailAmountRequest = {$payload["PRDAmountRequest"]},
|
||||
PurchaseRequestDirectDetailEstimationPrice = {$payload["PRDEstimationPrice"]},
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice = {$PRDTotalPrice},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request update error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => $payload["PRDID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectDetailIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request delete error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function orderRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailStatus = 'Pending'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$sql = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectNumber) RowNumber
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
$row = [];
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$row = $exec->result_array();
|
||||
}
|
||||
$result = array("total" => 1, "records" => $row);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUnit()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
|
||||
$sql = "SELECT
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ItemUnitCreated,
|
||||
ItemUnitLastUpdated,
|
||||
ItemUnitIsActive,
|
||||
ItemUnitUserID
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName LIKE '%$search%'
|
||||
ORDER BY ItemUnitName ASC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("item unit list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function insert_act_log($code, $status, $description, $refId, $data, $userId)
|
||||
{
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated)
|
||||
VALUES (?,?,?,?,?,?,?)";
|
||||
$query = $this->db->query($sql, [$code, $status, $description, $refId, $data, $userId, date("Y-m-d H:i:s")]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("user activity", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
private function safeJsonEncode($data)
|
||||
{
|
||||
// Coba encode data ke JSON
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Cek apakah terjadi error saat encode
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errorMsg = json_last_error_msg();
|
||||
error_log("JSON encode error: " . $errorMsg);
|
||||
|
||||
// Lakukan sanitasi dan perbaikan data
|
||||
$fixedData = $this->fixJsonEncodeIssues($data, $errorMsg);
|
||||
|
||||
// Coba encode lagi setelah diperbaiki
|
||||
$jsonData = json_encode($fixedData);
|
||||
|
||||
// Jika masih error, log dan kembalikan objek kosong
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("Failed to fix JSON encode issues: " . json_last_error_msg());
|
||||
// Kembalikan objek kosong jika masih gagal
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Fungsi untuk memperbaiki masalah encoding JSON
|
||||
private function fixJsonEncodeIssues($data, $errorMsg)
|
||||
{
|
||||
// Buat salinan data untuk dimodifikasi
|
||||
$fixedData = $data;
|
||||
|
||||
// Tangani berbagai jenis error
|
||||
if (strpos($errorMsg, 'Malformed UTF-8') !== false) {
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
$fixedData = $this->fixUTF8Issues($fixedData);
|
||||
} else if (strpos($errorMsg, 'Inf and NaN cannot be JSON encoded') !== false) {
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
$fixedData = $this->fixInfNanIssues($fixedData);
|
||||
} else {
|
||||
// Konversi semua nilai numerik menjadi string untuk menghindari masalah presisi
|
||||
$fixedData = $this->convertNumericValuesToStrings($fixedData);
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
$fixedData = $this->fixRecursiveReferences($fixedData);
|
||||
}
|
||||
|
||||
return $fixedData;
|
||||
}
|
||||
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
private function fixUTF8Issues($data)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->fixUTF8Issues($value);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
private function fixInfNanIssues($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_float($value) && (is_nan($value) || is_infinite($value))) {
|
||||
$data[$key] = (string)$value; // Konversi ke string
|
||||
} else if (is_array($value)) {
|
||||
$data[$key] = $this->fixInfNanIssues($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
private function fixRecursiveReferences($data, $depth = 0)
|
||||
{
|
||||
// Batasi kedalaman rekursi untuk menghindari infinite loop
|
||||
if ($depth > 50) {
|
||||
return "[MAX_DEPTH_REACHED]";
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = $this->fixRecursiveReferences($value, $depth + 1);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Cari dan konversi numerik ke string secara rekursif
|
||||
private function convertNumericValuesToStrings($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->convertNumericValuesToStrings($value);
|
||||
} else if (is_numeric($value)) {
|
||||
$data[$key] = (string)$value;
|
||||
} else if (is_bool($value)) {
|
||||
$data[$key] = $value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1348
application/controllers/mockup/purchase/suratjalan/SuratJalan.php
Normal file
1348
application/controllers/mockup/purchase/suratjalan/SuratJalan.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,540 @@
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTkyLjE0OS4xODYiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzOS4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM5LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNy0wOCAxMDo0MjoyMCIsIk1fU2F0ZWxsaXRlSUQiOjB9.0_H99mFpJ4ij8tgaWGmR85T16r_55il3q7bY1RRJ_JQ"
|
||||
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/transfer/TransferRequest
|
||||
|
||||
### get branches
|
||||
POST {{host}}/getBranches/
|
||||
|
||||
{
|
||||
"S_RegionalID": 8,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### get status
|
||||
GET {{ host }}/getStatus
|
||||
|
||||
{
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### search
|
||||
POST {{ host }}/search
|
||||
|
||||
{
|
||||
"startDate": "2025-01-01",
|
||||
"endDate": "2025-02-28",
|
||||
"M_BranchCode": "BA",
|
||||
"StatusName": "",
|
||||
"current_page": 0,
|
||||
"search": "",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### getDraftDetail
|
||||
POST {{host}}/getDraftDetail
|
||||
|
||||
{
|
||||
"token" : {{token}},
|
||||
"goodTfID" : 30
|
||||
}
|
||||
|
||||
### delete
|
||||
POST {{ host }}/deleteTfRequest
|
||||
|
||||
{
|
||||
"GoodsTfID": 1,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### get details
|
||||
POST {{ host }}/getDetails
|
||||
|
||||
{
|
||||
"S_RegionalID": 8,
|
||||
"M_BranchCode": "BA",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
|
||||
### Get List Detail
|
||||
POST {{host}}/getListDetail
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"currpage":1,
|
||||
"regionalid":"6",
|
||||
"branchcodedestin":"LA",
|
||||
"branchIDorigin":"0"
|
||||
}
|
||||
|
||||
### Get Batch Listing
|
||||
POST {{host}}/getItemBatchListing
|
||||
|
||||
{
|
||||
"itemid":"1",
|
||||
"unitid":"33",
|
||||
"batchno":"",
|
||||
"token": {{token}},
|
||||
"regionalid":"6",
|
||||
"branchid":"0"
|
||||
}
|
||||
|
||||
### Unpack Stock
|
||||
POST {{host}}/unpackingStock
|
||||
|
||||
{
|
||||
"StockStockNumber" : "SN2507006",
|
||||
"StockBatchNo" : "B20250701002",
|
||||
"UnpackQty" : 2,
|
||||
"ToItemUnitID" : 2,
|
||||
"UnitConvertAmount" : 10,
|
||||
"token" : {{token}},
|
||||
"isDebug" : true
|
||||
}
|
||||
|
||||
### Create TF Request
|
||||
### 1 Item 1 Batch
|
||||
POST {{host}}/createTFRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID" : "6",
|
||||
"M_BranchCode" : "LA",
|
||||
"GoodsTfNotes" : "Req 5 BOTOL, TF 2 BOTOL",
|
||||
"GoodsTfDate" : "2025-07-03",
|
||||
"GoodsTfStatus" : "Draft",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-06-30",
|
||||
"PurchaseRequestNumber": "PR25060105",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "2",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"RequestItemUnitID": "2",
|
||||
"RequestItemUnitName": "BOTOL",
|
||||
"PurchaseRequestFlagID": "22",
|
||||
"PurchaseRequestFlagQty": "5",
|
||||
"PurchaseRequestFlagQtyRest": 2,
|
||||
"PurchaseRequestFlagStatus": "TF,PO",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "11",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "1761914"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "2",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemPrice": "1761914"
|
||||
}
|
||||
],
|
||||
"MustUnpack": false,
|
||||
"UnpackData": {
|
||||
"CanUnpack": true,
|
||||
"Reason": "Direct unit match available - no conversion needed"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "40",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "2",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockItemPrice": "176191.4",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "10",
|
||||
"QtyReq": "2"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 2
|
||||
}
|
||||
],
|
||||
"isDebug": true
|
||||
}
|
||||
|
||||
|
||||
### Create TF Request
|
||||
### 2 Item each 1 Batch
|
||||
POST {{host}}/createTFRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID": "6",
|
||||
"M_BranchCode": "LA",
|
||||
"GoodsTfNotes": "",
|
||||
"GoodsTfDate": "2025-07-03",
|
||||
"GoodsTfStatus": "Draft",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-06-26",
|
||||
"PurchaseRequestNumber": "PR25060096",
|
||||
"PurchaseRequestDetailM_ItemID": "13",
|
||||
"PurchaseRequestDetailItemUnitID": "3",
|
||||
"M_ItemDesc": "VITEX 2 GN - 21341",
|
||||
"RequestItemUnitID": "3",
|
||||
"RequestItemUnitName": "BOX",
|
||||
"PurchaseRequestFlagID": "13",
|
||||
"PurchaseRequestFlagQty": "2",
|
||||
"PurchaseRequestFlagQtyRest": 2,
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockItemUnitID": "3",
|
||||
"StockItemUnitName": "BOX",
|
||||
"StockQty": "6",
|
||||
"StockBatchNo": "B20250626005",
|
||||
"StockED": "2025-12-31",
|
||||
"StockStockNumber": "SN2506069",
|
||||
"StockItemPrice": "0"
|
||||
}
|
||||
],
|
||||
"MustUnpack": false,
|
||||
"UnpackData": {
|
||||
"CanUnpack": true,
|
||||
"Reason": "Direct unit match available - no conversion needed"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "9",
|
||||
"StockStockNumber": "SN2506069",
|
||||
"StockItemID": "13",
|
||||
"StockItemUnitID": "3",
|
||||
"ItemUnitName": "BOX",
|
||||
"StockItemPrice": "0",
|
||||
"StockBatchNo": "B20250626005",
|
||||
"StockED": "2025-12-31",
|
||||
"StockQty": "6",
|
||||
"QtyReq": "2"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 2
|
||||
},
|
||||
{
|
||||
"PurchaseRequestDate": "2025-06-30",
|
||||
"PurchaseRequestNumber": "PR25060105",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "2",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"RequestItemUnitID": "2",
|
||||
"RequestItemUnitName": "BOTOL",
|
||||
"PurchaseRequestFlagID": "22",
|
||||
"PurchaseRequestFlagQty": "5",
|
||||
"PurchaseRequestFlagQtyRest": 4,
|
||||
"PurchaseRequestFlagStatus": "TF,PO",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "11",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "1761914"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "2",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemPrice": "1761914"
|
||||
}
|
||||
],
|
||||
"MustUnpack": false,
|
||||
"UnpackData": {
|
||||
"CanUnpack": true,
|
||||
"Reason": "Direct unit match available - no conversion needed"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "40",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "2",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockItemPrice": "176191.4",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "10",
|
||||
"QtyReq": "4"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 4
|
||||
}
|
||||
],
|
||||
"isDebug": true
|
||||
}
|
||||
|
||||
### Create TF Request
|
||||
POST {{host}}/createTFRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID": "6",
|
||||
"M_BranchCode": "LA",
|
||||
"GoodsTfNotes": "Tes ambil req",
|
||||
"GoodsTfDate": "2025-07-08",
|
||||
"GoodsTfStatus": "Verified",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070019",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "33",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"RequestItemUnitID": "33",
|
||||
"RequestItemUnitName": "DUS",
|
||||
"PurchaseRequestFlagID": "61",
|
||||
"PurchaseRequestFlagQty": "2",
|
||||
"PurchaseRequestFlagQtyRest": 2,
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockID": "23",
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "9",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507006",
|
||||
"StockItemPrice": "1761914"
|
||||
},
|
||||
{
|
||||
"StockID": "47",
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "5",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507018",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockID": "53",
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2507024",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockID": "17",
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "1",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemPrice": "1761914"
|
||||
}
|
||||
],
|
||||
"CanDirectUse": true,
|
||||
"CanUnpack": false,
|
||||
"UnpackData": {
|
||||
"M_ItemID": "1",
|
||||
"CanUnpack": false,
|
||||
"ReasonCannotUnpack": "Tidak ditemukan konversi dari unit stock yang tersedia ke unit request DUS"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "23",
|
||||
"StockStockNumber": "SN2507006",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "33",
|
||||
"ItemUnitName": "DUS",
|
||||
"StockItemPrice": "1761914",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "9",
|
||||
"QtyReq": "1"
|
||||
},
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "17",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "33",
|
||||
"ItemUnitName": "DUS",
|
||||
"StockItemPrice": "1761914",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockQty": "1",
|
||||
"QtyReq": "1"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 2
|
||||
},
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070020",
|
||||
"PurchaseRequestDetailM_ItemID": "2",
|
||||
"PurchaseRequestDetailItemUnitID": "3",
|
||||
"M_ItemDesc": "STANDART F NS 1 Ag FIA - SD BIOSENSOR ( 10DEN10D )",
|
||||
"RequestItemUnitID": "3",
|
||||
"RequestItemUnitName": "BOX",
|
||||
"PurchaseRequestFlagID": "62",
|
||||
"PurchaseRequestFlagQty": "1",
|
||||
"PurchaseRequestFlagQtyRest": 1,
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockID": "50",
|
||||
"StockItemUnitID": "29",
|
||||
"StockItemUnitName": "TES",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockStockNumber": "SN2507021",
|
||||
"StockItemPrice": "17848.8"
|
||||
},
|
||||
{
|
||||
"StockID": "49",
|
||||
"StockItemUnitID": "3",
|
||||
"StockItemUnitName": "BOX",
|
||||
"StockQty": "2",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockStockNumber": "SN2507020",
|
||||
"StockItemPrice": "89244"
|
||||
}
|
||||
],
|
||||
"CanDirectUse": true,
|
||||
"CanUnpack": false,
|
||||
"UnpackData": {
|
||||
"M_ItemID": "2",
|
||||
"CanUnpack": false,
|
||||
"ReasonCannotUnpack": "Tidak ditemukan konversi dari unit stock yang tersedia ke unit request BOX"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "49",
|
||||
"StockStockNumber": "SN2507020",
|
||||
"StockItemID": "2",
|
||||
"StockItemUnitID": "3",
|
||||
"ItemUnitName": "BOX",
|
||||
"StockItemPrice": "89244",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockQty": "2",
|
||||
"QtyReq": "1"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
### Update TF Request
|
||||
POST {{host}}/updateTfRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID": "6",
|
||||
"M_BranchCode": "LE",
|
||||
"GoodsTfID": "27",
|
||||
"GoodsTfNum": "TRB202507080008",
|
||||
"GoodsTfNotes": "Test Update lalu Verif",
|
||||
"GoodsTfDate": "2025-07-08",
|
||||
"GoodsTfStatus": "Verified",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070021",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "2",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockGudang": "23",
|
||||
"PurchaseRequestFlagID": "63",
|
||||
"PurchaseRequestFlagQty": "15",
|
||||
"PurchaseRequestFlagQtyRest": "5",
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "47",
|
||||
"StockStockNumber": "SN2507018",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "2",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockItemPrice": "176191.4",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "5",
|
||||
"QtyReq": "5"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070022",
|
||||
"PurchaseRequestDetailM_ItemID": "2",
|
||||
"PurchaseRequestDetailItemUnitID": "29",
|
||||
"M_ItemDesc": "STANDART F NS 1 Ag FIA - SD BIOSENSOR ( 10DEN10D )",
|
||||
"ItemUnitName": "TES",
|
||||
"StockGudang": "11",
|
||||
"PurchaseRequestFlagID": "64",
|
||||
"PurchaseRequestFlagQty": "5",
|
||||
"PurchaseRequestFlagQtyRest": "5",
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "50",
|
||||
"StockStockNumber": "SN2507021",
|
||||
"StockItemID": "2",
|
||||
"StockItemUnitID": "29",
|
||||
"ItemUnitName": "TES",
|
||||
"StockItemPrice": "17848.8",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockQty": "10",
|
||||
"QtyReq": "5"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1740
application/controllers/mockup/purchase/transfer/TransferRequest.php
Normal file
1740
application/controllers/mockup/purchase/transfer/TransferRequest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/transfer/TransferRequestNP/createTfRequest
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTkyLjE0OS4xODYiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzOS4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM5LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNy0wOCAxMDo0MjoyMCIsIk1fU2F0ZWxsaXRlSUQiOjB9.0_H99mFpJ4ij8tgaWGmR85T16r_55il3q7bY1RRJ_JQ"
|
||||
|
||||
###
|
||||
POST {{host}}/createTfRequest
|
||||
|
||||
{"token": {{token}},"S_RegionalID":"6","M_BranchCode":"LA","DivisionID":"12","GoodsTfNotes":"Tes create langsung verif","GoodsTfDate":"2025-07-08","GoodsTfStatus":"Verified","detail":[{"PurchaseRequestDate":"2025-07-08","PurchaseRequestNumber":"PR25070024","PurchaseRequestDetailM_ItemID":"33","PurchaseRequestDetailItemUnitID":"19","M_ItemDesc":"MEJA KERJA","ItemUnitName":"PCS","PurchaseRequestFlagID":"67","PurchaseRequestFlagQty":"2","PurchaseRequestFlagQtyRest":2,"StockGudang":"10","PurchaseRequestFlagStatus":"TF","ItemRequest":[{"WarehouseID":"9","WarehouseName":"Gudang Regional 1","StockID":"13","StockStockNumber":"SN2506073","StockWarehouseID":"9","StockItemID":"33","StockItemUnitID":"19","StockItemPrice":"300000","ItemUnitName":"PCS","StockQty":"10","QtyReq":"2"}],"QtyFilled":2},{"PurchaseRequestDate":"2025-07-08","PurchaseRequestNumber":"PR25070025","PurchaseRequestDetailM_ItemID":"35","PurchaseRequestDetailItemUnitID":"19","M_ItemDesc":"MEJA KOMPUTER","ItemUnitName":"PCS","PurchaseRequestFlagID":"68","PurchaseRequestFlagQty":"2","PurchaseRequestFlagQtyRest":1,"StockGudang":"8","PurchaseRequestFlagStatus":"TF","ItemRequest":[{"WarehouseID":"9","WarehouseName":"Gudang Regional 1","StockID":"12","StockStockNumber":"SN2506072","StockWarehouseID":"9","StockItemID":"35","StockItemUnitID":"19","StockItemPrice":"450000","ItemUnitName":"PCS","StockQty":"8","QtyReq":"1"}],"QtyFilled":1}]}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user