Miglioramenti vari importFE

This commit is contained in:
Thomas Zilio 2019-07-24 17:39:11 +02:00
parent 5af5cf25e9
commit 1c7653be97
6 changed files with 92 additions and 54 deletions

View File

@ -25,32 +25,52 @@ switch (filter('op')) {
$file = Interaction::getInvoiceFile($name);
}
if (FatturaElettronica::isValid($file)) {
// Individuazione ID fisico
$files = Interaction::getFileList();
foreach ($files as $key => $value) {
if ($value['name'] == $file) {
$index = $key;
try {
if (!FatturaElettronica::isValid($file)) {
echo json_encode([
'already' => 1,
]);
break;
}
return;
}
echo json_encode([
'id' => $index + 1,
]);
} else {
echo json_encode([
'already' => 1,
]);
} catch (Exception $e) {
}
// Individuazione ID fisico
$files = Interaction::getFileList();
foreach ($files as $key => $value) {
if ($value['name'] == $file) {
$index = $key;
break;
}
}
echo json_encode([
'id' => $index + 1,
]);
break;
case 'delete':
$file_id = get('file_id');
$files = Interaction::getFileList();
$file = $files[$file_id];
$directory = FatturaElettronica::getImportDirectory();
delete($directory.'/'.$file['name']);
break;
case 'download':
$file_id = get('file_id');
$files = Interaction::getFileList();
$file = $files[$file_id];
$directory = FatturaElettronica::getImportDirectory();
delete($directory.'/'.get('name'));
download($directory.'/'.$file['name']);
break;

View File

@ -97,7 +97,7 @@ echo '
<div class="pull-right">
<button type="button" class="btn btn-warning" onclick="importAll(this)">
<i class="fa fa-download"></i> '.tr('Importa in sequenza').'
<i class="fa fa-cloud-download"></i> '.tr('Importa in sequenza').'
</button>';
// Ricerca automatica

View File

@ -29,7 +29,7 @@ if (!empty($list)) {
echo '
<tr>';
if (file_exists($directory.'/'.$name)) {
if (!empty($element['file'])) {
echo '
<td>
<p>'.$name.'</p>
@ -40,7 +40,7 @@ if (!empty($list)) {
<td class="text-center">-</td>
<td class="text-center">
<button type="button" class="btn btn-danger" onclick="delete_fe(this, \''.$name.'\')">
<button type="button" class="btn btn-danger" onclick="delete_fe(this, \''.$element['id'].'\')">
<i class="fa fa-trash"></i>
</button>';
} else {
@ -85,10 +85,17 @@ if (!empty($list)) {
</button>';
}
if (file_exists($directory.'/'.$name)) {
echo '
<button type="button" class="btn btn-primary" onclick="download_fe(this, \''.$element['id'].'\')">
<i class="fa fa-download"></i>
</button>';
}
echo '
<button type="button" class="btn btn-warning" '.((!extension_loaded('openssl') && substr(strtolower($name), -4) == '.p7m') ? 'disabled' : '').' onclick="download(this, \''.$name.'\', \''.$data.'\')">
<i class="fa fa-download"></i> '.tr('Importa').'
<button type="button" class="btn btn-warning" '.((!extension_loaded('openssl') && substr(strtolower($name), -4) == '.p7m') ? 'disabled' : '').' onclick="import_fe(this, \''.$name.'\', \''.$data.'\')">
<i class="fa fa-cloud-download"></i> '.tr('Importa').'
</button>
</td>
</tr>';
@ -104,7 +111,7 @@ if (!empty($list)) {
echo '
<script>
function download(button, file, data_registrazione) {
function import_fe(button, file, data_registrazione) {
var restore = buttonLoading(button);
$.ajax({
@ -140,34 +147,6 @@ function download(button, file, data_registrazione) {
});
}
function delete_fe(button, file) {
swal({
title: "'.tr('Rimuovere la fattura salvata localmente?').'",
html: "'.tr('Sarà possibile inserirla nuovamente nel gestionale attraverso il caricamento').'",
type: "error",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function (result) {
var restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "get",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
op: "delete",
name: file,
},
success: function(data) {
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
buttonRestore(button, restore);
});
}
});
});
}
function process_fe(button, file) {
swal({
title: "'.tr('Segnare la fattura come processata?').'",
@ -196,5 +175,42 @@ function process_fe(button, file) {
});
}
function delete_fe(button, file_id) {
swal({
title: "'.tr('Rimuovere la fattura salvata localmente?').'",
html: "'.tr('Sarà possibile inserirla nuovamente nel gestionale attraverso il caricamento').'",
type: "error",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function (result) {
var restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "get",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
op: "delete",
file_id: file_id,
},
success: function(data) {
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
buttonRestore(button, restore);
});
}
});
});
}
function download_fe(button, file_id) {
redirect(globals.rootdir + "/actions.php", {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
op: "download",
file_id: file_id,
}, "get", true);
}
start_local_datatables();
</script>';

View File

@ -50,12 +50,14 @@ class Interaction extends Services
$directory = FatturaElettronica::getImportDirectory();
$files = glob($directory.'/*.xml*');
foreach ($files as $file) {
foreach ($files as $id => $file) {
$name = basename($file);
if (!in_array($name, $names)) {
$list[] = [
'id' => $id,
'name' => $name,
'file' => true,
];
}
}

View File

@ -50,7 +50,7 @@ if (Interaction::isEnabled()) {
echo '
<div class="pull-right">
<button type="button" class="btn btn-warning" onclick="importAll(this)">
<i class="fa fa-download"></i> '.tr('Importa tutte le ricevute').'
<i class="fa fa-cloud-download"></i> '.tr('Importa tutte le ricevute').'
</button>
<button type="button" class="btn btn-primary" onclick="search(this)">

View File

@ -40,7 +40,7 @@ if (!empty($list)) {
echo '
<button type="button" class="btn btn-warning" '.((!extension_loaded('openssl') and substr(strtolower($element), -4) == '.p7m') ? 'disabled' : '').' onclick="download(this, \''.$element.'\')">
<i class="fa fa-download"></i> '.tr('Importa').'
<i class="fa fa-cloud-download"></i> '.tr('Importa').'
</button>
</td>
</tr>';