db_onedev = $this->load->database("onedev", 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 ) 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 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, 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' => '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(T_PacketID, 0) AS T_PacketID, T_PriceHeaderName, T_PriceHeaderCode, 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, IFNULL(T_PacketStartDate, '0000-00-00 00:00:00') AS T_PacketStartDate, IFNULL(T_PacketEndDate, '0000-00-00 00:00:00') AS T_PacketEndDate, IFNULL(DATE_FORMAT(T_PacketStartDate,'%d-%m-%Y'), '0000-00-00 00:00:00') AS T_PacketStartDateTxt, IFNULL(DATE_FORMAT(T_PacketEndDate,'%d-%m-%Y'), '0000-00-00 00:00:00') AS T_PacketEndDateTxt, T_PacketIsGenerated, T_PacketGeneratedDate FROM t_packet JOIN t_priceheader ON T_PacketT_PriceHeaderID = T_PriceHeaderID AND T_PriceHeaderIsActive = 'Y' 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, 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 * FROM t_packet WHERE 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(); $sql = "SELECT * FROM t_packetdetail WHERE T_PacketDetailT_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; } $detail = $query->result_array(); $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_onedev->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_onedev->error(); $message['qry'] = $this->db_onedev->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); } } }