php-e-invoice-it
php-e-invoice-it copied to clipboard
Allow invoices and notices to be loaded by contents, not only via-files
Ciao Ale scusa il disturbo. Abbiamo aggiornato l'applicazione per lavorare esclusivamente con un Filesystem Bucket, Ci siamo accorti che possiamo passare solamente il contenuto del file e NON la dir.
Esempio funsione load() in FileSdIBase per invio fatture:
/**
* Load Signed Invoice from Bucket
*/
$fileSdI->load(Storage::get($signdir));
$response = new RispostaSdIRiceviFile($client->RiceviFile($fileSdI));
la funzione GET ci ritorna il contenuto di un file nel Bucket 'PRIVATE': non accessibile.
Ma nella funzione load() file_get_contents ovviamente non può essere instanziato.
public function load( $invoice )
{
if ($invoice instanceOf \Taocomp\Einvoicing\AbstractDocument) {
$this->NomeFile = $invoice->getFilename();
$this->File = $invoice->asXML();
} else if (true === is_readable($invoice)) {
$this->NomeFile = basename($invoice);
$this->File = file_get_contents($invoice);
$this->removeBOM();
} else {
throw new \Exception("Invalid file or object '$invoice'");
}
return $this;
}
Anche noi abbiamo dovuto modificare delle librerie perchè non possono più accedere ai file direttamente.
ora, Come facciamo ? Io posso anche modificare la classe, ma le modifiche le perderei all'aggiornamento.
Potresti aggiungere per esempio loadContents() ??? Io l'ho dovuta aggiungere manualmente in DUE FILE:
- FileSdI.php
/**
* @param $filename
* @param $filecontents
* @return $this|FileSdIBase
* @throws \Exception
*/
public function loadContents($filename, $filecontents)
{
parent::loadContents($filename, $filecontents);
$xml = simplexml_load_string($filecontents);
if (!$xml->IdentificativoSdI) {
throw new \Exception("Cannot find 'IdentificativoSdI' File Contents");
}
$this->IdentificativoSdI = $xml->IdentificativoSdI;
return $this;
}
- FileSdIBase.php
/**
* @param $filename
* @param $filecontents
* @return $this
* @throws \Exception
*/
public function loadContents($filename, $filecontents)
{
$this->NomeFile = $filename;
$this->File = $filecontents;
$this->removeBOM();
return $this;
}
Ovviamente se l'aggiungi, magari su tutte le funzioni che richiedono una dir file di avere anche la possibilità di passare direttamente anche il contenuto. 😘😘
Aspetto tue, Salutissimi!
Ok, filesdi e filesdibase stanno in php-sdicoop-client :-) ma ho compreso la questione, più tardi pusho un aggiornamento. Probabilmente aggiungerò un secondo parametro opzionale a load() per il contenuto.
Fare la stessa cosa per la classe FatturaElettronica di questo repo potrebbe richiedere un po' più di tempo invece. Ma adesso vediamo :-)
Aggiornato php-sdicoop-client, adesso il metodo load può essere usato anche con un secondo parametro come segue:
$fileSdi->load($filename, $contents);
Lascio aperto l'issue come promemoria per fare la stessa cosa qui su AbstractDocument.
Ale scusa, come ti ho precisato sulla funzione loadcontents()
Il metodo simplexml_load_file() in FileSdI.php non va bene :
public function load( $file, $contents = null )
{
parent::load($file, $contents);
$xml = simplexml_load_file($file);
if (!property_exists($xml, 'IdentificativoSdI')) {
throw new \Exception("Cannot find 'IdentificativoSdI' in '$file'");
}
$this->IdentificativoSdI = $xml->IdentificativoSdI;
return $this;
}
Io avevo utilizzato in metodo simplexml_load_string()
Ora lo modifico io, ma aspetto tue 🐱🚀🐱🚀 :
/**
* @param $file
* @param null $contents
* @return $this|FileSdIBase
* @throws \Exception
*/
public function load($file, $contents = null)
{
parent::load($file, $contents);
if (null !== $contents && is_string($contents)) {
$xml = simplexml_load_string($contents);
} else {
$xml = simplexml_load_file($file);
}
if (!property_exists($xml, 'IdentificativoSdI')) {
throw new \Exception("Cannot find 'IdentificativoSdI' in '$file'");
}
$this->IdentificativoSdI = $xml->IdentificativoSdI;
return $this;
}
Pushato bugfix :-)
Ciao, ho un db (MYSQL) dove ho i dati utili per poter :
- generare una fattura elettronica
- Inviare il documento in formato XML alla PA
Non ho capito come poter inviare i dati dal DB ai moduli, in modo da poter generare appunto un documento. Potresti aiutarmi con qualche esempio ?
Ringrazio in anticipo