Skip to content

Commit 216e076

Browse files
committed
feat: aggiunta controllo di importFE attiva solo se ZIP
1 parent 56dac3e commit 216e076

2 files changed

Lines changed: 83 additions & 63 deletions

File tree

plugins/importFE_ZIP/actions.php

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@
9494

9595
$files_xml = scandir($directory);
9696
} else {
97-
$files_xml[] = $file ?: $files;
97+
// Messaggio di errore per file non ZIP
98+
echo json_encode([
99+
'error' => tr('È possibile caricare solo file ZIP. Il file selezionato non è un file ZIP valido.'),
100+
]);
101+
exit;
98102
}
99103

100104
$i = 1;
@@ -185,22 +189,11 @@
185189

186190
exit;
187191
} else {
188-
$files_xml[] = $file ?: $files;
189-
190-
$i = 1;
191-
foreach ($files_xml as $xml) {
192-
if ($xml != '.' && $xml != '..' && is_file($directory.'/'.$xml)) {
193-
if (FatturaElettronica::isValid($xml, 'Fatture di vendita', 'Importazione FE')) {
194-
if (string_ends_with($xml, '.p7m')) {
195-
$file = XML::decodeP7M($directory.'/'.$xml);
196-
} else {
197-
$file = XML::readFile($directory.'/'.$xml);
198-
}
199-
200-
$file = FatturaElettronica::store($xml, $content);
201-
}
202-
}
203-
}
192+
// Messaggio di errore per file non ZIP
193+
echo json_encode([
194+
'error' => tr('È possibile caricare solo file ZIP. Il file selezionato non è un file ZIP valido.'),
195+
]);
196+
exit;
204197
}
205198
}
206199

@@ -554,14 +547,14 @@
554547

555548
// Se nella fattura elettronica è indicato un DDT cerco quel documento specifico
556549
$ddt = $dati_ddt[$numero_linea];
557-
$query = "SELECT
558-
`dt_righe_ddt`.`id`,
559-
`dt_righe_ddt`.`idddt` AS id_documento,
560-
`dt_righe_ddt`.`is_descrizione`,
561-
`dt_righe_ddt`.`idarticolo`,
550+
$query = "SELECT
551+
`dt_righe_ddt`.`id`,
552+
`dt_righe_ddt`.`idddt` AS id_documento,
553+
`dt_righe_ddt`.`is_descrizione`,
554+
`dt_righe_ddt`.`idarticolo`,
562555
`dt_righe_ddt`.`is_sconto`, 'ddt' AS ref,
563556
CONCAT('DDT num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', `dt_statiddt_lang`.`title`, ']') AS opzione
564-
FROM
557+
FROM
565558
`dt_righe_ddt`
566559
INNER JOIN `dt_ddt` ON `dt_ddt`.`id` = `dt_righe_ddt`.`idddt`
567560
INNER JOIN `dt_statiddt` ON `dt_statiddt`.`id` = `dt_ddt`.`idstatoddt`
@@ -595,12 +588,12 @@
595588
// cerco per quell'ordine
596589
if (empty($collegamento)) {
597590
$ordine = $dati_ordini[$numero_linea];
598-
$query = "SELECT
599-
`or_righe_ordini`.`id`,
600-
`or_righe_ordini`.`idordine` AS id_documento,
601-
`or_righe_ordini`.`is_descrizione`,
602-
`or_righe_ordini`.`idarticolo`,
603-
`or_righe_ordini`.`is_sconto`,
591+
$query = "SELECT
592+
`or_righe_ordini`.`id`,
593+
`or_righe_ordini`.`idordine` AS id_documento,
594+
`or_righe_ordini`.`is_descrizione`,
595+
`or_righe_ordini`.`idarticolo`,
596+
`or_righe_ordini`.`is_sconto`,
604597
'ordine' AS ref,
605598
CONCAT('Ordine num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', `or_statiordine_lang`.`title` , ']') AS opzione
606599
FROM `or_righe_ordini`
@@ -640,45 +633,45 @@
640633
// Se non ci sono Ordini o DDT cerco per contenuto
641634
if (empty($collegamento)) {
642635
$match_documento_da_fe = false;
643-
$query = "SELECT
644-
`dt_righe_ddt`.`id`,
645-
`dt_righe_ddt`.`idddt` AS id_documento,
646-
`dt_righe_ddt`.`is_descrizione`,
647-
`dt_righe_ddt`.`idarticolo`,
648-
`dt_righe_ddt`.`is_sconto`,
636+
$query = "SELECT
637+
`dt_righe_ddt`.`id`,
638+
`dt_righe_ddt`.`idddt` AS id_documento,
639+
`dt_righe_ddt`.`is_descrizione`,
640+
`dt_righe_ddt`.`idarticolo`,
641+
`dt_righe_ddt`.`is_sconto`,
649642
'ddt' AS ref,
650643
CONCAT('DDT num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', `dt_statiddt_lang`.`title`, ']') AS opzione
651-
FROM
644+
FROM
652645
`dt_righe_ddt`
653646
INNER JOIN `dt_ddt` ON `dt_ddt`.`id` = `dt_righe_ddt`.`idddt`
654647
INNER JOIN `dt_statiddt` ON `dt_statiddt`.`id` = `dt_ddt`.`idstatoddt`
655648
LEFT JOIN `dt_statiddt_lang` ON (`dt_statiddt_lang`.`id_record` = `dt_statiddt`.`id` AND `dt_statiddt_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
656649
INNER JOIN `dt_tipiddt` ON `dt_ddt`.`idtipoddt` = `dt_tipiddt`.`id`
657-
WHERE
658-
`dt_ddt`.`idanagrafica` = '.prepare($anagrafica->id)." AND
659-
|where_ddt| AND
660-
`dt_righe_ddt`.`qta` > `dt_righe_ddt`.`qta_evasa` AND
650+
WHERE
651+
`dt_ddt`.`idanagrafica` = '.prepare($anagrafica->id)." AND
652+
|where_ddt| AND
653+
`dt_righe_ddt`.`qta` > `dt_righe_ddt`.`qta_evasa` AND
661654
`dt_statiddt_lang`.`title` != 'Fatturato' AND
662655
`dt_tipiddt`.`dir` = 'entrata'
663-
UNION
664-
SELECT
656+
UNION
657+
SELECT
665658
`or_righe_ordini`.`id`,
666659
`or_righe_ordini`.`idordine` AS id_documento,
667-
`or_righe_ordini`.`is_descrizione`,
668-
`or_righe_ordini`.`idarticolo`,
669-
`or_righe_ordini`.`is_sconto`,
660+
`or_righe_ordini`.`is_descrizione`,
661+
`or_righe_ordini`.`idarticolo`,
662+
`or_righe_ordini`.`is_sconto`,
670663
'ordine' AS ref,
671664
CONCAT('Ordine num. ', IF(`numero_esterno` != '', `numero_esterno`, `numero`), ' del ', DATE_FORMAT(`data`, '%d/%m/%Y'), ' [', (SELECT `descrizione` FROM `or_statiordine` WHERE `id` = `idstatoordine`) , ']') AS opzione
672-
FROM
665+
FROM
673666
`or_righe_ordini`
674667
INNER JOIN `or_ordini` ON `or_ordini`.`id` = `or_righe_ordini`.`idordine`
675668
INNER JOIN `or_statiordine` ON `or_statiordine`.`id` = `or_ordini`.`idstatoordine`
676669
LEFT JOIN `or_statiordine_lang` ON (`or_statiordine_lang`.`id_record` = `or_statiordine`.`id` AND `or_statiordine_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
677670
INNER JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine` = `or_tipiordine`.`id`
678-
WHERE
679-
`or_ordini`.`idanagrafica` = '.prepare($anagrafica->id)." AND
680-
|where_ordini| AND
681-
`or_righe_ordini`.`qta` > `or_righe_ordini`.`qta_evasa` AND
671+
WHERE
672+
`or_ordini`.`idanagrafica` = '.prepare($anagrafica->id)." AND
673+
|where_ordini| AND
674+
`or_righe_ordini`.`qta` > `or_righe_ordini`.`qta_evasa` AND
682675
`or_statiordine_lang`.`title` != 'Fatturato' AND
683676
`or_tipiordine`.`dir` ='entrata'";
684677

plugins/importFE_ZIP/edit.php

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,20 @@ function upload1(btn) {
3030
type: "post",
3131
success: function(data){
3232
$("#main_loading").fadeOut();
33-
swal("Caricamento completato!", "", "success");
3433
34+
try {
35+
var response = JSON.parse(data);
36+
if (response.error) {
37+
swal("'.tr('Errore').'", response.error, "error");
38+
$("#blob1").val("");
39+
buttonRestore(btn, restore);
40+
return;
41+
}
42+
} catch (e) {
43+
// Se non è JSON valido, continua normalmente
44+
}
45+
46+
swal("Caricamento completato!", "", "success");
3547
$("#blob1").val("");
3648
buttonRestore(btn, restore);
3749
},
@@ -82,16 +94,31 @@ function upload1(btn) {
8294
type: "post",
8395
success: function(data){
8496
$("#main_loading").fadeOut();
85-
data = JSON.parse(data);
86-
87-
if (!data.already) {
88-
redirect(globals.rootdir + "/editor.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&id_record=" + data.id);
89-
} else {
90-
swal({
91-
title: "'.tr('Fattura già importata').'.",
92-
type: "info",
93-
});
9497
98+
try {
99+
data = JSON.parse(data);
100+
101+
// Controlla se c\'è un messaggio di errore nella risposta
102+
if (data.error) {
103+
swal("'.tr('Errore').'", data.error, "error");
104+
$("#blob1").val("");
105+
buttonRestore(btn, restore);
106+
return;
107+
}
108+
109+
if (!data.already) {
110+
redirect(globals.rootdir + "/editor.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&id_record=" + data.id);
111+
} else {
112+
swal({
113+
title: "'.tr('Fattura già importata').'.",
114+
type: "info",
115+
});
116+
117+
$("#blob1").val("");
118+
}
119+
} catch (e) {
120+
// Se non è JSON valido, mostra un errore generico
121+
swal("'.tr('Errore').'", "'.tr('Si è verificato un errore durante l\'elaborazione della risposta').'", "error");
95122
$("#blob1").val("");
96123
}
97124
@@ -177,9 +204,9 @@ function upload1(btn) {
177204
if (Interaction::isEnabled()) {
178205
echo '
179206
<div class="alert alert-info">
180-
<i class="fa fa-info-circle mr-2"></i>'.tr('Per vedere le fatture da importare utilizza il pulsante _BUTTON_', [
181-
'_BUTTON_' => '<b>"'.tr('Ricerca fatture').'"</b>',
182-
]).'
207+
<i class="fa fa-info-circle mr-2"></i>'.tr('Per vedere le fatture da importare utilizza il pulsante <b>_BUTTON_</b>', [
208+
'_BUTTON_' => tr('Ricerca fatture'),
209+
]).'
183210
</div>';
184211
} else {
185212
include $structure->filepath('list.php');

0 commit comments

Comments
 (0)