74 lines
2.9 KiB
PHP
74 lines
2.9 KiB
PHP
<?php
|
|
class Fixexpertisi extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database("onedev", true);
|
|
}
|
|
function fix_all() {
|
|
$sql = "update ss_expertisi,t_orderdetail
|
|
set SsExpertisiAmount = T_OrderDetailTotal
|
|
where SsExpertisiT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
and SsExpertisiT_TestID = T_OrderDetailT_TestID and SsExpertisiAmount = 0
|
|
";
|
|
$this->db->query($sql);
|
|
|
|
$sql = "select SsExpertisiID, SsExpertisiT_OrderHeaderID,SsExpertisiT_TestID,
|
|
T_OrderDetailT_TestSasCode T_TestSasCode
|
|
from ss_expertisi
|
|
join t_orderdetail on T_OrderDetailT_OrderHeaderID= SsExpertisiT_OrderHeaderID
|
|
and T_OrderDetailT_TestID = SsExpertisiT_TestID
|
|
where SsExpertisiAmount = 0";
|
|
$qry = $this->db->query($sql );
|
|
$rows = array();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$orderHeaderID= $r["SsExpertisiT_OrderHeaderID"];
|
|
$testID= $r["SsExpertisiT_TestID"];
|
|
$sasCode = $r["T_TestSasCode"];
|
|
$SsExpertisiID = $r["SsExpertisiID"];
|
|
|
|
$sql = "select T_OrderDetailAddOnT_PacketID
|
|
from
|
|
t_orderdetail
|
|
join t_orderdetailaddon on T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID
|
|
and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailT_OrderHeaderID = ?
|
|
and T_OrderDetailAddOnIsPacket = 'Y'
|
|
and instr(?, T_OrderDetailT_TestSasCode)
|
|
";
|
|
|
|
$qry = $this->db->query($sql, array($orderHeaderID, $sasCode));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$packetID = $rows[0]["T_OrderDetailAddOnT_PacketID"];
|
|
$sql = "select T_PacketDetailPrice
|
|
from t_packetdetail
|
|
where T_PacketDetailIsActive = 'Y'
|
|
and t_PacketDetailT_PacketID = ? and T_PacketDetailT_TestID = ? ";
|
|
$qry = $this->db->query($sql, array($packetID, $testID));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) {
|
|
$price = $rows[0]["T_PacketDetailPrice"];
|
|
if ($price > 0 ) {
|
|
$sql = "update ss_expertisi set SsExpertisiAmount = ?
|
|
where SsExpertisiID = ? ";
|
|
$this->db->query($sql, array($price,$SsExpertisiID));
|
|
echo "update $SsExpertisiID , price : $price \n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
}
|
|
} else {
|
|
print_r($this->db->error());
|
|
}
|
|
}
|
|
}
|