398 lines
14 KiB
PHP
398 lines
14 KiB
PHP
<?php
|
|
|
|
class Exesumtemplate extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "BRANCH API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function lookupexesumtpl()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$limit = 'LIMIT 10';
|
|
|
|
$mgmmcuid = "";
|
|
if (isset($prm['mgmmcuid']) && $prm['mgmmcuid'] != 0) {
|
|
$mgmmcuid = "AND Mgm_McuID = " . $prm['mgmmcuid'];
|
|
}
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
$sql = "SELECT COUNT(*) AS total FROM (SELECT * FROM one_etl.mgm_mcu
|
|
JOIN one_etl.exe_sum_tpl ON Mgm_McuID = exeSumTplMgm_McuID
|
|
AND Mgm_McuIsActive = 'Y'
|
|
AND exeSumTplIsActive = 'Y'
|
|
$mgmmcuid )a";
|
|
$query = $this->db_onedev->query($sql);
|
|
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
|
$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("exe_sum_tpl count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
// echo $tot_page;
|
|
|
|
$sql = "SELECT exeSumTplID as id,
|
|
exe_sum_tpl.*
|
|
FROM one_etl.mgm_mcu
|
|
JOIN one_etl.exe_sum_tpl ON Mgm_McuID = exeSumTplMgm_McuID
|
|
AND Mgm_McuIsActive = 'Y' AND exeSumTplIsActive = 'Y'
|
|
$mgmmcuid
|
|
ORDER BY exeSumTplCode ASC
|
|
limit $number_limit offset $number_offset
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("exe_sum_tpl 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);
|
|
}
|
|
}
|
|
|
|
public function searchexesumtplbyid()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$exesumtpl_id = $prm["exesumtpl_id"];
|
|
$mgmmcuid = $prm['mgmmcuid'];
|
|
|
|
$sql = "SELECT *
|
|
FROM one_etl.exe_sum_tpl
|
|
WHERE exeSumTplIsActive = 'Y'
|
|
AND exeSumTplMgm_McuID = ?
|
|
AND exeSumTplID = ? ";
|
|
$query = $this->db_onedev->query($sql, [$mgmmcuid, $exesumtpl_id]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("exe_sum_tpl rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function searchmgmmcu()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$mgmmcuid = $prm['M_CompanyID'];
|
|
|
|
$sql = "SELECT Mgm_McuID, Mgm_McuNumber
|
|
FROM one_etl.mgm_mcu
|
|
WHERE Mgm_McuIsActive = 'Y'
|
|
AND Mgm_McuM_CompanyID = ?
|
|
ORDER BY Mgm_McuID ASC
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$mgmmcuid]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("mgm_mcu rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function searchcompany()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$q = [
|
|
'M_CompanyName' => '%',
|
|
'M_CompanyID' => ''
|
|
];
|
|
if ($prm['M_CompanyName'] == 'All') {
|
|
$q['M_CompanyName'] = "%%";
|
|
}
|
|
if ($prm['M_CompanyName'] != '') {
|
|
$q['M_CompanyName'] = "%{$prm['M_CompanyName']}%";
|
|
}
|
|
if ($prm['M_CompanyID'] != null) {
|
|
$q['M_CompanyID'] = "AND M_CompanyID LIKE %{$prm['M_CompanyID']}%";
|
|
}
|
|
|
|
$sql = "SELECT M_CompanyID, M_CompanyName
|
|
FROM m_company
|
|
where M_CompanyIsActive = 'Y'
|
|
AND M_CompanyName LIKE ? ?";
|
|
$query = $this->db_onedev->query($sql, [$q['M_CompanyName'], $q['M_CompanyID']]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_company rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function updateexesumtpl()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = "";
|
|
if (isset($prm["ID"])) {
|
|
$id = $prm["ID"];
|
|
}
|
|
$mcuid = "";
|
|
if (isset($prm["McuID"])) {
|
|
$mcuid = $prm["McuID"];
|
|
}
|
|
$title = "";
|
|
if (isset($prm["Title"])) {
|
|
$title = $prm["Title"];
|
|
}
|
|
$subtitle = "";
|
|
if (isset($prm["SubTitle"])) {
|
|
$subtitle = $prm["SubTitle"];
|
|
}
|
|
$body = "";
|
|
if (isset($prm["Body"])) {
|
|
$body = $prm["Body"];
|
|
}
|
|
|
|
$sql = "UPDATE one_etl.exe_sum_tpl SET
|
|
exeSumTplTitle = ?,
|
|
exeSumTplSubTitleTitle = ?,
|
|
exeSumTplSubBody = ?
|
|
WHERE exeSumTplID = ?
|
|
AND exeSumTplMgm_McuID =?
|
|
";
|
|
$qry = $this->db->query($sql, array($title, $subtitle, $body, $id, $mcuid));
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("edit executive summary error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM one_etl.exe_sum_tpl
|
|
WHERE exeSumTplID = ?
|
|
AND exeSumTplMgm_McuID =?
|
|
";
|
|
$qry = $this->db->query($sql, array($id, $mcuid));
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("edit executive summary error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("exe_sum_tpl rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function searchmcunotgenerated()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$mgmcompanyid = $prm['M_CompanyID'];
|
|
|
|
$sql = "SELECT Mgm_McuID, Mgm_McuNumber, Mgm_McuM_CompanyID
|
|
FROM one_etl.mgm_mcu
|
|
WHERE Mgm_McuID NOT IN (
|
|
SELECT exeSumTplMgm_McuID
|
|
FROM one_etl.exe_sum_tpl
|
|
WHERE exeSumTplIsActive = 'Y'
|
|
)
|
|
AND Mgm_McuIsActive = 'Y'
|
|
AND Mgm_McuM_CompanyID = ?
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$mgmcompanyid]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("mgm_mcu rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function searchmcugenerated()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$mgmcompanyid = $prm['M_CompanyID'];
|
|
|
|
$sql = "SELECT Mgm_McuID, Mgm_McuNumber, Mgm_McuM_CompanyID
|
|
FROM one_etl.mgm_mcu
|
|
WHERE Mgm_McuID IN (
|
|
SELECT exeSumTplMgm_McuID
|
|
FROM one_etl.exe_sum_tpl
|
|
WHERE exeSumTplIsActive = 'Y'
|
|
)
|
|
AND Mgm_McuIsActive = 'Y'
|
|
AND Mgm_McuM_CompanyID = ?
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$mgmcompanyid]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if (count($rows) == 0) {
|
|
$sql = "SELECT Mgm_McuID, Mgm_McuNumber, Mgm_McuM_CompanyID
|
|
FROM one_etl.mgm_mcu
|
|
WHERE Mgm_McuID IN (
|
|
SELECT exeSumTplMgm_McuID
|
|
FROM one_etl.exe_sum_tpl
|
|
WHERE exeSumTplIsActive = 'Y'
|
|
)
|
|
AND Mgm_McuIsActive = 'Y'
|
|
AND Mgm_McuM_CompanyID != ?
|
|
ORDER BY Mgm_McuID DESC
|
|
LIMIT 1
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$mgmcompanyid]);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array("available" => false, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("mgm_mcu rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
} else {
|
|
$result = array("available" => true, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("mgm_mcu rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$mcuid = $prm['Mgm_McuID'];
|
|
$genmgmcompanyid = $prm['gen_Mgm_McuID'];
|
|
|
|
$sql = "INSERT INTO one_etl.exe_sum_tpl (exeSumTplCode, exeSumTplMgm_McuID, exeSumTplTitle,exeSumTplSubTitleTitle,exeSumTplSubBody)
|
|
SELECT exeSumTplCode, ? ,exeSumTplTitle,exeSumTplSubTitleTitle,exeSumTplSubBody
|
|
FROM one_etl.exe_sum_tpl
|
|
JOIN one_etl.mgm_mcu ON exeSumTplMgm_McuID= Mgm_McuID
|
|
AND exeSumTplIsActive = 'Y'
|
|
AND Mgm_McuIsActive = 'Y'
|
|
AND exeSumTplMgm_McuID = ?
|
|
";
|
|
$query = $this->db_onedev->query($sql, [$mcuid,$genmgmcompanyid]);
|
|
|
|
if ($query) {
|
|
|
|
$result = array("data" => "Success");
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$result = array("data" => "Unsuccess");
|
|
$this->sys_ok($result);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
} |