948 lines
42 KiB
PHP
948 lines
42 KiB
PHP
<?php
|
|
class Almari extends MY_Controller
|
|
{
|
|
var $inventory;
|
|
var $log_inventory;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->inventory = $this->load->database("inventory", true);
|
|
$this->log_inventory = $this->load->database("inventory_log", true);
|
|
}
|
|
function get_location()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = "SELECT WarehouseLocationID as locationId,
|
|
WarehouseLocationCode as locationCode,
|
|
WarehouseLocationName as locationName
|
|
FROM warehouselocation
|
|
WHERE WarehouseLocationIsActive ='Y' ";
|
|
$qry = $this->inventory->query($sql);
|
|
$last_qry = $this->inventory->last_query();
|
|
$rows = $qry->result_array();
|
|
$wh = [];
|
|
if (!$qry) {
|
|
$this->inventory->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$result = array(
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_warehouse()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = "id";
|
|
if (isset($prm['id'])) {
|
|
$id = trim($prm["id"]);
|
|
}
|
|
$sql = "SELECT WarehouseID as warehouseId,
|
|
WarehouseCode as warehouseCode,
|
|
WarehouseName as warehouseName,
|
|
WarehouseWarehouseLocationID as locationId
|
|
FROM warehouse
|
|
WHERE WarehouseIsActive = 'Y'
|
|
AND WarehouseWarehouseLocationID = ?";
|
|
$qry = $this->inventory->query($sql, array($id));
|
|
$last_qry = $this->inventory->last_query();
|
|
|
|
if (!$qry) {
|
|
$this->inventory->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$result = array(
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$locationId = "locationId";
|
|
if (isset($prm['locationId'])) {
|
|
$locationId = trim($prm["locationId"]);
|
|
}
|
|
$warehouseId = "warehouseId";
|
|
if (isset($prm['warehouseId'])) {
|
|
$warehouseId = trim($prm["warehouseId"]);
|
|
}
|
|
$search = "%%";
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
$search = '%' . $prm['search'] . '%';
|
|
}
|
|
$order_by = "WarehouseAlmariCode";
|
|
if (isset($prm['order_by'])) {
|
|
$order_by = trim($prm["order_by"]);
|
|
}
|
|
$order = "asc";
|
|
if (isset($prm['order'])) {
|
|
$order = trim($prm["order"]);
|
|
}
|
|
$sort = "order by " . $order_by . " " . $order;
|
|
$page = $prm["page"];
|
|
$ROW_PER_PAGE = 10;
|
|
$start_offset = 0;
|
|
if (isset($prm["page"])) {
|
|
if (
|
|
is_numeric($prm["page"]) && $prm["page"] > 0
|
|
) {
|
|
$start_offset = ($page - 1) * $ROW_PER_PAGE;
|
|
}
|
|
}
|
|
$total_count = 0;
|
|
$total_page = 0;
|
|
if ($locationId == 0) {
|
|
$count = "SELECT count(WarehouseAlmariID) as total FROM
|
|
warehousealmari
|
|
JOIN warehouselocation
|
|
ON WarehouseAlmariLocationID = WarehouseLocationID
|
|
AND WarehouseLocationIsActive = 'Y'
|
|
JOIN warehouse
|
|
ON WarehouseAlmariWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
AND WarehouseAlmariIsActive ='Y'
|
|
WHERE WarehouseAlmariName like ?
|
|
OR WarehouseLocationName LIKE ?
|
|
OR WarehouseName LIKE ?
|
|
OR WarehouseAlmariCode LIKE ?
|
|
$sort";
|
|
$qry_count =
|
|
$this->inventory->query($count, [$search, $search, $search, $search]);
|
|
if ($qry_count) {
|
|
$total_count = $qry_count->row()->total;
|
|
$total_page = ceil($total_count / $ROW_PER_PAGE);
|
|
} else {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$sql = "SELECT WarehouseAlmariID as almariId,
|
|
WarehouseAlmariLocationID as locationId,
|
|
WarehouseAlmariWarehouseID as warehouseId,
|
|
WarehouseAlmariCode as almariCode,
|
|
WarehouseAlmariName as almariName,
|
|
WarehouseAlmariRows as almariRows,
|
|
WarehouseAlmariCols as almariCols,
|
|
WarehouseLocationCode as locationCode,
|
|
WarehouseLocationName as locationName,
|
|
WarehouseCode as warehouseCode,
|
|
WarehouseName as warehouseName,
|
|
fn_get_stock_almari(WarehouseAlmariID) as stockAlmari FROM
|
|
warehousealmari
|
|
JOIN warehouselocation
|
|
ON WarehouseAlmariLocationID = WarehouseLocationID
|
|
AND WarehouseLocationIsActive = 'Y'
|
|
JOIN warehouse
|
|
ON WarehouseAlmariWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
AND WarehouseAlmariIsActive ='Y'
|
|
WHERE WarehouseAlmariName like ?
|
|
OR WarehouseLocationName LIKE ?
|
|
OR WarehouseName LIKE ?
|
|
OR WarehouseAlmariCode LIKE ?
|
|
$sort
|
|
LIMIT 10 OFFSET ?";
|
|
$qry = $this->inventory->query($sql, [$search, $search, $search, $search, $start_offset]);
|
|
$lst_qryyy = $this->inventory->last_query();
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0) {
|
|
foreach ($rows as $key => $value) {
|
|
$sql = "SELECT WarehouseRackID as rackId,
|
|
WarehouseRackWarehouseAlmariID as almariId,
|
|
WarehouseRackCode as rackCode,
|
|
WarehouseRackName as rackName,
|
|
WarehouseRackRow as rackRow,
|
|
WarehouseRackCol as rackCol FROM warehouserack
|
|
WHERE WarehouseRackWarehouseAlmariID = ?
|
|
AND WarehouseRackIsActive = 'Y'";
|
|
$qry = $this->inventory->query($sql, array($value['almariId']));
|
|
$lst_qryyy = $this->inventory->last_query();
|
|
if ($qry) {
|
|
$rows[$key]['rack'] =
|
|
$qry->result_array();
|
|
} else {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
} elseif ($locationId > 0 && $warehouseId == 0) {
|
|
$count = "SELECT count(WarehouseAlmariID) as total FROM
|
|
warehousealmari
|
|
JOIN warehouselocation
|
|
ON WarehouseAlmariLocationID = WarehouseLocationID
|
|
AND WarehouseLocationIsActive = 'Y'
|
|
AND WarehouseAlmariLocationID = ?
|
|
JOIN warehouse
|
|
ON WarehouseAlmariWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
AND WarehouseAlmariIsActive ='Y'
|
|
WHERE WarehouseAlmariName like ?
|
|
OR WarehouseLocationName LIKE ?
|
|
OR WarehouseName LIKE ?
|
|
OR WarehouseAlmariCode LIKE ?
|
|
$sort";
|
|
$qry_count =
|
|
$this->inventory->query($count, [$locationId, $search, $search, $search, $search]);
|
|
if ($qry_count) {
|
|
$total_count = $qry_count->row()->total;
|
|
$total_page = ceil($total_count / $ROW_PER_PAGE);
|
|
} else {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$sql = "SELECT WarehouseAlmariID as almariId,
|
|
WarehouseAlmariLocationID as locationId,
|
|
WarehouseAlmariWarehouseID as warehouseId,
|
|
WarehouseAlmariCode as almariCode,
|
|
WarehouseAlmariName as almariName,
|
|
WarehouseAlmariRows as almariRows,
|
|
WarehouseAlmariCols as almariCols,
|
|
WarehouseLocationCode as locationCode,
|
|
WarehouseLocationName as locationName,
|
|
WarehouseCode as warehouseCode,
|
|
WarehouseName as warehouseName FROM
|
|
warehousealmari
|
|
JOIN warehouselocation
|
|
ON WarehouseAlmariLocationID = WarehouseLocationID
|
|
AND WarehouseLocationIsActive = 'Y'
|
|
AND WarehouseAlmariLocationID = ?
|
|
JOIN warehouse
|
|
ON WarehouseAlmariWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
AND WarehouseAlmariIsActive ='Y'
|
|
WHERE WarehouseAlmariName like ?
|
|
OR WarehouseLocationName LIKE ?
|
|
OR WarehouseName LIKE ?
|
|
OR WarehouseAlmariCode LIKE ?
|
|
$sort
|
|
LIMIT 10 OFFSET ?";
|
|
$qry = $this->inventory->query($sql, [
|
|
$locationId,
|
|
$search,
|
|
$search,
|
|
$search,
|
|
$search,
|
|
$start_offset
|
|
]);
|
|
$lst_qryyy = $this->inventory->last_query();
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0) {
|
|
foreach ($rows as $key => $value) {
|
|
$sql = "SELECT WarehouseRackID as rackId,
|
|
WarehouseRackWarehouseAlmariID as almariId,
|
|
WarehouseRackCode as rackCode,
|
|
WarehouseRackName as rackName,
|
|
WarehouseRackRow as rackRow,
|
|
WarehouseRackCol as rackCol FROM warehouserack
|
|
WHERE WarehouseRackWarehouseAlmariID = ?
|
|
AND WarehouseRackIsActive = 'Y'";
|
|
$qry = $this->inventory->query($sql, array($value['almariId']));
|
|
$lst_qryyy = $this->inventory->last_query();
|
|
if ($qry) {
|
|
$rows[$key]['rack'] =
|
|
$qry->result_array();
|
|
} else {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
} elseif ($locationId > 0 && $warehouseId > 0) {
|
|
$count = "SELECT count(WarehouseAlmariID) as total FROM
|
|
warehousealmari
|
|
JOIN warehouselocation
|
|
ON WarehouseAlmariLocationID = WarehouseLocationID
|
|
AND WarehouseLocationIsActive = 'Y'
|
|
AND WarehouseAlmariLocationID = ?
|
|
JOIN warehouse
|
|
ON WarehouseAlmariWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
AND WarehouseAlmariIsActive ='Y'
|
|
AND WarehouseAlmariWarehouseID = ?
|
|
WHERE WarehouseAlmariName like ?
|
|
OR WarehouseLocationName LIKE ?
|
|
OR WarehouseName LIKE ?
|
|
OR WarehouseAlmariCode LIKE ?
|
|
$sort";
|
|
$qry_count =
|
|
$this->inventory->query($count, [$locationId, $warehouseId, $search, $search, $search, $search]);
|
|
if ($qry_count) {
|
|
$total_count = $qry_count->row()->total;
|
|
$total_page = ceil($total_count / $ROW_PER_PAGE);
|
|
} else {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$sql = "SELECT WarehouseAlmariID as almariId,
|
|
WarehouseAlmariLocationID as locationId,
|
|
WarehouseAlmariWarehouseID as warehouseId,
|
|
WarehouseAlmariCode as almariCode,
|
|
WarehouseAlmariName as almariName,
|
|
WarehouseAlmariRows as almariRows,
|
|
WarehouseAlmariCols as almariCols,
|
|
WarehouseLocationCode as locationCode,
|
|
WarehouseLocationName as locationName,
|
|
WarehouseCode as warehouseCode,
|
|
WarehouseName as warehouseName FROM
|
|
warehousealmari
|
|
JOIN warehouselocation
|
|
ON WarehouseAlmariLocationID = WarehouseLocationID
|
|
AND WarehouseLocationIsActive = 'Y'
|
|
AND WarehouseAlmariLocationID = ?
|
|
JOIN warehouse
|
|
ON WarehouseAlmariWarehouseID = WarehouseID
|
|
AND WarehouseIsActive = 'Y'
|
|
AND WarehouseAlmariWarehouseID = ?
|
|
AND WarehouseAlmariIsActive ='Y'
|
|
WHERE WarehouseAlmariName like ?
|
|
OR WarehouseLocationName LIKE ?
|
|
OR WarehouseName LIKE ?
|
|
OR WarehouseAlmariCode LIKE ?
|
|
$sort
|
|
LIMIT 10 OFFSET ?";
|
|
$qry = $this->inventory->query($sql, [
|
|
$locationId,
|
|
$warehouseId,
|
|
$search,
|
|
$search,
|
|
$search,
|
|
$search,
|
|
$start_offset
|
|
]);
|
|
$lst_qryyy = $this->inventory->last_query();
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0) {
|
|
foreach ($rows as $key => $value) {
|
|
$sql = "SELECT WarehouseRackID as rackId,
|
|
WarehouseRackWarehouseAlmariID as almariId,
|
|
WarehouseRackCode as rackCode,
|
|
WarehouseRackName as rackName,
|
|
WarehouseRackRow as rackRow,
|
|
WarehouseRackCol as rackCol
|
|
FROM warehouserack
|
|
WHERE WarehouseRackWarehouseAlmariID = ?
|
|
AND WarehouseRackIsActive = 'Y'";
|
|
$qry = $this->inventory->query($sql, array($value['almariId']));
|
|
$lst_qryyy = $this->inventory->last_query();
|
|
if ($qry) {
|
|
$rows[$key]['rack'] =
|
|
$qry->result_array();
|
|
} else {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total_filter" => $total_count,
|
|
"total" => $total_page,
|
|
"records" => $rows,
|
|
"qry" => $lst_qryyy
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function add()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$locationId = "";
|
|
if (isset($prm['locationId'])) {
|
|
$locationId = trim($prm["locationId"]);
|
|
}
|
|
$warehouseId = "";
|
|
if (isset($prm['warehouseId'])) {
|
|
$warehouseId = trim($prm["warehouseId"]);
|
|
}
|
|
$name = "";
|
|
if (isset($prm['name'])) {
|
|
$name = trim($prm["name"]);
|
|
}
|
|
$row = "";
|
|
if (isset($prm['row'])) {
|
|
$row = trim($prm["row"]);
|
|
}
|
|
$col = "";
|
|
if (isset($prm['col'])) {
|
|
$col = trim($prm["col"]);
|
|
}
|
|
$rak = [];
|
|
if (isset($prm['rak'])) {
|
|
$rak = $prm["rak"];
|
|
}
|
|
if ($locationId == "" || $warehouseId == "" || $name == "" || $row == "" || $col == "") {
|
|
$this->sys_error("location id, warehouse id, name, row, col is mandatory");
|
|
exit;
|
|
}
|
|
$this->inventory->trans_start();
|
|
$this->inventory->trans_strict(FALSE);
|
|
$inserted_almari_id = 0;
|
|
$rak_log = array();
|
|
$sql = "INSERT INTO warehousealmari(
|
|
WarehouseAlmariLocationID,
|
|
WarehouseAlmariWarehouseID,
|
|
WarehouseAlmariCode,
|
|
WarehouseAlmariName,
|
|
WarehouseAlmariRows,
|
|
WarehouseAlmariCols,
|
|
WarehouseAlmariIsActive,
|
|
WarehouseAlmariUserID,
|
|
WarehouseAlmariCreated,
|
|
WarehouseAlmariLastUpdated)
|
|
VALUES(
|
|
?,?,(select fn_numbering('AL')),?, ?,?,'Y',?,NOW(),NOW())";
|
|
$qry = $this->inventory->query($sql, array($locationId, $warehouseId, $name, $row, $col, $userid));
|
|
if ($qry) {
|
|
$inserted_almari_id = $this->inventory->insert_id();
|
|
|
|
$sql = "SELECT * FROM warehousealmari WHERE WarehouseAlmariID = ?";
|
|
$qry = $this->inventory->query($sql, array($inserted_almari_id));
|
|
$almari = $qry->row_array();
|
|
$almariCode = $almari['WarehouseAlmariCode'];
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (count($rak) > 0) {
|
|
foreach ($rak as $key => $value) {
|
|
$name = trim($value['rackName']);
|
|
$row = trim($value['rackRow']);
|
|
$col = trim($value['rackCol']);
|
|
$code = $almariCode . $row . $col;
|
|
$sql = "INSERT INTO warehouserack(
|
|
WarehouseRackWarehouseAlmariID,
|
|
WarehouseRackCode,
|
|
WarehouseRackName,
|
|
WarehouseRackRow,
|
|
WarehouseRackCol,
|
|
WarehouseRackIsActive,
|
|
WarehouseRackUserID,
|
|
WarehouseRackCreated,
|
|
WarehouseRackLastUpdated)
|
|
VALUES (
|
|
?, ?, ?, ?,?,'Y', ?,NOW(),NOW()
|
|
)";
|
|
$qry = $this->inventory->query($sql, array($inserted_almari_id, $code, $name, $row, $col, $userid));
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
} else {
|
|
$rak_inserted_id = $this->inventory->insert_id();
|
|
$sql = "SELECT * FROM warehouserack WHERE WarehouseRackID = ?";
|
|
$qry = $this->inventory->query($sql, array($rak_inserted_id));
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
} else {
|
|
$rak_json_after = $qry->row_array();
|
|
|
|
$sql = "INSERT INTO warehouserack_log
|
|
(WarehouseRackLogStatus,
|
|
WarehouseRackLogWarehouseRackId,
|
|
WarehouseRackLogJSONBefore,
|
|
WarehouseRackLogJSONAfter,
|
|
WarehouseRackLogUserId,
|
|
WarehouseRackLogCreated)
|
|
VALUES(
|
|
'ADD', ?,NULL,?,?, NOW()
|
|
)";
|
|
$qry = $this->log_inventory->query($sql, array($rak_inserted_id, json_encode($rak_json_after), $userid));
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->log_inventory->error()["message"],
|
|
"qry" => $this->log_inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
array_push($rak_log, $rak_json_after);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$sql = "SELECT * FROM warehousealmari WHERE WarehouseAlmariID= ?";
|
|
$qry = $this->inventory->query($sql, array($inserted_almari_id));
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
} else {
|
|
$almari_json_after = $qry->row_array();
|
|
$almari_json_after['rack'] = $rak_log;
|
|
$sql = "INSERT INTO warehousealmari_log
|
|
(WarehouseAlmariLogStatus,
|
|
WarehouseAlmariLogWarehouseAlmariId,
|
|
WarehouseAlmariLogJSONBefore,
|
|
WarehouseAlmariLogJSONAfter,
|
|
WarehouseAlmariLogUserId,
|
|
WarehouseAlmariLogCreated)
|
|
VALUES(
|
|
'ADD', ?,NULL,?,?,NOW()
|
|
)";
|
|
$qry = $this->log_inventory->query($sql, array($inserted_almari_id, json_encode($almari_json_after), $userid));
|
|
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->log_inventory->error()["message"],
|
|
"qry" => $this->log_inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
$this->sys_error_db("save almari error", $this->inventory->last_query());
|
|
exit;
|
|
}
|
|
$this->inventory->trans_complete();
|
|
$result = array(
|
|
"message" => "success",
|
|
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function edit()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$almariId = "";
|
|
if (isset($prm['almariId'])) {
|
|
$almariId = trim($prm["almariId"]);
|
|
}
|
|
|
|
$almariName = "";
|
|
if (isset($prm['almariName'])) {
|
|
$almariName = trim($prm["almariName"]);
|
|
}
|
|
|
|
$rak = [];
|
|
if (isset($prm['rack'])) {
|
|
$rak = $prm["rack"];
|
|
}
|
|
if ($almariId == "" || $almariName == "" || $rak == "") {
|
|
$this->sys_error("almari id, almari name and rack is mandatory");
|
|
exit;
|
|
}
|
|
$this->inventory->trans_start();
|
|
$this->inventory->trans_strict(FALSE);
|
|
|
|
$sql_almari_json_before = "SELECT * FROM warehousealmari WHERE WarehouseAlmariID= ?";
|
|
$qry_almari_json_before = $this->inventory->query($sql_almari_json_before, array($almariId));
|
|
if (!$qry_almari_json_before) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$almari_json_before = $qry_almari_json_before->row_array();
|
|
|
|
$sql_rak_json_before = "SELECT * FROM warehouserack WHERE WarehouseRackWarehouseAlmariID= ?";
|
|
$qry_rak_json_before = $this->inventory->query($sql_rak_json_before, array($almariId));
|
|
if (!$qry_rak_json_before) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rak_json_before = $qry_rak_json_before->result_array();
|
|
$almari_json_before['rack'] = $rak_json_before;
|
|
|
|
$sql = "UPDATE warehousealmari
|
|
SET WarehouseAlmariName = ?,
|
|
WarehouseAlmariLastUpdated = NOW()
|
|
WHERE WarehouseAlmariID = ? ";
|
|
$qry = $this->inventory->query($sql, [$almariName, $almariId]);
|
|
$lst = $this->inventory->last_query();
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $lst,
|
|
"aa" => "aaa"
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
if (count($rak) > 0) {
|
|
foreach ($rak as $key => $value) {
|
|
$id = trim($value['rackId']);
|
|
$name = trim($value['rackName']);
|
|
$sql_rak_json_before = "SELECT * FROM warehouserack WHERE WarehouseRackID= ?";
|
|
$qry_rak_json_before = $this->inventory->query($sql_rak_json_before, array($id));
|
|
if (!$qry_rak_json_before) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rak_json_before = $qry_rak_json_before->row_array();
|
|
|
|
$sql = "UPDATE warehouserack
|
|
SET WarehouseRackName = ?,
|
|
WarehouseRackLastUpdated =NOW()
|
|
WHERE WarehouseRackID = ?";
|
|
$qry = $this->inventory->query($sql, array($name, $id));
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$sql_rak_json_after = "SELECT * FROM warehouserack WHERE WarehouseRackID= ?";
|
|
$qry_rak_json_after = $this->inventory->query($sql_rak_json_after, array($id));
|
|
if (!$qry_rak_json_after) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rak_json_after = $qry_rak_json_after->row_array();
|
|
|
|
$sql_rak_log = "INSERT INTO warehouserack_log
|
|
(WarehouseRackLogStatus,
|
|
WarehouseRackLogWarehouseRackId,
|
|
WarehouseRackLogJSONBefore,
|
|
WarehouseRackLogJSONAfter,
|
|
WarehouseRackLogUserId,
|
|
WarehouseRackLogCreated)
|
|
VALUES(
|
|
'EDIT', ?,?,?,?, NOW()
|
|
)";
|
|
$qry_rak_log = $this->log_inventory->query($sql_rak_log, array(
|
|
$id,
|
|
json_encode($rak_json_before),
|
|
json_encode($rak_json_after),
|
|
$userid
|
|
));
|
|
if (!$qry_rak_log) {
|
|
$error = array(
|
|
"message" => $this->log_inventory->error()["message"],
|
|
"qry" => $this->log_inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql_almari_json_after = "SELECT * FROM warehousealmari WHERE WarehouseAlmariID= ?";
|
|
$qry_almari_json_after = $this->inventory->query($sql_almari_json_after, array($almariId));
|
|
if (!$qry_almari_json_after) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$almari_json_after = $qry_almari_json_after->row_array();
|
|
|
|
$sql_rak_json_after = "SELECT * FROM warehouserack WHERE WarehouseRackWarehouseAlmariID= ?";
|
|
$qry_rak_json_after = $this->inventory->query($sql_rak_json_after, array($almariId));
|
|
if (!$qry_rak_json_after) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rak_json_after = $qry_rak_json_after->result_array();
|
|
$almari_json_after['rack'] = $rak_json_after;
|
|
|
|
$sql_almari_log = "INSERT INTO warehousealmari_log
|
|
(WarehouseAlmariLogStatus,
|
|
WarehouseAlmariLogWarehouseAlmariId,
|
|
WarehouseAlmariLogJSONBefore,
|
|
WarehouseAlmariLogJSONAfter,
|
|
WarehouseAlmariLogUserId,
|
|
WarehouseAlmariLogCreated)
|
|
VALUES(
|
|
'EDIT', ?,?,?,?,NOW()
|
|
)";
|
|
$qry_almari_log = $this->log_inventory->query($sql_almari_log, array(
|
|
$almariId,
|
|
json_encode($almari_json_before),
|
|
json_encode($almari_json_after),
|
|
$userid
|
|
));
|
|
if (!$qry_almari_log) {
|
|
$error = array(
|
|
"message" => $this->log_inventory->error()["message"],
|
|
"qry" => $this->log_inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$this->inventory->trans_complete();
|
|
$result = array(
|
|
"message" => "success",
|
|
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function delete()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$almariId = "";
|
|
if (isset($prm['almariId'])) {
|
|
$almariId = trim($prm["almariId"]);
|
|
}
|
|
if ($almariId == "") {
|
|
$this->sys_error("almari id is mandatory");
|
|
exit;
|
|
}
|
|
$rak = [];
|
|
if (isset($prm['rack'])) {
|
|
$rak = $prm["rack"];
|
|
}
|
|
$this->inventory->trans_start();
|
|
$this->inventory->trans_strict(FALSE);
|
|
$sql = "UPDATE warehousealmari
|
|
SET WarehouseAlmariIsActive = 'N',
|
|
WarehouseAlmariLastUpdated =NOW()
|
|
WHERE WarehouseAlmariID = ?";
|
|
$qry = $this->inventory->query($sql, array($almariId));
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
} else {
|
|
if (count($rak) > 0) {
|
|
foreach ($rak as $key => $value) {
|
|
$id = trim($value['rackId']);
|
|
$name = trim($value['rackName']);
|
|
|
|
$sql = "UPDATE warehouserack
|
|
SET WarehouseRackIsActive = 'N',
|
|
WarehouseRackLastUpdated =NOW()
|
|
WHERE WarehouseRackID = ?";
|
|
$qry = $this->inventory->query($sql, array($id));
|
|
if (!$qry) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$sql_rak_json_after = "SELECT * FROM warehouserack WHERE WarehouseRackID= ?";
|
|
$qry_rak_json_after = $this->inventory->query($sql_rak_json_after, array($id));
|
|
if (!$qry_rak_json_after) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rak_json_after = $qry_rak_json_after->row_array();
|
|
|
|
$sql_rak_log = "INSERT INTO warehouserack_log
|
|
(WarehouseRackLogStatus,
|
|
WarehouseRackLogWarehouseRackId,
|
|
WarehouseRackLogJSONBefore,
|
|
WarehouseRackLogJSONAfter,
|
|
WarehouseRackLogUserId,
|
|
WarehouseRackLogCreated)
|
|
VALUES(
|
|
'DELETE', ?,NULL,?,?, NOW()
|
|
)";
|
|
$qry_rak_log = $this->log_inventory->query($sql_rak_log, array(
|
|
$id,
|
|
json_encode($rak_json_after),
|
|
$userid
|
|
));
|
|
if (!$qry_rak_log) {
|
|
$error = array(
|
|
"message" => $this->log_inventory->error()["message"],
|
|
"qry" => $this->log_inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$sql_almari_json_after = "SELECT * FROM warehousealmari WHERE WarehouseAlmariID= ?";
|
|
$qry_almari_json_after = $this->inventory->query($sql_almari_json_after, array($almariId));
|
|
if (!$qry_almari_json_after) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$almari_json_after = $qry_almari_json_after->row_array();
|
|
|
|
$sql_rak_json_after = "SELECT * FROM warehouserack WHERE WarehouseRackWarehouseAlmariID= ?";
|
|
$qry_rak_json_after = $this->inventory->query($sql_rak_json_after, array($almariId));
|
|
if (!$qry_rak_json_after) {
|
|
$error = array(
|
|
"message" => $this->inventory->error()["message"],
|
|
"qry" => $this->inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$rak_json_after = $qry_rak_json_after->result_array();
|
|
$almari_json_after['rack'] = $rak_json_after;
|
|
|
|
$sql_almari_log = "INSERT INTO warehousealmari_log
|
|
(WarehouseAlmariLogStatus,
|
|
WarehouseAlmariLogWarehouseAlmariId,
|
|
WarehouseAlmariLogJSONBefore,
|
|
WarehouseAlmariLogJSONAfter,
|
|
WarehouseAlmariLogUserId,
|
|
WarehouseAlmariLogCreated)
|
|
VALUES(
|
|
'DELETE', ?,NULL,?,?,NOW()
|
|
)";
|
|
$qry_almari_log = $this->log_inventory->query($sql_almari_log, array(
|
|
$almariId,
|
|
json_encode($almari_json_after),
|
|
$userid
|
|
));
|
|
if (!$qry_almari_log) {
|
|
$error = array(
|
|
"message" => $this->log_inventory->error()["message"],
|
|
"qry" => $this->log_inventory->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$this->inventory->trans_complete();
|
|
$result = array(
|
|
"message" => "success",
|
|
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|