1349 lines
53 KiB
PHP
1349 lines
53 KiB
PHP
<?php
|
|
class Receive extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
$this->db_inventory_log = $this->load->database('inventory_log', true);
|
|
$this->db_onex = 'one_aditya';
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$search = "%%";
|
|
if (isset($prm['search']) && trim($prm["search"]) != '') {
|
|
$search = trim($prm["search"]);
|
|
$search = '%' . $prm['search'] . '%';
|
|
}
|
|
$start_date = date("Y-m-d");
|
|
if (isset($prm['start_date'])) {
|
|
$start_date = $prm["start_date"];
|
|
}
|
|
$end_date = date("Y-m-d");
|
|
if (isset($prm['end_date'])) {
|
|
$end_date = $prm["end_date"];
|
|
}
|
|
$filter_warehouse = '';
|
|
if (isset($prm['warehouse_id']) && intval($prm['warehouse_id']) > 0) {
|
|
$filter_warehouse = ' AND WarehouseID = '.$prm['warehouse_id'];
|
|
}
|
|
$order_by = "PurchaseReturReceiveNumber";
|
|
if (isset($prm['order_by'])) {
|
|
$order_by = trim($prm["order_by"]);
|
|
}
|
|
$order_type = "asc";
|
|
if (isset($prm['order_type'])) {
|
|
$order_type = trim($prm["order_type"]);
|
|
}
|
|
$order = $order_by.' '.$order_type;
|
|
$perpage = 10;
|
|
$offset = ($prm['current_page'] - 1) * $perpage ;
|
|
|
|
$sql = "SELECT COUNT(*) as total FROM
|
|
(
|
|
SELECT PurchaseReturReceiveID
|
|
FROM `purchasereturreceive`
|
|
JOIN `warehouse` ON PurchaseReturReceiveWarehouseID = WarehouseID $filter_warehouse
|
|
WHERE
|
|
PurchaseReturReceiveIsActive = 'Y' AND (PurchaseReturReceiveDate BETWEEN ? AND ?) AND
|
|
( PurchaseReturReceiveNumber like ? )
|
|
) x";
|
|
$qry = $this->db_inventory->query($sql,array($start_date, $end_date, $search));
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry) {
|
|
$tot_count = $qry->row()->total;
|
|
$tot_page = ceil($tot_count/$perpage);
|
|
} else {
|
|
$this->sys_error_db("purchase order count error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$rows = array();
|
|
$sql = "SELECT PurchaseReturReceiveID as id,
|
|
PurchaseReturReceiveWarehouseID as warehouse_id,
|
|
WarehouseName as warehouse_name,
|
|
PurchaseReturReceivePurchaseReturID as po_id,
|
|
PurchaseReturNumber as po_number,
|
|
PurchaseReturReceiveNumber as numbering,
|
|
DATE_FORMAT(PurchaseReturReceiveDate,'%d-%m-%Y') as purchase_date,
|
|
IFNULL(M_UserUsername,'') as user_receive,
|
|
PurchaseReturReceiveIsConfirm as is_confirm,
|
|
'' as details
|
|
FROM `purchasereturreceive`
|
|
JOIN `warehouse` ON PurchaseReturReceiveWarehouseID = WarehouseID $filter_warehouse
|
|
JOIN purchaseretur ON PurchaseReturID = PurchaseReturReceivePurchaseReturID
|
|
LEFT JOIN $this->db_onex.m_user ON PurchaseReturReceiveUserID = M_UserID
|
|
WHERE
|
|
PurchaseReturReceiveIsActive = 'Y' AND (PurchaseReturReceiveDate BETWEEN ? AND ?) AND
|
|
( PurchaseReturReceiveNumber like ? )
|
|
ORDER BY $order_by $order_type
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db_inventory->query($sql, array($start_date, $end_date, $search, $perpage, $offset));
|
|
//echo $this->db_inventory->last_query();
|
|
if($qry){
|
|
$rows = $qry->result_array();
|
|
if(count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$sql = "SELECT PurchaseReturReceiveDetailID as id,
|
|
PurchaseReturNumber as po_number,
|
|
SupplierName as supplier_name,
|
|
PurchaseReturDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
ItemSKU as item_sku,
|
|
PurchaseReturDetailItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
PurchaseReturDetailQty as po_qty,
|
|
PurchaseReturReceiveDetailQty as receive_qty,
|
|
PurchaseReturReceiveDetailQty as qty,
|
|
'N' as is_exist,
|
|
'N' as selected
|
|
FROM `purchasereturreceivedetail`
|
|
JOIN purchasereturdetail ON PurchaseReturDetailID = PurchaseReturReceiveDetailPurchaseReturDetailID
|
|
JOIN purchaseretur ON PurchaseReturID = PurchaseReturDetailPurchaseReturID
|
|
JOIN `item` ON PurchaseReturDetailItemID = ItemID
|
|
LEFT JOIN itemunit ON PurchaseReturDetailItemUnitID = ItemUnitID
|
|
JOIN supplier ON SupplierID = PurchaseReturSupplierID
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ? AND
|
|
PurchaseReturReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($value['id']));
|
|
if($qry){
|
|
$rows[$key]['details'] = $qry->result_array();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}else {
|
|
// echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("purchase order data error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
|
|
$result = array("total_page" => $tot_page, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function save(){
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$warehouseid = $prm["warehouseid"];
|
|
$poid = $prm["poid"];
|
|
$sdate = $prm["sdate"];
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$numbering = '';
|
|
$sql = "SELECT `fn_numbering`('RR') as numbering";
|
|
$qry = $this->db_inventory->query($sql);
|
|
if($qry){
|
|
$numbering = $qry->row()->numbering;
|
|
}
|
|
else{
|
|
$this->sys_error_db("get numbering error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$last_id = 0;
|
|
$sql = "INSERT INTO purchasereturreceive(
|
|
PurchaseReturReceiveNumber,
|
|
PurchaseReturReceiveDate,
|
|
PurchaseReturReceiveWarehouseID,
|
|
PurchaseReturReceivePurchaseReturID,
|
|
PurchaseReturReceiveCreated,
|
|
PurchaseReturReceiveLastUpdated,
|
|
PurchaseReturReceiveUserID)
|
|
VALUES(
|
|
?,?,?,?,NOW(),NOW(),?)";
|
|
$qry = $this->db_inventory->query($sql, array($numbering,$sdate,$warehouseid,$poid,$userid));
|
|
$last_id = 0;
|
|
// echo $this->db_inventory->last_query();
|
|
if($qry){
|
|
$last_id = $this->db_inventory->insert_id();
|
|
}
|
|
else{
|
|
$this->sys_error_db("save purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
foreach ($prm['details'] as $key => $value) {
|
|
$qty = $value['qty'];
|
|
$id = $value['id'];
|
|
$po_qty = $value['po_qty'];
|
|
$batch_no = $value['batch_no'];
|
|
$almariid = $value['almariid'];
|
|
$rackid = $value['rackid'];
|
|
$item_id = $value['item_id'];
|
|
$unit_id = $value['unit_id'];
|
|
$ed = substr($value['ed'],4,4).'-'.substr($value['ed'],2,2).'-'.substr($value['ed'],0,2);
|
|
if($qty > 0){
|
|
$sql = "INSERT INTO purchasereturreceivedetail(
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID,
|
|
PurchaseReturReceiveDetailPurchaseReturDetailID,
|
|
PurchaseReturReceiveDetailItemID,
|
|
PurchaseReturReceiveDetailItemUnitID,
|
|
PurchaseReturReceiveDetailQtyPO,
|
|
PurchaseReturReceiveDetailQty,
|
|
PurchaseReturReceiveDetailBatchNo,
|
|
PurchaseReturReceiveDetailED,
|
|
PurchaseReturReceiveDetailWarehouseAlmariID,
|
|
PurchaseReturReceiveDetailWarehouseRackID,
|
|
PurchaseReturReceiveDetailCreated,
|
|
PurchaseReturReceiveDetailLastUpdated,
|
|
PurchaseReturReceiveDetailUserID)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,?,NOW(),NOW(),?)";
|
|
$qry = $this->db_inventory->query($sql, array($last_id, $id, $item_id, $unit_id, $po_qty, $qty,$batch_no,$ed,$almariid,$rackid,$userid));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("save purchasereturreceive detail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
$id = $last_id;
|
|
$sql = "SELECT purchasereturreceive.*, '' as details
|
|
FROM purchasereturreceive
|
|
WHERE PurchaseReturReceiveID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturreceivedetail`
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ? AND
|
|
PurchaseReturReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturreceive details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
$sql = "INSERT INTO purchasereturreceive_log (
|
|
PurchaseReturReceiveLogPurchaseReturReceiveID,
|
|
PurchaseReturReceiveLogStatus,
|
|
PurchaseReturReceiveLogJSONBefore,
|
|
PurchaseReturReceiveLogJSONAfter,
|
|
PurchaseReturReceiveLogUserID,
|
|
PurchaseReturReceiveLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'ADD',NULL,json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
|
|
$result = array(
|
|
"message" => ''
|
|
);
|
|
$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'];
|
|
|
|
$this->update($prm,$userid);
|
|
|
|
|
|
$result = array(
|
|
"message" => ''
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function update($prm,$userid){
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$warehouseid = $prm["warehouseid"];
|
|
$poid = $prm["poid"];
|
|
$sdate = $prm["sdate"];
|
|
$id = $prm["id"];
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
foreach ($prm['details'] as $key => $value) {
|
|
$qty = $value['qty'];
|
|
$detailid = $value['id'];
|
|
$po_qty = $value['po_qty'];
|
|
$batch_no = $value['batch_no'];
|
|
$almariid = $value['almariid'];
|
|
$rackid = $value['rackid'];
|
|
$ed = substr($value['ed'],4,4).'-'.substr($value['ed'],2,2).'-'.substr($value['ed'],0,2);
|
|
if($qty > 0){
|
|
$sql = "UPDATE purchasereturreceivedetail SET
|
|
PurchaseReturReceiveDetailQty = ?,
|
|
PurchaseReturReceiveDetailBatchNo = ?,
|
|
PurchaseReturReceiveDetailED = ?,
|
|
PurchaseReturReceiveDetailWarehouseAlmariID = ?,
|
|
PurchaseReturReceiveDetailWarehouseRackID = ?,
|
|
PurchaseReturReceiveDetailLastUpdated = now(),
|
|
PurchaseReturReceiveDetailUserID = ?
|
|
WHERE PurchaseReturReceiveDetailID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, array($qty, $batch_no, $ed, $almariid, $rackid,$userid, $detailid));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("update purchasereturreceive detail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
$sql = "SELECT purchasereturreceive.*, '' as details
|
|
FROM purchasereturreceive
|
|
WHERE PurchaseReturReceiveID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturreceivedetail`
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ? AND
|
|
PurchaseReturReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturreceive details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
$sql = "INSERT INTO purchasereturreceive_log (
|
|
PurchaseReturReceiveLogPurchaseReturReceiveID,
|
|
PurchaseReturReceiveLogStatus,
|
|
PurchaseReturReceiveLogJSONBefore,
|
|
PurchaseReturReceiveLogJSONAfter,
|
|
PurchaseReturReceiveLogUserID,
|
|
PurchaseReturReceiveLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'EDIT',NULL,json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
return true;
|
|
|
|
}
|
|
function confirm()
|
|
{
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$param = $this->sys_input;
|
|
|
|
$this->edit($param,$userid);
|
|
$this->update_po_detail($param,$userid);
|
|
$this->update_stock($param,$userid);
|
|
$id = "";
|
|
if (isset($param['id'])) {
|
|
$id = intval($param["id"]);
|
|
}
|
|
if ($id == "" || !$id) {
|
|
$error = array(
|
|
"message" => "id is mandatory",
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT purchasereturreceive.*, '' as details
|
|
FROM purchasereturreceive
|
|
WHERE PurchaseReturReceiveID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturreceivedetail`
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ? AND
|
|
PurchaseReturReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturreceive details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_before = $row;
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "UPDATE purchasereturreceive
|
|
SET PurchaseReturReceiveIsConfirm = 'Y',
|
|
PurchaseReturReceiveLastUpdated = NOW(),
|
|
PurchaseReturReceiveConfirmDatetime = NOW(),
|
|
PurchaseReturReceiveConfirmBy = ?,
|
|
PurchaseReturReceiveUserID = ?
|
|
WHERE PurchaseReturReceiveID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$userid,$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("confirm purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT purchasereturreceive.*, '' as details
|
|
FROM purchasereturreceive
|
|
WHERE PurchaseReturReceiveID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturreceivedetail`
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ? AND
|
|
PurchaseReturReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturreceive details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO purchasereturreceive_log (
|
|
PurchaseReturReceiveLogPurchaseReturReceiveID,
|
|
PurchaseReturReceiveLogStatus,
|
|
PurchaseReturReceiveLogJSONBefore,
|
|
PurchaseReturReceiveLogJSONAfter,
|
|
PurchaseReturReceiveLogUserID,
|
|
PurchaseReturReceiveLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'CONFIRM',json_decode($data_log_before),json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
return true;
|
|
}
|
|
function update_po_detail($prm,$userid){
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$warehouseid = $prm["warehouseid"];
|
|
$poid = $prm["poid"];
|
|
$sdate = $prm["sdate"];
|
|
$id = $prm["id"];
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
foreach ($prm['details'] as $key => $value) {
|
|
$qty = $value['qty'];
|
|
$detailid = $value['podetailid'];
|
|
$batch_no = $value['batch_no'];
|
|
$ed = substr($value['ed'],4,4).'-'.substr($value['ed'],2,2).'-'.substr($value['ed'],0,2);
|
|
if($qty > 0){
|
|
$sqty =
|
|
$sql = "UPDATE purchasereturdetail SET
|
|
PurchaseReturDetailStatus = IF(PurchaseReturDetailReceiveQty+$qty = PurchaseReturDetailQty,'D','P'),
|
|
PurchaseReturDetailReceiveQty = PurchaseReturDetailReceiveQty+$qty
|
|
WHERE PurchaseReturDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql, array($detailid));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("update purchasereturdetail detail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$x = $this->db_inventory->query("SELECT SUM(PurchaseReturDetailQty) as qty FROM
|
|
purchasereturdetail
|
|
WHERE PurchaseReturDetailPurchaseReturID = $poid AND PurchaseReturDetailIsActive = 'Y'")->row();
|
|
$poqty = $x->qty;
|
|
|
|
$y = $this->db_inventory->query("SELECT SUM(PurchaseReturDetailReceiveQty) as qty FROM
|
|
purchasereturdetail
|
|
WHERE PurchaseReturDetailPurchaseReturID = $poid AND PurchaseReturDetailIsActive = 'Y'")->row();
|
|
$receiveqty = $y->qty;
|
|
|
|
$is_status = 'N';
|
|
if($receiveqty > 0 && $receiveqty < $poqty){
|
|
$is_status = 'P';
|
|
}elseif($receiveqty > 0 && $receiveqty = $poqty){
|
|
$is_status = 'D';
|
|
}
|
|
$sql = "UPDATE purchaseretur SET
|
|
PurchaseReturStatus = '{$is_status}'
|
|
WHERE PurchaseReturID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, array($poid));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("update purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$this->db_inventory->trans_complete();
|
|
|
|
return true;
|
|
|
|
}
|
|
function update_stock($prm,$userid){
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$warehouseid = $prm["warehouseid"];
|
|
$poid = $prm["poid"];
|
|
$sdate = $prm["sdate"];
|
|
$id = $prm["id"];
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
foreach ($prm['details'] as $key => $value) {
|
|
$qty = $value['qty'];
|
|
$detailid = $value['id'];
|
|
$item_id = $value['item_id'];
|
|
$item_sku = $value['item_sku'];
|
|
$unit_id = $value['unit_id'];
|
|
$batch_no = $value['batch_no'];
|
|
$almariid = $value['almariid'];
|
|
$rackid = $value['rackid'];
|
|
$ed = substr($value['ed'],4,4).'-'.substr($value['ed'],2,2).'-'.substr($value['ed'],0,2);
|
|
$stok_number = '';
|
|
$stok_qty = '';
|
|
if($qty > 0){
|
|
$s_number = $this->db_inventory->query("SELECT `fn_numbering_stock`('{$item_sku}') as stok_number")->row();
|
|
$stok_number = $s_number->stok_number;
|
|
|
|
$sql = "UPDATE purchasereturreceivedetail SET
|
|
PurchaseReturReceiveDetailStockNumber = '{$stok_number}'
|
|
WHERE PurchaseReturReceiveDetailID = $detailid
|
|
";
|
|
$qry = $this->db_inventory->query($sql);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("update purchasereturdetail detail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
//echo $stok_number;
|
|
$sql = "insert into stock(
|
|
StockWarehouseID,
|
|
StockWarehouseAlmariID,
|
|
StockWarehouseRackID,
|
|
StockStockNumber,
|
|
StockItemID,
|
|
StockItemUnitID,
|
|
StockBatchNo,
|
|
StockED,
|
|
StockQty,
|
|
StockLastUpdated,
|
|
StockUserID)
|
|
VALUES(
|
|
'{$warehouseid}',
|
|
'{$almariid}',
|
|
'{$rackid}',
|
|
'{$stok_number}',
|
|
'{$item_id}',
|
|
'{$unit_id}',
|
|
'{$batch_no}',
|
|
'{$ed}',
|
|
'{$qty}',
|
|
now(),
|
|
$userid)";
|
|
$qry = $this->db_inventory->query($sql);
|
|
// echo $query;
|
|
if(!$qry){
|
|
$this->sys_error_db("insert stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$x = $this->db_inventory->query("SELECT StockCardAfter as beforeqty FROM
|
|
stockcard
|
|
WHERE StockCardItemID = $item_id
|
|
AND StockCardItemUnitID = $unit_id
|
|
AND StockCardBatchNo = '{$batch_no}'
|
|
AND StockCardED = '{$ed}'
|
|
AND StockCardWarehouseID = $warehouseid
|
|
ORDER BY StockCardID DESC LIMIT 1")->row();
|
|
$beforeqty = $x->beforeqty;
|
|
$afterqty = $beforeqty + $qty;
|
|
|
|
$sql = "insert into stockcard(
|
|
StockCardItemID,
|
|
StockCardItemUnitID,
|
|
StockCardBatchNo,
|
|
StockCardReffID,
|
|
StockCardBefore,
|
|
StockCardIn,
|
|
StockCardAfter,
|
|
StockCardED,
|
|
StockCardStatus,
|
|
StockCardWarehouseID,
|
|
StockCardDatetime,
|
|
StockCardUserID)
|
|
VALUES('{$item_id}',
|
|
'{$unit_id}',
|
|
'{$batch_no}',
|
|
'{$detailid}',
|
|
'{$beforeqty}',
|
|
'{$qty}',
|
|
'{$afterqty}',
|
|
'{$ed}',
|
|
'RPR',
|
|
'{$warehouseid}',
|
|
now(),
|
|
$userid)";
|
|
// echo $sql;
|
|
$qry = $this->db_inventory->query($sql);
|
|
// echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("insert stock card error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "insert into stocklog(
|
|
StockLogStockNumber,
|
|
StockLogItemID,
|
|
StockLogItemUnitID,
|
|
StockLogBatchNo,
|
|
StockLogReffID,
|
|
StockLogQty,
|
|
StockLogED,
|
|
StockLogStatus,
|
|
StockLogWarehouseID,
|
|
StockLogWarehouseAlmariID,
|
|
StockLogWarehouseRackID,
|
|
StockLogDatetime,
|
|
StockLogUserID)
|
|
VALUES('{$stok_number}',
|
|
'{$item_id}',
|
|
'{$unit_id}',
|
|
'{$batch_no}',
|
|
'{$detailid}',
|
|
'{$qty}',
|
|
'{$ed}',
|
|
'RPR',
|
|
'{$warehouseid}',
|
|
'{$almariid}',
|
|
'{$rackid}',
|
|
now(),
|
|
$userid)";
|
|
// echo $sql;
|
|
$qry = $this->db_inventory->query($sql);
|
|
// echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("insert stock log error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
$this->db_inventory->trans_complete();
|
|
|
|
return true;
|
|
|
|
}
|
|
function delete()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$param = $this->sys_input;
|
|
$id = "";
|
|
if (isset($param['id'])) {
|
|
$id = intval($param["id"]);
|
|
}
|
|
if ($id == "" || !$id) {
|
|
$error = array(
|
|
"message" => "id is mandatory",
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "UPDATE purchasereturreceive
|
|
SET PurchaseReturReceiveIsActive = 'N',
|
|
PurchaseReturReceiveLastUpdated = now(),
|
|
PurchaseReturReceiveUserID = ?
|
|
WHERE PurchaseReturReceiveID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("delete purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}else{
|
|
$sql = "UPDATE purchasereturreceivedetail
|
|
SET PurchaseReturReceiveDetailIsActive = 'N',
|
|
PurchaseReturReceiveDetailLastUpdated = now(),
|
|
PurchaseReturReceiveDetailUserID = ?
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->sys_error_db("delete supplier address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT purchasereturreceive.*, '' as details
|
|
FROM purchasereturreceive
|
|
WHERE PurchaseReturReceiveID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchasereturreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturreceivedetail`
|
|
WHERE
|
|
PurchaseReturReceiveDetailPurchaseReturReceiveID = ? AND
|
|
PurchaseReturReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturreceive details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
$sql = "INSERT INTO purchasereturreceive_log (
|
|
PurchaseReturReceiveLogPurchaseReturReceiveID,
|
|
PurchaseReturReceiveLogStatus,
|
|
PurchaseReturReceiveLogJSONBefore,
|
|
PurchaseReturReceiveLogJSONAfter,
|
|
PurchaseReturReceiveLogUserID,
|
|
PurchaseReturReceiveLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'DELETE',NULL,json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
|
|
$result = array(
|
|
"message" => ''
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
function search_warehouse(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM supplier
|
|
WHERE
|
|
SupplierName like ?
|
|
AND SupplierIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Semua');
|
|
$sql = "
|
|
SELECT SupplierID as id, SupplierName as name
|
|
FROM supplier
|
|
WHERE
|
|
SupplierName like ?
|
|
AND SupplierIsActive = 'Y'
|
|
ORDER BY SupplierName DESC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplier rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_po_form(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM purchaseretur
|
|
JOIN supplier ON SupplierID = PurchaseReturSupplierID
|
|
WHERE
|
|
PurchaseReturNumber like ?
|
|
AND PurchaseReturIsActive = 'Y'
|
|
AND PurchaseReturIsConfirm = 'Y'
|
|
AND PurchaseReturStatus NOT IN('D','Y')";
|
|
$query = $this->db_inventory->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Cari Purchase Retur','sup_name' => '');
|
|
$sql = "SELECT 0 as id, 'Cari Purchase Retur' as name, '' as sup_name
|
|
UNION
|
|
SELECT PurchaseReturID as id, PurchaseReturNumber as name, SupplierName as sup_name
|
|
FROM purchaseretur
|
|
JOIN supplier ON SupplierID = PurchaseReturSupplierID
|
|
WHERE
|
|
PurchaseReturNumber like ?
|
|
AND PurchaseReturIsActive = 'Y'
|
|
AND PurchaseReturIsConfirm = 'Y'
|
|
AND PurchaseReturStatus NOT IN('D','Y')
|
|
ORDER BY name DESC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//array_push($rows,array('id'=>0,'name'=>'Pilih Supplier'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplier rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_expedition(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM expedition
|
|
WHERE
|
|
ExpeditionName like ?
|
|
AND ExpeditionIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Semua');
|
|
$sql = "
|
|
SELECT ExpeditionID as id, ExpeditionName as name
|
|
FROM expedition
|
|
WHERE
|
|
ExpeditionName like ?
|
|
AND ExpeditionIsActive = 'Y'
|
|
ORDER BY ExpeditionName DESC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("expedition rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search_supplier_form(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM supplier WHERE
|
|
SupplierName like ?
|
|
AND SupplierIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Cari Supplier');
|
|
$sql = "SELECT 0 as id, 'Cari Supplier' as name
|
|
UNION
|
|
SELECT SupplierID as id, SupplierName as name
|
|
FROM supplier WHERE
|
|
SupplierName like ?
|
|
AND SupplierIsActive = 'Y'
|
|
ORDER BY name DESC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//array_push($rows,array('id'=>0,'name'=>'Pilih Supplier'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplier rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function search_supplier_filter(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM supplier WHERE
|
|
SupplierName like ?
|
|
AND SupplierIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Cari Supplier');
|
|
$sql = "SELECT 0 as id, 'Cari Supplier' as name
|
|
UNION
|
|
SELECT SupplierID as id, SupplierName as name
|
|
FROM supplier WHERE
|
|
SupplierName like ?
|
|
AND SupplierIsActive = 'Y'
|
|
ORDER BY name DESC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//array_push($rows,array('id'=>0,'name'=>'Pilih Supplier'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplier rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_data_po_form(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$sql = "SELECT 0 as id,
|
|
'Pilih Purchase Retur' as name
|
|
|
|
UNION SELECT PurchaseReturID as id, PurchaseReturNumber as name
|
|
FROM purchaseretur
|
|
JOIN supplier ON SupplierID = PurchaseReturSupplierID
|
|
WHERE
|
|
PurchaseReturSupplierID = $id
|
|
AND PurchaseReturIsActive = 'Y'
|
|
AND PurchaseReturIsConfirm = 'Y'
|
|
AND PurchaseReturStatus NOT IN('D')
|
|
ORDER BY id ASC";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->result_array();
|
|
$result = array("records" => $row);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("purchaseorder rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_data_warehouse(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT 0 as id,
|
|
'' as code,
|
|
'Pilih Gudang' as name
|
|
|
|
UNION SELECT WarehouseID as id,
|
|
WarehouseCode as code,
|
|
WarehouseName as name
|
|
FROM warehouse
|
|
JOIN warehousealmari ON WarehouseAlmariWarehouseID = WarehouseID AND WarehouseAlmariIsActive = 'Y'
|
|
JOIN warehouserack ON WarehouseRackWarehouseAlmariID = WarehouseAlmariID AND WarehouseAlmariIsActive = 'Y'
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'Y'
|
|
ORDER BY id ASC";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->result_array();
|
|
$result = array("records" => $row);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehouse rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_data_warehouse_filter(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT 0 as id,
|
|
'' as code,
|
|
'Semua Gudang' as name
|
|
|
|
UNION SELECT WarehouseID as id,
|
|
WarehouseCode as code,
|
|
WarehouseName as name
|
|
FROM warehouse
|
|
JOIN warehousealmari ON WarehouseAlmariWarehouseID = WarehouseID AND WarehouseAlmariIsActive = 'Y'
|
|
JOIN warehouserack ON WarehouseRackWarehouseAlmariID = WarehouseAlmariID AND WarehouseAlmariIsActive = 'Y'
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'Y'
|
|
ORDER BY id ASC";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->result_array();
|
|
$result = array("records" => $row);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehouse rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_data_almari(){
|
|
try{
|
|
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm["id"];
|
|
|
|
$sql = "SELECT WarehouseAlmariID as id,
|
|
WarehouseAlmariCode as code,
|
|
WarehouseAlmariName as name
|
|
FROM warehousealmari
|
|
WHERE
|
|
WarehouseAlmariIsActive = 'Y'
|
|
AND WarehouseAlmariWarehouseID = $id
|
|
ORDER BY id ASC";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->result_array();
|
|
$result = array("records" => $row);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehousealmari rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_data_rack(){
|
|
try{
|
|
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm["id"];
|
|
|
|
$sql = "SELECT WarehouseRackID as id,
|
|
WarehouseRackCode as code,
|
|
WarehouseRackName as name
|
|
FROM warehouserack
|
|
WHERE
|
|
WarehouseRackIsActive = 'Y'
|
|
AND WarehouseRackWarehouseAlmariID = $id
|
|
ORDER BY id ASC";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->result_array();
|
|
$result = array("records" => $row);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehousealmari rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function check_stock(){
|
|
try{
|
|
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm["id"];
|
|
|
|
$sql = "SELECT SUM(status) as tot_status
|
|
FROM(SELECT IF(PurchaseReturDetailStatus = 'D',1,0) as status
|
|
FROM purchasereturreceivedetail
|
|
JOIN purchasereturdetail ON PurchaseReturDetailID = PurchaseReturReceiveDetailPurchaseReturDetailID
|
|
WHERE PurchaseReturReceiveDetailPurchaseReturReceiveID = $id)a";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->result_array();
|
|
$result = array("records" => $row);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("tot_status rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|