diff --git a/Acumuladores/EntradasUsadosResumenRep.aspx b/Acumuladores/EntradasUsadosResumenRep.aspx index eb86ecdc5..9fe1ff8df 100644 --- a/Acumuladores/EntradasUsadosResumenRep.aspx +++ b/Acumuladores/EntradasUsadosResumenRep.aspx @@ -11,7 +11,10 @@
  • - + +
  • +
  • +
  • @@ -97,6 +100,87 @@
    + + diff --git a/Acumuladores/EntradasUsadosResumenRep.aspx.vb b/Acumuladores/EntradasUsadosResumenRep.aspx.vb index ced8542ab..4043c344f 100644 --- a/Acumuladores/EntradasUsadosResumenRep.aspx.vb +++ b/Acumuladores/EntradasUsadosResumenRep.aspx.vb @@ -1,6 +1,8 @@ Imports System.Data Imports Extensiones Imports Microsoft.Reporting.WebForms +Imports GemBox.Spreadsheet +Imports System.IO Partial Class Acumuladores_RepEntradasUsados Inherits ClsPaginas @@ -22,6 +24,9 @@ Partial Class Acumuladores_RepEntradasUsados txtFechaI.Text = Today.AddDays((-1) * (Today.Day - 1)) txtFechaF.Text = Today CargarDatos() + CargarCombos() + + End If End Sub @@ -30,6 +35,18 @@ Partial Class Acumuladores_RepEntradasUsados DdlAlmacenes.DataBind() End Sub + Protected Sub CargarCombos() + Dim ObjAcum As New ClsAcumuladores + Dim fecha As Date = Date.Now.AddMonths(-1) + ObjAcum.GetAñosVentas(UsuarioActual.CveEmpresa) + DdlAño.DataSource = ObjAcum.DtResultados + DdlAño.DataBind() + DdlAño.SelectedValue = fecha.Year.ToEntero + ObjAcum.Dispose() + + DdlMes.SelectedValue = fecha.Month.ToEntero + End Sub + Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Dim ObjAcum As New ClsAcumuladores @@ -63,5 +80,77 @@ Partial Class Acumuladores_RepEntradasUsados ImprimirPDF(String.Format("Empresas/{0}/Formatos/RepEntradasUsados.rdlc", UsuarioActual.CveEmpresa), DatosEntradasUsados, params, "Reporte entrada usados", "PDF") + End Sub + + Protected Sub BtnDescargaSabana_Click(sender As Object, e As EventArgs) Handles BtnDescargaSabana.Click + RegistraScript(String.Format("$('#{0}').modal('show');", "DivModalSabana")) + + 'RegistraScript("$('#DModalEditarFecha').modal('hide')") + + End Sub + + Protected Sub BtnDescargarSabana_Click(sender As Object, e As EventArgs) Handles BtnDescargarSabana.Click + Dim Retorno As New IO.MemoryStream() + Dim ObjAcum As New ClsAcumuladores + Dim Mes As String = DdlMes.SelectedValue.ToString + Dim Año As String = DdlAño.SelectedValue.ToString + Dim Fecha As Date = (String.Format("01/{0}/{1}", Mes, Año)).ToDate + Dim dt As DataTable + Dim NombreArchivo As String + Try + If DdlOpcion.SelectedValue = 1 Then + ObjAcum.GetSabanaVenta(Fecha, 1, UsuarioActual.CveEmpresa) + + ElseIf DdlOpcion.SelectedValue = 2 Then + ObjAcum.GetSabanaVenta(Fecha, 2, UsuarioActual.CveEmpresa) + + End If + dt = ObjAcum.DtResultados + + If dt IsNot Nothing And dt.Rows.Count > 0 Then + SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) + Dim workbook As New ExcelFile() + + Dim worksheet = workbook.Worksheets.Add("Sabana de ventas") + worksheet.InsertDataTable(dt, New InsertDataTableOptions() With + { + .ColumnHeaders = True, + .StartRow = 0, + .StartColumn = 0 + }) + worksheet.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255)) + worksheet.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255) + + Dim columnCount = worksheet.CalculateMaxUsedColumns() + For i = 0 To columnCount + worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1)) + Next + + Año = Strings.Right(Año, 2) + If Mes.ToEntero < 10 Then + Mes = String.Format("0{0}", Mes) + End If + If DdlOpcion.SelectedValue = 1 Then + NombreArchivo = String.Format("700415-{0}{1}-GE", Mes, Año) + workbook.Save(Response, $"{NombreArchivo}.xlsx", SaveOptions.XlsxDefault) + + + ElseIf DdlOpcion.SelectedValue = 2 Then + NombreArchivo = String.Format("700415-{0}{1}-CS", Mes, Año) + workbook.Save(Response, $"{NombreArchivo}.xlsx", SaveOptions.XlsxDefault) + + End If + End If + Catch ex As Exception + GuardaLog(String.Format("Ocurrio un error al generar el excel {0}", ex.Message)) + + End Try + + ObjAcum.Dispose() + RegistraScript("$('#DModalEditarFecha').modal('hide')") + + + + End Sub End Class diff --git a/App_Code/ClsAcumuladores.vb b/App_Code/ClsAcumuladores.vb index c37e75652..b14e03dfe 100644 --- a/App_Code/ClsAcumuladores.vb +++ b/App_Code/ClsAcumuladores.vb @@ -1173,6 +1173,42 @@ Public Class ClsAcumuladores End Function + Public Function GetSabanaVenta(Fecha As Date, CveOpcion As Integer, CveEmpresa As Integer) As Boolean + Dim Retorno As Boolean = False + + SqlDataAdapter("PA_Acum_SabanaVentaGet") + + With SqlAdapter.SelectCommand.Parameters + .Add("@Fecha", SqlDbType.Date).Value = Fecha + .Add("@Opcion", SqlDbType.Int).Value = CveOpcion + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As SqlException + OnError("Ocurrió un error al consultar los movimientos. ", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function + + Public Function GetAñosVentas(CveEmprea As Integer) As Boolean + Dim Retorno As Boolean = False + SqlDataAdapter(String.Format("select year(Fecha) as Año from Ventas where CveEmpresa = {0} group by year(Fecha) Order by year(Fecha)", CveEmprea.ToString), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError(String.Format("Ocurrió un error al consultar los año de venta"), ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + Return Retorno + + End Function + #Region " IDisposable Support " ' IDisposable