Files
2026-04-15 15:23:57 +07:00

153 lines
6.1 KiB
PHP

<?php
class Stock 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 SupplierPaymentTermsID as id,
SupplierPaymentTermsCode as code,
SupplierPaymentTermsName as name,
SupplierPaymentTermsDescription as description,
DATE_FORMAT(SupplierPaymentTermsStartDate,'%d-%m-%Y') as start_date,
DATE_FORMAT(SupplierPaymentTermsEndDate,'%d-%m-%Y') as end_date
FROM supplierpaymentterms
WHERE
SupplierPaymentTermsSupplierID = ? AND SupplierPaymentTermsIsActive = '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("supplierpaymentterms 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_stock(){
try{
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT StockID as idx,ItemID as item_id, ItemName as item_name, ItemUnitID as unit_id, ItemUnitName as unit_name, WarehouseName as warehouse_name,
SUM(StockQty) as qty
FROM stock
JOIN mutasirequestinternaldetail ON MutasiRequestInternalDetailItemID = StockItemID AND
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y'
JOIN item ON MutasiRequestInternalDetailItemID = ItemID AND StockItemID = ItemID
JOIN itemunit ON StockItemUnitID = ItemUnitID
JOIN warehouse ON StockWarehouseID = WarehouseID AND WarehouseIsOffice = 'Y'
GROUP BY StockWarehouseID, StockItemID, StockItemUnitID
";
$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("stock rows",$this->db_inventory);
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) > 0){
$id = $prm['id'];
$sql = "SELECT SupplierPaymentTermsDetailID as id,
SupplierPaymentTermsDetailItemID as item_id,
ItemName as item_name,
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
SupplierPaymentTermsDetailItemUnitID as unit_id,
ItemUnitName as unit_name,
0 as qty,
'N' as is_exist,
SupplierPaymentTermsDetailPrice as price,
SupplierPaymentTermsDetailDiscount as discount_percent,
SupplierPaymentTermsDetailDiscountRp as discount_rp,
SupplierPaymentTermsDetailTotal as total,
'N' as selected
FROM supplierpaymenttermsdetail
JOIN item ON SupplierPaymentTermsDetailItemID = ItemID AND ItemIsActive = 'Y'
JOIN itemunit ON SupplierPaymentTermsDetailItemUnitID = ItemUnitID AND ItemUnitIsActive = 'Y'
WHERE
SupplierPaymentTermsSupplierPaymentTermsID = ? AND
SupplierPaymentTermsDetailIsActive = '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("supplierpaymenttermsdetail rows",$this->db_inventory);
exit;
}
}
else{
$this->sys_error("Invalid Param ID");
exit;
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}