1441 lines
54 KiB
PHP
1441 lines
54 KiB
PHP
<?php
|
|
class Retur 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_supplier = '';
|
|
if (isset($prm['supplier_id']) && intval($prm['supplier_id']) > 0) {
|
|
$filter_supplier = ' AND SupplierID = '.$prm['supplier_id'];
|
|
}
|
|
$order_by = "PurchaseReturNumber";
|
|
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 PurchaseReturID
|
|
FROM `purchaseretur`
|
|
JOIN `supplier` ON PurchaseReturSupplierID = SupplierID $filter_supplier
|
|
WHERE
|
|
PurchaseReturIsActive = 'Y' AND (PurchaseReturDate BETWEEN ? AND ?) AND
|
|
( PurchaseReturNumber 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 {
|
|
echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("purchase order count error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$rows = array();
|
|
$sql = "SELECT PurchaseReturID as id,
|
|
PurchaseOrderID as purchase_order_id,
|
|
PurchaseOrderNumber as purchase_order_number,
|
|
PurchaseReturSupplierID as supplier_id,
|
|
SupplierName as supplier_name,
|
|
CompanyAddressID as company_address_id,
|
|
CompanyAddressLabel as company_address_label,
|
|
CompanyAddressDescription as company_address_description,
|
|
PurchaseReturNumber as code,
|
|
PurchaseReturStatus as status_pengiriman,
|
|
PurchaseReturDate as retur_date,
|
|
IFNULL(PurchaseReturExpeditionID,0) as expedition_id,
|
|
IFNULL(ExpeditionName,'') as expedition_name,
|
|
PurchaseReturNote as note,
|
|
PurchaseReturIsConfirm as is_confirm,
|
|
IFNULL(M_UserUsername,'') as user_confirm,
|
|
IFNULL(M_StaffName,'') as courier_name,
|
|
'' as details
|
|
FROM `purchaseretur`
|
|
JOIN `purchaseorder` ON PurchaseReturPurchaseOrderID = PurchaseOrderID
|
|
JOIN `supplier` ON PurchaseReturSupplierID = SupplierID $filter_supplier
|
|
JOIN `companyaddress` ON PurchaseReturCompanyAddressID = CompanyAddressID
|
|
LEFT JOIN `expedition` ON PurchaseReturExpeditionID = ExpeditionID
|
|
LEFT JOIN $this->db_onex.m_user ON PurchaseReturConfirmBy = M_UserID
|
|
LEFT JOIN $this->db_onex.m_staff ON PurchaseReturM_StaffID = M_StaffID
|
|
WHERE
|
|
PurchaseReturIsActive = 'Y' AND (PurchaseReturDate BETWEEN ? AND ?) AND
|
|
( PurchaseReturNumber 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();
|
|
|
|
$result = array("total_page" => $tot_page, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
else{
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("purchase retur select error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function getdetails(){
|
|
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT PurchaseReturDetailID as xid,
|
|
PurchaseReturDetailID as id,
|
|
PurchaseReturDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
ItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
PurchaseReturDetailStatus as status,
|
|
PurchaseReturDetailQty as qty,
|
|
PurchaseReturDetailReceiveQty as receive_qty,
|
|
PurchaseReturDetailBatchNo as batch_no,
|
|
PurchaseReturDetailStockNumber as stock_no,
|
|
PurchaseReturDetailED as ed,
|
|
PurchaseReturDetailWarehouseID as warehouse_id,
|
|
WarehouseName as warehouse_name,
|
|
PurchaseReturDetailWarehouseAlmariID as almari_id,
|
|
WarehouseAlmariName as almari_name,
|
|
WarehouseRackName as rack_name,
|
|
PurchaseReturDetailWarehouseRackID as rack_id,
|
|
WarehouseName as warehouse_name,
|
|
PurchaseOrderNumber as po_no,
|
|
PurchaseReceiveNumber as ro_no,
|
|
'' as qty_stock
|
|
FROM `purchasereturdetail`
|
|
JOIN `item` ON PurchaseReturDetailItemID = ItemID AND ItemIsActive = 'Y'
|
|
JOIN `itemunit` ON PurchaseReturDetailItemUnitID = ItemUnitID AND ItemUnitIsActive = 'Y'
|
|
JOIN `warehouse` ON PurchaseReturDetailWarehouseID = WarehouseID
|
|
JOIN `warehousealmari` ON PurchaseReturDetailWarehouseAlmariID = WarehouseAlmariID
|
|
JOIN `warehouserack` ON PurchaseReturDetailWarehouseRackID = WarehouseRackID
|
|
JOIN `purchasereceivedetail` ON PurchaseReceiveDetailStockNumber = PurchaseReturDetailStockNumber
|
|
JOIN `purchaseorderdetail` ON PurchaseReceiveDetailPurchaseOrderDetailID = PurchaseOrderDetailID
|
|
JOIN `purchaseorder` ON PurchaseOrderDetailPurchaseOrderID = PurchaseOrderID
|
|
JOIN `purchasereceive` ON PurchaseReceiveDetailPurchaseReceiveID = PurchaseReceiveID
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($prm['id']));
|
|
if($qry){
|
|
$rows = $qry->result_array();
|
|
if(count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$sql = " SELECT
|
|
IFNULL(SUM(StockQty),0) as qty_stock
|
|
FROM stock
|
|
JOIN item ON ItemID = ?
|
|
JOIN itemunit ON ItemUnitID = ?
|
|
WHERE
|
|
StockWarehouseID = ? AND
|
|
StockStockNumber = ?AND
|
|
StockBatchNo = ? AND
|
|
StockED = ? AND
|
|
StockQty > 0
|
|
GROUP BY StockBatchNo
|
|
LIMIT 1";
|
|
$param_detail = array(
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['warehouse_id'],
|
|
$value['stock_no'],
|
|
$value['batch_no'],
|
|
$value['ed']
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_detail);
|
|
if($qry){
|
|
$row = $qry->row_array();
|
|
$rows[$key]['qty_stock'] = $row['qty_stock'];
|
|
}
|
|
else{
|
|
echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("get stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
}
|
|
}
|
|
}else {
|
|
echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("get purchase order detail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$result = array( "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;
|
|
|
|
$company = "";
|
|
if (isset($prm['company'])) {
|
|
$company = trim($prm["company"]);
|
|
}
|
|
$company_address = "";
|
|
if (isset($prm['company_address'])) {
|
|
$company_address = trim($prm["company_address"]);
|
|
}
|
|
$expedition = "";
|
|
if (isset($prm['expedition'])) {
|
|
$expedition = trim($prm["expedition"]);
|
|
}
|
|
$courier = "";
|
|
if (isset($prm['courier'])) {
|
|
$courier = trim($prm["courier"]);
|
|
}
|
|
$retur_date = "";
|
|
if (isset($prm['retur_date'])) {
|
|
$retur_date = trim($prm["retur_date"]);
|
|
}
|
|
$supplier = "";
|
|
if (isset($prm['supplier'])) {
|
|
$supplier = trim($prm["supplier"]);
|
|
}
|
|
$purchase = "";
|
|
if (isset($prm['purchase'])) {
|
|
$purchase = trim($prm["purchase"]);
|
|
}
|
|
$note = "";
|
|
if (isset($prm['note'])) {
|
|
$note = trim($prm["note"]);
|
|
}
|
|
|
|
$details = "";
|
|
if (isset($prm['details'])) {
|
|
$details = trim($prm["details"]);
|
|
}
|
|
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$numbering = '';
|
|
$sql = "SELECT `fn_numbering`('RP') 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 purchaseretur(
|
|
PurchaseReturPurchaseOrderID,
|
|
PurchaseReturSupplierID,
|
|
PurchaseReturCompanyAddressID,
|
|
PurchaseReturNumber,
|
|
PurchaseReturDate,
|
|
PurchaseReturExpeditionID,
|
|
PurchaseReturM_StaffID,
|
|
PurchaseReturNote,
|
|
PurchaseReturUserID,
|
|
PurchaseReturCreated,
|
|
PurchaseReturLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert = array(
|
|
$purchase,
|
|
$supplier,
|
|
$company_address,
|
|
$numbering,
|
|
$retur_date,
|
|
$expedition,
|
|
$courier,
|
|
$note,
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_insert);
|
|
$last_id = 0;
|
|
if($qry){
|
|
$last_id = $this->db_inventory->insert_id();
|
|
}
|
|
else{
|
|
$this->sys_error_db("save supplier error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['details'])>0){
|
|
foreach ($prm['details'] as $key => $value) {
|
|
$sql = "INSERT INTO purchasereturdetail(
|
|
PurchaseReturDetailPurchaseReturID,
|
|
PurchaseReturDetailWarehouseID,
|
|
PurchaseReturDetailWarehouseAlmariID,
|
|
PurchaseReturDetailWarehouseRackID,
|
|
PurchaseReturDetailItemID,
|
|
PurchaseReturDetailItemUnitID,
|
|
PurchaseReturDetailBatchNo,
|
|
PurchaseReturDetailED,
|
|
PurchaseReturDetailStockNumber,
|
|
PurchaseReturDetailQty,
|
|
PurchaseReturDetailUserID,
|
|
PurchaseReturDetailCreated,
|
|
PurchaseReturDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_id,
|
|
$value['warehouse_id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['stock_no'],
|
|
$value['qty'],
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql,$param_insert_detail);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save purchasereturdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT purchaseretur.*, '' as details
|
|
FROM purchaseretur
|
|
WHERE PurchaseReturID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchaseorder error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturdetail`
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchaseretur details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO purchareorder_log (
|
|
PurchaseOrderLogPurchaseOrderID,
|
|
PurchaseOrderLogStatus,
|
|
PurchaseOrderLogJSONBefore,
|
|
PurchaseOrderLogJSONAfter,
|
|
PurchaseOrderLogUserID,
|
|
PurchaseOrderLogCreated
|
|
)
|
|
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){
|
|
|
|
$company = "";
|
|
if (isset($prm['company'])) {
|
|
$company = trim($prm["company"]);
|
|
}
|
|
$company_address = "";
|
|
if (isset($prm['company_address'])) {
|
|
$company_address = trim($prm["company_address"]);
|
|
}
|
|
$expedition = "";
|
|
if (isset($prm['expedition'])) {
|
|
$expedition = trim($prm["expedition"]);
|
|
}
|
|
$courier = "";
|
|
if (isset($prm['courier'])) {
|
|
$courier = trim($prm["courier"]);
|
|
}
|
|
$retur_date = "";
|
|
if (isset($prm['retur_date'])) {
|
|
$retur_date = trim($prm["retur_date"]);
|
|
}
|
|
$supplier = "";
|
|
if (isset($prm['supplier'])) {
|
|
$supplier = trim($prm["supplier"]);
|
|
}
|
|
$purchase = "";
|
|
if (isset($prm['purchase'])) {
|
|
$purchase = trim($prm["purchase"]);
|
|
}
|
|
$note = "";
|
|
if (isset($prm['note'])) {
|
|
$note = trim($prm["note"]);
|
|
}
|
|
|
|
$details = "";
|
|
if (isset($prm['details'])) {
|
|
$details = trim($prm["details"]);
|
|
}
|
|
|
|
$id = $prm['id'];
|
|
|
|
$sql = "SELECT purchaseretur.*, '' as details
|
|
FROM purchaseretur
|
|
WHERE PurchaseReturID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_before = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturdetail`
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_before['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchaseorder details error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_before = $row_before;
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$last_id = $id;
|
|
$sql = "UPDATE purchaseretur SET
|
|
PurchaseReturPurchaseOrderID = ?,
|
|
PurchaseReturSupplierID = ?,
|
|
PurchaseReturCompanyAddressID = ?,
|
|
PurchaseReturDate = ?,
|
|
PurchaseReturExpeditionID = ?,
|
|
PurchaseReturM_StaffID = ?,
|
|
PurchaseReturNote = ?,
|
|
PurchaseReturUserID = ?,
|
|
PurchaseReturCreated = NOW(),
|
|
PurchaseReturLastUpdated = NOW()
|
|
WHERE
|
|
PurchaseReturID = ?";
|
|
$param_update_header = array(
|
|
$purchase,
|
|
$supplier,
|
|
$company_address,
|
|
$retur_date,
|
|
$expedition,
|
|
$courier,
|
|
$note,
|
|
$userid,
|
|
$id
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_update_header);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("edit purchaseorder error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE purchasereturdetail SET PurchaseReturDetailIsActive = 'N' WHERE PurchaseReturDetailPurchaseReturID = ?";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update N address error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
if(count($prm['details'])>0){
|
|
foreach ($prm['details'] as $key => $value) {
|
|
if(intval($value['id']) > 0){
|
|
$sql = "UPDATE purchasereturdetail SET
|
|
PurchaseReturDetailQty = ?,
|
|
PurchaseReturDetailUserID = ?,
|
|
PurchaseReturDetailIsActive = 'Y',
|
|
PurchaseReturDetailLastUpdated = NOW()
|
|
WHERE
|
|
PurchaseReturDetailID = ?";
|
|
$param_edit_detail = array(
|
|
$value['qty'],
|
|
$userid,
|
|
$value['id']
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_edit_detail);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("edit purchasereturdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "INSERT INTO purchasereturdetail(
|
|
PurchaseReturDetailPurchaseReturID,
|
|
PurchaseReturDetailWarehouseID,
|
|
PurchaseReturDetailWarehouseAlmariID,
|
|
PurchaseReturDetailWarehouseRackID,
|
|
PurchaseReturDetailItemID,
|
|
PurchaseReturDetailItemUnitID,
|
|
PurchaseReturDetailBatchNo,
|
|
PurchaseReturDetailED,
|
|
PurchaseReturDetailStockNumber,
|
|
PurchaseReturDetailQty,
|
|
PurchaseReturDetailUserID,
|
|
PurchaseReturDetailCreated,
|
|
PurchaseReturDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$id,
|
|
$value['warehouse_id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['stock_no'],
|
|
$value['qty'],
|
|
$userid
|
|
);
|
|
//echo $this->db_inventory->last_query();
|
|
$qry = $this->db_inventory->query($sql, $param_insert_detail);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save purchaseorderdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT purchaseretur.*, '' as details
|
|
FROM purchaseretur
|
|
WHERE PurchaseReturID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturdetail`
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO purchareorder_log (
|
|
PurchaseOrderLogPurchaseOrderID,
|
|
PurchaseOrderLogStatus,
|
|
PurchaseOrderLogJSONBefore,
|
|
PurchaseOrderLogJSONAfter,
|
|
PurchaseOrderLogUserID,
|
|
PurchaseOrderLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
//print_r($data_log_before);
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'EDIT',json_encode($data_log_before),json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->sys_error_db("update log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
return true;
|
|
}
|
|
|
|
function confirm()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$param = $this->sys_input;
|
|
|
|
$this->update($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 purchaseretur.*, '' as details
|
|
FROM purchaseretur
|
|
WHERE PurchaseReturID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturdetail`
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_before = $row;
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "UPDATE purchaseretur
|
|
SET PurchaseReturIsConfirm = 'Y',
|
|
PurchaseReturLastUpdated = NOW(),
|
|
PurchaseReturConfirmDatetime = NOW(),
|
|
PurchaseReturConfirmBy = ?,
|
|
PurchaseReturUserID = ?
|
|
WHERE PurchaseReturID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$userid,$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("confirm purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
foreach ($param['details'] as $key => $value) {
|
|
$sql="INSERT INTO stocklog (
|
|
StockLogWarehouseID,
|
|
StockLogWarehouseAlmariID,
|
|
StockLogWarehouseRackID,
|
|
StockLogDatetime,
|
|
StockLogItemID,
|
|
StockLogItemUnitID,
|
|
StockLogStockNumber,
|
|
StockLogBatchNo,
|
|
StockLogED,
|
|
StockLogReffID,
|
|
StockLogStatus,
|
|
StockLogQty,
|
|
StockLogUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,NOW(),?,?,?,?,?,?,?,?,?
|
|
)";
|
|
$param_stock_log = array(
|
|
$value['warehouse_id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['stock_no'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['id'],
|
|
'RPO',
|
|
-1 * floatval($value['qty']),
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_stock_log);
|
|
|
|
$latest_stock = 0;
|
|
|
|
$sql=" SELECT StockCardAfter as qty_latest
|
|
FROM stockcard
|
|
WHERE
|
|
StockCardWarehouseID = ? AND
|
|
StockCardItemID = ? AND
|
|
StockCardItemUnitID = ? AND
|
|
StockCardBatchNo = ? AND
|
|
StockCardED = ?
|
|
ORDER BY StockCardDatetime DESC
|
|
LIMIT 1
|
|
";
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$value['warehouse_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['batch_no'],
|
|
$value['ed']
|
|
)
|
|
);
|
|
|
|
if(!$qry){
|
|
$this->sys_error_db("select qty_latest error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$latest_stock = $qry->row()->qty_latest;
|
|
$after_stock = $latest_stock - floatval($value['qty']);
|
|
|
|
$sql = "INSERT INTO stockcard (
|
|
StockCardWarehouseID,
|
|
StockCardDatetime,
|
|
StockCardItemID,
|
|
StockCardItemUnitID,
|
|
StockCardBatchNo,
|
|
StockCardED,
|
|
StockCardReffID,
|
|
StockCardStatus,
|
|
StockCardBefore,
|
|
StockCardIn,
|
|
StockCardOut,
|
|
StockCardAfter,
|
|
StockCardUserID
|
|
)VALUES(
|
|
?,NOW(),?,?,?,?,?,?,?,?,?,?,?
|
|
)
|
|
";
|
|
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$value['warehouse_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['id'],
|
|
'RPO',
|
|
$latest_stock,
|
|
0,
|
|
$value['qty'],
|
|
$after_stock,
|
|
$userid
|
|
)
|
|
);
|
|
|
|
if(!$qry){
|
|
$this->sys_error_db("insert stockcard error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO stock(
|
|
StockWarehouseID,
|
|
StockWarehouseAlmariID,
|
|
StockWarehouseRackID,
|
|
StockStockNumber,
|
|
StockItemID,
|
|
StockItemUnitID,
|
|
StockBatchNo,
|
|
StockED,
|
|
StockQty,
|
|
StockUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,?
|
|
) ON DUPLICATE KEY
|
|
UPDATE
|
|
StockQty = StockQty - {$value['qty']},
|
|
StockUserID = {$userid}";
|
|
|
|
$qry = $this->db_inventory->query($sql,
|
|
array(
|
|
$value['warehouse_id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['stock_no'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['qty'],
|
|
$userid
|
|
)
|
|
);
|
|
|
|
if(!$qry){
|
|
$this->sys_error_db("insert-update stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT purchaseretur.*, '' as details
|
|
FROM purchaseretur
|
|
WHERE PurchaseReturID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturdetail`
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchasereturdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO purchaseretur_log (
|
|
PurchaseReturLogPurchaseReturID,
|
|
PurchaseReturLogStatus,
|
|
PurchaseReturLogJSONBefore,
|
|
PurchaseReturLogJSONAfter,
|
|
PurchaseReturLogUserID,
|
|
PurchaseReturLogCreated
|
|
)
|
|
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();
|
|
|
|
|
|
$result = array(
|
|
"message" => 'confirm 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;
|
|
}
|
|
$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 purchaseretur
|
|
SET
|
|
PurchaseReturIsActive = 'N',
|
|
PurchaseReturLastUpdated = now(),
|
|
PurchaseReturUserID = ?
|
|
WHERE PurchaseReturID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("delete purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}else{
|
|
$sql = "UPDATE purchasereturdetail
|
|
SET
|
|
PurchaseReturDetailIsActive = 'N',
|
|
PurchaseReturDetailLastUpdated = now(),
|
|
PurchaseReturDetailUserID = ?
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->sys_error_db("delete purchasereturdetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT purchaseretur.*, '' as details
|
|
FROM purchaseretur
|
|
WHERE PurchaseReturID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `purchasereturdetail`
|
|
WHERE
|
|
PurchaseReturDetailPurchaseReturID = ? AND
|
|
PurchaseReturDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if($qry){
|
|
$row_after['details'] = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("select purchaseretur error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO purchaseretur_log (
|
|
PurchaseReturLogPurchaseReturID,
|
|
PurchaseReturLogStatus,
|
|
PurchaseReturLogJSONBefore,
|
|
PurchaseReturLogJSONAfter,
|
|
PurchaseReturLogUserID,
|
|
PurchaseReturLogCreated
|
|
)
|
|
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_supplier(){
|
|
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_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'=>'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'=>'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_purchase(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM purchaseorder
|
|
WHERE
|
|
PurchaseOrderNumber LIKE ? AND
|
|
PurchaseOrderIsActive = 'Y' AND
|
|
PurchaseOrderSupplierID = ?";
|
|
$query = $this->db_inventory->query($sql,array("%{$prm['search']}%",$prm['supplier_id']));
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
|
|
echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("purchaseorder count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
$rows = array('id'=>0,'name'=>'Semua');
|
|
$sql = "SELECT PurchaseOrderID as id, PurchaseOrderNumber as name
|
|
FROM purchaseorder
|
|
WHERE
|
|
PurchaseOrderNumber LIKE ?
|
|
AND PurchaseOrderIsActive = 'Y'
|
|
AND PurchaseOrderSupplierID = ?
|
|
ORDER BY PurchaseOrderNumber DESC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array("%{$prm['search']}%",$prm['supplier_id']));
|
|
|
|
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("purchase 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 get_data_company_default(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT CompanyID as id,
|
|
CompanyName as name,
|
|
'' as address
|
|
FROM company
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y'
|
|
WHERE
|
|
CompanyIsActive = 'Y' LIMIT 1";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->row_array();
|
|
|
|
$sql = "SELECT CompanyAddressID as id,
|
|
CompanyAddressLabel as name,
|
|
CompanyAddressDescription as description
|
|
FROM companyaddress
|
|
WHERE
|
|
CompanyAddressCompanyID = ? AND CompanyAddressIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,array($row['id']));
|
|
$data_address = $query->result_array();
|
|
$row['address'] = $data_address;
|
|
|
|
|
|
|
|
$result = array("records" => $row);
|
|
$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 get_expedition(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT ExpeditionID as id,
|
|
ExpeditionName as name,
|
|
ExpeditionIsInternal as is_internal
|
|
FROM expedition
|
|
WHERE
|
|
ExpeditionIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
|
|
|
|
$result = array("records" => $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 get_expedition_staff(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT M_StaffID as id,
|
|
M_StaffName as name
|
|
FROM expeditionstaff
|
|
JOIN $this->db_onex.m_staff ON ExpeditionStaffM_StaffID = M_StaffID AND M_StaffIsActive = 'Y'
|
|
WHERE
|
|
ExpeditionStaffIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
|
|
|
|
$result = array("records" => $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 get_printout(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM r_report
|
|
WHERE
|
|
R_ReportCode = 'MPB' AND R_ReportIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->row_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("r_report rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|