From fbb44e3f68f7f6be485f6e41862944a98cf7419e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 6 Mar 2026 08:04:51 +0530 Subject: [PATCH] Chnaged logic in sticker reprint against machine id --- app/Filament/Pages/StickerReprint.php | 1456 ++++++++++--------------- 1 file changed, 555 insertions(+), 901 deletions(-) diff --git a/app/Filament/Pages/StickerReprint.php b/app/Filament/Pages/StickerReprint.php index 9ff489a..73977bf 100644 --- a/app/Filament/Pages/StickerReprint.php +++ b/app/Filament/Pages/StickerReprint.php @@ -7,6 +7,7 @@ use App\Models\Line; use App\Models\Plant; use App\Models\ProductionQuantity; use App\Models\Shift; +use App\Models\Machine; use App\Models\StickerMaster; use Filament\Pages\Page; use Filament\Notifications\Notification; @@ -30,10 +31,45 @@ class StickerReprint extends Page implements HasForms protected static ?string $navigationGroup = 'Sticker Reprint'; - public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr, $prodOrder; + // public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr, $prodOrder; // public $recent_qr, $clear_qr; + public $qrData; + + public $pId; + + public $mId; + + public $mNam; + + public $bId; + + public $bNam; + + public $sId; + + public $sNam; + + public $lId; + + public $lNam; + + public $iId; + + public $succId; + + public $sNoId; + + public $succStat; + + public $recQr; + + public $prodOrder; + + public $workCenter; + + public $recent_qr; use HasFiltersForm; @@ -46,6 +82,7 @@ class StickerReprint extends Page implements HasForms 'line' => null, ]); } + public function boot(): void { Filament::registerRenderHook( @@ -122,31 +159,51 @@ class StickerReprint extends Page implements HasForms ->schema([ Select::make('plant_id') + // ->options(Plant::pluck('name', 'id')) ->label('Plant') - ->reactive() - ->required() - ->columnSpan(1) - //->options(Plant::pluck('name', 'id')) ->options(function (callable $get) { $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); }) + ->required() + ->reactive() + ->columnSpan(1) ->default(function () { return optional(ProductionQuantity::latest()->first())->plant_id; }) - ->afterStateUpdated(function ($state, $set, callable $get,$livewire) { + ->afterStateUpdated(function ($state, $set, callable $get, $livewire) { $plantId = $get('plant_id'); $set('block_name', null); + $now = Carbon::now()->format('H:i:s'); + $shiftType = ($now >= '08:00:00' && $now <= '19:29:59') + ? 'Day' + : 'Night'; + + $set('shift_id', $shiftType); + session(['select_plant' => $state]); - if (!$plantId) - { + if (! $plantId) { $set('pqPlantError', 'Please select a plant first.'); + $this->form->fill([ + 'plant_id' => $this->pId, + 'block_name' => null, + 'shift_id' => null, + 'line_id' => null, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => null, + 'sap_msg_status' => null, + 'sap_msg_description' => null, + // 'operator_id'=> $operatorName, + 'recent_qr' => $this->recQr, + ]); + return; - } - else - { + } else { $this->pId = $plantId; $set('validationError', null); $set('pqPlantError', null); @@ -156,202 +213,79 @@ class StickerReprint extends Page implements HasForms ->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null) ->hintColor('danger'), - // Block Filter - Select::make('block_name') + TextInput::make('machine_id') + ->label('Machine') + ->required() + ->columnSpan(1) + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + $machineId = $get('machine_id'); + + $this->mNam = $machineId; + + }) + ->extraAttributes(fn ($get) => [ + 'wire:keydown.enter' => 'processMachine($event.target.value)', + ]), + + TextInput::make('line_id') + ->label('Line') + ->reactive() + ->readOnly() + ->required() + ->afterStateUpdated(fn ($state) => $this->lNam = $state), + + TextInput::make('block_name') ->label('Block') - ->required() - // ->nullable() ->reactive() - ->columnSpan(1) - ->options(function (callable $get) { - if (!$get('plant_id')) { - return []; - } - - return \App\Models\Block::where('plant_id', $get('plant_id')) - ->pluck('name', 'id') - ->toArray(); - }) - ->default(function () { - $latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id; - return optional(Shift::where('id', $latestShiftId)->first())->block_id; - }) - ->afterStateUpdated(function ($state, callable $set, callable $get) { - if($get('id')) - { - $getShift = ProductionQuantity::where('id', $get('id'))->first(); - $getBlock = Shift::where('id', $getShift->shift_id)->first(); - if($getBlock->block_id) - { - $set('block_name', $getBlock->block_id); - $set('pqBlockError', null); - } - } - - $blockId = $get('block_name'); - $set('shift_id', null); - - if (!$blockId) { - $set('pqBlockError', 'Please select a block first.'); - return; - } - else - { - $this->bId = $blockId; - $set('validationError', null); - $set('pqBlockError', null); - } - }) - ->extraAttributes(fn ($get) => [ - 'class' => $get('pqBlockError') ? 'border-red-500' : '', - ]) - ->hint(fn ($get) => $get('pqBlockError') ? $get('pqBlockError') : null) - ->hintColor('danger'), - - Select::make('shift_id') - ->relationship('shift', 'name') + ->readOnly() ->required() - ->columnSpan(1) - // ->nullable() - ->options(function (callable $get) { - if (!$get('plant_id') || !$get('block_name')) { - return []; - } + ->afterStateUpdated(fn ($state) => $this->bNam = $state), - return Shift::where('plant_id', $get('plant_id')) - ->where('block_id', $get('block_name')) - ->pluck('name', 'id') - ->toArray(); - }) + TextInput::make('shift_id') + ->label('Shift') ->reactive() - ->default(function () { - return optional(ProductionQuantity::latest()->first())->shift_id; - }) - ->afterStateUpdated(function ($state, callable $set, callable $get) { - if($get('id')) - { - $getShift = ProductionQuantity::where('id', $get('id'))->first(); - if($getShift->shift_id) - { - $set('shift_id', $getShift->shift_id); - $set('pqShiftError', null); - } - } - - $curShiftId = $get('shift_id'); - - $set('line_id', null); - - if (!$curShiftId) { - $set('pqShiftError', 'Please select a shift first.'); - return; - } - else - { - $this->sId = $curShiftId; - $set('validationError', null); - $set('pqShiftError', null); - } - }) - ->extraAttributes(fn ($get) => [ - 'class' => $get('pqShiftError') ? 'border-red-500' : '', - ]) - ->hint(fn ($get) => $get('pqShiftError') ? $get('pqShiftError') : null) - ->hintColor('danger'), - - Select::make('line_id') - ->relationship('line', 'name') + ->readOnly() ->required() - ->columnSpan(1) - ->options(function (callable $get) { - if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) { - return []; - } + ->afterStateUpdated(fn ($state) => $this->sNam = $state), - return \App\Models\Line::where('plant_id', $get('plant_id')) - ->pluck('name', 'id') - ->toArray(); - }) + TextInput::make('production_order') + ->label('Production Order') ->reactive() - ->default(function () { - return optional(ProductionQuantity::latest()->first())->line_id; - }) - ->afterStateUpdated(function ($state, callable $set, callable $get) { - if($get('id')) - { - $getShift = ProductionQuantity::where('id', $get('id'))->first(); - if($getShift->line_id) - { - $set('line_id', $getShift->line_id); - $set('pqLineError', null); - } - } - - $lineId = $get('line_id'); - $set('item_code', null); - - - session(['select_line' => $state]); - // dd(session('select_line')); - - $this->triggerChartUpdate(); - - if (!$lineId) { - $set('pqLineError', 'Please select a line first.'); - return; - } - else - { - $this->lId = $lineId; - $set('validationError', null); - $set('pqLineError', null); + ->minLength(7) + ->maxLength(14) + // ->columnSpan(1) + ->columnSpan(['default' => 1, 'sm' => 1]) + ->afterStateUpdated(function ($state, callable $get, callable $set): void { + if (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) { + $set('productionError', 'Must be a numeric value with 7 to 14 digits.'); + $set('production_order', null); + $set('item_code', null); $set('item_id', null); // $set('item_description', null); $set('serial_number', null); + $set('validationError', null); + $this->prodOrder = null; + } else { + $set('productionError', null); + $set('production_order', $state); + $set('item_code', null); + $set('item_id', null); + // $set('item_description', null); + $set('serial_number', null); + $set('validationError', null); + $this->prodOrder = $state; + // if (empty($state)) { + // } } }) ->extraAttributes(fn ($get) => [ - 'class' => $get('pqLineError') ? 'border-red-500' : '', - ]) - ->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null) - ->hintColor('danger'), - - TextInput::make('production_order') - ->label('Production Order') - ->minLength(7) - ->maxLength(14) - ->reactive() - //->required() - //->columnSpan(1) - ->columnSpan(['default' => 1, 'sm' => 1]) - ->afterStateUpdated(function ($state, callable $get, callable $set): void { - if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) - { - $set('productionError', "Must be a numeric value with 7 to 14 digits."); - $set('production_order', null); - $set('item_code', null); - $set('item_id', null); - $set('serial_number', null); - $this->prodOrder = null; - } - else - { - $set('productionError', null); - $set('production_order', $state); - $set('item_code', null); - $set('item_id', null); - // $set('item_description', null); - $set('serial_number', null); - $this->prodOrder = $state; - // if (empty($state)) { - // } - } - }) - ->extraAttributes(fn ($get) => [ + 'id' => 'scan_locator_no', 'class' => $get('productionError') ? 'border-red-500' : '', - ]) - ->hint(fn ($get) => $get('productionError') ? $get('productionError') : null) - ->hintColor('danger'), + ]) + ->hint(fn ($get) => $get('productionError') ? $get('productionError') : null) + ->hintColor('danger'), // TextInput::make('item_code') // ->label('Item Code') // ->columnSpan(1) @@ -372,33 +306,6 @@ class StickerReprint extends Page implements HasForms Hidden::make('sap_msg_status'), Hidden::make('sap_msg_description'), - // TextInput::make('recent_qr') - // ->label('Last scanned QR') - // ->reactive() - // ->columnSpan(['default' => 1, 'sm' => 2]) - //->columnSpan(2) - // ->default(function () { - // // Get the latest 'item_id' foreign key from 'production_quantities' table - // $latestProductionQuantity = ProductionQuantity::latest()->first(); - // if (!$latestProductionQuantity) { - // return null; // Return null if no production quantities exist - // } - - // // Get the corresponding 'code' from 'items' table where 'id' matches 'item_id' - // $itemCode = optional(Item::find($latestProductionQuantity->item_id))->code; - - // // Get the latest 'serial_number' from 'production_quantities' table - // $serialNumber = $latestProductionQuantity->serial_number; - - // // Combine 'code' and 'serial_number' into the desired format - // // return $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null; - - // $this->recQr = $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null; - - // }) - // ->default(fn () => $this->recQr) - // ->readOnly(true), - TextInput::make('id') ->hidden() ->readOnly(), @@ -410,7 +317,114 @@ class StickerReprint extends Page implements HasForms } - // Method to process the value when Enter is pressed + public function processMachine($value) + { + $plantId = $this->pId; + $plantCode = Plant::find($plantId); + + $PlaCo = $plantCode->code; + $this->mNam = $value; + + $now = Carbon::now()->format('H:i:s'); + $this->sNam = ($now >= '08:00:00' && $now <= '19:29:59') + ? 'Day' + : 'Night'; + + $machine = Machine::where('plant_id', $plantId)->where('work_center', $this->mNam)->with('line.block')->first(); + + $machinenotAgaPlant = Machine::where('work_center', $this->mNam)->first(); + + $machineAgaPlant = Machine::where('plant_id', $plantId)->where('work_center', $this->mNam)->first(); + + if (! $machinenotAgaPlant) { + Notification::make() + ->title('Unknown WorkCenter') + ->body('Work Center not found') + ->danger() + ->send(); + $this->form->fill([ + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + '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, + ]); + + return; + } elseif (! $machineAgaPlant) { + Notification::make() + ->title('Unknown WorkCenter') + ->body("Work Center not found against plant code $PlaCo") + ->danger() + ->send(); + + $this->form->fill([ + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + '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, + ]); + + return; + } + + $rec = ProductionQuantity::where('plant_id', $plantId)->where('machine_id', $machineAgaPlant->id)->latest()->first(); + + if ($rec) { + + $item = Item::where('id', $rec->item_id)->where('plant_id', $plantId)->first(); + + $itemCode = $item?->code ?? ''; + $serialNo = $rec->serial_number ?? ''; + + $this->recQr = $itemCode.' | '.$serialNo; + + } + + if ($machine) { + $this->lNam = Line::where('id', $machine->line_id)->value('name'); + $this->bNam = $machine->line->block->name ?? null; + + // dd($lineName, $blockName); + + session(['select_line' => $machine->line_id]); + + $this->form->fill([ + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + '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, + ]); + $this->triggerChartUpdate(); + } + } + #[On('handleQrScan')] public function handleQrScan($value) @@ -435,7 +449,7 @@ class StickerReprint extends Page implements HasForms public function validateAndProcessForm($formQRData) { - $user = Filament::auth()->user(); //->name + $user = Filament::auth()->user(); // ->name $operatorName = $user->name; $this->qrData = $formQRData; @@ -447,146 +461,148 @@ class StickerReprint extends Page implements HasForms $this->recQr = $itemCode && $serialNumber ? "{$itemCode} | {$serialNumber}" : null; } - // Notification::make() - // ->title("Scanned the valid QR code is $formQRData)") - // ->info() - // ->send(); - - if (empty($formQRData)) { $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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Invalid QR') - ->body("Scan the valid QR code.
(Ex: Item_Code|Serial_Number )") + ->body('Scan the valid QR code.
(Ex: Item_Code|Serial_Number )') ->danger() ->send(); + return; - } - else - { - if (!$this->pId) { + } else { + if (! $this->pId) { $this->form->fill([ - 'plant_id'=> null, - 'block_name'=> null, - 'shift_id'=> null, - 'line_id'=> null, - 'item_id'=> null, - 'serial_number'=> null, - 'success_msg'=> null, - 'production_order'=> null, + 'plant_id' => null, + 'machine_id' => null, + 'block_name' => null, + 'shift_id' => null, + 'line_id' => null, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => null, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Choose Plant') - ->body("Please select a plant first.") + ->body('Please select a plant first.') ->danger() ->send(); + return; - } - else if (!$this->bId) { + } elseif (! $this->mNam) { $this->form->fill([ - 'plant_id'=> $this->pId, - 'block_name'=> null, - 'shift_id'=> null, - 'line_id'=> null, - 'item_id'=> null, - 'serial_number'=> null, - 'success_msg'=> null, - 'production_order'=> null, + 'plant_id' => $this->pId, + 'machine_id' => null, + 'block_name' => null, + 'shift_id' => null, + 'line_id' => null, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => null, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() - ->title('Choose Block') - ->body("Please select a block first.") + ->title('Unknown Machine') + ->body("Machine can't be empty!") ->danger() ->send(); + return; - } - else if (!$this->sId) { + } elseif (! $this->lNam) { $this->form->fill([ - 'plant_id'=> $this->pId, - 'block_name'=> $this->bId, - 'shift_id'=> null, - 'line_id'=> null, - 'item_id'=> null, - 'serial_number'=> null, - 'success_msg'=> null, - 'production_order'=> null, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => null, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => null, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, - 'recent_qr' => $this->recQr, - ]); - Notification::make() - ->title('Choose Shift') - ->body("Please select a shift first.") - ->danger() - ->send(); - return; - } - else if (!$this->lId) { - $this->form->fill([ - 'plant_id'=> $this->pId, - 'block_name'=> $this->bId, - 'shift_id'=> $this->sId, - 'line_id'=> null, - 'item_id'=> null, - 'serial_number'=> null, - 'success_msg'=> null, - 'production_order'=> null, - 'sap_msg_status' => null, - 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Choose Line') - ->body("Please select a line first.") + ->body('Please select a line first.') ->danger() ->send(); + + return; + } elseif (! $this->bNam) { + + $this->form->fill([ + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => null, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + '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('Choose Line') + ->body('Please select a Block first.') + ->danger() + ->send(); + + return; + } elseif (! $this->sNam) { + $this->form->fill([ + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => null, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => null, + 'sap_msg_status' => null, + 'sap_msg_description' => null, + 'operator_id' => $operatorName, + 'recent_qr' => $this->recQr, + ]); + Notification::make() + ->title('Choose Shift') + ->body('Please select a shift first.') + ->danger() + ->send(); + return; } - // else if (!$this->prodOrder) { - // $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'=> null, - // 'sap_msg_status' => null, - // 'sap_msg_description' => null, - // 'operator_id'=> $operatorName, - // 'recent_qr' => $this->recQr, - // ]); - // Notification::make() - // ->title('Please scan the production order first.') - // ->danger() - // ->send(); - // return; - // } else if ($this->prodOrder) { if(!is_numeric($this->prodOrder)) @@ -639,371 +655,50 @@ class StickerReprint extends Page implements HasForms } } - // ******************************** - - // $exists = \App\Models\ProductionPlan::where('plant_id', $this->pId) - // ->where('shift_id', $this->sId) - // ->where('line_id', $this->lId) - // ->whereDate('created_at', today()) - // ->latest() - // ->exists(); - - // if ($exists) - // { - // $currentDate = date('Y-m-d'); - - // $shiftId = Shift::where('id', $this->sId) - // ->first(); - - // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; - // $hRs = (int) $hRs; - // //$miNs = (int) $miNs;-*/ - - // $totalMinutes = $hRs * 60 + $miNs; - - // $from_dt = $currentDate . ' ' . $shiftId->start_time; - - // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); - - // $currentDateTime = date('Y-m-d H:i:s'); - - // // Check if current date time is within the range - // if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) { - // //echo "Choosed a valid shift..."; - // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); - - // $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 Shift') - // ->body("Please select a valid shift.") - // ->danger() - // ->send(); - // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')'); - // 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, - // ]); - // } - // } - // else - // { - // $existShifts = \App\Models\ProductionPlan::where('plant_id', $this->pId) - // ->where('shift_id', $this->sId) - // ->where('line_id', $this->lId) - // ->whereDate('created_at', Carbon::yesterday()) - // ->latest() - // ->exists(); - - // if ($existShifts) //if ($existShifts->count() > 0) - // { // record exist on yesterday - // //$currentDate = date('Y-m-d'); - // $yesterday = date('Y-m-d', strtotime('-1 days')); - - // $shiftId = Shift::where('id', $this->sId) - // ->first(); - - // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; - // $hRs = (int) $hRs; - // // $miNs = (int) $miNs;-*/ - - // $totalMinutes = $hRs * 60 + $miNs; - - // $from_dt = $yesterday . ' ' . $shiftId->start_time; - - // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); - - // $currentDateTime = date('Y-m-d H:i:s'); - - // // Check if current date time is within the range - // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) { - // $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, - // ]); - // } - // else - // { - // $currentDate = date('Y-m-d'); - - // $shiftId = Shift::where('id', $this->sId) - // ->first(); - - // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; - // $hRs = (int) $hRs; - // // $miNs = (int) $miNs;-*/ - - // $totalMinutes = $hRs * 60 + $miNs; - - // $from_dt = $currentDate . ' ' . $shiftId->start_time; - - // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); - - // $currentDateTime = date('Y-m-d H:i:s'); - - // // Check if current date time is within the range - // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) { - // //echo "Choosed a valid shift..."; - // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); - - // $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('Plan Not Found') - // ->body("Please set production plan first.") - // ->danger() - // ->send(); - // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')'); - // return; - // } - // else - // { - // //echo "Choosed a valid shift..."; - // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); - - // $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 Shift') - // ->body("Please select a valid shift.") - // ->danger() - // ->send(); - // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')'); - // return; - // } - // } - // } - // else - // { // record not exist on yesterday - - // //$currentDate = date('Y-m-d'); - // $yesterday = date('Y-m-d', strtotime('-1 days')); - - // $shiftId = Shift::where('id', $this->sId) - // ->first(); - - // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; - // $hRs = (int) $hRs; - // // $miNs = (int) $miNs;-*/ - - // $totalMinutes = $hRs * 60 + $miNs; - - // $from_dt = $yesterday . ' ' . $shiftId->start_time; - - // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); - - // $currentDateTime = date('Y-m-d H:i:s'); - - // // Check if current date time is within the range - // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) { - // //echo "Choosed a valid shift..."; - // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); - - // $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('Plan Not Found') - // ->body("Please set production plan first.") - // ->danger() - // ->send(); - // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')'); - // return; - // } - // else - // { - // $currentDate = date('Y-m-d'); - - // $shiftId = Shift::where('id', $this->sId) - // ->first(); - - // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0]; - // $hRs = (int) $hRs; - // // $miNs = (int) $miNs;-*/ - - // $totalMinutes = $hRs * 60 + $miNs; - - // $from_dt = $currentDate . ' ' . $shiftId->start_time; - - // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes")); - - // $currentDateTime = date('Y-m-d H:i:s'); - - // // Check if current date time is within the range - // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) { - // //echo "Choosed a valid shift..."; - // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); - - // $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('Plan Not Found') - // ->body("Please set production plan first.") - // ->danger() - // ->send(); - // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')'); - // return; - // } - // else - // { - // //echo "Choosed a valid shift..."; - // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')'); - - // $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 Shift') - // ->body("Please select a valid shift.") - // ->danger() - // ->send(); - // //$set('validationError', 'Curr.'.$currentDateTime.' (From: '.$from_dt.', To: '.$to_dt.')'); - // return; - // } - // } - // } - // } - - // ******************************** - - $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, - ]); + // $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 (!preg_match('/^[a-zA-Z0-9]{6,}+\|[1-9][a-zA-Z0-9]{8,}+(\|)?$/', $formQRData)) - // { + if (!preg_match('/^[A-Za-z0-9]{6,}\|[1-9][A-Za-z0-9]{7,}(\/[A-Za-z0-9]*)?(\|)?$/', $formQRData)) { - if (strpos($formQRData, '|') === false) { + + if (strpos($formQRData, '|') == false) { $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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Invalid QR') - ->body("Scan the valid QR code.
(Ex: Item_Code|Serial_Number )") + ->body('Scan the valid QR code.
(Ex: Item_Code|Serial_Number )') ->danger() ->send(); + return; - } - else - { + } else { $splits = explode('|', $formQRData); $iCode = trim($splits[0]); $sNumberRaw = isset($splits[1]) ? trim($splits[1]) : null; @@ -1015,53 +710,56 @@ class StickerReprint extends Page implements HasForms $sNumber = null; } - if (!ctype_alnum($iCode)) { + if (! ctype_alnum($iCode)) { + $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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Invalid Item Code') - ->body("Item code must contain alpha-numeric values only.") + ->body('Item code must contain alpha-numeric values only.') ->danger() ->send(); + return; - } - else if (strlen($iCode) < 6) { + } elseif (strlen($iCode) < 6) { $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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Invalid Item Code') - ->body("Item code must be at least 6 digits.") + ->body('Item code must be at least 6 digits.') ->danger() ->send(); + return; } - else if (!ctype_alnum($sNumber)) { $this->form->fill([ 'plant_id'=> $this->pId, @@ -1086,68 +784,71 @@ class StickerReprint extends Page implements HasForms ->send(); return; } - else if (strlen($sNumber) < 9) { + elseif (strlen($sNumber) < 9) { $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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Invalid Serial Number') - ->body("Serial Number must be at least 9 digits.") + ->body('Serial Number must be at least 9 digits.') ->danger() ->duration(800) ->send(); + return; } } $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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Invalid QR') - ->body("Scan the valid QR code.
(Ex: Item_Code|Serial_Number )") + ->body('Scan the valid QR code.
(Ex: Item_Code|Serial_Number )') ->danger() ->send(); + return; - } - else - { + } 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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); } @@ -1156,18 +857,10 @@ class StickerReprint extends Page implements HasForms $parts = explode('|', $formQRData); $itemCode = trim($parts[0]); - $serialNumberRaw = isset($parts[1]) ? trim($parts[1]) : null; - // // Remove slash and everything after it - // if ($serialNumberRaw != null) { - // $serialNumber = preg_replace('/\/.*/', '', $serialNumberRaw); - // $serialNumber = trim($serialNumber); - // } else { - // $serialNumber = null; - // } if ($serialNumberRaw != null) { - if (strpos($serialNumberRaw, '/') !== false) { + if (strpos($serialNumberRaw, '/') != false) { $serialNumber = strstr($serialNumberRaw, '/', true); // gets text before slash } else { $serialNumber = $serialNumberRaw; // keep original @@ -1179,32 +872,33 @@ class StickerReprint extends Page implements HasForms } else { $serialNumber = null; } - $item = Item::where('code', $itemCode)->first(); - - 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, - ]); + $masItem = Item::where('code', $itemCode)->first(); + if (! $masItem) { + $this->form->fill([ + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + '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.") + ->title('Unknown Item Code') + ->body('Item code does not exist in master data.') ->danger() ->send(); + return; } + $item = Item::where('code', $itemCode) ->where('plant_id', $this->pId) ->first(); @@ -1212,23 +906,24 @@ class StickerReprint extends Page implements HasForms if ($item) { $sNo = ProductionQuantity::where('serial_number', $serialNumber) - ->where('plant_id', $this->pId) - ->exists(); + ->where('plant_id', $this->pId) + ->exists(); if (!$sNo) { $this->form->fill([ - 'plant_id'=> $this->pId, - 'block_name'=> $this->bId, - 'shift_id'=> $this->sId, - 'line_id'=> $this->lId, - 'item_id'=> $item->id, - 'serial_number'=> null, - 'success_msg'=> 'Y', - 'production_order'=> $this->prodOrder, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => $item->id, + 'serial_number' => null, + 'success_msg' => 'Y', + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); $this->succId = 'Y'; @@ -1237,162 +932,84 @@ class StickerReprint extends Page implements HasForms 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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Duplicate Serial Number') - ->body("Serial number already exists in database for the selected plant.") + ->body('Serial number already exist in database for choosed plant.') ->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, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() ->title('Unknown Item Code') - ->body("Item code does not exist in master data for choosed plant.") + ->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, - 'shift_id'=> $this->sId, - 'line_id'=> $this->lId, - 'item_id'=> null, - 'serial_number'=> null, - 'success_msg'=> null, - 'production_order'=> $this->prodOrder, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $this->recQr, ]); Notification::make() - ->title("Invalid QR Found") // {$operatorName} - ->body("Please, scan the valid QR code.") - ->danger() - // ->persistent() - ->send(); + ->title('Invalid QR Found') + ->body('Please, scan the valid QR code.') + ->danger() + ->send(); + return; } else { - // // Perform any additional processing or database operations - // $this->saveFormData($formValues); $parts = explode('|', $this->qrData); $itemCode = trim($parts[0]); @@ -1432,10 +1049,51 @@ class StickerReprint extends Page implements HasForms $this->sNoId = null; } + $machine = Machine::where('work_center', $this->mNam)->where('plant_id', $this->pId)->first(); + + if (! $machine) { + Notification::make() + ->title('Unknown Machine') + ->body("Work center {$this->mNam} not found for this plant.") + ->danger() + ->send(); + + return; + } + + $this->mId = $machine->id; + + $this->lId = $machine->line_id; + + $line = Line::find($this->lId); + if (! $line) { + Notification::make() + ->title('Invalid Line') + ->body('Line associated with the machine not found.') + ->danger() + ->send(); + return; + } + + $this->bId = $line->block_id; + + $shift = Shift::where('block_id', $this->bId)->first(); + if (! $shift) { + Notification::make() + ->title('No Shift Found') + ->body('No shift associated with this block.') + ->danger() + ->send(); + return; + } + + $this->sId = $shift->id; + //$this->qrData = preg_replace('/\/.*/', '', $this->qrData); ProductionQuantity::create([ 'plant_id'=> $this->pId, + 'machine_id' => $this->mId, 'shift_id'=> $this->sId, 'line_id' => $this->lId, 'item_id'=> $this->iId, @@ -1446,25 +1104,24 @@ class StickerReprint extends Page implements HasForms $this->iId = null; - // after success insertion $this->form->fill([ - 'plant_id'=> $this->pId, - 'block_name'=> $this->bId, - 'shift_id'=> $this->sId, - 'line_id'=> $this->lId, - 'item_id'=> null, - //'item_code'=> null, - 'serial_number'=> null, - 'success_msg'=> null, - 'production_order'=> $this->prodOrder, + 'plant_id' => $this->pId, + 'machine_id' => $this->mNam, + 'block_name' => $this->bNam, + 'shift_id' => $this->sNam, + 'line_id' => $this->lNam, + 'item_id' => null, + 'serial_number' => null, + 'success_msg' => null, + 'production_order' => $this->prodOrder, 'sap_msg_status' => null, 'sap_msg_description' => null, - 'operator_id'=> $operatorName, + 'operator_id' => $operatorName, 'recent_qr' => $itemCode.' | '.$this->sNoId, ]); Notification::make() - ->title("Valid QR Found") // {$operatorName} + ->title("Valid QR Found") ->body("Valid QR code scanned: {$this->qrData}.") ->success() ->duration(1000) @@ -1491,15 +1148,12 @@ class StickerReprint extends Page implements HasForms // ProductionQuantity::create($formValues); - // dd('Production Updated Event Dispatched'); - $this->dispatch('productionUpdated'); - - // // Optionally, you can emit an event or perform a redirect after saving // $this->emit('formSaved', $model->id); } + public function triggerChartUpdate(): void { if (session()->has('select_plant') && session()->has('select_line')) {