'.$riga['Descrizione'].' |
- '.Translator::numberToLocale( $riga['Quantita'] ).' '.$riga['UnitaMisura'].' |
- '.Translator::numberToLocale( $riga['PrezzoUnitario'] ).' € |
+ '.Translator::numberToLocale($riga['Quantita']).' '.$riga['UnitaMisura'].' |
+ '.Translator::numberToLocale($riga['PrezzoUnitario']).' € |
{[ "type": "select", "name": "iva['.$key.']", "values": "query='.str_replace('"', '\"', $query).'", "required": 1 ]}
|
- {[ "type": "select", "name": "conto['.$key.']", "ajax-source": "conti-acquisti" ]}
+ {[ "type": "select", "name": "conto['.$key.']", "ajax-source": "conti-acquisti", "required": 1 ]}
|
{[ "type": "select", "name": "articoli['.$key.']", "ajax-source": "articoli" ]}
diff --git a/plugins/importPA/src/FatturaElettronica.php b/plugins/importFE/src/FatturaElettronica.php
similarity index 77%
rename from plugins/importPA/src/FatturaElettronica.php
rename to plugins/importFE/src/FatturaElettronica.php
index aa6c066cb..c04fcecc4 100644
--- a/plugins/importPA/src/FatturaElettronica.php
+++ b/plugins/importFE/src/FatturaElettronica.php
@@ -1,6 +1,6 @@
file = static::getImportDirectory().'/'.$file;
- $this->xml = $array;
- $this->id_sezionale = $id_sezionale;
+ $xml = simplexml_load_file($this->file, 'SimpleXMLElement', LIBXML_NOCDATA);
+ $json = json_decode(json_encode($xml), true);
+
+ $this->xml = $json;
// Individuazione fattura pre-esistente
$dati_generali = $this->getBody()['DatiGenerali']['DatiGeneraliDocumento'];
$data = $dati_generali['Data'];
$numero = $dati_generali['Numero'];
+ $progressivo_invio = $this->getHeader()['DatiTrasmissione']['ProgressivoInvio'];
$fattura = Fattura::where([
- 'id_segment' => $id_sezionale,
+ 'progressivo_invio' => $progressivo_invio,
'data' => $data,
'numero' => $numero,
])->first();
if (!empty($fattura)) {
- throw new \UnexpectedValueException();
+ $this->delete();
+
+ throw new UnexpectedValueException();
+ }
+ }
+
+ public static function getImportDirectory()
+ {
+ if (!isset(self::$directory)) {
+ $module = Modules::get('Fatture di acquisto');
+
+ $plugin = $module->plugins->first(function ($value, $key) {
+ return $value->name = 'Fatturazione Elettronica';
+ });
+
+ self::$directory = DOCROOT.'/'.$plugin->upload_directory;
+ }
+
+ return self::$directory;
+ }
+
+ public static function store($filename, $content)
+ {
+ $file = static::getImportDirectory().'/'.$filename;
+
+ file_put_contents($file, $content);
+
+ return $filename;
+ }
+
+ public static function isValid($file)
+ {
+ try {
+ new static($file);
+
+ return true;
+ } catch (UnexpectedValueException $e) {
+ return false;
}
}
@@ -200,12 +243,18 @@ class FatturaElettronica
return $result;
}
- public function saveAllegati($directory)
+ public function saveAllegati()
{
$allegati = $this->getAllegati();
$module = Modules::get('Fatture di acquisto');
+ $info = [
+ 'category' => tr('Fattura Elettronica'),
+ 'id_module' => $module->id,
+ 'id_record' => $this->fattura->id,
+ ];
+
foreach ($allegati as $allegato) {
$content = base64_decode($allegato['Attachment']);
$original = $allegato['NomeAttachment'].'.'.strtolower($allegato['FormatoAttachment']);
@@ -213,16 +262,18 @@ class FatturaElettronica
'id_module' => $module['id'],
]);
- file_put_contents($directory.'/'.$filename, $content);
+ file_put_contents($module->upload_directory.'/'.$filename, $content);
- Uploads::register([
+ Uploads::register(array_merge($info, [
'filename' => $filename,
'original' => $original,
- 'category' => tr('Fattura elettronica'),
- 'id_module' => $module['id'],
- 'id_record' => $this->fattura->id,
- ]);
+ ]));
}
+
+ // Registrazione XML come allegato
+ $filename = Uploads::upload($this->file, array_merge($info, [
+ 'name' => tr('Fattura Elettronica'),
+ ]));
}
public function getFattura()
@@ -235,22 +286,22 @@ class FatturaElettronica
*
* @return int
*/
- public function saveFattura($id_pagamento)
+ public function saveFattura($id_pagamento, $id_sezionale)
{
$anagrafica = static::createAnagrafica($this->getHeader()['CedentePrestatore']);
$dati_generali = $this->getBody()['DatiGenerali']['DatiGeneraliDocumento'];
$data = $dati_generali['Data'];
- $numero = Fattura::getNumero($data, 'uscita', $this->id_sezionale);
$numero_esterno = $dati_generali['Numero'];
+ $progressivo_invio = $this->getHeader()['DatiTrasmissione']['ProgressivoInvio'];
$descrizione_tipo = empty($this->getBody()['DatiGenerali']['DatiTrasporto']) ? 'Fattura immediata di acquisto' : 'Fattura accompagnatoria di acquisto';
$tipo = TipoFattura::where('descrizione', $descrizione_tipo)->first();
- $fattura = Fattura::make($anagrafica, $tipo, $data, $this->id_sezionale);
+ $fattura = Fattura::make($anagrafica, $tipo, $data, $id_sezionale);
$this->fattura = $fattura;
- $fattura->numero = $numero;
+ $fattura->progressivo_invio = $progressivo_invio;
$fattura->numero_esterno = $numero_esterno;
$fattura->idpagamento = $id_pagamento;
@@ -288,4 +339,9 @@ class FatturaElettronica
return $fattura->id;
}
+
+ public function delete()
+ {
+ delete($this->file);
+ }
}
diff --git a/plugins/importFE/src/Interaction.php b/plugins/importFE/src/Interaction.php
new file mode 100644
index 000000000..28bd496ce
--- /dev/null
+++ b/plugins/importFE/src/Interaction.php
@@ -0,0 +1,91 @@
+ 'https://services.osmcloud.it/v1/',
+ 'verify' => false
+ ]);
+ }
+
+ return self::$client;
+ }
+
+ public 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();
+
+ $list = json_decode($body, true) ?: [];
+
+ $files = glob($directory.'/*.xml');
+ foreach ($files as $file) {
+ $list[] = basename($file);
+ }
+
+ return array_clean($list);
+ }
+
+ public static function getImportXML($name)
+ {
+ $directory = FatturaElettronica::getImportDirectory();
+ $file = $directory.'/'.$name;
+
+ if (!file_exists($file)) {
+ $response = static::request('GET', 'get_fattura_da_importare', [
+ 'name' => $name,
+ ]);
+
+ $body = $response->getBody();
+
+ FatturaElettronica::store($name, $body);
+ }
+
+ return $name;
+ }
+}
diff --git a/src/Uploads.php b/src/Uploads.php
index 418e81d2a..3e5b98199 100644
--- a/src/Uploads.php
+++ b/src/Uploads.php
@@ -86,15 +86,17 @@ class Uploads
*/
public static function upload($source, $data, $options = [])
{
- $src = $source['tmp_name'];
- $original = $source['name'];
+ $original = isset($source['name']) ? $source['name'] : $source;
$filename = self::getName($original, $data);
-
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
// Creazione file fisico
- if (!directory($directory) || !move_uploaded_file($src, $directory.'/'.$filename)) {
+ if (
+ !directory($directory) ||
+ (is_uploaded_file($source['tmp_name']) && !move_uploaded_file($source['tmp_name'], $directory.'/'.$filename)) ||
+ (is_string($source) && !copy($source, $directory.'/'.$filename))
+ ) {
return null;
}
diff --git a/update/2_4_3.sql b/update/2_4_3.sql
index 3ee0c32db..a0aaffaef 100644
--- a/update/2_4_3.sql
+++ b/update/2_4_3.sql
@@ -48,3 +48,7 @@ UPDATE `zz_views` SET `visible` = '0' WHERE `zz_views`.`name` = 'id' AND `id_mod
-- Colonna tipi di spedizione predefinita
INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `search`, `slow`, `format`, `search_inside`, `order_by`, `visible`, `summable`, `default` ) VALUES (NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Tipi di spedizione'), 'Predefinita', 'IF(predefined, ''Sì'', ''No'')', 2, 1, 0, 0, NULL, NULL, 0, 0, 0);
+
+-- Fix plugin
+UPDATE `zz_plugins` SET `directory` = 'exportFE' WHERE `idmodule_to` = (SELECT `id` FROM `zz_modules` WHERE `name`='Fatture di vendita') AND `name` = 'Fatturazione Elettronica';
+UPDATE `zz_plugins` SET `directory` = 'importFE' WHERE `idmodule_to` = (SELECT `id` FROM `zz_modules` WHERE `name`='Fatture di acquisto') AND `name` = 'Fatturazione Elettronica';
|