Skip to content

Commit 76cedd1

Browse files
committed
feat: Valorizzazione dati_aggiuntivi_fe in importazione fatture acquisto
1 parent ce263fd commit 76cedd1

4 files changed

Lines changed: 131 additions & 19 deletions

File tree

modules/fatture/buttons.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@
2121
include_once __DIR__.'/../../core.php';
2222
use Models\Module;
2323

24-
if ($module->name == 'Fatture di vendita') {
25-
$attributi_visibili = $record['dati_aggiuntivi_fe'] != null || $record['stato'] == 'Bozza';
24+
// Pulsante "Attributi avanzati" per fatture di vendita e di acquisto
25+
if ($module->name == 'Fatture di vendita' || $module->name == 'Fatture di acquisto') {
26+
// Condizioni di visibilità
27+
if ($module->name == 'Fatture di vendita') {
28+
// Per fatture di vendita: visibile se ci sono dati aggiuntivi FE o se è in bozza
29+
$attributi_visibili = $record['dati_aggiuntivi_fe'] != null || $record['stato'] == 'Bozza';
30+
$readonly_param = '';
31+
} else {
32+
// Per fatture di acquisto: visibile solo se ci sono dati aggiuntivi FE importati
33+
$attributi_visibili = $record['dati_aggiuntivi_fe'] != null;
34+
$readonly_param = '&readonly=1';
35+
}
2636

2737
echo '
28-
<a class="btn btn-info '.($attributi_visibili ? '' : 'disabled').'" data-widget="modal" data-title="'.tr('Dati Fattura Elettronica').'" data-href="'.$structure->fileurl('fe/document-fe.php').'?id_module='.$id_module.'&id_record='.$id_record.'" '.($attributi_visibili ? '' : 'disabled').'>
38+
<a class="btn btn-info '.($attributi_visibili ? '' : 'disabled').'" data-widget="modal" data-title="'.tr('Dati Fattura Elettronica').'" data-href="'.$structure->fileurl('fe/document-fe.php').'?id_module='.$id_module.'&id_record='.$id_record.$readonly_param.'" '.($attributi_visibili ? '' : 'disabled').'>
2939
<i class="fa fa-file-code-o"></i> '.tr('Attributi avanzati').'
3040
</a>';
3141
}

modules/fatture/fe/components/dati_documento.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
'_NUM_' => $key,
2828
]);
2929

30-
if ($key == 1) {
30+
if ($key == 1 && !$is_readonly) {
3131
echo '
3232
<button type="button" class="btn btn-xs btn-info pull-right" onclick="add_blocco(this, \''.$nome.'\')">
3333
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
@@ -62,7 +62,7 @@
6262
echo '
6363
</td>
6464
<td>
65-
{[ "type": "number", "name": "'.$nome.'['.$key.'][riferimento_linea][]", "value": "'.$linea.'", "maxlength": 4, "decimals": 0, "extra": " title=\"\" " ]}
65+
{[ "type": "number", "name": "'.$nome.'['.$key.'][riferimento_linea][]", "value": "'.$linea.'", "maxlength": 4, "decimals": 0, "extra": " title=\"\" ", "readonly": '.($is_readonly ? '1' : '0').' ]}
6666
</td>
6767
</tr>';
6868

@@ -74,7 +74,7 @@
7474
<tr class="fifth-level">
7575
<td style="vertical-align: middle;">'.str_repeat((string) $space, 4).$info['code'].'.2 IdDocumento</td>
7676
<td>
77-
{[ "type": "text", "name": "'.$nome.'['.$key.'][id_documento]", "value": "'.$dato['id_documento'].'", "maxlength": 20 ]}
77+
{[ "type": "text", "name": "'.$nome.'['.$key.'][id_documento]", "value": "'.$dato['id_documento'].'", "maxlength": 20, "readonly": '.($is_readonly ? '1' : '0').' ]}
7878
</td>
7979
</tr>';
8080

@@ -83,7 +83,7 @@
8383
<tr class="fifth-level">
8484
<td style="vertical-align: middle;">'.str_repeat((string) $space, 4).$info['code'].'.3 Data</td>
8585
<td>
86-
{[ "type": "date", "name": "'.$nome.'['.$key.'][data]", "value": "'.$dato['data'].'", "readonly": '.(empty($dato['id_documento']) ? 1 : 0).' ]}
86+
{[ "type": "date", "name": "'.$nome.'['.$key.'][data]", "value": "'.$dato['data'].'", "readonly": '.($is_readonly || empty($dato['id_documento']) ? 1 : 0).' ]}
8787
</td>
8888
</tr>';
8989

@@ -92,7 +92,7 @@
9292
<tr class="fifth-level">
9393
<td style="vertical-align: middle;">'.str_repeat((string) $space, 4).$info['code'].'.4 NumItem</td>
9494
<td>
95-
{[ "type": "text", "name": "'.$nome.'['.$key.'][num_item]", "value": "'.$dato['num_item'].'", "maxlength": 20, "readonly": '.(empty($dato['id_documento']) ? 1 : 0).' ]}
95+
{[ "type": "text", "name": "'.$nome.'['.$key.'][num_item]", "value": "'.$dato['num_item'].'", "maxlength": 20, "readonly": '.($is_readonly || empty($dato['id_documento']) ? 1 : 0).' ]}
9696
</td>
9797
</tr>';
9898

@@ -101,7 +101,7 @@
101101
<tr class="fifth-level">
102102
<td style="vertical-align: middle;">'.str_repeat((string) $space, 4).$info['code'].'.5 CodiceCommessaConvenzione</td>
103103
<td>
104-
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_commessa]", "value": "'.$dato['codice_commessa'].'", "maxlength": 100, "readonly": '.(empty($dato['id_documento']) ? 1 : 0).' ]}
104+
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_commessa]", "value": "'.$dato['codice_commessa'].'", "maxlength": 100, "readonly": '.($is_readonly || empty($dato['id_documento']) ? 1 : 0).' ]}
105105
</td>
106106
</tr>';
107107

@@ -110,7 +110,7 @@
110110
<tr class="fifth-level">
111111
<td style="vertical-align: middle;">'.str_repeat((string) $space, 4).$info['code'].'.6 CodiceCUP</td>
112112
<td>
113-
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_cup]", "value": "'.$dato['codice_cup'].'", "maxlength": 15, "readonly": '.(empty($dato['id_documento']) ? 1 : 0).' ]}
113+
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_cup]", "value": "'.$dato['codice_cup'].'", "maxlength": 15, "readonly": '.($is_readonly || empty($dato['id_documento']) ? 1 : 0).' ]}
114114
</td>
115115
</tr>';
116116

@@ -119,7 +119,7 @@
119119
<tr class="fifth-level" id="last-'.$nome.'-'.$key.'">
120120
<td style="vertical-align: middle;">'.str_repeat((string) $space, 4).$info['code'].'.7 CodiceCIG</td>
121121
<td>
122-
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_cig]", "value": "'.$dato['codice_cig'].'", "maxlength": 15, "readonly": '.(empty($dato['id_documento']) ? 1 : 0).' ]}
122+
{[ "type": "text", "name": "'.$nome.'['.$key.'][codice_cig]", "value": "'.$dato['codice_cig'].'", "maxlength": 15, "readonly": '.($is_readonly || empty($dato['id_documento']) ? 1 : 0).' ]}
123123
</td>
124124
</tr>
125125
</tbody>';

modules/fatture/fe/document-fe.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
$documento = Fattura::find($id_record);
2828

29+
// Verifica se si tratta di una fattura di acquisto (modalità readonly)
30+
$is_readonly = filter('readonly') == '1';
31+
$readonly_attr = $is_readonly ? 'readonly' : '';
32+
2933
$result = $documento->toArray();
3034
$result = array_merge($result, $documento->dati_aggiuntivi_fe);
3135

@@ -44,10 +48,22 @@
4448
<tbody>
4549
<tr class="first-level">
4650
<th colspan="2">
47-
2 FatturaElettronicaBody
51+
2 FatturaElettronicaBody';
52+
53+
// Mostra il pulsante "Salva" solo se non è in modalità readonly
54+
if (!$is_readonly) {
55+
echo '
4856
<button type="submit" class="btn btn-primary pull-right">
4957
<i class="fa fa-edit"></i> '.tr('Salva').'
50-
</button>
58+
</button>';
59+
} else {
60+
echo '
61+
<span class="label label-info pull-right">
62+
<i class="fa fa-eye"></i> '.tr('Sola lettura').'
63+
</span>';
64+
}
65+
66+
echo '
5167
</th>
5268
</tr>
5369
<tr class="second-level">
@@ -69,7 +85,7 @@
6985
<tr class="fifth-level">
7086
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.1.1.8.1 Tipo</td>
7187
<td>
72-
{[ "type": "select", "name": "sconto_maggiorazione_tipo", "values": "list=\"SC\":\"Sconto\",\"MG\":\"Maggiorazione\"", "value": "'.$result['sconto_maggiorazione_tipo'].'" ]}
88+
{[ "type": "select", "name": "sconto_maggiorazione_tipo", "values": "list=\"SC\":\"Sconto\",\"MG\":\"Maggiorazione\"", "value": "'.$result['sconto_maggiorazione_tipo'].'", "readonly": '.($is_readonly ? '1' : '0').' ]}
7389
</td>
7490
</tr>
7591
';
@@ -79,7 +95,7 @@
7995
<tr class="fifth-level">
8096
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.1.1.8.2 Percentuale</td>
8197
<td>
82-
{[ "type": "number", "name": "sconto_maggiorazione_percentuale", "value": "'.$result['sconto_maggiorazione_percentuale'].'" ]}
98+
{[ "type": "number", "name": "sconto_maggiorazione_percentuale", "value": "'.$result['sconto_maggiorazione_percentuale'].'", "readonly": '.($is_readonly ? '1' : '0').' ]}
8399
</td>
84100
</tr>
85101
';
@@ -89,7 +105,7 @@
89105
<tr class="fifth-level">
90106
<td style="vertical-align: middle;">'.str_repeat($space, 4).'2.1.1.8.3 Importo</td>
91107
<td>
92-
{[ "type": "number", "name": "sconto_maggiorazione_importo", "value": "'.$result['sconto_maggiorazione_importo'].'" ]}
108+
{[ "type": "number", "name": "sconto_maggiorazione_importo", "value": "'.$result['sconto_maggiorazione_importo'].'", "readonly": '.($is_readonly ? '1' : '0').' ]}
93109
</td>
94110
</tr>
95111
';
@@ -99,7 +115,7 @@
99115
<tr class="fourth-level">
100116
<td style="vertical-align: middle;">'.str_repeat($space, 3).'2.1.1.12 Art73</td>
101117
<td>
102-
{[ "type": "checkbox", "name": "art73", "value": "'.$result['art73'].'", "placeholder": "'.tr("Emesso ai sensi dell'articolo 73 del DPR 633/72").'" ]}
118+
{[ "type": "checkbox", "name": "art73", "value": "'.$result['art73'].'", "placeholder": "'.tr("Emesso ai sensi dell'articolo 73 del DPR 633/72").'", "readonly": '.($is_readonly ? '1' : '0').' ]}
103119
</td>
104120
</tr>
105121
</tbody>';
@@ -178,14 +194,16 @@
178194
]).'
179195
</td>
180196
<td>
181-
{[ "type": "number", "name": "'.$nome.'[-id-][riferimento_linea][]", "value": "", "maxlength": 4, "decimals": 0 ]}
197+
{[ "type": "number", "name": "'.$nome.'[-id-][riferimento_linea][]", "value": "", "maxlength": 4, "decimals": 0, "readonly": '.($is_readonly ? '1' : '0').' ]}
182198
</td>
183199
</tr>
184200
</tbody>
185201
</table>';
186202
}
187203

188-
echo '
204+
// Mostra i pulsanti solo se non è in modalità readonly
205+
if (!$is_readonly) {
206+
echo '
189207
<!-- PULSANTI -->
190208
<div class="row">
191209
<div class="col-md-12 text-right">
@@ -194,6 +212,7 @@
194212
</button>
195213
</div>
196214
</div>';
215+
}
197216

198217
echo '
199218
</form>';

plugins/importFE/src/FatturaElettronica.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ public function saveFattura($id_pagamento, $id_sezionale, $id_tipo, $data_regist
398398
$fattura->note = $note;
399399
}
400400

401+
// Valorizzazione dati aggiuntivi FE
402+
$dati_aggiuntivi_fe = $this->extractDatiAggiuntiviFE();
403+
if (!empty($dati_aggiuntivi_fe)) {
404+
$fattura->dati_aggiuntivi_fe = $dati_aggiuntivi_fe;
405+
}
406+
401407
// Sconto finale da ScontoMaggiorazione: non importato
402408
$fattura->save();
403409

@@ -452,6 +458,83 @@ protected function forceArray($result)
452458
return $result;
453459
}
454460

461+
/**
462+
* Estrae i dati aggiuntivi per la fattura elettronica dal file XML.
463+
*
464+
* @return array
465+
*/
466+
protected function extractDatiAggiuntiviFE()
467+
{
468+
$dati_aggiuntivi = [];
469+
470+
// Estrazione dati dall'header
471+
$header = $this->getHeader();
472+
$dati_trasmissione = $header['DatiTrasmissione'];
473+
474+
if (!empty($dati_trasmissione)) {
475+
$dati_aggiuntivi['dati_trasmissione'] = [];
476+
477+
if (!empty($dati_trasmissione['FormatoTrasmissione'])) {
478+
$dati_aggiuntivi['dati_trasmissione']['formato_trasmissione'] = $dati_trasmissione['FormatoTrasmissione'];
479+
}
480+
481+
if (!empty($dati_trasmissione['CodiceDestinatario'])) {
482+
$dati_aggiuntivi['dati_trasmissione']['codice_destinatario'] = $dati_trasmissione['CodiceDestinatario'];
483+
}
484+
485+
if (!empty($dati_trasmissione['ContattiTrasmittente'])) {
486+
$dati_aggiuntivi['dati_trasmissione']['contatti_trasmittente'] = $dati_trasmissione['ContattiTrasmittente'];
487+
}
488+
}
489+
490+
// Estrazione dati dal body
491+
$body = $this->getBody();
492+
$dati_generali = $body['DatiGenerali'];
493+
494+
// Verifica presenza Art73
495+
if (!empty($dati_generali['DatiGeneraliDocumento']['Art73'])) {
496+
$dati_aggiuntivi['art73'] = $dati_generali['DatiGeneraliDocumento']['Art73'];
497+
}
498+
499+
// Estrazione dati ordine acquisto
500+
if (!empty($dati_generali['DatiOrdineAcquisto'])) {
501+
$dati_ordini = $this->forceArray($dati_generali['DatiOrdineAcquisto']);
502+
$dati_aggiuntivi['dati_ordine_acquisto'] = $dati_ordini;
503+
}
504+
505+
// Estrazione dati contratto
506+
if (!empty($dati_generali['DatiContratto'])) {
507+
$dati_contratti = $this->forceArray($dati_generali['DatiContratto']);
508+
$dati_aggiuntivi['dati_contratto'] = $dati_contratti;
509+
}
510+
511+
// Estrazione dati convenzione
512+
if (!empty($dati_generali['DatiConvenzione'])) {
513+
$dati_convenzioni = $this->forceArray($dati_generali['DatiConvenzione']);
514+
$dati_aggiuntivi['dati_convenzione'] = $dati_convenzioni;
515+
}
516+
517+
// Estrazione dati ricezione
518+
if (!empty($dati_generali['DatiRicezione'])) {
519+
$dati_ricezioni = $this->forceArray($dati_generali['DatiRicezione']);
520+
$dati_aggiuntivi['dati_ricezione'] = $dati_ricezioni;
521+
}
522+
523+
// Estrazione dati fatture collegate
524+
if (!empty($dati_generali['DatiFattureCollegate'])) {
525+
$dati_fatture = $this->forceArray($dati_generali['DatiFattureCollegate']);
526+
$dati_aggiuntivi['dati_fatture'] = $dati_fatture;
527+
}
528+
529+
// Estrazione dati DDT
530+
if (!empty($dati_generali['DatiDDT'])) {
531+
$dati_ddt = $this->forceArray($dati_generali['DatiDDT']);
532+
$dati_aggiuntivi['dati_ddt'] = $dati_ddt;
533+
}
534+
535+
return array_filter($dati_aggiuntivi);
536+
}
537+
455538
/**
456539
* Verifica se almeno un riepilogo IVA ha EsigibilitaIVA = 'S' (split payment).
457540
*

0 commit comments

Comments
 (0)