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