369 lines
17 KiB
VB.net
369 lines
17 KiB
VB.net
Imports Extensiones
|
|
|
|
Partial Class Ventas_CatAutorizacionLimites
|
|
Inherits ClsPaginas
|
|
|
|
#Region "PROPIEDADES"
|
|
Private Property CveAutorizacion() As Integer
|
|
Get
|
|
Return If(IsNothing(ViewState("CveAutorizacion")), -1, CInt(ViewState("CveAutorizacion")))
|
|
End Get
|
|
Set
|
|
ViewState("CveAutorizacion") = Value
|
|
End Set
|
|
End Property
|
|
Private Property Modalidad() As String
|
|
Get
|
|
Return If(IsNothing(ViewState("Modalidad")), "", (ViewState("Modalidad").ToString))
|
|
End Get
|
|
Set
|
|
ViewState("Modalidad") = Value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
|
|
Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
CargaCombos()
|
|
CargaDatos()
|
|
End If
|
|
End Sub
|
|
|
|
#Region "CARGAS"
|
|
Private Sub CargaCombos()
|
|
txtFechaI.Text = Now.AddDays(-1).ToString("dd/MM/yyyy")
|
|
txtFechaI.Text = Now.ToString("dd/MM/yyyy")
|
|
|
|
DdlCliente.setEsWebService(True)
|
|
DdlClienteFiltro.setEsWebService(True)
|
|
|
|
'Dim EsWS = If(UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1", True, False)
|
|
'If EsWS Then
|
|
' DdlCliente.setEsWebService(True)
|
|
' DdlClienteFiltro.setEsWebService(True)
|
|
'Else
|
|
' DdlCliente.setEsWebService(False)
|
|
' DdlCliente.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa, -1)
|
|
' DdlCliente.DataBind()
|
|
' DdlCliente.ddl.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
|
|
' DdlClienteFiltro.setEsWebService(False)
|
|
' DdlClienteFiltro.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa, -1)
|
|
' DdlClienteFiltro.DataBind()
|
|
' DdlClienteFiltro.ddl.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
'End If
|
|
|
|
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
|
|
DdlVendedor.DataBind()
|
|
|
|
DdlVendedorFiltro.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
|
|
DdlVendedorFiltro.DataBind()
|
|
DdlVendedorFiltro.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
DdlEstatus.SelectedValue = "0"
|
|
|
|
UpModal.Update()
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
Dim CveCliente As Integer = -1
|
|
If DdlClienteFiltro.SelectedValue.ToEntero() <= 0 Then
|
|
CveCliente = -1
|
|
Else
|
|
CveCliente = DdlClienteFiltro.SelectedValue.ToEntero()
|
|
End If
|
|
|
|
Dim FechaI, FechaF As Date
|
|
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim.ToDate, MinFecha)
|
|
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim.ToDate, MaxFecha)
|
|
|
|
Dim ObjGral As New ClsVentas
|
|
If ObjGral.GetAutorizacionLimite(UsuarioActual.CveEmpresa, CveCliente, DdlVendedorFiltro.SelectedValue.ToEntero(), "-1", CveEstatus:=DdlEstatus.SelectedValue.ToEntero(), FechaI:=FechaI, FechaF:=FechaF, CveUsuarioConsulta:=UsuarioActual.CveUsuario) Then
|
|
GvDatos.DataSource = ObjGral.DtResultados
|
|
End If
|
|
ObjGral.Dispose()
|
|
GvDatos.DataBind()
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "BOTONES"
|
|
Protected Sub LnkEliminar_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
|
|
Dim CveAutorizacion = gvRow.DataKey("CveAutorizacion").ToEntero()
|
|
Dim CveCliente = gvRow.DataKey("CveCliente").ToEntero()
|
|
|
|
Dim ObjGral As New ClsVentas
|
|
If ObjGral.RemoveAutorizacionLimite(CveAutorizacion, CveCliente) Then
|
|
Alert("La autorización se elimino correctamente.", TipoMensaje.MsgInformacion)
|
|
End If
|
|
ObjGral.Dispose()
|
|
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
Protected Sub LnkAgregar_Click(sender As Object, e As EventArgs)
|
|
LimpiaModal()
|
|
Modalidad = "A"
|
|
BtnGuardar.Text = "Agregar"
|
|
ltlMotititulo.Text = "Agregar autorización"
|
|
UpModal.Update()
|
|
RegistraScript("$('#DModal').modal()")
|
|
End Sub
|
|
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs)
|
|
If DdlTipoAutorizacion.SelectedValue.ToEntero() <= 0 Then
|
|
Alert("Debe seleccionar un tipo de autorización", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
Dim DiasVencidos As Integer = 0
|
|
Dim CveEstatus As Integer = 1
|
|
Dim TipoDocto As String = DdlTipoDocto.SelectedValue
|
|
Dim CveTipoAutorizacion As Integer = DdlTipoAutorizacion.SelectedValue.ToEntero()
|
|
|
|
If CveTipoAutorizacion = 2 Then
|
|
DiasVencidos = TxtDiasVencidos.Text.ToEntero()
|
|
End If
|
|
|
|
Dim Motivo As String = TxtMotivo.Text.Trim
|
|
|
|
Dim ObjPS As New ClsVentas
|
|
If ObjPS.AddAutorizacionLimite(UsuarioActual.CveEmpresa, DdlCliente.SelectedValue.ToEntero(), DdlVendedor.SelectedValue.ToEntero(), TxtPrecio.Text.ToDecimal(), CveEstatus, UsuarioActual.CveUsuario, CveTipoAutorizacion, TipoDocto, DiasVencidos, Motivo:=Motivo, PorcentajeDescuento:=TxtPorcentaje.Text.ToDecimal()) Then
|
|
RegistraScript("$('#DModal').modal('hide')")
|
|
Alert("La autorización se agregó correctamente.", TipoMensaje.MsgInformacion)
|
|
End If
|
|
ObjPS.Dispose()
|
|
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "LIMPIAR"
|
|
Protected Sub LimpiaModal()
|
|
Me.CveAutorizacion = -1
|
|
TxtPrecio.Text = ""
|
|
|
|
DdlCliente.SelectedValue = "-1"
|
|
DdlVendedor.SelectedValueExist("-1")
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "GRIDVIEW"
|
|
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
If e.Row.DBCampo("CveEstatus") = "0" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-secondary"
|
|
e.Row.FCLinkButton("LnkAutorizar").Visible = True
|
|
e.Row.FCLinkButton("LnkRechazar").Visible = True
|
|
ElseIf e.Row.DBCampo("CveEstatus") = "1" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-success"
|
|
e.Row.FCLinkButton("LnkAutorizar").Visible = False
|
|
e.Row.FCLinkButton("LnkRechazar").Visible = True
|
|
ElseIf e.Row.DBCampo("CveEstatus") = "2" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-primary"
|
|
e.Row.FCLinkButton("LnkAutorizar").Visible = False
|
|
e.Row.FCLinkButton("LnkRechazar").Visible = False
|
|
ElseIf e.Row.DBCampo("CveEstatus") = "3" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-danger"
|
|
e.Row.FCLinkButton("LnkAutorizar").Visible = False
|
|
e.Row.FCLinkButton("LnkRechazar").Visible = False
|
|
End If
|
|
|
|
If e.Row.DBCampo("TipoDocumento") = "Ingreso" Then
|
|
e.Row.FCLabel("LblTipo").CssClass = "label label-sm label-success"
|
|
Else
|
|
e.Row.FCLabel("LblTipo").CssClass = "label label-sm label-warning"
|
|
End If
|
|
|
|
If e.Row.DBCampo("TipoAutorizacion") = "1" Then
|
|
e.Row.FCLabel("LblTipoAuto").CssClass = "badge badge-success"
|
|
ElseIf e.Row.DBCampo("TipoAutorizacion") = "2" Then
|
|
e.Row.FCLabel("LblTipoAuto").CssClass = "badge badge-primary"
|
|
ElseIf e.Row.DBCampo("TipoAutorizacion") = "3" Then
|
|
e.Row.FCLabel("LblTipoAuto").CssClass = "badge badge-secondary"
|
|
End If
|
|
|
|
'If e.Row.DBCampo("Estatus") = "True" Then
|
|
' e.Row.Cells(1).ForeColor = Drawing.Color.Green
|
|
' e.Row.Cells(1).Font.Bold = True
|
|
' e.Row.Cells(1).Text = "Activo"
|
|
'Else
|
|
' e.Row.Cells(1).Text = "Inactivo"
|
|
' e.Row.Cells(1).ForeColor = Drawing.Color.Red
|
|
' e.Row.Cells(1).Font.Bold = True
|
|
'End If
|
|
End If
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
Protected Sub LnkAutorizar_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
|
|
Dim TipoAutorizacion = gvRow.DataKey("TipoAutorizacion").ToEntero()
|
|
Dim CveAutorizacion = gvRow.DataKey("CveAutorizacion").ToEntero()
|
|
Dim CveCliente = gvRow.DataKey("CveCliente").ToEntero()
|
|
Dim CveVendedor = gvRow.DataKey("CveVendedor").ToEntero()
|
|
Dim CveEstatusAutorizacion As Integer = 1
|
|
|
|
Dim Importe = gvRow.DataKey("Importe").ToDecimal().RoundSQL(2)
|
|
'AUTORIZACION DE IMPORTE,
|
|
'el cliente limite de 500, y saldo de 501. autorización que puede autorizar no puede ser mayor a 49 ( limite * 1.% - Saldo)
|
|
If TipoAutorizacion = 1 Then
|
|
|
|
Dim SaldoCliente = gvRow.DataKey("Saldo").ToDecimal()
|
|
Dim LimiteCredito = gvRow.DataKey("LimiteCredito").ToDecimal()
|
|
'SI EL LIMITE ES 0, PERMITE AUTORIZAR
|
|
If LimiteCredito > 0 Then
|
|
Dim PorcentajeMaximoAutorizar As Decimal = 0.1D
|
|
|
|
If UsuarioActual.PorcentajeMaximoAutorizacion > 0 Then
|
|
PorcentajeMaximoAutorizar = (UsuarioActual.PorcentajeMaximoAutorizacion / 100)
|
|
End If
|
|
|
|
Dim ImporteMaximoAutorizar As Decimal = ((LimiteCredito * (1D + PorcentajeMaximoAutorizar)) - SaldoCliente).RoundSQL(2)
|
|
|
|
If Importe > ImporteMaximoAutorizar Then
|
|
Alert($"No se puede autorizar, el importe máximo a autorizar es de {ImporteMaximoAutorizar:N2}", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
|
|
|
|
'AUTORIZACION POR DIAS VENCIDOS
|
|
ElseIf TipoAutorizacion = 2 Then
|
|
Dim DiasVencidos = gvRow.DataKey("DiasVencidos").ToEntero()
|
|
If DiasVencidos > 0 Then
|
|
Dim DiasVencidosPermitidos As Integer = 5
|
|
|
|
Dim DiasVencidosAutorizacion = gvRow.DataKey("DiasVencidosAutorizacion").ToEntero()
|
|
|
|
If DiasVencidos > DiasVencidosAutorizacion Then
|
|
Alert($"No se puede autorizar, los días vencidos del cliente son mayores a la autorización. Dias Vencidos: {DiasVencidos:N0}", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
If UsuarioActual.DiasMaximoAutorizacion > 0 Then
|
|
DiasVencidosPermitidos = UsuarioActual.DiasMaximoAutorizacion
|
|
End If
|
|
|
|
If DiasVencidosAutorizacion > DiasVencidosPermitidos Then
|
|
Alert($"No se puede autorizar, la cantidad máxima de días vencidos permitidas es de {DiasVencidosPermitidos:N0}", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
Dim ObjVentas As New ClsVentas
|
|
If ObjVentas.AutorizacionLimitesUpdate(CveAutorizacion, CveCliente, CveVendedor, Importe, CveEstatusAutorizacion) Then
|
|
Alert("El límite de crédito fue autorizado.")
|
|
End If
|
|
ObjVentas.Dispose()
|
|
|
|
CargaDatos()
|
|
End Sub
|
|
Protected Sub LnkRechazar_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
|
|
Dim CveAutorizacion = gvRow.DataKey("CveAutorizacion").ToEntero()
|
|
Dim CveCliente = gvRow.DataKey("CveCliente").ToEntero()
|
|
Dim CveVendedor = gvRow.DataKey("CveVendedor").ToEntero()
|
|
Dim Importe = gvRow.DataKey("Importe").ToDecimal()
|
|
Dim CveEstatusAutorizacion As Integer = 3
|
|
|
|
Dim ObjVentas As New ClsVentas
|
|
If ObjVentas.AutorizacionLimitesUpdate(CveAutorizacion, CveCliente, CveVendedor, Importe, CveEstatusAutorizacion) Then
|
|
Alert("El límite de crédito fue rechazado.")
|
|
End If
|
|
ObjVentas.Dispose()
|
|
|
|
CargaDatos()
|
|
End Sub
|
|
Protected Sub DdlTipoAutorizacion_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
DivImporte.Visible = DdlTipoAutorizacion.SelectedValue.ToEntero() = 1
|
|
DivDiasVencidos.Visible = DdlTipoAutorizacion.SelectedValue.ToEntero() = 2
|
|
DivPorcentajeDescuento.Visible = DdlTipoAutorizacion.SelectedValue.ToEntero() = 3
|
|
UpModal.Update()
|
|
End Sub
|
|
Protected Sub DdlCliente_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
Dim CveCliente As Integer = DdlCliente.SelectedValue.ToEntero()
|
|
If CveCliente > 0 Then
|
|
Using ObjClientes As New ClsClientes
|
|
If ObjClientes.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) AndAlso ObjClientes.DtResultados.Rows.Count > 0 Then
|
|
DdlVendedor.SelectedValueExist(ObjClientes.DtResultados.Rows(0)("CveVendedor"))
|
|
End If
|
|
End Using
|
|
End If
|
|
|
|
UpModal.Update()
|
|
End Sub
|
|
Protected Sub DdlTipoDocto_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
Dim TipoDocto As String = DdlTipoDocto.SelectedValue.ToString()
|
|
Select Case TipoDocto
|
|
Case "Ing"
|
|
If DdlTipoAutorizacion.Items.FindByValue("1") Is Nothing Then
|
|
DdlTipoAutorizacion.Items.Insert(0, New ListItem("Importe", "1"))
|
|
End If
|
|
If DdlTipoAutorizacion.Items.FindByValue("2") Is Nothing Then
|
|
DdlTipoAutorizacion.Items.Insert(0, New ListItem("Vencimiento", "2"))
|
|
End If
|
|
DdlTipoAutorizacion.Items.Remove(DdlTipoAutorizacion.Items.FindByValue("3"))
|
|
DivMotivo.Visible = False
|
|
Case "Egs"
|
|
If DdlTipoAutorizacion.Items.FindByValue("1") Is Nothing Then
|
|
DdlTipoAutorizacion.Items.Insert(0, New ListItem("Importe", "1"))
|
|
End If
|
|
'QUITAR LA DE VENCIMIENTO
|
|
DdlTipoAutorizacion.Items.Remove(DdlTipoAutorizacion.Items.FindByValue("2"))
|
|
'QUITAR LA DE DESCUENTO
|
|
DdlTipoAutorizacion.Items.Remove(DdlTipoAutorizacion.Items.FindByValue("3"))
|
|
DivMotivo.Visible = True
|
|
Case "Rem"
|
|
If DdlTipoAutorizacion.Items.FindByValue("3") Is Nothing Then
|
|
DdlTipoAutorizacion.Items.Insert(0, New ListItem("Porcentaje Descuento", "3"))
|
|
End If
|
|
DdlTipoAutorizacion.Items.Remove(DdlTipoAutorizacion.Items.FindByValue("1"))
|
|
DdlTipoAutorizacion.Items.Remove(DdlTipoAutorizacion.Items.FindByValue("2"))
|
|
DivMotivo.Visible = False
|
|
End Select
|
|
UpModal.Update()
|
|
End Sub
|
|
|
|
#Region " EXPORTA EXCEL "
|
|
Protected Sub LnkExportarExcel_Click(sender As Object, e As EventArgs) Handles LnkExportarExcel.Click
|
|
If GvDatos.Rows.Count <= 0 Then
|
|
Alert("No hay registros para exportar. Por favor modifique su consulta.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim StrFiltro As New StringBuilder
|
|
StrFiltro.AppendFormat("Filtro: ")
|
|
StrFiltro.AppendFormat("Estatus: {0}, ", DdlEstatus.SelectedItem)
|
|
StrFiltro.AppendFormat("Cliente: {0}, ", IIf(DdlClienteFiltro.SelectedText <> "", DdlClienteFiltro.SelectedText, "Todos"))
|
|
StrFiltro.AppendFormat("Vendedor: {0}, ", DdlVendedorFiltro.SelectedItem)
|
|
StrFiltro.AppendFormat("Fecha Inicio: {0}", txtFechaI.Text.ToDate.ToString("dd/MM/yyyy"))
|
|
'If txtFechaF.Text <> "" Then StrFiltro.AppendFormat(", Fecha Fin: {0}", txtFechaF.Text.ToDate.ToString("dd/MM/yyyy"))
|
|
Dim fechaFin As String = If(txtFechaF.Text <> "", txtFechaF.Text.ToDate.ToString("dd/MM/yyyy"), Now.ToString("dd/MM/yyyy"))
|
|
StrFiltro.AppendFormat(", Fecha Fin: {0}", fechaFin)
|
|
|
|
'Oculta columnas en export sin afectar GridView en página
|
|
Dim tcols = GvDatos.Columns.Count
|
|
GvDatos.HeaderRow.Cells(tcols - 2).Visible = False 'Autorizar/Rechazar
|
|
GvDatos.HeaderRow.Cells(tcols - 1).Visible = False 'Eliminar
|
|
|
|
GvDatos.ExportToExcelGembox("CatAutorizacionLimites " & txtFechaI.Text.ToDate.ToString("dd-MM-yyyy") + " a " & fechaFin.ToDate.ToString("dd-MM-yyyy"), UsuarioActual, "Catálogo de autorizaciones de límite de crédito", DatosFiltros:=StrFiltro.ToString())
|
|
End Sub
|
|
|
|
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
|
|
End Sub
|
|
#End Region
|
|
End Class
|