Skip to content

Commit db5a96e

Browse files
committed
fix negative allocation
1 parent cee467a commit db5a96e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Pdf/PdfInvoice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function totalTaxAmount(): Money
137137
* we allocate the discount across items before computing taxes.
138138
*/
139139
$allocatedDiscounts = $totalDiscount->allocate(...array_map(
140-
fn ($item) => $item->subTotalAmount()->getMinorAmount()->toInt(),
140+
fn ($item) => $item->subTotalAmount()->abs()->getMinorAmount()->toInt(),
141141
$this->items
142142
));
143143

tests/Feature/PdfInvoiceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@
4343
[[100.0, 50.0], 0.0, 0.0, 150.0, 0.0, 0.0, 150.0],
4444
[[100.0, 50.0], 20.0, 0.0, 150.0, 0.0, 30.0, 180.0],
4545
[[100.0, 50.0], 20.0, 10.0, 150.0, 15.0, 27.0, 162.0],
46+
[[-100.0], 0.0, 0.0, -100.0, 0.0, 0.0, -100.0],
47+
[[-100.0, -50.0], 20.0, 10.0, -150.0, -15.0, -27.0, -162.0],
4648
]);

0 commit comments

Comments
 (0)