1439 lines
52 KiB
PHP
1439 lines
52 KiB
PHP
<?php
|
|
class Request 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_warehouse = '';
|
|
if (isset($prm['warehouse']) && intval($prm['warehouse']) > 0) {
|
|
$filter_warehouse = ' AND OpnameWarehouseID = '.$prm['warehouse'];
|
|
}
|
|
|
|
$order_by = "OpnameNumber";
|
|
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 OpnameID as id
|
|
FROM `opname`
|
|
JOIN `warehouse` ON OpnameWarehouseID = WarehouseID $filter_warehouse
|
|
LEFT JOIN $this->db_onex.m_user ON OpnameConfirmBy = M_UserID
|
|
WHERE
|
|
OpnameIsActive = 'Y' AND (DATE(OpnameDate) BETWEEN ? AND ?) AND
|
|
( OpnameNumber like ? )
|
|
) x";
|
|
$qry = $this->db_inventory->query($sql,array($prm['start_date'],$prm['end_date'],$search));
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
// echo $this->db_inventory->last_query();
|
|
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 OpnameID as id,
|
|
OpnameNumber as code,
|
|
OpnameDate as mutation_date,
|
|
OpnameWarehouseID as warehouse_id,
|
|
WarehouseName as warehouse_name,
|
|
OpnameNote as note,
|
|
OpnameIsConfirm as is_confirm,
|
|
IF(OpnameConfirmAt = NULL, '',DATE_FORMAT(OpnameConfirmAt,'%d-%m-%Y %H:%i')) as confirm_at,
|
|
IFNULL(M_UserUsername,'') as confirm_by,
|
|
'' as details
|
|
FROM `opname`
|
|
JOIN `warehouse` ON OpnameWarehouseID = WarehouseID $filter_warehouse
|
|
LEFT JOIN $this->db_onex.m_user ON OpnameConfirmBy = M_UserID
|
|
WHERE
|
|
OpnameIsActive = 'Y' AND (DATE(OpnameDate) BETWEEN ? AND ?) AND
|
|
( OpnameNumber 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("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 IFNULL(OpnameDetailID,0) as id,
|
|
IFNULL(StockID,0) as stock_id,
|
|
IFNULL(OpnameDetailQtyBefore,StockQty) as qty_before,
|
|
StockWarehouseAlmariID as almari_id,
|
|
WarehouseAlmariName as almari_name,
|
|
StockWarehouseRackID as rack_id,
|
|
WarehouseRackName as rack_name,
|
|
StockStockNumber as stock_number,
|
|
StockItemID as item_id,
|
|
ItemName as item_name,
|
|
StockItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
StockBatchNo as batch_no,
|
|
DATE_FORMAT(StockED,'%d-%m-%Y') as ed,
|
|
IFNULL(OpnameDetailQty,0) as qty_after
|
|
FROM stock
|
|
JOIN item ON StockItemID = ItemID
|
|
JOIN itemunit ON StockItemUnitID = ItemUnitID
|
|
JOIN warehousealmari ON StockWarehouseAlmariID = WarehouseAlmariID
|
|
JOIN warehouserack ON StockWarehouseRackID = WarehouseRackID
|
|
LEFT JOIN opnamedetail ON OpnameDetailOpnameID = ? AND
|
|
OpnameDetailItemID = StockItemID AND OpnameDetailItemUnitID = StockItemUnitID AND
|
|
OpnameDetailWarehouseAlmariID = StockWarehouseAlmariID AND
|
|
OpnameDetailWarehouseRackID = StockWarehouseRackID AND
|
|
OpnameDetailBatchNo = StockBatchNo AND
|
|
OpnameDetailIsActive = 'Y'
|
|
WHERE
|
|
StockWarehouseID = ?
|
|
";
|
|
$query = $this->db_inventory->query($sql,array($prm['id'],$prm['warehouse_id']));
|
|
// echo $this->db_inventory->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("mutasirequestinternaldetail rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_staff(){
|
|
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 M_StaffID as id, M_StaffName as name
|
|
FROM $this->db_onex.m_staff
|
|
WHERE
|
|
M_StaffName like ?
|
|
AND M_StaffIsActive = 'Y'
|
|
ORDER BY M_StaffName ASC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
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("item rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_item(){
|
|
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 ItemID as id, ItemName as name
|
|
FROM item
|
|
JOIN itemunitmap ON ItemUnitMapItemID = ItemID
|
|
WHERE
|
|
ItemName like ?
|
|
AND ItemIsActive = 'Y'
|
|
ORDER BY ItemName ASC
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
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("item rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_unit_by_item(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT ItemUnitID as id, ItemUnitName as name, ItemUnitMapMin as min_stock
|
|
FROM itemunitmap
|
|
JOIN itemunit ON ItemUnitMapItemUnitID = ItemUnitID
|
|
WHERE
|
|
ItemUnitMapItemID = ? AND ItemUnitMapIsActive = 'Y'
|
|
ORDER BY ItemUnitName ASC
|
|
";
|
|
$query = $this->db_inventory->query($sql,[$prm['id']]);
|
|
|
|
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("unit 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
|
|
WHERE
|
|
WarehouseIsActive = 'Y'
|
|
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("companyaddress rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_to_warehouse(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
WHERE
|
|
WarehouseIsOffice = 'Y' AND WarehouseIsActive = 'Y'
|
|
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("companyaddress 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`('OPN') 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 opname(
|
|
OpnameNumber,
|
|
OpnameWarehouseID,
|
|
OpnameDate,
|
|
OpnameNote,
|
|
OpnameCreated,
|
|
OpnameLastUpdated,
|
|
OpnameUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?,NOW(),NOW(),?
|
|
)";
|
|
$param_insert = array(
|
|
$numbering,
|
|
$prm['warehouse']['id'],
|
|
$prm['date'],
|
|
$note,
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql, $param_insert);
|
|
$last_id = 0;
|
|
//echo $this->db_inventory->last_query();
|
|
if($qry){
|
|
$last_id = $this->db_inventory->insert_id();
|
|
}
|
|
else{
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save request mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(count($prm['details'])>0){
|
|
foreach ($prm['details'] as $key => $value) {
|
|
if(intval($value['qty_after']) > 0){
|
|
$sql = "INSERT INTO opnamedetail(
|
|
OpnameDetailOpnameID,
|
|
OpnameDetailItemID,
|
|
OpnameDetailItemUnitID,
|
|
OpnameDetailWarehouseAlmariID,
|
|
OpnameDetailWarehouseRackID,
|
|
OpnameDetailStockNumber,
|
|
OpnameDetailBatchNo,
|
|
OpnameDetailED,
|
|
OpnameDetailQtyBefore,
|
|
OpnameDetailQty,
|
|
OpnemaeDetailUserID,
|
|
OpnameDetailCreated,
|
|
OpnameDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_id,
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['stock_number'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['qty_before'],
|
|
$value['qty_after'],
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql,$param_insert_detail);
|
|
// echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT opname.*, '' as details
|
|
FROM opname
|
|
WHERE OpnameID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *, '' as details
|
|
FROM `opnamedetail`
|
|
WHERE
|
|
OpnameDetailOpnameID = ? AND
|
|
OpnameDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
$this->sys_error_db("select request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after['details'] = $qry->result_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO opname_log (
|
|
OpnameLogOpnameID,
|
|
OpnameLogStatus,
|
|
OpnameLogJSONBefore,
|
|
OpnameLogJSONAfter,
|
|
OpnameLogUserID,
|
|
OpnameLogCreated
|
|
)
|
|
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'];
|
|
|
|
$sql = "SELECT opname.*, '' as details
|
|
FROM opname
|
|
WHERE OpnameID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select request mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_before = $qry->row_array();
|
|
$sql = "SELECT *, '' as details
|
|
FROM `opnamedetail`
|
|
WHERE
|
|
OpnameDetailOpnameID = ? AND
|
|
OpnameDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select requestmutasidetail 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 opname SET
|
|
OpnameDate = ?,
|
|
OpnameWarehouseID = ?,
|
|
OpnameNote = ?,
|
|
OpnameLastUpdated = NOW(),
|
|
OpnameUserID = ?
|
|
WHERE
|
|
OpnameID = ?";
|
|
$param_update_header = array(
|
|
$prm['date'],
|
|
isset($prm['warehouse'])?$prm['warehouse']['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 mutasirequestinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE opnamedetail SET OpnameDetailIsActive = 'N' WHERE OpnameDetailOpnameID = ?";
|
|
$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_after']) > 0){
|
|
if(intval($value['id']) > 0){
|
|
$sql = "UPDATE opnamedetail SET
|
|
OpnameDetailQty = ?,
|
|
OpnemaeDetailUserID = ?,
|
|
OpnameDetailIsActive = 'Y',
|
|
OpnameDetailLastUpdated = NOW()
|
|
WHERE
|
|
OpnameDetailID = ?";
|
|
$param_edit_detail = array(
|
|
$value['qty_after'],
|
|
$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 request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "INSERT INTO opnamedetail(
|
|
OpnameDetailOpnameID,
|
|
OpnameDetailItemID,
|
|
OpnameDetailItemUnitID,
|
|
OpnameDetailWarehouseAlmariID,
|
|
OpnameDetailWarehouseRackID,
|
|
OpnameDetailStockNumber,
|
|
OpnameDetailBatchNo,
|
|
OpnameDetailED,
|
|
OpnameDetailQtyBefore,
|
|
OpnameDetailQty,
|
|
OpnemaeDetailUserID,
|
|
OpnameDetailCreated,
|
|
OpnameDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_id,
|
|
$value['item_id'],
|
|
$value['unit_id'],
|
|
$value['almari_id'],
|
|
$value['rack_id'],
|
|
$value['stock_number'],
|
|
$value['batch_no'],
|
|
$value['ed'],
|
|
$value['qty_before'],
|
|
$value['qty_after'],
|
|
$userid
|
|
);
|
|
$qry = $this->db_inventory->query($sql,$param_insert_detail);
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT opname.*, '' as details
|
|
FROM opname
|
|
WHERE OpnameID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$sql = "SELECT *, '' as details
|
|
FROM `opnamedetail`
|
|
WHERE
|
|
OpnameDetailOpnameID = ? AND
|
|
OpnameDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
if(!$qry){
|
|
$this->sys_error_db("select request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after['details'] = $qry->result_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO opname_log (
|
|
OpnameLogOpnameID,
|
|
OpnameLogStatus,
|
|
OpnameLogJSONBefore,
|
|
OpnameLogJSONAfter,
|
|
OpnameLogUserID,
|
|
OpnameLogCreated
|
|
)
|
|
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 opname
|
|
SET
|
|
OpnameIsActive = 'N',
|
|
OpnameLastUpdated = now(),
|
|
OpnameUserID = ?
|
|
WHERE OpnameID = ?
|
|
";
|
|
$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 opnamedetail
|
|
SET
|
|
OpnameDetailIsActive = 'N',
|
|
OpnameDetailLastUpdated = now(),
|
|
OpnemaeDetailUserID = ?
|
|
WHERE
|
|
OpnameDetailOpnameID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$id]);
|
|
if(!$qry){
|
|
$this->sys_error_db("delete request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT opname.*, '' as details
|
|
FROM opname
|
|
WHERE OpnameID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasi error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO opname_log (
|
|
OpnameLogOpnameID,
|
|
OpnameLogStatus,
|
|
OpnameLogJSONBefore,
|
|
OpnameLogJSONAfter,
|
|
OpnameLogUserID,
|
|
OpnameLogCreated
|
|
)
|
|
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;
|
|
|
|
$warehouse_id = $param['warehouse']['id'];
|
|
|
|
$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 opname
|
|
SET OpnameIsConfirm = 'Y',
|
|
OpnameLastUpdated = NOW(),
|
|
OpnameConfirmAt = NOW(),
|
|
OpnameConfirmBy = ?,
|
|
OpnameUserID = ?
|
|
WHERE OpnameID = ?
|
|
";
|
|
$qry = $this->db_inventory->query($sql, [$userid,$userid,$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("confirm mutasirequestinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "SELECT *, '' as details
|
|
FROM `opnamedetail`
|
|
WHERE
|
|
OpnameDetailOpnameID = ? AND
|
|
OpnameDetailIsActive = 'Y'";
|
|
$qry = $this->db_inventory->query($sql, [$id]);
|
|
if(!$qry){
|
|
|
|
$this->sys_error_db("select mutasirequestinternaldetail before get stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$details = $qry->result_array();
|
|
|
|
foreach ($param['details'] as $key => $value) {
|
|
|
|
//start stockcard out
|
|
$sql = "SELECT *
|
|
FROM stock
|
|
WHERE
|
|
StockID = ?";
|
|
$qry = $this->db_inventory->query($sql, array(
|
|
$value['stock_id']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("select stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
|
|
}
|
|
|
|
$data_last_stock = $qry->row_array();
|
|
$last_stock = $data_last_stock['StockQty'];
|
|
|
|
$arr_insert_stockcard = array(
|
|
'StockCardWarehouseID' => $warehouse_id,
|
|
'StockCardItemID' => $value['item_id'],
|
|
'StockCardItemUnitID' => $value['unit_id'],
|
|
'StockCardBatchNo' => $value['batch_no'],
|
|
'StockCardBefore' => $last_stock,
|
|
'StockCardIn' => 0,
|
|
'StockCardOut' => $value['qty_before'],
|
|
'StockCardAfter' => $last_stock-intval($value['qty_before']),
|
|
'StockCardDatetime' => date("Y-m-d H:i:s"),
|
|
'StockCardUserID' => $userid,
|
|
'StockCardStatus' => 'OPO'
|
|
);
|
|
|
|
|
|
if($valid_ed && $value['ed'] != '0000-00-00')
|
|
$arr_insert_stockcard['StockCardED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('stockcard', $arr_insert_stockcard);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("insert stockcard error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end stockcard out
|
|
|
|
// start update stock out
|
|
$sql = "UPDATE stock SET StockQty = StockQty - {$value['qty_before']}
|
|
WHERE
|
|
StockID = ?";
|
|
$qry = $this->db_inventory->query($sql, array(
|
|
$value['stock_id']
|
|
));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
// end update stock out
|
|
|
|
|
|
//start stockcard in
|
|
$sql = "SELECT *
|
|
FROM stock
|
|
WHERE
|
|
StockID = ?";
|
|
$qry = $this->db_inventory->query($sql, array(
|
|
$value['stock_id']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("select stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
|
|
}
|
|
|
|
$data_last_stock = $qry->row_array();
|
|
$last_stock = $data_last_stock['StockQty'];
|
|
|
|
$arr_insert_stockcard = array(
|
|
'StockCardWarehouseID' => $warehouse_id,
|
|
'StockCardItemID' => $value['item_id'],
|
|
'StockCardItemUnitID' => $value['unit_id'],
|
|
'StockCardBatchNo' => $value['batch_no'],
|
|
'StockCardBefore' => $last_stock,
|
|
'StockCardIn' => $value['qty_after'],
|
|
'StockCardOut' => 0,
|
|
'StockCardAfter' => $last_stock+intval($value['qty_after']),
|
|
'StockCardDatetime' => date("Y-m-d H:i:s"),
|
|
'StockCardUserID' => $userid,
|
|
'StockCardStatus' => 'OPI'
|
|
);
|
|
|
|
|
|
if($valid_ed && $value['ed'] != '0000-00-00')
|
|
$arr_insert_stockcard['StockCardED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('stockcard', $arr_insert_stockcard);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("insert stockcard error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end stockcard in
|
|
|
|
// start update stock in
|
|
$sql = "UPDATE stock SET StockQty = StockQty + {$value['qty_after']}
|
|
WHERE
|
|
StockID = ?";
|
|
$qry = $this->db_inventory->query($sql, array(
|
|
$value['stock_id']
|
|
));
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("update stock error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
// end update stock in
|
|
|
|
|
|
|
|
//start insert stocklog
|
|
$arr_insert_stock = array(
|
|
'StockLogWarehouseID' => $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_before'] * -1,
|
|
'StockLogDatetime' => date("Y-m-d H:i:s"),
|
|
'StockLogUserID' => $userid,
|
|
'StockLogReffID' => $value['id'],
|
|
'StockLogStatus' => 'OPO'
|
|
);
|
|
|
|
|
|
if($valid_ed && $value['ed'] != '0000-00-00')
|
|
$arr_insert_stock['StockLogED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('stocklog', $arr_insert_stock);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save stocklog error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$arr_insert_stock = array(
|
|
'StockLogWarehouseID' => $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_after'],
|
|
'StockLogDatetime' => date("Y-m-d H:i:s"),
|
|
'StockLogUserID' => $userid,
|
|
'StockLogReffID' => $value['id'],
|
|
'StockLogStatus' => 'OPI'
|
|
);
|
|
|
|
|
|
if($valid_ed && $value['ed'] != '0000-00-00')
|
|
$arr_insert_stock['StockLogED'] = $value['ed'];
|
|
|
|
$qry = $this->db_inventory->insert('stocklog', $arr_insert_stock);
|
|
if(!$qry){
|
|
//echo $this->db_inventory->last_query();
|
|
$this->sys_error_db("save stocklog error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
//end insert stocklog
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT opname.*, '' as details
|
|
FROM opname
|
|
WHERE OpnameID = ? ";
|
|
$qry = $this->db_inventory->query($sql, array($id));
|
|
//echo $this->db_inventory->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select mutasirequestinternal error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
$row_after = $qry->row_array();
|
|
|
|
|
|
|
|
$row_after['details'] = $details;
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO opname_log (
|
|
OpnameLogOpnameID,
|
|
OpnameLogStatus,
|
|
OpnameLogJSONBefore,
|
|
OpnameLogJSONAfter,
|
|
OpnameLogUserID,
|
|
OpnameLogCreated
|
|
)
|
|
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;
|
|
}
|
|
//print_r($details);
|
|
|
|
|
|
|
|
$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['company_address_id'];
|
|
$sql = "SELECT MutasiRequestReceiveID as request_receive_id,
|
|
MutasiRequestReceiveMutasiRequestNumber as request_number,
|
|
CompanyName as company_name,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
MutasiRequestReceiveRequestQty-MutasiRequestReceiveReceiveQty as qty_request,
|
|
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 mutasirequestreceive
|
|
JOIN companyaddress ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
JOIN item ON MutasiRequestReceiveItemID = ItemID
|
|
JOIN itemunit ON MutasiRequestReceiveItemUnitID = ItemUnitID
|
|
LEFT JOIN stock ON StockItemID = ItemID AND StockItemUnitID = ItemUnitID
|
|
LEFT JOIN warehouse ON StockWarehouseID = WarehouseID AND WarehouseIsOffice = 'Y'
|
|
WHERE
|
|
MutasiRequestReceiveStatus NOT IN('N','D','C') AND MutasiRequestReceiveIsActive = 'Y' AND
|
|
MutasiRequestReceiveCompanyAddressID = ? AND
|
|
( MutasiRequestReceiveRequestQty - MutasiRequestReceiveReceiveQty ) > 0
|
|
GROUP BY MutasiRequestReceiveID";
|
|
$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);
|
|
}
|
|
}
|
|
|
|
function get_data_stock(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = isset($prm['opname']['id'])?$prm['opname']['id']:0;
|
|
|
|
if($id == 0){
|
|
$sql = "SELECT 0 as id,
|
|
StockID as stock_id,
|
|
StockQty as qty_before,
|
|
StockWarehouseID as warehouse_id,
|
|
StockWarehouseAlmariID as almari_id,
|
|
WarehouseAlmariName as almari_name,
|
|
StockWarehouseRackID as rack_id,
|
|
WarehouseRackName as rack_name,
|
|
StockStockNumber as stock_number,
|
|
StockItemID as item_id,
|
|
ItemName as item_name,
|
|
StockItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
StockBatchNo as batch_no,
|
|
DATE_FORMAT(StockED,'%d-%m-%Y') as ed,
|
|
0 as qty_after
|
|
FROM stock
|
|
JOIN item ON StockItemID = ItemID
|
|
JOIN itemunit ON StockItemUnitID = ItemUnitID
|
|
JOIN warehousealmari ON StockWarehouseAlmariID = WarehouseAlmariID
|
|
JOIN warehouserack ON StockWarehouseRackID = WarehouseRackID
|
|
WHERE
|
|
StockWarehouseID = ?";
|
|
$query = $this->db_inventory->query($sql,array($prm['id']));
|
|
}else{
|
|
$sql = "SELECT IFNULL(OpnameDetailID,0) as id,
|
|
IFNULL(StockID,0) as stock_id,
|
|
StockQty as qty_before,
|
|
StockWarehouseAlmariID as almari_id,
|
|
WarehouseAlmariName as almari_name,
|
|
StockWarehouseRackID as rack_id,
|
|
WarehouseRackName as rack_name,
|
|
StockStockNumber as stock_number,
|
|
StockItemID as item_id,
|
|
ItemName as item_name,
|
|
StockItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
StockBatchNo as batch_no,
|
|
DATE_FORMAT(StockED,'%d-%m-%Y') as ed,
|
|
0 as qty_after
|
|
FROM stock
|
|
JOIN item ON StockItemID = ItemID
|
|
JOIN itemunit ON StockItemUnitID = ItemUnitID
|
|
JOIN warehousealmari ON StockWarehouseAlmariID = WarehouseAlmariID
|
|
JOIN warehouserack ON StockWarehouseRackID = WarehouseRackID
|
|
LEFT JOIN opnamedetail ON OpnameDetailOpnameID = ? AND
|
|
OpnameDetailItemID = StockItemID AND OpnameDetailItemUnitID = StockItemUnitID AND
|
|
OpnameDetailWarehouseAlmariID = StockWarehouseAlmariID AND
|
|
OpnameDetailWarehouseRackID = StockWarehouseRackID AND
|
|
OpnameDetailStockNumber = StockStockNumber AND
|
|
OpnameDetailBatchNo = StockBatchNo AND
|
|
OpnameDetailED = StockED
|
|
WHERE
|
|
StockWarehouseID = ?
|
|
|
|
";
|
|
$query = $this->db_inventory->query($sql,array($prm['id']));
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|