diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 61625b7..9f3c0f5 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -77,4 +77,7 @@ $routes->group('user', ['filter' => 'role:user'], static function ($routes) { $routes->group('fo', ['filter' => 'role:fo'], static function ($routes) { $routes->get('', 'FoController::index'); $routes->get('dashboard/viewAccess/(:any)', 'FoController::viewAccess/$1'); -}); \ No newline at end of file +}); + +// Printers +$routes->get('/prints/single_sample/(:any)/(:any)', 'PrinterController::printSingleSampleBarcode/$1/$2'); \ No newline at end of file diff --git a/app/Controllers/PrinterController.php b/app/Controllers/PrinterController.php new file mode 100644 index 0000000..fb82a7d --- /dev/null +++ b/app/Controllers/PrinterController.php @@ -0,0 +1,246 @@ +get('userrole'); + // $role = "admin"; + $networkPath = ""; + + // Ruang Analis Printer POSTEK C168/200s + if ($role == 'admin' || $role == 'user') { + + // Buka Mapping Drive PC Laboratorium + exec('net use L: \\\\10.148.5.20\\Labelshare /user:Administrator 2>&1', $output, $return_var); + $pathNetworkFolder = 'L:/Sampling_Labels/'; + $letterPath = 'L:'; + + // Printer Posteck + $sampleLable ="N +OD +q400 +Q200,10+0 +I8,A,001 +D10 +A4,3,0,2,1,1,N,\"Mr.I Putu Agus Ariesta Adi Wawan\" +A4,25,0,2,1,1,N,\"M 29Y\" +A4,55,0,2,1,1,N,\"SAMPLE\" +A4,75,0,2,1,1,N,\"Chapter\" +B149,35,0,1,3,8,70,N,\"24020840\" +A199,110,0,2,1,1,N,\"LAB 24020840\" +A4,140,0,2,1,1,N,\"UH : 1B094943\" +A4,160,0,2,1,1,N,\"BV : BV035725\" +A195,156,0,2,1,1,N,\"$filename\" + +P1 +"; + + // Ruang Analis Printer Zebra + } else if ($role == 'sampling') { + + // Buka Mapping Drive PC Sampling + exec('net use S: \\\\10.148.3.169\\Labelshare /user:Administrator 2>&1', $output, $return_var); + $pathNetworkFolder = 'S:/Sampling_Labels/'; + $letterPath = 'S:'; + + // Printer Zebra + $sampleLable ="N +OD +q400 +Q185,10+0 +I8,A,001 +D10 +A4,3,0,2,1,1,N,\"Mr.I Putu Agus Ariesta Adi Wawan\" +A4,25,0,2,1,1,N,\"M 29Y\" +A4,55,0,2,1,1,N,\"SAMPLE\" +A4,75,0,2,1,1,N,\"Chapter\" +B149,35,0,1,3,8,70,N,\"24020840\" +A199,110,0,2,1,1,N,\"LAB 24020840\" +A4,140,0,2,1,1,N,\"UH : 1B094943\" +A4,160,0,2,1,1,N,\"BV : BV035725\" +A195,156,0,2,1,1,N,\"03/12/2024 07:10\" + +P1 +"; + } else { + // Eksekusi Kode Berikut Apabila Role Bukan Analis atau Sampling + return $this->response->setJSON([ + 'message' => "Akses Tidak Berwenang", + 'error' => "Hak Akses Anda Tidak Dikenali", + 'status' => false, + ]); + } + + $fullPath = $pathNetworkFolder . $filename; + + // Tulis file ke folder tujuan + if (!file_put_contents($fullPath, $sampleLable)) { + + 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 printAllSampleBarcode() { + + $data = 5; + + $role = session()->get('userrole'); + // $role="sampling"; + $networkPath = ""; + + // Ruang Analis Printer POSTEK + if ($role == 'admin' || $role == 'user') { + + // Buka Mapping Drive PC Laboratorium + exec('net use L: \\\\10.148.5.20\\Labelshare /user:Administrator 2>&1', $output, $return_var); + $pathNetworkFolder = 'L:/Sampling_Labels/'; + $letterPath = 'L:'; + + for ($i=0; $i<$data; $i++) { + + $time = microtime(true); + $logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000); + $filename = "sample_".$logTime; + + // Printer Posteck + $sampleLable ="N +OD +q400 +Q200,10+0 +I8,A,001 +D10 +A4,3,0,2,1,1,N,\"Mr.I Putu Agus Ariesta Adi Wawan\" +A4,25,0,2,1,1,N,\"M 29Y\" +A4,55,0,2,1,1,N,\"SAMPLE\" +A4,75,0,2,1,1,N,\"Chapter\" +B149,35,0,1,3,8,70,N,\"24020840\" +A199,110,0,2,1,1,N,\"LAB 24020840\" +A4,140,0,2,1,1,N,\"UH : 1B094943\" +A4,160,0,2,1,1,N,\"BV : BV035725\" +A195,156,0,2,1,1,N,\"$filename\" + +P1 +"; + $fullPath = $pathNetworkFolder . $filename; + + // Tulis file ke folder tujuan + if (!file_put_contents($fullPath, $sampleLable)) { + + 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, + ]); + } + } + + // Ruang Analis Printer Zebra + } else if ($role == 'sampling') { + + // Buka Mapping Drive PC Sampling + exec('net use S: \\\\10.148.3.169\\Labelshare /user:Administrator 2>&1', $output, $return_var); + $pathNetworkFolder = 'S:/Sampling_Labels/'; + $letterPath = 'S:'; + + for ($i=0; $i<$data; $i++) { + + $time = microtime(true); + $logTime = date('d-m-Y_H_i_s', $time) . sprintf('_%03d', ($time - floor($time)) * 1000); + $filename = "sample_".$logTime; + + // Printer Zebra + $sampleLable ="N +OD +q400 +Q185,10+0 +I8,A,001 +D10 +A4,3,0,2,1,1,N,\"Mr.I Putu Agus Ariesta Adi Wawan\" +A4,25,0,2,1,1,N,\"M 29Y\" +A4,55,0,2,1,1,N,\"SAMPLE\" +A4,75,0,2,1,1,N,\"Chapter\" +B149,35,0,1,3,8,70,N,\"24020840\" +A199,110,0,2,1,1,N,\"LAB 24020840\" +A4,140,0,2,1,1,N,\"UH : 1B094943\" +A4,160,0,2,1,1,N,\"BV : BV035725\" +A195,156,0,2,1,1,N,\"03/12/2024 07:10\" + +P1 +"; + $fullPath = $pathNetworkFolder . $filename; + + // Tulis file ke folder tujuan + if (!file_put_contents($fullPath, $sampleLable)) { + + 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 { + // Eksekusi Kode Berikut Apabila Role Bukan Analis atau Sampling + return $this->response->setJSON([ + 'message' => "Akses Tidak Berwenang", + 'error' => "Hak Akses Anda Tidak Dikenali", + 'status' => false, + ]); + } + + // Hapus Koneksi + exec('net use '. $letterPath .' /delete 2>&1', $output, $return_var); + return $this->response->setJSON( + [ + 'message' => "Print Berhasil", + 'status' => true, + ] + ); + + } + +} \ No newline at end of file diff --git a/app/Views/admin/dashboard_viewAccess.php b/app/Views/admin/dashboard_viewAccess.php index 53c0f1b..1f2a560 100644 --- a/app/Views/admin/dashboard_viewAccess.php +++ b/app/Views/admin/dashboard_viewAccess.php @@ -45,7 +45,7 @@ $name = $row['NAME']; } echo "