Files
BE_IBL/application/controllers/mockup/masterdata/Day.php
2026-04-15 15:24:12 +07:00

490 lines
14 KiB
PHP

<?php
class Day extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "DAY API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookuppromise(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select distinct
SsNoPromiseID as id,
M_DayOfWeekID as usergroupid,
Nat_TestCode as code,
Nat_TestName As name,
group_concat(distinct M_DayOfWeekName order by M_DayOfWeekID) AS Hari ,
group_concat(distinct SsNoPromiseHour separator ' , ' ) AS Jam,
group_concat(distinct M_MouName) AS Agreement,
'xxx' as action
from ss_no_promise
join nat_test on SSNoPromiseNat_TestID = Nat_TestID
join m_dayofweek on SsNoPromiseDow = M_DayOfWeekID
join m_mou on json_contains(SsNoPromiseInAgreementJson, M_MouID )
where
M_DayOfWeekID = {$id} AND SsNoPromiseInAgreement = 'Y'
group by Nat_TestCode
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result();
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookup()
{
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_dayofweek
where
M_DayOfWeekIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$sql = "select M_DayOfWeekID as id,
M_DayOfWeekName as code,
M_DayOfWeekName as name,
M_DayOfWeekName as description ,
'xxx' as usergrouptype
from m_dayofweek
where
M_DayOfWeekName LIKE CONCAT('%','{$search}','%') AND
M_DayOfWeekIsActive = '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_dayofweek select",$this->db_onedev);
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 addnewstation()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_station = $prm['name'];
$code_station = $prm['code'];
$isnonlab_station = $prm['isnonlab'];
$query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
//echo $exist_name;
if($exist_name == 0 ){
$sql = "insert into t_samplestation(
T_SampleStationCode,
T_SampleStationName,
T_SampleStationIsNonLab,
T_SampleStationCreated,
T_SampleStationLastUpdated
)
values( ?, ?, ?,now(), now())";
$query = $this->db_onedev->query($sql,
array(
$name_station,
$code_station,
$isnonlab_station
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("t_samplestation insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada '));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editstation()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_station = $prm['id'];
$code_station = $prm['code'];
$name_station = $prm['name'];
$isnonlab_station = $prm['isnonlab'];
$query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'
AND T_SampleStationID <> {$id_station} ";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "update t_samplestation SET
T_SampleStationCode = ?,
T_SampleStationName = ?,
T_SampleStationIsNonLab = ?,
T_SampleStationLastUpdated = now()
where
T_SampleStationID = ?
";
$query = $this->db_onedev->query($sql,
array(
$code_station,
$name_station,
$isnonlab_station,
$id_station
)
);
//file_put_contents("/tmp/adi-update-user.sql",$this->db_onedev->last_query());
//echo $query;
if (!$query) {
$this->sys_error_db("t_samplestation update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id_station));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editbahan()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$bahanid = $prm['xid'];
$code = $prm['code'];
$name = $prm['name'];
$xstationname = $prm['xstationname'];
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'
and T_BahanID <> $bahanid ";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "update m_user SET
T_BahanCode = ?,
T_BahanName = ?,
T_BahanT_SampleStationID = ?,
T_BahanLastUpdated = now()
where T_BahanID = ? ";
$query = $this->db_onedev->query($sql,
array(
$code,
$name,
$xstationname["T_SampleStationID"],
$bahanid
));
if (!$query) {
$this->sys_error_db("t_bahan update",$this->db_onedev);
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $bahanid));
$this->sys_ok($result);
} else {
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewbahan()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$stationid = $prm['stationid'];
$code = $prm['code'];
$name = $prm['name'];
if($prm['xid'] == 0){
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "insert into t_bahan(
T_BahanT_SampleStationID,
T_BahanCode,
T_BahanName,
T_BahanCreated,
T_BahanLastUpdated
)
values( ?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$stationid,
$code,
$name
)
);
if (!$query) {
$this->sys_error_db("t_bahan insert",$this->db_onedev);
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}else{
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}' AND T_BahanID <> {$prm['xid']}";
$exist_name = $this->db_onedev->query($query)->row()->exist;
//echo $query;
//echo $query;
if($exist_name == 0 ){
$sql = "UPDATE t_bahan SET T_BahanName = '{$name}', T_BahanCode = '{$code}' WHERE T_BahanID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'name sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletebahan()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update t_bahan SET
T_BahanIsActive = 'N',
T_BahanLastUpdated = now()
WHERE
T_BahanID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_bahan 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 deleteselect()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update t_samplestation SET
T_SampleStationIsActive = 'N',
T_SampleStationLastUpdated = now()
WHERE
T_SampleStationID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_samplestation delete");
exit;
}
$sql = "UPDATE m_user SET
M_UserIsActive = 'N',
M_UserLastUpdated = now()
WHERE
M_UserM_UserGroupID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_user delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}