1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* The MIT License (MIT) |
6
|
|
|
* |
7
|
|
|
* Copyright (c) 2017 Daniel Popiniuc |
8
|
|
|
* |
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
11
|
|
|
* in the Software without restriction, including without limitation the rights |
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
14
|
|
|
* furnished to do so, subject to the following conditions: |
15
|
|
|
* |
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
17
|
|
|
* copies or substantial portions of the Software. |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
25
|
|
|
* SOFTWARE. |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
namespace danielgp\salariu; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Description of Taxation |
33
|
|
|
* |
34
|
|
|
* @author E303778 |
35
|
|
|
*/ |
36
|
|
|
trait Taxation |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
private $txLvl; |
40
|
|
|
|
41
|
|
|
private function getIncomeTaxValue($inDate, $lngBase, $vBA, $aryDeductions, $arySettings) |
42
|
|
|
{ |
43
|
|
|
$rest = $lngBase - array_sum($aryDeductions); |
44
|
|
|
if ($inDate >= 20100701) { |
45
|
|
|
$rest += round($vBA, -4); // food tickets are taxable |
46
|
|
|
$val = $this->tCmnSuperGlobals->request->get('gbns'); |
|
|
|
|
47
|
|
|
$taxMinAmount = 0; |
48
|
|
|
if ($inDate >= 20160101) { |
49
|
|
|
$taxMinAmount = 150 * ($val || 0); |
50
|
|
|
} |
51
|
|
|
if ($inDate >= 20101001) { |
52
|
|
|
$rest += round(min($val, $val - $taxMinAmount) * pow(10, 4), -4); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
$rest += round($this->tCmnSuperGlobals->request->get('afet') * pow(10, 4), -4); |
56
|
|
|
return $this->setIncomeTax($inDate, $rest, $arySettings['Income Tax']); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* CAS |
61
|
|
|
* |
62
|
|
|
* */ |
63
|
|
|
private function setHealthFundTax($lngDate, $lngBrutto, $nPercentages, $nValues) |
64
|
|
|
{ |
65
|
|
|
$this->txLvl['casP'] = $this->setValuesFromJson($lngDate, $nPercentages); |
66
|
|
|
$this->txLvl['casP_base'] = $this->setHealthFndTxBs($lngDate, $lngBrutto, $nValues); |
67
|
|
|
$nReturn = $this->txLvl['casP_base'] * $this->txLvl['casP'] / 100; |
68
|
|
|
if ($lngDate > 20060701) { |
69
|
|
|
$nReturn = ceil($nReturn / pow(10, 4)) * pow(10, 4); |
70
|
|
|
} |
71
|
|
|
$this->txLvl['cas'] = round($nReturn, 0); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* baza CAS |
76
|
|
|
* |
77
|
|
|
* http://www.lapensie.com/forum/salariul-mediu-brut.php |
78
|
|
|
* */ |
79
|
|
|
private function setHealthFndTxBs($lngDate, $lngBrutto, $nValues) |
80
|
|
|
{ |
81
|
|
|
$crtValues = $nValues[substr($lngDate, 0, 4)]; |
82
|
|
|
$base = min($lngBrutto, $crtValues['Multiplier'] * $crtValues['Monthly Average Salary']); |
83
|
|
|
if ($lngDate >= 20170201) { |
84
|
|
|
$base = $lngBrutto; |
85
|
|
|
} |
86
|
|
|
if (array_key_exists('Month Secondary Value', $crtValues)) { |
87
|
|
|
if (substr($lngDate, 4, 2) >= $crtValues['Month Secondary Value']) { |
88
|
|
|
$base = min($lngBrutto, $crtValues['Multiplier'] * $crtValues['Monthly Average Salary Secondary']); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
return $base; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Sanatate |
96
|
|
|
* */ |
97
|
|
|
protected function setHealthTax($lngDate, $lngBrutto, $nPercentages, $nValues) |
98
|
|
|
{ |
99
|
|
|
$this->txLvl['sntP'] = $this->setValuesFromJson($lngDate, $nPercentages); |
100
|
|
|
$nReturn = round($lngBrutto * $this->txLvl['sntP'] / 100, 0); |
101
|
|
|
if ($lngDate >= 20170101) { |
102
|
|
|
$this->txLvl['sntP_base'] = $this->setHealthFndTxBs($lngDate, $lngBrutto, $nValues); |
103
|
|
|
$nReturn = round($this->txLvl['sntP_base'] * $this->txLvl['sntP'] / 100, 0); |
104
|
|
|
} |
105
|
|
|
$this->txLvl['snt'] = (($lngDate > 20060701) ? round($nReturn, -4) : $nReturn); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Impozit pe salariu |
110
|
|
|
* */ |
111
|
|
|
protected function setIncomeTax($lngDate, $lngTaxBase, $nValues) |
112
|
|
|
{ |
113
|
|
|
$this->txLvl['inTaxP'] = '16'; |
114
|
|
|
$this->txLvl['inTaxP_base'] = $lngTaxBase; |
115
|
|
|
$nReturn = $lngTaxBase * 16 / 100; |
116
|
|
|
$yrDate = (int) substr($lngDate, 0, 4); |
117
|
|
|
if (in_array($yrDate, [2002, 2003, 2004])) { |
118
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues[$yrDate]); |
119
|
|
|
} elseif ($yrDate == 2001) { |
120
|
|
|
$nReturn = $this->setIncomeTax2001($lngDate, $lngTaxBase, $nValues); |
121
|
|
|
} |
122
|
|
|
return (($lngDate >= 20060701) ? round($nReturn, -4) : $nReturn); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Impozit pe salariu |
127
|
|
|
* */ |
128
|
|
|
private function setIncomeTax2001($lngDate, $lngTaxBase, $nValues) |
129
|
|
|
{ |
130
|
|
|
$nReturn = 0; |
131
|
|
|
$mnth = substr($lngDate, 4, 2); |
132
|
|
|
if ($mnth <= 6) { |
133
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues["2001-06"]); |
134
|
|
|
} elseif ($mnth <= 9) { |
135
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues["2001-09"]); |
136
|
|
|
} elseif ($mnth > 9) { |
137
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues["2001-12"]); |
138
|
|
|
} |
139
|
|
|
return $nReturn; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
private function setIncomeTaxFromJson($lngTaxBase, $nValues) |
143
|
|
|
{ |
144
|
|
|
$nReturn = 0; |
145
|
|
|
$howMany = count($nValues); |
146
|
|
|
for ($counter = 0; $counter <= $howMany; $counter++) { |
147
|
|
|
if (($lngTaxBase <= $nValues[$counter]['Upper Limit Value'])) { |
148
|
|
|
$sLbl = [ |
149
|
|
|
'BDP' => $nValues[$counter]['Base Deducted Percentage'], |
150
|
|
|
'BDV' => $nValues[$counter]['Base Deduction Value'], |
151
|
|
|
'TFV' => $nValues[$counter]['Tax Free Value'], |
152
|
|
|
]; |
153
|
|
|
$nReturn = $sLbl['TFV'] + ($lngTaxBase - $sLbl['BDV']) * $sLbl['BDP'] / 100; |
154
|
|
|
$this->txLvl['inTaxP'] = 'fx+' . $sLbl['BDP']; |
155
|
|
|
$counter = $howMany; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
return $nReturn; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Somaj |
163
|
|
|
* */ |
164
|
|
|
protected function setUnemploymentTax($lngDate, $lngBase) |
165
|
|
|
{ |
166
|
|
|
$yrDate = substr($lngDate, 0, 4); |
167
|
|
|
$this->txLvl['smjP'] = 0.5; |
168
|
|
|
if ($yrDate <= 2007) { |
169
|
|
|
$this->txLvl['smjP'] = 1; |
170
|
|
|
} |
171
|
|
|
$nReturn = round($lngBase * $this->txLvl['smjP'] / 100, 0); |
172
|
|
|
$this->txLvl['smj'] = (($lngDate >= 20060701) ? round($nReturn, -4) : $nReturn); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Media zilelor lucratoare (pt. calcularea suplimentarelor) |
177
|
|
|
* astfel incat acestea sa nu fie mai valoroase sau nu functie |
178
|
|
|
* de numarul zilelor din luna respectiva |
179
|
|
|
* |
180
|
|
|
* @param string $lngDate |
181
|
|
|
* @param array $stdAvgWrkngHrs |
182
|
|
|
* @param boolean $bCEaster |
183
|
|
|
* @return int |
184
|
|
|
*/ |
185
|
|
|
protected function setMonthlyAverageWorkingHours($lngDate, $stdAvgWrkngHrs, $bCEaster = false) |
186
|
|
|
{ |
187
|
|
|
$nReturn = $stdAvgWrkngHrs[substr($lngDate, 0, 4)]; |
188
|
|
|
if ($bCEaster) { |
189
|
|
|
$nReturn = ($nReturn * 12 - 8) / 12; |
190
|
|
|
} |
191
|
|
|
return $nReturn; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
private function setValuesFromJson($lngDate, $nValues) |
195
|
|
|
{ |
196
|
|
|
$crtValues = $nValues[substr($lngDate, 0, 4)]; |
197
|
|
|
$nReturn = $crtValues['Value']; |
198
|
|
|
if (array_key_exists('Month Secondary Value', $crtValues)) { |
199
|
|
|
if (date('n', $lngDate) >= $crtValues['Month Secondary Value']) { |
200
|
|
|
$nReturn = $crtValues['Secondary Value']; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
return $nReturn; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: