From c29847d43f199b636221c7176108cf2d51552c6c Mon Sep 17 00:00:00 2001 From: Fabio Lovato Date: Tue, 22 Jan 2019 08:59:11 +0100 Subject: [PATCH] Aggiornamento API invio/ricezione FE --- include/common/articolo.php | 2 +- plugins/exportFE/actions.php | 7 ++---- plugins/exportFE/edit.php | 6 ++--- plugins/exportFE/src/Interaction.php | 4 +--- plugins/importFE/src/Interaction.php | 33 +++++++++++++++++++++++----- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/include/common/articolo.php b/include/common/articolo.php index 5c20f830b..687512946 100644 --- a/include/common/articolo.php +++ b/include/common/articolo.php @@ -11,7 +11,7 @@ if (!isset($options['edit_articolo']) || !empty($options['edit_articolo'])) { echo '
- {[ "type": "select", "label": "'.tr('Articolo').'", "name": "idarticolo", "required": 1, "value": "'.$result['idarticolo'].'", "ajax-source": "articoli" '.(($options['dir'] == 'uscita') ? ',"icon-after": "add|'.Modules::get('Articoli')['id'].'"' : '').' ]} + {[ "type": "select", "label": "'.tr('Articolo').'", "name": "idarticolo", "required": 1, "value": "'.$result['idarticolo'].'", "ajax-source": "articoli", "icon-after": "add|'.Modules::get('Articoli')['id'].'||'.(($options['dir'] == 'uscita') ? '' : 'disabled').'" ]}
'; } else { diff --git a/plugins/exportFE/actions.php b/plugins/exportFE/actions.php index 1b696e52a..35ad6cf10 100644 --- a/plugins/exportFE/actions.php +++ b/plugins/exportFE/actions.php @@ -28,16 +28,13 @@ switch (filter('op')) { $result = Interaction::sendXML($id_record); // Aggiornamento dello stato - /* if ($result) { database()->update('co_documenti', [ 'codice_stato_fe' => 'WAIT', ], ['id' => $id_record]); } -*/ - echo json_encode([ - 'sent' => $result, - ]); + + echo json_encode($result); break; } diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index 905d76cd1..cc707b054 100644 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -176,12 +176,12 @@ echo ' data = JSON.parse(data); buttonRestore(btn, restore); - if (data.sent) { - swal("'.tr('Fattura inviata!').'", "'.tr('Fattura inoltrata con successo').'", "success"); + if (data.code == "200") { + swal("'.tr('Fattura inviata!').'", data.message, "success"); $(btn).attr("disabled", true).addClass("disabled"); } else { - swal("'.tr('Invio fallito').'", "'.tr("L'invio della fattura รจ fallito").'", "error"); + swal("'.tr('Invio fallito').'", data.code + " - " + data.message, "error"); } }, error: function(data) { diff --git a/plugins/exportFE/src/Interaction.php b/plugins/exportFE/src/Interaction.php index 7a7caee95..0e8cd03cb 100644 --- a/plugins/exportFE/src/Interaction.php +++ b/plugins/exportFE/src/Interaction.php @@ -27,9 +27,7 @@ class Interaction extends Connection $body = static::responseBody($response); - if (!empty($body['sent'])) { - return true; - } + return $body; } catch (UnexpectedValueException $e) { } diff --git a/plugins/importFE/src/Interaction.php b/plugins/importFE/src/Interaction.php index 5e22f9eaf..3bac5f837 100644 --- a/plugins/importFE/src/Interaction.php +++ b/plugins/importFE/src/Interaction.php @@ -18,14 +18,18 @@ class Interaction extends Connection $response = static::request('POST', 'get_fatture_da_importare'); $body = static::responseBody($response); - $list = $body['results']; + $code = $body['code']; - $files = glob($directory.'/*.xml'); - foreach ($files as $file) { - $list[] = basename($file); + if($code=='200'){ + $list = $body['results']; + + $files = glob($directory.'/*.xml'); + foreach ($files as $file) { + $list[] = basename($file); + } + + return array_clean($list); } - - return array_clean($list); } public static function getImportXML($name) @@ -44,4 +48,21 @@ class Interaction extends Connection return $name; } + + public static function processXML($filename) + { + $response = static::request('POST', 'process_xml', [ + 'filename' => $filename, + ]); + + $body = static::responseBody($response); + + if($body['processed']=='0'){ + $message = $body['code']." - ".$body['message']; + }else{ + $message = ""; + } + + return $message; + } }