231 lines
6.3 KiB
PHP
231 lines
6.3 KiB
PHP
<?php
|
|
|
|
class Hanan extends MY_Controller
|
|
{
|
|
var $db_inventory;
|
|
var $db_one_iventory_log;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
$this->db_one_inventory_log = $this->load->database("inventory_log", true);
|
|
}
|
|
|
|
function index()
|
|
{
|
|
echo "Api: Training Playground";
|
|
echo "<br>";
|
|
$cek = $this->db_inventory->query("select database() as cunrrent_db")->result();
|
|
|
|
print_r($cek);
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
$sql_data = "";
|
|
$sql_filter = "";
|
|
$search = "";
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
}else{
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
// sort
|
|
$sortBY = $prm['sortBy'];
|
|
$sortStatus = $prm['sortStatus'];
|
|
if($sortBY){
|
|
$q_sort = "ORDER BY".$sortBY." ".$sortStatus;
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
// $number_limit = 2;
|
|
if($prm['current_page'] > 0) {
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter .= "select count(distinct ItemImageID, ItemImageCode, ItemImageSKU)
|
|
as total
|
|
from itemimage_log
|
|
where (ItemImageCode like ?
|
|
or ItemImageSKU like ?)";
|
|
|
|
$qry_filter = $this->db_one_inventory_log->query($sql_filter, [$search, $search]);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
}else{
|
|
$this->sys_error_db("itemimage_log count", $this->db);
|
|
exit;
|
|
}
|
|
|
|
// echo json_encode($tot_count);
|
|
$sql_data .= "select
|
|
distinct ItemImageCode, ItemImageSKU
|
|
from itemimage_log
|
|
where (ItemImageCode like ?
|
|
or ItemImageSKU like ?)
|
|
limit ? offset ?";
|
|
|
|
$qry_data = $this->db_one_inventory_log->query($sql_data, [$search, $search, $number_limit, $number_offset]);
|
|
|
|
// untuk menampilkan query di postman
|
|
// echo $this->db_one_inventory_log->last_query();
|
|
|
|
if ($qry_data) {
|
|
$rows = $qry_data->result_array();
|
|
}else{
|
|
$this->sys_error_db("Itemimage_log select");
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"total_filter" =>count($rows),
|
|
"records" => $rows
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function insertdata()
|
|
{
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//
|
|
$this->db->trans_begin();
|
|
|
|
$prm = $this->sys_input;
|
|
$sql_data = "insert into itemimage_log(ItemImageCode, ItemImageSKU, ItemImageCreated) values (?,?, now())";
|
|
$qry = $this->db_one_inventory_log->query($sql_data, [
|
|
$prm["ItemImageCode"],
|
|
$prm["ItemImageSKU"],
|
|
]);
|
|
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("item log insert");
|
|
}
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function update()
|
|
{
|
|
try {
|
|
//code...
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$this->db->trans_begin();
|
|
|
|
$prm = $this->sys_input;
|
|
$sql = "update itemimage_log set
|
|
ItemImageCode = ?,
|
|
ItemImageSKU = ?
|
|
where
|
|
ItemImageID = ?";
|
|
$qry = $this->db_one_inventory_log->query($sql, [
|
|
$prm["ItemImageCode"],
|
|
$prm["ItemImageSKU"],
|
|
$prm["ItemImageID"]
|
|
]);
|
|
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("item log update");
|
|
}
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function delete()
|
|
{
|
|
try {
|
|
//code...
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$this->db->trans_begin();
|
|
|
|
$prm = $this->sys_input;
|
|
$sql = "update itemunit set
|
|
ItemUnitIsActive = ?
|
|
where
|
|
ItemUnitID = ?";
|
|
$qry = $this->db_inventory->query($sql, [
|
|
"N",
|
|
$prm["ItemUnitID"]
|
|
]);
|
|
|
|
if(!$qry){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("item log delete");
|
|
}
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
} |