226 lines
9.8 KiB
PHP
226 lines
9.8 KiB
PHP
<?php
|
|
class Terms 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 get_terms(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm) > 0){
|
|
$id = $prm['id'];
|
|
$sql = "SELECT PurchaseOrderID as id,
|
|
PurchaseOrderCode as code,
|
|
PurchaseOrderName as name,
|
|
PurchaseOrderDescription as description,
|
|
DATE_FORMAT(PurchaseOrderStartDate,'%d-%m-%Y') as start_date,
|
|
DATE_FORMAT(PurchaseOrderEndDate,'%d-%m-%Y') as end_date
|
|
FROM purchaseorder
|
|
WHERE
|
|
PurchaseOrderSupplierID = ? AND PurchaseOrderIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("purchaseorder rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_term_detail(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm['id']) > 0){
|
|
$id = $prm['id'];
|
|
$warehouseid = $prm['warehouseid'];
|
|
|
|
$almari = $this->db_inventory->query("SELECT WarehouseAlmariID as id
|
|
FROM warehousealmari
|
|
WHERE
|
|
WarehouseAlmariIsActive = 'Y'
|
|
AND WarehouseAlmariWarehouseID = $warehouseid
|
|
ORDER BY id ASC LIMIT 1")->row();
|
|
$almarid = $almari->id;
|
|
|
|
$sql = "SELECT WarehouseRackID as id
|
|
FROM warehouserack
|
|
WHERE
|
|
WarehouseRackIsActive = 'Y'
|
|
AND WarehouseRackWarehouseAlmariID = $almarid
|
|
AND WarehouseRackRow = 1
|
|
AND WarehouseRackCol = 1
|
|
ORDER BY id ASC LIMIT 1";
|
|
//echo $sql;
|
|
$rack = $this->db_inventory->query($sql)->row();
|
|
|
|
//echo $this->db_inventory->last_query();
|
|
$rackid = $rack->id;
|
|
|
|
|
|
|
|
$sql = "SELECT PurchaseOrderDetailID as id,
|
|
PurchaseOrderDetailID as podetailid,
|
|
PurchaseOrderDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
ItemSKU as item_sku,
|
|
PurchaseOrderDetailItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
PurchaseOrderDetailQty as po_qty,
|
|
PurchaseOrderDetailReceiveQty as receive_qty,
|
|
0 as qty,
|
|
'N' as is_exist,
|
|
PurchaseOrderDetailAmount as price,
|
|
PurchaseOrderDetailDiscount as discount_percent,
|
|
PurchaseOrderDetailDiscountRp as discount_rp,
|
|
PurchaseOrderDetailTotal as total,
|
|
'N' as selected,
|
|
'' as batch_no,
|
|
'' as ed,
|
|
WarehouseAlmariID as almariid,
|
|
WarehouseAlmariName as almariname,
|
|
WarehouseRackID as rackid,
|
|
WarehouseRackName as rackname
|
|
|
|
FROM purchaseorderdetail
|
|
JOIN item ON PurchaseOrderDetailItemID = ItemID
|
|
LEFT JOIN itemunit ON PurchaseOrderDetailItemUnitID = ItemUnitID
|
|
LEFT JOIN warehousealmari ON WarehouseAlmariID = $almarid
|
|
LEFT JOIN warehouserack ON WarehouseRackID = $rackid
|
|
LEFT JOIN purchasereceivedetail ON PurchaseReceiveDetailPurchaseOrderDetailID = PurchaseOrderDetailID AND PurchaseReceiveDetailIsActive = 'Y'
|
|
LEFT JOIN purchasereceive ON PurchaseReceiveID = PurchaseReceiveDetailPurchaseReceiveID AND PurchaseReceiveIsActive = 'Y'
|
|
WHERE
|
|
PurchaseOrderDetailPurchaseOrderID = ? AND
|
|
PurchaseOrderDetailIsActive = 'Y' AND
|
|
PurchaseOrderDetailStatus NOT IN('D','X')
|
|
GROUP BY PurchaseOrderDetailID";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows && count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['selected'] = false;
|
|
}
|
|
}
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("purchaseorderdetail rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_term_detail_edit(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm) > 0){
|
|
$id = $prm['id'];
|
|
$sql = "SELECT PurchaseReceiveDetailID as id,
|
|
PurchaseOrderDetailID as podetailid,
|
|
PurchaseOrderDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
ItemSKU as item_sku,
|
|
PurchaseOrderDetailItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
PurchaseOrderDetailQty as po_qty,
|
|
PurchaseOrderDetailReceiveQty as receive_qty,
|
|
PurchaseReceiveDetailQty as qty,
|
|
'N' as is_exist,
|
|
PurchaseOrderDetailAmount as price,
|
|
PurchaseOrderDetailDiscount as discount_percent,
|
|
PurchaseOrderDetailDiscountRp as discount_rp,
|
|
PurchaseOrderDetailTotal as total,
|
|
'N' as selected,
|
|
PurchaseReceiveDetailBatchNo as batch_no,
|
|
DATE_FORMAT(PurchaseReceiveDetailED,'%d%m%Y') as ed,
|
|
WarehouseAlmariID as almariid,
|
|
WarehouseAlmariName as almariname,
|
|
WarehouseRackID as rackid,
|
|
WarehouseRackName as rackname
|
|
FROM `purchasereceivedetail`
|
|
JOIN purchaseorderdetail ON PurchaseOrderDetailID = PurchaseReceiveDetailPurchaseOrderDetailID
|
|
JOIN purchaseorder ON PurchaseOrderID = PurchaseOrderDetailPurchaseOrderID
|
|
JOIN `item` ON PurchaseOrderDetailItemID = ItemID
|
|
LEFT JOIN itemunit ON PurchaseOrderDetailItemUnitID = ItemUnitID
|
|
JOIN supplier ON SupplierID = PurchaseOrderSupplierID
|
|
LEFT JOIN warehousealmari ON WarehouseAlmariID = PurchaseReceiveDetailWarehouseAlmariID
|
|
LEFT JOIN warehouserack ON WarehouseRackID = PurchaseReceiveDetailWarehouseRackID
|
|
WHERE
|
|
PurchaseReceiveDetailPurchaseReceiveID = ? AND
|
|
PurchaseReceiveDetailIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows && count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['selected'] = false;
|
|
}
|
|
}
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("purchaseorderdetail rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|