コード例 #1
0
        void LlenarMontosTotales(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            MonetaryTotalType oTotal = new MonetaryTotalType
            {
                LineExtensionAmount = new LineExtensionAmountType
                {
                    Value      = Comprobante.TotalValorVenta,
                    currencyID = Comprobante.Moneda.Trim()
                },
                TaxInclusiveAmount = new TaxInclusiveAmountType
                {
                    Value      = Comprobante.TotalPrecioVenta,
                    currencyID = Comprobante.Moneda.Trim()
                },
                PayableAmount = new PayableAmountType
                {
                    Value      = Comprobante.ImporteTotal,
                    currencyID = Comprobante.Moneda.Trim()
                },
                ChargeTotalAmount = new ChargeTotalAmountType
                {
                    Value      = Comprobante.TotalCargo,
                    currencyID = Comprobante.Moneda.Trim()
                },
                AllowanceTotalAmount = new AllowanceTotalAmountType
                {
                    Value      = Comprobante.TotalDescuento,
                    currencyID = Comprobante.Moneda.Trim()
                }
            };

            debitNote.RequestedMonetaryTotal = oTotal;
        }
コード例 #2
0
        void LlenarMontosIGV(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            List <TaxSubtotalType> oListaSubtotal = new List <TaxSubtotalType>();

            if (Comprobante.MontoTotales != null)
            {
                if (Comprobante.MontoTotales.Gravado != null)
                {
                    if (Comprobante.MontoTotales.Gravado.GravadoIGV != null)
                    {
                        TaxSubtotalType oTotalGravado = LlenarSubTotalCabecera(Comprobante.MontoTotales.Gravado.GravadoIGV.MontoBase, Comprobante.MontoTotales.Gravado.GravadoIGV.MontoTotalImpuesto, Comprobante.Moneda, Comprobante.MontoTotales.Gravado.GravadoIGV.Porcentaje, "1000", "IGV", "VAT");
                        oListaSubtotal.Add(oTotalGravado);
                    }
                }
            }


            TaxTotalType oTaxTotal = new TaxTotalType
            {
                TaxAmount = new TaxAmountType
                {
                    Value      = Comprobante.TotalImpuesto,
                    currencyID = Comprobante.Moneda
                },
                TaxSubtotal = oListaSubtotal.ToArray()
            };

            debitNote.TaxTotal = new TaxTotalType[] { oTaxTotal };
        }
コード例 #3
0
        private DataTable FnTablaDetalle(DebitNoteType ocomprobante)
        {
            DataTable dtDetalle = new DataTable();

            dtDetalle.Columns.Add(new DataColumn("Item", typeof(string)));
            dtDetalle.Columns.Add(new DataColumn("Descripcion", typeof(string)));
            dtDetalle.Columns.Add(new DataColumn("UM", typeof(string)));
            dtDetalle.Columns.Add(new DataColumn("VU", typeof(string)));
            dtDetalle.Columns.Add(new DataColumn("PU", typeof(string)));
            dtDetalle.Columns.Add(new DataColumn("Cantidad", typeof(string)));
            dtDetalle.Columns.Add(new DataColumn("ImporteSinIGV", typeof(string)));

            DataRow fila;

            fila = dtDetalle.NewRow();

            if (ocomprobante.DebitNoteLine != null)
            {
                foreach (DebitNoteLineType detalle in ocomprobante.DebitNoteLine)
                {
                    fila["Item"]          = FnValidarNulo(detalle.ID.Value.ToString());
                    fila["Descripcion"]   = FnValidarNulo(detalle.Item.Description[0].Value.ToString());
                    fila["UM"]            = "UND";
                    fila["VU"]            = FnValidarNulo(detalle.PricingReference.AlternativeConditionPrice[0].PriceAmount.Value.ToString());
                    fila["PU"]            = FnValidarNulo(detalle.PricingReference.AlternativeConditionPrice[0].PriceAmount.Value.ToString());
                    fila["Cantidad"]      = FnValidarNulo(detalle.DebitedQuantity.Value.ToString());
                    fila["ImporteSinIGV"] = FnValidarNulo(detalle.LineExtensionAmount.Value.ToString());
                }
            }

            dtDetalle.Rows.Add(fila);

            return(dtDetalle);
        }
コード例 #4
0
        private DataTable FnTablaReceptor(DebitNoteType ocomprobante)
        {
            DataTable dtReceptor = new DataTable();

            dtReceptor.Columns.Add(new DataColumn("RucReceptor", typeof(string)));
            dtReceptor.Columns.Add(new DataColumn("RazonSocialReceptor", typeof(string)));
            dtReceptor.Columns.Add(new DataColumn("NombreComercialReceptor", typeof(string)));
            dtReceptor.Columns.Add(new DataColumn("DepartamentoReceptor", typeof(string)));
            dtReceptor.Columns.Add(new DataColumn("ProvinciaReceptor", typeof(string)));
            dtReceptor.Columns.Add(new DataColumn("DistritoReceptor", typeof(string)));
            dtReceptor.Columns.Add(new DataColumn("DireccionReceptor", typeof(string)));

            DataRow fila;

            fila = dtReceptor.NewRow();

            if (ocomprobante.AccountingCustomerParty != null)
            {
                fila["RucReceptor"]             = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyIdentification[0].ID.Value.ToString());
                fila["RazonSocialReceptor"]     = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyLegalEntity[0].RegistrationName.Value.ToString());
                fila["NombreComercialReceptor"] = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyName[0].Name.Value.ToString());
                fila["DepartamentoReceptor"]    = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyLegalEntity[0].RegistrationAddress.CountrySubentity.Value.ToString());
                fila["ProvinciaReceptor"]       = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyLegalEntity[0].RegistrationAddress.CityName.Value.ToString());
                fila["DistritoReceptor"]        = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyLegalEntity[0].RegistrationAddress.District.Value.ToString());
                fila["DireccionReceptor"]       = FnValidarNulo(ocomprobante.AccountingCustomerParty.Party.PartyLegalEntity[0].RegistrationAddress.AddressLine[0].Line.Value.ToString());
            }

            dtReceptor.Rows.Add(fila);

            return(dtReceptor);
        }
コード例 #5
0
        void CrearXML(ref DebitNoteType debitNote, En_ComprobanteElectronico Comprobante, ref string codigoHASH, ref byte[] archivoXML, ref string firma)
        {
            XmlSerializer oxmlSerializer  = new XmlSerializer(typeof(DebitNoteType));
            var           xmlNameSpaceNom = new XmlSerializerNamespaces();

            xmlNameSpaceNom.Add("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
            xmlNameSpaceNom.Add("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
            xmlNameSpaceNom.Add("ccts", "urn:un:unece:uncefact:documentation:2");
            xmlNameSpaceNom.Add("ds", "http://www.w3.org/2000/09/xmldsig#");
            xmlNameSpaceNom.Add("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
            xmlNameSpaceNom.Add("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
            xmlNameSpaceNom.Add("sac", "urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1");
            xmlNameSpaceNom.Add("udt", "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
            xmlNameSpaceNom.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            string carpetaTemp = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temporal");
            string nombreXml   = string.Format("{0}-{1}-{2}.xml", Comprobante.Emisor.NumeroDocumentoIdentidad, Comprobante.TipoComprobante, Comprobante.SerieNumero);
            string ruta        = Path.Combine(carpetaTemp, nombreXml);

            string            sxml      = "";
            Encoding          utf8noBOM = new UTF8Encoding(false);
            XmlWriterSettings settings  = new XmlWriterSettings
            {
                Indent   = true,
                Encoding = utf8noBOM
            };

            // Se ha creado una nueva clase llamada StringWriterWithEncoding que grabaen formato UTF-8
            // Por defecto la clase StringWriter graba con UTF-16 y no se podía firmar, con UTF-8 ya se puede
            using (var sw = new StringWriterWithEncoding())
            {
                using (XmlWriter writter = XmlWriter.Create(sw, settings))
                {
                    oxmlSerializer.Serialize(writter, debitNote, xmlNameSpaceNom);
                    sxml = sw.ToString();
                }
            }

            // Se elimina el tag temporal creado dentro de ext:ExtensionContent y en su lugar se colocará la firma
            string cadena  = "<Borrar xmlns=\"\" />";
            int    tamanio = cadena.Length;
            int    indice  = sxml.IndexOf(cadena);

            sxml = sxml.Remove(indice, tamanio);

            // Se sigue grabando el archivo como siempre
            File.WriteAllText(ruta, sxml, Encoding.UTF8);

            // Firma del comprobante
            var objFirma = new Firma.FirmaComprobante();
            var document = new XmlDocument();

            document.Load(ruta);
            // Enviamos el RUC de la empresa, para ello el certificado debe estar registrado
            objFirma.FirmarXml(document, Comprobante.Emisor.NumeroDocumentoIdentidad, ref codigoHASH, ref firma);
            document.Save(ruta);

            archivoXML = File.ReadAllBytes(ruta);
        }
コード例 #6
0
        private DataTable FnTablaReferenciadoDebitNote(DebitNoteType ocomprobante)
        {
            DataTable dtSustento = new DataTable();

            dtSustento.Columns.Add(new DataColumn("DocumentoReferenciado", typeof(string)));
            dtSustento.Columns.Add(new DataColumn("TipoDocumentoReferenciado", typeof(string)));
            dtSustento.Columns.Add(new DataColumn("Sustento", typeof(string)));


            DataRow fila;

            fila = dtSustento.NewRow();


            if (ocomprobante.BillingReference != null)
            {
                foreach (BillingReferenceType oreferencia in ocomprobante.BillingReference)
                {
                    DocumentReferenceType oDocument = oreferencia.InvoiceDocumentReference;

                    fila["DocumentoReferenciado"] = FnValidarNulo(oDocument.ID.Value.ToString());

                    if (oDocument.DocumentTypeCode.Value.ToString() == "01")
                    {
                        fila["TipoDocumentoReferenciado"] = "Factura";
                    }
                    else if (oDocument.DocumentTypeCode.Value.ToString() == "03")
                    {
                        fila["TipoDocumentoReferenciado"] = "Boleta";
                    }
                }
            }

            if (ocomprobante.DiscrepancyResponse != null)
            {
                foreach (ResponseType oreferencia in ocomprobante.DiscrepancyResponse)
                {
                    DescriptionType[] oDocument = oreferencia.Description;
                    string            sustento  = "";
                    foreach (DescriptionType valor in oDocument)
                    {
                        sustento += valor.Value.ToString() + Environment.NewLine;
                    }
                    fila["Sustento"] = sustento;
                }
            }

            dtSustento.Rows.Add(fila);

            return(dtSustento);
        }
コード例 #7
0
        public En_Respuesta RegistroComprobante(En_ComprobanteElectronico Comprobante)
        {
            log.Info("Invocación al método RegistroComprobante");
            En_Respuesta oRespuesta = new En_Respuesta();
            string       rutaXML    = "";

            try
            {
                DebitNoteType debitNote = new DebitNoteType();
                LlenarCabecera(Comprobante, ref debitNote);
                LlenarDocumentoRefenciado(Comprobante, ref debitNote);
                LlenarEmisor(Comprobante.Emisor, ref debitNote);
                LlenarReceptor(Comprobante.Receptor, ref debitNote);
                LlenarDescuentoCargo(Comprobante, ref debitNote);
                LlenarMontosIGV(Comprobante, ref debitNote);
                LlenarMontosTotales(Comprobante, ref debitNote);
                LlenarDetalle(Comprobante, ref debitNote);

                string codigoHASH = "", nombreXML = "", firma = "";
                byte[] archivoXML = null;
                nombreXML = string.Format("{0}-{1}-{2}.xml", Comprobante.Emisor.NumeroDocumentoIdentidad, Comprobante.TipoComprobante, Comprobante.SerieNumero);
                CrearXML(ref debitNote, Comprobante, ref codigoHASH, ref archivoXML, ref firma);

                string         mensajeRetorno = "";
                Lp_Comprobante lpComprobante  = new Lp_Comprobante();
                bool           resultado      = lpComprobante.InsertarComprobante(Comprobante, nombreXML, archivoXML, codigoHASH, firma, ref mensajeRetorno);

                oRespuesta.Codigo      = (resultado) ? "0" : "99";
                oRespuesta.Descripcion = mensajeRetorno;

                string carpetaTemp = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temporal");
                rutaXML = Path.Combine(carpetaTemp, nombreXML);
                if (File.Exists(rutaXML))
                {
                    File.Delete(rutaXML);
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Codigo      = "99";
                oRespuesta.Descripcion = "Ocurrió un error general, mensaje: " + ex.Message.ToString();
                if (rutaXML != "" && File.Exists(rutaXML))
                {
                    File.Delete(rutaXML);
                }
            }
            return(oRespuesta);
        }
コード例 #8
0
        void LlenarDescuentoCargo(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            List <AllowanceChargeType> oListaDescuentoCargo = new List <AllowanceChargeType>();

            foreach (En_DescuentoCargo oDescar in Comprobante.DescuentoCargo)
            {
                AllowanceChargeType oDescuentoCargo = new AllowanceChargeType
                {
                    ChargeIndicator = new ChargeIndicatorType
                    {
                        Value = oDescar.Indicador
                    },
                    AllowanceChargeReasonCode = new AllowanceChargeReasonCodeType
                    {
                        listAgencyName = "PE:SUNAT",
                        listName       = "Cargo/descuento",
                        listURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo53",
                        Value          = oDescar.CodigoMotivo
                    },
                    MultiplierFactorNumeric = new MultiplierFactorNumericType
                    {
                        Value = oDescar.Factor
                    },
                    Amount = new AmountType2
                    {
                        Value      = oDescar.MontoTotal,
                        currencyID = Comprobante.Moneda.Trim()
                    },
                    BaseAmount = new BaseAmountType
                    {
                        Value      = oDescar.MontoBase,
                        currencyID = Comprobante.Moneda.Trim()
                    }
                };
                oListaDescuentoCargo.Add(oDescuentoCargo);
            }
            debitNote.AllowanceCharge = oListaDescuentoCargo.ToArray();
        }
コード例 #9
0
        void LlenarCabecera(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            UBLExtensionType uBLExtensionType = new UBLExtensionType()
            {
                // Se crea un tag temporal llamado "Borrar", esto porque no he conseguido crear el tag
                // ext:ExtensionContent con un valor vacío
                ExtensionContent = new XmlDocument().CreateElement("Borrar")
            };

            UBLExtensionType[] ublExtensions = { uBLExtensionType };
            debitNote.UBLExtensions = ublExtensions;
            //Serie y Numero
            debitNote.ID = new IDType
            {
                Value = Comprobante.SerieNumero.Trim()
            };

            debitNote.UBLVersionID = new UBLVersionIDType
            {
                Value = "2.1"
            };

            debitNote.IssueDate = new IssueDateType
            {
                Value = Comprobante.FechaEmision
            };
            debitNote.IssueTime = new IssueTimeType
            {
                Value = Comprobante.HoraEmision
            };

            debitNote.DocumentCurrencyCode = new DocumentCurrencyCodeType
            {
                listAgencyName = "United Nations Economic Commission for Europe",
                listID         = "ISO 4217 Alpha",
                listName       = "Currency",
                Value          = Comprobante.Moneda.Trim()
            };

            List <NoteType> oListaNota = new List <NoteType>();

            foreach (En_Leyenda oNote in Comprobante.Leyenda)
            {
                NoteType oNota = new NoteType
                {
                    Value            = oNote.Valor,
                    languageLocaleID = oNote.Codigo
                };
                oListaNota.Add(oNota);
            }
            ;

            debitNote.Note = oListaNota.ToArray();



            debitNote.CustomizationID = new CustomizationIDType
            {
                Value = "2.0"
            };



            List <DocumentReferenceType> oListadocumento = new List <DocumentReferenceType>();

            foreach (En_DocumentoReferencia oreferen in Comprobante.DocumentoReferenciaDespacho)
            {
                DocumentReferenceType odocumento = new DocumentReferenceType
                {
                    ID = new IDType
                    {
                        Value = oreferen.SerieNumero.Trim()
                    },
                    IssueDate = new IssueDateType
                    {
                        Value = oreferen.Fecha.Trim()
                    },
                    DocumentTypeCode = new DocumentTypeCodeType
                    {
                        Value          = oreferen.TipoDocumento.Trim(),
                        listAgencyName = "PE:SUNAT",
                        listName       = "SUNAT:Identificador de guía relacionada",
                        listURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo12"
                    }
                };
                oListadocumento.Add(odocumento);
            }
            ;
            debitNote.DespatchDocumentReference = oListadocumento.ToArray();
        }
コード例 #10
0
        void LlenarDetalle(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            List <DebitNoteLineType> oListaDetalle = new List <DebitNoteLineType>();

            foreach (En_ComprobanteDetalle oDet in Comprobante.ComprobanteDetalle)
            {
                List <DescriptionType> oListaDescripcion = new List <DescriptionType>();

                DescriptionType oDescripcion = new DescriptionType();
                oDescripcion.Value = oDet.Descripcion;
                oListaDescripcion.Add(oDescripcion);

                foreach (string oDes in oDet.MultiDescripcion)
                {
                    DescriptionType oDescrip = new DescriptionType();
                    oDescrip.Value = oDes.ToString();
                    oListaDescripcion.Add(oDescrip);
                }



                List <TaxSubtotalType> oListaSubtotal = new List <TaxSubtotalType>();

                foreach (En_ComprobanteDetalleImpuestos odetImpuesto in oDet.ComprobanteDetalleImpuestos)
                {
                    TaxSubtotalType oSubTotal = new TaxSubtotalType();
                    oSubTotal = LlenarSubTotalDetalle(odetImpuesto.MontoBase, odetImpuesto.MontoTotalImpuesto, Comprobante.Moneda.Trim(), odetImpuesto.Porcentaje, odetImpuesto.CodigoInternacionalTributo, odetImpuesto.NombreTributo, odetImpuesto.CodigoTributo, odetImpuesto.AfectacionIGV);
                    oListaSubtotal.Add(oSubTotal);
                }

                DebitNoteLineType oInvoiceLine = new DebitNoteLineType
                {
                    ID = new IDType
                    {
                        Value = oDet.Item.ToString()
                    },
                    DebitedQuantity = new DebitedQuantityType
                    {
                        unitCode = oDet.UnidadMedida.Trim().ToUpper(),
                        unitCodeListAgencyName = "United Nations Economic Commission for Europe",
                        unitCodeListID         = "UN/ECE rec 20",
                        Value = oDet.Cantidad
                    },
                    LineExtensionAmount = new LineExtensionAmountType
                    {
                        Value      = oDet.Total,
                        currencyID = Comprobante.Moneda.Trim()
                    },
                    PricingReference = new PricingReferenceType
                    {
                        AlternativeConditionPrice = new PriceType[] {
                            new PriceType {
                                PriceAmount = new PriceAmountType {
                                    Value      = oDet.ValorVentaUnitarioIncIgv,
                                    currencyID = Comprobante.Moneda.Trim()
                                },
                                PriceTypeCode = new PriceTypeCodeType {
                                    Value          = oDet.CodigoTipoPrecio,
                                    listAgencyName = "PE:SUNAT",
                                    listName       = "Tipo de Precio",
                                    listURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16"
                                }
                            }
                        }
                    },
                    TaxTotal = new TaxTotalType[] {
                        new TaxTotalType {
                            TaxAmount = new TaxAmountType {
                                Value      = oDet.ImpuestoTotal,
                                currencyID = Comprobante.Moneda.Trim()
                            },
                            TaxSubtotal = oListaSubtotal.ToArray()
                        }
                    },
                    Price = new PriceType
                    {
                        PriceAmount = new PriceAmountType
                        {
                            Value      = oDet.ValorVentaUnitario,
                            currencyID = Comprobante.Moneda.Trim()
                        }
                    },
                    Item = new ItemType
                    {
                        Description = oListaDescripcion.ToArray(),

                        SellersItemIdentification = new ItemIdentificationType
                        {
                            ID = new IDType
                            {
                                Value = oDet.Codigo
                            }
                        },
                        CommodityClassification = new CommodityClassificationType[]
                        {
                            new CommodityClassificationType {
                                CommodityCode = new CommodityCodeType
                                {
                                    listAgencyName = "GS1 US",
                                    listID         = "UNSPSC",
                                    listName       = "Item Classification",
                                    Value          = oDet.CodigoSunat
                                }
                            }
                        }
                    }
                };
                oListaDetalle.Add(oInvoiceLine);
            }
            ;
            debitNote.DebitNoteLine = oListaDetalle.ToArray();
        }
コード例 #11
0
        /// <summary>
        /// Genera un documento XML para Notas de Debito.
        /// </summary>
        /// <param name="debitHeaderEntity">Entidad de Nota de Debito</param>
        /// <returns>Retorna el XML generado.</returns>
        public XmlFileResult GenerarDocumentoDebitNote(DebitNoteHeader debitHeaderEntity)
        {
            try
            {
                #region FileName
                string xmlFilename =
                    $"{debitHeaderEntity.RucEmisor}-08-{debitHeaderEntity.SerieDocumento}-{debitHeaderEntity.CorrelativoDocumento}";
                #endregion

                #region Gen DebitNote
                AmountType.TlsDefaultCurrencyID = debitHeaderEntity.CodigoMoneda;
                var debitDoc = new DebitNoteType
                {
                    ID                          = string.Concat(debitHeaderEntity.SerieDocumento, "-", debitHeaderEntity.CorrelativoDocumento),
                    IssueDate                   = debitHeaderEntity.FechaEmision,
                    DocumentCurrencyCode        = debitHeaderEntity.CodigoMoneda,
                    CustomizationID             = "1.0",
                    DespatchDocumentReference   = UtilsXmlDoc.DevuelveGuiasRemisionReferenciadas(debitHeaderEntity.GuiaRemisionReferencia),
                    AdditionalDocumentReference = UtilsXmlDoc.DevuelveDocumentosReferenciaNote(debitHeaderEntity),
                    DiscrepancyResponse         = new[]
                    {
                        new ResponseType
                        {
                            ReferenceID  = debitHeaderEntity.DocumentoRef,
                            ResponseCode = ((int)debitHeaderEntity.TipoNota).ToString("00"),
                            Description  = new TextType[]
                            {
                                debitHeaderEntity.Motivo
                            }
                        }
                    },
                    BillingReference = new[]
                    {
                        new BillingReferenceType
                        {
                            InvoiceDocumentReference = new DocumentReferenceType
                            {
                                ID = debitHeaderEntity.DocumentoRef,
                                DocumentTypeCode = ((int)debitHeaderEntity.TipoDocRef).ToString("00")
                            }
                        }
                    },
                    Signature = UtilsXmlDoc.GetSignature(debitHeaderEntity),
                    AccountingSupplierParty = UtilsXmlDoc.GetInfoEmisor(debitHeaderEntity),
                    AccountingCustomerParty = new CustomerPartyType
                    {
                        CustomerAssignedAccountID = debitHeaderEntity.NroDocCliente,
                        AdditionalAccountID       =
                            new IdentifierType[] { ((int)debitHeaderEntity.TipoDocumentoIdentidadCliente).ToString() },
                        Party = new PartyType
                        {
                            PostalAddress = string.IsNullOrWhiteSpace(debitHeaderEntity.DireccionCliente) ? null : new AddressType
                            {
                                StreetName = debitHeaderEntity.DireccionCliente
                            },
                            PartyLegalEntity = new[]
                            {
                                new PartyLegalEntityType
                                {
                                    RegistrationName = debitHeaderEntity.NombreRazonSocialCliente,
                                }
                            }
                        },
                    },
                    TaxTotal = UtilsXmlDoc.DevuelveSubTotalImpuestos(debitHeaderEntity.Impuesto),
                    RequestedMonetaryTotal = new MonetaryTotalType
                    {
                        ChargeTotalAmount = debitHeaderEntity.TotalCargos > 0 ? new AmountType {
                            Value = debitHeaderEntity.TotalCargos
                        } : null,
                        AllowanceTotalAmount = debitHeaderEntity.DescuentoGlobal > 0 ? new AmountType {
                            Value = debitHeaderEntity.DescuentoGlobal
                        } : null,
                        PayableAmount = debitHeaderEntity.Total
                    },
                    DebitNoteLine = UtilsXmlDoc.ToDebit(UtilsXmlDoc.DevuelveDetallesDelComprobante(debitHeaderEntity.DetallesDocumento)),
                };
                #region Ext
                var lisExt = new List <UBLExtensionType>(2);
                if (debitHeaderEntity.TotalTributosAdicionales != null)
                {
                    lisExt.Add(new UBLExtensionType
                    {
                        ExtensionContent = new AdditionalsInformationType //(mas informacion en el catalogo no 14 del manual.)
                        {
                            AdditionalInformation = new AdditionalInformationType {
                                AdditionalMonetaryTotal = UtilsXmlDoc.DevuelveTributosAdicionales(debitHeaderEntity.TotalTributosAdicionales),
                            }
                        }
                    });
                }
                lisExt.Add(new UBLExtensionType
                {
                    ExtensionContent = new AdditionalsInformationType()
                });
                debitDoc.UBLExtensions = lisExt.ToArray();
                #endregion
                debitDoc.AccountingSupplierParty.Party.PostalAddress = UtilsXmlDoc.ObtenerDireccion(debitHeaderEntity.DireccionEmisor);
                #endregion |

                return(FromDocument(debitDoc, xmlFilename));
            }
            catch (Exception ex)
            {
                return(FromException(ex));
            }
        }
コード例 #12
0
        private DataTable FnTablaCabeceraDebitNote(DebitNoteType ocomprobante, En_Archivo archivo)
        {
            DataTable dtCabecera = new DataTable();

            dtCabecera.Columns.Add(new DataColumn("SerieNumero", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("FechaEmision", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("FechaVencimiento", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("TipoComprobante", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("Moneda", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("MontoLetras", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("QR", typeof(Byte[])));
            dtCabecera.Columns.Add(new DataColumn("TotalValorVentaGravada", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("IGV", typeof(string)));
            dtCabecera.Columns.Add(new DataColumn("ImporteTotal", typeof(string)));

            DataRow fila;

            fila = dtCabecera.NewRow();
            fila["SerieNumero"]      = FnValidarNulo(ocomprobante.ID.Value.ToString());
            fila["FechaEmision"]     = FnValidarNulo(ocomprobante.IssueDate.Value.ToString());
            fila["FechaVencimiento"] = "";

            fila["TipoComprobante"] = "NOTA CREDITO ELECTRÓNICA";


            if (ocomprobante.DocumentCurrencyCode.Value.ToString() == "PEN")
            {
                fila["Moneda"] = "NUEVO SOL";
            }
            if (ocomprobante.DocumentCurrencyCode.Value.ToString() == "USD")
            {
                fila["Moneda"] = "DOLAR AMERICANO";
            }


            fila["MontoLetras"] = "";
            if (ocomprobante.Note != null)
            {
                if (ocomprobante.Note.Length > 0)
                {
                    foreach (NoteType nota in ocomprobante.Note)
                    {
                        if (nota.languageLocaleID == "1000")
                        {
                            fila["MontoLetras"] = nota.Value.ToString();
                        }
                    }
                }
            }

            fila["QR"] = FnCodigoQR(archivo.Qr);

            if (ocomprobante.TaxTotal != null)
            {
                foreach (TaxTotalType total in ocomprobante.TaxTotal)
                {
                    foreach (TaxSubtotalType subTotal in total.TaxSubtotal)
                    {
                        if (subTotal.TaxCategory.TaxScheme.Name.Value.ToString() == "IGV")
                        {
                            fila["IGV"] = FnValidarNulo(subTotal.TaxAmount.Value.ToString());
                        }
                    }
                }
            }

            if (ocomprobante.RequestedMonetaryTotal != null)
            {
                fila["TotalValorVentaGravada"] = FnValidarNulo(ocomprobante.RequestedMonetaryTotal.LineExtensionAmount.Value.ToString());
                fila["ImporteTotal"]           = FnValidarNulo(ocomprobante.RequestedMonetaryTotal.PayableAmount.Value.ToString());
            }


            dtCabecera.Rows.Add(fila);

            return(dtCabecera);
        }
コード例 #13
0
ファイル: Generar.cs プロジェクト: RSEANCAS/bilecom
        public byte[] GenerarXML(DebitNoteType item)
        {
            byte[] xmlByte = null;

            return(xmlByte);
        }
コード例 #14
0
        public static DebitNoteType Create()
        {
            var doc = new DebitNoteType
            {
                UBLVersionID = "2.1",
                ID           = "TOSL108",
                IssueDate    = "2009-12-15",
                Note         = new TextType[]
                {
                    new TextType
                    {
                        languageID = "en",
                        Value      = "Ordered in our booth at the convention."
                    }
                },
                TaxPointDate         = "2009-11-30",
                DocumentCurrencyCode = new CodeType
                {
                    listID       = "ISO 4217 Alpha",
                    listAgencyID = "6",
                    Value        = "EUR"
                },
                AccountingCost = "Project cost code 123",
                InvoicePeriod  = new PeriodType[]
                {
                    new PeriodType
                    {
                        StartDate = "2009-11-01",
                        EndDate   = "2009-11-30"
                    }
                },
                OrderReference = new OrderReferenceType
                {
                    ID = "123"
                },
                ContractDocumentReference = new DocumentReferenceType[]
                {
                    new DocumentReferenceType
                    {
                        ID           = "Contract321",
                        DocumentType = "Framework agreement"
                    }
                },
                AdditionalDocumentReference = new DocumentReferenceType[]
                {
                    new DocumentReferenceType
                    {
                        ID           = "Doc1",
                        DocumentType = "Timesheet",
                        Attachment   = new AttachmentType
                        {
                            ExternalReference = new ExternalReferenceType
                            {
                                URI = "http://www.suppliersite.eu/sheet001.html"
                            }
                        }
                    },
                    new DocumentReferenceType
                    {
                        ID           = "Doc2",
                        DocumentType = "Drawing",
                        Attachment   = new AttachmentType
                        {
                            EmbeddedDocumentBinaryObject = new BinaryObjectType
                            {
                                mimeCode = "application/pdf",
                                Value    = System.Convert.FromBase64String("UjBsR09EbGhjZ0dTQUxNQUFBUUNBRU1tQ1p0dU1GUXhEUzhi")
                            }
                        }
                    }
                },
                AccountingSupplierParty = new SupplierPartyType
                {
                    Party = new PartyType
                    {
                        EndpointID = new IdentifierType
                        {
                            schemeID       = "GLN",
                            schemeAgencyID = "9",
                            Value          = "1234567890123"
                        },
                        PartyIdentification = new PartyIdentificationType[]
                        {
                            new PartyIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID = "ZZZ",
                                    Value    = "Supp123"
                                }
                            }
                        },
                        PartyName = new PartyNameType[]
                        {
                            new PartyNameType
                            {
                                Name = "Salescompany ltd."
                            }
                        },
                        PostalAddress = new AddressType
                        {
                            ID = new IdentifierType
                            {
                                schemeID       = "GLN",
                                schemeAgencyID = "9",
                                Value          = "1231412341324"
                            },
                            Postbox              = "5467",
                            StreetName           = "Main street",
                            AdditionalStreetName = "Suite 123",
                            BuildingNumber       = "1",
                            Department           = "Revenue department",
                            CityName             = "Big city",
                            PostalZone           = "54321",
                            CountrySubentityCode = "RegionA",
                            Country              = new CountryType
                            {
                                IdentificationCode = new CodeType
                                {
                                    listID       = "ISO3166-1",
                                    listAgencyID = "6",
                                    Value        = "DK"
                                }
                            }
                        },
                        PartyTaxScheme = new PartyTaxSchemeType[]
                        {
                            new PartyTaxSchemeType
                            {
                                CompanyID = new IdentifierType
                                {
                                    schemeID       = "DKVAT",
                                    schemeAgencyID = "ZZZ",
                                    Value          = "DK12345"
                                },
                                TaxScheme = new TaxSchemeType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5153",
                                        schemeAgencyID = "6",
                                        Value          = "VAT"
                                    }
                                }
                            }
                        },
                        PartyLegalEntity = new PartyLegalEntityType[]
                        {
                            new PartyLegalEntityType
                            {
                                RegistrationName = "The Sellercompany Incorporated",
                                CompanyID        = new IdentifierType
                                {
                                    schemeID       = "CVR",
                                    schemeAgencyID = "ZZZ",
                                    Value          = "5402697509"
                                },
                                RegistrationAddress = new AddressType
                                {
                                    CityName         = "Big city",
                                    CountrySubentity = "RegionA",
                                    Country          = new CountryType
                                    {
                                        IdentificationCode = "DK"
                                    }
                                }
                            }
                        },
                        Contact = new ContactType
                        {
                            Telephone      = "4621230",
                            Telefax        = "4621231",
                            ElectronicMail = "*****@*****.**"
                        },
                        Person = new PersonType[]
                        {
                            new PersonType
                            {
                                FirstName  = "Antonio",
                                FamilyName = "M",
                                MiddleName = "Salemacher",
                                JobTitle   = "Sales manager"
                            }
                        }
                    }
                },
                AccountingCustomerParty = new CustomerPartyType
                {
                    Party = new PartyType
                    {
                        EndpointID = new IdentifierType
                        {
                            schemeID       = "GLN",
                            schemeAgencyID = "9",
                            Value          = "1234567987654"
                        },
                        PartyIdentification = new PartyIdentificationType[]
                        {
                            new PartyIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID = "ZZZ",
                                    Value    = "345KS5324"
                                }
                            }
                        },
                        PartyName = new PartyNameType[]
                        {
                            new PartyNameType
                            {
                                Name = "Buyercompany ltd"
                            }
                        },
                        PostalAddress = new AddressType
                        {
                            ID = new IdentifierType
                            {
                                schemeID       = "GLN",
                                schemeAgencyID = "9",
                                Value          = "1238764941386"
                            },
                            Postbox              = "123",
                            StreetName           = "Anystreet",
                            AdditionalStreetName = "Back door",
                            BuildingNumber       = "8",
                            Department           = "Accounting department",
                            CityName             = "Anytown",
                            PostalZone           = "101",
                            CountrySubentity     = "RegionB",
                            Country              = new CountryType
                            {
                                IdentificationCode = new CodeType
                                {
                                    listID       = "ISO3166-1",
                                    listAgencyID = "6",
                                    Value        = "BE"
                                }
                            }
                        },
                        PartyTaxScheme = new PartyTaxSchemeType[]
                        {
                            new PartyTaxSchemeType
                            {
                                CompanyID = new IdentifierType
                                {
                                    schemeID       = "BEVAT",
                                    schemeAgencyID = "ZZZ",
                                    Value          = "BE54321"
                                },
                                TaxScheme = new TaxSchemeType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5153",
                                        schemeAgencyID = "6",
                                        Value          = "VAT"
                                    }
                                }
                            }
                        },
                        PartyLegalEntity = new PartyLegalEntityType[]
                        {
                            new PartyLegalEntityType
                            {
                                RegistrationName = "The buyercompany inc.",
                                CompanyID        = new IdentifierType
                                {
                                    schemeAgencyID = "ZZZ",
                                    schemeID       = "ZZZ",
                                    Value          = "5645342123"
                                },
                                RegistrationAddress = new AddressType
                                {
                                    CityName         = "Mainplace",
                                    CountrySubentity = "RegionB",
                                    Country          = new CountryType
                                    {
                                        IdentificationCode = "BE"
                                    }
                                }
                            }
                        },
                        Contact = new ContactType
                        {
                            Telephone      = "5121230",
                            Telefax        = "5121231",
                            ElectronicMail = "*****@*****.**"
                        },
                        Person = new PersonType[]
                        {
                            new PersonType
                            {
                                FirstName  = "John",
                                FamilyName = "X",
                                MiddleName = "Doe",
                                JobTitle   = "Purchasing manager"
                            }
                        }
                    }
                },
                TaxTotal = new TaxTotalType[]
                {
                    new TaxTotalType
                    {
                        TaxAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 292.20M
                        },
                        TaxSubtotal = new TaxSubtotalType[]
                        {
                            new TaxSubtotalType
                            {
                                TaxableAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 1460.5M
                                },
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 292.1M
                                },
                                TaxCategory = new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "S"
                                    },
                                    Percent   = 20M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            },
                            new TaxSubtotalType
                            {
                                TaxableAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 1M
                                },
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 0.1M
                                },
                                TaxCategory = new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "AA"
                                    },
                                    Percent   = 10M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            },
                            new TaxSubtotalType
                            {
                                TaxableAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = -25M
                                },
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 0M
                                },
                                TaxCategory = new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "E"
                                    },
                                    Percent = 0M,
                                    TaxExemptionReasonCode = new CodeType
                                    {
                                        listID       = "CWA 15577",
                                        listAgencyID = "ZZZ",
                                        Value        = "AAM"
                                    },
                                    TaxExemptionReason = new TextType[]
                                    {
                                        new TextType
                                        {
                                            Value = "Exempt New Means of Transport"
                                        }
                                    },
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                RequestedMonetaryTotal = new MonetaryTotalType
                {
                    LineExtensionAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 1436.5M
                    },
                    TaxExclusiveAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 1436.5M
                    },
                    TaxInclusiveAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 1729M
                    },
                    AllowanceTotalAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 100M
                    },
                    ChargeTotalAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 100M
                    },
                    PrepaidAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 1000M
                    },
                    PayableRoundingAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 0.30M
                    },
                    PayableAmount = new AmountType
                    {
                        currencyID = "EUR",
                        Value      = 729M
                    }
                },
                DebitNoteLine = new DebitNoteLineType[]
                {
                    new DebitNoteLineType
                    {
                        ID   = "1",
                        Note = new TextType[]
                        {
                            new TextType
                            {
                                Value = "Scratch on box"
                            }
                        },
                        DebitedQuantity = new QuantityType
                        {
                            unitCode = "C62",
                            Value    = 1M
                        },
                        LineExtensionAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 1273M
                        },
                        AccountingCost = "BookingCode001",
                        TaxTotal       = new TaxTotalType[]
                        {
                            new TaxTotalType
                            {
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 254.6M
                                }
                            }
                        },
                        Item = new ItemType
                        {
                            Description = new TextType[]
                            {
                                new TextType
                                {
                                    languageID = "EN",
                                    Value      = @"Processor: Intel Core 2 Duo SU9400 LV (1.4GHz). RAM:
				3MB. Screen 1440x900"
                                }
                            },
                            Name = "Labtop computer",
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "JB007"
                            },
                            StandardItemIdentification = new ItemIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID       = "GTIN",
                                    schemeAgencyID = "9",
                                    Value          = "1234567890124"
                                }
                            },
                            CommodityClassification = new CommodityClassificationType[]
                            {
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "113",
                                        listID       = "UNSPSC",
                                        Value        = "12344321"
                                    }
                                },
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "2",
                                        listID       = "CPV",
                                        Value        = "65434568"
                                    }
                                }
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "S"
                                    },
                                    Percent   = 20M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            },
                            AdditionalItemProperty = new ItemPropertyType[]
                            {
                                new ItemPropertyType
                                {
                                    Name  = "Color",
                                    Value = "black"
                                }
                            }
                        },
                        Price = new PriceType
                        {
                            PriceAmount = new AmountType
                            {
                                currencyID = "EUR",
                                Value      = 1273M
                            },
                            BaseQuantity = new QuantityType
                            {
                                unitCode = "C62",
                                Value    = 1M
                            },
                            AllowanceCharge = new AllowanceChargeType[]
                            {
                                new AllowanceChargeType
                                {
                                    ChargeIndicator       = false,
                                    AllowanceChargeReason = new TextType[]
                                    {
                                        new TextType
                                        {
                                            Value = "Contract"
                                        }
                                    },
                                    MultiplierFactorNumeric = 0.15M,
                                    Amount = new AmountType
                                    {
                                        currencyID = "EUR",
                                        Value      = 225M
                                    },
                                    BaseAmount = new AmountType
                                    {
                                        currencyID = "EUR",
                                        Value      = 1500M
                                    }
                                }
                            }
                        }
                    },
                    new DebitNoteLineType
                    {
                        ID   = "2",
                        Note = new TextType[]
                        {
                            new TextType
                            {
                                Value = "Cover is slightly damaged."
                            }
                        },
                        DebitedQuantity = new QuantityType
                        {
                            unitCode = "C62",
                            Value    = -1M
                        },
                        LineExtensionAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = -3.96M
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType
                            {
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = -0.396M
                                }
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "Returned \"Advanced computing\" book",
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "JB008"
                            },
                            StandardItemIdentification = new ItemIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID       = "GTIN",
                                    schemeAgencyID = "9",
                                    Value          = "1234567890125"
                                }
                            },
                            CommodityClassification = new CommodityClassificationType[]
                            {
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "113",
                                        listID       = "UNSPSC",
                                        Value        = "32344324"
                                    }
                                },
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "2",
                                        listID       = "CPV",
                                        Value        = "65434567"
                                    }
                                }
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "AA"
                                    },
                                    Percent   = 10M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            }
                        },
                        Price = new PriceType
                        {
                            PriceAmount = new AmountType
                            {
                                currencyID = "EUR",
                                Value      = 3.96M
                            },
                            BaseQuantity = new QuantityType
                            {
                                unitCode = "C62",
                                Value    = 1M
                            }
                        }
                    },
                    new DebitNoteLineType
                    {
                        ID = "3",
                        DebitedQuantity = new QuantityType
                        {
                            unitCode = "C62",
                            Value    = 2M
                        },
                        LineExtensionAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 4.96M
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType
                            {
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 0.496M
                                }
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "\"Computing for dummies\" book",
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "JB009"
                            },
                            StandardItemIdentification = new ItemIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID       = "GTIN",
                                    schemeAgencyID = "9",
                                    Value          = "1234567890126"
                                }
                            },
                            CommodityClassification = new CommodityClassificationType[]
                            {
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "113",
                                        listID       = "UNSPSC",
                                        Value        = "32344324"
                                    }
                                },
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "2",
                                        listID       = "CPV",
                                        Value        = "65434566"
                                    }
                                }
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "AA"
                                    },
                                    Percent   = 10M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            }
                        },
                        Price = new PriceType
                        {
                            PriceAmount = new AmountType
                            {
                                currencyID = "EUR",
                                Value      = 2.48M
                            },
                            BaseQuantity = new QuantityType
                            {
                                unitCode = "C62",
                                Value    = 1M
                            },
                            AllowanceCharge = new AllowanceChargeType[]
                            {
                                new AllowanceChargeType
                                {
                                    ChargeIndicator       = false,
                                    AllowanceChargeReason = new TextType[]
                                    {
                                        new TextType
                                        {
                                            Value = "Contract"
                                        }
                                    },
                                    MultiplierFactorNumeric = 0.1M,
                                    Amount = new AmountType
                                    {
                                        currencyID = "EUR",
                                        Value      = 0.275M
                                    },
                                    BaseAmount = new AmountType
                                    {
                                        currencyID = "EUR",
                                        Value      = 2.75M
                                    }
                                }
                            }
                        }
                    },
                    new DebitNoteLineType
                    {
                        ID = "4",
                        DebitedQuantity = new QuantityType
                        {
                            unitCode = "C62",
                            Value    = -1M
                        },
                        LineExtensionAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = -25M
                        },
                        TaxTotal = new TaxTotalType[]
                        {
                            new TaxTotalType
                            {
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 0M
                                }
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "Returned IBM 5150 desktop",
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "JB010"
                            },
                            StandardItemIdentification = new ItemIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID       = "GTIN",
                                    schemeAgencyID = "9",
                                    Value          = "1234567890127"
                                }
                            },
                            CommodityClassification = new CommodityClassificationType[]
                            {
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "113",
                                        listID       = "UNSPSC",
                                        Value        = "12344322"
                                    }
                                },
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "2",
                                        listID       = "CPV",
                                        Value        = "65434565"
                                    }
                                }
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "E"
                                    },
                                    Percent   = 0M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            }
                        },
                        Price = new PriceType
                        {
                            PriceAmount = new AmountType
                            {
                                currencyID = "EUR",
                                Value      = 25M
                            },
                            BaseQuantity = new QuantityType
                            {
                                unitCode = "C62",
                                Value    = 1M
                            }
                        }
                    },
                    new DebitNoteLineType
                    {
                        ID = "5",
                        DebitedQuantity = new QuantityType
                        {
                            unitCode = "C62",
                            Value    = 250M
                        },
                        LineExtensionAmount = new AmountType
                        {
                            currencyID = "EUR",
                            Value      = 187.5M
                        },
                        AccountingCost = "BookingCode002",
                        TaxTotal       = new TaxTotalType[]
                        {
                            new TaxTotalType
                            {
                                TaxAmount = new AmountType
                                {
                                    currencyID = "EUR",
                                    Value      = 37.5M
                                }
                            }
                        },
                        Item = new ItemType
                        {
                            Name = "Network cable",
                            SellersItemIdentification = new ItemIdentificationType
                            {
                                ID = "JB011"
                            },
                            StandardItemIdentification = new ItemIdentificationType
                            {
                                ID = new IdentifierType
                                {
                                    schemeID       = "GTIN",
                                    schemeAgencyID = "9",
                                    Value          = "1234567890128"
                                }
                            },
                            CommodityClassification = new CommodityClassificationType[]
                            {
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "113",
                                        listID       = "UNSPSC",
                                        Value        = "12344325"
                                    }
                                },
                                new CommodityClassificationType
                                {
                                    ItemClassificationCode = new CodeType
                                    {
                                        listAgencyID = "2",
                                        listID       = "CPV",
                                        Value        = "65434564"
                                    }
                                }
                            },
                            ClassifiedTaxCategory = new TaxCategoryType[]
                            {
                                new TaxCategoryType
                                {
                                    ID = new IdentifierType
                                    {
                                        schemeID       = "UN/ECE 5305",
                                        schemeAgencyID = "6",
                                        Value          = "S"
                                    },
                                    Percent   = 20M,
                                    TaxScheme = new TaxSchemeType
                                    {
                                        ID = new IdentifierType
                                        {
                                            schemeID       = "UN/ECE 5153",
                                            schemeAgencyID = "6",
                                            Value          = "VAT"
                                        }
                                    }
                                }
                            },
                            AdditionalItemProperty = new ItemPropertyType[]
                            {
                                new ItemPropertyType
                                {
                                    Name  = "Type",
                                    Value = "Cat5"
                                }
                            }
                        },
                        Price = new PriceType
                        {
                            PriceAmount = new AmountType
                            {
                                currencyID = "EUR",
                                Value      = 0.75M
                            },
                            BaseQuantity = new QuantityType
                            {
                                unitCode = "C62",
                                Value    = 1M
                            }
                        }
                    }
                }
            };

            doc.Xmlns = new System.Xml.Serialization.XmlSerializerNamespaces(new[]
            {
                new XmlQualifiedName("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"),
                new XmlQualifiedName("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"),
            });
            return(doc);
        }
コード例 #15
0
        void LlenarDocumentoRefenciado(En_ComprobanteElectronico Comprobante, ref DebitNoteType debitNote)
        {
            if (Comprobante.DocumentoSustentoNota != null)
            {
                debitNote.DiscrepancyResponse = new ResponseType[]
                {
                    new ResponseType {
                        Description = new DescriptionType[] {
                            new DescriptionType
                            {
                                Value = Comprobante.DocumentoSustentoNota.MotivoAnulacion
                            }
                        },
                        ResponseCode = new ResponseCodeType
                        {
                            listName       = "Tipo de nota de credito",
                            listAgencyName = "PE:SUNAT",
                            listURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo09",
                            Value          = Comprobante.DocumentoSustentoNota.CodigoMotivoAnulacion
                        },
                        ReferenceID = new ReferenceIDType {
                            Value = Comprobante.DocumentoSustentoNota.SerieNumero
                        }
                    }
                };
            }

            if (Comprobante.DocumentoReferenciaNota != null)
            {
                List <BillingReferenceType> oListaReferencia = new List <BillingReferenceType>();

                foreach (En_DocumentoReferenciaNota oDoc in Comprobante.DocumentoReferenciaNota)
                {
                    BillingReferenceType oreferencia = new BillingReferenceType();
                    oreferencia.InvoiceDocumentReference = new DocumentReferenceType
                    {
                        ID = new IDType
                        {
                            Value = oDoc.SerieNumero
                        },
                        IssueDate = new IssueDateType
                        {
                            Value = oDoc.Fecha
                        },
                        DocumentTypeCode = new DocumentTypeCodeType
                        {
                            listName       = "Tipo de Documento",
                            listAgencyName = "PE:SUNAT",
                            listURI        = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01",
                            Value          = oDoc.TipoDocumento
                        }
                    };

                    oListaReferencia.Add(oreferencia);
                }

                if (oListaReferencia.Count > 0)
                {
                    debitNote.BillingReference = oListaReferencia.ToArray();
                }
            }
        }
コード例 #16
0
        void LlenarReceptor(En_Receptor Receptor, ref DebitNoteType debitNote)
        {
            WebsiteURIType EmisorPaginaWeb = new WebsiteURIType
            {
                Value = Receptor.PaginaWeb.Trim()
            };

            List <PartyNameType> oListaNombreComercial = new List <PartyNameType>();
            PartyNameType        PartyName             = new PartyNameType
            {
                Name = new NameType1
                {
                    Value = Receptor.NombreComercial.Trim()
                }
            };

            oListaNombreComercial.Add(PartyName);


            PartyIdentificationType        EmisorIdentificacion      = new PartyIdentificationType();
            List <PartyIdentificationType> EmisorListaIdentificacion = new List <PartyIdentificationType>();

            EmisorIdentificacion.ID = new IDType
            {
                Value          = Receptor.NumeroDocumentoIdentidad.Trim(),
                schemeAgencyID = "PE:SUNAT",
                schemeID       = Receptor.TipoDocumentoIdentidad.Trim(),
                schemeName     = "Documento de Identidad",
                schemeURI      = "urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06"
            };
            EmisorListaIdentificacion.Add(EmisorIdentificacion);

            //Razon social
            PartyLegalEntityType oRazonSocial = new PartyLegalEntityType
            {
                RegistrationName = new RegistrationNameType
                {
                    Value = Receptor.RazonSocial,
                },

                RegistrationAddress = new AddressType
                {
                    ID = new IDType
                    {
                        Value            = Receptor.CodigoUbigeo.Trim(),
                        schemeAgencyName = "PE:INEI",
                        schemeName       = "Ubigeos"
                    },
                    AddressTypeCode = new AddressTypeCodeType
                    {
                        Value          = Receptor.CodigoDomicilioFiscal.Trim(),
                        listAgencyName = "PE:SUNAT",
                        listName       = "Establecimientos anexos"
                    },
                    CitySubdivisionName = new CitySubdivisionNameType
                    {
                        Value = Receptor.Urbanizacion.Trim()
                    },
                    CityName = new CityNameType
                    {
                        Value = Receptor.Provincia.Trim()
                    },
                    CountrySubentity = new CountrySubentityType
                    {
                        Value = Receptor.Departamento.Trim()
                    },
                    District = new DistrictType
                    {
                        Value = Receptor.Distrito.Trim()
                    },
                    AddressLine = new AddressLineType[] {
                        new AddressLineType {
                            Line = new LineType {
                                Value = Receptor.Direccion.Trim()
                            }
                        }
                    },
                    Country = new CountryType
                    {
                        IdentificationCode = new IdentificationCodeType
                        {
                            listAgencyName = "United Nations Economic Commission for Europe",
                            listID         = "ISO 3166-1",
                            listName       = "Country",
                            Value          = Receptor.CodigoPais.Trim()
                        }
                    }
                }
            };

            ContactType oContacto = new ContactType
            {
                ElectronicMail = new ElectronicMailType()
                {
                    Value = Receptor.Contacto.Correo.Trim()
                },
                Name = new NameType1
                {
                    Value = Receptor.Contacto.Nombre.Trim()
                },
                Telephone = new TelephoneType
                {
                    Value = Receptor.Contacto.Telefono.Trim()
                }
            };

            CustomerPartyType oReceptor = new CustomerPartyType
            {
                Party = new PartyType
                {
                    WebsiteURI          = EmisorPaginaWeb,
                    PartyIdentification = EmisorListaIdentificacion.ToArray(),
                    PartyName           = oListaNombreComercial.ToArray(),
                    PartyLegalEntity    = new PartyLegalEntityType[] { oRazonSocial },
                    Contact             = oContacto
                }
            };

            debitNote.AccountingCustomerParty = oReceptor;
        }
コード例 #17
0
ファイル: EDebitNote.cs プロジェクト: perezgradosj/ADE
        public bool GenerateXML()
        {
            bool isGenerated = false;

            try
            {
                MS.GeneraLog.GeneracionXML("-----  Inicio de Generación de Archivo: " + MS.XMLIFileLocation);
                XmlSerializer           mySerializer = new XmlSerializer(typeof(DebitNoteType));
                XmlSerializerNamespaces ns           = getNamespaces();
                XmlWriterSettings       setting      = getSettings();

                DebitNoteType deb = new DebitNoteType();
                deb.AccountingSupplierParty = getSupplierPartyType();
                deb.AccountingCustomerParty = getAccountingCustomerParty();
                deb.Signature       = getSignatureType();
                deb.UBLVersionID    = getUBLVersionID();
                deb.CustomizationID = getCustomizationID();
                deb.ID                     = getID();
                deb.IssueDate              = getIssueDate();
                deb.DiscrepancyResponse    = getDiscrepancyResponseType();
                deb.BillingReference       = getBillingReferenceType();
                deb.DocumentCurrencyCode   = getDocumentCurrencyCode();
                deb.RequestedMonetaryTotal = getRequestedMonetaryTotal();
                deb.DebitNoteLine          = getDebitNoteLine();
                deb.UBLExtensions          = getUBLExtensions();

                if (VD.Taxes.Count > 0)
                {
                    deb.TaxTotal = getTaxTotal();
                }

                deb.AdditionalDocumentReference = getAdditionalDocumentReferenceType();
                deb.DespatchDocumentReference   = getDespatchDocumentReferenceType();
                deb.OrderReference = getOrderReferenceType();

                XMLI = ObjectToXml(deb, ns);

                XMLI = XMLI.Replace("&lt;", "<");
                XMLI = XMLI.Replace("&gt;", ">");
                XMLI = XMLI.Replace("encoding=\"utf-16\"", "encoding=\"ISO-8859-1\"");
                XMLI = XMLI.Replace("q1:DebitNote", "DebitNote");
                XMLI = XMLI.Replace("q1", "DebitNote");
                XMLI = XMLI.Replace("xmlns=\"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2\"", "");
                XMLI = XMLI.Replace("xmlns:DebitNote", "xmlns");

                XMLI = XMLI.Replace("&amp;", "&");

                using (StreamWriter sw = new StreamWriter(MS.XMLIFileLocation, false, ISO_8859_1))
                {
                    sw.Write(XMLI);
                }

                SXMLI = GenerateStreamFromString(XMLI);

                isGenerated = true;
            }
            catch (Exception ex)
            {
                MS.GeneraLog.GeneracionXML("Ocurrió un error al momento de general el XML Inicial");
                MS.GeneraLog.GeneracionXML("Error: " + ex.Message);
            }
            return(isGenerated);
        }