Aggiornamento API invio/ricezione FE

This commit is contained in:
Fabio Lovato 2019-01-22 08:59:11 +01:00
parent 858a3060bf
commit c29847d43f
5 changed files with 34 additions and 18 deletions

View File

@ -11,7 +11,7 @@ if (!isset($options['edit_articolo']) || !empty($options['edit_articolo'])) {
echo ' echo '
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
{[ "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').'" ]}
</div> </div>
</div>'; </div>';
} else { } else {

View File

@ -28,16 +28,13 @@ switch (filter('op')) {
$result = Interaction::sendXML($id_record); $result = Interaction::sendXML($id_record);
// Aggiornamento dello stato // Aggiornamento dello stato
/*
if ($result) { if ($result) {
database()->update('co_documenti', [ database()->update('co_documenti', [
'codice_stato_fe' => 'WAIT', 'codice_stato_fe' => 'WAIT',
], ['id' => $id_record]); ], ['id' => $id_record]);
} }
*/
echo json_encode([ echo json_encode($result);
'sent' => $result,
]);
break; break;
} }

View File

@ -176,12 +176,12 @@ echo '
data = JSON.parse(data); data = JSON.parse(data);
buttonRestore(btn, restore); buttonRestore(btn, restore);
if (data.sent) { if (data.code == "200") {
swal("'.tr('Fattura inviata!').'", "'.tr('Fattura inoltrata con successo').'", "success"); swal("'.tr('Fattura inviata!').'", data.message, "success");
$(btn).attr("disabled", true).addClass("disabled"); $(btn).attr("disabled", true).addClass("disabled");
} else { } else {
swal("'.tr('Invio fallito').'", "'.tr("L'invio della fattura è fallito").'", "error"); swal("'.tr('Invio fallito').'", data.code + " - " + data.message, "error");
} }
}, },
error: function(data) { error: function(data) {

View File

@ -27,9 +27,7 @@ class Interaction extends Connection
$body = static::responseBody($response); $body = static::responseBody($response);
if (!empty($body['sent'])) { return $body;
return true;
}
} catch (UnexpectedValueException $e) { } catch (UnexpectedValueException $e) {
} }

View File

@ -18,14 +18,18 @@ class Interaction extends Connection
$response = static::request('POST', 'get_fatture_da_importare'); $response = static::request('POST', 'get_fatture_da_importare');
$body = static::responseBody($response); $body = static::responseBody($response);
$list = $body['results']; $code = $body['code'];
$files = glob($directory.'/*.xml'); if($code=='200'){
foreach ($files as $file) { $list = $body['results'];
$list[] = basename($file);
$files = glob($directory.'/*.xml');
foreach ($files as $file) {
$list[] = basename($file);
}
return array_clean($list);
} }
return array_clean($list);
} }
public static function getImportXML($name) public static function getImportXML($name)
@ -44,4 +48,21 @@ class Interaction extends Connection
return $name; 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;
}
} }