234 lines
9.1 KiB
PHP
234 lines
9.1 KiB
PHP
<?php
|
|
class Setupmapkelainan extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->db = $this->load->database("onedev", true);
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "CPONE MD PRICE API";
|
|
}
|
|
|
|
public function getsetup()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$page = $prm["page"];
|
|
$search = '%' . $prm['search'] . '%';
|
|
|
|
$ROW_PER_PAGE = 20;
|
|
$start_offset = 0;
|
|
// print_r($prm);
|
|
|
|
if (isset($prm["page"])) {
|
|
if (
|
|
is_numeric($prm["page"]) && $prm["page"] > 0
|
|
) {
|
|
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
|
}
|
|
}
|
|
$sql = "SELECT COUNT(Mgm_McuID) as total
|
|
FROM mgm_mcu
|
|
WHERE Mgm_McuIsActive = 'Y'
|
|
ORDER BY Mgm_McuStartDate ASC, Mgm_McuEndDate ASC";
|
|
$qry = $this->db->query($sql, []);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$total = $qry->row_array()['total'];
|
|
$sql = "SELECT *
|
|
FROM mgm_mcu
|
|
WHERE Mgm_McuIsActive = 'Y'
|
|
AND (Mgm_McuLabel LIKE ? OR Mgm_McuNumber LIKE ?)
|
|
ORDER BY Mgm_McuStartDate ASC, Mgm_McuEndDate ASC
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db->query($sql, [$search, $search, $ROW_PER_PAGE, $start_offset]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$data = $qry->result_array();
|
|
$result = [
|
|
"records" => $data,
|
|
"total" => ceil($total / $ROW_PER_PAGE),
|
|
];
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function getdetail()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$page = $prm["page"];
|
|
$setupid = $prm["setupid"];
|
|
$search = '%' . $prm['search'] . '%';
|
|
|
|
$ROW_PER_PAGE = 20;
|
|
$start_offset = 0;
|
|
// print_r($prm);
|
|
|
|
if (isset($prm["page"])) {
|
|
if (
|
|
is_numeric($prm["page"]) && $prm["page"] > 0
|
|
) {
|
|
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
|
}
|
|
}
|
|
$sql = "SELECT
|
|
COUNT(Mcu_KelainanGroupSummaryID) as total
|
|
FROM mcu_kelainangroupsummary
|
|
LEFT JOIN mcu_mapping_kelainangroupsummary
|
|
ON Mcu_KelainanGroupSummaryID = Mcu_Mapping_KeliananGroupSummaryMcu_KelainanGroupSummaryID
|
|
AND Mcu_Mapping_KeliananGroupSummaryIsActive = 'Y'
|
|
AND Mcu_Mapping_KeliananGroupSummaryMgm_McuID = ?
|
|
WHERE Mcu_KelainanGroupSummaryIsActive = 'Y'
|
|
AND Mcu_KelainanGroupSummaryName LIKE ?";
|
|
$qry = $this->db->query($sql, [$setupid, $search]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$total = $qry->row_array()['total'];
|
|
|
|
$sql = "SELECT
|
|
Mcu_KelainanGroupSummaryID as kelainanGroupSummaryID,
|
|
Mcu_KelainanGroupSummaryName as kelainanGroupSummaryName,
|
|
Mcu_Mapping_KeliananGroupSummaryID as mappingID,
|
|
CASE
|
|
WHEN Mcu_Mapping_KeliananGroupSummaryID IS NULL THEN 'N'
|
|
WHEN Mcu_Mapping_KeliananGroupSummaryID IS NOT NULL THEN 'Y'
|
|
ELSE 'N'
|
|
END as status
|
|
FROM mcu_kelainangroupsummary
|
|
LEFT JOIN mcu_mapping_kelainangroupsummary
|
|
ON Mcu_KelainanGroupSummaryID = Mcu_Mapping_KeliananGroupSummaryMcu_KelainanGroupSummaryID
|
|
AND Mcu_Mapping_KeliananGroupSummaryIsActive = 'Y'
|
|
AND Mcu_Mapping_KeliananGroupSummaryMgm_McuID = ?
|
|
WHERE Mcu_KelainanGroupSummaryIsActive = 'Y'
|
|
AND Mcu_KelainanGroupSummaryName LIKE ?
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db->query($sql, [$setupid, $search, $ROW_PER_PAGE, $start_offset]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$data = $qry->result_array();
|
|
$result = [
|
|
"records" => $data,
|
|
"total" => ceil($total / $ROW_PER_PAGE),
|
|
];
|
|
$this->sys_ok($result);
|
|
}
|
|
public function save()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$data = $prm["data"];
|
|
$setup = $prm["setup"];
|
|
// $this->sys_error("Mencapai batas maksimal 10 kelainan group");
|
|
// exit;
|
|
$sql = "SELECT Mcu_Mapping_KeliananGroupSummaryID
|
|
FROM mcu_mapping_kelainangroupsummary
|
|
WHERE Mcu_Mapping_KeliananGroupSummaryMgm_McuID = ?
|
|
AND Mcu_Mapping_KeliananGroupSummaryMcu_KelainanGroupSummaryID = ?
|
|
AND Mcu_Mapping_KeliananGroupSummaryIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$setup['Mgm_McuID'], $data['kelainanGroupSummaryID']]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$total = $qry->result_array();
|
|
if (count($total) > 0) {
|
|
$sql = "UPDATE mcu_mapping_kelainangroupsummary
|
|
SET Mcu_Mapping_KeliananGroupSummaryIsActive = 'N',
|
|
Mcu_Mapping_KeliananGroupSummaryDeleted = NOW(),
|
|
Mcu_Mapping_KeliananGroupSummaryDeletedUserID = {$userid}
|
|
WHERE Mcu_Mapping_KeliananGroupSummaryMgm_McuID = ?
|
|
AND Mcu_Mapping_KeliananGroupSummaryMcu_KelainanGroupSummaryID = ?";
|
|
$qry = $this->db->query($sql, [$setup['Mgm_McuID'], $data['kelainanGroupSummaryID']]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
} else {
|
|
$sql = "SELECT
|
|
COUNT(Mcu_KelainanGroupSummaryID) as total
|
|
FROM mcu_kelainangroupsummary
|
|
JOIN mcu_mapping_kelainangroupsummary
|
|
ON Mcu_KelainanGroupSummaryID = Mcu_Mapping_KeliananGroupSummaryMcu_KelainanGroupSummaryID
|
|
AND Mcu_Mapping_KeliananGroupSummaryIsActive = 'Y'
|
|
AND Mcu_Mapping_KeliananGroupSummaryMgm_McuID = ?
|
|
WHERE Mcu_KelainanGroupSummaryIsActive = 'Y' ";
|
|
$qry = $this->db->query($sql, [$setup['Mgm_McuID']]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$total = $qry->row_array()['total'];
|
|
if (intval($total) >= 10) {
|
|
$this->sys_error("Mencapai batas maksimal 10 kelainan group");
|
|
exit;
|
|
}
|
|
$sql = "INSERT INTO mcu_mapping_kelainangroupsummary(
|
|
Mcu_Mapping_KeliananGroupSummaryMgm_McuID,
|
|
Mcu_Mapping_KeliananGroupSummaryMcu_KelainanGroupSummaryID,
|
|
Mcu_Mapping_KeliananGroupSummaryCreated,
|
|
Mcu_Mapping_KeliananGroupSummaryCreatedUserID
|
|
)VALUES(?,?,NOW(),{$userid})
|
|
";
|
|
$qry = $this->db->query($sql, [$setup['Mgm_McuID'], $data['kelainanGroupSummaryID']]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
$this->sys_ok("OK");
|
|
}
|
|
}
|