Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
vatcalculator.php
1<?php
2
3namespace Bitrix\Sale\Tax;
4
6
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}
static roundPrecision($value)
accrue(float $price, bool $withRound=true)
calc(float $price, bool $isVatInPrice, bool $withRound=true)
allocate(float $price, bool $withRound=true)