186 lines
6.6 KiB
PHP
186 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\InvoiceValidationResource\Pages;
|
|
use App\Models\InvoiceValidation;
|
|
use App\Models\StickerMaster;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Section;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Forms\Components\View;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Tables\Actions\Action;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Livewire\Livewire; // Ensure this is imported
|
|
|
|
class InvoiceValidationResource extends Resource
|
|
{
|
|
protected static ?string $model = InvoiceValidation::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Invoice';
|
|
|
|
public $invoiceNumber;
|
|
|
|
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
// Forms\Components\Hidden::make('sticker_master_id')
|
|
// //->relationship('stickerMaster', 'id')
|
|
// ->required(),
|
|
|
|
Section::make('')
|
|
->schema([
|
|
|
|
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')
|
|
->extraAttributes([
|
|
'x-data' => '{ value: "" }',
|
|
'x-model' => 'value',
|
|
'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown
|
|
])
|
|
|
|
->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),
|
|
]);
|
|
}
|
|
|
|
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(),
|
|
])
|
|
|
|
->headerActions([
|
|
Tables\Actions\Action::make('Import Serial Number')
|
|
->label('Import Serial Number')
|
|
->form([
|
|
FileUpload::make('invoice_serial_number')
|
|
->label('Invoice Serial Number')
|
|
->preserveFilenames() // <- this keeps the original filename
|
|
->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.
|
|
->directory('uploads/temp'), //storage/app/uploads/temp
|
|
])
|
|
|
|
->action(function (array $data) {
|
|
$uploadedFile = $data['invoice_serial_number'];
|
|
|
|
// Get original filename
|
|
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
|
|
|
// Store manually using storeAs to keep original name
|
|
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
|
|
|
|
$fullPath = Storage::disk('local')->path($path);
|
|
|
|
// Save full file path to session
|
|
session(['uploaded_invoice_path' => $fullPath]);
|
|
|
|
// session()->flash('just_uploaded_invoice', true); // 👈 add this
|
|
|
|
Notification::make()
|
|
->title('File Uploaded. Continue in Create Page.')
|
|
->success()
|
|
->send();
|
|
}),
|
|
|
|
Tables\Actions\Action::make('Import Invoice Material')
|
|
->label('Import Invoice Material')
|
|
->form([
|
|
FileUpload::make('invoice_material')
|
|
->label('Invoice Material')
|
|
->required(),
|
|
])
|
|
]);
|
|
|
|
// ->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,
|
|
]);
|
|
}
|
|
}
|