Skip to content

Commit ff9e615

Browse files
committed
Slight update to allow zero fields in invoice items
1 parent b8122ab commit ff9e615

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Pdf/PdfInvoice.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,22 @@ public function totalTaxAmount(): Money
144144
* Since discounts apply at the invoice level and taxes at the item level,
145145
* we allocate the discount across items before computing taxes.
146146
*/
147-
$allocatedDiscounts = $totalDiscount->allocate(...array_map(
147+
$ratios = array_map(
148148
fn ($item) => $item->subTotalAmount()->abs()->getMinorAmount()->toInt(),
149149
$this->items
150-
));
150+
);
151+
// Check if all ratios are zero
152+
$hasNonZeroRatios = collect($ratios)->filter(fn($ratio) => $ratio > 0)->isNotEmpty();
153+
154+
if ($hasNonZeroRatios) {
155+
// Normal allocation when we have non-zero ratios
156+
$allocatedDiscounts = $totalDiscount->allocate(...$ratios);
157+
} else {
158+
// All items have zero price - return zero amounts for each item
159+
$allocatedDiscounts = collect($ratios)->map(function() use ($totalDiscount) {
160+
return Money::of('0.00', $totalDiscount->getCurrency());
161+
})->toArray();
162+
}
151163

152164
$totalTaxAmount = Money::of(0, $this->getCurrency());
153165

0 commit comments

Comments
 (0)