Added view rights against plant on view report and Updated alignments and load available item code logic on resource
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 28s
Laravel Pint / pint (pull_request) Successful in 2m31s
Laravel Larastan / larastan (pull_request) Failing after 3m37s

This commit is contained in:
dhanabalan
2026-01-14 11:59:50 +05:30
parent 96a8311317
commit 9540fb95c9

View File

@@ -5,14 +5,10 @@ namespace App\Filament\Resources;
use App\Filament\Exports\WeightValidationExporter; use App\Filament\Exports\WeightValidationExporter;
use App\Filament\Imports\WeightValidationImporter; use App\Filament\Imports\WeightValidationImporter;
use App\Filament\Resources\WeightValidationResource\Pages; use App\Filament\Resources\WeightValidationResource\Pages;
use App\Filament\Resources\WeightValidationResource\RelationManagers;
use App\Models\Item; use App\Models\Item;
use App\Models\Line;
use App\Models\Plant; use App\Models\Plant;
use App\Models\QualityValidation;
use App\Models\StickerMaster; use App\Models\StickerMaster;
use App\Models\WeightValidation; use App\Models\WeightValidation;
use Filament\Actions\Action;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\DateTimePicker;
@@ -26,14 +22,13 @@ use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction; use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table; use Filament\Tables\Table;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use Str; use Str;
use Filament\Tables\Filters\Filter;
class WeightValidationResource extends Resource class WeightValidationResource extends Resource
{ {
@@ -51,6 +46,7 @@ class WeightValidationResource extends Resource
->relationship('plant', 'name') ->relationship('plant', 'name')
->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::pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
@@ -80,7 +76,7 @@ class WeightValidationResource extends Resource
Forms\Components\TextInput::make('picked_weight') Forms\Components\TextInput::make('picked_weight')
->label('Picked Weight'), ->label('Picked Weight'),
Forms\Components\TextInput::make('scanned_by') Forms\Components\TextInput::make('scanned_by')
->label('Scanned By') ->label('Scanned By'),
]); ]);
} }
@@ -98,6 +94,7 @@ class WeightValidationResource extends Resource
$paginator = $livewire->getTableRecords(); $paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
@@ -157,9 +154,6 @@ class WeightValidationResource extends Resource
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
]) ])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters') Filter::make('advanced_filters')
@@ -173,6 +167,7 @@ class WeightValidationResource 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::pluck('name', 'id')->toArray();
}) })
->reactive(), ->reactive(),
@@ -180,18 +175,33 @@ class WeightValidationResource extends Resource
// $set('sticker_master_id', null); // $set('sticker_master_id', null);
// $set('sap_msg_status', null); // $set('sap_msg_status', null);
// }), // }),
Select::make('Item Code') Select::make('Item Code')
->label('Search by Item Code') ->label('Search by Item Code')
->nullable() ->nullable()
// ->options(function (callable $get) {
// $plantId = $get('Plant');
// if (! $plantId) {
// return [];
// }
// return Item::where('plant_id', $plantId)->pluck('code', 'id');
// })
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (! $plantId) { if (! $plantId) {
return []; return [];
} }
return Item::where('plant_id', $plantId)->pluck('code', 'id');
return Item::whereHas('weightValidations', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
})->pluck('code', 'id');
}) })
->searchable() ->searchable()
->reactive(), ->reactive(),
TextInput::make('Obd Number') TextInput::make('Obd Number')
->label('OBD Number') ->label('OBD Number')
->placeholder('Enter OBD Number'), ->placeholder('Enter OBD Number'),
@@ -243,6 +253,7 @@ class WeightValidationResource extends Resource
->placeholder(placeholder: 'Select From DateTime') ->placeholder(placeholder: 'Select From DateTime')
->reactive() ->reactive()
->native(false), ->native(false),
DateTimePicker::make('created_to') DateTimePicker::make('created_to')
->label('Created To') ->label('Created To')
->placeholder(placeholder: 'Select To DateTime') ->placeholder(placeholder: 'Select To DateTime')
@@ -257,6 +268,12 @@ class WeightValidationResource extends Resource
if (! empty($data['Plant'])) { if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']); $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['Item Code'])) { if (! empty($data['Item Code'])) {
@@ -295,7 +312,6 @@ class WeightValidationResource extends Resource
$query->where('scanned_by', $data['Scanned By']); $query->where('scanned_by', $data['Scanned By']);
} }
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']); $query->where('created_at', '>=', $data['created_from']);
} }
@@ -309,6 +325,12 @@ class WeightValidationResource extends Resource
if (! empty($data['Plant'])) { if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name'); $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['Item Code'])) { if (! empty($data['Item Code'])) {
@@ -361,7 +383,7 @@ class WeightValidationResource extends Resource
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([
@@ -383,6 +405,7 @@ class WeightValidationResource extends Resource
// ->options(Plant::pluck('name', 'id')->toArray()) // ->options(Plant::pluck('name', 'id')->toArray())
->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::pluck('name', 'id')->toArray();
}) })
->label('Select Plant') ->label('Select Plant')
@@ -435,10 +458,10 @@ class WeightValidationResource extends Resource
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) if ($disk->exists($path)) {
{
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -469,6 +492,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -482,9 +506,10 @@ class WeightValidationResource extends Resource
$lineNumbers = []; $lineNumbers = [];
$validRowsFound = false; $validRowsFound = false;
foreach ($rows as $index => $row) foreach ($rows as $index => $row) {
{ if ($index === 0) {
if ($index === 0) continue; // Skip header continue;
} // Skip header
$materialCode = trim($row[0]); $materialCode = trim($row[0]);
$lineNumber = trim($row[1]); $lineNumber = trim($row[1]);
@@ -497,31 +522,23 @@ class WeightValidationResource extends Resource
} }
if (! empty($materialCode)) { if (! empty($materialCode)) {
if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode)) if (Str::length($materialCode) < 6 || ! ctype_alnum($materialCode)) {
{
$invalidMatCodes[] = $materialCode; $invalidMatCodes[] = $materialCode;
continue; continue;
} } else {
else
{
$materialCodes[] = $materialCode; $materialCodes[] = $materialCode;
$validData = true; $validData = true;
if(Str::length($lineNumber) < 1 || !is_numeric($lineNumber)) if (Str::length($lineNumber) < 1 || ! is_numeric($lineNumber)) {
{
$validData = false; $validData = false;
$invalidLines[] = $materialCode; $invalidLines[] = $materialCode;
} } elseif (in_array($lineNumber, $lineNumbers)) {
else if (in_array($lineNumber, $lineNumbers))
{
$duplicateLines[] = $materialCode; $duplicateLines[] = $materialCode;
} } else {
else
{
$lineNumbers[] = $lineNumber; $lineNumbers[] = $lineNumber;
} }
if(Str::length($batchNumber) < 8 || !is_numeric($batchNumber))//ctype_alnum if (Str::length($batchNumber) < 8 || ! is_numeric($batchNumber)) {// ctype_alnum
{
$validData = false; $validData = false;
$invalidBatch[] = $materialCode; $invalidBatch[] = $materialCode;
} }
@@ -530,20 +547,16 @@ class WeightValidationResource extends Resource
// $validData = false; // $validData = false;
// $invalidHeat[] = $materialCode; // $invalidHeat[] = $materialCode;
// } // }
if(Str::length($actualWeight) < 1 || !is_numeric($actualWeight))//ctype_alnum if (Str::length($actualWeight) < 1 || ! is_numeric($actualWeight)) {// ctype_alnum
{
$validData = false; $validData = false;
$invalidWeight[] = $materialCode; $invalidWeight[] = $materialCode;
} }
if ($validData) if ($validData) {
{
$validRowsFound = true; $validRowsFound = true;
} }
} }
} } else {
else
{
continue; continue;
} }
} }
@@ -560,6 +573,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -575,6 +589,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -590,6 +605,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -605,6 +621,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -635,6 +652,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -671,6 +689,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -695,6 +714,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -709,6 +729,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -729,10 +750,11 @@ class WeightValidationResource extends Resource
$inserted = 0; $inserted = 0;
// $updated = 0; // $updated = 0;
foreach ($rows as $index => $row) foreach ($rows as $index => $row) {
{
// Skip header // Skip header
if ($index === 0) { continue; } if ($index === 0) {
continue;
}
$materialCode = trim($row[0]); $materialCode = trim($row[0]);
$lineNumber = trim($row[1]); $lineNumber = trim($row[1]);
@@ -750,12 +772,9 @@ class WeightValidationResource extends Resource
$masItem = Item::where('plant_id', $plantId)->where('code', $materialCode)->first(); $masItem = Item::where('plant_id', $plantId)->where('code', $materialCode)->first();
if ($recordExist) { if ($recordExist) {
$skipUpd = $recordExist->vehicle_number ?? null; $skipUpd = $recordExist->vehicle_number ?? null;
if($skipUpd) if ($skipUpd) {
{
continue; continue;
} } else {
else
{
if ($masItem) { if ($masItem) {
$recordExist->update([ $recordExist->update([
'item_id' => $masItem->id, 'item_id' => $masItem->id,
@@ -767,8 +786,7 @@ class WeightValidationResource extends Resource
$updated++; $updated++;
} }
} }
} } else {
else {
if ($masItem) { if ($masItem) {
WeightValidation::create([ WeightValidation::create([
'item_id' => $masItem->id, 'item_id' => $masItem->id,
@@ -779,12 +797,9 @@ class WeightValidationResource extends Resource
// 'heat_number' => $heatNumber, // 'heat_number' => $heatNumber,
'obd_weight' => $actualWeight, 'obd_weight' => $actualWeight,
]); ]);
if (in_array($lineNumber, $availLines)) if (in_array($lineNumber, $availLines)) {
{
continue; continue;
} } else {
else
{
$inserted++; $inserted++;
} }
} }
@@ -795,7 +810,7 @@ class WeightValidationResource extends Resource
if ($updateInv) { if ($updateInv) {
if ($updated > 0) { if ($updated > 0) {
Notification::make() Notification::make()
->title("Start the scanning process!") ->title('Start the scanning process!')
->body("'$updated' OBD lines were updated and<br>'$inserted' OBD lines were inserted for<br>imported OBD Invoice : '$originalNameOnly'.") ->body("'$updated' OBD lines were updated and<br>'$inserted' OBD lines were inserted for<br>imported OBD Invoice : '$originalNameOnly'.")
->info() ->info()
// ->success() // ->success()
@@ -806,24 +821,20 @@ class WeightValidationResource extends Resource
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count(); $totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count(); $scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if ($totalQuantity === $scannedQuantity) if ($totalQuantity === $scannedQuantity) {
{
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
} } else {
else
{
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
} }
} } elseif ($inserted > 0) {
else if ($inserted > 0) {
Notification::make() Notification::make()
->title("Start the scanning process!") ->title('Start the scanning process!')
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.") ->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
->info() ->info()
// ->success() // ->success()
@@ -834,24 +845,20 @@ class WeightValidationResource extends Resource
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count(); $totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count(); $scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if ($totalQuantity === $scannedQuantity) if ($totalQuantity === $scannedQuantity) {
{
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
} } else {
else
{
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
} }
} } else {
else {
Notification::make() Notification::make()
->title("Import Failed: OBD Invoice") ->title('Import Failed: OBD Invoice')
->body("No exist records were updated for imported OBD Invoice : '$originalNameOnly'.") ->body("No exist records were updated for imported OBD Invoice : '$originalNameOnly'.")
->danger() ->danger()
->seconds(2) ->seconds(2)
@@ -863,14 +870,14 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
return; return;
} }
} } else {
else {
if ($inserted > 0) { if ($inserted > 0) {
Notification::make() Notification::make()
->title("Start the scanning process!") ->title('Start the scanning process!')
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.") ->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
->info() ->info()
// ->success() // ->success()
@@ -881,24 +888,20 @@ class WeightValidationResource extends Resource
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count(); $totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count(); $scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if ($totalQuantity === $scannedQuantity) if ($totalQuantity === $scannedQuantity) {
{
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
} } else {
else
{
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
} }
} } else {
else {
Notification::make() Notification::make()
->title("Import Failed: OBD Invoice") ->title('Import Failed: OBD Invoice')
->body("No new records were inserted for imported OBD Invoice : '$originalNameOnly'.") ->body("No new records were inserted for imported OBD Invoice : '$originalNameOnly'.")
->danger() ->danger()
->seconds(2) ->seconds(2)
@@ -910,6 +913,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId); // $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
return; return;
} }