-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEUTax.php
86 lines (82 loc) · 1.57 KB
/
EUTax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace core;
/**
* Calculate price.
*/
class EUTax
{
/**
* Check if $country is in SEPA.
* @param string $country ISO2 country notation
* @return bool inSEPA
*/
public static function in_sepa($country)
{
$sepaCountries = [
"FI", "AT", "PT", "BE", "BG", "ES",
"HR", "CY", "CZ", "DK", "EE", "FI",
"FR", "GF", "DE", "GI", "GR", "GP",
"GG", "HU", "IS", "IE", "IM", "IT",
"JE", "LV", "LI", "LT", "LU", "PT",
"MT", "MQ", "YT", "MC", "NL", "NO",
"PL", "PT", "RE", "RO", "BL", "MF",
"PM", "SM", "SK", "SI", "SE", "CH",
"GB"
];
return in_array($country, $sepaCountries);
}
public static function rates()
{
return [
"BE" => "21",
"NL" => "21",
"DE" => "19",
"EE" => "20",
"LU" => "15",
"MT" => "18",
"CY" => "19",
"GB" => "20",
"BG" => "20",
"FR" => "20",
"SK" => "20",
"AT" => "20",
"LT" => "21",
"ES" => "21",
"LV" => "21",
"CZ" => "21",
"SI" => "22",
"IT" => "22",
"IE" => "23",
"PT" => "23",
"PL" => "23",
"GR" => "23",
"FI" => "24",
"RO" => "24",
"DK" => "25",
"SE" => "25",
"HR" => "25",
"HU" => "27"
];
}
/** Strip tax from $price */
public static function calc($country, $price)
{
$rates = self::rates();
$rate = null;
if (isset($rates[$country])) {
$rate = $rates[$country];
} else {
$rate = "0";
}
$factor = bcadd("1", bcdiv($rate, "100", 3), 3);
$ex = bcdiv($price, $factor, 3);
$vat = bcsub($price, $ex, 3);
return [
"factor" => $factor,
"total" => $price,
"ex" => $ex,
"vat" => $vat,
"vat_percent" => $rate
];
}
}