function cw_cart_calc_taxes_single($formula_data, $products_taxes, $amount, &$taxes) { foreach ($products_taxes as $tax_name => $v) { if ($v['skip']) { continue; } if (!isset($taxes['taxes'][$tax_name])) { $taxes['taxes'][$tax_name] = $v; $taxes['taxes'][$tax_name]['tax_cost'] = 0; } if ($v['rate_type'] == '%') { $assessment = cw_cart_calc_assessment($v['formula'], $formula_data); $tax_value = $amount * price_format($assessment * $v['rate_value'] / 100, true); } else { $tax_value = price_format($v['rate_value'], true) * $amount; } $formula_data[$tax_name] = $tax_value; $tax_result += $tax_value; $taxes['taxes'][$tax_name]['tax_cost'] += $tax_value; } return $tax_result; }
function cw_tax_price($price, $user_info = '', $product_id = 0, $disable_abs = false, $discounted_price = NULL, $taxes = "", $price_deducted_tax = false) { global $tables, $config, $addons, $current_language; $return_taxes = array(); $no_discounted_price = false; if (empty($discounted_price)) { $discounted_price = $price; $no_discounted_price = true; } if ($product_id > 0) { $product = cw_query_first("SELECT product_id, free_shipping, shipping_freight, distribution, '{$price}' as price FROM {$tables['products']} WHERE product_id='{$product_id}'"); $taxes = cw_get_product_tax_rates($product, $user_info); } $total_tax_cost = 0; if (is_array($taxes)) { # # Calculate price and tax_value # foreach ($taxes as $k => $tax_rate) { if (!$tax_rate['price_includes_tax'] || $price_deducted_tax) { if (!$price_includes_tax || $price_deducted_tax) { continue; } } if (!preg_match("!\\b(DST|ST)\\b!S", $tax_rate['formula'])) { continue; } if ($tax_rate['rate_type'] == "%") { $_tax_value = $price - $price * 100 / ($tax_rate['rate_value'] + 100); $price -= $_tax_value; if ($discounted_price > 0) { $_tax_value = $discounted_price - $discounted_price * 100 / ($tax_rate['rate_value'] + 100); } $discounted_price -= $_tax_value; } else { $price -= $tax_rate['rate_value']; $discounted_price -= $tax_rate['rate_value']; } } $taxed_price = $discounted_price; $formula_data['ST'] = $price; if (!$no_discounted_price) { $formula_data['DST'] = $discounted_price; } foreach ($taxes as $k => $v) { if (!empty($v['skip'])) { continue; } if (!$v['display_including_tax']) { continue; } if ($v['rate_type'] == "%") { $assessment = cw_cart_calc_assessment($v['formula'], $formula_data); $tax_value = $assessment * $v['rate_value'] / 100; } elseif (!$disable_abs) { $tax_value = $v['rate_value']; } $formula_data[$v['tax_name']] = $tax_value; $total_tax_cost += $tax_value; $taxed_price += $tax_value; $return_taxes['taxes'][$v['tax_id']] = $tax_value; } } $return_taxes['taxed_price'] = $taxed_price; return $return_taxes; }