be crud m_ruangan
This commit is contained in:
@@ -2135,7 +2135,7 @@ class Mediajurnalauto extends MY_Controller
|
|||||||
M_BranchName, S_RegionalName
|
M_BranchName, S_RegionalName
|
||||||
FROM m_branch
|
FROM m_branch
|
||||||
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID
|
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID
|
||||||
WHERE M_BranchCode = ? ";
|
WHERE M_BranchCode = ? AND M_BranchIsActive = 'Y'";
|
||||||
$qry = $this->db->query($sql, [$branchCode]);
|
$qry = $this->db->query($sql, [$branchCode]);
|
||||||
|
|
||||||
$regID = $qry->row()->M_BranchS_RegionalID;
|
$regID = $qry->row()->M_BranchS_RegionalID;
|
||||||
|
|||||||
301
application/controllers/mockup/masterdata/accounting/Ruangan.php
Normal file
301
application/controllers/mockup/masterdata/accounting/Ruangan.php
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
<?php
|
||||||
|
class Ruangan extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db;
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
function index()
|
||||||
|
{
|
||||||
|
echo "API Ruangan";
|
||||||
|
}
|
||||||
|
|
||||||
|
function lookupRuangan()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception('Invalid token');
|
||||||
|
}
|
||||||
|
|
||||||
|
$para = $this->sys_input;
|
||||||
|
|
||||||
|
$keyword = "%";
|
||||||
|
if (isset($para['keyword'])) {
|
||||||
|
$keyword .= $para['keyword'] . "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit = 10;
|
||||||
|
$offset = 0;
|
||||||
|
if ($para['latestPage'] > 0) {
|
||||||
|
$offset = ($para['latestPage'] - 1) * $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
r.M_RuanganID AS id,
|
||||||
|
r.M_RuanganM_BranchID AS branch_id,
|
||||||
|
b.M_BranchName AS branch_name,
|
||||||
|
b.M_BranchCode AS branch_code,
|
||||||
|
r.M_RuanganCode AS code,
|
||||||
|
r.M_RuanganName AS name,
|
||||||
|
r.M_RuanganUserID AS user_id,
|
||||||
|
r.M_RuanganCreated AS created,
|
||||||
|
r.M_RuanganLastUpdated AS last_updated
|
||||||
|
FROM m_ruangan r
|
||||||
|
JOIN m_branch b
|
||||||
|
ON b.M_BranchID = r.M_RuanganM_BranchID
|
||||||
|
AND b.M_BranchIsActive = 'Y'
|
||||||
|
JOIN s_regional s
|
||||||
|
ON s.S_RegionalID = b.M_BranchS_RegionalID
|
||||||
|
WHERE r.M_RuanganIsActive = 'Y'
|
||||||
|
AND s.S_RegionalID = ?
|
||||||
|
AND (? = 0 OR r.M_RuanganM_BranchID = ?)
|
||||||
|
AND ( r.M_RuanganName LIKE ? OR r.M_RuanganCode LIKE ?)";
|
||||||
|
|
||||||
|
$sql_data = $sql . " ORDER BY r.M_RuanganName ASC LIMIT ? OFFSET ? ";
|
||||||
|
$que_data = $this->db->query($sql_data, [
|
||||||
|
$para['regionalID'],
|
||||||
|
$para['branchID'],
|
||||||
|
$para['branchID'],
|
||||||
|
$keyword,
|
||||||
|
$keyword,
|
||||||
|
$limit,
|
||||||
|
$offset
|
||||||
|
]);
|
||||||
|
if (!$que_data) {
|
||||||
|
throw new Exception('failed to query data ruangan', 1);
|
||||||
|
}
|
||||||
|
$data = $que_data->result_array();
|
||||||
|
|
||||||
|
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||||
|
$que_total = $this->db->query($sql_total, [
|
||||||
|
$para['regionalID'],
|
||||||
|
$para['branchID'],
|
||||||
|
$para['branchID'],
|
||||||
|
$keyword,
|
||||||
|
$keyword,
|
||||||
|
]);
|
||||||
|
if (!$que_total) {
|
||||||
|
throw new Exception('failed to query total data ruangan', 1);
|
||||||
|
}
|
||||||
|
$total = $que_total->row_array()['total'];
|
||||||
|
|
||||||
|
$this->sys_ok([
|
||||||
|
"records" => $data,
|
||||||
|
"total" => $total
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$msg = '[Error] ' . $e->getMessage();
|
||||||
|
$code = $e->getCode();
|
||||||
|
if ($code == 0) {
|
||||||
|
$this->sys_error($msg);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($msg);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertRuangan()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception('Invalid token');
|
||||||
|
}
|
||||||
|
|
||||||
|
$para = $this->sys_input;
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
|
||||||
|
$sql_check = "SELECT COUNT(*) AS exist
|
||||||
|
FROM m_ruangan
|
||||||
|
WHERE M_RuanganIsActive = 'Y'
|
||||||
|
AND M_RuanganM_BranchID = ?
|
||||||
|
AND M_RuanganCode = ?";
|
||||||
|
|
||||||
|
$que_check = $this->db->query($sql_check, [
|
||||||
|
$para['branchID'],
|
||||||
|
$para['ruanganCode']
|
||||||
|
]);
|
||||||
|
if (!$que_check) {
|
||||||
|
throw new Exception('failed to check duplicate ruangan', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($que_check->row_array()['exist'] > 0) {
|
||||||
|
throw new Exception('ruangan already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO m_ruangan (
|
||||||
|
M_RuanganM_BranchID,
|
||||||
|
M_RuanganName,
|
||||||
|
M_RuanganCode,
|
||||||
|
M_RuanganUserID,
|
||||||
|
M_RuanganIsActive,
|
||||||
|
M_RuanganCreated,
|
||||||
|
M_RuanganLastUpdated
|
||||||
|
) VALUES (?,?,?,?,'Y',NOW(),NOW())";
|
||||||
|
|
||||||
|
$que = $this->db->query($sql, [
|
||||||
|
$para['branchID'],
|
||||||
|
$para['ruanganName'],
|
||||||
|
$para['ruanganCode'],
|
||||||
|
$userid
|
||||||
|
]);
|
||||||
|
if (!$que) {
|
||||||
|
throw new Exception('failed to insert ruangan', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insert_id = $this->db->insert_id();
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
|
||||||
|
$this->sys_ok([
|
||||||
|
"records" => [
|
||||||
|
"id" => $insert_id,
|
||||||
|
"name" => $para['ruanganName'],
|
||||||
|
"msg" => "Success Insert Ruangan"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
|
||||||
|
$msg = '[Error] ' . $e->getMessage();
|
||||||
|
$code = $e->getCode();
|
||||||
|
if ($code == 0) {
|
||||||
|
$this->sys_error($msg);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($msg);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRuangan()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception('Invalid token');
|
||||||
|
}
|
||||||
|
|
||||||
|
$para = $this->sys_input;
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
|
||||||
|
$sql_check = "SELECT COUNT(*) AS exist
|
||||||
|
FROM m_ruangan
|
||||||
|
WHERE M_RuanganIsActive = 'Y'
|
||||||
|
AND M_RuanganM_BranchID = ?
|
||||||
|
AND M_RuanganCode = ?
|
||||||
|
AND M_RuanganID != ?";
|
||||||
|
|
||||||
|
$que_check = $this->db->query($sql_check, [
|
||||||
|
$para['branchID'],
|
||||||
|
$para['ruanganCode'],
|
||||||
|
$para['ruanganID']
|
||||||
|
]);
|
||||||
|
if (!$que_check) {
|
||||||
|
throw new Exception('failed to check duplicate ruangan', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($que_check->row_array()['exist'] > 0) {
|
||||||
|
throw new Exception('ruangan already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE m_ruangan
|
||||||
|
SET
|
||||||
|
M_RuanganM_BranchID = ?,
|
||||||
|
M_RuanganName = ?,
|
||||||
|
M_RuanganCode = ?,
|
||||||
|
M_RuanganUserID = ?,
|
||||||
|
M_RuanganLastUpdated = NOW()
|
||||||
|
WHERE M_RuanganID = ?
|
||||||
|
AND M_RuanganIsActive = 'Y'";
|
||||||
|
|
||||||
|
$que = $this->db->query($sql, [
|
||||||
|
$para['branchID'],
|
||||||
|
$para['ruanganName'],
|
||||||
|
$para['ruanganCode'],
|
||||||
|
$userid,
|
||||||
|
$para['ruanganID']
|
||||||
|
]);
|
||||||
|
if (!$que) {
|
||||||
|
throw new Exception('failed to update ruangan', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
|
||||||
|
$this->sys_ok([
|
||||||
|
"records" => [
|
||||||
|
"id" => $para['ruanganID'],
|
||||||
|
"name" => $para['ruanganName'],
|
||||||
|
"msg" => "Success Update Ruangan"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
|
||||||
|
$msg = '[Error] ' . $e->getMessage();
|
||||||
|
$code = $e->getCode();
|
||||||
|
if ($code == 0) {
|
||||||
|
$this->sys_error($msg);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($msg);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteRuangan()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception('Invalid token');
|
||||||
|
}
|
||||||
|
|
||||||
|
$para = $this->sys_input;
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
|
||||||
|
$sql = "UPDATE m_ruangan
|
||||||
|
SET
|
||||||
|
M_RuanganIsActive = 'N',
|
||||||
|
M_RuanganUserID = ?,
|
||||||
|
M_RuanganDeleted = NOW(),
|
||||||
|
M_RuanganLastUpdated = NOW()
|
||||||
|
WHERE M_RuanganID = ?
|
||||||
|
AND M_RuanganIsActive = 'Y'";
|
||||||
|
|
||||||
|
$que = $this->db->query($sql, [
|
||||||
|
$userid,
|
||||||
|
$para['ruanganID']
|
||||||
|
]);
|
||||||
|
if (!$que) {
|
||||||
|
throw new Exception('failed to delete ruangan', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
|
||||||
|
$this->sys_ok([
|
||||||
|
"records" => [
|
||||||
|
"id" => $para['ruanganID'],
|
||||||
|
"msg" => "Success Update Ruangan"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
|
||||||
|
$msg = '[Error] ' . $e->getMessage();
|
||||||
|
$code = $e->getCode();
|
||||||
|
if ($code == 0) {
|
||||||
|
$this->sys_error($msg);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($msg);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,20 +113,19 @@ class PurchaseRequestNonPersediaan extends MY_Controller
|
|||||||
IFNULL(M_BranchCode, '') as M_BranchCode,
|
IFNULL(M_BranchCode, '') as M_BranchCode,
|
||||||
IFNULL(M_BranchName, '') as M_BranchName,
|
IFNULL(M_BranchName, '') as M_BranchName,
|
||||||
item_category.ItemCategoryName as itemCategoryName,
|
item_category.ItemCategoryName as itemCategoryName,
|
||||||
item_category.ItemCategoryID as itemCategoryID,
|
item_category.ItemCategoryID as itemCategoryID
|
||||||
IF(ah.AssetHandoverID IS NULL, 0, 1) AS hasHandover,
|
-- IF(ah.AssetHandoverID IS NULL, 0, 1) AS hasHandover,
|
||||||
ah.AssetHandoverConfirmedBy as handoverConfirmedBy,
|
-- ah.AssetHandoverConfirmedBy as handoverConfirmedBy,
|
||||||
ah.AssetHandoverID AS handoverID,
|
-- ah.AssetHandoverID AS handoverID,
|
||||||
ah.AssetHandoverDate AS handoverDate,
|
-- ah.AssetHandoverDate AS handoverDate,
|
||||||
ah.AssetHandoverToUserID AS handoverToUserID
|
-- ah.AssetHandoverToUserID AS handoverToUserID
|
||||||
FROM purchase_request
|
FROM purchase_request
|
||||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||||
JOIN item_category ON item_category.ItemCategoryID = PurchaseRequestItemCategoryID
|
JOIN item_category ON item_category.ItemCategoryID = PurchaseRequestItemCategoryID
|
||||||
JOIN m_user requestedBy ON requestedBy.M_UserID = PurchaseRequestRequestedBy
|
JOIN m_user requestedBy ON requestedBy.M_UserID = PurchaseRequestRequestedBy
|
||||||
LEFT JOIN m_user approvedBy ON approvedBy.M_UserID = PurchaseRequestApprovedBy
|
LEFT JOIN m_user approvedBy ON approvedBy.M_UserID = PurchaseRequestApprovedBy
|
||||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||||
LEFT JOIN asset_handover ah ON ah.AssetHandoverPurchaseRequestID = PurchaseRequestID
|
-- LEFT JOIN asset_handover ah ON ah.AssetHandoverPurchaseRequestID = PurchaseRequestID AND ah.AssetHandoverIsActive = 'Y'
|
||||||
AND ah.AssetHandoverIsActive = 'Y'
|
|
||||||
WHERE PurchaseRequestIsActive = 'Y'
|
WHERE PurchaseRequestIsActive = 'Y'
|
||||||
AND PurchaseRequestItemCategoryID <> '1'
|
AND PurchaseRequestItemCategoryID <> '1'
|
||||||
AND ( PurchaseRequestDate BETWEEN ? AND ? )
|
AND ( PurchaseRequestDate BETWEEN ? AND ? )
|
||||||
@@ -142,14 +141,39 @@ class PurchaseRequestNonPersediaan extends MY_Controller
|
|||||||
$this->sys_error_db("select purchase request", $this->db);
|
$this->sys_error_db("select purchase request", $this->db);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = $exec->result_array();
|
$rows = $exec->result_array();
|
||||||
$query = $this->db->last_query();
|
|
||||||
|
foreach ($rows as $key => $value) {
|
||||||
|
$sql_isHandedOver = "SELECT
|
||||||
|
AssetHandoverID,
|
||||||
|
AssetHandoverDetailID,
|
||||||
|
AssetHandoverToUserID,
|
||||||
|
AssetHandoverConfirmedBy,
|
||||||
|
T_BarcodeBarangNumber,
|
||||||
|
M_UserUsername,
|
||||||
|
CASE
|
||||||
|
WHEN AssetHandoverConfirmedBy = 0 THEN 'N'
|
||||||
|
ELSE 'Y'
|
||||||
|
END AS allHandedOver
|
||||||
|
FROM asset_handover
|
||||||
|
JOIN asset_handover_detail ON AssetHandoverDetailAssetHandoverID = AssetHandoverID
|
||||||
|
AND AssetHandoverIsActive = 'Y'
|
||||||
|
JOIN t_barcode_barang ON AssetHandoverDetailT_BarcodeBarangID = T_BarcodeBarangID
|
||||||
|
JOIN m_user ON M_UserID = AssetHandoverToUserID
|
||||||
|
WHERE AssetHandoverPurchaseRequestID = ?";
|
||||||
|
$que_isHandedOver = $this->db->query($sql_isHandedOver, [$value['prId']]);
|
||||||
|
if (!$que_isHandedOver) {
|
||||||
|
$this->sys_error_db("select purchase request", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$data_handed = $que_isHandedOver->result_array();
|
||||||
|
$rows[$key]['itemHandedOver'] = $data_handed;
|
||||||
|
}
|
||||||
|
|
||||||
$result = array(
|
$result = array(
|
||||||
"total" => $totalPage,
|
"total" => $totalPage,
|
||||||
"totalFilter" => $totalCount,
|
"totalFilter" => $totalCount,
|
||||||
"records" => $rows,
|
"records" => $rows
|
||||||
"db" => $query
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->sys_ok($result);
|
$this->sys_ok($result);
|
||||||
@@ -2149,52 +2173,28 @@ class PurchaseRequestNonPersediaan extends MY_Controller
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dataHanded = $prm['itemHandedOver'];
|
||||||
|
foreach ($dataHanded as $key => $value) {
|
||||||
# update confirm hand over #
|
# update confirm hand over #
|
||||||
$sql = "UPDATE asset_handover SET
|
$sql = "UPDATE asset_handover SET
|
||||||
AssetHandoverConfirmedAt = NOW(),
|
AssetHandoverConfirmedAt = NOW(),
|
||||||
AssetHandoverConfirmedBy = ?,
|
AssetHandoverConfirmedBy = ?,
|
||||||
AssetHandoverLastUpdated = NOW(),
|
AssetHandoverLastUpdated = NOW(),
|
||||||
AssetHandoverUserID = ?
|
AssetHandoverUserID = ?
|
||||||
WHERE AssetHandoverPurchaseRequestID = ?";
|
WHERE AssetHandoverPurchaseRequestID = ?
|
||||||
|
AND AssetHandoverID = ?";
|
||||||
$qry = $this->db->query($sql, [
|
$qry = $this->db->query($sql, [
|
||||||
$user['M_UserID'],
|
$user['M_UserID'],
|
||||||
$user['M_UserID'],
|
$user['M_UserID'],
|
||||||
$prm['purchaseRequestID']
|
$prm['purchaseRequestID'],
|
||||||
|
$value['AssetHandoverID']
|
||||||
]);
|
]);
|
||||||
if (!$qry) {
|
if (!$qry) {
|
||||||
$this->db->trans_rollback();
|
$this->db->trans_rollback();
|
||||||
$this->sys_error_db("[Error] update confirm hand over", $this->db);
|
$this->sys_error_db("[Error] update confirm hand over", $this->db);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
# update status purchase request #
|
|
||||||
// $sql_pr = "UPDATE purchase_request
|
|
||||||
// SET PurchaseRequestStatus = 'Closed',
|
|
||||||
// PurchaseRequestLastUpdated = NOW(),
|
|
||||||
// PurchaseRequestLastUpdatedUserID = ?
|
|
||||||
// WHERE PurchaseRequestID = ?";
|
|
||||||
// $qry_pr = $this->db->query($sql_pr, [$user['M_UserID'], $prm['purchaseRequestID']]);
|
|
||||||
// if (!$qry_pr) {
|
|
||||||
// $this->db->trans_rollback();
|
|
||||||
// $this->sys_error_db("[Error] update status purchase request", $this->db);
|
|
||||||
// exit;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $sql = "SELECT *
|
|
||||||
// FROM purchase_request
|
|
||||||
// JOIN m_user ON M_UserID = PurchaseRequestCreatedUserID
|
|
||||||
// WHERE PurchaseRequestID = ?";
|
|
||||||
// $query = $this->db->query($sql, [$prm['purchaseRequestID']]);
|
|
||||||
// $row = $query->row_array();
|
|
||||||
// $sql = "SELECT * FROM purchase_request_detail WHERE PurchaseRequestDetailPurchaseRequestID = ? AND PurchaseRequestDetailIsActive = 'Y'";
|
|
||||||
// $query = $this->db->query($sql, [$prm['purchaseRequestID']]);
|
|
||||||
// $rows = $query->result_array();
|
|
||||||
// $data = array(
|
|
||||||
// "header" => $row,
|
|
||||||
// "details" => $rows
|
|
||||||
// );
|
|
||||||
// $message = "Nomor PR: " . $row["PurchaseRequestNumber"] . " telah melakukan konfirmasi serah terima oleh " . $row["M_UserUsername"];
|
|
||||||
// $this->insert_act_log("PRNP", "CONFIRM", $message, $prm['purchaseRequestID'], $this->safeJsonEncode($data), $user['M_UserID']);
|
|
||||||
|
|
||||||
$this->db->trans_commit();
|
$this->db->trans_commit();
|
||||||
$this->sys_ok("Konfirmasi serah terima berhasil disimpan");
|
$this->sys_ok("Konfirmasi serah terima berhasil disimpan");
|
||||||
|
|||||||
Reference in New Issue
Block a user