using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using iTextSharp.text;
using Font = iTextSharp.text.Font;
using Image = iTextSharp.text.Image;
using System.Data.SQLite;
using System.Net;
using System.Net.Http;
namespace CKUERA
{
public partial class Cierre : Form
{
public Cierre()
{
InitializeComponent();
}
private BaseColor FondoDiv;
private BaseColor BordeDiv;
private BaseColor FondoDet;
private BaseColor BordeDet;
private BaseColor FondoCab;
private BaseColor BordeCab;
private void Cierre_Load(object sender, EventArgs e)
{
Mon_decl_Lb.Text = Global.SIMB_;
Mon_decl_Lb2.Text = Global.simboloMoneda2;
Mon_decl_Lb3.Text = Global.simboloMoneda3;
Mon_decl_Lb4.Text = Global.simboloMoneda4;
if (double.Parse(Global.version) < 2)
{
Mon2_declarado.Text = "0";
Mon3_declarado.Text = "0";
Mon4_declarado.Text = "0";
}
}
private void Cierre_Activated(object sender, EventArgs e)
{
this.Width = 20;
}
private void reportarCierre()
{
// CREAR PDF
string pdfgenerate = "\\DOC_PDF\\CIERRES_PDF\\" + Global.USUARIO_SIST + "_" + DateTime.Now.ToString("dd-MM-yy") + "_" + DateTime.Now.ToString("HH-mm") + "_CIERRE.pdf";
Document oDoc;
PdfWriter pdfw;
PdfContentByte cb;
float top1;
//PREPARA EL PDF
oDoc = new Document(PageSize.A4, 30, 20, 20, 20);
pdfw = PdfWriter.GetInstance(oDoc, new FileStream(pdfgenerate, FileMode.Create, FileAccess.Write, FileShare.None));
pdfw.CompressionLevel = PdfStream.NO_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 - 80);
oDoc.Add(logo);
}
catch (Exception)
{
}
cb = pdfw.DirectContent;//DEBE IR ANTES DE LAS LÍNEAS DE TEXTO
//EL TÍTULO
Paragraph title = new Paragraph();
title.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 12, BaseColor.BLACK);
title.Add("\n\n\n\n" + "REPORTE DE CIERRE DE VENTAS" +
"\nOPERADOR " + Global.USUARIO_SIST + ", Caja " + Global.NUM_caja + ", Fecha: " + DateTime.Now.ToString("dd/MM/yyyy") + ", Hora: " + DateTime.Now.ToString("HH:mm"));
title.Alignment = Element.ALIGN_RIGHT;
oDoc.Add(title);
//Colores
BaseColor FondoCab = new BaseColor(100, 200, 200);
BaseColor BordeCab = new BaseColor(200, 200, 200);
//oDoc.Add(new Paragraph("\n"));
//Espacio de cabecera
PdfPTable TablaEspa = new PdfPTable(1);
TablaEspa.WidthPercentage = 100;
PdfPCell CelEspa = new PdfPCell(new Phrase("aaaaa", FontFactory.GetFont(FontFactory.HELVETICA, 2, BaseColor.WHITE)));
CelEspa.Border = 0;
TablaEspa.AddCell(CelEspa);
oDoc.Add(TablaEspa);
//Espacio vacío2
PdfPTable TablaEspa2 = new PdfPTable(1);
TablaEspa2.WidthPercentage = 100;
PdfPCell CelEspa2 = new PdfPCell(new Phrase("aaaaa", FontFactory.GetFont(FontFactory.HELVETICA, 2, BaseColor.WHITE)));
CelEspa2.Border = 0;
TablaEspa2.AddCell(CelEspa2);
oDoc.Add(TablaEspa2);
PdfPTable table = new PdfPTable(4);//TABLA CON 8 CELDAS
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Phrase Titulo0= new Phrase(Global.denominacion1, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T0 = new PdfPCell(Titulo0);
TEXTO_T0.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T0.BackgroundColor = FondoCab;
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Phrase Titulo1 = new Phrase(Global.denominacion2, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T1 = new PdfPCell(Titulo1);
TEXTO_T1.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T1.BackgroundColor = FondoCab;
Phrase Titulo2 = new Phrase(Global.denominacion3, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T2 = new PdfPCell(Titulo2);
TEXTO_T2.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T2.BackgroundColor = FondoCab;
Phrase Titulo3 = new Phrase(Global.denominacion4, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T3 = new PdfPCell(Titulo3);
TEXTO_T3.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T3.BackgroundColor = FondoCab;
table.HorizontalAlignment = 0;
table.TotalWidth = 545f;//MEDIDA TOTAL DE LA TABLA
table.LockedWidth = true;
//float[] widths = new float[] { 16f, 270f, 51f, 20f, 50f, 25f, 25f, 60f, 22f };//MEDIDAS DE COLUMNAS
//table.SetWidths(widths);
table.AddCell(TEXTO_T0); table.AddCell(TEXTO_T1);
table.AddCell(TEXTO_T2); table.AddCell(TEXTO_T3);
//table.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255);
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/cierre.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}", Global.USUARIO_SIST));
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(devuelve2);
return;
}
//VUELVE INHABILITADOS LOS CONTROLES
Mon_declarado.Enabled = false;
Mon_computo.Enabled = false;
Mon_resul.Enabled = false;
button1.Enabled = false;
this.Close();
}
}
private void reportarCajaChica()
{
// CREAR PDF
string pdfgenerate = "\\DOC_PDF\\CIERRES_PDF\\" + Global.USUARIO_SIST + "_" + DateTime.Now.ToString("dd-MM-yy") + "_" + DateTime.Now.ToString("HH-mm") + "_CAJA_CHICA.pdf";
Document oDoc;
PdfWriter pdfw;
PdfContentByte cb;
float top1;
//PREPARA EL PDF
oDoc = new Document(PageSize.A4, 30, 20, 20, 20);
pdfw = PdfWriter.GetInstance(oDoc, new FileStream(pdfgenerate, FileMode.Create, FileAccess.Write, FileShare.None));
pdfw.CompressionLevel = PdfStream.NO_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 - 80);
oDoc.Add(logo);
}
catch (Exception)
{
}
cb = pdfw.DirectContent;//DEBE IR ANTES DE LAS LÍNEAS DE TEXTO
//EL TÍTULO
Paragraph title = new Paragraph();
title.Font = FontFactory.GetFont(FontFactory.DefaultEncoding, 12, BaseColor.BLACK);
title.Add("\n" + "REPORTE DE CAJA CHICA" +
"\nOPERADOR " + Global.USUARIO_SIST + ", Caja " + Global.NUM_caja + ", Fecha: " + DateTime.Now.ToString("dd/MM/yyyy") + ", Hora: " + DateTime.Now.ToString("HH:mm"));
title.Alignment = Element.ALIGN_RIGHT;
oDoc.Add(title);
//Colores
BaseColor FondoCab = new BaseColor(100, 200, 200);
BaseColor BordeCab = new BaseColor(200, 200, 200);
BaseColor FondoCuer = new BaseColor(144, 238, 144);
FondoDiv = new BaseColor(180, 180, 180); ;//BaseColor(200, 150, 200);
BordeDiv = new BaseColor(125, 125, 125);
//oDoc.Add(new Paragraph("\n"));
//Espacio de cabecera
PdfPTable TablaEspa = new PdfPTable(1);
TablaEspa.WidthPercentage = 100;
PdfPCell CelEspa = new PdfPCell(new Phrase("aaaaa", FontFactory.GetFont(FontFactory.HELVETICA, 2, BaseColor.WHITE)));
CelEspa.Border = 0;
TablaEspa.AddCell(CelEspa);
oDoc.Add(TablaEspa);
//Espacio de cabecera
PdfPTable TablaEspa4 = new PdfPTable(1);
TablaEspa4.WidthPercentage = 100;
PdfPCell CelEspa4 = new PdfPCell(new Phrase("MOVIMIENTOS DE CAJA", FontFactory.GetFont(FontFactory.HELVETICA, 11, BaseColor.BLACK)));
CelEspa4.Border = 0;
CelEspa4.HorizontalAlignment = Element.ALIGN_LEFT;
TablaEspa4.AddCell(CelEspa4);
oDoc.Add(TablaEspa4);
PdfPTable table = new PdfPTable(7);//TABLA CON 7 CELDAS
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Phrase Titulo0 = new Phrase("Fecha", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T0 = new PdfPCell(Titulo0);
TEXTO_T0.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T0.BackgroundColor = FondoCab;
//TEXTO QUE IRÁ DENTRO DE LA TABLA DEL ENCABEZADO
Phrase Titulo1 = new Phrase("Hora", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T1 = new PdfPCell(Titulo1);
TEXTO_T1.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T1.BackgroundColor = FondoCab;
Phrase Titulo2 = new Phrase(Global.SIMB_, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T2 = new PdfPCell(Titulo2);
TEXTO_T2.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T2.BackgroundColor = FondoCab;
Phrase Titulo3 = new Phrase(Global.simboloMoneda2, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T3 = new PdfPCell(Titulo3);
TEXTO_T3.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T3.BackgroundColor = FondoCab;
Phrase Titulo4 = new Phrase(Global.simboloMoneda3, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T4 = new PdfPCell(Titulo4);
TEXTO_T4.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T4.BackgroundColor = FondoCab;
Phrase Titulo5 = new Phrase(Global.simboloMoneda4, FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T5 = new PdfPCell(Titulo5);
TEXTO_T5.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T5.BackgroundColor = FondoCab;
Phrase Titulo6 = new Phrase("Descripción", FontFactory.GetFont(FontFactory.DefaultEncoding, 9, BaseColor.BLACK));
PdfPCell TEXTO_T6 = new PdfPCell(Titulo6);
TEXTO_T6.HorizontalAlignment = Element.ALIGN_CENTER;
TEXTO_T6.BackgroundColor = FondoCab;
table.HorizontalAlignment = 0;
table.TotalWidth = 545f;//MEDIDA TOTAL DE LA TABLA
table.LockedWidth = true;
float[] widths = new float[] { 55f, 40f, 55f, 55f, 55f, 55f, 230f };//MEDIDAS DE COLUMNAS
table.SetWidths(widths);
table.AddCell(TEXTO_T0); 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.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255);
string UsuarioSis = Global.USUARIO_SIST;
this.Cursor = Cursors.WaitCursor;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/cajachicarep.php");
rq.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(string.Format("nu={0}▼", UsuarioSis));
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[] c = devuelve.Split('▲');
this.Cursor = Cursors.Default;
//if (c[0].Length > 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] != "")
{
double V2, V3, V4, V5;
try
{
V2 = double.Parse(valores[2]);
} catch { V2 = 0; }
try
{
V3 = double.Parse(valores[3]);
} catch { V3 = 0; }
try
{
V4 = double.Parse(valores[4]);
} catch { V4 = 0; }
try
{
V5 = double.Parse(valores[5]);
}
catch { V5 = 0; }
//FECHA
DateTime V0 = DateTime.Parse(valores[0]);
string fecha = V0.ToString("dd-MM-yyyy");
PdfPCell Conte0 = new PdfPCell();
Conte0.Phrase = new Phrase(fecha, FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte0.HorizontalAlignment = Element.ALIGN_CENTER;
Conte0.BackgroundColor = FondoCuer;
Conte0.BorderColor = BordeDiv;
//HORA
DateTime V1 = DateTime.Parse(valores[1]);
string hora = V1.ToString("HH:mm:ss");
PdfPCell Conte1 = new PdfPCell();
Conte1.Phrase = new Phrase(hora, FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte1.HorizontalAlignment = Element.ALIGN_CENTER;
Conte1.BackgroundColor = FondoCuer;
Conte1.BorderColor = BordeDiv;
//MONEDA1
PdfPCell Conte2 = new PdfPCell();
Conte2.Phrase = new Phrase(V2.ToString("#,##0.##"), FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte2.HorizontalAlignment = Element.ALIGN_RIGHT;
Conte2.BackgroundColor = FondoCuer;
Conte2.BorderColor = BordeDiv;
//MONEDA2
PdfPCell Conte3 = new PdfPCell();
Conte3.Phrase = new Phrase(V3.ToString("#,##0.##"), FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte3.HorizontalAlignment = Element.ALIGN_RIGHT;
Conte3.BackgroundColor = FondoCuer;
Conte3.BorderColor = BordeDiv;
//MONEDA3
PdfPCell Conte4 = new PdfPCell();
Conte4.Phrase = new Phrase(V4.ToString("#,##0.##"), FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte4.HorizontalAlignment = Element.ALIGN_RIGHT;
Conte4.BackgroundColor = FondoCuer;
Conte4.BorderColor = BordeDiv;
//MONEDA4
PdfPCell Conte5 = new PdfPCell();
Conte5.Phrase = new Phrase(V5.ToString("#,##0.##"), FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte5.HorizontalAlignment = Element.ALIGN_RIGHT;
Conte5.BackgroundColor = FondoCuer;
Conte5.BorderColor = BordeDiv;
//Descripción
PdfPCell Conte6 = new PdfPCell();
Conte6.Phrase = new Phrase(valores[6], FontFactory.GetFont(FontFactory.HELVETICA, 9, BaseColor.BLACK));
Conte6.HorizontalAlignment = Element.ALIGN_LEFT;
Conte6.BackgroundColor = FondoCuer;
Conte6.BorderColor = BordeDiv;
//table.WidthPercentage = 100;
//table.DefaultCell.BorderColor = new BaseColor(0, 0, 0);//211, 211, 211
table.AddCell(Conte0); table.AddCell(Conte1); table.AddCell(Conte2); table.AddCell(Conte3);
table.AddCell(Conte4); table.AddCell(Conte5); table.AddCell(Conte6);
}
}
}
oDoc.Add(table);
double montoVenta1=0, montoVenta2=0, montoVenta3 = 0, montoVenta4=0;
{//Crear una tabla de 7 columnas para los ingresos y egresos contables
PdfPTable TablaPie = new PdfPTable(7);//TABLA CON 7 CELDAS
TablaPie.WidthPercentage = 100;
BaseColor FondoCuer2 = new BaseColor(200, 230, 250);
//CONSULTA PARA LLENAR ING-EGR CONTABLE Y VENTAS
HttpWebRequest rq2 = (HttpWebRequest)WebRequest.Create("http://" + Global._host + "/ecv/cajachica_in_eg_rep.php");
rq2.Method = "POST";
byte[] byteArray2 = Encoding.UTF8.GetBytes(string.Format("nu={0}", Global.USUARIO_SIST));
rq2.ContentType = "application/x-www-form-urlencoded";
rq2.ContentLength = byteArray2.Length;
Stream stream2 = rq2.GetRequestStream();
stream2.Write(byteArray2, 0, byteArray2.Length);
stream2.Close();
//
WebResponse response2 = rq2.GetResponse();
stream2 = response2.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
string devuelve2 = reader2.ReadToEnd();
reader2.Close();
stream2.Close();
response2.Close();
string resultado2 = devuelve2.ToUpper();
bool re2;
re2 = resultado2.Contains("