|
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 in scadenza e scadut |
172 | | - $servizi_in_scadenza = $servizi->filter(function ($item) use ($limite_scadenze) { |
173 | | - if (!is_array($item) || !isset($item['expiration_at'])) { |
| 171 | + // Calcolo degli elementi con crediti in esaurimento |
| 172 | + $servizi_in_scadenza = $servizi->filter(function ($item) { |
| 173 | + if (!is_array($item)) { |
174 | 174 | return false; |
175 | 175 | } |
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; |
| 176 | + return isset($item['credits']) && $item['credits'] !== null && $item['credits'] !== 0 && $item['credits'] < 100 && $item['credits'] >= 0; |
181 | 177 | }); |
182 | 178 |
|
183 | 179 | $servizi_scaduti = $servizi->filter(function ($item) { |
184 | | - if (!is_array($item) || !isset($item['expiration_at'])) { |
| 180 | + if (!is_array($item)) { |
185 | 181 | return false; |
186 | 182 | } |
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; |
| 183 | + // Crediti esauriti: presenti, non null, e < 0 |
| 184 | + return isset($item['credits']) && $item['credits'] !== null && $item['credits'] < 0; |
192 | 185 | }); |
193 | 186 |
|
194 | 187 | // Messaggi di avviso |
195 | 188 | if (!$servizi_scaduti->isEmpty()) { |
196 | 189 | echo ' |
197 | 190 | <div class="alert alert-danger m-3 mb-0"> |
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 | | - ]).' |
| 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 | + ]).' |
201 | 194 | </div>'; |
202 | 195 | } |
203 | 196 |
|
204 | 197 | if (!$servizi_in_scadenza->isEmpty()) { |
205 | 198 | echo ' |
206 | 199 | <div class="alert alert-warning m-3 mb-0"> |
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 | | - ]).' |
| 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 | + ]).' |
210 | 203 | </div>'; |
211 | 204 | } |
212 | 205 |
|
|
216 | 209 | <tr> |
217 | 210 | <th width="5%" class="text-center">'.tr('Stato').'</th> |
218 | 211 | <th>'.tr('Nome').'</th> |
219 | | - <th width="15%">'.tr('Tipo').'</th> |
220 | | - <th width="15%">'.tr('Scadenza').'</th> |
221 | | - <th width="20%" class="text-center">'.tr('#').'</th> |
| 212 | + <th width="25%" class="text-center">'.tr('#').'</th> |
| 213 | + <th width="20%">'.tr('Scadenza').'</th> |
222 | 214 | </tr> |
223 | 215 | </thead> |
224 | 216 |
|
|
230 | 222 | } |
231 | 223 |
|
232 | 224 | $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 | | - |
249 | 225 | // Campi dell'elemento |
250 | 226 | $codice = $elemento['code'] ?? $elemento['name'] ?? 'N/A'; |
251 | 227 | $nome = $elemento['name'] ?? 'N/A'; |
252 | | - $tipo = $elemento['type'] ?? $elemento['category'] ?? 'N/A'; |
253 | 228 |
|
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>'; |
| 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 | + } |
258 | 264 |
|
259 | 265 | echo ' |
260 | 266 | <tr class="'.$status_class.'"> |
261 | 267 | <td class="text-center">'.$status_icon.'</td> |
262 | 268 | <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> |
265 | 269 | <td class="text-center"> |
266 | 270 | <span class="badge badge-'.$credits_class.'">'.$crediti_display.' '.tr('Crediti').' '.$credits_icon.'</span> |
267 | 271 | </td> |
| 272 | + <td>'.dateFormat($scadenza).' <br><small class="text-muted">'.$scadenza->diffForHumans().'</small></td> |
268 | 273 | </tr>'; |
269 | 274 | } |
270 | 275 |
|
|
0 commit comments