Update Khusus untuk user sby, routes, auth, controller printlabelsby, dashboarduser
This commit is contained in:
parent
da40324dee
commit
60c6356e5a
@ -121,4 +121,9 @@ $routes->group('fo', ['filter' => 'role:fo'], static function ($routes) {
|
||||
$routes->get('printLabel/single/(:any)/(:any)', 'PrintLabel::printSingle/$1/$2');
|
||||
$routes->get('printLabel/collection/(:any)', 'PrintLabel::labelPostekCollection/$1');
|
||||
$routes->get('printLabel/all/(:any)', 'PrintLabel::printAll/$1');
|
||||
$routes->get('printResult/(:any)', 'PrintResult::printResultTest/$1');
|
||||
$routes->get('printResult/(:any)', 'PrintResult::printResultTest/$1');
|
||||
|
||||
$routes->get('printLabelSby/single/(:any)/(:any)', 'PrintLabelSby::printSingle/$1/$2');
|
||||
$routes->get('printLabelSby/collection/(:any)', 'PrintLabelSby::labelZebraCollection/$1');
|
||||
$routes->get('printLabelSby/all/(:any)', 'PrintLabelSby::printAll/$1');
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ class Auth extends BaseController {
|
||||
$data['password'] = $password;
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "SELECT u.USERID, u.USERNAME, u1.PASSWORD, ur.USERROLENAME
|
||||
$sql = "SELECT u.USERID, u.USERNAME, u1.PASSWORD, u1.CITYID, ur.USERROLENAME
|
||||
FROM USERS u
|
||||
left join cmod.dbo.CM_USERS u1 on u.USERID=u1.USERID
|
||||
left join cmod.dbo.CM_USERROLES ur on u1.USERROLEID=ur.USERROLEID
|
||||
@ -31,6 +31,7 @@ WHERE u.USERID='$userid'";
|
||||
$userid = $row['USERID'];
|
||||
$username = $row['USERNAME'];
|
||||
$userrole = $row['USERROLENAME'];
|
||||
$usercityid = $row['CITYID'];
|
||||
// if pass empty then first login / reset password
|
||||
$data['password']=$password;
|
||||
$data['qpassword']=$qpassword;
|
||||
@ -51,6 +52,7 @@ WHERE u.USERID='$userid'";
|
||||
'userid' => $userid,
|
||||
'userrole' => $userrole,
|
||||
'username' => $username,
|
||||
'usercityid' => $usercityid
|
||||
];
|
||||
session()->set( $sessiondata );
|
||||
return redirect()->to('/');
|
||||
|
||||
288
app/Controllers/PrintLabelSby.php
Normal file
288
app/Controllers/PrintLabelSby.php
Normal file
@ -0,0 +1,288 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
class PrintLabelSby extends BaseController {
|
||||
|
||||
public function splitName($fullName) {
|
||||
$words = explode(' ', $fullName); // Pisahkan nama berdasarkan spasi
|
||||
$line1 = '';
|
||||
$line2 = '';
|
||||
|
||||
// Tambahkan kata-kata ke baris pertama hingga mencapai batas 20 karakter
|
||||
foreach ($words as $word) {
|
||||
if (strlen($line1 . ' ' . $word) <= 27) {
|
||||
$line1 .= (empty($line1) ? '' : ' ') . $word;
|
||||
} else {
|
||||
// Setelah line1 penuh, pindahkan kata ke line2
|
||||
if (strlen($line2 . ' ' . $word) <= 19) {
|
||||
$line2 .= (empty($line2) ? '' : ' ') . $word;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jika Line 2 lebih dari 19 karakter, hapus kata terakhir sampai sesuai
|
||||
while (strlen($line2) > 19) {
|
||||
$wordsLine2 = explode(' ', $line2);
|
||||
array_pop($wordsLine2); // Hapus kata terakhir
|
||||
$line2 = implode(' ', $wordsLine2); // Gabungkan kembali
|
||||
}
|
||||
|
||||
// Kembalikan kedua baris sebagai array
|
||||
return ['line1' => $line1, 'line2' => $line2];
|
||||
}
|
||||
|
||||
public function labelZebraCollection($access) {
|
||||
|
||||
$time = microtime(true);
|
||||
$logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000);
|
||||
$filename = "sample_".$logTime;
|
||||
|
||||
$role = session()->get('userrole');
|
||||
$networkPath = "";
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "select p.PATNUMBER as UHID, sr.HOSTORDERNUMBER as BV, p.NAME, p.SEX,
|
||||
DATEDIFF(YEAR, BirthDate, GETDATE()) -
|
||||
CASE WHEN MONTH(BirthDate) > MONTH(GETDATE()) OR (MONTH(BirthDate) = MONTH(GETDATE()) AND DAY(BirthDate) > DAY(GETDATE())) THEN 1
|
||||
ELSE 0 END AS AGE, sr.COLLECTIONDATE
|
||||
from SP_REQUESTS sr
|
||||
left join SP_REQUESTS st on sr.SP_ACCESSNUMBER=st.SP_ACCESSNUMBER
|
||||
left join PATIENTS p on p.PATID=sr.PATID
|
||||
where st.SP_ACCESSNUMBER='$access'";
|
||||
$query = $db->query($sql);
|
||||
$results = $query->getResultArray();
|
||||
$item = $results[0];
|
||||
|
||||
$uhid = substr($item['UHID'], -10);
|
||||
$bv = $item['BV'];
|
||||
$sex = $item['SEX'] == 1 ? "M" : "F";
|
||||
$title = $item['SEX'] == 1 ? "Mr" : "Mrs";
|
||||
$name = $item['NAME'];
|
||||
$age = $item['AGE'];
|
||||
$collectiondate = $item['COLLECTIONDATE'];
|
||||
$date = \DateTime::createFromFormat('Y-m-d H:i:s.v', $collectiondate);
|
||||
if ($date) {
|
||||
$collectiondate = $date->format('d/m/Y H:i');
|
||||
} else {
|
||||
$collectiondate = "";
|
||||
}
|
||||
|
||||
$fixName = $this->splitName($name);
|
||||
$name1 = $fixName['line1'];
|
||||
$name2 = $fixName['line2'];
|
||||
|
||||
if ($sex == 'M') {
|
||||
$jarak = '42';
|
||||
} else {
|
||||
$jarak = '53';
|
||||
}
|
||||
|
||||
// $label = "N
|
||||
// OD
|
||||
// q400
|
||||
// Q200,10+0
|
||||
// I8,A,001
|
||||
// D10
|
||||
// A4,3,0,2,1,1,N,\"$title.$name1\"
|
||||
// A$jarak,20,0,2,1,1,N,\"$name2\"
|
||||
// A325,25,0,2,1,1,N,\"$sex {$age}Y\"
|
||||
// B15,50,0,1,4,8,70,N,\"$access\"
|
||||
// A120,125,0,2,1,1,N,\"REQ# $access\"
|
||||
// A4,164,0,2,1,1,N,\"RM:$uhid\"
|
||||
// A4,147,0,2,1,1,N,\"VN:$bv\"
|
||||
// A195,164,0,2,1,1,N,\"$collectiondate\"
|
||||
|
||||
// P1
|
||||
// ";
|
||||
$label = "^XA
|
||||
^LH0,0
|
||||
^LL400
|
||||
^PW400
|
||||
^FO4,20^ADN,18,10^FD$title.$name1^FS
|
||||
^FO$jarak,37^ADN,18,10^FD$name2^FS
|
||||
^FO325,42^ADN,18,10^FD$sex {$age}Y^FS
|
||||
^FO50,67^BY2,2,70^BCN,70,N,N^FD$access^FS
|
||||
^FO110,142^ADN,18,10^FDREQ# $access^FS
|
||||
^FO4,181^ADN,18,10^FDRM:$uhid^FS
|
||||
^FO4,164^ADN,18,10^FDVN:$bv^FS
|
||||
^FO195,181^ADN,18,10^FD$collectiondate^FS
|
||||
^XZ
|
||||
";
|
||||
|
||||
$printer = $this->printerLab();
|
||||
|
||||
// $folder = "C:/data/";
|
||||
$folder = $printer[0];
|
||||
$fullPath = $folder . $filename;
|
||||
|
||||
// Tulis file ke folder tujuan
|
||||
if (!file_put_contents($fullPath, $label)) {
|
||||
|
||||
//exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var);
|
||||
// Eksekusi Kode Berikut Apabila Ada Error
|
||||
return $this->response->setJSON([
|
||||
'error' => $output,
|
||||
'message' => "Gagal Melakukan Print, Mohon Ulangi Atau Cek Koneksi Printer Anda",
|
||||
'status' => false,
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
// Hapus Koneksi
|
||||
//exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var);
|
||||
return $this->response->setJSON( [
|
||||
'message' => "Print Berhasil!" ,
|
||||
'status' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function labelZebra($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collection_date) {
|
||||
$fixName = $this->splitName($name);
|
||||
$name1 = $fixName['line1'];
|
||||
$name2 = $fixName['line2'];
|
||||
|
||||
if ($sex == 'M') {
|
||||
$jarak = '42';
|
||||
} else {
|
||||
$jarak = '53';
|
||||
}
|
||||
|
||||
// Printer Posteck
|
||||
// $sampleLabel ="N
|
||||
// OD
|
||||
// q400
|
||||
// Q200,10+0
|
||||
// I8,A,001
|
||||
// D10
|
||||
// A4,3,0,2,1,1,N,\"$title.$name1\"
|
||||
// A$jarak,20,0,2,1,1,N,\"$name2\"
|
||||
// A325,25,0,2,1,1,N,\"$sex {$age}Y\"
|
||||
// A4,47,0,2,1,1,N,\"$sample\"
|
||||
// A265,47,0,2,1,1,N,\"Chapter\"
|
||||
// B37,68,0,1,4,8,70,N,\"$barcode\"
|
||||
// A115,143,0,2,1,1,N,\"SAM# $barcode\"
|
||||
// A4,165,0,2,1,1,N,\"RM:$uhid\"
|
||||
// A195,165,0,2,1,1,N,\"$collection_date\"
|
||||
|
||||
// P1
|
||||
// ";
|
||||
|
||||
$sampleLabel = "^XA
|
||||
^LH0,0
|
||||
^LL400
|
||||
^PW400
|
||||
^FO4,20^ADN,18,10^FD$title.$name1^FS
|
||||
^FO$jarak,37^ADN,18,10^FD$name2^FS
|
||||
^FO325,42^ADN,18,10^FD$sex {$age}Y^FS
|
||||
^FO4,54^ADN,18,10^FD$sample^FS
|
||||
^FO265,64^ADN,18,10^FDChapter^FS
|
||||
^FO13,85^BY3,3,70^BCN,70,N,N^FD$barcode^FS
|
||||
^FO115,160^ADN,18,10^FDSAM# $barcode^FS
|
||||
^FO4,182^ADN,18,10^FDRM:$uhid^FS
|
||||
^FO195,182^ADN,18,10^FD$collection_date^FS
|
||||
^XZ
|
||||
";
|
||||
|
||||
return $sampleLabel;
|
||||
}
|
||||
|
||||
|
||||
public function printerLab() {
|
||||
exec('net use Y: \\\\10.0.10.30\\Labelshare /user:Administrator 2>&1', $output, $return_var);
|
||||
$pathNetworkFolder = 'Y:/Sampling_Labels/';
|
||||
$letterPath = 'Y:';
|
||||
return array($pathNetworkFolder, $letterPath);
|
||||
}
|
||||
|
||||
public function printSingle($access, $sampletype) {
|
||||
|
||||
$time = microtime(true);
|
||||
$logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000);
|
||||
$filename = "sample_".$logTime;
|
||||
|
||||
$role = session()->get('userrole');
|
||||
$networkPath = "";
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "select p.PATNUMBER as UHID, sr.HOSTORDERNUMBER as BV, p.NAME, p.SEX,
|
||||
DATEDIFF(YEAR, BirthDate, GETDATE()) -
|
||||
CASE WHEN MONTH(BirthDate) > MONTH(GETDATE()) OR (MONTH(BirthDate) = MONTH(GETDATE()) AND DAY(BirthDate) > DAY(GETDATE())) THEN 1
|
||||
ELSE 0 END AS AGE,
|
||||
ds.FULLTEXT, st.SAMPLETYPE+right(sr.SP_ACCESSNUMBER,5) as BARCODE, sr.COLLECTIONDATE
|
||||
from SP_TUBES st
|
||||
left join SP_REQUESTS sr on st.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER
|
||||
left join PATIENTS p on p.PATID=sr.PATID
|
||||
left join DICT_SAMPLES_TYPES ds on ds.SAMPCODE=st.SAMPLETYPE
|
||||
where st.SP_ACCESSNUMBER='$access' AND ds.SAMPCODE = '$sampletype'";
|
||||
|
||||
$query = $db->query($sql);
|
||||
$results = $query->getResultArray();
|
||||
$item = $results[0];
|
||||
|
||||
$uhid = substr($item['UHID'], -10);
|
||||
$bv = $item['BV'];
|
||||
$sex = $item['SEX'] == 1 ? "M" : "F";
|
||||
$title = $item['SEX'] == 1 ? "Mr" : "Mrs";
|
||||
$name = $item['NAME'];
|
||||
|
||||
if ($sampletype == '200'){
|
||||
$sample = 'SERUM KIMIA';
|
||||
} else if ($sampletype == '250'){
|
||||
$sample = 'SERUM IMUN';
|
||||
} else {
|
||||
$sample = $item['FULLTEXT'];
|
||||
}
|
||||
|
||||
$barcode = $item['BARCODE'];
|
||||
$age = $item['AGE'];
|
||||
$collectiondate = $item['COLLECTIONDATE'];
|
||||
$date = \DateTime::createFromFormat('Y-m-d H:i:s.v', $collectiondate);
|
||||
if ($date) {
|
||||
$collectiondate = $date->format('d/m/Y H:i');
|
||||
} else {
|
||||
$collectiondate = "";
|
||||
}
|
||||
|
||||
$printer = $this->printerLab();
|
||||
$label = $this->labelZebra($sample, $title, $name, $sex, $age, $barcode, $uhid, $bv, $collectiondate);
|
||||
|
||||
// $folder = "C:/data/";
|
||||
$folder = $printer[0];
|
||||
$fullPath = $folder . $filename;
|
||||
|
||||
// Tulis file ke folder tujuan
|
||||
if (!file_put_contents($fullPath, $label)) {
|
||||
|
||||
//exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var);
|
||||
// Eksekusi Kode Berikut Apabila Ada Error
|
||||
return $this->response->setJSON([
|
||||
'error' => $output,
|
||||
'message' => "Gagal Melakukan Print, Mohon Ulangi Atau Cek Koneksi Printer Anda",
|
||||
'status' => false,
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
// Hapus Koneksi
|
||||
//exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var);
|
||||
return $this->response->setJSON( [
|
||||
'message' => "Print Berhasil!" ,
|
||||
'status' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function printAll($access) {
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "select SAMPLETYPE from SP_TUBES where SP_ACCESSNUMBER='$access'";
|
||||
$query = $db->query($sql);
|
||||
$results = $query->getResultArray();
|
||||
foreach($results as $data) {
|
||||
$sample = $data['SAMPLETYPE'];
|
||||
$this->printSingle($access, $sample);
|
||||
}
|
||||
$this->labelZebraCollection($access);
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,10 @@ class UserController extends BaseController {
|
||||
}
|
||||
|
||||
public function viewAccess($accessnumber): string {
|
||||
|
||||
// Mengetahui Apakah User Bali atau Surabaya
|
||||
$data['usercityid'] = session()->get('usercityid');
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "select sr.HOSTORDERNUMBER, tu.SAMPLETYPE, ds.SHORTTEXT, tu.TUBESTATUS, ct.COLLSTATUS, ct.TUBECOMMENT from SP_TUBES tu
|
||||
left join SP_REQUESTS sr on tu.SP_ACCESSNUMBER=sr.SP_ACCESSNUMBER
|
||||
@ -43,7 +47,7 @@ class UserController extends BaseController {
|
||||
|
||||
$data['accessnumber'] = $accessnumber;
|
||||
|
||||
return view('admin/dashboard_viewAccess', $data);
|
||||
return view('user/dashboard_viewAccess', $data);
|
||||
}
|
||||
|
||||
public function changePass() {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
if(isset($data[0])) {
|
||||
$row = $data[0];
|
||||
|
||||
@ -59,7 +60,7 @@ if(isset($data[0])) {
|
||||
<tr>
|
||||
<td></td> <td></td> <td>All</td>
|
||||
<td>
|
||||
<button type='button' class='btn btn-dark m-0 px-2 py-1' onclick="printAllLabel(<?=$accessnumber;?>)"> <h6 class='p-0 m-0'><i class='bi bi-printer'></i></h6> </button>
|
||||
<button type='button' class='btn btn-dark m-0 px-2 py-1' onclick="printAllLabel(<?=$accessnumber;?>, <?=$usercityid;?>)"> <h6 class='p-0 m-0'><i class='bi bi-printer'></i></h6> </button>
|
||||
<button type='button' class='btn btn-success m-0 px-2 py-1' onclick='collectAll(<?=$accessnumber;?>)'><h6 class='p-0 m-0'>Coll.</h6></button>
|
||||
<!-- <button class='badge bg-black text-white m-0 px-2 py-1' onclick='uncollectAll(<?=$accessnumber;?>)'>un-collect</button> -->
|
||||
<button type='button' class='btn btn-primary m-0 px-2 py-1' onclick='unreceiveAll(<?=$accessnumber;?>)'><h6 class='p-0 m-0'>Un-Rec.</h6></button>
|
||||
@ -67,7 +68,7 @@ if(isset($data[0])) {
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td> <td></td> <td>Collection</td>
|
||||
<td><button type='button' class='btn btn-dark m-0 px-2 py-1' onclick="printCollectionLabel(<?=$accessnumber;?>)"><h6 class='p-0 m-0'> <i class='bi bi-printer'></i></h6></button></td>
|
||||
<td><button type='button' class='btn btn-dark m-0 px-2 py-1' onclick="printCollectionLabel(<?=$accessnumber;?>, <?=$usercityid;?>)"><h6 class='p-0 m-0'> <i class='bi bi-printer'></i></h6></button></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
@ -95,7 +96,7 @@ if(isset($data[0])) {
|
||||
}
|
||||
echo "<td>$sampletext ($sampletype)</td>";
|
||||
echo "<td>
|
||||
<button type='button' class='btn btn-dark m-0 px-2 py-1' " . "onclick='printSingleLabel($accessnumber, $sampletype)'" . "><h6 class='p-0 m-0'><i class='bi bi-printer'></i></h6></button>
|
||||
<button type='button' class='btn btn-dark m-0 px-2 py-1' " . "onclick='printSingleLabel($accessnumber, $sampletype, $usercityid)'" . "><h6 class='p-0 m-0'><i class='bi bi-printer'></i></h6></button>
|
||||
<button type='button' class='btn btn-success m-0 px-2 py-1' onclick='collect($sampletype, $accessnumber)'><h6 class='p-0 m-0'>Coll.</h6></button>
|
||||
<button type='button' class='btn btn-warning m-0 px-2 py-1' onclick='uncollect($sampletype, $accessnumber)'><h6 class='p-0 m-0'>Un-Coll.</h6></button>
|
||||
<button type='button' class='btn btn-primary m-0 px-2 py-1' onclick='unreceive($sampletype, $accessnumber)'><h6 class='p-0 m-0'>Un-Rec.</h6></button>
|
||||
@ -112,8 +113,42 @@ if(isset($data[0])) {
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function printCollectionLabel(access){
|
||||
const url = '<?=base_url();?>printLabel/collection/'+access.toString();
|
||||
function printCollectionLabel(access, usercityid){
|
||||
|
||||
let url;
|
||||
if (usercityid == 2) {
|
||||
url = '<?=base_url();?>printLabelSby/collection/'+access.toString();
|
||||
} else {
|
||||
url = '<?=base_url();?>printLabel/collection/'+access.toString();
|
||||
}
|
||||
|
||||
console.log(url);
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
||||
if (data['status']) {
|
||||
console.log(data['message']);
|
||||
} else {
|
||||
console.log(data['message']+"\n"+data['error']);
|
||||
message = data['message']+"\n"+data['error'];
|
||||
alert(message);
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
function printSingleLabel(access, sample, usercityid) {
|
||||
|
||||
let url;
|
||||
if (usercityid == 2) {
|
||||
url = '<?=base_url();?>printLabelSby/single/'+access.toString()+'/'+sample.toString();
|
||||
} else {
|
||||
url = '<?=base_url();?>printLabel/single/'+access.toString()+'/'+sample.toString();
|
||||
}
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
@ -132,28 +167,14 @@ function printCollectionLabel(access){
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
function printSingleLabel(access, sample) {
|
||||
const url = '<?=base_url();?>printLabel/single/'+access.toString()+'/'+sample.toString();
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
||||
if (data['status']) {
|
||||
console.log(data['message']);
|
||||
} else {
|
||||
console.log(data['message']+"\n"+data['error']);
|
||||
message = data['message']+"\n"+data['error'];
|
||||
alert(message);
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
function printAllLabel(access) {
|
||||
const url = '<?=base_url();?>printLabel/all/'+access.toString();
|
||||
function printAllLabel(access, usercityid) {
|
||||
|
||||
let url;
|
||||
if (usercityid == 2) {
|
||||
url = '<?=base_url();?>printLabelSby/all/'+access.toString();
|
||||
} else {
|
||||
url = '<?=base_url();?>printLabel/all/'+access.toString();
|
||||
}
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user