$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, bool $compoundTax, bool $ignorePlaceholders = false): int { $sum = 0; foreach ($taxes as $tax) { if ($ignorePlaceholders && empty($tax['tax_type_id'])) { continue; } if (self::isCompoundTax($tax) !== $compoundTax) { continue; } $sum += (int) round((float) ($tax['amount'] ?? 0)); } return $sum; } protected static function isCompoundTax(array $tax): bool { return filter_var($tax['compound_tax'] ?? false, FILTER_VALIDATE_BOOLEAN); } }