diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php index e0e20cd..32350b0 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php @@ -210,6 +210,39 @@ class CreateProductionOrder extends CreateRecord } } + public function printItemSerial() + { + $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; + + $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; + + 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]); + } + } + public function printPanel() { $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; diff --git a/app/Http/Controllers/ProductionOrderController.php b/app/Http/Controllers/ProductionOrderController.php index 732f71f..12349af 100644 --- a/app/Http/Controllers/ProductionOrderController.php +++ b/app/Http/Controllers/ProductionOrderController.php @@ -50,7 +50,8 @@ class ProductionOrderController extends Controller $qrCode = new QrCode($qrData); $output = new Output\Png; - $qrBinary = $output->output($qrCode, 100); + // $qrBinary = $output->output($qrCode, 100); + $qrBinary = $output->output($qrCode, 600); $qrBase64 = base64_encode($qrBinary); $stickers[] = [ @@ -134,6 +135,53 @@ class ProductionOrderController extends Controller } } + public function printitemserial($production_order) + { + $order = ProductionOrder::where('production_order', $production_order)->first(); + + 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 ?? ''; + + $stickers = []; + + for ($i = $fromSerial; $i <= $toSerial; $i++) + { + + $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + + $qrData = $itemCode . '|' . $serial; + + // $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'); + } + } + /** * Store a newly created resource in storage. */