Added pdf file for pallet validation resource page
This commit is contained in:
@@ -9,6 +9,8 @@ use App\Models\TestingPanelReading;
|
||||
use DB;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Http\Request;
|
||||
use Mpdf\Mpdf;
|
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||
|
||||
class TestingPanelController extends Controller
|
||||
{
|
||||
@@ -20,6 +22,236 @@ class TestingPanelController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
public function downloadQrPdf($palletNo)
|
||||
{
|
||||
$qrBinary = QrCode::format('png')->size(70)->generate($palletNo); // Adjust size as needed
|
||||
$qrBase64 = base64_encode($qrBinary);
|
||||
|
||||
$html = '
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 60mm;
|
||||
height: 14mm;
|
||||
font-size: 10pt;
|
||||
font-family: DejaVu Sans, sans-serif;
|
||||
}
|
||||
.sticker-table {
|
||||
width: 60mm;
|
||||
height: 14mm;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.qr-cell {
|
||||
width: 14mm;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
padding-left: 5mm;
|
||||
padding-top: 2mm;
|
||||
}
|
||||
.text-cell {
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
font-size: 12pt;
|
||||
padding-left: 7mm;
|
||||
padding-top: 2mm;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: bold;
|
||||
}
|
||||
img.qr {
|
||||
width: 10mm;
|
||||
height: 10mm;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="sticker-table">
|
||||
<tr>
|
||||
<td class="qr-cell">
|
||||
<img class="qr" src="data:image/png;base64,' . $qrBase64 . '" alt="QR" />
|
||||
</td>
|
||||
<td class="text-cell">
|
||||
' . htmlspecialchars($palletNo) . '
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
|
||||
$mpdf = new Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => [60, 14],
|
||||
'margin_left' => 0,
|
||||
'margin_right' => 0,
|
||||
'margin_top' => 0,
|
||||
'margin_bottom' => 0,
|
||||
]);
|
||||
|
||||
$mpdf->WriteHTML($html);
|
||||
$mpdf->Output(); // This directly flushes output as PDF
|
||||
exit;
|
||||
|
||||
// $mpdf->WriteHTML($html);
|
||||
|
||||
// return response($mpdf->Output('qr-code.pdf', 'S'), 200, [
|
||||
// 'Content-Type' => 'application/pdf',
|
||||
// //'Content-Disposition' => 'attachment; filename="qr-code.pdf"'
|
||||
// 'Content-Disposition' => 'inline; filename="qr-code.pdf"'
|
||||
// ]);
|
||||
}
|
||||
|
||||
|
||||
// public function downloadQrPdf($palletNo)
|
||||
// {
|
||||
// // 1. Generate TSPL commands
|
||||
// $labelContent = <<<EOT
|
||||
// SIZE 60 mm,14 mm
|
||||
// GAP 2 mm,0 mm
|
||||
// DIRECTION 1
|
||||
// CLS
|
||||
// QRCODE 20,20,L,5,A,0,"$palletNo"
|
||||
// TEXT 160,30,"0",0,12,12,"$palletNo"
|
||||
// PRINT 1
|
||||
// EOT;
|
||||
|
||||
// $filePath = '/tmp/labelprint.txt';
|
||||
// file_put_contents($filePath, $labelContent);
|
||||
|
||||
// //$printerShare = '//LASER-STANDBY/TSC TTP';
|
||||
// $tempFile = '/tmp/labelprint.txt';
|
||||
// $printerIp = '172.31.31.250'; // Printer server IP
|
||||
// $username = 'admin'; // SMB username
|
||||
// $password = 'admin'; // SMB password (can be empty, but better with password)
|
||||
// $printerShare = "//$printerIp/TSC_TTP_244 Pro"; // SMB share path
|
||||
|
||||
|
||||
// $tempFile = $filePath;
|
||||
|
||||
// $command = "smbclient \"$printerShare\" -U \"$username%$password\" -c \"put $tempFile labelprint.txt\"";
|
||||
// exec($command, $output, $status);
|
||||
// // $tempFile = '/tmp/labelprint.txt';
|
||||
// // $printerName = 'TSC_TTP_244_Pro'; // Replace with your actual CUPS printer queue name
|
||||
|
||||
// // $command = "lp -d $printerName -o raw $tempFile";
|
||||
// // exec($command, $output, $status);
|
||||
|
||||
// if ($status === 0) {
|
||||
// return response("Print sent to printer.");
|
||||
// } else {
|
||||
// return response("Print failed. Output: " . implode("\n", $output));
|
||||
// }
|
||||
// }
|
||||
// public function downloadQrPdf($palletNo)
|
||||
// {
|
||||
// $tspl = <<<EOT
|
||||
// SIZE 40 mm,30 mm
|
||||
// GAP 2 mm,0 mm
|
||||
// CLS
|
||||
// TEXT 50,50,"0",0,1,1,"Hello, TSC!"
|
||||
// PRINT 1
|
||||
// EOT;
|
||||
|
||||
// // Save TSPL to a temporary file
|
||||
// $tmpFile = tempnam(sys_get_temp_dir(), 'tsc_') . '.tspl';
|
||||
// file_put_contents($tmpFile, $tspl);
|
||||
|
||||
// // Print using CUPS (replace with your actual printer name)
|
||||
// $printerName = "TSC TTP-244 Pro"; // Example, use the exact name from CUPS
|
||||
|
||||
// $command = "lp -d \"$printerName\" \"$tmpFile\" 2>&1";
|
||||
|
||||
// exec($command, $output, $return_var);
|
||||
// $outputStr = implode("\n", $output);
|
||||
|
||||
// unlink($tmpFile);
|
||||
|
||||
// if ($return_var === 0) {
|
||||
// return "Label sent to printer!";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return "Failed to send label to printer. Error: " . $outputStr;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function downloadQrPdf($palletNo)
|
||||
// {
|
||||
// // TSPL commands for test label
|
||||
// $labelContent = <<<EOT
|
||||
// SIZE 60 mm,14 mm
|
||||
// GAP 3 mm,0 mm
|
||||
// OFFSET 0 mm
|
||||
// DIRECTION 1
|
||||
// CLS
|
||||
// QRCODE 35,21,L,4,A,0,"$palletNo"
|
||||
// TEXT 180,50,"4",0,1,1,"$palletNo"
|
||||
// PRINT 1
|
||||
// EOT;
|
||||
|
||||
// //A : error correction level:
|
||||
|
||||
// $escapedContent = escapeshellarg($labelContent);
|
||||
|
||||
// $printerName = '4';
|
||||
|
||||
// $command = "echo $escapedContent | lp -d \"$printerName\" -o raw";
|
||||
|
||||
// exec($command, $output, $status);
|
||||
|
||||
// if ($status === 0) {
|
||||
// return response("Test print sent to printer successfully.");
|
||||
// } else {
|
||||
// return response("Print failed. Output: " . implode("\n", $output));
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function downloadQrPdf($palletNo)
|
||||
// {
|
||||
// // TSPL label content (no indentation in heredoc)
|
||||
// $labelContent = <<<EOT
|
||||
// SIZE 60 mm,14 mm
|
||||
// GAP 2 mm,0 mm
|
||||
// DIRECTION 1
|
||||
// CLS
|
||||
// TEXT 10,10,"1",0,6,6,"Test"
|
||||
// PRINT 1
|
||||
// EOT;
|
||||
|
||||
|
||||
// $printerName = '4';
|
||||
|
||||
// //TEXT x, y, font, rotation, x_multiplication, y_multiplication, "text"
|
||||
|
||||
// // $command = "echo \"$labelContent\" | lp -d \"$printerName\" -o raw";
|
||||
|
||||
// // exec($command, $output, $status);
|
||||
|
||||
// // Save label content to a temp file
|
||||
// $tempFile = sys_get_temp_dir() . '/label.txt';
|
||||
// file_put_contents($tempFile, $labelContent);
|
||||
|
||||
// // Send the temp file to the printer
|
||||
// $command = "cat " . escapeshellarg($tempFile) . " | lp -d " . escapeshellarg($printerName) . " -o raw";
|
||||
|
||||
// exec($command, $output, $status);
|
||||
|
||||
// // Delete the temp file
|
||||
// unlink($tempFile);
|
||||
|
||||
// if ($status === 0) {
|
||||
// return response("TSPL command sent to printer.");
|
||||
// } else {
|
||||
// return response("TSPL print failed. Output: " . implode("\n", $output));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
@@ -216,7 +448,7 @@ class TestingPanelController extends Controller
|
||||
foreach ($data['item_codes'] as $item)
|
||||
{
|
||||
|
||||
$motorTestingMaster = \App\Models\MotorTestingMaster::whereHas('item', callback: function ($query) use ($item) {
|
||||
$motorTestingMaster = MotorTestingMaster::whereHas('item', callback: function ($query) use ($item) {
|
||||
$query->where('code', $item['item_code']);
|
||||
})->where('plant_id', $plantId)->first();
|
||||
|
||||
@@ -336,8 +568,6 @@ class TestingPanelController extends Controller
|
||||
|
||||
// return response("" . implode("\n", $messages), 200)
|
||||
// ->header('Content-Type', 'text/plain');
|
||||
|
||||
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
@@ -345,7 +575,7 @@ class TestingPanelController extends Controller
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Internal Sever Error : '.$e->getCode()
|
||||
'status_description' => 'Internal Sever Error : '.$e?->getCode()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\TestingPanelController;
|
||||
use App\Mail\test;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||
use Mpdf\Mpdf;
|
||||
|
||||
Route::get('/', function () {
|
||||
return redirect('/admin');
|
||||
@@ -10,4 +15,22 @@ Route::get('/', function () {
|
||||
// Mail::to('jothikumar.padmanaban@cripumps.com')->send(
|
||||
// new test()
|
||||
// );
|
||||
|
||||
// });
|
||||
|
||||
// Route::get('/qr-pdf-test', function () {
|
||||
// $qrBinary = QrCode::format('png')->size(200)->generate('Test');
|
||||
// $qrBase64 = base64_encode($qrBinary);
|
||||
|
||||
// $html = '<img src="data:image/png;base64,' . $qrBase64 . '" alt="QR" />';
|
||||
// $mpdf = new Mpdf(['mode' => 'utf-8']);
|
||||
// $mpdf->WriteHTML($html);
|
||||
// return response($mpdf->Output('qr-code.pdf', 'S'), 200, [
|
||||
// 'Content-Type' => 'application/pdf',
|
||||
// 'Content-Disposition' => 'attachment; filename="qr-code.pdf"'
|
||||
// ]);
|
||||
// });
|
||||
|
||||
//Route::get('/download-qr-pdf', [TestingPanelController::class, 'downloadQrPdf'])->name('download-qr-pdf');
|
||||
|
||||
Route::get('/download-qr-pdf/{palletNo}', [TestingPanelController::class, 'downloadQrPdf'])->name('download-qr-pdf');
|
||||
|
||||
Reference in New Issue
Block a user