Option Explicit On Option Strict On Imports System.Data Imports System.IO Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class Ventas_RepRecuperacion Inherits ClsPaginas #Region "P R O P I E D A D E S" Private Property DtDatos As DataTable Get Return DirectCast(ViewState("DtDatos"), DataTable) End Get Set(value As DataTable) ViewState("DtDatos") = value End Set End Property Private Property TipoCambio As Integer Get Return ViewState("TipoCambio").ToString.ToEntero End Get Set(value As Integer) ViewState("TipoCambio") = value End Set End Property Private Property TCEspecifico As Decimal Get Return ViewState("TCEspecifico").ToString.ToDecimal End Get Set(value As Decimal) ViewState("TCEspecifico") = value End Set End Property Private Property Agrupador As String Get Return ViewState("Agrupador").ToString End Get Set(value As String) ViewState("Agrupador") = 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 CargaCombos() 'CargaDatos() End If End Sub #Region "CARGAS" Private Sub CargaCombos() 'Carga Clientes If (UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1") Then DdlClientes.setEsWebService(True) DdlClientes.Attributes.Add("data-metodo", "getcliente") DdlClientes.SelectedText = "Todos" DdlClientes.SelectedValue = "-1" Else DdlClientes.setEsWebService(False) DdlClientes.ddl.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa) DdlClientes.ddl.DataBind() DdlClientes.ddl.Items.Insert(0, New ListItem("Todos", "-1")) End If 'Carga SubProyectos DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) DdlSubProyecto.DataBind() 'Carga Vendedor DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa) DdlVendedor.DataBind() DdlVendedor.Items.Insert(1, New ListItem("Sin Vendedor", "-2")) DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor) If UsuarioActual.CveVendedor > 0 AndAlso Not UsuarioActual.TienePermisoProceso(263) Then DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor.ToString()) DdlVendedor.Attributes.Add("disabled", "disabled") DdlVendedor.Enabled = False End If 'Carga Usuarios DdlUsuario.DataSource = GlobalDTUsuarios.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) DdlUsuario.DataBind() 'Carga Responsable DdlResponsable.DataSource = GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa) DdlResponsable.DataBind() 'Carga Bancos' DdlBanco.DataSource = GlobalDTBancos().FiltraParametros($"CveEmpresa = {UsuarioActual.CveEmpresa}") DdlBanco.DataBind() DdlBanco.Items.Insert(0, New ListItem("Todos", "-1")) DdlBanco.Items.Add(New ListItem("Empresa", "0")) 'Carga Clasificacion Cliente' Dim ObjCliente As New ClsClientes If ObjCliente.GetClienteClasificacion(UsuarioActual.CveEmpresa) Then DdlClienteClasificacion.DataSource = ObjCliente.DtResultados End If ObjCliente.Dispose() DdlClienteClasificacion.Items.Insert(0, New ListItem("Todos", "-1")) DdlClienteClasificacion.DataBind() txtFechaI.Text = $"01/{Now.Month}/{Now.Year}" txtFechaF.Text = Now.ToShortDateString If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then lblEsDistribuidor.Visible = True divEsDistribuidor.Visible = True End If UPFiltros.Update() End Sub Private Sub CargaDatos() Dim ObjMovtos As New ClsMovimientos() If RblTipoCambio.SelectedValue.ToEntero = 3 And TxtEspecifico.Text <> "" Then TCEspecifico = TxtEspecifico.Text.ToDecimal Else TCEspecifico = -1 End If Dim FechaAplicadoI As Date = If(IsDate(TxtFechaAplicadoI.Text), TxtFechaAplicadoI.Text.ToDate, MinFecha) Dim FechaAplicadoF As Date = If(IsDate(TxtFechaAplicadoF.Text), TxtFechaAplicadoF.Text.ToDate, MaxFecha) If ObjMovtos.GetRepRecuperacion(txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, DdlClientes.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, DdlVendedor.SelectedValue.ToEntero, DdlUsuario.SelectedValue.ToEntero, -1, "-1", UsuarioActual.CveEmpresa, DdlGrupo.SelectedValue.ToEntero, DdlResponsable.SelectedValue.ToEntero, DdlTipoDocto.SelectedValue.ToString, CveBanco:=DdlBanco.SelectedValue.ToEntero, CveCuenta:=DdlCuentaBancaria.SelectedValue.ToEntero, EstatusCliente:=DdlEstatusCliente.SelectedValue.ToEntero, CveUsuarioConsulta:=UsuarioActual.CveUsuario, TipoCambio:=RblTipoCambio.SelectedValue.ToEntero, TCEspecifico:=TCEspecifico, CveClienteClasificacion:=DdlClienteClasificacion.SelectedValue.ToEntero, EsDistribuidor:=DdlDistribuidor.SelectedValue.ToEntero(), FechaAplicadoI:=FechaAplicadoI, FechaAplicadoF:=FechaAplicadoF) Then GvDatos.DataSource = ObjMovtos.DtResultados DtDatos = ObjMovtos.DtResultados Else GvDatos.DataSource = Nothing End If ObjMovtos.Dispose() GvDatos.DataBind() Agrupador = DdlGrupo.SelectedItem.Text End Sub Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click CargaDatos() UpDatos.Update() End Sub #End Region #Region "GRIDVIEW" Private Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim Css As String = "Texto" Dim FechaI, FechaF, FechaAplicadoI, FechaAplicadoF As String Dim CveClienteSucursal As Integer = -1 FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1") FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1") FechaAplicadoI = If(IsDate(TxtFechaAplicadoI.Text.Trim()), TxtFechaAplicadoI.Text.Trim(), MinFecha.ToShortDateString.ToString) FechaAplicadoF = If(IsDate(TxtFechaAplicadoF.Text.Trim()), TxtFechaAplicadoF.Text.Trim(), MaxFecha.ToShortDateString.ToString) If e.Row.DBCampo("Orden") = "" Then e.Row.CssClass = "Totales" End If If DdlGrupo.SelectedValue = "5" Then CveClienteSucursal = e.Row.DBCampo("CveClienteSucursal").ToString.ToEntero If e.Row.DBCampo("CveCliente").ToString.ToEntero <= 0 Then ' cuando es el total general. CveClienteSucursal = -1 End If End If Dim Liga4 As String = String.Format("/Ventas/RepRecuperacionDetalle.aspx?GPO={0}&CveCliente={1}&CveSubProyecto={2}&Vendedor={3}&CveUsuario={4}&CveEstatusFactura={5}&IVA={6}&FechaI={7}&FechaF={8}&CveResponsable={9}&TipoDocto={10}&CveClienteSucursal={11}&CveBanco{12}&CveCuenta{13}&Grupo={14}&TipoCambio={15}&TCEspecifico={16}&CveMoneda={17}&Tipo={18}&EsDistribuidor={19}&FechaAplicadoI={20}&FechaAplicadoF={21}", DdlGrupo.SelectedValue, e.Row.DBCampo("CveCliente"), e.Row.DBCampo("CveSubProyecto"), e.Row.DBCampo("CveVendedor"), e.Row.DBCampo("CveUsuario"), e.Row.DBCampo("CveEstatusFactura"), e.Row.DBCampo("GPO_IVA"), FechaI, FechaF, DdlResponsable.SelectedValue, e.Row.DBCampo("TipoDocto"), CveClienteSucursal, e.Row.DBCampo("CveBanco"), e.Row.DBCampo("CveCuenta"), e.Row.DBCampo("GPO"), e.Row.DBCampo("TipoCambio"), e.Row.DBCampo("TCEspecifico"), e.Row.DBCampo("CveMoneda"), 2, e.Row.DBCampo("EsDistribuidor"), FechaAplicadoI, FechaAplicadoF) e.Row.FCHyperLink("HplPagado").NavigateUrl = Liga4 Dim Liga5 As String = String.Format("/Ventas/RepRecuperacionDetalle.aspx?GPO={0}&CveCliente={1}&CveSubProyecto={2}&Vendedor={3}&CveUsuario={4}&CveEstatusFactura={5}&IVA={6}&FechaI={7}&FechaF={8}&CveResponsable={9}&TipoDocto={10}&CveClienteSucursal={11}&CveBanco{12}&CveCuenta{13}&Grupo={14}&TipoCambio={15}&TCEspecifico={16}&CveMoneda={17}&Tipo={18}&EsDistribuidor={19}&FechaAplicadoI={20}&FechaAplicadoF={21}", DdlGrupo.SelectedValue, e.Row.DBCampo("CveCliente"), e.Row.DBCampo("CveSubProyecto"), e.Row.DBCampo("CveVendedor"), e.Row.DBCampo("CveUsuario"), e.Row.DBCampo("CveEstatusFactura"), e.Row.DBCampo("GPO_IVA"), FechaI, FechaF, DdlResponsable.SelectedValue, e.Row.DBCampo("TipoDocto"), CveClienteSucursal, e.Row.DBCampo("CveBanco"), e.Row.DBCampo("CveCuenta"), e.Row.DBCampo("GPO"), e.Row.DBCampo("TipoCambio"), e.Row.DBCampo("TCEspecifico"), e.Row.DBCampo("CveMoneda"), 1, e.Row.DBCampo("EsDistribuidor"), FechaAplicadoI, FechaAplicadoF) e.Row.FCHyperLink("HplVendido").NavigateUrl = Liga5 If DdlGrupo.SelectedValue.ToEntero = 16 Then If e.Row.DBCampo("GPO").Contains("Total") Then e.Row.CssClass = "Totales" Else If e.Row.DBCampo("CveCliente") = "" Then e.Row.CssClass = "SubTotales" End If End If End If End If End Sub #End Region #Region "SELECTED INDEX CHANGE" Protected Sub DdlBanco_SelectedIndexChanged(sender As Object, e As EventArgs) DdlCuentaBancaria.Items.Clear() DdlCuentaBancaria.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros($"CveBanco = {DdlBanco.SelectedValue.ToEntero}") DdlCuentaBancaria.Items.Insert(0, New ListItem("Todos", "-1")) DdlCuentaBancaria.DataBind() End Sub #End Region #Region "IMPRESIONES" Protected Sub LnkPdf_Click(sender As Object, e As EventArgs) Imprimir("PDF") End Sub Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Imprimir("EXCEL") End Sub Public Sub Imprimir(Formato As String) If DtDatos IsNot Nothing Then Dim StrFiltro As New StringBuilder If txtFechaI.Text <> "" Then StrFiltro.AppendFormat(" Fecha Inicio : {0}", txtFechaI.Text.ToDate.ToShortDateString) If txtFechaF.Text <> "" Then StrFiltro.AppendFormat(" Fecha Fin : {0}", txtFechaF.Text.ToDate.ToShortDateString) If DdlSubProyecto.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Sucursal: {0}", DdlSubProyecto.SelectedItem.Text) If DdlGrupo.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Grupo: {0}", DdlGrupo.SelectedItem.Text) If DdlVendedor.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Vendedor: {0}", DdlVendedor.SelectedItem.Text) If DdlClientes.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Cliente: {0}", DdlClientes.SelectedText) If DdlClienteClasificacion.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Clasificación Cliente: {0}", DdlClienteClasificacion.SelectedItem.Text) If DdlBanco.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Banco: {0}", DdlBanco.SelectedItem.Text) If DdlCuentaBancaria.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Cuenta Bancaria: {0}", DdlCuentaBancaria.SelectedItem.Text) If DdlTipoDocto.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Tipo Docto: {0}", DdlTipoDocto.SelectedItem.Text) If DdlEstatusCliente.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Estatus Cliente: {0}", DdlEstatusCliente.SelectedItem.Text) If DdlUsuario.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Registro: {0}", DdlUsuario.SelectedItem.Text) If DdlResponsable.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Responsable: {0}", DdlResponsable.SelectedItem.Text) Dim RutaPDF As String Dim Ruta As String = $"{ModExtensiones.DirectorioBaseEmpresas}Empresas\{UsuarioActual.CveEmpresa}\" RutaPDF = $"{Ruta}\Formatos\RepRecuperacion.rdlc" If Not File.Exists(RutaPDF) Then RutaPDF = "Empresas/Grales/Formatos/RepRecuperacion.rdlc" End If 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("UsuarioImprimio", UsuarioActual.Nombre)) params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) params.Add(New ReportParameter("Filtros", StrFiltro.ToString)) If Imagen.Exists Then params.Add(New ReportParameter("LogoPath", logouri)) Else params.Add(New ReportParameter("LogoPath", "")) End If ImprimirPDF(RutaPDF, DtDatos, params, String.Format("ReporteRecuperacion-{0}", Now.ToDateTime.ToShortDateString), Formato) Else Alert("No hay datos consultados.", TipoMensaje.MsgAdvertencia) End If End Sub #End Region #Region "TIPO DE CAMBIO" Private Sub RblTipoCambio_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RblTipoCambio.SelectedIndexChanged TipoCambio = RblTipoCambio.SelectedValue.ToEntero If TipoCambio = 3 Then LiEspecifico.Visible = True TCEspecifico = GlobalTipoCambio(Now).ToDecimal TxtEspecifico.Text = TCEspecifico.ToString Else LiEspecifico.Visible = False End If UpBodyTipoCambio.Update() End Sub Private Sub BtnTipoCambio_Click(sender As Object, e As EventArgs) Handles BtnTipoCambio.Click CargaDatos() RegistraScript(String.Format("$('#{0}').modal('hide');", "DivTipoCambio")) UpDatos.Update() End Sub #End Region #Region "GRAFICA" Protected Sub LnkVerGrafica_Click(sender As Object, e As EventArgs) If Not DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 Then Alert("No hay datos disponibles", TipoMensaje.MsgAdvertencia) Exit Sub End If LblTituloGrafica.Text = $"Agrupado por: {Agrupador}" RegistraScript("$('#DivModalGrafica').modal('show')") Dim Dt As New DataTable() Dt.Columns.Add("gpo") Dt.Columns.Add("vendido") Dt.Columns.Add("pagado") Dt.Columns.Add("moneda") For Each Dr As DataRow In DtDatos.Rows If Not Dr("Orden").ToString = "" Then Dim Row As DataRow = Nothing Row = Dt.NewRow() Row("gpo") = $"{Dr("GPO").ToString} {GlobalDTMonedas().FiltraParametros($"CveMoneda = {Dr("CveMoneda").ToString}").Rows(0)("Abreviatura").ToString}" Row("vendido") = Dr("Vendido").ToString.FormatoNumero Row("pagado") = Dr("Pagado").ToString.FormatoNumero Row("moneda") = Dr("Moneda").ToString Dt.Rows.Add(Row) End If Next Dim query = From s In Dt.AsEnumerable() Select New With {.gpo = s("gpo").ToString(), .vendido = s("vendido").ToString().ToDouble(), .pagado = s("pagado").ToString().ToDouble, .moneda = s("moneda").ToString()} Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(query) RegistraScript($"CargaGraficaCompracion({json})", "22") UPModalProd.Update() End Sub #End Region End Class