Files
SIG/Ventas/RepPS.aspx.vb
JORGE LUIS CAUDILLO ESPARZA bc7143a261
2020-09-22 20:15:50 -07:00

235 lines
10 KiB
VB.net

Option Explicit On
Option Strict On
Imports Extensiones
Imports System.Data
Imports Microsoft.Reporting.WebForms
Partial Class Ventas_RepPS
Inherits ClsPaginas
#Region "P R O P I E D A D E S"
Private Property DtReporte As DataTable
Get
Return DirectCast(ViewState("DtReporte"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtReporte") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
pnlOrden.Visible = False
If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
pnlOrden.Visible = True
DdlOrden.SelectedValue = "2"
'Using ObjPS As New ClsProductosServicios
' If ObjPS.GetMarcas(UsuarioActual.CveEmpresa) Then
' DdlMarca.DataSource = ObjPS.DtResultados.Copy()
' End If
'End Using
'DdlMarca.DataBind()
'DdlMarca.Items.Insert(0, New ListItem("Todos", "-1"))
End If
CargaDatosIniciales()
CargaCombos()
CargaDatos()
End If
End Sub
Private Sub CargaDatosIniciales()
txtFechaI.Text = $"01/{Now.Month}/{Now.Year}"
txtFechaF.Text = Now.ToString("dd/MM/yyyy")
End Sub
Private Sub CargaCombos()
CargaTipoCentroCosto()
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
DdlClasificacion.DataBind()
DdlPS.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then
DdlPS.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue)
DdlPS.SelectedText = ""
DdlPS.SelectedValue = "-1"
Else
DdlPS.ddl.Items.Clear()
DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero)
DdlPS.ddl.DataBind()
DdlPS.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1"))
End If
If UsuarioActual.Empresa.Funcionalidad(130) = "1" Then
DivMarca.Visible = True
LblMarca.Visible = True
LblLinea.Visible = True
DivLinea.Visible = True
Using ObjMarcas As New ClsProductosServicios
If ObjMarcas.GetMarcas(UsuarioActual.CveEmpresa) Then
DdlMarcaPSDes.DataSource = ObjMarcas.DtResultados
DdlMarcaPSDes.DataBind()
End If
End Using
End If
DdlLinea.DataSource = GlobalDTClasificacionesDetalle(UsuarioActual.CveEmpresa)
DdlLinea.DataBind()
'DdlMarcaPSDes.Items.Insert(0, New ListItem(" Todos ", "-1"))
End Sub
Private Sub CargaTipoCentroCosto()
Dim index As Integer = 17
If UsuarioActual.Empresa.Tipo_CentroCosto = 1 Then
DdlSubProyecto.Items.Clear()
LblSubProyecto.InnerText = "Sucursal:"
DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1)
DdlSubProyecto.Items.Insert(0, New ListItem("Todos", "-1"))
DdlSubProyecto.DataBind()
ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then
DdlSubProyecto.Items.Clear()
LblSubProyecto.InnerText = "Proyecto:"
DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1)
DdlSubProyecto.Items.Insert(0, New ListItem("Todos", "-1"))
DdlSubProyecto.DataBind()
ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 3 Then
DdlGrupo.Items.Insert(0, New ListItem("Proyecto", "1"))
DdlGrupo.Items.Insert(1, New ListItem("SubProyecto", "2"))
If DdlGrupo.Items.Count < 17 Then
index = DdlGrupo.Items.Count
End If
DdlGrupo.Items.Insert(index, New ListItem("SubProyecto Ejec.", "19"))
DdlGrupo.DataBind()
ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 4 Then
LblSubProyecto.InnerText = "Proyecto:"
DdlGrupo.Items.Insert(0, New ListItem("Proyecto", "1"))
DdlGrupo.Items.Insert(1, New ListItem("SubProyecto", "2"))
If DdlGrupo.Items.Count < 17 Then
index = DdlGrupo.Items.Count
End If
DdlGrupo.Items.Insert(index, New ListItem("SubProyecto Ejec.", "19"))
DdlGrupo.DataBind()
ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then
LblSubProyecto.InnerText = "Sucursal:"
End If
End Sub
Private Sub CargaDatos()
Dim Clasificacion As String = If(DdlClasificacion.GetSelectedValuesM = "", "-1", DdlClasificacion.GetSelectedValuesM)
Dim Linea As String = If(DdlLinea.GetSelectedValuesM = "", "-1", DdlLinea.GetSelectedValuesM)
Dim Marca As String = If(DdlMarcaPSDes.GetSelectedValuesM = "", "-1", DdlMarcaPSDes.GetSelectedValuesM)
Dim CveSubProyecto As Integer = DdlSubProyecto.SelectedValue.ToEntero()
Dim Grupo As Integer = DdlGrupo.SelectedValue.ToEntero()
Dim CvePS As Integer = DdlPS.SelectedValue.ToEntero()
Dim CveMoneda As Integer = -1
Dim TC As Integer = 1
Dim TCEspecifico As Decimal = -1
Dim FechaI, FechaF As DateTime
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.ToDate, MinFecha)
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.ToDate, MaxFecha)
Dim ObjVentas As New ClsVentas()
If ObjVentas.GetRepPSEcono(CveSubProyecto, CvePS, FechaI, FechaF, UsuarioActual.CveEmpresa, CveUsuarioConsulta:=UsuarioActual.CveUsuario, GPO:=Grupo, CveMoneda:=CveMoneda, TipoCambio:=TC, TCEspecifico:=TCEspecifico, Clasificacion:=Clasificacion, Linea:=Linea, Marca:=Marca, orden:=DdlOrden.SelectedValue.ToEntero()) Then
DtReporte = ObjVentas.DtResultados.Copy()
GvDatos.DataSource = DtReporte
Else
GvDatos.DataSource = Nothing
End If
ObjVentas.Dispose()
GvDatos.DataBind()
UPDatos.Update()
End Sub
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Select Case e.Row.DBCampo("Orden").ToString.ToEntero()
Case 4
e.Row.Cells(0).ColumnSpan = 2
e.Row.Cells(1).Visible = False
e.Row.CssClass = "Totales"
Case 3
e.Row.Cells(0).ColumnSpan = 2
e.Row.Cells(1).Visible = False
e.Row.CssClass = "SubTotales2"
Case 2
e.Row.Cells(0).ColumnSpan = 2
e.Row.Cells(1).Visible = False
e.Row.CssClass = "SubTotales"
Case 1
e.Row.Cells(0).ColumnSpan = 2
e.Row.Cells(1).Visible = False
e.Row.CssClass = "SubTotalesB"
Case 0
e.Row.Cells(0).ColumnSpan = 1
e.Row.Cells(1).Visible = True
e.Row.CssClass = "Texto"
End Select
End If
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
CargaDatos()
End Sub
#Region " IMPRIMIR "
Protected Sub LnkPdf_Click(sender As Object, e As EventArgs) Handles LnkPdf.Click
If GvDatos.Rows.Count > 0 Then
GenerarPDF()
Else
Alert("No hay datos para imprimir")
End If
End Sub
Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
GvDatos.ExportToExcel("ReporteProductosServicios" & Now.ToShortDateString)
End Sub
Private Sub GenerarPDF()
Dim FechaI, FechaF As Date
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.ToDate, MinFecha)
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.ToDate, MaxFecha)
If DtReporte IsNot Nothing AndAlso DtReporte.Rows.Count > 0 Then
Dim SbParametros As New StringBuilder
SbParametros.AppendFormat("Sucursal:{0}", DdlSubProyecto.SelectedItem.Text)
SbParametros.AppendFormat(", Orden:{0}", DdlGrupo.SelectedItem.Text)
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta))
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
Dim params As New List(Of ReportParameter)
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("FechaInicio", If(txtFechaI.Text <> "", FechaI.ToShortDateString, "")))
params.Add(New ReportParameter("FechaFin", If(txtFechaF.Text <> "", FechaF.ToShortDateString, "")))
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString))
If Imagen.Exists Then
params.Add(New ReportParameter("LogoPath", logouri))
Else
params.Add(New ReportParameter("LogoPath", ""))
End If
params.Add(New ReportParameter("Parametros", SbParametros.ToString()))
If System.IO.File.Exists($"{ModExtensiones.DirectorioBaseEmpresas}/Empresas/{UsuarioActual.CveEmpresa}/Formatos/RepPS.rdlc") Then
ImprimirPDF($"Empresas/{UsuarioActual.CveEmpresa}/Formatos/RepPS.rdlc", DtReporte, params, "ReportePS")
Else
ImprimirPDF($"Empresas/Grales/Formatos/RepPS.rdlc", DtReporte, params, "ReportePS")
End If
Else
Alert("No hay información para mostrar.", TipoMensaje.MsgAdvertencia)
End If
End Sub
#End Region
End Class