Files
BE_CPONE/application/controllers/fix/Fixsspricemou.php
2026-04-27 10:26:26 +07:00

94 lines
3.5 KiB
PHP

<?php
class Fixsspricemou extends CI_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database("onedev", true);
}
function packet($packetID) {
$sql = "select T_PacketM_MouID from t_packet where T_PacketID = ?";
$qry = $this->db->query($sql,array($packetID));
$mouID = 0;
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$mouID = $rows[0]["T_PacketM_MouID"];
}
} else {
print_r($this->db->error());
exit;
}
if ( $mouID == 0 ) {
echo "Mou not found";
exit;
}
$sql = "select M_MouM_CompanyID from m_mou where M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
$companyID = 0;
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$companyID= $rows[0]["M_MouM_CompanyID"];
}
} else {
print_r($this->db->error());
exit;
}
if ($companyID == 0 ) {
echo "CompanyID not found!";
exit;
}
//child test
$sql = "select T_PacketM_MouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
T_PacketM_mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
from t_packetdetail
join t_packet on T_PacketDetailT_PacketID = T_PacketID and T_PacketID = ?
join t_test on T_PacketDetailT_TestID = T_TestID
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($packetID));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$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 ) {
return array(false, print_r($this->db->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;
}
$child_test = json_encode($x_arr,true);
$nat_test = json_encode($p_nat_test,true);
}
echo "Child Test : \n" ;
echo $child_test . "\n";
echo "Nat Test : \n";
echo $nat_test . "\n";
}
}