Commit inicial Ventas Productivo
This commit is contained in:
215
Ventas/RepComisiones.aspx.vb
Normal file
215
Ventas/RepComisiones.aspx.vb
Normal file
@@ -0,0 +1,215 @@
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports Extensiones
|
||||
Imports System.Data
|
||||
|
||||
Partial Class Ventas_RepComisiones
|
||||
Inherits ClsPaginas
|
||||
|
||||
#Region "Propiedades"
|
||||
|
||||
#End Region
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||
If Not IsPostBack Then
|
||||
DdlSubProyecto.DataSource = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa)
|
||||
DdlSubProyecto.DataBind()
|
||||
|
||||
InicializaValores()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
#Region " INICIALIZA VALORES "
|
||||
|
||||
Private Sub InicializaValores()
|
||||
txtFechaI.Text = FirstDayOfMonth(Now).ToShortDateString
|
||||
txtFechaF.Text = Now.LastDayOfMonth.ToShortDateString
|
||||
|
||||
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
|
||||
DdlVendedor.DataBind()
|
||||
|
||||
DdlVendedorAjuste.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
|
||||
DdlVendedorAjuste.DataBind()
|
||||
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
#Region " CARGA DATOS "
|
||||
Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click
|
||||
CargaDatos()
|
||||
UPDatos.Update()
|
||||
End Sub
|
||||
|
||||
Private Sub CargaDatos()
|
||||
Dim ObjComisiones As New ClsEsquemasComisiones()
|
||||
|
||||
Dim FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim().ToDate, MinFecha)
|
||||
Dim FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim().ToDate, MaxFecha)
|
||||
|
||||
If ObjComisiones.GetRepComisiones(DdlVendedor.SelectedValue.ToEntero, FechaI, FechaF, DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
||||
GvDatos.DataSource = ObjComisiones.DtResultados
|
||||
If ObjComisiones.DtResultados.SUM("ImporteAjuste") <> 0 Then
|
||||
GvDatos.Columns(5).Visible = True
|
||||
End If
|
||||
Else
|
||||
GvDatos.DataSource = Nothing
|
||||
End If
|
||||
ObjComisiones.Dispose()
|
||||
|
||||
GvDatos.DataBind()
|
||||
|
||||
If GvDatos.Rows.Count > 0 Then
|
||||
BtnPagar.Visible = True
|
||||
ImgExcel.Visible = True
|
||||
Else
|
||||
BtnPagar.Visible = False
|
||||
ImgExcel.Visible = False
|
||||
End If
|
||||
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
|
||||
|
||||
Dim CveVendedorURL = DdlVendedor.SelectedValue.ToEntero
|
||||
|
||||
If e.Row.DBCampo("CveVendedor") = "" Then
|
||||
e.Row.FCHyperLink("HLVendedor").Text = "Total"
|
||||
e.Row.CssClass = "SubTotales"
|
||||
e.Row.Attributes.Add("style", "background:#CCCCCC !important")
|
||||
Else
|
||||
CveVendedorURL = e.Row.DBCampo("CveVendedor").ToEntero
|
||||
End If
|
||||
|
||||
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 Region
|
||||
|
||||
|
||||
#Region " PAGAR COMISIONES "
|
||||
Protected Sub BtnPagar_Click(sender As Object, e As EventArgs)
|
||||
If Not GvDatos.Rows.Count > 0 Then
|
||||
Alert("No se encuentra ninguna comision por pagar.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim ObjComisiones As New ClsEsquemasComisiones
|
||||
ObjComisiones.IniciaTransacSQL()
|
||||
Dim TieneError = False
|
||||
|
||||
For Each Gvr As GridViewRow In GvDatos.Rows
|
||||
If Gvr.DataKey("CveVendedor").ToString.ToEntero > 0 Then
|
||||
|
||||
If ObjComisiones.GetComisionesPagadas(Gvr.DataKey("Comision").ToString.ToDouble,
|
||||
Gvr.DataKey("CveVendedor").ToString.ToEntero,
|
||||
Gvr.DataKey("FechaI").ToString.ToDate,
|
||||
Gvr.DataKey("FechaF").ToString.ToDate,
|
||||
UsuarioActual.CveEmpresa) Then
|
||||
|
||||
For Each Dr As DataRow In ObjComisiones.DtResultados.Rows
|
||||
If Not ObjComisiones.AddComisionesPagadas(Dr("CveVenta").ToString.ToEntero,
|
||||
Dr("CveVendedor").ToString.ToEntero,
|
||||
Dr("ImporteVenta").ToString.ToDouble,
|
||||
Dr("CostoVenta").ToString.ToDouble,
|
||||
Dr("UtilidadVenta").ToString.ToDouble,
|
||||
Dr("TipoComision").ToString.ToEntero,
|
||||
Dr("ComisionPorcentaje").ToString.ToDouble,
|
||||
Dr("ComisionImporte").ToString.ToDouble,
|
||||
Dr("ImporteAjuste").ToString.ToDouble,
|
||||
UsuarioActual.CveUsuario) Then
|
||||
TieneError = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If TieneError Then
|
||||
Exit For
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
Next
|
||||
|
||||
|
||||
If Not TieneError Then
|
||||
ObjComisiones.Commit()
|
||||
Alert("Las comisiones se registraron correctamente.", TipoMensaje.MsgInformacion)
|
||||
CargaDatos()
|
||||
UPDatos.Update()
|
||||
Else
|
||||
ObjComisiones.RollBack()
|
||||
Alert("Ocurrió un error al registrar las comisiones. Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
ObjComisiones.Dispose()
|
||||
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
|
||||
#Region " AJUSTE "
|
||||
Protected Sub DdlVendedorAjuste_SelectedIndexChanged(sender As Object, e As EventArgs)
|
||||
Dim ObjComisiones As New ClsEsquemasComisiones
|
||||
|
||||
If ObjComisiones.GetAjusteComisiones(DdlVendedorAjuste.SelectedValue.ToEntero) Then
|
||||
If ObjComisiones.DtResultados.Rows.Count = 1 Then
|
||||
TxtImporteAjuste.Text = ObjComisiones.DtResultados.Rows(0)("Importe").ToString.FormatoNumero
|
||||
UpAjuste.Update()
|
||||
End If
|
||||
Else
|
||||
Alert("Ocurrió un error al obtener el ajuste de comisiones del vendedor. Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
ObjComisiones.Dispose()
|
||||
End Sub
|
||||
Protected Sub BtnGuardarAjuste_Click(sender As Object, e As EventArgs)
|
||||
Dim ObjComisiones As New ClsEsquemasComisiones
|
||||
Dim TieneError = False
|
||||
|
||||
If ObjComisiones.AddUpdateAjusteComisiones(DdlVendedorAjuste.SelectedValue.ToEntero, TxtImporteAjuste.Text.ToDecimal) Then
|
||||
Alert("El ajuste de comisiones se guardo correctamente.", TipoMensaje.MsgInformacion)
|
||||
Else
|
||||
Alert("Ocurrió un error al guardar el ajuste de comisiones. Por favor vuelva a intentar", TipoMensaje.MsgError)
|
||||
TieneError = True
|
||||
End If
|
||||
|
||||
ObjComisiones.Dispose()
|
||||
|
||||
If Not TieneError Then
|
||||
DdlVendedorAjuste.SelectedValue = "-1"
|
||||
TxtImporteAjuste.Text = "0"
|
||||
RegistraScript("$('#Modal').modal('hide');")
|
||||
UpAjuste.Update()
|
||||
CargaDatos()
|
||||
UPDatos.Update()
|
||||
End If
|
||||
|
||||
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 Region
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user