|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright (c) 2024, Daniel Popiniuc and its licensors. |
|
5
|
|
|
* |
|
6
|
|
|
* All rights reserved. This program and the accompanying materials |
|
7
|
|
|
* are made available under the terms of the Eclipse Public License v1.0 |
|
8
|
|
|
* which accompanies this distribution, and is available at |
|
9
|
|
|
* http://www.eclipse.org/legal/epl-v20.html |
|
10
|
|
|
* |
|
11
|
|
|
* Contributors: |
|
12
|
|
|
* Daniel Popiniuc |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace danielgp\efactura; |
|
16
|
|
|
|
|
17
|
|
|
class ClassElectronicInvoiceUserInterface |
|
18
|
|
|
{ |
|
19
|
|
|
use \danielgp\efactura\TraitUserInterfaceLogic; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
private \SebastianBergmann\Timer\Timer $classTimer; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->classTimer = new \SebastianBergmann\Timer\Timer(); |
|
26
|
|
|
$this->classTimer->start(); |
|
27
|
|
|
$this->getConfiguration(); |
|
28
|
|
|
$this->setLocalization(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
private function getButtonForLocalisation(string $strLanguageCountry): string |
|
32
|
|
|
{ |
|
33
|
|
|
$arrayMapFlags = [ |
|
34
|
|
|
'ro_RO' => 'ro', |
|
35
|
|
|
'it_IT' => 'it', |
|
36
|
|
|
'en_US' => 'us', |
|
37
|
|
|
]; |
|
38
|
|
|
$arrayFlagSizes = ['20px', '15px']; |
|
39
|
|
|
if ($strLanguageCountry === $_GET['language_COUNTRY']) { |
|
40
|
|
|
$arrayFlagSizes = ['40px', '30px']; |
|
41
|
|
|
} |
|
42
|
|
|
return vsprintf('<a href="?language_COUNTRY=%s" style="float:left;margin-left:10px;">' |
|
43
|
|
|
. '<span class="fi fi-%s" style="%s"> </span>' |
|
44
|
|
|
. '</a>', [ |
|
45
|
|
|
$strLanguageCountry . (array_key_exists('action', $_GET) ? '&action=' . $_GET['action'] : ''), |
|
46
|
|
|
$arrayMapFlags[$strLanguageCountry], |
|
47
|
|
|
vsprintf('width:%s;height:%s;', $arrayFlagSizes), |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
private function getButtonToActionSomething(array $arrayButtonFeatures): string |
|
52
|
|
|
{ |
|
53
|
|
|
$arrayButtonStyle = [ |
|
54
|
|
|
'font:bold 14pt Arial', |
|
55
|
|
|
'margin:2px', |
|
56
|
|
|
'padding:4px 10px', |
|
57
|
|
|
]; |
|
58
|
|
|
$arrayStylePieces = $arrayButtonStyle; |
|
59
|
|
|
if (array_key_exists('AdditionalStyle', $arrayButtonFeatures)) { |
|
60
|
|
|
$arrayStylePieces = array_merge($arrayButtonStyle, $arrayButtonFeatures['AdditionalStyle']); |
|
61
|
|
|
} |
|
62
|
|
|
return vsprintf('<a href="%s" class="btn btn-outline-primary" style="%s">%s</a>', [ |
|
63
|
|
|
$arrayButtonFeatures['URL'] |
|
64
|
|
|
. (array_key_exists('language_COUNTRY', $_GET) ? '&language_COUNTRY=' . $_GET['language_COUNTRY'] : ''), |
|
65
|
|
|
implode(';', $arrayStylePieces), |
|
66
|
|
|
$arrayButtonFeatures['Text'], |
|
67
|
|
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function getHeaderColumnMapping(array $arrayColumns): array |
|
71
|
|
|
{ |
|
72
|
|
|
$arrayMap = []; |
|
73
|
|
|
foreach ($arrayColumns as $strColumnName) { |
|
74
|
|
|
$arrayMap[$strColumnName] = $strColumnName; |
|
75
|
|
|
$strRelevant = $this->translation->find(null, 'i18n_Clmn_' . $strColumnName); |
|
76
|
|
|
if (!is_null($strRelevant)) { |
|
77
|
|
|
$arrayMap[$strColumnName] = $strRelevant->getTranslation(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
return $arrayMap; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function setActionToDo(): void |
|
84
|
|
|
{ |
|
85
|
|
|
echo '<main>'; |
|
86
|
|
|
if (is_array($_GET) && array_key_exists('action', $_GET)) { |
|
87
|
|
|
$arrayOptions = [ |
|
88
|
|
|
'action' => FILTER_SANITIZE_SPECIAL_CHARS, |
|
89
|
|
|
]; |
|
90
|
|
|
$arrayInputs = filter_input_array(INPUT_GET, $arrayOptions, true); |
|
91
|
|
|
switch ($arrayInputs['action']) { |
|
92
|
|
|
case 'AnalyzeZIPfromANAFfromLocalFolder': |
|
93
|
|
|
echo '<div class="tabber" id="tabStandard">' |
|
94
|
|
|
. '<div class="tabbertab" id="tab1" title="Filters">'; |
|
95
|
|
|
echo '</div><!-- tab1 -->'; |
|
96
|
|
|
echo '<div class="tabbertab" id="tab2" title="Lista">'; |
|
97
|
|
|
$strRelevantFolder = 'P:/e-Factura/ZIPs_from_ANAF/'; |
|
98
|
|
|
if (!file_exists($strRelevantFolder)) { |
|
99
|
|
|
$strRelevantFolder = realpath('../../'); |
|
100
|
|
|
} |
|
101
|
|
|
$arrayInvoices = $this->actionAnalyzeZIPfromANAFfromLocalFolder($strRelevantFolder); |
|
102
|
|
|
if (count($arrayInvoices) === 0) { |
|
103
|
|
|
echo sprintf('<p style="color:red;">' |
|
104
|
|
|
. $this->translation->find(null, 'i18n_Msg_NoZip')->getTranslation() |
|
105
|
|
|
. '</p>', $strRelevantFolder); |
|
106
|
|
|
} else { |
|
107
|
|
|
echo $this->setHtmlTable($arrayInvoices); |
|
108
|
|
|
} |
|
109
|
|
|
echo '</div><!-- tab2 -->' |
|
110
|
|
|
. '</div><!-- tabStandard -->'; |
|
111
|
|
|
break; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
echo '</main>'; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function setHtmlFooter(): void |
|
118
|
|
|
{ |
|
119
|
|
|
$strHtmlContent = implode('', $this->getFileEntireContent(implode(DIRECTORY_SEPARATOR, [ |
|
120
|
|
|
__DIR__, |
|
121
|
|
|
'HTML', |
|
122
|
|
|
'footer.html', |
|
123
|
|
|
]))); |
|
124
|
|
|
echo vsprintf($strHtmlContent, [ |
|
125
|
|
|
(new \SebastianBergmann\Timer\ResourceUsageFormatter())->resourceUsage($this->classTimer->stop()), |
|
126
|
|
|
date('Y'), |
|
127
|
|
|
$this->arrayConfiguration['Application']['Developer'], |
|
128
|
|
|
]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function setHtmlHeader(): void |
|
132
|
|
|
{ |
|
133
|
|
|
$strHtmlContent = implode('', $this->getFileEntireContent(implode(DIRECTORY_SEPARATOR, [ |
|
134
|
|
|
__DIR__, |
|
135
|
|
|
'HTML', |
|
136
|
|
|
'header.html', |
|
137
|
|
|
]))); |
|
138
|
|
|
echo vsprintf($strHtmlContent, [ |
|
139
|
|
|
$this->arrayConfiguration['Application']['Name'], |
|
140
|
|
|
$this->arrayConfiguration['Application']['Developer'], |
|
141
|
|
|
]); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function setHtmlTable(array $arrayData): string |
|
145
|
|
|
{ |
|
146
|
|
|
$strReturn = '<table style="margin-left:auto;margin-right:auto;">'; |
|
147
|
|
|
foreach ($arrayData as $intLineNo => $arrayContent) { |
|
148
|
|
|
ksort($arrayContent); |
|
149
|
|
|
if ($intLineNo === 0) { |
|
150
|
|
|
$strReturn .= $this->setHtmlTableHeader(array_keys($arrayContent)) |
|
151
|
|
|
. '<tbody>'; |
|
152
|
|
|
} |
|
153
|
|
|
$strReturn .= $this->setHtmlTableLine(($intLineNo + 1), $arrayContent); |
|
154
|
|
|
} |
|
155
|
|
|
return ($strReturn . '</tbody>' . '</table>'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
private function setHtmlTableHeader(array $arrayData): string |
|
159
|
|
|
{ |
|
160
|
|
|
$arrayMap = $this->getHeaderColumnMapping(array_values($arrayData)); |
|
161
|
|
|
$strToReturn = '<th>#</th>'; |
|
162
|
|
|
foreach ($arrayData as $key) { |
|
163
|
|
|
$strToReturn .= sprintf('<th>%s</th>', (array_key_exists($key, $arrayMap) ? $arrayMap[$key] : $key)); |
|
164
|
|
|
} |
|
165
|
|
|
return '<thead><tr>' . $strToReturn . '</tr></thead>'; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
private function setHtmlTableLine(int $intLineNo, array $arrayLine): string |
|
169
|
|
|
{ |
|
170
|
|
|
$arrayContent = []; |
|
171
|
|
|
foreach ($arrayLine as $strColumn => $strValue) { |
|
172
|
|
|
if (str_starts_with($strColumn, 'Amount_')) { |
|
173
|
|
|
$arrayContent[] = sprintf('<td style="text-align:right;">%s</td>', $this->setNumbers($strValue, 2, 2)); |
|
174
|
|
|
} elseif (in_array($strColumn, ['No_of_Lines', 'Response_Size', 'Size'])) { |
|
175
|
|
|
$arrayContent[] = sprintf('<td style="text-align:right;">%s</td>', $this->setNumbers($strValue, 0, 0)); |
|
176
|
|
|
} else { |
|
177
|
|
|
$arrayContent[] = sprintf('<td>%s</td>', $strValue); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
return '<tr' . ($arrayLine['Error'] === '' ? '' : ' style="color:red;"') . '>' |
|
181
|
|
|
. '<td>' . $intLineNo . '</td>' |
|
182
|
|
|
. implode('', $arrayContent) |
|
183
|
|
|
. '</tr>'; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
private function setNumbers(float $floatNumber, int $intMinDigits, int $intMaxDigits): string |
|
187
|
|
|
{ |
|
188
|
|
|
$classFormat = new \NumberFormatter($_GET['language_COUNTRY'], \NumberFormatter::DECIMAL); |
|
189
|
|
|
$classFormat->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $intMinDigits); |
|
190
|
|
|
$classFormat->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $intMaxDigits); |
|
191
|
|
|
return $classFormat->format($floatNumber); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function setUserInterface(): void |
|
195
|
|
|
{ |
|
196
|
|
|
echo '<header class="border-bottom">' |
|
197
|
|
|
. $this->getButtonForLocalisation('en_US') |
|
198
|
|
|
. $this->getButtonForLocalisation('it_IT') |
|
199
|
|
|
. $this->getButtonForLocalisation('ro_RO') |
|
200
|
|
|
. $this->getButtonToActionSomething([ |
|
201
|
|
|
'Text' => $this->translation->find(null, 'i18n_Btn_AnalyzeZIP')->getTranslation(), |
|
202
|
|
|
'URL' => '?action=AnalyzeZIPfromANAFfromLocalFolder', |
|
203
|
|
|
]) |
|
204
|
|
|
. ' </header>'; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|