131 lines
4.2 KiB
PHP
131 lines
4.2 KiB
PHP
<?php
|
|
class Stockcard extends MY_Controller
|
|
{
|
|
var $db_inventory;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
}
|
|
|
|
function index()
|
|
{
|
|
echo "Api: Training Playground";
|
|
echo "<br>";
|
|
$cek = $this->db_inventory->query("select database() as current_db")->result();
|
|
// echo $this->db->last_query();
|
|
|
|
print_r($cek);
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
}else{
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$sortBy = $prm["sortBy"];
|
|
$sortStatus = $prm["sortStatus"];
|
|
if ($sortBy) {
|
|
$q_sort = "ORDER BY ".$sortBy." ".$sortStatus;
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter = "SELECT count(StockCardID) as total
|
|
FROM stockcard
|
|
JOIN warehouse
|
|
ON StockCardWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
JOIN item
|
|
ON StockCardItemID = ItemID
|
|
AND ItemIsActive = 'Y'
|
|
JOIN itemunit
|
|
ON StockCardItemUnitID = ItemUnitID
|
|
AND ItemUnitIsActive = 'Y'
|
|
WHERE WarehouseName LIKE ?
|
|
OR ItemName LIKE ?";
|
|
|
|
$qry_filter = $this->db_inventory->query($sql_filter, [$search, $search]);
|
|
// $last_qry = $this->db_inventory->last_query();
|
|
// print_r($last_qry);
|
|
|
|
$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("stockcard select count", $this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
$sql_data = "SELECT StockCardID as cardId,
|
|
StockCardWarehouseID as warehouseId,
|
|
WarehouseCode as warehouseCode,
|
|
WarehouseName as warehouse,
|
|
StockCardItemID as itemId,
|
|
ItemName as itemName,
|
|
StockCardItemUnitID as itemunitId,
|
|
ItemUnitName as itemunit,
|
|
StockCardBatchNo as cardNo,
|
|
StockCardStatus as cardStatus,
|
|
StockCardBefore as cardBefore,
|
|
StockCardIn as cardIn,
|
|
StockCardOut as cardOut,
|
|
StockCardAfter as cardAfter,
|
|
StockCardED as cardED
|
|
FROM stockcard
|
|
JOIN warehouse ON StockCardWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
JOIN item ON StockCardItemID = ItemID
|
|
AND ItemIsActive = 'Y'
|
|
JOIN itemunit ON StockCardItemUnitID = ItemUnitID
|
|
AND ItemUnitIsActive = 'Y'
|
|
WHERE WarehouseName LIKE ?
|
|
OR ItemName LIKE ?
|
|
$q_sort
|
|
LIMIT ? OFFSET ?";
|
|
|
|
$qry_data = $this->db_inventory->query($sql_data, array($search, $search, $number_limit, $number_offset));
|
|
// $last_qry = $this->db_inventory->last_query();
|
|
// print_r($last_qry);
|
|
|
|
if ($qry_data) {
|
|
$rows = $qry_data->result_array();
|
|
}else{
|
|
$this->sys_error_db("stockcard select", $this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_page" => $tot_page,
|
|
"total_filter" => $tot_count,
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|
|
?>
|