Improving Order table front-end

Nisse Lommerde 1 week ago
parent cf4a56ee84
commit 9bf9437cd6

@ -95,7 +95,7 @@ class CustomerReportResource extends Resource
DatePicker::make('created_until') DatePicker::make('created_until')
->label('Until date'), ->label('Until date'),
]), ]),
], layout: Tables\Enums\FiltersLayout::AboveContentCollapsible) ])
->actions([ ->actions([
]) ])
->bulkActions([ ->bulkActions([

@ -102,9 +102,6 @@ class InvoiceResource extends Resource
->sortable() ->sortable()
->extraHeaderAttributes(['class' => 'w-full']) ->extraHeaderAttributes(['class' => 'w-full'])
->searchable(), ->searchable(),
Tables\Columns\TextColumn::make('status')
->badge(InvoiceStatus::class)
->sortable(),
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->label('Created') ->label('Created')
->date() ->date()
@ -126,17 +123,18 @@ class InvoiceResource extends Resource
->money('USD') ->money('USD')
->weight('bold') ->weight('bold')
->alignRight(), ->alignRight(),
Tables\Columns\TextColumn::make('status')
->badge(InvoiceStatus::class)
->sortable(),
]) ])
->filters([ ->filters([
Tables\Filters\Filter::make('created_at') Tables\Filters\Filter::make('created_at')
->form([ ->form([
Split::make([
DatePicker::make('created_from') DatePicker::make('created_from')
->label('From date'), ->label('From date'),
DatePicker::make('created_until') DatePicker::make('created_until')
->label('Until date'), ->label('Until date'),
]),
]) ])
->query(function (Builder $query, array $data): Builder { ->query(function (Builder $query, array $data): Builder {
return $query return $query
@ -151,11 +149,9 @@ class InvoiceResource extends Resource
}), }),
Tables\Filters\SelectFilter::make('status') Tables\Filters\SelectFilter::make('status')
->options(InvoiceStatus::class) ->options(InvoiceStatus::class),
->columnSpan(1),
], layout: Tables\Enums\FiltersLayout::AboveContentCollapsible) ], )
->filtersFormColumns(3)
->groups([ ->groups([
'status', 'status',

@ -223,15 +223,29 @@ class OrderResource extends Resource
{ {
return $table return $table
->columns([ ->columns([
Tables\Columns\IconColumn::make('alert')
->getStateUsing(fn ($record) => $record->is_alert_danger || $record->is_alert_warning)
->label('')
->color(fn ($record) => $record->is_alert_danger ? 'danger' : 'warning')
->icon(function ($record) {
return $record->is_alert_danger
? 'lucide-calendar-clock' : ($record->rush
? OrderAttributes::rush->getIcon() : null);
})
->size(Tables\Columns\IconColumn\IconColumnSize::Small),
TextColumn::make('internal_po') TextColumn::make('internal_po')
->label('Internal PO') ->label('Internal PO')
->fontFamily('mono') ->fontFamily('mono')
->color('info') ->color('info')
->searchable() ->searchable()
->sortable(), ->sortable(),
TextColumn::make('customer.company_name') TextColumn::make('customer.company_name')
->searchable() ->searchable()
->sortable(), ->sortable(),
TextColumn::make('customer_po') TextColumn::make('customer_po')
->label('PO') ->label('PO')
->wrap() ->wrap()
@ -242,18 +256,23 @@ class OrderResource extends Resource
->extraHeaderAttributes([ ->extraHeaderAttributes([
'class' => 'w-full', 'class' => 'w-full',
]), ]),
TextColumn::make('order_date') TextColumn::make('order_date')
->searchable() ->searchable()
->sortable(), ->sortable(),
TextColumn::make('due_date') TextColumn::make('due_date')
->searchable() ->searchable()
->sortable(), ->sortable(),
TextColumn::make('status') TextColumn::make('status')
->badge() ->badge()
->searchable() ->searchable()
->sortable(), ->sortable(),
]) ])
->defaultSort('order_date', 'desc') ->defaultSort('order_date', 'desc')
->filters([ ->filters([
Tables\Filters\Filter::make('order_date') Tables\Filters\Filter::make('order_date')
->form([ ->form([
@ -271,10 +290,12 @@ class OrderResource extends Resource
fn (Builder $query, $date): Builder => $query->whereDate('order_date', '<=', $date), fn (Builder $query, $date): Builder => $query->whereDate('order_date', '<=', $date),
); );
}), }),
], layout: Tables\Enums\FiltersLayout::AboveContentCollapsible) ], )
->actions([ ->actions([
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),
]) ])
->bulkActions([ ->bulkActions([
Tables\Actions\BulkActionGroup::make([ Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(), Tables\Actions\DeleteBulkAction::make(),

@ -2,8 +2,12 @@
namespace App\Filament\Resources\OrderResource\Pages; namespace App\Filament\Resources\OrderResource\Pages;
use App\Enums\OrderAttributes;
use App\Enums\OrderStatus;
use App\Filament\Resources\OrderResource; use App\Filament\Resources\OrderResource;
use App\Models\Order;
use Filament\Actions; use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords; use Filament\Resources\Pages\ListRecords;
class ListOrders extends ListRecords class ListOrders extends ListRecords
@ -16,4 +20,66 @@ class ListOrders extends ListRecords
Actions\CreateAction::make(), Actions\CreateAction::make(),
]; ];
} }
public function getTabs(): array
{
return [
null => Tab::make('All')
->icon('lucide-layout-grid'),
'overdue' => Tab::make()
->query(function ($query) {
return $query->whereDate('due_date', '<=', today())
->whereNot('status', OrderStatus::INVOICED)
->whereNot('status', ORderStatus::SHIPPED);
})
->icon('lucide-calendar-clock')
->badge(function () {
$count = Order::whereDate('due_date', '<=', today())
->whereNot('status', OrderStatus::INVOICED)
->whereNot('status', ORderStatus::SHIPPED)
->count();
return $count > 0 ? $count : null;
})
->badgeColor('danger'),
'rush' => Tab::make()
->query(function ($query) {
return $query->where('rush', true)
->whereNot('status', OrderStatus::INVOICED)
->whereNot('status', OrderStatus::SHIPPED);
})
->icon(OrderAttributes::rush->getIcon())
->badge(function () {
$count = Order::where('rush', true)
->whereNot('status', OrderStatus::INVOICED)
->whereNot('status', OrderStatus::SHIPPED)
->count();
return $count > 0 ? $count : null;
})
->badgeColor('warning'),
'draft' => Tab::make()
->query(fn ($query) => $query->where('status', OrderStatus::DRAFT->value))
->icon(OrderStatus::DRAFT->getIcon()),
'approved' => Tab::make()
->query(fn ($query) => $query->where('status', OrderStatus::APPROVED->value))
->icon(OrderStatus::APPROVED->getIcon()),
'production' => Tab::make()
->query(fn ($query) => $query->where('status', OrderStatus::PRODUCTION->value))
->icon(OrderStatus::PRODUCTION->getIcon()),
'shipped' => Tab::make()
->query(fn ($query) => $query->where('status', OrderStatus::SHIPPED->value))
->icon(OrderStatus::SHIPPED->getIcon()),
'invoiced' => Tab::make()
->query(fn ($query) => $query->where('status', OrderStatus::INVOICED->value))
->icon(OrderStatus::INVOICED->getIcon()),
];
}
} }

@ -45,6 +45,8 @@ class Order extends Model
protected $appends = [ protected $appends = [
'total_service_price', 'total_service_price',
'total_product_quantity', 'total_product_quantity',
'is_alert_warning',
'is_alert_danger',
]; ];
protected $casts = [ protected $casts = [
@ -80,6 +82,20 @@ class Order extends Model
return 'TN'.$year.'-'.$po; return 'TN'.$year.'-'.$po;
} }
public function getIsAlertWarningAttribute(): bool
{
if ($this->rush) {
return ! ($this->status === OrderStatus::INVOICED || $this->status === OrderStatus::SHIPPED);
}
return false;
}
public function getIsAlertDangerAttribute(): bool
{
return $this->due_date <= today() && $this->status !== OrderStatus::INVOICED && $this->status !== OrderStatus::SHIPPED;
}
public function getTotalProductQuantityAttribute(): int public function getTotalProductQuantityAttribute(): int
{ {
$total = 0; $total = 0;

@ -14,7 +14,7 @@ class OrderSeeder extends Seeder
public function run(): void public function run(): void
{ {
foreach (Customer::all() as $customer) { foreach (Customer::all() as $customer) {
Order::factory(rand(2, 50), ['customer_id' => $customer])->create(); Order::factory(rand(10, 50), ['customer_id' => $customer])->create();
} }
} }
} }

Binary file not shown.
Loading…
Cancel
Save