Git Product home page Git Product logo

mapubl's Introduction

Dragon MapXmlUBL

Library that allows you to read electronic documents such as invoices, tickets and the answers given by SUNAT (CDR). Se requiere mínimo .Net Core 3.1

Installation

Install-Package Dragon.MapUBL -Version 1.1.0

Example of use

Invoice

static void Main(string[] args) 
{
        XmlSerializer serial = new XmlSerializer(typeof(InvoiceType));
        string path = UniversalFilePathResolver.ResolvePath(@"~\xml\20553510661-01-F001-1.xml");
        FileStream fs = new FileStream($"{path}", FileMode.Open);
        var _comprobante = (InvoiceType)serial.Deserialize(fs);
        var invoices = _comprobante.InvoiceLine.Select(c => new Invoice
        {
            Id = c.ID.Value,
            Quantity = c.InvoicedQuantity.Value.ToString(),
            Ammount = c.LineExtensionAmount.Value.ToString(),
            Description = string.Join("; ", c.Item.Description.Select(x => x.Value))
        }).ToList();

        Console.ForegroundColor = ConsoleColor.DarkGreen;
        Console.BackgroundColor = ConsoleColor.Green;
        Console.WriteLine($"ID  |Description    |Quantity  |Ammount |");
        Console.ResetColor();
        foreach (var item in invoices)
        {
            Console.WriteLine($"{item.Id}|{item.Description}|{item.Quantity}|{item.Ammount}|");
        }
        Console.ReadKey();
}

CDR

static void Main(string[] args)
{

        var cdrResponse = new CdrResponse();

        string base64 = Convert.ToBase64String(File.ReadAllBytes(UniversalFilePathResolver.ResolvePath(@"~\zip\R20602690866-01-FF60-00000004.zip")));

        XmlSerializer serial = new XmlSerializer(typeof(ApplicationResponseType));

        var returnByte = Convert.FromBase64String(base64);
        using (var memRespuesta = new MemoryStream(returnByte))
        {
            using (var zipFile = Ionic.Zip.ZipFile.Read(memRespuesta))
            {
                foreach (var entry in zipFile.Entries)
                {
                    if (!entry.FileName.EndsWith(".xml")) continue;

                    using (var ms = new MemoryStream())
                    {


                        entry.Extract(ms);
                        ms.Position = 0;
                        var responseReader = new StreamReader(ms);
                        var applicationResponseType = (ApplicationResponseType)serial.Deserialize(responseReader);

                        cdrResponse.ID = applicationResponseType.ID.Value;
                        cdrResponse.ProcessReceptionId = applicationResponseType.ID.Value;
                        cdrResponse.ResponseDescription = applicationResponseType.DocumentResponse[0].Response.Description != null ? string.Join("; ", applicationResponseType.DocumentResponse[0].Response.Description.Select(x => x.Value)) : string.Empty;
                        cdrResponse.ResponseCode = applicationResponseType.DocumentResponse[0].Response.ResponseCode.Value;
                        cdrResponse.ResponseNote = applicationResponseType.Note != null ? string.Join("; ", applicationResponseType.Note.Select(x => x.Value)) : string.Empty;
                    }
                }
            }
        }
        Console.WriteLine($"COD: {cdrResponse.ResponseCode}, DESCRIPCION: {cdrResponse.ResponseDescription}");
        Console.ReadKey();
    }

mapubl's People

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.