774 lines
25 KiB
PHP
774 lines
25 KiB
PHP
<?php
|
|
|
|
class Pricecopyjpa_v6 extends MY_Controller
|
|
{
|
|
var $db_regional;
|
|
|
|
public function index()
|
|
{
|
|
echo "Price API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_regional = $this->load->database("regional", true);
|
|
}
|
|
|
|
public function search_company()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 999999999;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select distinct count(*) total
|
|
from m_company
|
|
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
|
|
and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now())
|
|
where M_CompanyIsActive = 'Y' and M_CompanyName LIKE ?
|
|
order by M_CompanyName ASC";
|
|
$query = $this->db_regional->query($sql, ['%'.$prm['search'].'%']);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("price company count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select distinct M_CompanyID, M_CompanyName
|
|
from m_company
|
|
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
|
|
-- and M_MouStartDate <= date(now())
|
|
and M_MouEndDate >= date(now())
|
|
where M_CompanyIsActive = 'Y' and M_CompanyName LIKE ?
|
|
order by M_CompanyName ASC
|
|
limit 0, {$max_rst}";
|
|
$query = $this->db_regional->query($sql, ['%'.$prm['search'].'%']);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price company rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_mou()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 999999999;
|
|
|
|
$search = '%' . $prm["search"] . '%';
|
|
$company = $prm["company_id"];
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from m_mou
|
|
where M_MouIsActive = 'Y'
|
|
and M_MouM_CompanyID = ?
|
|
and M_MouName LIKE ?
|
|
|
|
-- and date(now()) >= M_MouStartDate
|
|
and date(now()) <= M_MouEndDate
|
|
order by M_MouName ASC";
|
|
$query = $this->db_regional->query($sql, [$company, $search]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select M_MouID, M_MouName, M_MouStartDate, M_MouEndDate, M_MouIsVerified
|
|
from m_mou
|
|
where M_MouIsActive = 'Y'
|
|
and M_MouM_CompanyID = ?
|
|
and M_MouName LIKE ?
|
|
|
|
-- and date(now()) >= M_MouStartDate
|
|
and date(now()) <= M_MouEndDate
|
|
order by M_MouName ASC
|
|
limit 0, {$max_rst}";
|
|
$query = $this->db_regional->query($sql, [$company, $search]);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_price()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 10;
|
|
|
|
$search = '%' . $prm["search"] . '%';
|
|
$mou = $prm["mou_id"];
|
|
$page = $prm['page'];
|
|
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from t_price
|
|
join t_test on t_pricet_testid = t_testid
|
|
where T_PriceIsActive = 'Y'
|
|
and T_PriceM_MouID = ?
|
|
and T_TestName LIKE ?
|
|
order by T_TestName ASC";
|
|
$query = $this->db_regional->query($sql, [$mou, $search]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_PriceID, T_TestID, T_TestCode, T_TestName, T_PriceIsCito,
|
|
T_TestSasCode,
|
|
T_PriceM_CompanyID,
|
|
T_PriceM_MouID,
|
|
T_PricePriority,
|
|
T_PriceAmount,
|
|
T_PriceDisc,
|
|
T_PriceDiscRp,
|
|
T_PriceSubTotal,
|
|
T_PriceOther,
|
|
T_PriceTotal,
|
|
JSON_OBJECT('T_TestID', T_TestID, 'T_TestCode', T_TestCode, 'T_TestName', T_TestName) px,
|
|
M_MouIsVerified,
|
|
IFNULL(fn_pricecopyjpa_v4_have_packet(M_MouID, T_TestID),'N') as havepacket
|
|
from t_price
|
|
join t_test on t_pricet_testid = t_testid
|
|
join m_mou on t_pricem_mouid = m_mouid
|
|
|
|
where T_PriceIsActive = 'Y'
|
|
and T_PriceM_MouID = ?
|
|
and T_TestName LIKE ?
|
|
order by T_TestSasCode ASC
|
|
limit {$offset}, {$max_rst}";
|
|
$query = $this->db_regional->query($sql, [$mou, $search]);
|
|
//echo $this->db_regional->last_query();
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
|
|
foreach ($rows as $k => $v)
|
|
{
|
|
$rows[$k]['px'] = json_decode($v['px']);
|
|
|
|
$sql = "select t_addonid id, t_addonname name, t_priceaddonamount price
|
|
from t_priceaddon
|
|
join t_addon on t_priceaddont_addonid = t_addonid
|
|
where t_priceaddont_priceid = ?
|
|
and t_priceaddonisactive = 'Y'";
|
|
|
|
$query = $this->db_regional->query($sql, [$v['T_PriceID']]);
|
|
|
|
$rows2 = [];
|
|
if ($query)
|
|
{
|
|
$rows2 = $query->result_array();
|
|
}
|
|
|
|
$rows[$k]['others'] = $rows2;
|
|
}
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_page" => ceil($tot_count/$max_rst), "cur_page" => $page, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
public function deleteallprice()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$id = $prm["id"];
|
|
|
|
$sql = "update t_price
|
|
set t_priceisactive = 'N'
|
|
where T_PriceIsActive = 'Y'
|
|
and T_PriceM_MouID = ?";
|
|
$query = $this->db_regional->query($sql, [$id]);
|
|
$querypacket = $this->db_regional->query("CALL sp_master_price_delete_packet_v4('{$id}')");
|
|
|
|
if ($query)
|
|
{
|
|
/*
|
|
$sql = "update t_priceaddon
|
|
set t_priceaddonisactive = 'N'
|
|
where T_PriceaddonIsActive = 'Y'
|
|
and t_priceaddont_priceid = ?";
|
|
$query = $this->db_regional->query($sql, [$id]);
|
|
*/
|
|
$result = array("query"=>$this->db_regional->last_query(), "id"=>$id);
|
|
$this->sys_ok($result);
|
|
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function del_price()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$id = $prm["id"];
|
|
|
|
$sql = "update t_price
|
|
set t_priceisactive = 'N'
|
|
where T_PriceIsActive = 'Y'
|
|
and T_PriceID = ?";
|
|
$query = $this->db_regional->query($sql, [$id]);
|
|
|
|
if ($query)
|
|
{
|
|
$sql = "update t_priceaddon
|
|
set t_priceaddonisactive = 'N'
|
|
where T_PriceaddonIsActive = 'Y'
|
|
and t_priceaddont_priceid = ?";
|
|
$query = $this->db_regional->query($sql, [$id]);
|
|
|
|
$result = array("query"=>$this->db_regional->last_query(), "id"=>$id);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_px()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 50;
|
|
|
|
$search = '%' . $prm["search"] . '%';
|
|
$cito = $prm["cito"];
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from t_test
|
|
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where T_TestIsActive = 'Y'
|
|
and T_TestName LIKE ?
|
|
and T_TestIsPrice = 'Y' AND Nat_TestTypeName <> 'Profile'
|
|
and T_TestID not in (
|
|
select T_PriceT_TestID from t_price where T_PriceM_MouID = ? and T_PriceIsActive = 'Y'
|
|
and T_PriceIsCito = ? )
|
|
order by T_TestName ASC";
|
|
$mou_id = $prm["mou_id"];
|
|
$query = $this->db_regional->query($sql, [$search,$mou_id,$cito]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("px count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_TestID, T_TestCode, T_TestSasCode, CONCAT('[',T_TestSasCode,'] ',T_TestName) T_TestName, Nat_TestTypeName, CONCAT(Nat_TestTypeName, ' | ', T_TestSasCode) as description
|
|
from t_test
|
|
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where T_TestIsActive = 'Y'
|
|
and T_TestName LIKE ?
|
|
and T_TestIsPrice = 'Y' AND Nat_TestTypeName <> 'Profile'
|
|
and T_TestID not in (
|
|
select T_PriceT_TestID from t_price where T_PriceM_MouID = ? and T_PriceIsActive = 'Y'
|
|
and T_PriceIsCito = ? )
|
|
order by T_TestSasCode ASC
|
|
limit 0, {$max_rst}";
|
|
$query = $this->db_regional->query($sql, [$search,$mou_id,$cito]);
|
|
// echo $this->db_regional->last_query();
|
|
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("px rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function save_px()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 50;
|
|
|
|
$data = $prm["data"];
|
|
$data_others = $prm["data_others"];
|
|
|
|
$a = (array) json_decode($prm["data"]);
|
|
$mouid = $a['mou_id'];
|
|
$sql = $this->db_regional->query("SELECT M_MouIsVerified as isverif FROM m_mou
|
|
WHERE M_MouID = '{$mouid}'")->row();
|
|
$isverif = $sql->isverif;
|
|
|
|
if($isverif == 'N'){
|
|
// QUERY
|
|
// $sql = "INSERT INTO t_addon(T_AddonName) values('{$name}')";
|
|
$query = $this->db_regional->query("CALL sp_master_price_save_v4b('{$data}', '{$data_others}', '0')");
|
|
|
|
if ($query) {
|
|
$result = $query->row();
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
else {
|
|
$this->sys_error_db("addon new", $this->db_regional);
|
|
exit;
|
|
}
|
|
}else{
|
|
$this->sys_error_db("Agreement Sudah Verified", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
public function search_addon()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 50;
|
|
|
|
$search = '%' . $prm["search"] . '%';
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from t_addon
|
|
where T_AddonIsActive = 'Y'
|
|
and T_AddonName LIKE ?
|
|
order by T_AddonName ASC";
|
|
$query = $this->db_regional->query($sql, [$search]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("addon count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_AddonID, T_AddonName
|
|
from t_addon
|
|
where T_AddonIsActive = 'Y'
|
|
and T_AddonName LIKE ?
|
|
order by T_AddonName ASC
|
|
limit 0, {$max_rst}";
|
|
$query = $this->db_regional->query($sql, [$search]);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("addon rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function save_addon()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 50;
|
|
|
|
$name = $prm["name"];
|
|
|
|
// QUERY
|
|
// $sql = "INSERT INTO t_addon(T_AddonName) values('{$name}')";
|
|
$query = $this->db_regional->set('T_AddonName', $name)
|
|
->insert('t_addon');
|
|
|
|
if ($query) {
|
|
$result = array("inserted_id" => $this->db_regional->insert_id(), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
else {
|
|
$this->sys_error_db("addon new", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_company_2()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$search = '%'.$prm['query'].'%';
|
|
|
|
$max_rst = 25;
|
|
$sql = "SELECT M_CompanyID, M_CompanyName,
|
|
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', M_MouName, 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate) ), ']'), '[]') as mou
|
|
from m_company
|
|
JOIN m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
|
|
and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now())
|
|
where M_CompanyIsActive = 'Y'
|
|
-- sipe ndoy minta di buka
|
|
-- AND M_CompanyID <> {$prm['M_CompanyID']}
|
|
and M_CompanyName LIKE ?
|
|
group by m_companyid
|
|
order by M_CompanyName ASC
|
|
limit 0, {$max_rst}";
|
|
$query = $this->db_regional->query($sql, [$search]);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
foreach ($rows as $k => $v)
|
|
$rows[$k]['mou'] = json_decode($v['mou']);
|
|
|
|
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price company rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
function log_save_setting($user_id,$prm) {
|
|
$sql = "insert into price_copy(
|
|
PriceCopyDate, PriceCopySourceM_MouID, PriceCopyTargetM_CompanyID, PriceCopyTargetM_MouID,
|
|
PriceCopyM_UserID, PriceCopyIsAll, PriceCopyIsActive)
|
|
values(now(), ?,?,?,?,?,'Y')";
|
|
$sourceMouID = $prm["source_id"];
|
|
$targetMouID= $prm["target_id"];
|
|
$targetCompanyID= $prm["company_target_id"];
|
|
$copyAll= $prm["copyall"];
|
|
$qry = $this->db->query($sql, array($sourceMouID, $targetCompanyID, $targetMouID,
|
|
$user_id,$copyAll));
|
|
if ($qry) {
|
|
$priceCopyID = $this->db->insert_id();
|
|
$sql = "insert into price_copydetail(PriceCopyDetailPriceCopyID,PriceCopyDetailNat_JpaGroupID,
|
|
PriceCopyDetailDiscount, PriceCopyDetailIsCheck)
|
|
values(?,?, ?,?)";
|
|
foreach($prm["trx"] as $t) {
|
|
$nat_JpaGroupID = $t["Nat_JPAGroupID"];
|
|
$discount = $t["discount"];
|
|
$isCheck = $t["chex"];
|
|
$this->db->query($sql, array($priceCopyID, $nat_JpaGroupID, $discount, $isCheck));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public function copy_price()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$groups = $prm['trx'];
|
|
$copyall = $prm['copyall'];
|
|
//sipe : tambah save setting saat copy price
|
|
$this->log_save_setting($userid,$prm);
|
|
|
|
//$sql = "CALL sp_master_price_copy(?, ?, ?, 'N')";
|
|
//$query = $this->db_regional->query($sql, [$prm['source_id'], $prm['target_id'], $prm['disc']]);
|
|
if($copyall == 'N'){
|
|
foreach($groups as $k => $v){
|
|
if($v['chex']){
|
|
$sql = "
|
|
INSERT INTO t_price(
|
|
T_PriceT_TestID,
|
|
T_PriceIsCito,
|
|
T_PriceM_MouID,
|
|
T_PricePriority,
|
|
T_PriceAmount,
|
|
T_PriceDisc,
|
|
T_PriceSubTotal,
|
|
T_PriceTotal,
|
|
T_PriceUserID)
|
|
SELECT T_PriceT_TestID,
|
|
T_PriceIsCito,
|
|
{$prm['target_id']},
|
|
T_PricePriority,
|
|
T_PriceAmount,
|
|
{$v['discount']},
|
|
T_PriceAmount - (({$v['discount']}/100) * T_PriceAmount),
|
|
T_PriceAmount - (({$v['discount']}/100) * T_PriceAmount),
|
|
{$userid}
|
|
FROM t_price
|
|
JOIN t_test ON T_PriceT_TestID = T_TestID
|
|
JOIN jpa_test ON JPA_TestNat_TestID = T_TestNat_TestID AND JPA_TestNat_JpaGroupID = {$v['Nat_JPAGroupID']} AND JPA_TestIsActive = 'Y'
|
|
WHERE T_PriceM_MouID = ? AND T_PriceIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql, [$prm['source_id']]);
|
|
if(!$query){
|
|
$this->sys_error_db("price copy", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
//echo $sql;
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
$sql = "INSERT INTO t_price(
|
|
T_PriceT_TestID,
|
|
T_PriceIsCito,
|
|
T_PriceM_MouID,
|
|
T_PricePriority,
|
|
T_PriceAmount,
|
|
T_PriceDisc,
|
|
T_PriceDiscRp,
|
|
T_PriceSubTotal,
|
|
T_PriceTotal,
|
|
T_PriceUserID)
|
|
SELECT T_PriceT_TestID,
|
|
T_PriceIsCito,
|
|
?,
|
|
T_PricePriority,
|
|
T_PriceAmount,
|
|
T_PriceDisc,
|
|
T_PriceDiscRp,
|
|
T_PriceSubTotal,
|
|
T_PriceTotal,
|
|
?
|
|
FROM t_price
|
|
JOIN t_test ON T_PriceT_TestID = T_TestID
|
|
JOIN jpa_test ON JPA_TestNat_TestID = T_TestNat_TestID AND JPA_TestIsActive = 'Y'
|
|
WHERE T_PriceM_MouID = ? AND T_PriceIsActive = 'Y'
|
|
GROUP BY T_PriceT_TestID,T_PriceIsCito";
|
|
|
|
$query = $this->db_regional->query($sql,[$prm['target_id'],$userid,$prm['source_id']]);
|
|
//echo $this->db_regional->last_query();
|
|
|
|
if(!$query){
|
|
$this->sys_error_db("price copy", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM t_packet
|
|
WHERE
|
|
T_PacketM_MouID = {$prm['source_id']} AND T_PacketIsActive = 'Y' ";
|
|
$rows_parent = $this->db_regional->query($sql)->result();
|
|
if($rows_parent){
|
|
foreach($rows_parent as $k => $v){
|
|
//sipe : tambahkan T_PacketOriginalBruto
|
|
$sql = "INSERT INTO t_packet (
|
|
T_PacketM_CompanyID,
|
|
T_PacketM_MouID,
|
|
T_PacketType,
|
|
T_PacketName,
|
|
T_PacketPrice,
|
|
T_PacketOriginalPrice,
|
|
T_PacketIsNota,
|
|
T_PacketSequence,
|
|
T_PacketSasCode,
|
|
T_PacketOriginalBruto
|
|
)
|
|
VALUES(
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
?
|
|
)";
|
|
$query = $this->db_regional->query($sql,array(
|
|
$prm['company_target_id'],
|
|
$prm['target_id'],
|
|
$v->T_PacketType,
|
|
$v->T_PacketName,
|
|
$v->T_PacketPrice,
|
|
$v->T_PacketOriginalPrice,
|
|
$v->T_PacketIsNota,
|
|
$v->T_PacketSequence,
|
|
$v->T_PacketSasCode,
|
|
$v->T_PacketOriginalBruto
|
|
));
|
|
if(!$query){
|
|
$this->sys_error_db("packet copy", $this->db_regional);
|
|
exit;
|
|
}
|
|
$last_id = $this->db_regional->insert_id();
|
|
$sql = "SELECT * FROM t_packetdetail WHERE T_PacketDetailT_PacketID = {$v->T_PacketID} AND T_PacketDetailIsActive = 'Y'";
|
|
$details = $this->db_regional->query($sql)->result();
|
|
if($details){
|
|
foreach($details as $ik => $iv){
|
|
//sipe : tambahkan T_PacketDetailPriceAmount,
|
|
// T_PacketDetailPriceDisc, T_PacketDetailPriceDiscRp, T_PacketDetailPriceSubTotal
|
|
$sql = "INSERT INTO t_packetdetail (
|
|
T_PacketDetailT_PacketID,
|
|
T_PacketDetailT_TestID,
|
|
T_PacketDetailPrice,
|
|
T_PacketDetailPriceAmount,
|
|
T_PacketDetailPriceDisc,
|
|
T_PacketDetailPriceDiscRp,
|
|
T_PacketDetailPriceSubTotal
|
|
)
|
|
VALUES(
|
|
{$last_id},
|
|
{$iv->T_PacketDetailT_TestID},
|
|
{$iv->T_PacketDetailPrice},
|
|
{$iv->T_PacketDetailPriceAmount},
|
|
{$iv->T_PacketDetailPriceDisc},
|
|
{$iv->T_PacketDetailPriceDiscRp},
|
|
{$iv->T_PacketDetailPriceSubTotal}
|
|
)";
|
|
|
|
$query = $this->db_regional->query($sql);
|
|
if(!$query){
|
|
$this->sys_error_db("packet detail copy", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
$result = array("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
public function search_single_company()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT M_CompanyID, M_CompanyName, CONCAT('[', GROUP_CONCAT(JSON_OBJECT('M_MouID', M_MouID, 'M_MouName', M_MouName, 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouIsVerified', M_MouIsVerified) SEPARATOR ','), ']') mou
|
|
from m_company
|
|
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
|
|
-- and M_MouStartDate <= date(now())
|
|
and M_MouEndDate >= date(now()) AND M_MouID = ?
|
|
where M_CompanyIsActive = 'Y'
|
|
GROUP BY M_CompanyID
|
|
order by M_CompanyName ASC";
|
|
$query = $this->db_regional->query($sql, [$prm['id']]);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
$rows[0]['mou'] = json_decode($rows[0]['mou']);
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price company rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function getjpagroups()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "select 'N' as chex, 0 as discount, Nat_JPAGroupID, Nat_JPAGroupName, Nat_JpaGroupMaxPxDisc
|
|
from nat_jpagroup
|
|
where Nat_JPAGroupIsActive = 'Y'";
|
|
$query = $this->db_regional->query($sql, [$company, $search]);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['chex'] = false;
|
|
}
|
|
|
|
$result = array("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search_price_packet()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 10;
|
|
|
|
$search = '%' . $prm["search"] . '%';
|
|
$mou = $prm["mou_id"];
|
|
$page = $prm['page'];
|
|
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "select count(*) total
|
|
from t_packet
|
|
where T_PacketIsActive = 'Y'
|
|
and T_PacketM_MouID = ?
|
|
and T_PacketName LIKE ?
|
|
order by T_PacketName ASC";
|
|
$query = $this->db_regional->query($sql, [$mou, $search]);
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("price mou count", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "select T_PacketID, T_PacketName, T_PacketType,
|
|
T_PacketPrice, T_PacketOriginalPrice,
|
|
T_PacketOriginalPrice - T_PacketPrice discrp
|
|
from t_packet
|
|
where T_PacketIsActive = 'Y'
|
|
and T_PacketM_MouID = ?
|
|
and T_PacketName LIKE ?
|
|
order by T_PacketName ASC
|
|
";
|
|
$query = $this->db_regional->query($sql, [$mou, $search]);
|
|
|
|
if ($query)
|
|
{
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_page" => ceil($tot_count/$max_rst), "cur_page" => $page, "total_display" => sizeof($rows), "q" => $this->db_regional->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("packet mou rows", $this->db_regional);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
?>
|