#79 Add sums of columns for Customer Reports
This commit is contained in:
parent
6fc753fc19
commit
fc8a2052ba
@ -4,13 +4,12 @@
|
||||
|
||||
use App\Enums\IconEnum;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\Summarizers\Summarizer;
|
||||
use Filament\Tables\Columns\Summarizers\Sum;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@ -44,25 +43,51 @@ public static function table(Table $table): Table
|
||||
->searchable()
|
||||
->extraHeaderAttributes(['class' => 'w-full']),
|
||||
|
||||
Tables\Columns\TextColumn::make('subtotal')
|
||||
Tables\Columns\TextColumn::make('invoices.subtotal')
|
||||
->label('Subtotal')
|
||||
->money()
|
||||
// ->summarize(Summarizer::make()->using(function ($query, Table $table) {
|
||||
// $createdAt = $table->getfilter('created_at')->getstate()['created_at'] ?? '1900-01-01';
|
||||
// $createdUntil = $table->getfilter('created_until')->getstate()['created_until'] ?? '2100-01-01';
|
||||
//
|
||||
// $invoiceSum = invoice::wherebetween('date', [$createdAt, $createdUntil])->sum('subtotal');
|
||||
//
|
||||
// return '$'.number_format(round($invoiceSum, 2), 2, '.', ',');
|
||||
// }))
|
||||
->alignRight()
|
||||
->getStateUsing(function (Table $table, Model $record) {
|
||||
return $record->getSubtotalAttribute(
|
||||
$table->getFilter('created_at')->getState()['created_at'],
|
||||
$table->getFilter('created_until')->getState()['created_until']
|
||||
);
|
||||
}),
|
||||
})
|
||||
->summarize(Sum::make('subtotal')
|
||||
->label('')
|
||||
->money()
|
||||
->using(fn (Table $table, $query) => $query
|
||||
->when($createdAt = $table->getFilter('created_at')->getState()['created_at'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '>=', $createdAt))
|
||||
->when($createdUntil = $table->getFilter('created_until')->getState()['created_until'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '<=', $createdUntil))
|
||||
->sum('subtotal')
|
||||
)
|
||||
),
|
||||
|
||||
Tables\Columns\TextColumn::make('gst')
|
||||
Tables\Columns\TextColumn::make('invoices.hst_amount')
|
||||
->label('HST')
|
||||
->money()
|
||||
->alignRight()
|
||||
->getStateUsing(fn (Table $table, Model $record) => $record->invoices()
|
||||
->when($createdAt = $table->getFilter('created_at')->getState()['created_at'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '>=', $createdAt))
|
||||
->when($createdUntil = $table->getFilter('created_until')->getState()['created_until'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '<=', $createdUntil))
|
||||
->sum('hst_amount'))
|
||||
->summarize(Sum::make('hst_amount')
|
||||
->label('')
|
||||
->money()
|
||||
->using(fn (Table $table, $query) => $query
|
||||
->when($createdAt = $table->getFilter('created_at')->getState()['created_at'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '>=', $createdAt))
|
||||
->when($createdUntil = $table->getFilter('created_until')->getState()['created_until'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '<=', $createdUntil))
|
||||
->sum('hst_amount')
|
||||
)
|
||||
),
|
||||
|
||||
Tables\Columns\TextColumn::make('invoices.gst_amount')
|
||||
->label('GST')
|
||||
->money()
|
||||
->alignRight()
|
||||
@ -71,9 +96,20 @@ public static function table(Table $table): Table
|
||||
$table->getFilter('created_at')->getState()['created_at'],
|
||||
$table->getFilter('created_until')->getState()['created_until']
|
||||
);
|
||||
}),
|
||||
})
|
||||
->summarize(Sum::make('gst_amount')
|
||||
->label('')
|
||||
->money()
|
||||
->using(fn (Table $table, $query) => $query
|
||||
->when($createdAt = $table->getFilter('created_at')->getState()['created_at'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '>=', $createdAt))
|
||||
->when($createdUntil = $table->getFilter('created_until')->getState()['created_until'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '<=', $createdUntil))
|
||||
->sum('gst_amount')
|
||||
)
|
||||
),
|
||||
|
||||
Tables\Columns\TextColumn::make('pst')
|
||||
Tables\Columns\TextColumn::make('invoices.pst_amount')
|
||||
->label('PST')
|
||||
->money()
|
||||
->alignRight()
|
||||
@ -82,18 +118,22 @@ public static function table(Table $table): Table
|
||||
$table->getFilter('created_at')->getState()['created_at'],
|
||||
$table->getFilter('created_until')->getState()['created_until']
|
||||
);
|
||||
}),
|
||||
})
|
||||
->summarize(Sum::make('pst_amount')
|
||||
->label('')
|
||||
->money()
|
||||
->using(fn (Table $table, $query) => $query
|
||||
->when($createdAt = $table->getFilter('created_at')->getState()['created_at'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '>=', $createdAt))
|
||||
->when($createdUntil = $table->getFilter('created_until')->getState()['created_until'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '<=', $createdUntil))
|
||||
->sum('pst_amount')
|
||||
)
|
||||
),
|
||||
|
||||
Tables\Columns\TextColumn::make('total')
|
||||
Tables\Columns\TextColumn::make('invoices.total')
|
||||
->label('Total')
|
||||
->money()
|
||||
// ->summarize(summarizer::make()->using(function ($query, table $table) {
|
||||
// $createdAt = $table->getfilter('created_at')->getstate()['created_at'] ?? '1900-01-01';
|
||||
// $createdUntil = $table->getfilter('created_until')->getstate()['created_until'] ?? '2100-01-01';
|
||||
//
|
||||
// $invoiceSum = invoice::wherebetween('date', [$createdAt, $createdUntil])->sum('total');
|
||||
//
|
||||
// return '$'.number_format(round($invoiceSum, 2), 2, '.', ',');
|
||||
// }))
|
||||
->weight(FontWeight::Bold)
|
||||
->alignRight()
|
||||
->getStateUsing(function (Table $table, Model $record) {
|
||||
@ -101,7 +141,19 @@ public static function table(Table $table): Table
|
||||
$table->getFilter('created_at')->getState()['created_at'],
|
||||
$table->getFilter('created_until')->getState()['created_until']
|
||||
);
|
||||
}),
|
||||
})
|
||||
|
||||
->summarize(Sum::make('total')
|
||||
->label('')
|
||||
->money()
|
||||
->using(fn (Table $table, $query) => $query
|
||||
->when($createdAt = $table->getFilter('created_at')->getState()['created_at'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '>=', $createdAt))
|
||||
->when($createdUntil = $table->getFilter('created_until')->getState()['created_until'] ?? null,
|
||||
fn ($q) => $q->whereDate('created_at', '<=', $createdUntil))
|
||||
->sum('total')
|
||||
)
|
||||
),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('created_at')
|
||||
|
@ -52,6 +52,7 @@ public static function table(Table $table): Table
|
||||
->extraHeaderAttributes(['class' => 'w-full']),
|
||||
|
||||
TextColumn::make('productServices.amount')
|
||||
->label('Quantity')
|
||||
->alignRight()
|
||||
->getStateUsing(function (Table $table, Model $record) {
|
||||
return $record->getQuantityAttribute(
|
||||
@ -71,6 +72,7 @@ public static function table(Table $table): Table
|
||||
),
|
||||
|
||||
TextColumn::make('productServices.amount_price')
|
||||
->label('Amount')
|
||||
->alignRight()
|
||||
->money()
|
||||
->getStateUsing(function (Table $table, Model $record) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user