Roberto Santini 3 недель назад
Родитель
Сommit
d575cb086e

+ 10
- 0
app/Http/Controllers/AziendaController.php Просмотреть файл

66
             'nome' => 'nullable|string|max:255',
66
             'nome' => 'nullable|string|max:255',
67
             'piva' => 'nullable|string|max:50',
67
             'piva' => 'nullable|string|max:50',
68
             'cod_fiscale' => 'nullable|string|max:16',
68
             'cod_fiscale' => 'nullable|string|max:16',
69
+            'codice_sdi' => ['nullable', 'string', 'regex:/^[A-Za-z0-9]{6,7}$/'],
70
+            'pec' => 'nullable|email|max:255',
69
             'email' => 'nullable|email|max:255',
71
             'email' => 'nullable|email|max:255',
70
             'telefono' => 'nullable|string|max:255',
72
             'telefono' => 'nullable|string|max:255',
71
             'indirizzo' => 'nullable|string|max:500',
73
             'indirizzo' => 'nullable|string|max:500',
91
         $azienda->cod_fiscale = isset($validated['cod_fiscale']) && trim((string) $validated['cod_fiscale']) !== ''
93
         $azienda->cod_fiscale = isset($validated['cod_fiscale']) && trim((string) $validated['cod_fiscale']) !== ''
92
             ? strtoupper(trim($validated['cod_fiscale']))
94
             ? strtoupper(trim($validated['cod_fiscale']))
93
             : null;
95
             : null;
96
+        $azienda->codice_sdi = isset($validated['codice_sdi']) && trim((string) $validated['codice_sdi']) !== ''
97
+            ? strtoupper(trim($validated['codice_sdi']))
98
+            : null;
99
+        $azienda->pec = isset($validated['pec']) && trim((string) $validated['pec']) !== ''
100
+            ? trim($validated['pec'])
101
+            : null;
94
         $azienda->email = $validated['email'] ?? null;
102
         $azienda->email = $validated['email'] ?? null;
95
         $azienda->telefono = $validated['telefono'] ?? null;
103
         $azienda->telefono = $validated['telefono'] ?? null;
96
         $azienda->indirizzo = $validated['indirizzo'] ?? null;
104
         $azienda->indirizzo = $validated['indirizzo'] ?? null;
131
             'nome' => $azienda->nome,
139
             'nome' => $azienda->nome,
132
             'piva' => $azienda->piva,
140
             'piva' => $azienda->piva,
133
             'cod_fiscale' => $azienda->cod_fiscale,
141
             'cod_fiscale' => $azienda->cod_fiscale,
142
+            'codice_sdi' => $azienda->codice_sdi,
143
+            'pec' => $azienda->pec,
134
             'email' => $azienda->email,
144
             'email' => $azienda->email,
135
             'telefono' => $azienda->telefono,
145
             'telefono' => $azienda->telefono,
136
             'indirizzo' => $azienda->indirizzo,
146
             'indirizzo' => $azienda->indirizzo,

+ 6
- 0
app/Http/Controllers/UserController.php Просмотреть файл

86
       'ragione_sociale' => 'nullable|string|max:255',
86
       'ragione_sociale' => 'nullable|string|max:255',
87
       'piva' => 'nullable|string|max:50',
87
       'piva' => 'nullable|string|max:50',
88
       'cod_fiscale' => 'nullable|string|max:50',
88
       'cod_fiscale' => 'nullable|string|max:50',
89
+      'codice_sdi' => ['nullable', 'string', 'regex:/^[A-Za-z0-9]{6,7}$/'],
90
+      'pec' => 'nullable|email|max:255',
89
       'indirizzo' => 'nullable|string|max:255',
91
       'indirizzo' => 'nullable|string|max:255',
90
       'comune_id' => 'nullable|exists:comune,id',
92
       'comune_id' => 'nullable|exists:comune,id',
91
       'note' => 'nullable|string',
93
       'note' => 'nullable|string',
100
       }
102
       }
101
     }
103
     }
102
 
104
 
105
+    if (array_key_exists('codice_sdi', $validated) && $validated['codice_sdi']) {
106
+      $validated['codice_sdi'] = strtoupper($validated['codice_sdi']);
107
+    }
108
+
103
     if (array_key_exists('dominio_email', $validated)) {
109
     if (array_key_exists('dominio_email', $validated)) {
104
       $validated['dominio_email'] = $user->is_azienda
110
       $validated['dominio_email'] = $user->is_azienda
105
         ? User::normalizeDominioEmail($validated['dominio_email'])
111
         ? User::normalizeDominioEmail($validated['dominio_email'])

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

15
 
15
 
16
 class User extends \App\Models\AbstractModels\AbstractUser
16
 class User extends \App\Models\AbstractModels\AbstractUser
17
 {
17
 {
18
+  public function getFillable()
19
+  {
20
+    return array_merge(parent::getFillable(), [
21
+      'codice_sdi',
22
+      'pec',
23
+    ]);
24
+  }
25
+
18
 
26
 
19
   use HasApiTokens;
27
   use HasApiTokens;
20
   use HasRoles;
28
   use HasRoles;

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

4
 
4
 
5
 use App\Models\Config;
5
 use App\Models\Config;
6
 use App\Models\Fattura;
6
 use App\Models\Fattura;
7
+use App\Models\User;
7
 use App\Models\FatturaRiga;
8
 use App\Models\FatturaRiga;
8
 use App\Models\FicCollegamento;
9
 use App\Models\FicCollegamento;
9
 use App\Models\Prodotto;
10
 use App\Models\Prodotto;
38
         try {
39
         try {
39
             $client = $this->fic->getClient((int) $collegamento->fic_client_id);
40
             $client = $this->fic->getClient((int) $collegamento->fic_client_id);
40
             $vatId = $this->vatId((float) ($fattura->iva_percentuale ?? Config::ivaPercentualeDefault()));
41
             $vatId = $this->vatId((float) ($fattura->iva_percentuale ?? Config::ivaPercentualeDefault()));
41
-            $document = $this->fic->createIssuedDocument($this->payload($fattura, $client, $vatId));
42
+            $anagrafica = User::find($collegamento->user_id);
43
+            $document = $this->fic->createIssuedDocument($this->payload($fattura, $client, $vatId, $anagrafica));
42
             if (! isset($document['number']) || $document['number'] === '' || $document['number'] === null) {
44
             if (! isset($document['number']) || $document['number'] === '' || $document['number'] === null) {
43
                 $document = $this->fic->getIssuedDocument((int) $document['id']);
45
                 $document = $this->fic->getIssuedDocument((int) $document['id']);
44
             }
46
             }
105
      * @param  array<string, mixed>  $client
107
      * @param  array<string, mixed>  $client
106
      * @return array<string, mixed>
108
      * @return array<string, mixed>
107
      */
109
      */
108
-    protected function payload(Fattura $fattura, array $client, int $vatId): array
110
+    protected function payload(Fattura $fattura, array $client, int $vatId, ?User $anagrafica = null): array
109
     {
111
     {
110
         $data = $fattura->data ? Carbon::parse($fattura->data)->toDateString() : now()->toDateString();
112
         $data = $fattura->data ? Carbon::parse($fattura->data)->toDateString() : now()->toDateString();
111
         $entity = ['id' => (int) $client['id']];
113
         $entity = ['id' => (int) $client['id']];
133
         if (empty($entity['country'])) {
135
         if (empty($entity['country'])) {
134
             $entity['country'] = 'Italia';
136
             $entity['country'] = 'Italia';
135
         }
137
         }
136
-        if (empty($entity['ei_code'])) {
138
+        $codiceSdi = strtoupper(trim((string) ($anagrafica->codice_sdi ?? '')));
139
+        if ($codiceSdi !== '') {
140
+            $entity['ei_code'] = $codiceSdi;
141
+        } elseif (empty($entity['ei_code'])) {
137
             $entity['ei_code'] = '0000000';
142
             $entity['ei_code'] = '0000000';
138
         }
143
         }
144
+        $pec = trim((string) ($anagrafica->pec ?? ''));
145
+        if ($pec !== '') {
146
+            $entity['certified_email'] = $pec;
147
+        }
139
 
148
 
140
         $items = [];
149
         $items = [];
141
         foreach ($fattura->righe as $riga) {
150
         foreach ($fattura->righe as $riga) {

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

20
         'address_street' => 'Indirizzo',
20
         'address_street' => 'Indirizzo',
21
         'citta' => 'Città',
21
         'citta' => 'Città',
22
         'notes' => 'Note',
22
         'notes' => 'Note',
23
+        'codice_sdi' => 'Codice SDI',
24
+        'pec' => 'PEC',
23
     ];
25
     ];
24
 
26
 
25
     public function configured(): bool
27
     public function configured(): bool
175
                 'address_city' => $raw['city'] ?? '',
177
                 'address_city' => $raw['city'] ?? '',
176
                 'address_province' => $raw['province'] ?? '',
178
                 'address_province' => $raw['province'] ?? '',
177
             ],
179
             ],
180
+            'codice_sdi' => ['ei_code' => strtoupper(trim((string) ($raw['value'] ?? '')))],
181
+            'pec' => ['certified_email' => trim((string) ($raw['value'] ?? ''))],
178
             default => [$key => $raw['value'] ?? ''],
182
             default => [$key => $raw['value'] ?? ''],
179
         };
183
         };
180
     }
184
     }
205
                 'raw' => ['city' => $city, 'province' => $province],
209
                 'raw' => ['city' => $city, 'province' => $province],
206
             ],
210
             ],
207
             'notes' => $this->pack(trim((string) $azienda->note)),
211
             'notes' => $this->pack(trim((string) $azienda->note)),
212
+            'codice_sdi' => $this->pack(strtoupper(trim((string) $azienda->codice_sdi))),
213
+            'pec' => $this->pack(strtolower(trim((string) $azienda->pec)), trim((string) $azienda->pec)),
208
         ];
214
         ];
209
     }
215
     }
210
 
216
 
229
                 'raw' => ['city' => $city, 'province' => $province],
235
                 'raw' => ['city' => $city, 'province' => $province],
230
             ],
236
             ],
231
             'notes' => $this->pack(trim((string) ($client['notes'] ?? ''))),
237
             'notes' => $this->pack(trim((string) ($client['notes'] ?? ''))),
238
+            'codice_sdi' => $this->pack(strtoupper(trim((string) ($client['ei_code'] ?? '')))),
239
+            'pec' => $this->pack(strtolower(trim((string) ($client['certified_email'] ?? ''))), trim((string) ($client['certified_email'] ?? ''))),
232
         ];
240
         ];
233
     }
241
     }
234
 
242
 
244
             'phone' => $this->applyString($azienda, 'telefono', $value, 255),
252
             'phone' => $this->applyString($azienda, 'telefono', $value, 255),
245
             'address_street' => $this->applyString($azienda, 'indirizzo', $value, 255),
253
             'address_street' => $this->applyString($azienda, 'indirizzo', $value, 255),
246
             'notes' => $this->applyNote($azienda, $value),
254
             'notes' => $this->applyNote($azienda, $value),
255
+            'codice_sdi' => $this->applyString($azienda, 'codice_sdi', strtoupper($value), 7),
256
+            'pec' => $this->applyEmailField($azienda, 'pec', $value),
247
             'citta' => $this->applyCitta($azienda, (string) ($raw['city'] ?? ''), (string) ($raw['province'] ?? '')),
257
             'citta' => $this->applyCitta($azienda, (string) ($raw['city'] ?? ''), (string) ($raw['province'] ?? '')),
248
             default => null,
258
             default => null,
249
         };
259
         };
289
     }
299
     }
290
 
300
 
291
     private function applyEmail(Azienda $azienda, string $value): ?string
301
     private function applyEmail(Azienda $azienda, string $value): ?string
302
+    {
303
+        return $this->applyEmailField($azienda, 'email', $value);
304
+    }
305
+
306
+    private function applyEmailField(Azienda $azienda, string $attribute, string $value): ?string
292
     {
307
     {
293
         if ($value !== '' && ! filter_var($value, FILTER_VALIDATE_EMAIL)) {
308
         if ($value !== '' && ! filter_var($value, FILTER_VALIDATE_EMAIL)) {
294
             return 'L\'email remota non è valida.';
309
             return 'L\'email remota non è valida.';
295
         }
310
         }
296
-        $azienda->email = $value !== '' ? $value : null;
311
+        $azienda->{$attribute} = $value !== '' ? $value : null;
297
 
312
 
298
         return null;
313
         return null;
299
     }
314
     }

+ 23
- 0
database/migrations/2026_10_12_230800_add_codice_sdi_and_pec_to_users_table.php Просмотреть файл

1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    public function up(): void
10
+    {
11
+        Schema::table('users', function (Blueprint $table) {
12
+            $table->string('codice_sdi', 7)->nullable()->after('cod_fiscale');
13
+            $table->string('pec', 255)->nullable()->after('codice_sdi');
14
+        });
15
+    }
16
+
17
+    public function down(): void
18
+    {
19
+        Schema::table('users', function (Blueprint $table) {
20
+            $table->dropColumn(['codice_sdi', 'pec']);
21
+        });
22
+    }
23
+};

+ 2
- 0
resources/views/azienda/modal-scripts.blade.php Просмотреть файл

73
       $('#azienda_nome').val(data.nome || '');
73
       $('#azienda_nome').val(data.nome || '');
74
       $('#azienda_piva').val(data.piva || '');
74
       $('#azienda_piva').val(data.piva || '');
75
       $('#azienda_cod_fiscale').val(data.cod_fiscale || '');
75
       $('#azienda_cod_fiscale').val(data.cod_fiscale || '');
76
+      $('#azienda_codice_sdi').val(data.codice_sdi || '');
77
+      $('#azienda_pec').val(data.pec || '');
76
       $('#azienda_telefono').val(data.telefono || '');
78
       $('#azienda_telefono').val(data.telefono || '');
77
       $('#azienda_email').val(data.email || '');
79
       $('#azienda_email').val(data.email || '');
78
       $('#azienda_dominio_email').val(data.dominio_email || '');
80
       $('#azienda_dominio_email').val(data.dominio_email || '');

+ 9
- 0
resources/views/azienda/modal.blade.php Просмотреть файл

36
               <label class="form-label" for="azienda_cod_fiscale">Codice fiscale</label>
36
               <label class="form-label" for="azienda_cod_fiscale">Codice fiscale</label>
37
               <input type="text" class="form-control text-uppercase" name="cod_fiscale" id="azienda_cod_fiscale" maxlength="16">
37
               <input type="text" class="form-control text-uppercase" name="cod_fiscale" id="azienda_cod_fiscale" maxlength="16">
38
             </div>
38
             </div>
39
+            <div class="col-md-6">
40
+              <label class="form-label" for="azienda_codice_sdi">Codice SDI</label>
41
+              <input type="text" class="form-control text-uppercase" name="codice_sdi" id="azienda_codice_sdi" maxlength="7"
42
+                placeholder="7 caratteri, oppure 0000000">
43
+            </div>
44
+            <div class="col-md-6">
45
+              <label class="form-label" for="azienda_pec">PEC</label>
46
+              <input type="email" class="form-control" name="pec" id="azienda_pec" maxlength="255">
47
+            </div>
39
             <div class="col-md-6">
48
             <div class="col-md-6">
40
               <label class="form-label" for="azienda_telefono">Telefono</label>
49
               <label class="form-label" for="azienda_telefono">Telefono</label>
41
               <input type="text" class="form-control" name="telefono" id="azienda_telefono" maxlength="255">
50
               <input type="text" class="form-control" name="telefono" id="azienda_telefono" maxlength="255">

+ 8
- 0
resources/views/user/scheda.blade.php Просмотреть файл

202
               <label class="form-label">Codice fiscale</label>
202
               <label class="form-label">Codice fiscale</label>
203
               <input type="text" name="cod_fiscale" class="form-control" value="{{ old('cod_fiscale', $user->cod_fiscale) }}">
203
               <input type="text" name="cod_fiscale" class="form-control" value="{{ old('cod_fiscale', $user->cod_fiscale) }}">
204
             </div>
204
             </div>
205
+            <div class="col-md-4">
206
+              <label class="form-label">Codice SDI</label>
207
+              <input type="text" name="codice_sdi" class="form-control text-uppercase" maxlength="7" value="{{ old('codice_sdi', $user->codice_sdi) }}" placeholder="7 caratteri">
208
+            </div>
209
+            <div class="col-md-4">
210
+              <label class="form-label">PEC</label>
211
+              <input type="email" name="pec" class="form-control" maxlength="255" value="{{ old('pec', $user->pec) }}">
212
+            </div>
205
             <div class="col-md-4">
213
             <div class="col-md-4">
206
               <label class="form-label">Indirizzo</label>
214
               <label class="form-label">Indirizzo</label>
207
               <input type="text" name="indirizzo" class="form-control" value="{{ old('indirizzo', $user->indirizzo) }}">
215
               <input type="text" name="indirizzo" class="form-control" value="{{ old('indirizzo', $user->indirizzo) }}">

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