Files
SIG/Ventas/RepVentas.aspx.vb2
JORGE LUIS CAUDILLO ESPARZA c35cf91883 Commit inicial Ventas Productivo
2019-08-14 16:40:54 -07:00

381 lines
19 KiB
Plaintext
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.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Partial Class Ventas_RepVentas
Inherits ClsPaginas
#Region "Propiedades"
Private Property Opcion As String
Get
Return ViewState("Opcion").ToString
End Get
Set(value As String)
ViewState("Opcion") = value
End Set
End Property
Private Property CveProyecto As Integer
Get
Return ViewState("CveProyecto").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveProyecto") = value
End Set
End Property
Private Property TipoCambio As Integer
Get
Return ViewState("TipoCambio").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("TipoCambio") = value
End Set
End Property
Private Property TCEspecifico As Decimal
Get
Return ViewState("TCEspecifico").ToString.ToDecimal
End Get
Set(value As Decimal)
ViewState("TCEspecifico") = value
End Set
End Property
Private Property DtVentas As DataTable
Get
Return DirectCast(ViewState("DtVentas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtVentas") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
TipoCambio = 1
TCEspecifico = -1
If UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario.Contiene(77, 21) Then Response.Redirect("/Inicio.aspx")
CargaCombos()
'MODALIDADES
If Request("Op") IsNot Nothing AndAlso Request("Op").ToString <> "" Then
Opcion = Request("Op").ToString
Else
Opcion = "-1"
End If
If UsuarioActual.CveEmpresa = 72 AndAlso UsuarioActual.CveUsuario.Contiene(100, 1614, 1517) Then
liRepHP.Visible = True
End If
'Modalidad Cotizacion
If Opcion = "Cot" Then
DdlTipoComprobante.SelectedValueExist(Opcion)
DdlGrupo.SelectedValueExist("7")
DdlTipoComprobante_SelectedIndexChanged(DdlTipoComprobante, EventArgs.Empty)
DdlEstatus.SelectedValue = "-1"
End If
End If
End Sub
#Region " CARGA COMBOS "
Private Sub ConfiguraEmpresa()
If Not UsuarioActual.Empresa.MostrarRetIVA Then GvDatos.Columns(6).Visible = False
If Not UsuarioActual.Empresa.MostrarRetISR Then GvDatos.Columns(7).Visible = False
End Sub
Private Sub CargaCombos()
'CargaClientes
Dim ObjClientes As New ClsClientes
If ObjClientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then
DdlClientes.DataSource = ObjClientes.DtResultados
Else
DdlClientes.DataSource = Nothing
End If
ObjClientes.Dispose()
DdlClientes.DataBind()
'CargaSucursales
DdlSucursal.DataSource = GlobalDTSucursales.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
DdlSucursal.DataBind()
DdlSucursalEjec.DataSource = GlobalDTSucursales.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
DdlSucursalEjec.DataBind()
'Vendedor
DdlVendedor.DataSource = GlobalDTVendedores(UsuarioActual.CveEmpresa)
DdlVendedor.DataBind()
DdlVendedor.Items.Insert(0, New ListItem("Todos", "-1"))
'CargaUsuarios
DdlUsuario.DataSource = GlobalDTUsuarios.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
DdlUsuario.DataBind()
'CargaEstatus
DdlEstatus.DataSource = GlobalDTEstatusFactura.FiltraParametros(" CveEstatusFactura NOT IN (1, 4, 5) ")
DdlEstatus.DataBind()
DdlEstatus.Items.Add(New ListItem("Canceladas", "4"))
If UsuarioActual.Empresa.TipoFacturacion = "CFDi" Then
DdlEstatus.SelectedIndex = 2
Else
DdlEstatus.SelectedIndex = 1
End If
'CargaProyectos
DdlProyecto.DataSource = GlobalDTProyectos(UsuarioActual.Empresa.CveEmpresa)
DdlProyecto.DataBind()
DdlProyecto.Items.Insert(0, New ListItem("Todos", "-1"))
'CargaProyectos
End Sub
Protected Sub DdlProyecto_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlProyecto.SelectedIndexChanged
CargaSubProyecto()
End Sub
Private Sub CargaSubProyecto()
DdlSubProyecto.Items.Clear()
DdlSubProyecto.DataSource = GlobalDTSubProyectos(DdlProyecto.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa)
DdlSubProyecto.DataBind()
DdlSubProyecto.Items.Insert(0, New ListItem("Todos", "-1"))
''dsadasd
End Sub
Protected Sub DdlTipoComprobante_SelectedIndexChanged(sender As Object, e As EventArgs)
DdlEstatus.Items.Clear()
If DdlTipoComprobante.SelectedValue <> "-1" Then
DdlEstatus.DataSource = GlobalDTEstatusFactura.FiltraParametros(String.Format("TipoDocto = '{0}'", DdlTipoComprobante.SelectedValue))
Else
DdlEstatus.DataSource = GlobalDTEstatusFactura
End If
DdlEstatus.Items.Add(New ListItem("Todos", "-1"))
DdlEstatus.DataBind()
End Sub
#End Region
#Region " CARGA DATOS "
Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click
CargaDatos()
ConfiguraEmpresa()
UPDatos.Update()
End Sub
Private Sub CargaDatos()
Dim ObjVentas As New ClsVentas()
If RblTipoCambio.SelectedValue.ToEntero = 3 And TxtEspecifico.Text <> "" Then
TCEspecifico = TxtEspecifico.Text.ToDecimal
Else
TCEspecifico = -1
End If
Dim FechaI, FechaF, FechaIEjec, FechaFEjec As String
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1")
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1")
FechaIEjec = If(IsDate(TxtFechaIEjec.Text.Trim()), TxtFechaIEjec.Text.Trim(), "-1")
FechaFEjec = If(IsDate(TxtFechaFEjec.Text.Trim()), TxtFechaFEjec.Text.Trim(), "-1")
If ObjVentas.GetRepVentas(FechaI, FechaF, FechaIEjec, FechaFEjec, DdlClientes.SelectedValue.ToEntero, DdlSucursal.SelectedValue.ToEntero, DdlSucursalEjec.SelectedValue.ToEntero, DdlVendedor.SelectedValue.ToEntero,
DdlUsuario.SelectedValue.ToEntero, DdlEstatus.SelectedValue.ToEntero, "-1", UsuarioActual.CveEmpresa, DdlGrupo.SelectedValue.ToEntero, DdlTipoComprobante.SelectedValue, DdlProyecto.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, RblTipoCambio.SelectedValue.ToEntero, TCEspecifico) Then
GvDatos.DataSource = ObjVentas.DtResultados
DtVentas = ObjVentas.DtResultados
Else
GvDatos.DataSource = Nothing
End If
CveProyecto = DdlProyecto.SelectedValue.ToEntero
ObjVentas.Dispose()
GvDatos.DataBind()
End Sub
#End Region
#Region " GV DATOS - ROW DATABOUND "
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 Css As String = "Texto"
' CABECERA TOTAL
If e.Row.DBCampo("Orden") = "" Then
e.Row.CssClass = "Totales"
e.Row.Cells(2).BackColor = Drawing.Color.Transparent
e.Row.Cells(6).BackColor = Drawing.Color.Transparent
End If
If e.Row.DBCampo("GPO") = "Total Dólares" Then
e.Row.CssClass = "Totales"
End If
' PARA LIGA
Dim FechaI, FechaF, FechaIEjec, FechaFEjec As String
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1")
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1")
FechaIEjec = If(IsDate(TxtFechaIEjec.Text.Trim()), TxtFechaIEjec.Text.Trim(), "-1")
FechaFEjec = If(IsDate(TxtFechaFEjec.Text.Trim()), TxtFechaFEjec.Text.Trim(), "-1")
Dim CveMoneda As Integer = -1
If TipoCambio = 1 Then
CveMoneda = e.Row.DBCampo("CveMoneda").ToString.ToEntero
End If
'LIGA A DETALLE
Dim Liga As String = $"/Ventas/RepVentaDetalle.aspx?GPO={DdlGrupo.SelectedValue}&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&AnioEjec={e.Row.DBCampo("AnioEjec")}&MesEjec={e.Row.DBCampo("MesEjec")}&AnioMesEjec={e.Row.DBCampo("AnioMesEjec")}&FechaEjec={e.Row.DBCampo("FechaEjec")}&CveCliente={e.Row.DBCampo("CveCliente")}&CveSucursal={e.Row.DBCampo("CveSucursal")}&CveVendedor={ e.Row.DBCampo("CveVendedor")}&CveUsuario={e.Row.DBCampo("CveUsuario")}&CveEstatusFactura={e.Row.DBCampo("CveEstatusFactura")}&FechaI={FechaI}&FechaF={FechaF}&FechaIEjec={FechaIEjec}&FechaFEjec={FechaFEjec}&IVA={e.Row.DBCampo("GPO_IVA")}&CveCorte={ e.Row.DBCampo("CveCorte")}&TipoDocto={ DdlTipoComprobante.SelectedValue}&CveSucursalEjec={e.Row.DBCampo("CveSucursalEjec")}&CveSubProyecto={e.Row.DBCampo("CveSubProyecto")}&CveProyecto={e.Row.DBCampo("CveProyecto")}&TipoCambio={TipoCambio}&TCEspecifico={TCEspecifico}&CveMoneda={CveMoneda}"
e.Row.FCLiteral("LtlGrupo").Text = "<a class=""" & Css & """ href=""" & Liga & """>" & e.Row.FCLiteral("LtlGrupo").Text & "</a>"
e.Row.FCLiteral("LtlCantidad").Text = "<a class=""" & Css & """ href=""" & Liga & """>" & e.Row.FCLiteral("LtlCantidad").Text & "</a>"
If DdlGrupo.SelectedValue.ToEntero > 16 AndAlso e.Row.DBCampo("Orden") = "2" Then
e.Row.CssClass = "SubTotales"
e.Row.Attributes.Add("style", "background:#CCCCCC !important")
End If
End If
End Sub
#End Region
#Region " PERSONALIZAR "
Protected Sub BtnPersonalizar_Click(sender As Object, e As System.EventArgs)
If ChkRetIVA.Checked Then
GvDatos.Columns(6).Visible = True
Else
GvDatos.Columns(6).Visible = False
End If
If ChkRetISR.Checked Then
GvDatos.Columns(7).Visible = True
Else
GvDatos.Columns(7).Visible = False
End If
If ChkMinSub.Checked Then
GvDatos.Columns(9).Visible = True
Else
GvDatos.Columns(9).Visible = False
End If
If ChkAVGSub.Checked Then
GvDatos.Columns(10).Visible = True
Else
GvDatos.Columns(10).Visible = False
End If
If ChkMaxSub.Checked Then
GvDatos.Columns(11).Visible = True
Else
GvDatos.Columns(11).Visible = False
End If
If ChkMinTot.Checked Then
GvDatos.Columns(14).Visible = True
Else
GvDatos.Columns(14).Visible = False
End If
If ChkAvgTot.Checked Then
GvDatos.Columns(13).Visible = True
Else
GvDatos.Columns(13).Visible = False
End If
If ChkMaxTot.Checked Then
GvDatos.Columns(12).Visible = True
Else
GvDatos.Columns(12).Visible = False
End If
UPDatos.Update()
End Sub
#End Region
#Region " EXCEL "
Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
'GvDatos.ExportToExcel("ReporteVentas" & Now.ToShortDateString)
GenerarPDF("Excel")
End Sub
#End Region
Private Sub GenerarPDF(Optional Formato As String = "PDF")
If DtVentas IsNot Nothing Then
Dim StrFiltro As New StringBuilder
StrFiltro.AppendFormat("<b>Agrupado por</b>: {0}", DdlGrupo.SelectedItem.Text)
If DdlTipoComprobante.SelectedValue <> "-1" Then StrFiltro.AppendFormat("&emsp;<b>Tipo Documento</b>: {0}", DdlTipoComprobante.SelectedItem.Text)
If txtFechaI.Text <> "" Then StrFiltro.AppendFormat("&emsp;<b>Fecha Inicio </b>: {0}", txtFechaI.Text.ToDate.ToShortDateString)
If txtFechaF.Text <> "" Then StrFiltro.AppendFormat("&emsp;<b>Fecha Fin </b>: {0}", txtFechaF.Text.ToDate.ToShortDateString)
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta))
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
Dim dt As DataTable = DtVentas.FiltraParametros("", "Orden") '.FiltraParametros("Total > 0", DistinctColumns:={"GPO", "Cantidad", "SubTotal", "Descuento", "Amortizacion", "IVA", "Total"})
Dim FechaI, FechaF As String
FechaI = If(txtFechaI.Text = "" Or txtFechaI.Text = "__/__/____", "-1", txtFechaI.Text)
FechaF = If(txtFechaF.Text = "" Or txtFechaF.Text = "__/__/____", "-1", txtFechaF.Text)
Dim params As New List(Of ReportParameter)
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("FechaInicio", FechaI))
params.Add(New ReportParameter("FechaFin", FechaF))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString))
params.Add(New ReportParameter("Filtros", StrFiltro.ToString))
If Imagen.Exists Then
params.Add(New ReportParameter("LogoPath", logouri))
Else
params.Add(New ReportParameter("LogoPath", ""))
End If
ImprimirPDF("Empresas/Grales/Formatos/RepVentas.rdlc", dt, params, String.Format("ReporteVentas-{0}", Now.ToDateTime.ToShortDateString), Formato:=Formato)
Else
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia)
End If
End Sub
Protected Sub ImgImprimir_Click(sender As Object, e As EventArgs) Handles ImgImprimir.Click
GenerarPDF()
End Sub
Private Sub LnkRepHP_Click(sender As Object, e As EventArgs) Handles LnkRepHP.Click
Dim Rep As New ClsVentas
Dim Str As New StringBuilder
Str.AppendLine("Header Section,,,,,,,,,,,End Customer Identification ,,,,,,,,,,,,, Ship To Identification,,,,,,,,,,,,, Sold To Identification,,,,,,,,,,,,, Bill To Identification,,,,,,,,,,,,, Salesperson Detail,,,,,, Line Item Detail,,,,,,,,,,,,,,,,,,,,,,,,,,,, New FIELDS,,,,,,,,,,,,,,,,,,,,,,,,,, ")
Str.AppendLine("Partner Purchase Price Currency Code, Exchange Rate, Reporter_id, Reported Partner Type, Reporter Company Name , Sell From Address line 1, Sell From Address line 2, Sell From City, Reported Partner State/Province, Sell from postal code, Sell from Country code,End User Customer Name,End User Company Tax ID,End User Address Line 1,End User Address Line 2,End User City,End User State/Province Code,End User Postal Code,End User Country Code,End User ID,End Customer Department,End Customer Contact Name,End Customer Contact Phone,End Customer County, Ship To Customer Name, Ship To Company Tax ID, Ship To Address Line 1, Ship To Address Line 2, Ship To City, Ship To State/Province Code, Ship To Postal Code, Ship To Country Code, Ship To Customer ID, Ship To Department, Ship To Contact Name, Ship To Contact Phone, Ship To County, Sold To Customer Name, Sold To Company Tax ID, Sold To Address Line 1, Sold To Address Line 2, Sold To City, Sold To State/Province Code, Sold To Postal Code, Sold To Country Code, Sold To Customer ID, Sold To Department, Sold To Contact Name, Sold To Contact Phone, Sold To County, Bill To Customer Name, Bill To Company Tax ID, Bill To Address Line 1 , Bill To Address Line 2, Bill To City, Bill To State/Province Code, Bill To Postal Code, Bill To Country Code, Bill To Customer ID, Bill To Agreement Number, Bill To Contact Name, Bill To Contact Phone, Bill To County, HP Representative Name, HP Sales Rep Email, Salesperson2 Name, Salesperson2 Unique Employee ID, Salesperson's Manager's Name,Salesperson's Manager Unique Employee ID,Quantity Qualifier,Product Quantity Shipped/Sold,Line Item ID,Partner Reported Product ID,Product Description,Date Type Qualifier,Channel Partner to Customer Transaction Date,Reseller’’s Product Number,Partner Purchase Price,Extended Price,Partner Sell Price,Extended Resale Price,Transaction Type,Rebate Tracking #,Partner Requested Rebate Amount,Extended Rebate Amount,Debit Number,Channel Partner to Customer Invoice ID,Reference Number,Customer to Channel Partner Purchase Order ID,Deal ID #1,Deal ID #2,Deal ID #3,Deal ID #4,Deal ID #5,Deal ID #6,Marketing Subprogram Code,Product Serial ID assigned by HP,Purchasing Source wholesaler indicator,Drop Ship Flag,Distributor's Invoice Number,Partner Internal transaction ID,Partner Comment,Deal Bundle ID #1,Deal Bundle ID #2,Deal Bundle ID #3,Deal Bundle ID #4,Deal Bundle ID #5,Deal Bundle ID #6,NMSO NAME,Sales Type,Purchase Agreement,Product Origin,Partner Reported CBN#,Partner Reference,Supplies Tracking ID (QR Code),Sell From Location ID (assigned by HP or Partner-assigned),Sell from name,Comment Deal ID #1,Comment Deal ID #2,Comment Deal ID #3,Comment Deal ID #4,Comment Deal ID #5,Comment Deal ID #6,Partner Sell Price Currency Code")
If Rep.GetReporteHP(72, Now.AddMonths(-1).FirstDayOfMonth, Now.AddMonths(-1).LastDayOfMonth) Then
For Each dr As DataRow In Rep.DtResultados.Rows
Str.AppendLine($"MXN,,AM30089,,""COMPUPROVEEDORES, S.A.DE C.V."",,,,,,,,,,,,,,,,,,,,{dr("Nombre")},{dr("RFC")},{dr("Direccion")},,,{dr("Ciudad")},{dr("Estado")},{dr("CP")},MX,{dr("RFC")},,,,,{dr("Nombre")},{dr("RFC")},{dr("Direccion")},,{dr("Ciudad")},{dr("Estado")},{dr("CP")},MX,{dr("RFC")},,,,,,,,,,,,,,,,,,,,,,,,,{dr("Cantidad")},,{dr("Codigo")},,,{dr("Fecha")},,,,{dr("PU")},,,,,,,{dr("SerieFolio")},,,,,,,,,,,,,,,,,,,,,,,,,{dr("Proveedor")},,,,,,,,,,,,MXN")
Next
End If
Rep.Dispose()
'GenerarPDF una salida
Response.Clear()
Response.ContentType = "text/csv"
Response.AppendHeader("Content-Disposition", "attachment; filename=ReporteHP.csv")
Response.Write(Str.ToString)
Context.Response.End()
End Sub
Private Sub RblTipoCambio_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RblTipoCambio.SelectedIndexChanged
TipoCambio = RblTipoCambio.SelectedValue.ToEntero
If TipoCambio = 3 Then
LiEspecifico.Visible = True
TCEspecifico = GlobalTipoCambio(Now).ToDecimal
TxtEspecifico.Text = TCEspecifico.ToString
Else
LiEspecifico.Visible = False
End If
UpBodyTipoCambio.Update()
End Sub
Private Sub BtnTipoCambio_Click(sender As Object, e As EventArgs) Handles BtnTipoCambio.Click
CargaDatos()
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivTipoCambio"))
UPDatos.Update()
End Sub
End Class