diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php new file mode 100644 index 000000000..13a981735 --- /dev/null +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -0,0 +1,155 @@ +schema([ + Forms\Components\Hidden::make('sticker_master_id') + //->relationship('stickerMaster', 'id') + ->required(), + + Section::make('') + ->schema([ + + // FileUpload::make('excel_file') + // ->label('Choose Excel File') + // ->disk('local') + // ->columnSpan(1), + + Forms\Components\Select::make('plant_id') + ->relationship('plant', 'name') + ->required(), + + Forms\Components\TextInput::make('invoice_number') + ->required() + ->label('Invoice Number') + ->columnSpan(1) + ->extraAttributes([ + 'x-data' => '{ value: "" }', + 'x-model' => 'value', + 'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)', + ]), + + Forms\Components\TextInput::make('serial_number') + //->required() + ->reactive() + ->columnSpan(1), + + Forms\Components\TextInput::make('total_quantity') + ->label('Total Quantity') + ->columnSpan(1), + Forms\Components\TextInput::make('scanned_quantity') + ->label('Scanned Quantity') + ->columnSpan(1), + + ]) + ->columns(5), + + // View::make('livewire.invoice-data-table') + // ->label('Invoice Details') + // ->viewData([ + // 'invoiceData' => fn ($get) => $get('invoice_data') ?? [], // Changed from invoiceData to invoice_data + // ]) + // ->columnSpan('full'), + ]); + } + + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('id') + ->label('ID') + ->numeric() + ->sortable(), + Tables\Columns\TextColumn::make('stickerMaster.id') + ->numeric() + ->sortable(), + Tables\Columns\TextColumn::make('plant.name') + ->numeric() + ->sortable(), + Tables\Columns\TextColumn::make('load_rate') + ->numeric() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('deleted_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + Tables\Filters\TrashedFilter::make(), + ]) + ->actions([ + Tables\Actions\ViewAction::make(), + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), + ]), + ]); + } + + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListInvoiceValidations::route('/'), + 'create' => Pages\CreateInvoiceValidation::route('/create'), + 'view' => Pages\ViewInvoiceValidation::route('/{record}'), + 'edit' => Pages\EditInvoiceValidation::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php new file mode 100644 index 000000000..d2c5b3d19 --- /dev/null +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php @@ -0,0 +1,131 @@ +invoice_number = $invoiceNumber; + + // Check if the file is uploaded + if (!$this->excel_file) { + Notification::make() + ->title('No File Uploaded') + ->body("Please upload an Excel file to proceed with invoice: {$invoiceNumber}.") + ->danger() + ->persistent() + ->send(); + return; + } + + $localPath = $this->excel_file->getPath(); + + // Check if file exists + if (!file_exists($localPath)) { + Notification::make() + ->title('File Not Found') + ->body("No Excel file found for invoice: {$invoiceNumber}. Please ensure the file exists in your Downloads folder.") + ->danger() + ->persistent() + ->send(); + return; + } + + + try { + $rows = \Maatwebsite\Excel\Facades\Excel::toArray([], $localPath)[0] ?? []; + array_shift($rows); + + if (empty($rows)) { + Notification::make() + ->title('Empty File') + ->body('The Excel file contains no data rows') + ->danger() + ->send(); + return; + } + + $validRecords = []; + $invalidMaterials = []; + + foreach ($rows as $row) { + $materialCode = $row[0] ?? null; + $serialNumber = $row[1] ?? null; + + if (!\App\Models\StickerMaster::where('item_id', $materialCode)->exists()) { + $invalidMaterials[] = $materialCode; + continue; + } + + $validRecords[] = [ + 'material_code' => $materialCode, + 'serial_number' => $serialNumber, + 'invoice_number' => $invoiceNumber, + 'created_at' => now(), + 'updated_at' => now(), + ]; + } + + if (!empty($invalidMaterials)) { + Notification::make() + ->title('Invalid Materials') + ->body('These codes not found: ' . implode(', ', array_unique($invalidMaterials))) + ->danger() + ->send(); + return; + } + + \DB::table('invoice_validations')->insert($validRecords); + + $this->invoice_data = $validRecords; + $this->scanned_quantity = count($validRecords); + $this->total_quantity = count($validRecords); + + Notification::make() + ->title('Success') + ->body(count($validRecords) . ' records inserted successfully') + ->success() + ->send(); + } catch (\Exception $e) { + Notification::make() + ->title('Error') + ->body($e->getMessage()) + ->danger() + ->send(); + } + } + + public function getHeading(): string + { + return 'Scan Invoice Validation'; + } + + // public function render(): View + // { + // return view('filament.resources.invoice-validation-resource.pages.create-invoice-validation'); + // } + +} diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/EditInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/EditInvoiceValidation.php new file mode 100644 index 000000000..1d5b8aad9 --- /dev/null +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/EditInvoiceValidation.php @@ -0,0 +1,22 @@ + 'loadData']; + + public function mount() + { + $this->loadData(); + + } + + public function loadData() + { + $this->invoiceData = InvoiceValidation::all()->toArray(); + } + + public function render() + { + // Always fetch fresh data when Livewire re-renders (like via polling) + $invoiceData = InvoiceValidation::latest()->get(); + + return view('livewire.invoice-data-table', [ + 'invoiceData' => $invoiceData, + ]); + // return view('livewire.invoice-data-table', [ + // 'invoiceData' => $this->invoiceData, // <--- this is important + // ]); + } + + +} diff --git a/app/Models/InvoiceValidation.php b/app/Models/InvoiceValidation.php new file mode 100644 index 000000000..5bf76a89a --- /dev/null +++ b/app/Models/InvoiceValidation.php @@ -0,0 +1,42 @@ +belongsTo(Plant::class); + } + + public function stickerMaster(): BelongsTo + { + return $this->belongsTo(StickerMaster::class); + } + + +} 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 new file mode 100644 index 000000000..489132b69 --- /dev/null +++ b/database/migrations/2025_04_08_083322_create_invoice_validations_table.php @@ -0,0 +1,60 @@ + + {{ $this->form }} + + {{-- @livewire('invoice-data-table') --}} + + + diff --git a/resources/views/livewire/invoice-data-table.blade.php b/resources/views/livewire/invoice-data-table.blade.php new file mode 100644 index 000000000..cdf33bdfe --- /dev/null +++ b/resources/views/livewire/invoice-data-table.blade.php @@ -0,0 +1,45 @@ +
+
+

INVOICE DATA TABLE

+
+
+
+
+ + + + + + + + + + + + + + + + + + @forelse ($invoiceData as $index => $row) + + + + + + + + + + + + + @empty + + + + @endforelse + +
NoMaterial CodeSerial NumberMotor Scanned StatusPump Scanned StatusCapacitor Scanned StatusScanned Status SetPanel Box SupplierPanel Box Serial NumberScanned Status
{{ $index + 1 }}{{ $row['material_code'] ?? 'N/A' }}{{ $row['serial_number'] ?? 'N/A' }}{{ $row['motor_scanned_status'] ?? 'N/A' }}{{ $row['pump_scanned_status'] ?? 'N/A' }}{{ $row['capacitor_scanned_status'] ?? 'N/A' }}{{ $row['scanned_status_set'] ?? 'N/A' }}{{ $row['panel_box_supplier'] ?? 'N/A' }}{{ $row['panel_box_serial_number'] ?? 'N/A' }}{{ $row['scanned_status'] ?? 'N/A' }}
No data available.
+