コード例 #1
0
        /// <summary>
        /// Genera un documento XML para la emision de un comprobante.
        /// </summary>
        /// <param name="invoiceHeaderEntity">Entidad Invoice</param>
        /// <returns>Retorna el XML generado.</returns>
        public XmlFileResult GeneraDocumentoInvoice(InvoiceHeader invoiceHeaderEntity)
        {
            try
            {
                #region Filename
                var xmlFilename =
                    $"{invoiceHeaderEntity.RucEmisor}-{(int) invoiceHeaderEntity.TipoDocumento:00}-" +
                    $"{invoiceHeaderEntity.SerieDocumento}-{invoiceHeaderEntity.CorrelativoDocumento}";
                #endregion

                #region Gen Invoice
                AmountType.TlsDefaultCurrencyID = invoiceHeaderEntity.CodigoMoneda;

                var invoice = new InvoiceType
                {
                    ID                   = $"{invoiceHeaderEntity.SerieDocumento}-{invoiceHeaderEntity.CorrelativoDocumento}",
                    IssueDate            = invoiceHeaderEntity.FechaEmision,
                    InvoiceTypeCode      = ((int)invoiceHeaderEntity.TipoDocumento).ToString("00"),
                    DocumentCurrencyCode = invoiceHeaderEntity.CodigoMoneda,
                    CustomizationID      = "1.0",
                    OrderReference       = invoiceHeaderEntity.Compra != null ? new OrderReferenceType {
                        ID = invoiceHeaderEntity.Compra
                    } : null,
                    DespatchDocumentReference   = UtilsXmlDoc.DevuelveGuiasRemisionReferenciadas(invoiceHeaderEntity.GuiaRemisionReferencia),
                    AdditionalDocumentReference = UtilsXmlDoc.DevuelveDocumentosReferencia(invoiceHeaderEntity),
                    UBLExtensions = new[]
                    { new UBLExtensionType
                      {
                          ExtensionContent = new AdditionalsInformationType   //(mas informacion en el catalogo no 14 del manual.)
                          {
                              AdditionalInformation = new AdditionalInformationType {
                                  AdditionalMonetaryTotal    = UtilsXmlDoc.DevuelveTributosAdicionales(invoiceHeaderEntity.TotalTributosAdicionales),
                                  AdditionalProperty         = invoiceHeaderEntity.InfoAddicional.ToArray(),
                                  SUNATEmbededDespatchAdvice = invoiceHeaderEntity.GuiaEmbebida,
                                  SUNATTransaction           = invoiceHeaderEntity.TipoOperacion.HasValue ? new SUNATTransactionType
                                  {
                                      ID = ((int)invoiceHeaderEntity.TipoOperacion).ToString("00")
                                  }: null
                              }
                          }
                      },
                      new UBLExtensionType
                      {
                          ExtensionContent = new AdditionalsInformationType(),
                      } },
                    Signature = UtilsXmlDoc.GetSignature(invoiceHeaderEntity),
                    AccountingSupplierParty = UtilsXmlDoc.GetInfoEmisor(invoiceHeaderEntity),
                    SellerSupplierParty     = invoiceHeaderEntity.VendedorCodigo != null || invoiceHeaderEntity.VendedorNombre != null ? new SupplierPartyType
                    {
                        CustomerAssignedAccountID = invoiceHeaderEntity.VendedorCodigo,
                        Party = new PartyType
                        {
                            PartyName = new PartyNameType[] { invoiceHeaderEntity.VendedorNombre }
                        }
                    }: null,
                    AccountingCustomerParty = new CustomerPartyType
                    {
                        CustomerAssignedAccountID = invoiceHeaderEntity.NroDocCliente,
                        AdditionalAccountID       =
                            new IdentifierType[] { ((int)invoiceHeaderEntity.TipoDocumentoIdentidadCliente).ToString() },
                        Party = new PartyType
                        {
                            PostalAddress = string.IsNullOrWhiteSpace(invoiceHeaderEntity.DireccionCliente) ? null : new AddressType
                            {
                                StreetName = invoiceHeaderEntity.DireccionCliente
                            },
                            PartyLegalEntity = new[]
                            {
                                new PartyLegalEntityType
                                {
                                    RegistrationName = invoiceHeaderEntity.NombreRazonSocialCliente,
                                }
                            }
                        },
                        BuyerContact = invoiceHeaderEntity.CorreoCliente != null ? new ContactType {
                            ElectronicMail = invoiceHeaderEntity.CorreoCliente
                        } : null
                    },
                    PaymentMeans = invoiceHeaderEntity.Vencimiento != null ? new []
                    {
                        new PaymentMeansType
                        {
                            PaymentMeansCode = "-",
                            PaymentDueDate   = invoiceHeaderEntity.Vencimiento.Value
                        }
                    }: null,
                    PrepaidPayment     = UtilsXmlDoc.GetAnticipos(invoiceHeaderEntity.Anticipos),
                    LegalMonetaryTotal = new MonetaryTotalType
                    {
                        AllowanceTotalAmount = invoiceHeaderEntity.DescuentoGlobal > 0 ? new AmountType {
                            Value = invoiceHeaderEntity.DescuentoGlobal
                        } : null,
                        PrepaidAmount = invoiceHeaderEntity.TotalAnticipos.HasValue ? new AmountType {
                            Value = invoiceHeaderEntity.TotalAnticipos.Value
                        } : null,
                        PayableAmount = invoiceHeaderEntity.TotalVenta
                    },
                    InvoiceLine = UtilsXmlDoc.DevuelveDetallesDelComprobante(invoiceHeaderEntity.DetallesDocumento),
                    TaxTotal    = UtilsXmlDoc.DevuelveSubTotalImpuestos(invoiceHeaderEntity.Impuesto)
                };
                invoice.AccountingSupplierParty.Party.PostalAddress = UtilsXmlDoc.ObtenerDireccion(invoiceHeaderEntity.DireccionEmisor);
                #endregion

                return(FromDocument(invoice, xmlFilename));
            }
            catch (Exception ex)
            {
                return(FromException(ex));
            }
        }
コード例 #2
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));
            }
        }