1861 lines
73 KiB
PHP
1861 lines
73 KiB
PHP
<?php
|
|
class Packetcponev6 extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
var $db_cpone_log;
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->db_cpone_log = $this->load->database("cpone_log", true);
|
|
}
|
|
|
|
public function copypacket()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$inp_T_PacketNameCopy = strtoupper($prm['inp_T_PacketNameCopy']);
|
|
$T_PacketSasCode = "";
|
|
|
|
$T_PacketID = $prm['T_PacketID'];
|
|
|
|
$sqlCheck = "SELECT *
|
|
FROM t_packet
|
|
WHERE T_PacketIsActive = 'Y'
|
|
AND T_PacketName = '$inp_T_PacketNameCopy'";
|
|
|
|
$qryCheck = $this->db_onedev->query($sqlCheck);
|
|
|
|
if (!$qryCheck) {
|
|
$this->sys_error_db("t_packet check nama paket", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rowCheck = $qryCheck->result_array();
|
|
|
|
if (count($rowCheck) > 0) {
|
|
$this->sys_error("Data dengan nama paket " . $inp_T_PacketNameCopy . " Sudah Ada");
|
|
exit;
|
|
} else {
|
|
// get data by id
|
|
$sql_data = "SELECT *
|
|
FROM t_packet
|
|
WHERE T_PacketIsActive = 'Y'
|
|
AND T_PacketID = $T_PacketID";
|
|
|
|
$qry_data = $this->db_onedev->query($sql_data);
|
|
if (!$qry_data) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("packet get data cpone", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$row_data = $qry_data->result_array();
|
|
$T_PacketType = $row_data[0]['T_PacketType'];
|
|
|
|
// get numbering
|
|
$sql_get_numbering = "SELECT fn_numbering_cpone('PCPN') as numberx";
|
|
if ($T_PacketType == 'PR') {
|
|
$sql_get_numbering = "SELECT fn_numbering_cpone('PCPR') 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'];
|
|
|
|
// query insert t_packet
|
|
$sql_insert_packet_copy = "INSERT INTO t_packet (
|
|
T_PacketT_PriceHeaderID,
|
|
T_PacketType,
|
|
T_PacketName,
|
|
T_PacketPrice,
|
|
T_PacketOriginalPrice,
|
|
T_PacketSasCode,
|
|
T_PacketStartDate,
|
|
T_PacketEndDate,
|
|
T_PacketIsGenerated,
|
|
T_PacketGeneratedDate,
|
|
T_PacketIsActive,
|
|
T_PacketCreated,
|
|
T_PacketLastUpdated,
|
|
T_PacketOriginalBruto,
|
|
T_PacketIsOptional
|
|
)
|
|
SELECT
|
|
T_PacketT_PriceHeaderID,
|
|
T_PacketType,
|
|
'$inp_T_PacketNameCopy' as T_PacketName,
|
|
T_PacketPrice,
|
|
T_PacketOriginalPrice,
|
|
'$T_PacketSasCode' as T_PacketSasCode,
|
|
T_PacketStartDate,
|
|
T_PacketEndDate,
|
|
'N' as T_PacketIsGenerated,
|
|
T_PacketGeneratedDate,
|
|
T_PacketIsActive,
|
|
NOW() as T_PacketCreated,
|
|
T_PacketLastUpdated,
|
|
T_PacketOriginalBruto,
|
|
T_PacketIsOptional
|
|
FROM t_packet
|
|
WHERE T_PacketID = $T_PacketID";
|
|
|
|
$qry_insert_packet_copy = $this->db_onedev->query($sql_insert_packet_copy);
|
|
if (!$qry_insert_packet_copy) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_packet insert into select cpone", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$last_id = $this->db_onedev->insert_id();
|
|
|
|
// query insert t_packetdetail
|
|
$sql_insert_detail_copy = "INSERT INTO t_packetdetail (
|
|
T_PacketDetailT_PacketID,
|
|
T_PacketDetailT_TestID,
|
|
T_PacketDetailOriginalPrice,
|
|
T_PacketDetailPrice,
|
|
T_PacketDetailIsActive,
|
|
T_PacketDetailCreated,
|
|
T_PacketDetailLastUpdated,
|
|
T_PacketDetailPriceAmount,
|
|
T_PacketDetailPriceDisc,
|
|
T_PacketDetailPriceDiscRp,
|
|
T_PacketDetailPriceSubTotal
|
|
)
|
|
SELECT
|
|
$last_id as T_PacketDetailT_PacketID,
|
|
T_PacketDetailT_TestID,
|
|
T_PacketDetailOriginalPrice,
|
|
T_PacketDetailPrice,
|
|
T_PacketDetailIsActive,
|
|
T_PacketDetailCreated,
|
|
T_PacketDetailLastUpdated,
|
|
T_PacketDetailPriceAmount,
|
|
T_PacketDetailPriceDisc,
|
|
T_PacketDetailPriceDiscRp,
|
|
T_PacketDetailPriceSubTotal
|
|
FROM t_packetdetail
|
|
WHERE T_PacketDetailT_PacketID = $T_PacketID
|
|
AND T_PacketDetailIsActive = 'Y'";
|
|
|
|
$qry_sql_insert_detail_copy = $this->db_onedev->query($sql_insert_detail_copy);
|
|
if (!$qry_sql_insert_detail_copy) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("t_packetdetail insert into select cpone", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
// sql data
|
|
$sql = "SELECT T_PacketName as xnumber , T_PacketSasCode as xcode
|
|
FROM t_packet
|
|
WHERE T_PacketID = {$last_id}";
|
|
|
|
//echo $sql;
|
|
$row = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $row,
|
|
);
|
|
|
|
$dataAfter = $this->getPacket($last_id);
|
|
$logPacket = [
|
|
'ID' => $last_id,
|
|
'detailID' => '0',
|
|
'type' => 'COPY PACKET',
|
|
'desc' => "copy paket dari copy packet id $T_PacketID",
|
|
'prm' => $prm,
|
|
'dataBefore' => '',
|
|
'dataAfter' => $dataAfter,
|
|
'userID' => $this->sys_user["M_UserID"],
|
|
];
|
|
$this->insertLogPacket($logPacket);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
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'];
|
|
$T_PacketStartDate = date('Y-m-d', strtotime($prm["T_PacketStartDate"]));
|
|
$T_PacketEndDate = date('Y-m-d', strtotime($prm["T_PacketEndDate"]));
|
|
$T_PacketIsOptional = $prm['isOpsional'];
|
|
// $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 nama paket", $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('PCPN') as numberx";
|
|
if ($T_PacketType == 'PR') {
|
|
$sql_get_numbering = "SELECT fn_numbering_cpone('PCPR') 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_PacketOriginalBruto,
|
|
T_PacketStartDate,
|
|
T_PacketEndDate,
|
|
T_PacketIsOptional,
|
|
T_PacketIsActive,
|
|
T_PacketCreated
|
|
) VALUES (?,?,?,?,?,?,?,?,?,?,'Y',NOW())";
|
|
|
|
$qryInsert = $this->db_onedev->query($sql_insert, [
|
|
$T_PriceHeaderID,
|
|
$T_PacketType,
|
|
$T_PacketName,
|
|
$T_PacketPrice,
|
|
$T_PacketOriginalPrice,
|
|
$T_PacketSasCode,
|
|
$T_PacketOriginalBruto,
|
|
$T_PacketStartDate,
|
|
$T_PacketEndDate,
|
|
$T_PacketIsOptional
|
|
]);
|
|
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,
|
|
);
|
|
$dataAfter = $this->getPacket($last_id);
|
|
$logPacket = [
|
|
'ID' => $last_id,
|
|
'detailID' => '0',
|
|
'type' => 'INSERT PACKET',
|
|
'desc' => "Insert paket",
|
|
'prm' => $prm,
|
|
'dataBefore' => '',
|
|
'dataAfter' => $dataAfter,
|
|
'userID' => $this->sys_user["M_UserID"],
|
|
];
|
|
$this->insertLogPacket($logPacket);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
} else {
|
|
// check paket exists or not
|
|
//echo "IIN";
|
|
$sqlCheck = "SELECT *
|
|
FROM t_packet
|
|
WHERE T_PacketIsActive = 'Y'
|
|
AND T_PacketName = '$T_PacketName'
|
|
AND T_PacketID <> {$prm["xid"]}";
|
|
|
|
// echo $sqlCheck;
|
|
// exit;
|
|
|
|
$qryCheck = $this->db_onedev->query($sqlCheck);
|
|
|
|
if (!$qryCheck) {
|
|
$this->sys_error_db("t_packet check nama paket", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rowCheck = $qryCheck->result_array();
|
|
//print_r($rowCheck);
|
|
if (count($rowCheck) > 0) {
|
|
// echo $sqlCheck;
|
|
// exit;
|
|
$this->sys_error("Data dengan nama paket " . $T_PacketName . " Sudah Ada", $this->db_onedev);
|
|
exit;
|
|
} else {
|
|
$dataBefore = $this->getPacket($prm["xid"]);
|
|
$sql = "SELECT LEFT(T_PacketSasCode, 2) as PCPREFIX, T_PacketType as PCTYPE
|
|
FROM t_packet
|
|
WHERE
|
|
T_PacketID = {$prm["xid"]}";
|
|
$qryCheckNumber = $this->db_onedev->query($sql);
|
|
|
|
if (!$qryCheckNumber) {
|
|
$this->sys_error_db("t_packet check nama paket", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rowCheckNumber = $qryCheckNumber->row_array();
|
|
//print_r($rowCheckNumber);
|
|
$update_numbering = "";
|
|
if ($rowCheckNumber['PCPREFIX'] != $rowCheckNumber['PCTYPE']) {
|
|
$sql_get_numbering = "SELECT fn_numbering_cpone('PCPN') as numberx";
|
|
if ($T_PacketType == 'PR') {
|
|
$sql_get_numbering = "SELECT fn_numbering_cpone('PCPR') 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;
|
|
}
|
|
|
|
$new_numbering = $qry_get_numbering->row()->numberx;
|
|
$update_numbering = "T_PacketSasCode = '{$new_numbering}', ";
|
|
}
|
|
// update t_packet
|
|
$sql_update = "UPDATE t_packet
|
|
SET
|
|
$update_numbering
|
|
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,
|
|
T_PacketStartDate = '$T_PacketStartDate',
|
|
T_PacketEndDate = '$T_PacketEndDate',
|
|
T_PacketIsOptional = '$T_PacketIsOptional'
|
|
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 , T_PacketSasCode as xcode
|
|
FROM t_packet
|
|
WHERE T_PacketID = {$last_id}";
|
|
|
|
//echo $sql;
|
|
$row = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $row,
|
|
);
|
|
$dataAfter = $this->getPacket($last_id);
|
|
$logPacket = [
|
|
'ID' => $last_id,
|
|
'detailID' => '0',
|
|
'type' => 'UPDATE PACKET',
|
|
'desc' => "UPDATE paket",
|
|
'prm' => $prm,
|
|
'dataBefore' => $dataBefore,
|
|
'dataAfter' => $dataAfter,
|
|
'userID' => $this->sys_user["M_UserID"],
|
|
];
|
|
$this->insertLogPacket($logPacket);
|
|
|
|
$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;
|
|
$dataBefore = $this->getPacket($prm['id']);
|
|
|
|
// 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')
|
|
);
|
|
|
|
$dataAfter = $this->getPacket($prm['id']);
|
|
$logPacket = [
|
|
'ID' => $prm['id'],
|
|
'detailID' => '0',
|
|
'type' => 'DELETE PACKET',
|
|
'desc' => "delete paket",
|
|
'prm' => $prm,
|
|
'dataBefore' => $dataBefore,
|
|
'dataAfter' => $dataAfter,
|
|
'userID' => $this->sys_user["M_UserID"],
|
|
];
|
|
$this->insertLogPacket($logPacket);
|
|
|
|
$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 = 30;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
|
|
$natsubgroup = "";
|
|
$sql_where_natsubgroup = "";
|
|
|
|
$filter_group = "";
|
|
|
|
if (isset($prm['natsubgroup']) && !empty($prm['natsubgroup']) && $prm['natsubgroup'] != "All") {
|
|
$natsubgroup = $prm['natsubgroup'];
|
|
$sql_where_natsubgroup = " AND Nat_SubGroupID = $natsubgroup";
|
|
$filter_group = " JOIN nat_subgroup
|
|
ON T_TestNat_SubgroupID = Nat_SubgroupID
|
|
AND Nat_SubGroupIsActive = 'Y'";
|
|
}
|
|
|
|
// if($natsubgroup != "All"){
|
|
// $sql_where_natsubgroup = " AND Nat_SubGroupID = $natsubgroup";
|
|
// }
|
|
|
|
$tpriceheader = $prm['tpriceheader'];
|
|
$sql_where_tpriceheader = "";
|
|
|
|
if (isset($prm['tpriceheader']) && intval($prm['tpriceheader']) != 0) {
|
|
|
|
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'
|
|
$filter_group
|
|
$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
|
|
//echo $this->db_onedev->last_query();
|
|
$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'
|
|
$filter_group
|
|
$sql_where
|
|
ORDER BY p.T_PriceID DESC
|
|
limit $number_limit offset $number_offset
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
// echo $this->db_onedev->last_query();
|
|
|
|
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();
|
|
} else {
|
|
$rows = 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,
|
|
T_PriceHeaderIsGenerated
|
|
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']}%' OR T_PacketSasCode 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(tp.T_PacketID, 0) AS T_PacketID,
|
|
tph.T_PriceHeaderName,
|
|
tph.T_PriceHeaderCode,
|
|
IFNULL(tp.T_PacketT_PriceHeaderID, 0) AS T_PacketT_PriceHeaderID,
|
|
IFNULL(tp.T_PacketType,'') AS T_PacketType,
|
|
IFNULL(tp.T_PacketName,'') AS T_PacketName,
|
|
IFNULL(tp.T_PacketPrice,0) AS T_PacketPrice,
|
|
IFNULL(tp.T_PacketOriginalPrice,0) AS T_PacketOriginalPrice,
|
|
IFNULL(tp.T_PacketSasCode,'') AS T_PacketSasCode,
|
|
IFNULL(tp.T_PacketIsActive,'') AS T_PacketIsActive,
|
|
IFNULL(tp.T_PacketCreated,'') AS T_PacketCreated,
|
|
IFNULL(tp.T_PacketLastUpdated,'') AS T_PacketLastUpdated,
|
|
IFNULL(tp.T_PacketStartDate, '0000-00-00 00:00:00') AS T_PacketStartDate,
|
|
IFNULL(tp.T_PacketEndDate, '0000-00-00 00:00:00') AS T_PacketEndDate,
|
|
IFNULL(DATE_FORMAT(tp.T_PacketStartDate,'%d-%m-%Y'), '0000-00-00 00:00:00') AS T_PacketStartDateTxt,
|
|
IFNULL(DATE_FORMAT(tp.T_PacketEndDate,'%d-%m-%Y'), '0000-00-00 00:00:00') AS T_PacketEndDateTxt,
|
|
tp.T_PacketIsValidated,
|
|
tp.T_PacketValidatedCode,
|
|
tp.T_PacketIsGenerated,
|
|
tp.T_PacketGeneratedDate,
|
|
IFNULL(logx.LogTotal, 0) AS LogTotal
|
|
FROM t_packet tp
|
|
JOIN t_priceheader tph
|
|
ON tp.T_PacketT_PriceHeaderID = tph.T_PriceHeaderID
|
|
AND tph.T_PriceHeaderIsActive = 'Y'
|
|
LEFT JOIN (
|
|
SELECT
|
|
LogPacketT_PacketID,
|
|
COUNT(*) AS LogTotal
|
|
FROM ".$this->db_cpone_log->database.".log_packet
|
|
GROUP BY LogPacketT_PacketID
|
|
) logx ON logx.LogPacketT_PacketID = tp.T_PacketID
|
|
WHERE $sql_where
|
|
GROUP BY tp.T_PacketID
|
|
ORDER BY tp.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,
|
|
T_PacketIsOptional,
|
|
IFNULL(T_PacketStartDate, '0000-00-00 00:00:00') AS T_PacketStartDate,
|
|
IFNULL(T_PacketEndDate, '0000-00-00 00:00:00') AS T_PacketEndDate,
|
|
'' 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;
|
|
}
|
|
function getPacket($id)
|
|
{
|
|
$sql = "SELECT
|
|
tp.*,
|
|
IFNULL(mu_valid.M_UserFullName, '') AS T_PacketValidatedUserName,
|
|
IFNULL(mu_create.M_UserFullName, '') AS T_PacketCreatedUserName,
|
|
IFNULL(mu_update.M_UserFullName, '') AS T_PacketLastUpdatedUserName
|
|
FROM t_packet tp
|
|
LEFT JOIN m_user mu_valid
|
|
ON mu_valid.M_UserID = tp.T_PacketValidatedUserID
|
|
LEFT JOIN m_user mu_create
|
|
ON mu_create.M_UserID = tp.T_PacketCreatedUserID
|
|
LEFT JOIN m_user mu_update
|
|
ON mu_update.M_UserID = tp.T_PacketLastUpdatedUserID
|
|
WHERE tp.T_PacketID = ?";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$header = $query->row_array();
|
|
if (!$header) {
|
|
return array();
|
|
}
|
|
|
|
if (!empty($header['T_PacketValidatedUserName'])) {
|
|
$header['T_PacketValidatedUserID'] = $header['T_PacketValidatedUserName'];
|
|
} else {
|
|
$header['T_PacketValidatedUserID'] = '-';
|
|
}
|
|
|
|
$sql = "SELECT
|
|
tpd.*,
|
|
IFNULL(tt.T_TestName, '') AS T_TestName
|
|
FROM t_packetdetail tpd
|
|
LEFT JOIN t_test tt
|
|
ON tt.T_TestID = tpd.T_PacketDetailT_TestID
|
|
WHERE tpd.T_PacketDetailT_PacketID = ?
|
|
AND tpd.T_PacketDetailIsActive = 'Y'
|
|
ORDER BY tpd.T_PacketDetailID ASC";
|
|
$query = $this->db_onedev->query($sql, [$id]);
|
|
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$detail = $query->result_array();
|
|
|
|
usort($detail, function($a, $b) {
|
|
return (int)$a['T_PacketDetailT_TestID'] <=> (int)$b['T_PacketDetailT_TestID'];
|
|
});
|
|
|
|
$header['detail'] = $detail;
|
|
|
|
return $header;
|
|
}
|
|
function insertLogPacket($data)
|
|
{
|
|
$sql = "INSERT INTO cpone_log.log_packet
|
|
(LogPacketT_PacketID,
|
|
LogPacketT_PacketDetailID,
|
|
LogPacketType,
|
|
LogPacketDesc,
|
|
LogPacketPrm,
|
|
LogPacketJsonBefore,
|
|
LogPacketJsonAfter,
|
|
LogPacketUserID,
|
|
LogPacketCreated)
|
|
VALUES(?,?,?,?,?,?,?,?, NOW())";
|
|
$query = $this->db_cpone_log->query($sql, [
|
|
$data['ID'],
|
|
$data['detailID'],
|
|
$data['type'],
|
|
$data['desc'],
|
|
$data['prm'] == '' ? '' : json_encode($data['prm']),
|
|
$data['dataBefore'] == '' ? '' : json_encode($data['dataBefore']),
|
|
$data['dataAfter'] == '' ? '' : json_encode($data['dataAfter']),
|
|
$data['userID']
|
|
]);
|
|
// [
|
|
// 'ID' => $data[''],
|
|
// 'detailID' => $data[''],
|
|
// 'type' => $data[''],
|
|
// 'desc' => $data[''],
|
|
// 'prm' => $data[''],
|
|
// 'dataBefore' => $data[''],
|
|
// 'dataAfter ' => $data[''],
|
|
// 'userID ' => $data[''],
|
|
// ];
|
|
if (!$query) {
|
|
$message = $this->db_cpone_log->error();
|
|
$message['qry'] = $this->db_cpone_log->last_query();
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error($message);
|
|
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);
|
|
}
|
|
}
|
|
|
|
public function searchTPriceHeader()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT * FROM t_priceheader WHERE T_PriceHeaderName LIKE '%{$prm['search']}%'";
|
|
$query = $this->db_onedev->query($sql);
|
|
$this->sys_ok($query->result_array());
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function validatePacket() {
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$param = $this->sys_input;
|
|
$user = $this->sys_user;
|
|
$dataBefore = $this->getPacket($param['packetID']);
|
|
|
|
$this->db_onedev->trans_begin();
|
|
|
|
// check nat test
|
|
$sql_detailist = "SELECT T_PacketDetailID, T_PacketDetailT_TestID
|
|
FROM t_packetdetail
|
|
WHERE T_PacketDetailT_PacketID = ?
|
|
AND T_PacketDetailIsActive= 'Y'";
|
|
$que_detailist = $this->db_onedev->query($sql_detailist, [$param['packetID']]);
|
|
if (!$que_detailist) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] get detail item");
|
|
exit;
|
|
}
|
|
|
|
$packetdetail = $que_detailist->result_array();
|
|
|
|
$unique_nattest = array();
|
|
foreach ($packetdetail as $key => $item) {
|
|
$sql_nattest = "WITH RECURSIVE TestNatTest AS (
|
|
SELECT
|
|
T_TestID,
|
|
T_TestCode,
|
|
T_TestSasCode,
|
|
T_TestName,
|
|
T_TestNat_TestID,
|
|
T_TestParentT_TestID
|
|
FROM t_test
|
|
WHERE T_TestIsActive = 'Y'
|
|
AND T_TestID = ?
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
t.T_TestID,
|
|
t.T_TestCode,
|
|
t.T_TestSasCode,
|
|
t.T_TestName,
|
|
t.T_TestNat_TestID,
|
|
t.T_TestParentT_TestID
|
|
FROM t_test t
|
|
INNER JOIN TestNatTest tnt ON t.T_TestParentT_TestID = tnt.T_TestID
|
|
WHERE t.T_TestIsActive = 'Y'
|
|
)
|
|
|
|
SELECT
|
|
T_TestID,
|
|
T_TestName,
|
|
T_TestNat_TestID
|
|
FROM TestNatTest
|
|
ORDER BY T_TestParentT_TestID, T_TestNat_TestID";
|
|
$que_nattest = $this->db_onedev->query($sql_nattest, [
|
|
$item['T_PacketDetailT_TestID']
|
|
]);
|
|
$nattest = $que_nattest->result_array();
|
|
|
|
foreach ($nattest as $key => $nat) {
|
|
if (!isset($unique_nattest[$nat['T_TestNat_TestID']])) {
|
|
$unique_nattest[$nat['T_TestNat_TestID']] = $nattest[0]['T_TestName'];
|
|
} else {
|
|
$msg = "Test " . $nat['T_TestName'] . " pada " . $nattest[0]['T_TestName']
|
|
. " sudah termasuk dalam test " . $unique_nattest[$nat['T_TestNat_TestID']];
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error("[Error] {$msg}");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// gen code
|
|
$sql_code = "SELECT fn_numbering_cpone('PKTVL') as valcode";
|
|
$que_code = $this->db_onedev->query($sql_code, []);
|
|
if (!$que_code) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] update header table t_packet");
|
|
exit;
|
|
}
|
|
$valcode = $que_code->row_array()['valcode'];
|
|
|
|
// update table
|
|
$sql_header = "UPDATE t_packet SET
|
|
T_PacketIsValidated = 'Y',
|
|
T_PacketValidatedCode = ?,
|
|
T_PacketValidatedDate = NOW(),
|
|
T_PacketValidatedUserID = ?,
|
|
T_PacketLastUpdated = NOW()
|
|
WHERE T_PacketID = ?
|
|
AND T_PacketIsActive = 'Y'";
|
|
$que_header = $this->db_onedev->query($sql_header, [
|
|
$valcode, $user['M_UserID'], $param['packetID']
|
|
]);
|
|
if (!$que_header) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] update header table t_packet");
|
|
exit;
|
|
}
|
|
|
|
$sql_detail = "UPDATE t_packetdetail SET
|
|
T_PacketValidatedCode = ?,
|
|
T_PacketDetailLastUpdated = NOW()
|
|
WHERE T_PacketDetailT_PacketID = ?
|
|
AND T_PacketDetailIsActive = 'Y'";
|
|
$que_detail = $this->db_onedev->query($sql_detail, [
|
|
$valcode, $param['packetID']
|
|
]);
|
|
if (!$que_detail) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] update header table t_packetdetail");
|
|
exit;
|
|
}
|
|
|
|
// run ss price
|
|
$ssprice = $this->create_ss_price($user['M_UserID'], $param['priceHeaderID']);
|
|
if (!$ssprice) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] func ssprice");
|
|
exit;
|
|
}
|
|
|
|
$dataAfter = $this->getPacket($param['packetID']);
|
|
$logPacket = [
|
|
'ID' => $param['packetID'],
|
|
'detailID' => '0',
|
|
'type' => 'VALIDATE',
|
|
'desc' => "Validate price and packet, price id {$param['priceHeaderID']}",
|
|
'prm' => $param,
|
|
'dataBefore' => $dataBefore,
|
|
'dataAfter' => $dataAfter,
|
|
'userID' => $this->sys_user["M_UserID"],
|
|
];
|
|
$this->insertLogPacket($logPacket);
|
|
$this->db_onedev->trans_commit();
|
|
$this->sys_ok("[Success] validation success");
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
private function create_ss_price($userid, $id) {
|
|
$this->load->library("SsPriceMou");
|
|
// $sql = "SELECT * FROM temp_validation_price WHERE status = 'N' LIMIT 30";
|
|
// $que = $this->db_onedev->query($sql);
|
|
// if (!$que) {
|
|
// return false;
|
|
// }
|
|
// $dt_price_header = $que->result_array();
|
|
|
|
// if(count($dt_price_header) > 0) {
|
|
// foreach ($dt_price_header as $k_price_header => $v_price_header) {
|
|
|
|
// $id = $v_price_header['T_PriceHeaderID'];
|
|
|
|
$sql = "UPDATE t_priceheader
|
|
SET T_PriceHeaderValidasi = 'Y',
|
|
T_PriceHeaderValidasiDate = NOW(),
|
|
T_PriceHeaderValidasiUserID = {$userid},
|
|
T_PriceHeaderIsGenerated = 'Y',
|
|
T_PriceHeaderGeneratedDate = NOW()
|
|
WHERE T_PriceHeaderID = $id";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
return false;
|
|
}
|
|
|
|
$sql = "UPDATE t_price
|
|
SET T_PriceValidasi = 'Y',
|
|
T_PriceValidasiDate = NOW(),
|
|
T_PriceValidasiDateUserID = {$userid},
|
|
T_PriceIsGenerated = 'Y',
|
|
T_PriceIsGeneratedDate = NOW()
|
|
WHERE T_PriceT_PriceHeaderID = $id
|
|
AND T_PriceValidasi = 'N'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
return false;
|
|
}
|
|
|
|
$sql = "UPDATE t_packet
|
|
SET T_PacketIsGenerated = 'Y',
|
|
T_PacketGeneratedDate = NOW()
|
|
WHERE T_PacketT_PriceHeaderID = $id";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
return false;
|
|
}
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
$this->sspricemou->create($id);
|
|
|
|
$sql = "UPDATE temp_validation_price SET status = 'Y' WHERE T_PriceHeaderID = $id";
|
|
$que = $this->db_onedev->query($sql);
|
|
if (!$que) {
|
|
return false;
|
|
}
|
|
|
|
// echo $v_price_header['T_PriceHeaderID'].'<br>';
|
|
// }
|
|
// }
|
|
|
|
return true;
|
|
}
|
|
|
|
public function unValidatePacket() {
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid token");
|
|
exit;
|
|
}
|
|
|
|
$param = $this->sys_input;
|
|
$user = $this->sys_user;
|
|
$dataBefore = $this->getPacket($param['packetID']);
|
|
|
|
$this->db_onedev->trans_begin();
|
|
|
|
$sql_header = "UPDATE t_packet SET
|
|
T_PacketIsGenerated = 'N',
|
|
T_PacketIsValidated = 'N',
|
|
T_PacketValidatedCode = '',
|
|
T_PacketValidatedDate = null,
|
|
T_PacketValidatedUserID = 0
|
|
WHERE T_PacketID = ?";
|
|
$que_header = $this->db_onedev->query($sql_header, [$param['packetID']]);
|
|
if (!$que_header) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] update header table t_packet");
|
|
exit;
|
|
}
|
|
|
|
$sql_detailist = "SELECT T_PacketDetailID
|
|
FROM t_packetdetail
|
|
WHERE T_PacketDetailT_PacketID = ?
|
|
AND T_PacketDetailIsActive = 'Y'";
|
|
$que_detailist = $this->db_onedev->query($sql_detailist, [$param['packetID']]);
|
|
if (!$que_detailist) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] update header table t_packet");
|
|
exit;
|
|
}
|
|
$list_detail = $que_detailist->result_array();
|
|
|
|
$sql_detail = "UPDATE t_packetdetail
|
|
SET T_PacketDetailIsActive = 'N',
|
|
T_PacketDetailLastUpdated = NOW()
|
|
WHERE T_PacketDetailT_PacketID = ?
|
|
AND T_PacketDetailIsActive = 'Y'";
|
|
$que_detail = $this->db_onedev->query($sql_detail, [$param['packetID']]);
|
|
if (!$que_detail) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("[Error] update detail is active");
|
|
exit;
|
|
}
|
|
|
|
$detailID = array_map(function($item) {
|
|
return $item['T_PacketDetailID'];
|
|
}, $list_detail);
|
|
$placeholders = implode(', ', array_fill(0, count($detailID), '?'));
|
|
|
|
$sql_detailins = "INSERT INTO t_packetdetail (
|
|
T_PacketDetailT_PacketID,
|
|
T_PacketDetailT_TestID,
|
|
T_PacketDetailOriginalPrice,
|
|
T_PacketDetailPrice,
|
|
T_PacketDetailCreated,
|
|
T_PacketDetailPriceAmount,
|
|
T_PacketDetailPriceDisc,
|
|
T_PacketDetailPriceDiscRp,
|
|
T_PacketDetailPriceSubTotal
|
|
) SELECT
|
|
tpd.T_PacketDetailT_PacketID,
|
|
tpd.T_PacketDetailT_TestID,
|
|
tpd.T_PacketDetailOriginalPrice,
|
|
tpd.T_PacketDetailPrice,
|
|
NOW(),
|
|
tpd.T_PacketDetailPriceAmount,
|
|
tpd.T_PacketDetailPriceDisc,
|
|
tpd.T_PacketDetailPriceDiscRp,
|
|
tpd.T_PacketDetailPriceSubTotal
|
|
FROM t_packetdetail tpd
|
|
WHERE tpd.T_PacketDetailID IN ({$placeholders})";
|
|
$que_detailins = $this->db_onedev->query($sql_detailins, $detailID);
|
|
if (!$que_detailins) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db();
|
|
exit;
|
|
}
|
|
|
|
$dataAfter = $this->getPacket($param['packetID']);
|
|
$logPacket = [
|
|
'ID' => $param['packetID'],
|
|
'detailID' => '0',
|
|
'type' => 'UNVALIDATE',
|
|
'desc' => "Unvalidate packet",
|
|
'prm' => $param,
|
|
'dataBefore' => $dataBefore,
|
|
'dataAfter' => $dataAfter,
|
|
'userID' => $this->sys_user["M_UserID"],
|
|
];
|
|
$this->insertLogPacket($logPacket);
|
|
$this->db_onedev->trans_commit();
|
|
$this->sys_ok("[Success] unvalidate packet");
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
private function safe_json_decode_array($json_string)
|
|
{
|
|
if (!isset($json_string) || $json_string === '' || $json_string === null) {
|
|
return array();
|
|
}
|
|
|
|
$decoded = json_decode($json_string, true);
|
|
if (json_last_error() !== JSON_ERROR_NONE || !is_array($decoded)) {
|
|
return array();
|
|
}
|
|
|
|
return $decoded;
|
|
}
|
|
|
|
private function getUserMap()
|
|
{
|
|
$sql = "SELECT M_UserID, M_UserFullName
|
|
FROM m_user
|
|
WHERE M_UserIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
return array();
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
$map = array();
|
|
|
|
foreach ($rows as $row) {
|
|
$map[$row['M_UserID']] = $row['M_UserFullName'];
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
private function getTestMap()
|
|
{
|
|
$sql = "SELECT T_TestID, T_TestName
|
|
FROM t_test
|
|
WHERE T_TestIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
return array();
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
$map = array();
|
|
|
|
foreach ($rows as $row) {
|
|
$map[$row['T_TestID']] = $row['T_TestName'];
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
private function getPacketTypeMap()
|
|
{
|
|
$sql = "SELECT T_PacketID, T_PacketName, T_PacketSasCode
|
|
FROM t_packet
|
|
WHERE T_PacketIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
return array();
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
$map = array();
|
|
|
|
foreach ($rows as $row) {
|
|
$map[$row['T_PacketID']] = array(
|
|
'name' => $row['T_PacketName'],
|
|
'code' => $row['T_PacketSasCode']
|
|
);
|
|
}
|
|
|
|
return $map;
|
|
}
|
|
|
|
private function transformPacketLogJson($json_string)
|
|
{
|
|
$data = $this->safe_json_decode_array($json_string);
|
|
if (empty($data)) {
|
|
return array();
|
|
}
|
|
|
|
$userMap = $this->getUserMap();
|
|
$testMap = $this->getTestMap();
|
|
|
|
if (isset($data['T_PacketValidatedUserID'])) {
|
|
$uid = (int)$data['T_PacketValidatedUserID'];
|
|
|
|
if ($uid > 0 && isset($userMap[$uid]) && $userMap[$uid] != '') {
|
|
$data['T_PacketValidatedUserID'] = $userMap[$uid];
|
|
} else {
|
|
$data['T_PacketValidatedUserID'] = '-';
|
|
}
|
|
}
|
|
|
|
if (isset($data['detail']) && is_array($data['detail'])) {
|
|
foreach ($data['detail'] as $k => $detail) {
|
|
$testId = 0;
|
|
|
|
if (isset($detail['T_PacketDetailT_TestID'])) {
|
|
$testId = (int)$detail['T_PacketDetailT_TestID'];
|
|
} elseif (isset($detail['T_TestID'])) {
|
|
$testId = (int)$detail['T_TestID'];
|
|
}
|
|
|
|
if (!isset($data['detail'][$k]['T_TestName']) || $data['detail'][$k]['T_TestName'] == '') {
|
|
$data['detail'][$k]['T_TestName'] = isset($testMap[$testId]) ? $testMap[$testId] : '-';
|
|
}
|
|
|
|
if (!isset($data['detail'][$k]['T_PacketDetailPrice']) && isset($detail['T_PriceTotalPacket'])) {
|
|
$data['detail'][$k]['T_PacketDetailPrice'] = $detail['T_PriceTotalPacket'];
|
|
}
|
|
}
|
|
|
|
usort($data['detail'], function($a, $b) {
|
|
$aId = isset($a['T_PacketDetailT_TestID']) ? (int)$a['T_PacketDetailT_TestID'] : 0;
|
|
$bId = isset($b['T_PacketDetailT_TestID']) ? (int)$b['T_PacketDetailT_TestID'] : 0;
|
|
return $aId <=> $bId;
|
|
});
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getPacketLogs()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$packetId = isset($prm['T_PacketID']) ? (int)$prm['T_PacketID'] : 0;
|
|
|
|
if ($packetId <= 0) {
|
|
$this->sys_error("T_PacketID tidak valid");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT
|
|
lp.LogPacketID,
|
|
lp.LogPacketT_PacketID,
|
|
lp.LogPacketT_PacketDetailID,
|
|
lp.LogPacketType,
|
|
lp.LogPacketDesc,
|
|
lp.LogPacketPrm,
|
|
lp.LogPacketJsonBefore,
|
|
lp.LogPacketJsonAfter,
|
|
lp.LogPacketUserID,
|
|
lp.LogPacketCreated,
|
|
IFNULL(mu.M_UserFullName, '') AS LogPacketUserName
|
|
FROM log_packet lp
|
|
LEFT JOIN ".$this->db_onedev->database.".m_user mu
|
|
ON mu.M_UserID = lp.LogPacketUserID
|
|
WHERE lp.LogPacketT_PacketID = {$packetId}
|
|
ORDER BY lp.LogPacketCreated DESC, lp.LogPacketID DESC";
|
|
|
|
$qry = $this->db_cpone_log->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("get packet logs", $this->db_cpone_log);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
foreach ($rows as $key => $row) {
|
|
$rows[$key]['LogPacketPrmParsed'] = $this->safe_json_decode_array($row['LogPacketPrm']);
|
|
$rows[$key]['LogPacketJsonBeforeParsed'] = $this->transformPacketLogJson($row['LogPacketJsonBefore']);
|
|
$rows[$key]['LogPacketJsonAfterParsed'] = $this->transformPacketLogJson($row['LogPacketJsonAfter']);
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_cpone_log->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|