public XmlDocGeneratorTests() { var filename = Path.Combine(Environment.CurrentDirectory, "Resources", "SFSCert.p"); var certify = new X509Certificate2(File.ReadAllBytes(filename), "123456"); _generator = new XmlDocGenerator(certify); }
private string WorkingNotaDebito(Tuple <ventaDto, clienteDto, decimal> objs) { #region Entidades var objVenta = objs.Item1; var client = objs.Item2; #endregion #region Gen Entidad Nota Credito Init(); var notaDebit = new DebitNoteHeader(GetBaseNota(objVenta, client, objs.Item3)) { TipoNota = (TipoNotaDebitoElectronica)Enum.ToObject(typeof(TipoNotaDebitoElectronica), objVenta.i_IdTipoNota ?? 1) }; #endregion #region Generando XML var objOperationResult = new OperationResult2(); var xmlResultPath = new XmlDocGenerator(_cert).GenerarDocumentoDebitNote(ref objOperationResult, notaDebit); return(objOperationResult.Success ? xmlResultPath : string.Empty); #endregion }
/// <summary> /// Initializes a new instance of the <see cref="XmlManager"/> class. /// </summary> /// <param name="company">The company.</param> public XmlManager(Company company) { var cert = new X509Certificate2(company.Certified.Content, company.Certified.Password); _xmlGenerator = new XmlDocGenerator(cert); }
private string WorkingInvoice(Tuple <ventaDto, clienteDto, decimal> objs) { #region Entidad var objventa = objs.Item1; var client = objs.Item2; #endregion #region Generando la Entidad Invoice Init(); var tipoComprobante = (TipoDocumentoElectronico)Enum.ToObject(typeof(TipoDocumentoElectronico), objventa.i_IdTipoDocumento ?? 1); var tipoDocIdentidadClient = (TipoDocumentoIdentidad)Enum.ToObject(typeof(TipoDocumentoIdentidad), client.i_IdTipoIdentificacion ?? 1); var invoiceHeaderEntity = new InvoiceHeader { TipoDocumento = tipoComprobante, SerieDocumento = objventa.v_SerieDocumento, CorrelativoDocumento = objventa.v_CorrelativoDocumento, FechaEmision = objventa.t_FechaRegistro ?? DateTime.Now, NombreRazonSocialCliente = System.Text.RegularExpressions.Regex.Replace(string.Join(" ", client.v_ApePaterno, client.v_ApeMaterno, client.v_PrimerNombre, client.v_SegundoNombre, client.v_RazonSocial), @"[^\w\.-]", " ").Trim(), NroDocCliente = client.v_NroDocIdentificacion, RucEmisor = _config.v_Ruc, NombreRazonSocialEmisor = _config.v_RazonSocial, NombreComercialEmisor = _config.v_NombreComercial, CodigoMoneda = objventa.i_IdMoneda == 1 ? "PEN" : "USD", TipoDocumentoIdentidadCliente = tipoDocIdentidadClient, TipoDocumentoIdentidadEmisor = TipoDocumentoIdentidad.RegistroUnicoContribuyentes, DetallesDocumento = new List <InvoiceDetail>(), TotalVenta = objventa.d_Total ?? 0M, InfoAddicional = new List <AdditionalPropertyType>(), Impuesto = GetImpuestosGlobal(objventa), DireccionEmisor = new DireccionType { CodigoPais = "PE", CodigoUbigueo = _config.v_Ubigueo, Direccion = _config.v_Domicilio, Zona = _config.v_Urbanizacion, Departamento = _config.v_Departamento, Provincia = _config.v_Provincia, Distrito = _config.v_Distrito, } }; if (!string.IsNullOrWhiteSpace(objventa.v_SerieDocumentoRef)) { invoiceHeaderEntity.DocumentoReferenciaNumero = objventa.v_SerieDocumentoRef + "-" + objventa.v_CorrelativoDocumentoRef; invoiceHeaderEntity.DocumentoReferenciaTipoDocumento = (TipoDocumentoElectronico)Enum.ToObject(typeof(TipoDocumentoElectronico), objventa.i_IdTipoDocumentoRef ?? 1); } if (!string.IsNullOrWhiteSpace(objventa.v_NroGuiaRemisionSerie)) { invoiceHeaderEntity.GuiaRemisionReferencia = new List <GuiaRemisionType> { new GuiaRemisionType { IdTipoGuiaRemision = "09", // Tipo Guia Remision NumeroGuiaRemision = objventa.v_NroGuiaRemisionSerie + "-" + objventa.v_NroGuiaRemisionCorrelativo } }; } //Descuento Global var factDesc = 1M; if (IsValueNotNullorZero(objventa.d_PorcDescuento)) { factDesc = 1 - (objventa.d_PorcDescuento ?? 0) / 100; var valTotal = objventa.d_Total / factDesc; invoiceHeaderEntity.DescuentoGlobal = valTotal - objventa.d_Total ?? 0; } var sumTotales = LoadDetail(invoiceHeaderEntity.DetallesDocumento, objventa, objs.Item3); invoiceHeaderEntity.TotalTributosAdicionales = GetTributosAddicionales(sumTotales, factDesc); if (invoiceHeaderEntity.TotalVenta != 0M) { invoiceHeaderEntity.InfoAddicional.Add(new AdditionalPropertyType { ID = "1000", // Monto en Letras Value = Utils.Utils.ConvertirenLetras(objventa.d_Total ?? 0) }); } if (objventa.i_EsGratuito == 1) { invoiceHeaderEntity.InfoAddicional.Add(new AdditionalPropertyType { ID = "1002", Value = "TRANSFERENCIA GRATUITA DE UN BIEN Y/O SERVICIO PRESTADO GRATUITAMENTE" }); } if (IsValueNotNullorZero(objventa.d_Descuento)) //Si Tiene Descuentos { invoiceHeaderEntity.TotalTributosAdicionales.Add(new TotalTributosType { Id = OtrosConceptosTributarios.TotalDescuentos, MontoPagable = objventa.d_Descuento ?? 0 }); } #endregion #region Generando XML var objOperationResult = new OperationResult2(); var xmlResultPath = new XmlDocGenerator(_cert).GeneraDocumentoInvoice(ref objOperationResult, invoiceHeaderEntity); return(objOperationResult.Success ? xmlResultPath : ""); #endregion }