Added sticker reprint updated logic and added blade file
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionQuantity;
|
||||
use App\Models\Shift;
|
||||
@@ -20,7 +21,7 @@ use Filament\Facades\Filament;
|
||||
use Livewire\Attributes\On;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
use Str;
|
||||
class StickerReprint extends Page implements HasForms
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
@@ -1145,6 +1146,20 @@ class StickerReprint extends Page implements HasForms
|
||||
|
||||
if (!$item) {
|
||||
// Handle unknown item code
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'sap_msg_status' => null,
|
||||
'sap_msg_description' => null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
Notification::make()
|
||||
->title('Invalid Item Code')
|
||||
->body("Item code '{$itemCode}' does not exist in Item master.")
|
||||
@@ -1152,37 +1167,9 @@ class StickerReprint extends Page implements HasForms
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$sticker = StickerMaster::where('item_id', $item->id)->first();
|
||||
|
||||
if (!$sticker) {
|
||||
// If no sticker or item_id is found, it's an unknown item
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'sap_msg_status' => null,
|
||||
'sap_msg_description' => null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
Notification::make()
|
||||
->title('Unknown Item Code')
|
||||
->body("Item code does not exist in the Sticker Master.")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
// Now fetch the Item using item_id from sticker and plant_id check
|
||||
$item = Item::where('id', $sticker->item_id)
|
||||
->where('plant_id', $this->pId)
|
||||
->first();
|
||||
$item = Item::where('code', $itemCode)
|
||||
->where('plant_id', $this->pId)
|
||||
->first();
|
||||
|
||||
if ($item)
|
||||
{
|
||||
@@ -1233,8 +1220,114 @@ class StickerReprint extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'sap_msg_status' => null,
|
||||
'sap_msg_description' => null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
|
||||
if ($this->succId === null) {
|
||||
Notification::make()
|
||||
->title('Unknown Item Code')
|
||||
->body("Item code does not exist in master data for choosed plant.")
|
||||
->danger()
|
||||
->seconds(2)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$line = Line::find($this->lId);
|
||||
$lineName = $line ? $line->name : null;
|
||||
|
||||
$categoryName = (Str::length($item->category) > 0) ? $item->category : "";
|
||||
|
||||
if ($categoryName == 'Submersible Motor')
|
||||
{
|
||||
if ($lineName != '6 inch motor line')
|
||||
{
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'sap_msg_status' => null,
|
||||
'sap_msg_description' => null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
Notification::make()
|
||||
->title('Invalid Line Found')
|
||||
->body("Choose '6 inch motor line' to proceed..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ($categoryName == 'Submersible Pump')
|
||||
{
|
||||
if ($lineName != '6 inch pump line')
|
||||
{
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'sap_msg_status' => null,
|
||||
'sap_msg_description' => null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
Notification::make()
|
||||
->title('Invalid Line Found')
|
||||
->body("Choose '6 inch pump line' to proceed..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'production_order'=> $this->prodOrder,
|
||||
'sap_msg_status' => null,
|
||||
'sap_msg_description' => null,
|
||||
'operator_id'=> $operatorName,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
Notification::make()
|
||||
->title('Invalid Category Found')
|
||||
->body("Set proper category to proceed..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->succId == null) {
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
|
||||
@@ -20,23 +20,200 @@ class ProductionStickerReprintController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
// 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_pump == 1) {
|
||||
// // If pump is selected (regardless of motor), 2 copies
|
||||
// $copies = 2;
|
||||
// } elseif ($sticker->serial_number_motor == 1) {
|
||||
// // Only motor selected, 1 copy
|
||||
// $copies = 1;
|
||||
// }
|
||||
// }
|
||||
// return '
|
||||
// <html>
|
||||
// <head>
|
||||
// <style>
|
||||
// body {
|
||||
// margin: 0;
|
||||
// padding: 0;
|
||||
// width: 100mm;
|
||||
// height: 14mm;
|
||||
// font-size: 10pt;
|
||||
// font-family: Arial Narrow, Arial, sans-serif;
|
||||
// }
|
||||
|
||||
// .sticker-table {
|
||||
// width: 100mm;
|
||||
// height: 14mm;
|
||||
// }
|
||||
|
||||
// .text-cell {
|
||||
// margin: 0;
|
||||
// padding: 0;
|
||||
// text-align: left;
|
||||
// font-size: 14pt;
|
||||
// font-weight: normal;
|
||||
// line-height: 1.2;
|
||||
// }
|
||||
|
||||
// .text-row {
|
||||
// font-weight: bold;
|
||||
// font-size: 9pt;
|
||||
// }
|
||||
|
||||
// .serial {
|
||||
// text-align: left;
|
||||
// }
|
||||
|
||||
// .po-number {
|
||||
// text-align: right;
|
||||
// white-space: nowrap;
|
||||
// }
|
||||
|
||||
// .desc-row {
|
||||
// font-weight: normal;
|
||||
// font-size: 8pt;
|
||||
// }
|
||||
|
||||
// .qr-cell {
|
||||
// width: 14mm;
|
||||
// text-align: left;
|
||||
// padding-left: 0mm;
|
||||
// padding-top: 0mm;
|
||||
// }
|
||||
|
||||
// img.qr {
|
||||
// width: 20mm;
|
||||
// height: 20mm;
|
||||
// }
|
||||
// </style>
|
||||
// </head>
|
||||
// <body>
|
||||
// <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 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();
|
||||
$itemId= $item->id;
|
||||
|
||||
if (!$item) {
|
||||
abort(404, "Item with code {$itemCode} not found.");
|
||||
}
|
||||
|
||||
$itemId = $item->id;
|
||||
|
||||
$production = ProductionQuantity::where('item_id', $itemId)
|
||||
$production = ProductionQuantity::where('item_id', $item->id)
|
||||
->where('serial_number', $serial)
|
||||
->first();
|
||||
|
||||
@@ -44,171 +221,31 @@ class ProductionStickerReprintController extends Controller
|
||||
abort(404, "Production data for item code '{$itemCode}' with serial '{$serial}' not found.");
|
||||
}
|
||||
|
||||
$productionOrder = $production->production_order;
|
||||
$productionOrder = $production->production_order ?? '';
|
||||
|
||||
if ($item->category == 'Submersible Motor')
|
||||
{
|
||||
$copies = 1;
|
||||
}
|
||||
elseif ($item->category == 'Submersible Pump')
|
||||
{
|
||||
$copies = 2;
|
||||
}
|
||||
// 5. Generate QR Code (base64)
|
||||
$qrCode = new QrCode($palletNo);
|
||||
$output = new Output\Png();
|
||||
$qrBinary = $output->output($qrCode, 100);
|
||||
$qrBinary = $output->output($qrCode, 100); // 100 = size
|
||||
$qrBase64 = base64_encode($qrBinary);
|
||||
|
||||
$sticker = StickerMaster::where('item_id', $itemId)->first();
|
||||
|
||||
// Decide number of copies
|
||||
$copies = 1;
|
||||
|
||||
if ($sticker) {
|
||||
if ($sticker->serial_number_pump == 1) {
|
||||
// If pump is selected (regardless of motor), 2 copies
|
||||
$copies = 2;
|
||||
} elseif ($sticker->serial_number_motor == 1) {
|
||||
// Only motor selected, 1 copy
|
||||
$copies = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
<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;
|
||||
// 6. Return view
|
||||
return view('print-qr', [
|
||||
'qrBase64' => $qrBase64,
|
||||
'serial' => $serial,
|
||||
'productionOrder' => $productionOrder,
|
||||
'item' => $item,
|
||||
'copies'=> $copies,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
94
resources/views/print-qr.blade.php
Normal file
94
resources/views/print-qr.blade.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
@media print {
|
||||
@page {
|
||||
size: 60mm 14mm;
|
||||
margin: -1mm;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 60mm;
|
||||
height: 14mm;
|
||||
font-family: 'Arial Narrow', Arial, sans-serif;
|
||||
}
|
||||
|
||||
.serial {
|
||||
text-align: left;
|
||||
font-family: 'Arial Narrow', Arial, sans-serif;
|
||||
font-weight: bold;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
.desc-row {
|
||||
font-weight: normal;
|
||||
font-family: 'Arial Narrow', Arial, sans-serif;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
table, td, tr
|
||||
{
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
pre
|
||||
{
|
||||
margin: 0;
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
.po-number {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
img.qr {
|
||||
width: 13mm;
|
||||
height: 13mm;
|
||||
padding-left: 2mm;
|
||||
padding-top: 1mm;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="print-container"></div>
|
||||
|
||||
<script>
|
||||
const copies = {{ $copies }};
|
||||
const qrBase64 = @json($qrBase64);
|
||||
const serial = @json($serial);
|
||||
const productionOrder = @json($productionOrder);
|
||||
const description = @json($item->description);
|
||||
|
||||
const htmlBlock = `
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img class="qr" src="data:image/png;base64,${qrBase64}" alt="QR" />
|
||||
</td>
|
||||
<td>
|
||||
<pre><span class="serial">${serial}</span><span class="po-number">${productionOrder}</span><br><span class="desc-row">${description}</span></pre>
|
||||
</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(() => {
|
||||
window.close();
|
||||
}, 500);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user