Added view rights against plant on view report and Updated alignments and filter query logic on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s

This commit is contained in:
dhanabalan
2026-01-14 10:43:14 +05:30
parent adb61638c9
commit f611a81da0

View File

@@ -6,8 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction as ActionsFilam
use App\Filament\Exports\ProductionQuantityExporter; use App\Filament\Exports\ProductionQuantityExporter;
use App\Filament\Imports\ProductionQuantityImporter; use App\Filament\Imports\ProductionQuantityImporter;
use App\Filament\Resources\ProductionQuantityResource\Pages; use App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
use App\Forms\Components\PlantSelect;
use App\Models\Block; use App\Models\Block;
use App\Models\Item; use App\Models\Item;
use App\Models\Line; use App\Models\Line;
@@ -18,29 +16,25 @@ use Carbon\Carbon;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
use Livewire\Livewire; use Filament\Tables\Actions\ImportAction;
// use Filament\Forms\Components\View;
use Filament\Tables\Actions\FilamentExportBulkAction;
use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
// use Filament\Forms\Components\View;
use Livewire\Livewire;
class ProductionQuantityResource extends Resource class ProductionQuantityResource extends Resource
{ {
protected static ?string $model = ProductionQuantity::class; protected static ?string $model = ProductionQuantity::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
@@ -52,7 +46,6 @@ class ProductionQuantityResource extends Resource
protected static ?int $navigationSort = 1; protected static ?int $navigationSort = 1;
// public $plant_id; // public $plant_id;
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
@@ -66,28 +59,27 @@ class ProductionQuantityResource extends Resource
// ->nullable() // ->nullable()
->reactive() ->reactive()
// ->statePath('filters') // ->statePath('filters')
->columnSpan(2) //1 ->columnSpan(2) // 1
->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();
}) })
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id) // ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () { ->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id; return optional(ProductionQuantity::latest()->first())->plant_id;
}) })
->disabled(fn (Get $get) => !empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null)) // ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, $set, callable $get,$livewire) { ->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
$set('block_name', null); $set('block_name', null);
if (!$plantId) if (! $plantId) {
{
$set('pqPlantError', 'Please select a plant first.'); $set('pqPlantError', 'Please select a plant first.');
return; return;
} } else {
else
{
$set('validationError', null); $set('validationError', null);
$set('pqPlantError', null); $set('pqPlantError', null);
} }
@@ -127,7 +119,7 @@ class ProductionQuantityResource extends Resource
// ->nullable() // ->nullable()
->columnSpan(1) ->columnSpan(1)
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id')) { if (! $get('plant_id')) {
return []; return [];
} }
@@ -138,15 +130,14 @@ class ProductionQuantityResource extends Resource
->reactive() ->reactive()
->default(function () { ->default(function () {
$latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id; $latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id; return optional(Shift::where('id', $latestShiftId)->first())->block_id;
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if ($get('id')) {
{
$getShift = ProductionQuantity::where('id', $get('id'))->first(); $getShift = ProductionQuantity::where('id', $get('id'))->first();
$getBlock = Shift::where('id', $getShift->shift_id)->first(); $getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id) if ($getBlock->block_id) {
{
$set('block_name', $getBlock->block_id); $set('block_name', $getBlock->block_id);
$set('pqBlockError', null); $set('pqBlockError', null);
} }
@@ -158,12 +149,11 @@ class ProductionQuantityResource extends Resource
// session(['select_plant' => $get('plant_id')]); // session(['select_plant' => $get('plant_id')]);
// session()->forget('select_line'); // session()->forget('select_line');
if (!$blockId) { if (! $blockId) {
$set('pqBlockError', 'Please select a block first.'); $set('pqBlockError', 'Please select a block first.');
return; return;
} } else {
else
{
$set('validationError', null); $set('validationError', null);
$set('pqBlockError', null); $set('pqBlockError', null);
} }
@@ -179,7 +169,7 @@ class ProductionQuantityResource extends Resource
->columnSpan(1) ->columnSpan(1)
// ->nullable() // ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name')) { if (! $get('plant_id') || ! $get('block_name')) {
return []; return [];
} }
@@ -192,13 +182,11 @@ class ProductionQuantityResource extends Resource
->default(function () { ->default(function () {
return optional(ProductionQuantity::latest()->first())->shift_id; return optional(ProductionQuantity::latest()->first())->shift_id;
}) })
//->afterStateUpdated(fn ($set) => $set('line_id', null)) // ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if ($get('id')) {
{
$getShift = ProductionQuantity::where('id', $get('id'))->first(); $getShift = ProductionQuantity::where('id', $get('id'))->first();
if($getShift->shift_id) if ($getShift->shift_id) {
{
$set('shift_id', $getShift->shift_id); $set('shift_id', $getShift->shift_id);
$set('pqShiftError', null); $set('pqShiftError', null);
} }
@@ -207,12 +195,11 @@ class ProductionQuantityResource extends Resource
$curShiftId = $get('shift_id'); $curShiftId = $get('shift_id');
$set('line_id', null); $set('line_id', null);
if (!$curShiftId) { if (! $curShiftId) {
$set('pqShiftError', 'Please select a shift first.'); $set('pqShiftError', 'Please select a shift first.');
return; return;
} } else {
else
{
$set('validationError', null); $set('validationError', null);
$set('pqShiftError', null); $set('pqShiftError', null);
} }
@@ -233,7 +220,7 @@ class ProductionQuantityResource extends Resource
// ->toArray() // Convert collection to array // ->toArray() // Convert collection to array
// ) // )
->options(function (callable $get) { ->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) { if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
return []; return [];
} }
@@ -246,11 +233,9 @@ class ProductionQuantityResource extends Resource
return optional(ProductionQuantity::latest()->first())->line_id; return optional(ProductionQuantity::latest()->first())->line_id;
}) })
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id')) if ($get('id')) {
{
$getShift = ProductionQuantity::where('id', $get('id'))->first(); $getShift = ProductionQuantity::where('id', $get('id'))->first();
if($getShift->line_id) if ($getShift->line_id) {
{
$set('line_id', $getShift->line_id); $set('line_id', $getShift->line_id);
$set('pqLineError', null); $set('pqLineError', null);
} }
@@ -263,12 +248,11 @@ class ProductionQuantityResource extends Resource
session(['select_line' => $state]); session(['select_line' => $state]);
if (!$lineId) { if (! $lineId) {
$set('pqLineError', 'Please select a line first.'); $set('pqLineError', 'Please select a line first.');
return; return;
} } else {
else
{
$set('validationError', null); $set('validationError', null);
$set('pqLineError', null); $set('pqLineError', null);
$set('item_id', null); $set('item_id', null);
@@ -276,7 +260,7 @@ class ProductionQuantityResource extends Resource
$set('serial_number', null); $set('serial_number', null);
$exists = ProductionQuantity::where('plant_id', $get('plant_id')) $exists = ProductionQuantity::where('plant_id', $get('plant_id'))
//->where('shift_id', $get('shift_id')) // ->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id')) ->where('line_id', $get('line_id'))
->latest() // Orders by created_at DESC ->latest() // Orders by created_at DESC
->first(); ->first();
@@ -296,7 +280,7 @@ class ProductionQuantityResource extends Resource
// 'x-on:change' => "\$wire.dispatch('filtersUpdated')", // Dispatch Livewire event from Alpine.js // 'x-on:change' => "\$wire.dispatch('filtersUpdated')", // Dispatch Livewire event from Alpine.js
// ]) // ])
->extraAttributes([ ->extraAttributes([
'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })" 'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })",
]) ])
->extraAttributes(fn ($get) => [ ->extraAttributes(fn ($get) => [
'class' => $get('pqLineError') ? 'border-red-500' : '', 'class' => $get('pqLineError') ? 'border-red-500' : '',
@@ -319,7 +303,7 @@ class ProductionQuantityResource extends Resource
->minLength(7) ->minLength(7)
->maxLength(14) ->maxLength(14)
->columnSpan(2) ->columnSpan(2)
//->rules(['regex:/^[1-9][0-9]{6,}$/']) // ->rules(['regex:/^[1-9][0-9]{6,}$/'])
// ->disabled(function ($get) { // ->disabled(function ($get) {
// return $get('item_code'); // return $get('item_code');
// }) // })
@@ -328,21 +312,20 @@ class ProductionQuantityResource extends Resource
// $latestProductionOrder = ProductionQuantity::latest()->first()->production_order; // $latestProductionOrder = ProductionQuantity::latest()->first()->production_order;
// return $latestProductionOrder ?? null; // return $latestProductionOrder ?? null;
$latestProduction = ProductionQuantity::latest()->first(); $latestProduction = ProductionQuantity::latest()->first();
return $latestProduction ? $latestProduction->production_order : null; return $latestProduction ? $latestProduction->production_order : null;
}) })
->afterStateUpdated(function ($state, callable $get, callable $set): void { ->afterStateUpdated(function ($state, callable $get, callable $set): void {
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) if (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) {
{
$set('item_code', null); $set('item_code', null);
$set('item_id', null); $set('item_id', null);
$set('serial_number', null); $set('serial_number', null);
$set('production_order', null); $set('production_order', null);
$set('prodOrdError', "Must be a numeric value with 7 to 14 digits."); $set('prodOrdError', 'Must be a numeric value with 7 to 14 digits.');
$set('validationError', null); $set('validationError', null);
return; return;
} } else {
else
{
$set('item_code', null); $set('item_code', null);
$set('item_id', null); $set('item_id', null);
// $set('item_description', null); // $set('item_description', null);
@@ -350,6 +333,7 @@ class ProductionQuantityResource extends Resource
$set('production_order', $state); $set('production_order', $state);
$set('prodOrdError', null); $set('prodOrdError', null);
$set('validationError', null); $set('validationError', null);
return; return;
// if (empty($state)) { // if (empty($state)) {
// } // }
@@ -923,17 +907,17 @@ class ProductionQuantityResource extends Resource
->required(), ->required(),
Forms\Components\Hidden::make('sap_msg_status'), Forms\Components\Hidden::make('sap_msg_status'),
Forms\Components\Hidden::make('sap_msg_description'), Forms\Components\Hidden::make('sap_msg_description'),
//->unique(ignoreRecord: true), // ->unique(ignoreRecord: true),
// ->autocapitalize('characters'), // ->autocapitalize('characters'),
// ->columnSpanFull(), // ->columnSpanFull(),
Forms\Components\TextInput::make('recent_qr') //item_description Forms\Components\TextInput::make('recent_qr') // item_description
->label('Last scanned QR') ->label('Last scanned QR')
->reactive() ->reactive()
->columnSpan(2) ->columnSpan(2)
->default(function () { ->default(function () {
// Get the latest 'item_id' foreign key from 'production_quantities' table // Get the latest 'item_id' foreign key from 'production_quantities' table
$latestProductionQuantity = ProductionQuantity::latest()->first(); $latestProductionQuantity = ProductionQuantity::latest()->first();
if (!$latestProductionQuantity) { if (! $latestProductionQuantity) {
return null; // Return null if no production quantities exist return null; // Return null if no production quantities exist
} }
@@ -953,7 +937,7 @@ class ProductionQuantityResource extends Resource
Forms\Components\Hidden::make('operator_id') Forms\Components\Hidden::make('operator_id')
->default(Filament::auth()->user()->name), ->default(Filament::auth()->user()->name),
]) ])
->columns(12), //6 ->columns(12), // 6
]); ]);
} }
@@ -971,20 +955,21 @@ class ProductionQuantityResource 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('production_order') Tables\Columns\TextColumn::make('production_order')
->label('Production Order') ->label('Production Order')
->alignCenter() ->alignCenter()
->sortable(),// ->searchable(), ->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('serial_number') Tables\Columns\TextColumn::make('serial_number')
->label('Serial Number') ->label('Serial Number')
->alignCenter() ->alignCenter()
->sortable(),// ->searchable(), ->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('item.code') Tables\Columns\TextColumn::make('item.code')
->label('Item Code') ->label('Item Code')
->alignCenter() ->alignCenter()
->sortable(),// ->searchable(), ->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('item.uom') Tables\Columns\TextColumn::make('item.uom')
->label('Unit of Measure') ->label('Unit of Measure')
->alignCenter() ->alignCenter()
@@ -1040,7 +1025,7 @@ class ProductionQuantityResource extends Resource
Filter::make('advanced_filters') Filter::make('advanced_filters')
->label('Advanced Filters') ->label('Advanced Filters')
->form([ ->form([
//plant // plant
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
@@ -1049,6 +1034,7 @@ class ProductionQuantityResource 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()
@@ -1061,16 +1047,17 @@ class ProductionQuantityResource extends Resource
$set('operator_id', null); $set('operator_id', null);
}), }),
//line // line
Select::make('Line') Select::make('Line')
->label('Select line') ->label('Select line')
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId ) { if (! $plantId) {
return []; return [];
} }
return Line::where('plant_id', $plantId) return Line::where('plant_id', $plantId)
->pluck('name', 'id'); ->pluck('name', 'id');
}) })
@@ -1079,16 +1066,17 @@ class ProductionQuantityResource extends Resource
$set('operator_id', null); $set('operator_id', null);
}), }),
//block // block
Select::make('Block') Select::make('Block')
->label('Select Block') ->label('Select Block')
->nullable() ->nullable()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId ) { if (! $plantId) {
return []; return [];
} }
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id'); return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
}) })
->reactive() ->reactive()
@@ -1097,7 +1085,7 @@ class ProductionQuantityResource extends Resource
$set('operator_id', null); $set('operator_id', null);
}), }),
//shift // shift
Select::make('Shift') Select::make('Shift')
->label('Select Shift') ->label('Select Shift')
->nullable() ->nullable()
@@ -1105,7 +1093,7 @@ class ProductionQuantityResource extends Resource
$plantId = $get('Plant'); $plantId = $get('Plant');
$blockId = $get('Block'); $blockId = $get('Block');
if (!$plantId || !$blockId) { if (! $plantId || ! $blockId) {
return []; // Return empty if plant or block is not selected return []; // Return empty if plant or block is not selected
} }
@@ -1132,11 +1120,10 @@ class ProductionQuantityResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId ) { if (! $plantId) {
return Item::distinct()->whereHas('productionQuantities')->pluck('code', 'id'); return Item::whereHas('productionQuantities')->distinct()->pluck('code', 'id');
} } else {
else { return Item::whereHas('productionQuantities')->where('plant_id', $plantId)->distinct()->pluck('code', 'id');
return Item::where('plant_id', $plantId)->whereHas('productionQuantities')->distinct()->pluck('code', 'id');
} }
// return Item::whereHas('stickerMasters', function ($query) use ($pId) { // return Item::whereHas('stickerMasters', function ($query) use ($pId) {
// if ($pId) { // if ($pId) {
@@ -1154,10 +1141,9 @@ class ProductionQuantityResource extends Resource
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('Plant'); $plantId = $get('Plant');
if (!$plantId ) { if (! $plantId) {
return ProductionQuantity::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status'); return ProductionQuantity::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status');
} } else {
else {
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status'); return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status');
} }
}) })
@@ -1171,24 +1157,15 @@ class ProductionQuantityResource extends Resource
$plantId = $get('Plant'); $plantId = $get('Plant');
$lineId = $get('Line'); $lineId = $get('Line');
$shiftId = $get('Shift'); $shiftId = $get('Shift');
if (!$plantId && !$lineId && !$shiftId) if (! $plantId && ! $lineId && ! $shiftId) {
{
return ProductionQuantity::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id'); return ProductionQuantity::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
} } elseif ($plantId && ! $lineId && ! $shiftId) {
else if ($plantId && !$lineId && !$shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id'); return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
} } elseif ($plantId && $lineId && ! $shiftId) {
else if ($plantId && $lineId && !$shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id'); return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
} } elseif ($plantId && ! $lineId && $shiftId) {
else if ($plantId && !$lineId && $shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id'); return ProductionQuantity::where('plant_id', $plantId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
} } else { // if ($plantId && $lineId && $shiftId)
else// if ($plantId && $lineId && $shiftId)
{
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id'); return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
} }
}) })
@@ -1212,44 +1189,50 @@ class ProductionQuantityResource extends Resource
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
if ($plant = $data['Plant'] ?? null) { if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $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 ($shift = $data['Shift'] ?? null) { if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift); $query->where('shift_id', $data['Shift']);
} }
if ($line = $data['Line'] ?? null) { if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line); $query->where('line_id', $data['Line']);
} }
if (!empty($data['production_order'])) { if (! empty($data['production_order'])) {
$query->where('production_order', 'like', '%' . $data['production_order'] . '%'); $query->where('production_order', 'like', '%'.$data['production_order'].'%');
} }
if (!empty($data['serial_number'])) { if (! empty($data['serial_number'])) {
$query->where('serial_number', 'like', '%' . $data['serial_number'] . '%'); $query->where('serial_number', 'like', '%'.$data['serial_number'].'%');
} }
if (!empty($data['Item'])) { if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']); $query->where('item_id', $data['Item']);
} }
if (!empty($data['sap_msg_status'])) { if (! empty($data['sap_msg_status'])) {
$query->where('sap_msg_status', $data['sap_msg_status']); $query->where('sap_msg_status', $data['sap_msg_status']);
} }
if (!empty($data['operator_id'])) { if (! empty($data['operator_id'])) {
$query->where('operator_id', $data['operator_id']); $query->where('operator_id', $data['operator_id']);
} }
if ($from = $data['created_from'] ?? null) { if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from); $query->where('created_at', '>=', $data['created_from']);
} }
if ($to = $data['created_to'] ?? null) { if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to); $query->where('created_at', '<=', $data['created_to']);
} }
// return $query; // return $query;
@@ -1257,48 +1240,54 @@ class ProductionQuantityResource extends Resource
->indicateUsing(function (array $data) { ->indicateUsing(function (array $data) {
$indicators = []; $indicators = [];
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['Shift'])) { if (! empty($data['Shift'])) {
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name'); $indicators[] = 'Shift: '.Shift::where('id', $data['Shift'])->value('name');
} }
if (!empty($data['Line'])) { if (! empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name'); $indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
} }
if (!empty($data['production_order'])) { if (! empty($data['production_order'])) {
$indicators[] = 'Production Order: ' . $data['production_order']; $indicators[] = 'Production Order: '.$data['production_order'];
} }
if (!empty($data['serial_number'])) { if (! empty($data['serial_number'])) {
$indicators[] = 'Serial Number: ' . $data['serial_number']; $indicators[] = 'Serial Number: '.$data['serial_number'];
} }
if (!empty($data['Item'])) { if (! empty($data['Item'])) {
$indicators[] = 'Item Code: ' . Item::where('id', $data['Item'])->value('code'); $indicators[] = 'Item Code: '.Item::where('id', $data['Item'])->value('code');
} }
if (!empty($data['sap_msg_status'])) { if (! empty($data['sap_msg_status'])) {
$indicators[] = 'SAP Message Status: ' . $data['sap_msg_status']; $indicators[] = 'SAP Message Status: '.$data['sap_msg_status'];
} }
if (!empty($data['operator_id'])) { if (! empty($data['operator_id'])) {
$indicators[] = 'Created By: ' . $data['operator_id']; $indicators[] = 'Created By: '.$data['operator_id'];
} }
if (!empty($data['created_from'])) { if (! empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from']; $indicators[] = 'From: '.$data['created_from'];
} }
if (!empty($data['created_to'])) { if (! empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to']; $indicators[] = 'To: '.$data['created_to'];
} }
return $indicators; return $indicators;
}) }),
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([
@@ -1319,7 +1308,7 @@ class ProductionQuantityResource extends Resource
->label('Import Production Quantities') ->label('Import Production Quantities')
->color('warning') ->color('warning')
->importer(ProductionQuantityImporter::class) ->importer(ProductionQuantityImporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view import production quantities'); return Filament::auth()->user()->can('view import production quantities');
}), }),
// ->chunkSize(250), // ->chunkSize(250),
@@ -1328,7 +1317,7 @@ class ProductionQuantityResource extends Resource
->label('Export Production Quantities') ->label('Export Production Quantities')
->color('warning') ->color('warning')
->exporter(ProductionQuantityExporter::class) ->exporter(ProductionQuantityExporter::class)
->visible(function() { ->visible(function () {
return Filament::auth()->user()->can('view export production quantities'); return Filament::auth()->user()->can('view export production quantities');
}), }),
]); ]);
@@ -1370,7 +1359,6 @@ class ProductionQuantityResource extends Resource
return 'Production Reports'; return 'Production Reports';
} }
// public function triggerChartUpdate(): void // public function triggerChartUpdate(): void
// { // {
// if (session()->has('select_plant') && session()->has('select_line')) { // if (session()->has('select_plant') && session()->has('select_line')) {