mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Correzioni per l'API osmservices
This commit is contained in:
parent
5a0ed16733
commit
97fb5cd324
@ -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,
|
||||
]);
|
||||
|
||||
|
@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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 = '';
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user