从 OpenCart 中的含税价格中减去税款?

Subtract tax from a price with tax in 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'] );

这个 returns 是一个不正确的值 $14,64,因为它计算了 $number (20,80) 的税,这已经是 和 [=24= 的价格] 税。不含税 $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);