280 lines
12 KiB
PHP
280 lines
12 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'] . '%';
|
|
}
|
|
$start_date = date("Y-m-d");
|
|
if (isset($prm['start_date'])) {
|
|
$start_date = $prm["start_date"];
|
|
}
|
|
$end_date = date("Y-m-d");
|
|
if (isset($prm['end_date'])) {
|
|
$end_date = $prm["end_date"];
|
|
}
|
|
$filter_branch = '';
|
|
if (isset($prm['branch_id']) && intval($prm['branch_id']) > 0) {
|
|
$filter_branch = ' AND M_BranchID = '.$prm['branch_id'];
|
|
}
|
|
$filter_status = '';
|
|
if (isset($prm['status']) && count($prm['status']) > 0) {
|
|
$status = '';
|
|
foreach ($prm['status'] as $k_status => $v_status) {
|
|
if($status != '') $status .= ',';
|
|
$status .= "'".$v_status['id']."'";
|
|
}
|
|
$filter_status = ' AND MutasiRequestReceiveStatus IN ('.$status.')';
|
|
}
|
|
$order_by = "MutasiRequestReceiveID";
|
|
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 MutasiRequestReceiveID
|
|
FROM `mutasirequestreceive`
|
|
JOIN `companyaddress` ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID
|
|
JOIN `company` ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON CompanyM_BranchID = M_BranchID $filter_branch
|
|
JOIN `item` ON MutasiRequestReceiveItemID = ItemID
|
|
JOIN `itemunit` ON MutasiRequestReceiveItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiRequestReceiveIsActive = 'Y' AND (MutasiRequestReceiveDate BETWEEN ? AND ?) $filter_status
|
|
) x";
|
|
$qry = $this->db_inventory->query($sql,array($start_date, $end_date));
|
|
$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 MutasiRequestReceiveID as id,
|
|
MutasiRequestReceiveCompanyAddressID as company_address_id,
|
|
MutasiRequestReceiveMutasiRequestNumber as request_number,
|
|
MutasiRequestReceiveNumber as receive_number,
|
|
M_BranchID as branch_id,
|
|
M_BranchName as branch_name,
|
|
MutasiRequestReceiveEstimatedDelivery as estimated_delivery,
|
|
MutasiRequestReceiveDate as request_date,
|
|
MutasiRequestReceiveNote as request_note,
|
|
MutasiRequestReceiveSenderUsername as sender_name,
|
|
MutasiRequestReceiveSentAt as sent_at,
|
|
MutasiRequestReceiveStatus as request_status,
|
|
MutasiRequestReceiveCompleteNote as complete_note,
|
|
MutasiRequestReceiveRequestQty as request_qty,
|
|
MutasiRequestReceiveReceiveQty as receive_qty,
|
|
MutasiRequestReceiveItemID as item_id,
|
|
ItemName as item_name,
|
|
MutasiRequestReceiveItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
MutasiRequestReceiveStatus as request_status
|
|
FROM `mutasirequestreceive`
|
|
JOIN `companyaddress` ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID
|
|
JOIN `company` ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON CompanyM_BranchID = M_BranchID $filter_branch
|
|
JOIN `item` ON MutasiRequestReceiveItemID = ItemID
|
|
JOIN `itemunit` ON MutasiRequestReceiveItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiRequestReceiveIsActive = 'Y' AND (MutasiRequestReceiveDate BETWEEN ? AND ?) $filter_status
|
|
ORDER BY $order_by $order_type
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db_inventory->query($sql, array($start_date, $end_date, $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("request select error", $this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_branch(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "
|
|
SELECT M_BranchID as id, M_BranchName as name
|
|
FROM company
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
CompanyIsActive = 'Y'
|
|
";
|
|
$query = $this->db_inventory->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("branch rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function read(){
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$this->db_inventory->trans_start();
|
|
$this->db_inventory->trans_strict(FALSE);
|
|
|
|
$sql = "UPDATE mutasirequestreceive SET MutasiRequestReceiveStatus = 'R' WHERE MutasiRequestReceiveID = ? ";
|
|
$query = $this->db_inventory->query($sql,array($prm['id']));
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("m_city count",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO mutasirequestreceive_status (
|
|
MutasiRequestReceiveStatusMutasiRequestReceiveID,
|
|
MutasiRequestReceiveStatusStatus,
|
|
MutasiRequestReceiveStatusJSON,
|
|
MutasiRequestReceiveStatusCreated,
|
|
MutasiRequestReceiveStatusUserID
|
|
)
|
|
VALUES(
|
|
?,?,NULL,NOW(),?
|
|
)";
|
|
$query = $this->db_inventory->query($sql,array($prm['id'],'R',$userid));
|
|
if(!$query){
|
|
$this->sys_error_db("insert mutasirequestreceive_status",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT MutasiRequestReceiveID as id,
|
|
MutasiRequestReceiveCompanyAddressID as company_address_id,
|
|
M_BranchID as branch_id,
|
|
M_BranchName as branch_name,
|
|
MutasiRequestReceiveEstimatedDelivery as estimated_delivery,
|
|
MutasiRequestReceiveMutasiRequestDetailID as request_detail_id,
|
|
MutasiRequestReceiveMutasiRequestNumber as request_number,
|
|
MutasiRequestReceiveDate as request_date,
|
|
MutasiRequestReceiveNote as request_note,
|
|
MutasiRequestReceiveSenderUsername as sender_name,
|
|
MutasiRequestReceiveSentAt as sent_at,
|
|
MutasiRequestReceiveStatus as request_status,
|
|
MutasiRequestReceiveCompleteNote as complete_note,
|
|
MutasiRequestReceiveRequestQty as request_qty,
|
|
MutasiRequestReceiveReceiveQty as receive_qty,
|
|
MutasiRequestReceiveItemID as item_id,
|
|
ItemName as item_name,
|
|
MutasiRequestReceiveItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
MutasiRequestReceiveStatus as request_status
|
|
FROM `mutasirequestreceive`
|
|
JOIN `companyaddress` ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID
|
|
JOIN `company` ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.`m_branch` ON CompanyM_BranchID = M_BranchID
|
|
JOIN `item` ON MutasiRequestReceiveItemID = ItemID
|
|
JOIN `itemunit` ON MutasiRequestReceiveItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiRequestReceiveID = ?";
|
|
$query = $this->db_inventory->query($sql,array($prm['id']));
|
|
if($query){
|
|
$row = $query->row_array();
|
|
|
|
$data_insert = array(
|
|
'RequestStatusResponMutasiRequestReceiveID' => $row['id'] ,
|
|
'RequestStatusResponCompanyAddressID' => $row['company_address_id'] ,
|
|
'RequestStatusResponMutasiRequestDetailID' => $row['request_detail_id'] ,
|
|
'RequestStatusResponMutasiRequestNumber' => $row['request_number'] ,
|
|
'RequestStatusResponStatus' => $row['request_status'] ,
|
|
'RequestStatusResponCreated' => date("Y-m-d H:i:s"),
|
|
'RequestStatusResponUsername' => $this->sys_user['M_UserUsername']
|
|
);
|
|
|
|
$save_respon = $this->db_inventory->insert('requeststatusrespon', $data_insert);
|
|
if(!$save_respon){
|
|
$this->sys_error_db("error insert respon",$this->db_inventory->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$this->sys_error_db("after read row",$this->db_inventory);
|
|
exit;
|
|
}
|
|
|
|
$this->db_inventory->trans_complete();
|
|
|
|
$result = array(
|
|
'records' => $row,
|
|
"message" => ''
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|