2018-12-07 18:16:46 +01: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-12-07 18:16:46 +01:00
|
|
|
|
|
|
|
namespace Plugins\ExportFE;
|
|
|
|
|
2019-07-19 15:23:00 +02:00
|
|
|
use API\Services;
|
2021-03-31 22:03:55 +02:00
|
|
|
use Modules\Fatture\Fattura;
|
2020-07-01 15:57:16 +02:00
|
|
|
use UnexpectedValueException;
|
2019-07-19 15:23:00 +02:00
|
|
|
|
2018-12-07 18:16:46 +01:00
|
|
|
/**
|
2021-05-10 17:48:00 +02:00
|
|
|
* Classe per la gestione delle API esterne per l'invio delle Fatture Elettroniche e la ricerca di ricevute collegate.
|
2018-12-07 18:16:46 +01:00
|
|
|
*
|
|
|
|
* @since 2.4.3
|
|
|
|
*/
|
2019-07-19 15:23:00 +02:00
|
|
|
class Interaction extends Services
|
2018-12-07 18:16:46 +01:00
|
|
|
{
|
2019-07-24 17:17:54 +02:00
|
|
|
public static function sendInvoice($id_record)
|
2018-12-07 18:16:46 +01:00
|
|
|
{
|
|
|
|
try {
|
2021-03-31 22:03:55 +02:00
|
|
|
$fattura_elettronica = new FatturaElettronica($id_record);
|
|
|
|
$fattura = Fattura::find($id_record);
|
|
|
|
$file = $fattura->getFatturaElettronica();
|
2018-12-07 18:16:46 +01:00
|
|
|
|
2019-02-19 15:59:27 +01:00
|
|
|
$response = static::request('POST', 'invio_fattura_xml', [
|
2021-03-31 22:03:55 +02:00
|
|
|
'xml' => $file->getContent(),
|
|
|
|
'filename' => $fattura_elettronica->getFilename(),
|
2018-12-07 18:16:46 +01:00
|
|
|
]);
|
2018-12-14 12:50:44 +01:00
|
|
|
$body = static::responseBody($response);
|
2020-11-27 15:10:27 +01:00
|
|
|
|
2019-08-29 16:01:49 +02:00
|
|
|
// Aggiornamento dello stato
|
2020-11-20 16:54:40 +01:00
|
|
|
if ($body['status'] == 200 || $body['status'] == 301) {
|
2019-08-29 16:01:49 +02:00
|
|
|
database()->update('co_documenti', [
|
|
|
|
'codice_stato_fe' => 'WAIT',
|
|
|
|
'data_stato_fe' => date('Y-m-d H:i:s'),
|
|
|
|
], ['id' => $id_record]);
|
|
|
|
} elseif ($body['status'] == 405) {
|
|
|
|
database()->update('co_documenti', [
|
|
|
|
'codice_stato_fe' => 'ERR',
|
|
|
|
'data_stato_fe' => date('Y-m-d H:i:s'),
|
|
|
|
], ['id' => $id_record]);
|
|
|
|
}
|
|
|
|
|
2019-02-19 15:59:27 +01:00
|
|
|
return [
|
|
|
|
'code' => $body['status'],
|
|
|
|
'message' => $body['message'],
|
|
|
|
];
|
2018-12-07 18:16:46 +01:00
|
|
|
} catch (UnexpectedValueException $e) {
|
|
|
|
}
|
|
|
|
|
2019-02-19 15:59:27 +01:00
|
|
|
return [
|
|
|
|
'code' => 400,
|
|
|
|
'message' => tr('Fattura non generata correttamente'),
|
|
|
|
];
|
2018-12-07 18:16:46 +01:00
|
|
|
}
|
2020-07-01 15:57:16 +02:00
|
|
|
|
|
|
|
public static function getInvoiceRecepits($id_record)
|
|
|
|
{
|
|
|
|
try {
|
2021-03-31 22:03:55 +02:00
|
|
|
$fattura_elettronica = new FatturaElettronica($id_record);
|
|
|
|
$filename = $fattura_elettronica->getFilename();
|
2020-07-01 15:57:16 +02:00
|
|
|
|
|
|
|
$response = static::request('POST', 'notifiche_fattura', [
|
|
|
|
'name' => $filename,
|
|
|
|
]);
|
|
|
|
$body = static::responseBody($response);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'code' => $body['status'],
|
|
|
|
'results' => $body['results'],
|
|
|
|
];
|
|
|
|
} catch (UnexpectedValueException $e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'code' => 400,
|
|
|
|
'message' => tr('Fattura non generata correttamente'),
|
|
|
|
];
|
|
|
|
}
|
2018-12-07 18:16:46 +01:00
|
|
|
}
|