Files
BE_CPONE/application/controllers/cpone/mcuoffline/Packetcpone.php
2026-04-27 10:26:26 +07:00

924 lines
36 KiB
PHP

<?php
class Packetcpone extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function savesetupv0()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$T_PacketName = strtoupper($prm['namapacket']);
$T_PriceHeaderID = $prm['priceheader']['T_PriceHeaderID'];
$T_PacketType = $prm['jenispacket'];
$T_PacketPrice = $prm['T_PacketPrice'];
$T_PacketOriginalPrice = $prm['T_PacketOriginalPrice'];
$T_PacketSasCode = "";
$T_PacketOriginalBruto = 0;
$detail_packet = $prm['detailpacket'];
// $act = $prm['act'];
if($prm["act"] == 'new'){
// check paket exists or not
$sqlCheck = "SELECT *
FROM t_packet
WHERE T_PacketIsActive = 'Y'
AND T_PacketName = '$T_PacketName'";
$qryCheck = $this->db_onedev->query($sqlCheck);
if(!$qryCheck){
$this->sys_error_db("t_packet check", $this->db_onedev);
exit;
}
$rowCheck = $qryCheck->result_array();
if(count($rowCheck) > 0){
$this->sys_error("Data dengan nama paket ".$T_PacketName." Sudah Ada");
exit;
} else {
// get numbering
$sql_get_numbering = "SELECT fn_numbering_cpone('PC') as numberx";
$qry_get_numbering = $this->db_onedev->query($sql_get_numbering);
if(!$qry_get_numbering){
$this->db_onedev->trans_rollback();
$this->sys_error_db("packet numbering cpone", $this->db_onedev);
exit;
}
$data_numbering = $qry_get_numbering->result_array();
$T_PacketSasCode = $data_numbering[0]['numberx'];
// insert t_packet
$sql_insert = "INSERT INTO t_packet
(
T_PacketT_PriceHeaderID,
T_PacketType,
T_PacketName,
T_PacketPrice,
T_PacketOriginalPrice,
T_PacketSasCode,
T_PacketIsActive,
T_PacketCreated,
T_PacketOriginalBruto
)
VALUES
(
$T_PriceHeaderID, -- T_PacketT_PriceHeaderID
'$T_PacketType', -- T_PacketType (assuming 'PR' for Profile)
'$T_PacketName', -- T_PacketName
$T_PacketPrice, -- T_PacketPrice
$T_PacketOriginalPrice, -- T_PacketOriginalPrice
'$T_PacketSasCode', -- T_PacketSasCode
'Y', -- T_PacketIsActive
NOW(), -- T_PacketCreated
$T_PacketOriginalBruto -- T_PacketOriginalBruto (can be NULL)
)";
$qryInsert = $this->db_onedev->query($sql_insert);
if(!$qryInsert){
$this->db_onedev->trans_rollback();
$this->sys_error_db("t_packet insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
// insert t_packetdetail
if(count($detail_packet) > 0) {
foreach($detail_packet as $k => $v){
$T_PriceTotalPacket = $v['T_PriceTotalPacket'];
// bisa berubah ubah kalau PN
if($T_PacketType == "PN"){
$T_PacketDetailOriginalPrice = $v['T_PriceTotal'];
$T_PacketDetailPrice = $T_PriceTotalPacket;
}
if($T_PacketType == "PR"){
$T_PacketDetailOriginalPrice = $v['T_PriceTotal'];
$T_PacketDetailPrice = $v['T_PriceTotal'];
}
$T_PacketDetailPriceAmount = 0;
$T_PacketDetailPriceDisc = 0;
$T_PacketDetailPriceDiscRp = 0;
$T_PacketDetailPriceSubTotal = 0;
if(!empty($v['T_PriceAmount'])){
$T_PacketDetailPriceAmount = $v['T_PriceAmount'];
}
if(!empty($v['T_PriceDisc'])){
$T_PacketDetailPriceDisc = $v['T_PriceDisc'];
}
if(!empty($v['T_PriceDiscRp'])){
$T_PacketDetailPriceDiscRp = $v['T_PriceDiscRp'];
}
if(!empty($v['T_PriceSubTotal'])){
$T_PacketDetailPriceSubTotal = $v['T_PriceSubTotal'];
}
$sql_insert_detail = "INSERT INTO t_packetdetail
(
T_PacketDetailT_PacketID,
T_PacketDetailT_TestID,
T_PacketDetailOriginalPrice,
T_PacketDetailPrice,
T_PacketDetailIsActive,
T_PacketDetailCreated,
T_PacketDetailPriceAmount,
T_PacketDetailPriceDisc,
T_PacketDetailPriceDiscRp,
T_PacketDetailPriceSubTotal
) VALUES (
$last_id, -- T_PacketDetailT_PacketID
{$v['T_TestID']}, -- T_PacketDetailT_TestID
{$T_PacketDetailOriginalPrice}, -- T_PacketDetailOriginalPrice
{$T_PacketDetailPrice}, -- T_PacketDetailPrice
'Y', -- T_PacketDetailIsActive
NOW(), -- T_PacketDetailCreated
{$T_PacketDetailPriceAmount}, -- T_PacketDetailPriceAmount
{$T_PacketDetailPriceDisc}, -- T_PacketDetailPriceDisc
{$T_PacketDetailPriceDiscRp}, -- T_PacketDetailPriceDiscRp
{$T_PacketDetailPriceSubTotal} -- T_PacketDetailPriceSubTotal
)";
$qry_detail = $this->db_onedev->query($sql_insert_detail);
if(!$qry_detail) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("t_packetdetail insert", $this->db_onedev);
exit;
}
}
}
// sql data
$sql = "SELECT T_PacketName as xnumber
FROM t_packet
WHERE T_PacketID = {$last_id}";
//echo $sql;
$row = $this->db_onedev->query($sql)->row_array();
$result = array(
"total" => 1 ,
"records" => $row,
);
$this->sys_ok($result);
exit;
}
} else{
// check paket exists or not
$sqlCheck = "SELECT *
FROM t_packet
WHERE T_PacketIsActive = 'Y'
AND T_PacketName = '$T_PacketName'
AND T_PacketID <> {$prm["xid"]}";
$qryCheck = $this->db_onedev->query($sqlCheck);
if(!$qryCheck){
$this->sys_error_db("t_packet check", $this->db_onedev);
exit;
}
$rowCheck = $qryCheck->result_array();
if(count($rowCheck) > 0){
// echo $sqlCheck;
// exit;
$this->sys_error("Data dengan nama paket ".$T_PacketName." Sudah Ada");
exit;
} else {
// update t_packet
$sql_update = "UPDATE t_packet
SET
T_PacketT_PriceHeaderID = $T_PriceHeaderID,
T_PacketType = '$T_PacketType',
T_PacketName = '$T_PacketName',
T_PacketPrice = $T_PacketPrice,
T_PacketOriginalPrice = $T_PacketOriginalPrice,
T_PacketIsActive = 'Y',
T_PacketLastUpdated = NOW(),
T_PacketOriginalBruto = $T_PacketOriginalBruto
WHERE
T_PacketID = {$prm["xid"]}";
$qryUpdate = $this->db_onedev->query($sql_update);
if(!$qryUpdate){
$this->db_onedev->trans_rollback();
$this->sys_error_db("error t_packet update", $this->db_onedev);
exit;
}
$last_id = $prm["xid"];
// // update detail packet
// // update isActive N kan semua
$sqlUpdatePacket = "UPDATE t_packetdetail
SET
T_PacketDetailIsActive = 'N',
T_PacketDetailLastUpdated = NOW()
WHERE T_PacketDetailT_PacketID = $last_id";
// echo $sqlUpdatePacket;
$qry_mgm_update_tpacketdetails = $this->db_onedev->query($sqlUpdatePacket);
if(!$qry_mgm_update_tpacketdetails){
$this->db_onedev->trans_rollback();
$this->sys_error_db("t_packetdetail update", $this->db_onedev);
exit;
}
// insert t_packetdetail
if(count($detail_packet) > 0) {
foreach($detail_packet as $k => $v){
$T_PriceTotalPacket = $v['T_PriceTotalPacket'];
// bisa berubah ubah kalau PN
if($T_PacketType == "PN"){
$T_PacketDetailOriginalPrice = $v['T_PriceTotal'];
$T_PacketDetailPrice = $T_PriceTotalPacket;
}
if($T_PacketType == "PR"){
$T_PacketDetailOriginalPrice = $v['T_PriceTotal'];
$T_PacketDetailPrice = $v['T_PriceTotal'];
}
$T_PacketDetailPriceAmount = 0;
$T_PacketDetailPriceDisc = 0;
$T_PacketDetailPriceDiscRp = 0;
$T_PacketDetailPriceSubTotal = 0;
if(!empty($v['T_PriceAmount'])){
$T_PacketDetailPriceAmount = $v['T_PriceAmount'];
}
if(!empty($v['T_PriceDisc'])){
$T_PacketDetailPriceDisc = $v['T_PriceDisc'];
}
if(!empty($v['T_PriceDiscRp'])){
$T_PacketDetailPriceDiscRp = $v['T_PriceDiscRp'];
}
if(!empty($v['T_PriceSubTotal'])){
$T_PacketDetailPriceSubTotal = $v['T_PriceSubTotal'];
}
$sql_insert_detail = "INSERT INTO t_packetdetail
(
T_PacketDetailT_PacketID,
T_PacketDetailT_TestID,
T_PacketDetailOriginalPrice,
T_PacketDetailPrice,
T_PacketDetailIsActive,
T_PacketDetailCreated,
T_PacketDetailPriceAmount,
T_PacketDetailPriceDisc,
T_PacketDetailPriceDiscRp,
T_PacketDetailPriceSubTotal
) VALUES (
$last_id, -- T_PacketDetailT_PacketID
{$v['T_TestID']}, -- T_PacketDetailT_TestID
{$T_PacketDetailOriginalPrice}, -- T_PacketDetailOriginalPrice
{$T_PacketDetailPrice}, -- T_PacketDetailPrice
'Y', -- T_PacketDetailIsActive
NOW(), -- T_PacketDetailCreated
{$T_PacketDetailPriceAmount}, -- T_PacketDetailPriceAmount
{$T_PacketDetailPriceDisc}, -- T_PacketDetailPriceDisc
{$T_PacketDetailPriceDiscRp}, -- T_PacketDetailPriceDiscRp
{$T_PacketDetailPriceSubTotal} -- T_PacketDetailPriceSubTotal
)";
$qry_detail = $this->db_onedev->query($sql_insert_detail);
if(!$qry_detail) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("t_packetdetail insert", $this->db_onedev);
exit;
}
}
}
// sql data
$sql = "SELECT T_PacketName as xnumber
FROM t_packet
WHERE T_PacketID = {$last_id}";
//echo $sql;
$row = $this->db_onedev->query($sql)->row_array();
$result = array(
"total" => 1 ,
"records" => $row,
);
$this->sys_ok($result);
exit;
}
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletev0(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
// packet
$query_t_packet = $this->db_onedev->query("UPDATE t_packet SET
T_PacketIsActive = 'N',
T_PacketLastUpdated = NOW()
WHERE
T_PacketID = '{$prm['id']}'
");
if (!$query_t_packet) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("t_packet update error", $this->db_onedev);
exit;
}
// packet details
$query_t_packetdetail = $this->db_onedev->query("UPDATE t_packetdetail SET
T_PacketDetailIsActive = 'N',
T_PacketDetailLastUpdated = NOW()
WHERE
T_PacketDetailT_PacketID = '{$prm['id']}'
");
if (!$query_t_packetdetail) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("t_packetdetail update error", $this->db_onedev);
exit;
}
// $rows = $this->db_onedev->query($query_mgmmcu);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getTTestByTPriceHeaderCurrent()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
// $search_kode = $prm['searchKode'];
// $search_nama = $prm['searchNama'];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$natsubgroup = "";
$sql_where_natsubgroup = "";
if(isset($prm['natsubgroup']) && !empty($prm['natsubgroup']) && $prm['natsubgroup'] != "All"){
$natsubgroup = $prm['natsubgroup'];
$sql_where_natsubgroup = " AND Nat_SubGroupID = $natsubgroup";
}
// if($natsubgroup != "All"){
// $sql_where_natsubgroup = " AND Nat_SubGroupID = $natsubgroup";
// }
$tpriceheader = $prm['tpriceheader'];
$sql_where_tpriceheader = "";
if(isset($prm['tpriceheader']) && !empty($prm['tpriceheader'])){
$sql_where_tpriceheader = " AND ph.T_PriceHeaderID = $tpriceheader";
}
$sqlSearch = "T_TestName LIKE '%%' AND T_TestCode LIKE '%%' ".$sql_where_tpriceheader.$sql_where_natsubgroup;
if(isset($prm['searchKode']) && !empty($prm['searchKode'])){
$sqlSearch = " T_TestCode LIKE '%{$prm['searchKode']}%' ".$sql_where_tpriceheader.$sql_where_natsubgroup;
}
if(isset($prm['searchNama']) && !empty($prm['searchNama'])){
$sqlSearch = " T_TestName LIKE '%{$prm['searchNama']}%' ".$sql_where_tpriceheader.$sql_where_natsubgroup;
}
if(
((isset($prm['searchKode']) && !empty($prm['searchKode'])))
&& (isset($prm['searchNama']) && !empty($prm['searchNama']))
){
$sqlSearch = " T_TestName LIKE '%{$prm['searchNama']}%' AND T_TestCode LIKE '%{$prm['searchKode']}%' ".$sql_where_tpriceheader.$sql_where_natsubgroup;
}
$sql_where = "
WHERE (
".$sqlSearch."
)";
// $sql_where = "
// WHERE (
// T_TestCode LIKE '%{$prm['searchKode']}%'
// OR T_TestName LIKE '%{$prm['searchNama']}%'
// )";
$sql = "SELECT count(*) as total
FROM (
SELECT
IFNULL(p.T_PriceID, 0) AS T_PriceID
FROM
t_price p
JOIN
t_priceheader ph
ON
p.T_PriceT_PriceHeaderID = ph.T_PriceHeaderID
AND p.T_PriceIsActive = 'Y'
AND ph.T_PriceHeaderIsActive = 'Y'
JOIN
t_test testx
ON p.T_PriceT_TestID = testx.T_TestID
AND testx.T_TestIsActive = 'Y'
LEFT JOIN nat_subgroup
ON T_TestNat_SubgroupID = Nat_SubgroupID
AND Nat_SubGroupIsActive = 'Y'
$sql_where
) x";
$sql_param = array();
$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("tprice count", $this->db_onedev);
exit;
}
// sql data
$sql = "SELECT
ROW_NUMBER() OVER (ORDER BY T_PriceID) AS RowNum,
IFNULL(p.T_PriceTotal, 0) AS T_PriceTotalPacket,
IFNULL(p.T_PriceID, 0) AS T_PriceID,
IFNULL(p.T_PriceT_PriceHeaderID, 0) AS T_PriceT_PriceHeaderID,
IFNULL(p.T_PriceT_TestID, 0) AS T_PriceT_TestID,
IFNULL(p.T_PriceIsCito, 'N') AS T_PriceIsCito,
IFNULL(p.T_PricePriority, 1) AS T_PricePriority,
IFNULL(p.T_PriceAmount, 0) AS T_PriceAmount,
IFNULL(p.T_PriceDisc, 0) AS T_PriceDisc,
IFNULL(p.T_PriceDiscRp, 0) AS T_PriceDiscRp,
IFNULL(p.T_PriceSubTotal, 0) AS T_PriceSubTotal,
IFNULL(p.T_PriceOther, 0) AS T_PriceOther,
IFNULL(p.T_PriceTotal, 0) AS T_PriceTotal,
IFNULL(p.T_PriceIsActive, 'Y') AS T_PriceIsActive,
IFNULL(p.T_PriceCreated, '0000-00-00') AS T_PriceCreated,
IFNULL(p.T_PriceLastUpdated, '0000-00-00') AS T_PriceLastUpdated,
IFNULL(p.T_PriceUserID, 0) AS T_PriceUserID,
IFNULL(ph.T_PriceHeaderID, 0) AS T_PriceHeaderID,
IFNULL(ph.T_PriceHeaderName, '') AS T_PriceHeaderName,
IFNULL(ph.T_PriceHeaderStartDate, '0000-00-00') AS T_PriceHeaderStartDate,
IFNULL(ph.T_PriceHeaderEndDate, '0000-00-00') AS T_PriceHeaderEndDate,
IFNULL(ph.T_PriceHeaderIsActive, 'Y') AS T_PriceHeaderIsActive,
IFNULL(ph.T_PriceHeaderUserID, 0) AS T_PriceHeaderUserID,
IFNULL(ph.T_PriceHeaderCreated, '0000-00-00 00:00:00') AS T_PriceHeaderCreated,
IFNULL(ph.T_PriceHeaderCraetdUserID, 0) AS T_PriceHeaderCraetdUserID,
IFNULL(ph.T_PriceHeaderLastUpdated, '0000-00-00 00:00:00') AS T_PriceHeaderLastUpdated,
IFNULL(ph.T_PriceHeaderLastUpdatedUserID, 0) AS T_PriceHeaderLastUpdatedUserID,
IFNULL(ph.T_PriceHeaderDeleted, '0000-00-00 00:00:00') AS T_PriceHeaderDeleted,
IFNULL(ph.T_PriceHeaderDeletedUserID, 0) AS T_PriceHeaderDeletedUserID,
IFNULL(testx.T_TestID, 0) AS T_TestID,
IFNULL(testx.T_TestCode, '') AS T_TestCode,
IFNULL(testx.T_TestName, '') AS T_TestName
FROM
t_price p
JOIN
t_priceheader ph
ON
p.T_PriceT_PriceHeaderID = ph.T_PriceHeaderID
AND p.T_PriceIsActive = 'Y'
AND ph.T_PriceHeaderIsActive = 'Y'
JOIN
t_test testx
ON p.T_PriceT_TestID = testx.T_TestID
AND testx.T_TestIsActive = 'Y'
LEFT JOIN nat_subgroup
ON T_TestNat_SubgroupID = Nat_SubgroupID
AND Nat_SubGroupIsActive = 'Y'
$sql_where
ORDER BY p.T_PriceID DESC
limit $number_limit offset $number_offset
";
$query = $this->db_onedev->query($sql, $sql_param);
if ($query === false) {
// If query failed, log the error and exit
$this->sys_error_db("select t_price data", $this->db_onedev);
exit;
}
$rows = $query->result_array();
$result = array(
"total" => $tot_page,
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getTPriceHeader()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT *
FROM t_priceheader
WHERE T_PriceHeaderIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("t_priceheader select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$new_entry = array(
'T_PriceHeaderID' => 'All',
'T_PriceHeaderName' => 'All',
'T_PriceHeaderStartDate' => "",
'T_PriceHeaderEndDate' => "",
'T_PriceHeaderIsActive' => "",
'T_PriceHeaderUserID' => "",
'T_PriceHeaderCreated' => "",
'T_PriceHeaderCraetdUserID' => "",
'T_PriceHeaderLastUpdated' => "",
'T_PriceHeaderLastUpdatedUserID' => "",
'T_PriceHeaderDeleted' => "",
'T_PriceHeaderDeletedUserID' => ""
);
array_unshift($rows, $new_entry);
$result = array(
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getTPriceHeaderCurrent()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
IFNULL(T_PriceHeaderID, 0) AS T_PriceHeaderID,
IFNULL(T_PriceHeaderName, '') AS T_PriceHeaderName,
IFNULL(T_PriceHeaderStartDate, '0000-00-00') AS T_PriceHeaderStartDate,
IFNULL(T_PriceHeaderEndDate, '0000-00-00') AS T_PriceHeaderEndDate,
IFNULL(T_PriceHeaderIsActive, 'Y') AS T_PriceHeaderIsActive,
IFNULL(T_PriceHeaderUserID, 0) AS T_PriceHeaderUserID,
IFNULL(T_PriceHeaderCreated, '0000-00-00 00:00:00') AS T_PriceHeaderCreated,
IFNULL(T_PriceHeaderCraetdUserID, 0) AS T_PriceHeaderCraetdUserID,
IFNULL(T_PriceHeaderLastUpdated, '0000-00-00 00:00:00') AS T_PriceHeaderLastUpdated,
IFNULL(T_PriceHeaderLastUpdatedUserID, 0) AS T_PriceHeaderLastUpdatedUserID,
IFNULL(T_PriceHeaderDeleted, '0000-00-00 00:00:00') AS T_PriceHeaderDeleted,
IFNULL(T_PriceHeaderDeletedUserID, 0) AS T_PriceHeaderDeletedUserID
FROM
t_priceheader
WHERE T_PriceHeaderIsActive = 'Y'
AND CURDATE() BETWEEN T_PriceHeaderStartDate AND T_PriceHeaderEndDate";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("t_priceheader select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$result = array(
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function searchv0()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
// $search = $prm['search'];
// if (isset($prm['search'])) {
// $search = trim($prm["search"]);
// if ($search != "") {
// $search = '%' . $prm['search'] . '%';
// }else{
// $search = '%%';
// }
// }
// $limit = '';
// $filter_paket = $prm['searchPacket'];
// if($all == 'N'){
// $limit = ' LIMIT 10';
// }
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
// $sql_where = " (
// T_PacketName LIKE '%{$prm['search']}%'
// OR T_PacketType LIKE '%{$prm['search']}%'
// ) AND T_PacketIsActive = 'Y'";
$sql_where_tpriceheader = "";
$tpriceheader = "";
if(isset($prm['tpriceheader'])){
$tpriceheader = $prm['tpriceheader'];
}
if($tpriceheader != "All"){
$sql_where_tpriceheader = " AND T_PacketT_PriceHeaderID = $tpriceheader";
}
$sql_where = " (
T_PacketName LIKE '%{$prm['search']}%'
) AND T_PacketIsActive = 'Y'
$sql_where_tpriceheader";
$sql = "SELECT count(*) as total
FROM t_packet
WHERE $sql_where
";
$sql_param = array();
$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("t_packet count", $this->db_onedev);
exit;
}
// sql data
$sql = "SELECT
IFNULL(T_PacketID, 0) AS T_PacketID,
IFNULL(T_PacketT_PriceHeaderID, 0) AS T_PacketT_PriceHeaderID,
IFNULL(T_PacketType,'') AS T_PacketType,
IFNULL(T_PacketName,'') AS T_PacketName,
IFNULL(T_PacketPrice,0) AS T_PacketPrice,
IFNULL(T_PacketOriginalPrice,0) AS T_PacketOriginalPrice,
IFNULL(T_PacketSasCode,'') AS T_PacketSasCode,
IFNULL(T_PacketIsActive,'') AS T_PacketIsActive,
IFNULL(T_PacketCreated,'') AS T_PacketCreated,
IFNULL(T_PacketLastUpdated,'') AS T_PacketLastUpdated
FROM t_packet
WHERE $sql_where
GROUP BY T_PacketID
ORDER BY T_PacketID DESC
limit $number_limit offset $number_offset";
$query = $this->db_onedev->query($sql, $sql_param);
if ($query === false) {
// If query failed, log the error and exit
$this->sys_error_db("select t_packet data", $this->db_onedev);
exit;
}
$rows = $query->result_array();
$result = array(
"total" => $tot_page,
"records" => $rows,
"sql"=> $this->db_onedev->last_query()
);
$this->sys_ok($result);
exit;
}
public function getPaketById()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$id = $prm['T_PacketID'];
$sql_paket = "SELECT
T_PacketID,
T_PacketName,
T_PriceHeaderID,
T_PriceHeaderName,
T_PacketType,
'' as detailpackets
FROM t_packet
JOIN t_priceheader
ON T_PacketT_PriceHeaderID = T_PriceHeaderID
AND T_PacketIsActive = 'Y'
AND T_PriceHeaderIsActive = 'Y'
AND T_PacketID = $id
JOIN t_packetdetail
ON T_PacketID = T_PacketDetailT_PacketID
AND T_PacketDetailIsActive = 'Y'
GROUP BY T_PacketID";
$qry = $this->db_onedev->query($sql_paket);
if(!$qry){
$this->sys_error_db("t_packet count", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
foreach ($rows as $key => $vx) {
$sql_detail = "SELECT
T_PacketDetailID,
T_PacketDetailT_PacketID,
T_PacketDetailT_TestID,
T_PacketDetailOriginalPrice as T_PriceTotal,
T_PacketDetailPrice as T_PriceTotalPacket,
T_PacketDetailIsActive,
T_PacketDetailCreated,
T_PacketDetailLastUpdated,
T_PacketDetailPriceAmount,
T_PacketDetailPriceDisc,
T_PacketDetailPriceDiscRp,
T_PacketDetailPriceSubTotal,
T_TestID,
T_TestName
FROM t_packetdetail
JOIN t_test
ON T_PacketDetailT_TestID = T_TestID
AND T_TestIsActive = 'Y'
AND T_PacketDetailIsActive = 'Y'
AND T_PacketDetailT_PacketID = $id";
$qry_detail = $this->db_onedev->query($sql_detail);
if(!$qry_detail){
$this->sys_error_db("t_packetdetail count", $this->db_onedev);
exit;
}
$rowdet = $qry_detail->result_array();
$rows[$key]['sumhargaawal'] = 0;
$rows[$key]['sumhargapaket'] = 0;
$rows[$key]['detailpackets'] = $rowdet;
foreach($rowdet as $k => $vk){
$rows[$key]['sumhargaawal'] += $vk['T_PriceTotal'];
$rows[$key]['sumhargapaket'] += $vk['T_PriceTotalPacket'];
}
}
//
$result = array(
// "total" => $tot_page,
"records" => $rows,
"sql"=> $this->db_onedev->last_query()
);
$this->sys_ok($result);
exit;
}
public function getGroupPemeriksaan() {
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
Nat_SubGroupID,
Nat_SubGroupNat_GroupID,
Nat_SubGroupCode,
Nat_SubGroupName,
Nat_SubGroupLangName,
Nat_SubGroupIsResult,
Nat_SubGroupReportTitle,
Nat_SubGroupCreated,
Nat_SubGroupLastUpdated,
Nat_SubGroupIsActive
FROM
nat_subgroup
WHERE
Nat_SubGroupIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("nat_subgroup select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$new_entry = array(
"Nat_SubGroupID" => "All",
"Nat_SubGroupNat_GroupID" => "",
"Nat_SubGroupCode" => "",
"Nat_SubGroupName" => "All",
"Nat_SubGroupLangName" => "",
"Nat_SubGroupIsResult" => "",
"Nat_SubGroupReportTitle" => "",
"Nat_SubGroupCreated"=> "",
"Nat_SubGroupLastUpdated"=> "",
"Nat_SubGroupIsActive"=> ""
);
array_unshift($rows, $new_entry);
$result = array(
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}
?>