diff --git a/Contabilidad/RepIVA.aspx b/Contabilidad/RepIVA.aspx index 1ce1ea9f3..e07baa0a6 100644 --- a/Contabilidad/RepIVA.aspx +++ b/Contabilidad/RepIVA.aspx @@ -231,6 +231,14 @@ + + + SubTotal
Imp. No Tan.16%
+
+ + + +
<%-- --%> @@ -318,14 +326,6 @@ - - - SubTotal
Imp. No Tan.16%
-
- - - -
diff --git a/Contabilidad/RepIVA.aspx.cs b/Contabilidad/RepIVA.aspx.cs index 03e1e139b..679812716 100644 --- a/Contabilidad/RepIVA.aspx.cs +++ b/Contabilidad/RepIVA.aspx.cs @@ -7,8 +7,16 @@ using System.Linq; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; -using static Extensiones.ModExtensiones; +using Microsoft.VisualBasic.CompilerServices; +using System.IO; +using GemBox.Spreadsheet; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Drawing; +using static Extensiones.ModExtensiones; +using ADSNetLibrary.SIGAPI.Models.Agropecuaria.Embarques; +//using DocumentFormat.OpenXml.Spreadsheet; public partial class Contabilidad_RepIVA : ClsPaginas { #region PROPIEDADES @@ -30,9 +38,21 @@ public partial class Contabilidad_RepIVA : ClsPaginas } private DataTable DtIVAA { - get { return DtIVAAcreditable = (DataTable)ViewState["DtIVAA"]; } + get { return DtIVAA = (DataTable)ViewState["DtIVAA"]; } set { ViewState["DtIVAA"] = value; } } + private DataTable DtIVA2 + { + get { return DtIVA2 = (DataTable)ViewState["DtIVA2"]; } + set { ViewState["DtIVA2"] = value; } + } + + private DataTable DtRetIVA + { + get { return DtRetIVA = (DataTable)ViewState["DtRetIVA"]; } + set { ViewState["DtRetIVA"] = value; } + } + private double TCEspecifico { get { return TCEspecifico = (double)ViewState["TCEspecifico"]; } @@ -120,7 +140,8 @@ public partial class Contabilidad_RepIVA : ClsPaginas if (ObjCont.GetRepIVAAcumulado(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), Conciliado, 3, DdlCuenta.SelectedValue.ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)) { - GvIVA2.DataSource = ObjCont.DtResultados; + DtIVA2 = ObjCont.DtResultados.Copy(); + GvIVA2.DataSource = DtIVA2; } if (UsuarioActual.CveEmpresa == 119) @@ -128,7 +149,8 @@ public partial class Contabilidad_RepIVA : ClsPaginas divRetIVA.Visible = true; if (ObjCont.GetRepIVAAcumulado(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), Conciliado, 4, DdlCuenta.SelectedValue.ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)) { - GvRetIVA.DataSource = ObjCont.DtResultados; + DtRetIVA = ObjCont.DtResultados.Copy(); + GvRetIVA.DataSource = DtRetIVA; } } } @@ -192,19 +214,21 @@ public partial class Contabilidad_RepIVA : ClsPaginas protected void LnkPdf_Click(object sender, EventArgs e) { - ImprimirCrystal("PDF"); + //ImprimirCrystal("PDF"); + ImprimirStimulsoft(); + //ImprimirGembox("PDF"); } protected void LnkExcel_Click(object sender, EventArgs e) { - ImprimirGembox(); + ImprimirGembox("EXCEL"); } protected void LnkExcel2_Click(object sender, EventArgs e) { ImprimirCrystal("EXCEL2"); } - private void ImprimirGembox() + private void ImprimirGembox(string Formato) { String FechaF; if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = $"Fecha Final: {txtFechaF.Text}"; } @@ -215,21 +239,323 @@ public partial class Contabilidad_RepIVA : ClsPaginas var filtros = $"Filtros: {FechaI} {FechaF} {TipoMov}"; - GvA.ExportToExcelGembox("ReporteIVA", UsuarioActual, "Reporte de IVA", DatosFiltros: filtros); + var Gv = TT.ActiveTabIndex == 0 ? GvT : GvA; + + var GvExtra1 = TT.ActiveTabIndex == 0 ? GvIEPSA : GvIVA2; + var GvExtra2 = TT.ActiveTabIndex == 0 ? GvIVAA : UsuarioActual.CveEmpresa == 119 ? GvRetIVA : null; + + var NombreHoja = TT.ActiveTabIndex == 0 ? "IVA Trasladado" : "IVA Acreditable"; + + var NombreHojaExtra1 = TT.ActiveTabIndex == 0 ? "IEPS por Porcentaje" : "IVA por Porcentaje"; + var NombreHojaExtra2 = TT.ActiveTabIndex == 0 ? "IVA por Porcentaje" : "Ret IVA"; + + ExportarGembox(Formato, Gv, "ReporteIVA", UsuarioActual, "Reporte de IVA", NombreHoja: NombreHoja, DatosFiltros: filtros, GvExtra1: GvExtra1, NombreHojaExtra1: NombreHojaExtra1, GvExtra2: GvExtra2, NombreHojaExtra2: NombreHojaExtra2); } public override void VerifyRenderingInServerForm(Control control) { } + public void ExportarGembox(String Formato,GridView GridView, string NombreArchivoXLSx, Usuario Usuario, string Titulo, string NombreHoja = "Hoja1", string DatoTituloExtra = "", string DatosFiltros = "", int AnchoImagen = 100, int AlturaImagen = 100, GridView GvExtra1 = null, string NombreHojaExtra1 = "Hoja2", GridView GvExtra2 = null, string NombreHojaExtra2 = "Hoja3") + { + StringWriter stringWriter = new StringWriter(); + HtmlTextWriter writer = new HtmlTextWriter(stringWriter); + GridView.RenderControl(writer); + HtmlLoadOptions htmlDefault = GemBox.Spreadsheet.LoadOptions.HtmlDefault; + MemoryStream memoryStream = new MemoryStream(htmlDefault.Encoding.GetBytes(stringWriter.ToString())); + memoryStream.Position = 0L; + StreamReader streamReader = new StreamReader(memoryStream); + string text = streamReader.ReadToEnd(); + streamReader.Dispose(); + memoryStream.Dispose(); + stringWriter.Dispose(); + string input = text; + input = Regex.Replace(input, "\\<[\\/]*a[^\\>]*\\>", ""); + MemoryStream stream = new MemoryStream(htmlDefault.Encoding.GetBytes(input)); + SpreadsheetInfo.SetLicense(SerialGemBoxSpreadsheet()); + ExcelFile excelFile = ExcelFile.Load(stream, htmlDefault); + checked + { + if (Usuario != null) + { + int num = 6; + int num2 = 2; + ExcelWorksheet excelWorksheet = excelFile.Worksheets[0]; + excelWorksheet.Rows.InsertEmpty(0, num); + foreach (ExcelRow row in excelWorksheet.Rows) + { + foreach (ExcelCell allocatedCell in row.AllocatedCells) + { + if (allocatedCell.Value != null) + { + string s = allocatedCell.Value.ToString().Trim(); + if (decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) + { + allocatedCell.Value = result; + } + } + } + } + + CellRange usedCellRange = excelWorksheet.GetUsedCellRange(ignoreCellsWithoutValue: true); + if ((object)usedCellRange == null) + { + return; + } + + usedCellRange.Style.Font.Name = "Calibri Light"; + CellRange subrangeAbsolute = excelWorksheet.Cells.GetSubrangeAbsolute(1, usedCellRange.FirstColumnIndex, 1, usedCellRange.LastColumnIndex); + subrangeAbsolute.Merged = true; + subrangeAbsolute.Value = Usuario.Empresa.Empresa; + subrangeAbsolute.Style.Font.Size = 360; + subrangeAbsolute.Style.Font.Name = "Calibri Light"; + subrangeAbsolute.Style.HorizontalAlignment = HorizontalAlignmentStyle.Center; + subrangeAbsolute.Style.VerticalAlignment = VerticalAlignmentStyle.Center; + CellRange subrangeAbsolute2 = excelWorksheet.Cells.GetSubrangeAbsolute(3, usedCellRange.FirstColumnIndex, 3, usedCellRange.LastColumnIndex); + subrangeAbsolute2.Merged = true; + subrangeAbsolute2.Value = Titulo; + subrangeAbsolute2.Style.Font.Size = 400; + subrangeAbsolute2.Style.Font.Name = "Calibri Light"; + subrangeAbsolute2.Style.HorizontalAlignment = HorizontalAlignmentStyle.Center; + subrangeAbsolute2.Style.VerticalAlignment = VerticalAlignmentStyle.Center; + if (DatoTituloExtra.Length > 0) + { + CellRange subrangeAbsolute3 = excelWorksheet.Cells.GetSubrangeAbsolute(num, usedCellRange.FirstColumnIndex, num, usedCellRange.LastColumnIndex); + subrangeAbsolute3.Merged = true; + subrangeAbsolute3.Value = DatoTituloExtra; + subrangeAbsolute3.Style.Font.Size = 400; + subrangeAbsolute3.Style.Font.Name = "Calibri Light"; + subrangeAbsolute3.Style.HorizontalAlignment = HorizontalAlignmentStyle.Left; + subrangeAbsolute3.Style.VerticalAlignment = VerticalAlignmentStyle.Center; + } + + if (DatosFiltros.Length > 0) + { + string[] array = DatosFiltros.Split('|'); + excelWorksheet.Rows.InsertEmpty(num, array.Count()); + string[] array2 = array; + foreach (string value in array2) + { + CellRange subrangeAbsolute4 = excelWorksheet.Cells.GetSubrangeAbsolute(num, usedCellRange.FirstColumnIndex, num, usedCellRange.LastColumnIndex); + subrangeAbsolute4.Merged = true; + subrangeAbsolute4.Value = value; + subrangeAbsolute4.Style.Font.Size = 240; + subrangeAbsolute4.Style.Font.Name = "Calibri Light"; + subrangeAbsolute4.Style.HorizontalAlignment = HorizontalAlignmentStyle.Left; + subrangeAbsolute4.Style.VerticalAlignment = VerticalAlignmentStyle.Center; + num++; + } + } + + int firstColumnIndex = usedCellRange.FirstColumnIndex; + int lastColumnIndex = usedCellRange.LastColumnIndex; + for (int j = firstColumnIndex; j <= lastColumnIndex; j++) + { + excelWorksheet.Rows[num].Cells[j].Style.Font.Size = 240; + excelWorksheet.Rows[num].Cells[j].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center; + excelWorksheet.Rows[num].Cells[j].Style.VerticalAlignment = VerticalAlignmentStyle.Center; + excelWorksheet.Rows[num].Cells[j].Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255)); + excelWorksheet.Rows[num].Cells[j].Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255); + if (j > 0) + { + try + { + excelWorksheet.Columns[j].AutoFit(1.0); + } + catch (Exception ex) + { + ProjectData.SetProjectError(ex); + Exception ex2 = ex; + ProjectData.ClearProjectError(); + } + } + } + + int num3 = GridView.Rows.Count + num + num2; + excelWorksheet.Rows[num3].Cells[1].Value = "Usuario Imprimió"; + excelWorksheet.Rows[num3 + 1].Cells[1].Value = Usuario.Nombre; + excelWorksheet.Rows[num3].Cells[3].Value = "Fecha Impresión"; + excelWorksheet.Rows[num3 + 1].Cells[3].Value = ClsPaginas.NowADS().ToString("dd/MM/yyyy"); + FileInfo fileInfo = new FileInfo($"{Usuario.Empresa.Ruta}/Logo.png"); + if (fileInfo.Exists) + { + string path = $"{Usuario.Empresa.Ruta}/Logo.png"; + using StreamReader streamReader2 = new StreamReader(path); + MemoryStream memoryStream2 = new MemoryStream(); + streamReader2.BaseStream.CopyTo(memoryStream2); + excelWorksheet.Pictures.Add(memoryStream2, ExcelPictureFormat.Png, "A1", AnchoImagen, AlturaImagen, LengthUnit.Pixel); + } + + int firstColumnIndex2 = usedCellRange.FirstColumnIndex; + int lastColumnIndex2 = usedCellRange.LastColumnIndex; + for (int k = firstColumnIndex2; k <= lastColumnIndex2; k++) + { + if (k > 0) + { + bool flag = true; + excelWorksheet.Columns[k + 1].Style.NumberFormat = "#,##0.00"; + try + { + excelWorksheet.Columns[k].AutoFit(1.0); + } + catch (Exception ex3) + { + ProjectData.SetProjectError(ex3); + Exception ex4 = ex3; + ProjectData.ClearProjectError(); + } + } + } + + excelFile.Worksheets[0].Name = NombreHoja; + + if (GvExtra1 != null) + { + StringWriter stringWriter1 = new StringWriter(); + HtmlTextWriter writer1 = new HtmlTextWriter(stringWriter1); + GvExtra1.RenderControl(writer1); + + MemoryStream memoryStream1 = new MemoryStream(htmlDefault.Encoding.GetBytes(stringWriter1.ToString())); + memoryStream1.Position = 0L; + StreamReader streamReader1 = new StreamReader(memoryStream1); + string input1 = streamReader1.ReadToEnd(); + + streamReader1.Dispose(); + memoryStream1.Dispose(); + stringWriter1.Dispose(); + + input1 = Regex.Replace(input1, "\\<[\\/]*a[^\\>]*\\>", ""); + MemoryStream stream1 = new MemoryStream(htmlDefault.Encoding.GetBytes(input1)); + SpreadsheetInfo.SetLicense(SerialGemBoxSpreadsheet()); + + ExcelFile excelFile2 = ExcelFile.Load(stream1, htmlDefault); + + ExcelWorksheet excelWorksheet2 = excelFile2.Worksheets[0]; + int num4 = excelWorksheet2.CalculateMaxUsedColumns(); + int num5 = num4 - 1; + for (int l = 0; l <= num5; l++) + { + excelWorksheet2.Columns[l].AutoFit(1.0, excelWorksheet2.Rows[1], excelWorksheet2.Rows[excelWorksheet2.Rows.Count - 1]); + + excelWorksheet2.Cells[0, l].Style.FillPattern.SetSolid(ColorTranslator.FromHtml("#4b77be")); + excelWorksheet2.Cells[0, l].Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255); + } + + excelFile.Worksheets.AddCopy(NombreHojaExtra1, excelWorksheet2); + } + + if (GvExtra2 != null) + { + StringWriter stringWriter2 = new StringWriter(); + HtmlTextWriter writer2 = new HtmlTextWriter(stringWriter2); + GvExtra2.RenderControl(writer2); + + MemoryStream memoryStream2 = new MemoryStream(htmlDefault.Encoding.GetBytes(stringWriter2.ToString())); + memoryStream2.Position = 0L; + StreamReader streamReader2 = new StreamReader(memoryStream2); + string input2 = streamReader2.ReadToEnd(); + + streamReader2.Dispose(); + memoryStream2.Dispose(); + stringWriter2.Dispose(); + + input2 = Regex.Replace(input2, "\\<[\\/]*a[^\\>]*\\>", ""); + MemoryStream stream2 = new MemoryStream(htmlDefault.Encoding.GetBytes(input2)); + SpreadsheetInfo.SetLicense(SerialGemBoxSpreadsheet()); + + ExcelFile excelFile3 = ExcelFile.Load(stream2, htmlDefault); + + ExcelWorksheet excelWorksheet3 = excelFile3.Worksheets[0]; + int num4 = excelWorksheet3.CalculateMaxUsedColumns(); + int num5 = num4 - 1; + + for (int l = 0; l <= num5; l++) + { + excelWorksheet3.Columns[l].AutoFit(1.0, excelWorksheet3.Rows[1], excelWorksheet3.Rows[excelWorksheet3.Rows.Count - 1]); + excelWorksheet3.Cells[0, l].Style.FillPattern.SetSolid(ColorTranslator.FromHtml("#4b77be")); + excelWorksheet3.Cells[0, l].Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255); + } + + excelFile.Worksheets.AddCopy(NombreHojaExtra2, excelWorksheet3); + } + + int num6 = 8; + int num7 = 0; + int num8 = -1; + if (DatosFiltros.Trim().Length > 0) + { + num8 = 0; + } + + int num9 = excelWorksheet.Rows.Count - 4; + for (num6 = 8; num6 <= num9; num6++) + { + try + { + switch (GridView.Rows[num7].CssClass.Trim()) + { + case "Totales": + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.FillPattern.SetSolid(ColorTranslator.FromHtml("#67809f")); + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.Font.Weight = 1000; + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.Font.Color = ColorTranslator.FromHtml("#ddd"); + break; + case "SubTotales2": + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.FillPattern.SetSolid(ColorTranslator.FromHtml("#c0c0c0")); + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.Font.Weight = 1000; + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.Font.Color = ColorTranslator.FromHtml("#000077"); + break; + case "SubTotales": + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.FillPattern.SetSolid(ColorTranslator.FromHtml("#dddddd")); + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.Font.Weight = 1000; + excelWorksheet.Cells.GetSubrangeRelative(num6 + num8, 0, usedCellRange.LastColumnIndex + 1, 1).Style.Font.Color = ColorTranslator.FromHtml("#67809F"); + break; + } + } + catch (Exception ex5) + { + ProjectData.SetProjectError(ex5); + Exception ex6 = ex5; + ProjectData.ClearProjectError(); + } + + num7++; + } + } + + if (Formato == "EXCEL") + { + excelFile.Save(System.Web.HttpContext.Current.Response, $"{NombreArchivoXLSx}.xlsx"); + } + else + { + foreach (var worksheet in excelFile.Worksheets) + { + var printOptions = worksheet.PrintOptions; + printOptions.LeftMargin = + printOptions.RightMargin = + printOptions.TopMargin = + printOptions.BottomMargin = 0; + + printOptions.AutomaticPageBreakScalingFactor = 93; + printOptions.Portrait = false; + } + + var saveOptions = new PdfSaveOptions(); + saveOptions.SelectionType = SelectionType.EntireFile; + + excelFile.Save(System.Web.HttpContext.Current.Response, $"{NombreArchivoXLSx}.pdf", saveOptions); + } + } + } + public void ImprimirStimulsoft() { String FechaF; - if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = $" Fecha Final: {txtFechaF.Text}"; } + if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = $"Fecha Final:{txtFechaF.Text}"; } String FechaI; - if (txtFechaI.Text == "" || txtFechaI.Text == "__/__/____") { FechaI = "-1"; } else { FechaI = $" Fecha Inicial: {txtFechaI.Text}"; } + if (txtFechaI.Text == "" || txtFechaI.Text == "__/__/____") { FechaI = "-1"; } else { FechaI = $"Fecha Inicial: {txtFechaI.Text} "; } String TipoMov; - if (DdlTipoMovto.SelectedItem.Text == "Todos") { TipoMov = ""; } else { TipoMov = $" Tipo Movimiento: {DdlTipoMovto.SelectedItem.Text}"; } + if (DdlTipoMovto.SelectedItem.Text == "Todos") { TipoMov = ""; } else { TipoMov = $"Tipo Movimiento: {DdlTipoMovto.SelectedItem.Text} "; } if (GvT.Rows.Count > 0 || GvA.Rows.Count > 0) { @@ -247,7 +573,7 @@ public partial class Contabilidad_RepIVA : ClsPaginas List para = new List(); para.Add(new ReportParameter("Empresa", UsuarioActual.Empresa.Empresa)); para.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)); - para.Add(new ReportParameter("Filtros", $"Filtros: {FechaI}{FechaF}{TipoMov}")); + para.Add(new ReportParameter("Filtros", $"Filtros: {FechaI}{FechaF}{TipoMov}")); if (Imagen.Exists) { @@ -258,8 +584,9 @@ public partial class Contabilidad_RepIVA : ClsPaginas para.Add(new ReportParameter("LogoPath", "")); } - DataTable Dt = DtIVAAcreditable.Copy(); - string Formato = "RepIVAAcreditable.mrt"; + DataTable Dt = TT.ActiveTabIndex == 0 ? DtIVATrasladado.Copy() : DtIVAAcreditable.Copy(); + + string Formato = TT.ActiveTabIndex == 0 ? "RepIVA.mrt" : "RepIVAAcreditable.mrt"; para.Add(new ReportParameter("Formato", "PDF")); @@ -270,24 +597,48 @@ public partial class Contabilidad_RepIVA : ClsPaginas List lrds = new List(); ReportDataSource rds = new ReportDataSource(); - rds.Name = "RepIVAAcreditable"; + rds.Name = TT.ActiveTabIndex == 0 ? "RepIVA" : "RepIVAAcreditable"; rds.Value = Dt; lrds.Add(rds); - if (DtIEPSA != null) + //RepIVA + if (TT.ActiveTabIndex == 0) { - ReportDataSource rds2 = new ReportDataSource(); - rds2.Name = "IEPSPorcentaje"; - rds2.Value = DtIEPSA; - lrds.Add(rds2); + if (DtIEPSA != null) + { + ReportDataSource rds2 = new ReportDataSource(); + rds2.Name = "IEPSPorcentaje"; + rds2.Value = DtIEPSA; + lrds.Add(rds2); + } + + if (DtIVAA != null) + { + ReportDataSource rds3 = new ReportDataSource(); + rds3.Name = "IVAPorcentaje"; + rds3.Value = DtIVAA; + lrds.Add(rds3); + } } - if (DtIVAA != null) + //RepIVAAcreditable + if (TT.ActiveTabIndex == 1) { - ReportDataSource rds3 = new ReportDataSource(); - rds3.Name = "IVAPorcentaje"; - rds3.Value = DtIVAA; - lrds.Add(rds3); + if (DtIVA2 != null) + { + ReportDataSource rds4 = new ReportDataSource(); + rds4.Name = "IVAPorcentaje"; + rds4.Value = DtIVA2; + lrds.Add(rds4); + } + + if (DtRetIVA != null) + { + ReportDataSource rds5 = new ReportDataSource(); + rds5.Name = "RetIVAPorcentaje"; + rds5.Value = DtRetIVA; + lrds.Add(rds5); + } } string Extension = "pdf"; @@ -424,7 +775,6 @@ public partial class Contabilidad_RepIVA : ClsPaginas protected void LnkTxtDIOT_Click(object sender, EventArgs e) { - StringBuilder SBDIOT = new StringBuilder(); int Conciliado = DdlTipoMovto.SelectedValue.ToEntero(); @@ -568,28 +918,6 @@ public partial class Contabilidad_RepIVA : ClsPaginas } } - - - - - //MemoryStream ms = new MemoryStream(); - //TextWriter tw = new StreamWriter(ms, System.Text.Encoding.UTF8); - - //tw.Write(SBDIOT.ToString()); - - //tw.Flush(); - - //byte[] bytes = ms.ToArray(); - //ms.Close(); - - //Response.Clear(); - //Response.AppendHeader("Content-Length", text.Length.ToString()); - //Response.ContentType = "text/plain"; - //Response.AddHeader("content-disposition", $"attachment; filename=DIOT_{ txtFechaI.Text.ToDate().ToString("ddMMyyyy") }_{txtFechaI.Text.ToDate().ToString("ddMMyyyy") }.txt"); - //Response.BinaryWrite(bytes); - //Response.End(); - - } static DataTable AcumularYReemplazar(DataTable dt) @@ -704,136 +1032,6 @@ public partial class Contabilidad_RepIVA : ClsPaginas } } - //public void IImprimirbytesPDF(byte[] bytes, string NombreArchivo = "Reporte", string Formato = "PDF", bool Descarga = false, string Content_Disposition = "attachment", string Extension = "") - //{ - // // limpio ReportViwer - // string mimeType = null; - // // If Descarga Then - // // Try - // // bytes = bytes - // // File.WriteAllBytes(String.Format("{0}PDF/whatever.gif", UsuarioActual.Empresa.Ruta), img) - // // Catch ex As Exception - // // If UsuarioActual.CveRol = 1 Then - // // Alert(ex.Message, TipoMensaje.MsgAdvertencia) - // // Else - // // Alert("Ocurrió un error al generar la descarga. Favor de contactar a soporte tecnico cod'IMPDFclspag'", TipoMensaje.MsgAdvertencia) - // // End If - // // End Try - // // End If - // try - // { - // bytes = bytes; - // //Response.Buffer = true; - // //Response.Clear(); - // //if (Formato == "PDF") - // // Response.ContentType = "application/pdf"; - // //else - // // Response.ContentType = mimeType; - // //Response.ClearHeaders(); - // //string fileExtension = ""; - // //if (!string.IsNullOrEmpty(Extension)) - // // fileExtension = Extension; - // //else - // // fileExtension = Formato == "PDF" ? "pdf" : "xls"; - // //Response.AddHeader("content-disposition", string.Format("{0}; filename=\"{1}.{2}\"", Content_Disposition, NombreArchivo, fileExtension)); - // //Response.BinaryWrite(bytes); // create the file - // //Response.Flush(); // send it to the client to download - // //bytes = null; - // //HttpContext.Current.Response.SuppressContent = true; - // //HttpContext.Current.ApplicationInstance.CompleteRequest(); - // Alert("ok"); - // } - // // HttpContext.Current.Response.End() - // catch (Exception ex) - // { - // if (UsuarioActual.CveRol == 1) { - - // } - // else - // Alert("Ocurrió un error al generar la descarga. Favor de contactar a soporte tecnico cod:'IMPDFclspag'", TipoMensaje.MsgAdvertencia); - // } - //} - - - //public byte[] IImprimirSubRepPDFCrystal(string RutaReporte, DataTable DataSource, List Parametros, DataTable DataSource1, DataTable DataSource2, string SubRep1, string SubRep2, string NombreArchivo = "Reporte", string Formato = "PDF", ReportDocument MR = null/* TODO Change to default(_) if this is not a reference type */) - //{ - // // limpio ReportViwer - // Stopwatch sw = Stopwatch.StartNew(); - - // if (MR == null) - // MR = new ReportDocument(); - // ReportDocument SR1 = new ReportDocument(); - // ReportDocument SR2 = new ReportDocument(); - // byte[] Bytes = null; - // ExportFormatType formatType = ExportFormatType.NoFormat; - // try - // { - // MR.Load(RutaReporte); - // SR1 = MR.OpenSubreport(SubRep1); - // SR2 = MR.OpenSubreport(SubRep2); - // MR.SetDataSource(DataSource); - // SR1.SetDataSource(DataSource1); - // SR2.SetDataSource(DataSource2); - // foreach (CrystalParametro item in Parametros) - // MR.SetParameterValue(item.Nombre, item.Valor); - // switch (Formato) - // { - // case "PDF": - // { - // formatType = ExportFormatType.PortableDocFormat; - // break; - // } - - // case "EXCEL": - // { - // formatType = ExportFormatType.Excel; - // break; - // } - // } - // System.IO.Stream Stream = MR.ExportToStream(formatType); - // BinaryReader BD = new BinaryReader(MR.ExportToStream(formatType)); - // Bytes = BD.ReadBytes(System.Convert.ToInt32(MR.ExportToStream(formatType).Length)); - // BD.Dispose(); - // Stream.Dispose(); - // } - // // Dim Buffer(CInt(Stream.Length)) As Byte - // // Bytes = Buffer - // // MR.ExportToHttpResponse(formatType, Response, True, NombreArchivo) - // catch (CrystalReportsException ex) - // { - // if(ex.Message != null) - // { - // Alert(ex.Message); - // } - // if (ex.InnerException != null) - // { - // Alert(ex.InnerException.Message); - // } - - // } - // // HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 - // // GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") - // catch (Exception ex) - // { - // //GuardaLog(ex.InnerException != null && ex.Message != null ? $"Error: {ex.InnerException.Message ?? ex.Message} | Descripcion: {ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message != null ? ex.InnerException.InnerException.Message : ex.InnerException != null && ex.InnerException.Message != null ? ex.InnerException.Message : "Sin descripcion"} Ruta {RutaReporte}" : $"Sin descripción - Ruta {RutaReporte}"); - // if (ex.Message != null) - // { - // Alert(ex.Message); - // } - // if (ex.InnerException != null) - // { - // Alert(ex.InnerException.Message); - // } - // } - // sw.Stop(); - // if (sw.Elapsed.TotalSeconds > 10) - // // GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} "); - // if (MR != null) - // MR.Dispose(); - // return Bytes; - //} - - protected void GvIEPSA_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && e.Row.DataKey("PorcentajeIEPS").Trim() == "") diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb index 835e0e09b..167f6a4db 100644 --- a/Ventas/PVCobranza.aspx.vb +++ b/Ventas/PVCobranza.aspx.vb @@ -500,82 +500,99 @@ Partial Class Ventas_PVCobranza Dim GvRow As GridViewRow = DirectCast(ImgBtn.BindingContainer, GridViewRow) Dim TieneError As Boolean = False - Dim CveVenta As Integer = e.CommandArgument.ToString.ToEntero - Dim CondicionesPagoContado As Boolean = GvRow.DataKey("CondicionesPago") = "0" - Dim ObjVentas As New ClsVentas - ObjVentas.IniciaTransacSQL() - - Try - If Not ObjVentas.UpdateAsignaVentaCobranza(CveVenta, 1, UsuarioActual.CveUsuario, -1, "", Now) Then + Dim CveVenta As Integer = e.CommandArgument.ToString.ToEntero + + Dim RowVenta As DataRow = Nothing + + Using ObjVta As New ClsVentas + If ObjVta.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then + RowVenta = ObjVta.DtResultados.Copy().Rows(0) + End If + End Using + + If RowVenta IsNot Nothing Then + Dim ObjVentas As New ClsVentas + ObjVentas.IniciaTransacSQL() + + Try + If Not ObjVentas.UpdateAsignaVentaCobranza(CveVenta, 1, UsuarioActual.CveUsuario, -1, "", Now) Then + TieneError = True + End If + HdnCveVenta.Value = CveVenta.ToString + + Dim Saldo As Decimal = RowVenta("Saldo").ToString().ToDecimal() + Dim CveFormaPago33 As String = RowVenta("CveFormaPago33").ToString() + + HdnCveCliente.Value = RowVenta("CveCliente").ToString() + TxtImporteContado.Text = Saldo.FormatoNumero + HdnTotal.Value = Saldo.ToString() + TxtImporteEfectivo.Focus() + LtlNombre.Text = RowVenta("AtencionA").ToString() + LtlFolio.Text = RowVenta("SerieFolio").ToString() + LtlSaldo.Text = Saldo.FormatoNumero + LtlMoneda.Text = RowVenta("Moneda").ToString() + + Dim CondicionesPagoContado As Boolean = RowVenta("CondicionesPago").ToString() = "0" + Dim CveMoneda As Integer = RowVenta("CveMoneda").ToString().ToEntero() + + HdnMoneda.Value = CveMoneda.ToString() + If CveMoneda = 2 Then + DivUSD.Visible = True + TxtTC.Text = GlobalTipoCambio(Now).ToString() + TxtTotalMXN.Text = (TxtImporteContado.Text.ToDecimal() * TxtTC.Text.ToDecimal()).FormatoNumero() + End If + + HdnVentaCondicionesPago.Value = RowVenta("CondicionesPago").ToString() + HdnPlazoCobranza.Value = GvRow.DataKey("PlazoCobranza") + + If UsuarioActual.CveEmpresa.Contiene(189, 193, 195, 196, 197) AndAlso RowVenta("TipoDocto").ToString().Contiene("Rem", "Ant") Then + DivAnticipo.Visible = True + ImgAntiPend.Visible = True + End If + + If CondicionesPagoContado Then + 'según la forma de pago va a establecer el valor para pago. + Select Case CveFormaPago33 + Case "1" + TxtImporteEfectivo.Text = Saldo.FormatoNumero + Case "2" + TxtImporteCheque.Text = Saldo.FormatoNumero + Case "3" + TxtImporteTransferencia.Text = Saldo.FormatoNumero + Case "4" + TxtImporteCredito.Text = Saldo.FormatoNumero + Case "18" + TxtImporteDebito.Text = Saldo.FormatoNumero + Case Else + TxtImporteEfectivo.Text = Saldo.FormatoNumero + End Select + DivContadoBancos.Visible = True + BtnPagar.Text = "Pagar" + Else + DivContadoBancos.Visible = False + BtnPagar.Text = "Emitir a crédito" + End If + + Catch ex As Exception TieneError = True - End If - HdnCveVenta.Value = CveVenta.ToString - HdnCveCliente.Value = GvRow.DataKey("CveCliente") - TxtImporteContado.Text = GvRow.DataKey("Saldo").FormatoNumero - HdnTotal.Value = GvRow.DataKey("Saldo") - TxtImporteEfectivo.Focus() - LtlNombre.Text = GvRow.DataKey("AtencionA") - LtlFolio.Text = GvRow.DataKey("SerieFolio") - LtlSaldo.Text = GvRow.DataKey("Saldo").ToDecimal.FormatoNumero - LtlMoneda.Text = GvRow.DataKey("Moneda") + End Try - Dim CveMoneda As Integer = GvRow.DataKey("CveMoneda").ToEntero() + 'carga información para cobranza - HdnMoneda.Value = CveMoneda.ToString() - If CveMoneda = 2 Then - DivUSD.Visible = True - TxtTC.Text = GlobalTipoCambio(Now).ToString() - TxtTotalMXN.Text = (TxtImporteContado.Text.ToDecimal() * TxtTC.Text.ToDecimal()).FormatoNumero() - End If - - HdnVentaCondicionesPago.Value = GvRow.DataKey("CondicionesPago") - HdnPlazoCobranza.Value = GvRow.DataKey("PlazoCobranza") - - If UsuarioActual.CveEmpresa.Contiene(189, 193, 195, 196, 197) AndAlso GvRow.DataKey("TipoDocto").Contiene("Rem", "Ant") Then - DivAnticipo.Visible = True - ImgAntiPend.Visible = True - End If - - If CondicionesPagoContado Then - 'según la forma de pago va a establecer el valor para pago. - Select Case GvRow.DataKey("CveFormaPago33") - Case "1" - TxtImporteEfectivo.Text = GvRow.DataKey("Saldo").FormatoNumero - Case "2" - TxtImporteCheque.Text = GvRow.DataKey("Saldo").FormatoNumero - Case "3" - TxtImporteTransferencia.Text = GvRow.DataKey("Saldo").FormatoNumero - Case "4" - TxtImporteCredito.Text = GvRow.DataKey("Saldo").FormatoNumero - Case "18" - TxtImporteDebito.Text = GvRow.DataKey("Saldo").FormatoNumero - Case Else - TxtImporteEfectivo.Text = GvRow.DataKey("Saldo").FormatoNumero - End Select - DivContadoBancos.Visible = True - BtnPagar.Text = "Pagar" + If Not TieneError Then + ObjVentas.Commit() + PnlContado.Visible = True Else - DivContadoBancos.Visible = False - BtnPagar.Text = "Emitir a crédito" + ObjVentas.RollBack() + PnlContado.Visible = False + Alert("Hubo un error al asignar datos de cobranza", TipoMensaje.MsgInformacion) End If - Catch ex As Exception - TieneError = True - End Try - - 'carga información para cobranza - - If Not TieneError Then - ObjVentas.Commit() - PnlContado.Visible = True - Else - ObjVentas.RollBack() - PnlContado.Visible = False - Alert("Hubo un error al asignar datos de cobranza", TipoMensaje.MsgInformacion) - End If - - ObjVentas.Dispose() - 'CargaDatos() + ObjVentas.Dispose() + End If + + + 'CargaDatos() End If End Sub diff --git a/Ventas/Ventas.aspx b/Ventas/Ventas.aspx index 97640280d..390e804f4 100644 --- a/Ventas/Ventas.aspx +++ b/Ventas/Ventas.aspx @@ -7699,7 +7699,7 @@
+ DataKeyNames="CveVenta,CveVentaDetalleRNC,CvePS,PU,PorcentajeIVA,Saldo" CssClass="table table-striped table-advance table-hover Widthall mysmallbtn" GridLines="None"> diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 2c255cd97..31cc18ddf 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -8119,6 +8119,8 @@ Partial Class Ventas If CreditoDispo < 0 Then BtnsFacturar.Visible = False BtnGenerarRemision.Visible = False + + TieneBloqueoPorCreditoVencimiento = 1 Alert("El límite de crédito se ha excedido", TipoMensaje.MsgAdvertencia) End If End If @@ -8133,9 +8135,7 @@ Partial Class Ventas BtnGenerarRemision.Visible = False Alert(OpcionMsg, TipoMensaje.MsgAdvertencia) - If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso ClienteEsDistribuidor AndAlso Opcion.Contiene(2, 3) Then - TieneBloqueoPorCreditoVencimiento = 1 - End If + TieneBloqueoPorCreditoVencimiento = 1 End If End If End If @@ -8439,6 +8439,12 @@ Partial Class Ventas End If + 'SI ES COTIZACION, PERMITIR CREAR UN DOCUMENTO NUEVO TIPO "PA" + If DdlTipoComprobante.SelectedValue = "Cot" AndAlso UsuarioActual.Empresa.Funcionalidad(595) = "1" AndAlso TieneBloqueoPorCreditoVencimiento = 1 Then + BtnGeneraAutorizacion.Visible = True + UpFacturar.Update() + End If + End Sub @@ -22102,6 +22108,20 @@ Partial Class Ventas End If End If + 'SI ES FACTURACION DE COTIZACION Y REQUIERE AUTORIZACION, SOLO DEBE PERMITIR ESTA + If UsuarioActual.Empresa.Funcionalidad(595) = "1" AndAlso Request("CveCotizacion") IsNot Nothing AndAlso Request("CveCotizacion").ToString().ToEntero() > 0 AndAlso TieneBloqueoPorAutorizacion = 1 Then + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ing")) + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Egs")) + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Cot")) + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Dev")) + + DdlTipoComprobante.SelectedValueExistInsert("PA", "Autorización") + DdlTipoComprobante.SelectedValue = "PA" + + BtnCrearApartirDe.Visible = False + UpFacturar.Update() + End If + '[IPP]: FALTA CONFIGURAR Y DAR PERMISO A TODOS LOS QUE TENGAN ACCESO A VENTAS ''Puede remisionar @@ -24737,6 +24757,19 @@ Partial Class Ventas Exit Sub End If + 'si es de FNC contado. bloquear edición si está pagada o en proceso de cobro + If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then + Using ObjVta As New ClsVentas + If ObjVta.GetVenta(Me.CveVenta, UsuarioActual.CveEmpresa) Then + Dim DbRowVenta As DataRow = ObjVta.DtResultados.FiltroPrimero("") + If DbRowVenta IsNot Nothing AndAlso (DbRowVenta("CveCobranzaEstatus").ToString = "1" OrElse DbRowVenta("Saldo").ToString.ToDecimal = 0) Then + Alert("No se puede actualizar la información de la remisión porque esta en proceso de cobro. Para aplicar cambios se debera de liberar desde el módulo de 'cobro por caja'.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + End Using + End If + Dim OcurrioError As Boolean = False Dim ObjVentas As New ClsVentas ObjVentas.IniciaTransacSQL() @@ -30711,7 +30744,7 @@ Partial Class Ventas If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then Dim ObjMovtos As New ClsMovimientos() If ObjMovtos.GetAnticiposNCIxCCliente(CveCliente, CveMoneda:=-1) Then - DtNC = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'RNC' AND CveVenta > 0 and Saldo > 0", "Moneda,Fecha,Folio") + DtNC = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'RNC' AND CveVenta > 0 and Saldo > 1", "Moneda,Fecha,Folio") End If ObjMovtos.Dispose() @@ -30815,7 +30848,7 @@ Partial Class Ventas If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then Dim ObjMovtos As New ClsMovimientos() If ObjMovtos.GetAnticiposNCIxCCliente(CveCliente, CveMoneda:=-1) Then - DtNC = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'RNC' AND CveVenta > 0 and Saldo > 0", "Moneda,Fecha,Folio") + DtNC = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'RNC' AND CveVenta > 0 and Saldo > 1", "Moneda,Fecha,Folio") End If ObjMovtos.Dispose() @@ -33143,7 +33176,7 @@ Partial Class Ventas Next If Not Selecciono Then - Alert("Tiene que seleccionar al menos un concepto y este dege tener una cantidad mayor a 0. Por favor verifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) + Alert("Tiene que seleccionar al menos un concepto y este debe tener una cantidad mayor a 0. Por favor verifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) Exit Sub End If @@ -35984,7 +36017,7 @@ Partial Class Ventas #Region "GENERAR AUTORIZACIÓN" Protected Sub BtnGeneraAutorizacion_Click(sender As Object, e As EventArgs) - If DdlTipoComprobante.SelectedValue.Contiene("Ped") Then + If DdlTipoComprobante.SelectedValue.Contiene("Ped", "Cot") Then EmitirDocumentoNuevo("PA") End If End Sub @@ -36678,10 +36711,15 @@ Partial Class Ventas Dim ImporteIVA As Decimal = (TotalCalculableImpuestos * PorcentajeIVA).RoundSQL(2) Dim TotalRNCDetalle As Decimal = (TotalCalculableImpuestos + ImporteIVA) + Dim Saldo As Decimal = GvRow.DataKey("Saldo").ToDecimal() + + 'AJUSTAR SALDO SI EL TOTAL ES MAYOR + If TotalRNCDetalle > Saldo Then + TotalRNCDetalle = Saldo + End If TotalRNC += TotalRNCDetalle - End If End If