diff --git a/app/Filament/Imports/UserImporter.php b/app/Filament/Imports/UserImporter.php index fecfe8e..da3758d 100644 --- a/app/Filament/Imports/UserImporter.php +++ b/app/Filament/Imports/UserImporter.php @@ -18,7 +18,7 @@ class UserImporter extends Importer public static function getColumns(): array { return [ - ImportColumn::make('plant') + ImportColumn::make('plant_id') ->requiredMapping() ->exampleHeader('Plant Code') ->example('1000') @@ -54,10 +54,13 @@ class UserImporter extends Importer public function resolveRecord(): ?User { $warnMsg = []; - $plantCod = $this->data['plant']; + $plantCod = $this->data['plant_id']; $plant = null; - if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { + if (Str::length($plantCod) > 0 && (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod))) { $warnMsg[] = 'Invalid plant code found!'; + } elseif (Str::length($plantCod) <= 0) { + $plant = null; + $plantCod = null; } else { $plant = Plant::where('code', $plantCod)->first(); if (! $plant) { diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php index c5e8b49..1a6d833 100644 --- a/app/Filament/Resources/InvoiceValidationResource.php +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -212,6 +212,14 @@ class InvoiceValidationResource extends Resource Forms\Components\TextInput::make('id') ->hidden() ->readOnly(true), + // Forms\Components\Hidden::make('created_by') + // ->label('Created By') + // ->default(Filament::auth()->user()?->name) + // ->reactive(), + // Forms\Components\Hidden::make('updated_by') + // ->label('Updated By') + // ->default(Filament::auth()->user()?->name) + // ->reactive(), ]) ->columns(5), ]); @@ -267,9 +275,11 @@ class InvoiceValidationResource extends Resource Tables\Columns\TextColumn::make('scanned_status') ->label('Scanned Status') ->alignCenter(), - // Tables\Columns\TextColumn::make('stickerMaster.panel_box_code') - // ->label('Panel Box Code') - // ->alignCenter(), + Tables\Columns\TextColumn::make('panel_box_code')// stickerMaster.panel_box_code + ->label('Panel Box Code') + ->alignCenter() + ->sortable(), // ->searchable() + // ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('panel_box_supplier') ->label('Panel Box Supplier') ->alignCenter(), @@ -294,11 +304,20 @@ class InvoiceValidationResource extends Resource ->label('Plant') ->alignCenter() ->sortable(), + Tables\Columns\TextColumn::make('created_by') + ->label('Created By') + ->alignCenter() + ->sortable(), Tables\Columns\TextColumn::make('created_at') ->label('Created At') ->dateTime() ->alignCenter() ->sortable(), + Tables\Columns\TextColumn::make('updated_by') + ->label('Updated By') + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->label('Updated At') ->dateTime() @@ -358,11 +377,15 @@ class InvoiceValidationResource extends Resource FileUpload::make('invoice_serial_number') ->label('Invoice Serial Number') - // ->required() - ->preserveFilenames() // <- this keeps the original filename - ->storeFiles(false) // prevent auto-storing, we will store manually - ->reactive() ->required() + ->acceptedFileTypes([ + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'application/vnd.ms-excel', // Legacy .xls fallback if needed + ]) + ->rules(['mimes:xlsx']) // Laravel validation: extension check + ->preserveFilenames() // <- this keeps the original filename + ->reactive() + ->storeFiles(false) // prevent auto-storing, we will store manually ->disk('local') // 'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app. ->visible(fn (Get $get) => ! empty($get('plant_id'))) ->directory(function (callable $get) { @@ -370,7 +393,9 @@ class InvoiceValidationResource extends Resource $plantCode = $plant?->code ?? null; return "uploads/temp/{$plantCode}"; - }), + }) + ->uploadingMessage('Uploading...') + ->helperText('Only .xlsx files are allowed (Excel files).'), ]) ->action(function (array $data) { $uploadedFile = $data['invoice_serial_number']; @@ -385,15 +410,22 @@ class InvoiceValidationResource extends Resource // Get original filename $originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx + $extension = strtolower(pathinfo($originalName, PATHINFO_EXTENSION)); + if ($extension !== 'xlsx') { + throw new \Exception('Only .xlsx files allowed.'); + } + $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); + $originalName = "{$originalNameOnly}.xlsx"; + // Store manually using storeAs to keep original name $path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); // returns relative path // uploads/temp/{$plantCode}/3RA0018735.xlsx - if ($originalNameOnly && strlen($originalNameOnly) < 8) { + if (strlen($originalNameOnly) < 8 || ! ctype_alnum($originalNameOnly)) { Notification::make() - ->title("Invoice number : '$originalNameOnly' should be greater than or equal to 8 characters!") + ->title("Serial invoice number : '$originalNameOnly' should contain minimum 8 digit alpha numeric values!") ->danger() ->send(); @@ -692,8 +724,8 @@ class InvoiceValidationResource extends Resource FileUpload::make('invoice_material') ->label('Invoice Material') ->required() - ->preserveFilenames() - ->reactive() // <- this keeps the original filename + ->preserveFilenames() // <- this keeps the original filename + ->reactive() ->storeFiles(false) // prevent auto-storing ->disk('local') ->visible(fn (Get $get) => ! empty($get('plant_id'))) @@ -702,7 +734,8 @@ class InvoiceValidationResource extends Resource $plantCode = $plant?->code ?? null; return "uploads/temp/{$plantCode}"; - }), + }) + ->helperText('Only .xlsx files are allowed (Excel files).'), ]) ->action(function (array $data) { $uploadedFile = $data['invoice_material']; @@ -717,13 +750,20 @@ class InvoiceValidationResource extends Resource // Get original filename $originalName = $uploadedFile->getClientOriginalName(); + $extension = strtolower(pathinfo($originalName, PATHINFO_EXTENSION)); + if ($extension !== 'xlsx') { + throw new \Exception('Only .xlsx files allowed.'); + } + $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); + $originalName = "{$originalNameOnly}.xlsx"; + $path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); - if ($originalNameOnly && strlen($originalNameOnly) < 8) { + if (strlen($originalNameOnly) < 8 || ! ctype_alnum($originalNameOnly)) { Notification::make() - ->title("Invoice number : '$originalNameOnly' should be greater than or equal to 8 characters!") + ->title("Material invoice number : '$originalNameOnly' should contain minimum 8 digit alpha numeric values!") ->danger() ->send(); diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php index 3a411a2..61fe91d 100644 --- a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php @@ -613,6 +613,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => 1, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -653,6 +655,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => $bundleQty, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -716,6 +720,7 @@ class CreateInvoiceValidation extends CreateRecord $existEmpRecQty->update([ 'quantity' => $newInsQty, 'operator_id' => $operatorName, + 'updated_by' => $operatorName, 'updated_at' => now(), ]); $newQuan--; @@ -727,6 +732,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => $newInsQty, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -746,6 +753,7 @@ class CreateInvoiceValidation extends CreateRecord $existEmpRecQty->update([ 'quantity' => $newInsQty, 'operator_id' => $operatorName, + 'updated_by' => $operatorName, 'updated_at' => now(), ]); $newQuan--; @@ -757,6 +765,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => $newInsQty, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -780,6 +790,8 @@ class CreateInvoiceValidation extends CreateRecord ->send(); $this->dispatch('playNotificationSound'); + InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->update(['updated_by' => $operatorName]); // 'updated_at' => now(), + // Update total quantity in the form $totalQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); @@ -1232,6 +1244,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'serial_number' => $serialNumber, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -1254,6 +1268,8 @@ class CreateInvoiceValidation extends CreateRecord $this->dispatch('playNotificationSound'); + InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->update(['updated_by' => $operatorName]); // 'updated_at' => now(), + // Update total quantity in the form $totalQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count(); @@ -1777,6 +1793,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => 1, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -1810,6 +1828,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => $bundleQty, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -1841,6 +1861,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'quantity' => $totalExcelQty, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -2205,6 +2227,8 @@ class CreateInvoiceValidation extends CreateRecord 'invoice_number' => $invoiceNumber, 'serial_number' => $serialNumber, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); $inserted++; } @@ -2949,6 +2973,7 @@ class CreateInvoiceValidation extends CreateRecord if ($curExistQty > $curScanQty) { // 5 > 2 $record->quantity = $curExistQty - $curScanQty; // 5 - 2 $record->operator_id = $operatorName; + // $record->updated_by = $operatorName; // $record->updated_at = now(); $record->save(); @@ -2961,12 +2986,15 @@ class CreateInvoiceValidation extends CreateRecord 'quantity' => $curScanQty, 'created_at' => $createdDt, 'operator_id' => $operatorName, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, ]); } elseif ($curExistQty == $curScanQty) { // 2 = 2 // $record->delete(); $record->serial_number = $serialNumber; $record->batch_number = $batchNumber; $record->operator_id = $operatorName; + // $record->updated_by = $operatorName; // $record->updated_at = now(); $record->save(); @@ -2977,6 +3005,8 @@ class CreateInvoiceValidation extends CreateRecord // 'quantity' => $curScanQty, // 'created_at' => $createdDt, // 'operator_id'=> $operatorName, + // 'created_by' => $operatorName, + // 'updated_by' => $operatorName, // ]); } else { Notification::make() @@ -3032,6 +3062,7 @@ class CreateInvoiceValidation extends CreateRecord $record->batch_number = $batchNumber; // $record->updated_at = now(); $record->operator_id = $operatorName; + // $record->updated_by = $operatorName; $record->save(); } @@ -3400,6 +3431,7 @@ class CreateInvoiceValidation extends CreateRecord $record->scanned_status = 'Scanned'; } $record->operator_id = $operatorName; + // $record->updated_by = $operatorName; $record->save(); // Notification::make() @@ -3516,6 +3548,7 @@ class CreateInvoiceValidation extends CreateRecord $record->scanned_status = 'Scanned'; } $record->operator_id = $operatorName; + // $record->updated_by = $operatorName; $record->save(); // Notification::make() @@ -3698,6 +3731,7 @@ class CreateInvoiceValidation extends CreateRecord $record->scanned_status = 'Scanned'; } $record->operator_id = $operatorName; + // $record->updated_by = $operatorName; $record->save(); // Notification::make() diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index dbc5c35..86de298 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -5,7 +5,7 @@ namespace App\Filament\Resources; use App\Filament\Exports\UserExporter; use App\Filament\Imports\UserImporter; use App\Filament\Resources\UserResource\Pages; -use App\Filament\Resources\UserResource\RelationManagers; +use App\Models\Plant; use App\Models\User; use Filament\Facades\Filament; use Filament\Forms; @@ -36,16 +36,21 @@ class UserResource extends Resource ->relationship('plant', 'name') ->nullable() ->reactive() + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) ->default(function () { return optional(User::latest()->first())->plant_id; }), Forms\Components\TextInput::make('name') ->required() ->autofocus() - //->reactive() + // ->reactive() ->live(debounce: 600) ->afterStateUpdated(function ($state, callable $set, callable $get) { - $set('email', $state . '@cripumps.com'); + $set('email', $state.'@cripumps.com'); }) ->maxLength(255), Forms\Components\TextInput::make('email') @@ -58,7 +63,7 @@ class UserResource extends Resource // ->ignore($get('id')); // Ignore current record during updates // }) ->reactive() - //->prefix(fn ($get) => $get('name') ?? null) + // ->prefix(fn ($get) => $get('name') ?? null) // ->suffix('@cripumps.com') ->maxLength(255), Forms\Components\DateTimePicker::make('email_verified_at'), @@ -73,7 +78,7 @@ class UserResource extends Resource // ->relationship('roles', 'name'), Forms\Components\Select::make('roles') ->relationship('roles', 'name') - //->relationship(name: 'roles', titleAttribute: 'name') + // ->relationship(name: 'roles', titleAttribute: 'name') // ->saveRelationshipsUsing(function (Model $record, $state) { // $record->roles()->syncWithPivotValues($state, [config('permission.column_names.team_foreign_key') => getPermissionsTeamId()]); // }) @@ -101,6 +106,7 @@ class UserResource extends Resource $paginator = $livewire->getTableRecords(); $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; + return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), Tables\Columns\TextColumn::make('plant.name') @@ -165,14 +171,14 @@ class UserResource extends Resource ->label('Import Users') ->color('warning') ->importer(UserImporter::class) - ->visible(function() { + ->visible(function () { return Filament::auth()->user()->can('view import user'); }), ExportAction::make() ->label('Export Users') ->color('warning') ->exporter(UserExporter::class) - ->visible(function() { + ->visible(function () { return Filament::auth()->user()->can('view export user'); }), ]); diff --git a/app/Livewire/InvoiceDataTable.php b/app/Livewire/InvoiceDataTable.php index 048206f..71307b1 100644 --- a/app/Livewire/InvoiceDataTable.php +++ b/app/Livewire/InvoiceDataTable.php @@ -6,17 +6,17 @@ use App\Models\InvoiceValidation; use App\Models\StickerMaster; use Filament\Facades\Filament; use Filament\Notifications\Notification; -use Livewire\Component; -use Str; use Livewire\Attributes\On; +use Livewire\Component; use Livewire\WithPagination; +use Str; class InvoiceDataTable extends Component { - use WithPagination; protected $paginationTheme = 'tailwind'; + public $invoiceData = []; // public $invoiceRecords; @@ -25,7 +25,6 @@ class InvoiceDataTable extends Component public $package = []; - public $packageCount = 0; public string $invoiceNumber = ''; @@ -58,7 +57,7 @@ class InvoiceDataTable extends Component public $panel_box_supplier; - public $panel_box_item_code; + public $panel_box_code; public $panel_box_serial_number; @@ -187,126 +186,124 @@ class InvoiceDataTable extends Component // } // } -// public function loadData($invoiceNumber, $plantId, $onCapFocus = false) -// { -// $this->invoiceNumber = $invoiceNumber; -// $this->plantId = $plantId; + // public function loadData($invoiceNumber, $plantId, $onCapFocus = false) + // { + // $this->invoiceNumber = $invoiceNumber; + // $this->plantId = $plantId; -// $this->completedInvoice = false; -// $this->isSerial = true; -// $this->onCapFocus = $onCapFocus; -// $this->emptyInvoice = false; -// $this->hasSearched = true; -// $this->materialInvoice = false; + // $this->completedInvoice = false; + // $this->isSerial = true; + // $this->onCapFocus = $onCapFocus; + // $this->emptyInvoice = false; + // $this->hasSearched = true; + // $this->materialInvoice = false; -// $this->resetPage(); + // $this->resetPage(); -// $this->packageCount = 0; + // $this->packageCount = 0; -// // IMPORTANT: keep scanned rows, otherwise count will not update -// $this->invoiceRecords = InvoiceValidation::with('stickerMasterRelation') -// ->where('invoice_number', $this->invoiceNumber) -// ->where('plant_id', $this->plantId) -// ->get(); + // // IMPORTANT: keep scanned rows, otherwise count will not update + // $this->invoiceRecords = InvoiceValidation::with('stickerMasterRelation') + // ->where('invoice_number', $this->invoiceNumber) + // ->where('plant_id', $this->plantId) + // ->get(); -// foreach ($this->invoiceRecords as &$row) { + // foreach ($this->invoiceRecords as &$row) { -// $stickCount = 0; -// $scannedCount = 0; + // $stickCount = 0; + // $scannedCount = 0; -// // Get item code -// $row['code'] = StickerMaster::with('item') -// ->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A'; + // // Get item code + // $row['code'] = StickerMaster::with('item') + // ->find($row['sticker_master_id'] ?? null)?->item?->code ?? 'N/A'; -// $curStick = StickerMaster::find($row['sticker_master_id']); + // $curStick = StickerMaster::find($row['sticker_master_id']); -// if ($curStick) { + // if ($curStick) { -// /** ---------------- REQUIRED STICKERS ---------------- */ + // /** ---------------- REQUIRED STICKERS ---------------- */ -// // PANEL BOX (capacitor) -// if (!empty($curStick->panel_box_code)) { -// $stickCount++; + // // PANEL BOX (capacitor) + // if (!empty($curStick->panel_box_code)) { + // $stickCount++; -// // Panel box scan = capacitor_scanned_status -// if ($row['capacitor_scanned_status'] == 1) { -// $scannedCount++; -// } -// } + // // Panel box scan = capacitor_scanned_status + // if ($row['capacitor_scanned_status'] == 1) { + // $scannedCount++; + // } + // } -// // Tube stickers -// if ( -// $curStick->tube_sticker_motor == 1 || -// $curStick->tube_sticker_pump == 1 || -// $curStick->tube_sticker_pumpset == 1 -// ) { -// if ($curStick->tube_sticker_motor == 1) { -// $stickCount++; -// if ($row['motor_scanned_status'] == 1) { -// $scannedCount++; -// } -// } + // // Tube stickers + // if ( + // $curStick->tube_sticker_motor == 1 || + // $curStick->tube_sticker_pump == 1 || + // $curStick->tube_sticker_pumpset == 1 + // ) { + // if ($curStick->tube_sticker_motor == 1) { + // $stickCount++; + // if ($row['motor_scanned_status'] == 1) { + // $scannedCount++; + // } + // } -// if ( -// $curStick->tube_sticker_pump == 1 || -// ($curStick->tube_sticker_pumpset != 1 && -// $curStick->tube_sticker_pump != 1 && -// $curStick->pack_slip_pump == 1) -// ) { -// $stickCount++; -// if ($row['pump_scanned_status'] == 1) { -// $scannedCount++; -// } -// } + // if ( + // $curStick->tube_sticker_pump == 1 || + // ($curStick->tube_sticker_pumpset != 1 && + // $curStick->tube_sticker_pump != 1 && + // $curStick->pack_slip_pump == 1) + // ) { + // $stickCount++; + // if ($row['pump_scanned_status'] == 1) { + // $scannedCount++; + // } + // } -// if ($curStick->tube_sticker_pumpset == 1) { -// $stickCount++; -// if ($row['scanned_status_set'] == 1) { -// $scannedCount++; -// } -// } -// } + // if ($curStick->tube_sticker_pumpset == 1) { + // $stickCount++; + // if ($row['scanned_status_set'] == 1) { + // $scannedCount++; + // } + // } + // } -// // Pack slips (only if no tube stickers) -// elseif ( -// $curStick->pack_slip_motor == 1 || -// $curStick->pack_slip_pump == 1 || -// $curStick->pack_slip_pumpset == 1 -// ) { -// if ($curStick->pack_slip_motor == 1) { -// $stickCount++; -// if ($row['motor_scanned_status'] == 1) { -// $scannedCount++; -// } -// } + // // Pack slips (only if no tube stickers) + // elseif ( + // $curStick->pack_slip_motor == 1 || + // $curStick->pack_slip_pump == 1 || + // $curStick->pack_slip_pumpset == 1 + // ) { + // if ($curStick->pack_slip_motor == 1) { + // $stickCount++; + // if ($row['motor_scanned_status'] == 1) { + // $scannedCount++; + // } + // } -// if ($curStick->pack_slip_pump == 1) { -// $stickCount++; -// if ($row['pump_scanned_status'] == 1) { -// $scannedCount++; -// } -// } + // if ($curStick->pack_slip_pump == 1) { + // $stickCount++; + // if ($row['pump_scanned_status'] == 1) { + // $scannedCount++; + // } + // } -// if ($curStick->pack_slip_pumpset == 1) { -// $stickCount++; -// if ($row['scanned_status_set'] == 1) { -// $scannedCount++; -// } -// } -// } -// } + // if ($curStick->pack_slip_pumpset == 1) { + // $stickCount++; + // if ($row['scanned_status_set'] == 1) { + // $scannedCount++; + // } + // } + // } + // } -// // SAFETY: never go negative -// $this->packageCount += max($stickCount - $scannedCount, 0); -// } - -// $this->dispatch($onCapFocus ? 'focus-capacitor-input' : 'focus-serial-number'); -// } + // // SAFETY: never go negative + // $this->packageCount += max($stickCount - $scannedCount, 0); + // } + // $this->dispatch($onCapFocus ? 'focus-capacitor-input' : 'focus-serial-number'); + // } // #[On('refreshInvoiceData')] - // public function loadData($invoiceNumber, $plantId, $onCapFocus = false) // { // $this->invoiceNumber = $invoiceNumber; @@ -371,7 +368,6 @@ class InvoiceDataTable extends Component // $this->dispatch($onCapFocus ? 'focus-capacitor-input' : 'focus-serial-number'); // } - public function loadData($invoiceNumber, $plantId, $onCapFocus = false) { $this->invoiceNumber = $invoiceNumber; @@ -396,24 +392,23 @@ class InvoiceDataTable extends Component $sm = $record->stickerMasterRelation; - if (!$sm) { + if (! $sm) { return 0; } - $stickCount = 0; + $stickCount = 0; $scannedCount = 0; - if (!empty($sm->panel_box_code)) { + if (! empty($sm->panel_box_code)) { $stickCount++; if ($record->capacitor_scanned_status == 1) { $scannedCount++; } } - if ($sm->tube_sticker_motor == 1 || $sm->tube_sticker_pump == 1 || $sm->tube_sticker_pumpset == 1){ + if ($sm->tube_sticker_motor == 1 || $sm->tube_sticker_pump == 1 || $sm->tube_sticker_pumpset == 1) { - if ($sm->tube_sticker_motor == 1) - { + if ($sm->tube_sticker_motor == 1) { $stickCount++; if ($record->motor_scanned_status == 1) { $scannedCount++; @@ -438,9 +433,7 @@ class InvoiceDataTable extends Component $scannedCount++; } } - } - elseif ($sm->pack_slip_motor == 1 || $sm->pack_slip_pump == 1 || $sm->pack_slip_pumpset == 1) - { + } elseif ($sm->pack_slip_motor == 1 || $sm->pack_slip_pump == 1 || $sm->pack_slip_pumpset == 1) { if ($sm->pack_slip_motor == 1) { $stickCount++; if ($record->motor_scanned_status == 1) { @@ -488,7 +481,6 @@ class InvoiceDataTable extends Component ->paginate(6); } - // public function loadData($invoiceNumber, $plantId, $onCapFocus = false) // { // $this->plantId = $plantId; @@ -571,7 +563,6 @@ class InvoiceDataTable extends Component // } // } - public function loadMaterialData($invoiceNumber, $plantId) { $this->plantId = $plantId; @@ -636,6 +627,7 @@ class InvoiceDataTable extends Component public function cancelCapacitorInput() { + $this->capacitorInput = null; $this->showCapacitorInput = false; $this->dispatch('focus-serial-number'); } @@ -689,7 +681,7 @@ class InvoiceDataTable extends Component // if (($row['code'] ?? '') === $this->currentItemCode && ($row['serial_number'] ?? '') === $this->currentSerialNumber) { // $row['panel_box_supplier'] = $supplier; - // $row['panel_box_item_code'] = $itemCode; + // $row['panel_box_code'] = $itemCode; // $row['panel_box_serial_number'] = $serialNumber; // $row['capacitor_scanned_status'] = 1; // // $row['scanned_status_set'] = true; @@ -730,7 +722,7 @@ class InvoiceDataTable extends Component // if ($packCnt === $scanCnt) { // $matchingValidation->update([ // 'panel_box_supplier' => $supplier, - // 'panel_box_item_code' => $itemCode, + // 'panel_box_code' => $itemCode, // 'panel_box_serial_number' => $serialNumber, // 'capacitor_scanned_status' => 1, // 'scanned_status' => 'Scanned', @@ -739,7 +731,7 @@ class InvoiceDataTable extends Component // } else { // $matchingValidation->update([ // 'panel_box_supplier' => $supplier, - // 'panel_box_item_code' => $itemCode, + // 'panel_box_code' => $itemCode, // 'panel_box_serial_number' => $serialNumber, // 'capacitor_scanned_status' => 1, // 'operator_id' => $operatorName, @@ -748,7 +740,7 @@ class InvoiceDataTable extends Component // } else { // $matchingValidation->update([ // 'panel_box_supplier' => $supplier, - // 'panel_box_item_code' => $itemCode, + // 'panel_box_code' => $itemCode, // 'panel_box_serial_number' => $serialNumber, // 'capacitor_scanned_status' => 1, // 'scanned_status' => 'Scanned', @@ -797,8 +789,6 @@ class InvoiceDataTable extends Component // $this->dispatch('focus-serial-number'); // } - - public function processCapacitorInput() { $user = Filament::auth()->user(); @@ -818,6 +808,7 @@ class InvoiceDataTable extends Component ->send(); $this->capacitorInput = ''; + return; } @@ -856,7 +847,7 @@ class InvoiceDataTable extends Component if ($stickerCode === $this->currentItemCode && $serialNo === $this->currentSerialNumber) { $row['panel_box_supplier'] = $supplier; - $row['panel_box_item_code'] = $itemCode; + $row['panel_box_code'] = $itemCode; $row['panel_box_serial_number'] = $serialNumber; $row['capacitor_scanned_status'] = 1; // $row['scanned_status_set'] = true; @@ -869,7 +860,7 @@ class InvoiceDataTable extends Component return $validation->stickerMaster?->item?->code === $this->currentItemCode; }); - // dd($matchingValidation); + // dd($matchingValidation); if ($matchingValidation) { $hasMotorQr = $matchingValidation->stickerMasterRelation->tube_sticker_motor ?? null; @@ -897,7 +888,7 @@ class InvoiceDataTable extends Component if ($packCnt === $scanCnt) { $matchingValidation->update([ 'panel_box_supplier' => $supplier, - 'panel_box_item_code' => $itemCode, + 'panel_box_code' => $itemCode, 'panel_box_serial_number' => $serialNumber, 'capacitor_scanned_status' => 1, 'scanned_status' => 'Scanned', @@ -906,7 +897,7 @@ class InvoiceDataTable extends Component } else { $matchingValidation->update([ 'panel_box_supplier' => $supplier, - 'panel_box_item_code' => $itemCode, + 'panel_box_code' => $itemCode, 'panel_box_serial_number' => $serialNumber, 'capacitor_scanned_status' => 1, 'operator_id' => $operatorName, @@ -915,7 +906,7 @@ class InvoiceDataTable extends Component } else { $matchingValidation->update([ 'panel_box_supplier' => $supplier, - 'panel_box_item_code' => $itemCode, + 'panel_box_code' => $itemCode, 'panel_box_serial_number' => $serialNumber, 'capacitor_scanned_status' => 1, 'scanned_status' => 'Scanned', diff --git a/app/Models/InvoiceValidation.php b/app/Models/InvoiceValidation.php index 0413a71..9245695 100644 --- a/app/Models/InvoiceValidation.php +++ b/app/Models/InvoiceValidation.php @@ -23,6 +23,7 @@ class InvoiceValidation extends Model 'capacitor_scanned_status', 'scanned_status_set', 'scanned_status', + 'panel_box_code', 'panel_box_supplier', 'panel_box_serial_number', 'load_rate', @@ -30,6 +31,8 @@ class InvoiceValidation extends Model 'batch_number', 'quantity', 'operator_id', + 'created_by', + 'updated_by', ]; public function plant(): BelongsTo diff --git a/database/migrations/2025_04_08_083322_create_invoice_validations_table.php b/database/migrations/2025_04_08_083322_create_invoice_validations_table.php index 4cfcbda..0d6f849 100644 --- a/database/migrations/2025_04_08_083322_create_invoice_validations_table.php +++ b/database/migrations/2025_04_08_083322_create_invoice_validations_table.php @@ -1,7 +1,6 @@ Scanned Status