Initial import
This commit is contained in:
127
one-api/application/controllers/tools/price/Xfer.php
Normal file
127
one-api/application/controllers/tools/price/Xfer.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
class Xfer extends CI_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database("regional", true);
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
function upload_mou($mouID,$branchCode) {
|
||||
//upload aggrement , ss_price_mou
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db_regional->query($sql, array($mouID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return array(false, "No MOU : " . $this->db_regional->last_query());
|
||||
}
|
||||
$mou = $rows[0];
|
||||
|
||||
$sql = "select * from m_company where M_CompanyID = ?";
|
||||
$qry = $this->db_regional->query($sql, array($mou["M_MouM_CompanyID"]));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Company");
|
||||
}
|
||||
$company = $rows[0];
|
||||
|
||||
$sql = "select * from g_moustatuslog where G_MouStatusLogM_MouID = ?";
|
||||
$qry = $this->db_regional->query($sql, array($mouID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return array(false, "No Log");
|
||||
}
|
||||
$logs = $rows;
|
||||
$mou["M_MouUserID"] = 3; // set to 3
|
||||
foreach($logs as $idx => $l ) {
|
||||
$logs[$idx]["G_MouStatusLogUserID"] = 3;
|
||||
}
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID= ?";
|
||||
$qry = $this->db_regional->query($sql, array($mouID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Ss Price Mou");
|
||||
}
|
||||
|
||||
$sql = "select * from t_price where T_PriceM_MouID= ?";
|
||||
$qry = $this->db_regional->query($sql, array($mouID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$t_rows = $qry->result_array();
|
||||
|
||||
$sql = "select * from t_packet where T_PacketM_MouID = ?";
|
||||
$qry = $this->db_regional->query($sql, array($mouID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$pkt_rows = $qry->result_array();
|
||||
|
||||
$sql = "select t_packetdetail.*
|
||||
from t_packet
|
||||
join t_packetdetail on T_PacketDetailT_PacketID = T_PacketID
|
||||
where T_PacketM_MouID = ?";
|
||||
$qry = $this->db_regional->query($sql, array($mouID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$pd_rows = $qry->result_array();
|
||||
|
||||
$param = array (
|
||||
"mou" => $mou,
|
||||
"company" => $company,
|
||||
"logs" => $logs,
|
||||
"price_mou" => $rows,
|
||||
"t_price" => $t_rows,
|
||||
"packet" => $pkt_rows,
|
||||
"packet_detail" => $pd_rows
|
||||
);
|
||||
$param_md5 = md5(json_encode($param));
|
||||
$j_param = json_encode(array("param" => $param, "md5" => $param_md5 ));
|
||||
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchCode=?";
|
||||
|
||||
$qry = $this->db_regional->query($sql, array($branchCode));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Ss Price Mou");
|
||||
}
|
||||
|
||||
$sql = "insert into tx_mou(TxMouM_BranchIPAddress, TxMouM_BranchCode,TxMouM_MouID, TxMouJson,TxMouM_UserID )
|
||||
values(?,?,?,?,?)";
|
||||
$sql_del = "delete from tx_mou where TxMouM_MouID=? and TxMouM_BranchCode=?";
|
||||
$flag_error = false;
|
||||
$err_msg = array();
|
||||
$userID = 3;
|
||||
foreach($rows as $r ) {
|
||||
$branchCode = $r["M_BranchCode"];
|
||||
$ipAddress = $r["M_BranchIPAddress"];
|
||||
$qry = $this->db_regional->query($sql_del, array($mouID,$branchCode));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
$qry = $this->db_regional->query($sql, array($ipAddress, $branchCode,$mouID,$j_param,$userID));
|
||||
if (! $qry) {
|
||||
return array(false, print_r($this->db_regional->error(),true));
|
||||
}
|
||||
}
|
||||
if ( $flag_error) {
|
||||
return array(false, join(",",$err_msg));
|
||||
}
|
||||
return array(true,"OK");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user