diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb
index 9a0fd3c83..b47df49b8 100644
--- a/App_Code/ClsVentas.vb
+++ b/App_Code/ClsVentas.vb
@@ -4256,6 +4256,74 @@ Public Class ClsVentas
#End Region
+
+#Region "P O R C E N T A J E - C O M I S I O N E S"
+ Public Function AddCierreComisionVendedor(CveVendedor As Integer, Mes As Integer, Anio As Integer, PorcentajeComision As Decimal) As Boolean
+ Dim Retorno As Boolean = False
+
+ DataAdapter("PA_Vta_CierreComisionVendedoresAdd", CommandType.StoredProcedure)
+
+ With SqlAdapter.SelectCommand.Parameters
+ .Add("@CveVendedor", SqlDbType.Int).Value = CveVendedor
+ .Add("@Mes", SqlDbType.Int).Value = Mes
+ .Add("@Anio", SqlDbType.Int).Value = Anio
+ .Add("@PorcentajeComision", SqlDbType.Money).Value = PorcentajeComision
+ End With
+
+ Try
+ SqlAdapter.Fill(Data)
+ Retorno = True
+ Catch ex As Exception
+ OnError("Ocurrió un error al agregar cierre de comisión al vendedor.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
+ End Try
+
+ Return Retorno
+ End Function
+ Public Function GetCierreComisionVendedor(CveVendedor As Integer, Mes As Integer, Anio As Integer, CveEmpresa As Integer) As Boolean
+ Dim Retorno As Boolean = False
+
+ DataAdapter("PA_Vta_CierreComisionVendedoresGet", CommandType.StoredProcedure)
+
+ With SqlAdapter.SelectCommand.Parameters
+ .Add("@CveVendedor", SqlDbType.Int).Value = CveVendedor
+ .Add("@Mes", SqlDbType.Int).Value = Mes
+ .Add("@Anio", SqlDbType.Int).Value = Anio
+ .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
+ End With
+
+ Try
+ SqlAdapter.Fill(Data)
+ Retorno = True
+ Catch ex As Exception
+ OnError("Ocurrió un error al agregar cierre de comisión al vendedor.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
+ End Try
+
+ Return Retorno
+ End Function
+
+ Public Function UpdateCierreComisionVendedor(CveVendedor As Integer, Mes As Integer, Anio As Integer, PorcentajeComision As Decimal) As Boolean
+ Dim Retorno As Boolean = False
+
+ DataAdapter("PA_Vta_CierreComisionVendedoresUpdate", CommandType.StoredProcedure)
+
+ With SqlAdapter.SelectCommand.Parameters
+ .Add("@CveVendedor", SqlDbType.Int).Value = CveVendedor
+ .Add("@Mes", SqlDbType.Int).Value = Mes
+ .Add("@Anio", SqlDbType.Int).Value = Anio
+ .Add("@PorcentajeComision", SqlDbType.Money).Value = PorcentajeComision
+ End With
+
+ Try
+ SqlAdapter.Fill(Data)
+ Retorno = True
+ Catch ex As Exception
+ OnError("Ocurrió un error al actualizar el cierre de comisión del vendedor.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
+ End Try
+
+ Return Retorno
+ End Function
+#End Region
+
#Region "IDisposable Support"
diff --git a/Ventas/RepComisiones.aspx b/Ventas/RepComisiones.aspx
index e59ff7aad..2b5127d5f 100644
--- a/Ventas/RepComisiones.aspx
+++ b/Ventas/RepComisiones.aspx
@@ -1,197 +1,256 @@
-<%@ Page Title="SIG | Reporte de Comisiones" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="RepComisiones.aspx.vb" Inherits="Ventas_RepComisiones" %>
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/Ventas/RepComisiones.aspx.vb b/Ventas/RepComisiones.aspx.vb
index a936e0805..6edfa8fbd 100644
--- a/Ventas/RepComisiones.aspx.vb
+++ b/Ventas/RepComisiones.aspx.vb
@@ -18,26 +18,30 @@ Partial Class Ventas_RepComisiones
InicializaValores()
End If
- End Sub
-
-
+ End Sub
+
#Region " INICIALIZA VALORES "
-
+
Private Sub InicializaValores()
txtFechaI.Text = FirstDayOfMonth(Now).ToShortDateString
txtFechaF.Text = Now.LastDayOfMonth.ToShortDateString
+ TxtAnio.Text = Now.Year.ToString()
+ DdlMes.SelectedValueExist(Now.Month)
+
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
DdlVendedor.DataBind()
DdlVendedorAjuste.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
DdlVendedorAjuste.DataBind()
- End Sub
+ DdlVendedorPorcentaje.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
+ DdlVendedorPorcentaje.DataBind()
+ End Sub
+
#End Region
-
-
+
#Region " CARGA DATOS "
Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click
CargaDatos()
@@ -69,10 +73,9 @@ Partial Class Ventas_RepComisiones
BtnPagar.Visible = False
ImgExcel.Visible = False
End If
- End Sub
+ End Sub
#End Region
-
-
+
#Region " GV DATOS "
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
@@ -90,11 +93,10 @@ Partial Class Ventas_RepComisiones
e.Row.FCHyperLink("HLVendedor").NavigateUrl = String.Format("/Ventas/RepComisionesDetalle.aspx?CveVendedor={0}&FI={1}&FF={2}&CveSubProyecto={3}", CveVendedorURL, If(txtFechaI.Text.Trim() = "", "-1", txtFechaI.Text.Trim()), If(txtFechaF.Text.Trim() = "", "-1", txtFechaF.Text.Trim()), DdlSubProyecto.SelectedValue.ToEntero)
End If
- End Sub
-
+ End Sub
+
#End Region
-
-
+
#Region " PAGAR COMISIONES "
Protected Sub BtnPagar_Click(sender As Object, e As EventArgs)
If Not GvDatos.Rows.Count > 0 Then
@@ -153,10 +155,9 @@ Partial Class Ventas_RepComisiones
ObjComisiones.Dispose()
- End Sub
+ End Sub
#End Region
-
-
+
#Region " AJUSTE "
Protected Sub DdlVendedorAjuste_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim ObjComisiones As New ClsEsquemasComisiones
@@ -194,22 +195,75 @@ Partial Class Ventas_RepComisiones
UPDatos.Update()
End If
- End Sub
+ End Sub
#End Region
-
-
-
-
-
-
-
-
+
#Region " EXCEL "
Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
GvDatos.ExportToExcel("ReporteComisiones_" & Now.ToShortDateString)
- End Sub
+ End Sub
#End Region
-
-
-
+
+ Protected Sub BtnGuardarPorcentajeComision_Click(sender As Object, e As EventArgs)
+ Dim CveVendedor As Integer = DdlVendedorPorcentaje.SelectedValue.ToEntero()
+ Dim Mes As Integer = DdlMes.SelectedValue.ToEntero()
+ Dim Anio As Integer = TxtAnio.Text.ToEntero()
+
+ Dim Porcentaje As Decimal = TxtPorcentajeComision.Text.ToDecimal() / 100
+
+ Dim RowCierre As DataRow = Nothing
+ Dim ObjVentas As New ClsVentas
+ Try
+ If ObjVentas.GetCierreComisionVendedor(CveVendedor, Mes, Anio, UsuarioActual.CveEmpresa) AndAlso ObjVentas.DtResultados.Rows.Count > 0 Then
+ RowCierre = ObjVentas.DtResultados.Rows(0)
+ End If
+
+ If RowCierre IsNot Nothing Then
+ If ObjVentas.UpdateCierreComisionVendedor(CveVendedor, Mes, Anio, Porcentaje) Then
+ Alert("El porcentaje de comisiones se guardo correctamente.", TipoMensaje.MsgInformacion)
+ Else
+ Alert("Ocurrió un error al guardar el porcentaje de comisiones.", TipoMensaje.MsgError)
+ End If
+ Else
+ If ObjVentas.AddCierreComisionVendedor(CveVendedor, Mes, Anio, Porcentaje) Then
+ Alert("El porcentaje de comisiones se guardo correctamente.", TipoMensaje.MsgInformacion)
+ Else
+ Alert("Ocurrió un error al guardar el porcentaje de comisiones.", TipoMensaje.MsgError)
+ End If
+ End If
+ Catch ex As Exception
+ OnError("Ocurrió un error al asginar el porcentaje de la comisión", ex)
+ End Try
+
+ ObjVentas.Dispose()
+
+ UpPorcentajeComisiones.Update()
+ End Sub
+ Protected Sub DdlVendedorPorcentaje_SelectedIndexChanged(sender As Object, e As EventArgs)
+ CargaPorcentajeComisiones()
+ End Sub
+ Protected Sub DdlMes_SelectedIndexChanged(sender As Object, e As EventArgs)
+ CargaPorcentajeComisiones()
+ End Sub
+ Protected Sub CargaPorcentajeComisiones()
+ Dim CveVendedor As Integer = DdlVendedorPorcentaje.SelectedValue.ToEntero()
+ Dim Mes As Integer = DdlMes.SelectedValue.ToEntero()
+ Dim Anio As Integer = TxtAnio.Text.ToEntero()
+
+ Dim RowCierre As DataRow = Nothing
+
+ Dim ObjVentas As New ClsVentas
+ If ObjVentas.GetCierreComisionVendedor(CveVendedor, Mes, Anio, UsuarioActual.CveEmpresa) AndAlso ObjVentas.DtResultados.Rows.Count > 0 Then
+ RowCierre = ObjVentas.DtResultados.Rows(0)
+ End If
+ ObjVentas.Dispose()
+
+ If RowCierre IsNot Nothing Then
+ TxtPorcentajeComision.Text = (RowCierre("PorcentajeComision").ToString().ToDecimal() * 100).FormatoNumero(0)
+ Else
+ TxtPorcentajeComision.Text = "0"
+ End If
+
+ UpPorcentajeComisiones.Update()
+ End Sub
End Class