Roberto Santini 10 часов назад
Родитель
Сommit
245659f22b

+ 38
- 0
app/Models/Config.php Просмотреть файл

627
     $row->save();
627
     $row->save();
628
   }
628
   }
629
 
629
 
630
+  /**
631
+   * Modalità fattura elettronica del metodo. Se Fatture in Cloud non la indica, si ricava dal nome.
632
+   *
633
+   * @param  array<string, mixed>  $metodo
634
+   */
635
+  public static function modalitaElettronicaMetodo(array $metodo): string
636
+  {
637
+    $ei = strtoupper(trim((string) ($metodo['ei_payment_method'] ?? '')));
638
+    if (preg_match('/^MP\d{2}$/', $ei)) {
639
+      return $ei;
640
+    }
641
+
642
+    $name = mb_strtolower(trim((string) ($metodo['name'] ?? '')));
643
+    foreach ([
644
+      'assegno circolare' => 'MP03',
645
+      'bonifico' => 'MP05',
646
+      'rimessa diretta' => 'MP01',
647
+      'contanti' => 'MP01',
648
+      'assegno' => 'MP02',
649
+      'paypal' => 'MP08',
650
+      'carta' => 'MP08',
651
+      'ri.ba' => 'MP12',
652
+      'riba' => 'MP12',
653
+      'mav' => 'MP13',
654
+      'bollettino' => 'MP18',
655
+      'sepa' => 'MP19',
656
+      'rid' => 'MP09',
657
+      'pagopa' => 'MP23',
658
+      'pago pa' => 'MP23',
659
+    ] as $needle => $code) {
660
+      if ($name !== '' && str_contains($name, $needle)) {
661
+        return $code;
662
+      }
663
+    }
664
+
665
+    return '';
666
+  }
667
+
630
   /**
668
   /**
631
    * @param  array<string, mixed>  $item
669
    * @param  array<string, mixed>  $item
632
    * @return array<string, mixed>
670
    * @return array<string, mixed>

+ 1
- 1
app/Services/FatturaFicService.php Просмотреть файл

205
         if (! $metodo) {
205
         if (! $metodo) {
206
             throw new RuntimeException('Scegli il metodo di pagamento predefinito nella configurazione Fatture in Cloud.');
206
             throw new RuntimeException('Scegli il metodo di pagamento predefinito nella configurazione Fatture in Cloud.');
207
         }
207
         }
208
-        $ei = trim((string) ($metodo['ei_payment_method'] ?? ''));
208
+        $ei = Config::modalitaElettronicaMetodo($metodo);
209
         if ($ei === '') {
209
         if ($ei === '') {
210
             $nome = trim((string) ($metodo['name'] ?? ''));
210
             $nome = trim((string) ($metodo['name'] ?? ''));
211
             throw new RuntimeException('Il metodo'.($nome !== '' ? ' «'.$nome.'»' : '').' non ha la modalità di pagamento elettronica. Impostala su Fatture in Cloud e aggiorna l\'elenco.');
211
             throw new RuntimeException('Il metodo'.($nome !== '' ? ' «'.$nome.'»' : '').' non ha la modalità di pagamento elettronica. Impostala su Fatture in Cloud e aggiorna l\'elenco.');

+ 3
- 1
app/Services/FattureInCloudClient.php Просмотреть файл

419
      */
419
      */
420
     public function paymentMethods(): array
420
     public function paymentMethods(): array
421
     {
421
     {
422
-        $json = $this->decode($this->http()->get($this->url('/info/payment_methods')));
422
+        $json = $this->decode($this->http()->get($this->url('/info/payment_methods'), [
423
+            'fieldset' => 'detailed',
424
+        ]));
423
 
425
 
424
         return is_array($json['data'] ?? null) ? $json['data'] : [];
426
         return is_array($json['data'] ?? null) ? $json['data'] : [];
425
     }
427
     }

+ 2
- 2
resources/views/config/index.blade.php Просмотреть файл

257
                         <input class="form-check-input" type="radio" name="fic_metodo_pagamento_default" value="{{ $metodo['id'] }}" @checked((int) ($catalogoPagamento['default_id'] ?? 0) === (int) $metodo['id']) {{ $disabled }}>
257
                         <input class="form-check-input" type="radio" name="fic_metodo_pagamento_default" value="{{ $metodo['id'] }}" @checked((int) ($catalogoPagamento['default_id'] ?? 0) === (int) $metodo['id']) {{ $disabled }}>
258
                       </td>
258
                       </td>
259
                       <td>{{ $metodo['name'] !== '' ? $metodo['name'] : 'Metodo #'.$metodo['id'] }}</td>
259
                       <td>{{ $metodo['name'] !== '' ? $metodo['name'] : 'Metodo #'.$metodo['id'] }}</td>
260
-                      <td class="text-muted">{{ $metodo['ei_payment_method'] !== '' ? $metodo['ei_payment_method'] : '—' }}</td>
260
+                      <td class="text-muted">{{ ($eiMetodo = Config::modalitaElettronicaMetodo($metodo)) !== '' ? $eiMetodo : '—' }}</td>
261
                     </tr>
261
                     </tr>
262
                     @empty
262
                     @empty
263
                     <tr>
263
                     <tr>
267
                   </tbody>
267
                   </tbody>
268
                 </table>
268
                 </table>
269
               </div>
269
               </div>
270
-              <div class="form-text mb-2">Il metodo segnato viene scritto sulla fattura quando la generi e quando la invii a Fatture in Cloud. Serve anche la modalità elettronica (MP05, MP01, …) impostata sul metodo.</div>
270
+              <div class="form-text mb-2">Il metodo segnato viene scritto sulla fattura quando la generi e quando la invii. Se Fatture in Cloud non indica la modalità elettronica, per il bonifico si usa MP05.</div>
271
               @if($canEdit)
271
               @if($canEdit)
272
               <button type="submit" class="btn btn-sm btn-outline-primary" formaction="{{ route('admin.config.fic_metodi_pagamento') }}">
272
               <button type="submit" class="btn btn-sm btn-outline-primary" formaction="{{ route('admin.config.fic_metodi_pagamento') }}">
273
                 <i class="bx bx-cloud-download me-1"></i>Aggiorna da Fatture in Cloud
273
                 <i class="bx bx-cloud-download me-1"></i>Aggiorna da Fatture in Cloud

Загрузка…
Отмена
Сохранить