Giter Site home page Giter Site logo

php-validatore-fattura-elettronica's Introduction

Validatore di XML della Fattura Elettronica

Latest Stable Version Downloads Integrate Code Coverage

WARNING: This package only works for ITALIAN standards!

Installazione

composer require slam/php-validatore-fattura-elettronica

Utilizzo

use SlamFatturaElettronica\Validator;

$feValidator = new Validator();
$feValidator->assertValidXml('<xml ...>');

// In caso di struttura XML errata, viene lanciata una
//      SlamFatturaElettronica\Exception\InvalidXmlStructureException
// In caso di XML valido ma non aderente all'XSD, viene lanciata una
//      SlamFatturaElettronica\Exception\InvalidXsdStructureComplianceException

Elencare tutte le eccezioni

use SlamFatturaElettronica\Validator;

$feValidator = new Validator();
$feValidator->getAllExceptions('<xml ...>');

// Restituisce un array contentente le eccezioni rilevati. Se non ci sono errori l'array sarà vuoto:

Notifiche

use SlamFatturaElettronica\Validator;

$feValidator = new Validator();
$feValidator->assertValidXml('<xml ...>', Validator::XSD_MESSAGGI_LATEST);

Riferimenti

I due siti di riferimento sono al momento:

  1. https://www.agenziaentrate.gov.it/wps/content/Nsilib/Nsi/Schede/Comunicazioni/Fatture+e+corrispettivi/Fatture+e+corrispettivi+ST/ST+invio+di+fatturazione+elettronica/?page=schedecomunicazioni
  2. http://www.fatturapa.gov.it/export/fatturazione/it/normativa/f-2.htm

Gli XSD usati da questa libreria sono quelli presi dal primo dei due siti, ovvero www.agenziaentrate.gov.it, che a dispetto del numero di versione esplicitato sembra quello più aggiornato (vedi ad esempio tra i tipi di documento la differenza su Autofattura).

Validazione Email in versione 1.2.1

La versione 1.2.1 introduce una regex per la validazione delle email, che tuttavia è costruita male. Visto che la finalità di questa libreria è di più ampio respiro, è stata sovrascritta la regex delle email con una più permissiva. La validazione della mail è in capo all'utente:

diff --git a/xsd/Schema_VFPR121a.xsd b/xsd/Schema_VFPR121a.xsd
index e999199..fa5696b 100644
--- a/xsd/Schema_VFPR121a.xsd
+++ b/xsd/Schema_VFPR121a.xsd
@@ -1364,8 +1364,9 @@
   </xs:simpleType>
   <xs:simpleType name="EmailType">
     <xs:restriction base="xs:token">
+      <xs:minLength value="7" />
       <xs:maxLength value="256" />
-      <xs:pattern value="([!#-'*+/-9=?A-Z^-~-]+(\.[!#-'*+/-9=?A-Z^-~-]+)*|&quot;(\[\]!#-[^-~ \t]|(\\[\t -~]))+&quot;)@([!#-'*+/-9=?A-Z^-~-]+(\.[!#-'*+/-9=?A-Z^-~-]+)*|\[[\t -Z^-~]*\])" />
+      <xs:pattern value=".+@.+[.]+.+" />
     </xs:restriction>
   </xs:simpleType>
   <xs:simpleType name="EmailContattiType">

php-validatore-fattura-elettronica's People

Contributors

aded avatar dependabot[bot] avatar renovate[bot] avatar slamdunk avatar tox82 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-validatore-fattura-elettronica's Issues

DOMDocument::schemaValidateSource(): Element 'RiferimentoNormativo'

Buondies !!! 😁😁
Oggi abbiamo aggiunto dei dati alla fattura XML per Bollo ed esenzione..
Il validator Valida tutti questi campi ?
PS: nel post di prima avevamo fatto un'errore. Ma chiediamo solo conferma
image

Ti riporto i campi che inseriremo:
image

image

image

image

image

image

Dovrebbero esserci tutti. Il documento è stato preso da un gestionale MOLTO utilizzato.
Noi per adesso abbiamo disabilitato la validazione per continuare a generare l'xml.
Se si da un'occhio anche qui, ne parlano di questi campi

Element 'PECDestinatario': [facet 'pattern'] The value '[email protected]' is not accepted by the pattern

Dopo l'ultimo aggiornamento si presenta un problema nella validazione di indirizzi PEC. L'errore generato è

DOMDocument::schemaValidateSource(): Element 'PECDestinatario': [facet 'pattern'] The value '[email protected]' is not accepted by the pattern '([!#-'*+/-9=?A-Z^-~-]+(\\.[!#-'*+/-9=?A-Z^-~-]+)*|"(\\[\\]!#-[^-~ \\t]|(\\\\[\\t -~]))+")@([!#-'*+/-9=?A-Z^-~-]+(\\.[!#-'*+/-9=?A-Z^-~-]+)*|\\[[\\t -Z^-~]*\\])'.

Sembra che il problema sia il trattino - nell'indirizzo

Unable to test validation

Hi, I am trying to test your module with your instructions:

use SlamFatturaElettronica\Validator;

$feValidator = new Validator();
$feValidator->assertValidXml('xml data goes here');

But I get error

Fatal error: Uncaught Error: Class 'SlamFatturaElettronica\Validator' not found in /Users/home/Sites/xml-val/test.php

Any help will be greatly appreciated, I am trying to incorporate a XML validator for Costa Rica Factura Electrónica.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Use matchDepNames instead of matchPackageNames

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Pending Branch Automerge

These updates await pending status checks before automerging. Click on a checkbox to abort the branch automerge, and create a PR instead.

  • Update dependency phpstan/phpstan to ^1.11.1

Detected dependencies

composer
composer.json
  • php ~8.2.0 || ~8.3.0
  • phpstan/phpstan ^1.11.0
  • phpstan/phpstan-phpunit ^1.4.0
  • phpstan/phpstan-strict-rules ^1.6.0
  • phpunit/phpunit ^11.1.3
  • slam/php-cs-fixer-extensions ^3.10.0
github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • shivammathur/setup-php v2
  • actions/checkout v4
  • shivammathur/setup-php v2
  • codecov/codecov-action v4
  • actions/checkout v4
  • shivammathur/setup-php v2
  • actions/checkout v4
  • shivammathur/setup-php v2

  • Check this box to trigger a request for Renovate to run again on this repository

Errori in lingua inglese

Ottimo progetto, è quello che cercavo!

Domanda forse banale: quando la validazione dà errore mostra degli errori in lingua inglese, ad esempio su metto ITA invece di IT e l'errore è:

DOMDocument::schemaValidateSource(): Element 'IdPaese': 'ITA' is not a valid value of the atomic type '{http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2}NazioneType'.

Non so come funzioni la validazione, ma se volessi avere la versione in italiano come dovrei fare?

errore DOMDocument::loadXML(): Start tag expected, '&lt;' not found in Entity

Ciao,
ho utilizzato questo codice :
$xml = simplexml_load_file($file_locale); $feValidator = new Validator(); $feValidator->assertValidXml($xml->asXML());
e ricevo questo errore :

 Fatal error: Uncaught SlamFatturaElettronica\Exception\InvalidXsdStructureComplianceException: DOMDocument::schemaValidateSource(): Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': The QName value '{http://www.w3.org/2000/09/xmldsig#}Signature' does not resolve to a(n) element declaration. in C:\xampp2\htdocs\roberta\vendor\slam\php-validatore-fattura-elettronica\lib\Validator.php on line 36

Come posso risolverlo?

Grazie

[SlamFatturaElettronica\Exception\InvalidXmlStructureException] simplexml_load_string(): namespace error : xmlns:pfx6: 'http://www.example.com/XSD riepilogo_fattura_ordinaria_v1.2_mod.xsd' is not a valid URI

Ciao, ho notato un problema quando nell'intestazione della fattura c'è un namespace che contiene uno spazio (mi è capitato più volte di ricevere fatture che lo contenevano, quindi sono passate dal Servizio di Interscambio). Per esempio:

Funziona
<p:FatturaElettronica ... xmlns:pfx6="http://www.example.com/XSD_riepilogo_fattura_ordinaria_v1.2_mod.xsd" >

Non funziona
<p:FatturaElettronica ... xmlns:pfx6="http://www.example.com/XSD riepilogo_fattura_ordinaria_v1.2_mod.xsd" >

L'errore generato nel secondo caso è [SlamFatturaElettronica\Exception\InvalidXmlStructureException] simplexml_load_string(): namespace error : xmlns:pfx6: 'http://www.example.com/XSD riepilogo_fattura_ordinaria_v1.2_mod.xsd' is not a valid URI

Allego due files di esempio

test_funzionante.txt
test_non_funzionante.txt

Metodo getAllExceptions restituisce un array troppo prolisso

In seguito alla pull request #43 , ho notato che gli errori vengono riportati in modo più prolisso rispetto a come l'avevo implementato io.

Secondo me l'array dovrebbe contenere solo gli errori effettivamente rilevati, senza stack trace o informazioni sull'eccezione generata. Questo perché gli errori in questo modo risulterebbero """"accettabili"""" anche come informazione da dare all'utente:

Element 'CodiceDestinatario': [facet 'pattern'] The value '' is not accepted by the pattern '[A-Z0-9]{6,7}'.

Lo stesso errore, nella patch rilasciata, secondo me contiene troppe informazioni per quel tipo di utilizzo:

SlamFatturaElettronica\Exception\InvalidXsdStructureComplianceException: Element 'CodiceDestinatario': [facet 'pattern'] The value '' is not accepted by the pattern '[A-Z0-9]{6,7}'. in /var/www/gktmanager/vendor/slam/php-validatore-fattura-elettronica/lib/Validator.php:63 Stack trace: #0 [internal function]: SlamFatturaElettronica\Validator::SlamFatturaElettronica\{closure}() #1 /var/www/gktmanager/vendor/slam/php-validatore-fattura-elettronica/lib/Validator.php(63): DOMDocument->schemaValidateSource() #2 /var/www/gktmanager/plugins/exportFE/src/SdiValidator.php(27): SlamFatturaElettronica\Validator->getAllExceptions() #3 /var/www/gktmanager/plugins/exportFE/edit.php(112): Plugins\ExportFE\SdiValidator::valida() #4 /var/www/gktmanager/include/manager.php(245): include('...') #5 /var/www/gktmanager/editor.php(425): include('...') #6 {main}

Può avere senso mantenere separate le logiche, e gestire da una parte gli errori semplici e dall'altra le eccezioni?

DOMDocument::schemaValidateSource(): Invalid Schema

Salve,
Ad ogni tentativo di validazione di fattura elettronica esce sempre questo errore.
Sia per fatture create da template sia per fatture create da zero;
Se evito la validazione le fatture create sono valide
Grazie per la risposta

Supporto a versioni più vecchie di PHP

In seguito a #46 , #41 ecc.

Anche se non è ottimale è abbastanza comune che su progetti grossi per un motivo o per l'altro non si riesca a restare al passo con le versioni di PHP, finendo con il restare indietro di qualche versione nell'attesa di poter fare l'aggiornamento.

Se non ci sono limitazioni tecniche sarebbe comodo se il validatore fosse configurato funzionare su tutte le versioni di PHP tecnicamente supportate.
In altre parole, se il progetto può girare su php 8.0 (o 7.4, o ancora più indietro) si può lasciare questa versione nel require di composer.json? Altrimenti tutti i software che non riescono a stare al passo rischiano di restare tagliati fuori dagli aggiornamenti di questa libreria.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.