Implement initial structure for code changes and prepare for future updates and Added view rights against plant on view report
This commit is contained in:
@@ -5,35 +5,33 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\LocatorInvoiceValidationExporter;
|
||||
use App\Filament\Imports\LocatorInvoiceValidationImporter;
|
||||
use App\Filament\Resources\LocatorInvoiceValidationResource\Pages;
|
||||
use App\Filament\Resources\LocatorInvoiceValidationResource\RelationManagers;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerMaster;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Storage;
|
||||
use Str;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
class LocatorInvoiceValidationResource extends Resource
|
||||
{
|
||||
@@ -57,14 +55,14 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->relationship('plant', 'name')
|
||||
->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();
|
||||
})
|
||||
->disabled(fn (Get $get) => $get('invoice_number'))
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
$set('plant', $plantId);
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
@@ -72,9 +70,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$set('sno_quantity', 0);
|
||||
$set('scan_quantity', 0);
|
||||
$set('pend_quantity', 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plant', null);
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
@@ -107,9 +103,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
}
|
||||
else if ($invNo)
|
||||
{
|
||||
} elseif ($invNo) {
|
||||
$snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invNo)->count();
|
||||
|
||||
$pendingCount = LocatorInvoiceValidation::where('invoice_number', $invNo)->where('plant_id', $plantId)->whereNull('scanned_status')->orWhere('scanned_status', '=', '')->count();
|
||||
@@ -139,8 +133,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->get();
|
||||
|
||||
$allScanned = true;
|
||||
foreach ($records as $record)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
if (($record->scanned_status == null) || trim($record->scanned_status) == '') {
|
||||
$allScanned = false;
|
||||
break;
|
||||
@@ -181,8 +174,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->get();
|
||||
|
||||
$allScanned = true;
|
||||
foreach ($records as $record)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
if (($record->scanned_status == null) || trim($record->scanned_status) == '') {
|
||||
$allScanned = false;
|
||||
break;
|
||||
@@ -236,8 +228,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
$allScanned = true;
|
||||
|
||||
foreach ($records as $record)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
if (($record->scanned_status == null) || trim($record->scanned_status) == '') {
|
||||
$allScanned = false;
|
||||
break;
|
||||
@@ -289,6 +280,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($state !== '1') {
|
||||
$set('update_locator_invoice', '0');
|
||||
$set('pallet_number', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -296,13 +288,13 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->where('pallet_number', $palletNumber)
|
||||
->first();
|
||||
|
||||
if (!$palletRecord)
|
||||
{
|
||||
if (! $palletRecord) {
|
||||
Notification::make()
|
||||
->title("Pallet number '{$palletNumber}' does not exist.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,13 +310,13 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
if (!$allCompleted)
|
||||
{
|
||||
if (! $allCompleted) {
|
||||
Notification::make()
|
||||
->title("Pallet number '{$palletNumber}' is not completed in masters")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -413,7 +405,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
})
|
||||
}),
|
||||
])
|
||||
->columns(5),
|
||||
|
||||
@@ -431,6 +423,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$paginator = $livewire->getTableRecords();
|
||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
@@ -504,6 +497,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||
->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();
|
||||
})
|
||||
->label('Select Plant')
|
||||
@@ -546,8 +540,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$fullFolderPath = "uploads/$folderPath";
|
||||
|
||||
// Check if the folder exists, if not, create it
|
||||
if (!Storage::disk('local')->exists($fullFolderPath))
|
||||
{
|
||||
if (! Storage::disk('local')->exists($fullFolderPath)) {
|
||||
Storage::disk('local')->makeDirectory($fullFolderPath);
|
||||
}
|
||||
|
||||
@@ -555,12 +548,10 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
if ($fullPath && file_exists($fullPath))
|
||||
{
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if((count($rows) - 1) <= 0)
|
||||
{
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
Notification::make()
|
||||
->title('Invalid Locator Invoice Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
@@ -571,6 +562,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -579,29 +571,22 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$seenSerialNumbers = [];
|
||||
$validRowsFound = false;
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$serialNumber = trim($row[0]);
|
||||
|
||||
if (empty($serialNumber))
|
||||
{
|
||||
if (empty($serialNumber)) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Str::length($serialNumber) < 9 || Str::length($serialNumber) > 20 || !ctype_alnum($serialNumber))
|
||||
{
|
||||
} else {
|
||||
if (Str::length($serialNumber) < 9 || Str::length($serialNumber) > 20 || ! ctype_alnum($serialNumber)) {
|
||||
$invalidSerialCodes[] = $serialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (in_array($serialNumber, $seenSerialNumbers)) {
|
||||
$duplicateSerials[] = $serialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$seenSerialNumbers[] = $serialNumber;
|
||||
$validRowsFound = true;
|
||||
}
|
||||
@@ -622,6 +607,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -638,6 +624,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -652,6 +639,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -674,10 +662,9 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Save full file path to session
|
||||
session(['uploaded_invoice_path' => $fullPath]);
|
||||
Notification::make()
|
||||
@@ -707,11 +694,6 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
return Filament::auth()->user()->can('view export locator invoice validation');
|
||||
}),
|
||||
])
|
||||
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -725,6 +707,7 @@ class LocatorInvoiceValidationResource 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();
|
||||
})
|
||||
->reactive()
|
||||
@@ -748,6 +731,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('invoice_number')
|
||||
->where('invoice_number', '!=', '')
|
||||
@@ -770,6 +754,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('pallet_number')
|
||||
->where('pallet_number', '!=', '')
|
||||
@@ -788,6 +773,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('locator_number')
|
||||
->where('locator_number', '!=', '')
|
||||
@@ -839,6 +825,12 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -889,6 +881,12 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -933,7 +931,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
Reference in New Issue
Block a user