ranjith-dev #293
@@ -67,7 +67,7 @@ class InvoiceValidationResource extends Resource
|
|||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$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 () {
|
->default(function () {
|
||||||
return optional(InvoiceValidation::latest()->first())->plant_id;
|
return optional(InvoiceValidation::latest()->first())->plant_id;
|
||||||
@@ -332,7 +332,7 @@ class InvoiceValidationResource extends Resource
|
|||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$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')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
@@ -341,6 +341,13 @@ class InvoiceValidationResource extends Resource
|
|||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('invoice_serial_number', null);
|
$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(),
|
->reactive(),
|
||||||
|
|
||||||
@@ -353,7 +360,12 @@ class InvoiceValidationResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
->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('uploads/temp'),
|
->directory(function (callable $get) {
|
||||||
|
$plant = Plant::find($get('plant_id'));
|
||||||
|
$plantCode = $plant?->code ?? null;
|
||||||
|
|
||||||
|
return "uploads/temp/{$plantCode}";
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
->action(function (array $data) {
|
->action(function (array $data) {
|
||||||
$uploadedFile = $data['invoice_serial_number'];
|
$uploadedFile = $data['invoice_serial_number'];
|
||||||
@@ -362,17 +374,33 @@ class InvoiceValidationResource extends Resource
|
|||||||
|
|
||||||
$plantId = $data['plant_id'];
|
$plantId = $data['plant_id'];
|
||||||
|
|
||||||
|
$plant = Plant::find($plantId);
|
||||||
|
$plantCode = $plant?->code ?? null;
|
||||||
|
|
||||||
// Get original filename
|
// Get original filename
|
||||||
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
||||||
|
|
||||||
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
||||||
|
|
||||||
// Store manually using storeAs to keep original name
|
// Store manually using storeAs to keep original name
|
||||||
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
|
$path = $uploadedFile->storeAs("uploads/temp/{$plantCode}", $originalName, 'local'); // returns relative path
|
||||||
// uploads/temp/3RA0018735.xlsx
|
// 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);
|
$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();
|
$totQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->count();
|
||||||
if ($totQuan > 0) {
|
if ($totQuan > 0) {
|
||||||
@@ -637,7 +665,7 @@ class InvoiceValidationResource extends Resource
|
|||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$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')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
@@ -646,6 +674,13 @@ class InvoiceValidationResource extends Resource
|
|||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('invoice_material', null);
|
$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(),
|
->reactive(),
|
||||||
|
|
||||||
@@ -657,13 +692,21 @@ class InvoiceValidationResource extends Resource
|
|||||||
->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')))
|
||||||
->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) {
|
->action(function (array $data) {
|
||||||
$uploadedFile = $data['invoice_material'];
|
$uploadedFile = $data['invoice_material'];
|
||||||
|
|
||||||
$plantId = $data['plant_id']; // Access the selected plant_id
|
$plantId = $data['plant_id']; // Access the selected plant_id
|
||||||
|
|
||||||
|
$plant = Plant::find($plantId);
|
||||||
|
$plantCode = $plant?->code ?? null;
|
||||||
|
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
|
|
||||||
// Get original filename
|
// Get original filename
|
||||||
@@ -671,7 +714,20 @@ class InvoiceValidationResource extends Resource
|
|||||||
|
|
||||||
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
$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);
|
$fullPath = Storage::disk('local')->path($path);
|
||||||
|
|
||||||
@@ -1073,7 +1129,7 @@ class InvoiceValidationResource extends Resource
|
|||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$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()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
$this->plantId = $plantId;
|
$this->plantId = $plantId;
|
||||||
|
|
||||||
// $plant = Plant::find($plantId);
|
$plant = Plant::find($plantId);
|
||||||
// $plantCode = $plant ? $plant->code : null;
|
$plantCode = $plant?->code ?? null;
|
||||||
|
|
||||||
// ..GET SERIAL INVOICE API
|
// ..GET SERIAL INVOICE API
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('playNotificationSound');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -266,7 +266,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
if ($updateStatus == '1') {
|
if ($updateStatus == '1') {
|
||||||
// 'Material invoice update in progress...';
|
// 'Material invoice update in progress...';
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
$fullPath = $disk->path($filePath);
|
$fullPath = $disk->path($filePath);
|
||||||
@@ -877,7 +877,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('playNotificationSound');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -907,16 +907,15 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
|
|
||||||
if ($updateStatus == '1') {
|
if ($updateStatus == '1') {
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
$fullPath = $disk->path($filePath);
|
$fullPath = $disk->path($filePath);
|
||||||
|
|
||||||
// Check if file exists //if ($disk->exists($filePath))
|
// Check if file exists //if ($disk->exists($filePath))
|
||||||
if ($fullPath && file_exists($fullPath)) {
|
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...'
|
// 'Serial invoice update in progress...'
|
||||||
|
|
||||||
// Now you can read/process the file here
|
// Now you can read/process the file here
|
||||||
$rows = Excel::toArray(null, $fullPath)[0];
|
$rows = Excel::toArray(null, $fullPath)[0];
|
||||||
|
|
||||||
@@ -1337,7 +1336,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
$fullPath = null; // $fullPath = $disk->path($filePath);
|
$fullPath = null; // $fullPath = $disk->path($filePath);
|
||||||
@@ -2358,6 +2357,9 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$invoiceNumber = $this->form->getState()['invoice_number'];
|
$invoiceNumber = $this->form->getState()['invoice_number'];
|
||||||
$this->invoiceNumber = $invoiceNumber;
|
$this->invoiceNumber = $invoiceNumber;
|
||||||
|
|
||||||
|
$plant = Plant::find($plantId);
|
||||||
|
$plantCode = $plant?->code ?? null;
|
||||||
|
|
||||||
$totQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
|
$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();
|
$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', '!=', '')
|
$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');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -3055,7 +3057,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('playNotificationSound');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -3099,7 +3101,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('playNotificationSound');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -3427,7 +3429,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('playNotificationSound');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -3544,7 +3546,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
$this->dispatch('playNotificationSound');
|
$this->dispatch('playNotificationSound');
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
@@ -3740,7 +3742,7 @@ class CreateInvoiceValidation extends CreateRecord
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
$filename = $invoiceNumber.'.xlsx';
|
$filename = $invoiceNumber.'.xlsx';
|
||||||
$directory = 'uploads/temp';
|
$directory = "uploads/temp/{$plantCode}";
|
||||||
$disk = Storage::disk('local');
|
$disk = Storage::disk('local');
|
||||||
$filePath = $directory.'/'.$filename;
|
$filePath = $directory.'/'.$filename;
|
||||||
// $fullPath = null;
|
// $fullPath = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user