Files
BE_IBL/application/controllers/one-bb/bb_bloodrequest/Stock.php
2026-04-15 15:23:57 +07:00

201 lines
9.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 Bb_StockID as stock_id,
Bb_StockTd_BloodTypeID as bloodtype_id,
Td_BloodTypeName as bloodtype_name,
Bb_StockTd_BloodRhesusID as bloodrhesus_id,
Td_BloodRhesusCode as bloodrhesus_code,
Td_BloodCategoryName as bloodcategory_name,
Bb_StockTd_BloodCategoryID as bloodcategory_id,
Td_BloodTypeName as bloodtype_name,
Bb_StockBb_AlmariID as almari_id,
Bb_AlmariName as almari_name,
Bb_StockBB_RackID as rack_id,
Bb_RackName as rack_name,
Bb_StockStatus as is_requested,
Bb_StockAmount as amount,
'' as blood_status,
'' as details
FROM `bb_stock`
JOIN `td_bloodtype` ON Bb_StockTd_BloodTypeID = Td_BloodTypeID
JOIN `td_bloodcategory` ON Bb_StockTd_BloodCategoryID = Td_BloodCategoryID
JOIN `td_bloodrhesus` ON Bb_StockTd_BloodRhesusID = Td_BloodRhesusID
JOIN `bb_almari` ON Bb_StockBb_AlmariID = Bb_AlmariID
JOIN `bb_rack` ON Bb_StockBB_RackID = Bb_RackID
WHERE
Bb_StockAmount > 0
";
$query = $this->db_bloodbank->query($sql);
//echo $this->db_bloodbank->last_query();
if ($query) {
$rows = $query->result_array();
if($rows){
foreach ($rows as $key => $value) {
$sql = "SELECT Bb_BloodEntryID as bloodentry_id,
Bb_BloodEntryBagNumberBarcode as barcode,
IF(Bb_BloodEntryIsAlreadyCrossmatch = 'N','Ready',IF(Bb_BloodEntryIsAlreadyDistributed = 'Y','Distributed','Drossmatched')) as status,
IFNULL(Bb_BloodRequestOrderHeaderReqNumber,'-') as req_number,
IFNULL(Bb_BloodRequestOrderHeaderM_PatientName,'-') as patient_name,
Bb_BloodEntryBb_BloodRequestOrderDetailID as orderdetail_id
FROM `bb_stockdetail`
JOIN `bb_bloodentry` ON Bb_StockDetailBb_BloodEntryID = Bb_BloodEntryID
LEFT JOIN `bb_bloodrequest_orderdetail` ON Bb_BloodEntryBb_BloodRequestOrderDetailID = Bb_BloodRequestOrderDetailID
LEFT JOIN `bb_bloodrequest_orderheader` ON Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = Bb_BloodRequestOrderHeaderID
WHERE
Bb_StockDetailBb_StockID = ?";
$query = $this->db_bloodbank->query($sql,array($value['stock_id']));
if(!$query){
//echo $this->db_bloodbank->last_query();
$this->sys_error_db("get data stock detail error", $this->db_bloodbank->last_query());
exit;
}
if($value['is_requested'] == 'Y')
$rows[$key]['blood_status'] = 'Booked';
else{
if($value['is_requested'] == 'N' && intval($value['orderdetail_id']) > 0){
$rows[$key]['blood_status'] = 'Used';
}else{
$rows[$key]['blood_status'] = 'Open';
}
}
$rows[$key]['details'] = $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);
}
}
}