openstamanager/plugins/importFE/src/Interaction.php

80 lines
2.3 KiB
PHP
Raw Normal View History

2018-11-30 15:33:25 +01:00
<?php
namespace Plugins\ImportFE;
2018-12-14 12:50:44 +01:00
use Plugins\ExportFE\Connection;
2018-11-30 15:33:25 +01:00
/**
* Classe per l'interazione con API esterne.
*
* @since 2.4.3
*/
2018-12-14 12:50:44 +01:00
class Interaction extends Connection
2018-11-30 15:33:25 +01:00
{
public static function listToImport()
{
$directory = FatturaElettronica::getImportDirectory();
2018-12-14 12:50:44 +01:00
$response = static::request('POST', 'get_fatture_da_importare');
$body = static::responseBody($response);
2018-11-30 15:33:25 +01:00
2019-01-22 08:59:11 +01:00
$code = $body['code'];
2018-11-30 15:33:25 +01:00
2019-01-22 08:59:11 +01:00
if($code=='200'){
$files = $body['results'];
2019-01-22 08:59:11 +01:00
foreach ($files as $file) {
/**
* Verifico che l'XML non sia già stato importato nel db
*/
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) {
2019-01-22 08:59:11 +01:00
$list[] = basename($file);
}
}
2019-01-22 08:59:11 +01:00
}
2018-11-30 15:33:25 +01:00
2019-01-22 08:59:11 +01:00
return array_clean($list);
}
2018-11-30 15:33:25 +01:00
}
public static function getImportXML($name)
{
$directory = FatturaElettronica::getImportDirectory();
$file = $directory.'/'.$name;
if (!file_exists($file)) {
2018-12-14 12:50:44 +01:00
$response = static::request('POST', 'get_fattura_da_importare', [
2018-11-30 15:33:25 +01:00
'name' => $name,
]);
2018-12-14 12:50:44 +01:00
$body = static::responseBody($response);
2018-11-30 15:33:25 +01:00
2018-12-14 12:50:44 +01:00
FatturaElettronica::store($name, $body['content']);
2018-11-30 15:33:25 +01:00
}
return $name;
}
2019-01-22 08:59:11 +01:00
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;
}
2018-11-30 15:33:25 +01:00
}