ranjith-dev #1578
@@ -19,6 +19,14 @@ use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use App\Filament\Exports\PanelPalletValidationExporter;
|
||||
use App\Filament\Imports\PanelPalletValidationImporter;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Str;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\StickerMaster;
|
||||
|
||||
class PanelPalletValidationResource extends Resource
|
||||
{
|
||||
@@ -182,34 +190,42 @@ class PanelPalletValidationResource extends Resource
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('item.code')
|
||||
->label('Item')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('panel_box_supplier')
|
||||
->label('Panel Box Supplier')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('panel_box_serial_number')
|
||||
->label('Panel Box Serial Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('panel_box_code')
|
||||
->label('Panel Box Code')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('pallet_status')
|
||||
->label('Pallet Status')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
@@ -230,7 +246,181 @@ class PanelPalletValidationResource extends Resource
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
Select::make('Plant')
|
||||
->label('Search by Plant Name')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
|
||||
} else {
|
||||
return Plant::whereHas('panelPalletValidations', function ($query) {
|
||||
$query->whereNotNull('id');
|
||||
})->orderBy('code')->pluck('name', 'id');
|
||||
}
|
||||
|
||||
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('item_id', null);
|
||||
}),
|
||||
Select::make('item_id')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get, $state) {
|
||||
$pId = $get('Plant');
|
||||
|
||||
if (empty($pId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Item::whereHas('panelPalletValidations', function ($query) use ($pId) {
|
||||
$query->where('plant_id', $pId);
|
||||
})->pluck('code', 'id');
|
||||
}),
|
||||
TextInput::make('pallet_number')
|
||||
->label('Pallet Number')
|
||||
->reactive()
|
||||
->placeholder('Enter Production Order (or) Doc No')
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('serial_number', null);
|
||||
}),
|
||||
TextInput::make('serial_number')
|
||||
->label('Serial Number')
|
||||
->reactive()
|
||||
->placeholder('Enter Serial Number'),
|
||||
TextInput::make('panel_box_supplier')
|
||||
->label('Supplier Number')
|
||||
->reactive()
|
||||
->placeholder('Enter Supplier Number'),
|
||||
TextInput::make('panel_box_code')
|
||||
->label('Panel Box Code')
|
||||
->reactive()
|
||||
->placeholder('Enter Panel Box Code'),
|
||||
Select::make('pallet_status')
|
||||
->label('Pallet Status')
|
||||
->options([
|
||||
'Completed' => 'Completed',
|
||||
'Pending' => 'Pending',
|
||||
])
|
||||
->reactive(),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
->placeholder('Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->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['Item']) && empty($data['production_order']) && empty($data['serial_number']) && empty($data['panel_box_supplier']) && empty($data['panel_box_code']) && empty($data['pallet_status']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (! empty($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_id'])) {
|
||||
$query->where('item_id', $data['item_id']);
|
||||
}
|
||||
|
||||
if (! empty($data['production_order'])) {
|
||||
$query->where('production_order', 'like', '%'.$data['production_order'].'%');
|
||||
}
|
||||
|
||||
if (Str::length($data['serial_number']) > 0) {
|
||||
$query->where('serial_number', 'like', '%'.$data['serial_number'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['panel_box_supplier'])) {
|
||||
$query->where('panel_box_supplier', $data['panel_box_supplier']);
|
||||
}
|
||||
|
||||
if (! empty($data['panel_box_code'])) {
|
||||
$query->where('panel_box_code', $data['panel_box_code']);
|
||||
}
|
||||
|
||||
if (! empty($data['pallet_status'])) {
|
||||
$query->where('pallet_status', $data['pallet_status']);
|
||||
}
|
||||
|
||||
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 Name: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant Name: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['item_id'])) {
|
||||
$itemCode = Item::find($data['item_id'])->code ?? 'Unknown';
|
||||
$indicators[] = 'Item Code: ' . $itemCode;
|
||||
}
|
||||
|
||||
if (! empty($data['production_order'])) {
|
||||
$indicators[] = 'Production Order: '.$data['production_order'];
|
||||
}
|
||||
|
||||
if (Str::length($data['serial_number']) > 0) {
|
||||
$indicators[] = 'Serial Number: '.$data['serial_number'];
|
||||
}
|
||||
|
||||
if (! empty($data['panel_box_supplier'])) {
|
||||
$indicators[] = 'Supplier No: '.$data['panel_box_supplier'];
|
||||
}
|
||||
|
||||
if (! empty($data['panel_box_code'])) {
|
||||
$indicators[] = 'Panel Box Code: '.$data['panel_box_code'];
|
||||
}
|
||||
|
||||
if (! empty($data['pallet_status'])) {
|
||||
$indicators[] = 'Pallet Status: '.$data['pallet_status'];
|
||||
}
|
||||
|
||||
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([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
|
||||
@@ -155,4 +155,9 @@ class Item extends Model
|
||||
{
|
||||
return $this->hasMany(ItemCharacteristic::class, 'item_id', 'id');
|
||||
}
|
||||
|
||||
public function panelPalletValidations()
|
||||
{
|
||||
return $this->hasMany(PanelPalletValidation::class, 'item_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,4 +277,8 @@ class Plant extends Model
|
||||
return $this->hasMany(CourierOutward::class, 'plant_id', 'id');
|
||||
}
|
||||
|
||||
public function panelPalletValidations()
|
||||
{
|
||||
return $this->hasMany(PanelPalletValidation::class, 'plant_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user