From 5a54672aad5a08e4cf4ffc73c680db2bdf66eaa6 Mon Sep 17 00:00:00 2001 From: Nisse Lommerde Date: Wed, 20 Nov 2024 20:09:45 -0500 Subject: [PATCH] Work on invoice report table (added date groups) --- .../Resources/CustomerReportResource.php | 3 +- .../Resources/InvoiceReportResource.php | 35 +++++++++++-------- .../Pages/ListInvoiceReports.php | 5 ++- app/Models/Invoice.php | 1 + database/factories/InvoiceFactory.php | 1 + database/seeders/OrderSeeder.php | 2 +- todos | 30 ++++++++++++++++ 7 files changed, 60 insertions(+), 17 deletions(-) diff --git a/app/Filament/Resources/CustomerReportResource.php b/app/Filament/Resources/CustomerReportResource.php index 7a86555..b19db79 100644 --- a/app/Filament/Resources/CustomerReportResource.php +++ b/app/Filament/Resources/CustomerReportResource.php @@ -38,7 +38,8 @@ class CustomerReportResource extends Resource Tables\Columns\TextColumn::make('company_name') ->label('Customer') ->sortable() - ->searchable(), + ->searchable() + ->extraHeaderAttributes(['class' => 'w-full']), Tables\Columns\TextColumn::make('subtotal') ->money('usd') diff --git a/app/Filament/Resources/InvoiceReportResource.php b/app/Filament/Resources/InvoiceReportResource.php index b4b2575..ce4d181 100644 --- a/app/Filament/Resources/InvoiceReportResource.php +++ b/app/Filament/Resources/InvoiceReportResource.php @@ -9,6 +9,7 @@ use Filament\Forms\Components\DatePicker; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; +use Filament\Tables\Grouping\Group; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; @@ -36,21 +37,15 @@ class InvoiceReportResource extends Resource { return $table ->columns([ - Tables\Columns\TextColumn::make('year') - ->getStateUsing(fn (Order $record) => $record->invoice->date) - ->date('Y'), - - Tables\Columns\TextColumn::make('month') - ->getStateUsing(fn (Order $record) => $record->invoice->date) - ->date('m'), + Tables\Columns\TextColumn::make('invoice.date') + ->label('Date') + ->date('Y-m-d'), Tables\Columns\TextColumn::make('customer_po') ->color('code') ->weight('bold') ->extraHeaderAttributes(['class' => 'w-full']), - Tables\Columns\TextColumn::make('invoice.date') - ->label('Date'), Tables\Columns\TextColumn::make('total_service_price') ->label('Subtotal') ->alignRight() @@ -87,6 +82,7 @@ class InvoiceReportResource extends Resource Tables\Columns\TextColumn::make('invoice.status') ->badge(InvoiceStatus::class), ]) + ->filters([ Tables\Filters\SelectFilter::make('customer') ->relationship('customer', 'company_name') @@ -95,7 +91,7 @@ class InvoiceReportResource extends Resource ->placeholder('Select a customer...') ->selectablePlaceholder(false) ->query(function (array $data, Builder $query): Builder { - return $query->where('customer_id', $data['value'] ?? '-1'); + return $query->where('orders.customer_id', $data['value'] ?? '-1'); }), Tables\Filters\Filter::make('date_from') @@ -121,11 +117,22 @@ class InvoiceReportResource extends Resource }), ], layout: Tables\Enums\FiltersLayout::AboveContent) + ->hiddenFilterIndicators() - ->actions([// Action::make('generateReport') - // ->label('Make Report') - // ->icon('lucide-sticky-note'), - ]); + + ->actions([]) + ->defaultGroup( + Group::make('date') + ->getKeyFromRecordUsing(fn (Order $record): string => $record->invoice->date->format('Y-m-0')) + ->getTitleFromRecordUsing(fn (Order $record): string => $record->invoice->date->format('F Y')) + ->orderQueryUsing(function (Builder $query) { + + return $query->join('invoices', 'orders.invoice_id', '=', 'invoices.id') + ->orderBy('invoices.date', 'desc'); + }) + ->titlePrefixedWithLabel(false), + ); + // ->defaultSort('date', 'desc'); } diff --git a/app/Filament/Resources/InvoiceReportResource/Pages/ListInvoiceReports.php b/app/Filament/Resources/InvoiceReportResource/Pages/ListInvoiceReports.php index 12f06c4..c3d9335 100644 --- a/app/Filament/Resources/InvoiceReportResource/Pages/ListInvoiceReports.php +++ b/app/Filament/Resources/InvoiceReportResource/Pages/ListInvoiceReports.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\InvoiceReportResource\Pages; use App\Filament\Resources\InvoiceReportResource; +use Filament\Actions\Action; use Filament\Resources\Pages\ListRecords; class ListInvoiceReports extends ListRecords @@ -14,7 +15,9 @@ class ListInvoiceReports extends ListRecords protected function getHeaderActions(): array { return [ - // Actions\CreateAction::make(), + Action::make('generateReport') + ->label('Make Report') + ->icon('lucide-printer'), ]; } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 6a570ab..befbcc9 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -30,6 +30,7 @@ class Invoice extends Model ]; protected $casts = [ + 'date' => 'datetime', 'total' => 'decimal:2', 'subtotal' => 'decimal:2', 'status' => InvoiceStatus::class, diff --git a/database/factories/InvoiceFactory.php b/database/factories/InvoiceFactory.php index 259de6e..1c87eb8 100644 --- a/database/factories/InvoiceFactory.php +++ b/database/factories/InvoiceFactory.php @@ -20,6 +20,7 @@ class InvoiceFactory extends Factory 'created_at' => Carbon::now()->subDays(rand(1, 30)), 'gst' => true, 'pst' => $this->faker->boolean(40), + 'date' => Carbon::now()->subDays(rand(1, 60)), 'status' => $this->faker->randomElement(InvoiceStatus::cases())->value, 'customer_id' => $customer->id, 'updated_at' => Carbon::now(), diff --git a/database/seeders/OrderSeeder.php b/database/seeders/OrderSeeder.php index 813f3de..aea9c52 100644 --- a/database/seeders/OrderSeeder.php +++ b/database/seeders/OrderSeeder.php @@ -14,7 +14,7 @@ class OrderSeeder extends Seeder public function run(): void { foreach (Customer::all() as $customer) { - Order::factory(rand(10, 50), ['customer_id' => $customer])->create(); + Order::factory(rand(50, 150), ['customer_id' => $customer])->create(); } } } diff --git a/todos b/todos index 856867d..3158327 100644 --- a/todos +++ b/todos @@ -1,4 +1,34 @@ todo +Invoice Report +-------------- +Model ?customer > table + +Quotes +------ +- Add date? + +Orders +------- +- Fix service type +- PDF pre-pro property +- Change order status from table > do thru checkboxes? +- Tabs for quotes, invoices, packingSlips? +- Fix total order price +- Duplicate to new order + +Shipping Entries +----------------- +- Clickable URL in title + +Others +------- +- ServiceFile findOrCreate +- Way to set GST and PST +- Remove service_type from ProductService? +- order pdfs checkboxes don't tick no more +- duplicate order button (edit page header) +- badge for invoices + - finish invoice styling - add to invoice button on order page