Added 'created_by' and 'updated_by' columns to InvoiceValidationResource table and updated file upload validation for .xlsx file (serial / material invoice)
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-02-03 20:51:12 +05:30
parent 951a69b85e
commit bdd8e9dfc3

View File

@@ -212,6 +212,14 @@ class InvoiceValidationResource extends Resource
Forms\Components\TextInput::make('id') Forms\Components\TextInput::make('id')
->hidden() ->hidden()
->readOnly(true), ->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), ->columns(5),
]); ]);
@@ -267,9 +275,11 @@ class InvoiceValidationResource extends Resource
Tables\Columns\TextColumn::make('scanned_status') Tables\Columns\TextColumn::make('scanned_status')
->label('Scanned Status') ->label('Scanned Status')
->alignCenter(), ->alignCenter(),
// Tables\Columns\TextColumn::make('stickerMaster.panel_box_code') Tables\Columns\TextColumn::make('panel_box_code')// stickerMaster.panel_box_code
// ->label('Panel Box Code') ->label('Panel Box Code')
// ->alignCenter(), ->alignCenter()
->sortable(), // ->searchable()
// ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('panel_box_supplier') Tables\Columns\TextColumn::make('panel_box_supplier')
->label('Panel Box Supplier') ->label('Panel Box Supplier')
->alignCenter(), ->alignCenter(),
@@ -294,11 +304,20 @@ class InvoiceValidationResource extends Resource
->label('Plant') ->label('Plant')
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_by')
->label('Created By')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->label('Created At') ->label('Created At')
->dateTime() ->dateTime()
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated By')
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at') Tables\Columns\TextColumn::make('updated_at')
->label('Updated At') ->label('Updated At')
->dateTime() ->dateTime()
@@ -358,11 +377,15 @@ class InvoiceValidationResource extends Resource
FileUpload::make('invoice_serial_number') FileUpload::make('invoice_serial_number')
->label('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() ->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. ->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'))) ->visible(fn (Get $get) => ! empty($get('plant_id')))
->directory(function (callable $get) { ->directory(function (callable $get) {
@@ -370,7 +393,9 @@ class InvoiceValidationResource extends Resource
$plantCode = $plant?->code ?? null; $plantCode = $plant?->code ?? null;
return "uploads/temp/{$plantCode}"; return "uploads/temp/{$plantCode}";
}), })
->uploadingMessage('Uploading...')
->helperText('Only .xlsx files are allowed (Excel files).'),
]) ])
->action(function (array $data) { ->action(function (array $data) {
$uploadedFile = $data['invoice_serial_number']; $uploadedFile = $data['invoice_serial_number'];
@@ -385,15 +410,22 @@ class InvoiceValidationResource extends Resource
// Get original filename // Get original filename
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx $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); $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
$originalName = "{$originalNameOnly}.xlsx";
// Store manually using storeAs to keep original name // Store manually using storeAs to keep original name
$path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); // returns relative path $path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); // returns relative path
// uploads/temp/{$plantCode}/3RA0018735.xlsx // uploads/temp/{$plantCode}/3RA0018735.xlsx
if ($originalNameOnly && strlen($originalNameOnly) < 8) { if (strlen($originalNameOnly) < 8 || ! ctype_alnum($originalNameOnly)) {
Notification::make() 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() ->danger()
->send(); ->send();
@@ -692,8 +724,8 @@ class InvoiceValidationResource extends Resource
FileUpload::make('invoice_material') FileUpload::make('invoice_material')
->label('Invoice Material') ->label('Invoice Material')
->required() ->required()
->preserveFilenames() ->preserveFilenames() // <- this keeps the original filename
->reactive() // <- this keeps the original filename ->reactive()
->storeFiles(false) // prevent auto-storing ->storeFiles(false) // prevent auto-storing
->disk('local') ->disk('local')
->visible(fn (Get $get) => ! empty($get('plant_id'))) ->visible(fn (Get $get) => ! empty($get('plant_id')))
@@ -702,7 +734,8 @@ class InvoiceValidationResource extends Resource
$plantCode = $plant?->code ?? null; $plantCode = $plant?->code ?? null;
return "uploads/temp/{$plantCode}"; return "uploads/temp/{$plantCode}";
}), })
->helperText('Only .xlsx files are allowed (Excel files).'),
]) ])
->action(function (array $data) { ->action(function (array $data) {
$uploadedFile = $data['invoice_material']; $uploadedFile = $data['invoice_material'];
@@ -717,13 +750,20 @@ class InvoiceValidationResource extends Resource
// Get original filename // Get original filename
$originalName = $uploadedFile->getClientOriginalName(); $originalName = $uploadedFile->getClientOriginalName();
$extension = strtolower(pathinfo($originalName, PATHINFO_EXTENSION));
if ($extension !== 'xlsx') {
throw new \Exception('Only .xlsx files allowed.');
}
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
$originalName = "{$originalNameOnly}.xlsx";
$path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); $path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local');
if ($originalNameOnly && strlen($originalNameOnly) < 8) { if (strlen($originalNameOnly) < 8 || ! ctype_alnum($originalNameOnly)) {
Notification::make() 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() ->danger()
->send(); ->send();