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