add api file from used in s_menu fe accone
This commit is contained in:
831
application/controllers/fixedasset/Item.php
Normal file
831
application/controllers/fixedasset/Item.php
Normal file
@@ -0,0 +1,831 @@
|
|||||||
|
<?php
|
||||||
|
class Item extends MY_Controller{
|
||||||
|
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "AUTH API";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// search
|
||||||
|
function search()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = isset($prm["search"]) ? trim($prm["search"]) : '';
|
||||||
|
$search = ($search !== '') ? "%$search%" : "%%";
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
|
||||||
|
/* if (isset($branchCode)) {
|
||||||
|
$join_branch = " JOIN m_branch ON M_BranchCode = '{$branchCode}'
|
||||||
|
JOIN s_regional ON S_RegionalID = '{$regionalID}'";
|
||||||
|
$filter_branch = " AND Fa_ItemS_RegionalID = '{$regionalID}'";
|
||||||
|
}else{
|
||||||
|
$join_branch = " JOIN s_regional ON S_RegionalID = '{$regionalID}'
|
||||||
|
LEFT JOIN m_branch ON M_BranchS_RegionalID = '{$regionalID}'";
|
||||||
|
$filter_branch = " AND Fa_ItemS_RegionalID = '{$regionalID}'";
|
||||||
|
} */
|
||||||
|
$join_branch = " JOIN s_regional ON S_RegionalID = '{$regionalID}'
|
||||||
|
LEFT JOIN m_branch ON M_BranchS_RegionalID = '{$regionalID}'";
|
||||||
|
$filter_branch = " AND Fa_ItemS_RegionalID = '{$regionalID}'";
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0;
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
f.Fa_ItemID,
|
||||||
|
IFNULL(f.Fa_ItemDate, '') AS Fa_ItemDate,
|
||||||
|
IFNULL(f.Fa_ItemNumber, '') AS Fa_ItemNumber,
|
||||||
|
IFNULL(f.Fa_ItemType, '') AS Fa_ItemType,
|
||||||
|
IFNULL(f.Fa_ItemNote, '') AS Fa_ItemNote,
|
||||||
|
IFNULL(f.Fa_ItemM_DepartmentID, 0) AS Fa_ItemM_DepartmentID,
|
||||||
|
IFNULL(f.Fa_ItemBranchFaPercentID, 0) AS Fa_ItemBranchFaPercentID,
|
||||||
|
IFNULL(f.Fa_ItemM_ItemID, 0) AS Fa_ItemM_ItemID,
|
||||||
|
IFNULL(f.Fa_ItemQty, 0) AS Fa_ItemQty,
|
||||||
|
IFNULL(f.Fa_ItemPurchaseDate, '') AS Fa_ItemPurchaseDate,
|
||||||
|
IFNULL(f.Fa_ItemPurchasePrice, 0.00) AS Fa_ItemPurchasePrice,
|
||||||
|
IFNULL(f.Fa_ItemAcquisitionPrice, 0.00) AS Fa_ItemAcquisitionPrice,
|
||||||
|
IFNULL(f.Fa_ItemNetBookValue, 0.00) AS Fa_ItemNetBookValue,
|
||||||
|
IFNULL(f.Fa_ItemDeprePerMonth, 0.00) AS Fa_ItemDeprePerMonth,
|
||||||
|
IFNULL(f.Fa_ItemFa_ClassCoaID, 0) AS Fa_ItemFa_ClassCoaID,
|
||||||
|
IFNULL(f.Fa_ItemFa_ClassAccumDepreCoaID, 0) AS Fa_ItemFa_ClassAccumDepreCoaID,
|
||||||
|
IFNULL(f.Fa_ItemFa_ClassDepreCoaID, 0) AS Fa_ItemFa_ClassDepreCoaID,
|
||||||
|
IFNULL(f.Fa_ItemAcquisitionCoaID, 0) AS Fa_ItemAcquisitionCoaID,
|
||||||
|
IFNULL(f.Fa_ItemCurrentValue, 0.00) AS Fa_ItemCurrentValue,
|
||||||
|
IFNULL(f.Fa_ItemAccumDepre, 0.00) AS Fa_ItemAccumDepre,
|
||||||
|
IFNULL(f.Fa_ItemStatus, '') AS Fa_ItemStatus,
|
||||||
|
IFNULL(f.Fa_ItemUserID, 0) AS Fa_ItemUserID,
|
||||||
|
IFNULL(f.Fa_ItemCreated, CURRENT_TIMESTAMP) AS Fa_ItemCreated,
|
||||||
|
IFNULL(f.Fa_ItemLastUpdated, CURRENT_TIMESTAMP) AS Fa_ItemLastUpdated,
|
||||||
|
Fa_ItemInventarisNumber,
|
||||||
|
|
||||||
|
M_ItemID,
|
||||||
|
M_ItemCode,
|
||||||
|
M_ItemDesc,
|
||||||
|
M_ItemItem_CategoryID,
|
||||||
|
M_ItemInventoryCode,
|
||||||
|
M_ItemNat_GroupID,
|
||||||
|
M_ItemNat_SubGroupID,
|
||||||
|
M_ItemFa_ClassID,
|
||||||
|
Fa_ClassID,
|
||||||
|
Fa_ClassName,
|
||||||
|
Fa_ClassFlagType,
|
||||||
|
Fa_ClassCoaID,
|
||||||
|
Fa_ClassCoaAccountNo,
|
||||||
|
Fa_ClassCoaDesc,
|
||||||
|
Fa_ClassDepreCorp,
|
||||||
|
Fa_ClassDepreGov,
|
||||||
|
Fa_ClassAccumDepreCoaID,
|
||||||
|
Fa_ClassAccumDepreCoaAccountNo,
|
||||||
|
Fa_ClassAccumDepreCoaDesc,
|
||||||
|
Fa_ClassDepreCoaID,
|
||||||
|
Fa_ClassAccumNote,
|
||||||
|
M_ItemM_InventarisGolID,
|
||||||
|
M_ItemPurchaseUOM,
|
||||||
|
M_ItemBaseUOM,
|
||||||
|
M_ItemItem_UnitID,
|
||||||
|
Fa_ClassAgeAsset,
|
||||||
|
-- Data dari tabel coa untuk Class CoA
|
||||||
|
IFNULL(c_class.coaID, 0) AS ClassCoaID,
|
||||||
|
IFNULL(c_class.coaAccountNo, '') AS ClassCoaAccountNo,
|
||||||
|
IFNULL(c_class.coaDescription, '') AS ClassCoaDescription,
|
||||||
|
|
||||||
|
-- Data dari tabel coa untuk Accumulated Depreciation CoA
|
||||||
|
IFNULL(c_accum.coaID, 0) AS AccumDepreCoaID,
|
||||||
|
IFNULL(c_accum.coaAccountNo, '') AS AccumDepreCoaAccountNo,
|
||||||
|
IFNULL(c_accum.coaDescription, '') AS AccumDepreCoaDescription,
|
||||||
|
|
||||||
|
-- Data dari tabel coa untuk Depre
|
||||||
|
IFNULL(c_depre.coaID, 0) AS DepreCoaID,
|
||||||
|
IFNULL(c_depre.coaAccountNo, '') AS DepreCoaAccountNo,
|
||||||
|
IFNULL(c_depre.coaDescription, '') AS DepreCoaDescription,
|
||||||
|
|
||||||
|
M_DepartmentID,
|
||||||
|
M_DepartmentCode,
|
||||||
|
M_DepartmentName,
|
||||||
|
|
||||||
|
IFNULL(c_acquisition.coaID, 0) AS AcquisitionCoaID,
|
||||||
|
IFNULL(c_acquisition.coaAccountNo, '') AS AcquisitionCoaAccountNo,
|
||||||
|
IFNULL(c_acquisition.coaDescription, '') AS AcquisitionCoaDescription,
|
||||||
|
|
||||||
|
M_BranchID,
|
||||||
|
M_BranchS_RegionalID,
|
||||||
|
M_BranchCode,
|
||||||
|
M_BranchName,
|
||||||
|
S_RegionalID,
|
||||||
|
S_RegionalName,
|
||||||
|
BranchFaPercentID,
|
||||||
|
BranchFaPercentType
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM fa_item f
|
||||||
|
LEFT JOIN m_item ON M_ItemID = Fa_ItemM_ItemID
|
||||||
|
LEFT JOIN fa_class ON Fa_ClassID = M_ItemFa_ClassID
|
||||||
|
LEFT JOIN m_department ON M_DepartmentID = Fa_ItemM_DepartmentID
|
||||||
|
LEFT JOIN branch_fa_percent ON BranchFaPercentID = Fa_ItemBranchFaPercentID
|
||||||
|
LEFT JOIN coa c_class
|
||||||
|
ON f.Fa_ItemFa_ClassCoaID = c_class.coaID
|
||||||
|
LEFT JOIN coa c_accum
|
||||||
|
ON f.Fa_ItemFa_ClassAccumDepreCoaID = c_accum.coaID
|
||||||
|
LEFT JOIN coa c_depre
|
||||||
|
ON f.Fa_ItemFa_ClassDepreCoaID = c_depre.coaID
|
||||||
|
LEFT JOIN coa c_acquisition
|
||||||
|
ON f.Fa_ItemAcquisitionCoaID = c_acquisition.coaID
|
||||||
|
$join_branch
|
||||||
|
WHERE f.Fa_ItemIsActive = 'Y'
|
||||||
|
$filter_branch
|
||||||
|
AND (
|
||||||
|
f.Fa_ItemName LIKE CONCAT('%', '$search', '%')
|
||||||
|
OR f.Fa_ItemNumber LIKE CONCAT('%', '$search', '%')
|
||||||
|
)
|
||||||
|
GROUP BY f.Fa_ItemID
|
||||||
|
ORDER BY f.Fa_ItemID DESC";
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
|
||||||
|
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||||
|
$qry_total = $this->db_onedev->query($sql_total);
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
|
$totalPage = 0;
|
||||||
|
if ($qry_total) {
|
||||||
|
$totalCount = $qry_total->result_array()[0]["total"];
|
||||||
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("select fa_item count error", $this->db_onedev);;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||||
|
|
||||||
|
$qry = $this->db_onedev->query($sql_select);
|
||||||
|
if ($qry) {
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
} else {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("select fa_item error", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"total" => $totalPage,
|
||||||
|
"totalFilter" => $totalCount,
|
||||||
|
"records" => $rows,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$this->sys_error($exc->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ac getAcAccumDepre
|
||||||
|
function getAcAccumDepre()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = $prm['search'];
|
||||||
|
// $where_search = "%%";
|
||||||
|
$where_search_desc = '%'.$search.'%';
|
||||||
|
$where_search_acc = "$search%";
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
coaID,
|
||||||
|
coaAccountNo,
|
||||||
|
coaDescription,
|
||||||
|
coaSubDescription,
|
||||||
|
coaAccountType,
|
||||||
|
coaSpecialAccountType,
|
||||||
|
coaIsInput,
|
||||||
|
coaReportSchedule,
|
||||||
|
coaCurrencyCode,
|
||||||
|
coaCashFlowCategory,
|
||||||
|
coaCreated,
|
||||||
|
coaLastUpdated,
|
||||||
|
coaIsActive,
|
||||||
|
coaLevel
|
||||||
|
FROM coa
|
||||||
|
WHERE coaIsInput = 'Y'
|
||||||
|
AND coaIsActive = 'Y'
|
||||||
|
AND
|
||||||
|
(
|
||||||
|
coaDescription LIKE '$where_search_desc'
|
||||||
|
OR coaAccountNo LIKE '$where_search_acc'
|
||||||
|
)";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
// die();
|
||||||
|
$qry = $this->db_onedev->query($sql, array());
|
||||||
|
|
||||||
|
if (!$qry) {
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Error get coa pendapatan");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = $qry->result_array();
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ac getAcCoa
|
||||||
|
function getAcCoa()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = $prm['search'];
|
||||||
|
// $where_search = "%%";
|
||||||
|
$where_search_desc = '%'.$search.'%';
|
||||||
|
$where_search_acc = "$search%";
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
coaID,
|
||||||
|
coaAccountNo,
|
||||||
|
coaDescription,
|
||||||
|
coaSubDescription,
|
||||||
|
coaAccountType,
|
||||||
|
coaSpecialAccountType,
|
||||||
|
coaIsInput,
|
||||||
|
coaReportSchedule,
|
||||||
|
coaCurrencyCode,
|
||||||
|
coaCashFlowCategory,
|
||||||
|
coaCreated,
|
||||||
|
coaLastUpdated,
|
||||||
|
coaIsActive,
|
||||||
|
coaLevel
|
||||||
|
FROM coa
|
||||||
|
WHERE coaIsInput = 'Y'
|
||||||
|
AND coaIsActive = 'Y'
|
||||||
|
AND
|
||||||
|
(
|
||||||
|
coaDescription LIKE '$where_search_desc'
|
||||||
|
OR coaAccountNo LIKE '$where_search_acc'
|
||||||
|
)";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
// die();
|
||||||
|
$qry = $this->db_onedev->query($sql, array());
|
||||||
|
|
||||||
|
if (!$qry) {
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Error get coa pendapatan");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = $qry->result_array();
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getItem()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = $prm['search'];
|
||||||
|
// $where_search = "%%";
|
||||||
|
$where_search_desc = '%'.$search.'%';
|
||||||
|
$where_search_acc = "$search%";
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
M_ItemID,
|
||||||
|
M_ItemCode,
|
||||||
|
M_ItemDesc,
|
||||||
|
M_ItemItem_CategoryID,
|
||||||
|
M_ItemInventoryCode,
|
||||||
|
M_ItemNat_GroupID,
|
||||||
|
M_ItemNat_SubGroupID,
|
||||||
|
M_ItemFa_ClassID,
|
||||||
|
Fa_ClassID,
|
||||||
|
Fa_ClassName,
|
||||||
|
Fa_ClassFlagType,
|
||||||
|
Fa_ClassCoaID,
|
||||||
|
Fa_ClassCoaAccountNo,
|
||||||
|
Fa_ClassCoaDesc,
|
||||||
|
Fa_ClassDepreCorp,
|
||||||
|
Fa_ClassDepreGov,
|
||||||
|
Fa_ClassAccumDepreCoaID,
|
||||||
|
Fa_ClassAccumDepreCoaAccountNo,
|
||||||
|
Fa_ClassAccumDepreCoaDesc,
|
||||||
|
Fa_ClassDepreCoaID,
|
||||||
|
coaID,
|
||||||
|
coaAccountNo,
|
||||||
|
coaDescription,
|
||||||
|
Fa_ClassAccumNote,
|
||||||
|
M_ItemM_InventarisGolID,
|
||||||
|
M_ItemPurchaseUOM,
|
||||||
|
M_ItemBaseUOM,
|
||||||
|
M_ItemItem_UnitID,
|
||||||
|
Fa_ClassAgeAsset
|
||||||
|
FROM m_item
|
||||||
|
JOIN fa_class ON Fa_ClassID = M_ItemFa_ClassID
|
||||||
|
LEFT JOIN coa ON coaID = Fa_ClassDepreCoaID
|
||||||
|
WHERE M_ItemIsActive = 'Y'
|
||||||
|
AND M_ItemItem_CategoryID = '3'
|
||||||
|
AND
|
||||||
|
(
|
||||||
|
M_ItemDesc LIKE '$where_search_desc'
|
||||||
|
OR M_ItemCode LIKE '$where_search_acc'
|
||||||
|
)";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
// die();
|
||||||
|
$qry = $this->db_onedev->query($sql, array());
|
||||||
|
|
||||||
|
if (!$qry) {
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Error get coa pendapatan");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = $qry->result_array();
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getDepartment()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = $prm['search'];
|
||||||
|
// $where_search = "%%";
|
||||||
|
$where_search_desc = '%'.$search.'%';
|
||||||
|
$where_search_acc = "$search%";
|
||||||
|
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM m_department
|
||||||
|
WHERE M_DepartmentIsActive = 'Y'
|
||||||
|
AND
|
||||||
|
(
|
||||||
|
M_DepartmentName LIKE '$where_search_desc'
|
||||||
|
OR M_DepartmentCode LIKE '$where_search_acc'
|
||||||
|
)";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
// die();
|
||||||
|
$qry = $this->db_onedev->query($sql, array());
|
||||||
|
|
||||||
|
if (!$qry) {
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Error get coa pendapatan");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = $qry->result_array();
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPresentase()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = $prm['search'];
|
||||||
|
// $where_search = "%%";
|
||||||
|
$where_search_desc = '%'.$search.'%';
|
||||||
|
$where_search_acc = "$search%";
|
||||||
|
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM branch_fa_percent
|
||||||
|
WHERE BranchFaPercentIsActive = 'Y'
|
||||||
|
AND
|
||||||
|
(
|
||||||
|
BranchFaPercentType LIKE '$where_search_desc'
|
||||||
|
|
||||||
|
)";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
// die();
|
||||||
|
$qry = $this->db_onedev->query($sql, array());
|
||||||
|
|
||||||
|
if (!$qry) {
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Error get coa pendapatan");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = $qry->result_array();
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// addData
|
||||||
|
function addData()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_begin();
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$pdSql = "SELECT `fn_numbering`('FAI') AS FAI";
|
||||||
|
$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]["FAI"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract input parameters
|
||||||
|
$Fa_ItemNote = $prm['Fa_ItemNote'];
|
||||||
|
$Fa_ItemM_DepartmentID = isset($prm['Fa_ItemM_DepartmentID']) ? $prm['Fa_ItemM_DepartmentID'] : 0;
|
||||||
|
$Fa_ItemBranchFaPercentID = isset($prm['Fa_ItemBranchFaPercentID']) ? $prm['Fa_ItemBranchFaPercentID'] : 0;
|
||||||
|
$Fa_ItemM_ItemID = isset($prm['Fa_ItemM_ItemID']) ? $prm['Fa_ItemM_ItemID'] : 0;
|
||||||
|
$Fa_ItemQty = isset($prm['Fa_ItemQty']) ? $prm['Fa_ItemQty'] : 0;
|
||||||
|
$Fa_ItemPurchasePrice = isset($prm['Fa_ItemPurchasePrice']) ? $prm['Fa_ItemPurchasePrice'] : 0.00;
|
||||||
|
$Fa_ItemAcquisitionPrice = isset($prm['Fa_ItemAcquisitionPrice']) ? $prm['Fa_ItemAcquisitionPrice'] : 0.00;
|
||||||
|
$Fa_ItemNetBookValue = isset($prm['Fa_ItemNetBookValue']) ? $prm['Fa_ItemNetBookValue'] : 0.00;
|
||||||
|
$Fa_ItemDeprePerMonth = isset($prm['Fa_ItemDeprePerMonth']) ? $prm['Fa_ItemDeprePerMonth'] : 0.00;
|
||||||
|
$Fa_ItemFa_ClassCoaID = isset($prm['Fa_ItemFa_ClassCoaID']) ? $prm['Fa_ItemFa_ClassCoaID'] : 0;
|
||||||
|
$Fa_ItemFa_ClassAccumDepreCoaID = isset($prm['Fa_ItemFa_ClassAccumDepreCoaID']) ? $prm['Fa_ItemFa_ClassAccumDepreCoaID'] : 0;
|
||||||
|
$Fa_ItemFa_ClassDepreCoaID = isset($prm['Fa_ItemFa_ClassDepreCoaID']) ? $prm['Fa_ItemFa_ClassDepreCoaID'] : 0;
|
||||||
|
$Fa_ItemAcquisitionCoaID = isset($prm['Fa_ItemAcquisitionCoaID']) ? $prm['Fa_ItemAcquisitionCoaID'] : 0;
|
||||||
|
$Fa_ItemCurrentValue = isset($prm['Fa_ItemCurrentValue']) ? $prm['Fa_ItemCurrentValue'] : 0.00;
|
||||||
|
$Fa_ItemAccumDepre = isset($prm['Fa_ItemAccumDepre']) ? $prm['Fa_ItemAccumDepre'] : 0.00;
|
||||||
|
$Fa_ItemStatus = isset($prm['Fa_ItemStatus']) ? $prm['Fa_ItemStatus'] : 'Draft';
|
||||||
|
$Fa_ItemInventarisNumber = isset($prm['Fa_ItemInventarisNumber']) ? $prm['Fa_ItemInventarisNumber'] : '';
|
||||||
|
$Fa_ItemS_RegionalID = isset($prm['Fa_ItemS_RegionalID']) ? $prm['Fa_ItemS_RegionalID'] : 0;
|
||||||
|
$Fa_ItemM_BranchCode = isset($prm['Fa_ItemM_BranchCode']) ? $prm['Fa_ItemM_BranchCode'] : '';
|
||||||
|
|
||||||
|
// Construct SQL query
|
||||||
|
$sql = "INSERT INTO fa_item (
|
||||||
|
Fa_ItemS_RegionalID,
|
||||||
|
Fa_ItemM_BranchCode,
|
||||||
|
Fa_ItemDate,
|
||||||
|
Fa_ItemNumber,
|
||||||
|
Fa_ItemType,
|
||||||
|
Fa_ItemNote,
|
||||||
|
Fa_ItemM_DepartmentID,
|
||||||
|
Fa_ItemBranchFaPercentID,
|
||||||
|
Fa_ItemM_ItemID,
|
||||||
|
Fa_ItemQty,
|
||||||
|
Fa_ItemPurchaseDate,
|
||||||
|
Fa_ItemPurchasePrice,
|
||||||
|
Fa_ItemAcquisitionPrice,
|
||||||
|
Fa_ItemNetBookValue,
|
||||||
|
Fa_ItemDeprePerMonth,
|
||||||
|
Fa_ItemFa_ClassCoaID,
|
||||||
|
Fa_ItemFa_ClassAccumDepreCoaID,
|
||||||
|
Fa_ItemFa_ClassDepreCoaID,
|
||||||
|
Fa_ItemAcquisitionCoaID,
|
||||||
|
Fa_ItemCurrentValue,
|
||||||
|
Fa_ItemAccumDepre,
|
||||||
|
Fa_ItemInventarisNumber,
|
||||||
|
Fa_ItemStatus,
|
||||||
|
Fa_ItemUserID,
|
||||||
|
Fa_ItemCreated,
|
||||||
|
Fa_ItemLastUpdated
|
||||||
|
) VALUES (
|
||||||
|
'$Fa_ItemS_RegionalID',
|
||||||
|
'$Fa_ItemM_BranchCode',
|
||||||
|
now(),
|
||||||
|
'$pd',
|
||||||
|
'ACCOUNT',
|
||||||
|
'$Fa_ItemNote',
|
||||||
|
'$Fa_ItemM_DepartmentID',
|
||||||
|
'$Fa_ItemBranchFaPercentID',
|
||||||
|
'$Fa_ItemM_ItemID',
|
||||||
|
'$Fa_ItemQty',
|
||||||
|
now(),
|
||||||
|
'$Fa_ItemPurchasePrice',
|
||||||
|
'$Fa_ItemAcquisitionPrice',
|
||||||
|
'$Fa_ItemNetBookValue',
|
||||||
|
'$Fa_ItemDeprePerMonth',
|
||||||
|
'$Fa_ItemFa_ClassCoaID',
|
||||||
|
'$Fa_ItemFa_ClassAccumDepreCoaID',
|
||||||
|
'$Fa_ItemFa_ClassDepreCoaID',
|
||||||
|
'$Fa_ItemAcquisitionCoaID',
|
||||||
|
'$Fa_ItemCurrentValue',
|
||||||
|
'$Fa_ItemAccumDepre',
|
||||||
|
'$Fa_ItemInventarisNumber',
|
||||||
|
'$Fa_ItemStatus',
|
||||||
|
'$userid',
|
||||||
|
NOW(),
|
||||||
|
NOW()
|
||||||
|
)";
|
||||||
|
|
||||||
|
// Execute query
|
||||||
|
$qry = $this->db_onedev->query($sql);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_commit();
|
||||||
|
$result = array("total" => 1);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get_by_id
|
||||||
|
function get_by_id()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fa_item
|
||||||
|
$Fa_ItemID = isset($prm['Fa_ItemID']) ? $prm['Fa_ItemID'] : 0;
|
||||||
|
|
||||||
|
$sql_m = "SELECT * FROM fa_item where Fa_ItemID = '$Fa_ItemID'";
|
||||||
|
|
||||||
|
$qry_m = $this->db_onedev->query($sql_m);
|
||||||
|
if (!$qry_m) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows_m = $qry_m->result_array();
|
||||||
|
|
||||||
|
// coa start
|
||||||
|
$Fa_ItemCoaID = isset($prm['Fa_ItemCoaID']) ? $prm['Fa_ItemCoaID'] : 0;
|
||||||
|
$sql_u = "SELECT * FROM coa where coaID = '$Fa_ItemCoaID'
|
||||||
|
AND coaIsInput = 'Y'
|
||||||
|
AND coaIsActive = 'Y'
|
||||||
|
";
|
||||||
|
|
||||||
|
$qry_u = $this->db_onedev->query($sql_u);
|
||||||
|
if (!$qry_u) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows_u = $qry_u->result_array();
|
||||||
|
|
||||||
|
// empty $rows_u
|
||||||
|
if (empty($rows_u)) {
|
||||||
|
$rows_u = [[
|
||||||
|
"coaID" => 0,
|
||||||
|
"coaAccountNo" => '',
|
||||||
|
"coaDescription" => '',
|
||||||
|
"coaSubDescription" => '',
|
||||||
|
"coaAccountType" => '',
|
||||||
|
"coaSpecialAccountType" => '',
|
||||||
|
"coaIsInput" => 'N',
|
||||||
|
"coaReportSchedule" => '',
|
||||||
|
"coaCurrencyCode" => '',
|
||||||
|
"coaCashFlowCategory" => '',
|
||||||
|
"coaCreated" => '',
|
||||||
|
"coaLastUpdated" => '',
|
||||||
|
"coaIsActive" => 'Y',
|
||||||
|
"coaLevel" => 1
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// coa end
|
||||||
|
|
||||||
|
// accum depre start
|
||||||
|
$Fa_ItemAccumDepreCoaID = $prm['Fa_ItemAccumDepreCoaID'];
|
||||||
|
$sql_h = "SELECT * FROM coa where coaID = '$Fa_ItemAccumDepreCoaID'
|
||||||
|
AND coaIsInput = 'Y'
|
||||||
|
AND coaIsActive = 'Y'";
|
||||||
|
|
||||||
|
$qry_h = $this->db_onedev->query($sql_h);
|
||||||
|
if (!$qry_h) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows_h = $qry_h->result_array();
|
||||||
|
// empty $rows_h
|
||||||
|
if (empty($rows_h)) {
|
||||||
|
$rows_h = [[
|
||||||
|
"coaID" => 0,
|
||||||
|
"coaAccountNo" => '',
|
||||||
|
"coaDescription" => '',
|
||||||
|
"coaSubDescription" => '',
|
||||||
|
"coaAccountType" => '',
|
||||||
|
"coaSpecialAccountType" => '',
|
||||||
|
"coaIsInput" => 'N',
|
||||||
|
"coaReportSchedule" => '',
|
||||||
|
"coaCurrencyCode" => '',
|
||||||
|
"coaCashFlowCategory" => '',
|
||||||
|
"coaCreated" => '',
|
||||||
|
"coaLastUpdated" => '',
|
||||||
|
"coaIsActive" => 'Y',
|
||||||
|
"coaLevel" => 1
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
// accum depre end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"record_fa_item" => $rows_m,
|
||||||
|
"records_coa" => $rows_u,
|
||||||
|
"records_accum_depre" => $rows_h,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// editData
|
||||||
|
function editData()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_begin();
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$Fa_ItemID = $prm['Fa_ItemID'];
|
||||||
|
$Fa_ItemNote = $prm['Fa_ItemNote'];
|
||||||
|
$Fa_ItemM_DepartmentID = isset($prm['Fa_ItemM_DepartmentID']) ? $prm['Fa_ItemM_DepartmentID'] : 0;
|
||||||
|
$Fa_ItemBranchFaPercentID = isset($prm['Fa_ItemBranchFaPercentID']) ? $prm['Fa_ItemBranchFaPercentID'] : 0;
|
||||||
|
$Fa_ItemM_ItemID = isset($prm['Fa_ItemM_ItemID']) ? $prm['Fa_ItemM_ItemID'] : 0;
|
||||||
|
$Fa_ItemQty = isset($prm['Fa_ItemQty']) ? $prm['Fa_ItemQty'] : 0;
|
||||||
|
$Fa_ItemPurchasePrice = isset($prm['Fa_ItemPurchasePrice']) ? $prm['Fa_ItemPurchasePrice'] : 0.00;
|
||||||
|
$Fa_ItemAcquisitionPrice = isset($prm['Fa_ItemAcquisitionPrice']) ? $prm['Fa_ItemAcquisitionPrice'] : 0.00;
|
||||||
|
$Fa_ItemNetBookValue = isset($prm['Fa_ItemNetBookValue']) ? $prm['Fa_ItemNetBookValue'] : 0.00;
|
||||||
|
$Fa_ItemDeprePerMonth = isset($prm['Fa_ItemDeprePerMonth']) ? $prm['Fa_ItemDeprePerMonth'] : 0.00;
|
||||||
|
$Fa_ItemFa_ClassCoaID = isset($prm['Fa_ItemFa_ClassCoaID']) ? $prm['Fa_ItemFa_ClassCoaID'] : 0;
|
||||||
|
$Fa_ItemFa_ClassAccumDepreCoaID = isset($prm['Fa_ItemFa_ClassAccumDepreCoaID']) ? $prm['Fa_ItemFa_ClassAccumDepreCoaID'] : 0;
|
||||||
|
$Fa_ItemFa_ClassDepreCoaID = isset($prm['Fa_ItemFa_ClassDepreCoaID']) ? $prm['Fa_ItemFa_ClassDepreCoaID'] : 0;
|
||||||
|
$Fa_ItemAcquisitionCoaID = isset($prm['Fa_ItemAcquisitionCoaID']) ? $prm['Fa_ItemAcquisitionCoaID'] : 0;
|
||||||
|
$Fa_ItemCurrentValue = isset($prm['Fa_ItemCurrentValue']) ? $prm['Fa_ItemCurrentValue'] : 0.00;
|
||||||
|
$Fa_ItemAccumDepre = isset($prm['Fa_ItemAccumDepre']) ? $prm['Fa_ItemAccumDepre'] : 0.00;
|
||||||
|
$Fa_ItemStatus = isset($prm['Fa_ItemStatus']) ? $prm['Fa_ItemStatus'] : 'Draft';
|
||||||
|
$Fa_ItemInventarisNumber = isset($prm['Fa_ItemInventarisNumber']) ? $prm['Fa_ItemInventarisNumber'] : '';
|
||||||
|
$Fa_ItemS_RegionalID = isset($prm['Fa_ItemS_RegionalID']) ? $prm['Fa_ItemS_RegionalID'] : 0;
|
||||||
|
$Fa_ItemM_BranchCode = isset($prm['Fa_ItemM_BranchCode']) ? $prm['Fa_ItemM_BranchCode'] : '';
|
||||||
|
|
||||||
|
$sql = "UPDATE fa_item SET
|
||||||
|
Fa_ItemNote = '{$Fa_ItemNote}',
|
||||||
|
Fa_ItemM_DepartmentID = '{$Fa_ItemM_DepartmentID}',
|
||||||
|
Fa_ItemBranchFaPercentID = '{$Fa_ItemBranchFaPercentID}',
|
||||||
|
Fa_ItemM_ItemID = '{$Fa_ItemM_ItemID}',
|
||||||
|
Fa_ItemQty = '{$Fa_ItemQty}',
|
||||||
|
Fa_ItemAcquisitionPrice = '{$Fa_ItemAcquisitionPrice}',
|
||||||
|
Fa_ItemNetBookValue = '{$Fa_ItemNetBookValue}',
|
||||||
|
Fa_ItemDeprePerMonth = '{$Fa_ItemDeprePerMonth}',
|
||||||
|
Fa_ItemFa_ClassCoaID = '{$Fa_ItemFa_ClassCoaID}',
|
||||||
|
Fa_ItemFa_ClassAccumDepreCoaID = '{$Fa_ItemFa_ClassAccumDepreCoaID}',
|
||||||
|
Fa_ItemFa_ClassDepreCoaID = '{$Fa_ItemFa_ClassDepreCoaID}',
|
||||||
|
Fa_ItemAcquisitionCoaID = '{$Fa_ItemAcquisitionCoaID}',
|
||||||
|
Fa_ItemCurrentValue = '{$Fa_ItemCurrentValue}',
|
||||||
|
Fa_ItemAccumDepre = '{$Fa_ItemAccumDepre}',
|
||||||
|
Fa_ItemInventarisNumber = '{$Fa_ItemInventarisNumber}',
|
||||||
|
Fa_ItemUserID = '{$userid}',
|
||||||
|
Fa_ItemLastUpdated = now(),
|
||||||
|
Fa_ItemS_RegionalID = '{$Fa_ItemS_RegionalID}',
|
||||||
|
Fa_ItemM_BranchCode = '{$Fa_ItemM_BranchCode}'
|
||||||
|
WHERE Fa_ItemID = '$Fa_ItemID'
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
|
||||||
|
$qry = $this->db_onedev->query($sql);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
// "sql" => $last_qry
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_commit();
|
||||||
|
$result = array("total" => 1);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteData
|
||||||
|
function deleteData()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_begin();
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$Fa_ItemID = $prm['Fa_ItemID'];
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "UPDATE fa_item
|
||||||
|
SET
|
||||||
|
Fa_ItemIsActive = 'N',
|
||||||
|
Fa_ItemLastUpdated = now(),
|
||||||
|
Fa_ItemUserID = '$userid'
|
||||||
|
WHERE Fa_ItemID = '$Fa_ItemID'";
|
||||||
|
|
||||||
|
$qry = $this->db_onedev->query($sql);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $last_qry
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_commit();
|
||||||
|
$result = array("total" => 1);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
1055
application/controllers/fixedasset/Journalfixedassetv2.php
Normal file
1055
application/controllers/fixedasset/Journalfixedassetv2.php
Normal file
File diff suppressed because it is too large
Load Diff
365
application/controllers/itemdivision/Itemdivision.php
Normal file
365
application/controllers/itemdivision/Itemdivision.php
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
<?php
|
||||||
|
class Itemdivision extends MY_Controller {
|
||||||
|
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "AUTH API";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// search item
|
||||||
|
function search_item()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$search_item = isset($prm['search_item']) ? trim($prm['search_item']) : '';
|
||||||
|
|
||||||
|
$where_search = '%'.$search_item.'%';
|
||||||
|
$itemCategoryID = isset($prm['itemCategoryID']) ? (int) $prm['itemCategoryID'] : (int) 0;
|
||||||
|
|
||||||
|
$where_item_category_id = ($itemCategoryID > 0) ? "AND itemCategoryID = '$itemCategoryID'" : "";
|
||||||
|
// $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * 20 : 0;
|
||||||
|
// $number_limit = 2;
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0;
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
M_ItemID,
|
||||||
|
IFNULL(itemCategoryName, '') AS itemCategoryName,
|
||||||
|
IFNULL(M_ItemCode, '') AS M_ItemCode,
|
||||||
|
IFNULL(M_ItemDesc, '') AS M_ItemDesc
|
||||||
|
from m_item
|
||||||
|
join item_category
|
||||||
|
ON M_ItemItem_CategoryID = itemCategoryID
|
||||||
|
AND itemCategoryIsActive = 'Y'
|
||||||
|
WHERE M_ItemIsActive = 'Y'
|
||||||
|
$where_item_category_id
|
||||||
|
AND (
|
||||||
|
M_ItemDesc LIKE '$where_search'
|
||||||
|
OR M_ItemCode LIKE '$where_search'
|
||||||
|
)
|
||||||
|
ORDER BY M_ItemID ASC";
|
||||||
|
|
||||||
|
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||||
|
$qry_total = $this->db_onedev->query($sql_total);
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
|
$totalPage = 0;
|
||||||
|
if ($qry_total) {
|
||||||
|
$totalCount = $qry_total->result_array()[0]["total"];
|
||||||
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("select m_item count error", $this->db_onedev);;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||||
|
|
||||||
|
$qry = $this->db_onedev->query($sql_select);
|
||||||
|
|
||||||
|
if(!$qry){
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("select m_item error", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"total" => $totalPage,
|
||||||
|
"totalFilter" => $totalCount,
|
||||||
|
"records" => $rows,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$this->sys_error($exc->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dropdown item_category
|
||||||
|
function dropdown_item_category()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
itemCategoryID,
|
||||||
|
itemCategoryName
|
||||||
|
FROM item_category
|
||||||
|
WHERE itemCategoryIsActive = 'Y'
|
||||||
|
ORDER BY itemCategoryID ASC";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
// die();
|
||||||
|
$qry = $this->db_onedev->query($sql, array());
|
||||||
|
|
||||||
|
if (!$qry) {
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Error get dropdown item_category");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
if(count($rows) > 0){
|
||||||
|
$response = [
|
||||||
|
"records" => $rows,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
} else {
|
||||||
|
$rows[] = [
|
||||||
|
"M_ItemID" => 0,
|
||||||
|
"itemCategoryName" => "Item Tidak Ada",
|
||||||
|
"M_ItemCode" => "",
|
||||||
|
"M_ItemDesc" => ""
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"records" => $rows,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
}
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// item division list
|
||||||
|
function item_division_list()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$M_ItemID = isset($prm['M_ItemID']) ? (int) $prm['M_ItemID'] : (int) 0;
|
||||||
|
|
||||||
|
$where_item_id = ($M_ItemID > 0) ? "AND M_ItemDivisionM_ItemID = '$M_ItemID'" : "";
|
||||||
|
// $number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * 20 : 0;
|
||||||
|
// $number_limit = 2;
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0;
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
IFNULL(M_ItemDivisionID, 0) AS M_ItemDivisionID,
|
||||||
|
IFNULL(M_ItemDivisionM_ItemID, 0) AS M_ItemDivisionM_ItemID,
|
||||||
|
DivisionName,
|
||||||
|
IFNULL(DivisionID, 0) AS DivisionID,
|
||||||
|
CASE
|
||||||
|
WHEN M_ItemDivisionIsActive = 'Y'
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END as IsChecked
|
||||||
|
from division
|
||||||
|
left join m_itemdivision
|
||||||
|
ON DivisionID = M_ItemDivisionID
|
||||||
|
$where_item_id
|
||||||
|
where DivisionIsActive = 'Y'
|
||||||
|
ORDER BY DivisionID asc";
|
||||||
|
|
||||||
|
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||||
|
$qry_total = $this->db_onedev->query($sql_total);
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
|
$totalPage = 0;
|
||||||
|
if ($qry_total) {
|
||||||
|
$totalCount = $qry_total->result_array()[0]["total"];
|
||||||
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("select m_itemdivision count error", $this->db_onedev);;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||||
|
$sql_select = $sql;
|
||||||
|
|
||||||
|
$qry = $this->db_onedev->query($sql_select);
|
||||||
|
|
||||||
|
if(!$qry){
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("select m_itemdivision error", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"total" => $totalPage,
|
||||||
|
"totalFilter" => $totalCount,
|
||||||
|
"records" => $rows,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$this->sys_error($exc->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update m_itemdivision
|
||||||
|
function update_item_division()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_begin();
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$M_ItemDivisionID = isset($prm['M_ItemDivisionID']) ? $prm['M_ItemDivisionID'] : [];
|
||||||
|
$M_ItemID = isset($prm['M_ItemID']) ? (int) $prm['M_ItemID'] : (int) 0;
|
||||||
|
$where_item_id = ($M_ItemID > 0) ? "AND M_ItemDivisionM_ItemID = '$M_ItemID'" : "";
|
||||||
|
|
||||||
|
// $sql_u = "";
|
||||||
|
|
||||||
|
// var_dump($M_ItemDivisionID);
|
||||||
|
|
||||||
|
if(count($M_ItemDivisionID) > 0){
|
||||||
|
foreach ($M_ItemDivisionID as $row) {
|
||||||
|
$id = $row['M_ItemDivisionID'];
|
||||||
|
|
||||||
|
$M_ItemDivisionDivisionID = $row['DivisionID'];
|
||||||
|
// $M_ItemDivisionM_ItemID = $row['M_ItemDivisionM_ItemID'];
|
||||||
|
|
||||||
|
$flag = ($row['IsChecked'] === "1") ? "Y" : "N";
|
||||||
|
|
||||||
|
// check data jika ada update jika tidak ada insert
|
||||||
|
$sql_c = "SELECT *
|
||||||
|
FROM m_itemdivision
|
||||||
|
WHERE M_ItemDivisionID = '$id'";
|
||||||
|
|
||||||
|
$qry_c = $this->db_onedev->query($sql_c);
|
||||||
|
if(!$qry_c){
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("query check data m_itemdivision", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rc = $qry_c->result_array();
|
||||||
|
if(count($rc) > 0) {
|
||||||
|
// update
|
||||||
|
$sql_u = "UPDATE m_itemdivision SET
|
||||||
|
M_ItemDivisionIsActive = '$flag',
|
||||||
|
M_ItemDivisionLastUpdatedUserID = '$userid',
|
||||||
|
M_ItemDivisionLastUpdated = NOW()
|
||||||
|
WHERE M_ItemDivisionID = '$id'";
|
||||||
|
|
||||||
|
// echo $sql_u;
|
||||||
|
$query_u = $this->db_onedev->query($sql_u);
|
||||||
|
if(!$query_u){
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("query m_itemdivision update", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
// insert
|
||||||
|
$sql_i = "INSERT INTO m_itemdivision (
|
||||||
|
M_ItemDivisionM_ItemID,
|
||||||
|
M_ItemDivisionDivisionID,
|
||||||
|
M_ItemDivisionIsActive,
|
||||||
|
M_ItemDivisionCreated,
|
||||||
|
M_ItemDivisionCreatedUserID
|
||||||
|
) VALUES (
|
||||||
|
'$M_ItemID',
|
||||||
|
'$M_ItemDivisionDivisionID',
|
||||||
|
'Y',
|
||||||
|
NOW(),
|
||||||
|
$userid
|
||||||
|
)";
|
||||||
|
|
||||||
|
$query_i = $this->db_onedev->query($sql_i);
|
||||||
|
if(!$query_i){
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("query m_itemdivision insert", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm["current_page"] > 0) ? ($prm["current_page"] - 1) * $number_limit : 0;
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
IFNULL(M_ItemDivisionID, 0) AS M_ItemDivisionID,
|
||||||
|
IFNULL(M_ItemDivisionM_ItemID, 0) AS M_ItemDivisionM_ItemID,
|
||||||
|
DivisionName,
|
||||||
|
IFNULL(DivisionID, 0) AS DivisionID,
|
||||||
|
CASE
|
||||||
|
WHEN M_ItemDivisionIsActive = 'Y'
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END as IsChecked
|
||||||
|
from division
|
||||||
|
left join m_itemdivision
|
||||||
|
ON DivisionID = M_ItemDivisionID
|
||||||
|
$where_item_id
|
||||||
|
where DivisionIsActive = 'Y'
|
||||||
|
ORDER BY DivisionID asc";
|
||||||
|
|
||||||
|
$sql_total = "SELECT count(*) as total FROM ($sql) as x";
|
||||||
|
$qry_total = $this->db_onedev->query($sql_total);
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
|
$totalPage = 0;
|
||||||
|
if ($qry_total) {
|
||||||
|
$totalCount = $qry_total->result_array()[0]["total"];
|
||||||
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("select m_itemdivision count error", $this->db_onedev);;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_select = $sql;
|
||||||
|
$qry = $this->db_onedev->query($sql_select);
|
||||||
|
|
||||||
|
if(!$qry){
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("select m_itemdivision error", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_commit();
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"total" => $totalPage,
|
||||||
|
"totalFilter" => $totalCount,
|
||||||
|
"records" => $rows,
|
||||||
|
"sql" => $this->db_onedev->last_query()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($response);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$this->sys_error($exc->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,665 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Approvalallrequest extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "API APPROVAL ALL";
|
||||||
|
// $cek = $this->db->query("select database() as current_db")->result();
|
||||||
|
// print_r($cek);
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listApprove()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$sql = "SELECT S_MenuID,
|
||||||
|
S_MenuName as menuname,
|
||||||
|
S_MenuName as name,
|
||||||
|
S_MenuRegional,
|
||||||
|
S_MenuUrl,
|
||||||
|
S_MenuIcon,
|
||||||
|
S_MenuParentS_MenuID,
|
||||||
|
S_MenuLevel,
|
||||||
|
S_MenuIsParent,
|
||||||
|
S_MenuOrder,
|
||||||
|
S_MenuIsActive
|
||||||
|
|
||||||
|
FROM s_menu
|
||||||
|
WHERE S_MenuID IN (31, 69, 82)";
|
||||||
|
$qry = $this->db->query($sql);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error get list menu");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"records" => $rows
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
$userID = $user['M_UserID'];
|
||||||
|
$approveLevelID = $user['M_UserM_ApproveLevelID'];
|
||||||
|
$loginType = $user['M_UserLocationFlag'];
|
||||||
|
$sqlBranch = '';
|
||||||
|
if ($loginType == 'B' || $loginType == 'RB') {
|
||||||
|
$sqlBranch = "AND PurchaseRequestM_BranchCode = '{$branchCode}'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$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'];
|
||||||
|
|
||||||
|
$params = [$regionalID, $regionalID];
|
||||||
|
|
||||||
|
if ($approveLevelID == '1') {
|
||||||
|
// manager -> verifikator
|
||||||
|
$sqlSupplierPayment = " AND SupplierPaymentIsVerif = 'N' AND SupplierPaymentStatus != 'Verif' ";
|
||||||
|
$sqlStockRequest = " AND (PurchaseRequestVerifiedBy = 0 OR PurchaseRequestVerifiedBy IS NULL) ";
|
||||||
|
$sqlPurchaseOrder = " AND PurchaseOrderApprovedManagerUserID = 0";
|
||||||
|
$sqlRIO = " AND RequestItemOutVerifiedUserID = 0";
|
||||||
|
} else if ($approveLevelID == '2') {
|
||||||
|
// kacab / regional -> approver
|
||||||
|
$sqlSupplierPayment = " AND SupplierPaymentIsApproved = 'N' AND SupplierPaymentStatus = 'Verif'";
|
||||||
|
$sqlStockRequest = " AND PurchaseRequestApprovedBy IS NULL";
|
||||||
|
$sqlPurchaseOrder = " AND PurchaseOrderApprovedUserID IS NULL";
|
||||||
|
$sqlRIO = " AND RequestItemOutVerifiedUserID != 0";
|
||||||
|
}
|
||||||
|
$sqlSelect = "SELECT
|
||||||
|
COUNT(*) total,
|
||||||
|
GROUP_CONCAT(PurchaseRequestNumber SEPARATOR ', ') AS number,
|
||||||
|
MIN(PurchaseRequestDate) AS date,
|
||||||
|
PurchaseRequestStatus as status,
|
||||||
|
'STOCK REQUEST (P)' as type,
|
||||||
|
'p' as flag
|
||||||
|
FROM purchase_request
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y'
|
||||||
|
AND PurchaseRequestStatus = 'Pending'
|
||||||
|
AND PurchaseRequestItemCategoryID = 1
|
||||||
|
AND PurchaseRequestS_RegionalID = ?
|
||||||
|
$sqlBranch
|
||||||
|
$sqlStockRequest
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
COUNT(*) total,
|
||||||
|
GROUP_CONCAT(PurchaseRequestNumber SEPARATOR ', ') AS number,
|
||||||
|
MIN(PurchaseRequestDate) AS date,
|
||||||
|
PurchaseRequestStatus as status,
|
||||||
|
'PURCHASE REQUEST (NP)' as type,
|
||||||
|
'np' as flag
|
||||||
|
FROM purchase_request
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y'
|
||||||
|
AND PurchaseRequestStatus = 'Pending'
|
||||||
|
AND PurchaseRequestItemCategoryID <> 1
|
||||||
|
AND PurchaseRequestS_RegionalID = ?
|
||||||
|
$sqlBranch
|
||||||
|
$sqlStockRequest
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT COUNT(*) as total,
|
||||||
|
GROUP_CONCAT(PurchaseOrderNumber SEPARATOR ', ') AS number,
|
||||||
|
MIN(PurchaseOrderDate) AS date,
|
||||||
|
PurchaseOrderStatus as status,
|
||||||
|
'PURCHASE ORDER' as type,
|
||||||
|
'po' as flag
|
||||||
|
FROM purchase_order
|
||||||
|
WHERE PurchaseOrderIsActive = 'Y'
|
||||||
|
AND PurchaseOrderStatus = 'Pending'
|
||||||
|
$sqlPurchaseOrder
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT COUNT(*) as total,
|
||||||
|
GROUP_CONCAT(PurchaseRequestDirectNumber SEPARATOR ', ') as number,
|
||||||
|
MIN(PurchaseRequestDirectDate) as date,
|
||||||
|
PurchaseRequestDirectStatus as status,
|
||||||
|
'PURCHASE REQUEST DIRECT' as type,
|
||||||
|
'prd' as flag
|
||||||
|
FROM purchase_request_direct
|
||||||
|
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||||
|
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||||
|
AND PurchaseRequestDirectIsActive = 'Y'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT COUNT(*) as total,
|
||||||
|
GROUP_CONCAT(PaymentVoucherNumber SEPARATOR ', ') as number,
|
||||||
|
MIN(DATE(PaymentVoucherDate)) as date,
|
||||||
|
PaymentVoucherStatus as status,
|
||||||
|
'KASIR (REALISASI)' as type,
|
||||||
|
'r' as flag
|
||||||
|
FROM payment_voucher
|
||||||
|
WHERE PaymentVoucherIsActive = 'Y'
|
||||||
|
AND PaymentVoucherStatus = 'Paid'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as total,
|
||||||
|
GROUP_CONCAT(SupplierInvoiceNumber SEPARATOR ', ') as number,
|
||||||
|
MIN(DATE(SupplierInvoiceDraftPaymentDate)) as date,
|
||||||
|
SupplierPaymentStatus as status,
|
||||||
|
'PAYMENT APPROVED' as type,
|
||||||
|
'pa' as flag
|
||||||
|
FROM supplier_payment
|
||||||
|
LEFT JOIN supplier_invoice ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
|
||||||
|
WHERE SupplierPaymentIsActive = 'Y'
|
||||||
|
$sqlSupplierPayment
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT COUNT(*) as total,
|
||||||
|
GROUP_CONCAT(RequestItemOutNumber SEPARATOR ', ') as number,
|
||||||
|
MIN(DATE(RequestItemOutDate)) as date,
|
||||||
|
IF(RequestItemOutStatus = 'Send Request' , 'SendRequest', '') as status,
|
||||||
|
'REQUEST PENGELUARAN BARANG' as type,
|
||||||
|
'rio' as flag
|
||||||
|
FROM request_item_out
|
||||||
|
WHERE RequestItemOutIsActive = 'Y'
|
||||||
|
AND RequestItemOutStatus = 'Send Request'
|
||||||
|
$sqlRIO
|
||||||
|
";
|
||||||
|
|
||||||
|
$qry_end = $this->db->query($sqlSelect, $params);
|
||||||
|
if ($qry_end) {
|
||||||
|
$rows = $qry_end->result_array();
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// echo $this->db->last_query();
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'records' => $rows,
|
||||||
|
"qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
public function searchold()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = '%' . $prm['search'] . '%';
|
||||||
|
|
||||||
|
$date = $prm['date'];
|
||||||
|
$status = $prm['status'];
|
||||||
|
$page = $prm['page'];
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
$loginType = $user['M_UserLocationFlag'];
|
||||||
|
$userID = $user['M_UserID'];
|
||||||
|
|
||||||
|
$sqlBranch = '';
|
||||||
|
if ($loginType == 'B' || $loginType == 'RB') {
|
||||||
|
$sqlBranch = "AND PurchaseRequestM_BranchCode = '{$branchCode}'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = [$search, $search, $regionalID, $search];
|
||||||
|
|
||||||
|
// $sql = "SELECT
|
||||||
|
// PurchaseRequestID prID,
|
||||||
|
// DATE_FORMAT(PurchaseRequestDate, '%d-%m-%Y') prDate,
|
||||||
|
// PurchaseRequestNumber prNumber,
|
||||||
|
// PurchaseRequestRefNumber prRefNumber,
|
||||||
|
// PurchaseRequestNote prNote,
|
||||||
|
// PurchaseRequestTotal prTotal,
|
||||||
|
// PurchaseRequestItemCategoryID prItemType,
|
||||||
|
// ItemCategoryName prItemTypeName,
|
||||||
|
// PurchaseRequestStatus prStatus,
|
||||||
|
// DATE_FORMAT(PurchaseRequestApprovedDate, '%d-%m-%Y %H:%i') prApprovedDate,
|
||||||
|
// a.M_userUserName prApprovedBy,
|
||||||
|
// b.M_UserID prRequestedByID,
|
||||||
|
// b.M_userUserName prRequestedBy,
|
||||||
|
// b.M_UserM_BranchID prRequestedByFromBranch,
|
||||||
|
// S_RegionalName prRegionalName,
|
||||||
|
// M_BranchName prBranchName,
|
||||||
|
// IFNULL(`fn_getitemnamebyprid`(PurchaseRequestID), '') prItemName
|
||||||
|
// FROM purchase_request
|
||||||
|
// JOIN s_regional
|
||||||
|
// ON PurchaseRequestS_RegionalID = S_RegionalID
|
||||||
|
// AND S_RegionalIsActive = 'Y'
|
||||||
|
// JOIN item_category
|
||||||
|
// ON PurchaseRequestItemCategoryID = ItemCategoryID
|
||||||
|
// AND ItemCategoryIsActive = 'Y'
|
||||||
|
// JOIN m_user b
|
||||||
|
// ON PurchaseRequestRequestedBy = b.M_UserID
|
||||||
|
// AND b.M_UserIsActive = 'Y'
|
||||||
|
// LEFT JOIN m_user a
|
||||||
|
// ON PurchaseRequestApprovedBy = a.M_UserID
|
||||||
|
// AND a.M_UserIsActive = 'Y'
|
||||||
|
// LEFT JOIN
|
||||||
|
// m_branch
|
||||||
|
// ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
// WHERE PurchaseRequestIsActive = 'Y'
|
||||||
|
// AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ? OR PurchaseRequestRequestedBy LIKE ?)
|
||||||
|
// AND PurchaseRequestS_RegionalID = ?
|
||||||
|
// AND PurchaseRequestStatus = 'Pending'
|
||||||
|
// $sqlBranch
|
||||||
|
// ORDER BY prDate,prNumber
|
||||||
|
// DESC
|
||||||
|
// LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
|
$sqlSelect = "SELECT
|
||||||
|
PurchaseRequestID AS ID,
|
||||||
|
'PR' AS SourceType,
|
||||||
|
DATE_FORMAT(PurchaseRequestDate, '%d-%m-%Y') AS Date,
|
||||||
|
PurchaseRequestNumber AS Number,
|
||||||
|
PurchaseRequestRefNumber AS RefNumber,
|
||||||
|
PurchaseRequestNote AS Note,
|
||||||
|
PurchaseRequestTotal AS Total,
|
||||||
|
PurchaseRequestItemCategoryID AS ItemCategoryID,
|
||||||
|
ItemCategoryName AS ItemCategoryName,
|
||||||
|
PurchaseRequestStatus AS Status,
|
||||||
|
DATE_FORMAT(PurchaseRequestApprovedDate, '%d-%m-%Y %H:%i') AS ApprovedDate,
|
||||||
|
a.M_userUserName AS ApprovedBy,
|
||||||
|
b.M_UserID AS RequestedByID,
|
||||||
|
b.M_userUserName AS RequestedBy,
|
||||||
|
b.M_UserM_BranchID AS RequestedByFromBranch,
|
||||||
|
S_RegionalName AS RegionalName,
|
||||||
|
M_BranchName AS BranchName,
|
||||||
|
IFNULL(`fn_getitemnamebyprid`(PurchaseRequestID), '') AS ItemName,
|
||||||
|
NULL AS DiscountType,
|
||||||
|
NULL AS DiscountAmount,
|
||||||
|
NULL AS TaxAmount,
|
||||||
|
NULL AS SupplierCode,
|
||||||
|
NULL AS SupplierName,
|
||||||
|
NULL AS WarehouseCode,
|
||||||
|
NULL AS WarehouseName,
|
||||||
|
NULL AS DisplayDate
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional ON PurchaseRequestS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category ON PurchaseRequestItemCategoryID = ItemCategoryID AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b ON PurchaseRequestRequestedBy = b.M_UserID AND b.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a ON PurchaseRequestApprovedBy = a.M_UserID AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_branch ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y'
|
||||||
|
AND PurchaseRequestStatus = 'Pending'
|
||||||
|
$sqlBranch
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ?)
|
||||||
|
AND PurchaseRequestS_RegionalID = ?
|
||||||
|
|
||||||
|
UNION
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
PurchaseOrderID AS ID,
|
||||||
|
'PO' AS SourceType,
|
||||||
|
DATE_FORMAT(PurchaseOrderDate, '%d-%m-%Y') AS Date,
|
||||||
|
PurchaseOrderNumber AS Number,
|
||||||
|
NULL AS RefNumber,
|
||||||
|
PurchaseOrderNote AS Note,
|
||||||
|
0 AS Total,
|
||||||
|
itemCategoryID AS ItemCategoryID,
|
||||||
|
itemCategoryName AS ItemCategoryName,
|
||||||
|
PurchaseOrderStatus AS Status,
|
||||||
|
NULL AS ApprovedDate,
|
||||||
|
NULL AS ApprovedBy,
|
||||||
|
NULL AS RequestedByID,
|
||||||
|
NULL AS RequestedBy,
|
||||||
|
NULL AS RequestedByFromBranch,
|
||||||
|
S_RegionalName AS RegionalName,
|
||||||
|
M_BranchName AS BranchName,
|
||||||
|
NULL AS ItemName,
|
||||||
|
CASE
|
||||||
|
WHEN PurchaseOrderDiscountPercent = 0 THEN 'Absolute'
|
||||||
|
WHEN PurchaseOrderDiscountAmount = 0 THEN 'Percentage'
|
||||||
|
ELSE ''
|
||||||
|
END AS DiscountType,
|
||||||
|
CASE
|
||||||
|
WHEN PurchaseOrderDiscountPercent <> 0 THEN (PurchaseOrderDiscountPercent / 100) * PurchaseOrderSubTotal
|
||||||
|
WHEN PurchaseOrderDiscountAmount <> 0 THEN PurchaseOrderDiscountAmount
|
||||||
|
ELSE 0
|
||||||
|
END AS DiscountAmount,
|
||||||
|
PurchaseOrderTaxAmountPph + PurchaseOrderTaxAmountPpn AS TaxAmount,
|
||||||
|
SupplierCode,
|
||||||
|
SupplierName,
|
||||||
|
WarehouseCode,
|
||||||
|
CASE
|
||||||
|
WHEN WarehouseType = 'B' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', M_BranchName)
|
||||||
|
WHEN WarehouseType = 'R' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', S_RegionalName)
|
||||||
|
ELSE ''
|
||||||
|
END AS WarehouseName,
|
||||||
|
DATE_FORMAT(PurchaseOrderDate, '%d %M %Y') AS DisplayDate
|
||||||
|
FROM purchase_order
|
||||||
|
LEFT JOIN item_category ON PurchaseOrderItemCategoryID = itemCategoryID
|
||||||
|
LEFT JOIN supplier ON SupplierID = PurchaseOrderSupplierID
|
||||||
|
LEFT JOIN warehouse ON WarehouseID = PurchaseOrderWarehouseID
|
||||||
|
LEFT JOIN s_regional ON S_RegionalID = WarehouseS_RegionalID
|
||||||
|
LEFT JOIN m_branch ON M_BranchID = WarehouseM_BranchID
|
||||||
|
WHERE PurchaseOrderIsActive = 'Y'
|
||||||
|
AND PurchaseOrderStatus = 'Pending'
|
||||||
|
AND PurchaseOrderNumber LIKE ?
|
||||||
|
)";
|
||||||
|
|
||||||
|
$sqlTotal = "SELECT COUNT(*) AS total FROM ($sqlSelect) AS x";
|
||||||
|
$qry = $this->db->query($sqlTotal, $params);
|
||||||
|
|
||||||
|
$number_limit = 20;
|
||||||
|
$number_offset = 0;
|
||||||
|
if ($page > 0) {
|
||||||
|
$number_offset = ($prm['page'] - 1) * $number_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
|
$totalPage = 0;
|
||||||
|
if ($qry) {
|
||||||
|
$totalCount = $qry->row_array()["total"];
|
||||||
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Error searching count");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_painated = $sqlSelect . " LIMIT ? OFFSET ?";
|
||||||
|
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||||
|
|
||||||
|
$qry_end = $this->db->query($sql_painated, $params_paginated);
|
||||||
|
if ($qry_end) {
|
||||||
|
$rows = $qry_end->result_array();
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// echo $this->db->last_query();
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'total' => $totalPage,
|
||||||
|
'records' => $rows,
|
||||||
|
// "qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search_x()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = '%' . $prm['search'] . '%';
|
||||||
|
|
||||||
|
$date = $prm['date'];
|
||||||
|
$status = $prm['status'];
|
||||||
|
$page = $prm['page'];
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
$loginType = $user['M_UserLocationFlag'];
|
||||||
|
$userID = $user['M_UserID'];
|
||||||
|
|
||||||
|
$sqlBranch = '';
|
||||||
|
if ($loginType == 'B' || $loginType == 'RB') {
|
||||||
|
$sqlBranch = "AND PurchaseRequestM_BranchCode = '{$branchCode}'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = [$search, $search, $regionalID, $search];
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
PurchaseRequestID prID,
|
||||||
|
DATE_FORMAT(PurchaseRequestDate, '%d-%m-%Y') prDate,
|
||||||
|
PurchaseRequestNumber prNumber,
|
||||||
|
PurchaseRequestRefNumber prRefNumber,
|
||||||
|
PurchaseRequestNote prNote,
|
||||||
|
PurchaseRequestTotal prTotal,
|
||||||
|
PurchaseRequestItemCategoryID prItemType,
|
||||||
|
ItemCategoryName prItemTypeName,
|
||||||
|
PurchaseRequestStatus prStatus,
|
||||||
|
DATE_FORMAT(PurchaseRequestApprovedDate, '%d-%m-%Y %H:%i') prApprovedDate,
|
||||||
|
a.M_userUserName prApprovedBy,
|
||||||
|
b.M_UserID prRequestedByID,
|
||||||
|
b.M_userUserName prRequestedBy,
|
||||||
|
b.M_UserM_BranchID prRequestedByFromBranch,
|
||||||
|
S_RegionalName prRegionalName,
|
||||||
|
M_BranchName prBranchName,
|
||||||
|
IFNULL(`fn_getitemnamebyprid`(PurchaseRequestID), '') prItemName
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional
|
||||||
|
ON PurchaseRequestS_RegionalID = S_RegionalID
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category
|
||||||
|
ON PurchaseRequestItemCategoryID = ItemCategoryID
|
||||||
|
AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b
|
||||||
|
ON PurchaseRequestRequestedBy = b.M_UserID
|
||||||
|
AND b.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a
|
||||||
|
ON PurchaseRequestApprovedBy = a.M_UserID
|
||||||
|
AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN
|
||||||
|
m_branch
|
||||||
|
ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y'
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ? OR PurchaseRequestRequestedBy LIKE ?)
|
||||||
|
AND PurchaseRequestS_RegionalID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'
|
||||||
|
$sqlBranch
|
||||||
|
ORDER BY prDate,prNumber
|
||||||
|
DESC
|
||||||
|
LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
|
$sqlSelect = "(SELECT
|
||||||
|
PurchaseRequestID AS ID,
|
||||||
|
'PR' AS SourceType,
|
||||||
|
DATE_FORMAT(PurchaseRequestDate, '%d-%m-%Y') AS Date,
|
||||||
|
PurchaseRequestNumber AS Number,
|
||||||
|
PurchaseRequestRefNumber AS RefNumber,
|
||||||
|
PurchaseRequestNote AS Note,
|
||||||
|
PurchaseRequestTotal AS Total,
|
||||||
|
PurchaseRequestItemCategoryID AS ItemCategoryID,
|
||||||
|
ItemCategoryName AS ItemCategoryName,
|
||||||
|
PurchaseRequestStatus AS Status,
|
||||||
|
DATE_FORMAT(PurchaseRequestApprovedDate, '%d-%m-%Y %H:%i') AS ApprovedDate,
|
||||||
|
a.M_userUserName AS ApprovedBy,
|
||||||
|
b.M_UserID AS RequestedByID,
|
||||||
|
b.M_userUserName AS RequestedBy,
|
||||||
|
b.M_UserM_BranchID AS RequestedByFromBranch,
|
||||||
|
S_RegionalName AS RegionalName,
|
||||||
|
M_BranchName AS BranchName,
|
||||||
|
IFNULL(`fn_getitemnamebyprid`(PurchaseRequestID), '') AS ItemName,
|
||||||
|
NULL AS DiscountType,
|
||||||
|
NULL AS DiscountAmount,
|
||||||
|
NULL AS TaxAmount,
|
||||||
|
NULL AS SupplierCode,
|
||||||
|
NULL AS SupplierName,
|
||||||
|
NULL AS WarehouseCode,
|
||||||
|
NULL AS WarehouseName,
|
||||||
|
NULL AS DisplayDate
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional ON PurchaseRequestS_RegionalID = S_RegionalID AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category ON PurchaseRequestItemCategoryID = ItemCategoryID AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b ON PurchaseRequestRequestedBy = b.M_UserID AND b.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a ON PurchaseRequestApprovedBy = a.M_UserID AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_branch ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y'
|
||||||
|
AND PurchaseRequestStatus = 'Pending'
|
||||||
|
$sqlBranch
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ?)
|
||||||
|
AND PurchaseRequestS_RegionalID = ?
|
||||||
|
)
|
||||||
|
UNION
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
PurchaseOrderID AS ID,
|
||||||
|
'PO' AS SourceType,
|
||||||
|
DATE_FORMAT(PurchaseOrderDate, '%d-%m-%Y') AS Date,
|
||||||
|
PurchaseOrderNumber AS Number,
|
||||||
|
NULL AS RefNumber,
|
||||||
|
PurchaseOrderNote AS Note,
|
||||||
|
0 AS Total,
|
||||||
|
itemCategoryID AS ItemCategoryID,
|
||||||
|
itemCategoryName AS ItemCategoryName,
|
||||||
|
PurchaseOrderStatus AS Status,
|
||||||
|
NULL AS ApprovedDate,
|
||||||
|
NULL AS ApprovedBy,
|
||||||
|
NULL AS RequestedByID,
|
||||||
|
NULL AS RequestedBy,
|
||||||
|
NULL AS RequestedByFromBranch,
|
||||||
|
S_RegionalName AS RegionalName,
|
||||||
|
M_BranchName AS BranchName,
|
||||||
|
NULL AS ItemName,
|
||||||
|
CASE
|
||||||
|
WHEN PurchaseOrderDiscountPercent = 0 THEN 'Absolute'
|
||||||
|
WHEN PurchaseOrderDiscountAmount = 0 THEN 'Percentage'
|
||||||
|
ELSE ''
|
||||||
|
END AS DiscountType,
|
||||||
|
CASE
|
||||||
|
WHEN PurchaseOrderDiscountPercent <> 0 THEN (PurchaseOrderDiscountPercent / 100) * PurchaseOrderSubTotal
|
||||||
|
WHEN PurchaseOrderDiscountAmount <> 0 THEN PurchaseOrderDiscountAmount
|
||||||
|
ELSE 0
|
||||||
|
END AS DiscountAmount,
|
||||||
|
PurchaseOrderTaxAmountPph + PurchaseOrderTaxAmountPpn AS TaxAmount,
|
||||||
|
SupplierCode,
|
||||||
|
SupplierName,
|
||||||
|
WarehouseCode,
|
||||||
|
CASE
|
||||||
|
WHEN WarehouseType = 'B' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', M_BranchName)
|
||||||
|
WHEN WarehouseType = 'R' THEN CONCAT(WarehouseCode,' ', WarehouseName, ' - ', S_RegionalName)
|
||||||
|
ELSE ''
|
||||||
|
END AS WarehouseName,
|
||||||
|
DATE_FORMAT(PurchaseOrderDate, '%d %M %Y') AS DisplayDate
|
||||||
|
FROM purchase_order
|
||||||
|
LEFT JOIN item_category ON PurchaseOrderItemCategoryID = itemCategoryID
|
||||||
|
LEFT JOIN supplier ON SupplierID = PurchaseOrderSupplierID
|
||||||
|
LEFT JOIN warehouse ON WarehouseID = PurchaseOrderWarehouseID
|
||||||
|
LEFT JOIN s_regional ON S_RegionalID = WarehouseS_RegionalID
|
||||||
|
LEFT JOIN m_branch ON M_BranchID = WarehouseM_BranchID
|
||||||
|
WHERE PurchaseOrderIsActive = 'Y'
|
||||||
|
AND PurchaseOrderStatus = 'Pending'
|
||||||
|
AND PurchaseOrderNumber LIKE ?
|
||||||
|
)
|
||||||
|
ORDER BY Date DESC";
|
||||||
|
|
||||||
|
$sqlTotal = "SELECT COUNT(*) AS total FROM ($sqlSelect) AS x";
|
||||||
|
$qry = $this->db->query($sqlTotal, $params);
|
||||||
|
|
||||||
|
$number_limit = 20;
|
||||||
|
$number_offset = 0;
|
||||||
|
if ($page > 0) {
|
||||||
|
$number_offset = ($prm['page'] - 1) * $number_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalCount = 0;
|
||||||
|
$totalPage = 0;
|
||||||
|
if ($qry) {
|
||||||
|
$totalCount = $qry->row_array()["total"];
|
||||||
|
$totalPage = ceil($totalCount / $number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Error searching count");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_painated = $sqlSelect . " LIMIT ? OFFSET ?";
|
||||||
|
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||||
|
|
||||||
|
$qry_end = $this->db->query($sql_painated, $params_paginated);
|
||||||
|
if ($qry_end) {
|
||||||
|
$rows = $qry_end->result_array();
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $this->db->last_query();
|
||||||
|
exit;
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'total' => $totalPage,
|
||||||
|
'records' => $rows,
|
||||||
|
// "qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
83
application/controllers/mockup/approvalall/Tasklist.php
Normal file
83
application/controllers/mockup/approvalall/Tasklist.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Tasklist extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "API LISTING TASK";
|
||||||
|
// $cek = $this->db->query("select database() as current_db")->result();
|
||||||
|
// print_r($cek);
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
$userID = $user['M_UserID'];
|
||||||
|
$loginType = $user['M_UserLocationFlag'];
|
||||||
|
$sqlBranch = '';
|
||||||
|
if ($loginType == 'B' || $loginType == 'RB') {
|
||||||
|
$sqlBranch = "AND PurchaseRequestM_BranchCode = '{$branchCode}'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = [$regionalID, $regionalID, $regionalID];
|
||||||
|
$sqlSelect = "SELECT COUNT(*) as total,
|
||||||
|
GROUP_CONCAT(PaymentVoucherNumber SEPARATOR ', ') as number,
|
||||||
|
MIN(DATE(PaymentVoucherDate)) as date,
|
||||||
|
PaymentVoucherStatus as status,
|
||||||
|
'PAID PR' as type,
|
||||||
|
'p' as flag
|
||||||
|
FROM payment_voucher
|
||||||
|
WHERE PaymentVoucherIsActive = 'Y'
|
||||||
|
AND PaymentVoucherStatus = 'Draft'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT count(*) as total,
|
||||||
|
GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as number,
|
||||||
|
MIN(DATE(SupplierInvoiceDraftPaymentDate)) as date,
|
||||||
|
SupplierPaymentIsConfirm as status,
|
||||||
|
'PAYMENT CASHIER' as type,
|
||||||
|
'pc' as flag
|
||||||
|
FROM supplier_invoice
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||||
|
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||||
|
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||||
|
WHERE SupplierInvoiceIsActive = 'Y'
|
||||||
|
AND SupplierPaymentIsApproved = 'Y'
|
||||||
|
AND SupplierPaymentIsVerif = 'Y'
|
||||||
|
AND SupplierPaymentIsConfirm = 'N'
|
||||||
|
";
|
||||||
|
|
||||||
|
$qry_end = $this->db->query($sqlSelect, []);
|
||||||
|
if ($qry_end) {
|
||||||
|
$rows = $qry_end->result_array();
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// echo $this->db->last_query();
|
||||||
|
// exit;
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'records' => $rows,
|
||||||
|
// "qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
3044
application/controllers/mockup/itemout/Itemoutv3.php
Normal file
3044
application/controllers/mockup/itemout/Itemoutv3.php
Normal file
File diff suppressed because it is too large
Load Diff
1272
application/controllers/mockup/itemout/Itemusagev3.php
Normal file
1272
application/controllers/mockup/itemout/Itemusagev3.php
Normal file
File diff suppressed because it is too large
Load Diff
2231
application/controllers/mockup/itemout/RequestItemOut.php
Normal file
2231
application/controllers/mockup/itemout/RequestItemOut.php
Normal file
File diff suppressed because it is too large
Load Diff
712
application/controllers/mockup/masterdata/Expedition.php
Normal file
712
application/controllers/mockup/masterdata/Expedition.php
Normal file
@@ -0,0 +1,712 @@
|
|||||||
|
<?php
|
||||||
|
class Expedition extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db;
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
function index()
|
||||||
|
{
|
||||||
|
echo "Api: Expedition";
|
||||||
|
}
|
||||||
|
function search()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = "%%";
|
||||||
|
if (isset($prm['search'])) {
|
||||||
|
$search = trim($prm["search"]);
|
||||||
|
$search = '%' . $prm['search'] . '%';
|
||||||
|
}
|
||||||
|
$order_by = "ExpeditionName";
|
||||||
|
if (isset($prm['order_by'])) {
|
||||||
|
$order_by = trim($prm["order_by"]);
|
||||||
|
}
|
||||||
|
$order_type = "asc";
|
||||||
|
if (isset($prm['order_type'])) {
|
||||||
|
$order_type = trim($prm["order_type"]);
|
||||||
|
}
|
||||||
|
$order = $order_by . ' ' . $order_type;
|
||||||
|
$perpage = 10;
|
||||||
|
$offset = ($prm['current_page'] - 1) * $perpage;
|
||||||
|
$count = "SELECT count(ExpeditionID) as total
|
||||||
|
FROM expedition
|
||||||
|
WHERE
|
||||||
|
ExpeditionIsActive = 'Y'
|
||||||
|
AND ExpeditionName like ?";
|
||||||
|
$qry_count = $this->db->query($count, array($search));
|
||||||
|
$total_count = 0;
|
||||||
|
$total_page = 0;
|
||||||
|
if ($qry_count) {
|
||||||
|
$total_count = $qry_count->row()->total;
|
||||||
|
$total_page = ceil($total_count / $perpage);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Expedition count error", $this->db->last_query());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$sql = "SELECT ExpeditionID as id,
|
||||||
|
ExpeditionName as name,
|
||||||
|
ExpeditionIsInternal as internal
|
||||||
|
FROM expedition
|
||||||
|
WHERE
|
||||||
|
ExpeditionIsActive = 'Y'
|
||||||
|
AND ExpeditionName like ?
|
||||||
|
ORDER BY $order LIMIT ? OFFSET ?";
|
||||||
|
$qry = $this->db->query($sql, array($search, $perpage, $offset));
|
||||||
|
$lst_qryyy = $this->db->last_query();
|
||||||
|
if ($qry) {
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
|
||||||
|
if (count($rows) > 0) {
|
||||||
|
foreach ($rows as $key => $value) {
|
||||||
|
$sql = "SELECT ExpeditionStaffID as id ,
|
||||||
|
ExpeditionStaffName as staffName,
|
||||||
|
ExpeditionStaffMobile as staffMobile,
|
||||||
|
ExpeditionStaffM_StaffID as staffId
|
||||||
|
FROM expeditionstaff
|
||||||
|
WHERE ExpeditionStaffIsActive = 'Y'
|
||||||
|
AND ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry = $this->db->query($sql, array($value['id']));
|
||||||
|
if ($qry) {
|
||||||
|
$rows[$key]['staff'] =
|
||||||
|
$qry->result_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Expedition data error", $this->db->last_query());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => $total_page,
|
||||||
|
"total_filter" => $total_count,
|
||||||
|
"records" => $rows,
|
||||||
|
"qry" => $lst_qryyy
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function get_staff()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$count = "SELECT count(M_StaffID) as total
|
||||||
|
FROM m_staff
|
||||||
|
WHERE M_StaffIsActive = 'Y'
|
||||||
|
AND M_StaffIsCourier = 'Y' ;";
|
||||||
|
$qry_count = $this->db->query($count);
|
||||||
|
$total_count = 0;
|
||||||
|
if ($qry_count) {
|
||||||
|
$total_count = $qry_count->row()->total;
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("Expedition count error", $this->db->last_query());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "SELECT M_StaffID as staffId,
|
||||||
|
M_StaffName as staffName,
|
||||||
|
M_StaffHP as staffMobile
|
||||||
|
FROM m_staff
|
||||||
|
WHERE M_StaffIsActive = 'Y'
|
||||||
|
AND M_StaffIsCourier = 'Y' ORDER BY M_StaffName asc ";
|
||||||
|
$qry = $this->db->query($sql);
|
||||||
|
$staff = $qry->result_array();
|
||||||
|
$result = array(
|
||||||
|
"total_filter" => $total_count,
|
||||||
|
"records" => $staff,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function add()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
$name = "";
|
||||||
|
if (isset($prm['name'])) {
|
||||||
|
$name = trim($prm["name"]);
|
||||||
|
}
|
||||||
|
$isInternal = "";
|
||||||
|
if (isset($prm['isInternal'])) {
|
||||||
|
$isInternal = trim($prm["isInternal"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_start();
|
||||||
|
$this->db->trans_strict(FALSE);
|
||||||
|
$last_id = 0;
|
||||||
|
$staff_log = array();
|
||||||
|
$sql = "INSERT INTO expedition
|
||||||
|
(ExpeditionName,
|
||||||
|
ExpeditionIsInternal,
|
||||||
|
ExpeditionIsActive,
|
||||||
|
ExpeditionCreated,
|
||||||
|
ExpeditionLastUpdated,
|
||||||
|
ExpeditionUserID)
|
||||||
|
VALUES
|
||||||
|
(?,
|
||||||
|
?,
|
||||||
|
'Y',
|
||||||
|
NOW(),
|
||||||
|
NOW(),
|
||||||
|
?)";
|
||||||
|
$qry = $this->db->query($sql, array($name, $isInternal, $userid));
|
||||||
|
if ($qry) {
|
||||||
|
$last_id = $this->db->insert_id();
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("save expedition error", $this->db->last_query());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (count($prm['staff']) > 0) {
|
||||||
|
foreach ($prm['staff'] as $key => $value) {
|
||||||
|
$stafName = trim($value['staffName']);
|
||||||
|
$stafMobile = trim($value['staffMobile']);
|
||||||
|
$staffId = trim($value['staffId']);
|
||||||
|
$sql = "INSERT INTO expeditionstaff
|
||||||
|
(ExpeditionStaffExpeditionID,
|
||||||
|
ExpeditionStaffName,
|
||||||
|
ExpeditionStaffMobile,
|
||||||
|
ExpeditionStaffM_StaffID,
|
||||||
|
ExpeditionStaffIsActive,
|
||||||
|
ExpeditionStaffUserID,
|
||||||
|
ExpeditionStaffCreated,
|
||||||
|
ExpeditionStaffLastUpdated)
|
||||||
|
VALUES
|
||||||
|
(?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
'Y',
|
||||||
|
?,
|
||||||
|
NOW(),
|
||||||
|
NOW()
|
||||||
|
)";
|
||||||
|
$qry = $this->db->query($sql, array($last_id, $stafName, $stafMobile, $staffId, $userid));
|
||||||
|
$insert_id = $this->db->insert_id();
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("save expedition error", $this->db->last_query());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql_json_after = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
WHERE
|
||||||
|
ExpeditionStaffID = ?";
|
||||||
|
$qry_json_after = $this->db->query($sql_json_after, [$insert_id]);
|
||||||
|
|
||||||
|
$json_after = $qry_json_after->row_array();
|
||||||
|
|
||||||
|
array_push($staff_log, $qry_json_after->row_array());
|
||||||
|
|
||||||
|
if (!$qry_json_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"qry" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
|
||||||
|
(ExpeditionStaffLogExpeditionStaffID,
|
||||||
|
ExpeditionStaffLogStatus,
|
||||||
|
ExpeditionStaffLogJSONAfter,
|
||||||
|
ExpeditionStaffLogUserID ,
|
||||||
|
ExpeditionStaffLogCreated)
|
||||||
|
VALUES(?,'ADD', ?,?, now() )";
|
||||||
|
$qry_insert_log = $this->db->query($sql_insert_log, [$insert_id, json_encode($json_after), $userid]);
|
||||||
|
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"qry" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sql_json_after = "SELECT * FROM
|
||||||
|
expedition
|
||||||
|
WHERE ExpeditionID = ?";
|
||||||
|
$affected_rows = $this->db->affected_rows();
|
||||||
|
$qry_json_after = $this->db->query($sql_json_after, [$last_id]);
|
||||||
|
$json_after = $qry_json_after->row_array();
|
||||||
|
if (!$qry_json_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_after['expeditionstaff'] = $staff_log;
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expedition_log
|
||||||
|
(ExpeditionLogStatus,
|
||||||
|
ExpeditionLogExpeditionID,
|
||||||
|
ExpeditionLogJSONAfter,
|
||||||
|
ExpeditionLogUserID,
|
||||||
|
ExpeditionLogCreated)
|
||||||
|
VALUES('ADD',?, ?,?, NOW() )";
|
||||||
|
$qry_insert_log = $this->db->query($sql_insert_log, [$last_id, json_encode($json_after), $userid]);
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"msg" => "failed insert expedition log",
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"qry" => $this->db->last_query(),
|
||||||
|
"json_after" => $json_after
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$this->db->trans_complete();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"affected_rows" => $affected_rows,
|
||||||
|
"inserted_id" => $last_id,
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function edit()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
$name = "";
|
||||||
|
if (isset($prm['name'])) {
|
||||||
|
$name = trim($prm["name"]);
|
||||||
|
}
|
||||||
|
$isInternal = "";
|
||||||
|
if (isset($prm['isInternal'])) {
|
||||||
|
$isInternal = trim($prm["isInternal"]);
|
||||||
|
}
|
||||||
|
$id = $prm['id'];
|
||||||
|
$sql_json_before = "SELECT * FROM
|
||||||
|
expedition
|
||||||
|
WHERE ExpeditionID = ?";
|
||||||
|
$affected_rows = $this->db->affected_rows();
|
||||||
|
$qry_json_before = $this->db->query($sql_json_before, [$id]);
|
||||||
|
if (!$qry_json_before) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_expedition_before = $qry_json_before->row_array();
|
||||||
|
|
||||||
|
$sql_json_before = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
WHERE ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry_json_before = $this->db->query($sql_json_before, [$id]);
|
||||||
|
if (!$qry_json_before) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_expedition_before['expeditionstaff'] = $qry_json_before->result_array();
|
||||||
|
$isInternalBefore = $json_expedition_before['ExpeditionIsInternal'];
|
||||||
|
$this->db->trans_start();
|
||||||
|
$this->db->trans_strict(FALSE);
|
||||||
|
$sql = "UPDATE expedition SET
|
||||||
|
ExpeditionName = ? ,
|
||||||
|
ExpeditionIsInternal = ?,
|
||||||
|
ExpeditionLastUpdated = now()
|
||||||
|
WHERE ExpeditionID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$name, $isInternal, $id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$last_qry = "";
|
||||||
|
//ISINTERNAL SAMA DENGAN KONDISI SEBELUMNYA
|
||||||
|
if ($isInternalBefore == $isInternal) {
|
||||||
|
// APABILA STAFF LEBIH DARI 0
|
||||||
|
if (count($prm['staff']) > 0) {
|
||||||
|
$sql = "UPDATE expeditionstaff SET
|
||||||
|
ExpeditionStaffIsActive = 'N'
|
||||||
|
WHERE ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
//PERULANGAN SETIAP STAFF
|
||||||
|
foreach ($prm['staff'] as $key => $value) {
|
||||||
|
$staffName = trim($value['staffName']);
|
||||||
|
$staffMobile = trim($value['staffMobile']);
|
||||||
|
$staffId = trim($value['id']);
|
||||||
|
$mStaffId = trim($value['staffId']);
|
||||||
|
//APABILA STAFFID YANG AKAN DI UBAH LEBIH DARI 0
|
||||||
|
if (intval($staffId) > 0) {
|
||||||
|
$sql_before = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
where ExpeditionStaffID = ?";
|
||||||
|
|
||||||
|
$qry_before = $this->db->query($sql_before, [$staffId]);
|
||||||
|
if (!$qry_before) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_before = json_encode($qry_before->row_array());
|
||||||
|
$sql = "UPDATE expeditionstaff SET
|
||||||
|
ExpeditionStaffName = ?,
|
||||||
|
ExpeditionStaffMobile =?,
|
||||||
|
ExpeditionStaffM_StaffID= ?,
|
||||||
|
ExpeditionStaffIsActive= 'Y',
|
||||||
|
ExpeditionStaffLastUpdated= now()
|
||||||
|
WHERE ExpeditionStaffID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$staffName, $staffMobile, $mStaffId, $staffId]);
|
||||||
|
$last_qry = $this->db->last_query();
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql_after = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
where ExpeditionStaffID = ?";
|
||||||
|
$qry_after = $this->db->query($sql_after, [$staffId]);
|
||||||
|
if (!$qry_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_after = json_encode($qry_after->row_array());
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
|
||||||
|
VALUES(null,?,'EDIT', ?, ?,?, now() )";
|
||||||
|
$qry_insert_log = $this->db->query($sql_insert_log, [$id, $json_before, $json_after, $userid]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("save expedition error", $this->db->last_query());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
//APABILA STAFF ID == 0
|
||||||
|
} else {
|
||||||
|
$sql = "INSERT INTO expeditionstaff
|
||||||
|
VALUES(null, ?, ?, ?,?,'Y',?, now(), now())";
|
||||||
|
$qry = $this->db->query($sql, array($id, $staffName, $staffMobile, $mStaffId, $userid));
|
||||||
|
$last_qry = $this->db->last_query();
|
||||||
|
$insert_id = $this->db->insert_id();
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql_after = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
where ExpeditionStaffID = ?";
|
||||||
|
$qry_after = $this->db->query($sql_after, [$insert_id]);
|
||||||
|
if (!$qry_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_after = json_encode($qry_after->row_array());
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
|
||||||
|
VALUES(null,?,'ADD', null, ?,?, now() )";
|
||||||
|
$qry_insert_log = $this->db->query($sql_insert_log, [$insert_id, $json_after, $userid]);
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//ISINTERNAL TIDAK SAMA DENGAN KONDISI SEBELUMNYA
|
||||||
|
} else {
|
||||||
|
if (count($prm['staff']) > 0) {
|
||||||
|
$sql = "UPDATE expeditionstaff SET
|
||||||
|
ExpeditionStaffIsActive = 'N'
|
||||||
|
WHERE ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
foreach ($prm['staff'] as $key => $value) {
|
||||||
|
$staffName = trim($value['staffName']);
|
||||||
|
$staffMobile = trim($value['staffMobile']);
|
||||||
|
$staffId = trim($value['id']);
|
||||||
|
$mStaffId = trim($value['staffId']);
|
||||||
|
$sql = "INSERT INTO expeditionstaff
|
||||||
|
VALUES(null, ?, ?, ?,?,'Y',?, now(), now())";
|
||||||
|
$qry = $this->db->query($sql, array($id, $staffName, $staffMobile, $mStaffId, $userid));
|
||||||
|
$last_qry = $this->db->last_query();
|
||||||
|
$insert_id = $this->db->insert_id();
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql_after = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
where ExpeditionStaffID = ?";
|
||||||
|
$qry_after = $this->db->query($sql_after, [$insert_id]);
|
||||||
|
if (!$qry_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_after = json_encode($qry_after->row_array());
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expeditionstaff_log
|
||||||
|
VALUES(null,?,'ADD', null, ?,?, now() )";
|
||||||
|
$qry_insert_log = $this->db->query($sql_insert_log, [$insert_id, $json_after, $userid]);
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->db->trans_complete();
|
||||||
|
$sql_json_after = "SELECT expedition.* FROM
|
||||||
|
expedition
|
||||||
|
WHERE ExpeditionID = ?";
|
||||||
|
$qry_json_after = $this->db->query($sql_json_after, [$id]);
|
||||||
|
if (!$qry_json_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_after = $qry_json_after->row_array();
|
||||||
|
$sql_json_after = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
WHERE ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry_json_after = $this->db->query($sql_json_after, [$id]);
|
||||||
|
$json_after['expeditionstaff'] = $qry_json_after->result_array();
|
||||||
|
if (!$qry_json_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expedition_log
|
||||||
|
VALUES(null,'EDIT',?, ?, ?,?, now() )";
|
||||||
|
$qry_insert_log = $this->db->query(
|
||||||
|
$sql_insert_log,
|
||||||
|
[$id, json_encode($json_expedition_before), json_encode($json_after), $userid]
|
||||||
|
);
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = array(
|
||||||
|
"message" => '',
|
||||||
|
"sql_log" => $this->db->last_query(),
|
||||||
|
"sql" => $this->db->last_query(),
|
||||||
|
"last_qry" => $last_qry
|
||||||
|
);
|
||||||
|
$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");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
$id = "";
|
||||||
|
if (isset($prm['id'])) {
|
||||||
|
$id = trim($prm["id"]);
|
||||||
|
}
|
||||||
|
if ($id == "" || !$id) {
|
||||||
|
$error = array(
|
||||||
|
"message" => "id is mandatory",
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$this->db->trans_start();
|
||||||
|
$this->db->trans_strict(FALSE);
|
||||||
|
$sql = "UPDATE expedition
|
||||||
|
SET ExpeditionIsActive = 'N',
|
||||||
|
ExpeditionLastUpdated = NOW(),
|
||||||
|
ExpeditionUserID = ?
|
||||||
|
WHERE ExpeditionID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userid, $id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$sql = "UPDATE expeditionstaff SET
|
||||||
|
ExpeditionStaffIsActive = 'N',
|
||||||
|
ExpeditionStaffUserID = ?,
|
||||||
|
ExpeditionStaffLastUpdated = NOW()
|
||||||
|
WHERE ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userid, $id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->db->trans_complete();
|
||||||
|
$sql_json_after = "SELECT * FROM
|
||||||
|
expedition
|
||||||
|
WHERE ExpeditionID = ?";
|
||||||
|
$qry_json_after = $this->db->query($sql_json_after, [$id]);
|
||||||
|
if (!$qry_json_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$json_after = $qry_json_after->row_array();
|
||||||
|
$sql_json_after = "SELECT * FROM
|
||||||
|
expeditionstaff
|
||||||
|
WHERE ExpeditionStaffExpeditionID = ?";
|
||||||
|
$qry_json_after = $this->db->query($sql_json_after, [$id]);
|
||||||
|
$json_after['expeditionstaff'] = $qry_json_after->result_array();
|
||||||
|
if (!$qry_json_after) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql_insert_log = "INSERT INTO acc_one_log.expedition_log
|
||||||
|
VALUES(null,'DELETE',?, NULL, ?,?, now() )";
|
||||||
|
$qry_insert_log = $this->db->query(
|
||||||
|
$sql_insert_log,
|
||||||
|
[$id, json_encode($json_after), $userid]
|
||||||
|
);
|
||||||
|
if (!$qry_insert_log) {
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db->error()["message"],
|
||||||
|
"sql" => $this->db->last_query()
|
||||||
|
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$result = array(
|
||||||
|
"message" => '',
|
||||||
|
"sql_log" => $this->db->last_query(),
|
||||||
|
"sql" => $this->db->last_query(),
|
||||||
|
"json_after" => $json_after
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
241
application/controllers/mockup/masterdata/Priviledge.php
Executable file
241
application/controllers/mockup/masterdata/Priviledge.php
Executable file
@@ -0,0 +1,241 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Priviledge extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "USERGROUP PRIVILEDGE API";
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lookupusergroup()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = $prm['search'];
|
||||||
|
$all = $prm['all'];
|
||||||
|
$limit = '';
|
||||||
|
if ($all == 'N') {
|
||||||
|
$limit = ' LIMIT 10';
|
||||||
|
}
|
||||||
|
$sql = "select COUNT(*) as total
|
||||||
|
from m_usergroup
|
||||||
|
where
|
||||||
|
M_UserGroupIsActive = 'Y'";
|
||||||
|
$sql_param = array($search);
|
||||||
|
$total = $this->db_onedev->query($sql, $sql_param)->row()->total;
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "select M_UserGroupID as id, M_UserGroupDashboard as dashboard, M_UserGroupName as name, M_UserGroupIsClinic as clinic, M_UserGroupName as description , 'xxx' as usergrouptype
|
||||||
|
from m_usergroup
|
||||||
|
where
|
||||||
|
M_UserGroupName LIKE CONCAT('%','{$search}','%') AND
|
||||||
|
M_UserGroupIsActive = 'Y' $limit";
|
||||||
|
$sql_param = array($search);
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_usergroup select");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array("total" => $total, "total_filter" => count($rows), "records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lookuppriviledge()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$sql = "SELECT S_MenuID as id, S_MenuUrl, S_MenuName as name, '' as childs FROM s_menu WHERE S_MenuParentS_MenuID = 0 AND S_MenuIsActive = 'Y' ORDER BY S_MenuOrder ASC";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if ($prm['code'] == 'R') {
|
||||||
|
foreach ($rows as $k => $v) {
|
||||||
|
if ($v['S_MenuUrl'] == '#') {
|
||||||
|
$sql = " SELECT S_MenuID as id, S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
|
||||||
|
FROM s_menu
|
||||||
|
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
|
||||||
|
WHERE
|
||||||
|
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$v['id']}'
|
||||||
|
ORDER BY S_MenuOrder ASC";
|
||||||
|
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
|
||||||
|
if ($rows[$k]['childs']) {
|
||||||
|
foreach ($rows[$k]['childs'] as $kx => $vx) {
|
||||||
|
if ($vx['S_MenuUrl'] == '#') {
|
||||||
|
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
|
||||||
|
FROM s_menu
|
||||||
|
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
|
||||||
|
WHERE
|
||||||
|
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$vx['id']}'
|
||||||
|
ORDER BY S_MenuOrder ASC";
|
||||||
|
$rows[$k]['childs'][$kx]['childs'] = $this->db_onedev->query($sql)->result_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
|
||||||
|
FROM s_menu
|
||||||
|
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
|
||||||
|
WHERE
|
||||||
|
S_MenuIsActive = 'Y' AND S_MenuID = '{$v['id']}'
|
||||||
|
ORDER BY S_MenuOrder ASC";
|
||||||
|
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($rows as $k => $v) {
|
||||||
|
if ($v['S_MenuUrl'] == '#') {
|
||||||
|
$sql = " SELECT S_MenuID as id, S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
|
||||||
|
FROM s_menu
|
||||||
|
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
|
||||||
|
WHERE
|
||||||
|
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$v['id']}' AND S_MenuRegional = '{$prm['code']}'
|
||||||
|
ORDER BY S_MenuOrder ASC";
|
||||||
|
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
|
||||||
|
if ($rows[$k]['childs']) {
|
||||||
|
foreach ($rows[$k]['childs'] as $kx => $vx) {
|
||||||
|
if ($vx['S_MenuUrl'] == '#') {
|
||||||
|
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
|
||||||
|
FROM s_menu
|
||||||
|
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
|
||||||
|
WHERE
|
||||||
|
S_MenuIsActive = 'Y' AND S_MenuParentS_MenuID = '{$vx['id']}' AND S_MenuRegional = '{$prm['code']}'
|
||||||
|
ORDER BY S_MenuOrder ASC";
|
||||||
|
$rows[$k]['childs'][$kx]['childs'] = $this->db_onedev->query($sql)->result_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sql = " SELECT S_MenuID, S_MenuUrl, S_MenuName, S_PrivilegeID, {$prm['id']} as usergroupid, IF(ISNULL(S_PrivilegeID),'N','Y') as status, 'N' as active, '' as childs
|
||||||
|
FROM s_menu
|
||||||
|
LEFT JOIN s_privilege ON S_PrivilegeS_MenuID = S_MenuID AND S_PrivilegeIsActive = 'Y' AND S_PrivilegeM_UserGroupID = '{$prm['id']}'
|
||||||
|
WHERE
|
||||||
|
S_MenuIsActive = 'Y' AND S_MenuID = '{$v['id']}' AND S_MenuRegional = '{$prm['code']}'
|
||||||
|
ORDER BY S_MenuOrder ASC";
|
||||||
|
$rows[$k]['childs'] = $this->db_onedev->query($sql)->result_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_usergroup select");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array("total" => count($rows), "records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$datas = $prm['datas'];
|
||||||
|
foreach ($datas as $k => $v) {
|
||||||
|
foreach ($v['childs'] as $kx => $vx) {
|
||||||
|
if ($vx['active'] == 'Y') {
|
||||||
|
if (is_null($vx['S_PrivilegeID']) && $vx['status'] == 'Y') {
|
||||||
|
$sql = "INSERT INTO s_privilege (
|
||||||
|
S_PrivilegeM_UserGroupID,
|
||||||
|
S_PrivilegeS_MenuID,
|
||||||
|
S_PrivilegeCreated
|
||||||
|
)
|
||||||
|
VALUES(
|
||||||
|
{$vx['usergroupid']},
|
||||||
|
{$vx['S_MenuID']},
|
||||||
|
NOW()
|
||||||
|
)";
|
||||||
|
$this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_null($vx['S_PrivilegeID'])) {
|
||||||
|
$sql = "UPDATE s_privilege SET
|
||||||
|
S_PrivilegeIsActive = '{$vx['status']}'
|
||||||
|
WHERE
|
||||||
|
S_PrivilegeID = '{$vx['S_PrivilegeID']}'
|
||||||
|
";
|
||||||
|
$this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($vx['childs']) {
|
||||||
|
foreach ($vx['childs'] as $kxz => $vxz) {
|
||||||
|
if ($vxz['active'] == 'Y') {
|
||||||
|
if (is_null($vxz['S_PrivilegeID']) && $vxz['status'] == 'Y') {
|
||||||
|
$sql = "INSERT INTO s_privilege (
|
||||||
|
S_PrivilegeM_UserGroupID,
|
||||||
|
S_PrivilegeS_MenuID,
|
||||||
|
S_PrivilegeCreated
|
||||||
|
)
|
||||||
|
VALUES(
|
||||||
|
{$vxz['usergroupid']},
|
||||||
|
{$vxz['S_MenuID']},
|
||||||
|
NOW()
|
||||||
|
)";
|
||||||
|
$this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_null($vxz['S_PrivilegeID'])) {
|
||||||
|
$sql = "UPDATE s_privilege SET
|
||||||
|
S_PrivilegeIsActive = '{$vxz['status']}'
|
||||||
|
WHERE
|
||||||
|
S_PrivilegeID = '{$vxz['S_PrivilegeID']}'
|
||||||
|
";
|
||||||
|
$this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array("total" => 1, "records" => array());
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
722
application/controllers/mockup/masterdata/Staffv2.php
Normal file
722
application/controllers/mockup/masterdata/Staffv2.php
Normal file
@@ -0,0 +1,722 @@
|
|||||||
|
<?php
|
||||||
|
class Staffv2 extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "Staff API";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
// $this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$nik = str_replace("'", "\\'", $prm["snik"]);
|
||||||
|
$nama = str_replace("'", "\\'", $prm["nama"]);
|
||||||
|
$status = str_replace("'", "\\'", $prm["status"]);
|
||||||
|
|
||||||
|
// echo $nik;
|
||||||
|
|
||||||
|
$sql_where = "WHERE M_StaffIsActive = 'Y' ";
|
||||||
|
$sql_param = array();
|
||||||
|
if ($nama != "") {
|
||||||
|
if ($sql_where != "") {
|
||||||
|
$sql_where .= " and ";
|
||||||
|
}
|
||||||
|
$sql_where .= " M_StaffName like ? ";
|
||||||
|
$sql_param[] = "%$nama%";
|
||||||
|
}
|
||||||
|
if ($nik != "") {
|
||||||
|
if ($sql_where != "") {
|
||||||
|
$sql_where .= " and ";
|
||||||
|
}
|
||||||
|
$sql_where .= " M_StaffNIK like ? ";
|
||||||
|
$sql_param[] = "%$nik%";
|
||||||
|
}
|
||||||
|
|
||||||
|
//if ($sql_where != "") $sql_where .= " and ";
|
||||||
|
|
||||||
|
// Order masih dalam status registrasi
|
||||||
|
//$sql_where .= " M_StaffIsActive = 'Y' ";
|
||||||
|
|
||||||
|
|
||||||
|
$sql = " SELECT count(*) as total
|
||||||
|
FROM m_staff
|
||||||
|
LEFT JOIN m_sex ON M_StaffM_SexID = M_SexID
|
||||||
|
LEFT JOIN m_position ON M_StaffM_PositionID = M_PositionID
|
||||||
|
$sql_where
|
||||||
|
";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
|
||||||
|
$tot_count = 0;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_staff count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
m_staff.*,
|
||||||
|
DATE_FORMAT(M_StaffDOB,'%d-%m-%Y') as M_StaffDOBx,
|
||||||
|
M_StaffM_SexID,
|
||||||
|
M_SexID,
|
||||||
|
m_sexname,
|
||||||
|
0 M_ReligionID,
|
||||||
|
0 M_StaffM_ReligionID,
|
||||||
|
0 M_ReligionName,
|
||||||
|
'' M_BranchID,
|
||||||
|
0 M_StaffM_BranchID,
|
||||||
|
'' M_BranchName,
|
||||||
|
0 M_StaffM_PositionID,
|
||||||
|
M_PositionID,
|
||||||
|
M_PositionName,
|
||||||
|
'' M_CityName,
|
||||||
|
'' M_SubareaName,
|
||||||
|
M_StaffIsCourier as iskurir,
|
||||||
|
'' OHStaffMapIhsNumber
|
||||||
|
FROM m_staff
|
||||||
|
LEFT JOIN m_sex ON M_StaffM_SexID = M_SexID
|
||||||
|
LEFT JOIN m_position ON M_StaffM_PositionID = M_PositionID
|
||||||
|
$sql_where
|
||||||
|
ORDER BY M_StaffName ASC
|
||||||
|
";
|
||||||
|
// echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
// echo $this->db_onedev->last_query();
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if ($rows) {
|
||||||
|
foreach ($rows as $k => $v) {
|
||||||
|
$$rows[$k]['M_StaffName'] = stripslashes($rows[$k]['M_StaffName']);
|
||||||
|
//$rows[$k]['verification_px'] = $this->add_verification_test($v['M_StaffID']);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//$this->_add_address($rows);
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getsexreg()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
$rows['branchs'] = [];
|
||||||
|
|
||||||
|
$query = " SELECT *
|
||||||
|
FROM m_sex
|
||||||
|
WHERE
|
||||||
|
M_SexIsActive = 'Y'
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
$rows['religions'] = [];
|
||||||
|
|
||||||
|
$query = " SELECT *, COUNT(M_StaffID) as used
|
||||||
|
FROM (SELECT m_position.*,M_StaffID
|
||||||
|
FROM
|
||||||
|
m_position
|
||||||
|
LEFT JOIN m_staff ON M_PositionID = M_StaffM_PositionID AND M_StaffIsActive = 'Y'
|
||||||
|
WHERE M_PositionIsActive = 'Y') a
|
||||||
|
GROUP BY M_PositionID
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['positions'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows),
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
public function addnewposition()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$name_position = $prm['name'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$sql = "insert into m_position(
|
||||||
|
M_PositionName,
|
||||||
|
M_PositionUserID,
|
||||||
|
M_PositionCreated,
|
||||||
|
M_PositionLastUpdated
|
||||||
|
)
|
||||||
|
values(?,?,now(),now())";
|
||||||
|
$query = $this->db_onedev->query(
|
||||||
|
$sql,
|
||||||
|
array(
|
||||||
|
$name_position,
|
||||||
|
$userid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
//echo $query;
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("m_position insert");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query = " SELECT *, COUNT(M_StaffID) as used
|
||||||
|
FROM (SELECT m_position.*,M_StaffID
|
||||||
|
FROM
|
||||||
|
m_position
|
||||||
|
LEFT JOIN m_staff ON M_PositionID = M_StaffM_PositionID AND M_StaffIsActive = 'Y'
|
||||||
|
WHERE M_PositionIsActive = 'Y') a
|
||||||
|
GROUP BY M_PositionID
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['positions'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
$result = array("total" => 1, "records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
$last_id = $this->db_onedev->insert_id();
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function editposition()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id_staff = $prm['id'];
|
||||||
|
$name_staff = $prm['name'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$sqlstaff = "update m_position SET
|
||||||
|
M_PositionName = ?,
|
||||||
|
M_PositionUserID = ?,
|
||||||
|
M_PositionLastUpdated = now()
|
||||||
|
where
|
||||||
|
M_PositionID = ?
|
||||||
|
";
|
||||||
|
$querystaff = $this->db_onedev->query(
|
||||||
|
$sqlstaff,
|
||||||
|
array(
|
||||||
|
$name_staff,
|
||||||
|
$userid,
|
||||||
|
$id_staff
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// echo $query;
|
||||||
|
if (!$querystaff) {
|
||||||
|
$this->sys_error_db("m_position update");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query = " SELECT *, COUNT(M_StaffID) as used
|
||||||
|
FROM (SELECT m_position.*,M_StaffID
|
||||||
|
FROM
|
||||||
|
m_position
|
||||||
|
LEFT JOIN m_staff ON M_PositionID = M_StaffM_PositionID AND M_StaffIsActive = 'Y'
|
||||||
|
WHERE M_PositionIsActive = 'Y') a
|
||||||
|
GROUP BY M_PositionID";
|
||||||
|
//echo $query;
|
||||||
|
$rows['positions'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
$result = array("total" => 1, "records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function deleteposition()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id_staff = $prm['id'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$sqlstaff = "update m_position SET
|
||||||
|
M_PositionIsActive = 'N',
|
||||||
|
M_PositionUserID = ?,
|
||||||
|
M_PositionLastUpdated = now()
|
||||||
|
where
|
||||||
|
M_PositionID = ?
|
||||||
|
";
|
||||||
|
$querystaff = $this->db_onedev->query(
|
||||||
|
$sqlstaff,
|
||||||
|
array(
|
||||||
|
$userid,
|
||||||
|
$id_staff
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// echo $query;
|
||||||
|
if (!$querystaff) {
|
||||||
|
$this->sys_error_db("m_position update");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query = " SELECT *
|
||||||
|
FROM m_position
|
||||||
|
WHERE
|
||||||
|
M_PositionIsActive = 'Y'
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['positions'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
$result = array("total" => 1, "records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function searchcity()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count = 0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '') {
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
$sql = "SELECT count(*) as total
|
||||||
|
FROM m_city
|
||||||
|
WHERE
|
||||||
|
M_CityName like ?
|
||||||
|
AND M_CityIsActive = 'Y'";
|
||||||
|
$query = $this->db_onedev->query($sql, $q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_city count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT *
|
||||||
|
FROM m_city
|
||||||
|
WHERE
|
||||||
|
M_CityName like ?
|
||||||
|
AND M_CityIsActive = 'Y'
|
||||||
|
ORDER BY M_CityName DESC
|
||||||
|
";
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_city rows", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getsubarea()
|
||||||
|
{
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$query = " SELECT *
|
||||||
|
FROM m_subarea
|
||||||
|
WHERE
|
||||||
|
M_SubareaIsActive = 'Y' AND M_SubareaM_CityID = ?
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows),
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function save()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$pdob = date('Y-m-d', strtotime($prm['M_StaffDOB']));
|
||||||
|
$iscourier = $prm['M_StaffIsCourier'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$prm['M_StaffName'] = str_replace("'", "\\'", $prm['M_StaffName']);
|
||||||
|
$query = "UPDATE m_staff SET
|
||||||
|
M_StaffM_BranchID = '{$prm['M_StaffM_BranchID']}',
|
||||||
|
M_StaffName = '{$prm['M_StaffName']}',
|
||||||
|
M_StaffDOB = '{$pdob}',
|
||||||
|
M_StaffM_SexID = '{$prm['M_StaffM_SexID']}',
|
||||||
|
M_StaffM_ReligionID = '{$prm['M_StaffM_ReligionID']}',
|
||||||
|
M_StaffAddress = '{$prm['M_StaffAddress']}',
|
||||||
|
M_StaffM_CityID = '{$prm['M_StaffM_CityID']}',
|
||||||
|
M_StaffM_SubareaID = '{$prm['M_StaffM_SubareaID']}',
|
||||||
|
M_StaffHP = '{$prm['M_StaffHP']}',
|
||||||
|
M_StaffPhone = '{$prm['M_StaffPhone']}',
|
||||||
|
M_StaffM_PositionID = '{$prm['M_StaffM_PositionID']}',
|
||||||
|
M_StaffNIK = '{$prm['M_StaffNIK']}',
|
||||||
|
M_StaffBlood = '{$prm['M_StaffBlood']}',
|
||||||
|
M_StaffStudy = '{$prm['M_StaffStudy']}',
|
||||||
|
M_StaffStartDate = '{$prm['M_StaffStartDate']}',
|
||||||
|
M_StaffEndDate = '{$prm['M_StaffEndDate']}',
|
||||||
|
M_StaffTimeWork = '{$prm['M_StaffTimeWork']}',
|
||||||
|
M_StaffTimeWorkSaturday = '{$prm['M_StaffTimeWorkSaturday']}',
|
||||||
|
M_StaffIsCourier = '{$iscourier}',
|
||||||
|
M_StaffUserID = '{$userid}'
|
||||||
|
|
||||||
|
WHERE
|
||||||
|
M_StaffID = '{$prm['M_StaffID']}'
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query);
|
||||||
|
if (!$rows) {
|
||||||
|
$this->sys_error_db("update m_staff", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ($rows) {
|
||||||
|
// $sql = "SELECT OHStaffMapID,
|
||||||
|
// OHStaffMapM_StaffNIK,
|
||||||
|
// OHStaffMapIhsNumber
|
||||||
|
// FROM one_health.oh_staff_map
|
||||||
|
// WHERE OHStaffMapM_StaffNIK = '{$prm['M_StaffNIK']}'";
|
||||||
|
// $qry = $this->db_onedev->query($sql);
|
||||||
|
// if ($qry) {
|
||||||
|
// $rows_oh = $qry->result_array();
|
||||||
|
// } else {
|
||||||
|
// $this->sys_error_db("select oh_staff_map", $this->db_onedev);
|
||||||
|
// exit;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (count($rows_oh) > 0) {
|
||||||
|
// $sql_oh_staff = "UPDATE one_health.oh_staff_map SET
|
||||||
|
// OHStaffMapM_StaffNIK = '{$prm['M_StaffNIK']}',
|
||||||
|
// OHStaffMapIhsNumber = '{$prm['OHStaffMapIhsNumber']}',
|
||||||
|
// OHStaffMapUserID = '{$userid}',
|
||||||
|
// OHStaffMapLastUpdated = NOW()
|
||||||
|
// WHERE OHStaffMapM_StaffNIK = '{$prm['M_StaffNIK']}'";
|
||||||
|
// $rows = $this->db_onedev->query($sql_oh_staff);
|
||||||
|
// // $last_qry = $this->db_onedev->last_query();
|
||||||
|
// // print_r($last_qry);
|
||||||
|
// // exit;
|
||||||
|
// if (!$rows) {
|
||||||
|
// $this->db_onedev->trans_rollback();
|
||||||
|
// $this->sys_error_db("update oh_staff_map error", $this->db_onedev);
|
||||||
|
// exit;
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// if ($prm['M_StaffNIK'] != "" && $prm['OHStaffMapIhsNumber'] != "") {
|
||||||
|
// $sql_oh_staff = "INSERT INTO one_health.oh_staff_map(
|
||||||
|
// OHStaffMapM_StaffNIK,
|
||||||
|
// OHStaffMapIhsNumber,
|
||||||
|
// OHStaffMapUserID,
|
||||||
|
// OHStaffMapCreated,
|
||||||
|
// OHStaffMapLastUpdated
|
||||||
|
// ) VALUES('{$prm['M_StaffNIK']}','{$prm['OHStaffMapIhsNumber']}','{$userid}',NOW(),NOW())";
|
||||||
|
// $rows = $this->db_onedev->query($sql_oh_staff);
|
||||||
|
// if (!$rows) {
|
||||||
|
// $this->db_onedev->trans_rollback();
|
||||||
|
// $this->sys_error_db("save oh_staff_map error", $this->db_onedev);
|
||||||
|
// exit;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1,
|
||||||
|
"records" => array('status' => 'OK')
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function newstaff()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$pdob = date('Y-m-d', strtotime($prm['M_StaffDOB']));
|
||||||
|
$iscourier = $prm['M_StaffIsCourier'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$query = "INSERT INTO m_staff (
|
||||||
|
M_StaffM_BranchID,
|
||||||
|
M_StaffName,
|
||||||
|
M_StaffDOB,
|
||||||
|
M_StaffM_SexID,
|
||||||
|
M_StaffM_ReligionID,
|
||||||
|
M_StaffAddress,
|
||||||
|
M_StaffM_CityID,
|
||||||
|
M_StaffM_SubareaID,
|
||||||
|
M_StaffHP,
|
||||||
|
M_StaffPhone,
|
||||||
|
M_StaffM_PositionID,
|
||||||
|
M_StaffNIK,
|
||||||
|
M_StaffBlood,
|
||||||
|
M_StaffStudy,
|
||||||
|
M_StaffStartDate ,
|
||||||
|
M_StaffEndDate,
|
||||||
|
M_StaffTimeWork,
|
||||||
|
M_StaffTimeWorkSaturday,
|
||||||
|
M_StaffIsCourier,
|
||||||
|
M_StaffUserID
|
||||||
|
)
|
||||||
|
VALUES(
|
||||||
|
'{$prm['M_StaffM_BranchID']}',
|
||||||
|
'{$prm['M_StaffName']}',
|
||||||
|
'{$pdob}',
|
||||||
|
'{$prm['M_StaffM_SexID']}',
|
||||||
|
'{$prm['M_StaffM_ReligionID']}',
|
||||||
|
'{$prm['M_StaffAddress']}',
|
||||||
|
'{$prm['M_StaffM_CityID']}',
|
||||||
|
'{$prm['M_StaffM_SubareaID']}',
|
||||||
|
'{$prm['M_StaffHP']}',
|
||||||
|
'{$prm['M_StaffPhone']}',
|
||||||
|
'{$prm['M_StaffM_PositionID']}',
|
||||||
|
'{$prm['M_StaffNIK']}',
|
||||||
|
'{$prm['M_StaffBlood']}',
|
||||||
|
'{$prm['M_StaffStudy']}',
|
||||||
|
'{$prm['M_StaffStartDate']}',
|
||||||
|
'{$prm['M_StaffEndDate']}',
|
||||||
|
'{$prm['M_StaffTimeWork']}',
|
||||||
|
'{$prm['M_StaffTimeWorkSaturday']}',
|
||||||
|
'{$iscourier}',
|
||||||
|
'{$userid}'
|
||||||
|
)
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query);
|
||||||
|
$last_id = $this->db_onedev->insert_id();
|
||||||
|
if ($rows) {
|
||||||
|
if ($iscourier == 'Y') {
|
||||||
|
$querycourier = "INSERT INTO m_courier(M_CourierM_StaffID,M_CourierCreated,M_CourierLastUpdated,M_CourierUserID)
|
||||||
|
VALUES('{$last_id}',now(),now(),'{$userid}')
|
||||||
|
";
|
||||||
|
$rows = $this->db_onedev->query($querycourier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ($rows) {
|
||||||
|
// if ($prm['M_StaffNIK'] !== "" && $prm['OHStaffMapIhsNumber'] !== "") {
|
||||||
|
// $sql_oh_staff = "INSERT INTO one_health.oh_staff_map(
|
||||||
|
// OHStaffMapM_StaffNIK,
|
||||||
|
// OHStaffMapIhsNumber,
|
||||||
|
// OHStaffMapUserID,
|
||||||
|
// OHStaffMapCreated,
|
||||||
|
// OHStaffMapLastUpdated
|
||||||
|
// ) VALUES('{$prm['M_StaffNIK']}','{$prm['OHStaffMapIhsNumber']}','{$userid}',NOW(),NOW())";
|
||||||
|
// $rows = $this->db_onedev->query($sql_oh_staff);
|
||||||
|
// if (!$rows) {
|
||||||
|
// $this->db_onedev->trans_rollback();
|
||||||
|
// $this->sys_error_db("save oh_staff_map error", $this->db_onedev);
|
||||||
|
// exit;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1,
|
||||||
|
"records" => array('status' => 'OK'),
|
||||||
|
"id" => $last_id
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletestaff()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$query = "UPDATE m_staff SET
|
||||||
|
M_StaffIsActive = 'N'
|
||||||
|
WHERE
|
||||||
|
M_StaffID = '{$prm['M_StaffID']}'
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query);
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1,
|
||||||
|
"records" => array('status' => 'OK')
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getaddress()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$query = " SELECT m_staffaddress.*,
|
||||||
|
M_KelurahanName,
|
||||||
|
M_DistrictID,
|
||||||
|
M_DistrictName,
|
||||||
|
M_CityID,
|
||||||
|
M_CityName,
|
||||||
|
'' as action
|
||||||
|
FROM m_staffaddress
|
||||||
|
JOIN m_kelurahan ON M_StaffAddressM_KelurahanID = M_KelurahanID
|
||||||
|
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||||
|
JOIN m_city ON M_DistrictM_CityID = M_CityID
|
||||||
|
WHERE
|
||||||
|
M_StaffAddressIsActive = 'Y' AND M_StaffAddressM_StaffID = ?
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
|
||||||
|
if ($rows) {
|
||||||
|
foreach ($rows as $k => $v) {
|
||||||
|
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
|
||||||
|
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows),
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function savenewaddress()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_staffaddress WHERE M_StaffAddressM_StaffID = '{$prm['M_StaffAddressM_StaffID']}' AND M_StaffAddressIsActive = 'Y'")->row()->countx;
|
||||||
|
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
if ($count_addrs == 0) {
|
||||||
|
$prm['M_StaffAddressNote'] = 'Utama';
|
||||||
|
} else {
|
||||||
|
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_staffaddress WHERE M_StaffAddressM_StaffID = '{$prm['M_StaffAddressM_StaffID']}' AND M_StaffAddressNote = 'Utama' AND M_StaffAddressIsActive = 'Y'")->row()->countx;
|
||||||
|
if ($count_addrs_utama > 0 && strtolower($prm['M_StaffAddressNote']) == 'utama') {
|
||||||
|
$rx = date('YmdHis');
|
||||||
|
$prm['M_StaffAddressNote'] = 'Utama_' . $rx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query = "INSERT INTO m_staffaddress (
|
||||||
|
M_StaffAddressM_StaffID,
|
||||||
|
M_StaffAddressNote,
|
||||||
|
M_StaffAddressDescription,
|
||||||
|
M_StaffAddressM_KelurahanID,
|
||||||
|
M_StaffAddressCreated
|
||||||
|
)
|
||||||
|
VALUES(
|
||||||
|
'{$prm['M_StaffAddressM_StaffID']}',
|
||||||
|
'{$prm['M_StaffAddressNote']}',
|
||||||
|
'{$prm['M_StaffAddressDescription']}',
|
||||||
|
'{$prm['M_StaffAddressM_KelurahanID']}',
|
||||||
|
NOW()
|
||||||
|
)
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query);
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1,
|
||||||
|
"records" => array('status' => 'OK')
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveeditaddress()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$query = "UPDATE m_staffaddress SET
|
||||||
|
M_StaffAddressM_StaffID = '{$prm['M_StaffAddressM_StaffID']}',
|
||||||
|
M_StaffAddressNote = '{$prm['M_StaffAddressNote']}',
|
||||||
|
M_StaffAddressDescription = '{$prm['M_StaffAddressDescription']}',
|
||||||
|
M_StaffAddressM_KelurahanID = '{$prm['M_StaffAddressM_KelurahanID']}'
|
||||||
|
WHERE
|
||||||
|
M_StaffAddressID = '{$prm['M_StaffAddressID']}'
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query);
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1,
|
||||||
|
"records" => array('status' => 'OK')
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteaddress()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$query = "UPDATE m_staffaddress SET
|
||||||
|
M_StaffAddressIsActive = 'N'
|
||||||
|
WHERE
|
||||||
|
M_StaffAddressID = '{$prm['M_StaffAddressID']}'
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows = $this->db_onedev->query($query);
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1,
|
||||||
|
"records" => array('status' => 'OK')
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,7 +139,9 @@ class Journalcashv2 extends MY_Controller
|
|||||||
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
LEFT JOIN m_branch ON jurnalM_BranchCode = M_BranchCode AND M_BranchIsActive = 'Y'
|
||||||
WHERE $where_sql
|
WHERE $where_sql
|
||||||
GROUP BY jurnalID
|
GROUP BY jurnalID
|
||||||
ORDER BY jurnalID DESC";
|
ORDER BY jurnalID DESC
|
||||||
|
";
|
||||||
|
|
||||||
// Ambil total count
|
// Ambil total count
|
||||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||||
$qry_total = $this->db->query($sql_total, $params);
|
$qry_total = $this->db->query($sql_total, $params);
|
||||||
@@ -163,6 +165,7 @@ class Journalcashv2 extends MY_Controller
|
|||||||
// Tambahkan LIMIT OFFSET
|
// Tambahkan LIMIT OFFSET
|
||||||
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
$sql_paginated = $sql . " LIMIT ? OFFSET ?";
|
||||||
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
$params_paginated = array_merge($params, [$number_limit, $number_offset]);
|
||||||
|
|
||||||
$qry = $this->db->query($sql_paginated, $params_paginated);
|
$qry = $this->db->query($sql_paginated, $params_paginated);
|
||||||
|
|
||||||
if ($qry) {
|
if ($qry) {
|
||||||
@@ -361,7 +364,6 @@ class Journalcashv2 extends MY_Controller
|
|||||||
$this->sys_error($message);
|
$this->sys_error($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserApproveLevel()
|
function getUserApproveLevel()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -118,6 +118,19 @@ class Journalgoodreceive extends MY_Controller
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if ($loginLevel == "branch") {
|
||||||
|
// $where_conditions[] = "jurnalM_BranchCode = ?";
|
||||||
|
// $params[] = $branchCode;
|
||||||
|
// } elseif ($loginLevel == "regional") {
|
||||||
|
// $where_conditions[] = "jurnalS_RegionalID = ?";
|
||||||
|
// $params[] = $regionalId;
|
||||||
|
|
||||||
|
// if (!empty($branchCode)) {
|
||||||
|
// $where_conditions[] = "jurnalM_BranchCode = ?";
|
||||||
|
// $params[] = $branchCode;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Gabungkan WHERE SQL
|
// Gabungkan WHERE SQL
|
||||||
$where_sql = implode(" AND ", $where_conditions);
|
$where_sql = implode(" AND ", $where_conditions);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,77 @@ class Ruangan extends MY_Controller
|
|||||||
echo "API Ruangan";
|
echo "API Ruangan";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function listingRegional()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception('Invalid token');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
S_RegionalID,
|
||||||
|
S_RegionalName
|
||||||
|
FROM s_regional
|
||||||
|
WHERE S_RegionalIsActive = 'Y'";
|
||||||
|
$que = $this->db->query($sql);
|
||||||
|
if (!$que) {
|
||||||
|
throw new Exception('failed to query list regional', 1);
|
||||||
|
}
|
||||||
|
$data = $que->result_array();
|
||||||
|
|
||||||
|
$this->sys_ok([
|
||||||
|
"records" => $data,
|
||||||
|
"total" => count($data)
|
||||||
|
]);
|
||||||
|
} 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 listingCabang()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception('Invalid token');
|
||||||
|
}
|
||||||
|
|
||||||
|
$para = $this->sys_input;
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
M_BranchID,
|
||||||
|
M_BranchName
|
||||||
|
FROM m_branch
|
||||||
|
WHERE M_BranchS_RegionalID = ?
|
||||||
|
AND M_BranchIsActive = 'Y'";
|
||||||
|
$que = $this->db->query($sql, [$para['regionalID']]);
|
||||||
|
if (!$que) {
|
||||||
|
throw new Exception('failed to query list cabang', 1);
|
||||||
|
}
|
||||||
|
$data = $que->result_array();
|
||||||
|
|
||||||
|
$this->sys_ok([
|
||||||
|
"records" => $data,
|
||||||
|
"total" => count($data)
|
||||||
|
]);
|
||||||
|
} 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 lookupRuangan()
|
function lookupRuangan()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -39,9 +110,8 @@ class Ruangan extends MY_Controller
|
|||||||
b.M_BranchCode AS branch_code,
|
b.M_BranchCode AS branch_code,
|
||||||
r.M_RuanganCode AS code,
|
r.M_RuanganCode AS code,
|
||||||
r.M_RuanganName AS name,
|
r.M_RuanganName AS name,
|
||||||
r.M_RuanganUserID AS user_id,
|
s.S_RegionalID AS regional_id,
|
||||||
r.M_RuanganCreated AS created,
|
s.S_RegionalName AS regional_name
|
||||||
r.M_RuanganLastUpdated AS last_updated
|
|
||||||
FROM m_ruangan r
|
FROM m_ruangan r
|
||||||
JOIN m_branch b
|
JOIN m_branch b
|
||||||
ON b.M_BranchID = r.M_RuanganM_BranchID
|
ON b.M_BranchID = r.M_RuanganM_BranchID
|
||||||
|
|||||||
1579
application/controllers/mockup/mutasi/HandoverMutasi.php
Normal file
1579
application/controllers/mockup/mutasi/HandoverMutasi.php
Normal file
File diff suppressed because it is too large
Load Diff
1006
application/controllers/mockup/mutasi/ReceiveMutasi.php
Normal file
1006
application/controllers/mockup/mutasi/ReceiveMutasi.php
Normal file
File diff suppressed because it is too large
Load Diff
1401
application/controllers/mockup/mutasi/Requestmutasi.php
Normal file
1401
application/controllers/mockup/mutasi/Requestmutasi.php
Normal file
File diff suppressed because it is too large
Load Diff
1420
application/controllers/mockup/mutasi/RequestmutasiApproved.php
Normal file
1420
application/controllers/mockup/mutasi/RequestmutasiApproved.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,715 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Nonpersediaanapproved extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "COA API";
|
||||||
|
// $cek = $this->db->query("select database() as current_db")->result();
|
||||||
|
// print_r($cek);
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = '%' . $prm['search'] . '%';
|
||||||
|
|
||||||
|
$startDate = $prm['startDate'];
|
||||||
|
$endDate = $prm['endDate'];
|
||||||
|
$status = $prm['status'];
|
||||||
|
$page = $prm['page'];
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
$loginType = $user['M_UserLocationFlag'];
|
||||||
|
$userID = $user['M_UserID'];
|
||||||
|
$approveLevelID = $user['M_UserM_ApproveLevelID'];
|
||||||
|
$flag = $prm['flag'];
|
||||||
|
|
||||||
|
$sqlBranch = '';
|
||||||
|
if ($loginType == 'B' || $loginType == 'RB') {
|
||||||
|
$sqlBranch = "AND PurchaseRequestM_BranchCode = '{$branchCode}'";
|
||||||
|
}
|
||||||
|
$sqlStatus = '';
|
||||||
|
if ($status != 'All') {
|
||||||
|
$sqlStatus = "AND PurchaseRequestStatus = '{$status}'";
|
||||||
|
}
|
||||||
|
$number_limit = 20;
|
||||||
|
$number_offset = 0;
|
||||||
|
if ($prm['page'] > 0) {
|
||||||
|
$number_offset = ($prm['page'] - 1) * $number_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($approveLevelID == '1') {
|
||||||
|
if ($flag == 'G') {
|
||||||
|
$sqlStockRequest = " AND (PurchaseRequestVerifiedBy = 0 OR PurchaseRequestVerifiedBy IS NULL) ";
|
||||||
|
}
|
||||||
|
} else if ($approveLevelID == '2') {
|
||||||
|
if ($flag == 'G') {
|
||||||
|
$sqlStockRequest = " AND PurchaseRequestApprovedBy IS NULL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$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'];
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
COUNT(PurchaseRequestID) total
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional
|
||||||
|
ON PurchaseRequestS_RegionalID = S_RegionalID
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category
|
||||||
|
ON PurchaseRequestItemCategoryID = ItemCategoryID
|
||||||
|
AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b
|
||||||
|
ON PurchaseRequestRequestedBy = b.M_UserID
|
||||||
|
AND b.M_UserIsActive = 'Y'
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a
|
||||||
|
ON PurchaseRequestApprovedBy = a.M_UserID
|
||||||
|
AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN
|
||||||
|
m_branch
|
||||||
|
ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y' AND PurchaseRequestItemCategoryID <> 1
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ? OR PurchaseRequestRequestedBy LIKE ?)
|
||||||
|
AND (PurchaseRequestDate BETWEEN ? AND ?) AND PurchaseRequestS_RegionalID = ?
|
||||||
|
$sqlBranch
|
||||||
|
$sqlStatus
|
||||||
|
$sqlStockRequest
|
||||||
|
-- AND PurchaseRequestTotal BETWEEN $totalStart AND $totalEnd
|
||||||
|
";
|
||||||
|
$qry = $this->db->query($sql, [$search, $search, $search, $startDate, $endDate, $regionalID]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$total = $qry->row_array()['total'];
|
||||||
|
$tot_page = ceil($total / $number_limit);
|
||||||
|
$params = [$search, $search, $search, $startDate, $endDate, $regionalID];
|
||||||
|
|
||||||
|
$params[] = $number_limit;
|
||||||
|
$params[] = $number_offset;
|
||||||
|
$sql = "SELECT
|
||||||
|
PurchaseRequestID prID,
|
||||||
|
DATE_FORMAT(PurchaseRequestDate, '%d-%m-%Y') prDate,
|
||||||
|
PurchaseRequestNumber prNumber,
|
||||||
|
PurchaseRequestRefNumber prRefNumber,
|
||||||
|
PurchaseRequestNote prNote,
|
||||||
|
PurchaseRequestTotal prTotal,
|
||||||
|
PurchaseRequestItemCategoryID prItemType,
|
||||||
|
ItemCategoryName prItemTypeName,
|
||||||
|
PurchaseRequestStatus prStatus,
|
||||||
|
IFNULL(PurchaseRequestVerifiedBy, 0) AS PurchaseRequestVerifiedBy,
|
||||||
|
PurchaseRequestVerifiedDate,
|
||||||
|
DATE_FORMAT(PurchaseRequestApprovedDate, '%d-%m-%Y %H:%i') prApprovedDate,
|
||||||
|
a.M_userUserName prApprovedBy,
|
||||||
|
b.M_UserID prRequestedByID,
|
||||||
|
b.M_userUserName prRequestedBy,
|
||||||
|
b.M_UserM_BranchID prRequestedByFromBranch,
|
||||||
|
S_RegionalName prRegionalName,
|
||||||
|
M_BranchName prBranchName,
|
||||||
|
IFNULL(`fn_getitemnamebyprid`(PurchaseRequestID), '') prItemName
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional
|
||||||
|
ON PurchaseRequestS_RegionalID = S_RegionalID
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category
|
||||||
|
ON PurchaseRequestItemCategoryID = ItemCategoryID
|
||||||
|
AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b
|
||||||
|
ON PurchaseRequestRequestedBy = b.M_UserID
|
||||||
|
AND b.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a
|
||||||
|
ON PurchaseRequestApprovedBy = a.M_UserID
|
||||||
|
AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN
|
||||||
|
m_branch
|
||||||
|
ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y' AND PurchaseRequestItemCategoryID <> 1
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ? OR PurchaseRequestRequestedBy LIKE ?)
|
||||||
|
AND (PurchaseRequestDate BETWEEN ? AND ?) AND PurchaseRequestS_RegionalID = ?
|
||||||
|
$sqlBranch
|
||||||
|
$sqlStatus
|
||||||
|
$sqlStockRequest
|
||||||
|
-- AND PurchaseRequestTotal BETWEEN $totalStart AND $totalEnd --PurchaseRequestTotal masih selalu 0, belum disimpan
|
||||||
|
LIMIT ? OFFSET ?
|
||||||
|
";
|
||||||
|
$qry = $this->db->query($sql, $params);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
// echo $this->db->last_query();
|
||||||
|
// exit;
|
||||||
|
$data = $qry->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'total' => $tot_page,
|
||||||
|
'records' => $data,
|
||||||
|
// "qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getDetail()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id = $prm['id'];
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
PurchaseRequestDetailID prDetailID,
|
||||||
|
PurchaseRequestDetailPurchaseRequestID prDetailPrID,
|
||||||
|
PurchaseRequestDetailM_ItemID prDetailItemID,
|
||||||
|
M_ItemDesc prDetailItemName,
|
||||||
|
M_ItemCode prDetailItemCode,
|
||||||
|
PurchaseRequestDetailQty prDetailItemQty,
|
||||||
|
PurchaseRequestDetailPrice prDetailItemPrice
|
||||||
|
FROM purchase_request_detail
|
||||||
|
JOIN m_item
|
||||||
|
ON PurchaseRequestDetailM_ItemID = M_ItemID
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestDetailIsActive = 'Y';";
|
||||||
|
$qry = $this->db->query($sql, [$id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error get detail");
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$data = $qry->result_array();
|
||||||
|
$this->sys_ok($data);
|
||||||
|
}
|
||||||
|
function approve()
|
||||||
|
{
|
||||||
|
$this->db->trans_begin();
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
// $this->db->trans_commit();
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$detail = $prm['detail'];
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$userid = $user["M_UserID"];
|
||||||
|
$pr = $prm['pr'];
|
||||||
|
$total = $prm['total'];
|
||||||
|
$type = $prm['type'];
|
||||||
|
|
||||||
|
// get user level approval
|
||||||
|
$sqlevel = "SELECT M_UserM_ApproveLevelID FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserID = ?";
|
||||||
|
$qulevel = $this->db->query($sqlevel, [$userid]);
|
||||||
|
if (!$qulevel) {
|
||||||
|
$this->sys_error_db("[Error] get approval level user");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$userlevel = $qulevel->row_array()['M_UserM_ApproveLevelID'];
|
||||||
|
|
||||||
|
$datas_log = array();
|
||||||
|
$sql = "SELECT * FROM purchase_request WHERE PurchaseRequestID = ? AND PurchaseRequestIsActive = 'Y'";
|
||||||
|
$query = $this->db->query($sql, [$pr['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_detail
|
||||||
|
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID AND M_ItemIsActive = 'Y'
|
||||||
|
JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID AND ItemUnitIsActive = 'Y'
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ? AND PurchaseRequestDetailIsActive = 'Y'";
|
||||||
|
$query = $this->db->query($sql, [$pr['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;
|
||||||
|
|
||||||
|
if ($type == 'A') {
|
||||||
|
// verifikasi jika manager
|
||||||
|
if ($userlevel == '1') {
|
||||||
|
$sql = "UPDATE purchase_request SET
|
||||||
|
PurchaseRequestVerifiedBy = ?,
|
||||||
|
PurchaseRequestVerifiedDate = NOW()
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, [$userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error verifikasi manager");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah diverifikasi";
|
||||||
|
$this->insert_act_log("PRNP", "Verified", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($userlevel == '2') {
|
||||||
|
// -- PurchaseRequestTotal = ?,
|
||||||
|
$sql = "UPDATE purchase_request
|
||||||
|
SET
|
||||||
|
PurchaseRequestStatus = ?,
|
||||||
|
PurchaseRequestApprovedDate = NOW(),
|
||||||
|
PurchaseRequestApprovedBy = ?
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, ['Approved', $userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error Approve");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "UPDATE purchase_request_detail
|
||||||
|
SET PurchaseRequestDetailStatus = ?
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestDetailStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, ['Approved', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error update detail");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di approved";
|
||||||
|
$this->insert_act_log("PRNP", "Approved", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
}
|
||||||
|
} else if ($type == 'R') {
|
||||||
|
$sql = "UPDATE purchase_request
|
||||||
|
SET
|
||||||
|
PurchaseRequestStatus = ?,
|
||||||
|
PurchaseRequestApprovedDate = NOW(),
|
||||||
|
PurchaseRequestApprovedBy = ?
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, ['Rejected', $userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error Approve");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "UPDATE purchase_request_detail
|
||||||
|
SET PurchaseRequestDetailStatus = ?
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestDetailStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, ['Rejected', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error update detail");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di reject";
|
||||||
|
$this->insert_act_log("PRNP", "Rejected", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
} else if ($type == 'U') {
|
||||||
|
|
||||||
|
// un approve kacab/reg
|
||||||
|
if ($userlevel == '2') {
|
||||||
|
// -- PurchaseRequestTotal = ?,
|
||||||
|
$sql = "UPDATE purchase_request
|
||||||
|
SET
|
||||||
|
PurchaseRequestStatus = ?,
|
||||||
|
PurchaseRequestApprovedDate = NULL,
|
||||||
|
PurchaseRequestApprovedBy = NULL
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Approved'";
|
||||||
|
$qry = $this->db->query($sql, ['Pending', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error Approve");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "UPDATE purchase_request_detail
|
||||||
|
SET PurchaseRequestDetailStatus = ?
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestDetailStatus = 'Approved'";
|
||||||
|
$qry = $this->db->query($sql, ['Pending', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error update detail");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di unapproved";
|
||||||
|
$this->insert_act_log("PRNP", "Unapproved", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update notification
|
||||||
|
$this->readNotif($type, $userlevel, $userid, $pr['prID']);
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
|
||||||
|
$this->sys_ok('Berhasil');
|
||||||
|
}
|
||||||
|
|
||||||
|
// read notification
|
||||||
|
function readNotif($type, $userlevel, $userId, $refID)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
|
||||||
|
// cari user penerima notifikasi
|
||||||
|
if ($type == "U") {
|
||||||
|
$sql_get = "SELECT PurchaseRequestID,
|
||||||
|
M_UserID,
|
||||||
|
M_UserUsername,
|
||||||
|
NotificationID,
|
||||||
|
NotificationDetailID,
|
||||||
|
NotificationDetailStatus,
|
||||||
|
NotificationDetailM_UserID,
|
||||||
|
NotificationDetailM_ApproveLevelID
|
||||||
|
FROM notification
|
||||||
|
JOIN purchase_request ON NotificationRefID = PurchaseRequestID
|
||||||
|
AND PurchaseRequestIsActive = 'Y'
|
||||||
|
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||||
|
JOIN m_user ON NotificationUserID = M_UserID
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND NotificationDetailStatus = 'read'";
|
||||||
|
$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 PurchaseRequestID,
|
||||||
|
M_UserID,
|
||||||
|
M_UserUsername,
|
||||||
|
NotificationID,
|
||||||
|
NotificationDetailID,
|
||||||
|
NotificationDetailStatus,
|
||||||
|
NotificationDetailM_UserID,
|
||||||
|
NotificationDetailM_ApproveLevelID
|
||||||
|
FROM notification
|
||||||
|
JOIN purchase_request ON NotificationRefID = PurchaseRequestID
|
||||||
|
AND PurchaseRequestIsActive = 'Y'
|
||||||
|
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||||
|
JOIN m_user ON NotificationUserID = M_UserID
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND NotificationDetailStatus = 'unread'";
|
||||||
|
$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") {
|
||||||
|
if ($userlevel === '1') {
|
||||||
|
// verifikasi manager
|
||||||
|
$sql = "UPDATE notification_detail SET
|
||||||
|
NotificationDetailStatus = 'read',
|
||||||
|
NotificationDetailLastUpdated = NOW(),
|
||||||
|
NotificationDetailUserID = ?
|
||||||
|
WHERE NotificationDetailNotificationID = ?
|
||||||
|
AND NotificationDetailM_ApproveLevelID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userId, $user["NotificationID"], $user["NotificationDetailM_ApproveLevelID"]]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("update notification error", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else if ($userlevel === '2') {
|
||||||
|
// approve kepala cabang / regional
|
||||||
|
$sql = "UPDATE notification_detail SET
|
||||||
|
NotificationDetailStatus = 'read',
|
||||||
|
NotificationDetailLastUpdated = NOW(),
|
||||||
|
NotificationDetailUserID = ?
|
||||||
|
WHERE NotificationDetailNotificationID = ?
|
||||||
|
AND NotificationDetailM_ApproveLevelID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userId, $user["NotificationID"], $user["NotificationDetailM_ApproveLevelID"]]);
|
||||||
|
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") {
|
||||||
|
if ($userlevel === '2') {
|
||||||
|
$sql = "UPDATE notification_detail SET
|
||||||
|
NotificationDetailStatus = 'unread',
|
||||||
|
NotificationDetailLastUpdated = NOW(),
|
||||||
|
NotificationDetailUserID = ?
|
||||||
|
WHERE NotificationDetailNotificationID = ?
|
||||||
|
AND NotificationDetailM_ApproveLevelID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userId, $user["NotificationID"], $user["NotificationDetailM_ApproveLevelID"]]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("update notification error", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateqty()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
$userId = $this->sys_user["M_UserID"];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$arrItems = $prm["arrItems"];
|
||||||
|
|
||||||
|
if (count($arrItems) > 0) {
|
||||||
|
foreach ($arrItems as $key => $value) {
|
||||||
|
$sql = "UPDATE purchase_request_detail SET
|
||||||
|
PurchaseRequestDetailQty = ?,
|
||||||
|
PurchaseRequestDetailLastUpdated = NOW(),
|
||||||
|
PurchaseRequestDetailLastUpdatedUserID = ?
|
||||||
|
WHERE PurchaseRequestDetailID = ?";
|
||||||
|
$qry = $this->db->query($sql, [
|
||||||
|
$value['prDetailItemQty'],
|
||||||
|
$userId,
|
||||||
|
$value['prDetailID']
|
||||||
|
]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Failed update qty", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
$this->sys_ok("Berhasil update qty");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,701 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Purchaserequestkacab extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "COA API";
|
||||||
|
// $cek = $this->db->query("select database() as current_db")->result();
|
||||||
|
// print_r($cek);
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = '%' . $prm['search'] . '%';
|
||||||
|
|
||||||
|
$startDate = $prm['startDate'];
|
||||||
|
$endDate = $prm['endDate'];
|
||||||
|
$status = $prm['status'];
|
||||||
|
$page = $prm['page'];
|
||||||
|
$flag = $prm['flag'];
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$regionalID = $user['S_RegionalID'];
|
||||||
|
$branchCode = $user['M_BranchCode'];
|
||||||
|
$loginType = $user['M_UserLocationFlag'];
|
||||||
|
$userID = $user['M_UserID'];
|
||||||
|
$approveLevelID = $user['M_UserM_ApproveLevelID'];
|
||||||
|
|
||||||
|
$sqlBranch = '';
|
||||||
|
if ($loginType == 'B' || $loginType == 'RB') {
|
||||||
|
$sqlBranch = "AND PurchaseRequestM_BranchCode = '{$branchCode}'";
|
||||||
|
}
|
||||||
|
$sqlStatus = '';
|
||||||
|
if ($status != 'All') {
|
||||||
|
$sqlStatus = "AND PurchaseRequestStatus = '{$status}'";
|
||||||
|
}
|
||||||
|
$number_limit = 20;
|
||||||
|
$number_offset = 0;
|
||||||
|
if ($page > 0) {
|
||||||
|
$number_offset = ($prm['page'] - 1) * $number_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($approveLevelID == '1') {
|
||||||
|
if ($flag == 'G') {
|
||||||
|
$sqlStockRequest = " AND (PurchaseRequestVerifiedBy = 0 OR PurchaseRequestVerifiedBy IS NULL) ";
|
||||||
|
}
|
||||||
|
} else if ($approveLevelID == '2') {
|
||||||
|
if ($flag == 'G') {
|
||||||
|
$sqlStockRequest = " AND PurchaseRequestApprovedBy IS NULL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$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'];
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
COUNT(PurchaseRequestID) total
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional
|
||||||
|
ON PurchaseRequestS_RegionalID = S_RegionalID
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category
|
||||||
|
ON PurchaseRequestItemCategoryID = ItemCategoryID
|
||||||
|
AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b
|
||||||
|
ON PurchaseRequestRequestedBy = b.M_UserID
|
||||||
|
AND b.M_UserIsActive = 'Y'
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a
|
||||||
|
ON PurchaseRequestApprovedBy = a.M_UserID
|
||||||
|
AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN
|
||||||
|
m_branch
|
||||||
|
ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y' AND PurchaseRequestItemCategoryID = 1
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ? OR PurchaseRequestRequestedBy LIKE ?)
|
||||||
|
AND (PurchaseRequestDate BETWEEN ? AND ?) AND PurchaseRequestS_RegionalID = ?
|
||||||
|
$sqlStockRequest
|
||||||
|
$sqlBranch
|
||||||
|
$sqlStatus";
|
||||||
|
$qry = $this->db->query($sql, [$search, $search, $search, $startDate, $endDate, $regionalID]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$total = $qry->row_array()['total'];
|
||||||
|
$tot_page = ceil($total / $number_limit);
|
||||||
|
$params = [$search, $search, $search, $startDate, $endDate, $regionalID];
|
||||||
|
|
||||||
|
$params[] = $number_limit;
|
||||||
|
$params[] = $number_offset;
|
||||||
|
$sql = "SELECT
|
||||||
|
PurchaseRequestID prID,
|
||||||
|
DATE_FORMAT(PurchaseRequestDate, '%d-%m-%Y') prDate,
|
||||||
|
PurchaseRequestNumber prNumber,
|
||||||
|
PurchaseRequestRefNumber prRefNumber,
|
||||||
|
PurchaseRequestNote prNote,
|
||||||
|
PurchaseRequestTotal prTotal,
|
||||||
|
PurchaseRequestItemCategoryID prItemType,
|
||||||
|
ItemCategoryName prItemTypeName,
|
||||||
|
PurchaseRequestStatus prStatus,
|
||||||
|
IFNULL(PurchaseRequestVerifiedBy, 0) AS PurchaseRequestVerifiedBy,
|
||||||
|
DATE_FORMAT(PurchaseRequestApprovedDate, '%d-%m-%Y %H:%i') prApprovedDate,
|
||||||
|
a.M_userUserName prApprovedBy,
|
||||||
|
b.M_UserID prRequestedByID,
|
||||||
|
b.M_userUserName prRequestedBy,
|
||||||
|
b.M_UserM_BranchID prRequestedByFromBranch,
|
||||||
|
S_RegionalName prRegionalName,
|
||||||
|
M_BranchName prBranchName,
|
||||||
|
IFNULL(`fn_getitemnamebyprid`(PurchaseRequestID), '') prItemName
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN s_regional
|
||||||
|
ON PurchaseRequestS_RegionalID = S_RegionalID
|
||||||
|
AND S_RegionalIsActive = 'Y'
|
||||||
|
JOIN item_category
|
||||||
|
ON PurchaseRequestItemCategoryID = ItemCategoryID
|
||||||
|
AND ItemCategoryIsActive = 'Y'
|
||||||
|
JOIN m_user b
|
||||||
|
ON PurchaseRequestRequestedBy = b.M_UserID
|
||||||
|
AND b.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN m_user a
|
||||||
|
ON PurchaseRequestApprovedBy = a.M_UserID
|
||||||
|
AND a.M_UserIsActive = 'Y'
|
||||||
|
LEFT JOIN
|
||||||
|
m_branch
|
||||||
|
ON PurchaseRequestM_BranchCode = M_BranchCode
|
||||||
|
WHERE PurchaseRequestIsActive = 'Y' AND PurchaseRequestItemCategoryID = 1
|
||||||
|
AND (PurchaseRequestNumber LIKE ? OR PurchaseRequestRefNumber LIKE ? OR PurchaseRequestRequestedBy LIKE ?)
|
||||||
|
AND (PurchaseRequestDate BETWEEN ? AND ?) AND PurchaseRequestS_RegionalID = ?
|
||||||
|
$sqlStockRequest
|
||||||
|
$sqlBranch
|
||||||
|
$sqlStatus
|
||||||
|
ORDER BY prDate,prNumber
|
||||||
|
DESC
|
||||||
|
LIMIT ? OFFSET ?
|
||||||
|
";
|
||||||
|
$qry = $this->db->query($sql, $params);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error searching");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
//echo $this->db->last_query();
|
||||||
|
//exit;
|
||||||
|
$data = $qry->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'total' => $tot_page,
|
||||||
|
'records' => $data,
|
||||||
|
// "qry" => $this->db->last_query()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDetail()
|
||||||
|
{
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id = $prm['id'];
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
PurchaseRequestID as prDetailPrID,
|
||||||
|
PurchaseRequestDetailID as prDetailID,
|
||||||
|
PurchaseRequestDetailM_ItemID as prDetailItemID,
|
||||||
|
M_ItemDesc as prDetailItemName,
|
||||||
|
M_ItemCode as prDetailItemCode,
|
||||||
|
PurchaseRequestDetailQty as prDetailItemQty,
|
||||||
|
PurchaseRequestDetailPrice as prDetailItemPrice,
|
||||||
|
PurchaseRequestDetailItemUnitID,
|
||||||
|
ItemUnitName as prDetailItemUnitName,
|
||||||
|
SUM(StockQty) AS CurrentStockQty
|
||||||
|
FROM purchase_request
|
||||||
|
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||||
|
AND PurchaseRequestDetailIsActive = 'Y'
|
||||||
|
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||||
|
JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID
|
||||||
|
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||||
|
JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||||
|
AND WarehouseM_BranchID = COALESCE(M_BranchID, 0)
|
||||||
|
AND WarehouseIsTransit = 'N'
|
||||||
|
LEFT JOIN stock ON StockWarehouseID = WarehouseID
|
||||||
|
AND StockItemID = PurchaseRequestDetailM_ItemID
|
||||||
|
AND StockItemUnitID = PurchaseRequestDetailItemUnitID
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
GROUP BY
|
||||||
|
PurchaseRequestDetailID,
|
||||||
|
PurchaseRequestDetailM_ItemID,
|
||||||
|
PurchaseRequestDetailItemUnitID,
|
||||||
|
M_ItemDesc,
|
||||||
|
M_ItemCode,
|
||||||
|
ItemUnitName";
|
||||||
|
$qry = $this->db->query($sql, [$id]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error get detail");
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$data = $qry->result_array();
|
||||||
|
$this->sys_ok($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function approve()
|
||||||
|
{
|
||||||
|
$this->db->trans_begin();
|
||||||
|
// $this->db->trans_rollback();
|
||||||
|
// $this->db->trans_commit();
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$detail = $prm['detail'];
|
||||||
|
$user = $this->sys_user;
|
||||||
|
$userid = $user["M_UserID"];
|
||||||
|
$pr = $prm['pr'];
|
||||||
|
$total = $prm['total'];
|
||||||
|
$type = $prm['type'];
|
||||||
|
|
||||||
|
// get user level approval
|
||||||
|
$sqlevel = "SELECT M_UserM_ApproveLevelID FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserID = ?";
|
||||||
|
$qulevel = $this->db->query($sqlevel, [$userid]);
|
||||||
|
if (!$qulevel) {
|
||||||
|
$this->sys_error_db("[Error] get approval level user");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$userlevel = $qulevel->row_array()['M_UserM_ApproveLevelID'];
|
||||||
|
|
||||||
|
$datas_log = array();
|
||||||
|
$sql = "SELECT * FROM purchase_request WHERE PurchaseRequestID = ? AND PurchaseRequestIsActive = 'Y'";
|
||||||
|
$query = $this->db->query($sql, [$pr['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_detail
|
||||||
|
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID AND M_ItemIsActive = 'Y'
|
||||||
|
JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID AND ItemUnitIsActive = 'Y'
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ? AND PurchaseRequestDetailIsActive = 'Y'";
|
||||||
|
$query = $this->db->query($sql, [$pr['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;
|
||||||
|
|
||||||
|
if ($type == 'A') {
|
||||||
|
// verifikasi jika manager
|
||||||
|
if ($userlevel == '1') {
|
||||||
|
$sql = "UPDATE purchase_request SET
|
||||||
|
PurchaseRequestVerifiedBy = ?,
|
||||||
|
PurchaseRequestVerifiedDate = NOW()
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, [$userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error verifikasi manager");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di verifikasi";
|
||||||
|
$this->insert_act_log("PRP", "Verified", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// approve jika kepala cabang / regional
|
||||||
|
if ($userlevel == '2') {
|
||||||
|
// -- PurchaseRequestTotal = ?,
|
||||||
|
$sql = "UPDATE purchase_request SET
|
||||||
|
PurchaseRequestStatus = ?,
|
||||||
|
PurchaseRequestApprovedDate = NOW(),
|
||||||
|
PurchaseRequestApprovedBy = ?
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, ['Approved', $userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error Approve");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "UPDATE purchase_request_detail
|
||||||
|
SET PurchaseRequestDetailStatus = ?
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?";
|
||||||
|
$qry = $this->db->query($sql, ['Approved', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error update detail");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di approved";
|
||||||
|
$this->insert_act_log("PRP", "Approved", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
}
|
||||||
|
} else if ($type == 'R') {
|
||||||
|
$sql = "UPDATE purchase_request
|
||||||
|
SET
|
||||||
|
PurchaseRequestStatus = ?,
|
||||||
|
PurchaseRequestApprovedDate = NOW(),
|
||||||
|
PurchaseRequestApprovedBy = ?
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Pending'";
|
||||||
|
$qry = $this->db->query($sql, ['Rejected', $userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error Approve");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "UPDATE purchase_request_detail
|
||||||
|
SET PurchaseRequestDetailStatus = ?
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?";
|
||||||
|
$qry = $this->db->query($sql, ['Rejected', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error update detail");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di reject";
|
||||||
|
$this->insert_act_log("PRP", "Rejected", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
} else if ($type == 'U') {
|
||||||
|
// un approve jika kepala cabang / regional
|
||||||
|
if ($userlevel == '2') {
|
||||||
|
// -- PurchaseRequestTotal = ?,
|
||||||
|
$sql = "UPDATE purchase_request SET
|
||||||
|
PurchaseRequestStatus = ?,
|
||||||
|
PurchaseRequestApprovedDate = NULL,
|
||||||
|
PurchaseRequestApprovedBy = NULL
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND PurchaseRequestStatus = 'Approved'";
|
||||||
|
$qry = $this->db->query($sql, ['Pending', $userid, $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error Approve");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "UPDATE purchase_request_detail
|
||||||
|
SET PurchaseRequestDetailStatus = ?
|
||||||
|
WHERE PurchaseRequestDetailPurchaseRequestID = ?";
|
||||||
|
$qry = $this->db->query($sql, ['Pending', $pr['prID']]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("Error update detail");
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$messages = "Purchase Request dengan kode " . $header['PurchaseRequestNumber'] . " telah di unapproved";
|
||||||
|
$this->insert_act_log("PRP", "Unapproved", $messages, $pr['prID'], $this->safeJsonEncode($datas_log), $userid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update notification
|
||||||
|
$this->readNotif($type, $userlevel, $userid, $pr['prID']);
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
|
||||||
|
$this->sys_ok('Berhasil');
|
||||||
|
}
|
||||||
|
|
||||||
|
// read notification
|
||||||
|
function readNotif($type, $userlevel, $userId, $refID)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
|
||||||
|
// cari user penerima notifikasi
|
||||||
|
if ($type == "U") {
|
||||||
|
$sql_get = "SELECT PurchaseRequestID,
|
||||||
|
M_UserID,
|
||||||
|
M_UserUsername,
|
||||||
|
NotificationID,
|
||||||
|
NotificationDetailID,
|
||||||
|
NotificationDetailStatus,
|
||||||
|
NotificationDetailM_UserID,
|
||||||
|
NotificationDetailM_ApproveLevelID
|
||||||
|
FROM notification
|
||||||
|
JOIN purchase_request ON NotificationRefID = PurchaseRequestID
|
||||||
|
AND PurchaseRequestIsActive = 'Y'
|
||||||
|
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||||
|
JOIN m_user ON NotificationUserID = M_UserID
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND NotificationDetailStatus = 'read'";
|
||||||
|
$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 PurchaseRequestID,
|
||||||
|
M_UserID,
|
||||||
|
M_UserUsername,
|
||||||
|
NotificationID,
|
||||||
|
NotificationDetailID,
|
||||||
|
NotificationDetailStatus,
|
||||||
|
NotificationDetailM_UserID,
|
||||||
|
NotificationDetailM_ApproveLevelID
|
||||||
|
FROM notification
|
||||||
|
JOIN purchase_request ON NotificationRefID = PurchaseRequestID
|
||||||
|
AND PurchaseRequestIsActive = 'Y'
|
||||||
|
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||||
|
JOIN m_user ON NotificationUserID = M_UserID
|
||||||
|
WHERE PurchaseRequestID = ?
|
||||||
|
AND NotificationDetailStatus = 'unread'";
|
||||||
|
$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") {
|
||||||
|
if ($userlevel === '1') {
|
||||||
|
// verifikasi manager
|
||||||
|
$sql = "UPDATE notification_detail SET
|
||||||
|
NotificationDetailStatus = 'read',
|
||||||
|
NotificationDetailLastUpdated = NOW(),
|
||||||
|
NotificationDetailUserID = ?
|
||||||
|
WHERE NotificationDetailNotificationID = ?
|
||||||
|
AND NotificationDetailM_ApproveLevelID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userId, $user["NotificationID"], $user["NotificationDetailM_ApproveLevelID"]]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("update notification error", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} else if ($userlevel === '2') {
|
||||||
|
// approve kepala cabang / regional
|
||||||
|
$sql = "UPDATE notification_detail SET
|
||||||
|
NotificationDetailStatus = 'read',
|
||||||
|
NotificationDetailLastUpdated = NOW(),
|
||||||
|
NotificationDetailUserID = ?
|
||||||
|
WHERE NotificationDetailNotificationID = ?
|
||||||
|
AND NotificationDetailM_ApproveLevelID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userId, $user["NotificationID"], $user["NotificationDetailM_ApproveLevelID"]]);
|
||||||
|
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") {
|
||||||
|
if ($userlevel === '2') {
|
||||||
|
$sql = "UPDATE notification_detail SET
|
||||||
|
NotificationDetailStatus = 'unread',
|
||||||
|
NotificationDetailLastUpdated = NOW(),
|
||||||
|
NotificationDetailUserID = ?
|
||||||
|
WHERE NotificationDetailNotificationID = ?
|
||||||
|
AND NotificationDetailM_ApproveLevelID = ?";
|
||||||
|
$qry = $this->db->query($sql, [$userId, $user["NotificationID"], $user["NotificationDetailM_ApproveLevelID"]]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->sys_error_db("update notification error", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUserApproveLevel()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$userId = $this->sys_user["M_UserID"];
|
||||||
|
|
||||||
|
$sqlevel = "SELECT M_UserM_ApproveLevelID FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserID = ?";
|
||||||
|
$qulevel = $this->db->query($sqlevel, [$userId]);
|
||||||
|
if (!$qulevel) {
|
||||||
|
$this->sys_error_db("[Error] get approval level user");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$data = $qulevel->row_array();
|
||||||
|
|
||||||
|
$this->sys_ok($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateqty()
|
||||||
|
{
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
$userId = $this->sys_user["M_UserID"];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$arrItems = $prm["arrItems"];
|
||||||
|
|
||||||
|
if (count($arrItems) > 0) {
|
||||||
|
foreach ($arrItems as $key => $value) {
|
||||||
|
$sql = "UPDATE purchase_request_detail SET
|
||||||
|
PurchaseRequestDetailQty = ?,
|
||||||
|
PurchaseRequestDetailLastUpdated = NOW(),
|
||||||
|
PurchaseRequestDetailLastUpdatedUserID = ?
|
||||||
|
WHERE PurchaseRequestDetailID = ?";
|
||||||
|
$qry = $this->db->query($sql, [
|
||||||
|
$value['prDetailItemQty'],
|
||||||
|
$userId,
|
||||||
|
$value['prDetailID']
|
||||||
|
]);
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
$this->sys_error_db("Failed update qty", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
$this->sys_ok("Berhasil update qty");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,7 +98,6 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
rod.ReceiveOrderPoDetailID,
|
rod.ReceiveOrderPoDetailID,
|
||||||
rod.ReceiveOrderPoItemID,
|
rod.ReceiveOrderPoItemID,
|
||||||
rod.ReceiveOrderPoItemUnitID,
|
rod.ReceiveOrderPoItemUnitID,
|
||||||
pod.PurchaseOrderDetailPurchaseRequestID AS PurchaseRequestID,
|
|
||||||
mi.M_ItemDesc,
|
mi.M_ItemDesc,
|
||||||
rod.ReceiveOrderPoDetailQty AS originalQty,
|
rod.ReceiveOrderPoDetailQty AS originalQty,
|
||||||
COALESCE(ahd_count.InsertedQty, 0) AS serahQty,
|
COALESCE(ahd_count.InsertedQty, 0) AS serahQty,
|
||||||
@@ -108,7 +107,6 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
ELSE 'N'
|
ELSE 'N'
|
||||||
END AS isHandoverDone
|
END AS isHandoverDone
|
||||||
FROM receive_order_po_detail rod
|
FROM receive_order_po_detail rod
|
||||||
JOIN purchase_order_detail pod ON pod.PurchaseOrderDetailID = rod.ReceiveOrderPoDetailPurchaseOrderDetailID
|
|
||||||
JOIN m_item mi ON mi.M_ItemID = rod.ReceiveOrderPoItemID
|
JOIN m_item mi ON mi.M_ItemID = rod.ReceiveOrderPoItemID
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
@@ -2675,7 +2673,6 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
}
|
}
|
||||||
$data_prid = $que_get_prid->row_array();
|
$data_prid = $que_get_prid->row_array();
|
||||||
|
|
||||||
foreach ($param['item'] as $key => $item) {
|
|
||||||
# insert handover #
|
# insert handover #
|
||||||
$sql_insert_handover = "INSERT INTO asset_handover(
|
$sql_insert_handover = "INSERT INTO asset_handover(
|
||||||
AssetHandoverPurchaseRequestID,
|
AssetHandoverPurchaseRequestID,
|
||||||
@@ -2688,7 +2685,7 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
AssetHandoverUserID
|
AssetHandoverUserID
|
||||||
) VALUES(?,?,NOW(),?,?,'Y',NOW(),?)";
|
) VALUES(?,?,NOW(),?,?,'Y',NOW(),?)";
|
||||||
$qry_insert_handover = $this->db->query($sql_insert_handover, [
|
$qry_insert_handover = $this->db->query($sql_insert_handover, [
|
||||||
$item['PurchaseRequestID'],
|
$data_prid['PurchaseRequestID'],
|
||||||
$param['receiveOrderPoID'],
|
$param['receiveOrderPoID'],
|
||||||
$param['ruanganID'],
|
$param['ruanganID'],
|
||||||
$param['staffID'],
|
$param['staffID'],
|
||||||
@@ -2699,8 +2696,10 @@ class ReceiveItemPoInventaris extends MY_Controller
|
|||||||
$this->sys_error_db("[Error] insert asset handover");
|
$this->sys_error_db("[Error] insert asset handover");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$handoverID = $this->db->insert_id();
|
$handoverID = $this->db->insert_id();
|
||||||
|
|
||||||
|
foreach ($param['item'] as $key => $item) {
|
||||||
$qty_invnt = intval($item['serahQty']);
|
$qty_invnt = intval($item['serahQty']);
|
||||||
for ($i = 0; $i < $qty_invnt; $i++) {
|
for ($i = 0; $i < $qty_invnt; $i++) {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,264 @@
|
|||||||
|
<?php
|
||||||
|
class Billv2 extends MY_Controller {
|
||||||
|
var $db;
|
||||||
|
public function index() {
|
||||||
|
echo "Bill V2 API";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search() {
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception("Invalid token", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = $this->sys_input;
|
||||||
|
|
||||||
|
$keyword = "%";
|
||||||
|
if ($params['search'] != '') {
|
||||||
|
$keyword .= $params['search'] . "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset = 0;
|
||||||
|
$limit = 5;
|
||||||
|
if ($params['currentpage'] > 0) {
|
||||||
|
$offset = ($params['currentpage'] - 1) * $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_base = "SELECT
|
||||||
|
SupplierPaymentID,
|
||||||
|
SupplierPaymentDate,
|
||||||
|
SupplierPaymentNumber,
|
||||||
|
SupplierPaymentAmount,
|
||||||
|
SupplierPaymentStatus,
|
||||||
|
SupplierPaymentIsVerif,
|
||||||
|
SupplierPaymentIsApproved,
|
||||||
|
SupplierInvoiceID,
|
||||||
|
SupplierInvoiceNumber,
|
||||||
|
SupplierInvoiceDraftPaymentDate,
|
||||||
|
SupplierCode,
|
||||||
|
SupplierName
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_invoice ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||||
|
AND SupplierPaymentNumber LIKE ?
|
||||||
|
AND (SupplierPaymentDate BETWEEN DATE(?) AND DATE(?))
|
||||||
|
AND (SupplierPaymentStatus = ? OR ? = 'All')
|
||||||
|
JOIN supplier ON SupplierID = SupplierInvoiceSupplierID
|
||||||
|
WHERE SupplierPaymentIsActive = 'Y'
|
||||||
|
ORDER BY SupplierPaymentID DESC";
|
||||||
|
|
||||||
|
$sql_data = $sql_base . " LIMIT ? OFFSET ? ";
|
||||||
|
$que_data = $this->db->query($sql_data, [
|
||||||
|
$keyword, $params['startdate'], $params['enddate'],
|
||||||
|
$params['status'], $params['status'], $limit, $offset
|
||||||
|
]);
|
||||||
|
if (!$que_data) {
|
||||||
|
throw new Exception("[Error] failed get data supplier payment", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_total = "SELECT COUNT(*) AS total FROM ($sql_base) AS x";
|
||||||
|
$que_total = $this->db->query($sql_total, [
|
||||||
|
$keyword, $params['startdate'], $params['enddate'],
|
||||||
|
$params['status'], $params['status']
|
||||||
|
]);
|
||||||
|
if (!$que_total) {
|
||||||
|
throw new Exception("[Error] failed get total data supplier payment", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = [
|
||||||
|
"records" => $que_data->result_array(),
|
||||||
|
"total" =>$que_total->row_array()['total']
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->sys_ok($output);
|
||||||
|
exit;
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$code = $exc->getCode();
|
||||||
|
|
||||||
|
if ($code == 1) {
|
||||||
|
$this->sys_error($message);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($message);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchDetail() {
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception("invalid token", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$para = $this->sys_input;
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
SupplierInvoiceID,
|
||||||
|
SupplierInvoiceRefNumber,
|
||||||
|
SupplierInvoiceDeliveryOrderNumber,
|
||||||
|
SupplierInvoiceSupplierInvoiceNumber,
|
||||||
|
SupplierInvoiceSupplierInvoiceDate,
|
||||||
|
SupplierInvoiceSubTotal,
|
||||||
|
SupplierInvoiceTaxPercentPph,
|
||||||
|
SupplierInvoiceTaxPercentPpn,
|
||||||
|
SupplierInvoiceTaxAmountPpn,
|
||||||
|
SupplierInvoiceDiscountAmount,
|
||||||
|
SupplierInvoiceDiscountPercent,
|
||||||
|
SupplierInvoiceShippingCost,
|
||||||
|
SupplierInvoiceGrandTotal,
|
||||||
|
SupplierInvoiceAdjustmentAmount,
|
||||||
|
SupplierInvoiceAdjustmentNote,
|
||||||
|
SupplierInvoiceNote,
|
||||||
|
IF (SupplierInvoiceDiscountAmount > 0, 'R', 'P') AS DiscountType
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_invoice ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
|
||||||
|
AND SupplierPaymentID = ?
|
||||||
|
AND SupplierPaymentIsActive = 'Y'";
|
||||||
|
$que = $this->db->query($sql, [$para['paymentID']]);
|
||||||
|
if (!$que) {
|
||||||
|
throw new Exception("[Error] failed get row data", 2);
|
||||||
|
}
|
||||||
|
$data = $que->row_array();
|
||||||
|
|
||||||
|
$sql_detail = "SELECT
|
||||||
|
SupplierInvoiceDetailID,
|
||||||
|
SupplierInvoiceDetailSupplierInvoiceID,
|
||||||
|
SupplierInvoiceDetailPurchaseOrderID,
|
||||||
|
SupplierInvoiceDetailPurchaseOrderSummaryID,
|
||||||
|
SupplierInvoiceDetailReceiveOrderPoID,
|
||||||
|
SupplierInvoiceDetailReceiveOrderPoDetailID,
|
||||||
|
SupplierInvoiceDetailItemID,
|
||||||
|
SupplierInvoiceDetailItemUnitID,
|
||||||
|
SupplierInvoiceDetailDescription,
|
||||||
|
SupplierInvoiceDetailQty,
|
||||||
|
SupplierInvoiceDetailPrice,
|
||||||
|
SupplierInvoiceDetailDiscountPercent,
|
||||||
|
SupplierInvoiceDetailDiscountDiscountRupiah,
|
||||||
|
SupplierInvoiceDetailDiscountDiscountType,
|
||||||
|
SupplierInvoiceDetailDiscountAmount,
|
||||||
|
(SupplierInvoiceDetailPrice - SupplierInvoiceDetailDiscountAmount) AS DiscountedPrice,
|
||||||
|
SupplierInvoiceDetailDiscountPoProrata,
|
||||||
|
SupplierInvoiceDetailTotal,
|
||||||
|
M_ItemCode,
|
||||||
|
M_ItemDesc
|
||||||
|
FROM supplier_payment_detail
|
||||||
|
JOIN supplier_invoice_detail ON SupplierInvoiceDetailIsActive = 'Y'
|
||||||
|
AND SupplierPaymentDetailSupplierPaymentID = ?
|
||||||
|
AND SupplierInvoiceDetailSupplierInvoiceID = ?
|
||||||
|
JOIN m_item ON M_ItemID = SupplierInvoiceDetailItemID
|
||||||
|
AND M_ItemIsActive = 'Y'
|
||||||
|
GROUP BY SupplierInvoiceDetailID";
|
||||||
|
$que_detail = $this->db->query($sql_detail, [
|
||||||
|
$para['paymentID'], $data['SupplierInvoiceID']
|
||||||
|
]);
|
||||||
|
if (!$que_detail) {
|
||||||
|
throw new Exception("[Error] failed to get item payments", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['detail'] = $que_detail->result_array();
|
||||||
|
|
||||||
|
$this->sys_ok($data);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$code = $exc->getCode();
|
||||||
|
|
||||||
|
if ($code == 1) {
|
||||||
|
$this->sys_error($message);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($message);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserApproveLevel() {
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception("Invalid token", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
$sql_level = "SELECT M_UserM_ApproveLevelID AS level
|
||||||
|
FROM m_user WHERE M_UserIsActive = 'Y' AND M_UserID = ? ";
|
||||||
|
$que_level = $this->db->query($sql_level, [$userid]);
|
||||||
|
if (!$que_level) {
|
||||||
|
throw new Exception("[Error] failed get user approve level", 2);
|
||||||
|
}
|
||||||
|
$data = $que_level->row_array();
|
||||||
|
$this->sys_ok($data);
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$code = $exc->getCode();
|
||||||
|
|
||||||
|
if ($code == 1) {
|
||||||
|
$this->sys_error($message);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($message);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateStatusPayment() {
|
||||||
|
try {
|
||||||
|
if (!$this->isLogin) {
|
||||||
|
throw new Exception("Invalid token", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_begin();
|
||||||
|
$para = $this->sys_input;
|
||||||
|
$user = $this->sys_user;
|
||||||
|
|
||||||
|
if ($para['userlevel'] == '1') {
|
||||||
|
$sql = "UPDATE supplier_payment SET
|
||||||
|
SupplierPaymentIsVerif = 'Y',
|
||||||
|
SupplierPaymentStatus = 'Verified',
|
||||||
|
SupplierPaymentVerifUserID = ?,
|
||||||
|
SupplierPaymentVerifDate = NOW()
|
||||||
|
WHERE SupplierPaymentID = ?
|
||||||
|
AND SupplierPaymentIsActive = 'Y'";
|
||||||
|
$query = $this->db->query($sql, [
|
||||||
|
$user['M_UserID'], $para['paymentID']
|
||||||
|
]);
|
||||||
|
if (!$query) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
throw new Exception("[Error] failed update status verified", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($para['userlevel'] == '2') {
|
||||||
|
$sql = "UPDATE supplier_payment SET
|
||||||
|
SupplierPaymentIsApproved = 'Y',
|
||||||
|
SupplierPaymentStatus = 'Approved',
|
||||||
|
SupplierPaymentApprovedUserID = ?,
|
||||||
|
SupplierPaymentApprovedDate = NOW()
|
||||||
|
WHERE SupplierPaymentID = ?
|
||||||
|
AND SupplierPaymentIsActive = 'Y'";
|
||||||
|
$query = $this->db->query($sql, [
|
||||||
|
$user['M_UserID'], $para['paymentID']
|
||||||
|
]);
|
||||||
|
if (!$query) {
|
||||||
|
$this->db->trans_rollback();
|
||||||
|
throw new Exception("[Error] failed update status approved", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->trans_commit();
|
||||||
|
$this->sys_ok("[Success] success update status Payment");
|
||||||
|
} catch (Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$code = $exc->getCode();
|
||||||
|
|
||||||
|
if ($code == 1) {
|
||||||
|
$this->sys_error($message);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db($message);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
769
application/controllers/mockup/supplierpaymentfailed/Bill.php
Normal file
769
application/controllers/mockup/supplierpaymentfailed/Bill.php
Normal file
@@ -0,0 +1,769 @@
|
|||||||
|
<?php
|
||||||
|
class Bill extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "Bill API";
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_notes($orderid){
|
||||||
|
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||||
|
SupplierPaymentID as note_id,
|
||||||
|
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||||
|
SupplierPaymentDate as note_date,
|
||||||
|
SupplierPaymentNumber as note_number,
|
||||||
|
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') as paymenttypes_name,
|
||||||
|
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||||
|
M_UserUsername as note_user,
|
||||||
|
SupplierPaymentDetailIsActive as note_active,
|
||||||
|
'xxx' as tests,
|
||||||
|
'N' as show_detail,
|
||||||
|
SupplierPaymentNote as keterangan,
|
||||||
|
SupplierPaymentCoaID,
|
||||||
|
coaID,
|
||||||
|
coaDescription,
|
||||||
|
SupplierPaymentIsConfirm
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||||
|
LEFT JOIN m_user ON SupplierPaymentUserID = M_UserID
|
||||||
|
WHERE
|
||||||
|
SupplierPaymentSupplierInvoiceID = {$orderid}
|
||||||
|
AND
|
||||||
|
SupplierPaymentIsActive = 'Y'
|
||||||
|
GROUP BY SupplierPaymentID";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if($rows){
|
||||||
|
foreach($rows as $k => $v){
|
||||||
|
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function add_tagihans($orderid){
|
||||||
|
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
||||||
|
PurchaseOrderNumber as tagihan_number,
|
||||||
|
jurnalTxDescription as pasien,
|
||||||
|
jurnalTxCredit as tagihan_total,
|
||||||
|
IF(SupplierPaymentDetailID IS NULL , jurnalTxCredit, jurnalTxCredit - SUM(SupplierPaymentDetailAmount)) as tagihan_tagihan,
|
||||||
|
0 as tagihan_bayar,
|
||||||
|
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
|
||||||
|
SupplierInvoiceIsActive as tagihan_active,
|
||||||
|
'N' as show_detail,
|
||||||
|
jurnalTxID SupplierInvoiceDetailID,
|
||||||
|
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
|
||||||
|
|
||||||
|
FROM supplier_invoice
|
||||||
|
JOIN purchase_order ON SupplierInvoicePurchaseOrderID = PurchaseOrderID
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||||
|
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceIsActive = 'Y'
|
||||||
|
LEFT JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
WHERE
|
||||||
|
SupplierInvoiceID = {$orderid}
|
||||||
|
GROUP BY jurnalTxID
|
||||||
|
";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function add_tests($orderid){
|
||||||
|
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||||
|
SupplierPaymentID as note_id,
|
||||||
|
SupplierPaymentDate as note_date,
|
||||||
|
SupplierPaymentNumber as note_number,
|
||||||
|
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
|
||||||
|
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||||
|
M_UserUsername as note_user,
|
||||||
|
SupplierPaymentDetailIsActive as note_active,
|
||||||
|
PurchaseOrderNumber,
|
||||||
|
SupplierInvoiceDetailTotal,
|
||||||
|
SupplierPaymentDetailAmount
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||||
|
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
|
||||||
|
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||||
|
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||||
|
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID
|
||||||
|
WHERE
|
||||||
|
SupplierPaymentID = {$orderid}
|
||||||
|
GROUP BY SupplierPaymentDetailID";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if($rows){
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function searchsupplier(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count =0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '')
|
||||||
|
{
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
$sql = "
|
||||||
|
SELECT count(*) as total
|
||||||
|
FROM supplier
|
||||||
|
WHERE
|
||||||
|
SupplierName like ?
|
||||||
|
AND SupplierIsActive = 'Y'
|
||||||
|
ORDER BY SupplierName DESC
|
||||||
|
";
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql,$q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "
|
||||||
|
SELECT *
|
||||||
|
FROM supplier
|
||||||
|
WHERE
|
||||||
|
SupplierName like ?
|
||||||
|
AND SupplierIsActive = 'Y'
|
||||||
|
ORDER BY SupplierName DESC
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("m_city rows",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function searchinvpayment(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count =0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '')
|
||||||
|
{
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
$sql = "SELECT count(*) as total
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_invoice ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
|
||||||
|
AND SupplierInvoiceSupplierID = {$prm['companyid']}
|
||||||
|
WHERE
|
||||||
|
SupplierPaymentNumber like ?
|
||||||
|
AND SupplierPaymentIsActive = 'Y'
|
||||||
|
AND SupplierPaymentIsConfirm = 'Y'
|
||||||
|
ORDER BY SupplierPaymentID ASC
|
||||||
|
";
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql,$q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "
|
||||||
|
SELECT *, CONCAT(SupplierPaymentNumber,' - ',coaDescription, ' Rp. ',SupplierPaymentAmount) PaymentName
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_invoice ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID
|
||||||
|
AND SupplierInvoiceSupplierID = {$prm['companyid']}
|
||||||
|
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||||
|
WHERE
|
||||||
|
SupplierPaymentNumber like ?
|
||||||
|
AND SupplierPaymentIsActive = 'Y'
|
||||||
|
AND SupplierPaymentIsConfirm = 'Y'
|
||||||
|
ORDER BY SupplierPaymentID ASC
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("m_city rows",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$supplier = $prm["supplier"];
|
||||||
|
$search = $prm["search"];
|
||||||
|
$status = $prm["status"];
|
||||||
|
$startdate = $prm["startdate"];
|
||||||
|
$enddate = $prm["enddate"];
|
||||||
|
$regionalid = $this->sys_user['S_RegionalID'];
|
||||||
|
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||||
|
|
||||||
|
$where = "SupplierPaymentIsFailed = 'Y'
|
||||||
|
AND (SupplierInvoiceNumber LIKE '%{$search}%' AND SupplierName LIKE '%{$supplier}%')
|
||||||
|
AND PurchaseOrderS_RegionalID = {$regionalid}
|
||||||
|
AND SupplierPaymentConfirmDate BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sql = " SELECT count(*) as total
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
JOIN supplier_invoice ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||||
|
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||||
|
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||||
|
WHERE
|
||||||
|
$where
|
||||||
|
";
|
||||||
|
// echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
|
||||||
|
|
||||||
|
$tot_count = 0;
|
||||||
|
$tot_page = 0;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
$tot_page = ceil($tot_count/$number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("supplier_invoice count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT SupplierInvoiceID,
|
||||||
|
SupplierPaymentID,
|
||||||
|
SupplierPaymentDetailSupplierInvoiceDetailID,
|
||||||
|
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
|
||||||
|
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
|
||||||
|
SupplierPaymentDate as note_date,
|
||||||
|
SupplierPaymentNumber as note_number,
|
||||||
|
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') as paymenttypes_name,
|
||||||
|
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||||
|
n.M_UserUsername as note_user,
|
||||||
|
SupplierPaymentDetailIsActive as note_active,
|
||||||
|
'xxx' as tests,
|
||||||
|
'N' as show_detail,
|
||||||
|
SupplierPaymentNote as keterangan,
|
||||||
|
SupplierPaymentCoaID,
|
||||||
|
coaID,
|
||||||
|
coaDescription,
|
||||||
|
SupplierPaymentIsConfirm,
|
||||||
|
SupplierPaymentApprovedUserID,
|
||||||
|
SupplierPaymentApprovedDate,
|
||||||
|
SupplierInvoiceNumber,
|
||||||
|
SupplierName,
|
||||||
|
SupplierPaymentNumber,
|
||||||
|
CONCAT('Created by : ',n.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentCreated,'%d-%m-%Y %H:%i')) as d_created,
|
||||||
|
CONCAT('Confirmed by : ',c.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentConfirmDate,'%d-%m-%Y %H:%i')) as d_confirm,
|
||||||
|
CONCAT('Approved by : ',a.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')) as d_approved
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
JOIN supplier_invoice ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||||
|
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||||
|
JOIN purchase_order ON PurchaseOrderID = SupplierInvoicePurchaseOrderID
|
||||||
|
JOIN coa ON SupplierPaymentCoaID = coaID
|
||||||
|
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID
|
||||||
|
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID
|
||||||
|
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID
|
||||||
|
WHERE
|
||||||
|
$where
|
||||||
|
GROUP BY SupplierPaymentID
|
||||||
|
ORDER BY SupplierPaymentID DESC
|
||||||
|
limit $number_limit offset $number_offset";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
$rows = $query->result_array();
|
||||||
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirm_note()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$xuserid = $this->sys_user['M_UserID'];
|
||||||
|
$regionalid = $this->sys_user['S_RegionalID'];
|
||||||
|
$branchid = $this->sys_user['M_BranchID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$prmnota = $prm['nota'];
|
||||||
|
$note = $prm['note'];
|
||||||
|
$sql = "UPDATE supplier_payment
|
||||||
|
SET SupplierPaymentIsFailed = 'Y',
|
||||||
|
SupplierPaymentFailedUserID = {$xuserid},
|
||||||
|
SupplierPaymentFailedDate = now(),
|
||||||
|
SupplierPaymentFailedNote = '{$note}'
|
||||||
|
WHERE SupplierPaymentID = {$prmnota['SupplierPaymentID']}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$headerid = $prmnota['SupplierPaymentID'];
|
||||||
|
$sql = "SELECT * FROM supplier_payment
|
||||||
|
JOIN m_user ON M_UserID = SupplierPaymentFailedUserID
|
||||||
|
WHERE SupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$row = $query->row_array();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sqlbill = "UPDATE supplier_invoice SET
|
||||||
|
SupplierInvoiceIsLunas = 'N'
|
||||||
|
WHERE SupplierInvoiceID = {$prmnota['SupplierInvoiceID']}";
|
||||||
|
$querybill = $this->db_onedev->query($sqlbill);
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM supplier_payment_detail
|
||||||
|
WHERE SupplierPaymentDetailSupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$rows = $query->row_array();
|
||||||
|
|
||||||
|
$data = array("header" => $row,
|
||||||
|
"details" => $rows);
|
||||||
|
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." telah dibatalkan oleh " . $row["M_UserUsername"];
|
||||||
|
$this->insert_act_log("PF", "CONFIRM", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
|
||||||
|
|
||||||
|
$sqlData = "SELECT SupplierPaymentDetailID as id,
|
||||||
|
SupplierPaymentID,
|
||||||
|
SupplierPaymentNumber,
|
||||||
|
$branchid M_BranchID,
|
||||||
|
'' M_BranchCode,
|
||||||
|
'' M_BranchName,
|
||||||
|
M_BranchS_RegionalID,
|
||||||
|
M_BranchCompanyID,
|
||||||
|
M_BranchCompanyName,
|
||||||
|
CONCAT('Jurnal Payment Invoice Failed Nomor : SupplierPaymentNumber', DATE_FORMAT(now(), '%d-%m-%Y')) xdescription,
|
||||||
|
IFNULL(periodeID,0) periodeid,
|
||||||
|
CONCAT('Jurnal Payment Invoice Failed Nomor : SupplierPaymentNumber', DATE_FORMAT(now(), '%d-%m-%Y'), ' regional ',S_RegionalName) title,
|
||||||
|
22 typeid,
|
||||||
|
'' detailjurnal,
|
||||||
|
coaID,
|
||||||
|
coaAccountNo,
|
||||||
|
coaDescription,
|
||||||
|
0 debit,
|
||||||
|
SupplierPaymentDetailAmount credit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
JOIN s_regional ON S_RegionalID = $regionalid
|
||||||
|
LEFT JOIN m_branch ON M_BranchS_RegionalID = S_RegionalID AND M_BranchID = {$branchid}
|
||||||
|
LEFT JOIN m_branch_companydetail ON M_BranchCompanyDetailM_BranchCode = M_BranchCode AND M_BranchCompanyDetailIsActive = 'Y'
|
||||||
|
LEFT JOIN m_branch_company ON M_BranchCompanyID = M_BranchCompanyDetailM_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||||
|
JOIN coa ON coaID = SupplierPaymentCoaID
|
||||||
|
LEFT JOIN periode ON date(now()) BETWEEN periodeStartDate AND periodeEndDate AND periodeIsActive = 'Y'
|
||||||
|
JOIN jurnal_tx ON jurnalTxID = SupplierPaymentDetailSupplierInvoiceDetailID
|
||||||
|
WHERE SupplierPaymentID = {$headerid} AND SupplierPaymentIsActive = 'Y'
|
||||||
|
GROUP BY SupplierPaymentID";
|
||||||
|
$newData = $this->db_onedev->query($sqlData)->result_array();
|
||||||
|
// echo $this->db_onedev->last_query();
|
||||||
|
if ($newData) {
|
||||||
|
foreach ($newData as $k => $v) {
|
||||||
|
$periodeid = $v["periodeid"];
|
||||||
|
$branchcompanyid = $v["M_BranchCompanyID"];
|
||||||
|
$date = date('Y-m-d');
|
||||||
|
$description = $v["xdescription"];
|
||||||
|
$regionalid = $v["M_BranchS_RegionalID"];
|
||||||
|
$title = $v["title"];
|
||||||
|
$typeid = $v["typeid"];
|
||||||
|
$pvno = $v["SupplierPaymentNumber"];
|
||||||
|
$detailjurnal = $this->db_onedev->query("SELECT SupplierPaymentDetailID as id,
|
||||||
|
coaID coaid,
|
||||||
|
coaDescription xdescription,
|
||||||
|
SupplierPaymentDetailAmount debit,
|
||||||
|
0 credit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
JOIN s_regional ON S_RegionalID = $regionalid
|
||||||
|
LEFT JOIN m_branch ON M_BranchS_RegionalID = S_RegionalID AND M_BranchID = $branchid
|
||||||
|
LEFT JOIN m_branch_companydetail ON M_BranchCompanyDetailM_BranchCode = M_BranchCode AND M_BranchCompanyDetailIsActive = 'Y'
|
||||||
|
LEFT JOIN m_branch_company ON M_BranchCompanyID = M_BranchCompanyDetailM_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||||
|
JOIN coa ON coaID = SupplierPaymentCoaID
|
||||||
|
LEFT JOIN periode ON date(now()) BETWEEN periodeStartDate AND periodeEndDate AND periodeIsActive = 'Y'
|
||||||
|
JOIN jurnal_tx ON jurnalTxID = SupplierPaymentDetailSupplierInvoiceDetailID
|
||||||
|
WHERE SupplierPaymentID = {$headerid} AND SupplierPaymentIsActive = 'Y'
|
||||||
|
|
||||||
|
UNION SELECT jurnalTxID as id,
|
||||||
|
jurnalTxCoaID coaid,
|
||||||
|
jurnalTxDescription xdescription,
|
||||||
|
0 debit,
|
||||||
|
SupplierPaymentDetailAmount credit
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
JOIN s_regional ON S_RegionalID = $regionalid
|
||||||
|
LEFT JOIN m_branch ON M_BranchS_RegionalID = S_RegionalID AND M_BranchID = $branchid
|
||||||
|
LEFT JOIN m_branch_companydetail ON M_BranchCompanyDetailM_BranchCode = M_BranchCode AND M_BranchCompanyDetailIsActive = 'Y'
|
||||||
|
LEFT JOIN m_branch_company ON M_BranchCompanyID = M_BranchCompanyDetailM_BranchCompanyID AND M_BranchCompanyIsActive = 'Y'
|
||||||
|
LEFT JOIN periode ON date(now()) BETWEEN periodeStartDate AND periodeEndDate AND periodeIsActive = 'Y'
|
||||||
|
JOIN jurnal_tx ON jurnalTxID = SupplierPaymentDetailSupplierInvoiceDetailID
|
||||||
|
JOIN coa ON coaID = jurnalTxCoaID
|
||||||
|
WHERE SupplierPaymentID = {$headerid} AND SupplierPaymentIsActive = 'Y'
|
||||||
|
GROUP BY id")->result_array();
|
||||||
|
//echo $this->db->last_query();
|
||||||
|
$rows[$k]['detailjurnal'] = $detailjurnal;
|
||||||
|
|
||||||
|
$this->savejurnal($branchid, $date, $description, $periodeid, $regionalid, $title, $typeid, $detailjurnal, $pvno, $branchcompanyid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => 1 ,
|
||||||
|
"records" => array('prm'=>$prm)
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function savejurnal($branchid, $date, $description, $periodeid, $regionalid, $title, $typeid, $detailjurnal, $pvno, $branchcompanyid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db_onedev->trans_begin();
|
||||||
|
$userid = $this->sys_user['M_UserID'];
|
||||||
|
|
||||||
|
$sql_branch = "SELECT
|
||||||
|
M_BranchID,
|
||||||
|
M_BranchCode,
|
||||||
|
M_BranchName
|
||||||
|
FROM m_branch
|
||||||
|
WHERE M_BranchIsActive = 'Y'
|
||||||
|
AND M_BranchID = ?";
|
||||||
|
$qry_branch = $this->db_onedev->query($sql_branch, array($branchid));
|
||||||
|
if ($qry_branch) {
|
||||||
|
$branchcodex = $qry_branch->row()->M_BranchCode;
|
||||||
|
} else {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("select branch error", $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO jurnal(
|
||||||
|
jurnalM_BranchCompanyID,
|
||||||
|
JurnalS_RegionalID,
|
||||||
|
jurnalM_BranchCode,
|
||||||
|
jurnalperiodeID,
|
||||||
|
jurnalNo,
|
||||||
|
jurnalTitle,
|
||||||
|
jurnalDescription,
|
||||||
|
jurnalDate,
|
||||||
|
jurnalJurnalTypeID,
|
||||||
|
jurnalIsActive,
|
||||||
|
jurnalCreated,
|
||||||
|
jurnalM_UserID
|
||||||
|
) VALUES(?,?,?,?,`fn_numbering`('J'),?,?,?,?,'Y',NOW(),?)";
|
||||||
|
$qry = $this->db_onedev->query($sql, array(
|
||||||
|
$branchcompanyid,
|
||||||
|
$regionalid,
|
||||||
|
$branchcodex,
|
||||||
|
$periodeid,
|
||||||
|
$title,
|
||||||
|
$description,
|
||||||
|
$date,
|
||||||
|
$typeid,
|
||||||
|
$userid
|
||||||
|
));
|
||||||
|
$last_qry = $this->db_onedev->last_query();
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $last_qry
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$last_id = $this->db_onedev->insert_id();
|
||||||
|
|
||||||
|
foreach ($detailjurnal as $key => $value) {
|
||||||
|
$sql_detail = "INSERT INTO jurnal_tx(
|
||||||
|
jurnalTxJurnalID,
|
||||||
|
jurnalTxCoaID,
|
||||||
|
jurnalTxDescription,
|
||||||
|
jurnalTxDebit,
|
||||||
|
jurnalTxCredit,
|
||||||
|
jurnalTxIsActive,
|
||||||
|
jurnalTxCreated,
|
||||||
|
jurnalTxM_UserID) VALUES(?,?,?,?,?,'Y',NOW(),?)";
|
||||||
|
$qry_detail = $this->db_onedev->query($sql_detail, array(
|
||||||
|
$last_id,
|
||||||
|
$value["coaid"],
|
||||||
|
$value["xdescription"],
|
||||||
|
$value["debit"],
|
||||||
|
$value["credit"],
|
||||||
|
$userid
|
||||||
|
));
|
||||||
|
$last_qry = $this->db_onedev->last_query();
|
||||||
|
if (!$qry_detail) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $last_qry
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tx_id = $this->db_onedev->insert_id();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO jurnal_addon
|
||||||
|
(jurnalAddOnJurnalID,
|
||||||
|
jurnalAddOnJurnalTxID,
|
||||||
|
jurnalAddOnCode,
|
||||||
|
jurnalAddOnValue,
|
||||||
|
jurnalAddOnCreated,
|
||||||
|
jurnalAddOnCreatedUserID,
|
||||||
|
jurnalAddOnLastUpdatedUserID,
|
||||||
|
jurnalAddOnLastUpdated)
|
||||||
|
VALUES
|
||||||
|
(?,
|
||||||
|
?,
|
||||||
|
'JFA',
|
||||||
|
?,
|
||||||
|
now(),
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
now())";
|
||||||
|
$qry = $this->db_onedev->query($sql, array(
|
||||||
|
$last_id,
|
||||||
|
$tx_id,
|
||||||
|
$pvno,
|
||||||
|
$userid,
|
||||||
|
$userid
|
||||||
|
));
|
||||||
|
$last_qry = $this->db_onedev->last_query();
|
||||||
|
if (!$qry) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$error = array(
|
||||||
|
"message" => $this->db_onedev->error()["message"],
|
||||||
|
"sql" => $last_qry
|
||||||
|
);
|
||||||
|
$this->sys_error_db($error, $this->db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->db_onedev->trans_commit();
|
||||||
|
// $result = array("total" => 1);
|
||||||
|
// $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_onedev->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_onedev);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1024
application/controllers/mockup/supplierpaymentfailed/Payment.php
Normal file
1024
application/controllers/mockup/supplierpaymentfailed/Payment.php
Normal file
File diff suppressed because it is too large
Load Diff
257
application/controllers/mockup/supplierpaymentv4/Bill.php
Normal file
257
application/controllers/mockup/supplierpaymentv4/Bill.php
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
<?php
|
||||||
|
class Bill extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "Bill API";
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_notes($orderid){
|
||||||
|
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||||
|
SupplierPaymentID as note_id,
|
||||||
|
SupplierPaymentDetailSupplierInvoiceDetailID as detail_id,
|
||||||
|
SupplierPaymentDate as note_date,
|
||||||
|
SupplierPaymentNumber as note_number,
|
||||||
|
GROUP_CONCAT(DISTINCT coaDescription separator ' , ') as paymenttypes_name,
|
||||||
|
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||||
|
n.M_UserUsername as note_user,
|
||||||
|
SupplierPaymentDetailIsActive as note_active,
|
||||||
|
'xxx' as tests,
|
||||||
|
'N' as show_detail,
|
||||||
|
SupplierPaymentNote as keterangan,
|
||||||
|
SupplierPaymentCoaID,
|
||||||
|
coaID,
|
||||||
|
coaDescription,
|
||||||
|
SupplierPaymentIsConfirm,
|
||||||
|
CONCAT('Confirmed by : ',c.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentConfirmDate,'%d-%m-%Y %H:%i')) as d_confirm,
|
||||||
|
SupplierPaymentIsApproved,
|
||||||
|
CONCAT('Approved by : ',a.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentApprovedDate,'%d-%m-%Y %H:%i')) as d_approved,
|
||||||
|
CONCAT('Verified by : ',b.M_UserUsername, ' ',DATE_FORMAT(SupplierPaymentVerifDate,'%d-%m-%Y %H:%i')) as d_verif
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
LEFT JOIN coa ON SupplierPaymentCoaID = coaID
|
||||||
|
LEFT JOIN m_user n ON SupplierPaymentUserID = n.M_UserID
|
||||||
|
LEFT JOIN m_user c ON SupplierPaymentConfirmUserID = c.M_UserID
|
||||||
|
LEFT JOIN m_user a ON SupplierPaymentApprovedUserID = a.M_UserID
|
||||||
|
LEFT JOIN m_user b ON SupplierPaymentVerifUserID = b.M_UserID
|
||||||
|
WHERE
|
||||||
|
SupplierPaymentSupplierInvoiceID = {$orderid}
|
||||||
|
AND
|
||||||
|
SupplierPaymentIsActive = 'Y'
|
||||||
|
GROUP BY SupplierPaymentID";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if($rows){
|
||||||
|
foreach($rows as $k => $v){
|
||||||
|
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function add_tagihans($orderid){
|
||||||
|
$sql = "SELECT SupplierInvoiceID as tagihan_id,
|
||||||
|
PurchaseOrderNumber as tagihan_number,
|
||||||
|
jurnalTxDescription as pasien,
|
||||||
|
jurnalTxCredit as tagihan_total,
|
||||||
|
IF(SupplierPaymentDetailID IS NULL , jurnalTxCredit, jurnalTxCredit - SUM(SupplierPaymentDetailAmount)) as tagihan_tagihan,
|
||||||
|
0 as tagihan_bayar,
|
||||||
|
DATE_FORMAT(SupplierInvoiceDueDate,'%d-%m-%Y') as tagihan_duedate,
|
||||||
|
SupplierInvoiceIsActive as tagihan_active,
|
||||||
|
'N' as show_detail,
|
||||||
|
jurnalTxID SupplierInvoiceDetailID,
|
||||||
|
PurchaseOrderID SupplierInvoiceDetailPurchaseOrderID
|
||||||
|
|
||||||
|
FROM supplier_invoice
|
||||||
|
JOIN receive_order_po ON ReceiveOrderPoID = SupplierInvoiceReceiveOrderPoID
|
||||||
|
JOIN receive_order_po_detail ON ReceiveOrderPoDetailReceiveOrderPoID = ReceiveOrderPoID
|
||||||
|
JOIN purchase_order ON ReceiveOrderPoDetailPurchaseOrderID = PurchaseOrderID
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||||
|
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierInvoiceIsActive = 'Y'
|
||||||
|
LEFT JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID AND SupplierPaymentDetailSupplierInvoiceDetailID = jurnalTxID AND SupplierPaymentDetailIsActive = 'Y'
|
||||||
|
WHERE
|
||||||
|
SupplierInvoiceID = {$orderid}
|
||||||
|
GROUP BY jurnalTxID
|
||||||
|
";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function add_tests($orderid){
|
||||||
|
$sql = " SELECT SupplierPaymentSupplierInvoiceID as note_order_id,
|
||||||
|
SupplierPaymentID as note_id,
|
||||||
|
SupplierPaymentDate as note_date,
|
||||||
|
SupplierPaymentNumber as note_number,
|
||||||
|
GROUP_CONCAT(coaDescription separator ' , ') as paymenttypes_name,
|
||||||
|
SUM(SupplierPaymentDetailAmount) as note_amount,
|
||||||
|
M_UserUsername as note_user,
|
||||||
|
SupplierPaymentDetailIsActive as note_active,
|
||||||
|
PurchaseOrderNumber,
|
||||||
|
SupplierInvoiceDetailTotal,
|
||||||
|
SupplierPaymentDetailAmount
|
||||||
|
FROM supplier_payment
|
||||||
|
JOIN supplier_payment_detail ON SupplierPaymentDetailSupplierPaymentID = SupplierPaymentID
|
||||||
|
LEFT JOIN supplier_invoice_detail ON SupplierPaymentDetailSupplierInvoiceDetailID = SupplierInvoiceDetailID
|
||||||
|
LEFT JOIN purchase_order ON SupplierInvoiceDetailPurchaseOrderID = PurchaseOrderID
|
||||||
|
LEFT JOIN coa ON SupplierPaymentCoaID = coaID
|
||||||
|
LEFT JOIN m_user ON SupplierPaymentDetailUserID = M_UserID
|
||||||
|
WHERE
|
||||||
|
SupplierPaymentID = {$orderid}
|
||||||
|
GROUP BY SupplierPaymentDetailID";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if($rows){
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("get notes", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function search()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$supplier = $prm["supplier"];
|
||||||
|
$search = $prm["search"];
|
||||||
|
$status = $prm["status"];
|
||||||
|
$startdate = $prm["startdate"];
|
||||||
|
$enddate = $prm["enddate"];
|
||||||
|
$regionalid = $this->sys_user['S_RegionalID'];
|
||||||
|
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||||
|
|
||||||
|
$where = "SupplierInvoiceIsActive = 'Y'
|
||||||
|
AND SupplierInvoiceStatus = 'Approved'
|
||||||
|
AND SupplierInvoiceGrandTotal > 0
|
||||||
|
AND IF(SupplierPaymentID IS NULL,'N','Y') = '{$status}'
|
||||||
|
AND (SupplierInvoiceNumber LIKE '%{$search}%' AND SupplierName LIKE '%{$supplier}%')
|
||||||
|
AND ReceiveOrderPoS_RegionalID = {$regionalid}
|
||||||
|
AND SupplierInvoiceDraftPaymentDate BETWEEN '{$startdate}' AND '{$enddate}'";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sql = " SELECT count(*) as total
|
||||||
|
FROM supplier_invoice
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
LEFT JOIN supplier_payment ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||||
|
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||||
|
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||||
|
WHERE
|
||||||
|
$where
|
||||||
|
";
|
||||||
|
// echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
|
||||||
|
|
||||||
|
$tot_count = 0;
|
||||||
|
$tot_page = 0;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
$tot_page = ceil($tot_count/$number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("supplier_invoice count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT supplier_invoice.*,
|
||||||
|
SupplierName,
|
||||||
|
'' M_MouName,
|
||||||
|
0 as totalbill,
|
||||||
|
0 as paid,
|
||||||
|
0 as unpaid,
|
||||||
|
SupplierInvoiceIsLunas as flaglunas,
|
||||||
|
0 as SupplierPaymentID,
|
||||||
|
'' as SupplierPaymentNumber,
|
||||||
|
0 as SupplierPaymentAmount,
|
||||||
|
'' as SupplierPaymentDate,
|
||||||
|
'' as SupplierInvoiceIssueRefNumber,
|
||||||
|
'' as notes,
|
||||||
|
'' as tagihans,
|
||||||
|
'N' as isbillterpusat,
|
||||||
|
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d-%m-%Y') as tanggalbayar,
|
||||||
|
DATE_FORMAT(SupplierInvoiceDraftPaymentDate,'%d%m%Y') as tanggalbayartext,
|
||||||
|
IF(SupplierPaymentID IS NULL,'N','Y') as status_invoice,
|
||||||
|
IFNULL(SupplierPaymentIsApproved,'N') as SupplierPaymentIsApproved,
|
||||||
|
IFNULL(SupplierPaymentIsVerif,'N') as SupplierPaymentIsVerif,
|
||||||
|
IFNULL(SupplierPaymentCashierNumber,'') SupplierPaymentCashierNumber
|
||||||
|
|
||||||
|
FROM supplier_invoice
|
||||||
|
LEFT JOIN supplier ON SupplierInvoiceSupplierID = SupplierID
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
JOIN receive_order_po ON SupplierInvoiceReceiveOrderPoID = ReceiveOrderPoID
|
||||||
|
LEFT JOIN supplier_payment ON SupplierPaymentSupplierInvoiceID = SupplierInvoiceID AND SupplierPaymentIsActive = 'Y'
|
||||||
|
WHERE
|
||||||
|
$where
|
||||||
|
GROUP BY SupplierInvoiceID
|
||||||
|
ORDER BY SupplierInvoiceID ASC
|
||||||
|
limit $number_limit offset $number_offset";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql, $sql_param);
|
||||||
|
$rows = $query->result_array();
|
||||||
|
if($rows){
|
||||||
|
foreach($rows as $k => $v){
|
||||||
|
$s_payment = $this->db_onedev->query("SELECT GROUP_CONCAT(SupplierPaymentNumber SEPARATOR ', ') as SupplierPaymentNumber,
|
||||||
|
SUM(IFNULL(SupplierPaymentAmount,0)) as SupplierPaymentAmount,
|
||||||
|
IFNULL(SupplierPaymentID,0) SupplierPaymentID,
|
||||||
|
GROUP_CONCAT(DATE_FORMAT(SupplierPaymentDate,'%d-%m-%Y') SEPARATOR ', ') as SupplierPaymentDate
|
||||||
|
FROM supplier_payment
|
||||||
|
WHERE SupplierPaymentIsActive = 'Y' AND SupplierPaymentSupplierInvoiceID = {$v['SupplierInvoiceID']}")->row();
|
||||||
|
|
||||||
|
$s_jurnal = $this->db_onedev->query("SELECT SUM(jurnalTxCredit) totalbill
|
||||||
|
FROM supplier_invoice
|
||||||
|
JOIN jurnal_addon ON jurnalAddOnValue = SupplierInvoiceNumber
|
||||||
|
JOIN jurnal_tx ON jurnalTxJurnalID = jurnalAddOnJurnalID AND jurnalTxCredit <> 0 AND jurnalTxCoaID <> 563
|
||||||
|
WHERE SupplierInvoiceID = {$v['SupplierInvoiceID']}
|
||||||
|
GROUP BY SupplierInvoiceID")->row();
|
||||||
|
$amount = $s_payment->SupplierPaymentAmount ? $s_payment->SupplierPaymentAmount : "0.00";
|
||||||
|
$unpaid = (float)$s_jurnal->totalbill - (float)$amount;
|
||||||
|
$rows[$k]['SupplierPaymentID'] = $s_payment->SupplierPaymentID ? $s_payment->SupplierPaymentID : '0';
|
||||||
|
$rows[$k]['SupplierPaymentNumber'] = $s_payment->SupplierPaymentNumber ? $s_payment->SupplierPaymentNumber : '';
|
||||||
|
$rows[$k]['SupplierPaymentAmount'] = $amount;
|
||||||
|
$rows[$k]['SupplierPaymentDate'] = $s_payment->SupplierPaymentDate;
|
||||||
|
$rows[$k]['paid'] = $amount;
|
||||||
|
$rows[$k]['totalbill'] = $s_jurnal->totalbill ? $s_jurnal->totalbill : "0.00";
|
||||||
|
$rows[$k]['unpaid'] = number_format($unpaid, 2, '.', '');
|
||||||
|
|
||||||
|
$rows[$k]['notes'] = $this->add_notes($v['SupplierInvoiceID']);
|
||||||
|
$rows[$k]['tagihans'] = $this->add_tagihans($v['SupplierInvoiceID']);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
982
application/controllers/mockup/supplierpaymentv4/Payment.php
Normal file
982
application/controllers/mockup/supplierpaymentv4/Payment.php
Normal file
@@ -0,0 +1,982 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Payment extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_smartone;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "API";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lookup_type()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$query = "SELECT coaID as id,
|
||||||
|
coaCode as code,
|
||||||
|
'N' as chex,
|
||||||
|
coaDescription as chexlabel,
|
||||||
|
'Jumlah' as leftlabel,
|
||||||
|
'' as selected_card,
|
||||||
|
'' as selected_edc,
|
||||||
|
'' as selected_account,
|
||||||
|
CASE
|
||||||
|
WHEN coaCode = 'CASH' THEN 'Kembali'
|
||||||
|
WHEN coaCode = 'DEBIT' THEN 'Nomor Kartu'
|
||||||
|
WHEN coaCode = 'CREDIT' THEN 'Nomor Kartu'
|
||||||
|
WHEN coaCode = 'TRANSFER' THEN 'No. Rekening'
|
||||||
|
ELSE 'Nomor Voucher'
|
||||||
|
END as rightlabel,
|
||||||
|
0 as leftvalue,
|
||||||
|
0 as rightvalue
|
||||||
|
FROM m_paymenttype WHERE coaIsActive = 'Y'";
|
||||||
|
$rows = $this->db_onedev->query($query)->result_array();
|
||||||
|
foreach($rows as $k => $v){
|
||||||
|
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
|
||||||
|
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
|
||||||
|
$rows[$k]['selected_account'] = array('id'=>0,'name'=>'');
|
||||||
|
if($v['chex'] == 'N')
|
||||||
|
$rows[$k]['chex'] = false;
|
||||||
|
else
|
||||||
|
$rows[$k]['chex'] = true;
|
||||||
|
}
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function selectpaymenttypeold(){
|
||||||
|
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query ="SELECT * FROM m_paymenttype
|
||||||
|
WHERE
|
||||||
|
coaIsActive = 'Y'";
|
||||||
|
//echo $query;
|
||||||
|
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function selectpaymenttype(){
|
||||||
|
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$regionalid = $this->sys_user['S_RegionalID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = $prm["search"];
|
||||||
|
$query ="SELECT coaID,
|
||||||
|
coaAccountNo,
|
||||||
|
coaDescription,
|
||||||
|
coaSubDescription
|
||||||
|
FROM coa
|
||||||
|
JOIN s_regional ON S_RegionalID = $regionalid
|
||||||
|
JOIN m_branch ON M_BranchS_RegionalID = S_RegionalID
|
||||||
|
JOIN map_bank_coa ON MapBank_CoaID = coaID AND MapBank_BranchCode = M_BranchCode
|
||||||
|
WHERE
|
||||||
|
coaIsActive = 'Y' AND
|
||||||
|
coaIsInput = 'Y' AND
|
||||||
|
coaAccountNo LIKE '111%' AND
|
||||||
|
coaAccountNo LIKE '11102%' AND
|
||||||
|
coaDescription LIKE '%{$search}%'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
SELECT coaID,
|
||||||
|
coaAccountNo,
|
||||||
|
coaDescription,
|
||||||
|
coaSubDescription
|
||||||
|
FROM coa
|
||||||
|
WHERE
|
||||||
|
coaIsActive = 'Y' AND
|
||||||
|
coaIsInput = 'Y' AND
|
||||||
|
coaAccountNo LIKE '111%' AND
|
||||||
|
coaAccountNo NOT LIKE '11102%' AND
|
||||||
|
coaDescription LIKE '%{$search}%'
|
||||||
|
ORDER BY coaAccountNo ASC";
|
||||||
|
//echo $query;
|
||||||
|
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function selectbank(){
|
||||||
|
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query =" SELECT *
|
||||||
|
FROM nat_bank
|
||||||
|
WHERE
|
||||||
|
Nat_BankIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankCode DESC
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['banks'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function selectaccount(){
|
||||||
|
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
|
||||||
|
FROM m_bank_account
|
||||||
|
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
|
||||||
|
WHERE
|
||||||
|
M_BankAccountIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankCode DESC";
|
||||||
|
//echo $query;
|
||||||
|
$rows['accounts'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function lookup_banks()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
|
||||||
|
FROM nat_bank
|
||||||
|
WHERE
|
||||||
|
Nat_BankIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankCode DESC";
|
||||||
|
$rows = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lookup_accounts()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
|
||||||
|
FROM m_bank_account
|
||||||
|
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
|
||||||
|
WHERE
|
||||||
|
M_BankAccountIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankCode DESC";
|
||||||
|
$rows = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function searchcard(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count =0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '')
|
||||||
|
{
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
if($prm['search'] != ''){
|
||||||
|
$sql = "
|
||||||
|
SELECT count(*) as total
|
||||||
|
FROM nat_bank
|
||||||
|
WHERE
|
||||||
|
Nat_BankName like ?
|
||||||
|
AND Nat_BankIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankName DESC
|
||||||
|
";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$sql = "
|
||||||
|
SELECT count(*) as total
|
||||||
|
FROM nat_bank
|
||||||
|
WHERE
|
||||||
|
Nat_BankIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankName DESC
|
||||||
|
";
|
||||||
|
}
|
||||||
|
$query = $this->db_onedev->query($sql,$q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if($prm['search'] != ''){
|
||||||
|
$sql = "
|
||||||
|
SELECT Nat_BankID as id, Nat_BankName as name
|
||||||
|
FROM nat_bank
|
||||||
|
WHERE
|
||||||
|
Nat_BankName like ?
|
||||||
|
AND Nat_BankIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankName DESC
|
||||||
|
";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$sql = "
|
||||||
|
SELECT Nat_BankID as id, Nat_BankName as name
|
||||||
|
FROM nat_bank
|
||||||
|
WHERE
|
||||||
|
Nat_BankIsActive = 'Y'
|
||||||
|
ORDER BY Nat_BankName DESC
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("m_city rows",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function pay()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$xuserid = $this->sys_user['M_UserID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$orderid = $prm['orderid'];
|
||||||
|
$payments = $prm['payments'];
|
||||||
|
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
|
||||||
|
$sql = "INSERT INTO supplier_payment
|
||||||
|
(SupplierPaymentSupplierInvoiceID,SupplierPaymentDate,SupplierPaymentCreated,SupplierPaymentUserID)
|
||||||
|
VALUES (?,CURDATE(),NOW(),?)";
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$orderid, $xuserid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment insert");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$headerid = $this->db_onedev->insert_id();
|
||||||
|
//echo $headerid;
|
||||||
|
|
||||||
|
foreach($payments as $k => $v){
|
||||||
|
if($v['chex']){
|
||||||
|
$actual = 0;
|
||||||
|
$change = 0;
|
||||||
|
$amount = $v['leftvalue'];
|
||||||
|
if($v['code'] == 'CASH'){
|
||||||
|
$actual = $v['leftvalue'];
|
||||||
|
$change = $v['rightvalue'];
|
||||||
|
if($actual > 0){
|
||||||
|
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$amount = $actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "CALL `sp_bill_payment_add_cash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment_detail cash insert");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(intval($v['leftvalue']) > 0){
|
||||||
|
$actual = 0;
|
||||||
|
$change = 0;
|
||||||
|
$amount = $v['leftvalue'];
|
||||||
|
$selected_card = 0;
|
||||||
|
$selected_edc = 0;
|
||||||
|
$selected_account = 0;
|
||||||
|
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
|
||||||
|
$selected_card = $v['selected_card']['id'];
|
||||||
|
$selected_edc = $v['selected_edc']['id'];
|
||||||
|
$selected_account = $v['selected_account']['id'];
|
||||||
|
}
|
||||||
|
$sql = "CALL `sp_bill_payment_add_noncash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")";
|
||||||
|
//echo $sql;
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment_detail non cash insert");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "SELECT coaID as id,
|
||||||
|
coaCode as code,
|
||||||
|
IF(coaCode = 'CASH','Y','N') as chex,
|
||||||
|
coaDescription as chexlabel,
|
||||||
|
'Jumlah' as leftlabel,
|
||||||
|
CASE
|
||||||
|
WHEN coaCode = 'CASH' THEN 'Kembali'
|
||||||
|
WHEN coaCode = 'DEBIT' THEN 'Nomor Kartu'
|
||||||
|
WHEN coaCode = 'CREDIT' THEN 'Nomor Kartu'
|
||||||
|
WHEN coaCode = 'TRANSFER' THEN 'Nomor Rekening'
|
||||||
|
ELSE 'Nomor Voucher'
|
||||||
|
END as rightlabel,
|
||||||
|
0 as leftvalue,
|
||||||
|
0 as rightvalue
|
||||||
|
FROM m_paymenttype WHERE coaIsActive = 'Y'";
|
||||||
|
$rows = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
foreach($rows as $k => $v){
|
||||||
|
if($v['chex'] == 'N')
|
||||||
|
$rows[$k]['chex'] = false;
|
||||||
|
else
|
||||||
|
$rows[$k]['chex'] = true;
|
||||||
|
}
|
||||||
|
$xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row();
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => array('types'=>$rows,'data'=>$xdata)
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function paymanual()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$xuserid = $this->sys_user['M_UserID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$orderid = $prm['orderid'];
|
||||||
|
$amount = $prm['amount'];
|
||||||
|
$paymenttype = $prm['paymenttype'];
|
||||||
|
$tanggalbayar = date('Y-m-d', strtotime($prm['tanggalbayar']));
|
||||||
|
|
||||||
|
$totalbill = $prm['totalbill'];
|
||||||
|
$paid = $prm['paid'];
|
||||||
|
|
||||||
|
$keterangan = $prm['keterangan'];
|
||||||
|
$bills = $prm['bills'];
|
||||||
|
$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PINV') as numberx")->row()->numberx;
|
||||||
|
$sql = "INSERT INTO supplier_payment
|
||||||
|
(SupplierPaymentSupplierInvoiceID,
|
||||||
|
SupplierPaymentNumber,
|
||||||
|
SupplierPaymentDate,
|
||||||
|
SupplierPaymentAmount,
|
||||||
|
SupplierPaymentCoaID,
|
||||||
|
SupplierPaymentNote,
|
||||||
|
SupplierPaymentCreated,
|
||||||
|
SupplierPaymentUserID)
|
||||||
|
VALUES (?,
|
||||||
|
?,
|
||||||
|
CURDATE(),
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
NOW(),
|
||||||
|
?)";
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$orderid,
|
||||||
|
$xnumber,
|
||||||
|
$amount,
|
||||||
|
$paymenttype,
|
||||||
|
$keterangan,
|
||||||
|
$xuserid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$headerid = $this->db_onedev->insert_id();
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment insert");
|
||||||
|
exit;
|
||||||
|
} else{
|
||||||
|
$sqlbill = "UPDATE supplier_invoice SET
|
||||||
|
SupplierInvoiceDraftPaymentDate = '{$tanggalbayar}'
|
||||||
|
WHERE SupplierInvoiceID = $orderid";
|
||||||
|
$querybill = $this->db_onedev->query($sqlbill);
|
||||||
|
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//echo $headerid;
|
||||||
|
|
||||||
|
foreach($bills as $k => $v){
|
||||||
|
if($v['tagihan_bayar'] > 0){
|
||||||
|
$SupplierInvoiceDetailID = $v['SupplierInvoiceDetailID'];
|
||||||
|
$tagihan_bayar = $v['tagihan_bayar'];
|
||||||
|
$SupplierInvoiceDetailPurchaseOrderID = $v['SupplierInvoiceDetailPurchaseOrderID'];
|
||||||
|
$sql = "INSERT INTO supplier_payment_detail(
|
||||||
|
SupplierPaymentDetailSupplierPaymentID,
|
||||||
|
SupplierPaymentDetailSupplierInvoiceDetailID,
|
||||||
|
SupplierPaymentDetailAmount,
|
||||||
|
SupplierPaymentDetailUserID,
|
||||||
|
SupplierPaymentDetailCreated,
|
||||||
|
SupplierPaymentDetailLastUpdated)
|
||||||
|
VALUES(
|
||||||
|
$headerid,
|
||||||
|
$SupplierInvoiceDetailID,
|
||||||
|
$tagihan_bayar,
|
||||||
|
$xuserid,
|
||||||
|
now(),
|
||||||
|
now())";
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
$billpaymentdetailid = $this->db_onedev->insert_id();
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment_detail cash insert");
|
||||||
|
exit;
|
||||||
|
}else{
|
||||||
|
$sqlbilldetail = "UPDATE supplier_invoice_detail SET
|
||||||
|
SupplierInvoiceDetailUnpaid = SupplierInvoiceDetailUnpaid - $tagihan_bayar
|
||||||
|
WHERE SupplierInvoiceDetailID = $SupplierInvoiceDetailID";
|
||||||
|
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
|
||||||
|
|
||||||
|
/* $sqlpayment = "INSERT INTO f_payment
|
||||||
|
(F_PaymentPurchaseOrderID,
|
||||||
|
F_PaymentDate,
|
||||||
|
F_PaymentTotal,
|
||||||
|
F_PaymentCreated,
|
||||||
|
F_PaymentLastUpdated,
|
||||||
|
F_PaymentM_UserID)
|
||||||
|
VALUES(
|
||||||
|
$SupplierInvoiceDetailPurchaseOrderID,
|
||||||
|
now(),
|
||||||
|
$tagihan_bayar,
|
||||||
|
now(),
|
||||||
|
now(),
|
||||||
|
$xuserid)";
|
||||||
|
$querypayment = $this->db_onedev->query($sqlpayment);
|
||||||
|
$paymentid = $this->db_onedev->insert_id();
|
||||||
|
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
|
||||||
|
(F_PaymentDetailF_PaymentID,
|
||||||
|
F_PaymentDetailcoaID,
|
||||||
|
F_PaymentDetailAmount,
|
||||||
|
F_PaymentDetailActual,
|
||||||
|
F_PaymentDetailChange,
|
||||||
|
F_PaymentDetailEDCNat_BankID,
|
||||||
|
F_PaymentDetailCardNat_BankID,
|
||||||
|
F_PaymentDetailM_BankAccountID,
|
||||||
|
F_PaymentDetailCreated,
|
||||||
|
F_PaymentDetailLastUpdated,
|
||||||
|
F_PaymentDetailUserID)
|
||||||
|
VALUES(
|
||||||
|
$paymentid,
|
||||||
|
$paymenttype,
|
||||||
|
$tagihan_bayar,
|
||||||
|
$tagihan_bayar,
|
||||||
|
0,
|
||||||
|
$edc,
|
||||||
|
$card,
|
||||||
|
$account,
|
||||||
|
now(),
|
||||||
|
now(),
|
||||||
|
$xuserid)";
|
||||||
|
//echo $sqlpaymentdetail;
|
||||||
|
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
|
||||||
|
|
||||||
|
$sqleditbillpaymentdetail = "UPDATE supplier_payment_detail SET
|
||||||
|
SupplierPaymentDetailF_PaymentID = $paymentid
|
||||||
|
WHERE SupplierPaymentDetailID = $billpaymentdetailid";
|
||||||
|
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sql = "SELECT * FROM supplier_payment
|
||||||
|
JOIN m_user ON M_UserID = SupplierPaymentUserID
|
||||||
|
WHERE SupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$row = $query->row_array();
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM supplier_payment_detail
|
||||||
|
WHERE SupplierPaymentDetailSupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$rows = $query->row_array();
|
||||||
|
|
||||||
|
$data = array("header" => $row,
|
||||||
|
"details" => $rows);
|
||||||
|
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." berhasil dibuat oleh " . $row["M_UserUsername"];
|
||||||
|
$this->insert_act_log("PF", "NEW", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
|
||||||
|
|
||||||
|
$xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row();
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => array('data'=>$xdata)
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function editpaymanual()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$xuserid = $this->sys_user['M_UserID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$orderid = $prm['orderid'];
|
||||||
|
$headerid = $prm['headerid'];
|
||||||
|
$tanggalbayar = date('Y-m-d', strtotime($prm['tanggalbayar']));
|
||||||
|
$sqlbill = "UPDATE supplier_invoice SET
|
||||||
|
SupplierInvoiceDraftPaymentDate = '{$tanggalbayar}'
|
||||||
|
WHERE SupplierInvoiceID = $orderid";
|
||||||
|
$querybill = $this->db_onedev->query($sqlbill);
|
||||||
|
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM supplier_payment
|
||||||
|
JOIN supplier_invoice ON SupplierInvoiceID = SupplierPaymentSupplierInvoiceID
|
||||||
|
JOIN m_user ON M_UserID = SupplierPaymentUserID
|
||||||
|
WHERE SupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$row = $query->row_array();
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM supplier_payment_detail
|
||||||
|
WHERE SupplierPaymentDetailSupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$rows = $query->row_array();
|
||||||
|
|
||||||
|
$data = array("header" => $row,
|
||||||
|
"details" => $rows);
|
||||||
|
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." berhasil diubah oleh " . $row["M_UserUsername"];
|
||||||
|
$this->insert_act_log("PF", "NEW", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
|
||||||
|
|
||||||
|
$xdata = $this->db_onedev->query("SELECT SupplierPaymentID as idx, SupplierPaymentNumber as numberx FROM supplier_payment WHERE SupplierPaymentID = {$headerid}")->row();
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => array('data'=>$xdata)
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function delete_note()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$xuserid = $this->sys_user['M_UserID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$prmnota = $prm['nota'];
|
||||||
|
|
||||||
|
$headerid = $prmnota['note_id'];
|
||||||
|
$sql = "SELECT * FROM supplier_payment
|
||||||
|
JOIN m_user ON M_UserID = SupplierPaymentUserID
|
||||||
|
WHERE SupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$row = $query->row_array();
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM supplier_payment_detail
|
||||||
|
WHERE SupplierPaymentDetailSupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$headerid]);
|
||||||
|
$rows = $query->row_array();
|
||||||
|
|
||||||
|
$data = array("header" => $row,
|
||||||
|
"details" => $rows);
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_payment
|
||||||
|
SET SupplierPaymentIsActive = 'N'
|
||||||
|
WHERE SupplierPaymentID = {$prmnota['note_id']}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_payment_detail
|
||||||
|
SET SupplierPaymentDetailIsActive = 'N'
|
||||||
|
WHERE SupplierPaymentDetailSupplierPaymentID = {$prmnota['note_id']}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment_detail delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_invoice
|
||||||
|
SET SupplierInvoiceUnpaid = SupplierInvoiceUnpaid + CAST({$prmnota['note_amount']} AS UNSIGNED)
|
||||||
|
WHERE SupplierInvoiceID = {$prmnota['note_order_id']}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_invoice delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_invoice_detail
|
||||||
|
SET SupplierInvoiceDetailUnpaid = SupplierInvoiceDetailUnpaid + CAST({$prmnota['note_amount']} AS UNSIGNED)
|
||||||
|
WHERE SupplierInvoiceDetailID = {$prmnota['detail_id']}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_invoice_detail delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = "Nomor Pembayaran Faktur: " . $row["SupplierPaymentNumber"] ." telah dihapus oleh " . $row["M_UserUsername"];
|
||||||
|
$this->insert_act_log("PF", "DELETE", $message, $headerid, $this->safeJsonEncode($data), $xuserid);
|
||||||
|
$result = array(
|
||||||
|
"total" => 1 ,
|
||||||
|
"records" => array('prm'=>$prm)
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function edit_note()
|
||||||
|
{
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$xuserid = $this->sys_user['M_UserID'];
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id = $prm['id'];
|
||||||
|
$inv_id = $prm['inv_id'];
|
||||||
|
$detail_id = $prm['detail_id'];
|
||||||
|
$paymenttype = $prm['paymenttype'];
|
||||||
|
$amount_old = $prm['amount_old'];
|
||||||
|
$amount_new = $prm['amount_new'];
|
||||||
|
$keterangan = $prm['keterangan'];
|
||||||
|
|
||||||
|
$datas_log = [];
|
||||||
|
$messages_log = [];
|
||||||
|
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM supplier_payment
|
||||||
|
WHERE SupplierPaymentID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql, [$id]);
|
||||||
|
if (!$query) {
|
||||||
|
$this->db_onedev->trans_rollback();
|
||||||
|
$this->sys_error_db("supplier payment", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$row = $query->row_array();
|
||||||
|
|
||||||
|
if($row["SupplierPaymentAmount"]!= $amount_new) {
|
||||||
|
$messages_log[] = "Perubahan pembayaran : " . $row["SupplierPaymentAmount"] . " menjadi " . $amount_new;
|
||||||
|
}
|
||||||
|
if($row["SupplierPaymentNote"]!= $keterangan) {
|
||||||
|
$messages_log[] = "Perubahan keterangan : " . $row["SupplierPaymentNote"] . " menjadi " . $keterangan;
|
||||||
|
}
|
||||||
|
if($row["SupplierPaymentCoaID"]!= $paymenttype) {
|
||||||
|
$messages_log[] = "Perubahan tipe pembayaran id : " . $row["SupplierPaymentCoaID"] . " menjadi " . $paymenttype;
|
||||||
|
}
|
||||||
|
|
||||||
|
$datas_log['header'] = $row;
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_payment SET
|
||||||
|
SupplierPaymentAmount = {$amount_new},
|
||||||
|
SupplierPaymentNote = '{$keterangan}',
|
||||||
|
SupplierPaymentCoaID = {$paymenttype},
|
||||||
|
SupplierPaymentUserID = {$xuserid}
|
||||||
|
WHERE SupplierPaymentID = {$id}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment edit");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_payment_detail
|
||||||
|
SET SupplierPaymentDetailAmount = {$amount_new},
|
||||||
|
SupplierPaymentDetailUserID = {$xuserid}
|
||||||
|
WHERE SupplierPaymentDetailSupplierPaymentID = {$id}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_payment_detail edit");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_invoice
|
||||||
|
SET SupplierInvoiceUnpaid = (SupplierInvoiceUnpaid + $amount_old) - {$amount_new}
|
||||||
|
WHERE SupplierInvoiceID = {$inv_id}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_invoice edit");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE supplier_invoice_detail
|
||||||
|
SET SupplierInvoiceDetailUnpaid = (SupplierInvoiceDetailUnpaid + $amount_old) - {$amount_new}
|
||||||
|
WHERE SupplierInvoiceDetailID = {$detail_id}";
|
||||||
|
//echo $sql;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("supplier_invoice_detail edit");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if(count($messages_log) > 0) {
|
||||||
|
$message = "Perubahan Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . "\n";
|
||||||
|
$message .= implode("\n", $messages_log);
|
||||||
|
}else{
|
||||||
|
$message = "Pembayaran Faktur: " . $row["SupplierPaymentNumber"] . " tanpa perubahan";
|
||||||
|
}
|
||||||
|
|
||||||
|
$datas_log = $this->convertNumericValuesToStrings($datas_log);
|
||||||
|
$this->insert_act_log("PF", "EDIT", $message, $id, $this->safeJsonEncode($datas_log), $xuserid);
|
||||||
|
$result = array(
|
||||||
|
"total" => 1 ,
|
||||||
|
"records" => array('prm'=>$prm)
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
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_onedev->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_onedev);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1014
application/controllers/mockup/usergroup/Usergroupv6.php
Normal file
1014
application/controllers/mockup/usergroup/Usergroupv6.php
Normal file
File diff suppressed because it is too large
Load Diff
650
application/controllers/v1/report-usergroup/Usergroup.php
Normal file
650
application/controllers/v1/report-usergroup/Usergroup.php
Normal file
@@ -0,0 +1,650 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Usergroup extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "USER GROUP REPORT API";
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_onedev = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lookupuserbyname(){
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$groupname = $prm['groupname'];
|
||||||
|
$filter = '';
|
||||||
|
if(isset($sexid)){
|
||||||
|
$filter .= "AND ($sexid = 0 or ($sexid > 0 and Nat_SexID = $sexid)) ";
|
||||||
|
}
|
||||||
|
if(isset($flagid)){
|
||||||
|
$filter .= "AND ($flagid = 0 or ($flagid > 0 and Nat_FlagID = $flagid))";
|
||||||
|
}
|
||||||
|
$limit = '';
|
||||||
|
if($all == 'N'){
|
||||||
|
$limit = ' LIMIT 10';
|
||||||
|
}
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||||
|
$sql = "select COUNT(*) as total
|
||||||
|
FROM(SELECT *
|
||||||
|
from m_usergroup
|
||||||
|
WHERE
|
||||||
|
M_UserGroupIsActive = 'Y' AND
|
||||||
|
M_UserGroupName like '%{$groupname}%'
|
||||||
|
$filter GROUP BY M_UserGroupID) a";
|
||||||
|
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$tot_count = 0;
|
||||||
|
$tot_page = 0;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
$tot_page = ceil($tot_count/$number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_usergroup count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT m_usergroup.*,
|
||||||
|
M_UserGroupID as id,
|
||||||
|
M_UserGroupID,
|
||||||
|
M_UserGroupName
|
||||||
|
FROM m_usergroup
|
||||||
|
WHERE
|
||||||
|
M_UserGroupIsActive = 'Y' AND
|
||||||
|
M_UserGroupName like '%{$groupname}%'
|
||||||
|
$filter
|
||||||
|
GROUP BY M_UserGroupID
|
||||||
|
ORDER BY M_UserGroupName ASC
|
||||||
|
limit $number_limit offset $number_offset";
|
||||||
|
$sql_param = array($search);
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
// echo $this->db_onedev->last_query();
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("m_usergroup select");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function lookupreportbyid(){
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id = $prm['id'];
|
||||||
|
$reportgroup = $prm['reportgroup'];
|
||||||
|
$reportcode = $prm['reportcode'];
|
||||||
|
$reportname = $prm['reportname'];
|
||||||
|
$status = $prm['status'];
|
||||||
|
$all = $prm['all'];
|
||||||
|
$filter = '';
|
||||||
|
if($status != 'A'){
|
||||||
|
$filter .= "AND status = '{$status}' ";
|
||||||
|
}else{
|
||||||
|
$filter .= "";
|
||||||
|
}
|
||||||
|
$limit = '';
|
||||||
|
if($all == 'N'){
|
||||||
|
$limit = ' LIMIT 10';
|
||||||
|
}
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||||
|
$sql = "select COUNT(*) as total
|
||||||
|
FROM(SELECT *, IF(IFNULL(UserGroupReportID,0) > 0 , 'Y', 'N') as status
|
||||||
|
from r_report
|
||||||
|
LEFT JOIN usergroup_report ON R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $id AND UserGroupReportIsActive = 'Y'
|
||||||
|
LEFT JOIN m_usergroup ON UserGroupReportM_UserGroupID = M_UserGroupID AND M_UserGroupIsActive = 'Y'
|
||||||
|
LEFT JOIN r_reportgroup ON R_ReportR_ReportGroupID = R_ReportGroupID
|
||||||
|
WHERE
|
||||||
|
R_ReportIsActive = 'Y') a
|
||||||
|
WHERE
|
||||||
|
R_ReportGroupName like '%{$reportgroup}%' AND
|
||||||
|
R_ReportCode like '%{$reportcode}%' AND
|
||||||
|
R_ReportName like '%{$reportname}%' $filter";
|
||||||
|
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$tot_count = 0;
|
||||||
|
$tot_page = 0;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
$tot_page = ceil($tot_count/$number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("r_report count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM(select R_ReportID as id,
|
||||||
|
R_ReportID,
|
||||||
|
R_ReportCode,
|
||||||
|
R_ReportName,
|
||||||
|
R_ReportGroupName,
|
||||||
|
UserGroupReportID,
|
||||||
|
UserGroupReportM_UserGroupID,
|
||||||
|
UserGroupReportR_ReportID,
|
||||||
|
IF(IFNULL(UserGroupReportID,0) > 0 , 'Y', 'N') as status
|
||||||
|
from r_report
|
||||||
|
LEFT JOIN usergroup_report ON R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $id AND UserGroupReportIsActive = 'Y'
|
||||||
|
LEFT JOIN m_usergroup ON UserGroupReportM_UserGroupID = M_UserGroupID AND M_UserGroupIsActive = 'Y'
|
||||||
|
LEFT JOIN r_reportgroup ON R_ReportR_ReportGroupID = R_ReportGroupID
|
||||||
|
WHERE
|
||||||
|
R_ReportIsActive = 'Y') a
|
||||||
|
WHERE
|
||||||
|
R_ReportGroupName like '%{$reportgroup}%' AND
|
||||||
|
R_ReportCode like '%{$reportcode}%' AND
|
||||||
|
R_ReportName like '%{$reportname}%' $filter
|
||||||
|
GROUP BY R_ReportID
|
||||||
|
ORDER BY R_ReportGroupName ASC, R_ReportName ASC
|
||||||
|
limit $number_limit offset $number_offset";
|
||||||
|
$sql_param = array($search);
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("r_report select");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getsexreg(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
$query ="
|
||||||
|
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
|
||||||
|
UNION
|
||||||
|
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
|
||||||
|
UNION
|
||||||
|
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function getstatus(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
$query ="
|
||||||
|
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
|
||||||
|
UNION
|
||||||
|
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
|
||||||
|
UNION
|
||||||
|
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
|
||||||
|
";
|
||||||
|
//echo $query;
|
||||||
|
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"total" => count($rows) ,
|
||||||
|
"records" => $rows,
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
public function addnewreport()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$userid = $prm['userid'];
|
||||||
|
$reportcode = $prm['reportcode'];
|
||||||
|
$reportname = $prm['reportname'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
|
||||||
|
$sql = "insert into r_report(
|
||||||
|
R_ReportCode,
|
||||||
|
R_ReportName,
|
||||||
|
R_ReportUserID,
|
||||||
|
R_ReportCreated,
|
||||||
|
R_ReportLastUpdated
|
||||||
|
)
|
||||||
|
values(?,?,?,now(),now())";
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$reportcode,
|
||||||
|
$reportname,
|
||||||
|
$userid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("m_usergroup insert",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$last_id = $this->db_onedev->insert_id();
|
||||||
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function saveaddeditreport()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$usergroupid = $prm['userid'];
|
||||||
|
$reportid = $prm['R_ReportID'];
|
||||||
|
$reportuserid = $prm['UserGroupReportID'];
|
||||||
|
$status = $prm['status'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
if($status == 'Y'){
|
||||||
|
$sql = "insert into usergroup_report(
|
||||||
|
UserGroupReportM_UserGroupID,
|
||||||
|
UserGroupReportR_ReportID,
|
||||||
|
UserGroupUserID,
|
||||||
|
UserGroupReportCreated,
|
||||||
|
UserGroupReportLastUpdated
|
||||||
|
)
|
||||||
|
values(?,?,?,now(),now())";
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$usergroupid,
|
||||||
|
$reportid,
|
||||||
|
$userid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("usergroup_report insert",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$last_id = $this->db_onedev->insert_id();
|
||||||
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$sql = "UPDATE usergroup_report SET
|
||||||
|
UserGroupReportIsActive = 'N',
|
||||||
|
UserGroupUserID = ?,
|
||||||
|
UserGroupReportCreated = now(),
|
||||||
|
UserGroupReportLastUpdated = now()
|
||||||
|
WHERE UserGroupReportID = ?";
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$userid,
|
||||||
|
$reportuserid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("usergroup_report insert",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$last_id = $this->db_onedev->insert_id();
|
||||||
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function saveallreport(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$details = $prm['details'];
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
foreach($details as $k => $v){
|
||||||
|
$query = "UPDATE usergroup_report SET
|
||||||
|
UserGroupReportM_UserGroupID = '{$v['UserGroupReportM_UserGroupID']}',
|
||||||
|
UserGroupReportAdviceIna = '{$v['UserGroupReportAdviceIna']}',
|
||||||
|
UserGroupReportAdviceEng = '{$v['UserGroupReportAdviceEng']}',
|
||||||
|
UserGroupReportUserID = {$userid},
|
||||||
|
UserGroupReportCreated = now(),
|
||||||
|
UserGroupReportLastUpdated = now()
|
||||||
|
WHERE UserGroupReportID = {$v['UserGroupReportID']}";
|
||||||
|
|
||||||
|
//echo $query;
|
||||||
|
$action = $this->db_onedev->query($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($action){
|
||||||
|
$result = array(
|
||||||
|
"total" => 1 ,
|
||||||
|
"records" => array(),
|
||||||
|
);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public function deleteuser()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$sql = "update nat_methode SET
|
||||||
|
Nat_MethodeIsActive = 'N'
|
||||||
|
WHERE
|
||||||
|
Nat_MethodeID = ?
|
||||||
|
|
||||||
|
";
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$prm['id']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// echo $query;
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("nat_methode delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sql = "update m_usergroup SET
|
||||||
|
M_UserGroupIsActive = 'N'
|
||||||
|
WHERE
|
||||||
|
M_UserGroupNat_MethodeID = ?
|
||||||
|
|
||||||
|
";
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$prm['id']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// echo $query;
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("m_usergroup delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function deletereport()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//# ambil parameter input
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$sql = "update m_usergroup SET
|
||||||
|
M_UserGroupIsActive = 'N'
|
||||||
|
WHERE
|
||||||
|
M_UserGroupID = ?
|
||||||
|
|
||||||
|
";
|
||||||
|
|
||||||
|
$query = $this->db_onedev->query($sql,
|
||||||
|
array(
|
||||||
|
$prm['id']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// echo $query;
|
||||||
|
if (!$query) {
|
||||||
|
$this->sys_error_db("m_usergroup delete");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchuser(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count =0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '')
|
||||||
|
{
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
$sql = "SELECT count(*) as total
|
||||||
|
FROM nat_methode
|
||||||
|
WHERE
|
||||||
|
Nat_MethodeName like ?
|
||||||
|
AND Nat_MethodeIsActive = 'Y'";
|
||||||
|
$query = $this->db_onedev->query($sql,$q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("nat_methode count",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT Nat_MethodeID, Nat_MethodeName
|
||||||
|
FROM nat_methode
|
||||||
|
WHERE
|
||||||
|
Nat_MethodeName like ?
|
||||||
|
AND Nat_MethodeIsActive = 'Y'
|
||||||
|
ORDER BY Nat_MethodeName ASC
|
||||||
|
";
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("nat_methode rows",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function searchuserbyname(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count =0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '')
|
||||||
|
{
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
$sql = "SELECT count(*) as total
|
||||||
|
FROM nat_methode
|
||||||
|
WHERE
|
||||||
|
Nat_MethodeName like ?
|
||||||
|
AND Nat_MethodeIsActive = 'Y'";
|
||||||
|
$query = $this->db_onedev->query($sql,$q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("nat_methode count",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT Nat_MethodeID, Nat_MethodeName
|
||||||
|
FROM nat_methode
|
||||||
|
WHERE
|
||||||
|
Nat_MethodeName like ?
|
||||||
|
AND Nat_MethodeIsActive = 'Y'
|
||||||
|
ORDER BY Nat_MethodeName ASC
|
||||||
|
";
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("nat_methode rows",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function searchtest(){
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
|
||||||
|
$max_rst = 12;
|
||||||
|
$tot_count =0;
|
||||||
|
|
||||||
|
$q = [
|
||||||
|
'search' => '%'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($prm['search'] != '')
|
||||||
|
{
|
||||||
|
$q['search'] = "%{$prm['search']}%";
|
||||||
|
}
|
||||||
|
|
||||||
|
// QUERY TOTAL
|
||||||
|
$sql = "SELECT count(*) as total
|
||||||
|
FROM t_test
|
||||||
|
WHERE
|
||||||
|
T_TestName like ?
|
||||||
|
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'";
|
||||||
|
$query = $this->db_onedev->query($sql,$q['search']);
|
||||||
|
//echo $query;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("t_test count",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT *
|
||||||
|
FROM t_test
|
||||||
|
WHERE
|
||||||
|
T_TestName like ?
|
||||||
|
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
|
||||||
|
ORDER BY T_TestName ASC
|
||||||
|
";
|
||||||
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||||
|
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||||
|
$this->sys_ok($result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->sys_error_db("t_test rows",$this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
application/controllers/v1/report-v9/Lookup.php
Normal file
43
application/controllers/v1/report-v9/Lookup.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
class Lookup extends MY_Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_smartone = $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dropdown($sp) {
|
||||||
|
$sql = "call $sp";
|
||||||
|
$qry = $this->db_smartone->query($sql);
|
||||||
|
if (! $qry) {
|
||||||
|
echo json_encode(array());
|
||||||
|
}
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
if (count($rows) == 0 ) {
|
||||||
|
echo json_encode(array());
|
||||||
|
}
|
||||||
|
echo json_encode($rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ac($sp) {
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = $prm['search'];
|
||||||
|
$sql = "call $sp(?)";
|
||||||
|
if (isset($prm['dep'])) {
|
||||||
|
$sql = "call $sp(?,?)";
|
||||||
|
$value = $prm['value'];
|
||||||
|
$qry = $this->db_smartone->query($sql,array($search,$value));
|
||||||
|
} else {
|
||||||
|
$qry = $this->db_smartone->query($sql,array($search));
|
||||||
|
}
|
||||||
|
if (! $qry) {
|
||||||
|
echo json_encode(array());
|
||||||
|
}
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
if (count($rows) == 0 ) {
|
||||||
|
echo json_encode(array());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
echo json_encode($rows);
|
||||||
|
}
|
||||||
|
}
|
||||||
185
application/controllers/v1/report-v9/Main.php
Normal file
185
application/controllers/v1/report-v9/Main.php
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Main extends MY_Controller
|
||||||
|
{
|
||||||
|
var $db_onedev;
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
echo "Report Main API";
|
||||||
|
}
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->db_one= $this->load->database("onedev", true);
|
||||||
|
}
|
||||||
|
function detail(){
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$id = $prm['id'];
|
||||||
|
$sql = "select *
|
||||||
|
from
|
||||||
|
r_reportdetail
|
||||||
|
join r_inputtype on R_ReportDetailR_InputTypeID = R_InputTypeID
|
||||||
|
and R_ReportDetailIsActive = 'Y'
|
||||||
|
where R_ReportDetailR_ReportID = ?
|
||||||
|
order by R_ReportDetailID, R_ReportDetailPriority desc";
|
||||||
|
|
||||||
|
// echo $sql;
|
||||||
|
$qry = $this->db_one->query($sql, array($id) );
|
||||||
|
$last_q = $this->db_one->last_query();
|
||||||
|
if ($qry) {
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
foreach($rows as $idx => $r) {
|
||||||
|
$rows[$idx]["model"] = "";
|
||||||
|
$rows[$idx]["items"] = "";
|
||||||
|
$rows[$idx]["tmp_date"] = false;
|
||||||
|
}
|
||||||
|
$result = array ("total" => count($rows), "records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} else {
|
||||||
|
$message = "Err Report Query";
|
||||||
|
$this->sys_error($message,$this->db_one);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function list(){
|
||||||
|
try {
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = $prm['search'];
|
||||||
|
$q_search = "where R_ReportIsActive = 'Y'";
|
||||||
|
$q_param = array();
|
||||||
|
if ($search !== "") {
|
||||||
|
$q_search = "where R_ReportIsActive = 'Y' and ( R_ReportCode like ? or R_ReportName like ? ) ";
|
||||||
|
$q_param[] = "%$search%";
|
||||||
|
$q_param[] = "%$search%";
|
||||||
|
}
|
||||||
|
$userid = $this->sys_user["M_UserID"];
|
||||||
|
$sqlusergroup = $this->db_onedev->query("SELECT M_UserM_UserGroupID FROM m_user
|
||||||
|
WHERE M_UserID = $userid")->row();
|
||||||
|
$usergroup = $sqlusergroup->M_UserM_UserGroupID;
|
||||||
|
$sql = "select
|
||||||
|
R_ReportGroupID, R_ReportGroupName, R_ReportGroupColor,
|
||||||
|
R_ReportID, R_ReportCode, R_ReportName, R_ReportUrl, R_ReportWithoutXls
|
||||||
|
from r_report
|
||||||
|
join r_reportgroup on R_ReportGroupID = R_ReportR_ReportGroupID
|
||||||
|
join usergroup_report on R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $usergroup
|
||||||
|
and UserGroupReportIsActive = 'Y'
|
||||||
|
$q_search ORDER BY R_ReportGroupName ASC, R_ReportCode ASC";
|
||||||
|
// echo $sql;
|
||||||
|
if ($q_search == "" ) {
|
||||||
|
$qry = $this->db_one->query($sql);
|
||||||
|
} else {
|
||||||
|
$qry = $this->db_one->query($sql,$q_param);
|
||||||
|
}
|
||||||
|
$last_q = $this->db_one->last_query();
|
||||||
|
if ($qry) {
|
||||||
|
$rows = $qry->result_array();
|
||||||
|
$reports = array();
|
||||||
|
$prev_group = 0;
|
||||||
|
$idx = -1;
|
||||||
|
foreach($rows as $r) {
|
||||||
|
if ($prev_group != $r["R_ReportGroupID"] ) {
|
||||||
|
$idx++;
|
||||||
|
$reports[] = array("id"=>$r["R_ReportGroupID"], "name" => $r["R_ReportGroupName"],
|
||||||
|
"color" => $r["R_ReportGroupColor"],
|
||||||
|
"reports" => array());
|
||||||
|
}
|
||||||
|
$prev_group = $r["R_ReportGroupID"];
|
||||||
|
$reports[$idx]["reports"][] = $r;
|
||||||
|
}
|
||||||
|
$result = array ("total" => count($reports), "records" => $reports);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
} else {
|
||||||
|
$message = "Err Report Query";
|
||||||
|
$this->sys_error($message,$this->db_one);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function lookupparam()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//# cek token valid
|
||||||
|
if (! $this->isLogin) {
|
||||||
|
$this->sys_error("Invalid Token");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prm = $this->sys_input;
|
||||||
|
$search = $prm['search'];
|
||||||
|
$limit = '';
|
||||||
|
if($all == 'N'){
|
||||||
|
$limit = ' LIMIT 10';
|
||||||
|
}
|
||||||
|
$number_limit = 10;
|
||||||
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||||
|
$sql = "select COUNT(*) as total
|
||||||
|
from r_reportparam
|
||||||
|
LEFT JOIN r_inputtype ON R_ReportParamR_InputTypeID = R_InputTypeID AND R_InputTypeIsActive = 'Y'
|
||||||
|
where
|
||||||
|
(R_ReportParamName LIKE CONCAT('%','{$search}','%') OR
|
||||||
|
IFNULL(R_InputTypeName,'') LIKE CONCAT('%','{$search}','%') OR
|
||||||
|
IFNULL(R_ReportParamLabel,'') LIKE CONCAT('%','{$search}','%')) AND
|
||||||
|
R_ReportParamIsActive = 'Y'";
|
||||||
|
$sql_param = array($search);
|
||||||
|
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
$tot_count = 0;
|
||||||
|
$tot_page = 0;
|
||||||
|
if ($query) {
|
||||||
|
$tot_count = $query->result_array()[0]["total"];
|
||||||
|
$tot_page = ceil($tot_count/$number_limit);
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("r_reportparam count", $this->db_onedev);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "select R_ReportParamID as id,
|
||||||
|
R_InputTypeName,
|
||||||
|
r_reportparam.*
|
||||||
|
from r_reportparam
|
||||||
|
LEFT JOIN r_inputtype ON R_ReportParamR_InputTypeID = R_InputTypeID AND R_InputTypeIsActive = 'Y'
|
||||||
|
where
|
||||||
|
(R_ReportParamName LIKE CONCAT('%','{$search}','%') OR
|
||||||
|
IFNULL(R_InputTypeName,'') LIKE CONCAT('%','{$search}','%') OR
|
||||||
|
IFNULL(R_ReportParamLabel,'') LIKE CONCAT('%','{$search}','%')) AND
|
||||||
|
R_ReportParamIsActive = 'Y'
|
||||||
|
GROUP BY R_ReportParamID
|
||||||
|
ORDER BY R_ReportParamName ASC
|
||||||
|
limit $number_limit offset $number_offset";
|
||||||
|
$sql_param = array($search);
|
||||||
|
$query = $this->db_onedev->query($sql);
|
||||||
|
//echo $this->db_onedev->last_query();
|
||||||
|
if ($query) {
|
||||||
|
$rows = $query->result_array();
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sys_error_db("r_reportparam select");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
||||||
|
$this->sys_ok($result);
|
||||||
|
|
||||||
|
} catch(Exception $exc) {
|
||||||
|
$message = $exc->getMessage();
|
||||||
|
$this->sys_error($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user