From 97fb5cd3246420889107020dbb9a1a5c25ec7ad4 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Tue, 19 Feb 2019 15:59:27 +0100 Subject: [PATCH] Correzioni per l'API osmservices --- plugins/exportFE/src/Connection.php | 12 +----------- plugins/exportFE/src/Interaction.php | 22 ++++++++++----------- plugins/importFE/src/Interaction.php | 28 +++++++-------------------- plugins/receiptFE/src/Interaction.php | 4 ++-- src/API.php | 4 ++++ 5 files changed, 25 insertions(+), 45 deletions(-) diff --git a/plugins/exportFE/src/Connection.php b/plugins/exportFE/src/Connection.php index e72e94d61..c297a0e7b 100644 --- a/plugins/exportFE/src/Connection.php +++ b/plugins/exportFE/src/Connection.php @@ -27,18 +27,8 @@ class Connection 'resource' => $resource, ]); - if (!empty($options['multipart'])) { - foreach ($json as $key => $value) { - $options['multipart'][] = [ - 'name' => $key, - 'contents' => $value, - ]; - } - } else { - $options['form_params'] = $json; - } - $options = array_merge($options, [ + 'json' => $json, 'http_errors' => false, ]); diff --git a/plugins/exportFE/src/Interaction.php b/plugins/exportFE/src/Interaction.php index 0e8cd03cb..ad1b97981 100644 --- a/plugins/exportFE/src/Interaction.php +++ b/plugins/exportFE/src/Interaction.php @@ -15,22 +15,22 @@ class Interaction extends Connection $fattura = new FatturaElettronica($id_record); $file = DOCROOT.'/'.FatturaElettronica::getDirectory().'/'.$fattura->getFilename(); - $response = static::request('POST', 'send_xml', [], [ - 'multipart' => [ - [ - 'name' => 'xml', - 'filename' => $fattura->getFilename(), - 'contents' => file_get_contents($file), - ], - ], + $response = static::request('POST', 'invio_fattura_xml', [ + 'xml' => file_get_contents($file), + 'filename' => $fattura->getFilename(), ]); - $body = static::responseBody($response); - return $body; + return [ + 'code' => $body['status'], + 'message' => $body['message'], + ]; } catch (UnexpectedValueException $e) { } - return false; + return [ + 'code' => 400, + 'message' => tr('Fattura non generata correttamente'), + ]; } } diff --git a/plugins/importFE/src/Interaction.php b/plugins/importFE/src/Interaction.php index 2aa216bc1..abead992b 100644 --- a/plugins/importFE/src/Interaction.php +++ b/plugins/importFE/src/Interaction.php @@ -24,28 +24,14 @@ class Interaction extends Connection // Ricerca da remoto if (self::isEnabled()) { - $response = static::request('POST', 'get_fatture_da_importare'); + $response = static::request('POST', 'fatture_da_importare'); $body = static::responseBody($response); - $code = $body['code']; - - if ($code == '200') { + if ($body['status'] == '200') { $files = $body['results']; foreach ($files as $file) { - /* - * Verifico che l'XML (fattura di acquisto) non sia giĆ  stato importato nel db, controllo p.iva del fornitore e progressivo invio - * TODO: caricare contenuto xml e verificare anche la data (e magari numero) della fattura. Potrebbe essere che il fornitore l'anno successivo mi genera FE con stesso progressivo invio. - */ - if (preg_match("/^([A-Z]{2})(.+?)_([^\.]+)\.xml/i", $file, $m)) { - $partita_iva = $m[2]; - $progressivo_invio = $m[3]; - $fattura = database()->fetchOne('SELECT co_documenti.id FROM (co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica WHERE co_tipidocumento.dir="uscita" AND an_anagrafiche.piva='.prepare($partita_iva).' AND co_documenti.progressivo_invio='.prepare($progressivo_invio)); - - if (!$fattura) { - $list[] = basename($file); - } - } + $list[] = basename($file); } } } @@ -59,7 +45,7 @@ class Interaction extends Connection $file = $directory.'/'.$name; if (!file_exists($file)) { - $response = static::request('POST', 'get_fattura_da_importare', [ + $response = static::request('POST', 'fattura_da_importare', [ 'name' => $name, ]); $body = static::responseBody($response); @@ -72,14 +58,14 @@ class Interaction extends Connection public static function processXML($filename) { - $response = static::request('POST', 'process_xml', [ + $response = static::request('POST', 'fattura_xml_salvata', [ 'filename' => $filename, ]); $body = static::responseBody($response); - if ($body['processed'] == '0') { - $message = $body['code'].' - '.$body['message']; + if ($body['status'] != '200') { + $message = $body['status'].' - '.$body['message']; } else { $message = ''; } diff --git a/plugins/receiptFE/src/Interaction.php b/plugins/receiptFE/src/Interaction.php index 12c100b4d..3610d71e1 100644 --- a/plugins/receiptFE/src/Interaction.php +++ b/plugins/receiptFE/src/Interaction.php @@ -13,7 +13,7 @@ class Interaction extends Connection { public static function getReceiptList() { - $response = static::request('POST', 'get_receipt_list'); + $response = static::request('POST', 'notifiche_da_importare'); $body = static::responseBody($response)['results']; return $body; @@ -21,7 +21,7 @@ class Interaction extends Connection public static function getReceipt($name) { - $response = static::request('POST', 'get_receipt', [ + $response = static::request('POST', 'notifica_da_importare', [ 'name' => $name, ]); $body = static::responseBody($response); diff --git a/src/API.php b/src/API.php index 677810402..f556fe24b 100644 --- a/src/API.php +++ b/src/API.php @@ -28,6 +28,10 @@ class API extends \Util\Singleton 'code' => 404, 'message' => 'Non trovato', ], + 'externalError' => [ + 'code' => 409, + 'message' => 'Errore in un servizio esterno', + ], 'serverError' => [ 'code' => 500, 'message' => 'Errore del server',