} $tax_percent = $tax_info["tax_percent"]; $fixed_amount = $tax_info["fixed_amount"]; $tax_types = $tax_info["types"]; $tax_cost = isset($tax_info["tax_total"]) ? $tax_info["tax_total"] : 0; if ($total_discount_tax) { // in case of order coupons decrease taxes value if ($tax_number == sizeof($tax_rates)) { $tax_discount = $discount_tax_sum; } else { $tax_discount = round($tax_cost * $total_discount_tax / $taxes_sum, 2); } $discount_tax_sum -= $tax_discount; $tax_cost -= $tax_discount; } $taxes_total += va_round($tax_cost, $currency["decimals"]); // hide tax if it has zero value if ($tax_cost != 0) { $t->set_var("tax_id", $tax_id); $t->set_var("tax_percent", $tax_percent); $t->set_var("tax_name", $tax_name); $t->set_var("tax_cost", currency_format($tax_cost)); $t->parse("taxes", true); } // build param if ($taxes_param) { $taxes_param .= "&"; } $taxes_param .= "tax_id=" . $tax_id; $taxes_param .= "&tax_type=" . prepare_js_value($tax_type); $taxes_param .= "&tax_name=" . prepare_js_value($tax_name);
function get_tax_amount($tax_rates, $item_type, &$price, $quantity, $item_tax_id, $tax_free, &$tax_percent, $default_tax_rates = "", $return_type = 1, $tax_prices_type = "", $tax_round = "") { global $settings, $currency; if ($quantity <= 0) { $quantity = 1; } // used to calculated fixed tax $taxes_values = array(); $item_tax_amount = 0; if (!strlen($tax_prices_type)) { $tax_prices_type = get_setting_value($settings, "tax_prices_type", 0); } if (!strlen($tax_round)) { $tax_round = get_setting_value($settings, "tax_round", 1); } $decimals = get_setting_value($currency, "decimals", 2); if (is_array($default_tax_rates) && $tax_prices_type == 1 && !$tax_free) { // if price includes tax check if default taxes different from user taxes $tax_rates_identical = true; if (is_array($tax_rates)) { $tax_rates_identical = $tax_rates == $default_tax_rates; } else { $tax_rates_identical = false; } if (!$tax_rates_identical) { // calculate price without tax to apply different tax rates $default_tax_percent = 0; $default_fixed_tax = 0; foreach ($default_tax_rates as $id => $tax_rate) { // check if tax should be used for current item $tax_id = $tax_rate["tax_id"]; $tax_type = $tax_rate["tax_type"]; if ($tax_type == 1 || $tax_type == 2 && $item_tax_id == $tax_id) { // check default tax percent if (isset($tax_rate["types"][$item_type]) && isset($tax_rate["types"][$item_type]["tax_percent"]) && strlen($tax_rate["types"][$item_type]["tax_percent"])) { $default_tax_percent += $tax_rate["types"][$item_type]["tax_percent"]; } else { $default_tax_percent += $tax_rate["tax_percent"]; } // check default tax amount if (isset($tax_rate["types"][$item_type]) && isset($tax_rate["types"][$item_type]["fixed_amount"]) && strlen($tax_rate["types"][$item_type]["fixed_amount"])) { $default_fixed_tax += $tax_rate["types"][$item_type]["fixed_amount"] * $quantity; } else { $default_fixed_tax += $tax_rate["fixed_amount"] * $quantity; } } } // deduct default tax $price_excl_tax = $price * 100 / ($default_tax_percent + 100) - $default_fixed_tax; $tax_percent = 0; $fixed_tax = 0; if (is_array($tax_rates)) { foreach ($tax_rates as $id => $tax_rate) { // check if tax should be used for current item $tax_id = $tax_rate["tax_id"]; $tax_type = $tax_rate["tax_type"]; if ($tax_type == 1 || $tax_type == 2 && $item_tax_id == $tax_id) { // check tax percent if (isset($tax_rate["types"][$item_type]) && isset($tax_rate["types"][$item_type]["tax_percent"]) && strlen($tax_rate["types"][$item_type]["tax_percent"])) { $tax_percent += $tax_rate["types"][$item_type]["tax_percent"]; } else { $tax_percent += $tax_rate["tax_percent"]; } // check tax amount if (isset($tax_rate["types"][$item_type]) && isset($tax_rate["types"][$item_type]["fixed_amount"]) && strlen($tax_rate["types"][$item_type]["fixed_amount"])) { $fixed_tax += $tax_rate["types"][$item_type]["fixed_amount"] * $quantity; } else { $fixed_tax += $tax_rate["fixed_amount"] * $quantity; } } } } // calculate price with current tax $price = va_round($price_excl_tax + $price_excl_tax * $tax_percent / 100 + $fixed_tax, $decimals); } } if (!isset($tax_percent)) { $tax_percent = 0; } if (!$tax_free) { // calculate summary tax $tax_percent = 0; $fixed_tax = 0; $item_tax_amount = 0; if (is_array($tax_rates)) { foreach ($tax_rates as $id => $tax_rate) { // check if tax should be used for current item $tax_id = $tax_rate["tax_id"]; $tax_type = $tax_rate["tax_type"]; if ($tax_type == 1 || $tax_type == 2 && $item_tax_id == $tax_id) { $current_tax_percent = 0; $current_fixed_tax = 0; $current_item_tax = 0; // check tax percent if (isset($tax_rate["types"][$item_type]) && isset($tax_rate["types"][$item_type]["tax_percent"]) && strlen($tax_rate["types"][$item_type]["tax_percent"])) { $current_tax_percent = $tax_rate["types"][$item_type]["tax_percent"]; } else { $current_tax_percent = $tax_rate["tax_percent"]; } // check tax amount if (isset($tax_rate["types"][$item_type]) && isset($tax_rate["types"][$item_type]["fixed_amount"]) && strlen($tax_rate["types"][$item_type]["fixed_amount"])) { $current_fixed_tax = $tax_rate["types"][$item_type]["fixed_amount"] * $quantity; } else { $current_fixed_tax = $tax_rate["fixed_amount"] * $quantity; } // calculate tax amount for each tax if ($tax_prices_type == 1) { // prices includes tax $current_item_tax = $price - $price * 100 / ($current_tax_percent + 100) - $current_fixed_tax; } else { $current_item_tax = $price * $current_tax_percent / 100 + $current_fixed_tax; } if ($tax_round == 1) { $current_item_tax = va_round($current_item_tax, $decimals); } $taxes_values[$tax_id] = array("tax_name" => $tax_rate["tax_name"], "show_type" => isset($tax_rate["show_type"]) ? $tax_rate["show_type"] : 0, "tax_percent" => $current_tax_percent, "fixed_value" => $current_fixed_tax, "tax_amount" => $current_item_tax); $tax_percent += $current_tax_percent; $fixed_tax += $current_fixed_tax; $item_tax_amount += $current_item_tax; } } } } else { $tax_percent = 0; $fixed_tax = 0; } if ($return_type == 2) { return $taxes_values; } else { return $item_tax_amount; } }