Skip to content

Commit 6d69f9f

Browse files
committed
fix: Importazione fatture da zip
1 parent c4bcaed commit 6d69f9f

1 file changed

Lines changed: 70 additions & 53 deletions

File tree

plugins/importFE_ZIP/edit.php

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ function upload1(btn) {
214214
// Ricerca automatica
215215
if (Interaction::isEnabled()) {
216216
echo '
217-
<button type="button" class="btn btn-primary" onclick="searchInvoicesZip(this)">
218-
<i class="fa fa-refresh mr-1"></i> '.tr('Ricerca fatture').'
219-
</button>';
217+
<button type="button" class="btn btn-primary" onclick="searchInvoicesZip(this)">
218+
<i class="fa fa-refresh mr-1"></i> '.tr('Ricerca fatture').'
219+
</button>';
220220
}
221221

222222
echo '
223+
</div>
223224
</div>
224225
</div>
225-
<br>
226226
<div class="card-body" id="list-importfe-zip">';
227227

228228
if (Interaction::isEnabled()) {
@@ -260,48 +260,71 @@ function upload1(btn) {
260260
});
261261
});';
262262

263-
if (Interaction::isEnabled()) {
264-
echo '
263+
echo '
265264
function importAllZip(btn) {
266-
swal({
267-
title: "'.tr('Importare tutte le fatture?').'",
268-
html: "'.tr('Verranno scaricate tutte le fatture da importare, e non sarà più possibile visualizzare altre informazioni oltre al nome per le fatture che non verranno importate completamente. Continuare?').'",
269-
showCancelButton: true,
270-
confirmButtonText: "'.tr('Procedi').'",
271-
type: "info",
272-
}).then(function (result) {
273-
var restore = buttonLoading(btn);
274-
$("#main_loading").show();
275-
276-
$.ajax({
277-
url: globals.rootdir + "/actions.php",
278-
data: {
279-
op: "list",
280-
id_module: "'.$id_module.'",
281-
id_plugin: "'.$id_plugin.'",
282-
},
283-
type: "post",
284-
success: function(data){
285-
try {
286-
// Verifica se la risposta è vuota
287-
if (!data || data.trim() === "") {
288-
console.error("Risposta vuota dal server");
289-
swal("'.tr('Errore').'", "'.tr('Risposta vuota dal server').'", "error");
290-
buttonRestore(btn, restore);
291-
$("#main_loading").fadeOut();
292-
return;
293-
}
294-
295-
data = JSON.parse(data);
296-
} catch (e) {
297-
console.error("Errore parsing JSON:", e);
298-
console.error("Dati ricevuti:", data);
299-
swal("'.tr('Errore').'", "'.tr('Errore durante l\'elaborazione della risposta del server').'", "error");
265+
// Controlla se ci sono fatture caricate nella datatable
266+
var invoiceRows = $("table tbody tr:not(#no-results-message)").length;
267+
268+
if (invoiceRows === 0) {
269+
swal({
270+
title: "'.tr('Nessuna fattura da importare').'",
271+
type: "info",
272+
});
273+
return;
274+
}
275+
276+
var restore = buttonLoading(btn);
277+
$("#main_loading").show();
278+
279+
// Prima verifica se ci sono documenti da importare
280+
$.ajax({
281+
url: globals.rootdir + "/actions.php",
282+
data: {
283+
op: "list",
284+
id_module: "'.$id_module.'",
285+
id_plugin: "'.$id_plugin.'",
286+
},
287+
type: "post",
288+
success: function(data){
289+
try {
290+
// Verifica se la risposta è vuota
291+
if (!data || data.trim() === "") {
292+
console.error("Risposta vuota dal server");
293+
swal("'.tr('Errore').'", "'.tr('Risposta vuota dal server').'", "error");
300294
buttonRestore(btn, restore);
301295
$("#main_loading").fadeOut();
302296
return;
303297
}
304298
299+
data = JSON.parse(data);
300+
} catch (e) {
301+
console.error("Errore parsing JSON:", e);
302+
console.error("Dati ricevuti:", data);
303+
swal("'.tr('Errore').'", "'.tr('Errore durante l\'elaborazione della risposta del server').'", "error");
304+
buttonRestore(btn, restore);
305+
$("#main_loading").fadeOut();
306+
return;
307+
}
308+
309+
// Controlla se ci sono documenti da importare
310+
if (!data || data.length === 0) {
311+
swal({
312+
title: "'.tr('Nessuna fattura da importare').'",
313+
type: "info",
314+
});
315+
buttonRestore(btn, restore);
316+
$("#main_loading").fadeOut();
317+
return;
318+
}
319+
320+
// Se ci sono documenti, mostra il dialogo di conferma
321+
swal({
322+
title: "'.tr('Importare tutte le fatture?').'",
323+
html: "'.tr('Verranno scaricate tutte le fatture da importare, e non sarà più possibile visualizzare altre informazioni oltre al nome per le fatture che non verranno importate completamente. Continuare?').'",
324+
showCancelButton: true,
325+
confirmButtonText: "'.tr('Procedi').'",
326+
type: "info",
327+
}).then(function (result) {
305328
count = data.length;
306329
counter = 0;
307330
data.forEach(function(element) {
@@ -328,14 +351,14 @@ function importAllZip(btn) {
328351
});
329352
330353
importComplete(count, counter, btn, restore);
331-
},
332-
error: function(data) {
333-
alert("'.tr('Errore').': " + data);
354+
});
355+
},
356+
error: function(data) {
357+
alert("'.tr('Errore').': " + data);
334358
335-
$("#main_loading").fadeOut();
336-
buttonRestore(btn, restore);
337-
}
338-
});
359+
$("#main_loading").fadeOut();
360+
buttonRestore(btn, restore);
361+
}
339362
});
340363
}
341364
@@ -347,12 +370,6 @@ function importComplete(count, counter, btn, restore) {
347370
redirect_url(globals.rootdir + "/editor.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&id_record=1&sequence=1");
348371
}
349372
}';
350-
} else {
351-
echo '
352-
function importAllZip(btn) {
353-
redirect_url(globals.rootdir + "/editor.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&id_record=1&sequence=1");
354-
}';
355-
}
356373
echo '
357374
358375
function searchInvoicesZip(btn) {

0 commit comments

Comments
 (0)