Merge pull request 'ranjith-dev' (#293) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #293
This commit was merged in pull request #293.
This commit is contained in:
2026-02-03 07:04:24 +00:00
2 changed files with 89 additions and 26 deletions

View File

@@ -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;
@@ -77,7 +77,7 @@ class InvoiceValidationResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('update_invoice', null);
// Ensure `linestop_id` is not cleared
if (! $plantId) {
$set('invoice_number', null);
$set('serial_number', null);
@@ -87,6 +87,11 @@ class InvoiceValidationResource extends Resource
return;
} else {
$plantCode = Plant::find($plantId)?->code ?? null;
$directory = "uploads/temp/{$plantCode}";
if (! Storage::disk('local')->exists($directory)) {
Storage::disk('local')->makeDirectory($directory);
}
$set('ivPlantError', null);
}
})
@@ -332,7 +337,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 +346,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 +365,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 +379,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 +670,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 +679,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 +697,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 +719,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 +1134,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 {

View File

@@ -117,8 +117,8 @@ class CreateInvoiceValidation extends CreateRecord
$this->plantId = $plantId;
// $plant = Plant::find($plantId);
// $plantCode = $plant ? $plant->code : null;
$plant = Plant::find($plantId);
$plantCode = $plant?->code ?? null;
// ..GET SERIAL INVOICE API
@@ -233,7 +233,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -266,7 +266,7 @@ class CreateInvoiceValidation extends CreateRecord
if ($updateStatus == '1') {
// 'Material invoice update in progress...';
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
$fullPath = $disk->path($filePath);
@@ -877,7 +877,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -907,16 +907,15 @@ class CreateInvoiceValidation extends CreateRecord
if ($updateStatus == '1') {
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
$fullPath = $disk->path($filePath);
// Check if file exists //if ($disk->exists($filePath))
if ($fullPath && file_exists($fullPath)) {
// /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
// 'Serial invoice update in progress...'
// Now you can read/process the file here
$rows = Excel::toArray(null, $fullPath)[0];
@@ -1337,7 +1336,7 @@ class CreateInvoiceValidation extends CreateRecord
}
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
$fullPath = null; // $fullPath = $disk->path($filePath);
@@ -2358,6 +2357,9 @@ class CreateInvoiceValidation extends CreateRecord
$invoiceNumber = $this->form->getState()['invoice_number'];
$this->invoiceNumber = $invoiceNumber;
$plant = Plant::find($plantId);
$plantCode = $plant?->code ?? null;
$totQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
$scanSQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
$totMQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('quantity')->where('plant_id', $plantId)->count(); // ->where('quantity', '!=', '')
@@ -2395,7 +2397,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -3055,7 +3057,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -3099,7 +3101,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -3427,7 +3429,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -3544,7 +3546,7 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('playNotificationSound');
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;
@@ -3740,7 +3742,7 @@ class CreateInvoiceValidation extends CreateRecord
// }
$filename = $invoiceNumber.'.xlsx';
$directory = 'uploads/temp';
$directory = "uploads/temp/{$plantCode}";
$disk = Storage::disk('local');
$filePath = $directory.'/'.$filename;
// $fullPath = null;