|
|
@@ -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()
|