Giter VIP home page Giter VIP logo

buzoncfdi-cfdireader's Introduction

eclipxe/buzoncfdi-cfdireader

Library to read and validate a Mexican CFDI 3.2 (Comprobantre Fiscal por Internet)

Latest Version Software License Build Status Scrutinizer Coverage Status Total Downloads SensioLabsInsight

This library open an Xml CFDI and read it as a SimpleXML (without namespaces) for easy access.

It also validates the CFDI agains it's XSD files (using Xml Schema Validator library).

This library is part of buzoncfdi project, be aware that this could change since the hole project is on development.

Install

Install using composer like composer require eclipxe/buzoncfdi-cfdireader

Basic usage

<?php
// get the contents from a file or whatever your source is
$xml = file_get_contents('some-cfdi-example.xml');

// create the reader
$reader = new \CFDIReader\CFDIReader($xml);

// The root element is retrieved by comprobante function, it returns always a new instance (cloned) of the root element
$cfdi = $reader->comprobante();

// all the nodes and attributes first letter is in lower case except if the attribute is all upper case
echo $cfdi->complemento->timbreFiscalDigital["UUID"];

scripts/validate.php

Use php scripts/validate.php [file1.xml] [file2.xml] to test CFDIs and see the results.

Create a reader

The CFDIReader class is immutable, it only perform the following checks:

Using the factory

The CFDIFactory allow a common way to create CFDIReaders using SchemaValidator and PostValidator.

The SchemaValidator is a tool that validates a XML against its multiple XSD files creating a root schema and importing all the schemas listed in the XML by schemaLocation nodes.

The PostValidator do some specific checks about the CFDI, this includes Conceptos, Fechas, Impuestos and Totales.

About Addendas and XML Validation

why don't you create valid XML files!?

An XML file has a strict specification, if it includes XML Schemas then the specification must be followed.

The CFDI spec say that it is valid to include additional nodes inside the Addenda but it must follow the XML specification (including namespaces and schemas). The problem is that -since the addenda is not part of the source string- the emmiters can include additional nodes inside the Addenda after it was signed without breaking the CFDI but breaking the XML validation.

So, can I edit a CFDI? Yes. as long you dont change any content of the source string (cadena de origen)

I has created an utility named CFDICleaner that removes Addendas and unused namespaces declarations. You can use this tool to validate the document without this garbage.

<?php
// $content as a clean version of the
$content = \CFDIReader\CFDICleaner::staticClean(file_get_contents('cfdi-dirty.xml'));

Contributing

There is a lot of work, this is an open source project that try to offer a framework agnostic way to deal with Mexican CFDI version 3.2.

Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in the TODO and CHANGELOG files.

License

The eclipxe/buzoncfdi-cfdireader library is copyright © Carlos C Soto and licensed for use under the MIT License (MIT). Please see LICENSE for more information.

buzoncfdi-cfdireader's People

Contributors

eclipxe13 avatar

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.