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')
->required()
->default(today()),
])->columns(2),
]);
])
->columns(2)
->columnSpan(3),
])->columns(3);
}
public static function table(Table $table): Table
@ -73,15 +75,14 @@ public static function table(Table $table): Table
->label('End Date')
->date('Y-m-d'),
TextColumn::make('total')
->label('Balance Due')
->weight(FontWeight::Bold)
->money(),
TextColumn::make('balance')
->weight(FontWeight::Bold)
->money(),
// ->getStateUsing(fn (Invoice))
])
->defaultSort('id', 'desc')
->filters([
])
->actions([]);
->defaultSort('id', 'desc');
}
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),
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')
->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)
->hidden(fn (?Invoice $record) => $record === null),
->hidden(fn (?Invoice $record) => $record === null)
->extraAttributes(['class' => 'h-full']),
])
->columns(3)

View File

@ -28,6 +28,7 @@
use Filament\Resources\Resource;
use Filament\Support\Enums\MaxWidth;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn\IconColumnSize;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Guava\FilamentClusters\Forms\Cluster;
@ -118,6 +119,10 @@ public static function form(Form $form): Form
->label('Order ID')
->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')
->label('Created')
->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()),
])
->columnSpan(1)
->hidden(fn (?Order $record) => $record === null),
->hidden(fn (?Order $record) => $record === null)
->extraAttributes(['class' => 'h-full']),
])
->columns(6)
->columnSpan(2),
@ -144,21 +150,29 @@ public static function form(Form $form): Form
->datalist(OrderProduct::all()->unique('color')->pluck('color')->toArray()),
Cluster::make([
TextInput::make('xs')
->placeholder('xs'),
->placeholder('xs')
->rules('numeric'),
TextInput::make('s')
->placeholder('s'),
->placeholder('s')
->rules('numeric'),
TextInput::make('m')
->placeholder('m'),
->placeholder('m')
->rules('numeric'),
TextInput::make('l')
->placeholder('l'),
->placeholder('l')
->rules('numeric'),
TextInput::make('xl')
->placeholder('xl'),
->placeholder('xl')
->rules('numeric'),
TextInput::make('2xl')
->placeholder('2xl'),
->placeholder('2xl')
->rules('numeric'),
TextInput::make('3xl')
->placeholder('3xl'),
->placeholder('3xl')
->rules('numeric'),
TextInput::make('osfa')
->placeholder('osfa'),
->placeholder('osfa')
->rules('numeric'),
])
->label('Sizes'),
])
@ -197,13 +211,16 @@ public static function form(Form $form): Form
->label('Logo Name'),
TextInput::make('serviceFileSetupNumber')
->label('Setup')
->columnSpan(1),
->columnSpan(1)
->rules('numeric'),
Cluster::make([
TextInput::make('serviceFileWidth')
->prefix('w'),
->prefix('w')
->rules('numeric'),
TextInput::make('serviceFileHeight')
->prefix('h'),
->prefix('h')
->rules('numeric'),
])
->label('Dimensions (inches)')
->columnSpan(4),
@ -212,12 +229,14 @@ public static function form(Form $form): Form
->label('Quantity')
->live()
->prefix('#')
->columnSpan(2),
->columnSpan(2)
->rules('numeric'),
TextInput::make('amount_price')
->label('Amount')
->prefix('$')
->columnSpan(2),
->columnSpan(2)
->rules('numeric'),
]),
Grid::make(9)
@ -254,7 +273,7 @@ public static function table(Table $table): Table
? 'lucide-calendar-clock' : ($record->rush
? OrderAttributes::rush->getIcon() : null);
})
->size(Tables\Columns\IconColumn\IconColumnSize::Medium),
->size(IconColumnSize::Medium),
TextColumn::make('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()),
])
->columnSpan(1)
->hidden(fn (?TaxRate $record) => $record === null),
->hidden(fn (?TaxRate $record) => $record === null)
->extraAttributes(['class' => 'h-full']),
])->columns(3);
}
@ -94,8 +95,8 @@ public static function getPages(): array
{
return [
'index' => Pages\ListTaxRates::route('/'),
'create' => Pages\CreateTaxRate::route('/create'),
'edit' => Pages\EditTaxRate::route('/{record}/edit'),
// 'create' => Pages\CreateTaxRate::route('/create'),
// 'edit' => Pages\EditTaxRate::route('/{record}/edit'),
];
}
}

View File

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

View File

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

View File

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

View File

@ -33,6 +33,8 @@ class ProductService extends Model
'price',
];
protected $touches = ['order'];
public function getPriceAttribute(): float
{
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
{
$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->calculateTotals();

Binary file not shown.

View File

@ -72,7 +72,7 @@
</div>
<br>
<div>
${{number_format($invoiceReport->total, 2)}}
${{number_format($invoiceReport->balance, 2)}}
</div>
</div>
</div>
@ -95,10 +95,10 @@
<tr>
<td>{{Date::make($invoice->created_at)->format('Y-m-d')}}</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">{{!$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>
</tr>
@endforeach

View File

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

View File

@ -1,6 +1,6 @@
@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="">
@ -135,7 +135,7 @@
<!-- Products Table -->
<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">
<th>SKU</th>
<th>Product Name</th>
@ -183,7 +183,7 @@
<!-- Services Table -->
<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">
<th>Placement & Service</th>
<th class="w-50">Logo Name & Instructions</th>
@ -201,7 +201,7 @@
</div>
<br>
<div class="text-uppercase">
<code style="font-size: 11px">
<code style="font-size: 12px">
{{$service->serviceFile->code}}
</code>
</div>

View File

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

View File

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