From 8eb0985128ae2928b9be4acc7f74d6a63f9ac59c Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 20 May 2026 15:08:47 +0530 Subject: [PATCH] Reduced qr code quality on generation --- .../Resources/ProductionOrderResource.php | 12 ++ .../Pages/CreateProductionOrder.php | 4 +- .../Pages/EditProductionOrder.php | 121 +++++++++++++---- .../Pages/ViewProductionOrder.php | 125 ++++++++++++++---- .../Controllers/ProductionOrderController.php | 19 ++- 5 files changed, 222 insertions(+), 59 deletions(-) diff --git a/app/Filament/Resources/ProductionOrderResource.php b/app/Filament/Resources/ProductionOrderResource.php index 232c263..e1730ea 100644 --- a/app/Filament/Resources/ProductionOrderResource.php +++ b/app/Filament/Resources/ProductionOrderResource.php @@ -247,6 +247,18 @@ class ProductionOrderResource extends Resource ->searchable() ->alignCenter() ->sortable(), + Tables\Columns\TextColumn::make('item.description') + ->label('Item Description') + ->searchable() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('item.uom') + ->label('Unit of Measure') + ->searchable() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('quantity') ->label('Quantity') ->searchable() diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php index 32350b0..b4afe86 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php @@ -216,6 +216,8 @@ class CreateProductionOrder extends CreateRecord $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; + $plantCode = Plant::where('id', $plantId)->value('code'); + if (empty($plantId)) { Notification::make() ->title('Plant name cannot be empty!') @@ -239,7 +241,7 @@ class CreateProductionOrder extends CreateRecord ->send(); return; } else { - return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder]); + return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); } } diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php index 6b0a4aa..f59857a 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php @@ -89,36 +89,107 @@ class EditProductionOrder extends EditRecord } - public function printItemSerial() + // public function printItemSerial() + // { + // $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; + + // $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; + // $plantCode = Plant::where('id', $plantId)->value('code'); + // if (empty($plantId)) { + // Notification::make() + // ->title('Plant name cannot be empty!') + // ->danger() + // ->send(); + // return; + // } elseif (empty($pOrder)) { + // Notification::make() + // ->title('Production order cannot be empty!') + // ->danger() + // ->send(); + // return; + // } + + // $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); + + // if (! $pOrderExists) { + // Notification::make() + // ->title("Production Order '{$pOrder}' does not exist to get print!") + // ->danger() + // ->send(); + // return; + // } else { + // return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); + // } + // } + + public function printitemserial($production_order, $plantCode) { - $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; + $order = ProductionOrder::where('production_order', $production_order)->first(); - $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; - $plantCode = Plant::where('id', $plantId)->value('code'); - if (empty($plantId)) { - Notification::make() - ->title('Plant name cannot be empty!') - ->danger() - ->send(); - return; - } elseif (empty($pOrder)) { - Notification::make() - ->title('Production order cannot be empty!') - ->danger() - ->send(); - return; + if (!$order) { + abort(404, 'Production Order not found'); } + else{ + $fromSerial = (int) $order->from_serial_number; + $toSerial = (int) $order->to_serial_number; + $itemCode = $order->item->code ?? ''; + $itemDes = $order->item->description ?? ''; - $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); + $wareHouseNo = Plant::where('code', $plantCode)->first(); - if (! $pOrderExists) { - Notification::make() - ->title("Production Order '{$pOrder}' does not exist to get print!") - ->danger() - ->send(); - return; - } else { - return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); + $wareNo = $wareHouseNo->warehouse_number ?? null; + + $now = Carbon::now(); + $year = $now->format('y'); + $month = $now->format('m'); + + $stickers = []; + + for ($i = $fromSerial; $i <= $toSerial; $i++) + { + + $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + + if(!empty($wareNo)){ + $serial = substr($serial, 0, 4) . $wareNo . substr($serial, 4); + $qrData = $itemCode . '|' . $serial; + } else { + $qrData = $itemCode . '|' . $serial; + $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + } + + // $qrData = $itemCode . '|' . $serial; + + // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); + + // $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4); + + // $qrData = $itemCode . '|' . $serialWithWarehouse; + + // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; + + // $qrBase64 = base64_encode( + // QrCode::format('png')->size(100)->generate($qrData) + // ); + + $qrCode = new QrCode($qrData); + $output = new Output\Png; + // $qrBinary = $output->output($qrCode, 100); + $qrBinary = $output->output($qrCode, 600); + $qrBase64 = base64_encode($qrBinary); + + $stickers[] = [ + 'serial' => $serial, + 'qr' => 'data:image/png;base64,' . $qrBase64, + 'production_order' => $itemCode, + 'description' => $itemDes ?? '' + ]; + } + + $pdf = Pdf::loadView('production-orders.printItemSerial', compact('stickers')) + ->setPaper([0, 0, 170, 40]); + + return $pdf->stream('stickers.pdf'); } } diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php index c146e39..389bb68 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php @@ -89,38 +89,109 @@ class ViewProductionOrder extends ViewRecord } - public function printItemSerial() + // public function printItemSerial() + // { + // $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; + + // $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; + + // $plantCode = Plant::where('id', $plantId)->value('code'); + + // if (empty($plantId)) { + // Notification::make() + // ->title('Plant name cannot be empty!') + // ->danger() + // ->send(); + // return; + // } elseif (empty($pOrder)) { + // Notification::make() + // ->title('Production order cannot be empty!') + // ->danger() + // ->send(); + // return; + // } + + // $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); + + // if (! $pOrderExists) { + // Notification::make() + // ->title("Production Order '{$pOrder}' does not exist to get print!") + // ->danger() + // ->send(); + // return; + // } else { + // return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); + // } + // } + + public function printitemserial($production_order, $plantCode) { - $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; + $order = ProductionOrder::where('production_order', $production_order)->first(); - $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; - - $plantCode = Plant::where('id', $plantId)->value('code'); - - if (empty($plantId)) { - Notification::make() - ->title('Plant name cannot be empty!') - ->danger() - ->send(); - return; - } elseif (empty($pOrder)) { - Notification::make() - ->title('Production order cannot be empty!') - ->danger() - ->send(); - return; + if (!$order) { + abort(404, 'Production Order not found'); } + else{ + $fromSerial = (int) $order->from_serial_number; + $toSerial = (int) $order->to_serial_number; + $itemCode = $order->item->code ?? ''; + $itemDes = $order->item->description ?? ''; - $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); + $wareHouseNo = Plant::where('code', $plantCode)->first(); - if (! $pOrderExists) { - Notification::make() - ->title("Production Order '{$pOrder}' does not exist to get print!") - ->danger() - ->send(); - return; - } else { - return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); + $wareNo = $wareHouseNo->warehouse_number ?? null; + + $now = Carbon::now(); + $year = $now->format('y'); + $month = $now->format('m'); + + $stickers = []; + + for ($i = $fromSerial; $i <= $toSerial; $i++) + { + + $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + + if(!empty($wareNo)){ + $serial = substr($serial, 0, 4) . $wareNo . substr($serial, 4); + $qrData = $itemCode . '|' . $serial; + } else { + $qrData = $itemCode . '|' . $serial; + $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + } + + // $qrData = $itemCode . '|' . $serial; + + // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); + + // $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4); + + // $qrData = $itemCode . '|' . $serialWithWarehouse; + + // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; + + // $qrBase64 = base64_encode( + // QrCode::format('png')->size(100)->generate($qrData) + // ); + + $qrCode = new QrCode($qrData); + $output = new Output\Png; + // $qrBinary = $output->output($qrCode, 100); + $qrBinary = $output->output($qrCode, 600); + $qrBase64 = base64_encode($qrBinary); + + $stickers[] = [ + 'serial' => $serial, + 'qr' => 'data:image/png;base64,' . $qrBase64, + 'production_order' => $itemCode, + 'description' => $itemDes ?? '' + ]; + } + + $pdf = Pdf::loadView('production-orders.printItemSerial', compact('stickers')) + ->setPaper([0, 0, 170, 40]); + + return $pdf->stream('stickers.pdf'); } } diff --git a/app/Http/Controllers/ProductionOrderController.php b/app/Http/Controllers/ProductionOrderController.php index d0d95b7..873c779 100644 --- a/app/Http/Controllers/ProductionOrderController.php +++ b/app/Http/Controllers/ProductionOrderController.php @@ -51,7 +51,7 @@ class ProductionOrderController extends Controller $qrCode = new QrCode($qrData); $output = new Output\Png; // $qrBinary = $output->output($qrCode, 100); - $qrBinary = $output->output($qrCode, 600); + $qrBinary = $output->output($qrCode, 100); $qrBase64 = base64_encode($qrBinary); $stickers[] = [ @@ -164,14 +164,21 @@ class ProductionOrderController extends Controller $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + if(!empty($wareNo)){ + $serial = substr($serial, 0, 4) . $wareNo . substr($serial, 4); + $qrData = $itemCode . '|' . $serial; + } else { + $qrData = $itemCode . '|' . $serial; + $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + } + // $qrData = $itemCode . '|' . $serial; - $serial = str_pad($i, 6, '0', STR_PAD_LEFT); - $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); + // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); - $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4); + // $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4); - $qrData = $itemCode . '|' . $serialWithWarehouse; + // $qrData = $itemCode . '|' . $serialWithWarehouse; // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; @@ -186,7 +193,7 @@ class ProductionOrderController extends Controller $qrBase64 = base64_encode($qrBinary); $stickers[] = [ - 'serial' => $serialWithWarehouse, + 'serial' => $serial, 'qr' => 'data:image/png;base64,' . $qrBase64, 'production_order' => $itemCode, 'description' => $itemDes ?? ''