109 lines
4.7 KiB
PHP
109 lines
4.7 KiB
PHP
<?php
|
|
class Uploadmutation extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
//$this->db_inventory_log = $this->load->database('inventory_log', true);
|
|
$this->db_onex = 'one_aditya';
|
|
|
|
|
|
}
|
|
|
|
function upload_data_to_branch(){
|
|
try{
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "SELECT mutasitransitdetail.*, M_BranchIPAddress as branch_ip
|
|
FROM `mutasitransitdetail`
|
|
JOIN `companyaddress` ON MutasiTransitDetailToCompanyAddressID = CompanyAddressID
|
|
JOIN `company` ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
MutasiTransitDetailIsSend = 'N' AND MutasiTransitDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql);
|
|
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
if($rows){
|
|
foreach ($rows as $k => $v) {
|
|
$config['hostname'] = $v['branch_ip'];
|
|
$config['username'] = 'root';
|
|
$config['password'] = 'sasone102938';
|
|
$config['database'] = 'one_inventory';
|
|
$config['dbdriver'] = 'mysqli';
|
|
$config['dbprefix'] = '';
|
|
$config['pconnect'] = FALSE;
|
|
$config['db_debug'] = TRUE;
|
|
$config['cache_on'] = FALSE;
|
|
$config['cachedir'] = '';
|
|
$config['char_set'] = 'utf8';
|
|
$config['dbcollat'] = 'utf8_general_ci';
|
|
$db_to = $this->load->database($config,TRUE);
|
|
if(!$db_to)
|
|
echo "error connection ".$v['branch_ip'];
|
|
|
|
$db_to->trans_start();
|
|
$db_to->trans_strict(FALSE);
|
|
|
|
$sql = "SELECT *
|
|
FROM mutasitransitdetail
|
|
WHERE
|
|
MutasiTransitDetailOldID = ? AND MutasiTransitDetailIsActive = 'Y'";
|
|
$qry = $db_to->query($sql,[$v['MutasiTransitDetailID']]);
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasitransitdetail exist error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(!$qry->row_array()){
|
|
|
|
$arr_insert_mutation_transit_detail = $v;
|
|
unset($arr_insert_mutation_transit_detail['branch_ip']);
|
|
|
|
$arr_insert_mutation_transit_detail['MutasiTransitDetailIsSend'] = 'Y';
|
|
$arr_insert_mutation_transit_detail['MutasiTransitDetailOldID'] = $v['MutasiTransitDetailID'];
|
|
$arr_insert_mutation_transit_detail['MutasiTransitDetailCreated'] = date("Y-m-d H:i:s");
|
|
$arr_insert_mutation_transit_detail['MutasiTransitDetailLastUpdated'] = date("Y-m-d H:i:s");
|
|
$arr_insert_mutation_transit_detail['MutasiTransitDetailUserID'] = $userid;
|
|
|
|
$qry = $db_to->insert('mutasitransitdetail', $arr_insert_mutation_transit_detail);
|
|
if(!$qry){
|
|
echo $db_to->last_query();
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE mutasitransitdetail SET MutasiTransitDetailIsSend = 'Y' WHERE MutasiTransitDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql,[$v['MutasiTransitDetailID']]);
|
|
if(!$qry){
|
|
$this->sys_error_db("update mutasitransitdetail local error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$db_to->trans_complete();
|
|
}
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("r_report rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|