319 lines
14 KiB
PHP
319 lines
14 KiB
PHP
<?php
|
|
class Edit extends CI_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
//$this->db = $this->load->database('regional', true);
|
|
$this->db = $this->load->database('onedev', true);
|
|
}
|
|
|
|
function do($mouID,$testID) {
|
|
$sql = "select * from t_test where T_TestID = ? ";
|
|
$qry = $this->db->query($sql, array($testID));
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Err : No Test Found!";
|
|
exit;
|
|
}
|
|
$testName = $rows[0]["T_TestName"];
|
|
$sasCode = $rows[0]["T_TestSasCode"];
|
|
if ( strlen($sasCode) == 8 ) {
|
|
$flagProfile = false;
|
|
} else {
|
|
$flagProfile = true;
|
|
}
|
|
|
|
$sql = "select * from m_mou where M_MouID = ?";
|
|
$qry = $this->db->query($sql, array($mouID));
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Err : No Mou Found!";
|
|
exit;
|
|
}
|
|
$mouName = $rows[0]["M_MouName"];
|
|
$companyID = $rows[0]["M_MouM_CompanyID"];
|
|
echo "$mouName : $testName : $sasCode \n";
|
|
|
|
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
|
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
|
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
|
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
|
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
|
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
|
from t_price
|
|
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
|
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
|
and T_TestIsPrice = 'Y'
|
|
join nat_test on T_TestNat_TestID = Nat_TestID
|
|
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
|
where T_PriceM_MouID = ?";
|
|
$qry = $this->db->query($sql, array($testID, $mouID));
|
|
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
|
|
foreach($rows as $idx => $r) {
|
|
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
|
switch($nat_testType) {
|
|
case 1: //Single
|
|
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
|
break;
|
|
case 3: //Multi
|
|
case 4: //Panel
|
|
$sasCode = $r["T_TestSasCode"] . '%';
|
|
$sql = "select T_TestNat_TestID
|
|
from t_test
|
|
where T_TestIsResult = 'Y'
|
|
and T_TestSasCode like ?
|
|
and T_TestIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($sasCode));
|
|
if (!$qry ) {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
$flag_error = true;
|
|
}
|
|
$nt_rows = $qry->result_array();
|
|
$t_rows = array($r["Nat_TestID"]);
|
|
foreach($nt_rows as $nr) {
|
|
$t_rows[] = $nr["T_TestNat_TestID"];
|
|
}
|
|
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
|
break;
|
|
}
|
|
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
|
unset($rows[$idx]["T_TestSasCode"]);
|
|
}
|
|
if ( count($rows) > 0 ) {
|
|
echo "Update test :\n";
|
|
$r = $rows[0];
|
|
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
|
$this->db->where("T_TestID", $r["T_TestID"]);
|
|
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
|
$qry = $this->db->update("ss_price_mou_v3",$r);
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
}
|
|
$sasCode = substr($sasCode,0,8);
|
|
if($flagProfile ) {
|
|
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
|
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
|
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
|
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
|
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
|
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
|
from t_test
|
|
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
|
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
|
where length(T_TestSasCode) = 8 ";
|
|
$qry = $this->db->query($sql, array($sasCode));
|
|
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$p_rows = $qry->result_array();
|
|
$flag_error = false;
|
|
foreach($p_rows as $idx => $r) {
|
|
$T_TestName= $r["T_TestName"] ;
|
|
$sasCode = $r["T_TestSasCode"];
|
|
$sql = "select T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
|
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
|
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
|
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
|
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
|
Nat_TestNat_TestTypeID, T_TestSasCode
|
|
from t_price
|
|
join t_test on T_PriceT_TestID = T_TestID
|
|
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
|
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
|
and T_TestSasCode like ? and length(T_TestSasCode) = 10
|
|
join nat_test on T_TestNat_TestID = Nat_TestID
|
|
and Nat_TestIsActive = 'Y'
|
|
where T_PriceM_MouID = ? ";
|
|
$qry = $this->db->query($sql,array($sasCode . '%',$mouID));
|
|
if (!$qry ) {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
$flag_error = true;
|
|
}
|
|
$ct_rows = $qry->result_array();
|
|
$p_nat_test = array();
|
|
foreach($ct_rows as $ct_idx => $cr) {
|
|
$sasCode = $cr["T_TestSasCode"] . '%';
|
|
$sql = "select T_TestNat_TestID
|
|
from t_test
|
|
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
|
and T_TestSasCode like ?
|
|
and T_TestIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($sasCode));
|
|
if (!$qry ) {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
$flag_error = true;
|
|
}
|
|
$nt_rows = $qry->result_array();
|
|
$t_rows = array();
|
|
foreach($nt_rows as $nr) {
|
|
$t_rows[] = $nr["T_TestNat_TestID"];
|
|
$p_nat_test[]=$nr["T_TestNat_TestID"];
|
|
}
|
|
$ct_rows[$ct_idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
|
}
|
|
if (count($ct_rows) > 0 ) {
|
|
$x_arr = array();
|
|
foreach($ct_rows as $x_cr) {
|
|
$x_arr[] = $x_cr;
|
|
}
|
|
$p_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
|
$p_rows[$idx]['nat_test'] = "[" . join( ",", $p_nat_test) . "]";
|
|
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
|
unset($p_rows[$idx]["T_TestSasCode"]);
|
|
} else {
|
|
unset($p_rows[$idx]);
|
|
}
|
|
}
|
|
if ( count($p_rows) > 0 ) {
|
|
echo "Update Profile :\n";
|
|
$r = $p_rows[0];
|
|
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
|
$this->db->where("T_TestID", $r["T_TestID"]);
|
|
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
|
$qry = $this->db->update("ss_price_mou_v3",$r);
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
//Update Panel yang mengandung Test
|
|
$sql = "select
|
|
distinct T_PacketDetailT_PacketID
|
|
from
|
|
t_packetdetail
|
|
where T_PacketDetailIsActive = 'Y'
|
|
and T_PacketDetailT_TestID = ?";
|
|
$qry = $this->db->query($sql, array($testID));
|
|
if (!$qry) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$packet_ids = "0";
|
|
foreach($rows as $r ) {
|
|
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
|
}
|
|
|
|
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
|
0 T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
|
0 T_PricePriority, T_PacketOriginalPrice T_PriceAmount, 0 T_PriceDisc,
|
|
(T_PacketOriginalPrice - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
|
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
|
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
|
$mouID Ss_PriceMouM_MouID
|
|
from
|
|
t_packet
|
|
where
|
|
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
|
and T_PacketM_MouID = ?";
|
|
|
|
$qry = $this->db->query($sql, array($mouID));
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$pn_rows = $qry->result_array();
|
|
foreach($pn_rows as $idx => $pnr) {
|
|
$packetID = $pnr["packet_id"];
|
|
//child test
|
|
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
|
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
|
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPrice T_PriceAmount,
|
|
0 T_PriceDisc, 0 T_PriceDiscRp, T_PacketDetailPrice T_PriceSubTotal,
|
|
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
|
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
|
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
|
from t_packetdetail
|
|
join t_test on T_PacketDetailT_TestID = T_TestID
|
|
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
|
and T_PacketDetailT_PacketID = ?
|
|
join nat_test on T_TestNat_TestID = Nat_TestID
|
|
and Nat_TestIsActive = 'Y'
|
|
";
|
|
$qry = $this->db->query($sql,array($packetID));
|
|
//echo $this->db->last_query() . "\n"; exit;
|
|
if (!$qry ) {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
$flag_error = true;
|
|
exit;
|
|
}
|
|
$ct_rows = $qry->result_array();
|
|
$p_nat_test = array();
|
|
foreach($ct_rows as $ct_idx => $cr) {
|
|
$sasCode = $cr["T_TestSasCode"] . '%';
|
|
$sql = "select distinct T_TestNat_TestID
|
|
from t_test
|
|
where T_TestSasCode like ?
|
|
and T_TestIsActive = 'Y'";
|
|
$qry = $this->db->query($sql,array($sasCode));
|
|
if (!$qry ) {
|
|
echo "Err : " . print_r($this->db->error(),true) . "\n";
|
|
$flag_error = true;
|
|
}
|
|
$nt_rows = $qry->result_array();
|
|
$t_rows = array();
|
|
foreach($nt_rows as $nr) {
|
|
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
|
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
|
}
|
|
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
|
}
|
|
if (count($ct_rows) > 0 ) {
|
|
$x_arr = array();
|
|
foreach($ct_rows as $x_cr) {
|
|
$x_arr[] = $x_cr;
|
|
}
|
|
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
|
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
|
}
|
|
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
|
unset($pn_rows[$idx]["T_TestSasCode"]);
|
|
}
|
|
foreach($pn_rows as $r ) {
|
|
$name = $r["T_TestName"];
|
|
echo "Packet : $name \n";
|
|
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
|
$this->db->where("T_TestID", $r["T_TestID"]);
|
|
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
|
$qry = $this->db->update("ss_price_mou_v3",$r);
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
echo $this->db->last_query() . "\n";
|
|
}
|
|
echo "Done";
|
|
}
|
|
function post($url,$data) {
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: ' . strlen($data))
|
|
);
|
|
$result = curl_exec($ch);
|
|
return $result;
|
|
}
|
|
}
|