Update 1 Sample Print
This commit is contained in:
parent
ffeb285293
commit
ddfb6a9b66
@ -15,6 +15,9 @@ $routes->get('/tubes/unreceive/(:any)/(:any)', 'Tubes::unreceive/$1/$2');
|
||||
$routes->get('/tubes/unreceiveAll/(:any)', 'Tubes::unreceiveAll/$1');
|
||||
$routes->post('/tubes/comment/(:any)/(:any)', 'Tubes::comment/$1/$2');
|
||||
|
||||
$routes->get('/prints/sample/(:any)/(:any)', 'Prints::sample/$1/$2');
|
||||
// $routes->get('/prints/sample/(:any)/(:any)', 'Prints::sample/$1/$2');
|
||||
|
||||
// Pages
|
||||
$routes->get('/', 'Pages::dashboard_index');
|
||||
$routes->get('/userroles/', 'Pages::userroles_index');
|
||||
|
||||
82
app/Controllers/Prints.php
Normal file
82
app/Controllers/Prints.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
class Prints extends BaseController {
|
||||
|
||||
public function sample($access, $sample) {
|
||||
// Path shared printer menggunakan format yang lebih jelas
|
||||
$printerPath = '\\\\10.148.5.20\\POSTEKC'; // Path ke printer yang dibagikan
|
||||
|
||||
|
||||
// $pplData = "<<<PPL
|
||||
// SIZE 100 mm, 50 mm
|
||||
// GAP 2 mm, 0
|
||||
// DIRECTION 1
|
||||
// REFERENCE 0,0
|
||||
// CLS
|
||||
|
||||
// TEXT 10,2,"Arial",0,1,1,"MRS. I PUTU AYU PUTRI PERTIWI"
|
||||
// TEXT 12,25,"Arial",0,1,1,"F 24Y"
|
||||
// BARCODE 85,50,"128",100,2,0,2,2,"25082257"
|
||||
// TEXT 374,43,"Arial",0,1,1,"25082257"
|
||||
// TEXT 19,45,"Arial",0,1,1,"$sample"
|
||||
// TEXT 10,165,"Arial",0,1,1,"PSA, HDL, LDL, BUN, SGOT"
|
||||
// TEXT 10,195,"Arial",0,1,1,"LIS 4112082257"
|
||||
// TEXT 10,210,"Arial",0,1,1,"HIS 01241101855"
|
||||
// TEXT 240,200,"Arial",0,1,1,"$access 115"
|
||||
|
||||
// PRINT 1
|
||||
// PPL";
|
||||
|
||||
// Data ZPL untuk mencetak label
|
||||
$startSection = "^XA\n^PW400\n^LL224\n";
|
||||
$nameSection = "^FO10,2\n^A0N,23,23\n^FD MRS. I PUTU AYU PUTRI PERTIWI ^FS\n";
|
||||
$yearSection = "^FO12,25\n^A0N,22,22\n^FD F 24Y ^FS\n";
|
||||
$labelBarcodeSection = "^FO85,50\n^BY2,2.0,45\n^BCN,100,N,N,N\n^FD25082257^FS\n";
|
||||
$numberCodeSection = "^FO374,43\n^A0B,25,25\n^FD 25082257 ^FS\n";
|
||||
$sampleSection = "^FO19,45\n^A0B,27,27\n^FD $sample ^FS\n";
|
||||
$parameterSection = "^FO10,165\n^A0N,23,23\n^FD PSA, HDL, LDL, BUN, SGOT ^FS\n";
|
||||
$lisNumSection = "^FO10,195\n^A0N,17,20\n^FD LIS 4112082257 ^FS\n";
|
||||
$hisNumSection = "^FO10,210\n^A0N,20,20\n^FD HIS 01241101855 ^FS\n";
|
||||
$numSampleSection = "^FO240,200\n^A0N,27,27\n^FD $access 115 ^FS\n";
|
||||
$endSection = "^XZ";
|
||||
|
||||
$messagesToPrint = $startSection.$nameSection.$yearSection.$labelBarcodeSection.$numberCodeSection.$sampleSection.$parameterSection.$parameterSection.$lisNumSection.$hisNumSection.$numSampleSection.$endSection;
|
||||
|
||||
// Membuat file sementara untuk ZPL
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'ZPL');
|
||||
|
||||
// Menulis data ZPL ke dalam file sementara
|
||||
file_put_contents($tempFile, $messagesToPrint);
|
||||
|
||||
// Membuat perintah untuk mengirim file ZPL ke printer
|
||||
$command = "copy /b $tempFile $printerPath";
|
||||
|
||||
// Menjalankan perintah untuk mengirimkan file ke printer
|
||||
exec($command, $output, $status);
|
||||
|
||||
// Memeriksa status eksekusi dan menampilkan pesan yang sesuai
|
||||
if ($status === 0) {
|
||||
unlink($tempFile);
|
||||
return $this->response->setJSON(
|
||||
[
|
||||
'message' => "Label Dicetak",
|
||||
'status' => true,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$output = json_encode($output); // Konversi ke JSON
|
||||
return $this->response->setJSON(
|
||||
[
|
||||
'error' => $output,
|
||||
'message' => "Label Gagal Dicetak",
|
||||
'status' => false,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -54,7 +54,7 @@ span.badge { cursor:pointer; }
|
||||
}
|
||||
echo "<td>$sampletext</td>";
|
||||
echo "<td>
|
||||
<span class='badge text-bg-dark'><i class='bi bi-printer'></i></span>
|
||||
<span class='badge text-bg-dark' onclick='print($sampletype, $accessnumber)'><i class='bi bi-printer'></i></span>
|
||||
<span class='badge text-bg-success' onclick='collect($sampletype, $accessnumber)'>Coll.</span>
|
||||
<span class='badge text-bg-warning' onclick='uncollect($sampletype, $accessnumber)'>Un-Coll.</span>
|
||||
<span class='badge text-bg-primary' onclick='unreceive($sampletype, $accessnumber)'>Un-Rec.</span>
|
||||
@ -83,8 +83,32 @@ span.badge { cursor:pointer; }
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
function print(sample, access) {
|
||||
|
||||
const url = '<?=base_url();?>prints/sample/'+access.toString()+'/'+sample.toString();
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json()) // Mengonversi response menjadi JSON (atau gunakan .text() jika formatnya teks)
|
||||
.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 collect(sample, access) {
|
||||
sample = sample.toString().padStart(3,'0');
|
||||
|
||||
const url = '<?=base_url();?>tubes/collect/'+access+'/'+sample;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user