Skip to content

Commit

Permalink
Add zero fallback to sum() calls
Browse files Browse the repository at this point in the history
If there are no data, sum() doesn't return zero but null.
Passing null to the internal PHP functions causes issues
and falling back to "zero" seems like a good option in
all of the affected places.

remp/crm#2706
  • Loading branch information
rootpd committed Jan 18, 2023
1 parent 6524f9c commit 352640a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Models/Generator/templates/invoice/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
<hr>

{php ksort($vatRates)}
{var $totalPrice = $invoice->related('invoice_items')->sum('price * count')}
{var $totalPrice = $invoice->related('invoice_items')->sum('price * count') ?? 0.00}

<!-- notes -->
<div class="cell-xs-4 float">
Expand Down Expand Up @@ -307,8 +307,8 @@
<tbody>
{foreach $vatRates as $rate => $_}
<tr>
{var $itemsPrice = $invoice->related('invoice_items')->where('vat', $rate)->sum('price * count')}
{var $itemsPriceWithoutVat = $invoice->related('invoice_items')->where('vat', $rate)->sum('price_without_vat * count')}
{var $itemsPrice = $invoice->related('invoice_items')->where('vat', $rate)->sum('price * count') ?? 0.00}
{var $itemsPriceWithoutVat = $invoice->related('invoice_items')->where('vat', $rate)->sum('price_without_vat * count') ?? 0.00}
{var $vatAmount = $itemsPrice - $itemsPriceWithoutVat}

<td>{$rate}%</td>
Expand Down

0 comments on commit 352640a

Please sign in to comment.