using DataAccessLibrary.Model.HelperClasses; using DataAccessLibrary.Utility.HelperClasses.Helpers; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using Microsoft.SqlServer.Server; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SQLite; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Font = iTextSharp.text.Font; using Image = iTextSharp.text.Image; using System.IO.Compression; using Path = System.IO.Path; using ECV; namespace CKUERA { public partial class Rep_ventas : Form { public Rep_ventas() { InitializeComponent(); } private void Rep_ventas_Resize(object sender, EventArgs e) { button2.Left = 3000; panel1.Left = this.Width / 2 - panel1.Width / 2; panel1.Top = this.Height / 2 - panel1.Height / 2; Btn_Cerrar.Top = 0; Btn_Cerrar.Left = panel1.Width - Btn_Cerrar.Width; Button1.BackColor = Global.ColorSistema;// Btn_Libro.BackColor = this.BackColor = Global.ColorSistema;// this.BackColor = Global.ColorSistema;//fp.Label1.BackColor; Lb_Titulo.Top = 0; Lb_Titulo.Left = 0; Lb_Titulo.Text = this.Text; } private void FaltaLic() { panel5.Top = 0; panel5.Left = 0; panel5.Height = this.Height; panel5.Width = this.Width; } private void Licencia() { mensaje_lab.Visible = true; HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/lventas_lic.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", "")); rq.ContentType = "application/x-www-form-urlencoded"; rq.ContentLength = byteArray.Length; Stream stream = rq.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); // utf8_encode stream.Close(); WebResponse response = rq.GetResponse(); stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string devuelve = reader.ReadToEnd(); reader.Close(); stream.Close(); response.Close(); string[] c = devuelve.Split('▲'); string resultado = devuelve.ToUpper(); bool re; re = resultado.Contains(" 89)//SI EL REGISTRO TIENE 30 DÍGITOS... { string LicNum = Global.LVentas_Lic.Replace("xTz", "1"); LicNum = LicNum.Replace("QkU", "2"); LicNum = LicNum.Replace("oPi", "3"); LicNum = LicNum.Replace("YwB", "4"); LicNum = LicNum.Replace("lnI", "5"); LicNum = LicNum.Replace("CfL", "6"); LicNum = LicNum.Replace("VaZ", "7"); LicNum = LicNum.Replace("RgM", "8"); LicNum = LicNum.Replace("HsD", "9"); LicNum = LicNum.Replace("JuE", "0"); Global.LVentas_Lic = LicNum; } else { MessageBox.Show("Licencia inválida para el uso del sistema.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error); panel5.Visible = true; this.Text = "Libro de Ventas - SERIE: " + Global.SerieServ; FaltaLic(); mensaje_lab.Visible = false; return; } if (Global.LVentas_Lic.Length > 29)//SI EL REGISTRO TIENE 30 DÍGITOS... { int fechalim = 0; int Modulo = int.Parse(Global.LVentas_Lic.Substring(0, 4)); if (Modulo != 103)//SI EL MÓDULO NO ES { MessageBox.Show("La licencia del modulo no corresponde.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error); panel5.Visible = true; this.Text = "Libro de Ventas - SERIE: " + Global.SerieServ; FaltaLic(); mensaje_lab.Visible = false; return; } if (Global.LVentas_Lic.Substring(4, 15) != Global.SerieServ)//SI LOS 15 DÍGITOS NO SON IGUALES A LA SERIE DEL SERVIDOR... { MessageBox.Show("Licencia vencida o no es correcta.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error); panel5.Visible = true; this.Text = "Libro de Ventas - SERIE: " + Global.SerieServ; FaltaLic(); mensaje_lab.Visible = false; return; } else//SI EL REGISTRO CORRECPONDE A LA SERIE DE LA PC... { //CONSULTA LA VALIDÉZ DE LA FECHA** fechalim = int.Parse(Global.LVentas_Lic.Substring(22, 8)); //SI EL REGISTRO.FECHA ES IGUAL A LA SERIE.FECHA (20210321)... if (Global.fechahoy > fechalim) { MessageBox.Show("Licencia vencida.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error); panel5.Visible = true; this.Text = "Libro de Ventas - SERIE: " + Global.SerieServ; FaltaLic(); mensaje_lab.Visible = false; return; } } panel5.Visible = false; string fechaL = Global.LVentas_Lic.Substring(22, 8); CrearLV(); mensaje_lab.Visible = false; } else { MessageBox.Show("Licencia inválida para el uso del sistema.\nConsulte con su proveedor.", "UFF, ¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Error); panel5.Visible = true; this.Text = "Libro de Ventas - SERIE: " + Global.SerieServ; FaltaLic(); mensaje_lab.Visible = false; return; } } private void Rep_ventas_Load(object sender, EventArgs e) { if (int.Parse(Global.version) < 2) { chec_rep_cliente.Visible= false; } panel2.Top = 34; panel5.Visible = false; Op_Productos.Checked = true; { Fecha_desde.Text = DateTime.Now.ToString(); Fecha_hasta.Text = DateTime.Now.ToString(); HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/cargar_usuarios.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", "")); rq.ContentType = "application/x-www-form-urlencoded"; rq.ContentLength = byteArray.Length; Stream stream = rq.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); stream.Close(); // WebResponse response = rq.GetResponse(); stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string devuelve = reader.ReadToEnd(); reader.Close(); stream.Close(); response.Close(); if (devuelve.Length > 100)//si el mensaje es un error... { MessageBox.Show(devuelve); } Operador_box.Items.Clear();//BORRA TODO foreach (var line in devuelve.Trim().Split('↔'))//cada línea se separa por '↔' { if (line == "") continue;//si la última línea está vacía, continua al siguiente proceso var valores = line.Split('▲');//dentro de cada línea se separa por columna ('▲') Operador_box.Items.Add(valores[0]); } } { string name = "iconos\\reportar.png"; try { Button1.Image = System.Drawing.Image.FromFile(name); } catch (Exception) { } } } private void Button1_Click(object sender, EventArgs e) { mensaje_lab.Visible = true; mensaje_lab.Visible=true; mensaje_lab.Refresh(); this.Cursor= Cursors.WaitCursor; Button1.Enabled=false; Global.fecha_desdex = string.Format("{0:yyyy-MM-dd}", Fecha_desde.Value); Global.fecha_hastax = string.Format("{0:yyyy-MM-dd}", Fecha_hasta.Value); Global.operadorRp = Operador_box.Text; Global.Op_Contado = Opcion_Contado.Checked;//Solo Contado Global.Op_Credito = Opcion_Credito.Checked;//Solo Crédito Global.Op_Ambos = Opcion_Ambos.Checked;//Contado y Crédito Global.Op_Incluir_IN_EG = Opcion_Ing_Egr.Checked;//Contado incluido Ingr-Egre Global.OP_Ambos_Incl_IN_EG = Opcion_Ambos_Ing_Egr.Checked;////Contado y Crédito, Incluidos IN-EG Global.NoVenta_Op_Ingresos = NoVenta_Opcion_S_ingr.Checked; Global.NoVenta_Op_Egresos = NoVenta_Opcion_S_egr.Checked; Global.NoVenta_Op_Ing_Egr_Ambos = NoVenta_ing_egr_ambos.Checked; Global.TotalRp = 0; if (Op_Productos.Checked == true) { pdf_Report_V_X_Prod Rep_Prod = new pdf_Report_V_X_Prod(); Rep_Prod.Mostrar_ReportPRO_pdf(); Button1.Enabled = true; this.Cursor = Cursors.Default; } else { pdf_Report rpdf = new pdf_Report(); rpdf.Mostrar_Report_pdf(); //Total_label.Text = Global.SIMB_ + " " + string.Format("{0:#,##0.##}", Global.TotalRp); mensaje_lab.Visible = false; mensaje_lab.Refresh(); Button1.Enabled = true; this.Cursor = Cursors.Default; } mensaje_lab.Visible = false; mensaje_lab.Refresh(); } private void Op_Productos_CheckedChanged(object sender, EventArgs e) { if (Op_Productos.Checked == true) { Operador_box.Enabled = false; } else { Operador_box.Enabled = true; } } private void Btn_Libro_Click(object sender, EventArgs e) { Licencia(); } private void CrearLV() { this.Cursor = Cursors.WaitCursor; string FechaDesde = string.Format("{0:yyyy-MM}", Fecha_desde.Value); HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/libro_ventas.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", FechaDesde)); rq.ContentType = "application/x-www-form-urlencoded"; rq.ContentLength = byteArray.Length; Stream stream = rq.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); stream.Close(); // WebResponse response = rq.GetResponse(); stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string devuelve = reader.ReadToEnd(); reader.Close(); stream.Close(); response.Close(); string resultado = devuelve.ToUpper(); bool re; re = resultado.Contains("_REG_MMAAAA_XXXXX ruta = LaCarpeta + "\\" + ElArchivo; foreach (var line in devuelve.Trim().Split('↔'))//cada línea se separa por '↔' { if (line == "") continue;//si la última línea está vacía, continua al siguiente proceso var v = line.Trim().Split('▲');//dentro de cada línea se separa por columna ('▲') if (v[0].Length > 4)// SI RUC ES MAS QUE 4 CARACTERES { if (v[0].Substring(v[0].Length - 2, 1) == "-") //SI ES RUC { Iden = "11"; //RUC NumIden = v[0].Substring(0, v[0].Length - 2); Cliente = v[1]; } else { Iden = "12"; //CEDULA NumIden = v[0].Trim(); Cliente = v[1]; } if (v[0].Substring(v[0].Length - 4, 4).ToString().Trim().Length == 0) { Iden = "13"; //"PASAPORTE " NumIden = v[0].Trim(); Cliente = v[1]; } if (v[0].Substring(v[0].Length - 4, 4).ToString().Trim().Length == 1) { Iden = "14"; //" CEDULA EXTRANJERA " NumIden = v[0].Trim(); Cliente = v[1]; } if (v[0].Substring(v[0].Length - 4, 4).ToString().Trim().Length == 2) { Iden = "16"; //" CEDULA DIPLOMÁTICA " NumIden = v[0].Trim(); Cliente = v[1]; } if (v[0].Substring(v[0].Length - 4, 4).ToString().Trim().Length == 3) { Iden = "17"; //" CEDULA EXTRANJERA " NumIden = v[0].Trim(); Cliente = v[1]; } } else { Iden = "15";//SIN NOMBRE NumIden = "X"; Cliente = "SIN NOMBRE"; } double Grav10; double Grav5; double Grav0; double TotalM; Grav10 = Math.Round(double.Parse(v[4])); Grav5 = Math.Round(double.Parse(v[5])); Grav0 = Math.Round(double.Parse(v[6])); TotalM = Grav10 + Grav5 + Grav0; string Fecha = string.Format("{0:dd/MM/yyy}", v[2]); string NumFact = v[3]; Crear = Crear + "1\t" + Iden + "\t" + NumIden + "\t" + Cliente + "\t109\t" + Fecha + "\t" + Global.Timb_EMPRESA + "\t" + NumFact + "\t" + Grav10 + "\t" + Grav5 + "\t" + Grav0 + "\t" + TotalM + "\t1\tNO\t" + Global.trib_iva + "\t" + Global.trib_ire + "\t" + Global.trib_rsp + "\t " + "\n"; } Zipear(); FTPenviar(); Principal principal = new Principal(); principal.EnviarWhatsApp(Global.ID_WhatsApp, "*LIBRO DE VENTAS*\nEl libro de ventas se envió y está listo para bajar haciendo clic en el enlace.\nhttps://encpy.com/ecvlventas/" + ElArchivo.Substring(0,ElArchivo.Length-4) + ".zip", Global.Tel_WhatsApp); this.Cursor = Cursors.Default; } try { var escribe = new StreamWriter(ruta); escribe.WriteLine(Crear); escribe.Close(); this.Cursor = Cursors.Default; MessageBox.Show("El archivo se creo con éxito. Si el sistema tiene Internet y está configurado para enviar WhatsApp, entonces podría llegarle un mensaje con el enlace de descarga.", "LISTO", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("El archivo de ventas en cuestión no se creó.\n\nRAZONES:\n1) No hay datos en la BD origen.\n2) Ya existe y está abierto u ocupado por otro programa.\n\nPor favor verifique y vuelva a intentar más tarde.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Cursor = Cursors.Default; } } private static string LaCarpeta; private static string ElArchivo; private void FTPenviar() { this.Cursor = Cursors.WaitCursor; string ftpServerIP = "ftp.encpy.com"; string ftpUserName = "ecv@encpy.com"; string ftpPassword = "EcvKakaneroto17061972"; FileInfo objFile = new FileInfo(LaCarpeta + ".zip"); FtpWebRequest objFTPRequest; objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + objFile.Name)); objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword); objFTPRequest.KeepAlive = false; objFTPRequest.UseBinary = true; objFTPRequest.ContentLength = objFile.Length; objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile; int intBufferLength = 16 * 1024; byte[] objBuffer = new byte[intBufferLength]; FileStream objFileStream = objFile.OpenRead(); try { Stream objStream = objFTPRequest.GetRequestStream(); int len = 0; while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0) { objStream.Write(objBuffer, 0, len); } objStream.Close(); objFileStream.Close(); MessageBox.Show("El archivo se envió con éxito.", "LISTO", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Cursor = Cursors.Default; } catch (Exception) { this.Cursor = Cursors.Default; MessageBox.Show("No hay internet o está muy lenta la conexión. Intente de nuevo más tarde.", "¡QUÉ PENA!", MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); } } private void Zipear() { if(File.Exists(LaCarpeta + ".zip")) { File.Delete(LaCarpeta + ".zip"); } ZipFile.CreateFromDirectory(LaCarpeta, LaCarpeta + ".zip"); } private void CerrarRegLic_Click(object sender, EventArgs e) { panel5.Visible=false; } private void button3_Click(object sender, EventArgs e) { //DEVOLVIENDO EN NÚMEROS LAS LETRAS REGISTRADAS //string Encrip1 = Lic.Text.Trim().Replace("XT", "1"); //string Encrip2 = Encrip1.Replace("Q!K", "2"); //string Encrip3 = Encrip2.Replace("OP#", "3"); //string Encrip4 = Encrip3.Replace("Y$W", "4"); //string Encrip5 = Encrip4.Replace("NI%", "5"); //string Encrip6 = Encrip5.Replace("C&F", "6"); //string Encrip7 = Encrip6.Replace("AZ/", "7"); //string Encrip8 = Encrip7.Replace("R(G", "8"); //string Encrip9 = Encrip8.Replace("SD)", "9"); //string Encrip10 = Encrip9.Replace("U=E", "0"); string LicNum = Lic.Text.Trim(); if (LicNum.Length > 29) { HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/lventas_lic.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", LicNum)); rq.ContentType = "application/x-www-form-urlencoded"; rq.ContentLength = byteArray.Length; Stream stream = rq.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); // utf8_encode stream.Close(); WebResponse response = rq.GetResponse(); stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string devuelve = reader.ReadToEnd(); reader.Close(); stream.Close(); response.Close(); string[] c = devuelve.Split('▲'); string resultado = devuelve.ToUpper(); bool re; re = resultado.Contains(" 100) { MessageBox.Show(devuelve); //return; } //TEXTO QUE IRÁ DENTRO DE LA TABLA DEL CUERPO if (devuelve.Trim() != "") { foreach (var line in devuelve.Split('↔')) { var valores = line.Split('▲'); if (valores[0] != "") { Paragraph codigo = new Paragraph(); codigo.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); codigo.Add(valores[0].Trim()); Paragraph cantidad = new Paragraph(); cantidad.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); cantidad.Add(valores[1]); Paragraph Descr = new Paragraph(); Descr.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); Descr.Add(valores[2]); //devolver //Phrase Conte4 = new Phrase(string.Format("{0:#,##0.##}", double.Parse(valores[3])), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); //PdfPCell compra = new PdfPCell(Conte4); //compra.HorizontalAlignment = Element.ALIGN_RIGHT; //compra.BackgroundColor = new BaseColor(255, 255, 255); //compra.BorderColor = new BaseColor(211, 211, 211);//125,125,255 //quitar esta parte Paragraph compra = new Paragraph(); compra.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); compra.Add(valores[3]); //fin de quitar esta parte Phrase Conte5 = new Phrase(string.Format("{0:#,##0.##}", double.Parse(valores[4])), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell venta = new PdfPCell(Conte5); venta.HorizontalAlignment = Element.ALIGN_RIGHT; venta.BackgroundColor = new BaseColor(255, 255, 255); venta.BorderColor = new BaseColor(211, 211, 211);//125,125,255 //devolver //double comprax = double.Parse(valores[3]); //double ventax = double.Parse(valores[4]); //double porciento = (ventax / comprax) * 100 - 100; //devolver //Phrase Conte6 = new Phrase(porciento.ToString("0.##") + "%", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); //PdfPCell rec = new PdfPCell(Conte6); //rec.HorizontalAlignment = Element.ALIGN_RIGHT; //rec.BackgroundColor = new BaseColor(255, 255, 255); //rec.BorderColor = new BaseColor(211, 211, 211);//125,125,255 //quitar esta parte Paragraph rec = new Paragraph(); rec.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); rec.Add(valores[3]); //fin de quitar esta parte //devolver //Phrase Conte7 = new Phrase(string.Format("{0:0,##0.##}", double.Parse(valores[4]) - double.Parse(valores[3])), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); //PdfPCell margen = new PdfPCell(Conte7); //margen.HorizontalAlignment = Element.ALIGN_RIGHT; //margen.BackgroundColor = new BaseColor(255, 255, 255); //margen.BorderColor = new BaseColor(211, 211, 211);//125,125,255 //quitar esta parte Paragraph margen = new Paragraph(); margen.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); margen.Add(valores[3]); //fin de quitar esta parte //table.WidthPercentage = 100; table.DefaultCell.BorderColor = new BaseColor(211, 211, 211);//125,125,255 table.AddCell(codigo); table.AddCell(cantidad); table.AddCell(Descr); table.AddCell(compra); table.AddCell(venta); table.AddCell(rec); table.AddCell(margen); //devolver //Global.TotalVenta = Global.TotalVenta + double.Parse(valores[4]); //Global.TotalCompra = Global.TotalCompra + double.Parse(valores[3]); } } } Global.TotalMargen = Global.TotalVenta - Global.TotalCompra; double TotalPorcen = (Global.TotalVenta / Global.TotalCompra) * 100 - 100; //TOTAL DE VENTA QUE SALE EN LA CABECERA Paragraph title2 = new Paragraph(); title2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 14f, BaseColor.BLUE); title2.Add("Valor Venta " + Global.SIMB_ + " " + Global.TotalVenta.ToString("#,##0.##") + "\n" + "Valor Compra " + Global.SIMB_ + " " + Global.TotalCompra.ToString("#,##0.##") + "\n" + "Total Margen " + Global.SIMB_ + " " + Global.TotalMargen.ToString("#,##0.##") + "\n" + "Porcentaje promedio % " + TotalPorcen.ToString("#,##0.##")); title2.Alignment = Element.ALIGN_RIGHT; oDoc.Add(title2); string Monto = "\n*Valor Venta*\n" + Global.SIMB_ + " " + Global.TotalVenta.ToString("#,##0.##") + ".-\n\n" + "*Valor Compra*\n" + Global.SIMB_ + " " + Global.TotalCompra.ToString("#,##0.##") + ".-\n\n" + "*Total Margen*\n" + Global.SIMB_ + " " + Global.TotalMargen.ToString("#,##0.##") + ".-\n\n" + "*Porcentaje promedio %* " + TotalPorcen.ToString("#,##0.##"); //PARRAFO VACÍO COMO SEPARADOR Paragraph title3 = new Paragraph(); title3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 2, BaseColor.BLACK); title3.Add("."); title3.Alignment = Element.ALIGN_LEFT; oDoc.Add(title3); oDoc.Add(table); //WHATSSAPP AL ADMINISTRADOR Principal principal = new Principal(); principal.EnviarWhatsApp(Global.ID_WhatsApp, Titulo + "\n" + Monto + "\n\n*_" + Global.Nom_EMPRESA + "_*\nCaja " + Global.NUM_caja + ": " + Global.USUARIO_SIST + "\n" + Global.Tel_EMPRESA, Global.Tel_WhatsApp); principal.Espera(1);//segundos pdfw.Flush(); oDoc.Close(); System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL REPORTE EN PDF //return (null); } private void button6_Click(object sender, EventArgs e) { panel2.Visible= false; } private void chec_rep_cliente_CheckedChanged(object sender, EventArgs e) { } private void chec_rep_cliente_Click(object sender, EventArgs e) { chec_rep_cliente.Checked = false; Rep_Cliente_Prod rep_Cliente_Prod = new Rep_Cliente_Prod(); rep_Cliente_Prod.ShowDialog(); } } public class pdf_Report { public object Mostrar_Report_pdf() { Rep_ventas frv = new Rep_ventas(); string Fecha = DateTime.Today.ToString("dd-MM-yy"); //CREAR PDF string pdfgenerate = "\\DOC_PDF\\REPORTE.pdf"; iTextSharp.text.Document oDoc; iTextSharp.text.pdf.PdfWriter pdfw; PdfContentByte cb; float top1; //PREPARA EL PDF oDoc = new iTextSharp.text.Document(PageSize.A4, 30, 20, 20, 20); pdfw = PdfWriter.GetInstance(oDoc, new FileStream(pdfgenerate, FileMode.Create, FileAccess.Write, FileShare.None)); pdfw.CompressionLevel = PdfStream.BEST_COMPRESSION; pdfw.SetFullCompression(); oDoc.Open(); oDoc.NewPage(); top1 = oDoc.PageSize.Top; try { //ENCABEZADO LOGO (usado en reportes) Image logo = Image.GetInstance("logo.png", true); logo.CompressionLevel = PdfStream.NO_COMPRESSION; //logo.SetAbsolutePosition(60, top1 - 130); oDoc.Add(logo); } catch (Exception) { } cb = pdfw.DirectContent;//DEBE IR ANTES DE LAS LÍNEAS DE TEXTO // Creamos un titulo personalizado con tamaño de fuente 10 y color Azul Paragraph title = new Paragraph(); title.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 10f, BaseColor.BLACK); string Titulo = ""; if (Global.Op_Contado == true)//SI ES CONTADO { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ventas Contado, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo= "*REPORTE de Ventas* Contado, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Ventas Contado, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Contado, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } if (Global.Op_Credito == true)//SI ES CRÉDITO { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ventas Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Ventas Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } if (Global.Op_Ambos == true)//SI ES ambos CONTADO Y CREDITO { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ventas Contado y Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Contado y Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Ventas Contado y Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Contado y Crédito, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } if (Global.Op_Incluir_IN_EG == true)//SI ES CONTADO incluido ING-EGRE { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ventas Contado, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Contado, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Ventas Contado, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ventas* Contado, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } if (Global.OP_Ambos_Incl_IN_EG == true)//SI ES CONTADO Y CREDITO incluido ING-EGRE { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ventas Contado y Crédito, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo= "*REPORTE DE VENTAS* Contado y Crédito, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp; } else { title.Add("REPORTE de Ventas Contado y Crédito, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo= "*REPORTE DE VENTAS* Contado y Crédito, incluidos Ingresos y Egresos, desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)); } } if (Global.NoVenta_Op_Ingresos == true)//SI ES CONTADO SOLO INGRESOS { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ingresos (cobros y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ingresos* (cobros y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Ingresos (cobros y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ingresos* (cobros y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } if (Global.NoVenta_Op_Egresos == true)//SI ES CONTADO SOLO EGRESOS { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Egresos (pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Egresos* (pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Egresos (pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo= "*REPORTE de Egresos* (pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } if (Global.NoVenta_Op_Ing_Egr_Ambos == true)//SI ES CONTADO INGRESOS Y EGRESOS { if (Global.operadorRp.Length > 0) { title.Add("REPORTE de Ingresos y Egresos (cobros, pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo = "*REPORTE de Ingresos y Egresos* (cobros, pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nVentas hechas por " + Global.operadorRp + "\nReporte Generado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } else { title.Add("REPORTE de Ingresos y Egresos (cobros, pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString()); Titulo= "*REPORTE de Ingresos y Egresos* (cobros, pagos y otros), desde el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_desdex)) + ", hasta el " + string.Format("{0:dd-MM-yyyy}", DateTime.Parse(Global.fecha_hastax)) + "\nGenerado por " + Global.USUARIO_SIST + " - Caja " + Global.NUM_caja + " - Fecha: " + DateTime.Now.ToString(); } } title.Alignment = Element.ALIGN_LEFT; oDoc.Add(title); PdfPTable table = new PdfPTable(7); //TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO Paragraph TEXTO_T1 = new Paragraph(); TEXTO_T1.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T1.Add("FECHA"); Paragraph TEXTO_T2 = new Paragraph(); TEXTO_T2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T2.Add("HORA"); Paragraph TEXTO_T3 = new Paragraph(); TEXTO_T3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T3.Add("CAJA"); Paragraph TEXTO_T4 = new Paragraph(); TEXTO_T4.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T4.Add("COMPROBANTE"); Paragraph TEXTO_T5 = new Paragraph(); TEXTO_T5.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); TEXTO_T5.Add("CLIENTE"); Phrase Titulo6 = new Phrase("MONTO", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell TEXTO_T6 = new PdfPCell(Titulo6); TEXTO_T6.HorizontalAlignment = Element.ALIGN_RIGHT; TEXTO_T6.BackgroundColor = new BaseColor(224, 255, 255); Phrase Titulo7 = new Phrase("OPERADOR", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell TEXTO_T7 = new PdfPCell(Titulo7); TEXTO_T7.HorizontalAlignment = Element.ALIGN_RIGHT; TEXTO_T7.BackgroundColor = new BaseColor(224, 255, 255); table.HorizontalAlignment = 0; table.TotalWidth = 545f; table.LockedWidth = true; float[] widths = new float[] { 50f, 40f, 30f, 75f, 200f, 50f, 100f }; table.SetWidths(widths); //table.WidthPercentage = 100; table.DefaultCell.BackgroundColor = new BaseColor(224, 255, 255); table.DefaultCell.BorderColor = new BaseColor(0, 0, 0);//125,125,255 table.AddCell(TEXTO_T1); table.AddCell(TEXTO_T2); table.AddCell(TEXTO_T3); table.AddCell(TEXTO_T4); table.AddCell(TEXTO_T5); table.AddCell(TEXTO_T6); table.AddCell(TEXTO_T7); table.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255); //INVOCAMOS A reporte_venta.php HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/reporte_venta.php"); rq.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼{1}▼{2}▼{3}▼{4}▼{5}▼{6}▼{7}▼{8}▼{9}▼{10}", Global.fecha_desdex, Global.fecha_hastax, Global.Op_Contado, Global.Op_Credito, Global.Op_Ambos, Global.Op_Incluir_IN_EG, Global.OP_Ambos_Incl_IN_EG, Global.NoVenta_Op_Ingresos, Global.NoVenta_Op_Egresos, Global.NoVenta_Op_Ing_Egr_Ambos, Global.operadorRp)); rq.ContentType = "application/x-www-form-urlencoded"; rq.ContentLength = byteArray.Length; Stream stream = rq.GetRequestStream(); stream.Write(byteArray, 0, byteArray.Length); stream.Close(); // WebResponse response = rq.GetResponse(); stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string devuelve = reader.ReadToEnd(); reader.Close(); stream.Close(); response.Close(); string resultado = devuelve.ToUpper(); bool re; re = resultado.Contains(" 100) { MessageBox.Show(devuelve); //return; } //TEXTO QUE IRÁ DENTRO DE LA TABLA DEL CUERPO if (devuelve.Trim() != "") { foreach (var line in devuelve.Split('↔')) { var valores = line.Split('▲'); if (valores[0] != "") { Paragraph codigo = new Paragraph(); codigo.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); codigo.Add(valores[0].Trim()); Paragraph cantidad = new Paragraph(); cantidad.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); cantidad.Add(valores[1]); Paragraph Descr = new Paragraph(); Descr.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 9f, BaseColor.BLACK); Descr.Add(valores[2]); Phrase Conte4 = new Phrase(string.Format("{0:#,##0.##}", double.Parse(valores[3])), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell compra = new PdfPCell(Conte4); compra.HorizontalAlignment = Element.ALIGN_RIGHT; compra.BackgroundColor = new BaseColor(255, 255, 255); compra.BorderColor = new BaseColor(211, 211, 211);//125,125,255 Phrase Conte5 = new Phrase(string.Format("{0:#,##0.##}", double.Parse(valores[4])), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell venta = new PdfPCell(Conte5); venta.HorizontalAlignment = Element.ALIGN_RIGHT; venta.BackgroundColor = new BaseColor(255, 255, 255); venta.BorderColor = new BaseColor(211, 211, 211);//125,125,255 double comprax = double.Parse(valores[3]); double ventax = double.Parse(valores[4]); double porciento = (ventax / comprax) * 100 - 100; Phrase Conte6 = new Phrase(porciento.ToString("0.##") + "%", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell rec = new PdfPCell(Conte6); rec.HorizontalAlignment = Element.ALIGN_RIGHT; rec.BackgroundColor = new BaseColor(255, 255, 255); rec.BorderColor = new BaseColor(211, 211, 211);//125,125,255 Phrase Conte7 = new Phrase(string.Format("{0:0,##0.##}", double.Parse(valores[4]) - double.Parse(valores[3])), FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK)); PdfPCell margen = new PdfPCell(Conte7); margen.HorizontalAlignment = Element.ALIGN_RIGHT; margen.BackgroundColor = new BaseColor(255, 255, 255); margen.BorderColor = new BaseColor(211, 211, 211);//125,125,255 //table.WidthPercentage = 100; table.DefaultCell.BorderColor = new BaseColor(211, 211, 211);//125,125,255 table.AddCell(codigo); table.AddCell(cantidad); table.AddCell(Descr); table.AddCell(compra); table.AddCell(venta); table.AddCell(rec); table.AddCell(margen); Global.TotalVenta = Global.TotalVenta + double.Parse(valores[4]); Global.TotalCompra = Global.TotalCompra + double.Parse(valores[3]); } } } Global.TotalMargen = Global.TotalVenta - Global.TotalCompra; double TotalPorcen = (Global.TotalVenta / Global.TotalCompra) *100-100; //TOTAL DE VENTA QUE SALE EN LA CABECERA Paragraph title2 = new Paragraph(); title2.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 14f, BaseColor.BLUE); title2.Add("Valor Venta " + Global.SIMB_ + " " + Global.TotalVenta.ToString("#,##0.##") + "\n" + "Valor Compra " + Global.SIMB_ + " " + Global.TotalCompra.ToString("#,##0.##") + "\n" + "Total Margen " + Global.SIMB_ + " " + Global.TotalMargen.ToString("#,##0.##") + "\n" + "Porcentaje promedio % " + TotalPorcen.ToString("#,##0.##")); title2.Alignment = Element.ALIGN_RIGHT; oDoc.Add(title2); string Monto = "\n*Valor Venta*\n" + Global.SIMB_ + " " + Global.TotalVenta.ToString("#,##0.##") + ".-\n\n" + "*Valor Compra*\n" + Global.SIMB_ + " " + Global.TotalCompra.ToString("#,##0.##") + ".-\n\n" + "*Total Margen*\n" + Global.SIMB_ + " " + Global.TotalMargen.ToString("#,##0.##") + ".-\n\n" + "*Porcentaje promedio %* " + TotalPorcen.ToString("#,##0.##"); //PARRAFO VACÍO COMO SEPARADOR Paragraph title3 = new Paragraph(); title3.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 2, BaseColor.BLACK); title3.Add("."); title3.Alignment = Element.ALIGN_LEFT; oDoc.Add(title3); oDoc.Add(table); //WHATSSAPP AL ADMINISTRADOR Principal principal = new Principal(); principal.EnviarWhatsApp(Global.ID_WhatsApp, Titulo + "\n" + Monto + "\n\n*_" + Global.Nom_EMPRESA + "_*\nCaja " + Global.NUM_caja + ": " + Global.USUARIO_SIST + "\n" + Global.Tel_EMPRESA, Global.Tel_WhatsApp); principal.Espera(1);//segundos pdfw.Flush(); oDoc.Close(); System.Diagnostics.Process.Start(@pdfgenerate);//MUESTRA EL REPORTE EN PDF return (null); } } }