Added numeric validation rules, some styling fixes

This commit is contained in:
Nisse Lommerde 2025-02-07 23:41:26 -05:00
parent 66168d0919
commit 4d451d2aba
15 changed files with 90 additions and 48 deletions

View File

@ -49,8 +49,10 @@ public static function form(Form $form): Form
DatePicker::make('date_end') DatePicker::make('date_end')
->required() ->required()
->default(today()), ->default(today()),
])->columns(2), ])
]); ->columns(2)
->columnSpan(3),
])->columns(3);
} }
public static function table(Table $table): Table public static function table(Table $table): Table
@ -73,15 +75,14 @@ public static function table(Table $table): Table
->label('End Date') ->label('End Date')
->date('Y-m-d'), ->date('Y-m-d'),
TextColumn::make('total') TextColumn::make('total')
->label('Balance Due')
->weight(FontWeight::Bold) ->weight(FontWeight::Bold)
->money(), ->money(),
TextColumn::make('balance')
->weight(FontWeight::Bold)
->money(),
// ->getStateUsing(fn (Invoice))
]) ])
->defaultSort('id', 'desc') ->defaultSort('id', 'desc');
->filters([
])
->actions([]);
} }
public static function canAccess(): bool public static function canAccess(): bool

View File

@ -112,7 +112,7 @@ public static function form(Form $form): Form
->content(fn (Invoice $record): ?string => $record->internal_id), ->content(fn (Invoice $record): ?string => $record->internal_id),
Placeholder::make('Amounts') Placeholder::make('Amounts')
->content(fn (Invoice $record): ?string => 'Total: $'.$record->total.', balance: $'.$record->remainingBalance()), ->content(fn (Invoice $record): ?string => 'Total: $'.number_format($record->total, 2).', balance: $'.number_format($record->remainingBalance(), 2)),
Placeholder::make('Tax Rates when created') Placeholder::make('Tax Rates when created')
->content(fn (Invoice $record): ?string => $record->gst_rate.'% GST, '.$record->pst_rate.'% PST, '.$record->hst_rate.'% HST'), ->content(fn (Invoice $record): ?string => $record->gst_rate.'% GST, '.$record->pst_rate.'% PST, '.$record->hst_rate.'% HST'),
@ -123,7 +123,8 @@ public static function form(Form $form): Form
]) ])
->columnSpan(1) ->columnSpan(1)
->hidden(fn (?Invoice $record) => $record === null), ->hidden(fn (?Invoice $record) => $record === null)
->extraAttributes(['class' => 'h-full']),
]) ])
->columns(3) ->columns(3)

View File

@ -28,6 +28,7 @@
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Support\Enums\MaxWidth; use Filament\Support\Enums\MaxWidth;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Columns\IconColumn\IconColumnSize;
use Filament\Tables\Columns\TextColumn; use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table; use Filament\Tables\Table;
use Guava\FilamentClusters\Forms\Cluster; use Guava\FilamentClusters\Forms\Cluster;
@ -118,6 +119,10 @@ public static function form(Form $form): Form
->label('Order ID') ->label('Order ID')
->content(fn (Order $record): ?string => $record->internal_po), ->content(fn (Order $record): ?string => $record->internal_po),
Placeholder::make('total_service_price')
->label('Total service price')
->content(fn (Order $record): ?string => '$'.number_format($record->total_service_price, 2)),
Placeholder::make('created_at') Placeholder::make('created_at')
->label('Created') ->label('Created')
->content(fn (Order $record): ?string => $record->created_at?->diffForHumans()), ->content(fn (Order $record): ?string => $record->created_at?->diffForHumans()),
@ -127,7 +132,8 @@ public static function form(Form $form): Form
->content(fn (Order $record): ?string => $record->updated_at?->diffForHumans()), ->content(fn (Order $record): ?string => $record->updated_at?->diffForHumans()),
]) ])
->columnSpan(1) ->columnSpan(1)
->hidden(fn (?Order $record) => $record === null), ->hidden(fn (?Order $record) => $record === null)
->extraAttributes(['class' => 'h-full']),
]) ])
->columns(6) ->columns(6)
->columnSpan(2), ->columnSpan(2),
@ -144,21 +150,29 @@ public static function form(Form $form): Form
->datalist(OrderProduct::all()->unique('color')->pluck('color')->toArray()), ->datalist(OrderProduct::all()->unique('color')->pluck('color')->toArray()),
Cluster::make([ Cluster::make([
TextInput::make('xs') TextInput::make('xs')
->placeholder('xs'), ->placeholder('xs')
->rules('numeric'),
TextInput::make('s') TextInput::make('s')
->placeholder('s'), ->placeholder('s')
->rules('numeric'),
TextInput::make('m') TextInput::make('m')
->placeholder('m'), ->placeholder('m')
->rules('numeric'),
TextInput::make('l') TextInput::make('l')
->placeholder('l'), ->placeholder('l')
->rules('numeric'),
TextInput::make('xl') TextInput::make('xl')
->placeholder('xl'), ->placeholder('xl')
->rules('numeric'),
TextInput::make('2xl') TextInput::make('2xl')
->placeholder('2xl'), ->placeholder('2xl')
->rules('numeric'),
TextInput::make('3xl') TextInput::make('3xl')
->placeholder('3xl'), ->placeholder('3xl')
->rules('numeric'),
TextInput::make('osfa') TextInput::make('osfa')
->placeholder('osfa'), ->placeholder('osfa')
->rules('numeric'),
]) ])
->label('Sizes'), ->label('Sizes'),
]) ])
@ -197,13 +211,16 @@ public static function form(Form $form): Form
->label('Logo Name'), ->label('Logo Name'),
TextInput::make('serviceFileSetupNumber') TextInput::make('serviceFileSetupNumber')
->label('Setup') ->label('Setup')
->columnSpan(1), ->columnSpan(1)
->rules('numeric'),
Cluster::make([ Cluster::make([
TextInput::make('serviceFileWidth') TextInput::make('serviceFileWidth')
->prefix('w'), ->prefix('w')
->rules('numeric'),
TextInput::make('serviceFileHeight') TextInput::make('serviceFileHeight')
->prefix('h'), ->prefix('h')
->rules('numeric'),
]) ])
->label('Dimensions (inches)') ->label('Dimensions (inches)')
->columnSpan(4), ->columnSpan(4),
@ -212,12 +229,14 @@ public static function form(Form $form): Form
->label('Quantity') ->label('Quantity')
->live() ->live()
->prefix('#') ->prefix('#')
->columnSpan(2), ->columnSpan(2)
->rules('numeric'),
TextInput::make('amount_price') TextInput::make('amount_price')
->label('Amount') ->label('Amount')
->prefix('$') ->prefix('$')
->columnSpan(2), ->columnSpan(2)
->rules('numeric'),
]), ]),
Grid::make(9) Grid::make(9)
@ -254,7 +273,7 @@ public static function table(Table $table): Table
? 'lucide-calendar-clock' : ($record->rush ? 'lucide-calendar-clock' : ($record->rush
? OrderAttributes::rush->getIcon() : null); ? OrderAttributes::rush->getIcon() : null);
}) })
->size(Tables\Columns\IconColumn\IconColumnSize::Medium), ->size(IconColumnSize::Medium),
TextColumn::make('internal_po') TextColumn::make('internal_po')
->label('Internal PO') ->label('Internal PO')

View File

@ -51,7 +51,8 @@ public static function form(Form $form): Form
->content(fn (TaxRate $record): ?string => $record->updated_at?->diffForHumans()), ->content(fn (TaxRate $record): ?string => $record->updated_at?->diffForHumans()),
]) ])
->columnSpan(1) ->columnSpan(1)
->hidden(fn (?TaxRate $record) => $record === null), ->hidden(fn (?TaxRate $record) => $record === null)
->extraAttributes(['class' => 'h-full']),
])->columns(3); ])->columns(3);
} }
@ -94,8 +95,8 @@ public static function getPages(): array
{ {
return [ return [
'index' => Pages\ListTaxRates::route('/'), 'index' => Pages\ListTaxRates::route('/'),
'create' => Pages\CreateTaxRate::route('/create'), // 'create' => Pages\CreateTaxRate::route('/create'),
'edit' => Pages\EditTaxRate::route('/{record}/edit'), // 'edit' => Pages\EditTaxRate::route('/{record}/edit'),
]; ];
} }
} }

View File

@ -45,7 +45,8 @@ class Invoice extends Model
'has_gst' => 'boolean', 'has_gst' => 'boolean',
'has_pst' => 'boolean', 'has_pst' => 'boolean',
'has_hst' => 'boolean', 'has_hst' => 'boolean',
'date' => 'datetime', 'date' => 'date',
'due_date' => 'date',
'status' => InvoiceStatus::class, 'status' => InvoiceStatus::class,
'subtotal' => 'float', 'subtotal' => 'float',
'pst_amount' => 'float', 'pst_amount' => 'float',

View File

@ -25,6 +25,7 @@ class InvoiceReport extends Model
protected $appends = [ protected $appends = [
'total', 'total',
'balance',
]; ];
protected $casts = [ protected $casts = [
@ -61,6 +62,11 @@ public function getTotalAttribute()
return $this->invoices()->sum('total'); return $this->invoices()->sum('total');
} }
public function getBalanceAttribute()
{
return $this->invoices->sum(fn (Invoice $invoice) => $invoice->remainingBalance());
}
public function customer(): BelongsTo public function customer(): BelongsTo
{ {
return $this->belongsTo(Customer::class); return $this->belongsTo(Customer::class);

View File

@ -21,6 +21,8 @@ class OrderProduct extends Model
'color', 'color',
]; ];
protected $touches = ['order'];
public function totalQuantity(): int public function totalQuantity(): int
{ {
return array_sum($this->productSizes()->pluck('amount')->toArray()); return array_sum($this->productSizes()->pluck('amount')->toArray());

View File

@ -33,6 +33,8 @@ class ProductService extends Model
'price', 'price',
]; ];
protected $touches = ['order'];
public function getPriceAttribute(): float public function getPriceAttribute(): float
{ {
return number_format($this->amount * $this->amount_price, 2); return number_format($this->amount * $this->amount_price, 2);

View File

@ -23,7 +23,7 @@ public function creating(Invoice $invoice): void
public function created(Invoice $invoice): void public function created(Invoice $invoice): void
{ {
$invoice->internal_id = 'INV4'.str_pad($invoice->id, 5, '0', STR_PAD_LEFT); $invoice->internal_id = 'INV4'.str_pad($invoice->id, 4, '0', STR_PAD_LEFT);
$invoice->saveQuietly(); $invoice->saveQuietly();
$invoice->calculateTotals(); $invoice->calculateTotals();

Binary file not shown.

View File

@ -72,7 +72,7 @@
</div> </div>
<br> <br>
<div> <div>
${{number_format($invoiceReport->total, 2)}} ${{number_format($invoiceReport->balance, 2)}}
</div> </div>
</div> </div>
</div> </div>
@ -95,10 +95,10 @@
<tr> <tr>
<td>{{Date::make($invoice->created_at)->format('Y-m-d')}}</td> <td>{{Date::make($invoice->created_at)->format('Y-m-d')}}</td>
<td>{{$invoice->internal_id}}</td> <td>{{$invoice->internal_id}}</td>
<td class="text-end">${{$invoice->subtotal}}</td> <td class="text-end">${{number_format($invoice->subtotal, 2)}}</td>
<td class="text-end">${{number_format($invoice->gst_amount, 2)}}</td> <td class="text-end">${{number_format($invoice->gst_amount, 2)}}</td>
<td class="text-end">{{!$invoice->pst_amount ? '-' : '$'.number_format($invoice->pst_amount, 2)}}</td> <td class="text-end">{{!$invoice->pst_amount ? '-' : '$'.number_format($invoice->pst_amount, 2)}}</td>
<td class="text-end">${{$invoice->total}}</td> <td class="text-end">${{number_format($invoice->remainingBalance(), 2)}}</td>
<td class="text-end">{{$invoice->status->value}}</td> <td class="text-end">{{$invoice->status->value}}</td>
</tr> </tr>
@endforeach @endforeach

View File

@ -30,9 +30,9 @@
BILL TO BILL TO
</div> </div>
<div> <div>
{{$invoice->customer->company_name}} <br> {{$invoice->customer->company_name ?? ''}} <br>
{{$invoice->customer->billing_address_line_1}} <br> {{$invoice->customer->billing_address_line_1 ?? ''}} <br>
{{$invoice->customer->billing_address_line_2}} <br> {{$invoice->customer->billing_address_line_2 ?? ''}} <br>
</div> </div>
</div> </div>
@ -50,13 +50,19 @@
<div> <div>
<div> <div>
@if(isset($invoice->internal_id))
{{$invoice->internal_id}} {{$invoice->internal_id}}
@endif
</div> </div>
<div> <div>
{{$invoice->date}} @if(isset($invoice->date))
{{$invoice->date->format('Y-m-d')}}
@endif
</div> </div>
<div> <div>
{{$invoice->due_date}} @if(isset($invoice->due_date))
{{$invoice->due_date->format('Y-m-d')}}
@endif
</div> </div>
</div> </div>
</div> </div>
@ -110,7 +116,7 @@
<div>${{number_format($invoice->pst_amount, 2)}}</div> <div>${{number_format($invoice->pst_amount, 2)}}</div>
<div>${{number_format($invoice->total, 2)}}</div> <div>${{number_format($invoice->total, 2)}}</div>
<br> <br>
<div class="fw-bold">${{number_format($invoice->total, 2)}}</div> <div class="fw-bold">${{number_format($invoice->remainingBalance(), 2)}}</div>
</div> </div>
<div class="fw-bold text-end"> <div class="fw-bold text-end">

View File

@ -1,6 +1,6 @@
@extends('layouts.pdf') @extends('layouts.pdf')
<title>Top Notch Order {{$order->internal_po}}</title> <title>Top Notch Order {{$order->internal_po ?? ''}}</title>
<div class="container-fluid "> <div class="container-fluid ">
<div class=""> <div class="">
@ -135,7 +135,7 @@
<!-- Products Table --> <!-- Products Table -->
<div class="row mt-4"> <div class="row mt-4">
<table class="table table-striped" style="font-size: 11px;"> <table class="table table-striped" style="font-size: 12px;">
<thead class="opacity-50 fw-normal"> <thead class="opacity-50 fw-normal">
<th>SKU</th> <th>SKU</th>
<th>Product Name</th> <th>Product Name</th>
@ -183,7 +183,7 @@
<!-- Services Table --> <!-- Services Table -->
<div class="row mt-2"> <div class="row mt-2">
<table class="table table-striped" style="font-size: 11px;"> <table class="table table-striped" style="font-size: 12px;">
<thead class="opacity-50 fw-normal"> <thead class="opacity-50 fw-normal">
<th>Placement & Service</th> <th>Placement & Service</th>
<th class="w-50">Logo Name & Instructions</th> <th class="w-50">Logo Name & Instructions</th>
@ -201,7 +201,7 @@
</div> </div>
<br> <br>
<div class="text-uppercase"> <div class="text-uppercase">
<code style="font-size: 11px"> <code style="font-size: 12px">
{{$service->serviceFile->code}} {{$service->serviceFile->code}}
</code> </code>
</div> </div>

View File

@ -50,7 +50,7 @@
->assertHasNoErrors(); ->assertHasNoErrors();
$this->assertDatabaseHas('invoices', [ $this->assertDatabaseHas('invoices', [
'internal_id' => 'INV400001', 'internal_id' => 'INV40001',
'customer_id' => $formData['customer_id'], 'customer_id' => $formData['customer_id'],
'status' => $formData['status'], 'status' => $formData['status'],
'has_gst' => $formData['has_gst'], 'has_gst' => $formData['has_gst'],
@ -61,7 +61,7 @@
'hst_rate' => $hst_rate, 'hst_rate' => $hst_rate,
]); ]);
$invoice = Invoice::where('internal_id', 'INV400001')->firstOrFail(); $invoice = Invoice::where('internal_id', 'INV40001')->firstOrFail();
$this->assertEquals($invoice->orders->isEmpty(), true); $this->assertEquals($invoice->orders->isEmpty(), true);
}); });

View File

@ -88,7 +88,10 @@
'width' => 1.5, 'width' => 1.5,
'height' => 2.5, 'height' => 2.5,
'color_amount' => 2, 'color_amount' => 2,
'color_match' => 5.10, 'setup_amount' => 2,
'run_charge' => 10,
'color_match' => true,
'color_change' => true,
'flash' => 5.20, 'flash' => 5.20,
'fleece' => 5.30, 'fleece' => 5.30,
'poly_ink' => 5.40, 'poly_ink' => 5.40,