Sumarize IF.....

I have this column in my table:
TextColumn::make('detalles.total')
->label('Total Detalle')
->getStateUsing(fn ($record) => $record->anulado? 0 : $record->detalles->sum('total'))
->money('ARS')
->summarize([
Sum::make('total')->money('ARS')
]),
TextColumn::make('detalles.total')
->label('Total Detalle')
->getStateUsing(fn ($record) => $record->anulado? 0 : $record->detalles->sum('total'))
->money('ARS')
->summarize([
Sum::make('total')->money('ARS')
]),
this sum every proformas_detalles total where anulado = 0, but when i tried to summarize the total its sums everything. any idea?
2 Replies
ζ͜͡Gurthang
ζ͜͡GurthangOP3mo ago
this is a screen of the table:
No description
ζ͜͡Gurthang
ζ͜͡GurthangOP3mo ago
THE ANSWER:
TextColumn::make('detalles.total')
->label('Total Detalle')
->getStateUsing(fn ($record) => $record->anulado? 0 : $record->detalles->sum('total'))
->money('ARS')
->summarize([
Sum::make('total')->query(fn (\Illuminate\Database\Query\Builder $query) =>
$query
->join('proformas', 'proformas.id', '=', 'proformas_detalles.proforma_id')
->where('anulado', false))->money('ARS')
]),
TextColumn::make('detalles.total')
->label('Total Detalle')
->getStateUsing(fn ($record) => $record->anulado? 0 : $record->detalles->sum('total'))
->money('ARS')
->summarize([
Sum::make('total')->query(fn (\Illuminate\Database\Query\Builder $query) =>
$query
->join('proformas', 'proformas.id', '=', 'proformas_detalles.proforma_id')
->where('anulado', false))->money('ARS')
]),
Want results from more Discord servers?
Add your server