Files
SIG/Ventas/Promociones.aspx.vb
2024-09-17 09:21:35 -07:00

1440 lines
62 KiB
VB.net
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Option Explicit On
Option Strict On
Imports System.Activities.Expressions
Imports System.Data
Imports DocumentFormat.OpenXml.Drawing.Diagrams
Imports Extensiones
Imports iText.StyledXmlParser.Css.Resolve.Shorthand.Impl
Imports Microsoft.Owin.Security.Provider
Imports Telerik.Web.UI
Partial Class Ventas_Promociones
Inherits ClsPaginas
#Region " PROPIEDADES "
Private Property TempDT As DataTable
Get
Return CType(ViewState("TempDT"), DataTable)
End Get
Set(value As DataTable)
ViewState("TempDT") = value
End Set
End Property
Private Property TempDTOrigial As DataTable
Get
Return CType(ViewState("TempDTOrigial"), DataTable)
End Get
Set(value As DataTable)
ViewState("TempDTOrigial") = value
End Set
End Property
Private Property CvePromocion As Integer
Get
Return ViewState("CvePromocion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePromocion") = value
End Set
End Property
Private Property CveConsecutivo As Integer
Get
Return ViewState("CveConsecutivo").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveConsecutivo") = value
End Set
End Property
Private Property DtSubProyectos As DataTable
Get
Return If(IsNothing(ViewState("DtSubProyectos")), Nothing, CType(ViewState("DtSubProyectos"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtSubProyectos") = value
End Set
End Property
Private Property CvePromocionPadre As Integer
Get
If ViewState("CvePromocionPadre") Is Nothing Then
ViewState("CvePromocionPadre") = -1
End If
Return ViewState("CvePromocionPadre").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePromocionPadre") = value
End Set
End Property
Private Property PorMinMasCostoVentaFnc129 As Decimal
Get
If ViewState("PorMinMasCostoVentaFnc129") Is Nothing Then
ViewState("PorMinMasCostoVentaFnc129") = -1
End If
Return ViewState("PorMinMasCostoVentaFnc129").ToString.ToDecimal
End Get
Set(value As Decimal)
ViewState("PorMinMasCostoVentaFnc129") = value
End Set
End Property
'Private Property DTPSUltimoCosto As DataTable
' Get
' If ViewState("DTPSUltimoCosto") Is Nothing Then
' ViewState("DTPSUltimoCosto") = New DataTable
' End If
' Return CType(ViewState("DTPSUltimoCosto"), DataTable)
' End Get
' Set(value As DataTable)
' ViewState("DTPSUltimoCosto") = value
' End Set
'End Property
Private Property PermisoAutorizPromocionPorcentaje As Boolean
Get
If ViewState("PermisoAutorizPromocionPorcentaje") Is Nothing Then
ViewState("PermisoAutorizPromocionPorcentaje") = False
End If
Return Boolean.Parse(ViewState("PermisoAutorizPromocionPorcentaje").ToString)
End Get
Set(value As Boolean)
ViewState("PermisoAutorizPromocionPorcentaje") = value
End Set
End Property
Private Property BloqueadoPromocionPorcentaje As Boolean
Get
If ViewState("BloqueadoPromocionPorcentaje") Is Nothing Then
ViewState("BloqueadoPromocionPorcentaje") = False
End If
Return Boolean.Parse(ViewState("BloqueadoPromocionPorcentaje").ToString)
End Get
Set(value As Boolean)
ViewState("BloqueadoPromocionPorcentaje") = value
End Set
End Property
Private Property EmpresaFnc382 As Boolean
Get
If ViewState("EmpresaFnc382") Is Nothing Then
ViewState("EmpresaFnc382") = False
End If
Return Boolean.Parse(ViewState("EmpresaFnc382").ToString)
End Get
Set(value As Boolean)
ViewState("EmpresaFnc382") = value
End Set
End Property
Private Property EstatusOriginal As Boolean
Get
If ViewState("EstatusOriginal") Is Nothing Then
ViewState("EstatusOriginal") = False
End If
Return Boolean.Parse(ViewState("EstatusOriginal").ToString)
End Get
Set(value As Boolean)
ViewState("EstatusOriginal") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PorMinMasCostoVentaFnc129 = UsuarioActual.Empresa.Funcionalidad(129).ToDecimal
PermisoAutorizPromocionPorcentaje = UsuarioActual.TienePermisoProceso(386)
EmpresaFnc382 = If(UsuarioActual.Empresa.Funcionalidad(382) = "1", True, False) 'Grupo díaz
'EmpresaFnc382 = True ''Para pruebas
CvePromocion = -1
CargaValoresIniciales()
CargaMonedas()
CargaDTUltimoCosto()
If Request("CvePromocion") IsNot Nothing AndAlso Request("CvePromocion").ToString.ToEntero > 0 Then
CvePromocion = Request("CvePromocion").ToString.ToEntero
CargaDatos()
LnkAgrgarPlantillaPS.Visible = False
ValidaPromosiones(False)
If EmpresaFnc382 AndAlso ChkEstatus.Checked = False AndAlso BloqueadoPromocionPorcentaje AndAlso Not PermisoAutorizPromocionPorcentaje Then
ChkEstatus.Enabled = False
End If
Else
ChkEstatus.Enabled = True
ChkEstatus.Checked = True
CreaDT()
End If
CargaGvBitacora()
End If
End Sub
#Region "BITACORA"
Private Sub CargaGvBitacora()
If CvePromocion > 0 Then
divBitacora.Visible = True
Dim ObjGral As New ClsGenerales()
If ObjGral.GetHistorialBitacora(-1, -1, -1, -1, -1, -1, -1, UsuarioActual.CveEmpresa, CvePromocion:=CvePromocion) Then
GvBitacora.DataSource = ObjGral.DtResultados
End If
ObjGral.Dispose()
GvBitacora.DataBind()
UpHistorialModificacion.Update()
Else
divBitacora.Visible = False
End If
End Sub
#End Region
#Region " VALORES INICIALES "
Private Sub CargaValoresIniciales()
Dim ObjPS As New ClsProductosServicios
'CLASIFICACIONES
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion")
DdlClasificacion.DataBind()
If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then
DdlClasificacion.Items.Insert(0, New ListItem("Todos", "-1"))
Else
DdlClasificacion.Items.Insert(0, New ListItem("Seleccione", "-1"))
End If
'CARGA PS
DdlPS.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
If Not DdlPS.UsaWebService AndAlso CType(DdlPS.DataSource, DataTable) Is Nothing Then
DdlPS.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
DdlPS.DataBind()
End If
'CARGA SUBPROYECTOS
DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa)
DdlSubProyecto.DataBind()
DdlSubProyecto.Items.Insert(0, New ListItem("Todos", "-1"))
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
DdlVendedor.DataBind()
DdlVendedor.Items.Insert(0, New ListItem("Todos", "-1"))
'DdlCliente.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa)
'DdlCliente.DataBind()
'DdlCliente.Items.Insert(0, New ListItem("todos", "-1"))
DdlClientes.setEsWebService(True)
TxtFechaI.Text = NowADS().FirstDayOfMonth.ToShortDateString
TxtFechaF.Text = NowADS().LastDayOfMonth.ToShortDateString
If ObjPS.GetMarcas(UsuarioActual.CveEmpresa) Then
DdlMarca.DataSource = ObjPS.DtResultados
End If
ObjPS.Dispose()
DdlMarca.DataBind()
DdlMarca.Items.Insert(0, New ListItem("Todos", "-1"))
If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
GvDatos.Columns(8).Visible = True
DivRin.Visible = True
'Dim ObjGral As New ClsGenerales
'If ObjGral.GetRinTamanios(UsuarioActual.CveEmpresa) Then
' DdlRin.DataSource = ObjGral.DtResultados
'End If
'ObjGral.Dispose()
DdlRin.DataSource = GlobalDTPSRinTamaños(UsuarioActual.CveEmpresa)
DdlRin.DataBind()
DdlRin.Items.Insert(0, New ListItem("Todos", "-1"))
End If
'' si es E acumuladora
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
divDistribuidor.Visible = True
End If
End Sub
Private Sub CreaDT()
TempDT = New DataTable
TempDT.Columns.Add("Estatus", GetType(Integer))
TempDT.Columns.Add("CvePromocionDetalle", GetType(Integer))
TempDT.Columns.Add("CveClasificacion", GetType(Integer))
TempDT.Columns.Add("Clasificacion", GetType(String))
TempDT.Columns.Add("CvePS", GetType(Integer))
TempDT.Columns.Add("CodigoPS", GetType(String))
TempDT.Columns.Add("PUAnterior", GetType(Decimal))
TempDT.Columns.Add("PUPromocion", GetType(Decimal))
TempDT.Columns.Add("CveTipoPromocion", GetType(Integer))
TempDT.Columns.Add("CveRinTamaño", GetType(Integer))
TempDT.Columns.Add("TipoPromocion", GetType(String))
TempDT.Columns.Add("Promocion", GetType(String))
TempDT.Columns.Add("CantidadMinima", GetType(Integer))
TempDT.Columns.Add("RinTamaño", GetType(String))
TempDT.Columns.Add("AplicaRestriccionTexto", GetType(String))
TempDT.Columns.Add("AplicaRestriccion", GetType(Boolean))
TempDT.Columns.Add("HoraInicio", GetType(DateTime))
TempDT.Columns.Add("HoraFin", GetType(DateTime))
TempDT.Columns.Add("AplicaLunes", GetType(Boolean))
TempDT.Columns.Add("AplicaMartes", GetType(Boolean))
TempDT.Columns.Add("AplicaMiercoles", GetType(Boolean))
TempDT.Columns.Add("AplicaJueves", GetType(Boolean))
TempDT.Columns.Add("AplicaViernes", GetType(Boolean))
TempDT.Columns.Add("AplicaSabado", GetType(Boolean))
TempDT.Columns.Add("AplicaDomingo", GetType(Boolean))
TempDT.Columns.Add("IncluyeImpuestos", GetType(Boolean))
TempDT.Columns.Add("UltimoCosto", GetType(Decimal))
TempDT.Columns.Add("CostoPromedio", GetType(Decimal))
TempDTOrigial = TempDT.Copy
'366 Estatus
'367 CvePS
'368 PUPromocion
'369 CveTipoPromocion
'370 Cantidad Minima
'371 AplicaRestriccion
'372 HoraInicio
'373 HoraFin
'374 AplicaLunes
'375 AplicaMartes
'376 AplicaMiercoles
'377 AplicaJueves
'378 AplicaViernes
'379 AplicaSabado
'380 AplicaDomingo
'381 IncluyeImpuestos
End Sub
Private Sub CargaDTUltimoCosto()
If EmpresaFnc382 Then
Dim DTPSUltimoCosto = New DataTable
Dim ObjInv As New ClsInventarios
If ObjInv.GetUltimoCosto(UsuarioActual.CveEmpresa) Then
DTPSUltimoCosto = ObjInv.DtResultados
End If
ObjInv.Dispose()
End If
End Sub
#Region " PS "
Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs)
ChangeDdlProducto()
DdlTipoPromocion.Items.FindByValue("1").Enabled = False
' DdlTipoPromocion.Items.FindByValue("3").Enabled = False
End Sub
Private Sub ChangeDdlProducto()
If UsuarioActual.Empresa.Funcionalidad(105) = "" Then
DdlPS.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltraParametros("", "PSCodigo")
DdlPS.DataBind()
DdlPS.ddl.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
Else
DdlPS.ddlWS.Attributes.Add("data-idClasificacion", DdlClasificacion.SelectedValue)
End If
End Sub
Protected Sub DdlPS_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPS.selectedindexchange
DdlTipoPromocion.Items.FindByValue("1").Enabled = True
DdlTipoPromocion.Items.FindByValue("3").Enabled = True
End Sub
#End Region
#End Region
#Region " CARGA DATOS "
Private Sub CargaDatos()
Dim ObjVentas As New ClsVentas
If ObjVentas.GetPromociones(CvePromocion, "-1", -1, -1, -1, UsuarioActual.CveEmpresa, -1) AndAlso ObjVentas.DtResultados.Rows.Count = 1 Then
Dim Dr As DataRow = ObjVentas.DtResultados.Rows(0)
TxtPromocion.Text = Dr("Promocion").ToString
TxtFechaI.Text = Dr("FechaInicio").ToString.ToDate.ToShortDateString
TxtFechaF.Text = Dr("FechaFin").ToString.ToDate.ToShortDateString
DdlSubProyecto.SelectedValue = Dr("CveSubProyecto").ToString
DdlMarca.SelectedValue = Dr("CveMarca").ToString
If Dr("CveVendedor").ToString.ToEntero > 0 Then DdlVendedor.SelectedValue = Dr("CveVendedor").ToString
If Dr("CveCliente").ToString.ToEntero > 0 Then
If DdlClientes.UsaWebService Then
DdlClientes.txtText.Value = Dr("NombreComercial").ToString
DdlClientes.txtValue.Value = Dr("CveCliente").ToString
Else
DdlClientes.SelectedValue = Dr("CveCliente").ToString
End If
End If
ChkEstatus.Checked = If(Dr("Estatus").ToString = "True", True, False)
EstatusOriginal = ChkEstatus.Checked
DdlMoneda.SelectedValueExist(Dr("CveMoneda").ToString)
DdlMarca.SelectedValueExist(Dr("CveMarca").ToString)
DdlTipoAplicacion.SelectedValueExist(Dr("TipoAplicacion").ToString)
CvePromocionPadre = If(Dr("CvePromocionPadre").ToString.ToEntero > 0, Dr("CvePromocionPadre").ToString.ToEntero, -1)
If ObjVentas.GetPromocionesDetalle(CvePromocion, UsuarioActual.CveEmpresa) Then
TempDT = ObjVentas.DtResultados.Copy
TempDTOrigial = ObjVentas.DtResultados.Copy
CargaGrid()
Else
Alert("Ocurrió un error al consultar los detalles de la promoción. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
Else
Alert("Ocurrió un error al consultar la promoción. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ButBtnEliminar.Visible = True
'If CvePromocionPadre > 0 Then
' BtnGuardar.Enabled = False
' ButBtnEliminar.Enabled = False
'End If
ObjVentas.Dispose()
End Sub
Private Sub CargaGrid()
GvDatos.DataSource = TempDT.FiltraParametros("Estatus <> 2")
GvDatos.DataBind()
UpDatos.Update()
End Sub
Private Sub CargaMonedas()
DdlMoneda.DataSource = GlobalDTMonedas
DdlMoneda.DataBind()
End Sub
#End Region
#Region " AGREGAR "
Protected Sub LbAgregarModal_Click(sender As Object, e As EventArgs)
RegistraScript("$('#DivAgregar').modal('show')")
CveConsecutivo = -1
DdlClasificacion.SelectedValue = "-1"
ChangeDdlProducto()
LbPUActual.Text = ""
LblCostoPromedio.Text = ""
LblUltimoCosto.Text = ""
DdlTipoPromocion.SelectedValue = "-1"
TxtPromocionConcepto.Text = ""
TxtCantMinima.Text = "1"
ChkRestricciones.Checked = False
'DivRestricciones.Visible = False
ChkLunes.Checked = False
ChkMartes.Checked = False
ChkMiercoles.Checked = False
ChkJueves.Checked = False
ChkViernes.Checked = False
ChkSabado.Checked = False
ChkDomingo.Checked = False
BtnAgregar.Text = "Agregar"
UpAgregar.Update()
End Sub
Protected Sub BtnAgregar_Click(sender As Object, e As EventArgs)
If DdlClasificacion.SelectedValue.ToEntero <= 0 Then
If DdlPS.SelectedValue.ToEntero <= 0 Then
Alert("Debe seleccionar una clasificacion o un producto y/o servicio", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
If DdlPS.SelectedValue.ToEntero <= 0 Then
If DdlClasificacion.SelectedValue.ToEntero <= 0 Then
Alert("Debe seleccionar una clasificacion o un producto y/o servicio", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
' validación de %minimo considerado 02580104V
If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then
Dim tuc As Decimal = LblUltimoCosto.Text.ToDecimal
Dim tpu As Decimal = TxtPromocionConcepto.Text.ToDecimal
If (tpu - tuc) / tuc < UsuarioActual.Empresa.Funcionalidad(129).ToDecimal / 100 Then
Alert("El producto está debajo de la utilidad permitida, la promoción requerirá autorización.", TipoMensaje.MsgAdvertencia.ToastAdventencia)
End If
End If
If TxtCantMinima.Text.ToEntero <= 0 Then
Alert("La cantidad minima debe ser de 1", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim Dr As DataRow = Nothing
If CveConsecutivo >= 0 Then
Dr = TempDT.Rows(CveConsecutivo)
Dr("Estatus") = 1
Else
Dr = TempDT.NewRow
Dr("Estatus") = 0
End If
If DdlClasificacion.SelectedValue.ToEntero > 0 Then
Dr("CveClasificacion") = DdlClasificacion.SelectedValue
Dr("Clasificacion") = DdlClasificacion.SelectedItem.Text
Else
If DdlPS.SelectedValue.ToEntero > 0 Then
Dr("CveClasificacion") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimeroValor("CveClasificacion")
Dr("Clasificacion") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimeroValor("Clasificacion")
Else
Dr("CveClasificacion") = -1
Dr("Clasificacion") = "Todas"
End If
End If
Dr("CvePS") = If(DdlPS.SelectedValue = "", "-1", DdlPS.SelectedValue)
Dr("CodigoPS") = If(String.IsNullOrEmpty(DdlPS.SelectedText), "Todos", DdlPS.SelectedText)
Dr("PUAnterior") = LbPUActual.Text.ToDecimal
Dr("UltimoCosto") = LblUltimoCosto.Text.ToDecimal
Dr("CostoPromedio") = LblCostoPromedio.Text.ToDecimal
Dr("CveTipoPromocion") = DdlTipoPromocion.SelectedValue.ToEntero
Dr("TipoPromocion") = DdlTipoPromocion.SelectedItem.Text
Dr("Promocion") = TxtPromocionConcepto.Text
If DdlTipoPromocion.SelectedValue.ToEntero.Contiene(1, 3) Then
Dr("PUPromocion") = TxtPromocionConcepto.Text.ToDecimal
Else
Dr("PUPromocion") = LbPUActual.Text.ToDecimal - (LbPUActual.Text.ToDecimal * TxtPromocionConcepto.Text.ToDecimal / 100)
End If
Dr("CantidadMinima") = TxtCantMinima.Text.ToEntero
If ChkRestricciones.Checked Then
Dr("AplicaRestriccionTexto") = "Si"
Dr("AplicaRestriccion") = True
Dr("HoraInicio") = NowADS().ToShortDateString.ToDate.AddHours(TxtHoraInicio.Text.Trim.Substring(0, 2).ToEntero).AddMinutes(TxtHoraInicio.Text.Trim.Substring(2, 2).ToEntero)
Dr("HoraFin") = NowADS().ToShortDateString.ToDate.AddHours(TxtHoraFin.Text.Trim.Substring(0, 2).ToEntero).AddMinutes(TxtHoraFin.Text.Trim.Substring(2, 2).ToEntero)
Dr("AplicaLunes") = ChkLunes.Checked
Dr("AplicaMartes") = ChkMartes.Checked
Dr("AplicaMiercoles") = ChkMiercoles.Checked
Dr("AplicaJueves") = ChkJueves.Checked
Dr("AplicaViernes") = ChkViernes.Checked
Dr("AplicaSabado") = ChkSabado.Checked
Dr("AplicaDomingo") = ChkDomingo.Checked
Else
Dr("AplicaRestriccionTexto") = "No"
Dr("AplicaRestriccion") = False
Dr("HoraInicio") = MinFecha.ToDateTime
Dr("HoraFin") = MaxFecha.ToDateTime
Dr("AplicaLunes") = False
Dr("AplicaMartes") = False
Dr("AplicaMiercoles") = False
Dr("AplicaJueves") = False
Dr("AplicaViernes") = False
Dr("AplicaSabado") = False
Dr("AplicaDomingo") = False
End If
Dr("IncluyeImpuestos") = ChkIncluyeImpuesto.Checked
If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
Dr("CveRinTamaño") = DdlRin.SelectedValue.ToEntero
Else
Dr("CveRinTamaño") = -1
End If
If CveConsecutivo >= 0 Then
Dr.AcceptChanges()
Else
TempDT.Rows.Add(Dr)
End If
CargaGrid()
RegistraScript("$('#DivAgregar').modal('hide')")
ValidaPromosiones(True)
End Sub
Private Sub ValidaPromosiones(Bloquear As Boolean)
If Not EmpresaFnc382 Then
BloqueadoPromocionPorcentaje = False
Exit Sub
End If
Dim DTPSUltimoCosto = New DataTable
Dim ObjInv As New ClsInventarios
If ObjInv.GetUltimoCosto(UsuarioActual.CveEmpresa) Then
DTPSUltimoCosto = ObjInv.DtResultados
End If
ObjInv.Dispose()
If PorMinMasCostoVentaFnc129 > 0 Then
For Each dRow As DataRow In TempDT.Rows
Dim CvePS As Integer = dRow("CvePS").ToString.ToEntero
Dim UltimoCosto As Decimal = dRow("UltimoCosto").ToString.ToDecimal
Dim CveTipoPromocion As Integer = dRow("CveTipoPromocion").ToString.ToEntero ' 1 importe 2 % descuento
Dim Promocion As Decimal = dRow("Promocion").ToString.ToDecimal
If UltimoCosto = 0 Then
UltimoCosto = DTPSUltimoCosto.FiltroPrimeroValor("UltimoCosto", $"CvePS = {CvePS}").ToDecimal
End If
If CvePS > 0 AndAlso UltimoCosto > 0 AndAlso CveTipoPromocion.Contiene(1, 2) Then
If CveTipoPromocion = 1 Then 'importe
'Sacamos el porcentaje
Dim PorDescuento As Decimal = 100 - ((Promocion * 100) / UltimoCosto)
If PorDescuento > PorMinMasCostoVentaFnc129 Then
BloqueadoPromocionPorcentaje = True
Exit For
End If
ElseIf CveTipoPromocion = 2 Then '% descuento
If Promocion > PorMinMasCostoVentaFnc129 Then
BloqueadoPromocionPorcentaje = True
Exit For
End If
End If
End If
Next
End If
If BloqueadoPromocionPorcentaje AndAlso Bloquear Then
ChkEstatus.Checked = False
ChkEstatus.Enabled = False
End If
UpGenerales.Update()
End Sub
Protected Sub ChkRestricciones_CheckedChanged(sender As Object, e As EventArgs)
DivRestricciones.Visible = ChkRestricciones.Checked
End Sub
Protected Sub BtnGenerarAPartir_Click(sender As Object, e As EventArgs)
CvePromocion = 0
End Sub
#End Region
#Region " GV PS "
Private Sub GvDatos_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GvDatos.RowCommand
If e.CommandName = "Editar" Then
Dim Gvr As GridViewRow = GvDatos.Rows(e.CommandArgument.ToString.ToEntero)
RegistraScript("$('#DivAgregar').modal('show')")
CveConsecutivo = e.CommandArgument.ToString.ToEntero
DdlRin.SelectedValueExist(Gvr.DataKey("CveRinTamaño"))
DdlClasificacion.SelectedValueExist(Gvr.DataKey("CveClasificacion"))
ChangeDdlProducto()
If UsuarioActual.Empresa.Funcionalidad(105) = "" Then
DdlPS.SelectedValue = Gvr.DataKey("CvePS")
Else
DdlPS.SelectedValue = Gvr.DataKey("CvePS")
DdlPS.SelectedText = Gvr.DataKey("CodigoPS")
End If
LbPUActual.Text = Gvr.DataKey("PUAnterior").FormatoNumero
LblUltimoCosto.Text = Gvr.DataKey("UltimoCosto").FormatoNumero
LblCostoPromedio.Text = Gvr.DataKey("CostoPromedio").FormatoNumero
DdlTipoPromocion.SelectedValue = Gvr.DataKey("CveTipoPromocion")
'DdlTipoPromocion_SelectedIndexChanged(sender, Nothing)
TxtPromocionConcepto.Text = Gvr.DataKey("Promocion").FormatoNumero(4)
TxtCantMinima.Text = Gvr.DataKey("CantidadMinima")
TxtHoraInicio.Text = $"{Gvr.DataKey("HoraInicio").ToDate.Hour}:{Gvr.DataKey("HoraInicio").ToDate.Minute}"
TxtHoraFin.Text = $"{Gvr.DataKey("HoraFin").ToDate.Hour}:{Gvr.DataKey("HoraFin").ToDate.Minute}"
ChkRestricciones.Checked = CBool(Gvr.DataKey("AplicaRestriccion"))
DivRestricciones.Visible = CBool(Gvr.DataKey("AplicaRestriccion"))
ChkLunes.Checked = CBool(Gvr.DataKey("AplicaLunes"))
ChkMartes.Checked = CBool(Gvr.DataKey("AplicaMartes"))
ChkMiercoles.Checked = CBool(Gvr.DataKey("AplicaMiercoles"))
ChkJueves.Checked = CBool(Gvr.DataKey("AplicaJueves"))
ChkViernes.Checked = CBool(Gvr.DataKey("AplicaViernes"))
ChkSabado.Checked = CBool(Gvr.DataKey("AplicaSabado"))
ChkDomingo.Checked = CBool(Gvr.DataKey("AplicaDomingo"))
ChkIncluyeImpuesto.Checked = CBool(Gvr.DataKey("IncluyeImpuestos"))
BtnAgregar.Text = "Actualizar"
UpAgregar.Update()
GvDatos.EditIndex = -1
End If
End Sub
Protected Sub GvPS_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
Dim DbRow As DataRow = TempDT.Rows(e.RowIndex)
If CvePromocion > 0 Then
DbRow("Estatus") = 2
Else
TempDT.Rows.Remove(DbRow)
End If
CargaGrid()
End Sub
#End Region
#Region " GUARDAR "
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs)
If CvePromocion > 0 Then
ActualizaPromocion()
Else
GuardaPromocion()
End If
End Sub
Private Sub GuardaPromocion()
ValidaPromosiones(True)
Dim CveCliente As Integer = If(DdlClientes.SelectedValue = "", -1, DdlClientes.SelectedValue.ToEntero)
Dim ObjVentas As New ClsVentas
Dim TieneError As Boolean = False
ObjVentas.IniciaTransacSQL()
CvePromocion = ObjVentas.AddPromociones(TxtPromocion.Text.Trim, If(IsDate(TxtFechaI.Text), TxtFechaI.Text.ToDate, MinFecha), If(IsDate(TxtFechaF.Text), TxtFechaF.Text.ToDate, MaxFecha),
DdlVendedor.SelectedValue.ToEntero, CveCliente, ChkEstatus.Checked, DdlMoneda.SelectedValue.ToEntero, UsuarioActual.CveUsuario,
UsuarioActual.CveEmpresa, DdlSubProyecto.SelectedValue.ToEntero, DdlTipoAplicacion.SelectedValue.ToString, DdlMarca.SelectedValue.ToEntero, DdlDistribuidor.SelectedValue.ToEntero)
If CvePromocion > 0 Then
For Each Dr As DataRow In TempDT.Rows
If Not ObjVentas.AddPromocionesDetalle(CvePromocion, Dr("CvePS").ToString.ToEntero, Dr("CveTipoPromocion").ToString.ToEntero, Dr("Promocion").ToString.ToDouble, Dr("PUAnterior").ToString.ToDouble, Dr("PUPromocion").ToString.ToDouble,
CBool(Dr("AplicaRestriccion")), CBool(Dr("AplicaLunes")), CBool(Dr("AplicaMartes")), CBool(Dr("AplicaMiercoles")), CBool(Dr("AplicaJueves")), CBool(Dr("AplicaViernes")), CBool(Dr("AplicaSabado")), CBool(Dr("AplicaDomingo")),
Dr("HoraInicio").ToString.ToDateTime, Dr("HoraFin").ToString.ToDateTime, Dr("CantidadMinima").ToString.ToEntero,
CveClasificacion:=If(Dr("CvePS").ToString = "", 20, Dr("CveClasificacion").ToString.ToEntero), CveRinTamaño:=Dr("CveRinTamaño").ToString.ToEntero, IncluyeImpuestos:=CBool(Dr("IncluyeImpuestos"))) Then
TieneError = True
Exit For
End If
Next
Else
TieneError = True
End If
If UsuarioActual.Empresa.Funcionalidad(563) <> "" Then
If Not ObjVentas.SincronizarPromocionesClonar(CvePromocion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1) Then
TieneError = True
End If
End If
If Not TieneError Then
ObjVentas.Commit()
Alert("La promoción se guardo correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Ventas/CatPromociones.aspx"";")
Else
ObjVentas.RollBack()
Alert("Ocurrió un error al guardar la promoción. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ObjVentas.Dispose()
If Not TieneError AndAlso BloqueadoPromocionPorcentaje Then
MandaCorreoNotificacionPromocionBloqueo(CvePromocion, TxtPromocion.Text.Trim)
End If
End Sub
Private Sub ActualizaPromocion()
Dim CveCliente As Integer = If(DdlClientes.SelectedValue = "", -1, DdlClientes.SelectedValue.ToEntero)
Dim ObjVentas As New ClsVentas
Dim TieneError As Boolean = False
ObjVentas.IniciaTransacSQL()
Dim ObjGral As New ClsGenerales(ObjVentas.IniciaTransacSQL)
If ObjVentas.UpdatePromociones(TxtPromocion.Text.Trim, If(IsDate(TxtFechaI.Text), TxtFechaI.Text.ToDate, MinFecha), If(IsDate(TxtFechaF.Text), TxtFechaF.Text.ToDate, MaxFecha),
DdlVendedor.SelectedValue.ToEntero, CveCliente, ChkEstatus.Checked, DdlMoneda.SelectedValue.ToEntero, UsuarioActual.CveUsuario,
CvePromocion, DdlSubProyecto.SelectedValue.ToEntero, DdlTipoAplicacion.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, CveMarca:=DdlMarca.SelectedValue.ToEntero, EsDistribuidor:=DdlDistribuidor.SelectedValue.ToEntero) Then
For Each Dr As DataRow In TempDT.FiltraParametros("Estatus = 0").Rows
Dim OpReplicarDetalleFranquicias As Integer = If(UsuarioActual.Empresa.Funcionalidad(563) <> "", 2, 1) ' op 2 Elimina detalles de franquicias
If Not ObjVentas.AddPromocionesDetalle(CvePromocion, Dr("CvePS").ToString.ToEntero, Dr("CveTipoPromocion").ToString.ToEntero, Dr("Promocion").ToString.ToDouble, Dr("PUAnterior").ToString.ToDouble, Dr("PUPromocion").ToString.ToDouble,
CBool(Dr("AplicaRestriccion")), CBool(Dr("AplicaLunes")), CBool(Dr("AplicaMartes")), CBool(Dr("AplicaMiercoles")), CBool(Dr("AplicaJueves")), CBool(Dr("AplicaViernes")), CBool(Dr("AplicaSabado")), CBool(Dr("AplicaDomingo")),
Dr("HoraInicio").ToString.ToDateTime, Dr("HoraFin").ToString.ToDateTime, Dr("CantidadMinima").ToString.ToEntero, CveClasificacion:=If(Dr("CvePS").ToString = "-1", Dr("CveClasificacion").ToString.ToEntero, -1),
CveRinTamaño:=Dr("CveRinTamaño").ToString.ToEntero, IncluyeImpuestos:=CBool(Dr("IncluyeImpuestos")), Opcion:=OpReplicarDetalleFranquicias) Then
TieneError = True
Exit For
End If
If Not TieneError Then
If Not ObjGral.AddHistorialBitacora(364, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, "", Dr("CodigoPS").ToString, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
Next
If Not TieneError Then
For Each Dr As DataRow In TempDT.FiltraParametros("Estatus = 1").Rows
If Not ObjVentas.UpdatePromocionesDetalle(Dr("CvePromocionDetalle").ToString.ToEntero, CvePromocion, Dr("CvePS").ToString.ToEntero, Dr("CveTipoPromocion").ToString.ToEntero, Dr("Promocion").ToString.ToDouble, Dr("PUAnterior").ToString.ToDouble, Dr("PUPromocion").ToString.ToDouble,
CBool(Dr("AplicaRestriccion")), CBool(Dr("AplicaLunes")), CBool(Dr("AplicaMartes")), CBool(Dr("AplicaMiercoles")), CBool(Dr("AplicaJueves")), CBool(Dr("AplicaViernes")), CBool(Dr("AplicaSabado")), CBool(Dr("AplicaDomingo")),
Dr("HoraInicio").ToString.ToDateTime, Dr("HoraFin").ToString.ToDateTime, Dr("CantidadMinima").ToString.ToEntero, CveClasificacion:=If(Dr("CvePS").ToString = "-1", Dr("CveClasificacion").ToString.ToEntero, -1), CveRinTamaño:=Dr("CveRinTamaño").ToString.ToEntero, IncluyeImpuestos:=ChkIncluyeImpuesto.Checked) Then
TieneError = True
Exit For
End If
If Not TieneError Then
Dim Dr2 As DataRow = TempDTOrigial.FiltraParametros($"CvePromocionDetalle = {Dr("CvePromocionDetalle").ToString}").Rows(0)
If Not TieneError And Dr("CvePS").ToString <> Dr2("CvePS").ToString Then
If Not ObjGral.AddHistorialBitacora(367, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Dr("CodigoPS").ToString, Dr2("CodigoPS").ToString, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("CveTipoPromocion").ToString <> Dr2("CveTipoPromocion").ToString Then
If Not ObjGral.AddHistorialBitacora(369, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Dr("TipoPromocion").ToString, $"{Dr("CodigoPS").ToString} - {Dr2("TipoPromocion").ToString}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("CantidadMinima").ToString <> Dr2("CantidadMinima").ToString Then
If Not ObjGral.AddHistorialBitacora(370, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Dr("CantidadMinima").ToString, $"{Dr("CodigoPS").ToString} - {Dr2("CantidadMinima").ToString}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("HoraInicio").ToString <> Dr2("HoraInicio").ToString Then
If Not ObjGral.AddHistorialBitacora(372, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Dr("HoraInicio").ToString, $"{Dr("CodigoPS").ToString} - {Dr2("HoraInicio").ToString}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("HoraFin").ToString <> Dr2("HoraFin").ToString Then
If Not ObjGral.AddHistorialBitacora(373, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Dr("HoraFin").ToString, $"{Dr("CodigoPS").ToString} - {Dr2("HoraFin").ToString}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaLunes").ToString <> Dr2("AplicaLunes").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaLunes").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaLunes").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(374, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaMartes").ToString <> Dr2("AplicaMartes").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaMartes").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaMartes").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(375, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaMiercoles").ToString <> Dr2("AplicaMiercoles").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaMiercoles").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaMiercoles").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(376, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaJueves").ToString <> Dr2("AplicaJueves").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaJueves").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaJueves").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(377, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaViernes").ToString <> Dr2("AplicaViernes").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaViernes").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaViernes").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(378, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaSabado").ToString <> Dr2("AplicaSabado").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaSabado").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaSabado").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(379, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("AplicaDomingo").ToString <> Dr2("AplicaDomingo").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("AplicaDomingo").ToString), "Aplica", "No aplica")
Dim EstadoActual As String = If(Boolean.Parse(Dr("AplicaDomingo").ToString), "Aplica", "No aplica")
If Not ObjGral.AddHistorialBitacora(380, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
If Not TieneError And Dr("IncluyeImpuestos").ToString <> Dr2("IncluyeImpuestos").ToString Then
Dim EstadoAnterior As String = If(Boolean.Parse(Dr2("IncluyeImpuestos").ToString), "Incluye", "No Incluye")
Dim EstadoActual As String = If(Boolean.Parse(Dr("IncluyeImpuestos").ToString), "Incluye", "No Incluye")
If Not ObjGral.AddHistorialBitacora(381, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, EstadoActual, $"{Dr("CodigoPS").ToString} - { EstadoAnterior }", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
End If
Next
End If
If Not TieneError Then
For Each Dr As DataRow In TempDT.FiltraParametros("Estatus = 2").Rows
'RunPromocionesClonar
Dim OpEliminacionDetalle As Integer = If(UsuarioActual.Empresa.Funcionalidad(563) <> "", 2, 1) ' op 2 Elimina detalles de franquicias
If Not ObjVentas.RemovePromocionesDetalle(Dr("CvePromocionDetalle").ToString.ToEntero, OpEliminacionDetalle) Then
TieneError = True
Exit For
End If
If Not TieneError Then
If Not ObjGral.AddHistorialBitacora(365, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, "", Dr("CodigoPS").ToString, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, "Se elimino " & Dr("CodigoPS").ToString, "PS", "", CvePromocion:=CvePromocion) Then
TieneError = True
Exit For
End If
End If
Next
End If
Else
TieneError = True
End If
If EmpresaFnc382 AndAlso EstatusOriginal = False AndAlso ChkEstatus.Checked And BloqueadoPromocionPorcentaje Then
Dim objGeneral As New ClsGenerales(ObjVentas.IniciaTransacSQL)
If Not objGeneral.AddHistorialBitacora(360, -1, -1, -1, -1, -1, -1, -1, "Se Autorizo con bloqueo", "No", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, "", "", "", CvePromocion:=CvePromocion) Then
TieneError = True
End If
End If
If UsuarioActual.Empresa.Funcionalidad(563) <> "" Then
If Not ObjVentas.SincronizarPromocionesClonar(CvePromocion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 2) Then
TieneError = True
End If
End If
If Not TieneError Then
ObjVentas.Commit()
Alert("La promoción se guardo correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Ventas/CatPromociones.aspx"";")
Else
ObjVentas.RollBack()
Alert("Ocurrió un error al guardar la promoción. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ObjVentas.Dispose()
End Sub
#End Region
#Region "ENVIAR CORREO PROMOSION BLOQUEADA"
Private Sub MandaCorreoNotificacionPromocionBloqueo(CvePromocionNueva As Integer, PromocionNueva As String)
Dim Asunto, Para, ArrayCC, Body, URL As String
Asunto = $"Promoción {PromocionNueva} requiere autorización"
Para = ""
ArrayCC = ""
URL = ""
If Request.Url.Port = 80 Then
URL = $"{Request.Url.Scheme}://{Request.Url.Host}{Request.Url.AbsolutePath}?CvePromocion={CvePromocionNueva}"
Else
URL = $"{Request.Url.Scheme}://{Request.Url.Host}:{Request.Url.Port}{Request.Url.AbsolutePath}?CvePromocion={CvePromocionNueva}"
End If
Body = $"Se a registrado promoción que requiere autorización <a href='{URL}' >{PromocionNueva}</a>"
Dim objUsu As New ClsSisUsuarios
Dim ListaCorreos As New List(Of String)
If objUsu.GetPermisosPorUsuarioProcesos(-1, -1, -1, -1, 386, CveEmpresa:=UsuarioActual.CveEmpresa) Then
For Each dRow As DataRow In objUsu.DtResultados.Rows
If dRow("Correo").ToString.Trim.Length > 0 Then
ListaCorreos.Add(dRow("Correo").ToString)
End If
Next
End If
objUsu.Dispose()
If ListaCorreos.Count > 0 Then
Para = String.Join(";", ListaCorreos)
Dim Mail As New ClsSisMail()
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC, LSRutasMail)
End If
End Sub
#End Region
#Region " ELIMINAR "
Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs)
Dim ObjVentas As New ClsVentas
ObjVentas.IniciaTransacSQL()
Dim TieneError As Boolean = False
If UsuarioActual.Empresa.Funcionalidad(563) <> "" Then
If Not ObjVentas.SincronizarPromocionesClonar(CvePromocion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) Then
TieneError = True
End If
End If
If Not TieneError Then
If ObjVentas.RemovePromocionesDetalle(-1, 3, CvePromocion) Then
If Not ObjVentas.RemovePromociones(CvePromocion, UsuarioActual.CveEmpresa) Then
TieneError = True
End If
Else
TieneError = True
End If
End If
If Not TieneError Then
ObjVentas.Commit()
Alert("La promoción se elimino correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Ventas/CatPromociones.aspx"";")
Else
ObjVentas.RollBack()
Alert("Ocurrió un error al registrar la promoción. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
If UsuarioActual.Empresa.Funcionalidad(563) <> "" AndAlso TieneError Then
If ObjVentas.SincronizarPromocionesClonar(CvePromocion, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) Then
Alert("Se presento un error al eliminar, se desactivo kla promoción actual y promociones relacionadas", TipoMensaje.MsgAdvertencia, $"document.location.href=""/Ventas/Promociones.aspx?CvePromocion={CvePromocion}"";")
End If
End If
ObjVentas.Dispose()
End Sub
#End Region
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If CvePromocionPadre > 0 Then
e.Row.FCLinkButton("LnkGvDetalleEditar").Visible = False
e.Row.FCLinkButton("LnkGvDetalleEliminar").Visible = False
End If
End If
End Sub
Protected Sub LnkAgrgarPlantillaPS_Click(sender As Object, e As EventArgs)
TxtExcel.Text = "[]"
UpAgregarPlantilla.Update()
RegistraScript("$('#DivAgregarPlantilla').modal('show');")
End Sub
Protected Sub LnkDecargaPlatilla_Click(sender As Object, e As EventArgs)
Dim rutaArchivoPlantilla As String = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\CargaPromociones.xlsx"
Dim nombreArchivo As String = "CargaPromociones.xlsx"
' Configurar la respuesta HTTP
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & nombreArchivo)
Dim contenido As Byte() = System.IO.File.ReadAllBytes(rutaArchivoPlantilla)
Response.BinaryWrite(contenido)
Response.Flush()
Response.End()
End Sub
Protected Sub BrnAgregarPlantilla_Click(sender As Object, e As EventArgs)
If TxtExcel.getfiles().Archivos.Count > 0 Then
Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
Dim Directorio As String = Server.MapPath("~") & file.path
Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV")
CargarArchivo(Directorio, file.filename, Tipo)
Else
Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError)
End If
End Sub
Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String)
TempDT.Clear()
CveConsecutivo = TempDT.Rows.Count + 1
Dim ProcesoOK As Boolean = False
Dim DTPlantilla As New DataTable
Dim ErrorArchivo As Boolean = False
Dim ErrorExcel As Boolean = False
DTPlantilla = ReadExcelFile(Ruta + FileName, True)
'Alert(DT.Rows.Count.ToString)
If DTPlantilla.Rows.Count = 0 Then
Alert("No encontraron registros.")
Exit Sub
End If
If Not ValidaDTPlantilla(DTPlantilla) Then
Exit Sub
End If
For Each dRowTemplate As DataRow In DTPlantilla.Rows
'Clasificacion Codigo TipoPromocion Promocion CantidadMinima Rin IncluyeImpuestos
Dim CveClasificacion As Integer = dRowTemplate("CveClasificacion").ToString.ToEntero
Dim CvePS As Integer = dRowTemplate("CvePS").ToString.ToEntero
Dim CveTipoPromosicion As Integer = dRowTemplate("CveTipoPromosicion").ToString.ToEntero
Dim Promocion As Decimal = dRowTemplate("Promocion").ToString.ToDecimal
Dim CantidadMinima As Decimal = dRowTemplate("CantidadMinima").ToString.ToDecimal
Dim CveRin As Integer = dRowTemplate("CveRin").ToString.ToEntero
Dim IncluyeImpuestos As Boolean = Boolean.Parse(dRowTemplate("IncluyeImpuestos").ToString)
Dim Dr As DataRow = TempDT.NewRow
Dr = TempDT.NewRow
Dr("Estatus") = 0
If CveClasificacion > 0 Then
Dr("CveClasificacion") = CveClasificacion
Dr("Clasificacion") = dRowTemplate("Clasificacion").ToString
Dr("CvePS") = -1
Else
Dr("CveClasificacion") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("CveClasificacion")
Dr("Clasificacion") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("Clasificacion")
Dr("CvePS") = CvePS
End If
Dr("CodigoPS") = dRowTemplate("CodigoPS").ToString
Dr("PUAnterior") = 0
Dr("CveTipoPromocion") = CveTipoPromosicion
Dr("TipoPromocion") = dRowTemplate("TipoPromocion").ToString
Dr("Promocion") = Promocion
Dr("PUPromocion") = Promocion
Dr("CantidadMinima") = CantidadMinima
Dr("AplicaRestriccionTexto") = "No"
Dr("AplicaRestriccion") = False
Dr("HoraInicio") = MinFecha.ToDateTime
Dr("HoraFin") = MaxFecha.ToDateTime
Dr("AplicaLunes") = False
Dr("AplicaMartes") = False
Dr("AplicaMiercoles") = False
Dr("AplicaJueves") = False
Dr("AplicaViernes") = False
Dr("AplicaSabado") = False
Dr("AplicaDomingo") = False
Dr("IncluyeImpuestos") = IncluyeImpuestos
If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
Dr("CveRinTamaño") = CveRin
Dr("RinTamaño") = dRowTemplate("RinTamaño").ToString
Else
Dr("CveRinTamaño") = -1
End If
TempDT.Rows.Add(Dr)
Next
CargaGrid()
RegistraScript("$('#DivAgregarPlantilla').modal('hide')")
End Sub
Private Function ValidaDTPlantilla(ByRef DTPlantilla As DataTable) As Boolean
Dim Errores As New StringBuilder
DTPlantilla.Columns.Add("CveClasificacion", GetType(Integer))
DTPlantilla.Columns.Add("CvePS", GetType(Integer))
DTPlantilla.Columns.Add("CveTipoPromosicion", GetType(Integer))
'DTPlantilla.Columns.Add("Promocion", GetType(Decimal))
'DTPlantilla.Columns.Add("CantidadMinima", GetType(Decimal))
DTPlantilla.Columns.Add("CveRin", GetType(Integer))
'DTPlantilla.Columns.Add("IncluyeImpuestos", GetType(Boolean))
DTPlantilla.Columns.Add("CodigoPS", GetType(String))
DTPlantilla.Columns.Add("RinTamaño", GetType(String))
Dim DTPS As DataTable = New DataTable
Dim DTRines As DataTable = New DataTable
Dim ObjPS As New ClsProductosServicios
If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then
DTPS = ObjPS.DtResultados
End If
ObjPS.Dispose()
DTRines = GlobalDTPSRinTamaños(UsuarioActual.CveEmpresa)
Dim RegistroActual As Integer = 1
For Each dRow As DataRow In DTPlantilla.Rows
Dim SBErrorRegistro As New StringBuilder
Dim ClasificacionStr, CodigoStr, TipoPromocionStr, PromocionStr, CantidadMinimaStr, RinStr, IncluyeImpuestosStr As String
ClasificacionStr = dRow("Clasificacion").ToString.Trim
CodigoStr = dRow("Codigo").ToString.Trim
TipoPromocionStr = dRow("TipoPromocion").ToString.Trim
PromocionStr = dRow("Promocion").ToString.Trim
CantidadMinimaStr = dRow("CantidadMinima").ToString.Trim
RinStr = dRow("Rin").ToString.Trim
IncluyeImpuestosStr = dRow("IncluyeImpuestos").ToString.Trim
If ClasificacionStr.Length > 0 Or CodigoStr.Length > 0 Then
Dim CveClasificacion As Integer = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{ClasificacionStr}'").ToString().ToEntero()
Dim CvePS As Integer = DTPS.FiltroPrimeroValor("CvePS", $"Codigo = '{CodigoStr}'").ToString().ToEntero()
Dim CodigoPS As String = DTPS.FiltroPrimeroValor("PSCodigo", $"Codigo = '{CodigoStr}'").ToString()
Dim CveTipoPromocion As Integer = -1
Dim Promocion As Decimal = PromocionStr.ToDecimal
Dim CantidadMinima As Decimal = CantidadMinimaStr.ToDecimal
Dim CveRin As Integer = If(RinStr <> "", DTRines.FiltroPrimeroValor("CveRinTamaño", $"Codigo = '{RinStr}'").ToString.ToEntero(), -1)
Dim RinTamaño As String = If(RinStr <> "", DTRines.FiltroPrimeroValor("RinTamaño", $"Codigo = '{RinStr}'").ToString(), "")
Dim IncluyeImpuestos As Boolean = If(IncluyeImpuestosStr.ToUpper.Contiene("SÍ", "SI", "1"), True, False)
' SBErrorRegistro.Append($"")
If ClasificacionStr.Length > 0 And CodigoStr.Length > 0 Then
SBErrorRegistro.Append($"No se puede agregar Clasificación y codigo en un mismo registro. ")
Else
If ClasificacionStr.Length > 0 Then
SBErrorRegistro.Append(If(CveClasificacion > 0, "", $"No se encontro Clasificación '{ClasificacionStr}'. </br>"))
Else
SBErrorRegistro.Append(If(CvePS > 0, "", $"No se encontro código de Producto/Servicio '{CodigoStr }'. </br>"))
End If
End If
If TipoPromocionStr.Trim.ToUpper.Contiene("IMPORTE $", "IMPORTE") Then
CveTipoPromocion = 1
ElseIf TipoPromocionStr.Trim.ToUpper.Contiene("DESCUENTO %", "DESCUENTO") Then
CveTipoPromocion = 2
ElseIf TipoPromocionStr.Trim.ToUpper = "CANTIDAD" Then
CveTipoPromocion = 3
Else
SBErrorRegistro.Append($"Tipo Promoción no encontrada '{TipoPromocionStr}'. </br>")
End If
If Not Promocion > 0 Then
SBErrorRegistro.Append($"La Promoción debe de ser mayor a 0. </br>")
End If
If CantidadMinimaStr.Length > 0 And Not CantidadMinima > 0 Then
SBErrorRegistro.Append($"La Cantidad Mínima debe de ser mayor a 0. </br>")
End If
If RinStr.Length > 0 And Not CveRin > 0 Then
SBErrorRegistro.Append($"Tamaño de Rin no encontrado '{RinStr}'. </br>")
End If
If Not IncluyeImpuestosStr.ToUpper.Contiene("´SÍ", "SI", "1", "NO", "0") Then
SBErrorRegistro.Append($"Campo IncluyeImpuestos no válido '{IncluyeImpuestosStr}'.<br/> ")
End If
If SBErrorRegistro.ToString.Length > 0 Then
Errores.AppendLine($"Registro {RegistroActual}, {SBErrorRegistro.ToString}")
Else
dRow("CveClasificacion") = CveClasificacion
dRow("CvePS") = CvePS
dRow("CveTipoPromosicion") = CveTipoPromocion
dRow("Promocion") = Promocion
dRow("CantidadMinima") = CantidadMinima
dRow("RinTamaño") = RinTamaño
dRow("CveRin") = CveRin
dRow("IncluyeImpuestos") = IncluyeImpuestos
dRow("CodigoPS") = If(CveClasificacion > 0, "Todos", CodigoPS)
End If
End If
RegistroActual = RegistroActual + 1
Next
If Errores.ToString.Length = 0 Then
DTPlantilla.AcceptChanges()
Return True
Else
Alert(Errores.ToString, TipoMensaje.MsgAdvertencia)
Return False
End If
End Function
Protected Sub DdlPS_selectedindexchange(sender As Object, e As EventArgs)
Dim DTPSUltimoCosto = New DataTable
Dim ObjInv As New ClsInventarios
If ObjInv.GetUltimoCosto(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero) Then
DTPSUltimoCosto = ObjInv.DtResultados
End If
ObjInv.Dispose()
LblUltimoCosto.Text = DTPSUltimoCosto.FiltroPrimeroValor("UltimoCosto", "").FormatoNumero(4)
LblCostoPromedio.Text = DTPSUltimoCosto.FiltroPrimeroValor("CostoPromedio", "").FormatoNumero(4)
UpAgregar.Update()
End Sub
End Class