|
|
@@ -651,7 +651,7 @@ class FatturazioneGeneraService
|
|
651
|
651
|
}
|
|
652
|
652
|
|
|
653
|
653
|
foreach ($contratto->righe as $riga) {
|
|
654
|
|
- $periodoKey = $riga->periodoCiclo($contratto->periodo);
|
|
|
654
|
+ $periodoKey = $riga->periodoFatturazione($contratto->periodo);
|
|
655
|
655
|
foreach ($this->dateOccorrenzeRigaNelPeriodo($contratto, $riga, $from, $to) as $occurrence) {
|
|
656
|
656
|
[$pDa, $pA] = $this->finestraCiclo($periodoKey, $occurrence, $this->decorrenzaRiga($contratto, $riga));
|
|
657
|
657
|
if ($this->cicloPrecedenteAllaSoglia($occurrence, $pDa, $rinnoviDa)) {
|
|
|
@@ -660,11 +660,16 @@ class FatturazioneGeneraService
|
|
660
|
660
|
if ($this->canoneGiaFatturato($contratto->id, $riga->id, $pDa, $pA)) {
|
|
661
|
661
|
continue;
|
|
662
|
662
|
}
|
|
663
|
|
- $importo = $riga->importo_ciclo;
|
|
|
663
|
+ $importo = $riga->importoFatturazione($contratto->periodo);
|
|
664
|
664
|
if ($importo <= 0) {
|
|
665
|
665
|
continue;
|
|
666
|
666
|
}
|
|
667
|
|
- $this->aggiungiCanoneCliente($clienti[$key], $contratto, $riga, $importo, $pDa, $pA);
|
|
|
667
|
+ $quantita = $riga->isUnitaOra() ? $riga->quantitaFatturata($contratto->periodo) : 1.0;
|
|
|
668
|
+ $prezzo = $riga->isUnitaOra() ? (float) $riga->prezzo_netto : $importo;
|
|
|
669
|
+ $label = ($riga->isUnitaOra() && $quantita > (float) ($riga->quantita ?? 1))
|
|
|
670
|
+ ? $riga->labelQuantita($quantita)
|
|
|
671
|
+ : null;
|
|
|
672
|
+ $this->aggiungiCanoneCliente($clienti[$key], $contratto, $riga, $importo, $pDa, $pA, $quantita, $prezzo, $label);
|
|
668
|
673
|
}
|
|
669
|
674
|
}
|
|
670
|
675
|
|
|
|
@@ -740,7 +745,7 @@ class FatturazioneGeneraService
|
|
740
|
745
|
return [];
|
|
741
|
746
|
}
|
|
742
|
747
|
|
|
743
|
|
- $periodo = $riga->periodoCiclo($contratto->periodo);
|
|
|
748
|
+ $periodo = $riga->periodoFatturazione($contratto->periodo);
|
|
744
|
749
|
if ($periodo === 'a_consumo') {
|
|
745
|
750
|
return [];
|
|
746
|
751
|
}
|
|
|
@@ -1129,11 +1134,19 @@ class FatturazioneGeneraService
|
|
1129
|
1134
|
?ContrattoServizioRiga $riga,
|
|
1130
|
1135
|
float $importo,
|
|
1131
|
1136
|
Carbon $pDa,
|
|
1132
|
|
- Carbon $pA
|
|
|
1137
|
+ Carbon $pA,
|
|
|
1138
|
+ float $quantita = 1,
|
|
|
1139
|
+ ?float $prezzoUnitario = null,
|
|
|
1140
|
+ ?string $labelRiga = null
|
|
1133
|
1141
|
): void {
|
|
1134
|
1142
|
$importo = round($importo, 2);
|
|
1135
|
|
- $labelRiga = $riga ? $riga->label : 'Canone contratto';
|
|
1136
|
|
- $periodoLabel = $riga ? $riga->periodo_label : $contratto->periodo_label;
|
|
|
1143
|
+ $quantita = $quantita > 0 ? $quantita : 1;
|
|
|
1144
|
+ $prezzoUnitario = round($prezzoUnitario ?? $importo, 2);
|
|
|
1145
|
+ $labelRiga = $labelRiga ?: ($riga ? $riga->label : 'Canone contratto');
|
|
|
1146
|
+ $periodoFattura = $riga?->periodoFatturazione($contratto->periodo);
|
|
|
1147
|
+ $periodoLabel = $riga && $periodoFattura && $periodoFattura !== (string) $riga->periodo
|
|
|
1148
|
+ ? (\App\Models\Prodotto::PERIODI[$periodoFattura] ?? $contratto->periodo_label)
|
|
|
1149
|
+ : ($riga ? $riga->periodo_label : $contratto->periodo_label);
|
|
1137
|
1150
|
$descrizione = $contratto->label.' — '.$labelRiga.' ('.$pDa->format('d/m/Y').' – '.$pA->format('d/m/Y').')';
|
|
1138
|
1151
|
$cliente['rinnovi'][] = [
|
|
1139
|
1152
|
'tipo' => 'canone',
|
|
|
@@ -1152,9 +1165,9 @@ class FatturazioneGeneraService
|
|
1152
|
1165
|
$cliente['voci'][] = [
|
|
1153
|
1166
|
'tipo' => FatturaRiga::TIPO_CANONE,
|
|
1154
|
1167
|
'descrizione' => $descrizione,
|
|
1155
|
|
- 'quantita' => 1,
|
|
|
1168
|
+ 'quantita' => $quantita,
|
|
1156
|
1169
|
'unita_misura' => $riga?->unita_misura ?: 'forfait',
|
|
1157
|
|
- 'prezzo_unitario' => $importo,
|
|
|
1170
|
+ 'prezzo_unitario' => $prezzoUnitario,
|
|
1158
|
1171
|
'importo' => $importo,
|
|
1159
|
1172
|
'minuti' => null,
|
|
1160
|
1173
|
'annotazione_id' => null,
|