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']);
$subject = $module->replacePlaceholders($id_record, $template['subject']);
$email = $module->replacePlaceholders($id_record, '{email}');
// Campi mancanti
$campi_mancanti = [];

View File

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

View File

@ -14,7 +14,8 @@ switch (filter('op')) {
ReceiptHook::update($list);
$results = [];
foreach ($list as $name) {
foreach ($list as $element) {
$name = $element['name'];
Interaction::getReceipt($name);
$fattura = null;
@ -77,9 +78,15 @@ switch (filter('op')) {
break;
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;

View File

@ -158,22 +158,26 @@ function importAll(btn) {
success: function(data){
data = JSON.parse(data);
var html = "'.tr('Sono state elaborate le seguenti ricevute:').'";
data.forEach(function(element) {
var text = "";
if(element.fattura) {
text += element.fattura;
} else {
text += "<i>'.tr('Fattura relativa alla ricevuta non rilevata. Controlla che esista una fattura di vendita corrispondente caricata a gestionale.').'</i>";
}
text += " (" + element.file + ")";
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>";
if(data.length == 0){
var html = "'.tr('Non sono state trovate ricevute da importare').'.";
} else {
var html = "'.tr('Sono state elaborate le seguenti ricevute:').'";
data.forEach(function(element) {
var text = "";
if(element.fattura) {
text += element.fattura;
} else {
text += "<i>'.tr('Fattura relativa alla ricevuta non rilevata. Controlla che esista una fattura di vendita corrispondente caricata a gestionale.').'</i>";
}
text += " (" + element.file + ")";
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({
title: "'.tr('Operazione completata!').'",

View File

@ -21,25 +21,27 @@ if (!empty($list)) {
<tbody>';
foreach ($list as $element) {
$name = $element['name'];
echo '
<tr>
<td>'.$element.'</td>
<td>'.$name.'</td>
<td class="text-center">';
if (file_exists($directory.'/'.$element)) {
if (file_exists($directory.'/'.$name)) {
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>
</button>';
} else {
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>
</button>';
}
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').'
</button>
</td>
@ -56,7 +58,7 @@ if (!empty($list)) {
echo '
<script>
function download(button, file) {
function import_fe(button, file) {
var restore = buttonLoading(button);
$.ajax({
@ -81,7 +83,7 @@ function download(button, file) {
});
}
function delete_fe(button, file) {
function delete_fe(button, file_id) {
swal({
title: "'.tr('Rimuovere la ricevuta salvata localmente?').'",
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_plugin: '.$id_plugin.',
op: "delete",
name: file,
file_id: file_id,
},
success: function(data) {
$("#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();
$list = [];
$list = self::getRemoteList();
$files = glob($directory.'/*.xml*');
foreach ($files as $file) {
$list[] = basename($file);
}
// Ricerca fisica
$names = array_column($list, 'name');
$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
if (self::isEnabled()) {
@ -28,18 +39,38 @@ class Interaction extends Services
$body = static::responseBody($response);
if ($body['status'] == '200') {
$files = $body['results'];
$results = $body['results'];
foreach ($files as $file) {
$list[] = basename($file);
foreach ($results as $result) {
$list[] = [
'name' => $result,
];
}
}
}
$list = array_clean($list);
return $list ?: [];
}
// Aggiornamento cache hook
ReceiptHook::update($list);
public static function getFileList($names = [])
{
$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;
}