Added production sticker reprint page
This commit is contained in:
1336
app/Filament/Pages/StickerReprint.php
Normal file
1336
app/Filament/Pages/StickerReprint.php
Normal file
File diff suppressed because it is too large
Load Diff
249
app/Http/Controllers/ProductionStickerReprintController.php
Normal file
249
app/Http/Controllers/ProductionStickerReprintController.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\ProductionQuantity;
|
||||
use App\Models\StickerMaster;
|
||||
use Illuminate\Http\Request;
|
||||
use Mpdf\Mpdf;
|
||||
use Mpdf\QrCode\Output;
|
||||
use Mpdf\QrCode\QrCode;
|
||||
|
||||
class ProductionStickerReprintController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function downloadQrPdf($palletNo)
|
||||
{
|
||||
|
||||
$parts = explode('|', $palletNo);
|
||||
$itemCode = trim($parts[0]);
|
||||
$serial = isset($parts[1]) ? trim($parts[1]) : null;
|
||||
|
||||
// Retrieve the item record by item code
|
||||
$item = Item::where('code', $itemCode)->first();
|
||||
|
||||
if (!$item) {
|
||||
abort(404, "Item with code {$itemCode} not found.");
|
||||
}
|
||||
|
||||
$itemId = $item->id;
|
||||
|
||||
$production = ProductionQuantity::where('item_id', $itemId)
|
||||
->where('serial_number', $serial)
|
||||
->first();
|
||||
|
||||
if (!$production) {
|
||||
abort(404, "Production data for item code '{$itemCode}' with serial '{$serial}' not found.");
|
||||
}
|
||||
|
||||
$productionOrder = $production->production_order;
|
||||
|
||||
$qrCode = new QrCode($palletNo);
|
||||
$output = new Output\Png();
|
||||
$qrBinary = $output->output($qrCode, 100);
|
||||
$qrBase64 = base64_encode($qrBinary);
|
||||
|
||||
$sticker = StickerMaster::where('item_id', $itemId)->first();
|
||||
|
||||
// Decide number of copies
|
||||
$copies = 1;
|
||||
if ($sticker) {
|
||||
if ($sticker->serial_number_motor == 1) {
|
||||
$copies = 1;
|
||||
} elseif (is_null($sticker->serial_number_motor) && $sticker->serial_number_pump == 1) {
|
||||
$copies = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return '
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 60mm;
|
||||
height: 14mm;
|
||||
font-size: 10pt;
|
||||
font-family: Arial Narrow, Arial, sans-serif;
|
||||
}
|
||||
|
||||
.sticker-table {
|
||||
width: 60mm;
|
||||
height: 14mm;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.text-cell {
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
font-size: 10pt;
|
||||
padding: 2mm 2mm 0 0;
|
||||
white-space: normal;
|
||||
font-weight: normal;
|
||||
line-height: 0.3;
|
||||
}
|
||||
|
||||
.text-row {
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
font-weight: bold;
|
||||
font-size: 9pt;
|
||||
}
|
||||
|
||||
.serial {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.po-number {
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.desc-row {
|
||||
font-weight: normal;
|
||||
font-size: 7pt;
|
||||
}
|
||||
|
||||
.qr-cell {
|
||||
width: 14mm;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
padding-left: 1mm;
|
||||
padding-top: 0mm;
|
||||
}
|
||||
|
||||
img.qr {
|
||||
width: 13mm;
|
||||
height: 13mm;
|
||||
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">
|
||||
<div class="text-row"><pre><span class="serial">' . htmlspecialchars($serial) . '</span> <span class="po-number">' . htmlspecialchars($productionOrder) . '</span></pre>
|
||||
</div>
|
||||
<div class="desc-row">
|
||||
' . htmlspecialchars($item->description) . '
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="print-container"></div>
|
||||
|
||||
<script>
|
||||
const copies = ' . $copies . ';
|
||||
const htmlBlock = `
|
||||
<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">
|
||||
<div class="text-row">
|
||||
<pre><span class="serial">' . htmlspecialchars($serial) . '</span> <span class="po-number">' . htmlspecialchars($productionOrder) . '</span></pre>
|
||||
</div>
|
||||
<div class="desc-row">
|
||||
' . htmlspecialchars($item->description) . '
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
`;
|
||||
|
||||
const container = document.getElementById("print-container");
|
||||
for (let i = 0; i < copies; i++) {
|
||||
container.insertAdjacentHTML("beforeend", htmlBlock);
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
window.print();
|
||||
setTimeout(function () {
|
||||
window.close();
|
||||
}, 500);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
|
||||
// //Get sticker master data
|
||||
// $sticker = StickerMaster::where('item_id', $itemId)->first();
|
||||
|
||||
// //Decide number of copies
|
||||
// $copies = 1; // default
|
||||
// if ($sticker) {
|
||||
// if ($sticker->serial_number_motor == 1) {
|
||||
// $copies = 1;
|
||||
// } elseif (is_null($sticker->serial_number_motor) && $sticker->serial_number_pump == 1) {
|
||||
// $copies = 2;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $mpdf = new Mpdf([
|
||||
// 'mode' => 'utf-8',
|
||||
// 'format' => [60, 14],
|
||||
// 'margin_left' => 0,
|
||||
// 'margin_right' => 0,
|
||||
// 'margin_top' => 0,
|
||||
// 'margin_bottom' => 0,
|
||||
// ]);
|
||||
|
||||
// for ($i = 0; $i < $copies; $i++) {
|
||||
// $mpdf->WriteHTML($html);
|
||||
// if ($i < $copies - 1) {
|
||||
// $mpdf->AddPage();
|
||||
// }
|
||||
// }
|
||||
|
||||
// $mpdf->Output('qr-label.pdf', 'I');
|
||||
// exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user