$subTotal, 'tax' => $totalTax, 'total' => $total, ]; } /** * Authoritative per-item total: round(price * quantity) minus the item * discount (only applied when discount is configured per item). */ public static function itemTotal(array $item, bool $perItemDiscount): int { $price = (float) ($item['price'] ?? 0); $quantity = (float) ($item['quantity'] ?? 0); $discount = $perItemDiscount ? (int) round((float) ($item['discount_val'] ?? 0)) : 0; return (int) round($price * $quantity) - $discount; } protected static function sumTaxAmounts(array $taxes): int { $sum = 0; foreach ($taxes as $tax) { $sum += (int) round((float) ($tax['amount'] ?? 0)); } return $sum; } }