1061 lines
46 KiB
PHP
1061 lines
46 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_from_warehouse = '';
|
|
if (isset($prm['from_warehouse']) && intval($prm['from_warehouse']) > 0) {
|
|
$filter_from_warehouse = ' AND MutasiInternalReceiveFromWarehouseID = '.$prm['from_warehouse'];
|
|
}
|
|
|
|
$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 MutasiInternalReceiveID as id
|
|
FROM `mutasiinternalreceive`
|
|
JOIN `warehouse` from_warehouse ON MutasiInternalReceiveFromWarehouseID = from_warehouse.WarehouseID $filter_from_warehouse
|
|
WHERE
|
|
MutasiInternalReceiveIsActive = 'Y' AND (DATE(MutasiInternalReceiveDate) BETWEEN ? AND ?) AND
|
|
( MutasiInternalReceiveNumber like ? )
|
|
) 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 MutasiInternalReceiveID as id,
|
|
MutasiInternalReceiveNumber as code,
|
|
MutasiInternalReceiveFromWarehouseID as from_warehouse_id,
|
|
from_warehouse.WarehouseName as from_warehouse_name,
|
|
to_warehouse.WarehouseName as to_warehouse_name,
|
|
MutasiInternalReceiveWarehouseID as to_warehouse_id,
|
|
MutasiInternalReceiveDate as receive_date,
|
|
MutasiInternalReceiveNote as note,
|
|
M_UserUsername as receiver_username,
|
|
DATE_FORMAT(MutasiInternalReceiveCreated,'%d-%m-%Y %H:%i') as received_at,
|
|
'' as details
|
|
FROM `mutasiinternalreceive`
|
|
JOIN `warehouse` from_warehouse ON MutasiInternalReceiveFromWarehouseID = from_warehouse.WarehouseID $filter_from_warehouse
|
|
JOIN `warehouse` to_warehouse ON MutasiInternalReceiveWarehouseID = to_warehouse.WarehouseID
|
|
JOIN $this->db_onex.`m_user` ON MutasiInternalReceiveUserID = M_UserID
|
|
WHERE
|
|
MutasiInternalReceiveIsActive = 'Y' AND (DATE(MutasiInternalReceiveDate) BETWEEN ? AND ?) AND
|
|
( MutasiInternalReceiveNumber like ? )
|
|
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("mutasiinternalreceive 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 MutasiInternalReceiveDetailID as detail_id,
|
|
MutasiInternalReceiveDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
MutasiInternalReceiveDetailItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
MutasiInternalReceiveDetailStockNumber as stock_number,
|
|
IFNULL(MutasiInternalReceiveDetailBatchNo,'-') as batch_no,
|
|
IF(MutasiInternalReceiveDetailED IS NOT NULL, DATE_FORMAT(MutasiInternalReceiveDetailED,'%d-%m-%Y'),'-') as ed,
|
|
MutasiInternalReceiveDetailQty as qty
|
|
FROM mutasiinternalreceivedetail
|
|
JOIN item ON MutasiInternalReceiveDetailItemID = ItemID
|
|
JOIN itemunit ON MutasiInternalReceiveDetailItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiInternalReceiveDetailMutasiInternalReceiveID = ? AND MutasiInternalReceiveDetailIsActive = 'Y'
|
|
GROUP BY MutasiInternalReceiveDetailID
|
|
";
|
|
$query = $this->db_inventory->query($sql,array($prm['id']));
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array( "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("mutasiinternalreceivedetail 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_from_company_address(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$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
|
|
CompanyAddressIsActive = 'Y'
|
|
ORDER BY CompanyName 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("companyaddress rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
function get_from_warehouse(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id,
|
|
WarehouseName as name
|
|
FROM warehouse
|
|
JOIN warehousealmari ON WarehouseAlmariWarehouseID = WarehouseID AND WarehouseAlmariIsActive = 'Y'
|
|
JOIN warehouserack ON WarehouseRackWarehouseAlmariID = WarehouseAlmariID AND WarehouseRackIsActive = 'Y' AND WarehouseIsOffice = 'Y'
|
|
WHERE
|
|
WarehouseIsOffice = 'Y' AND WarehouseIsActive = 'Y'
|
|
GROUP BY WarehouseID";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$rows[] = array('id'=>0,'name'=>'Semua');
|
|
|
|
|
|
$result = array("records" => $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 mutasiinternal ON MutasiInternalFromWarehouseID = WarehouseID AND MutasiInternalStatus = 'S'
|
|
JOIN mutasiinternaldetail ON MutasiInternalDetailMutasiInternalID = MutasiInternalID AND MutasiInternalDetailIsActive = 'Y'
|
|
WHERE
|
|
WarehouseIsActive = 'Y'
|
|
GROUP BY WarehouseID";
|
|
$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("warehouse rows",$this->db_inventory);
|
|
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;
|
|
//$this->db_inventory->trans_begin();
|
|
$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`('MIR') 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 mutasiinternalreceive(
|
|
MutasiInternalReceiveNumber,
|
|
MutasiInternalReceiveDate,
|
|
MutasiInternalReceiveFromWarehouseID,
|
|
MutasiInternalReceiveWarehouseID,
|
|
MutasiInternalReceiveNote,
|
|
MutasiInternalReceiveUserID,
|
|
MutasiInternalReceiveCreated,
|
|
MutasiInternalReceiveLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert = array(
|
|
$numbering,
|
|
$prm['receive_date'],
|
|
$prm['from_warehouse']['id'],
|
|
$prm['warehouse']['id'],
|
|
$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 receive mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['details'])>0){
|
|
foreach ($prm['details'] as $key => $value) {
|
|
if(intval($value['qty']) > 0){
|
|
$arr_insert_detail = array(
|
|
'MutasiInternalReceiveDetailMutasiInternalReceiveID' => $last_id,
|
|
'MutasiInternalReceiveDetailMutasiInternalDetailStockID' => $value['transit_detail_id'],
|
|
'MutasiInternalReceiveDetailItemID' => $value['item_id'],
|
|
'MutasiInternalReceiveDetailItemUnitID' => $value['unit_id'],
|
|
'MutasiInternalReceiveDetailStockNumber' => $value['stock_number'],
|
|
'MutasiInternalReceiveDetailBatchNo' => $value['batch_no'],
|
|
'MutasiInternalReceiveDetailQty' => $value['qty'],
|
|
'MutasiInternalReceiveDetailUserID' => $userid,
|
|
'MutasiInternalReceiveDetailCreated' => date("Y-m-d H:i:s"),
|
|
'MutasiInternalReceiveDetailLastUpdated' => date("Y-m-d H:i:s")
|
|
);
|
|
$valid_ed = $this->validateDate($value['ed'])?$value['value']:NULL;
|
|
if($this->validateDate($value['ed']) && $value['ed'] != '0000-00-00')
|
|
$arr_insert_detail['MutasiInternalReceiveDetailED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('mutasiinternalreceivedetail', $arr_insert_detail);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save mutasiinternalreceivedetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$detail_id = $this->db_inventory->insert_id();
|
|
|
|
//start insert stock
|
|
|
|
$select_ed = "";
|
|
if($valid_ed && $value['ed'] != '0000-00-00')
|
|
$select_ed = " AND StockED = '{$value['ed']}'";
|
|
|
|
$sql = "SELECT *
|
|
FROM stock
|
|
WHERE
|
|
StockWarehouseID = ? AND
|
|
StockWarehouseAlmariID = ? AND
|
|
StockWarehouseRackID = ? AND
|
|
StockStockNumber = ? AND
|
|
StockBatchNo = ? AND
|
|
StockItemID = ? AND
|
|
StockItemUnitID = ?
|
|
$select_ed
|
|
LIMIT 1";
|
|
$qry = $this->db_inventory->query($sql, array(
|
|
$prm['warehouse']['id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['stock_number'],
|
|
$value['batch_no'],
|
|
$value['item_id'],
|
|
$value['unit_id']
|
|
));
|
|
//echo $this->db_inventory->last_query();
|
|
|
|
$qty_last = 0;
|
|
$qty_after = 0;
|
|
if($qry->row_array()){
|
|
$data_stock_exist = $qry->row_array();
|
|
$sql = "UPDATE stock SET StockQty = ?
|
|
WHERE
|
|
StockID = ?";
|
|
$qry = $this->db_inventory->query($sql, array(
|
|
$data_stock_exist['StockID'],
|
|
intval($data_stock_exist['StockQty']) + intval($value['qty'])
|
|
));
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$qty_last = $data_stock_exist['StockQty'];
|
|
$qty_after = intval($data_stock_exist['StockQty']) + intval($value['qty']);
|
|
}else{
|
|
$arr_insert_stock = array(
|
|
'StockWarehouseID' => $prm['warehouse']['id'],
|
|
'StockWarehouseAlmariID' => $value['almari_id'],
|
|
'StockWarehouseRackID' => $value['rack_id'],
|
|
'StockStockNumber' => $value['stock_number'],
|
|
'StockItemID' => $value['item_id'],
|
|
'StockItemUnitID' => $value['unit_id'],
|
|
'StockBatchNo' => $value['batch_no'],
|
|
'StockQty' => $value['qty'],
|
|
'StockUserID' => $userid
|
|
);
|
|
|
|
if($this->validateDate($value['ed']) && $value['ed'] != '0000-00-00')
|
|
$arr_insert_stock['StockED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('stock', $arr_insert_stock);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("insert stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$qty_last = 0;
|
|
$qty_after = $value['qty'];
|
|
}
|
|
//end insert stock
|
|
|
|
//start insert stockcard
|
|
|
|
$arr_insert_stockcard = array(
|
|
'StockCardWarehouseID' => $prm['warehouse']['id'],
|
|
'StockCardItemID' => $value['item_id'],
|
|
'StockCardItemUnitID' => $value['unit_id'],
|
|
'StockCardBatchNo' => $value['batch_no'],
|
|
'StockCardBefore' => $qty_last,
|
|
'StockCardIn' => $value['qty'],
|
|
'StockCardOut' => 0,
|
|
'StockCardAfter' => $qty_after,
|
|
'StockCardDatetime' => date("Y-m-d H:i:s"),
|
|
'StockCardUserID' => $userid,
|
|
'StockCardStatus' => 'MIR',
|
|
'StockCardReffID' => $detail_id
|
|
);
|
|
|
|
$valid_ed = $this->validateDate($value['ed'])?$value['value']:NULL;
|
|
//echo $valid_ed;
|
|
//echo $value['ed'];
|
|
if($this->validateDate($value['ed']) && $value['ed'] != '0000-00-00'){
|
|
$arr_insert_stockcard['StockCardED'] = $value['ed'] ;
|
|
}
|
|
//print_r($arr_insert_stockcard);
|
|
|
|
|
|
|
|
$qry = $this->db_inventory->insert('stockcard', $arr_insert_stockcard);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("insert stockcard error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end insert stockcard
|
|
|
|
//start insert stocklog
|
|
$arr_insert_stock_log = array(
|
|
'StockLogWarehouseID' => $prm['warehouse']['id'],
|
|
'StockLogWarehouseAlmariID' => $value['almari_id'],
|
|
'StockLogWarehouseRackID' => $value['rack_id'],
|
|
'StockLogStockNumber' => $value['stock_number'],
|
|
'StockLogItemID' => $value['item_id'],
|
|
'StockLogItemUnitID' => $value['unit_id'],
|
|
'StockLogBatchNo' => $value['batch_no'],
|
|
'StockLogQty' => $value['qty'],
|
|
'StockLogDatetime' => date("Y-m-d H:i:s"),
|
|
'StockLogUserID' => $userid,
|
|
'StockLogReffID' => $detail_id,
|
|
'StockLogStatus' => 'MIR',
|
|
'StockLogED' => $ed
|
|
);
|
|
|
|
|
|
if($this->validateDate($value['ed']) && $value['ed'] != '0000-00-00')
|
|
$arr_insert_stock_log['StockLogED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('stocklog', $arr_insert_stock_log);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save stocklog error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end insert stocklog
|
|
|
|
|
|
|
|
//start update mutasiinternaldetailstock
|
|
$sql = "UPDATE mutasiinternaldetailstock SET
|
|
MutasiInternalDetailStockReceiveQty = ?,
|
|
MutasiInternalDetailStockIsReceive = 'Y',
|
|
MutasiInternalDetailStockLastUpdated = NOW()
|
|
WHERE
|
|
MutasiInternalDetailStockID = ?";
|
|
$qry = $this->db_inventory->query($sql, [$value['qty'],$value['detail_stock_id']]);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update mutasiinternaldetailstock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end update mutasiinternaldetailstock
|
|
|
|
//start update mutasiinternaldetail
|
|
$sql = "UPDATE mutasiinternaldetail SET
|
|
MutasiInternalDetailQtyReceive = ?,
|
|
MutasiInternalDetailLastUpdated = NOW()
|
|
WHERE
|
|
MutasiInternalDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql, [$value['qty'],$value['mutasi_detail_id']]);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update mutasiinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end update mutasiinternaldetail
|
|
|
|
$sql =" SELECT count(*) as total_not_done
|
|
FROM mutasiinternaldetail
|
|
WHERE
|
|
MutasiInternalDetailQtyReceive < MutasiInternalDetailQtyReceive AND
|
|
MutasiInternalDetailIsActive = 'Y' AND
|
|
MutasiInternalDetailMutasiInternalID = ?";
|
|
$qry = $this->db_inventory->query($sql,array(
|
|
$value['mutasi_id']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("select total_not_done error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$total_not_done = $qry->row()->total_not_done;
|
|
$status_header_mutasi = 'P';
|
|
if($total_not_done == 0)
|
|
$status_header_mutasi = 'D';
|
|
|
|
$sql = "UPDATE mutasiinternal
|
|
SET MutasiInternalStatus = ?
|
|
WHERE
|
|
MutasiInternalID = ?";
|
|
$qry = $this->db_inventory->query($sql,array(
|
|
$status_header_mutasi,$value['mutasi_id']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("update status error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT *
|
|
FROM mutasirequestinternaldetail
|
|
WHERE
|
|
MutasiRequestInternalDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql,array(
|
|
$value['mutasi_request_detail_id']
|
|
));
|
|
|
|
if(!$qry){
|
|
$this->sys_error_db("update mutasirequestinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_mutasirequestinternaldetail = $qry->row_array();
|
|
//rint_r($row_mutasirequestinternaldetail);
|
|
|
|
$now_received = intval($row_mutasirequestinternaldetail['MutasiRequestInternalDetailReceiveQty']) + intval($value['qty']);
|
|
//echo $now_received ;
|
|
$status_detail_request = 'P';
|
|
if($now_received >= intval($row_mutasirequestinternaldetail['MutasiRequestInternalDetailQty']))
|
|
$status_detail_request = 'D';
|
|
|
|
$sql = "UPDATE mutasirequestinternaldetail
|
|
SET MutasiRequestInternalDetailReceiveQty = ?,
|
|
MutasiRequestInternalDetailStatus = ?
|
|
WHERE
|
|
MutasiRequestInternalDetailID = ?";
|
|
$qry = $this->db_inventory->query($sql,array(
|
|
$now_received,
|
|
$status_detail_request,
|
|
$value['mutasi_request_detail_id']
|
|
));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("update mutasirequestinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$arr_insert_mutasirequestinternal_status = array(
|
|
'MutasiRequestInternalStatusMutasiRequestInternalDetailID' => $value['mutasi_request_detail_id'],
|
|
'MutasiRequestInternalStatus' => 'R',
|
|
'MutasiRequestInternalMutasiInternalReceiveDetailID' => $detail_id,
|
|
'MutasiRequestInternalStatusCreated' => date("Y-m-d H:i:s"),
|
|
'MutasiRequestInternalStatusLastUpdated' => date("Y-m-d H:i:s"),
|
|
'MutasiRequestInternalStatusUserID' => $userid
|
|
);
|
|
|
|
$qry = $this->db_inventory->insert('mutasirequestinternal_status', $arr_insert_mutasirequestinternal_status);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("insert mutasirequestinternal_status error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT COUNT(*) as total_not_done
|
|
FROM mutasirequestinternaldetail
|
|
WHERE
|
|
MutasiRequestInternalDetailReceiveQty < MutasiRequestInternalDetailQty AND
|
|
MutasiRequestInternalDetailIsActive = 'Y' AND
|
|
MutasiRequestInternalDetailMutasiRequestInternalID = ?";
|
|
$qry = $this->db_inventory->query($sql,array(
|
|
$row_mutasirequestinternaldetail['MutasiRequestInternalDetailMutasiRequestInternalID']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("select total_not_done mutasirequestinternaldetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//$row_mutasirequestinternaldetail = $qry->row_array();
|
|
|
|
$total_not_done_header = $qry->row()->total_not_done;
|
|
$status_header_request = 'P';
|
|
if(intval($total_not_done_header) == 0)
|
|
$status_header_request = 'D';
|
|
|
|
$sql = "UPDATE mutasirequestinternal
|
|
SET MutasiRequestInternalStatus = ?,
|
|
MutasiRequestInternalLastUpdated = NOW()
|
|
WHERE
|
|
MutasiRequestInternalID = ?";
|
|
$qry = $this->db_inventory->query($sql,array(
|
|
$status_header_request,
|
|
$row_mutasirequestinternaldetail['MutasiRequestInternalDetailMutasiRequestInternalID']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("update mutasirequestinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT mutasiinternalreceive.*, '' as details
|
|
FROM mutasiinternalreceive
|
|
WHERE MutasiInternalReceiveID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternalreceive error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *
|
|
FROM `mutasiinternalreceivedetail`
|
|
WHERE
|
|
MutasiInternalReceiveDetailMutasiInternalReceiveID = ? AND
|
|
MutasiInternalReceiveDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasiinternalreceivedetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after['details'] = $qry->result_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO mutasiinternalreceive_log (
|
|
MutasiInternalReceiveLogMutasiInternalReceiveID,
|
|
MutasiInternalReceiveLogStatus,
|
|
MutasiInternalReceiveLogBefore,
|
|
MutasiInternalReceiveLogAfter,
|
|
MutasiInternalReceiveLogUserID,
|
|
MutasiInternalReceiveLogCreated
|
|
)
|
|
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();
|
|
//$this->db_inventory->trans_rollback();
|
|
|
|
|
|
$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 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_warehouse(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT WarehouseID as id,
|
|
WarehouseName as name
|
|
FROM warehouse
|
|
JOIN mutasiinternal ON MutasiInternalToWarehouseID = WarehouseID AND MutasiInternalStatus = 'S' AND MutasiInternalFromWarehouseID = ?
|
|
JOIN mutasiinternaldetail ON MutasiInternalDetailMutasiInternalID = MutasiInternalID AND MutasiInternalDetailIsActive = 'Y'
|
|
JOIN warehousealmari ON WarehouseAlmariWarehouseID = WarehouseID AND WarehouseAlmariIsActive = 'Y'
|
|
JOIN warehouserack ON WarehouseRackWarehouseAlmariID = WarehouseAlmariID AND WarehouseRackIsActive = 'Y'
|
|
WHERE
|
|
WarehouseIsActive = 'Y'
|
|
GROUP BY WarehouseID";
|
|
$query = $this->db_inventory->query($sql,array($prm['from_warehouse_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("warehouse 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_from_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 mutasitransitdetail ON MutasiTransitDetailFromCompanyAddressID = CompanyAddressID AND
|
|
MutasiTransitDetailIsReceive = 'N'
|
|
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_transit(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$id_from = $prm['from_warehouse_id'];
|
|
$id_to = isset($prm['to_warehouse_id']) && intval($prm['to_warehouse_id']) > 0 ? $prm['to_warehouse_id'] : 0;
|
|
$sql = "SELECT MutasiInternalDetailStockID as transit_detail_id,
|
|
MutasiInternalDetailStockID as detail_stock_id,
|
|
MutasiInternalNumber as mutasi_number,
|
|
MutasiInternalID as mutasi_id,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
MutasiInternalDetailQty as qty_sent,
|
|
ItemName as item_name,
|
|
ItemUnitName as unit_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
MutasiInternalDetailStockQty as qty,
|
|
MutasiInternalDetailStockBatchNo as batch_no,
|
|
MutasiInternalDetailStockStockNumber as stock_number,
|
|
MutasiInternalDetailStockED as ed,
|
|
MutasiInternalFromWarehouseID as from_warehouse_id,
|
|
MutasiInternalToWarehouseID as to_warehouse_id,
|
|
M_StaffName as expedition_staff,
|
|
MutasiInternalDetailID as mutasi_detail_id,
|
|
MutasiInternalDetailMutasiRequestInternalDetailID as mutasi_request_receive_id,
|
|
MutasiInternalDetailMutasiRequestInternalDetailID as mutasi_request_detail_id,
|
|
MutasiInternalNote as note,
|
|
'' as almaries,
|
|
'' as racks,
|
|
'' as almari_id,
|
|
'' as rack_id
|
|
FROM mutasiinternaldetailstock
|
|
JOIN mutasiinternaldetail ON MutasiInternalDetailStockMutasiInternalDetailID = MutasiInternalDetailID
|
|
JOIN mutasiinternal ON MutasiInternalDetailMutasiInternalID = MutasiInternalID
|
|
JOIN $this->db_onex.m_staff ON MutasiInternalM_StaffID = M_StaffID
|
|
JOIN item ON MutasiInternalDetailStockItemID = ItemID
|
|
JOIN itemunit ON MutasiInternalDetailStockItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiInternalDetailStockIsReceive = 'N' AND MutasiInternalDetailStockIsActive = 'Y' AND
|
|
MutasiInternalToWarehouseID = ? AND MutasiInternalFromWarehouseID = ?";
|
|
$query = $this->db_inventory->query($sql,array($id_to,$id_from));
|
|
//echo $this->db_inventory->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if(intval($id_to) > 0){
|
|
$sql = "SELECT WarehouseAlmariID as id,
|
|
WarehouseAlmariName as name,
|
|
WarehouseAlmariCode as code,
|
|
'' as racks
|
|
FROM warehousealmari
|
|
JOIN warehouserack ON WarehouseRackWarehouseAlmariID = WarehouseAlmariID AND WarehouseRackIsActive = 'Y'
|
|
WHERE
|
|
WarehouseAlmariWarehouseID = ? AND WarehouseAlmariIsActive = 'Y'
|
|
GROUP BY WarehouseAlmariID";
|
|
$query = $this->db_inventory->query($sql,array($id_to));
|
|
if(!$query){
|
|
$this->sys_error_db("get data almari error",$this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$rows_almaries = $query->result_array();
|
|
foreach ($rows_almaries as $key => $value) {
|
|
$sql = "SELECT WarehouseRackID as id,
|
|
WarehouseRackCode as code,
|
|
WarehouseRackCode as name
|
|
FROM warehouserack
|
|
WHERE
|
|
WarehouseRackWarehouseAlmariID = ? AND WarehouseRackIsActive = 'Y'
|
|
GROUP BY WarehouseRackID
|
|
ORDER BY WarehouseRackCode ASC";
|
|
$query = $this->db_inventory->query($sql,array($value['id']));
|
|
if(!$query){
|
|
$this->sys_error_db("get data rack error",$this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$rows_racks = $query->result_array();
|
|
$rows_almaries[$key]['racks'] = $rows_racks;
|
|
}
|
|
|
|
if(count($rows_almaries) > 0){
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['almaries'] = $rows_almaries;
|
|
$rows[$k]['almari_id'] = $rows_almaries[0]['id'];
|
|
$rows[$k]['racks'] = $rows_almaries[0]['racks'];
|
|
$rows[$k]['rack_id'] = $rows[$k]['racks'][0]['id'];
|
|
}
|
|
}
|
|
|
|
}
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("get data transit 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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|