openstamanager/plugins/receiptFE/list.php

169 lines
5.3 KiB
PHP
Raw Normal View History

2019-07-10 15:02:09 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-07-10 15:02:09 +02:00
include_once __DIR__.'/../../core.php';
use Carbon\Carbon;
2019-07-10 15:02:09 +02:00
use Plugins\ReceiptFE\Interaction;
use Plugins\ReceiptFE\Ricevuta;
$list = Interaction::getReceiptList();
$directory = Ricevuta::getImportDirectory();
if (!empty($list)) {
echo '
<table class="table table-striped table-hover table-sm table-bordered datatables">
2019-07-10 15:02:09 +02:00
<thead>
<tr>
<th width="60%">'.tr('Nome').'</th>
<th width="15%" class="text-center">'.tr('Data di caricamento').'</th>
2019-07-10 15:02:09 +02:00
<th width="20%" class="text-center">#</th>
</tr>
</thead>
<tbody>';
foreach ($list as $element) {
2019-07-24 17:54:50 +02:00
$name = $element['name'];
$file = $directory.'/'.$name;
$local = file_exists($file);
$data_modifica = $local ? Carbon::createFromTimestamp(filemtime($file)) : null;
2019-07-24 17:54:50 +02:00
2019-07-10 15:02:09 +02:00
echo '
<tr>
2019-07-24 17:54:50 +02:00
<td>'.$name.'</td>
<td class="text-center">'.($local ? dateFormat($data_modifica) : '-').'</td>
2019-07-10 15:02:09 +02:00
<td class="text-center">';
if ($local) {
2019-07-10 15:02:09 +02:00
echo '
2019-07-24 17:54:50 +02:00
<button type="button" class="btn btn-danger" onclick="delete_fe(this, \''.$element['id'].'\')">
2019-07-10 15:02:09 +02:00
<i class="fa fa-trash"></i>
</button>';
} else {
echo '
2019-07-24 17:54:50 +02:00
<button type="button" class="btn btn-info" onclick="process_fe(this, \''.$name.'\')">
2019-07-10 15:02:09 +02:00
<i class="fa fa-upload"></i>
</button>';
}
echo '
2024-05-23 11:36:25 +02:00
<button type="button" class="btn btn-warning" '.((!extension_loaded('openssl') and str_ends_with(strtolower((string) $element), '.p7m')) ? 'disabled' : '').' onclick="import_fe(this, \''.$name.'\')">
2019-07-24 17:39:11 +02:00
<i class="fa fa-cloud-download"></i> '.tr('Importa').'
2019-07-10 15:02:09 +02:00
</button>
</td>
</tr>';
}
echo '
</tbody>
</table>';
} else {
echo '
<p>'.tr('Nessuna ricevuta da importare').'.</p>';
}
echo '
<script>
2019-07-24 17:54:50 +02:00
function import_fe(button, file) {
2019-07-10 15:02:09 +02:00
var restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "get",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
op: "prepare",
name: file,
},
success: function(data) {
importMessage(data);
2020-09-07 15:04:06 +02:00
2019-07-10 15:02:09 +02:00
buttonRestore(button, restore);
2019-09-18 11:31:49 +02:00
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'");
2019-07-10 15:02:09 +02:00
},
error: function(xhr) {
alert("'.tr('Errore').': " + xhr.responseJSON.error.message);
buttonRestore(button, restore);
}
});
}
2019-07-24 17:54:50 +02:00
function delete_fe(button, file_id) {
2019-07-10 15:02:09 +02:00
swal({
title: "'.tr('Rimuovere la ricevuta 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);
2020-09-07 15:04:06 +02:00
2019-07-10 15:02:09 +02:00
$.ajax({
url: globals.rootdir + "/actions.php",
type: "get",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
op: "delete",
2019-07-24 17:54:50 +02:00
file_id: file_id,
2019-07-10 15:02:09 +02:00
},
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 ricevuta come processata?').'",
html: "'.tr("Non sarà possibile individuarla nuovamente in modo automatico: l'unico modo per recuperarla sarà contattare l'assistenza").'",
type: "info",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function (result) {
var restore = buttonLoading(button);
2020-09-07 15:04:06 +02:00
2019-07-10 15:02:09 +02:00
$.ajax({
url: globals.rootdir + "/actions.php",
type: "get",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
op: "process",
name: file,
},
success: function(data) {
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
buttonRestore(button, restore);
});
}
});
});
}
start_local_datatables();
</script>';