Roberto Santini 23 часов назад
Родитель
Сommit
50ce097aaa

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

87
             'fic_client_id' => 'required|integer|min:1',
87
             'fic_client_id' => 'required|integer|min:1',
88
         ]);
88
         ]);
89
 
89
 
90
-        $this->assertClientFree((int) $validated['fic_client_id'], $azienda->id);
91
-
92
         try {
90
         try {
93
             $client = $fic->getClient((int) $validated['fic_client_id']);
91
             $client = $fic->getClient((int) $validated['fic_client_id']);
94
         } catch (RuntimeException $e) {
92
         } catch (RuntimeException $e) {
151
      */
149
      */
152
     private function allinea(Azienda $azienda, FattureInCloudClient $fic, int $ficClientId, array $scelte): array
150
     private function allinea(Azienda $azienda, FattureInCloudClient $fic, int $ficClientId, array $scelte): array
153
     {
151
     {
154
-        $this->assertClientFree($ficClientId, $azienda->id);
155
         $client = $fic->getClient($ficClientId);
152
         $client = $fic->getClient($ficClientId);
156
         $rows = $fic->confronto($azienda, $client);
153
         $rows = $fic->confronto($azienda, $client);
157
         $remote = $fic->remoteValues($client);
154
         $remote = $fic->remoteValues($client);
222
 
219
 
223
     private function collega(Azienda $azienda, int $ficClientId): void
220
     private function collega(Azienda $azienda, int $ficClientId): void
224
     {
221
     {
225
-        $this->assertClientFree($ficClientId, $azienda->id);
226
         FicCollegamento::query()->updateOrCreate(
222
         FicCollegamento::query()->updateOrCreate(
227
             ['user_id' => $azienda->id],
223
             ['user_id' => $azienda->id],
228
             ['fic_client_id' => $ficClientId]
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
     private function azienda($id): Azienda
228
     private function azienda($id): Azienda
251
     {
229
     {
252
         return Azienda::query()
230
         return Azienda::query()

+ 22
- 0
database/migrations/2026_11_03_132400_drop_unique_fic_client_id_on_fic_collegamento.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('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
+};

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