Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
vatcalculator.php
1
<?php
2
3
namespace
Bitrix\Sale\Tax
;
4
5
use
Bitrix\Sale\PriceMaths
;
6
16
class
VatCalculator
17
{
18
private
float
$rate;
19
24
public
function
__construct
(
float
$rate)
25
{
26
$this->rate = $rate;
27
}
28
37
public
function
calc
(
float
$price,
bool
$isVatInPrice,
bool
$withRound =
true
): float
38
{
39
if
($this->rate === 0.0)
40
{
41
return
0.0;
42
}
43
elseif ($isVatInPrice)
44
{
45
$vat = $price * $this->rate / ($this->rate + 1);
46
}
47
else
48
{
49
$vat = $price * $this->rate;
50
}
51
52
return
$withRound ?
PriceMaths::roundPrecision
($vat) : $vat;
53
}
54
63
public
function
allocate
(
float
$price,
bool
$withRound =
true
): float
64
{
65
if
($this->rate === 0.0)
66
{
67
return
$price;
68
}
69
70
$rate = $this->rate * 100;
71
$vat = $price * $rate / ($rate + 100);
72
$priceWithoutVat = $price - $vat;
73
74
return
$withRound ?
PriceMaths::roundPrecision
($priceWithoutVat) : $priceWithoutVat;
75
}
76
85
public
function
accrue
(
float
$price,
bool
$withRound =
true
): float
86
{
87
$priceWithVat = $price * (1 + $this->rate);
88
89
return
$withRound ?
PriceMaths::roundPrecision
($priceWithVat) : $priceWithVat;
90
}
91
}
Bitrix\Sale\PriceMaths
Definition
pricemaths.php:8
Bitrix\Sale\PriceMaths\roundPrecision
static roundPrecision($value)
Definition
pricemaths.php:16
Bitrix\Sale\Tax\VatCalculator
Definition
vatcalculator.php:17
Bitrix\Sale\Tax\VatCalculator\accrue
accrue(float $price, bool $withRound=true)
Definition
vatcalculator.php:85
Bitrix\Sale\Tax\VatCalculator\__construct
__construct(float $rate)
Definition
vatcalculator.php:24
Bitrix\Sale\Tax\VatCalculator\calc
calc(float $price, bool $isVatInPrice, bool $withRound=true)
Definition
vatcalculator.php:37
Bitrix\Sale\Tax\VatCalculator\allocate
allocate(float $price, bool $withRound=true)
Definition
vatcalculator.php:63
Bitrix\Sale\Tax
Definition
rate.php:8
modules
sale
lib
tax
vatcalculator.php
Создано системой
1.10.0