Initial import
This commit is contained in:
@@ -0,0 +1,399 @@
|
||||
<?php
|
||||
class Courierassigment extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "SampleStorage API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$xdate = $prm["xdate"];
|
||||
$kecamatan = $prm["kecamatan"];
|
||||
$filter_kecamatan = '';
|
||||
if(!empty($kecamatan)){
|
||||
$filter_kecamatan = " AND M_DistrictID = {$kecamatan['id']}";
|
||||
}
|
||||
|
||||
$sql_where = "WHERE T_OrderPromiseDateTime < '{$xdate}' AND T_OrderDeliveryM_DeliveryTypeID = 2 AND T_OrderDeliveryIsActive = 'Y' {$filter_kecamatan}";
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND
|
||||
T_OrderPromiseDateTime < '{$prm['xdate']}'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT T_OrderDeliveryID as xid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname,
|
||||
T_OrderDeliveryDestination as xaddress,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
M_KelurahanName as kelurahan
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND
|
||||
T_OrderPromiseDateTime < '{$prm['xdate']} 23:59:59'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
$sql_where
|
||||
ORDER BY T_OrderPromiseDateTime ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function searchall()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$xdate = $prm["xdate"];
|
||||
$kecamatan = $prm["kecamatan"];
|
||||
$filter_kecamatan = '';
|
||||
if(!empty($kecamatan)){
|
||||
$filter_kecamatan = " AND M_DistrictID = {$kecamatan['id']}";
|
||||
}
|
||||
|
||||
$sql_where = "WHERE T_OrderPromiseDateTime < '{$xdate}' AND T_OrderDeliveryM_DeliveryTypeID = 2 AND T_OrderDeliveryIsActive = 'Y' {$filter_kecamatan}";
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND
|
||||
T_OrderPromiseDateTime < '{$prm['xdate']}'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT T_OrderDeliveryID as xid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname,
|
||||
T_OrderDeliveryDestination as xaddress,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
M_KelurahanName as kelurahan
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND
|
||||
T_OrderPromiseDateTime < '{$prm['xdate']} 23:59:59'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
$sql_where
|
||||
ORDER BY T_OrderPromiseDateTime ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function getdatasform(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_CourierID as id, M_StaffName as name
|
||||
FROM m_courier
|
||||
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
|
||||
WHERE
|
||||
M_CourierIsActive = 'Y'
|
||||
";
|
||||
|
||||
$rows['couriers'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function getdatakecamatan(){
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_DistrictID as id, M_DistrictName as name
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND
|
||||
T_OrderPromiseDateTime < '{$prm['xdate']}'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
WHERE
|
||||
T_OrderDeliveryM_DeliveryID = 2 AND T_OrderDeliveryIsActive = 'Y'
|
||||
GROUP BY M_DistrictID
|
||||
";
|
||||
// echo $query;
|
||||
$rows['kecamatans'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getracks(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$rows = [];
|
||||
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
|
||||
FROM summary_samplestorage
|
||||
WHERE
|
||||
Summary_SampleStorageStatus = 'FILLED'
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['id']} as almariid,
|
||||
M_RackID as id,
|
||||
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
|
||||
M_RackCode as code,
|
||||
M_RackRows as row,
|
||||
M_RackColumns as col,
|
||||
'' as rackcontens
|
||||
FROM m_rack
|
||||
WHERE
|
||||
M_RackM_AlmariID = {$prm['id']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->result_array();
|
||||
foreach($datarows as $k => $v){
|
||||
$rows = $v['row'];
|
||||
$cols = $v['col'];
|
||||
$rackcontens = array();
|
||||
for ($x = 1; $x <= $rows; $x++) {
|
||||
$children = array();
|
||||
for ($i = 1; $i <= $cols; $i++) {
|
||||
$content = $x.' x '.$i;
|
||||
$xrow = $x;
|
||||
$xcol = $i;
|
||||
$status = $this->checkexistfilled($filledrows, $v['id'],$xrow,$xcol);
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>'N'));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
$datarows[$k]['rackcontens'] = $rackcontens;
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($datarows) ,
|
||||
"records" => $datarows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkexistfilled($datas,$rackid,$row,$col){
|
||||
$rtn = 'N';
|
||||
foreach($datas as $k => $v){
|
||||
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
|
||||
$rtn = 'Y';
|
||||
}
|
||||
}
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
function save(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$numbering = $this->db_onedev->query("SELECT fn_numbering('SS') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestorage (
|
||||
T_SampleStorageNumbering,
|
||||
T_SampleStorageDate,
|
||||
T_SampleStorageTime,
|
||||
T_SampleStorageNote,
|
||||
T_SampleStorageUserID,
|
||||
T_SampleStorageCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['time']}',
|
||||
'{$prm['note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
if($saveheader){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestorage_detail (
|
||||
T_SampleStorageDetailT_SampleStorageID,
|
||||
T_SampleStorageDetailT_OrderSampleID,
|
||||
T_SampleStorageDetailBarcode,
|
||||
T_SampleStorageDetailM_AlmariID,
|
||||
T_SampleStorageDetailM_RackID,
|
||||
T_SampleStorageDetailRowPosition,
|
||||
T_SampleStorageDetailColumnPosition,
|
||||
T_SampleStorageDetailUserID,
|
||||
T_SampleStorageDetailCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['ordersampleid']}',
|
||||
'{$v['barcode']}',
|
||||
'{$v['almari']['id']}',
|
||||
'{$v['rack']['id']}',
|
||||
'{$v['row']}',
|
||||
'{$v['col']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetail = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_samplestorage WHERE T_SampleStorageID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestorage_detail WHERE T_SampleStorageDetailT_SampleStorageID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CREATED.SAVE',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK'),
|
||||
"numbering" => $numbering,
|
||||
"id" => $last_id
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function checkbarcode(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$datarows = [];
|
||||
$query =" SELECT CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, T_OrderSampleID
|
||||
FROM t_ordersample
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
WHERE T_OrderSampleBarcode = '{$prm['barcode']}' AND T_OrderSampleIsActive = 'Y' ORDER BY T_OrderSampleID DESC LIMIT 1
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row();
|
||||
|
||||
$result = array(
|
||||
"total" => count($datarows) ,
|
||||
"records" => $datarows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,666 @@
|
||||
<?php
|
||||
class Courierspk extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "COurierSpk API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$start_date = $prm["startdate"];
|
||||
$end_date = $prm["enddate"];
|
||||
$status = $prm['status'];
|
||||
$prm['current_page'] = isset($prm['current_page'])?$prm['current_page']:1;
|
||||
|
||||
$sql_where = "WHERE (Result_CourierSPKDate BETWEEN CONCAT(?,' ','00:00:00') AND CONCAT(?,' ','23:59:59')) AND Result_CourierSPKIsActive = 'Y'";
|
||||
$sql_param = array($start_date,$end_date);
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM result_courierspk
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("m_doctor count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Result_CourierSPKID as id,
|
||||
Result_CourierSPKNumbering as trx_number,
|
||||
CONCAT(DATE_FORMAT(Result_CourierSPKDate,'%d-%m-%Y'),' ',DATE_FORMAT(Result_CourierSPKTime,'%H:%i') ) as trx_datetime,
|
||||
Result_CourierSPKNote as trx_note,
|
||||
M_StaffName as courier_name,
|
||||
M_CourierID as courier_id,
|
||||
DATE_FORMAT(Result_CourierSPKDate,'%d-%m-%Y') as xdate,
|
||||
DATE_FORMAT(Result_CourierSPKTime,'%H:%i') as xtime,
|
||||
'' as details
|
||||
FROM result_courierspk
|
||||
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
|
||||
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
|
||||
$sql_where
|
||||
ORDER BY Result_CourierSPKNumbering ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$query = " SELECT Result_CourierSPKDetailID as trx_id,
|
||||
T_OrderPromiseID as xid,
|
||||
T_OrderDeliveryID as delid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
Result_CourierSPKDetailForceDone as force_done,
|
||||
Result_CourierSPKDetailStatus as status,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(M_TitleName,' ',M_PatientName) as patientname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
M_KelurahanName as kelurahan,
|
||||
T_OrderDeliveryDestination as xaddress,
|
||||
'Y' as flag_checked,
|
||||
'Y' as chex
|
||||
FROM result_courierspk_detail
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryID = Result_CourierSPKDetailT_OrderDeliveryID
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
WHERE Result_CourierSPKDetailResult_CourierSPKID = '{$v['id']}' AND Result_CourierSPKDetailIsActive = 'Y'";
|
||||
//echo $query;
|
||||
$ddata = $this->db_onedev->query($query)->result_array();
|
||||
if($ddata){
|
||||
foreach($ddata as $i => $j){
|
||||
$ddata[$i]['chex'] = false;
|
||||
}
|
||||
}
|
||||
$rows[$k]['details'] = $ddata;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getcourier(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_CourierID as id, M_StaffName as name
|
||||
FROM m_courier
|
||||
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchall()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$xdate = $prm["xdate"];
|
||||
$kecamatan = $prm["kecamatan"];
|
||||
$filter_kecamatan = '';
|
||||
$details = $prm['details'];
|
||||
$deliveries_id = array();
|
||||
$promises_id = array();
|
||||
$join_deliveries = '';
|
||||
$join_promises = '';
|
||||
if($details){
|
||||
foreach($details as $xk => $xv){
|
||||
array_push($deliveries_id,$xv['delid']);
|
||||
array_push($promises_id,$xv['promiseid']);
|
||||
}
|
||||
|
||||
$join_deliveries = "(".join($deliveries_id,',').")";
|
||||
$join_promises = "(".join($promises_id,',').")";
|
||||
}
|
||||
|
||||
$sql_join_deliveries = '';
|
||||
$sql_join_promise = '';
|
||||
|
||||
if($deliveries_id){
|
||||
foreach($deliveries_id as $k => $v){
|
||||
if($sql_join_deliveries != '')
|
||||
$sql_join_deliveries .= ' AND ';
|
||||
|
||||
//$sql_join_deliveries .= ' ( T_OrderDeliveryID <> '.$v.' AND T_OrderPromiseID <> '.$promises_id[$k].' ) ';
|
||||
$sql_join_deliveries .= " ( CONCAT(T_OrderDeliveryID,'-',T_OrderPromiseID) <> '{$v}-{$promises_id[$k]}' ) ";
|
||||
//echo $sql;
|
||||
}
|
||||
$sql_join_deliveries = " AND ({$sql_join_deliveries})";
|
||||
//echo $sql_join_deliveries;
|
||||
}
|
||||
|
||||
if($kecamatan['id'] != '0' || $kecamatan['id'] != 0){
|
||||
$filter_kecamatan = " AND M_DistrictID = {$kecamatan['id']}";
|
||||
}
|
||||
$prm['current_page'] = isset($prm['current_page'])?$prm['current_page']:1;
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql_where = "WHERE ISNULL(Result_CourierSPKDetailID) AND T_OrderPromiseDateTime < '{$xdate} 23:59:59' AND T_OrderDeliveryM_DeliveryTypeID = 2 AND T_OrderDeliveryIsActive = 'Y' {$filter_kecamatan}";
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT * FROM t_orderdelivery
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
LEFT JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
|
||||
Result_CourierSPKDetailIsActive = 'Y' AND
|
||||
Result_CourierSPKDetailForceDone = 'N' AND
|
||||
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
$sql_where $sql_join_deliveries
|
||||
GROUP BY T_OrderDeliveryID,T_OrderPromiseID
|
||||
) x";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("m_doctor count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT IFNULL(Result_CourierSPKDetailID,0) as trx_id,
|
||||
T_OrderPromiseID as xid,
|
||||
T_OrderDeliveryID as delid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname,
|
||||
T_OrderDeliveryDestination as xaddress,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
T_OrderPromiseDateTime,
|
||||
M_KelurahanName as kelurahan,
|
||||
'N' as flag_checked,
|
||||
'N' as chex
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN t_orderpromise ON T_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
LEFT JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
|
||||
Result_CourierSPKDetailIsActive = 'Y' AND
|
||||
Result_CourierSPKDetailForceDone = 'N' AND
|
||||
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
$sql_where $sql_join_deliveries
|
||||
GROUP BY T_OrderDeliveryID,T_OrderPromiseID
|
||||
ORDER BY T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC
|
||||
limit $number_limit offset $number_offset
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$rows[$k]['chex'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getkecamatan(){
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_DistrictID as id, M_DistrictName as name
|
||||
FROM t_orderdelivery
|
||||
JOIN t_orderpromise ON T_OrderDeliveryT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID AND
|
||||
T_OrderPromiseDateTime < '{$prm['xdate']}'
|
||||
JOIN m_kelurahan ON T_OrderDeliveryM_KelurahanID = M_KelurahanID
|
||||
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
||||
WHERE
|
||||
T_OrderDeliveryM_DeliveryID = 2 AND T_OrderDeliveryIsActive = 'Y'
|
||||
GROUP BY M_DistrictID
|
||||
";
|
||||
// echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
array_push($rows,array('id'=>0,'name'=>'Semua Kecamatan'));
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getrackcontent(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$rows = [];
|
||||
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
|
||||
FROM summary_samplestorage
|
||||
WHERE
|
||||
Summary_SampleStorageStatus = 'FILLED' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} as almariid,
|
||||
M_RackID as id,
|
||||
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
|
||||
M_RackCode as code,
|
||||
M_RackRows as row,
|
||||
M_RackColumns as col,
|
||||
'' as rackcontens
|
||||
FROM m_rack
|
||||
WHERE
|
||||
M_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['col'];
|
||||
$rackcontens = array();
|
||||
for ($x = 1; $x <= $rows; $x++) {
|
||||
$children = array();
|
||||
for ($i = 1; $i <= $cols; $i++) {
|
||||
$content = $x.' x '.$i;
|
||||
$xrow = $x;
|
||||
$xcol = $i;
|
||||
$status = $this->checkexistfilled($filledrows, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkexistfilled($datas,$rackid,$row,$col){
|
||||
$rtn = 'N';
|
||||
foreach($datas as $k => $v){
|
||||
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
|
||||
$rtn = 'Y';
|
||||
}
|
||||
}
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
function save(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$last_id = $prm['trx_id'];
|
||||
if($last_id == 0 || $last_id == '0'){
|
||||
$numbering = $this->db_onedev->query("SELECT fn_numbering('DK') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["trx_date"]));
|
||||
|
||||
$query ="INSERT INTO result_courierspk (
|
||||
Result_CourierSPKNumbering,
|
||||
Result_CourierSPKDate,
|
||||
Result_CourierSPKTime,
|
||||
Result_CourierSPKM_CourierID,
|
||||
Result_CourierSPKNote,
|
||||
Result_CourierSPKUserID,
|
||||
Result_CourierSPKCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['trx_time']}',
|
||||
'{$prm['courier']}',
|
||||
'{$prm['trx_note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
}
|
||||
else{
|
||||
$numbering = $this->db_onedev->query("SELECT * FROM result_courierspk WHERE Result_CourierSPKID = {$last_id}")->row()->Result_CourierSPKNumbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["trx_date"]));
|
||||
$query ="UPDATE result_courierspk SET
|
||||
Result_CourierSPKDate = '{$xdate}',
|
||||
Result_CourierSPKTime = '{$prm['trx_time']}',
|
||||
Result_CourierSPKM_CourierID = '{$prm['courier']}',
|
||||
Result_CourierSPKNote = '{$prm['trx_note']}',
|
||||
Result_CourierSPKUserID = {$userid}
|
||||
WHERE
|
||||
Result_CourierSPKID = {$last_id}
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
}
|
||||
|
||||
if($saveheader){
|
||||
//$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailIsActive = 'N' WHERE Result_CourierSPKDetailResult_CourierSPKID = {$last_id}";
|
||||
//$this->db_onedev->query($sql);
|
||||
if($prm['details']){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
if($v['trx_id'] == '0' || $v['trx_id'] == 0){
|
||||
$query ="INSERT INTO result_courierspk_detail (
|
||||
Result_CourierSPKDetailResult_CourierSPKID,
|
||||
Result_CourierSPKDetailT_OrderDeliveryID,
|
||||
Result_CourierSPKDetailT_OrderPromiseID,
|
||||
Result_CourierSPKDetailsUserID,
|
||||
Result_CourierSPKDetailsCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['delid']}',
|
||||
'{$v['xid']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Result_CourierSPKDetailIsActive = 'Y',
|
||||
Result_CourierSPKDetailsUserID = {$userid}";
|
||||
//echo $query;
|
||||
$savedetail = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($prm['deleted_details']){
|
||||
foreach($prm['deleted_details'] as $k => $v){
|
||||
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailIsActive = 'N' WHERE Result_CourierSPKDetailID = {$v['trx_id']}";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM result_courierspk WHERE Result_CourierSPKID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM result_courierspk_detail WHERE Result_CourierSPKDetailResult_CourierSPKID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details));
|
||||
$sql = "INSERT INTO one_log.log_courierspk (
|
||||
Log_CourierSpkJSON,
|
||||
Log_CourierSpkUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK'),
|
||||
"numbering" => $numbering,
|
||||
"id" => $last_id
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function checkbarcode(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$datarows = [];
|
||||
$query =" SELECT CONCAT(M_TitleName,' ',M_PatientName) as patientname, T_OrderSampleID
|
||||
FROM t_ordersample
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
WHERE T_OrderSampleBarcode = '{$prm['barcode']}' AND T_OrderSampleIsActive = 'Y' ORDER BY T_OrderSampleID DESC LIMIT 1
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row();
|
||||
|
||||
$result = array(
|
||||
"total" => count($datarows) ,
|
||||
"records" => $datarows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
/*function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_samplestorage_detail ON T_SampleStorageDetailID = Summary_SampleStorageReffID
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageDetailT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_SampleStorageDetailBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(M_TitleName,' ',M_PatientName) as patientname, T_SampleStorageDetailT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_samplestorage_detail ON T_SampleStorageDetailID = Summary_SampleStorageReffID
|
||||
JOIN t_ordersample ON T_OrderSampleID = T_SampleStorageDetailT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}*/
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
<?php
|
||||
class XCourier extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Email API";
|
||||
/*truncate result_authorization;
|
||||
truncate result_office;
|
||||
truncate result_email;
|
||||
truncate t_orderauthorization;*/
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_join_result_email = '';
|
||||
$sql_having = 'AND status_done = "N"';
|
||||
$sql_where = '';
|
||||
|
||||
|
||||
if($prm['filter_status'] != 'ready'){
|
||||
$sql_having = ' AND status_done = "Y"';
|
||||
}
|
||||
|
||||
if($prm['name'] != ''){
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
|
||||
}
|
||||
|
||||
if($prm['nolab'] != ''){
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
|
||||
}
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
DATE(T_OrderPromiseDateTime) as raw_date_promise,
|
||||
'' as xgroups,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_done(T_OrderHeaderID,T_OrderPromiseID) as status_done,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status,
|
||||
fn_result_handling_color_row(T_OrderPromiseDateTime) as color_row,
|
||||
IFNULL(M_StaffName,'Belum ditentukan') as courier_name,
|
||||
IFNULL(M_StaffID,0) as courier_value
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 2 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
LEFT JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND Result_CourierSPKDetailIsActive = 'Y'
|
||||
LEFT JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
||||
LEFT JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
|
||||
LEFT JOIN m_staff ON M_CourierM_StaffID = M_StaffID
|
||||
$sql_join_result_office
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
HAVING check_ver_status <> 0 $sql_having
|
||||
ORDER BY T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC
|
||||
) xs
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
DATE(T_OrderPromiseDateTime) as raw_date_promise,
|
||||
'' as xgroups,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_done(T_OrderHeaderID,T_OrderPromiseID) as status_done,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status,
|
||||
fn_result_handling_color_row(T_OrderPromiseDateTime) as color_row,
|
||||
IFNULL(M_StaffName,'Belum ditentukan') as courier_name,
|
||||
IFNULL(M_StaffID,0) as courier_value
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 2 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
LEFT JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND Result_CourierSPKDetailIsActive = 'Y'
|
||||
LEFT JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
||||
LEFT JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
|
||||
LEFT JOIN m_staff ON M_CourierM_StaffID = M_StaffID
|
||||
$sql_join_result_office
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
HAVING check_ver_status <> 0 $sql_having
|
||||
ORDER BY T_OrderPromiseDateTime ASC, T_OrderHeaderID ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$sql = "SELECT IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
SUM(T_OrderDetailPrintCount) as print_count,
|
||||
fn_result_handling_get_cout_print_by_type(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as print_type,
|
||||
fn_result_handling_status_button(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status,
|
||||
fn_check_delivery_other_from_fo('{$v['orderid']}','{$v['promiseid']}','{$v['raw_date_promise']}') as fo_authorize
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$v['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$v['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_TestIsNonLab";
|
||||
//echo $sql;
|
||||
|
||||
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$tot_count = 25;
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getstaffs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_StaffID as id, M_StaffName as name
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function doauthorization(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['type'] == 'LAB'){
|
||||
$prm['type'] = '';
|
||||
}
|
||||
$sql = "INSERT INTO result_authorization (
|
||||
Result_AuthorizationDateTime,
|
||||
Result_AuthorizationM_StaffID,
|
||||
Result_AuthorizationT_OrderHeaderID,
|
||||
Result_AuthorizationT_OrderPromiseID,
|
||||
Result_AuthorizationNat_GroupID,
|
||||
Result_AuthorizationT_TestIsNonLab,
|
||||
Result_AuthorizationUserID,
|
||||
Result_AuthorizationCreated
|
||||
)
|
||||
VALUES(
|
||||
NOW(),
|
||||
{$prm['staff']['id']},
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$prm['groupid']},
|
||||
'{$prm['type']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$insert_auth = $this->db_onedev->query($sql);
|
||||
$id_auth = $this->db_onedev->insert_id();
|
||||
if($insert_auth){
|
||||
$sql = "SELECT T_OrderDetailID as id
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsNonLab = '{$prm['type']}'
|
||||
LEFT JOIN t_orderauthorization ON T_OrderAuthorizationT_OrderDetailID = T_OrderDetailID AND T_OrderAuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailPrintCount > 0 AND T_OrderDetailT_OrderHeaderID = {$prm['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
ISNULL(T_OrderAuthorizationID) AND T_OrderDetailIsActive = 'Y'";
|
||||
// echo $sql;
|
||||
$dt_rst_detail = $this->db_onedev->query($sql)->result();
|
||||
foreach($dt_rst_detail as $k => $v){
|
||||
$sql = "INSERT INTO t_orderauthorization (
|
||||
T_OrderAuthorizationT_OrderDetailID,
|
||||
T_OrderAuthorizationResult_AuthorizationID,
|
||||
T_OrderAuthorizationCreated,
|
||||
T_OrderAuthorizationUserID
|
||||
)
|
||||
VALUES(
|
||||
{$v->id},
|
||||
{$id_auth},
|
||||
NOW(),
|
||||
{$userid}
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_orderdelivery WHERE T_OrderDeliveryM_DeliveryTypeID = 2 AND T_OrderDeliveryT_OrderHeaderID = {$prm['orderid']} AND T_OrderDeliveryIsActive = 'Y'";
|
||||
//echo $sql;
|
||||
$xrst_courier = $this->db_onedev->query($sql)->result_array();
|
||||
foreach($xrst_courier as $k => $v){
|
||||
$sql = "INSERT INTO result_courier (
|
||||
Result_CourierT_OrderHeaderID,
|
||||
Result_CourierT_OrderDeliveryID,
|
||||
Result_CourierT_OrderPromiseID,
|
||||
Result_CourierResult_AuthorizationID,
|
||||
Result_CourierIsNonLab,
|
||||
Result_CourierUserID,
|
||||
Result_CourierCreated
|
||||
)
|
||||
VALUES(
|
||||
{$prm['orderid']},
|
||||
{$v['T_OrderDeliveryID']},
|
||||
{$prm['promiseid']},
|
||||
{$id_auth},
|
||||
'{$prm['type']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
//echo $sql;
|
||||
$insert_ro = $this->db_onedev->query($sql);
|
||||
$id_rc = $this->db_onedev->insert_id();
|
||||
|
||||
$sql = "UPDATE result_courierspk_detail SET
|
||||
Result_CourierSPKDetailStatus = 'O'
|
||||
WHERE
|
||||
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND Result_CourierSPKDetailT_OrderPromiseID = {$prm['promiseid']}
|
||||
AND Result_CourierSPKDetailStatus = 'N'
|
||||
AND Result_CourierSPKDetail = 'Y'";
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupnonsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE M_NonSampleName LIKE CONCAT('%',?,'%')) AND M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_NonSampleID as id,
|
||||
M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
ORDER BY M_NonSampleName ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewvendor(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_vendorsample (
|
||||
M_VendorSampleName,
|
||||
M_VendorSampleAddress,
|
||||
M_VendorSampleCreated,
|
||||
M_VendorSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['vendor_name']}',
|
||||
'{$prm['vendor_address']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewitem(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_nonsample (
|
||||
M_NonSampleName,
|
||||
M_NonSampleCreated,
|
||||
M_NonSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['name']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_NonSampleID as id, M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
WHERE
|
||||
M_NonSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
852
one-api/application/controllers/mockup/resulthandling/Xemail.php
Normal file
852
one-api/application/controllers/mockup/resulthandling/Xemail.php
Normal file
@@ -0,0 +1,852 @@
|
||||
<?php
|
||||
class XEmail extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Email API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_join_result_email = '';
|
||||
$sql_having = 'HAVING check_ver_status <> 0';
|
||||
$sql_where = '';
|
||||
|
||||
|
||||
if($prm['filter_work'] == 'manual'){
|
||||
$sql_having .= ' AND another_delivery = 0 ';
|
||||
}
|
||||
if($prm['filter_work'] == 'auto'){
|
||||
$sql_having .= ' AND another_delivery > 0 ';
|
||||
}
|
||||
|
||||
if($prm['filter_status'] == 'ready'){
|
||||
$sql_where .= " AND ISNULL(Result_EmailID)";
|
||||
$sql_join_result_email = 'LEFT JOIN result_email ON Result_EmailT_OrderHeaderID = T_OrderHeaderID AND
|
||||
Result_EmailT_OrderPromiseID = T_OrderPromiseID AND
|
||||
Result_EmailT_OrderDeliveryID = T_OrderDeliveryID AND Result_EmailIsActive = "Y"';
|
||||
}else{
|
||||
$sql_join_result_email = 'JOIN result_email ON Result_EmailT_OrderHeaderID = T_OrderHeaderID AND
|
||||
Result_EmailT_OrderPromiseID = T_OrderPromiseID AND
|
||||
Result_EmailT_OrderDeliveryID = T_OrderDeliveryID AND Result_EmailIsActive = "Y"';
|
||||
$sql_where .= " AND Result_EmailStatus = '{$prm['filter_status']}'";
|
||||
}
|
||||
|
||||
if($prm['name'] != '')
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
|
||||
if($prm['nolab'] != '')
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT IFNULL(Result_EmailID,0) as xid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
T_OrderDeliveryDestination as old_email_address,
|
||||
T_OrderDeliveryDestination as email_address,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
'' as xgroups,
|
||||
fn_check_delivery_other_email(T_OrderHeaderID) as another_delivery,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status,
|
||||
'N' as edit_email,
|
||||
fn_result_handling_color_row(T_OrderPromiseDateTime) as color_row
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 3 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_email
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
$sql_having
|
||||
) xs
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT IFNULL(Result_EmailID,0) as xid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDeliveryDestination SEPARATOR ' , ') as old_email_address,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDeliveryDestination SEPARATOR ' , ') as email_address,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDeliveryID,'-',T_OrderDeliveryDestination) SEPARATOR 'xfajrix') as xemail,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
'' as xgroups,
|
||||
fn_check_delivery_other_email(T_OrderHeaderID) as another_delivery,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status,
|
||||
'N' as edit_email,
|
||||
fn_result_handling_color_row(T_OrderPromiseDateTime) as color_row
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 3 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_email
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
$sql_having
|
||||
ORDER BY T_OrderHeaderLabNumber ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$sql = "SELECT IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
if({$v['another_delivery']} = '0','manual','auto') as type_work,
|
||||
IFNULL(Result_AuthorizationID,0) as xauth_id,
|
||||
SUM(T_OrderDetailPrintCount) as print_count,
|
||||
fn_result_handling_get_cout_print_by_type(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as print_type,
|
||||
fn_result_handling_status_button(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
LEFT JOIN result_authorization ON Result_AuthorizationT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
Result_AuthorizationT_OrderPromiseID = T_OrderPromiseID AND
|
||||
Result_AuthorizationT_TestIsNonLab = T_TestIsNonLab AND
|
||||
Result_AuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$v['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$v['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_TestIsNonLab";
|
||||
//echo $sql;
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$tot_count = 25;
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getstaffs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_StaffID as id, M_StaffName as name
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getrackcontent(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$rows = [];
|
||||
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
|
||||
FROM summary_samplestorage
|
||||
WHERE
|
||||
Summary_SampleStorageStatus = 'FILLED' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} as almariid,
|
||||
M_RackID as id,
|
||||
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
|
||||
M_RackCode as code,
|
||||
M_RackRows as row,
|
||||
M_RackColumns as col,
|
||||
'' as rackcontens
|
||||
FROM m_rack
|
||||
WHERE
|
||||
M_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['col'];
|
||||
$rackcontens = array();
|
||||
for ($x = 1; $x <= $rows; $x++) {
|
||||
$children = array();
|
||||
for ($i = 1; $i <= $cols; $i++) {
|
||||
$content = $x.' x '.$i;
|
||||
$xrow = $x;
|
||||
$xcol = $i;
|
||||
$status = $this->checkexistfilled($filledrows, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkexistfilled($datas,$rackid,$row,$col){
|
||||
$rtn = 'N';
|
||||
foreach($datas as $k => $v){
|
||||
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
|
||||
$rtn = 'Y';
|
||||
}
|
||||
}
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
function save(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$numbering = $this->db_onedev->query("SELECT fn_numbering('SD') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestoragedestroy (
|
||||
T_SampleStorageDestroyNumbering,
|
||||
T_SampleStorageDestroyDate,
|
||||
T_SampleStorageDestroyTime,
|
||||
T_SampleStorageDestroySampleWeight,
|
||||
T_SampleStorageDestroyM_StaffID,
|
||||
T_SampleStorageDestroyNote,
|
||||
T_SampleStorageDestroyUserID,
|
||||
T_SampleStorageDestroyCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['time']}',
|
||||
'{$prm['sampleweight']}',
|
||||
'{$prm['staffid']}',
|
||||
'{$prm['note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
if($saveheader){
|
||||
if($prm['details']){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detail (
|
||||
T_SampleStorageDestroyDetailT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailT_OrderSampleID,
|
||||
T_SampleStorageDestroyDetailBarcode,
|
||||
T_SampleStorageDestroyDetailM_AlmariID,
|
||||
T_SampleStorageDestroyDetailM_RackID,
|
||||
T_SampleStorageDestroyDetailRowPosition,
|
||||
T_SampleStorageDestroyDetailColPosition,
|
||||
T_SampleStorageDestroyDetailUserID,
|
||||
T_SampleStorageDestroyDetailCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['ordersampleid']}',
|
||||
'{$v['barcode']}',
|
||||
'{$v['almari']['id']}',
|
||||
'{$v['rack']['id']}',
|
||||
'{$v['row']}',
|
||||
'{$v['col']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetail = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
if($prm['detailnonsamples']){
|
||||
foreach($prm['detailnonsamples'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detailnonsample (
|
||||
T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailNonSampleM_NonSampleID,
|
||||
T_SampleStorageDestroyDetailNonSampleWeight,
|
||||
T_SampleStorageDestroyDetailNonSampleUserID,
|
||||
T_SampleStorageDestroyDetailNonSampleCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['id']}',
|
||||
'{$v['weight']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetailnonsample = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CREATED.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK'),
|
||||
"numbering" => $numbering,
|
||||
"id" => $last_id
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function deletetrx(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$datarows = [];
|
||||
$query ="UPDATE t_samplestoragedestroy SET T_SampleStorageDestroyIsActive = 'N', T_SampleStorageDestroyUserID = '{$userid}'
|
||||
WHERE T_SampleStorageDestroyID = '{$prm['id']}'";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query);
|
||||
$last_id = $prm['id'];
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CANCEL.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function doauthorization(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['type'] == 'LAB'){
|
||||
$prm['type'] = '';
|
||||
}
|
||||
$sql = "INSERT INTO result_authorization (
|
||||
Result_AuthorizationDateTime,
|
||||
Result_AuthorizationM_StaffID,
|
||||
Result_AuthorizationT_OrderHeaderID,
|
||||
Result_AuthorizationT_OrderPromiseID,
|
||||
Result_AuthorizationNat_GroupID,
|
||||
Result_AuthorizationT_TestIsNonLab,
|
||||
Result_AuthorizationUserID,
|
||||
Result_AuthorizationCreated
|
||||
)
|
||||
VALUES(
|
||||
NOW(),
|
||||
{$prm['staff']['id']},
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$prm['groupid']},
|
||||
'{$prm['type']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$insert_auth = $this->db_onedev->query($sql);
|
||||
$id_auth = $this->db_onedev->insert_id();
|
||||
if($insert_auth){
|
||||
$sql = "SELECT T_OrderDetailID as id
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsNonLab = '{$prm['type']}'
|
||||
LEFT JOIN t_orderauthorization ON T_OrderAuthorizationT_OrderDetailID = T_OrderDetailID AND T_OrderAuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailPrintCount > 0 AND T_OrderDetailT_OrderHeaderID = {$prm['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
ISNULL(T_OrderAuthorizationID) AND T_OrderDetailIsActive = 'Y'";
|
||||
// echo $sql;
|
||||
$dt_rst_detail = $this->db_onedev->query($sql)->result();
|
||||
foreach($dt_rst_detail as $k => $v){
|
||||
$sql = "INSERT INTO t_orderauthorization (
|
||||
T_OrderAuthorizationT_OrderDetailID,
|
||||
T_OrderAuthorizationResult_AuthorizationID,
|
||||
T_OrderAuthorizationCreated,
|
||||
T_OrderAuthorizationUserID
|
||||
)
|
||||
VALUES(
|
||||
{$v->id},
|
||||
{$id_auth},
|
||||
NOW(),
|
||||
{$userid}
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) as count_x
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
LEFT JOIN t_orderauthorization ON T_OrderAuthorizationT_OrderDetailID = T_OrderDetailID AND T_OrderAuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
ISNULL(T_OrderAuthorizationID) AND T_OrderDetailT_OrderHeaderID = {$prm['orderid']} AND T_OrderPromiseID = {$prm['promiseid']}
|
||||
|
||||
";
|
||||
//echo $sql;
|
||||
//echo 'ENTER';
|
||||
$count_x = $this->db_onedev->query($sql)->row()->count_x;
|
||||
//echo $count_x ;
|
||||
//echo $xcount_type;
|
||||
if($count_x == 0){
|
||||
$sql = "SELECT * FROM t_orderdelivery WHERE T_OrderDeliveryM_DeliveryTypeID = 3 AND T_OrderDeliveryT_OrderHeaderID = {$prm['orderid']} AND T_OrderDeliveryIsActive = 'Y'";
|
||||
//echo $sql;
|
||||
$xrst_email = $this->db_onedev->query($sql)->result_array();
|
||||
if($xrst_email){
|
||||
foreach($xrst_email as $k => $v){
|
||||
$sql = "INSERT INTO result_email (
|
||||
Result_EmailT_OrderHeaderID,
|
||||
Result_EmailT_OrderPromiseID,
|
||||
Result_EmailT_OrderDeliveryID,
|
||||
Result_EmailUserID,
|
||||
Result_EmailCreated
|
||||
)
|
||||
VALUES(
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$v['T_OrderDeliveryID']},
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function updateemail(){
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$email_address = '';
|
||||
$email = '';
|
||||
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if(isset($prm['emails'])){
|
||||
foreach($prm['emails'] as $k => $v){
|
||||
$sql = "UPDATE t_orderdelivery SET
|
||||
T_OrderDeliveryDestination = '{$v['address']}',
|
||||
T_OrderDeliveryUserID = {$userid}
|
||||
WHERE
|
||||
T_OrderDeliveryID = {$v['id']}";
|
||||
|
||||
$this->db_onedev->query($sql);
|
||||
$email .= $v['id'].'-'.$v['address'];
|
||||
if($email != '')
|
||||
$email .= 'xfajrix';
|
||||
|
||||
$email_address .= $v['address'];
|
||||
if($email_address != '')
|
||||
$email_address .= ' , ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array('email'=>$email,'email_address'=>$email_address)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupnonsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE M_NonSampleName LIKE CONCAT('%',?,'%')) AND M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_NonSampleID as id,
|
||||
M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
ORDER BY M_NonSampleName ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewvendor(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_vendorsample (
|
||||
M_VendorSampleName,
|
||||
M_VendorSampleAddress,
|
||||
M_VendorSampleCreated,
|
||||
M_VendorSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['vendor_name']}',
|
||||
'{$prm['vendor_address']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewitem(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_nonsample (
|
||||
M_NonSampleName,
|
||||
M_NonSampleCreated,
|
||||
M_NonSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['name']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_NonSampleID as id, M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
WHERE
|
||||
M_NonSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
430
one-api/application/controllers/mockup/resulthandling/Xfo.php
Normal file
430
one-api/application/controllers/mockup/resulthandling/Xfo.php
Normal file
@@ -0,0 +1,430 @@
|
||||
<?php
|
||||
class XFo extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Email API";
|
||||
/*truncate result_authorization;
|
||||
truncate result_office;
|
||||
truncate result_email;
|
||||
truncate t_orderauthorization;*/
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
if($prm['filter_status'] == 'ready' || $prm['filter_status'] == 'done'){
|
||||
$sql_join_result_email = '';
|
||||
$sql_having = 'AND status_done = "N"';
|
||||
$sql_where = '';
|
||||
|
||||
|
||||
if($prm['filter_status'] != 'ready'){
|
||||
$sql_having = ' AND status_done = "Y"';
|
||||
}
|
||||
|
||||
if($prm['name'] != '')
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
|
||||
if($prm['nolab'] != '')
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
'' as xgroups,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_done_fo(T_OrderHeaderID,T_OrderPromiseID) as status_done
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 1 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_office
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
HAVING sum_print > 0 $sql_having
|
||||
ORDER BY T_OrderHeaderLabNumber ASC
|
||||
) xs
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db->last_query();
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
'' as xgroups,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_done_fo(T_OrderHeaderID,T_OrderPromiseID) as status_done
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 1 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_office
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
HAVING sum_print > 0 $sql_having
|
||||
ORDER BY T_OrderHeaderLabNumber ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$sql = "SELECT IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
SUM(T_OrderDetailPrintCount) as print_count,
|
||||
'' as received,
|
||||
fn_result_handling_get_cout_print_by_type(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as print_type,
|
||||
fn_result_handling_status_button(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status,
|
||||
fn_result_handling_status_button_fo(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status_fo,
|
||||
fn_result_handling_check_received_fotype(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status_received
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$v['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$v['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_TestIsNonLab";
|
||||
//echo $sql;
|
||||
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
|
||||
if($prm['name'] != '')
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
|
||||
if($prm['nolab'] != '')
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
|
||||
$sqlx = '';
|
||||
if($prm['filter_status'] === 'readyhandover'){
|
||||
|
||||
$sqlx = "
|
||||
SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
'' as xgroups,
|
||||
Result_OfficeStatus as status
|
||||
FROM result_office
|
||||
JOIN t_orderpromise ON Result_OfficeT_OrderPromiseID = T_OrderPromiseID
|
||||
JOIN t_orderheader ON Result_OfficeT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
WHERE
|
||||
Result_OfficeStatus = 'RECEIVED'
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
limit $number_limit offset $number_offset
|
||||
";
|
||||
}
|
||||
else{
|
||||
$sqlx = "
|
||||
SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
'' as xgroups,
|
||||
Result_OfficeStatus as status,
|
||||
Result_HandOverReceivedBy as receiver,
|
||||
DATE_FORMAT(Result_HandOverDate,'%d-%m-%Y %H:%m') as date_received
|
||||
FROM result_handover
|
||||
JOIN result_office ON Result_OfficeResult_HandOverID = Result_HandOverID AND Result_OfficeStatus = 'HANDOVER'
|
||||
JOIN t_orderpromise ON Result_OfficeT_OrderPromiseID = T_OrderPromiseID
|
||||
JOIN t_orderheader ON Result_OfficeT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
WHERE
|
||||
Result_OfficeIsActive = 'Y'
|
||||
$sql_where
|
||||
GROUP BY Result_HandOverID
|
||||
limit $number_limit offset $number_offset
|
||||
";
|
||||
}
|
||||
//echo $sql;
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
$sqlx
|
||||
) xs
|
||||
";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "$sqlx";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$sql = "SELECT IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
0 as print_count,
|
||||
0 as print_type,
|
||||
'Y' as received,
|
||||
'N' as status,
|
||||
'N' as status_fo,
|
||||
'Y' as status_received
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$v['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$v['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_TestIsNonLab";
|
||||
//echo $sql;
|
||||
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//$tot_count = 25;
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getstaffs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_StaffID as id, M_StaffName as name
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function doauthorization(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['type'] == 'LAB'){
|
||||
$prm['type'] = '';
|
||||
}
|
||||
|
||||
$sql = "UPDATE result_office SET
|
||||
Result_OfficeStatus = 'RECEIVED',
|
||||
Result_OfficeUserID = {$userid}
|
||||
WHERE
|
||||
Result_OfficeT_OrderHeaderID = {$prm['orderid']} AND
|
||||
Result_OfficeT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
Result_OfficeIsNonLab = '{$prm['type']}' AND
|
||||
Result_OfficeStatus = 'NEW'
|
||||
";
|
||||
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function dohandover(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "INSERT INTO result_handover (
|
||||
Result_HandOverDate,
|
||||
Result_HandOverType,
|
||||
Result_HandOverReceivedBy,
|
||||
Result_HandOverReff,
|
||||
Result_HandOverUserID,
|
||||
Result_HandOverCreated
|
||||
)
|
||||
VALUES(
|
||||
NOW(),
|
||||
'OFFICE',
|
||||
'{$prm['receiver']}',
|
||||
'{$prm['receivernote']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$insert_new = $this->db_onedev->query($sql);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
$sql = "UPDATE result_office SET
|
||||
Result_OfficeStatus = 'HANDOVER',
|
||||
Result_OfficeUserID = {$userid},
|
||||
Result_OfficeResult_HandOverID = {$last_id}
|
||||
WHERE
|
||||
Result_OfficeT_OrderHeaderID = {$prm['orderid']} AND
|
||||
Result_OfficeT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
Result_OfficeStatus = 'RECEIVED'
|
||||
";
|
||||
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
class XFohandover extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Email API";
|
||||
/*truncate result_authorization;
|
||||
truncate result_office;
|
||||
truncate result_email;
|
||||
truncate t_orderauthorization;*/
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_join_result_email = '';
|
||||
$sql_where = '';
|
||||
$sqlx = '';
|
||||
if($prm['name'] != '')
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
|
||||
if($prm['nolab'] != '')
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
|
||||
|
||||
if($prm['filter_status'] = 'ready'){
|
||||
$sqlx = "SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
'' as xgroups
|
||||
FROM result_office
|
||||
JOIN t_orderpromise ON Result_OfficeT_OrderPromiseID = T_OrderPromiseID
|
||||
JOIN t_orderheader ON Result_OfficeT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
WHERE
|
||||
Result_OfficeIsActive = 'Y' AND
|
||||
Result_OfficeStatus = 'RECEIVED'
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
ORDER BY T_OrderHeaderLabNumber ASC
|
||||
limit 0,20";
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
$sqlx
|
||||
) xs
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = $sqlx;
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
if($prm['filter_status'] = 'ready'){
|
||||
$sqlx = "SELECT IF(Result_OfficeIsNonLab = '','LAB',Result_OfficeIsNonLab) as xgroup
|
||||
FROM result_office
|
||||
WHERE
|
||||
Result_OfficeIsActive = 'Y' AND
|
||||
Result_OfficeStatus = 'RECEIVED' AND
|
||||
Result_OfficeT_OrderHeaderID = {$v['orderid']} AND
|
||||
Result_OfficeT_OrderPromiseID = {$v['promiseid']}
|
||||
GROUP BY Result_OfficeIsNonLab";
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$tot_count = 25;
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getstaffs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_StaffID as id, M_StaffName as name
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function doauthorization(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['type'] == 'LAB'){
|
||||
$prm['type'] = '';
|
||||
}
|
||||
|
||||
$sql = "UPDATE result_office SET
|
||||
Result_OfficeStatus = 'RECEIVED',
|
||||
Result_OfficeUserID = {$userid}
|
||||
WHERE
|
||||
Result_OfficeT_OrderHeaderID = {$prm['orderid']} AND
|
||||
Result_OfficeT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
Result_OfficeIsNonLab = '{$prm['type']}' AND
|
||||
Result_OfficeStatus = 'NEW'
|
||||
";
|
||||
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,772 @@
|
||||
<?php
|
||||
class XOffice extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Email API";
|
||||
/*truncate result_authorization;
|
||||
truncate result_office;
|
||||
truncate result_email;
|
||||
truncate t_orderauthorization;*/
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_join_result_email = '';
|
||||
$sql_having = 'AND status_done = "N"';
|
||||
$sql_where = '';
|
||||
|
||||
|
||||
if($prm['filter_status'] != 'ready'){
|
||||
$sql_having = ' AND status_done = "Y"';
|
||||
}
|
||||
|
||||
if($prm['name'] != ''){
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
$prm['current_page'] = 1;
|
||||
}
|
||||
|
||||
if($prm['nolab'] != ''){
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
$prm['current_page'] = 1;
|
||||
}
|
||||
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_done(T_OrderHeaderID,T_OrderPromiseID) as status_done,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 1 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_office
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
HAVING check_ver_status <> 0 $sql_having
|
||||
) xs
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%m') as date_promise,
|
||||
'' as xgroups,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_done(T_OrderHeaderID,T_OrderPromiseID) as status_done,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status,
|
||||
fn_result_handling_color_row(T_OrderPromiseDateTime) as color_row
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 1 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_office
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
HAVING check_ver_status <> 0 $sql_having
|
||||
ORDER BY T_OrderPromiseDateTime ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$sql = "SELECT IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
SUM(T_OrderDetailPrintCount) as print_count,
|
||||
fn_result_handling_get_cout_print_by_type(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as print_type,
|
||||
fn_result_handling_status_button(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$v['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$v['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_TestIsNonLab";
|
||||
//echo $sql;
|
||||
|
||||
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$tot_count = 25;
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getstaffs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_StaffID as id, M_StaffName as name
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getrackcontent(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$rows = [];
|
||||
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
|
||||
FROM summary_samplestorage
|
||||
WHERE
|
||||
Summary_SampleStorageStatus = 'FILLED' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} as almariid,
|
||||
M_RackID as id,
|
||||
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
|
||||
M_RackCode as code,
|
||||
M_RackRows as row,
|
||||
M_RackColumns as col,
|
||||
'' as rackcontens
|
||||
FROM m_rack
|
||||
WHERE
|
||||
M_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['col'];
|
||||
$rackcontens = array();
|
||||
for ($x = 1; $x <= $rows; $x++) {
|
||||
$children = array();
|
||||
for ($i = 1; $i <= $cols; $i++) {
|
||||
$content = $x.' x '.$i;
|
||||
$xrow = $x;
|
||||
$xcol = $i;
|
||||
$status = $this->checkexistfilled($filledrows, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkexistfilled($datas,$rackid,$row,$col){
|
||||
$rtn = 'N';
|
||||
foreach($datas as $k => $v){
|
||||
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
|
||||
$rtn = 'Y';
|
||||
}
|
||||
}
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
function save(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$numbering = $this->db_onedev->query("SELECT fn_numbering('SD') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestoragedestroy (
|
||||
T_SampleStorageDestroyNumbering,
|
||||
T_SampleStorageDestroyDate,
|
||||
T_SampleStorageDestroyTime,
|
||||
T_SampleStorageDestroySampleWeight,
|
||||
T_SampleStorageDestroyM_StaffID,
|
||||
T_SampleStorageDestroyNote,
|
||||
T_SampleStorageDestroyUserID,
|
||||
T_SampleStorageDestroyCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['time']}',
|
||||
'{$prm['sampleweight']}',
|
||||
'{$prm['staffid']}',
|
||||
'{$prm['note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
if($saveheader){
|
||||
if($prm['details']){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detail (
|
||||
T_SampleStorageDestroyDetailT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailT_OrderSampleID,
|
||||
T_SampleStorageDestroyDetailBarcode,
|
||||
T_SampleStorageDestroyDetailM_AlmariID,
|
||||
T_SampleStorageDestroyDetailM_RackID,
|
||||
T_SampleStorageDestroyDetailRowPosition,
|
||||
T_SampleStorageDestroyDetailColPosition,
|
||||
T_SampleStorageDestroyDetailUserID,
|
||||
T_SampleStorageDestroyDetailCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['ordersampleid']}',
|
||||
'{$v['barcode']}',
|
||||
'{$v['almari']['id']}',
|
||||
'{$v['rack']['id']}',
|
||||
'{$v['row']}',
|
||||
'{$v['col']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetail = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
if($prm['detailnonsamples']){
|
||||
foreach($prm['detailnonsamples'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detailnonsample (
|
||||
T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailNonSampleM_NonSampleID,
|
||||
T_SampleStorageDestroyDetailNonSampleWeight,
|
||||
T_SampleStorageDestroyDetailNonSampleUserID,
|
||||
T_SampleStorageDestroyDetailNonSampleCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['id']}',
|
||||
'{$v['weight']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetailnonsample = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CREATED.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK'),
|
||||
"numbering" => $numbering,
|
||||
"id" => $last_id
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function deletetrx(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$datarows = [];
|
||||
$query ="UPDATE t_samplestoragedestroy SET T_SampleStorageDestroyIsActive = 'N', T_SampleStorageDestroyUserID = '{$userid}'
|
||||
WHERE T_SampleStorageDestroyID = '{$prm['id']}'";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query);
|
||||
$last_id = $prm['id'];
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CANCEL.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function doauthorization(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['type'] == 'LAB'){
|
||||
$prm['type'] = '';
|
||||
}
|
||||
$sql = "INSERT INTO result_authorization (
|
||||
Result_AuthorizationDateTime,
|
||||
Result_AuthorizationM_StaffID,
|
||||
Result_AuthorizationT_OrderHeaderID,
|
||||
Result_AuthorizationT_OrderPromiseID,
|
||||
Result_AuthorizationNat_GroupID,
|
||||
Result_AuthorizationT_TestIsNonLab,
|
||||
Result_AuthorizationUserID,
|
||||
Result_AuthorizationCreated
|
||||
)
|
||||
VALUES(
|
||||
NOW(),
|
||||
{$prm['staff']['id']},
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$prm['groupid']},
|
||||
'{$prm['type']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$insert_auth = $this->db_onedev->query($sql);
|
||||
$id_auth = $this->db_onedev->insert_id();
|
||||
if($insert_auth){
|
||||
$sql = "SELECT T_OrderDetailID as id
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsNonLab = '{$prm['type']}'
|
||||
LEFT JOIN t_orderauthorization ON T_OrderAuthorizationT_OrderDetailID = T_OrderDetailID AND T_OrderAuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailPrintCount > 0 AND T_OrderDetailT_OrderHeaderID = {$prm['orderid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
ISNULL(T_OrderAuthorizationID) AND T_OrderDetailIsActive = 'Y'";
|
||||
// echo $sql;
|
||||
$dt_rst_detail = $this->db_onedev->query($sql)->result();
|
||||
foreach($dt_rst_detail as $k => $v){
|
||||
$sql = "INSERT INTO t_orderauthorization (
|
||||
T_OrderAuthorizationT_OrderDetailID,
|
||||
T_OrderAuthorizationResult_AuthorizationID,
|
||||
T_OrderAuthorizationCreated,
|
||||
T_OrderAuthorizationUserID
|
||||
)
|
||||
VALUES(
|
||||
{$v->id},
|
||||
{$id_auth},
|
||||
NOW(),
|
||||
{$userid}
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO result_office (
|
||||
result_officeT_OrderHeaderID,
|
||||
result_officeT_OrderPromiseID,
|
||||
Result_OfficeResult_AuthorizationID,
|
||||
Result_OfficeIsNonLab,
|
||||
result_officeUserID,
|
||||
result_officeCreated
|
||||
)
|
||||
VALUES(
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$id_auth},
|
||||
'{$prm['type']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
//echo $sql;
|
||||
$insert_ro = $this->db_onedev->query($sql);
|
||||
|
||||
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupnonsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE M_NonSampleName LIKE CONCAT('%',?,'%')) AND M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_NonSampleID as id,
|
||||
M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
ORDER BY M_NonSampleName ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewvendor(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_vendorsample (
|
||||
M_VendorSampleName,
|
||||
M_VendorSampleAddress,
|
||||
M_VendorSampleCreated,
|
||||
M_VendorSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['vendor_name']}',
|
||||
'{$prm['vendor_address']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewitem(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_nonsample (
|
||||
M_NonSampleName,
|
||||
M_NonSampleCreated,
|
||||
M_NonSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['name']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_NonSampleID as id, M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
WHERE
|
||||
M_NonSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
845
one-api/application/controllers/mockup/resulthandling/Xwa.php
Normal file
845
one-api/application/controllers/mockup/resulthandling/Xwa.php
Normal file
@@ -0,0 +1,845 @@
|
||||
<?php
|
||||
class Xwa extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Wa API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
|
||||
$sql_join_result_wa = '';
|
||||
$sql_having = 'HAVING check_ver_status <> 0';
|
||||
$sql_where = '';
|
||||
|
||||
|
||||
if($prm['filter_work'] == 'manual'){
|
||||
$sql_having .= ' AND another_delivery = 0 ';
|
||||
}
|
||||
if($prm['filter_work'] == 'auto'){
|
||||
$sql_having .= ' AND another_delivery = 1 ';
|
||||
}
|
||||
|
||||
if($prm['filter_status'] == 'ready'){
|
||||
$sql_where .= " AND ISNULL(Result_WaID)";
|
||||
$sql_join_result_wa = 'LEFT JOIN result_wa ON Result_WaT_OrderHeaderID = T_OrderHeaderID AND
|
||||
Result_WaT_OrderPromiseID = T_OrderPromiseID AND
|
||||
Result_WaT_OrderDeliveryID = T_OrderDeliveryID AND Result_WaIsActive = "Y"';
|
||||
}else{
|
||||
$sql_join_result_wa = 'JOIN result_wa ON Result_WaT_OrderHeaderID = T_OrderHeaderID AND
|
||||
Result_WaT_OrderPromiseID = T_OrderPromiseID AND
|
||||
Result_WaT_OrderDeliveryID = T_OrderDeliveryID AND Result_WaIsActive = "Y"';
|
||||
$sql_where .= " AND Result_WaStatus = '{$prm['filter_status']}'";
|
||||
}
|
||||
|
||||
if($prm['name'] != '')
|
||||
$sql_where .= " AND M_PatientName LIKE CONCAT('%','{$prm['name']}','%')";
|
||||
|
||||
if($prm['nolab'] != '')
|
||||
$sql_where .= " AND T_OrderHeaderLabNumber LIKE CONCAT('%','{$prm['nolab']}','%')";
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM (
|
||||
SELECT IFNULL(Result_WaID,0) as xid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
T_OrderDeliveryDestination as wa_address,
|
||||
IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
fn_check_delivery_other_wa(T_OrderHeaderID) as another_delivery,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 4 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_wa
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID
|
||||
$sql_having
|
||||
) xs
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT IFNULL(Result_WaID,0) as xid,
|
||||
T_OrderHeaderID as orderid,
|
||||
T_OrderPromiseID as promiseid,
|
||||
T_OrderDeliveryID as orderdeliveryid,
|
||||
Nat_GroupID as group_id,
|
||||
CONCAT(T_OrderHeaderID,'.',T_OrderPromiseID) as uniqid,
|
||||
T_OrderHeaderLabNumber as labnumber,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDeliveryDestination SEPARATOR ' , ') as old_wa_address,
|
||||
GROUP_CONCAT(DISTINCT T_OrderDeliveryDestination SEPARATOR ' , ') as wa_address,
|
||||
GROUP_CONCAT(DISTINCT CONCAT(T_OrderDeliveryID,'-',T_OrderDeliveryDestination) SEPARATOR 'xfajrix') as xwa,
|
||||
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as date_order,
|
||||
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
|
||||
'' as xgroups,
|
||||
fn_check_delivery_other_wa(T_OrderHeaderID) as another_delivery,
|
||||
fn_sum_print_by_order_promise(T_OrderHeaderID,T_OrderPromiseID) as sum_print,
|
||||
fn_result_handling_check_status_verification(T_OrderHeaderID) as check_ver_status,
|
||||
'N' as edit_wa,
|
||||
fn_result_handling_color_row(T_OrderPromiseDateTime) as color_row
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
||||
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
T_OrderDeliveryM_DeliveryTypeID = 4 AND T_OrderDeliveryIsActive = 'Y'
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
$sql_join_result_wa
|
||||
WHERE
|
||||
T_OrderDetailIsActive = 'Y' AND
|
||||
T_OrderPromiseDateTime < CONCAT('{$prm['datepromise']}',' 23:59:59')
|
||||
$sql_where
|
||||
GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID
|
||||
$sql_having
|
||||
ORDER BY T_OrderHeaderLabNumber ASC
|
||||
limit $number_limit offset $number_offset";
|
||||
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
$sql = "SELECT IF(T_TestIsNonLab = '','LAB',T_TestIsNonLab) as xgroup,
|
||||
if({$v['another_delivery']} = '0','manual','auto') as type_work,
|
||||
IFNULL(Result_AuthorizationID,0) as xauth_id,
|
||||
SUM(T_OrderDetailPrintCount) as print_count,
|
||||
fn_result_handling_get_cout_print_by_type(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as print_type,
|
||||
fn_result_handling_status_button(T_OrderDetailT_OrderHeaderID,T_OrderDetailT_OrderPromiseID,T_TestIsNonLab) as status
|
||||
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
LEFT JOIN result_authorization ON Result_AuthorizationT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
Result_AuthorizationT_OrderPromiseID = T_OrderPromiseID AND
|
||||
Result_AuthorizationT_TestIsNonLab = T_TestIsNonLab AND
|
||||
Result_AuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = {$v['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$v['promiseid']} AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_TestIsNonLab";
|
||||
//echo $sql;
|
||||
$rows[$k]['xgroups'] = $this->db_onedev->query($sql)->result();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$tot_count = 25;
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getstaffs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
$query =" SELECT M_StaffID as id, M_StaffName as name
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows['staffs'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getrackcontent(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$rows = [];
|
||||
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
|
||||
FROM summary_samplestorage
|
||||
WHERE
|
||||
Summary_SampleStorageStatus = 'FILLED' AND
|
||||
Summary_SampleStorageM_AlmariID = {$prm['almariid']} AND
|
||||
Summary_SampleStorageM_RackID = {$prm['rackid']}
|
||||
";
|
||||
//echo $query;
|
||||
$filledrows = $this->db_onedev->query($query)->result_array();
|
||||
$query =" SELECT {$prm['almariid']} as almariid,
|
||||
M_RackID as id,
|
||||
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
|
||||
M_RackCode as code,
|
||||
M_RackRows as row,
|
||||
M_RackColumns as col,
|
||||
'' as rackcontens
|
||||
FROM m_rack
|
||||
WHERE
|
||||
M_RackID = {$prm['rackid']} AND M_RackIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query)->row_array();
|
||||
|
||||
$rows = $datarows['row'];
|
||||
$cols = $datarows['col'];
|
||||
$rackcontens = array();
|
||||
for ($x = 1; $x <= $rows; $x++) {
|
||||
$children = array();
|
||||
for ($i = 1; $i <= $cols; $i++) {
|
||||
$content = $x.' x '.$i;
|
||||
$xrow = $x;
|
||||
$xcol = $i;
|
||||
$status = $this->checkexistfilled($filledrows, $datarows['id'],$xrow,$xcol);
|
||||
$selected = 'N';
|
||||
if($xcol == $prm['col'] && $xrow == $prm['row']){
|
||||
$selected = 'T';
|
||||
}
|
||||
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>$selected));
|
||||
}
|
||||
array_push($rackcontens,$children);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => count($rackcontens) ,
|
||||
"records" => $rackcontens,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkexistfilled($datas,$rackid,$row,$col){
|
||||
$rtn = 'N';
|
||||
foreach($datas as $k => $v){
|
||||
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
|
||||
$rtn = 'Y';
|
||||
}
|
||||
}
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
function save(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$numbering = $this->db_onedev->query("SELECT fn_numbering('SD') as numbering")->row()->numbering;
|
||||
$xdate = date('Y-m-d',strtotime($prm["date"]));
|
||||
$query ="INSERT INTO t_samplestoragedestroy (
|
||||
T_SampleStorageDestroyNumbering,
|
||||
T_SampleStorageDestroyDate,
|
||||
T_SampleStorageDestroyTime,
|
||||
T_SampleStorageDestroySampleWeight,
|
||||
T_SampleStorageDestroyM_StaffID,
|
||||
T_SampleStorageDestroyNote,
|
||||
T_SampleStorageDestroyUserID,
|
||||
T_SampleStorageDestroyCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$numbering}',
|
||||
'{$xdate}',
|
||||
'{$prm['time']}',
|
||||
'{$prm['sampleweight']}',
|
||||
'{$prm['staffid']}',
|
||||
'{$prm['note']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$saveheader = $this->db_onedev->query($query);
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
if($saveheader){
|
||||
if($prm['details']){
|
||||
foreach($prm['details'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detail (
|
||||
T_SampleStorageDestroyDetailT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailT_OrderSampleID,
|
||||
T_SampleStorageDestroyDetailBarcode,
|
||||
T_SampleStorageDestroyDetailM_AlmariID,
|
||||
T_SampleStorageDestroyDetailM_RackID,
|
||||
T_SampleStorageDestroyDetailRowPosition,
|
||||
T_SampleStorageDestroyDetailColPosition,
|
||||
T_SampleStorageDestroyDetailUserID,
|
||||
T_SampleStorageDestroyDetailCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['ordersampleid']}',
|
||||
'{$v['barcode']}',
|
||||
'{$v['almari']['id']}',
|
||||
'{$v['rack']['id']}',
|
||||
'{$v['row']}',
|
||||
'{$v['col']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetail = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
if($prm['detailnonsamples']){
|
||||
foreach($prm['detailnonsamples'] as $k => $v){
|
||||
$query ="INSERT INTO t_samplestoragedestroy_detailnonsample (
|
||||
T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID,
|
||||
T_SampleStorageDestroyDetailNonSampleM_NonSampleID,
|
||||
T_SampleStorageDestroyDetailNonSampleWeight,
|
||||
T_SampleStorageDestroyDetailNonSampleUserID,
|
||||
T_SampleStorageDestroyDetailNonSampleCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$last_id}',
|
||||
'{$v['id']}',
|
||||
'{$v['weight']}',
|
||||
'{$userid}',
|
||||
NOW()
|
||||
)";
|
||||
//echo $query;
|
||||
$savedetailnonsample = $this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CREATED.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK'),
|
||||
"numbering" => $numbering,
|
||||
"id" => $last_id
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function deletetrx(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$datarows = [];
|
||||
$query ="UPDATE t_samplestoragedestroy SET T_SampleStorageDestroyIsActive = 'N', T_SampleStorageDestroyUserID = '{$userid}'
|
||||
WHERE T_SampleStorageDestroyID = '{$prm['id']}'";
|
||||
//echo $query;
|
||||
$datarows = $this->db_onedev->query($query);
|
||||
$last_id = $prm['id'];
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy WHERE T_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_header = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detail WHERE T_SampleStorageDestroyDetailT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_details = $this->db_onedev->query($sql)->result();
|
||||
$sql = "SELECT * FROM t_samplestoragedestroy_detailnonsample WHERE T_SampleStorageDestroyDetailNonSampleT_SampleStorageDestroyID = {$last_id}";
|
||||
$data_log_non_details = $this->db_onedev->query($sql)->result();
|
||||
|
||||
$data_log = json_encode(array('header'=>$data_log_header,'samples'=>$data_log_details,'nonsamples'=>$data_log_non_details));
|
||||
$sql = "INSERT INTO one_log.log_samplestorage (
|
||||
Log_SampleStorageCode,
|
||||
Log_SampleStorageDate,
|
||||
Log_SampleStorageJSON,
|
||||
Log_SampleStorageUserID
|
||||
)
|
||||
VALUES(
|
||||
'CANCEL.DESTROY',
|
||||
CURDATE(),
|
||||
'{$data_log}',
|
||||
{$userid}
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function doauthorization(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['type'] == 'LAB'){
|
||||
$prm['type'] = '';
|
||||
}
|
||||
$sql = "INSERT INTO result_authorization (
|
||||
Result_AuthorizationDateTime,
|
||||
Result_AuthorizationM_StaffID,
|
||||
Result_AuthorizationT_OrderHeaderID,
|
||||
Result_AuthorizationT_OrderPromiseID,
|
||||
Result_AuthorizationNat_GroupID,
|
||||
Result_AuthorizationT_TestIsNonLab,
|
||||
Result_AuthorizationUserID,
|
||||
Result_AuthorizationCreated
|
||||
)
|
||||
VALUES(
|
||||
NOW(),
|
||||
{$prm['staff']['id']},
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$prm['groupid']},
|
||||
'{$prm['type']}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$insert_auth = $this->db_onedev->query($sql);
|
||||
$id_auth = $this->db_onedev->insert_id();
|
||||
if($insert_auth){
|
||||
$sql = "SELECT T_OrderDetailID as id
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsNonLab = '{$prm['type']}'
|
||||
LEFT JOIN t_orderauthorization ON T_OrderAuthorizationT_OrderDetailID = T_OrderDetailID AND T_OrderAuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailPrintCount > 0 AND T_OrderDetailT_OrderHeaderID = {$prm['orderid']} AND
|
||||
T_OrderDetailT_OrderPromiseID = {$prm['promiseid']} AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
ISNULL(T_OrderAuthorizationID) AND T_OrderDetailIsActive = 'Y'";
|
||||
// echo $sql;
|
||||
$dt_rst_detail = $this->db_onedev->query($sql)->result();
|
||||
foreach($dt_rst_detail as $k => $v){
|
||||
$sql = "INSERT INTO t_orderauthorization (
|
||||
T_OrderAuthorizationT_OrderDetailID,
|
||||
T_OrderAuthorizationResult_AuthorizationID,
|
||||
T_OrderAuthorizationCreated,
|
||||
T_OrderAuthorizationUserID
|
||||
)
|
||||
VALUES(
|
||||
{$v->id},
|
||||
{$id_auth},
|
||||
NOW(),
|
||||
{$userid}
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) as count_x
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
||||
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
||||
LEFT JOIN t_orderauthorization ON T_OrderAuthorizationT_OrderDetailID = T_OrderDetailID AND T_OrderAuthorizationIsActive = 'Y'
|
||||
WHERE
|
||||
ISNULL(T_OrderAuthorizationID) AND T_OrderDetailT_OrderHeaderID = {$prm['orderid']} AND T_OrderPromiseID = {$prm['promiseid']}
|
||||
|
||||
";
|
||||
//echo $sql;
|
||||
//echo 'ENTER';
|
||||
$count_x = $this->db_onedev->query($sql)->row()->count_x;
|
||||
//echo $count_x ;
|
||||
//echo $xcount_type;
|
||||
if($count_x == 0){
|
||||
$sql = "SELECT * FROM t_orderdelivery WHERE T_OrderDeliveryM_DeliveryTypeID = 4 AND T_OrderDeliveryT_OrderHeaderID = {$prm['orderid']} AND T_OrderDeliveryIsActive = 'Y'";
|
||||
//echo $sql;
|
||||
$xrst_wa = $this->db_onedev->query($sql)->result_array();
|
||||
if($xrst_wa){
|
||||
foreach($xrst_wa as $k => $v){
|
||||
$sql = "INSERT INTO result_wa (
|
||||
Result_WaT_OrderHeaderID,
|
||||
Result_WaT_OrderPromiseID,
|
||||
Result_WaT_OrderDeliveryID,
|
||||
Result_WaUserID,
|
||||
Result_WaCreated
|
||||
)
|
||||
VALUES(
|
||||
{$prm['orderid']},
|
||||
{$prm['promiseid']},
|
||||
{$v['T_OrderDeliveryID']},
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $prm
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function updatewa(){
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$wa_address = '';
|
||||
$wa = '';
|
||||
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if(isset($prm['was'])){
|
||||
foreach($prm['was'] as $k => $v){
|
||||
$sql = "UPDATE t_orderdelivery SET
|
||||
T_OrderDeliveryDestination = '{$v['address']}',
|
||||
T_OrderDeliveryUserID = {$userid}
|
||||
WHERE
|
||||
T_OrderDeliveryID = {$v['id']}";
|
||||
|
||||
$this->db_onedev->query($sql);
|
||||
$wa .= $v['id'].'-'.$v['address'];
|
||||
if($wa != '')
|
||||
$wa .= 'xfajrix';
|
||||
|
||||
$wa_address .= $v['address'];
|
||||
if($wa_address != '')
|
||||
$wa_address .= ' , ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => array('wa'=>$wa,'wa_address'=>$wa_address)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%',?,'%') OR M_PatientName LIKE CONCAT('%',?,'%')) AND Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE Summary_SampleStorageStatus = 'FILLED'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_AlmariID = M_RackID
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Summary_SampleStorageID as id,
|
||||
T_OrderSampleBarcode as barcode,
|
||||
'' as almari,
|
||||
'' as rack,
|
||||
Summary_SampleStorageRowPosition as row,
|
||||
Summary_SampleStorageColPosition as col,
|
||||
m_almari.*,
|
||||
m_rack.*,
|
||||
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patientname, Summary_SampleStorageT_OrderSampleID as ordersampleid
|
||||
FROM summary_samplestorage
|
||||
JOIN t_ordersample ON T_OrderSampleID = Summary_SampleStorageT_OrderSampleID
|
||||
JOIN t_orderheader ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_almari ON Summary_SampleStorageM_AlmariID = M_AlmariID
|
||||
JOIN m_rack ON Summary_SampleStorageM_RackID = M_RackID
|
||||
$sql_where
|
||||
ORDER BY T_OrderHeaderID ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
if($rows){
|
||||
foreach($rows as $kx => $vx){
|
||||
$vx->almari = array('id'=>$vx->M_AlmariID,'name'=>'[ '.$vx->M_AlmariCode.' ] '.$vx->M_AlmariName,'code'=>$vx->M_AlmariCode);
|
||||
$vx->rack = array('id'=>$vx->M_RackID,'name'=>$vx->M_RackCode.' ( '.$vx->M_RackRows.' x '.$vx->M_RackColumns.' )','code'=>$vx->M_RackCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function lookupnonsamples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$search = $prm["search"];
|
||||
if($search){
|
||||
$sql_where = "WHERE M_NonSampleName LIKE CONCAT('%',?,'%')) AND M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array($search,$search);
|
||||
}
|
||||
else{
|
||||
$sql_where = "WHERE M_NonSampleIsActive = 'Y'";
|
||||
$sql_param = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = " SELECT count(*) as total
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT M_NonSampleID as id,
|
||||
M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
$sql_where
|
||||
ORDER BY M_NonSampleName ASC
|
||||
limit 0,20";
|
||||
|
||||
$query = $this->db_onedev->query($sql, $sql_param);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$rows = $query->result();
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewvendor(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_vendorsample (
|
||||
M_VendorSampleName,
|
||||
M_VendorSampleAddress,
|
||||
M_VendorSampleCreated,
|
||||
M_VendorSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['vendor_name']}',
|
||||
'{$prm['vendor_address']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_VendorSampleID as id, M_VendorSampleName as name
|
||||
FROM m_vendorsample
|
||||
WHERE
|
||||
M_VendorSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function savenewitem(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$query ="INSERT INTO m_nonsample (
|
||||
M_NonSampleName,
|
||||
M_NonSampleCreated,
|
||||
M_NonSampleUserID
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['name']}',
|
||||
NOW(),
|
||||
'{$userid}'
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$savevendor = $this->db_onedev->query($query);
|
||||
|
||||
$query =" SELECT M_NonSampleID as id, M_NonSampleName as name
|
||||
FROM m_nonsample
|
||||
WHERE
|
||||
M_NonSampleIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rows
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function searchstaff(){
|
||||
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']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_staff
|
||||
WHERE
|
||||
M_StaffName like ?
|
||||
AND M_StaffIsActive = 'Y'
|
||||
ORDER BY M_StaffName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_staff rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user