diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php index f78eff41..6b1aea2d 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/CreateProductionOrder.php @@ -211,6 +211,42 @@ class CreateProductionOrder extends CreateRecord } } + public function printProductionOrderSecond() + { + $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.print2', ['production_order' => $pOrder]); + } + } + public function printItemSerial() { $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; @@ -378,6 +414,7 @@ class CreateProductionOrder extends CreateRecord } } + protected function getFormActions(): array { return []; diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php index 698be38a..3b820895 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php @@ -49,6 +49,42 @@ class EditProductionOrder extends EditRecord } } + public function printProductionOrderSecond() + { + $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.print2', ['production_order' => $pOrder]); + } + } + public function printPanel() { $plantId = $this->form->getState()['plant_id'] ?? null; diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php index 8b5ce9f2..c54e2c4c 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php @@ -50,6 +50,42 @@ class ViewProductionOrder extends ViewRecord } } + public function printProductionOrderSecond() + { + $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.print2', ['production_order' => $pOrder]); + } + } + public function printPanel() { $plantId = $this->form->getState()['plant_id'] ?? null; diff --git a/app/Http/Controllers/ProductionOrderController.php b/app/Http/Controllers/ProductionOrderController.php index 0ccb5c9c..83aa0c71 100644 --- a/app/Http/Controllers/ProductionOrderController.php +++ b/app/Http/Controllers/ProductionOrderController.php @@ -72,6 +72,57 @@ class ProductionOrderController extends Controller } } + public function print2($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, 100); + $qrBase64 = base64_encode($qrBinary); + + $stickers[] = [ + 'serial' => $serial, + 'qr' => 'data:image/png;base64,' . $qrBase64, + 'production_order' => $production_order, + 'description' => $itemDes ?? '' + ]; + } + + + // $pdf = Pdf::loadView('production-orders.print', compact('stickers')) + // ->setPaper([0, 0, 170, 28.35]); + + $pdf = Pdf::loadView('production-orders.print2', compact('stickers')) + ->setPaper([0, 0, 170.0787, 28.3465]); + + return $pdf->stream('stickers.pdf'); + } + } + public function printpanel($production_order, $plantCode){ \Log::info('Print Panel Started', [ diff --git a/resources/views/forms/components/save-production-order-button.blade.php b/resources/views/forms/components/save-production-order-button.blade.php index a4421241..1f10387c 100644 --- a/resources/views/forms/components/save-production-order-button.blade.php +++ b/resources/views/forms/components/save-production-order-button.blade.php @@ -18,6 +18,15 @@ class="px-2 py-1 border border-primary-500 text-primary-600 rounded hover:bg-pri Print @endcan +@can('view print production order 2 button') + +@endcan @can('view print panel production order button')