php-e-invoice-it icon indicating copy to clipboard operation
php-e-invoice-it copied to clipboard

Allow invoices and notices to be loaded by contents, not only via-files

Open MwSpaceLLC opened this issue 6 years ago • 5 comments

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!

MwSpaceLLC avatar Feb 03 '19 19:02 MwSpaceLLC

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 :-)

aded avatar Feb 05 '19 12:02 aded

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.

aded avatar Feb 05 '19 15:02 aded

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;
  }

MwSpaceLLC avatar Feb 06 '19 09:02 MwSpaceLLC

Pushato bugfix :-)

aded avatar Feb 06 '19 10:02 aded

Ciao, ho un db (MYSQL) dove ho i dati utili per poter :

  1. generare una fattura elettronica
  2. 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

sroselli avatar Oct 22 '20 17:10 sroselli