1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* |
7
|
|
|
* The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* Copyright (c) 2017 Daniel Popiniuc |
10
|
|
|
* |
11
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
12
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
13
|
|
|
* in the Software without restriction, including without limitation the rights |
14
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
16
|
|
|
* furnished to do so, subject to the following conditions: |
17
|
|
|
* |
18
|
|
|
* The above copyright notice and this permission notice shall be included in all |
19
|
|
|
* copies or substantial portions of the Software. |
20
|
|
|
* |
21
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
27
|
|
|
* SOFTWARE. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
namespace danielgp\salariu; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Description of Taxation |
35
|
|
|
* |
36
|
|
|
* @author E303778 |
37
|
|
|
*/ |
38
|
|
|
trait Taxation |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
use \danielgp\salariu\TaxationHealth; |
42
|
|
|
|
43
|
|
|
private function determineUnemploymentTax($yearMonth, $inMny, $dtR) |
44
|
|
|
{ |
45
|
|
|
$intValue = 0; |
46
|
|
|
$maxCounter = count($inMny); |
47
|
|
View Code Duplication |
for ($counter = 0; $counter < $maxCounter; $counter++) { |
|
|
|
|
48
|
|
|
$crtVal = $inMny[$counter]; |
49
|
|
|
$crtDV = \DateTime::createFromFormat('Y-n-j', $crtVal['Year'] . '-' . $crtVal['Month'] . '-01'); |
50
|
|
|
$crtDateOfValue = (int) $crtDV->format('Ymd'); |
51
|
|
|
if (($yearMonth <= $dtR['maximumInt']) && ($yearMonth >= $crtDateOfValue)) { |
52
|
|
|
$intValue = $crtVal['Percentage']; |
53
|
|
|
$counter = $maxCounter; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
return $intValue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function getIncomeTaxBaseAdjustments(\Symfony\Component\HttpFoundation\Request $tCSG, $rest, $inMny) |
60
|
|
|
{ |
61
|
|
|
$restFinal = $rest + round($inMny['Food Tickets Value'], -4); |
62
|
|
|
$val = $tCSG->get('gbns'); |
63
|
|
|
$taxMinAmount = 0; |
64
|
|
|
if ($inMny['inDate'] >= 20160101) { |
65
|
|
|
$taxMinAmount = 150 * ($val || 0); |
66
|
|
|
} |
67
|
|
|
if ($inMny['inDate'] >= 20101001) { |
68
|
|
|
$restFinal += round(min($val, $val - $taxMinAmount) * pow(10, 4), -4); |
69
|
|
|
} |
70
|
|
|
return $restFinal; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function getIncomeTaxValue(\Symfony\Component\HttpFoundation\Request $tCSG, $inMny) |
74
|
|
|
{ |
75
|
|
|
$rest = 0; |
76
|
|
|
$dinish = array_sum($inMny['Deductions']) + round($tCSG->get('afet') * pow(10, 4), -4); |
77
|
|
|
if ($inMny['lngBase'] > $dinish) { |
78
|
|
|
$rest = $inMny['lngBase'] - array_sum($inMny['Deductions']) + round($tCSG->get('afet') * pow(10, 4), -4); |
79
|
|
|
} |
80
|
|
|
if ($inMny['inDate'] >= 20100701) { |
81
|
|
|
$rest = $this->getIncomeTaxBaseAdjustments($tCSG, $rest, $inMny); |
82
|
|
|
} |
83
|
|
|
return $this->setIncomeTax($inMny['inDate'], $rest, $inMny['Income Tax']); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Impozit pe salariu |
88
|
|
|
* */ |
89
|
|
|
protected function setIncomeTax($lngDate, $lngTaxBase, $nValues) |
90
|
|
|
{ |
91
|
|
|
$yrDate = (int) substr($lngDate, 0, 4); |
92
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues, $yrDate); |
93
|
|
|
if ($yrDate == 2001) { |
94
|
|
|
$nReturn = $this->setIncomeTax2001($lngDate, $lngTaxBase, $nValues); |
95
|
|
|
} |
96
|
|
|
return (($lngDate >= 20060701) ? round($nReturn, -4) : $nReturn); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Impozit pe salariu |
101
|
|
|
* */ |
102
|
|
|
private function setIncomeTax2001($lngDate, $lngTaxBase, $nValues) |
103
|
|
|
{ |
104
|
|
|
$mnth = substr($lngDate, 4, 2); |
105
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues["2001-12"], 2001); // for > 9 |
106
|
|
|
if ($mnth <= 6) { |
107
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues["2001-06"], 2001); |
108
|
|
|
} elseif ($mnth <= 9) { |
109
|
|
|
$nReturn = $this->setIncomeTaxFromJson($lngTaxBase, $nValues["2001-09"], 2001); |
110
|
|
|
} |
111
|
|
|
return $nReturn; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function setIncomeTaxFromJson($lngTaxBase, $nValues, $yrDate) |
115
|
|
|
{ |
116
|
|
|
$nReturn = 0; |
117
|
|
|
$howMany = count($nValues); |
118
|
|
|
if (array_key_exists('Percentage', $nValues[$yrDate])) { |
119
|
|
|
$this->txLvl['inTaxP'] = $nValues[$yrDate]['Percentage']; |
120
|
|
|
$this->txLvl['inTaxP_base'] = $lngTaxBase; |
121
|
|
|
$nReturn = $lngTaxBase * $this->txLvl['inTaxP'] / 100; |
122
|
|
|
} else { |
123
|
|
|
for ($counter = 0; $counter <= $howMany; $counter++) { |
124
|
|
|
$nReturn = $lngTaxBase * $this->txLvl['inTaxP']; |
125
|
|
|
if (($lngTaxBase <= $nValues[$counter]['Upper Limit Value'])) { |
126
|
|
|
$sLbl = [ |
127
|
|
|
'BDP' => $nValues[$counter]['Base Deducted Percentage'], |
128
|
|
|
'BDV' => $nValues[$counter]['Base Deduction Value'], |
129
|
|
|
'TFV' => $nValues[$counter]['Tax Free Value'], |
130
|
|
|
]; |
131
|
|
|
$nReturn = $sLbl['TFV'] + ($lngTaxBase - $sLbl['BDV']) * $sLbl['BDP'] / 100; |
132
|
|
|
$this->txLvl['inTaxP'] = 'fx+' . $sLbl['BDP']; |
133
|
|
|
$counter = $howMany; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
return $nReturn; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Somaj |
142
|
|
|
* */ |
143
|
|
|
protected function setUnemploymentTax($lngDate, $lngBase, $yearMonth, $aStngs, $dtR) |
144
|
|
|
{ |
145
|
|
|
$this->txLvl['smjP'] = $this->determineUnemploymentTax($yearMonth, $aStngs, $dtR); |
146
|
|
|
$nReturn = round($lngBase * $this->txLvl['smjP'] / 100, 0); |
147
|
|
|
$this->txLvl['smj'] = (($lngDate >= 20060701) ? round($nReturn, -4) : $nReturn); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Media zilelor lucratoare (pt. calcularea suplimentarelor) |
152
|
|
|
* astfel incat acestea sa nu fie mai valoroase sau nu functie |
153
|
|
|
* de numarul zilelor din luna respectiva |
154
|
|
|
* |
155
|
|
|
* @param string $lngDate |
156
|
|
|
* @param array $stdAvgWrkngHrs |
157
|
|
|
* @param boolean $bCEaster |
158
|
|
|
* @return int |
159
|
|
|
*/ |
160
|
|
|
protected function setMonthlyAverageWorkingHours($lngDate, $stdAvgWrkngHrs, $bCEaster = false) |
161
|
|
|
{ |
162
|
|
|
$nReturn = $stdAvgWrkngHrs[substr($lngDate, 0, 4)]; |
163
|
|
|
if ($bCEaster) { |
164
|
|
|
$nReturn = ($nReturn * 12 - 8) / 12; |
165
|
|
|
} |
166
|
|
|
return $nReturn; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.