/// <summary> /// Genera un documento XML para Notas de Credito. /// </summary> /// <param name="creditHeaderEntity">Entidad de Nota de Credito</param> /// <returns>Retorna el XML generado.</returns> public XmlFileResult GenerarDocumentoCreditNote(CreditNoteHeader creditHeaderEntity) { try { #region FileName string xmlFilename = $"{creditHeaderEntity.RucEmisor}-07-{creditHeaderEntity.SerieDocumento}-{creditHeaderEntity.CorrelativoDocumento}"; #endregion #region Gen CreditNote AmountType.TlsDefaultCurrencyID = creditHeaderEntity.CodigoMoneda; var creditDoc = new CreditNoteType { ID = string.Concat(creditHeaderEntity.SerieDocumento, "-", creditHeaderEntity.CorrelativoDocumento), IssueDate = creditHeaderEntity.FechaEmision, DocumentCurrencyCode = creditHeaderEntity.CodigoMoneda, CustomizationID = "1.0", DespatchDocumentReference = UtilsXmlDoc.DevuelveGuiasRemisionReferenciadas(creditHeaderEntity.GuiaRemisionReferencia), AdditionalDocumentReference = UtilsXmlDoc.DevuelveDocumentosReferenciaNote(creditHeaderEntity), DiscrepancyResponse = new[] { new ResponseType { ReferenceID = creditHeaderEntity.DocumentoRef, ResponseCode = ((int)creditHeaderEntity.TipoNota).ToString("00"), Description = new TextType[] { creditHeaderEntity.Motivo } } }, BillingReference = new[] { new BillingReferenceType { InvoiceDocumentReference = new DocumentReferenceType { ID = creditHeaderEntity.DocumentoRef, DocumentTypeCode = ((int)creditHeaderEntity.TipoDocRef).ToString("00") } } }, Signature = UtilsXmlDoc.GetSignature(creditHeaderEntity), AccountingSupplierParty = UtilsXmlDoc.GetInfoEmisor(creditHeaderEntity), AccountingCustomerParty = new CustomerPartyType { CustomerAssignedAccountID = creditHeaderEntity.NroDocCliente, AdditionalAccountID = new IdentifierType[] { ((int)creditHeaderEntity.TipoDocumentoIdentidadCliente).ToString() }, Party = new PartyType { PostalAddress = string.IsNullOrWhiteSpace(creditHeaderEntity.DireccionCliente) ? null : new AddressType { StreetName = creditHeaderEntity.DireccionCliente }, PartyLegalEntity = new[] { new PartyLegalEntityType { RegistrationName = creditHeaderEntity.NombreRazonSocialCliente, } } }, }, TaxTotal = UtilsXmlDoc.DevuelveSubTotalImpuestos(creditHeaderEntity.Impuesto), LegalMonetaryTotal = new MonetaryTotalType { ChargeTotalAmount = creditHeaderEntity.TotalCargos > 0 ? new AmountType { Value = creditHeaderEntity.TotalCargos } : null, AllowanceTotalAmount = creditHeaderEntity.DescuentoGlobal > 0 ? new AmountType { Value = creditHeaderEntity.DescuentoGlobal } : null, PayableAmount = creditHeaderEntity.Total }, CreditNoteLine = UtilsXmlDoc.ToCredit(UtilsXmlDoc.DevuelveDetallesDelComprobante(creditHeaderEntity.DetallesDocumento)), }; #region Ext var lisExt = new List <UBLExtensionType>(2); if (creditHeaderEntity.TotalTributosAdicionales != null) { lisExt.Add(new UBLExtensionType { ExtensionContent = new AdditionalsInformationType //(mas informacion en el catalogo no 14 del manual.) { AdditionalInformation = new AdditionalInformationType { AdditionalMonetaryTotal = UtilsXmlDoc.DevuelveTributosAdicionales(creditHeaderEntity.TotalTributosAdicionales), } } }); } lisExt.Add(new UBLExtensionType { ExtensionContent = new AdditionalsInformationType() }); creditDoc.UBLExtensions = lisExt.ToArray(); #endregion creditDoc.AccountingSupplierParty.Party.PostalAddress = UtilsXmlDoc.ObtenerDireccion(creditHeaderEntity.DireccionEmisor); #endregion | return(FromDocument(creditDoc, xmlFilename)); } catch (Exception ex) { return(FromException(ex)); } }