astronomic
When selecting filters in a list of records, the widget does not update
class InvoicesTotalization extends BaseWidget
{
protected static string $view = 'filament.resources.invoice-resource.widgets.invoices-totalization';
protected static ?string $pollingInterval = null;
protected $listeners = ['updateInvoicesTotalization' => '$refresh'];
public $tableFilters;
protected $queryString = ['tableFilters'];
protected function getCards(): array
{
$data = [];
$query = Invoice::query();
if ($this->tableFilters && isset($this->tableFilters['status'])) {
$query->where('status', $this->tableFilters['status']['value']);
}
if ($this->tableFilters && isset($this->tableFilters['street'])) {
$query->whereHas('Client', function($q){
$q->where('street', 'LIKE', '%'.$this->tableFilters['street']['street'].'%');
});
}
if ($this->tableFilters && isset($this->tableFilters['number'])) {
$query->whereHas('Client', function($q){
$q->where('address_number', $this->tableFilters['number']['number']);
});
}
if ($this->tableFilters && isset($this->tableFilters['invoice_date'])) {
$query->whereBetween('invoice_date', [$this->tableFilters['invoice_date']['start_date'], $this->tableFilters['invoice_date']['end_date']]);
}
$data['subtotal'] = $query->sum('subtotal');
$data['iva'] = $query->sum('iva');
$data['total'] = $query->sum('total');
return [
Card::make('SUBTOTAL: ', number_format($data['subtotal'], 2, ',', '.')),
Card::make('IVA: ', number_format($data['iva'], 2, ',', '.')),
Card::make('TOTAL: ', number_format($data['total'], 2, ',', '.')),
];
}
}
5 replies
Doubts with summarize(Count)
It's already done like that, even though it's not in the post. But that's not my problem. I don't want the space from the two 'ghost' columns to show up in the table. I would need another option. Thanks anyway.
21 replies