2018-07-09 12:57:55 +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/>.
|
|
|
|
*/
|
2018-07-09 12:57:55 +02:00
|
|
|
|
2018-09-18 15:57:55 +02:00
|
|
|
include_once __DIR__.'/init.php';
|
2018-07-10 12:07:48 +02:00
|
|
|
|
2018-12-07 18:16:46 +01:00
|
|
|
use Plugins\ExportFE\Interaction;
|
2020-07-02 10:26:17 +02:00
|
|
|
use Plugins\ReceiptFE\Ricevuta;
|
2018-12-07 18:16:46 +01:00
|
|
|
|
2018-07-09 12:57:55 +02:00
|
|
|
switch (filter('op')) {
|
|
|
|
case 'generate':
|
2018-09-21 15:50:42 +02:00
|
|
|
if (!empty($fattura_pa)) {
|
2021-03-31 22:03:55 +02:00
|
|
|
$file = $fattura_pa->save();
|
2018-11-09 07:02:59 +01:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Fattura elettronica generata correttamente!'));
|
2018-07-09 12:57:55 +02:00
|
|
|
|
2018-09-21 15:50:42 +02:00
|
|
|
if (!$fattura_pa->isValid()) {
|
2018-11-16 10:41:21 +01:00
|
|
|
$errors = $fattura_pa->getErrors();
|
|
|
|
|
|
|
|
flash()->warning(tr('La fattura elettronica potrebbe avere delle irregolarità!').' '.tr('Controllare i seguenti campi: _LIST_', [
|
|
|
|
'_LIST_' => implode(', ', $errors),
|
|
|
|
]).'.');
|
2018-07-09 12:57:55 +02:00
|
|
|
}
|
2018-09-18 15:57:55 +02:00
|
|
|
} else {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->error(tr('Impossibile generare la fattura elettronica'));
|
2018-07-09 12:57:55 +02:00
|
|
|
}
|
|
|
|
|
2018-12-07 18:16:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'send':
|
2019-07-24 17:17:54 +02:00
|
|
|
$result = Interaction::sendInvoice($id_record);
|
2018-12-07 18:16:46 +01:00
|
|
|
|
2019-01-22 08:59:11 +01:00
|
|
|
echo json_encode($result);
|
2018-12-07 18:16:46 +01:00
|
|
|
|
2020-07-01 15:57:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'verify':
|
|
|
|
$result = Interaction::getInvoiceRecepits($id_record);
|
2020-07-02 10:26:17 +02:00
|
|
|
$last_recepit = $result['results'][0];
|
2020-07-01 15:57:16 +02:00
|
|
|
|
2020-07-02 10:26:17 +02:00
|
|
|
// Messaggi relativi
|
2020-07-06 14:16:16 +02:00
|
|
|
if (empty($last_recepit)) {
|
2020-07-02 10:26:17 +02:00
|
|
|
echo json_encode($result);
|
2020-07-06 14:16:16 +02:00
|
|
|
|
2020-07-02 10:26:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Importazione ultima ricevuta individuata
|
2020-09-08 10:38:27 +02:00
|
|
|
$fattura = Ricevuta::process($last_recepit);
|
|
|
|
$numero_esterno = $fattura ? $fattura->numero_esterno : null;
|
2020-07-02 10:26:17 +02:00
|
|
|
|
2020-09-08 10:38:27 +02:00
|
|
|
echo json_encode([
|
|
|
|
'file' => $last_recepit,
|
|
|
|
'fattura' => $numero_esterno,
|
|
|
|
]);
|
2020-07-02 10:26:17 +02:00
|
|
|
|
2020-09-08 10:38:27 +02:00
|
|
|
break;
|
2020-07-02 10:26:17 +02:00
|
|
|
|
2020-09-08 10:38:27 +02:00
|
|
|
case 'gestione_ricevuta':
|
|
|
|
$name = filter('name');
|
|
|
|
$type = filter('type');
|
2020-07-02 10:26:17 +02:00
|
|
|
|
2020-09-08 10:38:27 +02:00
|
|
|
$cambia_stato = $type != 'download';
|
2020-10-30 15:30:24 +01:00
|
|
|
$fattura = Ricevuta::process($name, $cambia_stato);
|
2020-09-08 10:38:27 +02:00
|
|
|
|
|
|
|
$numero_esterno = $fattura ? $fattura->numero_esterno : null;
|
2020-07-02 10:26:17 +02:00
|
|
|
|
|
|
|
echo json_encode([
|
2020-09-08 10:38:27 +02:00
|
|
|
'file' => $name,
|
2020-07-02 10:26:17 +02:00
|
|
|
'fattura' => $fattura,
|
|
|
|
]);
|
2020-07-01 15:57:16 +02:00
|
|
|
|
2018-07-09 12:57:55 +02:00
|
|
|
break;
|
|
|
|
}
|