Browse Source

fatture in cloud

Roberto Santini 3 weeks ago
parent
commit
201e0751fc

+ 1
- 0
app/Services/FatturaReportTicketPdfService.php View File

@@ -91,6 +91,7 @@ class FatturaReportTicketPdfService
91 91
         $pdf->setPaper('a4', 'portrait');
92 92
         $pdf->setOption('defaultFont', 'DejaVu Sans');
93 93
         $pdf->setOption('isHtml5ParserEnabled', true);
94
+        $pdf->setOption('isPhpEnabled', true);
94 95
 
95 96
         return $pdf->output();
96 97
     }

+ 41
- 5
app/Services/FatturazioneGeneraService.php View File

@@ -5,6 +5,7 @@ namespace App\Services;
5 5
 use App\Models\AcquistoServizio;
6 6
 use App\Models\Annotazione;
7 7
 use App\Models\Config;
8
+use App\Models\ConfiguraSegnalazione;
8 9
 use App\Models\ContrattoServizio;
9 10
 use App\Models\ContrattoServizioRiga;
10 11
 use App\Models\Fattura;
@@ -578,6 +579,7 @@ class FatturazioneGeneraService
578 579
                 'minuti' => $allocazione['minuti_fatturare'],
579 580
                 'annotazione_id' => $annotazione->id,
580 581
                 'segnalazione_id' => $segnalazione->id,
582
+                'tipo_segnalazione' => $this->labelTipoSegnalazione($segnalazione),
581 583
                 'contratto_servizio_id' => $segnalazione->contratto_servizio_id,
582 584
                 'contratto_servizio_riga_id' => null,
583 585
                 'ordine_lavoro_id' => $segnalazione->ordine_lavoro_id,
@@ -599,6 +601,7 @@ class FatturazioneGeneraService
599 601
                 'minuti' => null,
600 602
                 'annotazione_id' => $annotazione->id,
601 603
                 'segnalazione_id' => $segnalazione->id,
604
+                'tipo_segnalazione' => $this->labelTipoSegnalazione($segnalazione),
602 605
                 'contratto_servizio_id' => $segnalazione->contratto_servizio_id,
603 606
                 'contratto_servizio_riga_id' => null,
604 607
                 'ordine_lavoro_id' => $segnalazione->ordine_lavoro_id,
@@ -619,6 +622,7 @@ class FatturazioneGeneraService
619 622
                 'minuti' => null,
620 623
                 'annotazione_id' => $annotazione->id,
621 624
                 'segnalazione_id' => $segnalazione->id,
625
+                'tipo_segnalazione' => $this->labelTipoSegnalazione($segnalazione),
622 626
                 'contratto_servizio_id' => $segnalazione->contratto_servizio_id,
623 627
                 'contratto_servizio_riga_id' => null,
624 628
                 'ordine_lavoro_id' => $segnalazione->ordine_lavoro_id,
@@ -1133,8 +1137,25 @@ class FatturazioneGeneraService
1133 1137
         return $daRighe->merge($daMeta)->unique()->values()->all();
1134 1138
     }
1135 1139
 
1140
+    protected function labelTipoSegnalazione($segnalazione): string
1141
+    {
1142
+        static $labels = null;
1143
+        if ($labels === null) {
1144
+            $labels = ConfiguraSegnalazione::query()
1145
+                ->where('gruppo', 'Tipo')
1146
+                ->pluck('label', 'value');
1147
+        }
1148
+        $value = trim((string) ($segnalazione->tipo ?? ''));
1149
+        if ($value === '') {
1150
+            return 'Ticket';
1151
+        }
1152
+        $label = trim((string) ($labels[$value] ?? $value));
1153
+
1154
+        return $label !== '' ? $label : 'Ticket';
1155
+    }
1156
+
1136 1157
     /**
1137
-     * Una riga fattura per tipo (ore, extra, spese, uscite) al posto di una riga per ticket.
1158
+     * Una riga per tipo di ticket (es. Assistenza remota), con le ore sommate.
1138 1159
      *
1139 1160
      * @param  array<int, array<string, mixed>>  $voci
1140 1161
      * @return array<int, array<string, mixed>>
@@ -1156,10 +1177,18 @@ class FatturazioneGeneraService
1156 1177
                 $resto[] = $voce;
1157 1178
                 continue;
1158 1179
             }
1159
-            $gruppi[$tipo][] = $voce;
1180
+            $tipoSegnalazione = trim((string) ($voce['tipo_segnalazione'] ?? ''));
1181
+            if ($tipoSegnalazione === '') {
1182
+                $tipoSegnalazione = 'Ticket';
1183
+            }
1184
+            $ore = in_array($tipo, [FatturaRiga::TIPO_TEMPO, FatturaRiga::TIPO_EXTRA_CONTRATTO, FatturaRiga::TIPO_EXTRA_ORDINE], true);
1185
+            $chiave = ($ore ? 'ore' : $tipo).'|'.$tipoSegnalazione;
1186
+            $gruppi[$chiave][] = $voce;
1160 1187
         }
1161 1188
 
1162
-        foreach ($gruppi as $tipo => $items) {
1189
+        foreach ($gruppi as $items) {
1190
+            $tipo = (string) ($items[0]['tipo'] ?? FatturaRiga::TIPO_TEMPO);
1191
+            $tipoSegnalazione = trim((string) ($items[0]['tipo_segnalazione'] ?? 'Ticket'));
1163 1192
             $importo = round(collect($items)->sum(fn ($v) => (float) ($v['importo'] ?? 0)), 2);
1164 1193
             $minuti = (int) collect($items)->sum(fn ($v) => (int) ($v['minuti'] ?? 0));
1165 1194
             $ore = in_array($tipo, [FatturaRiga::TIPO_TEMPO, FatturaRiga::TIPO_EXTRA_CONTRATTO, FatturaRiga::TIPO_EXTRA_ORDINE], true);
@@ -1167,9 +1196,16 @@ class FatturazioneGeneraService
1167 1196
             if ($qty <= 0) {
1168 1197
                 $qty = 1;
1169 1198
             }
1199
+            if ($ore) {
1200
+                $descrizione = $tipoSegnalazione;
1201
+            } elseif ($tipo === FatturaRiga::TIPO_SPESA) {
1202
+                $descrizione = 'Spesa — '.$tipoSegnalazione;
1203
+            } else {
1204
+                $descrizione = 'Costo d\'uscita — '.$tipoSegnalazione;
1205
+            }
1170 1206
             $resto[] = [
1171
-                'tipo' => $tipo,
1172
-                'descrizione' => FatturaRiga::TIPI[$tipo] ?? $tipo,
1207
+                'tipo' => $ore ? FatturaRiga::TIPO_TEMPO : $tipo,
1208
+                'descrizione' => $descrizione,
1173 1209
                 'quantita' => $qty,
1174 1210
                 'unita_misura' => $ore ? 'ora' : 'forfait',
1175 1211
                 'prezzo_unitario' => round($importo / $qty, 2),

+ 14
- 0
resources/views/fatturazione/report-ticket.blade.php View File

@@ -47,6 +47,20 @@
47 47
       </tr>
48 48
       @endforelse
49 49
     </tbody>
50
+    @if(count($righe))
51
+    @php
52
+      $oreTotali = round(collect($righe)->sum(fn ($r) => (float) ($r['ore'] ?? 0)), 2);
53
+    @endphp
54
+    <tfoot>
55
+      <tr>
56
+        <td colspan="2"><strong>Totale ore</strong></td>
57
+        <td class="text-end"><strong>{{ \App\Models\Config::formatTempo((int) round($oreTotali * 60)) }}</strong></td>
58
+        <td></td>
59
+      </tr>
60
+    </tfoot>
61
+    @endif
50 62
   </table>
63
+
64
+  @include('pdf.footer', ['documentoLabel' => 'Dettaglio ticket — Fattura '.$fattura->numero_documento])
51 65
 </body>
52 66
 </html>

+ 4
- 0
resources/views/pdf/styles.blade.php View File

@@ -106,6 +106,10 @@
106 106
     background: #f2f2f2;
107 107
     font-size: 9px;
108 108
   }
109
+  table.pdf-lines tfoot td {
110
+    background: #f2f2f2;
111
+    font-size: 10px;
112
+  }
109 113
 
110 114
   .pdf-notes {
111 115
     margin-top: 14px;

Loading…
Cancel
Save