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() |
43
|
|
|
{ |
44
|
|
|
$configPath = 'Salariu' . DIRECTORY_SEPARATOR . 'config'; |
45
|
|
|
$interfaceElements = $this->readTypeFromJsonFileUniversal($configPath, 'interfaceElements'); |
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
|
|
|
$this->refreshExchangeRatesFile($interfaceElements['Application']); |
56
|
|
|
$this->setCurrencyExchangeVariables($interfaceElements['Relevant Currencies']); |
57
|
|
|
$this->getExchangeRates($interfaceElements['Application'], $interfaceElements['Relevant Currencies']); |
58
|
|
|
$aryStngs = $this->readTypeFromJsonFileUniversal($configPath, 'valuesToCompute'); |
59
|
|
|
echo $this->setFormOutput($aryStngs); |
60
|
|
|
echo $this->setFooterHtml($interfaceElements['Application']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function buildArrayOfFieldsStyled() |
64
|
|
|
{ |
65
|
|
|
$sReturn = []; |
66
|
|
|
foreach ($this->appFlags['TCAS'] as $key => $value) { |
67
|
|
|
$sReturn[$this->tApp->gettext($key)] = $value; |
68
|
|
|
} |
69
|
|
|
return $sReturn; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function buildStyleForCellFormat($styleId) |
73
|
|
|
{ |
74
|
|
|
$sReturn = []; |
75
|
|
|
foreach ($this->appFlags['TCSD'][$styleId] as $key => $value) { |
76
|
|
|
$sReturn[] = $key . ':' . $value; |
77
|
|
|
} |
78
|
|
|
return implode(';', $sReturn) . ';'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
private function getExchangeRates($appSettings, $aryRelevantCurrencies) |
82
|
|
|
{ |
83
|
|
|
$xml = new \XMLReader(); |
84
|
|
|
if ($xml->open($appSettings['Exchange Rate Local'], 'UTF-8')) { |
85
|
|
|
while ($xml->read()) { |
86
|
|
|
if ($xml->nodeType == \XMLReader::ELEMENT) { |
87
|
|
|
switch ($xml->localName) { |
88
|
|
|
case 'Cube': |
89
|
|
|
$this->appFlags['currency_exchange_rate_date'] = strtotime($xml->getAttribute('date')); |
90
|
|
|
break; |
91
|
|
|
case 'Rate': |
92
|
|
|
if (array_key_exists($xml->getAttribute('currency'), $aryRelevantCurrencies)) { |
93
|
|
|
$cVal = $xml->readInnerXml(); |
94
|
|
|
if (!is_null($xml->getAttribute('multiplier'))) { |
95
|
|
|
$cVal = $cVal / $xml->getAttribute('multiplier'); |
96
|
|
|
} |
97
|
|
|
$this->appFlags['currency_exchange_rate_value'][$xml->getAttribute('currency')] = $cVal; |
98
|
|
|
} |
99
|
|
|
break; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
$xml->close(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
private function getOvertimes($aryStngs) |
108
|
|
|
{ |
109
|
|
|
$pcToBoolean = [0 => true, 1 => false]; |
110
|
|
|
$pcBoolean = $pcToBoolean[$this->tCmnSuperGlobals->get('pc')]; |
111
|
|
|
$ymVal = $this->tCmnSuperGlobals->get('ym'); |
112
|
|
|
$snVal = $this->tCmnSuperGlobals->get('sn'); |
113
|
|
|
$mnth = $this->setMonthlyAverageWorkingHours($ymVal, $aryStngs, $pcBoolean); |
114
|
|
|
return [ |
115
|
|
|
'os175' => ceil($this->tCmnSuperGlobals->get('os175') * 1.75 * $snVal / $mnth), |
116
|
|
|
'os200' => ceil($this->tCmnSuperGlobals->get('os200') * 2 * $snVal / $mnth), |
117
|
|
|
]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
private function getValues($lngBase, $aStngs) |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
$inDate = $this->tCmnSuperGlobals->get('ym'); |
123
|
|
|
$inDT = new \DateTime(date('Y/m/d', $inDate)); |
124
|
|
|
$wkDay = $this->setWorkingDaysInMonth($inDT, $_REQUEST['pc']); |
125
|
|
|
$nMealDays = ($wkDay - $_REQUEST['zfb']); |
126
|
|
|
$shLbl = [ |
127
|
|
|
'HFP' => 'Health Fund Percentage', |
128
|
|
|
'HFUL' => 'Health Fund Upper Limit', |
129
|
|
|
'HTP' => 'Health Tax Percentage', |
130
|
|
|
'IT' => 'Income Tax', |
131
|
|
|
'MTV' => 'Meal Ticket Value', |
132
|
|
|
]; |
133
|
|
|
$unemploymentBase = $lngBase; |
134
|
|
|
if ($this->tCmnSuperGlobals->get('ym') < mktime(0, 0, 0, 1, 1, 2008)) { |
135
|
|
|
$unemploymentBase = $_REQUEST['sn']; |
136
|
|
|
} |
137
|
|
|
$aReturn = [ |
138
|
|
|
'ba' => $this->setFoodTicketsValue($inDate, $aStngs[$shLbl['MTV']]) * $nMealDays, |
139
|
|
|
'cas' => $this->setHealthFundTax($inDate, $lngBase, $aStngs[$shLbl['HFP']], $aStngs[$shLbl['HFUL']]), |
140
|
|
|
'sanatate' => $this->setHealthTax($inDate, $lngBase, $aStngs[$shLbl['HTP']]), |
141
|
|
|
'somaj' => $this->setUnemploymentTax($inDate, $unemploymentBase), |
142
|
|
|
]; |
143
|
|
|
$pdVal = [ |
144
|
|
|
$inDate, |
145
|
|
|
($lngBase + $aReturn['ba']), |
146
|
|
|
$_REQUEST['pi'], |
147
|
|
|
$aStngs['Personal Deduction'], |
148
|
|
|
]; |
149
|
|
|
$aReturn['pd'] = $this->setPersonalDeduction($pdVal[0], $pdVal[1], $pdVal[2], $pdVal[3]); |
150
|
|
|
$restArrayToDeduct = [ |
151
|
|
|
$aReturn['cas'], |
152
|
|
|
$aReturn['sanatate'], |
153
|
|
|
$aReturn['somaj'], |
154
|
|
|
$aReturn['pd'], |
155
|
|
|
]; |
156
|
|
|
$rest = $lngBase - array_sum($restArrayToDeduct); |
157
|
|
|
if ($inDate >= mktime(0, 0, 0, 7, 1, 2010)) { |
158
|
|
|
$rest += round($aReturn['ba'], -4); |
159
|
|
|
if ($inDate >= mktime(0, 0, 0, 10, 1, 2010)) { |
160
|
|
|
$aReturn['gbns'] = $_REQUEST['gbns'] * pow(10, 4); |
161
|
|
|
$rest += round($aReturn['gbns'], -4); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
$rest += $_REQUEST['afet'] * pow(10, 4); |
165
|
|
|
$aReturn['impozit'] = $this->setIncomeTax($inDate, $rest, $aStngs[$shLbl['IT']]); |
166
|
|
|
$aReturn['zile'] = $wkDay; |
167
|
|
|
return $aReturn; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
private function handleLocalizationSalariu($appSettings) |
171
|
|
|
{ |
172
|
|
|
$this->handleLocalizationSalariuInputsIntoSession($appSettings); |
173
|
|
|
$this->handleLocalizationSalariuSafe($appSettings); |
174
|
|
|
$localizationFile = 'Salariu/locale/' . $this->tCmnSession->get('lang') . '/LC_MESSAGES/salariu.mo'; |
175
|
|
|
$translations = new \Gettext\Translations; |
176
|
|
|
$translations->addFromMoFile($localizationFile); |
177
|
|
|
$this->tApp = new \Gettext\Translator(); |
178
|
|
|
$this->tApp->loadTranslations($translations); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
private function handleLocalizationSalariuInputsIntoSession($appSettings) |
182
|
|
|
{ |
183
|
|
|
if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) { |
184
|
|
|
$this->tCmnSession->set('lang', $appSettings['Default Language']); |
185
|
|
|
} elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) { |
186
|
|
|
$this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING)); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* to avoid potential language injections from other applications that do not applies here |
192
|
|
|
*/ |
193
|
|
|
private function handleLocalizationSalariuSafe($appSettings) |
194
|
|
|
{ |
195
|
|
|
if (!array_key_exists($this->tCmnSession->get('lang'), $appSettings['Available Languages'])) { |
196
|
|
|
$this->tCmnSession->set('lang', $appSettings['Default Language']); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
private function refreshExchangeRatesFile($appSettings) |
201
|
|
|
{ |
202
|
|
|
if ((filemtime($appSettings['Exchange Rate Local']) + 90 * 24 * 60 * 60) < time()) { |
203
|
|
|
$fCntnt = file_get_contents($appSettings['Exchange Rate Source']); |
204
|
|
|
if ($fCntnt !== false) { |
205
|
|
|
file_put_contents($appSettings['Exchange Rate Local'], $fCntnt); |
206
|
|
|
chmod($appSettings['Exchange Rate Local'], 0666); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
private function setCurrencyExchangeVariables($aryRelevantCurrencies) |
212
|
|
|
{ |
213
|
|
|
$this->appFlags['currency_exchanges'] = $aryRelevantCurrencies; |
214
|
|
|
$this->appFlags['currency_exchange_rate_date'] = strtotime('now'); |
215
|
|
|
$krncy = array_keys($this->appFlags['currency_exchanges']); |
216
|
|
|
foreach ($krncy as $value) { |
217
|
|
|
$this->appFlags['currency_exchange_rate_value'][$value] = 1; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
private function setFooterHtml($appSettings) |
222
|
|
|
{ |
223
|
|
|
$sReturn = $this->setUpperRightBoxLanguages($appSettings['Available Languages']) |
224
|
|
|
. '<div class="resetOnly author">© ' . date('Y') . ' ' |
225
|
|
|
. $appSettings['Copyright Holder'] . '</div>' |
226
|
|
|
. '<hr/>' |
227
|
|
|
. '<div class="disclaimer">' |
228
|
|
|
. $this->tApp->gettext('i18n_Disclaimer') |
229
|
|
|
. '</div>'; |
230
|
|
|
return $this->setFooterCommon($sReturn); |
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
private function setFormInput() |
234
|
|
|
{ |
235
|
|
|
$sReturn = []; |
236
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('ym'), $this->setFormInputSelectYM(), 1); |
237
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('sn'), $this->setFormInputText('sn', 10, 'RON'), 1); |
238
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('sc'), $this->setFormInputText('sc', 2, '%'), 1); |
239
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('pb'), $this->setFormInputText('pb', 10, 'RON'), 1); |
240
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('pn'), $this->setFormInputText('pn', 10, 'RON'), 1); |
241
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('os175'), $this->setFormInputText('os175', 2, ''), 1); |
242
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('os200'), $this->setFormInputText('os200', 2, ''), 1); |
243
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('pi'), $this->setFormInputSelectPI(), 1); |
244
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('pc'), $this->setFormInputSelectPC(), 1); |
245
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('szamnt'), $this->setFormInputText('szamnt', 2, ''), 1); |
246
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('zfb'), $this->setFormInputText('zfb', 2, ''), 1); |
247
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('gbns'), $this->setFormInputText('gbns', 2, ''), 1); |
248
|
|
|
$sReturn[] = $this->setFormRow($this->setLabel('afet'), $this->setFormInputText('afet', 2, ''), 1); |
249
|
|
|
$fdVal = [ |
250
|
|
|
'colspan' => 2, |
251
|
|
|
'style' => 'color: red;' |
252
|
|
|
]; |
253
|
|
|
$sReturn[] = $this->setStringIntoTag($this->setStringIntoTag($this->setLabel('fd'), 'td', $fdVal), 'tr'); |
254
|
|
|
$submitParams = [ |
255
|
|
|
'type' => 'submit', |
256
|
|
|
'id' => 'submit', |
257
|
|
|
'value' => $this->setLabel('bc') |
258
|
|
|
]; |
259
|
|
|
$sReturn[] = $this->setFormRow('', $this->setStringIntoShortTag('input', $submitParams), 1); |
260
|
|
|
$frm = $this->setStringIntoTag($this->setStringIntoTag(implode('', $sReturn), 'table'), 'form', [ |
261
|
|
|
'method' => 'get', |
262
|
|
|
'action' => $this->tCmnSuperGlobals->getScriptName() |
263
|
|
|
]); |
264
|
|
|
$aryFieldSet = [ |
265
|
|
|
$this->setStringIntoTag($this->tApp->gettext('i18n_FieldsetLabel_Inputs'), 'legend'), |
266
|
|
|
$frm |
267
|
|
|
]; |
268
|
|
|
return $this->setStringIntoTag(implode('', $aryFieldSet), 'fieldset', ['style' => 'float: left;']); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
private function setFormInputSelectPC() |
272
|
|
|
{ |
273
|
|
|
$choices = [ |
274
|
|
|
$this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceNo'), |
275
|
|
|
$this->tApp->gettext('i18n_Form_Label_CatholicEasterFree_ChoiceYes'), |
276
|
|
|
]; |
277
|
|
|
return $this->setArrayToSelect($choices, $this->tCmnSuperGlobals->get('pc'), 'pc', ['size' => 1]); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
private function setFormInputSelectPI() |
281
|
|
|
{ |
282
|
|
|
$temp2 = []; |
283
|
|
|
for ($counter = 0; $counter <= 4; $counter++) { |
284
|
|
|
$temp2[$counter] = $counter . ($counter == 4 ? '+' : ''); |
285
|
|
|
} |
286
|
|
|
return $this->setArrayToSelect($temp2, $this->tCmnSuperGlobals->get('pi'), 'pi', ['size' => 1]); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
private function setFormInputSelectYM() |
290
|
|
|
{ |
291
|
|
|
$temp = []; |
292
|
|
|
for ($counter = date('Y'); $counter >= 2001; $counter--) { |
293
|
|
|
for ($counter2 = 12; $counter2 >= 1; $counter2--) { |
294
|
|
|
$crtDate = mktime(0, 0, 0, $counter2, 1, $counter); |
295
|
|
|
if ($crtDate <= mktime(0, 0, 0, date('m'), 1, date('Y'))) { |
296
|
|
|
$temp[$crtDate] = strftime('%Y, %m (%B)', $crtDate); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
return $this->setArrayToSelect($temp, $this->tCmnSuperGlobals->get('ym'), 'ym', ['size' => 1]); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
private function setFormInputText($inName, $inSize, $inAfterLabel) |
304
|
|
|
{ |
305
|
|
|
$inputParameters = [ |
306
|
|
|
'type' => 'text', |
307
|
|
|
'name' => $inName, |
308
|
|
|
'value' => $this->tCmnSuperGlobals->get($inName), |
309
|
|
|
'size' => $inSize, |
310
|
|
|
'maxlength' => $inSize, |
311
|
|
|
]; |
312
|
|
|
return $this->setStringIntoShortTag('input', $inputParameters) . ' ' . $inAfterLabel; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
private function setFormOutput($aryStngs) |
|
|
|
|
316
|
|
|
{ |
317
|
|
|
$sReturn = []; |
318
|
|
|
$overtime = $this->getOvertimes($aryStngs['Monthly Average Working Hours']); |
319
|
|
|
$additions = $_REQUEST['pb'] + $overtime['os175'] + $overtime['os200']; |
320
|
|
|
$brut = ($_REQUEST['sn'] * (1 + $_REQUEST['sc'] / 100) + $additions) * pow(10, 4); |
321
|
|
|
$text = $this->tApp->gettext('i18n_Form_Label_ExchangeRateAtDate'); |
322
|
|
|
$xRate = str_replace('%1', date('d.m.Y', $this->appFlags['currency_exchange_rate_date']), $text); |
323
|
|
|
$sReturn[] = $this->setFormRow($xRate, 1000000); |
324
|
|
|
$text = $this->tApp->gettext('i18n_Form_Label_NegotiatedSalary'); |
325
|
|
|
$sReturn[] = $this->setFormRow($text, $_REQUEST['sn'] * 10000); |
326
|
|
|
$prima = $_REQUEST['sn'] * $_REQUEST['sc'] * 100; |
327
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_CumulatedAddedValue'), $prima); |
328
|
|
|
$text = $this->tApp->gettext('i18n_Form_Label_AdditionalBruttoAmount'); |
329
|
|
|
$sReturn[] = $this->setFormRow($text, $_REQUEST['pb'] * 10000); |
330
|
|
|
$ovTime = [ |
331
|
|
|
'main' => $this->tApp->gettext('i18n_Form_Label_OvertimeAmount'), |
332
|
|
|
1 => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice1'), |
333
|
|
|
2 => $this->tApp->gettext('i18n_Form_Label_OvertimeChoice2'), |
334
|
|
|
]; |
335
|
|
|
$sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[1], '175%'), ($overtime['os175'] * pow(10, 4))); |
336
|
|
|
$sReturn[] = $this->setFormRow(sprintf($ovTime['main'], $ovTime[2], '200%'), ($overtime['os200'] * pow(10, 4))); |
337
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_BruttoSalary'), $brut); |
338
|
|
|
$brut += $_REQUEST['afet'] * pow(10, 4); |
339
|
|
|
$amount = $this->getValues($brut, $aryStngs); |
340
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PensionFund'), $amount['cas']); |
341
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_UnemploymentTax'), $amount['somaj']); |
342
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_HealthTax'), $amount['sanatate']); |
343
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_PersonalDeduction'), $amount['pd']); |
344
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_ExciseTax'), $amount['impozit']); |
345
|
|
|
$retineri = $amount['cas'] + $amount['somaj'] + $amount['sanatate'] + $amount['impozit']; |
346
|
|
|
$net = $brut - $retineri + $_REQUEST['pn'] * 10000; |
347
|
|
|
$text = $this->tApp->gettext('i18n_Form_Label_AdditionalNettoAmount'); |
348
|
|
|
$sReturn[] = $this->setFormRow($text, $_REQUEST['pn'] * 10000); |
349
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_NettoSalary'), $net); |
350
|
|
|
$text = $this->tApp->gettext('i18n_Form_Label_SeisureAmout'); |
351
|
|
|
$sReturn[] = $this->setFormRow($text, $_REQUEST['szamnt'] * 10000); |
352
|
|
|
$text = $this->tApp->gettext('i18n_Form_Label_NettoSalaryCash'); |
353
|
|
|
$sReturn[] = $this->setFormRow($text, ($net - $_REQUEST['szamnt'] * 10000)); |
354
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_WorkingDays'), $amount['zile'], 'value'); |
355
|
|
|
$fBonus = [ |
356
|
|
|
'main' => $this->tApp->gettext('i18n_Form_Label_FoodBonuses'), |
357
|
|
|
'no' => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceNo'), |
358
|
|
|
'value' => $this->tApp->gettext('i18n_Form_Label_FoodBonusesChoiceValue') |
359
|
|
|
]; |
360
|
|
|
$fBonusTxt = sprintf($fBonus['main'], $fBonus['value'], $fBonus['no'], ($amount['zile'] - $_REQUEST['zfb'])); |
361
|
|
|
$sReturn[] = $this->setFormRow($fBonusTxt, $amount['ba']); |
362
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_FoodBonusesValue'), $amount['gbns']); |
363
|
|
|
$total = ($net + $amount['ba'] + $amount['gbns'] - $_REQUEST['szamnt'] * 10000); |
364
|
|
|
$sReturn[] = $this->setFormRow($this->tApp->gettext('i18n_Form_Label_Total'), $total); |
365
|
|
|
setlocale(LC_TIME, explode('_', $this->tCmnSession->get('lang'))[0]); |
366
|
|
|
$crtMonth = strftime('%B', $this->tCmnSuperGlobals->get('ym')); |
367
|
|
|
$legend = sprintf($this->tApp->gettext('i18n_FieldsetLabel_Results') |
368
|
|
|
. '', $crtMonth, date('Y', $this->tCmnSuperGlobals->get('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, ['', ' ']) && (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() |
426
|
|
|
{ |
427
|
|
|
$headerParameters = [ |
428
|
|
|
'lang' => str_replace('_', '-', $this->tCmnSession->get('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
|
|
|
|
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: