ranjith-dev #784
@@ -23,6 +23,11 @@ use Illuminate\Database\Eloquent\Builder;
|
|||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Str;
|
use Str;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
|
use Filament\Forms\Components\FileUpload;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
|
||||||
class MachineResource extends Resource
|
class MachineResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -249,7 +254,177 @@ class MachineResource extends Resource
|
|||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
Filter::make('advanced_filters')
|
||||||
|
->label('Advanced Filters')
|
||||||
|
->form([
|
||||||
|
Select::make('Plant')
|
||||||
|
->label('Search by Plant Name')
|
||||||
|
->nullable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
|
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
|
||||||
|
} else {
|
||||||
|
return Plant::whereHas('machines', function ($query) {
|
||||||
|
$query->whereNotNull('id');
|
||||||
|
})->orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
$set('code', null);
|
||||||
|
$set('operator_id', null);
|
||||||
|
}),
|
||||||
|
Select::make('Line')
|
||||||
|
->label('Search by Line')
|
||||||
|
->searchable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
if (empty($plantId)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Line::whereHas('machines', function ($query) use ($plantId) {
|
||||||
|
if ($plantId) {
|
||||||
|
$query->where('plant_id', $plantId);
|
||||||
|
}
|
||||||
|
})->pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('name')
|
||||||
|
->label('Description')
|
||||||
|
->reactive(),
|
||||||
|
Select::make('work_group_master')
|
||||||
|
->label('Search by Work Group Center')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
|
return WorkGroupMaster::whereHas('machines', function ($query) use ($plantId) {
|
||||||
|
if ($plantId) {
|
||||||
|
$query->where('plant_id', $plantId);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->pluck('name', 'id')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
Select::make('work_center')
|
||||||
|
->label('Search by Work Center')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
$workGroupMasterId = $get('work_group_master');
|
||||||
|
|
||||||
|
if (!$workGroupMasterId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Machine::query()
|
||||||
|
->when($plantId, fn ($q) => $q->where('plant_id', $plantId))
|
||||||
|
->where('work_group_master_id', $workGroupMasterId)
|
||||||
|
->pluck('work_center', 'work_center')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
DateTimePicker::make(name: 'created_from')
|
||||||
|
->label('Created From')
|
||||||
|
->placeholder(placeholder: 'Select From DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
DateTimePicker::make('created_to')
|
||||||
|
->label('Created To')
|
||||||
|
->placeholder(placeholder: 'Select To DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
])
|
||||||
|
->query(function ($query, array $data) {
|
||||||
|
// Hide all records initially if no filters are applied
|
||||||
|
if (empty($data['Plant']) && empty($data['Line']) && empty($data['name']) && empty($data['work_group_master']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['updated_from']) && empty($data['updated_to'])) {
|
||||||
|
// return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
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['Line'])) {
|
||||||
|
$query->where('line_id', $data['Line']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['name'])) {
|
||||||
|
$query->where('name', $data['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['work_group_master'])) {
|
||||||
|
$query->where('work_group_master_id', $data['work_group_master']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['work_center'])) {
|
||||||
|
$query->where('work_center', $data['work_center']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_from'])) {
|
||||||
|
$query->where('created_at', '>=', $data['created_from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_to'])) {
|
||||||
|
$query->where('created_at', '<=', $data['created_to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
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['Line'])) {
|
||||||
|
$indicators[] = 'Line Name: '.Line::where('id', $data['Line'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['name'])) {
|
||||||
|
$indicators[] = 'Description: ' . $data['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['work_group_master'])) {
|
||||||
|
$indicators[] = 'Work Group Center: '.WorkGroupMaster::where('id', $data['work_group_master'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['work_center'])) {
|
||||||
|
$indicators[] = 'Work Center: '.Machine::where('work_center', $data['work_center'])->value('work_center');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_from'])) {
|
||||||
|
$indicators[] = 'From: '.$data['created_from'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_to'])) {
|
||||||
|
$indicators[] = 'To: '.$data['created_to'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indicators;
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ class Plant extends Model
|
|||||||
return $this->hasMany(StickerMaster::class, 'plant_id', 'id');
|
return $this->hasMany(StickerMaster::class, 'plant_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function locators(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Locator::class, 'plant_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
public function weightValidations(): HasMany
|
public function weightValidations(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(WeightValidation::class, 'plant_id', 'id');
|
return $this->hasMany(WeightValidation::class, 'plant_id', 'id');
|
||||||
@@ -104,6 +109,11 @@ class Plant extends Model
|
|||||||
return $this->hasMany(WorkGroupMaster::class, 'plant_id', 'id');
|
return $this->hasMany(WorkGroupMaster::class, 'plant_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function machines()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Machine::class, 'plant_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
public function processOrders()
|
public function processOrders()
|
||||||
{
|
{
|
||||||
return $this->hasMany(ProcessOrder::class, 'plant_id', 'id');
|
return $this->hasMany(ProcessOrder::class, 'plant_id', 'id');
|
||||||
@@ -178,4 +188,9 @@ class Plant extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(AsrsItemValidation::class, 'plant_id', 'id');
|
return $this->hasMany(AsrsItemValidation::class, 'plant_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function locatorValidations()
|
||||||
|
// {
|
||||||
|
// return $this->hasMany(LocatorValidation::class, 'plant_id', 'id');
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ class WorkGroupMaster extends Model
|
|||||||
return $this->hasMany(ProductCharacteristicsMaster::class);
|
return $this->hasMany(ProductCharacteristicsMaster::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function machines()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Machine::class, 'work_group_master_id');
|
||||||
|
}
|
||||||
|
|
||||||
// public function rejectReasons()
|
// public function rejectReasons()
|
||||||
// {
|
// {
|
||||||
// return $this->hasMany(RejectReason::class, 'work_group_master_id', 'id');
|
// return $this->hasMany(RejectReason::class, 'work_group_master_id', 'id');
|
||||||
|
|||||||
Reference in New Issue
Block a user