XtraReport CreateReport(string clave) { XtraReport report = null; using (var conexion = new DataModelFE()) { WSRecepcionPOSTProforma dato = conexion.WSRecepcionPOSTProforma.Where(x => x.clave == clave).FirstOrDefault(); if (dato != null) { string xml = EncodeXML.EncondeXML.base64Decode(dato.comprobanteXml); //Revertimos lo de la proforma xml = xml.Replace("FacturaElectronica", "ProformaElectronica"); RptComprobanteProformas reportES = new RptComprobanteProformas(); //Crear Proforma en Inglés RptComprobanteProformasEN reportEN = new RptComprobanteProformasEN(); ProformaElectronica documento = (ProformaElectronica)EncodeXML.EncondeXML.getObjetcFromXML(xml); Empresa empresa = conexion.Empresa.Find(documento.emisor.identificacion.numero); if (empresa != null && "EN".Equals(empresa.idioma)) { object dataSource = UtilidadesReporte.cargarObjetoImpresionProforma(documento, dato.mensaje, empresa); reportEN.objectDataSource1.DataSource = dataSource; string enviroment_url = ConfigurationManager.AppSettings["ENVIROMENT_URL_PROFORMA"].ToString(); reportEN.xrBarCode1.Text = (enviroment_url + documento.clave).ToUpper(); if (empresa != null && empresa.logo != null) { reportEN.pbLogo.Image = UtilidadesReporte.byteArrayToImage(empresa.logo); } reportEN.CreateDocument(); report = reportEN; } else { object dataSource = UtilidadesReporte.cargarObjetoImpresionProforma(documento, dato.mensaje, empresa); reportES.objectDataSource1.DataSource = dataSource; string enviroment_url = ConfigurationManager.AppSettings["ENVIROMENT_URL_PROFORMA"].ToString(); reportES.xrBarCode1.Text = (enviroment_url + documento.clave).ToUpper(); if (empresa != null && empresa.logo != null) { reportES.pbLogo.Image = UtilidadesReporte.byteArrayToImage(empresa.logo); } reportES.CreateDocument(); report = reportES; } } } return(report); }
public static string enviarProforma(ProformaElectronica documento, string tipoDocumento, string usuario) { String responsePostProforma = ""; try { string xmlFile = EncodeXML.XMLUtils.getXMLFromObject(documento); using (var conexion = new DataModelFE()) { WSDomain.WSRecepcionPOSTProforma trama = new WSDomain.WSRecepcionPOSTProforma(); trama.clave = XMLUtils.buscarValorEtiquetaXML(XMLUtils.tipoDocumentoXML(xmlFile), "Clave", xmlFile); trama.fecha = DateTime.ParseExact(XMLUtils.buscarValorEtiquetaXML(XMLUtils.tipoDocumentoXML(xmlFile), "FechaEmision", xmlFile), "yyyy-MM-ddTHH:mm:ss-06:00", System.Globalization.CultureInfo.InvariantCulture); string emisorIdentificacion = XMLUtils.buscarValorEtiquetaXML("Emisor", "Identificacion", xmlFile); trama.emisor.tipoIdentificacion = emisorIdentificacion.Substring(0, 2); trama.emisor.numeroIdentificacion = emisorIdentificacion.Substring(2); trama.emisorTipo = trama.emisor.tipoIdentificacion; trama.emisorIdentificacion = trama.emisor.numeroIdentificacion; string receptorIdentificacion = XMLUtils.buscarValorEtiquetaXML("Receptor", "Identificacion", xmlFile); if (!string.IsNullOrWhiteSpace(receptorIdentificacion)) { trama.receptor.tipoIdentificacion = receptorIdentificacion.Substring(0, 2); trama.receptor.numeroIdentificacion = receptorIdentificacion.Substring(2); } else { trama.receptor.tipoIdentificacion = "99"; trama.receptor.numeroIdentificacion = XMLUtils.buscarValorEtiquetaXML("Receptor", "IdentificacionExtranjero", xmlFile); } trama.montoTotalImpuesto = Convert.ToDecimal(XMLUtils.buscarValorEtiquetaXML("ResumenFactura", "TotalImpuesto", xmlFile)); trama.montoTotalFactura = Convert.ToDecimal(XMLUtils.buscarValorEtiquetaXML("ResumenFactura", "TotalComprobante", xmlFile)); trama.receptorTipo = trama.receptor.tipoIdentificacion; trama.receptorIdentificacion = trama.receptor.numeroIdentificacion; trama.tipoDocumento = tipoDocumento; trama.consecutivoReceptor = null; trama.comprobanteXml = xmlFile; trama.indEstado = 1; WSRecepcionPOSTProforma tramaExiste = conexion.WSRecepcionPOSTProforma.Find(trama.clave); if (tramaExiste != null) {// si existe trama.fechaModificacion = Date.DateTimeNow(); trama.usuarioModificacion = usuario; trama.indEstado = 1; trama.cargarEmisorReceptor(); conexion.Entry(tramaExiste).State = EntityState.Modified; } else//si no existe { trama.fechaCreacion = Date.DateTimeNow(); trama.usuarioCreacion = usuario; trama.cargarEmisorReceptor(); conexion.WSRecepcionPOSTProforma.Add(trama); } conexion.SaveChanges(); } } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(fullErrorMessage, ex.EntityValidationErrors); } catch (Exception ex) { throw new Exception(Utilidades.validarExepcionSQL(ex), ex.InnerException); } return(responsePostProforma); }
public static Impresion cargarObjetoImpresionProforma(ProformaElectronica dato, string mensajeHacienda, Empresa empresa) { Impresion impresion = new Impresion(); impresion.emisorNombre = dato.emisor.nombre; impresion.emisorIdentificacion = dato.emisor.identificacion.numero; impresion.emisorNombreComercial = dato.emisor.nombreComercial; impresion.emisorIdentificacionCorreo = dato.emisor.correoElectronico; impresion.emisorTelefonos = dato.emisor.telefono.numTelefono; using (var conexion = new DataModelFE()) { Web.Models.Catalogos.Ubicacion oDato = conexion.Ubicacion.Where(x => x.codProvincia == dato.emisor.ubicacion.provincia && x.codCanton == dato.emisor.ubicacion.canton && x.codDistrito == dato.emisor.ubicacion.distrito && x.codBarrio == dato.emisor.ubicacion.barrio).FirstOrDefault(); if (oDato != null) { impresion.emisorDireccion = ProperCase.ToTitleCase(oDato.nombreProvincia) + " , " + ProperCase.ToTitleCase(oDato.nombreCanton) + " , " + ProperCase.ToTitleCase(oDato.nombreDistrito) + " , " + ProperCase.ToTitleCase(dato.emisor.ubicacion.otrassenas); } else { impresion.emisorDireccion = ProperCase.ToTitleCase(dato.emisor.ubicacion.otrassenas); } } //dato.emisor.ubicacion.provincia.ToUpper().ToString() + ", " + dato.emisor.ubicacion.canton.ToUpper().ToString() + ", " + dato.emisor.ubicacion.distrito.ToUpper().ToString() + ", " + impresion.receptorNombre = dato.receptor.nombre; impresion.receptorIdentificacion = dato.receptor.identificacion.numero; impresion.receptorIdentificacionCorreo = dato.receptor.correoElectronico; impresion.clave = dato.clave; impresion.consecutivo = dato.clave.Substring(21, 20); impresion.fecha = dato.fechaEmision.Replace("T", " ").Replace("-06:00", ""); impresion.moneda = dato.resumenFactura.codigoMoneda; impresion.tipoCambio = dato.resumenFactura.tipoCambio.ToString("n2"); /* * if (empresa != null) * { * mensaje += String.Format(" {0}", empresa.leyenda); * } */ foreach (var otros in dato.otros.otrosTextos) { impresion.leyenda += string.Format("{0}\n", otros); } using (var conexion = new DataModelFE()) { if (empresa != null && "EN".Equals(empresa.idioma)) { if (string.IsNullOrWhiteSpace(impresion.leyenda)) { impresion.leyenda = empresa.leyenda; } impresion.tipoDocumento = conexion.TipoDocumento.Find(dato.tipoDocumento).descripcionEN; impresion.CondicionVenta = conexion.CondicionVenta.Find(dato.condicionVenta).descripcionEN; impresion.MedioPago = conexion.MedioPago.Find(dato.medioPago).descripcionEN; if (impresion.CondicionVenta.Equals(CondicionVenta.CREDIT)) { impresion.CondicionVenta += string.Format(" / {0} DAYS", dato.plazoCredito); } } else { impresion.tipoDocumento = conexion.TipoDocumento.Find(dato.tipoDocumento).descripcion; impresion.CondicionVenta = conexion.CondicionVenta.Find(dato.condicionVenta).descripcion; impresion.MedioPago = conexion.MedioPago.Find(dato.medioPago).descripcion; if (impresion.CondicionVenta.Equals(CondicionVenta.CREDITO)) { impresion.CondicionVenta += string.Format(" / {0} DÍAS", dato.plazoCredito); } } } impresion.detalles = new List <ImpresionDetalle>(); foreach (var item in dato.detalleServicio.lineaDetalle) { ImpresionDetalle detalle = new ImpresionDetalle(); detalle.cantidad = int.Parse(item.cantidad.ToString()); detalle.codigo = item.codigo.codigo; if (empresa != null && "EN".Equals(empresa.idioma)) { detalle.descripcion = string.Format("{0} - {1}", item.detalle, impresion.fecha.Substring(0, 7)); } else { detalle.descripcion = item.detalle; } detalle.monto = item.montoTotal; detalle.precioUnitario = item.precioUnitario; detalle.impuesto = item.impuestos.Sum(x => x.monto); impresion.detalles.Add(detalle); } impresion.montoSubTotal = dato.resumenFactura.totalVenta; impresion.montoDescuento = dato.resumenFactura.totalDescuentos; impresion.montoImpuestoVenta = dato.resumenFactura.totalImpuesto; impresion.montoTotal = dato.resumenFactura.totalComprobante; impresion.fechaImpresion = Date.DateTimeNow(); return(impresion); }
private XtraReport CreateReport() { XtraReport report1 = new XtraReport(); XtraReport report2 = new XtraReport(); List <XtraReport> oLista = new List <XtraReport>(); XtraReport report = null; var pLista = (List <String>)Session["claves"]; foreach (var item in pLista) { XtraReport reportP = new XtraReport(); using (var conexion = new DataModelFE()) { WSRecepcionPOSTProforma dato = conexion.WSRecepcionPOSTProforma.Where(x => x.clave == item.ToString()).FirstOrDefault(); string xml = EncodeXML.XMLUtils.base64Decode(dato.comprobanteXml); //Cambiar sector a Factura Electrónica xml = xml.Replace("FacturaElectronica", "ProformaElectronica");// esto es solo para que no se reemplace por el de abajo RptComprobante reportES = new RptComprobante(); RptComprobanteEN reportEN = new RptComprobanteEN(); ProformaElectronica documento = (ProformaElectronica)EncodeXML.XMLUtils.getObjetcFromXML(xml); Empresa empresa = conexion.Empresa.Find(documento.emisor.identificacion.numero); if (empresa != null && "EN".Equals(empresa.idioma)) { object dataSource = UtilidadesReporte.cargarObjetoImpresionProforma(documento, dato.mensaje, empresa); reportEN.objectDataSource1.DataSource = dataSource; string enviroment_url = ConfigurationManager.AppSettings["ENVIROMENT_URL"].ToString(); reportEN.xrBarCode1.Text = (enviroment_url + documento.clave).ToUpper(); if (empresa != null && empresa.logo != null) { reportEN.pbLogo.Image = UtilidadesReporte.byteArrayToImage(empresa.logo); } reportEN.CreateDocument(); reportP = reportEN; } else { object dataSource = UtilidadesReporte.cargarObjetoImpresionProforma(documento, dato.mensaje, empresa); reportES.objectDataSource1.DataSource = dataSource; string enviroment_url = ConfigurationManager.AppSettings["ENVIROMENT_URL"].ToString(); reportES.xrBarCode1.Text = (enviroment_url + documento.clave).ToUpper(); if (empresa != null && empresa.logo != null) { reportES.pbLogo.Image = UtilidadesReporte.byteArrayToImage(empresa.logo); } reportES.CreateDocument(); reportP = reportES; } } oLista.Add(reportP); } if (oLista.Count == 1) { report1 = oLista[0]; } else { if (oLista.Count == 2) { report1 = oLista[0]; report2 = oLista[1]; report1.Pages.AddRange(report2.Pages); report1.PrintingSystem.ContinuousPageNumbering = true; } else { for (int i = 0; i < oLista.Count - 1; i++) { if (i == 0) { report1 = oLista[i]; } else { report1 = report1; } report2 = oLista[i + 1]; report1.Pages.AddRange(report2.Pages); report1.PrintingSystem.ContinuousPageNumbering = true; } } } report = report1; return(report); }