Option Explicit On Option Strict On Imports System.Data Imports System.Xml Imports Extensiones Imports Microsoft.Reporting.WebForms Imports System.IO Partial Class RepVentasPeriodo 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 txtFechaI.Text = Now.FirstDayOfMonth.ToString("dd/MM/yyyy") 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() 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() DdlClientes.setEsWebService(True) DdlClientes.Attributes.Add("data-metodo", "getcliente") DdlClientes.SelectedText = "Todos" DdlClientes.SelectedValue = "-1" 'CargaSucursales DdlSubProyectoEjecucion.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) DdlSubProyectoEjecucion.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).FiltraParametros("", "", {"CveProyecto", "Proyecto"}) DdlProyecto.DataBind() DdlProyecto.Items.Insert(0, New ListItem("Todos", "-1")) 'Carga Clasificacion Cliente DdlClienteClasificacion.DataSource = GlobalDTClienteClasificaciones(UsuarioActual.CveEmpresa) DdlClienteClasificacion.DataBind() DdlClienteClasificacion.Items.Insert(0, New ListItem("Todos", "-1")) 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 = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) 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 VerEn As Integer = -1 If RbSubTotal.Checked Then VerEn = 1 If RbTotal.Checked Then VerEn = 2 If RbIVA.Checked Then VerEn = 3 Dim FechaI, FechaF, FechaIEjec, FechaFEjec As Date FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim.ToDate, MinFecha) FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim.ToDate, MaxFecha) FechaIEjec = If(IsDate(TxtFechaIEjec.Text.Trim()), TxtFechaIEjec.Text.Trim.ToDate, MinFecha) FechaFEjec = If(IsDate(TxtFechaFEjec.Text.Trim()), TxtFechaFEjec.Text.Trim.ToDate, MaxFecha) Dim ModalidadContable As Boolean = Not ChkLecturaAdmin.Checked If ObjVentas.GetRepVentasPeriodos(FechaI, FechaF, FechaIEjec, FechaFEjec, DdlClientes.SelectedValue.ToEntero, DdlSubProyectoEjecucion.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, CveUsuarioConsulta:=UsuarioActual.CveUsuario, VerEn:=VerEn, CveClienteClasificacion:=DdlClienteClasificacion.SelectedValue.ToEntero, TipoCliente:=DdlTipoCliente.SelectedValue.ToEntero, ModalidadContable:=ModalidadContable) Then GvDatos.DataSource = ObjVentas.DtResultados DtVentas = ObjVentas.DtResultados Else GvDatos.DataSource = Nothing End If CveProyecto = DdlProyecto.SelectedValue.ToEntero ObjVentas.Dispose() GvDatos.DataBind() If GvDatos.Rows.Count > 0 Then CargaGraficas(DtVentas) Me.DvGraficas.Visible = True Else Me.DvGraficas.Visible = False End If 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" If e.Row.RowIndex = 0 Then e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(0).Width = Unit.Pixel(200) e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(1).Width = Unit.Pixel(60) e.Row.Cells(2).Width = Unit.Pixel(90) e.Row.Cells(3).Width = Unit.Pixel(90) e.Row.Cells(4).Width = Unit.Pixel(90) e.Row.Cells(5).Width = Unit.Pixel(80) e.Row.Cells(8).Width = Unit.Pixel(100) e.Row.CssClass = "Totales" Css = "Totales" End If If e.Row.FCLiteral("LtlGrupo").Text = "Total Dólares" Then e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(0).Width = Unit.Pixel(200) e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(1).Width = Unit.Pixel(60) e.Row.Cells(2).Width = Unit.Pixel(90) e.Row.Cells(3).Width = Unit.Pixel(90) e.Row.Cells(4).Width = Unit.Pixel(90) e.Row.Cells(5).Width = Unit.Pixel(80) e.Row.Cells(8).Width = Unit.Pixel(100) e.Row.CssClass = "Totales" Css = "Totales" End If Dim FechaI, FechaF As String FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1") FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1") If e.Row.DBCampo("Cantidad").ToDouble = 0 Then e.Row.FCLiteral("LtlCant").Text = "" If e.Row.DBCampo("Enero").ToDouble = 0 Then e.Row.FCLiteral("LtlEne").Text = "" If e.Row.DBCampo("Febrero").ToDouble = 0 Then e.Row.FCLiteral("LtlFeb").Text = "" If e.Row.DBCampo("Marzo").ToDouble = 0 Then e.Row.FCLiteral("LtlMar").Text = "" If e.Row.DBCampo("Abril").ToDouble = 0 Then e.Row.FCLiteral("LtlAbr").Text = "" If e.Row.DBCampo("Mayo").ToDouble = 0 Then e.Row.FCLiteral("LtlMay").Text = "" If e.Row.DBCampo("Junio").ToDouble = 0 Then e.Row.FCLiteral("LtlJun").Text = "" If e.Row.DBCampo("Julio").ToDouble = 0 Then e.Row.FCLiteral("LtlJul").Text = "" If e.Row.DBCampo("Agosto").ToDouble = 0 Then e.Row.FCLiteral("LtlAgo").Text = "" If e.Row.DBCampo("Septiembre").ToDouble = 0 Then e.Row.FCLiteral("LtlSep").Text = "" If e.Row.DBCampo("Octubre").ToDouble = 0 Then e.Row.FCLiteral("LtlOct").Text = "" If e.Row.DBCampo("Noviembre").ToDouble = 0 Then e.Row.FCLiteral("LtlNov").Text = "" If e.Row.DBCampo("Diciembre").ToDouble = 0 Then e.Row.FCLiteral("LtlDic").Text = "" End If End Sub #End Region #Region " PERSONALIZAR " Protected Sub BtnPersonalizar_Click(sender As Object, e As System.EventArgs) CargaDatos() 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("Agrupado por: {0}", DdlGrupo.SelectedItem.Text) If DdlTipoComprobante.SelectedValue <> "-1" Then StrFiltro.AppendFormat(" Tipo Documento: {0}", DdlTipoComprobante.SelectedItem.Text) If txtFechaI.Text <> "" Then StrFiltro.AppendFormat(" Fecha Inicio : {0}", txtFechaI.Text.ToDate.ToShortDateString) If txtFechaF.Text <> "" Then StrFiltro.AppendFormat(" Fecha Fin : {0}", txtFechaF.Text.ToDate.ToShortDateString) Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png") 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)) params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", ""))) 'Alert("El reporte requiere papel tipo oficio", TipoMensaje.MsgInformacion) ImprimirPDF("Empresas/Grales/Formatos/RepVentasPeriodo.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 Private Sub CargaGraficas(DtVentas As DataTable) MuestraGrafica(div_ventas, DtVentas, "GPO", "Total", "", "", "gh2", "") End Sub Private Sub MuestraGrafica(divcontainer As HtmlGenericControl, DTDatos As DataTable, ColTitle As String, ColValue As String, Titulo As String, SubTitulo As String, Optional Indicador As String = "gh", Optional XReferencia As String = "", Optional YReferencia As String = "") Dim Info As String = "" Dim SBJSScript As New StringBuilder If DTDatos IsNot Nothing AndAlso DTDatos.Rows.Count > 0 Then For Each DbRow As DataRow In DTDatos.Rows Dim moneda As String = DbRow("Moneda").ToString Dim total As String = DbRow("GPO").ToString If total <> "Total Peso Mexicano" Then If moneda = "Peso Mexicano" Then Info = String.Format("{2}['{1}',{0}],", DbRow(ColValue), DbRow(ColTitle), Info) End If End If Next Info = Info.Remove(Info.Length - 1, 1) SBJSScript.AppendFormat("graficahighcharts('{0}','{1}','{2}','{3}',[{4}],1,'{5}');", divcontainer.ClientID, Titulo, SubTitulo, YReferencia, Info, XReferencia) Else SBJSScript.AppendFormat("graficahighcharts('{0}','{1}','{2}','{3}',[{4}],1,'{5}');", divcontainer.ClientID, Titulo, SubTitulo, YReferencia, " ", XReferencia) End If RegistraScript(SBJSScript.ToString, Indicador) End Sub Protected Sub DdlClienteClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs) CargaClientes() End Sub Private Sub CargaClientes() DdlClientes.ddl.Items.Clear() DdlClientes.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa, -1).FiltraParametros($"CveClienteClasificacion = {DdlClienteClasificacion.SelectedValue.ToEntero} OR {DdlClienteClasificacion.SelectedValue.ToEntero} = -1") DdlClientes.DataBind() DdlClientes.ddl.Items.Insert(0, New ListItem("Todos", "-1")) End Sub End Class