From d3c2b30ff69560fd0859d7773323a297ebc64093 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Fri, 15 Oct 2021 19:22:22 -0700 Subject: [PATCH] =?UTF-8?q?Candado=20de=20autorizaci=C3=B3nes=20en=20cotiz?= =?UTF-8?q?aciones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ventas/Ventas.aspx.vb | 257 ++++++++++++++++++++++++++++-------------- 1 file changed, 174 insertions(+), 83 deletions(-) diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index c44945cb0..19ee8aa5b 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -5079,69 +5079,7 @@ Partial Class Ventas End If 'ACTIVA BOTONERA | DEBE TENER CONCEPTOS PENDIENTES DE FACTURAR - If TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") AndAlso DdlTipoComprobante.SelectedValue.Contiene("Cot") Then - - If UsuarioActual.TienePermisoProceso(199) Then - BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) - Else - BtnGenerarRemision.Visible = False - End If - - If UsuarioActual.TienePermisoProceso(60) Then BtnsFacturar.Visible = True 'puede facturar - - If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso UsuarioActual.TienePermisoProceso(60) Then - - Select Case UsuarioActual.Empresa.Funcionalidad(135) - Case "1" ' POR SUPERVISOR - Dim ObjVendedores As New ClsVtaVendedores - - If ObjVendedores.GetVendedores(UsuarioActual.CveEmpresa) Then - Dim DTVendedores As New DataTable - If DbRowVenta("CveVendedor").ToString().ToEntero() > 0 AndAlso UsuarioActual.CveVendedor > 0 Then - DTVendedores = ObjVendedores.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", DbRowVenta("CveVendedor").ToString())).FiltraParametros(String.Format("CveSupervisor = {0}", UsuarioActual.CveVendedor)) - End If - - 'Verifico si es su supervisor asignado - If DTVendedores.Rows.Count > 0 Then - If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then - BtnsFacturar.Visible = True - - If UsuarioActual.TienePermisoProceso(199) Then - BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) - Else - BtnGenerarRemision.Visible = False - End If - - Else - BtnsFacturar.Visible = False - BtnGenerarRemision.Visible = False - End If - End If - - DTVendedores.Dispose() - End If - ObjVendedores.Dispose() - - Case "2" ' POR PERMISO - If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then - BtnsFacturar.Visible = UsuarioActual.TienePermisoProceso(60) - - If UsuarioActual.TienePermisoProceso(199) Then - BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) - Else - BtnGenerarRemision.Visible = False - End If - Else - BtnsFacturar.Visible = False - BtnGenerarRemision.Visible = False - End If - - End Select - - End If - - LBFacturarAnticipo.Visible = UsuarioActual.TienePermisoProceso(274) - End If + VerificarBtnFacturarCotizacion(DbRowVenta("CveVendedor").ToString().ToEntero()) End If If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then @@ -5255,6 +5193,75 @@ Partial Class Ventas ObjVentas.Dispose() Return Retorno End Function + + Private Sub VerificarBtnFacturarCotizacion(CveVendedor As Integer, Optional MostrarGenerarRemision As Boolean = True) + If TmpDT.SUM("CantidadFacturadaCot") < TmpDT.SUM("Cantidad") AndAlso DdlTipoComprobante.SelectedValue.Contiene("Cot") Then + + If UsuarioActual.TienePermisoProceso(199) Then + BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) + Else + BtnGenerarRemision.Visible = False + End If + + If UsuarioActual.TienePermisoProceso(60) Then BtnsFacturar.Visible = True 'puede facturar + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso UsuarioActual.TienePermisoProceso(60) Then + + Select Case UsuarioActual.Empresa.Funcionalidad(135) + Case "1" ' POR SUPERVISOR + Dim ObjVendedores As New ClsVtaVendedores + + If ObjVendedores.GetVendedores(UsuarioActual.CveEmpresa) Then + Dim DTVendedores As New DataTable + If CveVendedor > 0 AndAlso UsuarioActual.CveVendedor > 0 Then + DTVendedores = ObjVendedores.DtResultados.FiltraParametros(String.Format("CveVendedor = {0}", CveVendedor)).FiltraParametros(String.Format("CveSupervisor = {0}", UsuarioActual.CveVendedor)) + End If + + 'Verifico si es su supervisor asignado + If DTVendedores.Rows.Count > 0 Then + If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then + BtnsFacturar.Visible = True + + If UsuarioActual.TienePermisoProceso(199) Then + BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) + Else + BtnGenerarRemision.Visible = False + End If + + Else + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + End If + End If + + DTVendedores.Dispose() + End If + ObjVendedores.Dispose() + + Case "2" ' POR PERMISO + If GlobalDTEstatusFactura().FiltroPrimeroValor("TipoEstatus", $"CveEstatusFactura = {Me.CveEstatus}").ToEntero() = 2 Then + BtnsFacturar.Visible = UsuarioActual.TienePermisoProceso(60) + + If UsuarioActual.TienePermisoProceso(199) Then + BtnGenerarRemision.Visible = If(CveEstatus = 10, False, True) + Else + BtnGenerarRemision.Visible = False + End If + Else + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + End If + + End Select + + End If + + If BtnGenerarRemision.Visible AndAlso Not MostrarGenerarRemision Then + BtnGenerarRemision.Visible = False + End If + LBFacturarAnticipo.Visible = UsuarioActual.TienePermisoProceso(274) + End If + End Sub Private Sub CargaTiposDocumentos() DdlTipoComprobante.DataSource = GlobalDTTiposDocumentos() DdlTipoComprobante.DataBind() @@ -6278,17 +6285,23 @@ Partial Class Ventas Dim ValorAutorizacion As String = UsuarioActual.Empresa.Funcionalidad(595) 'OBLIGAR PAGO DE CONTADO SI EL CLIENTE NO PERMITE CREDITO - If UsuarioActual.Empresa.Funcionalidad(570) = "1" AndAlso Me.PermiteCredito = False AndAlso ((DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") AndAlso CveVenta < 1) OrElse (DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem", "Cot") AndAlso EsCreaApartirDe)) Then + If UsuarioActual.Empresa.Funcionalidad(570) = "1" AndAlso Me.PermiteCredito = False AndAlso ((DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") AndAlso CveVenta < 1) OrElse (DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem", "Cot") AndAlso EsCreaApartirDe) OrElse (DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveVenta > 0)) Then RBLPago.SelectedValue = "2" RBLPago.Items(0).Enabled = False RBLPago_SelectedIndexChanged(Nothing, Nothing) 'GENERAR UNA AUTORIZACIÓN SI EL CLIENTE NO PERMITE CREDITO If UsuarioActual.Empresa.Funcionalidad(595) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(268) Then - DdlTipoComprobante.SelectedValueExistInsert("PA", "Autorización") - DdlTipoComprobante.SelectedValue = "PA" + 'SI LLEGÓ POR LA OPCIÓN DE COTIZACIÓN NO DEBE DE RESTRINGUIR + If IfNull(Request("Op"), "").ToString() = "Cot" OrElse (DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0) Then + DdlTipoComprobante.SelectedValue = "Cot" + BtnGenerarRemision.Visible = False + Else + DdlTipoComprobante.SelectedValueExistInsert("PA", "Autorización") + DdlTipoComprobante.SelectedValue = "PA" + End If + TxtFechaPago.Text = Now.AddDays(PlazoCobranza).ToShortDateString - 'si llegó por la opción de cotización no debe de restringuir - If IfNull(Request("Op"), "").ToString() = "Cot" Then DdlTipoComprobante.SelectedValue = "Cot" + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ing")) If Not UsuarioActual.TienePermisoProceso(325) Then DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ant")) @@ -6302,7 +6315,7 @@ Partial Class Ventas 'CARGAR CREDITO DISPONIBLE AL GENERAR UNA FACTURA End If - If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem", "Cot", "PA") AndAlso CveVenta <= 0 AndAlso RBLPago.SelectedValue = "1" AndAlso PermiteCredito Then + If ((DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem", "Cot", "PA") AndAlso CveVenta <= 0) OrElse (DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveVenta > 0)) AndAlso RBLPago.SelectedValue = "1" AndAlso PermiteCredito Then 'FUNCIONALIDAD 702 - NO VERIFICAR LIMITE DE CRÉDITO Y CANDADOS DE VENTA If Not UsuarioActual.Empresa.Funcionalidad(702) = "1" Then RBLPago.SelectedValue = "1" @@ -6316,7 +6329,7 @@ Partial Class Ventas LblCreditoDisponible.Text = CreditoDispo.FormatoNumero If PorcentajeCredito > 80 Then TrPorcentajeCredito.Visible = True : LblPorcentajeCredito.Text = $"{PorcentajeCredito.FormatoNumero}%" - If Not UsuarioActual.TienePermisoProceso(268) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem", "PA") AndAlso (Not UsuarioActual.Empresa.Funcionalidad(702).Contiene("2")) Then + If Not UsuarioActual.TienePermisoProceso(268) AndAlso (DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem", "PA") OrElse (DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveVenta > 0)) AndAlso (Not UsuarioActual.Empresa.Funcionalidad(702).Contiene("2")) Then Dim Vta As New ClsVentas Dim Opcion As Integer = Vta.ObtenerClienteLimitesVenta(CveCliente, UsuarioActual.CveEmpresa) Dim OpcionMsg As String = String.Format("El Cliente se encuentra bloqueado por la siguiente razón:

{0}", Vta.SerieVenta) @@ -6332,7 +6345,7 @@ Partial Class Ventas DdlTipoComprobante.SelectedValue = "PA" TxtFechaPago.Text = Now.AddDays(PlazoCobranza).ToShortDateString 'si llegó por la opción de cotización no debe de restringuir - If IfNull(Request("Op"), "").ToString() = "Cot" Then DdlTipoComprobante.SelectedValue = "Cot" + If IfNull(Request("Op"), "").ToString() = "Cot" OrElse (DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0) Then DdlTipoComprobante.SelectedValue = "Cot" 'quito remisión y factura DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ing")) If Not UsuarioActual.TienePermisoProceso(325) Then @@ -6391,7 +6404,7 @@ Partial Class Ventas DdlTipoComprobante.SelectedValue = "PA" TxtFechaPago.Text = Now.AddDays(PlazoCobranza).ToShortDateString 'si llegó por la opción de cotización no debe de restringuir - If IfNull(Request("Op"), "").ToString() = "Cot" Then DdlTipoComprobante.SelectedValue = "Cot" + If IfNull(Request("Op"), "").ToString() = "Cot" OrElse (DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0) Then DdlTipoComprobante.SelectedValue = "Cot" DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ing")) If Not UsuarioActual.TienePermisoProceso(325) Then DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ant")) @@ -6403,6 +6416,27 @@ Partial Class Ventas LnkPedido2SinFacturar.Visible = False LnkCotizaciones.Visible = False LnkOCs.Visible = False + Else + 'VERIFICAR LIMITE DE CREDITO + If DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0 AndAlso RBLPago.SelectedValue = "1" Then + If CreditoDispo < 0 Then + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + Alert("El límite de crédito se ha excedido", TipoMensaje.MsgAdvertencia) + End If + End If + + If DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0 Then + Dim Vta As New ClsVentas + Dim Opcion As Integer = Vta.ObtenerClienteLimitesVenta(CveCliente, UsuarioActual.CveEmpresa) + Dim OpcionMsg As String = String.Format("El Cliente se encuentra bloqueado por la siguiente razón:

{0}", Vta.SerieVenta) + Vta.Dispose() + If Opcion > 0 Then + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + Alert(OpcionMsg, TipoMensaje.MsgAdvertencia) + End If + End If End If Case "2" 'Autorizacion desde una solicitud del catalogo de autorizaciones 'RMF. validacion temporal @@ -6427,6 +6461,18 @@ Partial Class Ventas Alert(OpcionMsg, TipoMensaje.MsgAdvertencia) End If Else + 'VERIFICAR CANDADOS DE VENTA + If DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0 Then + Dim Vta As New ClsVentas + Dim Opcion As Integer = Vta.ObtenerClienteLimitesVenta(CveCliente, UsuarioActual.CveEmpresa) + Dim OpcionMsg As String = String.Format("El Cliente se encuentra bloqueado por la siguiente razón:

{0}", Vta.SerieVenta) + Vta.Dispose() + If Opcion > 0 Then + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + Alert(OpcionMsg, TipoMensaje.MsgAdvertencia) + End If + End If If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then RBLPago.SelectedValue = "2" @@ -6449,9 +6495,25 @@ Partial Class Ventas End If End If - UPPCreditoDisponible.Update() + Else + + 'VERIFICAR RESTRICCIONES DEL CLIENTE + If DdlTipoComprobante.SelectedValue = "Cot" AndAlso CveVenta > 0 AndAlso RBLPago.SelectedValue = "2" Then + Dim Vta As New ClsVentas + Dim Opcion As Integer = Vta.ObtenerClienteLimitesVenta(CveCliente, UsuarioActual.CveEmpresa) + Dim OpcionMsg As String = String.Format("El Cliente se encuentra bloqueado por la siguiente razón:

{0}", Vta.SerieVenta) + Vta.Dispose() + If Opcion > 0 Then + Alert(OpcionMsg, TipoMensaje.MsgAdvertencia) + End If + BtnsFacturar.Visible = False + BtnGenerarRemision.Visible = False + End If + End If + UPPCreditoDisponible.Update() + 'Puede hacer pedido If CveVenta <= 0 Then If Not UsuarioActual.TienePermisoProceso(177) Then @@ -20830,7 +20892,7 @@ Partial Class Ventas End If Case 2 'CONTADO - If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") Or (UsuarioActual.Empresa.Funcionalidad(558).ToEntero() = 1 And DdlTipoComprobante.SelectedValue = "Cot") Then + If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") OrElse (UsuarioActual.Empresa.Funcionalidad(558).ToEntero() = 1 And DdlTipoComprobante.SelectedValue = "Cot") OrElse (CveVenta > 0 AndAlso DdlTipoComprobante.SelectedValue = "Cot" AndAlso Not UsuarioActual.CveEmpresa.Contiene(119, 158)) Then DivContado.Visible = True If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then DivTransferencia.Visible = False @@ -21195,6 +21257,12 @@ Partial Class Ventas saldo = TxtTotal.Text.Replace(",", "").ToDouble - abonado 'CVImporteContado.ValueToCompare = (saldo.FormatoNumero(2).ToDouble).ToString() + If (Not UsuarioActual.CveEmpresa.Contiene(119, 158)) AndAlso Me.CveVenta > 0 AndAlso DdlTipoComprobante.SelectedValue = "Cot" AndAlso Not ValidaPagosContado(MostrarAlertas:=False) Then + VerificarBtnFacturarCotizacion(DdlVendedor.SelectedValue.ToEntero(), MostrarGenerarRemision:=False) + + UpFacturar.Update() + End If + CargaGridContado() UpContado.Update() @@ -21202,7 +21270,7 @@ Partial Class Ventas Private Sub RBLPago_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLPago.SelectedIndexChanged LimpiaEscondeContado() End Sub - Private Function ValidaPagosContado() As Boolean + Private Function ValidaPagosContado(Optional MostrarAlertas As Boolean = True) As Boolean Dim Retorno = False Dim AmortizacionNC As Decimal = 0 @@ -21222,7 +21290,10 @@ Partial Class Ventas If UsuarioActual.Empresa.Funcionalidad(558) = "1" AndAlso CveVenta <= 0 AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Ant") Then If Not PermiteCredito AndAlso Not TienePagos AndAlso TxtTotal.Text.ToDecimal > 0 Then - Alert("Es necesario especificar un pago.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("Es necesario especificar un pago.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True Return Retorno End If @@ -21231,7 +21302,10 @@ Partial Class Ventas Dim TotalPago As Decimal = DtPagos.SUM("Importe").ToDecimal() + AmortizacionNC If TotalPago < TxtTotal.Text.ToDecimal Then - Alert("La suma de los pagos debe ser igual al total de la venta.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("La suma de los pagos debe ser igual al total de la venta.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True Return Retorno End If @@ -21242,7 +21316,10 @@ Partial Class Ventas 'SI TIENE SALDO PENDIENTE VALIDA SI TIENE PAGOS If Me.SaldoVenta > 0 Then If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Ant") AndAlso (UsuarioActual.Empresa.Funcionalidad(531) = "1") AndAlso (Not PermiteCredito) AndAlso Not TienePagos And TxtTotal.Text.ToDecimal > 0 Then - Alert("Es necesario especificar un pago.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("Es necesario especificar un pago.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True End If @@ -21252,7 +21329,10 @@ Partial Class Ventas Dim TotalPago As Decimal = DtPagos.SUM("Importe").ToDecimal() + AmortizacionNC If TotalPago < TxtTotal.Text.ToDecimal Then - Alert("La suma de los pagos debe ser igual al total de la venta.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("La suma de los pagos debe ser igual al total de la venta.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True Return Retorno End If @@ -21264,18 +21344,27 @@ Partial Class Ventas Dim TotalNC As Decimal = If((ListaNCDesc IsNot Nothing AndAlso ListaNCDesc.Count > 0) OrElse (ListaNCBonificacion IsNot Nothing AndAlso ListaNCBonificacion.Count > 0), LblTotalAPagar.Text.Trim().ToDecimal(), 0) If TotalNC > 0 Then If (DtPagos.SUM("Importe").ToString().ToDecimal() + AmortizacionNC + Total - TxtCambio.Text.ToDecimal) > TotalNC Then - Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True End If Else If (DtPagos.SUM("Importe").ToString().ToDecimal() + AmortizacionNC + Total - TxtCambio.Text.ToDecimal) > TxtTotal.Text.ToDecimal Then - Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True End If End If Else If (DtPagos.SUM("Importe").ToString().ToDecimal() + AmortizacionNC + Total - TxtCambio.Text.ToDecimal) > TxtTotal.Text.ToDecimal Then - Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + If MostrarAlertas Then + Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + End If + Retorno = True End If End If @@ -28265,7 +28354,9 @@ Partial Class Ventas TxtTotal.Attributes("readonly") = "readonly" RBLPago.Enabled = True - RBLPago.Items(0).Enabled = True + If Me.PermiteCredito Then + RBLPago.Items(0).Enabled = True + End If GvImpuestosLocales2.Enabled = True