Completed
Push — master ( b661cc...bbe755 )
by Daniel
02:24
created

Salariu::handleLocalizationSalariu()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 5
eloc 12
nc 6
nop 1
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
class Salariu
32
{
33
34
    use \danielgp\bank_holidays\Romanian,
35
        \danielgp\common_lib\CommonCode,
36
        \danielgp\salariu\Bonuses,
37
        \danielgp\salariu\Taxation;
38
39
    private $appFlags;
40
    private $tApp = null;
41
42
    public function __construct()
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
43
    {
44
        $configPath        = 'Salariu' . DIRECTORY_SEPARATOR . 'config';
45
        $interfaceElements = $this->readTypeFromJsonFileUniversal($configPath, 'interfaceElements');
0 ignored issues
show
Bug introduced by
The method readTypeFromJsonFileUniversal() does not exist on danielgp\salariu\Salariu. Did you maybe mean readTypeFromJsonFile()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
46
        $this->appFlags    = [
47
            'FI'   => $interfaceElements['Form Input'],
48
            'TCAS' => $interfaceElements['Table Cell Applied Style'],
49
            'TCSD' => $interfaceElements['Table Cell Style Definitions'],
50
        ];
51
        $this->initializeSprGlbAndSession();
52
        $this->handleLocalizationSalariu($interfaceElements['Application']);
53
        echo $this->setHeaderHtml();
54
        echo $this->setFormInput();
55
        if (isset($_REQUEST['ym'])) {
56
            $this->refreshExchangeRatesFile($interfaceElements['Application']);
57
            $this->setCurrencyExchangeVariables($interfaceElements['Relevant Currencies']);
58
            $this->getExchangeRates($interfaceElements['Application'], $interfaceElements['Relevant Currencies']);
59
            $aryStngs = $this->readTypeFromJsonFileUniversal($configPath, 'valuesToCompute');
0 ignored issues
show
Bug introduced by
The method readTypeFromJsonFileUniversal() does not exist on danielgp\salariu\Salariu. Did you maybe mean readTypeFromJsonFile()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
60
            echo $this->setFormOutput($aryStngs);
61
        }
62
        echo $this->setFooterHtml($interfaceElements['Application']);
63
    }
64
65
    private function buildArrayOfFieldsStyled()
66
    {
67
        $sReturn = [];
68
        foreach ($this->appFlags['TCAS'] as $key => $value) {
69
            $sReturn[$this->tApp->gettext($key)] = $value;
70
        }
71
        return $sReturn;
72
    }
73
74
    private function buildStyleForCellFormat($styleId)
75
    {
76
        $sReturn = [];
77
        foreach ($this->appFlags['TCSD'][$styleId] as $key => $value) {
78
            $sReturn[] = $key . ':' . $value;
79
        }
80
        return implode(';', $sReturn) . ';';
81
    }
82
83
    private function getExchangeRates($appSettings, $aryRelevantCurrencies)
84
    {
85
        $xml = new \XMLReader();
86
        if ($xml->open($appSettings['Exchange Rate Local'], 'UTF-8')) {
87
            while ($xml->read()) {
88
                if ($xml->nodeType == \XMLReader::ELEMENT) {
89
                    switch ($xml->localName) {
90
                        case 'Cube':
91
                            $this->appFlags['currency_exchange_rate_date'] = strtotime($xml->getAttribute('date'));
92
                            break;
93
                        case 'Rate':
94
                            if (array_key_exists($xml->getAttribute('currency'), $aryRelevantCurrencies)) {
95
                                $cVal = $xml->readInnerXml();
96
                                if (!is_null($xml->getAttribute('multiplier'))) {
97
                                    $cVal = $cVal / $xml->getAttribute('multiplier');
98
                                }
99
                                $this->appFlags['currency_exchange_rate_value'][$xml->getAttribute('currency')] = $cVal;
100
                            }
101
                            break;
102
                    }
103
                }
104
            }
105
            $xml->close();
106
        }
107
    }
108
109
    private function getOvertimes($aryStngs)
0 ignored issues
show
Coding Style introduced by
getOvertimes uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
110
    {
111
        $pcToBoolean = [0 => true, 1 => false];
112
        $mnth        = $this->setMonthlyAverageWorkingHours($_REQUEST['ym'], $aryStngs, $pcToBoolean[$_REQUEST['pc']]);
113
        return [
114
            'os175' => ceil($_REQUEST['os175'] * 1.75 * $_REQUEST['sn'] / $mnth),
115
            'os200' => ceil($_REQUEST['os200'] * 2 * $_REQUEST['sn'] / $mnth),
116
        ];
117
    }
118
119
    private function getValues($lngBase, $aStngs)
0 ignored issues
show
Coding Style introduced by
getValues uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
120
    {
121
        $inDate           = $_REQUEST['ym'];
122
        $inDT             = new \DateTime(date('Y/m/d', $_REQUEST['ym']));
123
        $wkDay            = $this->setWorkingDaysInMonth($inDT, $_REQUEST['pc']);
124
        $nMealDays        = ($wkDay - $_REQUEST['zfb']);
125
        $shLbl            = [
126
            'HFP'  => 'Health Fund Percentage',
127
            'HFUL' => 'Health Fund Upper Limit',
128
            'HTP'  => 'Health Tax Percentage',
129
            'IT'   => 'Income Tax',
130
            'MTV'  => 'Meal Ticket Value',
131
        ];
132
        $unemploymentBase = $lngBase;
133
        if ($_REQUEST['ym'] < mktime(0, 0, 0, 1, 1, 2008)) {
134
            $unemploymentBase = $_REQUEST['sn'];
135
        }
136
        $aReturn           = [
137
            'ba'       => $this->setFoodTicketsValue($inDate, $aStngs[$shLbl['MTV']]) * $nMealDays,
138
            'cas'      => $this->setHealthFundTax($inDate, $lngBase, $aStngs[$shLbl['HFP']], $aStngs[$shLbl['HFUL']]),
139
            'sanatate' => $this->setHealthTax($inDate, $lngBase, $aStngs[$shLbl['HTP']]),
140
            'somaj'    => $this->setUnemploymentTax($inDate, $unemploymentBase),
141
        ];
142
        $pdVal             = [
143
            $inDate,
144
            ($lngBase + $aReturn['ba']),
145
            $_REQUEST['pi'],
146
            $aStngs['Personal Deduction'],
147
        ];
148
        $aReturn['pd']     = $this->setPersonalDeduction($pdVal[0], $pdVal[1], $pdVal[2], $pdVal[3]);
149
        $restArrayToDeduct = [
150
            $aReturn['cas'],
151
            $aReturn['sanatate'],
152
            $aReturn['somaj'],
153
            $aReturn['pd'],
154
        ];
155
        $rest              = $lngBase - array_sum($restArrayToDeduct);
156
        if ($inDate >= mktime(0, 0, 0, 7, 1, 2010)) {
157
            $rest += round($aReturn['ba'], -4);
158
            if ($inDate >= mktime(0, 0, 0, 10, 1, 2010)) {
159
                $aReturn['gbns'] = $_REQUEST['gbns'] * pow(10, 4);
160
                $rest            += round($aReturn['gbns'], -4);
161
            }
162
        }
163
        $rest               += $_REQUEST['afet'] * pow(10, 4);
164
        $aReturn['impozit'] = $this->setIncomeTax($inDate, $rest, $aStngs[$shLbl['IT']]);
165
        $aReturn['zile']    = $wkDay;
166
        return $aReturn;
167
    }
168
169
    private function handleLocalizationSalariu($appSettings)
170
    {
171
        if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) {
172
            $this->tCmnSession->set('lang', $appSettings['Default Language']);
173
        } elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) {
174
            $this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING));
175
        }
176
        /* to avoid potential language injections from other applications that do not applies here */
177
        if (!array_key_exists($this->tCmnSession->get('lang'), $appSettings['Available Languages'])) {
178
            $this->tCmnSession->set('lang', $appSettings['Default Language']);
179
        }
180
        $localizationFile = 'Salariu/locale/' . $this->tCmnSession->get('lang') . '/LC_MESSAGES/salariu.mo';
181
        $translations     = new \Gettext\Translations;
182
        $translations->addFromMoFile($localizationFile);
183
        $this->tApp       = new \Gettext\Translator();
184
        $this->tApp->loadTranslations($translations);
185
    }
186
187
    private function refreshExchangeRatesFile($appSettings)
188
    {
189
        if ((filemtime($appSettings['Exchange Rate Local']) + 90 * 24 * 60 * 60) < time()) {
190
            $fCntnt = file_get_contents($appSettings['Exchange Rate Source']);
191
            if ($fCntnt !== false) {
192
                file_put_contents($appSettings['Exchange Rate Local'], $fCntnt);
193
                chmod($appSettings['Exchange Rate Local'], 0666);
194
            }
195
        }
196
    }
197
198
    private function setCurrencyExchangeVariables($aryRelevantCurrencies)
199
    {
200
        $this->appFlags['currency_exchanges']          = $aryRelevantCurrencies;
201
        $this->appFlags['currency_exchange_rate_date'] = strtotime('now');
202
        $krncy                                         = array_keys($this->appFlags['currency_exchanges']);
203
        foreach ($krncy as $value) {
204
            $this->appFlags['currency_exchange_rate_value'][$value] = 1;
205
        }
206
    }
207
208
    private function setFooterHtml($appSettings)
209
    {
210
        $sReturn = $this->setUpperRightBoxLanguages($appSettings['Available Languages'])
211
                . '<div class="resetOnly author">&copy; ' . date('Y') . ' '
212
                . $appSettings['Copyright Holder'] . '</div>'
213
                . '<hr/>'
214
                . '<div class="disclaimer">'
215
                . $this->tApp->gettext('i18n_Disclaimer')
216
                . '</div>';
217
        return $this->setFooterCommon($sReturn);
0 ignored issues
show
Documentation introduced by
$sReturn is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
218
    }
219
220
    private function setFormInput()
0 ignored issues
show
Coding Style introduced by
setFormInput uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
setFormInput uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
221
    {
222
        $sReturn      = [];
223
        $sReturn[]    = $this->setFormRow($this->setLabel('ym'), $this->setFormInputSelectYM(), 1);
224
        $sReturn[]    = $this->setFormRow($this->setLabel('sn'), $this->setFormInputText('sn', 10, 'RON'), 1);
225
        $sReturn[]    = $this->setFormRow($this->setLabel('sc'), $this->setFormInputText('sc', 2, '%'), 1);
226
        $sReturn[]    = $this->setFormRow($this->setLabel('pb'), $this->setFormInputText('pb', 10, 'RON'), 1);
227
        $sReturn[]    = $this->setFormRow($this->setLabel('pn'), $this->setFormInputText('pn', 10, 'RON'), 1);
228
        $sReturn[]    = $this->setFormRow($this->setLabel('os175'), $this->setFormInputText('os175', 2, ''), 1);
229
        $sReturn[]    = $this->setFormRow($this->setLabel('os200'), $this->setFormInputText('os200', 2, ''), 1);
230
        $sReturn[]    = $this->setFormRow($this->setLabel('pi'), $this->setFormInputSelectPI(), 1);
231
        $sReturn[]    = $this->setFormRow($this->setLabel('pc'), $this->setFormInputSelectPC(), 1);
232
        $sReturn[]    = $this->setFormRow($this->setLabel('szamnt'), $this->setFormInputText('szamnt', 2, ''), 1);
233
        $sReturn[]    = $this->setFormRow($this->setLabel('zfb'), $this->setFormInputText('zfb', 2, ''), 1);
234
        $sReturn[]    = $this->setFormRow($this->setLabel('gbns'), $this->setFormInputText('gbns', 2, ''), 1);
235
        $sReturn[]    = $this->setFormRow($this->setLabel('afet'), $this->setFormInputText('afet', 2, ''), 1);
236
        $label        = $this->tApp->gettext('i18n_Form_Disclaimer');
237
        $hiddenField  = $this->setStringIntoShortTag('input', [
238
            'type'  => 'hidden',
239
            'name'  => 'action',
240
            'value' => $_SERVER['SERVER_NAME']
241
        ]);
242
        $sReturn[]    = $this->setStringIntoTag($this->setStringIntoTag($label . $hiddenField, 'td', [
243
                    'colspan' => 2,
244
                    'style'   => 'color: red;'
245
                ]), 'tr');
246
        $resetBtn     = $this->setStringIntoShortTag('input', [
247
            'type'  => 'reset',
248
            'id'    => 'reset',
249
            'value' => $this->tApp->gettext('i18n_Form_Button_Reset'),
250
            'style' => 'color:#000;'
251
        ]);
252
        $submitBtnTxt = $this->tApp->gettext('i18n_Form_Button_Calculate');
253
        if (isset($_REQUEST['ym'])) {
254
            $resetBtn     = '';
255
            $submitBtnTxt = $this->tApp->gettext('i18n_Form_Button_Recalculate');
256
        }
257
        $sReturn[] = $this->setFormRow($resetBtn, $this->setStringIntoShortTag('input', [
258
                    'type'  => 'submit',
259
                    'id'    => 'submit',
260
                    'value' => $submitBtnTxt
261
                ]), 1);
262
        $frm       = $this->setStringIntoTag($this->setStringIntoTag(implode('', $sReturn), 'table'), 'form', [
263
            'method' => 'get',
264
            'action' => $_SERVER['SCRIPT_NAME']
265
        ]);
266
        return $this->setStringIntoTag(implode('', [
267
                    $this->setStringIntoTag($this->tApp->gettext('i18n_FieldsetLabel_Inputs'), 'legend'),
268
                    $frm
269
                        ]), 'fieldset', ['style' => 'float: left;']);
270
    }
271
272
    private function setFormInputSelectPC()
0 ignored issues
show
Coding Style introduced by
setFormInputSelectPC uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
273
    {
274
        $choices = [
275
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'),
276
            $this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'),
277
        ];
278
        return $this->setArrayToSelect($choices, $_REQUEST['pc'], 'pc', ['size' => 1]);
279
    }
280
281
    private function setFormInputSelectPI()
0 ignored issues
show
Coding Style introduced by
setFormInputSelectPI uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
282
    {
283
        $temp2 = [];
284
        for ($counter = 0; $counter <= 4; $counter++) {
285
            $temp2[$counter] = $counter . ($counter == 4 ? '+' : '');
286
        }
287
        return $this->setArrayToSelect($temp2, $_REQUEST['pi'], 'pi', ['size' => 1]);
288
    }
289
290
    private function setFormInputSelectYM()
0 ignored issues
show
Coding Style introduced by
setFormInputSelectYM uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
291
    {
292
        $temp = [];
293
        for ($counter = date('Y'); $counter >= 2001; $counter--) {
294
            for ($counter2 = 12; $counter2 >= 1; $counter2--) {
295
                $crtDate = mktime(0, 0, 0, $counter2, 1, $counter);
296
                if ($crtDate <= mktime(0, 0, 0, date('m'), 1, date('Y'))) {
297
                    $temp[$crtDate] = strftime('%Y, %m (%B)', $crtDate);
298
                }
299
            }
300
        }
301
        return $this->setArrayToSelect($temp, $_REQUEST['ym'], 'ym', ['size' => 1]);
302
    }
303
304
    private function setFormInputText($inName, $inSize, $inAfterLabel)
0 ignored issues
show
Coding Style introduced by
setFormInputText uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
305
    {
306
        $inputParameters = [
307
            'type'      => 'text',
308
            'name'      => $inName,
309
            'value'     => $_REQUEST[$inName],
310
            'size'      => $inSize,
311
            'maxlength' => $inSize,
312
        ];
313
        return $this->setStringIntoShortTag('input', $inputParameters) . ' ' . $inAfterLabel;
314
    }
315
316
    private function setFormOutput($aryStngs)
0 ignored issues
show
Coding Style introduced by
setFormOutput uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
setFormOutput uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
317
    {
318
        $sReturn   = [];
319
        $overtime  = $this->getOvertimes($aryStngs['Monthly Average Working Hours']);
320
        $additions = $_REQUEST['pb'] + $overtime['os175'] + $overtime['os200'];
321
        $brut      = ($_REQUEST['sn'] * (1 + $_REQUEST['sc'] / 100) + $additions) * pow(10, 4);
322
        $text      = $this->tApp->gettext('i18n_Form_Label_ExchangeRateAtDate');
323
        $xRate     = str_replace('%1', date('d.m.Y', $this->appFlags['currency_exchange_rate_date']), $text);
324
        $sReturn[] = $this->setFormRow($xRate, 1000000);
325
        $text      = $this->tApp->gettext('i18n_Form_Label_NegotiatedSalary');
326
        $sReturn[] = $this->setFormRow($text, $_REQUEST['sn'] * 10000);
327
        $prima     = $_REQUEST['sn'] * $_REQUEST['sc'] * 100;
328
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_CumulatedAddedValue'), $prima);
329
        $text      = $this->tApp->gettext('i18n_Form_Label_AdditionalBruttoAmount');
330
        $sReturn[] = $this->setFormRow($text, $_REQUEST['pb'] * 10000);
331
        $ovTime    = [
332
            'main' => $this->tApp->gettext('i18n_Form_Label_OvertimeAmount'),
333
            1      => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice1'),
334
            2      => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice2'),
335
        ];
336
        $sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[1], '175%'), ($overtime['os175'] * pow(10, 4)));
337
        $sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[2], '200%'), ($overtime['os200'] * pow(10, 4)));
338
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_BruttoSalary'), $brut);
339
        $brut      += $_REQUEST['afet'] * pow(10, 4);
340
        $amount    = $this->getValues($brut, $aryStngs);
341
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PensionFund'), $amount['cas']);
342
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_UnemploymentTax'), $amount['somaj']);
343
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_HealthTax'), $amount['sanatate']);
344
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PersonalDeduction'), $amount['pd']);
345
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_ExciseTax'), $amount['impozit']);
346
        $retineri  = $amount['cas'] + $amount['somaj'] + $amount['sanatate'] + $amount['impozit'];
347
        $net       = $brut - $retineri + $_REQUEST['pn'] * 10000;
348
        $text      = $this->tApp->gettext('i18n_Form_Label_AdditionalNettoAmount');
349
        $sReturn[] = $this->setFormRow($text, $_REQUEST['pn'] * 10000);
350
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_NettoSalary'), $net);
351
        $text      = $this->tApp->gettext('i18n_Form_Label_SeisureAmout');
352
        $sReturn[] = $this->setFormRow($text, $_REQUEST['szamnt'] * 10000);
353
        $text      = $this->tApp->gettext('i18n_Form_Label_NettoSalaryCash');
354
        $sReturn[] = $this->setFormRow($text, ($net - $_REQUEST['szamnt'] * 10000));
355
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_WorkingDays'), $amount['zile'], 'value');
356
        $fBonus    = [
357
            'main'  => $this->tApp->gettext('i18n_Form_Label_FoodBonuses'),
358
            'no'    => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceNo'),
359
            'value' => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceValue')
360
        ];
361
        $fBonusTxt = sprintf($fBonus['main'], $fBonus['value'], $fBonus['no'], ($amount['zile'] - $_REQUEST['zfb']));
362
        $sReturn[] = $this->setFormRow($fBonusTxt, $amount['ba']);
363
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_FoodBonusesValue'), $amount['gbns']);
364
        $total     = ($net + $amount['ba'] + $amount['gbns'] - $_REQUEST['szamnt'] * 10000);
365
        $sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_Total'), $total);
366
        setlocale(LC_TIME, explode('_', $_SESSION['lang'])[0]);
367
        $crtMonth  = strftime('%B', $_REQUEST['ym']);
368
        $legend    = sprintf($this->tApp->gettext('i18n_FieldsetLabel_Results'), $crtMonth, date('Y', $_REQUEST['ym']));
369
        return $this->setStringIntoTag(implode('', [
370
                    $this->setStringIntoTag($legend, 'legend'),
371
                    $this->setStringIntoTag(implode('', $sReturn), 'table')
372
                        ]), 'fieldset', ['style' => 'float: left;']);
373
    }
374
375
    private function setFormRow($text, $value, $type = 'amount')
376
    {
377
        $a                 = '';
378
        $defaultCellStyle  = $this->setFormatRow($text, $value);
379
        $defaultCellStyle2 = [];
380
        switch ($type) {
381
            case 'amount':
382
                $value                      = $value / pow(10, 4);
383
                $defaultCellStyle2['style'] = $defaultCellStyle['style'] . 'text-align:right;';
384
                $cellValue                  = [];
385
                foreach ($this->appFlags['currency_exchanges'] as $key2 => $value2) {
386
                    $fmt         = new \NumberFormatter($value2['locale'], \NumberFormatter::CURRENCY);
387
                    $fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $value2['decimals']);
388
                    $x           = $this->appFlags['currency_exchange_rate_value'][$key2];
389
                    $finalValue  = $fmt->formatCurrency($value / $x, $key2);
390
                    $cellValue[] = $this->setStringIntoTag($finalValue, 'td', $defaultCellStyle2);
391
                }
392
                $value2show        = implode('', $cellValue);
393
                break;
394
            case 'value':
395
                $defaultCellStyle2 = array_merge($defaultCellStyle, [
396
                    'colspan' => count($this->appFlags['currency_exchanges'])
397
                ]);
398
                $value2show        = $this->setStringIntoTag($value . $a, 'td', $defaultCellStyle2);
399
                break;
400
            default:
401
                $value2show        = $this->setStringIntoTag($value, 'td');
402
                break;
403
        }
404
        if (!in_array($text, ['', '&nbsp;']) && (strpos($text, '<input') === false)) {
405
            $text .= ':';
406
        }
407
        return $this->setStringIntoTag($this->setStringIntoTag($text, 'td', $defaultCellStyle) . $value2show, 'tr');
408
    }
409
410
    private function setFormatRow($text, $value)
411
    {
412
        $defaultCellStyle = [
413
            'class' => 'labelS',
414
        ];
415
        $fieldsStyled     = $this->buildArrayOfFieldsStyled();
416
        if (array_key_exists($text, $fieldsStyled)) {
417
            $defaultCellStyle['style'] = $this->buildStyleForCellFormat($fieldsStyled[$text]);
418
        }
419
        if ((is_numeric($value)) && ($value == 0)) {
420
            $defaultCellStyle['style'] = 'color:#666;';
421
        }
422
        return $defaultCellStyle;
423
    }
424
425
    private function setHeaderHtml()
0 ignored issues
show
Coding Style introduced by
setHeaderHtml uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
426
    {
427
        $headerParameters = [
428
            'lang'  => str_replace('_', '-', $_SESSION['lang']),
429
            'title' => $this->tApp->gettext('i18n_ApplicationName'),
430
            'css'   => [
431
                'vendor/components/flag-icon-css/css/flag-icon.min.css',
432
                'Salariu/css/salariu.css',
433
            ],
434
        ];
435
        return $this->setHeaderCommon($headerParameters)
436
                . '<h1>' . $this->tApp->gettext('i18n_ApplicationName') . '</h1>';
437
    }
438
439
    private function setLabel($labelId)
440
    {
441
        $labelInfo = $this->appFlags['FI'][$labelId]['Label'];
442
        $sReturn   = '';
443
        if (is_array($labelInfo)) {
444
            if (count($labelInfo) == 3) {
445
                $pieces  = [
446
                    $this->tApp->gettext($labelInfo[0]),
447
                    $this->tApp->gettext($labelInfo[1]),
448
                ];
449
                $sReturn = sprintf($pieces[0], $pieces[1], $labelInfo[2]);
450
            }
451
        } elseif (is_string($labelInfo)) {
452
            $sReturn = $this->tApp->gettext($labelInfo);
453
        }
454
        return $sReturn;
455
    }
456
}
457