Bugfix vari

This commit is contained in:
Thomas Zilio 2019-07-24 17:54:50 +02:00
parent 1c7653be97
commit a2f272b86c
6 changed files with 93 additions and 43 deletions

View File

@ -12,6 +12,8 @@ $subject = $template['subject'];
$body = $module->replacePlaceholders($id_record, $template['body']); $body = $module->replacePlaceholders($id_record, $template['body']);
$subject = $module->replacePlaceholders($id_record, $template['subject']); $subject = $module->replacePlaceholders($id_record, $template['subject']);
$email = $module->replacePlaceholders($id_record, '{email}');
// Campi mancanti // Campi mancanti
$campi_mancanti = []; $campi_mancanti = [];

View File

@ -55,22 +55,26 @@ switch (filter('op')) {
case 'delete': case 'delete':
$file_id = get('file_id'); $file_id = get('file_id');
$directory = FatturaElettronica::getImportDirectory();
$files = Interaction::getFileList(); $files = Interaction::getFileList();
$file = $files[$file_id]; $file = $files[$file_id];
$directory = FatturaElettronica::getImportDirectory(); if (!empty($file)) {
delete($directory.'/'.$file['name']); delete($directory.'/'.$file['name']);
}
break; break;
case 'download': case 'download':
$file_id = get('file_id'); $file_id = get('file_id');
$directory = FatturaElettronica::getImportDirectory();
$files = Interaction::getFileList(); $files = Interaction::getFileList();
$file = $files[$file_id]; $file = $files[$file_id];
$directory = FatturaElettronica::getImportDirectory(); if (!empty($file)) {
download($directory.'/'.$file['name']);
download($directory.'/'.$file['name']); }
break; break;

View File

@ -14,7 +14,8 @@ switch (filter('op')) {
ReceiptHook::update($list); ReceiptHook::update($list);
$results = []; $results = [];
foreach ($list as $name) { foreach ($list as $element) {
$name = $element['name'];
Interaction::getReceipt($name); Interaction::getReceipt($name);
$fattura = null; $fattura = null;
@ -77,9 +78,15 @@ switch (filter('op')) {
break; break;
case 'delete': case 'delete':
$directory = Ricevuta::getImportDirectory(); $file_id = get('file_id');
delete($directory.'/'.get('name')); $directory = Ricevuta::getImportDirectory();
$files = Interaction::getFileList();
$file = $files[$file_id];
if (!empty($file)) {
delete($directory.'/'.$file['name']);
}
break; break;

View File

@ -158,22 +158,26 @@ function importAll(btn) {
success: function(data){ success: function(data){
data = JSON.parse(data); data = JSON.parse(data);
var html = "'.tr('Sono state elaborate le seguenti ricevute:').'"; if(data.length == 0){
var html = "'.tr('Non sono state trovate ricevute da importare').'.";
data.forEach(function(element) { } else {
var text = ""; var html = "'.tr('Sono state elaborate le seguenti ricevute:').'";
if(element.fattura) {
text += element.fattura; data.forEach(function(element) {
} else { var text = "";
text += "<i>'.tr('Fattura relativa alla ricevuta non rilevata. Controlla che esista una fattura di vendita corrispondente caricata a gestionale.').'</i>"; if(element.fattura) {
} text += element.fattura;
} else {
text += " (" + element.file + ")"; text += "<i>'.tr('Fattura relativa alla ricevuta non rilevata. Controlla che esista una fattura di vendita corrispondente caricata a gestionale.').'</i>";
}
html += "<small><li>" + text + "</li></small>";
}); text += " (" + element.file + ")";
html += "<br><small>'.tr("Se si sono verificati degli errori durante la procedura e il problema continua a verificarsi, contatta l'assistenza ufficiale").'</small>"; html += "<small><li>" + text + "</li></small>";
});
html += "<br><small>'.tr("Se si sono verificati degli errori durante la procedura e il problema continua a verificarsi, contatta l'assistenza ufficiale").'</small>";
}
swal({ swal({
title: "'.tr('Operazione completata!').'", title: "'.tr('Operazione completata!').'",

View File

@ -21,25 +21,27 @@ if (!empty($list)) {
<tbody>'; <tbody>';
foreach ($list as $element) { foreach ($list as $element) {
$name = $element['name'];
echo ' echo '
<tr> <tr>
<td>'.$element.'</td> <td>'.$name.'</td>
<td class="text-center">'; <td class="text-center">';
if (file_exists($directory.'/'.$element)) { if (file_exists($directory.'/'.$name)) {
echo ' echo '
<button type="button" class="btn btn-danger" onclick="delete_fe(this, \''.$element.'\')"> <button type="button" class="btn btn-danger" onclick="delete_fe(this, \''.$element['id'].'\')">
<i class="fa fa-trash"></i> <i class="fa fa-trash"></i>
</button>'; </button>';
} else { } else {
echo ' echo '
<button type="button" class="btn btn-info" onclick="process_fe(this, \''.$element.'\')"> <button type="button" class="btn btn-info" onclick="process_fe(this, \''.$name.'\')">
<i class="fa fa-upload"></i> <i class="fa fa-upload"></i>
</button>'; </button>';
} }
echo ' echo '
<button type="button" class="btn btn-warning" '.((!extension_loaded('openssl') and substr(strtolower($element), -4) == '.p7m') ? 'disabled' : '').' onclick="download(this, \''.$element.'\')"> <button type="button" class="btn btn-warning" '.((!extension_loaded('openssl') and substr(strtolower($element), -4) == '.p7m') ? 'disabled' : '').' onclick="import_fe(this, \''.$element.'\')">
<i class="fa fa-cloud-download"></i> '.tr('Importa').' <i class="fa fa-cloud-download"></i> '.tr('Importa').'
</button> </button>
</td> </td>
@ -56,7 +58,7 @@ if (!empty($list)) {
echo ' echo '
<script> <script>
function download(button, file) { function import_fe(button, file) {
var restore = buttonLoading(button); var restore = buttonLoading(button);
$.ajax({ $.ajax({
@ -81,7 +83,7 @@ function download(button, file) {
}); });
} }
function delete_fe(button, file) { function delete_fe(button, file_id) {
swal({ swal({
title: "'.tr('Rimuovere la ricevuta salvata localmente?').'", title: "'.tr('Rimuovere la ricevuta salvata localmente?').'",
html: "'.tr('Sarà possibile inserirla nuovamente nel gestionale attraverso il caricamento').'", html: "'.tr('Sarà possibile inserirla nuovamente nel gestionale attraverso il caricamento').'",
@ -98,7 +100,7 @@ function delete_fe(button, file) {
id_module: globals.id_module, id_module: globals.id_module,
id_plugin: '.$id_plugin.', id_plugin: '.$id_plugin.',
op: "delete", op: "delete",
name: file, file_id: file_id,
}, },
success: function(data) { success: function(data) {
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() { $("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {

View File

@ -15,12 +15,23 @@ class Interaction extends Services
{ {
$directory = Ricevuta::getImportDirectory(); $directory = Ricevuta::getImportDirectory();
$list = []; $list = self::getRemoteList();
$files = glob($directory.'/*.xml*'); // Ricerca fisica
foreach ($files as $file) { $names = array_column($list, 'name');
$list[] = basename($file); $files = self::getFileList($names);
}
$list = array_merge($list, $files);
// Aggiornamento cache hook
ReceiptHook::update($list);
return $list;
}
public static function getRemoteList()
{
$list = [];
// Ricerca da remoto // Ricerca da remoto
if (self::isEnabled()) { if (self::isEnabled()) {
@ -28,18 +39,38 @@ class Interaction extends Services
$body = static::responseBody($response); $body = static::responseBody($response);
if ($body['status'] == '200') { if ($body['status'] == '200') {
$files = $body['results']; $results = $body['results'];
foreach ($files as $file) { foreach ($results as $result) {
$list[] = basename($file); $list[] = [
'name' => $result,
];
} }
} }
} }
$list = array_clean($list); return $list ?: [];
}
// Aggiornamento cache hook public static function getFileList($names = [])
ReceiptHook::update($list); {
$list = [];
// Ricerca fisica
$directory = Ricevuta::getImportDirectory();
$files = glob($directory.'/*.xml*');
foreach ($files as $id => $file) {
$name = basename($file);
if (!in_array($name, $names)) {
$list[] = [
'id' => $id,
'name' => $name,
'file' => true,
];
}
}
return $list; return $list;
} }