在OpenCart中从含税价格中减去税?



如何在OpenCart中从含税价格中减去所有税费?

在下面的示例中,我使用 OpenCart 的默认"应税商品"税收设置,即 20% 增值税 + 2,00 美元的生态税。

$number = 20.80
// Get $number tax:
$tax = $this->tax->getTax( $number , $product_info['tax_class_id'] , $this->config->get('config_tax') );
// Subtract tax from total price:
$result = $this->currency->format( ( $number - $tax ) , $this->session->data['currency'] );

这将返回不正确的值 $14,64,因为它计算了$number(20,80) 的税,这已经是税价格。不含税 20,80 美元的正确价格应该是 15,67 美元

在这种情况下,这应该是公式: (20.80 - 2.00)/120 * 100 = 15.6667

有没有办法从已经含税的价格中减去所有税费?

$taxRate = 20;
$gross = 150;
$divisor = (100 + $taxRate) / 100;
$net = round( $gross / $divisor, 2);
$tax = round( $gross - $net, 2 );
Echo "Gross was $gross - Net is $net Tax is $tax";

结果含20%税

Gross was 150 - Net is 133.33 Tax is 16.67

结果含15%税

Gross was 150 - Net is 130.43 Tax is 19.57

尝试几次试运行,然后使用此代码进行检查

例如,如果您的税是 21%,并且您的产品含税 = 120。不含税将是:120/1.21。 所以如果税率:

$tax_rate = 21;

产品价格:

$price = 120;

不含税价格:

$price_without_tax = $price/($tax_rate/100 +1);

最新更新