Files
2026-04-15 15:23:57 +07:00

374 lines
10 KiB
PHP

<?php
class Worksale extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Schedule API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function getschedule(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT IFNULL(M_RegPacketWorkID,0) as M_RegPacketWorkID,
T_PacketID,
T_PacketName,
T_PacketSasCode,
M_MouID,
M_MouName,
IF(IFNULL(M_RegPacketWorkID,0) > 0 , 'Y', 'N') as status,
'xxx' as regtimes,
'' as action
FROM
m_mou
JOIN t_packet ON T_PacketM_MouID = M_MouID AND T_PacketIsActive = 'Y'
LEFT JOIN m_reg_packetwork ON M_RegPacketWorkT_PacketID = T_PacketID AND M_RegPacketWorkIsActive = 'Y'
WHERE
M_MouIsOnline = 'Y' AND M_MouIsReleased = 'Y' AND M_MouIsActive = 'Y'
GROUP BY T_PacketName
ORDER BY T_PacketName ASC
";
//echo $query;
$rows = $this->db_onedev->query($query)->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 getsale(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT IFNULL(M_RegPacketSaleID,0) as M_RegPacketSaleID,
T_PacketID,
T_PacketName,
M_MouID,
M_MouName,
T_PacketSasCode,
IF(IFNULL(M_RegPacketSaleID,0) > 0 , 'Y', 'N') as status,
'xxx' as regtimes,
'' as action
FROM
m_mou
JOIN t_packet ON T_PacketM_MouID = M_MouID AND T_PacketIsActive = 'Y'
LEFT JOIN m_reg_packetsale ON M_RegPacketSaleT_PacketID = T_PacketID AND M_RegPacketSaleIsActive = 'Y'
WHERE
M_MouIsOnline = 'Y' AND M_MouIsReleased = 'Y' AND M_MouIsActive = 'Y'
GROUP BY T_PacketName
ORDER BY T_PacketName ASC
";
//echo $query;
$rows = $this->db_onedev->query($query)->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 add_regtime($tanggal, $branchid){
$query =" SELECT m_reg_packetwork.*,
T_PacketID,
T_PacketName,
T_PacketCode,
20 as jumlah,
'CITO' as tipe
FROM
m_reg_kuota_branch
LEFT JOIN t_packet ON T_PacketCode = M_RegKuotaT_PacketCode AND T_PacketIsActive = 'Y'
LEFT JOIN m_reg_packetwork ON M_RegPacketWorkT_PacketID = T_PacketID AND M_RegPacketWorkDate = '{$tanggal}' AND M_RegPacketWorkIsActive = 'Y'
WHERE
M_RegKuotaIsActive = 'Y' AND M_RegKuotaIsWork = 'Y' AND M_RegKuotaT_PacketID = '{$branchid}'
GROUP BY T_PacketID
UNION SELECT m_reg_packetwork.*,
T_PacketID,
T_PacketName,
T_PacketCode,
30 as jumlah,
'REGULER' as tipe
FROM
m_reg_kuota_branch
LEFT JOIN t_packet ON T_PacketCode = M_RegKuotaT_PacketCode AND T_PacketIsActive = 'Y'
LEFT JOIN m_reg_packetwork ON M_RegPacketWorkT_PacketID = T_PacketID AND M_RegPacketWorkDate = '{$tanggal}' AND M_RegPacketWorkIsActive = 'Y'
WHERE
M_RegKuotaIsActive = 'Y' AND M_RegKuotaIsWork = 'Y' AND M_RegKuotaT_PacketID = '{$branchid}'
GROUP BY T_PacketID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function getday(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_reg_day
WHERE
M_RegDayIsActive = 'Y'
";
//echo $query;
$rows['days'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsubcategory(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM t_subcategory
JOIN t_category ON T_CategoryID = T_SubCategoryT_CategoryID AND T_CategoryName LIKE '%covid%'
WHERE
T_SubCategoryIsActive = 'Y'
";
//echo $query;
$rows['subcategorys'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savenewwork(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$mouid = $prm['mouid'];
$packetid = $prm['packetid'];
$status = $prm['status'];
$userid = $this->sys_user["M_UserID"];
if($status == 'Y'){
$sql = "insert into m_reg_packetwork(
M_RegPacketWorkM_MouID,
M_RegPacketWorkT_PacketID,
M_RegPacketWorkUserID,
M_RegPacketWorkCreated,
M_RegPacketWorkLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$mouid,
$packetid,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_reg_packetwork 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 m_reg_packetwork SET
M_RegPacketWorkIsActive = 'N',
M_RegPacketWorkUserID = ?,
M_RegPacketWorkLastUpdated = now()
WHERE M_RegPacketWorkID = ?";
$query = $this->db_onedev->query($sql,
array(
$userid,
$id
)
);
if (!$query) {
$this->sys_error_db("m_reg_packetwork 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 savenewsale(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$mouid = $prm['mouid'];
$packetid = $prm['packetid'];
$status = $prm['status'];
$userid = $this->sys_user["M_UserID"];
if($status == 'Y'){
$sql = "insert into m_reg_packetsale(
M_RegPacketSaleM_MouID,
M_RegPacketSaleT_PacketID,
M_RegPacketSaleUserID,
M_RegPacketSaleCreated,
M_RegPacketSaleLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$mouid,
$packetid,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_reg_packetsale 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 m_reg_packetsale SET
M_RegPacketSaleIsActive = 'N',
M_RegPacketSaleUserID = ?,
M_RegPacketSaleLastUpdated = now()
WHERE M_RegPacketSaleID = ?";
$query = $this->db_onedev->query($sql,
array(
$userid,
$id
)
);
if (!$query) {
$this->sys_error_db("m_reg_packetsale 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 searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName 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("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable, 0 as xid, T_TestID, T_TestCode, T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one_lis_dev.t_test
JOIN one_lis_dev.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one_lis_dev.m_mou ON M_MouID = '{$mou_id}'
JOIN one_lis_dev.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = '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("test rows",$this->db_onedev);
exit;
}
}
}