1090 lines
43 KiB
PHP
1090 lines
43 KiB
PHP
<?php
|
|
class Bloodrequest 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'])) {
|
|
foreach ($prm['status'] as $k_status => $v_status) {
|
|
if($v_status == 'N'){
|
|
if($filter_status != '')
|
|
$filter_status .= " OR ";
|
|
|
|
$filter_status .= "( Bb_BloodRequestOrderDetailCountAlreadyCrossmatch = 0 AND Bb_BloodRequestOrderDetailCountAlreadyDistributed = 0)";
|
|
}
|
|
|
|
if($v_status == 'C'){
|
|
if($filter_status != '')
|
|
$filter_status .= " OR ";
|
|
|
|
$filter_status .= "( Bb_BloodRequestOrderDetailCountAlreadyCrossmatch > 0 )";
|
|
}
|
|
|
|
if($v_status == 'D'){
|
|
if($filter_status != '')
|
|
$filter_status .= " OR ";
|
|
|
|
$filter_status .= "( Bb_BloodRequestOrderDetailCountAlreadyDistributed > 0 )";
|
|
}
|
|
}
|
|
|
|
if($filter_status != '')
|
|
$filter_status = " AND ".$filter_status;
|
|
}
|
|
|
|
$order_by = "Bb_BloodRequestOrderHeaderReqNumber";
|
|
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_BloodRequestOrderHeaderID as id
|
|
FROM bb_bloodrequest_orderheader
|
|
JOIN td_bloodtype ON Bb_BloodRequestOrderHeaderTd_BloodTypeID = Td_BloodTypeID
|
|
JOIN td_bloodrhesus ON Bb_BloodRequestOrderHeaderTd_BloodRhesusID = Td_BloodRhesusID
|
|
JOIN bb_bloodrequest_orderdetail ON Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = Bb_BloodRequestOrderHeaderID AND
|
|
Bb_BloodRequestOrderDetailIsActive = 'Y' $filter_status
|
|
WHERE
|
|
Bb_BloodRequestOrderHeaderIsActive = 'Y' AND
|
|
(
|
|
DATE(Bb_BloodRequestOrderHeaderRequestDate) BETWEEN ? AND ?
|
|
) AND
|
|
(
|
|
Bb_BloodRequestOrderHeaderM_PatientName LIKE ? OR
|
|
Bb_BloodRequestOrderHeadeM_PatientMR LIKE ?
|
|
)
|
|
) 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_BloodRequestOrderHeaderID as id,
|
|
Bb_BloodRequestOrderHeaderRequestDate as request_date,
|
|
Bb_BloodRequestOrderHeaderReqNumber as request_number,
|
|
Bb_BloodRequestOrderHeaderM_PatientID as patient_id,
|
|
Bb_BloodRequestOrderHeaderM_PatientName as patient_name,
|
|
Bb_BloodRequestOrderHeaderM_PatientNoReg as patient_noreg,
|
|
Bb_BloodRequestOrderHeaderTd_BloodTypeID as bloodtype_id,
|
|
Td_BloodTypeName as bloodtype_name,
|
|
Bb_BloodRequestOrderHeaderTd_BloodRhesusID as rhesus_id,
|
|
Td_BloodRhesusCode as rhesus_name,
|
|
Bb_BloodRequestOrderHeaderDateNeeded as date_needed,
|
|
Bb_BloodRequestOrderHeaderRoom as room,
|
|
Bb_BloodRequestOrderHeaderDoctor as doctor,
|
|
Bb_BloodRequestOrderHeaderTypePatient as typepatient,
|
|
Bb_BloodRequestOrderHeaderDiagnosa as diagnosa,
|
|
Bb_BloodRequestOrderHeaderReason as reason,
|
|
Bb_BloodRequestOrderHeaderOfficerRequestName as request_by,
|
|
Bb_BloodRequestOrderHeaderUserRequestOfficerSamplingDatetime as sampling_time,
|
|
Bb_BloodRequestOrderHeaderUserRequestOfficerSamplingName as sampling_by,
|
|
Bb_BloodRequestOrderHeaderHemoglobin as hemoglobin,
|
|
Bb_BloodRequestOrderHeaderTrombosite as trombosit,
|
|
'' as details
|
|
FROM bb_bloodrequest_orderheader
|
|
JOIN td_bloodtype ON Bb_BloodRequestOrderHeaderTd_BloodTypeID = Td_BloodTypeID
|
|
JOIN td_bloodrhesus ON Bb_BloodRequestOrderHeaderTd_BloodRhesusID = Td_BloodRhesusID
|
|
JOIN bb_bloodrequest_orderdetail ON Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = Bb_BloodRequestOrderHeaderID AND
|
|
Bb_BloodRequestOrderDetailIsActive = 'Y' $filter_status
|
|
WHERE
|
|
Bb_BloodRequestOrderHeaderIsActive = 'Y' AND
|
|
(
|
|
DATE(Bb_BloodRequestOrderHeaderRequestDate) BETWEEN ? AND ?
|
|
) AND
|
|
(
|
|
Bb_BloodRequestOrderHeaderM_PatientName LIKE ? OR
|
|
Bb_BloodRequestOrderHeadeM_PatientMR LIKE ?
|
|
)
|
|
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();
|
|
foreach ($rows as $key => $value) {
|
|
$sql = "SELECT Bb_BloodRequestOrderDetailID as id,
|
|
Bb_BloodRequestOrderDetailTd_BloodCategoryID as category_id,
|
|
Td_BloodCategoryName as category_name,
|
|
Bb_BloodRequestOrderDetailAmountBag as amount_request_bag,
|
|
Bb_BloodRequestOrderDetailCountAlreadyCrossmatch as amount_crossmatched_bag,
|
|
Bb_BloodRequestOrderDetailCountAlreadyDistributed as amount_distributed_bag
|
|
FROM bb_bloodrequest_orderdetail
|
|
JOIN td_bloodcategory ON Bb_BloodRequestOrderDetailTd_BloodCategoryID = Td_BloodCategoryID
|
|
WHERE
|
|
Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = ? AND
|
|
Bb_BloodRequestOrderDetailIsActive = 'Y'";
|
|
$qry = $this->db_bloodbank->query($sql, array($value['id']));
|
|
if(!$qry){
|
|
$this->sys_error_db("get detail error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
$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;
|
|
|
|
if($prm['search'] != ''){
|
|
$prm['search'] = explode('(',$prm['search']);
|
|
$prm['search'] = trim($prm['search'][0]);
|
|
}
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
$sql = "SELECT M_PatientID as id,
|
|
M_PatientName as name,
|
|
M_PatientNoReg as noreg,
|
|
IFNULL(M_PatientMR,'-') as mr,
|
|
CONCAT(M_PatientName,' ( ',IFNULL(M_PatientMR,'-'),' )') as label
|
|
FROM $this->db_onex.m_patient
|
|
WHERE
|
|
M_PatientIsActive = 'Y' AND
|
|
( M_PatientName LIKE ? OR M_PatientMR LIKE ? )
|
|
LIMIT 50
|
|
";
|
|
$query = $this->db_bloodbank->query($sql, array(
|
|
$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, "search" => $prm['search'] );
|
|
$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;
|
|
|
|
$diagnose = "";
|
|
if (isset($prm['diagnose'])) {
|
|
$diagnose = trim($prm['diagnose']);
|
|
}
|
|
|
|
$doctor = '';
|
|
if (isset($prm['doctor'])) {
|
|
$doctor = trim($prm['doctor']);
|
|
}
|
|
|
|
$patienttype = '';
|
|
if (isset($prm['patienttype'])) {
|
|
$patienttype = trim($prm['patienttype']);
|
|
}
|
|
|
|
$hemoglobin = '';
|
|
if (isset($prm['hemoglobin'])) {
|
|
$hemoglobin = trim($prm['hemoglobin']);
|
|
}
|
|
|
|
$reason = '';
|
|
if (isset($prm['reason'])) {
|
|
$reason = trim($prm['reason']);
|
|
}
|
|
|
|
$requestedby = '';
|
|
if (isset($prm['requestedby'])) {
|
|
$requestedby = trim($prm['requestedby']);
|
|
}
|
|
|
|
$room = '';
|
|
if (isset($prm['room'])) {
|
|
$room = trim($prm['room']);
|
|
}
|
|
|
|
$samplingby = '';
|
|
if (isset($prm['samplingby'])) {
|
|
$samplingby = trim($prm['samplingby']);
|
|
}
|
|
|
|
|
|
$this->db_bloodbank->trans_start();
|
|
$this->db_bloodbank->trans_strict(FALSE);
|
|
|
|
$reqnumber = '';
|
|
$sql = "SELECT `fn_numbering`('REQ') as numbering";
|
|
$qry = $this->db_bloodbank->query($sql);
|
|
if($qry){
|
|
$reqnumber = $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_BloodRequestOrderHeaderReqNumber' => $reqnumber ,
|
|
'Bb_BloodRequestOrderHeaderM_PatientID' => $prm['patient']['id'],
|
|
'Bb_BloodRequestOrderHeaderM_PatientName' => $prm['patient']['name'],
|
|
'Bb_BloodRequestOrderHeaderM_PatientNoReg' => $prm['patient']['noreg'],
|
|
'Bb_BloodRequestOrderHeadeM_PatientMR' => $prm['patient']['mr'],
|
|
'Bb_BloodRequestOrderHeaderTd_BloodTypeID' => $prm['bloodtype']['id'],
|
|
'Bb_BloodRequestOrderHeaderTd_BloodRhesusID' => $prm['bloodrhesus']['id'],
|
|
'Bb_BloodRequestOrderHeaderDateNeeded' => $prm['bloodneeded_date'],
|
|
'Bb_BloodRequestOrderHeaderRoom' => $room,
|
|
'Bb_BloodRequestOrderHeaderDoctor' => $doctor,
|
|
'Bb_BloodRequestOrderHeaderTypePatient' => $patienttype,
|
|
'Bb_BloodRequestOrderHeaderDiagnosa' => $diagnose,
|
|
'Bb_BloodRequestOrderHeaderReason' => $reason,
|
|
'Bb_BloodRequestOrderHeaderOfficerRequestName' => $requestedby,
|
|
'Bb_BloodRequestOrderHeaderHemoglobin' => $hemoglobin,
|
|
'Bb_BloodRequestOrderHeaderTrombosite' => $trombosite,
|
|
'Bb_BloodRequestOrderHeaderUserRequestDateTime' => $prm['request_date'],
|
|
'Bb_BloodRequestOrderHeaderUserRequestOfficerSamplingDatetime' => $prm['sampling_date'],
|
|
'Bb_BloodRequestOrderHeaderUserRequestOfficerSamplingName' => $prm['samplingby'],
|
|
'Bb_BloodRequestOrderHeaderUserID' => $userid,
|
|
'Bb_BloodRequestOrderHeaderLastUpdate' => date("Y-m-d H:i:s"),
|
|
'Bb_BloodRequestOrderHeaderCreated' => date("Y-m-d H:i:s")
|
|
);
|
|
|
|
$qry = $this->db_bloodbank->insert('bb_bloodrequest_orderheader', $param_insert);
|
|
//echo $this->db_bloodbank->last_query();
|
|
$last_id = 0;
|
|
if($qry){
|
|
$last_id = $this->db_bloodbank->insert_id();
|
|
|
|
if(count($prm['categories']) > 0){
|
|
$categories = $prm['categories'];
|
|
foreach ($categories as $key => $value) {
|
|
$param_insert_detail = array(
|
|
'Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID' => $last_id,
|
|
'Bb_BloodRequestOrderDetailTd_BloodCategoryID' => $value['id'],
|
|
'Bb_BloodRequestOrderDetailAmountBag' => $value['value'],
|
|
'Bb_BloodRequestOrderDetailCreated' => date("Y-m-d H:i:s"),
|
|
'Bb_BloodRequestOrderDetailLastUpdate' => date("Y-m-d H:i:s"),
|
|
'Bb_BloodRequestOrderDetailUserID' => $userid
|
|
);
|
|
$qry = $this->db_bloodbank->insert('bb_bloodrequest_orderdetail', $param_insert_detail);
|
|
//echo $this->db_bloodbank->last_query();
|
|
if(!$qry){
|
|
$this->sys_error_db("insert bb_bloodrequest_orderdetail error", $this->db_bloodbank->last_query());
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT bb_bloodrequest_orderheader.*, '' as details
|
|
FROM `bb_bloodrequest_orderheader`
|
|
WHERE
|
|
Bb_BloodRequestOrderHeaderID = ?";
|
|
$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();
|
|
if($row_after){
|
|
$sql = "SELECT * as details
|
|
FROM `bb_bloodrequest_orderdetail`
|
|
WHERE
|
|
Bb_BloodRequestOrderDetailBb_BloodRequestOrderHeaderID = ?";
|
|
$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['details'] = $qry->result_array();
|
|
}
|
|
|
|
$data_log_after = json_encode($row_after);
|
|
$sql = "INSERT INTO bb_bloodrequest_log (
|
|
Bb_BloodRequestLogBb_BloodRequestOrderHeaderID,
|
|
Bb_BloodRequestLogStatus,
|
|
Bb_BloodRequestLogJSONBefore,
|
|
Bb_BloodRequestLogJsonAfter,
|
|
Bb_BloodRequestLogUserID,
|
|
Bb_BloodRequestLogCreated
|
|
)
|
|
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 bb_bloodrequest_orderheader 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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|