diff --git a/config/namespaces.php b/config/namespaces.php
index 4f5ba52bb..7d26b94bb 100644
--- a/config/namespaces.php
+++ b/config/namespaces.php
@@ -8,4 +8,5 @@ return [
'modules/interventi' => 'Modules\Interventi',
'plugins/exportFE' => 'Plugins\ExportFE',
'plugins/importFE' => 'Plugins\ImportFE',
+ 'plugins/receiptFE' => 'Plugins\ReceiptFE',
];
diff --git a/lib/util.php b/lib/util.php
index c483db626..f2522e521 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -39,9 +39,9 @@ if (!function_exists('array_clean')) {
*/
function array_clean($array)
{
- return array_values(array_filter($array, function ($value) {
+ return array_unique(array_values(array_filter($array, function ($value) {
return !empty($value);
- }));
+ })));
}
}
diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php
index d814e8788..58693441c 100644
--- a/modules/fatture/actions.php
+++ b/modules/fatture/actions.php
@@ -95,6 +95,7 @@ switch (post('op')) {
'rivalsainps' => 0,
'ritenutaacconto' => 0,
'iva_rivalsainps' => 0,
+ 'codice_stato_fe' => post('codice_stato_fe'),
], $data), ['id' => $id_record]);
$query = 'SELECT descrizione FROM co_statidocumento WHERE id='.prepare($idstatodocumento);
diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php
index 1d96c5bd3..8d66a6a6d 100644
--- a/modules/fatture/edit.php
+++ b/modules/fatture/edit.php
@@ -99,6 +99,10 @@ if (empty($record['is_fiscale'])) {
{[ "type": "select", "label": "", "name": "idstatodocumento", "required": 1, "values": "query=", "value": "$idstatodocumento$", "class": "unblockable", "extra": " onchange = \"if ($('#idstatodocumento option:selected').text()=='Pagato' || $('#idstatodocumento option:selected').text()=='Parzialmente pagato' ){if( confirm('') ){ return true; }else{ $('#idstatodocumento').selectSet(); }}\" " ]}
+
+
+ {[ "type": "select", "label": "", "name": "codice_stato_fe", "required": 0, "values": "query=SELECT codice as id, descrizione as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": ]}
+
@@ -193,7 +197,7 @@ if (!empty($record['is_fiscale'])) {
if (($n2 <= 0 && $record['stato'] == 'Emessa') || $differenza != 0) {
?>
-
...
+
...
update('co_documenti', [
- 'codice_stato_fe' => 'WAIT',
- ], ['id' => $id_record]);
+ if ($result) {
+ database()->update('co_documenti', [
+ 'codice_stato_fe' => 'WAIT',
+ ], ['id' => $id_record]);
+ }
echo json_encode([
'sent' => $result,
diff --git a/plugins/exportFE/src/Connection.php b/plugins/exportFE/src/Connection.php
new file mode 100644
index 000000000..c8a90a6ff
--- /dev/null
+++ b/plugins/exportFE/src/Connection.php
@@ -0,0 +1,71 @@
+ 'https://services.osmcloud.it/v1/',
+ 'verify' => false,
+ ]);
+ }
+
+ return self::$client;
+ }
+
+ public static function isEnabled()
+ {
+ return !empty(setting('OSMCloud Services API Token'));
+ }
+
+ protected function request($type, $resource, $data = [], $options = [])
+ {
+ $client = static::getClient();
+
+ $json = array_merge($data, [
+ 'token' => setting('OSMCloud Services API Token'),
+ 'resource' => $resource,
+ ]);
+
+ if (!empty($options['multipart'])) {
+ foreach ($json as $key => $value) {
+ $options['multipart'][] = [
+ 'name' => $key,
+ 'contents' => $value,
+ ];
+ }
+ } else {
+ $options['json'] = $json;
+ }
+
+ $options = array_merge($options, [
+ 'http_errors' => false,
+ ]);
+
+ return $client->request($type, '', $options);
+ }
+
+ protected function responseBody($response)
+ {
+ $body = $response->getBody();
+
+ return json_decode($body, true) ?: [];
+ }
+}
diff --git a/plugins/exportFE/src/Interaction.php b/plugins/exportFE/src/Interaction.php
index b71f0ec2c..19a4ff8dc 100644
--- a/plugins/exportFE/src/Interaction.php
+++ b/plugins/exportFE/src/Interaction.php
@@ -9,75 +9,32 @@ use GuzzleHttp\Client;
*
* @since 2.4.3
*/
-class Interaction
+class Interaction extends Connection
{
- protected static $client = null;
-
- /**
- * Restituisce l'oggetto per la connessione all'API del progetto.
- *
- * @return Client
- */
- protected static function getClient()
- {
- if (!isset(self::$client)) {
- self::$client = new Client([
- 'base_uri' => 'https://services.osmcloud.it/v1/',
- 'verify' => false,
- ]);
- }
-
- return self::$client;
- }
-
- public static function isEnabled()
- {
- return false;
- }
-
- 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', [
- 'name' => $fattura->getFilename(),
- ], [
+ $response = static::request('POST', 'send_xml', [], [
'multipart' => [
[
'name' => 'xml',
- 'contents' => fopen($file, 'r')
+ 'filename' => $fattura->getFilename(),
+ 'contents' => file_get_contents($file)
],
]
]);
- $body = $response->getBody();
+ $body = static::responseBody($response);
- if (!empty($body)) {
+ if (!empty($body['sent'])) {
return true;
}
} catch (UnexpectedValueException $e) {
- return false;
}
- return true;
+ return false;
}
}
diff --git a/plugins/importFE/src/Interaction.php b/plugins/importFE/src/Interaction.php
index 3dbf3ff9e..fe3362c50 100644
--- a/plugins/importFE/src/Interaction.php
+++ b/plugins/importFE/src/Interaction.php
@@ -3,63 +3,23 @@
namespace Plugins\ImportFE;
use GuzzleHttp\Client;
+use Plugins\ExportFE\Connection;
/**
* Classe per l'interazione con API esterne.
*
* @since 2.4.3
*/
-class Interaction
+class Interaction extends Connection
{
- protected static $client = null;
-
- /**
- * Restituisce l'oggetto per la connessione all'API del progetto.
- *
- * @return Client
- */
- protected static function getClient()
- {
- if (!isset(self::$client)) {
- self::$client = new Client([
- 'base_uri' => 'https://services.osmcloud.it/v1/',
- 'verify' => false,
- ]);
- }
-
- return self::$client;
- }
-
- public static function isEnabled()
- {
- return false;
- }
-
- 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 listToImport()
{
$directory = FatturaElettronica::getImportDirectory();
- $response = static::request('GET', 'get_fatture_da_importare');
- $body = $response->getBody();
+ $response = static::request('POST', 'get_fatture_da_importare');
+ $body = static::responseBody($response);
- $list = json_decode($body, true) ?: [];
+ $list = $body['results'];
$files = glob($directory.'/*.xml');
foreach ($files as $file) {
@@ -75,13 +35,12 @@ class Interaction
$file = $directory.'/'.$name;
if (!file_exists($file)) {
- $response = static::request('GET', 'get_fattura_da_importare', [
+ $response = static::request('POST', 'get_fattura_da_importare', [
'name' => $name,
]);
+ $body = static::responseBody($response);
- $body = $response->getBody();
-
- FatturaElettronica::store($name, $body);
+ FatturaElettronica::store($name, $body['content']);
}
return $name;
diff --git a/plugins/receiptFE/actions.php b/plugins/receiptFE/actions.php
new file mode 100644
index 000000000..7642f14eb
--- /dev/null
+++ b/plugins/receiptFE/actions.php
@@ -0,0 +1,59 @@
+ $file,
+ ]);
+ } else {
+ echo json_encode([
+ 'already' => 1,
+ ]);
+ }
+
+ break;
+
+ case 'import':
+ $list = Interaction::getReceiptList();
+
+ $results = [];
+ foreach ($list as $name) {
+ $file = Interaction::getReceipt($name);
+
+ $result = [];
+ if (!empty($file)) {
+ try {
+ $receipt = new Ricevuta($file['content']);
+
+ $result = [
+ 'fattura' => $receipt->getFattura()->numero_esterno,
+ ];
+ } catch (UnexpectedValueException $e) {
+ }
+ }
+
+ $results[] = array_merge([
+ 'file' => $name,
+ ], $result);
+ }
+
+ echo json_encode($results);
+
+ break;
+
+ case 'list':
+ $list = Interaction::getReceiptList();
+
+ echo json_encode($list);
+
+ break;
+}
diff --git a/plugins/receiptFE/edit.php b/plugins/receiptFE/edit.php
new file mode 100644
index 000000000..8cad932d9
--- /dev/null
+++ b/plugins/receiptFE/edit.php
@@ -0,0 +1,119 @@
+'.tr('Il sistema di rilevazione automatico è attualmente disabilitato').'.
+
'.tr('Per maggiori informazioni contatta gli sviluppatori ufficiali').'.
';
+
+ return;
+}
+
+echo '
+
'.tr("Le ricevute delle Fatture Elettroniche permettono di individuare se una determinata fattura rilasciata è $requesta accettata dal Sistema Di Interscambio e dal cliente relativo").'.
+
+
'.tr("Tramite il pulsante _BTN_ è possibile procedere all controllo automatico di queste ricevute, che aggiorneranno di conseguenza lo $requesto dei documenti relativi e verranno allegate ad essi", [
+ '_BTN_' => 'Ricerca ',
+]).'.
+
';
+
+echo '
+
+
+
+ '.tr('Ricerca').'...
+
+
';
+
+echo '
+';
diff --git a/plugins/receiptFE/src/Interaction.php b/plugins/receiptFE/src/Interaction.php
new file mode 100644
index 000000000..80316ff01
--- /dev/null
+++ b/plugins/receiptFE/src/Interaction.php
@@ -0,0 +1,36 @@
+ $name,
+ ]);
+ $body = static::responseBody($response);
+
+ if($body['code'] != '200'){
+ return false;
+ }
+
+ return $body;
+ }
+}
diff --git a/plugins/receiptFE/src/Ricevuta.php b/plugins/receiptFE/src/Ricevuta.php
new file mode 100644
index 000000000..e71fb3c47
--- /dev/null
+++ b/plugins/receiptFE/src/Ricevuta.php
@@ -0,0 +1,46 @@
+xml = XML::read($content);
+
+ $nome = $this->xml['NomeFile'];
+ $pieces = explode('_', $nome);
+
+ $progressivo_invio = explode('.', $pieces[1])[0];
+
+ $this->fattura = Fattura::where([
+ 'progressivo_invio' => $progressivo_invio,
+ ])->first();
+
+ if (empty($this->fattura)) {
+ throw new UnexpectedValueException();
+ }
+ }
+
+ public function getFattura()
+ {
+ return $this->fattura;
+ }
+}
diff --git a/update/2_4_5.sql b/update/2_4_5.sql
new file mode 100644
index 000000000..50ed9ef11
--- /dev/null
+++ b/update/2_4_5.sql
@@ -0,0 +1,2 @@
+INSERT INTO `zz_plugins` (`id`, `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `directory`, `options`) VALUES
+(NULL, 'Ricevute FE', 'Ricevute FE', (SELECT `id` FROM `zz_modules` WHERE `name`='Fatture di vendita'), (SELECT `id` FROM `zz_modules` WHERE `name`='Fatture di vendita'), 'tab_main', 'receiptFE', 'custom'),