Completed
Push — master ( f3c8ce...dcb10a )
by Daniel
02:27
created

Bonuses::readSettingsFromJsonFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
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 Bonuses
33
 *
34
 * @author E303778
35
 */
36
trait Bonuses
37
{
38
39
    /**
40
     * returns an array with non-standard holidays from a JSON file
41
     *
42
     * @param string $fileBaseName
43
     * @return mixed
44
     */
45
    protected function readSettingsFromJsonFile($fileBaseName)
46
    {
47
        $fName       = __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $fileBaseName . '.min.json';
48
        $fJson       = fopen($fName, 'r');
49
        $jSonContent = fread($fJson, filesize($fName));
50
        fclose($fJson);
51
        return json_decode($jSonContent, true);
52
    }
53
54
    /**
55
     * Tichete de alimente
56
     * */
57
    protected function setFoodTicketsValue($lngDate, $arySettingMealTickets)
58
    {
59
        $valueMealTicket       = 0;
60
        $indexArrayValues      = 0;
61
        $currentUpperLimitDate = mktime(0, 0, 0, date('n'), 1, date('Y'));
62
        while (($valueMealTicket === 0)) {
63
            $crtVal                = $arySettingMealTickets[$indexArrayValues];
64
            $currentLowerLimitDate = mktime(0, 0, 0, $crtVal['Month'], 1, $crtVal['Year']);
65
            if (($lngDate <= $currentUpperLimitDate) && ($lngDate >= $currentLowerLimitDate)) {
66
                $valueMealTicket = $crtVal['Value'];
67
            }
68
            $currentUpperLimitDate = $currentLowerLimitDate;
69
            $indexArrayValues++;
70
        }
71
        return $valueMealTicket;
72
    }
73
74
    /**
75
     * Deducere personala
76
     * */
77
    protected function setPersonalDeduction($lngDate, $lngBrutto, $sPersons, $cValues)
78
    {
79
        $yrDate  = date('Y', $lngDate);
80
        $nReturn = 0;
81
        if ($yrDate >= 2005) {
82
            $nReturn = $this->setPersonalDeductionComplex2016($sPersons, $lngBrutto, $yrDate, $cValues);
83
        } elseif ($yrDate >= 2001) {
84
            $valuesYearly = [
85
                2001 => $this->setPersonalDeductionSimple2001($lngDate),
86
                2002 => 1600000,
87
                2003 => 1800000,
88
                2004 => 2000000,
89
            ];
90
            $nReturn      = $valuesYearly[$yrDate];
91
        }
92 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...
93
            $nReturn = round($nReturn, -4);
94
        }
95
        return $nReturn;
96
    }
97
98
    private function setPersonalDeductionComplex($sPersons, $lngBrutto, $inRule)
99
    {
100
        $nDeduction = $inRule['Limit maximum amount'];
101
        if ($sPersons <= $inRule['Limit persons']) {
102
            $nDeduction = $inRule['Limit basic amount'] + ($sPersons * $inRule['Limit /person amount']);
103
        }
104
        $nReturn = $nDeduction;
105
        if ($lngBrutto >= $inRule['Limit zero deduction']) {
106
            $nReturn = 0;
107
        } elseif ($lngBrutto > $inRule['Reduced deduction']) {
108
            $nReturn = $nDeduction * (1 - ($lngBrutto - $inRule['Reduced deduction']) / $inRule['Reduced deduction']);
109
        }
110
        return $nReturn;
111
    }
112
113
    private function setPersonalDeductionComplex2016($sPersons, $lngBrutto, $yrDate, $cValues)
114
    {
115
        $inRule = $cValues[2005];
116
        if ($yrDate == 2016) {
117
            $inRule = $cValues[2016];
118
        }
119
        return $this->setPersonalDeductionComplex($sPersons, $lngBrutto, $inRule);
120
    }
121
122
    private function setPersonalDeductionSimple2001($lngDate)
123
    {
124
        $nReturn = 1300000;
125
        $mnDate  = date('n', $lngDate);
126
        if ($mnDate <= 6) {
127
            $nReturn = 1099000;
128
        } elseif ($mnDate <= 9) {
129
            $nReturn = 1273000;
130
        }
131
        return $nReturn;
132
    }
133
}
134