1118 lines
45 KiB
PHP
1118 lines
45 KiB
PHP
<?php
|
|
class Bloodentry extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
//$this->db_bloodbank = $this->load->database("inventory", true);
|
|
//$this->db_bloodbank_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_status = '';
|
|
|
|
if (isset($prm['status']) && $prm['status'] == 'B') {
|
|
$filter_status = " AND ( Bb_BloodEntryIsRequest ='Y' OR Bb_BloodEntryIsAlreadyCrossmatch = 'Y' )";
|
|
}
|
|
|
|
$order_by = "Bb_BloodEntryBagNumberBarcode";
|
|
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 Bb_BloodEntryID as id
|
|
FROM `bb_bloodentry`
|
|
JOIN `td_bloodtype` ON Bb_BloodEntryTd_BloodTypeID = Td_BloodTypeID
|
|
JOIN `td_bloodrhesus` ON Bb_BloodEntryTd_BloodRhesusID = Td_BloodRhesusID
|
|
JOIN `td_bloodcategory` ON Bb_BloodEntryTd_BloodCategoryID = Td_BloodCategoryID
|
|
JOIN `td_source` ON Bb_BloodEntryTd_SourceID = Td_SourceID
|
|
LEFT JOIN `bb_bloodrequest_orderdetail` ON Bb_BloodEntryBb_BloodRequestOrderDetailID = Bb_BloodRequestOrderDetailID
|
|
AND Bb_BloodRequestOrderDetailTd_BloodCategoryID = Bb_BloodEntryTd_BloodCategoryID
|
|
LEFT JOIN `bb_bloodrequest_orderheader` ON Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = Bb_BloodRequestOrderHeaderID
|
|
AND Bb_BloodRequestOrderHeaderTd_BloodTypeID = Bb_BloodEntryTd_BloodTypeID
|
|
AND Bb_BloodRequestOrderHeaderTd_BloodRhesusID = Bb_BloodEntryTd_BloodRhesusID
|
|
WHERE
|
|
Bb_BloodEntryIsActive = 'Y' AND (DATE(Bb_BloodEntryEntryDate) BETWEEN ? AND ?) AND
|
|
( Bb_BloodEntryBagNumber like ? OR Bb_BloodEntryBagNumberBarcode like ?) $filter_status
|
|
) x";
|
|
$qry = $this->db_bloodbank->query($sql,array(
|
|
$prm['start_date'],
|
|
$prm['end_date'],
|
|
$search,
|
|
$search
|
|
));
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
//echo $this->db_bloodbank->last_query();
|
|
if ($qry) {
|
|
$tot_count = $qry->row()->total;
|
|
$tot_page = ceil($tot_count/$perpage);
|
|
} else {
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("purchase order count error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
|
|
$rows = array();
|
|
$sql = "SELECT Bb_BloodEntryID as id,
|
|
Bb_BloodEntryIsRequest as is_requested,
|
|
Bb_BloodEntryBagNumberBarcode as code,
|
|
Bb_BloodEntryBagNumber as number_manual,
|
|
Bb_BloodEntryEntryDate as entry_date,
|
|
Bb_BloodEntryEntryTime as entry_time,
|
|
Bb_BloodEntryAftapDate as aftap_date,
|
|
TIME_FORMAT(Bb_BloodEntryAftapTime, '%H:%i') as aftap_time,
|
|
Bb_BloodEntryExpiredDate as expired_date,
|
|
Bb_BloodEntryExpiredTime as expired_time,
|
|
Bb_BloodEntryTd_BloodTypeID as bloodtype_id,
|
|
Td_BloodTypeName as bloodtype_name,
|
|
Bb_BloodEntryTd_BloodRhesusID as rhesus_id,
|
|
Td_BloodRhesusName as rhesus_name,
|
|
Td_BloodRhesusCode as rhesus_code,
|
|
Bb_BloodEntryTd_BloodCategoryID as category_id,
|
|
Td_BloodCategoryName as category_name,
|
|
Bb_BloodEntryReqNumber as request_number,
|
|
IFNULL(Bb_BloodEntryBb_BloodRequestOrderDetailID,0) as orderdetail_id,
|
|
Bb_BloodRequestOrderHeaderM_PatientName as patient_name,
|
|
Bb_BloodEntryIsAlreadyCrossmatch as is_crossmatched,
|
|
Bb_BloodEntryIsExternal as is_internal,
|
|
Bb_BloodEntryIsAlreadyDistributed as is_distributed,
|
|
Bb_BloodEntryIsDeposited as is_deposited,
|
|
Bb_AlmariName as almari_name,
|
|
Bb_RackName as rack_name
|
|
FROM `bb_bloodentry`
|
|
JOIN `bb_stockdetail` ON Bb_StockDetailBb_BloodEntryID = Bb_BloodEntryID
|
|
JOIN `bb_stock` ON Bb_StockDetailBb_StockID = Bb_StockID
|
|
JOIN `bb_almari` ON Bb_StockBb_AlmariID = Bb_AlmariID
|
|
JOIN `bb_rack` ON Bb_StockBB_RackID = Bb_RackID
|
|
JOIN `td_bloodtype` ON Bb_BloodEntryTd_BloodTypeID = Td_BloodTypeID
|
|
JOIN `td_bloodrhesus` ON Bb_BloodEntryTd_BloodRhesusID = Td_BloodRhesusID
|
|
JOIN `td_bloodcategory` ON Bb_BloodEntryTd_BloodCategoryID = Td_BloodCategoryID
|
|
JOIN `td_source` ON Bb_BloodEntryTd_SourceID = Td_SourceID
|
|
LEFT JOIN `bb_bloodrequest_orderdetail` ON Bb_BloodEntryBb_BloodRequestOrderDetailID = Bb_BloodRequestOrderDetailID
|
|
AND Bb_BloodRequestOrderDetailTd_BloodCategoryID = Bb_BloodEntryTd_BloodCategoryID
|
|
LEFT JOIN `bb_bloodrequest_orderheader` ON Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = Bb_BloodRequestOrderHeaderID
|
|
AND Bb_BloodRequestOrderHeaderTd_BloodTypeID = Bb_BloodEntryTd_BloodTypeID
|
|
AND Bb_BloodRequestOrderHeaderTd_BloodRhesusID = Bb_BloodEntryTd_BloodRhesusID
|
|
WHERE
|
|
Bb_BloodEntryIsActive = 'Y' AND (DATE(Bb_BloodEntryEntryDate) BETWEEN ? AND ?) AND
|
|
( Bb_BloodEntryBagNumber like ? OR Bb_BloodEntryBagNumberBarcode like ?) $filter_status
|
|
ORDER BY $order_by $order_type
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db_bloodbank->query($sql, array(
|
|
$prm['start_date'],
|
|
$prm['end_date'],
|
|
$search,
|
|
$search,
|
|
$perpage,
|
|
$offset
|
|
));
|
|
//echo $this->db_bloodbank->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_bloodbank->last_query();
|
|
$this->sys_error_db("purchase order select error", $this->db_bloodbank->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 MutasiInternalDetailMutasiRequestInternalDetailID as request_receive_id,
|
|
MutasiRequestInternalNumber as request_number,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
IFNULL(MutasiRequestInternalDetailQty,0)-IFNULL(MutasiRequestInternalDetailReceiveQty,0) as qty_request_rest,
|
|
MutasiRequestInternalDetailQty as qty_request,
|
|
IFNULL(MutasiRequestInternalDetailQty,0) as qty_request_all,
|
|
IFNULL(MutasiRequestInternalDetailReceiveQty,0) as qty_received_all,
|
|
ItemName as item_name,
|
|
ItemUnitName as unit_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
IFNULL(MutasiInternalDetailQty,0) as qty_send,
|
|
IFNULL(MutasiInternalDetailQty,0) as qty,
|
|
IFNULL(MutasiInternalDetailQtyReceive,0) as qty_received,
|
|
MutasiInternalDetailID as id,
|
|
IFNULL(SUM(StockQty),0) as qty_stock,
|
|
IFNULL(MutasiInternalIsConfirm,'N') as is_confirm,
|
|
'' as details
|
|
FROM mutasiinternaldetail
|
|
JOIN mutasiinternal ON MutasiInternalDetailMutasiInternalID = MutasiInternalID
|
|
JOIN item ON MutasiInternalDetailItemID = ItemID
|
|
JOIN itemunit ON MutasiInternalDetailItemUnitID = ItemUnitID
|
|
LEFT JOIN stock ON StockWarehouseID = MutasiInternalFromWarehouseID AND
|
|
MutasiInternalDetailItemID = StockItemID AND MutasiInternalDetailItemUnitID = ItemUnitID AND
|
|
StockQty > 0
|
|
JOIN mutasirequestinternaldetail ON
|
|
MutasiInternalDetailMutasiRequestInternalDetailID = MutasiRequestInternalDetailID
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID
|
|
WHERE
|
|
MutasiInternalDetailMutasiInternalID = ? AND
|
|
MutasiInternalDetailIsActive = 'Y' AND
|
|
MutasiInternalFromWarehouseID = ?
|
|
GROUP BY MutasiInternalDetailID
|
|
";
|
|
$query = $this->db_bloodbank->query($sql,array($prm['id'],$prm['from_warehouse_id']));
|
|
//echo $this->db_bloodbank->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach ($rows as $key => $value) {
|
|
if($value['is_confirm'] === 'Y'){
|
|
$sql = "SELECT MutasiInternalDetailStockID as id,
|
|
MutasiInternalDetailStockItemID as item_id,
|
|
ItemName as item_name,
|
|
MutasiInternalDetailStockItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
MutasiInternalDetailStockBatchNo as batch_no,
|
|
MutasiInternalDetailStockStockNumber as stock_number,
|
|
IF(MutasiInternalDetailStockED = NULL OR MutasiInternalDetailStockED = '0000-00-00','',MutasiInternalDetailStockED) as ed,
|
|
MutasiInternalDetailStockQty as qty
|
|
FROM `mutasiinternaldetailstock`
|
|
JOIN `item` ON MutasiInternalDetailStockItemID = ItemID
|
|
JOIN `itemunit` ON MutasiInternalDetailStockItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiInternalDetailStockMutasiInternalDetailID = ? AND
|
|
MutasiInternalDetailStockIsActive = 'Y'
|
|
|
|
";
|
|
$query = $this->db_bloodbank->query($sql,array($value['id']));
|
|
//echo $this->db_bloodbank->last_query();
|
|
if($query){
|
|
$rows[$key]['details'] = $query->result_array();
|
|
}
|
|
else{
|
|
$this->sys_error_db("mutasiinternaldetailstock rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//echo $this->db_bloodbank->last_query();
|
|
$result = array( "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("mutasidetail rows",$this->db_bloodbank);
|
|
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_bloodbank->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_bloodbank->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("companyaddress rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_patient(){
|
|
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 M_PatientID as patient_id,
|
|
M_PatientName as patient_name,
|
|
Bb_BloodRequestOrderHeaderID as request_id,
|
|
Bb_BloodRequestOrderHeaderReqNumber as request_number,
|
|
Bb_BloodRequestOrderHeaderM_PatientNoReg as patient_noreg,
|
|
Bb_BloodRequestOrderHeaderRegNumber as regnumber,
|
|
CONCAT(Bb_BloodRequestOrderHeaderReqNumber,' | ',M_PatientName) as label,
|
|
Bb_BloodRequestOrderDetailID as orderdetail_id
|
|
FROM $this->db_onex.`m_patient`
|
|
JOIN bb_bloodrequest_orderheader ON Bb_BloodRequestOrderHeaderM_PatientID = M_PatientID
|
|
AND Bb_BloodRequestOrderHeaderTd_BloodTypeID = ?
|
|
AND Bb_BloodRequestOrderHeaderTd_BloodRhesusID = ?
|
|
AND Bb_BloodRequestOrderHeaderIsActive = 'Y'
|
|
JOIN bb_bloodrequest_orderdetail ON Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = Bb_BloodRequestOrderHeaderID
|
|
AND Bb_BloodRequestOrderDetailTd_BloodCategoryID = ?
|
|
AND Bb_BloodRequestOrderDetailIsActive = 'Y'
|
|
AND Bb_BloodRequestOrderDetailCountAlreadyCrossmatch < Bb_BloodRequestOrderDetailAmountBag
|
|
AND Bb_BloodRequestOrderDetailCountAlreadyDistributed < Bb_BloodRequestOrderDetailAmountBag
|
|
WHERE
|
|
M_PatientIsActive = 'Y' AND
|
|
( M_PatientName LIKE ? OR Bb_BloodRequestOrderHeaderReqNumber LIKE ? ) AND
|
|
( Bb_BloodRequestOrderDetailAmountBag - Bb_BloodRequestOrderDetailCountAlreadyCrossmatch ) > (
|
|
SELECT COUNT(*)
|
|
FROM bb_bloodentry
|
|
WHERE
|
|
Bb_BloodEntryBb_BloodRequestOrderDetailID = Bb_BloodRequestOrderDetailID AND
|
|
Bb_BloodEntryIsActive = 'Y' AND Bb_BloodEntryIsAlreadyCrossmatch = 'N'
|
|
|
|
)
|
|
|
|
GROUP BY Bb_BloodRequestOrderDetailID
|
|
";
|
|
$query = $this->db_bloodbank->query($sql, array(
|
|
$prm['selected_bloodtype']['id'],
|
|
$prm['selected_rhesus']['id'],
|
|
$prm['selected_bloodcategory']['id'],
|
|
$q['search'],
|
|
$q['search']
|
|
));
|
|
//echo $this->db_bloodbank->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_bloodbank->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("search patient rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_warehouse(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'N'
|
|
ORDER BY WarehouseName ASC
|
|
";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_bloodbank->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehouse rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_from_warehouse_form(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
JOIN stock ON StockWarehouseID = WarehouseID
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalToWarehouseID = StockWarehouseID AND MutasiRequestInternalIsActive = 'Y'
|
|
JOIN mutasirequestinternaldetail ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID AND
|
|
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y' AND
|
|
StockItemID = MutasiRequestInternalDetailItemID
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'Y'
|
|
GROUP BY WarehouseID
|
|
ORDER BY WarehouseName ASC
|
|
";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
//echo $this->db_bloodbank->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_bloodbank->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehouse rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_to_warehouse_form(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT WarehouseID as id, WarehouseName as name
|
|
FROM warehouse
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalWarehouseID = WarehouseID AND MutasiRequestInternalIsActive = 'Y'
|
|
JOIN mutasirequestinternaldetail ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID AND
|
|
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y'
|
|
WHERE
|
|
WarehouseIsActive = 'Y' AND WarehouseIsOffice = 'N'
|
|
GROUP BY WarehouseID
|
|
ORDER BY WarehouseName ASC
|
|
";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_bloodbank->last_query();
|
|
$result = array( "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("warehouse rows",$this->db_bloodbank);
|
|
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']);
|
|
}
|
|
|
|
$bagnumber = '';
|
|
if (isset($prm['bagnumber'])) {
|
|
$bagnumber = trim($prm['bagnumber']);
|
|
}
|
|
|
|
|
|
$this->db_bloodbank->trans_start();
|
|
$this->db_bloodbank->trans_strict(FALSE);
|
|
|
|
if($bagnumber == ''){
|
|
$sql = "SELECT `fn_numbering`('BAG') as numbering";
|
|
$qry = $this->db_bloodbank->query($sql);
|
|
if($qry){
|
|
$bagnumber = $qry->row()->numbering;
|
|
}
|
|
else{
|
|
$this->sys_error_db("get numbering error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
$last_id = 0;
|
|
$now = new DateTime();
|
|
|
|
$param_insert = array(
|
|
'Bb_BloodEntryBagNumber' => $prm['bagnumber'] ,
|
|
'Bb_BloodEntryBagNumberBarcode' => $bagnumber ,
|
|
'Bb_BloodEntryTd_BloodTypeID' => $prm['bloodtype_id'],
|
|
'Bb_BloodEntryTd_BloodRhesusID' => $prm['rhesus_id'],
|
|
'Bb_BloodEntryTd_BloodCategoryID' => $prm['category_id'],
|
|
'Bb_BloodEntryAftapDate' => $prm['aftap_date'],
|
|
'Bb_BloodEntryAftapTime' => $prm['aftap_time'],
|
|
'Bb_BloodEntryExpiredDate' => $prm['expired_date'],
|
|
'Bb_BloodEntryEntryDate' => $prm['entry_date'],
|
|
'Bb_BloodEntryEntryTime' => $prm['entry_time'],
|
|
'Bb_BloodEntryTd_SourceID' => $prm['source_id'],
|
|
'Bb_BloodEntryIsRequest' => $prm['already_requested']?'Y':'N',
|
|
'Bb_BloodEntryReqNumber' => $prm['request_number'],
|
|
'Bb_BloodEntryBb_BloodRequestOrderDetailID' => $prm['orderdetail_id'],
|
|
'Bb_BloodEntryIsAlreadyCrossmatch' => $prm['already_crossmatched']?'Y':'N',
|
|
'Bb_BloodEntryIsExternal' => $prm['already_crossmatched']?'Y':'N',
|
|
'Bb_BloodEntryUserID' => $userid,
|
|
'Bb_BloodEntryLastUpdate' => date("Y-m-d H:i:s"),
|
|
'Bb_BloodEntryCreated' => date("Y-m-d H:i:s")
|
|
);
|
|
|
|
$qry = $this->db_bloodbank->insert('bb_bloodentry', $param_insert);
|
|
$last_id = 0;
|
|
if($qry){
|
|
$last_id = $this->db_bloodbank->insert_id();
|
|
$sql = "SELECT *
|
|
FROM `bb_bloodentry`
|
|
WHERE
|
|
Bb_BloodEntryID = ?";
|
|
$qry = $this->db_bloodbank->query($sql, array($last_id));
|
|
//echo $this->db_bloodbank->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("select supplier error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
$row_after = $qry->row_array();
|
|
$data_log_after = json_encode($row_after);
|
|
$sql = "INSERT INTO bb_bloodentry_log (
|
|
Bb_BloodEntryLogBb_BloodEntryID,
|
|
Bb_BloodEntryLogStatus,
|
|
Bb_BloodEntryLogJSONBefore,
|
|
Bb_BloodEntryLogJSONAfter,
|
|
Bb_BloodEntryLogUserID,
|
|
Bb_BloodEntryLogCreated
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,NOW()
|
|
)";
|
|
$qry = $this->db_bloodbank->query($sql, array($last_id,'ADD',NULL,json_encode($data_log_after),$userid));
|
|
if(!$qry){
|
|
$this->sys_error_db("insert log error", $this->db_inventory_log->last_query());
|
|
exit;
|
|
}
|
|
|
|
if(intval($prm['orderdetail_id']) > 0 && $prm['already_crossmatched']){
|
|
$sql = "UPDATE bb_bloodrequest_orderdetail SET
|
|
Bb_BloodRequestOrderDetailCountAlreadyCrossmatch = Bb_BloodRequestOrderDetailCountAlreadyCrossmatch + 1
|
|
WHERE
|
|
Bb_BloodRequestOrderDetailID = ?";
|
|
$qry = $this->db_bloodbank->query($sql,array(
|
|
$prm['orderdetail_id']
|
|
));
|
|
//echo $this->db_bloodbank->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("update CountAlreadyCrossmatch error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("save mutasi error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
|
|
$id = $last_id;
|
|
$sql = "SELECT *
|
|
FROM bb_stock
|
|
WHERE
|
|
Bb_StockTd_BloodTypeID = ? AND
|
|
Bb_StockTd_BloodCategoryID = ? AND
|
|
Bb_StockStatus = ? AND
|
|
Bb_StockTd_BloodRhesusID = ? AND
|
|
Bb_StockBb_AlmariID = ? AND
|
|
Bb_StockBB_RackID = ?
|
|
LIMIT 1";
|
|
$qry = $this->db_bloodbank->query($sql, array(
|
|
$prm['bloodtype_id'],
|
|
$prm['category_id'],
|
|
$prm['already_requested']?'Y':'N',
|
|
$prm['rhesus_id'],
|
|
$prm['almari_id'],
|
|
$prm['rack_id']
|
|
));
|
|
//echo $this->db_bloodbank->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("get data stock error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
|
|
$data_stock = $qry->row_array();
|
|
$stock_id = 0;
|
|
$last_amount_stock = 0;
|
|
if($data_stock && count($data_stock) > 0){
|
|
$stock_id = $data_stock['Bb_StockID'];
|
|
$last_amount_stock = $data_stock['Bb_StockAmount'];
|
|
$sql = "UPDATE bb_stock SET
|
|
Bb_StockAmount = Bb_StockAmount + 1,
|
|
Bb_StockLastUpdate = NOW(),
|
|
Bb_StockUserID = ?
|
|
WHERE
|
|
Bb_StockID = ?";
|
|
$qry = $this->db_bloodbank->query($sql, array(
|
|
$userid,
|
|
$data_stock['Bb_StockID']
|
|
));
|
|
if(!$qry){
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("get data stock error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
}else{
|
|
$param_stock_insert = array(
|
|
'Bb_StockTd_BloodTypeID' => $prm['bloodtype_id'],
|
|
'Bb_StockTd_BloodCategoryID' => $prm['category_id'],
|
|
'Bb_StockStatus' => $prm['already_requested']?'Y':'N',
|
|
'Bb_StockAmount' => 1,
|
|
'Bb_StockTd_BloodRhesusID' => $prm['rhesus_id'],
|
|
'Bb_StockBb_AlmariID' => $prm['almari_id'],
|
|
'Bb_StockBb_RackID' => $prm['rack_id'],
|
|
'Bb_StockLastUpdate' => date("Y-m-d H:i:s"),
|
|
'Bb_StockUserID' => $userid
|
|
);
|
|
$qry = $this->db_bloodbank->insert('bb_stock', $param_stock_insert);
|
|
if(!$qry){
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("insert data stock error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
$stock_id = $this->db_bloodbank->insert_id();
|
|
}
|
|
|
|
$param_insert_stock_detail = array(
|
|
'Bb_StockDetailBb_BloodEntryID' => $last_id,
|
|
'Bb_StockDetailBb_StockID' => $stock_id,
|
|
'Bb_StockDetailLastUpdate' => date("Y-m-d H:i:s"),
|
|
'Bb_StockDetailCreated' => date("Y-m-d H:i:s"),
|
|
'Bb_StockDetailUserID' => $userid
|
|
);
|
|
|
|
$qry = $this->db_bloodbank->insert('bb_stockdetail', $param_insert_stock_detail);
|
|
if(!$qry){
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("insert data stock detail error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
|
|
$param_insert_stock_log = array(
|
|
'Bb_StockLogTd_BloodTypeID' => $prm['bloodtype_id'],
|
|
'Bb_StockLogBb_BloodSourceID' => $prm['source_id'],
|
|
'Bb_StockLogTd_BloodCategoryID' => $prm['category_id'],
|
|
'Bb_StockLogTransactionType' => 'bloodentry',
|
|
'Bb_StockLogTransactionID' => $last_id,
|
|
'Bb_StockLogStatus' => $prm['already_requested']?'Y':'N',
|
|
'Bb_StockLogAmount' => 1,
|
|
'Bb_StockLogLastAmount' => $last_amount_stock,
|
|
'Bb_StockLogDate' => $prm['entry_date'],
|
|
'Bb_StockLogTime' => $prm['entry_time'],
|
|
'Bb_StockLogAftapDate' => $prm['aftap_date'],
|
|
'Bb_StockLogAftapTime' => $prm['aftap_time'],
|
|
'Bb_StockLogExpiredDate' => $prm['expired_date'],
|
|
'Bb_StockLogTd_BloodRhesusID' => $prm['rhesus_id'],
|
|
'Bb_StockLogBb_AlmariID' => $prm['almari_id'],
|
|
'Bb_StockLogBb_RackID' => $prm['rack_id'],
|
|
'Bb_StockLogLastUpdate' => date("Y-m-d H:i:s"),
|
|
'Bb_StockLogCreated' => date("Y-m-d H:i:s"),
|
|
'Bb_StockLogUserID' => $userid
|
|
);
|
|
|
|
$qry = $this->db_bloodbank->insert('bb_stocklog', $param_insert_stock_log);
|
|
//echo $this->db_bloodbank->last_query();
|
|
if(!$qry){
|
|
//echo $this->db_bloodbank->last_query();
|
|
$this->sys_error_db("insert data stock detail error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
|
|
$this->db_bloodbank->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 get_data_company_default(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT CompanyID as id,
|
|
CompanyName as name,
|
|
'' as address
|
|
FROM company
|
|
JOIN one_aditya.m_branch ON CompanyM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y'
|
|
WHERE
|
|
CompanyIsActive = 'Y' LIMIT 1";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$row = $query->row_array();
|
|
|
|
$sql = "SELECT CompanyAddressID as id,
|
|
CompanyAddressLabel as name,
|
|
CompanyAddressDescription as description
|
|
FROM companyaddress
|
|
WHERE
|
|
CompanyAddressCompanyID = ? AND CompanyAddressIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->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_bloodbank);
|
|
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_bloodbank->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_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_source(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_SourceID as id,
|
|
Td_SourceName as name,
|
|
Td_SourceIsPMI as is_pmi
|
|
FROM td_source
|
|
WHERE
|
|
Td_SourceIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("source rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_bloodtype(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_BloodTypeID as id,
|
|
Td_BloodTypeName as name
|
|
FROM td_bloodtype
|
|
WHERE
|
|
Td_BloodTypeIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("source rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_rhesus(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_BloodRhesusID as id,
|
|
Td_BloodRhesusCode as code,
|
|
Td_BloodRhesusName as name
|
|
FROM td_bloodrhesus
|
|
WHERE
|
|
Td_BloodRhesusIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("source rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_bloodcategory(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Td_BloodCategoryID as id,
|
|
Td_BloodCategoryName as name
|
|
FROM td_bloodcategory
|
|
WHERE
|
|
Td_BloodCategoryIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("source rows",$this->db_bloodbank);
|
|
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
|
|
FROM companyaddress
|
|
JOIN mutasirequestreceive ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID AND
|
|
MutasiRequestReceiveIsActive = 'Y' AND
|
|
( MutasiRequestReceiveStatus <> 'N' AND MutasiRequestReceiveStatus <> 'D' )
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
WHERE
|
|
CompanyAddressIsActive = 'Y'
|
|
GROUP BY CompanyAddressID";
|
|
$query = $this->db_bloodbank->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_bloodbank);
|
|
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['warehouse_id'];
|
|
$sql = "SELECT MutasiRequestInternalDetailID as request_receive_id,
|
|
MutasiRequestInternalNumber as request_number,
|
|
WarehouseName as warehouse_name,
|
|
ItemID as item_id,
|
|
ItemUnitID as unit_id,
|
|
MutasiRequestInternalDetailQty-MutasiRequestInternalDetailReceiveQty as qty_request_rest,
|
|
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 mutasirequestinternaldetail
|
|
JOIN mutasirequestinternal ON MutasiRequestInternalDetailMutasiRequestInternalID = MutasiRequestInternalID
|
|
JOIN warehouse ON MutasiRequestInternalToWarehouseID = WarehouseID
|
|
JOIN item ON MutasiRequestInternalDetailItemID = ItemID
|
|
JOIN itemunit ON MutasiRequestInternalDetailUnitID = ItemUnitID
|
|
LEFT JOIN stock ON StockItemID = ItemID AND StockItemUnitID = ItemUnitID
|
|
WHERE
|
|
MutasiRequestInternalDetailStatus NOT IN('N','D','C') AND MutasiRequestInternalDetailIsActive = 'Y' AND
|
|
MutasiRequestInternalWarehouseID = ? AND
|
|
( MutasiRequestInternalDetailQty - MutasiRequestInternalDetailReceiveQty ) > 0
|
|
GROUP BY MutasiRequestInternalDetailID";
|
|
$query = $this->db_bloodbank->query($sql,array($id));
|
|
//echo $this->db_bloodbank->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_bloodbank);
|
|
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_bloodbank->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_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_almari(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Bb_AlmariID as id,
|
|
Bb_AlmariCode as code,
|
|
Bb_AlmariName as name
|
|
FROM bb_almari
|
|
WHERE
|
|
Bb_almariIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("source rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_rack(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Bb_RackID as id,
|
|
Bb_RackCode as code,
|
|
Bb_RackName as name
|
|
FROM bb_rack
|
|
WHERE
|
|
Bb_RackIsActive = 'Y'";
|
|
$query = $this->db_bloodbank->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("source rows",$this->db_bloodbank);
|
|
exit;
|
|
}
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|