108 lines
4.0 KiB
PHP
108 lines
4.0 KiB
PHP
<?php
|
|
class Fixprice extends MY_Controller
|
|
{
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->db_one = $this->load->database("onedev", true);
|
|
}
|
|
function amount($mouId, $testID,$amount) {
|
|
try {
|
|
$sql = "update
|
|
ss_price_mou
|
|
set T_PriceAmount = ? ,
|
|
T_PriceSubTotal = ? - T_PriceDisc / 100 * ? ,
|
|
T_PriceTotal = ? - T_PriceDisc / 100 * ?
|
|
where T_TestID = ? and Ss_PriceMouM_MouID = ? ";
|
|
|
|
$this->db_one->query($sql, array($amount, $amount,$amount, $amount,$amount,
|
|
$testID, $mouId));
|
|
echo json_encode( array("status"=>"OK" , "message" => "Updated") );
|
|
} catch(Exception $e) {
|
|
echo json_encode(
|
|
array("status" => "ERR" , "id" => 0, "message" => $e.message() )
|
|
);
|
|
}
|
|
}
|
|
function profile($mouId, $testID) {
|
|
try {
|
|
$sql = "select T_TestSasCode, T_PriceAmount ,
|
|
T_PriceDisc, T_PriceSubTotal, T_PriceTotal
|
|
from
|
|
ss_price_mou s
|
|
join t_test t on s.T_TestID = t.T_TestID
|
|
and Ss_PriceMouM_MouID = ?
|
|
where t.T_TestID = ? ";
|
|
$qry = $this->db_one->query($sql, array($mouId,$testID));
|
|
$T_TestSasCode = "";
|
|
$T_PriceAmount = 0;
|
|
if ( $qry ) {
|
|
$rows = $qry->result_array();
|
|
$T_TestSasCode = $rows[0]["T_TestSasCode"];
|
|
$T_PriceAmount= $rows[0]["T_PriceAmount"];
|
|
$T_PriceDisc= $rows[0]["T_PriceDisc"];
|
|
$T_PriceSubTotal= $rows[0]["T_PriceSubTotal"];
|
|
$T_PriceTotal= $rows[0]["T_PriceTotal"];
|
|
}
|
|
if ($T_TestSasCode == "" || $T_PriceAmount == 0 ) {
|
|
echo json_encode( array("status"=>"ERR", "message"=> "NO Test") );
|
|
exit;
|
|
}
|
|
$T_TestSasCode = substr($T_TestSasCode, 0 , strlen($T_TestSasCode) - 2 );
|
|
// cari anak
|
|
$sql = "select T_TestID
|
|
from t_test
|
|
where T_TestSasCode like ?
|
|
and length(T_TestSasCode ) = ?
|
|
and T_TestIsPrice = 'Y'
|
|
and T_TestIsActive = 'Y'";
|
|
$qry = $this->db_one->query($sql, array($T_TestSasCode . "%" , strlen($T_TestSasCode) + 2 ) );
|
|
$px_childs = array();
|
|
if ($qry ) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$px_childs[] = $r["T_TestID"];
|
|
}
|
|
}
|
|
|
|
$sql = "select s.*
|
|
from ss_price_mou s
|
|
join t_test t on t.T_TestID = s.T_TestID
|
|
where Ss_PriceMouM_MouID = ? and
|
|
px_type = 'PXR' and T_TestSasCode = ? ";
|
|
$qry = $this->db_one->query($sql,array($mouId,$T_TestSasCode));
|
|
if($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$id = $r["Ss_PriceMouID"];
|
|
$child_test = json_decode($r["child_test"],true);
|
|
$new_child_test = array();
|
|
$flag_found = false;
|
|
foreach($child_test as $c) {
|
|
if($c["T_TestID"] == $testID ) {
|
|
$c["T_PriceAmount"] = $T_PriceAmount;
|
|
$c["T_PriceDisc"] = $T_PriceDisc;
|
|
$c["T_PriceSubTotal"] = $T_PriceSubTotal;
|
|
$c["T_PriceTotal"] = $T_PriceTotal;
|
|
$flag_found = true;
|
|
}
|
|
if ( in_array($c["T_TestID"], $px_childs ) ) {
|
|
$new_child_test[] = $c;
|
|
}
|
|
}
|
|
if ($flag_found) {
|
|
$j_child_test = json_encode($new_child_test);
|
|
$sql = "update ss_price_mou set
|
|
child_test = ? where Ss_PriceMouID = ? ";
|
|
$this->db_one->query($sql, array($j_child_test, $id));
|
|
}
|
|
}
|
|
}
|
|
echo json_encode( array("status"=>"OK" , "message" => "Updated") );
|
|
} catch(exception $e) {
|
|
echo json_encode(
|
|
array("status" => "ERR" , "id" => 0, "message" => $e.message() )
|
|
);
|
|
}
|
|
}
|
|
}
|