155 lines
3.6 KiB
PHP
155 lines
3.6 KiB
PHP
<?php
|
|
class R_sales extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// db devnas
|
|
// $this->db = $this->load->database("nas_report", true);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo "RECEIVER R_sales.php";
|
|
}
|
|
|
|
function get_param_z()
|
|
{
|
|
$body_z = file_get_contents("php://input");
|
|
$body = gzuncompress($body_z);
|
|
return json_decode($body, true);
|
|
}
|
|
|
|
function reply($resp)
|
|
{
|
|
echo json_encode($resp);
|
|
}
|
|
|
|
function reply_gz($resp)
|
|
{
|
|
//echo json_encode($resp);
|
|
echo gzcompress(json_encode($resp));
|
|
}
|
|
|
|
function r_sales_upload_log()
|
|
{
|
|
$this->db->trans_begin();
|
|
$param = $this->get_param_z();
|
|
// print_r($param);
|
|
// print_r;
|
|
|
|
// echo json_decode($param);
|
|
|
|
//print_r($prm);
|
|
|
|
$prev_day = "";
|
|
foreach ($param['data'] as $key) {
|
|
$day = $key['day'];
|
|
$M_BranchID= $key['M_BranchID'];
|
|
|
|
if ($day != $prev_day) {
|
|
// query delete
|
|
$sql_delete = "DELETE FROM one_dash.nat_sales
|
|
WHERE Nat_SalesM_BranchID = ?
|
|
AND Nat_SalesDay = ?";
|
|
|
|
$qry_delete = $this->db->query($sql_delete, [
|
|
$M_BranchID,
|
|
$day
|
|
]);
|
|
|
|
if (!$qry_delete) {
|
|
// print_r($this->db->last_query());
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "delete nat_sales | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
}
|
|
$prev_day = $day;
|
|
}
|
|
|
|
foreach ($param['data'] as $key) {
|
|
$this->insert_nat_sales(
|
|
$key['M_BranchID'],
|
|
$key['M_BranchCode'],
|
|
$key['day'],
|
|
$key['month'],
|
|
$key['year'],
|
|
$key['quarter'],
|
|
$key['T_OrderHeaderM_CompanyID'],
|
|
$key['Nat_TestNat_GroupID'],
|
|
$key['Nat_TestNat_SubGroupID'],
|
|
$key['SalesPrice'],
|
|
$key['SalesDiscount'],
|
|
$key['SalesTotal']
|
|
);
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$this->reply(
|
|
[
|
|
"status" => "OK",
|
|
"message" => "Data berhasil ditambahkan ke nat_sales",
|
|
]
|
|
);
|
|
}
|
|
|
|
function insert_nat_sales(
|
|
$M_BranchID,
|
|
$M_BranchCode,
|
|
$day,
|
|
$month,
|
|
$year,
|
|
$quarter,
|
|
$T_OrderHeaderM_CompanyID,
|
|
$Nat_TestNat_GroupID,
|
|
$Nat_TestNat_SubGroupID,
|
|
$SalesPrice,
|
|
$SalesDiscount,
|
|
$SalesTotal
|
|
) {
|
|
// insert
|
|
$sql_insert = "INSERT INTO one_dash.nat_sales(
|
|
Nat_SalesM_BranchID,
|
|
Nat_SalesM_BranchCode,
|
|
Nat_SalesDay,
|
|
Nat_SalesMonth,
|
|
Nat_SalesYear,
|
|
Nat_SalesQuarter,
|
|
Nat_SalesM_CompanyID,
|
|
Nat_SalesNat_GroupID,
|
|
Nat_SalesNat_SubGroupID,
|
|
Nat_SalesPrice,
|
|
Nat_SalesDiscount,
|
|
Nat_SalesTotal,
|
|
Nat_SalesIsActive
|
|
) VALUES (?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ? ,?)";
|
|
|
|
$qry_insert = $this->db->query($sql_insert, [
|
|
$M_BranchID,
|
|
$M_BranchCode,
|
|
$day,
|
|
$month,
|
|
$year,
|
|
$quarter,
|
|
$T_OrderHeaderM_CompanyID,
|
|
$Nat_TestNat_GroupID,
|
|
$Nat_TestNat_SubGroupID,
|
|
$SalesPrice,
|
|
$SalesDiscount,
|
|
$SalesTotal,
|
|
'Y'
|
|
]);
|
|
|
|
if (!$qry_insert) {
|
|
// print_r($this->db->last_query());
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "insert nat_sales | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
}
|
|
}
|