public void MakeReport(Object Sender, EventArgs E) { DatasForReport balComp = new DatasForReport(reportTitle); ds = balComp.GetDatas(false, GetParams()); //3 tablas: // 1. mcue_codipuc, mcue_nombre, tnat_codigo, timp_codigo FROM mcuenta // 2. mcuenta.mcue_codipuc as CODIGO, mcuenta.mcue_nombre as NOMBRE, parcial=msal_valodebi-msal_valocred o msal_valocred-msal_valodebi WHERE mcuenta.mcue_codipuc=msaldocuenta.mcue_codipuc AND msaldocuenta.pano_ano=@ AND msaldocuenta.pmes_mes<=@ AND mcuenta.timp_codigo in ('N','P','@') AND mcuenta.tcla_codigo='R' // 3. mauxiliarcuenta.mcue_codipuc as COD, mauxiliarcuenta.mnit_nit as NIT, mnit.mnit_nombres+mnit.mnit_apellidos as NOMBRE, DETALLE = mauxiliarcuenta.maux_valodebi-mauxiliarcuenta.maux_valocred o mauxiliarcuenta.maux_valocred-mauxiliarcuenta.maux_valodebi FROM mcuenta, mauxiliarcuenta, mnit WHERE mauxiliarcuenta.mnit_nit=mnit.mnit_nit AND mcuenta.mcue_codipuc=mauxiliarcuenta.mcue_codipuc AND mauxiliarcuenta.pano_ano=@ AND mauxiliarcuenta.pmes_mes<=@ AND mauxiliarcuenta.mnit_nit != '@' //reportInfo.Text=ds.Tables.Count.ToString(); Press frontEnd = new Press(ds, reportTitle); frontEnd.PreHeader(tabPreHeader, report.Width, pr); frontEnd.Firmas(tabFirmas, report.Width); frontEnd.SourceFieldTitles(balComp.PressFields); tbReport = frontEnd.TbReport; ArrayList arC0 = new ArrayList(); ArrayList arC1 = new ArrayList(); ArrayList arC2 = new ArrayList(); ArrayList arV0 = new ArrayList(); ArrayList arV1 = new ArrayList(); ArrayList arV2 = new ArrayList(); ArrayList arC = null; ArrayList arV = null; ArrayList arCT = new ArrayList(); DataRow[] rows; int ano, ai; ano = Convert.ToInt16(values[0]); for (i = 0; i < ds.Tables[1].Rows.Count; i++) { ai = ano - Convert.ToInt16(ds.Tables[1].Rows[i][4]); if (ai == 0) { arC = arC0; arV = arV0; } if (ai == 1) { arC = arC1; arV = arV1; } if (ai == 2) { arC = arC2; arV = arV2; } Inserta(arC, ds.Tables[1].Rows[i][0].ToString(), Convert.ToDouble(ds.Tables[1].Rows[i][2]), arV, arCT); if (ds.Tables[1].Rows[i][3].ToString().ToUpper() == "D") { TDeb += Convert.ToDouble(ds.Tables[1].Rows[i][2]); } if (ds.Tables[1].Rows[i][3].ToString().ToUpper() == "C") { TCred += Convert.ToDouble(ds.Tables[1].Rows[i][2]); } } double v0, v1, v2; if (arCT.Count > 0) { for (i = 0; i < arCT.Count; i++) { dr = tbReport.NewRow(); dr[0] = arCT[i].ToString(); rows = ds.Tables[0].Select("MCUE_CODIPUC = '" + arCT[i].ToString() + "'"); dr[1] = rows[0][1]; if (arC0.Contains(arCT[i])) { v0 = (double)arV0[i]; } else { v0 = 0; } dr[2] = (v0).ToString(); if (arC1.Contains(arCT[i])) { v1 = (double)arV1[i]; } else { v1 = 0; } dr[3] = (v1).ToString(); if (arC2.Contains(arCT[i])) { v2 = (double)arV2[i]; } else { v2 = 0; } dr[4] = (v2).ToString(); if (v0 != 0) { dr[5] = (((v1 - v0) * 100) / v0).ToString(); // % Año 0-1 dr[6] = (((v2 - v0) * 100) / v0).ToString(); // % Año 0-2 } else { dr[5] = "0.00"; dr[6] = "0.00"; } if (!(v0 == 0 && v1 == 0 && v2 == 0)) { tbReport.Rows.Add(dr); } } } frontEnd.PressFieldTitles(report); DataView dv = frontEnd.SortWithNextField(3, 0); DataTable dtTmp = dv.Table; if (values[2] == "A") { report.DataSource = SetAux(dv, 0); } else if (values[2] == "D") { report.DataSource = SetAux(dv, 14); } else if (values[2] == "G") { report.DataSource = SetAux(dv, 10); } else if (values[2] == "M") { report.DataSource = SetAux(dv, 6); } report.Columns[2].HeaderText = values[0]; report.Columns[3].HeaderText = (Convert.ToInt16(values[0]) - 1).ToString(); report.Columns[4].HeaderText = (Convert.ToInt16(values[0]) - 2).ToString(); report.Columns[5].HeaderText = "% " + values[0] + "-" + (Convert.ToInt16(values[0]) - 1).ToString(); report.Columns[6].HeaderText = "% " + values[0] + "-" + (Convert.ToInt16(values[0]) - 2).ToString(); report.DataBind(); StringBuilder SB = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htmlTW = new HtmlTextWriter(SW); tabPreHeader.RenderControl(htmlTW); report.RenderControl(htmlTW); tabFirmas.RenderControl(htmlTW); string strRep; strRep = SB.ToString(); Session.Clear(); Session["Rep"] = strRep; toolsHolder.Visible = true; }
public void MakeReport(Object Sender, EventArgs E) { DatasForReport balGen = new DatasForReport(reportTitle); ds = balGen.GetDatas(false, GetParams()); //3 tablas: // 1. mcue_codipuc, mcue_nombre, tnat_codigo, timp_codigo FROM mcuenta // 2. mcuenta.mcue_codipuc as CODIGO, mcuenta.mcue_nombre as NOMBRE, parcial=msal_valodebi-msal_valocred o msal_valocred-msal_valodebi WHERE mcuenta.mcue_codipuc=msaldocuenta.mcue_codipuc AND msaldocuenta.pano_ano=@ AND msaldocuenta.pmes_mes<=@ AND mcuenta.timp_codigo in ('N','P','@') AND mcuenta.tcla_codigo='R' // 3. mauxiliarcuenta.mcue_codipuc as COD, mauxiliarcuenta.mnit_nit as NIT, mnit.mnit_nombres+mnit.mnit_apellidos as NOMBRE, DETALLE = mauxiliarcuenta.maux_valodebi-mauxiliarcuenta.maux_valocred o mauxiliarcuenta.maux_valocred-mauxiliarcuenta.maux_valodebi FROM mcuenta, mauxiliarcuenta, mnit WHERE mauxiliarcuenta.mnit_nit=mnit.mnit_nit AND mcuenta.mcue_codipuc=mauxiliarcuenta.mcue_codipuc AND mauxiliarcuenta.pano_ano=@ AND mauxiliarcuenta.pmes_mes<=@ AND mauxiliarcuenta.mnit_nit != '@' //reportInfo.Text=ds.Tables.Count.ToString(); Press frontEnd = new Press(ds, reportTitle); frontEnd.PreHeader(tabPreHeader, report.Width, pr); frontEnd.Firmas(tabFirmas, report.Width); frontEnd.SourceFieldTitles(balGen.PressFields); tbReport = frontEnd.TbReport; ArrayList arC = new ArrayList(); ArrayList arV = new ArrayList(); DataRow[] rows; int l; TCred = new double[10]; TDeb = new double[10]; for (i = 0; i < 10; i++) { TCred[i] = 0; TDeb[i] = 0; } ; for (i = 0; i < ds.Tables[1].Rows.Count; i++) { Inserta(arC, ds.Tables[1].Rows[i][0].ToString(), Convert.ToDouble(ds.Tables[1].Rows[i][2]), arV); //Calcular Utilidades aca: //UBruta,UEjer,UOper /*if(Convert.ToInt16(ds.Tables[1].Rows[i][3])==1)UBruta+=Convert.ToDouble(ds.Tables[1].Rows[i][2]); * if(Convert.ToInt16(ds.Tables[1].Rows[i][3])==2)UEjer+=Convert.ToDouble(ds.Tables[1].Rows[i][2]); * if(Convert.ToInt16(ds.Tables[1].Rows[i][3])==3)UOper+=Convert.ToDouble(ds.Tables[1].Rows[i][2]);*/ if (ds.Tables[1].Rows[i][4].ToString().ToUpper() == "D") { TDeb[Convert.ToInt16(ds.Tables[1].Rows[i][0].ToString().Substring(0, 1))] += Convert.ToDouble(ds.Tables[1].Rows[i][2]); } if (ds.Tables[1].Rows[i][4].ToString().ToUpper() == "C") { TCred[Convert.ToInt16(ds.Tables[1].Rows[i][0].ToString().Substring(0, 1))] += Convert.ToDouble(ds.Tables[1].Rows[i][2]); } } //arC.Sort(); int tot = arC.Count; for (i = 0; i < tot; i++) { //reportInfo.Text+=arC[i].ToString()+"<br>"; l = arC[i].ToString().Length; dr = tbReport.NewRow(); dr[0] = arC[i].ToString(); rows = ds.Tables[0].Select("MCUE_CODIPUC = '" + arC[i].ToString() + "'"); if (rows.Length > 0) { dr[1] = rows[0][1]; } if (l < 3) { dr[5] = ((double)arV[i]).ToString(); } else { if (l == 4) { dr[4] = ((double)arV[i]).ToString(); } else { if (l == 6) { dr[3] = ((double)arV[i]).ToString(); } else { dr[2] = ((double)arV[i]).ToString(); } } } if (((double)arV[i]) != 0) { tbReport.Rows.Add(dr); } } frontEnd.PressFieldTitles(report); DataView dv = frontEnd.SortWithNextField(3, 0); DataTable dtTmp = dv.Table; if (values[3] == "A") { report.DataSource = SetAux(dv, 0); report.DataBind(); } else if (values[3] == "D") { report.DataSource = SetAux(dv, 14); report.DataBind(); } else if (values[3] == "G") { report.DataSource = SetAux(dv, 6); report.DataBind(); } else if (values[3] == "M") { report.DataSource = SetAux(dv, 4); report.DataBind(); } StringBuilder SB = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htmlTW = new HtmlTextWriter(SW); tabPreHeader.RenderControl(htmlTW); report.RenderControl(htmlTW); tabFirmas.RenderControl(htmlTW); string strRep; strRep = SB.ToString(); Session.Clear(); Session["Rep"] = strRep; toolsHolder.Visible = true; }
public void MakeReport(Object Sender, EventArgs E) { DatasForReport balGen = new DatasForReport(reportTitle); ds = balGen.GetDatas(false, GetParams()); //reportInfo.Text += balGen.SQL[0] + "<br>"; //dgTest.DataSource = ds.Tables[2]; //dgTest.DataBind(); Press frontEnd = new Press(ds, reportTitle); frontEnd.PreHeader(tabPreHeader, report.Width, pr); frontEnd.Firmas(tabFirmas, report.Width); frontEnd.SourceFieldTitles(balGen.PressFields); tbReport = frontEnd.TbReport; double parcialD1 = 0, parcialD2 = 0, parcialD3 = 0, parcialC1 = 0, parcialC2 = 0, parcialC3 = 0; double subtotalD1 = 0, subtotalD2 = 0, subtotalD3 = 0, subtotalC1 = 0, subtotalC2 = 0, subtotalC3 = 0; double totalD1 = 0, totalD2 = 0, totalD3 = 0, totalC1 = 0, totalC2 = 0, totalC3 = 0; string cVal, aVal; string mcue = ""; double saldoAntCuenta = 0, saldoAntSubCuenta = 0, saldoAntSubSubCuenta = 0; double saldoCuenta = 0, saldoSubCuenta = 0, saldoSubSubCuenta = 0; double saldo = 0; double totalSaldoAntDeb = 0, totalSaldoAntCre = 0, totalSaldoActDeb = 0, totalSaldoActCre = 0, totalSaldoDeb = 0, totalSaldoCre = 0; try{ mcue = DBFunctions.SingleData("SELECT mcue_codipuc FROM ccontabilidad"); }catch {}; mcue = mcue.Trim(); DataRow[] rows; for (i = 0; i < ds.Tables[3].Rows.Count; i++) { dr = tbReport.NewRow(); cVal = ds.Tables[3].Rows[i][0].ToString(); dr[0] = cVal; if (dr[0].ToString() != mcue) { tbReport.Rows.Add(dr); dr[1] = ds.Tables[3].Rows[i][1]; saldo = CalcularSaldoCuenta(cVal, Convert.ToDouble(ds.Tables[3].Rows[i][2]), Convert.ToDouble(ds.Tables[3].Rows[i][3])); if (NaturalezaCuenta(cVal) == "D") { if (saldo > 0) { dr[6] = saldo; totalSaldoDeb = totalSaldoDeb + saldo; } else if (saldo < 0) { dr[7] = saldo * -1; totalSaldoCre = totalSaldoCre + (saldo * -1); } } else if (NaturalezaCuenta(cVal) == "C") { if (saldo > 0) { dr[7] = saldo; totalSaldoCre = totalSaldoCre + saldo; } else if (saldo < 0) { dr[6] = saldo * -1; totalSaldoDeb = totalSaldoDeb + (saldo * -1); } } /*if(Convert.ToDouble(ds.Tables[3].Rows[i][2]) != 0) * dr[6] = Convert.ToDouble(ds.Tables[3].Rows[i][2]); * if(Convert.ToDouble(ds.Tables[3].Rows[i][3]) != 0) * dr[7] = Convert.ToDouble(ds.Tables[3].Rows[i][3]);*/ rows = ds.Tables[2].Select("CODIGO = '" + cVal + "'"); if (rows.Length > 0) { dr[4] = Convert.ToDouble(rows[0][2]); dr[5] = Convert.ToDouble(rows[0][3]); parcialD2 += Convert.ToDouble(rows[0][2]); parcialC2 += Convert.ToDouble(rows[0][3]); totalSaldoActDeb = totalSaldoActDeb + Convert.ToDouble(rows[0][2]); totalSaldoActCre = totalSaldoActCre + Convert.ToDouble(rows[0][3]); } rows = ds.Tables[1].Select("CODIGO = '" + cVal + "'"); if (rows.Length > 0) { dr[2] = Convert.ToDouble(rows[0][2]); dr[3] = Convert.ToDouble(rows[0][3]); parcialD1 += Convert.ToDouble(rows[0][2]); parcialC1 += Convert.ToDouble(rows[0][3]); totalSaldoAntDeb = totalSaldoAntDeb + Convert.ToDouble(rows[0][2]); totalSaldoAntCre = totalSaldoAntCre + Convert.ToDouble(rows[0][3]); } parcialD3 += Convert.ToDouble(ds.Tables[3].Rows[i][2]); parcialC3 += Convert.ToDouble(ds.Tables[3].Rows[i][3]); if (i != ds.Tables[3].Rows.Count - 1) { aVal = ds.Tables[3].Rows[i + 1][0].ToString(); } else { aVal = "00000"; } if (cVal.Substring(0, 4) != aVal.Substring(0, 4)) { dr = tbReport.NewRow(); tbReport.Rows.Add(dr); dr[0] = cVal.Substring(0, 4); rows = ds.Tables[0].Select("MCUE_CODIPUC = '" + cVal.Substring(0, 4) + "'"); dr[1] = rows[0][1]; saldoAntSubSubCuenta = CalcularSaldoCuenta(cVal.Substring(0, 4), parcialD1, parcialC1); if (NaturalezaCuenta(cVal.Substring(0, 4)) == "D") { if (saldoAntSubSubCuenta > 0) { dr[2] = saldoAntSubSubCuenta; } else if (saldoAntSubCuenta < 0) { dr[3] = saldoAntSubSubCuenta * -1; } } else if (NaturalezaCuenta(cVal.Substring(0, 4)) == "C") { if (saldoAntSubSubCuenta > 0) { dr[3] = saldoAntSubSubCuenta; } else if (saldoAntSubSubCuenta < 0) { dr[2] = saldoAntSubSubCuenta * -1; } } dr[4] = parcialD2; dr[5] = parcialC2; saldoSubSubCuenta = CalcularSaldoCuenta(cVal.Substring(0, 4), parcialD3, parcialC3); if (NaturalezaCuenta(cVal.Substring(0, 4)) == "D") { if (saldoSubSubCuenta > 0) { dr[6] = saldoSubSubCuenta; } else if (saldoSubSubCuenta < 0) { dr[7] = saldoSubSubCuenta * -1; } } else if (NaturalezaCuenta(cVal.Substring(0, 4)) == "C") { if (saldoSubSubCuenta > 0) { dr[7] = saldoSubSubCuenta; } else if (saldoSubSubCuenta < 0) { dr[6] = saldoSubSubCuenta * -1; } } subtotalD1 += parcialD1; subtotalD2 += parcialD2; subtotalD3 += parcialD3; subtotalC1 += parcialC1; subtotalC2 += parcialC2; subtotalC3 += parcialC3; parcialD1 = 0; parcialD2 = 0; parcialD3 = 0; parcialC1 = 0; parcialC2 = 0; parcialC3 = 0; } if (cVal.Substring(0, 2) != aVal.Substring(0, 2)) { dr = tbReport.NewRow(); tbReport.Rows.Add(dr); dr[0] = cVal.Substring(0, 2); //*rows = ds.Tables[0].Select("MCUE_CODIPUC = '" + cVal.Substring(0,2) + "'"); try{ dr[1] = DBFunctions.SingleData("SELECT mcue_nombre FROM mcuenta WHERE mcue_codipuc='" + cVal.Substring(0, 2) + "'"); } catch {} saldoAntSubCuenta = CalcularSaldoCuenta(cVal.Substring(0, 2), subtotalD1, subtotalC1); if (NaturalezaCuenta(cVal.Substring(0, 2)) == "D") { if (saldoAntSubCuenta > 0) { dr[2] = saldoAntSubCuenta; } else if (saldoAntSubCuenta < 0) { dr[3] = saldoAntSubCuenta * -1; } } else if (NaturalezaCuenta(cVal.Substring(0, 2)) == "C") { if (saldoAntSubCuenta > 0) { dr[3] = saldoAntSubCuenta; } else if (saldoAntSubCuenta < 0) { dr[2] = saldoAntSubCuenta * -1; } } dr[4] = subtotalD2; dr[5] = subtotalC2; saldoSubCuenta = CalcularSaldoCuenta(cVal.Substring(0, 2), subtotalD3, subtotalC3); if (NaturalezaCuenta(cVal.Substring(0, 2)) == "D") { if (saldoSubCuenta > 0) { dr[6] = saldoSubCuenta; } else if (saldoSubCuenta < 0) { dr[7] = saldoSubCuenta * -1; } } else if (NaturalezaCuenta(cVal.Substring(0, 2)) == "C") { if (saldoSubCuenta > 0) { dr[7] = saldoSubCuenta; } else if (saldoSubCuenta < 0) { dr[6] = saldoSubCuenta * -1; } } totalD1 += subtotalD1; totalD2 += subtotalD2; totalD3 += subtotalD3; totalC1 += subtotalC1; totalC2 += subtotalC2; totalC3 += subtotalC3; subtotalD1 = 0; subtotalD2 = 0; subtotalD3 = 0; subtotalC1 = 0; subtotalC2 = 0; subtotalC3 = 0; } if (cVal.Substring(0, 1) != aVal.Substring(0, 1)) { dr = tbReport.NewRow(); tbReport.Rows.Add(dr); dr[0] = cVal.Substring(0, 1); try { rows = ds.Tables[0].Select("MCUE_CODIPUC = '" + cVal.Substring(0, 1) + "'"); dr[1] = rows[0][1]; } catch { dr[1] = ""; } saldoAntCuenta = CalcularSaldoCuenta(cVal.Substring(0, 1), totalD1, totalC1); if (NaturalezaCuenta(cVal.Substring(0, 1)) == "D") { if (saldoAntCuenta > 0) { dr[2] = saldoAntCuenta; } else if (saldoAntCuenta < 0) { dr[3] = saldoAntCuenta * -1; } } else if (NaturalezaCuenta(cVal.Substring(0, 1)) == "C") { if (saldoAntCuenta > 0) { dr[3] = saldoAntCuenta; } else if (saldoAntCuenta < 0) { dr[2] = saldoAntCuenta * -1; } } dr[4] = totalD2; dr[5] = totalC2; saldoCuenta = CalcularSaldoCuenta(cVal.Substring(0, 1), totalD3, totalC3); if (NaturalezaCuenta(cVal.Substring(0, 1)) == "D") { if (saldoCuenta > 0) { dr[6] = saldoCuenta; } else if (saldoCuenta < 0) { dr[7] = saldoCuenta * -1; } } else if (NaturalezaCuenta(cVal.Substring(0, 1)) == "C") { if (saldoCuenta > 0) { dr[7] = saldoCuenta; } else if (saldoCuenta < 0) { dr[6] = saldoCuenta * -1; } } totalD1 = 0; totalD2 = 0; totalD3 = 0; totalC1 = 0; totalC2 = 0; totalC3 = 0; } } } drTotales = tbReport.NewRow(); dr[0] = "T O T "; dr[1] = " A L E S "; dr[2] = totalSaldoAntDeb.ToString("N"); dr[3] = totalSaldoAntCre.ToString("N"); dr[4] = totalSaldoActDeb.ToString("N"); dr[5] = totalSaldoActCre.ToString("N"); dr[6] = totalSaldoDeb.ToString("N"); dr[7] = totalSaldoCre.ToString("N"); tbReport.Rows.Add(drTotales); frontEnd.PressFieldTitles(report); DataView dv = frontEnd.SortWithNextField(4, 0); //DataTable dtTmp = dv.Table; if (values[2] == "D") { report.DataSource = dv; report.DataBind(); } else if (values[2] == "G") { report.DataSource = ApplyFilter(dv, 6); report.DataBind(); } else if (values[2] == "M") { report.DataSource = ApplyFilter(dv, 4); report.DataBind(); } StringBuilder SB = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htmlTW = new HtmlTextWriter(SW); tabPreHeader.RenderControl(htmlTW); report.RenderControl(htmlTW); tabFirmas.RenderControl(htmlTW); string strRep; strRep = SB.ToString(); Session.Clear(); Session["Rep"] = strRep; toolsHolder.Visible = true; }