public function taxTotal($format = true)
{
$totalTax = 0;
$discounted = 0;
$totalDiscount = $this->totalDiscount(false);
if ($this->count() != 0) {
foreach ($this->getItems() as $item) {
if ($discounted >= $totalDiscount) {
$totalTax += $item->tax();
} else {
$itemPrice = $item->subTotal(false);
if ($discounted + $itemPrice > $totalDiscount) {
$totalTax += $item->tax($totalDiscount - $discounted);
}
$discounted += $itemPrice;
}
}
}
foreach ($this->getFees() as $fee) {
if ($fee->taxable) {
$totalTax += $fee->amount * $fee->tax;
}
}
return $this->formatMoney($totalTax, null, null, $format);
}