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 }; }
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; }
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); }
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); }
void LlenarDescuentoCargo(En_ComprobanteElectronico Comprobante, ref InvoiceType invoice) { List <AllowanceChargeType> oListaDescuentoCargo = new List <AllowanceChargeType>(); if (Comprobante.DescuentoCargo != null) { foreach (En_DescuentoCargo oDescar in Comprobante.DescuentoCargo) { AllowanceChargeType oDescuentoCargo = new AllowanceChargeType { AllowanceChargeReason = new AllowanceChargeReasonType[] { new AllowanceChargeReasonType { Value = oDescar.Motivo } }, 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); } invoice.AllowanceCharge = oListaDescuentoCargo.ToArray(); } }
void LlenarMontosTotales(En_ComprobanteElectronico Comprobante, ref InvoiceType invoice) { 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() } }; if (Comprobante.TotalCargo > 0) { ChargeTotalAmountType oChargeTotalAmount = new ChargeTotalAmountType { Value = Comprobante.TotalCargo, currencyID = Comprobante.Moneda.Trim() }; oTotal.ChargeTotalAmount = oChargeTotalAmount; } if (Comprobante.TotalDescuento > 0) { AllowanceTotalAmountType oAllowanceTotalAmount = new AllowanceTotalAmountType { Value = Comprobante.TotalDescuento, currencyID = Comprobante.Moneda.Trim() }; oTotal.AllowanceTotalAmount = oAllowanceTotalAmount; } invoice.LegalMonetaryTotal = oTotal; }
public bool InsertarComprobante(En_ComprobanteElectronico comprobante, string nombreXML, byte[] archivoXML, string codigoHASH, string firma, ref string mensajeRetorno) { StringBuilder firmaQR = new StringBuilder(); string[] serieNumero = comprobante.SerieNumero.Split('-'); firmaQR.Append(comprobante.Emisor.NumeroDocumentoIdentidad).Append('|'); firmaQR.Append(comprobante.TipoComprobante).Append('|'); firmaQR.Append(serieNumero[0]).Append('|'); firmaQR.Append(serieNumero[1]).Append('|'); firmaQR.Append(comprobante.TotalImpuesto.ToString()).Append('|'); firmaQR.Append(comprobante.ImporteTotal).Append('|'); firmaQR.Append(comprobante.FechaEmision).Append('|'); firmaQR.Append(comprobante.Receptor.TipoDocumentoIdentidad).Append('|'); firmaQR.Append(comprobante.Receptor.NumeroDocumentoIdentidad).Append('|'); firmaQR.Append(codigoHASH).Append('|'); firmaQR.Append(firma); SqlConnection cn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("dbo.usp_InsertarComprobante", cn) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add(new SqlParameter { ParameterName = "@NroDocumentoIdentidadEmisor", SqlDbType = SqlDbType.VarChar, Size = 30, Value = comprobante.Emisor.NumeroDocumentoIdentidad }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TipoDocumentoIdentidad", SqlDbType = SqlDbType.VarChar, Size = 2, Value = comprobante.Receptor.TipoDocumentoIdentidad }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@NroDocumentoIdentidad", SqlDbType = SqlDbType.VarChar, Size = 30, Value = comprobante.Receptor.NumeroDocumentoIdentidad }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@RazonSocial", SqlDbType = SqlDbType.VarChar, Size = 500, Value = comprobante.Receptor.RazonSocial }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TipoComprobante", SqlDbType = SqlDbType.VarChar, Size = 2, Value = comprobante.TipoComprobante }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@SerieNumero", SqlDbType = SqlDbType.VarChar, Size = 13, Value = comprobante.SerieNumero }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@FechaEmison", SqlDbType = SqlDbType.VarChar, Size = 10, Value = comprobante.FechaEmision }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@CorreoElectronico", SqlDbType = SqlDbType.VarChar, Size = 500, Value = comprobante.Receptor.Contacto.Correo }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TotalImpuesto", SqlDbType = SqlDbType.Decimal, Value = comprobante.TotalImpuesto }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TotalValorVenta", SqlDbType = SqlDbType.Decimal, Value = comprobante.TotalValorVenta }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TotalPrecioVenta", SqlDbType = SqlDbType.Decimal, Value = comprobante.TotalPrecioVenta }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TotalDescuento", SqlDbType = SqlDbType.Decimal, Value = comprobante.TotalDescuento }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TotalCargo", SqlDbType = SqlDbType.Decimal, Value = comprobante.TotalCargo }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@ImporteTotal", SqlDbType = SqlDbType.Decimal, Value = comprobante.ImporteTotal }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@FechaVencimiento", SqlDbType = SqlDbType.VarChar, Size = 50, Value = comprobante.FechaVencimiento ?? "" }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@HoraEmision", SqlDbType = SqlDbType.VarChar, Size = 8, Value = comprobante.HoraEmision }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@Moneda", SqlDbType = SqlDbType.VarChar, Size = 5, Value = comprobante.Moneda }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TipoOperacion", SqlDbType = SqlDbType.VarChar, Size = 4, Value = comprobante.TipoOperacion }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@NombreXML", SqlDbType = SqlDbType.VarChar, Size = 50, Value = nombreXML }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@ArchivoXML", SqlDbType = SqlDbType.VarBinary, Value = archivoXML }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@CodigoHash", SqlDbType = SqlDbType.VarChar, Value = codigoHASH }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@CodigoQR", SqlDbType = SqlDbType.VarChar, Value = firmaQR.ToString() }); if (comprobante.MontoTotales != null && comprobante.MontoTotales.Gravado != null) { En_GrabadoIGV gravadoIGV = comprobante.MontoTotales.Gravado.GravadoIGV; cmd.Parameters.Add(new SqlParameter { ParameterName = "@CodigoTributo1001", SqlDbType = SqlDbType.VarChar, Size = 4, Value = "1001" }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@MontoOperaciones1001", SqlDbType = SqlDbType.Decimal, Value = gravadoIGV.MontoBase }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@MontoTotalImpuesto1001", SqlDbType = SqlDbType.Decimal, Value = gravadoIGV.MontoTotalImpuesto }); } if (comprobante.DocumentoReferenciaNota != null && comprobante.DocumentoReferenciaNota.Count > 0) { DataTable tablaReferenciados = ToDataTable(comprobante.DocumentoReferenciaNota); cmd.Parameters.Add(new SqlParameter { ParameterName = "@ComprobanteReferenciaNota", SqlDbType = SqlDbType.Structured, Value = tablaReferenciados }); } if (comprobante.DocumentoSustentoNota != null) { En_DocumentoSustentoNota sustentoNota = comprobante.DocumentoSustentoNota; cmd.Parameters.Add(new SqlParameter { ParameterName = "@SerieNumeroDocumentoSustento", SqlDbType = SqlDbType.VarChar, Size = 30, Value = sustentoNota.SerieNumero }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@CodigoAnulacionDocumentoSustento", SqlDbType = SqlDbType.VarChar, Size = 10, Value = sustentoNota.CodigoMotivoAnulacion }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@MotivoAnulacionDocumentoSustento", SqlDbType = SqlDbType.VarChar, Size = 500, Value = sustentoNota.MotivoAnulacion }); } cmd.Parameters.Add(new SqlParameter { ParameterName = "@TextoDetraccion", SqlDbType = SqlDbType.VarChar, Value = comprobante.TextoDetraccion }); try { cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); mensajeRetorno = "Se registró el comprobante satisfactoriamente."; log.Info(mensajeRetorno); return(true); } catch (SqlException ex) { if (cn.State == ConnectionState.Open) { cn.Close(); } mensajeRetorno = ex.Message.ToString(); return(false); } catch (Exception ex) { if (cn.State == ConnectionState.Open) { cn.Close(); } mensajeRetorno = "Ocurrió un error al registrar el comprobante, revisar el log."; log.Error(mensajeRetorno, ex); return(false); } }
public static En_Respuesta ComprobanteValido(En_ComprobanteElectronico comprobante, ref bool esValido) { En_Respuesta respuesta = new En_Respuesta(); try { List <En_Validacion> validaciones = new Da_Validacion().ListarValidaciones(); respuesta = ValidarEntidad(validaciones, comprobante, ref esValido); if (!esValido) { return(respuesta); } if (comprobante.ComprobanteDetalle != null) { foreach (En_ComprobanteDetalle detalle in comprobante.ComprobanteDetalle) { respuesta = ValidarEntidad(validaciones, detalle, ref esValido); if (!esValido) { return(respuesta); } if (detalle.ComprobanteDetalleImpuestos != null) { foreach (En_ComprobanteDetalleImpuestos detalleImpuesto in detalle.ComprobanteDetalleImpuestos) { respuesta = ValidarEntidad(validaciones, detalleImpuesto, ref esValido); if (!esValido) { return(respuesta); } } } } } if (comprobante.DescuentoCargo != null) { foreach (En_DescuentoCargo descuentoCargo in comprobante.DescuentoCargo) { respuesta = ValidarEntidad(validaciones, descuentoCargo, ref esValido); if (!esValido) { return(respuesta); } } } if (comprobante.DocumentoReferenciaDespacho != null) { foreach (En_DocumentoReferencia documentoReferenciaDespacho in comprobante.DocumentoReferenciaDespacho) { respuesta = ValidarEntidad(validaciones, documentoReferenciaDespacho, ref esValido); if (!esValido) { return(respuesta); } } } if (comprobante.DocumentoReferenciaNota != null) { foreach (En_DocumentoReferenciaNota documentoReferenciaNota in comprobante.DocumentoReferenciaNota) { respuesta = ValidarEntidad(validaciones, documentoReferenciaNota, ref esValido); if (!esValido) { return(respuesta); } } } if (comprobante.DocumentoSustentoNota != null) { respuesta = ValidarEntidad(validaciones, comprobante.DocumentoSustentoNota, ref esValido); if (!esValido) { return(respuesta); } } if (comprobante.Emisor != null) { respuesta = ValidarEntidad(validaciones, comprobante.Emisor, ref esValido); if (!esValido) { return(respuesta); } if (comprobante.Emisor.Contacto != null) { respuesta = ValidarEntidad(validaciones, comprobante.Emisor.Contacto, ref esValido); if (!esValido) { return(respuesta); } } } if (comprobante.Receptor != null) { respuesta = ValidarEntidad(validaciones, comprobante.Receptor, ref esValido); if (!esValido) { return(respuesta); } if (comprobante.Receptor.Contacto != null) { respuesta = ValidarEntidad(validaciones, comprobante.Receptor.Contacto, ref esValido); if (!esValido) { return(respuesta); } } } if (comprobante.Leyenda != null) { foreach (var leyenda in comprobante.Leyenda) { respuesta = ValidarEntidad(validaciones, leyenda, ref esValido); if (!esValido) { return(respuesta); } } } if (comprobante.MontoTotales != null && comprobante.MontoTotales.Gravado != null) { respuesta = ValidarEntidad(validaciones, comprobante.MontoTotales.Gravado, ref esValido); if (!esValido) { return(respuesta); } if (comprobante.MontoTotales.Gravado.GravadoIGV != null) { respuesta = ValidarEntidad(validaciones, comprobante.MontoTotales.Gravado.GravadoIGV, ref esValido); if (!esValido) { return(respuesta); } } } } catch (Exception ex) { esValido = false; respuesta.Codigo = "99"; respuesta.Descripcion = ex.Message.ToString(); } return(respuesta); }
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(); } } }
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(); }
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(); }