Files
BE_IBL/application/controllers/mockup/process/mapping-batch-rpt/Box.php
2026-04-15 15:24:21 +07:00

156 lines
5.1 KiB
PHP

<?php
class Box extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "REF RECEIVE SAMPLE API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->library("Kapus");
}
function selected_box1()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$barcode = $prm['barcode'];
$sql = "SELECT *,
ROUND(sysKaPusPct,0) as kapus
from sys_kapus ";
// echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db( $this->db_onedev->last_query() );
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selected_box2()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$barcode = $prm['barcode'];
$sql = "SELECT *,
FORMAT(sysFKapusSumAmount,0) as kapus,
FORMAT(sysFKapusSumTotal,0) as kascabang,
ROUND(sysFKapusSumTargetPct,0) as target,
sysFKapusSumActualPct as actual,
DATE_FORMAT(sysFKapusSumDate,'%d-%m-%Y') as tanggal
from sys_f_kapus_sum
WHERE sysFKapusSumID = $id";
// echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db( $this->db_onedev->last_query() );
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updategenerate(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$id = $prm["id"];
$tanggal = $prm["tanggal"];
$sysKaPusPct = $prm["sysKaPusPct"];
$sql = "update sys_kapus
set sysKaPusPct = '{$sysKaPusPct}'";
$qry = $this->db_onedev->query($sql);
//generate
$rst = $this->kapus->calc($tanggal,$userid);
if ($rst["status"] != "OK" ) {
$this->sys_error($rst["message"]);
exit;
}
$this->clean_mysqli_connection($this->db_onedev->conn_id);
$sqlkapus = "SELECT *,
sysFKapusSumID as id,
FORMAT(sysFKapusSumAmount,0) as kapus,
FORMAT(sysFKapusSumTotal,0) as kascabang,
ROUND(sysFKapusSumTargetPct,0) as target,
sysFKapusSumActualPct as actual,
DATE_FORMAT(sysFKapusSumDate,'%d-%m-%Y') as tanggal
from sys_f_kapus_sum
WHERE sysFKapusSumID = $id";
$querykapus = $this->db_onedev->query($sqlkapus);
$rows = $querykapus->result_array();
$result = array ("total" => count($rows), "records" => $rows, "message" =>$rst["message"]);
$this->sys_ok($result);
exit;
}
function konfirmasi(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$userid = $this->sys_user["M_UserID"];
$sql = "update sys_f_kapus_sum set sysFKapusSumIsPosted = 'Y',sysFKapusSumUserID = '{$userid}' where sysFKapusSumID = ?";
$query = $this->db_onedev->query($sql, array($id));
if ($query) {
$sqlkapus = "SELECT *,
sysFKapusSumID as id,
FORMAT(sysFKapusSumAmount,0) as kapus,
FORMAT(sysFKapusSumTotal,0) as kascabang,
ROUND(sysFKapusSumTargetPct,0) as target,
sysFKapusSumActualPct as actual,
DATE_FORMAT(sysFKapusSumDate,'%d-%m-%Y') as tanggal
from sys_f_kapus_sum
WHERE sysFKapusSumID = $id";
$querykapus = $this->db_onedev->query($sqlkapus);
$rows = $querykapus->result_array();
} else {
$this->sys_error_db( $this->db_onedev->last_query() );
exit;
}
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}