diff --git a/plugins/exportFE/actions.php b/plugins/exportFE/actions.php
index 284eec032..2e1c348a5 100644
--- a/plugins/exportFE/actions.php
+++ b/plugins/exportFE/actions.php
@@ -2,6 +2,8 @@
include_once __DIR__.'/init.php';
+use Plugins\ExportFE\Interaction;
+
switch (filter('op')) {
case 'generate':
if (!empty($fattura_pa)) {
@@ -20,5 +22,14 @@ switch (filter('op')) {
flash()->error(tr('Impossibile generare la fattura elettronica'));
}
+ break;
+
+ case 'send':
+ $result = Interaction::sendXML($id_record);
+
+ echo json_encode([
+ 'sent' => $result,
+ ]);
+
break;
}
diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php
index 7d582b3d1..16d66dabc 100644
--- a/plugins/exportFE/edit.php
+++ b/plugins/exportFE/edit.php
@@ -3,6 +3,7 @@
include_once __DIR__.'/init.php';
use Plugins\ExportFE\FatturaElettronica;
+use Plugins\ExportFE\Interaction;
if (!empty($fattura_pa)) {
$disabled = false;
@@ -137,15 +138,27 @@ echo '
'.tr('Scarica').'
-
-
- ';
+ ';
echo '
+
+
'.tr('Visualizza').'
-
+ ';
+
+if (Interaction::isEnabled()) {
+ echo '
+
+
+
+ ';
+}
+
+echo '
';
@@ -154,19 +167,51 @@ if ($generated) {
';
}
diff --git a/plugins/exportFE/src/FatturaElettronica.php b/plugins/exportFE/src/FatturaElettronica.php
index 3ab0d6e8a..2abf7b726 100644
--- a/plugins/exportFE/src/FatturaElettronica.php
+++ b/plugins/exportFE/src/FatturaElettronica.php
@@ -68,7 +68,7 @@ class FatturaElettronica
{
$documento = $this->getDocumento();
- return !empty($documento['xml_generated_at']) && !empty($documento['progressivo_invio']) && file_exists(DOCROOT.'/'.static::getDirectory().'/'.$this->getFilename());
+ return !empty($documento['progressivo_invio']) && file_exists(DOCROOT.'/'.static::getDirectory().'/'.$this->getFilename());
}
/**
@@ -882,7 +882,7 @@ class FatturaElettronica
$data = $fattura->getUploadData();
$dir = static::getDirectory();
- $rapportino_nome = sanitizeFilename($documento['numero'].'.pdf');
+ $rapportino_nome = sanitizeFilename($documento['numero_esterno'].'.pdf');
$filename = slashes(DOCROOT.'/'.$dir.'/'.$rapportino_nome);
Uploads::delete($rapportino_nome, $data);
@@ -1089,7 +1089,7 @@ class FatturaElettronica
// Aggiornamento effettivo
database()->update('co_documenti', [
'progressivo_invio' => $this->getDocumento()['progressivo_invio'],
- 'xml_generated_at' => date('Y-m-d H:i:s'),
+ 'codice_stato_fe' => 'GEN',
], ['id' => $this->getDocumento()['id']]);
return ($result === false) ? null : $filename;
diff --git a/plugins/exportFE/src/Interaction.php b/plugins/exportFE/src/Interaction.php
new file mode 100644
index 000000000..3be772e3a
--- /dev/null
+++ b/plugins/exportFE/src/Interaction.php
@@ -0,0 +1,83 @@
+ 'https://services.osmcloud.it/v1/',
+ 'verify' => false,
+ ]);
+ }
+
+ return self::$client;
+ }
+
+ public function isEnabled()
+ {
+ return true;
+ }
+
+ protected function request($type, $resource, $data = [], $options = [])
+ {
+ $client = static::getClient();
+
+ $json = array_merge($data, [
+ 'token' => setting('OSMCloud Services API Token'),
+ 'resource' => $resource,
+ ]);
+
+ $options = array_merge($options, [
+ 'json' => $json,
+ 'http_errors' => false,
+ ]);
+
+ return $client->request($type, '', $options);
+ }
+
+ public static function sendXML($id_record)
+ {
+ try {
+ $fattura = new FatturaElettronica($id_record);
+ $file = DOCROOT.'/'.FatturaElettronica::getDirectory().'/'.$fattura->getFilename();
+
+ $response = static::request('POST', 'send_fattura', [
+ 'name' => $fattura->getFilename(),
+ ], [
+ 'multipart' => [
+ [
+ 'name' => 'xml',
+ 'contents' => fopen($file, 'r')
+ ],
+ ]
+ ]);
+
+ $body = $response->getBody();
+
+ if (!empty($body)) {
+ return true;
+ }
+ } catch (UnexpectedValueException $e) {
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/update/2_4_4.sql b/update/2_4_4.sql
new file mode 100644
index 000000000..a8f718097
--- /dev/null
+++ b/update/2_4_4.sql
@@ -0,0 +1,21 @@
+-- Stati di invio del documento
+CREATE TABLE IF NOT EXISTS `fe_stati_documento` (
+ `codice` varchar(5) NOT NULL,
+ `descrizione` varchar(255) NOT NULL,
+ `icon` varchar(255) NOT NULL,
+ PRIMARY KEY (`codice`)
+) ENGINE=InnoDB;
+
+INSERT INTO `fe_stati_documento` (`codice`, `descrizione`, `icon`) VALUES
+('GEN', 'Generata', 'fa fa-file-code-o text-success'),
+('WAIT', 'In attesa', 'fa fa-clock-o text-warning'),
+('SENT', 'Inviata', 'fa fa-paper-plane-o text-info'),
+('ACK', 'Accettata', 'fa fa-paper-check text-success'),
+('REF', 'Rifiuta', 'fa fa-times text-error');
+
+ALTER TABLE `co_documenti` ADD `codice_stato_fe` varchar(5), ADD FOREIGN KEY (`codice_stato_fe`) REFERENCES `fe_stati_documento`(`codice`) ON DELETE SET NULL;
+UPDATE `co_documenti` SET `codice_stato_fe` = 'GEN' WHERE `xml_generated_at` IS NOT NULL;
+ALTER TABLE `co_documenti` DROP `xml_generated_at`;
+
+UPDATE `zz_views` SET `query` = '(SELECT `icon` FROM `fe_stati_documento` WHERE `codice` = `codice_stato_fe`)' WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di vendita') AND `name` = 'icon_FE';
+UPDATE `zz_views` SET `query` = '(SELECT `descrizione` FROM `fe_stati_documento` WHERE `codice` = `codice_stato_fe`)' WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di vendita') AND `name` = 'icon_title_FE';