1362 lines
56 KiB
PHP
1362 lines
56 KiB
PHP
<?php
|
|
class Mutation 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'] . '%';
|
|
}
|
|
|
|
$filter_to_warehouse = '';
|
|
if (isset($prm['to_warehouse']) && intval($prm['to_warehouse']) > 0) {
|
|
$filter_to_warehouse = ' AND MutasiInternalToWarehouseID = '.$prm['to_warehouse'];
|
|
}
|
|
|
|
$filter_status = '';
|
|
if (isset($prm['status']) && $prm['status'] != 'A') {
|
|
$filter_status = " AND MutasiInternalStatus = '{$prm['status']}'";
|
|
}
|
|
|
|
$order_by = "MutasiInternalNumber";
|
|
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 MutasiInternalID as id
|
|
FROM `mutasiinternal`
|
|
JOIN $this->db_onex.`m_staff` ON MutasiInternalM_StaffID = M_StaffID
|
|
LEFT JOIN $this->db_onex.`m_user` ON MutasiInternalConfirmBy = M_UserID
|
|
JOIN `warehouse` fromwarehouse ON MutasiInternalFromWarehouseID = fromwarehouse.WarehouseID
|
|
JOIN `warehouse` towarehouse ON MutasiInternalToWarehouseID = towarehouse.WarehouseID $filter_to_warehouse
|
|
WHERE
|
|
MutasiInternalIsActive = 'Y' AND (DATE(MutasiInternalDate) BETWEEN ? AND ?) AND
|
|
( MutasiInternalNumber like ? ) $filter_status
|
|
) x";
|
|
$qry = $this->db_inventory->query($sql,array($prm['start_date'],$prm['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 MutasiInternalID as id,
|
|
MutasiInternalStatus as status_pengiriman,
|
|
MutasiInternalNumber as code,
|
|
DATE(MutasiInternalDate) as mutation_date,
|
|
MutasiInternalFromWarehouseID as from_warehouse_id,
|
|
fromwarehouse.WarehouseName as from_warehouse_name,
|
|
MutasiInternalToWarehouseID as to_warehouse_id,
|
|
towarehouse.WarehouseName as to_warehouse_name,
|
|
MutasiInternalDate as mutasi_date,
|
|
M_StaffID as staff_id,
|
|
M_StaffName as staff_name,
|
|
M_StaffHP as staff_mobile,
|
|
MutasiInternalNote as note,
|
|
MutasiInternalIsConfirm as is_confirm,
|
|
IF(MutasiInternalConfrimAt = NULL, '',DATE_FORMAT(MutasiInternalConfrimAt,'%d-%m-%Y %H:%i')) as confirm_at,
|
|
IFNULL(M_UserUsername,'') as confirm_by,
|
|
'' as details
|
|
FROM `mutasiinternal`
|
|
JOIN $this->db_onex.`m_staff` ON MutasiInternalM_StaffID = M_StaffID
|
|
LEFT JOIN $this->db_onex.`m_user` ON MutasiInternalConfirmBy = M_UserID
|
|
JOIN `warehouse` fromwarehouse ON MutasiInternalFromWarehouseID = fromwarehouse.WarehouseID
|
|
JOIN `warehouse` towarehouse ON MutasiInternalToWarehouseID = towarehouse.WarehouseID $filter_to_warehouse
|
|
WHERE
|
|
MutasiInternalIsActive = 'Y' AND (DATE(MutasiInternalDate) BETWEEN ? AND ?) AND
|
|
( MutasiInternalNumber like ? ) $filter_status
|
|
ORDER BY $order_by $order_type
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db_inventory->query($sql, array($prm['start_date'],$prm['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 order select error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_details(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT MutasiInternalDetailMutasiRequestInternalDetailID as request_receive_id,
|
|
MutasiRequestInternalNumber as request_number,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
IFNULL(MutasiRequestInternalDetailQty,0)-IFNULL(MutasiRequestInternalDetailReceiveQty,0) as qty_request_rest,
|
|
MutasiRequestInternalDetailQty as qty_request,
|
|
IFNULL(MutasiRequestInternalDetailQty,0) as qty_request_all,
|
|
IFNULL(MutasiRequestInternalDetailReceiveQty,0) as qty_received_all,
|
|
ItemName as item_name,
|
|
ItemUnitName as unit_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
IFNULL(MutasiInternalDetailQty,0) as qty_send,
|
|
IFNULL(MutasiInternalDetailQty,0) as qty,
|
|
IFNULL(MutasiInternalDetailQtyReceive,0) as qty_received,
|
|
MutasiInternalDetailID as id,
|
|
IFNULL(SUM(StockQty),0) as qty_stock,
|
|
IFNULL(MutasiInternalIsConfirm,'N') as is_confirm,
|
|
'' as details
|
|
FROM mutasiinternaldetail
|
|
JOIN mutasiinternal ON MutasiInternalDetailMutasiInternalID = MutasiInternalID
|
|
JOIN item ON MutasiInternalDetailItemID = ItemID
|
|
JOIN itemunit ON MutasiInternalDetailItemUnitID = ItemUnitID
|
|
LEFT JOIN stock ON StockWarehouseID = MutasiInternalFromWarehouseID AND
|
|
MutasiInternalDetailItemID = StockItemID AND MutasiInternalDetailItemUnitID = ItemUnitID AND
|
|
StockQty > 0
|
|
JOIN mutasirequestinternaldetail ON
|
|
MutasiInternalDetailMutasiRequestInternalDetailID = MutasiRequestInternalDetailID
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ? AND
|
|
MutasiInternalDetailIsActive = 'Y' AND
|
|
MutasiInternalFromWarehouseID = ?
|
|
GROUP BY MutasiInternalDetailID
|
|
";
|
|
$query = $this->db_inventory->query($sql,array($prm['id'],$prm['from_warehouse_id']));
|
|
//echo $this->db_inventory->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach ($rows as $key => $value) {
|
|
if($value['is_confirm'] === 'Y'){
|
|
$sql = "SELECT MutasiInternalDetailStockID as id,
|
|
MutasiInternalDetailStockItemID as item_id,
|
|
ItemName as item_name,
|
|
MutasiInternalDetailStockItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
MutasiInternalDetailStockBatchNo as batch_no,
|
|
MutasiInternalDetailStockStockNumber as stock_number,
|
|
IF(MutasiInternalDetailStockED = NULL OR MutasiInternalDetailStockED = '0000-00-00','',MutasiInternalDetailStockED) as ed,
|
|
MutasiInternalDetailStockQty as qty
|
|
FROM `mutasiinternaldetailstock`
|
|
JOIN `item` ON MutasiInternalDetailStockItemID = ItemID
|
|
JOIN `itemunit` ON MutasiInternalDetailStockItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiInternalDetailStockMutasiInternalDetailID = ? AND
|
|
MutasiInternalDetailStockIsActive = 'Y'
|
|
|
|
";
|
|
$query = $this->db_inventory->query($sql,array($value['id']));
|
|
//echo $this->db_inventory->last_query();
|
|
if($query){
|
|
$rows[$key]['details'] = $query->result_array();
|
|
}
|
|
else{
|
|
$this->sys_error_db("mutasiinternaldetailstock rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array( "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("mutasidetail rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_to_company_address(){
|
|
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']}%";
|
|
}
|
|
|
|
$sql = "
|
|
SELECT CompanyAddressID as id, CompanyAddressLabel as name, CompanyAddressDescription as description,
|
|
M_BranchID as branch_id, M_BranchName as branch_name
|
|
FROM companyaddress
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
CompanyName like ?
|
|
AND CompanyAddressIsActive = 'Y'
|
|
ORDER BY CompanyName ASC
|
|
";
|
|
$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( "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("companyaddress rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_warehouse(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'N'
|
|
ORDER BY WarehouseName ASC
|
|
";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$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_from_warehouse_form(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
JOIN stock ON StockWarehouseID = WarehouseID
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalToWarehouseID = StockWarehouseID AND MutasiRequestInternalIsActive = 'Y'
|
|
JOIN mutasirequestinternaldetail ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID AND
|
|
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y' AND
|
|
StockItemID = MutasiRequestInternalDetailItemID
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'Y'
|
|
GROUP BY WarehouseID
|
|
ORDER BY WarehouseName ASC
|
|
";
|
|
$query = $this->db_inventory->query($sql);
|
|
//echo $this->db_inventory->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_inventory->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$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_to_warehouse_form(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalWarehouseID = WarehouseID AND MutasiRequestInternalIsActive = 'Y'
|
|
JOIN mutasirequestinternaldetail ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID AND
|
|
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y'
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'N'
|
|
GROUP BY WarehouseID
|
|
ORDER BY WarehouseName ASC
|
|
";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$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 saveAdd(){
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$note = "";
|
|
if (isset($prm['note'])) {
|
|
$note = trim($prm['note']);
|
|
}
|
|
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$numbering = '';
|
|
$sql = "SELECT `fn_numbering`('MIG') 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;
|
|
$now = new DateTime();
|
|
|
|
$sql = "INSERT INTO mutasiinternal(
|
|
MutasiInternalNumber,
|
|
MutasiInternalDate,
|
|
MutasiInternalFromWarehouseID,
|
|
MutasiInternalToWarehouseID,
|
|
MutasiInternalM_StaffID,
|
|
MutasiInternalNote,
|
|
MutasiInternalCreated,
|
|
MutasiInternalLastUpdated,
|
|
MutasiInternalUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,NOW(),NOW(),?
|
|
)";
|
|
$param_insert = array(
|
|
$numbering,
|
|
$prm['mutation_date'],
|
|
$prm['from_warehouse']['id'],
|
|
$prm['to_warehouse']['id'],
|
|
intval($prm['courier_staf']['id']) > 0?$prm['courier_staf']['id']:NULL,
|
|
$note,
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_insert);
|
|
$last_id = 0;
|
|
if($qry){
|
|
$last_id = $this->db_inventory->insert_id();
|
|
}
|
|
else{
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['details'])>0){
|
|
foreach ($prm['details'] as $key => $value) {
|
|
if(intval($value['qty']) > 0){
|
|
$sql = "INSERT INTO mutasiinternaldetail(
|
|
MutasiInternalDetailMutasiInternalID,
|
|
MutasiInternalDetailMutasiRequestInternalDetailID,
|
|
MutasiInternalDetailItemID,
|
|
MutasiInternalDetailItemUnitID,
|
|
MutasiInternalDetailQty,
|
|
MutasiInternalDetailUserID,
|
|
MutasiInternalDetailCreated,
|
|
MutasiInternalDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_id,
|
|
$value['request_receive_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$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 mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT mutasiinternal.*, '' as details
|
|
FROM mutasiinternal
|
|
WHERE MutasiInternalID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *, '' as details
|
|
FROM `mutasiinternaldetail`
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ? AND
|
|
MutasiInternalDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after['details'] = $qry->result_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO mutasiinternal_log (
|
|
MutasiInternalLogMutasiInternalID,
|
|
MutasiInternalLogStatus,
|
|
MutasiInternalLogJSONBefore,
|
|
MutasiInternalLogJSONAfter,
|
|
MutasiInternalLogUserID,
|
|
MutasiInternalLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,NULL,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'ADD',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){
|
|
$note = "";
|
|
if (isset($prm['note'])) {
|
|
$note = trim($prm["note"]);
|
|
}
|
|
|
|
|
|
$id = $prm['id'];
|
|
if(!$id){
|
|
$message = "id belum dikirimkan";
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
$sql = "SELECT mutasiinternal.*, '' as details
|
|
FROM mutasiinternal
|
|
WHERE MutasiInternalID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_before = $qry->row_array();
|
|
$sql = "SELECT *, '' as details
|
|
FROM `mutasiinternaldetail`
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ? AND
|
|
MutasiInternalDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_before['details'] = $qry->result_array();
|
|
$data_log_before = $row_before;
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$last_id = $id;
|
|
$sql = "UPDATE mutasiinternal SET
|
|
MutasiInternalDate = ?,
|
|
MutasiInternalFromWarehouseID = ?,
|
|
MutasiInternalToWarehouseID = ?,
|
|
MutasiInternalM_StaffID = ?,
|
|
MutasiInternalNote = ?,
|
|
MutasiInternalLastUpdated = NOW(),
|
|
MutasiInternalUserID = ?
|
|
WHERE
|
|
MutasiInternalID = ?";
|
|
$param_update_header = array(
|
|
$prm['mutation_date'],
|
|
isset($prm['from_warehouse'])?$prm['from_warehouse']['id']:0,
|
|
isset($prm['to_warehouse'])?$prm['to_warehouse']['id']:0,
|
|
isset($prm['courier_staf']) && intval($prm['courier_staf']['id']) > 0?$prm['courier_staf']['id']:0,
|
|
$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 mutasiinternaldetail SET MutasiInternalDetailIsActive = 'N' WHERE MutasiInternalDetailMutasiInternalID = ?";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update N detail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
if(count($prm['details'])>0){
|
|
foreach ($prm['details'] as $key => $value) {
|
|
if(intval($value['qty']) > 0){
|
|
if(intval($value['id']) > 0){
|
|
$sql = "UPDATE mutasiinternaldetail SET
|
|
MutasiInternalDetailQty = ?,
|
|
MutasiInternalDetailUserID = ?,
|
|
MutasiInternalDetailIsActive = 'Y',
|
|
MutasiInternalDetailLastUpdated = NOW()
|
|
WHERE
|
|
MutasiInternalDetailID = ?";
|
|
$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 mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "INSERT INTO mutasiinternaldetail(
|
|
MutasiInternalDetailMutasiInternalID,
|
|
MutasiInternalDetailMutasiRequestInternalDetailID,
|
|
MutasiInternalDetailItemID,
|
|
MutasiInternalDetailItemUnitID,
|
|
MutasiInternalDetailQty,
|
|
MutasiInternalDetailUserID,
|
|
MutasiInternalDetailCreated,
|
|
MutasiInternalDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_id,
|
|
$value['request_receive_id'],
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$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 mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT mutasiinternal.*, '' as details
|
|
FROM mutasiinternal
|
|
WHERE MutasiInternalID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *, '' as details
|
|
FROM `mutasiinternaldetail`
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ? AND
|
|
MutasiInternalDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after['details'] = $qry->result_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO mutasiinternal_log (
|
|
MutasiInternalLogMutasiInternalID,
|
|
MutasiInternalLogStatus,
|
|
MutasiInternalLogJSONBefore,
|
|
MutasiInternalLogJSONAfter,
|
|
MutasiInternalLogUserID,
|
|
MutasiInternalLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$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("insert log error", $this->db_inventory_log->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 mutasiinternal
|
|
SET
|
|
MutasiInternalIsActive = 'N',
|
|
MutasiInternalLastUpdated = now(),
|
|
MutasiInternalUserID = ?
|
|
WHERE MutasiInternalID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->sys_error_db("delete mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}else{
|
|
$sql = "UPDATE mutasiinternaldetail
|
|
SET
|
|
MutasiInternalDetailIsActive = 'N',
|
|
MutasiInternalDetailLastUpdated = now(),
|
|
MutasiInternalDetailUserID = ?
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->sys_error_db("delete mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT mutasiinternaldetail.*, '' as details
|
|
FROM mutasiinternaldetail
|
|
WHERE MutasiInternalDetailID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO mutasiinternal_log (
|
|
MutasiInternalLogMutasiInternalID,
|
|
MutasiInternalLogStatus,
|
|
MutasiInternalLogJSONBefore,
|
|
MutasiInternalLogJSONAfter,
|
|
MutasiInternalLogUserID,
|
|
MutasiInternalLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,NULL,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'DELETE',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 validateDate($date, $format = 'Y-m-d')
|
|
{
|
|
$d = DateTime::createFromFormat($format, $date);
|
|
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
|
|
return $d && $d->format($format) === $date;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "UPDATE mutasiinternal
|
|
SET MutasiInternalIsConfirm = 'Y',
|
|
MutasiInternalStatus = 'S',
|
|
MutasiInternalLastUpdated = NOW(),
|
|
MutasiInternalConfrimAt = NOW(),
|
|
MutasiInternalConfirmBy = ?,
|
|
MutasiInternalUserID = ?
|
|
WHERE MutasiInternalID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$userid,$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("confirm purchaseorder error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT mutasiinternaldetail.*,'' as details
|
|
FROM mutasiinternaldetail
|
|
JOIN mutasirequestinternaldetail ON MutasiRequestInternalDetailID = MutasiInternalDetailMutasiRequestInternalDetailID
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ? AND MutasiInternalDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, [$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("select mutasidetail before get stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_details = $qry->result_array();
|
|
|
|
|
|
//start mengeluarkan data dari stock
|
|
foreach ($data_details as $kdetail => $vdetail) {
|
|
$sql = "UPDATE mutasiinternaldetail SET MutasiInternalDetailQty = 0
|
|
WHERE
|
|
MutasiInternalDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql, [$vdetail['MutasiInternalDetailID']]);
|
|
if(!$qry){
|
|
$this->sys_error_db("update QTY = 0 mutasi detail", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//print_r($vdetail);
|
|
$qty = intval($vdetail['MutasiInternalDetailQty']);
|
|
//echo $qty;
|
|
if($qty > 0){
|
|
|
|
$qtyLoop = 0;
|
|
//start looping stock out sesuai qty yg dikirim
|
|
while($qtyLoop < $qty) {
|
|
$sql = "SELECT *
|
|
FROM stock
|
|
JOIN warehouse ON StockWarehouseID = WarehouseID AND
|
|
WarehouseIsOffice = 'Y'
|
|
WHERE
|
|
StockItemID = ? AND
|
|
StockItemUnitID = ? AND
|
|
StockQty > 0
|
|
ORDER BY StockED ASC, StockStockNumber ASC
|
|
LIMIT 1";
|
|
$qry = $this->db_inventory->query($sql, [$vdetail['MutasiInternalDetailItemID'],$vdetail['MutasiInternalDetailItemUnitID']]);
|
|
if(!$qry){
|
|
$qtyLoop = $qty;
|
|
$this->sys_error_db("select stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
|
|
}
|
|
|
|
if($qry->row_array()){
|
|
$data_stock = $qry->row_array();
|
|
$qtyOut = 0;
|
|
if(intval($data_stock['StockQty']) >= $qty){
|
|
$qtyOut = $qty;
|
|
|
|
}else{
|
|
$qtyOut = intval($data_stock['StockQty']);
|
|
}
|
|
$qty_stock_update = intval($data_stock['StockQty'])-$qtyOut;
|
|
$sql = "UPDATE stock SET StockQty = ?
|
|
WHERE
|
|
StockID = ? ";
|
|
$qry = $this->db_inventory->query($sql, [intval($data_stock['StockQty'])-$qtyOut,$data_stock['StockID']]);
|
|
if(!$qry){
|
|
$this->sys_error_db("stock out error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
|
|
$arr_insert = array(
|
|
'MutasiInternalDetailStockMutasiInternalDetailID' => $vdetail['MutasiInternalDetailID'],
|
|
'MutasiInternalDetailStockMutasiRequestInternalDetailID' => $vdetail['MutasiInternalDetailMutasiRequestInternalDetailID'],
|
|
'MutasiInternalDetailStockItemID' => $vdetail['MutasiInternalDetailItemID'],
|
|
'MutasiInternalDetailStockItemUnitID' => $vdetail['MutasiInternalDetailItemUnitID'],
|
|
'MutasiInternalDetailStockBatchNo' => $data_stock['StockBatchNo'],
|
|
'MutasiInternalDetailStockStockNumber' => $data_stock['StockStockNumber'],
|
|
'MutasiInternalDetailStockQty' => $qtyOut,
|
|
'MutasiInternalDetailStockUserID' => $userid,
|
|
'MutasiInternalDetailStockCreated' => date("Y-m-d H:i:s"),
|
|
'MutasiInternalDetailStockLastUpdated' => date("Y-m-d H:i:s")
|
|
);
|
|
$arr_insert_ed = $this->validateDate($data_stock['StockED'])?$data_stock['StockED']:NULL;
|
|
if($arr_insert_ed)
|
|
$arr_insert['MutasiInternalDetailStockED'] = $data_stock['StockED'];
|
|
|
|
$qry = $this->db_inventory->insert('mutasiinternaldetailstock', $arr_insert);
|
|
if(!$qry){
|
|
$this->sys_error_db("mutasiinternaldetailstock insert error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$detailstock_id = $this->db_inventory->insert_id();
|
|
|
|
$sql = "UPDATE mutasiinternaldetail SET MutasiInternalDetailQty = MutasiInternalDetailQty + ?
|
|
WHERE
|
|
MutasiInternalDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql, [$qtyOut,$vdetail['MutasiInternalDetailID']]);
|
|
if(!$qry){
|
|
$this->sys_error_db("update QTY mutasi detail berdasarkan stock keluar error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$last_stock_card = intval($data_stock['StockQty']);
|
|
|
|
$qty_after = $qty_stock_update;
|
|
$batch_no = $data_stock['StockBatchNo'];
|
|
$ed = $this->validateDate($data_stock['StockED'])?$data_stock['StockED']:NULL;
|
|
$data_insert_stocklog = array(
|
|
'StockCardStatus' => 'MIG',
|
|
'StockCardDatetime' => date('Y-m-d H:i:s'),
|
|
'StockCardWarehouseID' => $data_stock['StockWarehouseID'],
|
|
'StockCardItemID' => $data_stock['StockItemID'],
|
|
'StockCardItemUnitID' => $data_stock['StockItemUnitID'],
|
|
'StockCardBatchNo' => $batch_no,
|
|
'StockCardReffID' => $detailstock_id,
|
|
'StockCardBefore' => $last_stock_card,
|
|
'StockCardIn' => 0,
|
|
'StockCardOut' => $qtyOut,
|
|
'StockCardAfter' => $qty_after,
|
|
'StockCardUserID' => $userid
|
|
);
|
|
if($ed)
|
|
$data_insert_stocklog['StockCardED'] = $ed;
|
|
|
|
$qry = $this->db_inventory->insert('stockcard',$data_insert_stocklog);
|
|
if(!$qry){
|
|
$this->sys_error_db("insert stockcard error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO stocklog (
|
|
StockLogWarehouseID,
|
|
StockLogWarehouseAlmariID,
|
|
StockLogWarehouseRackID,
|
|
StockLogDatetime,
|
|
StockLogItemID,
|
|
StockLogItemUnitID,
|
|
StockLogStockNumber,
|
|
StockLogBatchNo,
|
|
StockLogED,
|
|
StockLogReffID,
|
|
StockLogQty,
|
|
StockLogUserID,
|
|
StockLogStatus
|
|
)
|
|
VALUES(
|
|
?,?,?,NOW(),?,?,?,?,?,?,?,?,'MIG'
|
|
)";
|
|
$param_insert_stocklog = array(
|
|
$data_stock['StockWarehouseID'],
|
|
$data_stock['StockWarehouseAlmariID'],
|
|
$data_stock['StockWarehouseRackID'],
|
|
$data_stock['StockItemID'],
|
|
$data_stock['StockItemUnitID'],
|
|
$data_stock['StockStockNumber'],
|
|
$batch_no,
|
|
$ed,
|
|
$detailstock_id,
|
|
$qtyOut,
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_insert_stocklog);
|
|
if(!$qry){
|
|
$this->sys_error_db("stocklog insert error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
$qtyLoop = $qtyLoop + $qtyOut;
|
|
}
|
|
else{
|
|
$qtyLoop = $qty;
|
|
}
|
|
|
|
}
|
|
//end looping stock out sesuai qty yg dikirim
|
|
|
|
$sql = "UPDATE mutasirequestinternaldetail SET MutasiRequestInternalDetailStatus = 'S'
|
|
WHERE
|
|
MutasiRequestInternalDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql, array($vdetail['MutasiInternalDetailMutasiRequestInternalDetailID']));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("cek qty detail and stockout error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO mutasirequestinternal_status(
|
|
MutasiRequestInternalStatusMutasiRequestInternalDetailID,
|
|
MutasiRequestInternalStatus,
|
|
MutasiRequestInternalMutasiInternalDetailID,
|
|
MutasiRequestInternalStatusUserID,
|
|
MutasiRequestInternalStatusCreated
|
|
)
|
|
VALUES(?,'S',?,?,NOW())";
|
|
$qry = $this->db_inventory->query($sql, array($vdetail['MutasiInternalDetailMutasiRequestInternalDetailID'],$vdetail['MutasiInternalDetailID'],$userid));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("cek qty detail and stockout error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
//end mengeluarkan data dari stock
|
|
|
|
|
|
$sql = "SELECT mutasiinternal.*, '' as details
|
|
FROM mutasiinternal
|
|
WHERE MutasiInternalID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
|
|
$row_after['details'] = $data_details;
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO mutasiinternal_log (
|
|
MutasiInternalLogMutasiInternalID,
|
|
MutasiInternalLogStatus,
|
|
MutasiInternalLogJSONBefore,
|
|
MutasiInternalLogJSONAfter,
|
|
MutasiInternalLogUserID,
|
|
MutasiInternalLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,NULL,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_inventory_log->query($sql, array($id,'CONFRIM',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 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 one_aditya.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_to_company_address_form(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT CompanyAddressID as id,
|
|
CompanyAddressLabel as name,
|
|
CompanyAddressDescription as description,
|
|
CompanyName as company_name
|
|
FROM companyaddress
|
|
JOIN mutasirequestreceive ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID AND
|
|
MutasiRequestReceiveIsActive = 'Y' AND
|
|
( MutasiRequestReceiveStatus <> 'N' AND MutasiRequestReceiveStatus <> 'D' )
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
WHERE
|
|
CompanyAddressIsActive = 'Y'
|
|
GROUP BY CompanyAddressID";
|
|
$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("companyaddress rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_data_request(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$id = $prm['warehouse_id'];
|
|
$sql = "SELECT MutasiRequestInternalDetailID as request_receive_id,
|
|
MutasiRequestInternalNumber as request_number,
|
|
WarehouseName as warehouse_name,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
MutasiRequestInternalDetailQty-MutasiRequestInternalDetailReceiveQty as qty_request_rest,
|
|
ItemName as item_name,
|
|
ItemUnitName as unit_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
IFNULL(SUM(StockQty),0) as qty_stock,
|
|
0 as qty
|
|
FROM mutasirequestinternaldetail
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID
|
|
JOIN warehouse ON MutasiRequestInternalToWarehouseID = WarehouseID
|
|
JOIN item ON MutasiRequestInternalDetailItemID = ItemID
|
|
JOIN itemunit ON MutasiRequestInternalDetailUnitID = ItemUnitID
|
|
LEFT JOIN stock ON StockItemID = ItemID AND StockItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y' AND
|
|
MutasiRequestInternalWarehouseID = ? AND
|
|
( MutasiRequestInternalDetailQty - MutasiRequestInternalDetailReceiveQty ) > 0
|
|
GROUP BY MutasiRequestInternalDetailID";
|
|
$query = $this->db_inventory->query($sql,array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("get data request 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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|