File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments