|
|
@@ -284,24 +284,29 @@ class Config extends \App\Models\AbstractModels\AbstractConfig
|
|
284
|
284
|
$items[] = self::normalizzaAliquota($item);
|
|
285
|
285
|
}
|
|
286
|
286
|
|
|
287
|
|
- $defaultId = isset($json['default_id']) ? (int) $json['default_id'] : 0;
|
|
288
|
287
|
$ids = array_column($items, 'id');
|
|
289
|
|
- if (! in_array($defaultId, $ids, true)) {
|
|
290
|
|
- $defaultId = 0;
|
|
|
288
|
+ $defaultId = null;
|
|
|
289
|
+ if (array_key_exists('default_id', $json) && $json['default_id'] !== null && $json['default_id'] !== '') {
|
|
|
290
|
+ $candidate = (int) $json['default_id'];
|
|
|
291
|
+ if (in_array($candidate, $ids, true)) {
|
|
|
292
|
+ $defaultId = $candidate;
|
|
|
293
|
+ }
|
|
291
|
294
|
}
|
|
292
|
295
|
|
|
293
|
296
|
return [
|
|
294
|
|
- 'default_id' => $defaultId ?: null,
|
|
|
297
|
+ 'default_id' => $defaultId,
|
|
295
|
298
|
'items' => $items,
|
|
296
|
299
|
];
|
|
297
|
300
|
}
|
|
298
|
301
|
|
|
299
|
302
|
/**
|
|
|
303
|
+ * L'id 0 è un'aliquota vera su Fatture in Cloud (di solito il 22%).
|
|
|
304
|
+ *
|
|
300
|
305
|
* @return array<string, mixed>|null
|
|
301
|
306
|
*/
|
|
302
|
307
|
public static function aliquotaFic(?int $id): ?array
|
|
303
|
308
|
{
|
|
304
|
|
- if (! $id) {
|
|
|
309
|
+ if ($id === null) {
|
|
305
|
310
|
return null;
|
|
306
|
311
|
}
|
|
307
|
312
|
foreach (self::aliquoteFic()['items'] as $item) {
|
|
|
@@ -361,7 +366,7 @@ class Config extends \App\Models\AbstractModels\AbstractConfig
|
|
361
|
366
|
* @param array<int, array<string, mixed>> $types
|
|
362
|
367
|
* @return array{default_id: ?int, items: array<int, array<string, mixed>>}
|
|
363
|
368
|
*/
|
|
364
|
|
- public static function salvaAliquoteDaFic(array $types, int $requestedDefault = 0): array
|
|
|
369
|
+ public static function salvaAliquoteDaFic(array $types, ?int $requestedDefault = null): array
|
|
365
|
370
|
{
|
|
366
|
371
|
$previous = self::aliquoteFic();
|
|
367
|
372
|
$items = [];
|
|
|
@@ -373,11 +378,12 @@ class Config extends \App\Models\AbstractModels\AbstractConfig
|
|
373
|
378
|
}
|
|
374
|
379
|
|
|
375
|
380
|
$ids = array_column($items, 'id');
|
|
376
|
|
- $defaultId = in_array($requestedDefault, $ids, true) ? $requestedDefault : 0;
|
|
377
|
|
- if (! $defaultId && in_array((int) ($previous['default_id'] ?? 0), $ids, true)) {
|
|
|
381
|
+ $defaultId = null;
|
|
|
382
|
+ if ($requestedDefault !== null && in_array($requestedDefault, $ids, true)) {
|
|
|
383
|
+ $defaultId = $requestedDefault;
|
|
|
384
|
+ } elseif ($previous['default_id'] !== null && in_array((int) $previous['default_id'], $ids, true)) {
|
|
378
|
385
|
$defaultId = (int) $previous['default_id'];
|
|
379
|
|
- }
|
|
380
|
|
- if (! $defaultId && $items) {
|
|
|
386
|
+ } elseif ($items) {
|
|
381
|
387
|
$defaultId = (int) $items[0]['id'];
|
|
382
|
388
|
foreach ($items as $item) {
|
|
383
|
389
|
$natura = (string) ($item['ei_type'] ?? '');
|
|
|
@@ -389,7 +395,7 @@ class Config extends \App\Models\AbstractModels\AbstractConfig
|
|
389
|
395
|
}
|
|
390
|
396
|
|
|
391
|
397
|
$payload = [
|
|
392
|
|
- 'default_id' => $defaultId ?: null,
|
|
|
398
|
+ 'default_id' => $defaultId,
|
|
393
|
399
|
'items' => $items,
|
|
394
|
400
|
];
|
|
395
|
401
|
|