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

This commit is contained in:
dhanabalan
2026-01-14 10:33:59 +05:30
parent 8c0676e9b8
commit adb61638c9

View File

@@ -6,7 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
use App\Filament\Exports\ProductionPlanExporter;
use App\Filament\Imports\ProductionPlanImporter;
use App\Filament\Resources\ProductionPlanResource\Pages;
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
use App\Models\Block;
use App\Models\Line;
use App\Models\Plant;
@@ -16,19 +15,18 @@ use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Forms\Get;
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 Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
use Illuminate\Support\Facades\Request;
class ProductionPlanResource extends Resource
{
@@ -55,6 +53,7 @@ class ProductionPlanResource extends Resource
->reactive()
->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();
})
->default(function () {
@@ -67,10 +66,9 @@ class ProductionPlanResource extends Resource
$set('block_name', null);
if (! $plantId) {
$set('ppPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('ppPlantError', null);
}
})
@@ -95,16 +93,15 @@ class ProductionPlanResource extends Resource
->reactive()
->default(function () {
$latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
})
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionPlan::where('id', $get('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('ppBlockError', null);
}
@@ -115,10 +112,9 @@ class ProductionPlanResource extends Resource
if (! $blockId) {
$set('ppBlockError', 'Please select a block first.');
return;
}
else
{
} else {
$set('ppBlockError', null);
}
})
@@ -148,11 +144,9 @@ class ProductionPlanResource extends Resource
})
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionPlan::where('id', $get('id'))->first();
if($getShift->shift_id)
{
if ($getShift->shift_id) {
$set('shift_id', $getShift->shift_id);
$set('ppShiftError', null);
}
@@ -163,10 +157,9 @@ class ProductionPlanResource extends Resource
if (! $curShiftId) {
$set('ppShiftError', 'Please select a shift first.');
return;
}
else
{
} else {
$set('ppShiftError', null);
}
})
@@ -198,17 +191,13 @@ class ProductionPlanResource extends Resource
// return optional(ProductionPlan::latest()->first())->line_id;
// })
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionPlan::where('id', $get('id'))->first();
if($getShift->line_id)
{
if ($getShift->line_id) {
$set('line_id', $getShift->line_id);
$set('ppLineError', null);
}
}
else
{
} else {
$currentDT = Carbon::now()->toDateTimeString();
$set('created_at', $currentDT);
$set('update_date', null);
@@ -219,13 +208,11 @@ class ProductionPlanResource extends Resource
if (! $lineId) {
$set('ppLineError', 'Please select a line first.');
return;
}
else
{
} else {
$isUpdate = ! empty($get('id'));
if (!$isUpdate)
{
if (! $isUpdate) {
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
@@ -233,14 +220,12 @@ class ProductionPlanResource extends Resource
->latest()
->exists();
if ($exists)
{
if ($exists) {
$set('line_id', null);
$set('ppLineError', 'Production plan already updated.');
return;
}
else
{
} else {
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
@@ -248,8 +233,7 @@ class ProductionPlanResource extends Resource
->latest()
->exists();
if ($existShifts) //if ($existShifts->count() > 0)
{
if ($existShifts) { // if ($existShifts->count() > 0)
// $currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
@@ -274,11 +258,10 @@ class ProductionPlanResource extends Resource
$set('line_id', null);
$set('ppLineError', 'Production plan already updated.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
else
{
} else {
$currentDate = date('Y-m-d');
$shiftId = Shift::where('id', $get('shift_id'))
@@ -302,16 +285,16 @@ class ProductionPlanResource extends Resource
$set('line_id', null);
$set('ppLineError', 'Choosed a invalid shift.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
}
$set('ppLineError', null);
return;
}
else
{
} else {
// $currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
@@ -339,11 +322,10 @@ class ProductionPlanResource extends Resource
$set('update_date', '1');
$set('ppLineError', null);
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
else
{
} else {
$currentDate = date('Y-m-d');
$shiftId = Shift::where('id', $get('shift_id'))
@@ -367,12 +349,14 @@ class ProductionPlanResource extends Resource
$set('line_id', null);
$set('ppLineError', 'Choosed a invalid shift.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
}
$set('ppLineError', null);
return;
}
@@ -449,10 +433,8 @@ class ProductionPlanResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$planQuan = $get('plan_quantity');
if(!$get('update_date') )
{
if(!$get('id'))
{
if (! $get('update_date')) {
if (! $get('id')) {
$currentDT = Carbon::now()->toDateTimeString();
$set('created_at', $currentDT);
}
@@ -460,10 +442,9 @@ class ProductionPlanResource extends Resource
if (! $planQuan) {
$set('ppPlanQuanError', 'Scan the valid plan quantity.');
return;
}
else
{
} else {
$set('ppPlanQuanError', null);
}
})
@@ -529,6 +510,7 @@ class ProductionPlanResource 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('plan_quantity')
@@ -593,6 +575,7 @@ class ProductionPlanResource 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()
@@ -612,6 +595,7 @@ class ProductionPlanResource extends Resource
if (! $plantId) {
return [];
}
return Line::where('plant_id', $plantId)
->pluck('name', 'id');
})
@@ -627,6 +611,7 @@ class ProductionPlanResource extends Resource
if (! $plantId) {
return [];
}
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
})
->reactive()
@@ -669,25 +654,32 @@ class ProductionPlanResource extends Resource
return $query->whereRaw('1 = 0');
}
if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant);
if (! empty($data['Plant'])) {// if ($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 ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift);
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $data['Shift']);
}
if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line);
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
$query->where('line_id', $data['Line']);
}
if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from);
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $data['created_from']);
}
if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to);
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $data['created_to']);
}
return $query;
})
->indicateUsing(function (array $data) {
@@ -695,6 +687,12 @@ class ProductionPlanResource 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['Shift'])) {
@@ -714,7 +712,7 @@ class ProductionPlanResource extends Resource
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -726,7 +724,7 @@ class ProductionPlanResource extends Resource
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
FilamentExportBulkAction::make('export')
FilamentExportBulkAction::make('export'),
]),
])
->headerActions([