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
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user