Completed
Push — master ( 4b9f77...969087 )
by Daniel
02:23
created

Taxation::setIncomeTax2003()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 5
nop 1
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2015 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
    /**
40
     * CAS
41
     *
42
     * */
43
    protected function setHealthFundTax($lngDate, $lngBrutto, $nPercentages, $nValues)
44
    {
45
        $prcntg  = $this->setValuesFromJson($lngDate, $nPercentages);
46
        $nReturn = round($this->setHealthFundTaxBase($lngDate, $lngBrutto, $nValues) * $prcntg / 100, 0);
47
        if ($lngDate > mktime(0, 0, 0, 7, 1, 2006)) {
48
            $nReturn = ceil($nReturn / pow(10, 4)) * pow(10, 4);
49
        }
50
        return $nReturn;
51
    }
52
53
    /**
54
     * baza CAS
55
     *
56
     * http://www.lapensie.com/forum/salariul-mediu-brut.php
57
     * */
58
    private function setHealthFundTaxBase($lngDate, $lngBrutto, $nValues)
59
    {
60
        $crtValues = $nValues[date('Y', $lngDate)];
61
        $base      = min($lngBrutto, $crtValues['Multiplier'] * $crtValues['Monthly Average Salary']);
62
        if (array_key_exists('Month Secondary Value', $crtValues)) {
63
            if (date('n', $lngDate) >= $crtValues['Month Secondary Value']) {
64
                $base = min($lngBrutto, $crtValues['Multiplier'] * $crtValues['Monthly Average Salary Secondary']);
65
            }
66
        }
67
        return $base;
68
    }
69
70
    /**
71
     * Sanatate
72
     * */
73
    protected function setHealthTax($lngDate, $lngBrutto, $nPercentages)
74
    {
75
        $prcntg  = $this->setValuesFromJson($lngDate, $nPercentages);
76
        $nReturn = round($lngBrutto * $prcntg / 100, 0);
77 View Code Duplication
        if ($lngDate > mktime(0, 0, 0, 7, 1, 2006)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
78
            $nReturn = round($nReturn, -4);
79
        }
80
        return $nReturn;
81
    }
82
83
    /**
84
     * Impozit pe salariu
85
     * */
86
    protected function setIncomeTax($lngDate, $lngTaxBase)
87
    {
88
        switch (date('Y', $lngDate)) {
89
            case 2001:
90
                $nReturn = $this->setIncomeTax2001($lngDate, $lngTaxBase);
91
                break;
92
            case 2002:
93
                $nReturn = $this->setIncomeTax2002($lngTaxBase);
94
                break;
95
            case 2003:
96
                $nReturn = $this->setIncomeTax2003($lngTaxBase);
97
                break;
98
            case 2004:
99
                $nReturn = $this->setIncomeTax2004($lngTaxBase);
100
                break;
101
            default:
102
                $nReturn = $lngTaxBase * 16 / 100;
103
                break;
104
        }
105 View Code Duplication
        if ($lngDate > mktime(0, 0, 0, 7, 1, 2006)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
106
            $nReturn = round($nReturn, -4);
107
        }
108
        return $nReturn;
109
    }
110
111
    /**
112
     * Impozit pe salariu
113
     * */
114
    private function setIncomeTax2001($lngDate, $lngTaxBase)
115
    {
116
        $mnth = date('n', $lngDate);
117
        if ($mnth <= 6) {
118
            $nReturn = 1822070 + ($lngTaxBase - 6867000 ) * 40 / 100;
119
            if ($lngTaxBase <= 1259000) {
120
                $nReturn = $lngTaxBase * 18 / 100;
121
            } elseif ($lngTaxBase <= 3090000) {
122
                $nReturn = 226620 + ($lngTaxBase - 1259000 ) * 23 / 100;
123
            } elseif ($lngTaxBase <= 4921000) {
124
                $nReturn = 647750 + ($lngTaxBase - 3090000 ) * 28 / 100;
125
            } elseif ($lngTaxBase <= 6867000) {
126
                $nReturn = 1160430 + ($lngTaxBase - 4921000 ) * 34 / 100;
127
            }
128
        } elseif ($mnth <= 9) {
129
            $nReturn = 2109940 + ($lngTaxBase - 7952000 ) * 40 / 100;
130
            if ($lngTaxBase <= 1458000) {
131
                $nReturn = $lngTaxBase * 18 / 100;
132
            } elseif ($lngTaxBase <= 3578000) {
133
                $nReturn = 262440 + ($lngTaxBase - 1458000 ) * 23 / 100;
134
            } elseif ($lngTaxBase <= 5699000) {
135
                $nReturn = 750040 + ($lngTaxBase - 3578000 ) * 28 / 100;
136
            } elseif ($lngTaxBase <= 7952000) {
137
                $nReturn = 1343920 + ($lngTaxBase - 5699000 ) * 34 / 100;
138
            }
139
        } elseif ($mnth > 9) {
140
            $nReturn = 2231000 + ($lngTaxBase - 8400000 ) * 40 / 100;
141
            if ($lngTaxBase <= 1500000) {
142
                $nReturn = $lngTaxBase * 18 / 100;
143
            } elseif ($lngTaxBase <= 3800000) {
144
                $nReturn = 270000 + ($lngTaxBase - 1500000 ) * 23 / 100;
145
            } elseif ($lngTaxBase <= 6000000) {
146
                $nReturn = 799000 + ($lngTaxBase - 3800000 ) * 28 / 100;
147
            } elseif ($lngTaxBase <= 8400000) {
148
                $nReturn = 1415000 + ($lngTaxBase - 6000000 ) * 34 / 100;
149
            }
150
        }
151
        return $nReturn;
0 ignored issues
show
Bug introduced by
The variable $nReturn does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
152
    }
153
154 View Code Duplication
    private function setIncomeTax2002($lngTaxBase)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
155
    {
156
        $nReturn = 2710000 + ($lngTaxBase - 10200000 ) * 40 / 100;
157
        if ($lngTaxBase <= 1800000) {
158
            $nReturn = $lngTaxBase * 18 / 100;
159
        } elseif ($lngTaxBase <= 4600000) {
160
            $nReturn = 324000 + ($lngTaxBase - 1800000 ) * 23 / 100;
161
        } elseif ($lngTaxBase <= 7300000) {
162
            $nReturn = 968000 + ($lngTaxBase - 4600000 ) * 28 / 100;
163
        } elseif ($lngTaxBase <= 10200000) {
164
            $nReturn = 1724000 + ($lngTaxBase - 7300000 ) * 34 / 100;
165
        }
166
        return $nReturn;
167
    }
168
169 View Code Duplication
    private function setIncomeTax2003($lngTaxBase)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
170
    {
171
        $nReturn = 3081000 + ($lngTaxBase - 11600000 ) * 40 / 100;
172
        if ($lngTaxBase <= 2100000) {
173
            $nReturn = ($lngTaxBase * 18) / 100;
174
        } elseif ($lngTaxBase <= 5200000) {
175
            $nReturn = 324000 + ($lngTaxBase - 2100000 ) * 23 / 100;
176
        } elseif ($lngTaxBase <= 8300000) {
177
            $nReturn = 1091000 + ($lngTaxBase - 5200000 ) * 28 / 100;
178
        } elseif ($lngTaxBase <= 11600000) {
179
            $nReturn = 1959000 + ($lngTaxBase - 8300000 ) * 34 / 100;
180
        }
181
        return $nReturn;
182
    }
183
184 View Code Duplication
    private function setIncomeTax2004($lngTaxBase)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
185
    {
186
        $nReturn = 3452000 + ($lngTaxBase - 13000000 ) * 40 / 100;
187
        if ($lngTaxBase <= 2400000) {
188
            $nReturn = ($lngTaxBase * 18) / 100;
189
        } elseif ($lngTaxBase <= 5800000) {
190
            $nReturn = 432000 + ($lngTaxBase - 2400000 ) * 23 / 100;
191
        } elseif ($lngTaxBase <= 9300000) {
192
            $nReturn = 1214000 + ($lngTaxBase - 5800000 ) * 28 / 100;
193
        } elseif ($lngTaxBase <= 13000000) {
194
            $nReturn = 2194000 + ($lngTaxBase - 9300000 ) * 34 / 100;
195
        }
196
        return $nReturn;
197
    }
198
199
    /**
200
     * Somaj
201
     * */
202
    protected function setUnemploymentTax($lngDate, $lngBase)
203
    {
204
        $yrDate  = date('Y', $lngDate);
205
        $nReturn = 0.5;
206
        if ($yrDate <= 2007) {
207
            $nReturn = 1;
208
        }
209
        $nReturn = round($lngBase * $nReturn / 100, 0);
210 View Code Duplication
        if ($lngDate > mktime(0, 0, 0, 7, 1, 2006)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
211
            $nReturn = round($nReturn, -4);
212
        }
213
        return $nReturn;
214
    }
215
216
    /**
217
     * Media zilelor lucratoare (pt. calcularea suplimentarelor)
218
     * astfel incat acestea sa nu fie mai valoroase sau nu functie
219
     * de numarul zilelor din luna respectiva
220
     *
221
     * @param date $lngDate
222
     * @return number
223
     */
224
    protected function setMonthlyAverageWorkingHours($lngDate, $stdAvgWrkngHrs, $bCEaster = false)
225
    {
226
        $nReturn = $stdAvgWrkngHrs[date('Y', $lngDate)];
227
        if ($bCEaster) {
228
            $nReturn = ($nReturn * 12 - 8) / 12;
229
        }
230
        return $nReturn;
231
    }
232
233
    private function setValuesFromJson($lngDate, $nValues)
234
    {
235
        $crtValues = $nValues[date('Y', $lngDate)];
236
        $nReturn   = $crtValues['Value'];
237
        if (array_key_exists('Month Secondary Value', $crtValues)) {
238
            if (date('n', $lngDate) >= $crtValues['Month Secondary Value']) {
239
                $nReturn = $crtValues['Secondary Value'];
240
            }
241
        }
242
        return $nReturn;
243
    }
244
}
245