1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-13 08:56:08 +01:00
openstamanager/plugins/exportFE/actions.php
2020-09-07 15:04:06 +02:00

87 lines
2.5 KiB
PHP
Executable File

<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.n.c.
*
* 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/>.
*/
include_once __DIR__.'/init.php';
use Plugins\ExportFE\Interaction;
use Plugins\ReceiptFE\Interaction as RecepitInteraction;
use Plugins\ReceiptFE\Ricevuta;
switch (filter('op')) {
case 'generate':
if (!empty($fattura_pa)) {
$file = $fattura_pa->save($upload_dir);
flash()->info(tr('Fattura elettronica generata correttamente!'));
if (!$fattura_pa->isValid()) {
$errors = $fattura_pa->getErrors();
flash()->warning(tr('La fattura elettronica potrebbe avere delle irregolarità!').' '.tr('Controllare i seguenti campi: _LIST_', [
'_LIST_' => implode(', ', $errors),
]).'.');
}
} else {
flash()->error(tr('Impossibile generare la fattura elettronica'));
}
break;
case 'send':
$result = Interaction::sendInvoice($id_record);
echo json_encode($result);
break;
case 'verify':
$result = Interaction::getInvoiceRecepits($id_record);
$last_recepit = $result['results'][0];
// Messaggi relativi
if (empty($last_recepit)) {
echo json_encode($result);
return;
}
// Importazione ultima ricevuta individuata
RecepitInteraction::getReceipt($last_recepit);
$fattura = null;
try {
$receipt = new Ricevuta($last_recepit);
$receipt->save();
$fattura = $receipt->getFattura()->numero_esterno;
$receipt->delete();
RecepitInteraction::processReceipt($name);
} catch (UnexpectedValueException $e) {
}
echo json_encode([
'file' => $last_recepit,
'fattura' => $fattura,
]);
break;
}