1164 lines
43 KiB
PHP
1164 lines
43 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_company_address = '';
|
|
if (isset($prm['to_company_addresses']) && intval($prm['to_company_addresses']) > 0) {
|
|
$filter_company_address = ' AND MutasiToCompanyAddressID = '.$prm['to_company_addresses'];
|
|
}
|
|
|
|
$filter_status = '';
|
|
if (isset($prm['status']) && $prm['status'] != 'A') {
|
|
$filter_status = " AND MutasiStatus = '{$prm['status']}'";
|
|
}
|
|
|
|
$order_by = "MutasiNumber";
|
|
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 MutasiRequestID as id
|
|
FROM `mutasirequest`
|
|
LEFT JOIN $this->db_onex.`m_user` ON MutasiRequestConfirmBy = M_UserID
|
|
JOIN `companyaddress` tocompanyaddress ON MutasiRequestCompanyAddressID = tocompanyaddress.CompanyAddressID
|
|
JOIN `company` tocompany ON tocompanyaddress.CompanyAddressCompanyID = tocompany.CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON tocompany.CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
MutasiRequestIsActive = 'Y' AND (DATE(MutasiRequestDate) BETWEEN ? AND ?) AND
|
|
( MutasiRequestNumber 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 MutasiRequestID as id,
|
|
MutasiRequestStatus as status_pengiriman,
|
|
MutasiRequestNumber as code,
|
|
DATE(MutasiRequestDate) as mutation_date,
|
|
MutasiRequestCompanyAddressID as to_company_address_id,
|
|
tocompanyaddress.CompanyAddressLabel as to_company_address_name,
|
|
tocompanyaddress.CompanyAddressDescription as to_company_address_description,
|
|
M_BranchName as branch_name,
|
|
CONCAT(tocompany.CompanyName,' (',M_BranchName,')') as to_company_show_name,
|
|
MutasiRequestDate as mutasi_date,
|
|
MutasiRequestEstimatedDelivery as estimated_date,
|
|
MutasiRequestNote as note,
|
|
MutasiRequestIsConfirm as is_confirm,
|
|
IF(MutasiRequestConfirmAt = NULL, '',DATE_FORMAT(MutasiRequestConfirmAt,'%d-%m-%Y %H:%i')) as confirm_at,
|
|
IFNULL(M_UserUsername,'') as confirm_by,
|
|
'' as details
|
|
FROM `mutasirequest`
|
|
LEFT JOIN $this->db_onex.`m_user` ON MutasiRequestConfirmBy = M_UserID
|
|
JOIN `companyaddress` tocompanyaddress ON MutasiRequestCompanyAddressID = tocompanyaddress.CompanyAddressID
|
|
JOIN `company` tocompany ON tocompanyaddress.CompanyAddressCompanyID = tocompany.CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON tocompany.CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
MutasiRequestIsActive = 'Y' AND (DATE(MutasiRequestDate) BETWEEN ? AND ?) AND
|
|
( MutasiRequestNumber 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 MutasiRequestDetailID as id,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
MutasiRequestDetailQty-MutasiRequestDetailReceiveQty as qty_request_rest,
|
|
ItemName as item_name,
|
|
ItemUnitName as unit_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
IFNULL(MutasiRequestDetailQty,0) as qty,
|
|
MutasiRequestDetailReceiveQty as qty_received,
|
|
MutasiRequestDetailID as id,
|
|
MutasiRequestDetailStatus as last_status,
|
|
'' as details
|
|
FROM mutasirequestdetail
|
|
JOIN item ON MutasiRequestDetailItemID = ItemID
|
|
JOIN itemunit ON MutasiRequestDetailItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiRequestDetailIsActive = 'Y' AND
|
|
MutasiRequestDetailMutasiRequestID = ?
|
|
GROUP BY MutasiRequestDetailID
|
|
";
|
|
$query = $this->db_inventory->query($sql,array($prm['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_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_to_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 AND CompanyIsCenter = 'Y'
|
|
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 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`('RMP') 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 mutasirequest(
|
|
MutasiRequestNumber,
|
|
MutasiRequestCompanyAddressID,
|
|
MutasiRequestDate,
|
|
MutasiRequestEstimatedDelivery,
|
|
MutasiRequestNote,
|
|
MutasiRequestCreated,
|
|
MutasiRequestLastUpdated,
|
|
MutasiRequestUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW(),NOW(),?
|
|
)";
|
|
$param_insert = array(
|
|
$numbering,
|
|
$prm['to_company_addresses']['id'],
|
|
$prm['mutation_date'],
|
|
$prm['estimated_date'],
|
|
$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 request 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 mutasirequestdetail(
|
|
MutasiRequestDetailMutasiRequestID,
|
|
MutasiRequestDetailItemID,
|
|
MutasiRequestDetailItemUnitID,
|
|
MutasiRequestDetailQty,
|
|
MutasiRequestDetailUserID,
|
|
MutasiRequestDetailCreated,
|
|
MutasiRequestDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_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 request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT mutasirequest.*, '' as details
|
|
FROM mutasirequest
|
|
WHERE MutasiRequestID = ? ";
|
|
$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 `mutasirequestdetail`
|
|
WHERE
|
|
MutasiRequestDetailMutasiRequestID = ? AND
|
|
MutasiRequestDetailIsActive = '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 requestmutasi_log (
|
|
RequestMutasiLogMutasiRequestInternalID,
|
|
RequestMutasiStatus,
|
|
RequestMutasiLogJSONBefore,
|
|
RequestMutasiLogJSONAfter,
|
|
RequestMutasiLogUserID,
|
|
RequestMutasiLogCreated
|
|
)
|
|
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 mutasirequest.*, '' as details
|
|
FROM mutasirequest
|
|
WHERE MutasiRequestID = ? ";
|
|
$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 `mutasirequestdetail`
|
|
WHERE
|
|
MutasiRequestDetailMutasiRequestID = ? AND
|
|
MutasiRequestDetailIsActive = '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 mutasirequest SET
|
|
MutasiRequestDate = ?,
|
|
MutasiRequestCompanyAddressID = ?,
|
|
MutasiRequestEstimatedDelivery = ?,
|
|
MutasiRequestNote = ?,
|
|
MutasiRequestLastUpdated = NOW(),
|
|
MutasiRequestUserID = ?
|
|
WHERE
|
|
MutasiRequestID = ?";
|
|
$param_update_header = array(
|
|
$prm['mutation_date'],
|
|
isset($prm['to_company_addresses'])?$prm['to_company_addresses']['id']:0,
|
|
$prm['estimated_date'],
|
|
$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 mutasirequestdetail SET MutasiRequestDetailIsActive = 'N' WHERE MutasiRequestDetailMutasiRequestID = ?";
|
|
$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 mutasirequestdetail SET
|
|
MutasiRequestDetailQty = ?,
|
|
MutasiRequestDetailUserID = ?,
|
|
MutasiRequestDetailIsActive = 'Y',
|
|
MutasiRequestDetailLastUpdated = NOW()
|
|
WHERE
|
|
MutasiRequestDetailID = ?";
|
|
$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 request mutasidetail error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "INSERT INTO mutasirequestdetail(
|
|
MutasiRequestDetailMutasiRequestID,
|
|
MutasiRequestDetailItemID,
|
|
MutasiRequestDetailItemUnitID,
|
|
MutasiRequestDetailQty,
|
|
MutasiRequestDetailUserID,
|
|
MutasiRequestDetailCreated,
|
|
MutasiRequestDetailLastUpdated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW(),NOW()
|
|
)";
|
|
$param_insert_detail = array(
|
|
$last_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 mutasirequest.*, '' as details
|
|
FROM mutasirequest
|
|
WHERE MutasiRequestID = ? ";
|
|
$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 `mutasirequestdetail`
|
|
WHERE
|
|
MutasiRequestDetailMutasiRequestID = ? AND
|
|
MutasiRequestDetailIsActive = '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 requestmutasi_log (
|
|
RequestMutasiLogMutasiRequestInternalID,
|
|
RequestMutasiStatus,
|
|
RequestMutasiLogJSONBefore,
|
|
RequestMutasiLogJSONAfter,
|
|
RequestMutasiLogUserID,
|
|
RequestMutasiLogCreated
|
|
)
|
|
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 mutasirequest
|
|
SET
|
|
MutasiRequestIsActive = 'N',
|
|
MutasiRequestLastUpdated = now(),
|
|
MutasiRequestUserID = ?
|
|
WHERE MutasiRequestID = ?
|
|
";
|
|
$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 mutasirequestdetail
|
|
SET
|
|
MutasiRequestDetailIsActive = 'N',
|
|
MutasiRequestDetailLastUpdated = now(),
|
|
MutasiRequestDetailUserID = ?
|
|
WHERE
|
|
MutasiRequestDetailMutasiRequestID = ?
|
|
";
|
|
$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 mutasirequest.*, '' as details
|
|
FROM mutasirequest
|
|
WHERE MutasiRequestID = ? ";
|
|
$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 requestmutasi_log (
|
|
RequestMutasiLogMutasiRequestInternalID,
|
|
RequestMutasiStatus,
|
|
RequestMutasiLogJSONBefore,
|
|
RequestMutasiLogJSONAfter,
|
|
RequestMutasiLogUserID,
|
|
RequestMutasiLogCreated
|
|
)
|
|
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 mutasirequest
|
|
SET MutasiRequestIsConfirm = 'Y',
|
|
MutasiRequestStatus = 'S',
|
|
MutasiRequestLastUpdated = NOW(),
|
|
MutasiRequestConfirmAt = NOW(),
|
|
MutasiRequestConfirmBy = ?,
|
|
MutasiRequestUserID = ?
|
|
WHERE MutasiRequestID = ?
|
|
";
|
|
$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 mutasirequest.*, '' as details
|
|
FROM mutasirequest
|
|
WHERE MutasiRequestID = ? ";
|
|
$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();
|
|
|
|
$sql = "SELECT mutasirequestdetail.*
|
|
FROM mutasirequestdetail
|
|
WHERE
|
|
MutasiRequestDetailMutasiRequestID = ? AND MutasiRequestDetailIsActive = '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();
|
|
|
|
$row_after['details'] = $details;
|
|
$data_log_after = $row_after;
|
|
|
|
$sql = "INSERT INTO requestmutasi_log (
|
|
RequestMutasiLogMutasiRequestInternalID,
|
|
RequestMutasiStatus,
|
|
RequestMutasiLogJSONBefore,
|
|
RequestMutasiLogJSONAfter,
|
|
RequestMutasiLogUserID,
|
|
RequestMutasiLogCreated
|
|
)
|
|
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);
|
|
|
|
/*$sql = "SELECT CompanyAddressID as id,
|
|
CompanyAddressLabel as label,
|
|
CompanyAddressDescription as address
|
|
FROM company
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y'
|
|
JOIN companyaddress ON CompanyAddressCompanyID = CompanyID AND CompanyAddressIsDefault = 'Y'
|
|
WHERE
|
|
CompanyIsActive = 'Y' LIMIT 1";
|
|
$query = $this->db_inventory->query($sql);
|
|
if(!$qry){
|
|
$this->sys_error_db("select company adreess default error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
$row_company_address = $query->row_array();*/
|
|
$sql = "INSERT INTO mutasirequest_upload (
|
|
MutasiRequestUploadFromCompanyAddressID,
|
|
MutasiRequestUploadMutasiRequestID,
|
|
MutasiRequestUploadJSON,
|
|
MutasiRequestUploadUsername
|
|
)VALUES(
|
|
?,?,?,?
|
|
)";
|
|
$query = $this->db_inventory->query($sql,array(
|
|
isset($param['from_company_address']['id'])?$param['from_company_address']['id']:0,
|
|
$id,
|
|
json_encode($data_log_after),
|
|
$this->sys_user['M_UserUsername']
|
|
));
|
|
if(!$qry){
|
|
$this->sys_error_db("insert mutasirequest_upload error", $this->db_inventory->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,
|
|
CONCAT(CompanyName,' (',M_BranchName,')') as show_name
|
|
FROM company
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y'
|
|
WHERE
|
|
CompanyIsActive = 'Y' LIMIT 1";
|
|
$query = $this->db_inventory->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->row_array();
|
|
|
|
$sql = "SELECT CompanyAddressID as id,
|
|
CompanyAddressLabel as name,
|
|
CompanyAddressDescription as description,
|
|
CONCAT(CompanyName,' (',M_BranchName,')') as show_name
|
|
FROM companyaddress
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y'
|
|
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 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' AND ItemUnitMapIsPurchase = 'N'
|
|
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_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,
|
|
CONCAT(CompanyName,' (',M_BranchName,')') as show_name
|
|
FROM companyaddress
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
CompanyAddressIsActive = 'Y' AND CompanyIsCenter = '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_id,
|
|
MutasiRequestReceiveMutasiRequestNumber as request_number,
|
|
CompanyName as company_name,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
SUM(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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|