Bonuses   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 22
lcom 1
cbo 1
dl 0
loc 97
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setFoodTicketsValue() 0 15 2
A setDynamicValues() 0 10 6
A setPersonalDeduction() 0 17 4
A setPersonalDeductionComplex() 0 17 4
A setPersonalDeductionComplex2016() 0 10 3
A setPersonalDeductionSimple2001() 0 11 3
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2016 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
 */
35
trait Bonuses
36
{
37
38
    use InputValidation;
39
40
    /**
41
     * Tichete de alimente
42
     * */
43
    protected function setFoodTicketsValue($dtR, $lngDate, $aryStngMealTickets)
44
    {
45
        $valueMealTicket   = 0;
46
        $indexArrayValues  = 0;
47
        $crtUpperLimitDate = (int) $dtR['maximum']->format('Ymd');
48
        while (($valueMealTicket === 0)) {
49
            $crtVal            = $aryStngMealTickets[$indexArrayValues];
50
            $crtLLDate         = \DateTime::createFromFormat('Y-n-j', $crtVal['Year'] . '-' . $crtVal['Month'] . '-1');
51
            $crtLowerLimitDate = (int) $crtLLDate->format('Ymd');
52
            $valueMealTicket   = $this->setDynamicValues($lngDate, $crtVal, $crtLowerLimitDate, $crtUpperLimitDate);
53
            $crtUpperLimitDate = $crtLowerLimitDate;
54
            $indexArrayValues++;
55
        }
56
        return $valueMealTicket;
57
    }
58
59
    protected function setDynamicValues($lngDate, $crtVal, $crtLowerLimitDate, $crtUpperLimitDate)
60
    {
61
        if (($lngDate <= $crtUpperLimitDate) && ($lngDate >= $crtLowerLimitDate)) {
62
            if (array_key_exists('Value', $crtVal)) {
63
                return $crtVal['Value'];
64
            } elseif (array_key_exists('Multiplier', $crtVal) && array_key_exists('Denominator', $crtVal)) {
65
                return ($crtVal['Multiplier'] / $crtVal['Denominator']);
66
            }
67
        }
68
    }
69
70
    /**
71
     * Deducere personala
72
     * */
73
    protected function setPersonalDeduction($lngDate, $lngBrutto, $sPersons, $cValues)
74
    {
75
        $yrDate  = substr($lngDate, 0, 4);
76
        $nReturn = 0;
77
        if ($yrDate >= 2005) {
78
            $nReturn = $this->setPersonalDeductionComplex2016($sPersons, $lngBrutto, $yrDate, $cValues);
79
        } elseif ($yrDate >= 2001) {
80
            $valuesYearly = [
81
                2001 => $this->setPersonalDeductionSimple2001($lngDate),
82
                2002 => 1600000,
83
                2003 => 1800000,
84
                2004 => 2000000,
85
            ];
86
            $nReturn      = $valuesYearly[$yrDate];
87
        }
88
        return (($lngDate >= 20060701) ? round($nReturn, -4) : $nReturn);
89
    }
90
91
    private function setPersonalDeductionComplex($sPersons, $lngBrutto, $inRule)
92
    {
93
        $nDeduction = $inRule['Limit maximum amount'];
94
        if ($sPersons <= $inRule['Limit persons']) {
95
            $nDeduction = $inRule['Limit basic amount'] + ($sPersons * $inRule['Limit /person amount']);
96
        }
97
        $nReturn = $nDeduction;
98
        if ($lngBrutto >= $inRule['Limit zero deduction']) {
99
            $nReturn = 0;
100
        } else {
101
            $reducedDed = $inRule['Reduced deduction'];
102
            if ($lngBrutto > $reducedDed) {
103
                $nReturn = $nDeduction * (1 - ($lngBrutto - $reducedDed) / $reducedDed);
104
            }
105
        }
106
        return $nReturn;
107
    }
108
109
    private function setPersonalDeductionComplex2016($sPersons, $lngBrutto, $yrDate, $cValues)
110
    {
111
        $inRule = $cValues[2005];
112
        if ($yrDate >= 2018) {
113
            $inRule = $cValues[2018];
114
        } elseif (in_array($yrDate, [2016, 2017])) {
115
            $inRule = $cValues[2016];
116
        }
117
        return $this->setPersonalDeductionComplex($sPersons, $lngBrutto, $inRule);
118
    }
119
120
    private function setPersonalDeductionSimple2001($lngDate)
121
    {
122
        $nReturn = 1300000;
123
        $mnDate  = substr($lngDate, 4, 2);
124
        if ($mnDate <= 6) {
125
            $nReturn = 1099000;
126
        } elseif ($mnDate <= 9) {
127
            $nReturn = 1273000;
128
        }
129
        return $nReturn;
130
    }
131
}
132