Roberto Santini 10 godzin temu
rodzic
commit
50ce097aaa

+ 0
- 22
app/Http/Controllers/AziendaFicController.php Wyświetl plik

@@ -87,8 +87,6 @@ class AziendaFicController extends Controller implements HasMiddleware
87 87
             'fic_client_id' => 'required|integer|min:1',
88 88
         ]);
89 89
 
90
-        $this->assertClientFree((int) $validated['fic_client_id'], $azienda->id);
91
-
92 90
         try {
93 91
             $client = $fic->getClient((int) $validated['fic_client_id']);
94 92
         } catch (RuntimeException $e) {
@@ -151,7 +149,6 @@ class AziendaFicController extends Controller implements HasMiddleware
151 149
      */
152 150
     private function allinea(Azienda $azienda, FattureInCloudClient $fic, int $ficClientId, array $scelte): array
153 151
     {
154
-        $this->assertClientFree($ficClientId, $azienda->id);
155 152
         $client = $fic->getClient($ficClientId);
156 153
         $rows = $fic->confronto($azienda, $client);
157 154
         $remote = $fic->remoteValues($client);
@@ -222,31 +219,12 @@ class AziendaFicController extends Controller implements HasMiddleware
222 219
 
223 220
     private function collega(Azienda $azienda, int $ficClientId): void
224 221
     {
225
-        $this->assertClientFree($ficClientId, $azienda->id);
226 222
         FicCollegamento::query()->updateOrCreate(
227 223
             ['user_id' => $azienda->id],
228 224
             ['fic_client_id' => $ficClientId]
229 225
         );
230 226
     }
231 227
 
232
-    private function assertClientFree(int $ficClientId, int $userId): void
233
-    {
234
-        $taken = FicCollegamento::query()
235
-            ->where('fic_client_id', $ficClientId)
236
-            ->where('user_id', '!=', $userId)
237
-            ->first();
238
-        if (! $taken) {
239
-            return;
240
-        }
241
-
242
-        $other = Azienda::query()->find($taken->user_id);
243
-        $label = $other?->full_name ?: ('#'.$taken->user_id);
244
-
245
-        throw ValidationException::withMessages([
246
-            'fic_client_id' => 'Questo cliente Fatture in Cloud è già collegato a '.$label.'.',
247
-        ]);
248
-    }
249
-
250 228
     private function azienda($id): Azienda
251 229
     {
252 230
         return Azienda::query()

+ 22
- 0
database/migrations/2026_11_03_132400_drop_unique_fic_client_id_on_fic_collegamento.php Wyświetl plik

@@ -0,0 +1,22 @@
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('fic_collegamento', function (Blueprint $table) {
12
+            $table->dropUnique(['fic_client_id']);
13
+        });
14
+    }
15
+
16
+    public function down(): void
17
+    {
18
+        Schema::table('fic_collegamento', function (Blueprint $table) {
19
+            $table->unique('fic_client_id');
20
+        });
21
+    }
22
+};

Ładowanie…
Anuluj
Zapisz