|
|
@@ -25,7 +25,14 @@ class FatturaFicService
|
|
25
|
25
|
throw new RuntimeException('Una fattura annullata non si invia.');
|
|
26
|
26
|
}
|
|
27
|
27
|
if ($fattura->ficDocumentId()) {
|
|
28
|
|
- throw new RuntimeException('Questa fattura è già su Fatture in Cloud.');
|
|
|
28
|
+ if (data_get($fattura->meta, 'fic.attachment')) {
|
|
|
29
|
+ throw new RuntimeException('Questa fattura è già su Fatture in Cloud.');
|
|
|
30
|
+ }
|
|
|
31
|
+ if (! $this->allegaDettaglio($fattura, (int) $fattura->ficDocumentId())) {
|
|
|
32
|
+ throw new RuntimeException('Questa fattura è già su Fatture in Cloud.');
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ return 'Dettaglio ticket allegato alla fattura su Fatture in Cloud.';
|
|
29
|
36
|
}
|
|
30
|
37
|
if ($fattura->righe->isEmpty()) {
|
|
31
|
38
|
throw new RuntimeException('La fattura non ha righe.');
|
|
|
@@ -76,24 +83,41 @@ class FatturaFicService
|
|
76
|
83
|
$fattura->save();
|
|
77
|
84
|
|
|
78
|
85
|
$allegato = '';
|
|
79
|
|
- $path = $this->report->store($fattura);
|
|
80
|
|
- if ($path !== null) {
|
|
81
|
|
- try {
|
|
82
|
|
- $nome = str_replace(['/', '\\'], '-', $this->report->filename($fattura));
|
|
83
|
|
- $this->fic->uploadIssuedDocumentAttachment(
|
|
84
|
|
- (int) $document['id'],
|
|
85
|
|
- $nome,
|
|
86
|
|
- (string) \Illuminate\Support\Facades\Storage::disk('local')->get($path)
|
|
87
|
|
- );
|
|
|
86
|
+ try {
|
|
|
87
|
+ if ($this->allegaDettaglio($fattura, (int) $document['id'])) {
|
|
88
|
88
|
$allegato = ' Il dettaglio ticket è allegato.';
|
|
89
|
|
- } catch (RuntimeException $e) {
|
|
90
|
|
- $allegato = ' Il dettaglio ticket non è stato allegato: '.$this->conScope($e->getMessage());
|
|
91
|
89
|
}
|
|
|
90
|
+ } catch (RuntimeException $e) {
|
|
|
91
|
+ $allegato = ' Il dettaglio ticket non è stato allegato: '.$this->conScope($e->getMessage());
|
|
92
|
92
|
}
|
|
93
|
93
|
|
|
94
|
94
|
return 'Fattura '.$fattura->numero_documento.' allineata a Fatture in Cloud.'.$allegato.' L\'invio allo SDI lo fai da lì.';
|
|
95
|
95
|
}
|
|
96
|
96
|
|
|
|
97
|
+ protected function allegaDettaglio(Fattura $fattura, int $documentId): bool
|
|
|
98
|
+ {
|
|
|
99
|
+ $path = $this->report->store($fattura);
|
|
|
100
|
+ if ($path === null) {
|
|
|
101
|
+ return false;
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ $nome = str_replace(['/', '\\'], '-', $this->report->filename($fattura));
|
|
|
105
|
+ $this->fic->uploadIssuedDocumentAttachment(
|
|
|
106
|
+ $documentId,
|
|
|
107
|
+ $nome,
|
|
|
108
|
+ (string) \Illuminate\Support\Facades\Storage::disk('local')->get($path)
|
|
|
109
|
+ );
|
|
|
110
|
+
|
|
|
111
|
+ $meta = is_array($fattura->meta) ? $fattura->meta : [];
|
|
|
112
|
+ $fic = is_array($meta['fic'] ?? null) ? $meta['fic'] : [];
|
|
|
113
|
+ $fic['attachment'] = true;
|
|
|
114
|
+ $meta['fic'] = $fic;
|
|
|
115
|
+ $fattura->meta = $meta;
|
|
|
116
|
+ $fattura->save();
|
|
|
117
|
+
|
|
|
118
|
+ return true;
|
|
|
119
|
+ }
|
|
|
120
|
+
|
|
97
|
121
|
protected function collegamento(Fattura $fattura): ?FicCollegamento
|
|
98
|
122
|
{
|
|
99
|
123
|
$ids = array_values(array_filter([
|