Added invoice upload directory creation file store logic on resource and create page
Some checks failed
Gemini PR Review / Gemini PR Review (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Waiting to run
Laravel Larastan / larastan (pull_request) Waiting to run
Laravel Pint / pint (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Gemini PR Review / Gemini PR Review (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Waiting to run
Laravel Larastan / larastan (pull_request) Waiting to run
Laravel Pint / pint (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -67,7 +67,7 @@ class InvoiceValidationResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(InvoiceValidation::latest()->first())->plant_id;
|
||||
@@ -332,7 +332,7 @@ class InvoiceValidationResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
->required()
|
||||
@@ -341,6 +341,13 @@ class InvoiceValidationResource extends Resource
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('invoice_serial_number', null);
|
||||
$plantId = $get('plant_id');
|
||||
$plantCode = Plant::find($plantId)?->code ?? null;
|
||||
|
||||
$directory = "uploads/temp/{$plantCode}";
|
||||
if ($plantId && ! Storage::disk('local')->exists($directory)) {
|
||||
Storage::disk('local')->makeDirectory($directory);
|
||||
}
|
||||
})
|
||||
->reactive(),
|
||||
|
||||
@@ -353,7 +360,12 @@ class InvoiceValidationResource extends Resource
|
||||
->required()
|
||||
->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('uploads/temp'),
|
||||
->directory(function (callable $get) {
|
||||
$plant = Plant::find($get('plant_id'));
|
||||
$plantCode = $plant?->code ?? null;
|
||||
|
||||
return "uploads/temp/{$plantCode}";
|
||||
}),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$uploadedFile = $data['invoice_serial_number'];
|
||||
@@ -362,17 +374,33 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
$plantId = $data['plant_id'];
|
||||
|
||||
$plant = Plant::find($plantId);
|
||||
$plantCode = $plant?->code ?? null;
|
||||
|
||||
// Get original filename
|
||||
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
||||
|
||||
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
||||
|
||||
// Store manually using storeAs to keep original name
|
||||
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
|
||||
// uploads/temp/3RA0018735.xlsx
|
||||
$path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); // returns relative path
|
||||
// uploads/temp/{$plantCode}/3RA0018735.xlsx
|
||||
|
||||
if ($originalNameOnly && strlen($originalNameOnly) < 8) {
|
||||
Notification::make()
|
||||
->title("Invoice number : '$originalNameOnly' should be greater than or equal to 8 characters!")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
// /home/iot-dev/projects/pds/storage/app/private/uploads/temp/3RA0018735.xlsx
|
||||
// /home/iot-dev/projects/pds/storage/app/private/uploads/temp/{$plantCode}/3RA0018735.xlsx
|
||||
|
||||
$totQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->count();
|
||||
if ($totQuan > 0) {
|
||||
@@ -637,7 +665,7 @@ class InvoiceValidationResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
->required()
|
||||
@@ -646,6 +674,13 @@ class InvoiceValidationResource extends Resource
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('invoice_material', null);
|
||||
$plantId = $get('plant_id');
|
||||
$plantCode = Plant::find($plantId)?->code ?? null;
|
||||
|
||||
$directory = "uploads/temp/{$plantCode}";
|
||||
if ($plantId && ! Storage::disk('local')->exists($directory)) {
|
||||
Storage::disk('local')->makeDirectory($directory);
|
||||
}
|
||||
})
|
||||
->reactive(),
|
||||
|
||||
@@ -657,13 +692,21 @@ class InvoiceValidationResource extends Resource
|
||||
->storeFiles(false) // prevent auto-storing
|
||||
->disk('local')
|
||||
->visible(fn (Get $get) => ! empty($get('plant_id')))
|
||||
->directory('uploads/temp'),
|
||||
->directory(function (callable $get) {
|
||||
$plant = Plant::find($get('plant_id'));
|
||||
$plantCode = $plant?->code ?? null;
|
||||
|
||||
return "uploads/temp/{$plantCode}";
|
||||
}),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$uploadedFile = $data['invoice_material'];
|
||||
|
||||
$plantId = $data['plant_id']; // Access the selected plant_id
|
||||
|
||||
$plant = Plant::find($plantId);
|
||||
$plantCode = $plant?->code ?? null;
|
||||
|
||||
$disk = Storage::disk('local');
|
||||
|
||||
// Get original filename
|
||||
@@ -671,7 +714,20 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
||||
|
||||
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local');
|
||||
$path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local');
|
||||
|
||||
if ($originalNameOnly && strlen($originalNameOnly) < 8) {
|
||||
Notification::make()
|
||||
->title("Invoice number : '$originalNameOnly' should be greater than or equal to 8 characters!")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
@@ -1073,7 +1129,7 @@ class InvoiceValidationResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||
|
||||
Reference in New Issue
Block a user