|
168 | 168 | // Recupero di tutti i servizi e risorse attivi |
169 | 169 | $servizi = Services::getRisorseAttive(true); |
170 | 170 | if (!$servizi->isEmpty()) { |
171 | | - // Calcolo degli elementi con crediti in esaurimento |
172 | | - $servizi_in_scadenza = $servizi->filter(function ($item) { |
173 | | - if (!is_array($item)) { |
| 171 | + // Calcolo degli elementi in scadenza e scaduti |
| 172 | + $servizi_in_scadenza = $servizi->filter(function ($item) use ($limite_scadenze) { |
| 173 | + if (!is_array($item) || !isset($item['expiration_at'])) { |
174 | 174 | return false; |
175 | 175 | } |
176 | | - return isset($item['credits']) && $item['credits'] !== null && $item['credits'] !== 0 && $item['credits'] < 100 && $item['credits'] >= 0; |
| 176 | + $scadenza = Carbon::parse($item['expiration_at']); |
| 177 | + $credits_warning = isset($item['credits']) && $item['credits'] < 100 && $item['credits'] !== null; |
| 178 | + $is_expiring = $scadenza->greaterThan(Carbon::now()) && $scadenza->lessThan($limite_scadenze); |
| 179 | + |
| 180 | + return $is_expiring || $credits_warning; |
177 | 181 | }); |
178 | 182 |
|
179 | 183 | $servizi_scaduti = $servizi->filter(function ($item) { |
180 | | - if (!is_array($item)) { |
| 184 | + if (!is_array($item) || !isset($item['expiration_at'])) { |
181 | 185 | return false; |
182 | 186 | } |
183 | | - // Crediti esauriti: presenti, non null, e < 0 |
184 | | - return isset($item['credits']) && $item['credits'] !== null && $item['credits'] < 0; |
| 187 | + $scadenza = Carbon::parse($item['expiration_at']); |
| 188 | + $credits_expired = isset($item['credits']) && $item['credits'] < 0; |
| 189 | + $is_expired = $scadenza->lessThan(Carbon::now()); |
| 190 | + |
| 191 | + return $is_expired || $credits_expired; |
185 | 192 | }); |
186 | 193 |
|
187 | 194 | // Messaggi di avviso |
188 | 195 | if (!$servizi_scaduti->isEmpty()) { |
189 | 196 | echo ' |
190 | 197 | <div class="alert alert-danger m-3 mb-0"> |
191 | | - <i class="fa fa-exclamation-triangle mr-2"></i>'.tr('Attenzione, alcuni elementi hanno esaurito i crediti: _NUM_', [ |
192 | | - '_NUM_' => $servizi_scaduti->count(), |
193 | | - ]).' |
| 198 | + <i class="fa fa-exclamation-triangle mr-2"></i>'.tr('Attenzione, alcuni elementi sono scaduti o hanno esaurito i crediti: _NUM_', [ |
| 199 | + '_NUM_' => $servizi_scaduti->count(), |
| 200 | + ]).' |
194 | 201 | </div>'; |
195 | 202 | } |
196 | 203 |
|
197 | 204 | if (!$servizi_in_scadenza->isEmpty()) { |
198 | 205 | echo ' |
199 | 206 | <div class="alert alert-warning m-3 mb-0"> |
200 | | - <i class="fa fa-clock-o mr-2"></i>'.tr('Attenzione, alcuni elementi stanno per esaurire i crediti: _NUM_', [ |
201 | | - '_NUM_' => $servizi_in_scadenza->count(), |
202 | | - ]).' |
| 207 | + <i class="fa fa-clock-o mr-2"></i>'.tr('Attenzione, alcuni elementi sono in scadenza o stanno per esaurire i crediti: _NUM_', [ |
| 208 | + '_NUM_' => $servizi_in_scadenza->count(), |
| 209 | + ]).' |
203 | 210 | </div>'; |
204 | 211 | } |
205 | 212 |
|
|
209 | 216 | <tr> |
210 | 217 | <th width="5%" class="text-center">'.tr('Stato').'</th> |
211 | 218 | <th>'.tr('Nome').'</th> |
212 | | - <th width="25%" class="text-center">'.tr('#').'</th> |
213 | | - <th width="20%">'.tr('Scadenza').'</th> |
| 219 | + <th width="15%">'.tr('Tipo').'</th> |
| 220 | + <th width="15%">'.tr('Scadenza').'</th> |
| 221 | + <th width="20%" class="text-center">'.tr('#').'</th> |
214 | 222 | </tr> |
215 | 223 | </thead> |
216 | 224 |
|
|
222 | 230 | } |
223 | 231 |
|
224 | 232 | $scadenza = Carbon::parse($elemento['expiration_at']); |
| 233 | + $has_credits = isset($elemento['credits']); |
| 234 | + $credits_warning = $has_credits && $elemento['credits'] < 100 && $elemento['credits'] !== null; |
| 235 | + $credits_expired = $has_credits && $elemento['credits'] < 0; |
| 236 | + $is_expired = $scadenza->lessThan(Carbon::now()); |
| 237 | + $is_expiring = $scadenza->greaterThan(Carbon::now()) && $scadenza->lessThan($limite_scadenze); |
| 238 | + |
| 239 | + // Determinazione dello stato |
| 240 | + $status_class = ($is_expired || $credits_expired) ? 'table-danger' : (($is_expiring || $credits_warning) ? 'table-warning' : ''); |
| 241 | + $status_icon = ($is_expired || $credits_expired) ? '<i class="fa fa-times-circle text-danger" title="'.tr('Scaduto/Esaurito').'"></i>' : |
| 242 | + (($is_expiring || $credits_warning) ? '<i class="fa fa-exclamation-triangle text-warning" title="'.tr('Attenzione').'"></i>' : |
| 243 | + '<i class="fa fa-check-circle text-success" title="'.tr('Attivo').'"></i>'); |
| 244 | + |
| 245 | + $credits_class = ($credits_expired ? 'danger' : ($credits_warning ? 'warning' : 'secondary')); |
| 246 | + $credits_icon = ($credits_warning || $credits_expired ? '<i class="fa fa-exclamation-triangle" title="'.tr('Attenzione').'"></i>' : ''); |
| 247 | + |
| 248 | + |
225 | 249 | // Campi dell'elemento |
226 | 250 | $codice = $elemento['code'] ?? $elemento['name'] ?? 'N/A'; |
227 | 251 | $nome = $elemento['name'] ?? 'N/A'; |
| 252 | + $tipo = $elemento['type'] ?? $elemento['category'] ?? 'N/A'; |
228 | 253 |
|
229 | | - // Gestione crediti semplificata |
230 | | - if (!isset($elemento['credits']) || $elemento['credits'] === null || $elemento['credits'] === 0) { |
231 | | - // Crediti infiniti |
232 | | - $crediti_display = tr('Infiniti'); |
233 | | - $credits_class = 'success'; |
234 | | - $credits_icon = ''; |
235 | | - $status_class = ''; |
236 | | - $status_icon = '<i class="fa fa-check-circle text-success" title="'.tr('Crediti infiniti').'"></i>'; |
237 | | - } else { |
238 | | - // Crediti specificati |
239 | | - $credits_value = (int) $elemento['credits']; |
240 | | - |
241 | | - if ($credits_value < 0) { |
242 | | - // Crediti esauriti |
243 | | - $crediti_display = '<i class="fa fa-times-circle text-danger mr-1"></i>'.$credits_value; |
244 | | - $credits_class = 'danger'; |
245 | | - $credits_icon = '<i class="fa fa-exclamation-triangle" title="'.tr('Crediti esauriti').'"></i>'; |
246 | | - $status_class = 'table-danger'; |
247 | | - $status_icon = '<i class="fa fa-times-circle text-danger" title="'.tr('Crediti esauriti').'"></i>'; |
248 | | - } elseif ($credits_value < 100) { |
249 | | - // Crediti in esaurimento |
250 | | - $crediti_display = '<i class="fa fa-exclamation-triangle text-warning mr-1"></i>'.$credits_value; |
251 | | - $credits_class = 'warning'; |
252 | | - $credits_icon = '<i class="fa fa-exclamation-triangle" title="'.tr('Crediti in esaurimento').'"></i>'; |
253 | | - $status_class = 'table-warning'; |
254 | | - $status_icon = '<i class="fa fa-exclamation-triangle text-warning" title="'.tr('Crediti in esaurimento').'"></i>'; |
255 | | - } else { |
256 | | - // Crediti OK |
257 | | - $crediti_display = $credits_value; |
258 | | - $credits_class = 'secondary'; |
259 | | - $credits_icon = ''; |
260 | | - $status_class = ''; |
261 | | - $status_icon = '<i class="fa fa-check-circle text-success" title="'.tr('Crediti OK').'"></i>'; |
262 | | - } |
263 | | - } |
| 254 | + // Gestione crediti: mostra solo se presenti, altrimenti "-" |
| 255 | + $crediti_display = $has_credits ? |
| 256 | + ($credits_warning || $credits_expired ? '<i class="fa fa-exclamation-triangle text-warning mr-1"></i>' : '').($elemento['credits'] ?? '-') : |
| 257 | + '<span class="text-muted">-</span>'; |
264 | 258 |
|
265 | 259 | echo ' |
266 | 260 | <tr class="'.$status_class.'"> |
267 | 261 | <td class="text-center">'.$status_icon.'</td> |
268 | 262 | <td><strong>'.$codice.'</strong><br><small class="text-muted">'.$nome.'</small></td> |
| 263 | + <td><span class="badge badge-info">'.$tipo.'</span></td> |
| 264 | + <td>'.dateFormat($scadenza).' <br><small class="text-muted">'.$scadenza->diffForHumans().'</small></td> |
269 | 265 | <td class="text-center"> |
270 | 266 | <span class="badge badge-'.$credits_class.'">'.$crediti_display.' '.tr('Crediti').' '.$credits_icon.'</span> |
271 | 267 | </td> |
272 | | - <td>'.dateFormat($scadenza).' <br><small class="text-muted">'.$scadenza->diffForHumans().'</small></td> |
273 | 268 | </tr>'; |
274 | 269 | } |
275 | 270 |
|
|
0 commit comments