384 lines
11 KiB
C#
384 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
using Extensiones;
|
|
using System.Data;
|
|
using System.IO;
|
|
using Microsoft.Reporting.WebForms;
|
|
|
|
public partial class Finanzas_RepRotacionCarteraDetalle : ClsPaginas
|
|
{
|
|
#region "P R O P I E D A D E S"
|
|
private DataTable DTDatosClientes
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTDatosClientes"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DTDatosClientes"] = value;
|
|
}
|
|
}
|
|
private DataTable DTDatosProveedores
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTDatosProveedores"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DTDatosProveedores"] = value;
|
|
}
|
|
}
|
|
private int CveCliente
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveCliente"].ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveCliente"] = value;
|
|
}
|
|
}
|
|
private String FechaInicio
|
|
{
|
|
get
|
|
{
|
|
return ViewState["FechaInicio"].ToString();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["FechaInicio"] = value;
|
|
}
|
|
}
|
|
|
|
private String FechaFin
|
|
{
|
|
get
|
|
{
|
|
return ViewState["FechaFin"].ToString();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["FechaFin"] = value;
|
|
}
|
|
}
|
|
private String FechaFinCobranza
|
|
{
|
|
get
|
|
{
|
|
return ViewState["FechaFinCobranza"].ToString();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["FechaFinCobranza"] = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
InicializaDatos();
|
|
}
|
|
}
|
|
|
|
#region "CARGA DATOS"
|
|
|
|
private void InicializaDatos()
|
|
{
|
|
|
|
if (Request["CveCliente"] != null && !Request["CveCliente"].ToString().Equals("") && Request["CveCliente"].ToEntero() > 0)
|
|
{
|
|
ViewState["CveCliente"] = Request["CveCliente"];
|
|
}
|
|
else
|
|
{
|
|
ViewState["CveMovimiento"] = -1;
|
|
}
|
|
|
|
if (Request["FechaInicio"] != null && !Request["FechaInicio"].ToString().Equals("") )
|
|
{
|
|
ViewState["FechaInicio"] = Request["FechaInicio"].ToString();
|
|
}
|
|
else
|
|
{
|
|
ViewState["FechaInicio"] = DateTime.Today.ToShortDateString();
|
|
}
|
|
|
|
if (Request["FechaFin"] != null && !Request["FechaFin"].ToString().Equals(""))
|
|
{
|
|
ViewState["FechaFin"] = Request["FechaFin"];
|
|
}
|
|
else
|
|
{
|
|
ViewState["FechaFin"] = (new DateTime(DateTime.Today.Year, 1, 1)).ToShortDateString();
|
|
}
|
|
|
|
if (Request["FechaFinCobranza"] != null && !Request["FechaFinCobranza"].ToString().Equals(""))
|
|
{
|
|
ViewState["FechaFinCobranza"] = Request["FechaFinCobranza"];
|
|
}
|
|
else
|
|
{
|
|
ViewState["FechaFinCobranza"] = FechaFin;
|
|
}
|
|
|
|
TxtFechaI.Text = FechaInicio;
|
|
TxtFechaF.Text = FechaFin;
|
|
TxtFechaCobranza.Text = FechaFinCobranza;
|
|
|
|
//TxtFechaCobranza.Text = DateTime.Today.ToShortDateString();
|
|
|
|
//CargaClientes();
|
|
//CargaVendedores();
|
|
//CargaSucursales();
|
|
//CargaProveedores();
|
|
|
|
MuestraFiltrosCliente();
|
|
CargaDatos();
|
|
|
|
}
|
|
|
|
private void CargaDatos()
|
|
{
|
|
ClsFinanzas ObjFinanzas = new ClsFinanzas();
|
|
|
|
DateTime FechaInicio = Convert.ToDateTime(TxtFechaI.Text);
|
|
DateTime FechaFin = Convert.ToDateTime(TxtFechaF.Text);
|
|
DateTime FechaFinCobranza = Convert.ToDateTime(TxtFechaCobranza.Text);
|
|
|
|
|
|
if (ObjFinanzas.GetRotacionCarteraClienteDetalle(FechaInicio, FechaFin, FechaFinCobranza, UsuarioActual.CveEmpresa, CveCliente))
|
|
{
|
|
//GvDatosCliente.Columns[0].HeaderText = DdlGrupo.SelectedItem.Text;
|
|
DTDatosClientes = ObjFinanzas.DtResultados;
|
|
GvDatosCliente.DataSource = DTDatosClientes;
|
|
|
|
if (DTDatosClientes.Rows.Count > 1)
|
|
{
|
|
//LtlTotalVentas.Text = DTDatosClientes.SUM("Ventas").ToString().FormatoNumero();
|
|
//LtlCarteraFinalCliente.Text = String.Format("$ {0}", DTDatosClientes.SUM("Pagado").ToString().FormatoNumero());
|
|
|
|
//LtlMediaDiasRecuperacionCliente.Text = String.Format("{0} Días", (DTDatosClientes.SUM("TotalDias") / DTDatosClientes.SUM("TotalNumVentas")).ToString().FormatoNumero());
|
|
//LtlRotacionCliente.Text = (DTDatosClientes.SUM("Pagado") / DTDatosClientes.SUM("Ventas")).ToString().FormatoNumero();
|
|
}
|
|
else
|
|
{
|
|
limpiaIndicadoresCliente();
|
|
}
|
|
|
|
}
|
|
ObjFinanzas.Dispose();
|
|
GvDatosCliente.DataBind();
|
|
UPRRPClientes.Update();
|
|
|
|
|
|
|
|
}
|
|
|
|
protected void limpiaIndicadoresCliente()
|
|
{
|
|
LtlTotalVentas.Text = "0".FormatoNumero();
|
|
LtlCarteraFinalCliente.Text = "0".FormatoNumero();
|
|
|
|
LtlMediaDiasRecuperacionCliente.Text = "0 Días";
|
|
LtlRotacionCliente.Text = "0".FormatoNumero();
|
|
}
|
|
protected void limpiaIndicadoresProveedor()
|
|
{
|
|
//LtlTotalCompras.Text = "0".FormatoNumero();
|
|
//LtlCarteraFinalProveedor.Text = "0".FormatoNumero();
|
|
|
|
//LtlMediaDiasRecuperacionProveedor.Text = "0 Días";
|
|
//LtlRotacionProveedor.Text = "0".FormatoNumero();
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
|
|
protected void GvDatosCliente_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (GvDatosCliente.Columns[0].HeaderText == "Folio")
|
|
{
|
|
e.Row.FCHyperLink("HypFolio").NavigateUrl = string.Format("/Ventas/Ventas.aspx?CveVenta={0}", e.Row.DBCampo("CveVenta"));
|
|
}
|
|
else
|
|
{
|
|
e.Row.FCHyperLink("HypFolio").ForeColor = System.Drawing.Color.Black;
|
|
}
|
|
}
|
|
}
|
|
|
|
//protected void GvDatosProveedores_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
//{
|
|
// if (e.Row.RowType == DataControlRowType.DataRow)
|
|
// {
|
|
// if (GvDatosProveedores.Columns[0].HeaderText == "Proveedor")
|
|
// {
|
|
// e.Row.FCHyperLink("HypProveedor").NavigateUrl = string.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor"));
|
|
// }
|
|
// else
|
|
// {
|
|
// e.Row.FCHyperLink("HypProveedor").ForeColor = System.Drawing.Color.Black;
|
|
// }
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
#region "CARGA DDL"
|
|
|
|
private void CargaSucursales()
|
|
{
|
|
//DdlSucursal.DataSource = get_GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa);
|
|
//DdlSucursal.DataBind();
|
|
//DdlSucursal.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
//DdlSucursal.SelectedValue = "-1";
|
|
}
|
|
|
|
private void CargaClientes()
|
|
{
|
|
//DdlCliente.DataSource = get_GlobalDTCliente(UsuarioActual.CveEmpresa);
|
|
//DdlCliente.DataBind();
|
|
//DdlCliente.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
//DdlCliente.SelectedValue = "-1";
|
|
}
|
|
|
|
private void CargaProveedores()
|
|
{
|
|
//DdlProveedor.DataSource = get_GlobalDTCompProveedores(UsuarioActual.CveEmpresa);
|
|
//DdlProveedor.DataBind();
|
|
//DdlProveedor.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
//DdlProveedor.SelectedValue = "-1";
|
|
}
|
|
|
|
private void CargaVendedores()
|
|
{
|
|
|
|
//DdlVendedores.DataSource = get_GlobalDTVendedores(UsuarioActual.CveEmpresa);
|
|
//DdlVendedores.DataBind();
|
|
//DdlVendedores.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
//DdlVendedores.SelectedValue = "-1";
|
|
}
|
|
#endregion
|
|
|
|
#region "CARGA CAMBIO REPORTE"
|
|
private void MuestraFiltrosCliente()
|
|
{
|
|
//DdlGrupo.Items.Clear();
|
|
//DdlGrupo.Items.Insert(0, new ListItem("Cliente", "1"));
|
|
//DdlGrupo.Items.Insert(1, new ListItem("Vendedor", "2"));
|
|
//DdlGrupo.Items.Insert(2, new ListItem("Sucursal", "3"));
|
|
//DdlGrupo.SelectedValue = "1";
|
|
|
|
//DivDdlCliente.Visible = true;
|
|
//DivDdlVendedor.Visible = true;
|
|
|
|
//DivDdlProveedor.Visible = false;
|
|
//DivDdlTipoProveedor.Visible = false;
|
|
|
|
//UpFiltros.Update();
|
|
|
|
}
|
|
private void MuestraFiltrosProveedor()
|
|
{
|
|
//DdlGrupo.Items.Clear();
|
|
//DdlGrupo.Items.Insert(0, new ListItem("Proveedor", "1"));
|
|
//DdlGrupo.Items.Insert(1, new ListItem("Tipo Proveedor", "2"));
|
|
//DdlGrupo.Items.Insert(2, new ListItem("Sucursal", "3"));
|
|
//DdlGrupo.SelectedValue = "1";
|
|
|
|
//DivDdlProveedor.Visible = true;
|
|
//DivDdlTipoProveedor.Visible = true;
|
|
|
|
//DivDdlCliente.Visible = false;
|
|
//DivDdlVendedor.Visible = false;
|
|
|
|
//UpFiltros.Update();
|
|
}
|
|
|
|
protected void Tab_ActiveTabChanged(object sender, EventArgs e)
|
|
{
|
|
//if (Tab.ActiveTabIndex == 0)
|
|
//{
|
|
// MuestraFiltrosCliente();
|
|
//}
|
|
//else if (Tab.ActiveTabIndex == 1)
|
|
//{
|
|
// MuestraFiltrosProveedor();
|
|
//}
|
|
}
|
|
#endregion
|
|
|
|
#region "GENERAR EXCEL"
|
|
//protected void GeneraPDF(string Formato = "PDF")
|
|
//{
|
|
// List<ReportParameter> @params = new List<ReportParameter>();
|
|
|
|
// System.IO.FileInfo Imagen = new System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png");
|
|
// var logouri = string.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
|
|
// @params.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
|
// @params.Add(new ReportParameter("FechaInicio", TxtFechaI.Text));
|
|
// @params.Add(new ReportParameter("FechaFin", TxtFechaF.Text));
|
|
// @params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
// @params.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToString()));
|
|
|
|
// @params.Add(new ReportParameter("Grupo", DdlGrupo.SelectedItem.Text));
|
|
// @params.Add(new ReportParameter("Sucursal", DdlSucursal.SelectedItem.Text));
|
|
|
|
// @params.Add(new ReportParameter("TipoReporte", Tab.ActiveTab.HeaderText));
|
|
|
|
|
|
// if (Imagen.Exists)
|
|
// {
|
|
// @params.Add(New ReportParameter("LogoPath", $"file://{Imagen.FullName}"));
|
|
// }
|
|
// else
|
|
// {
|
|
// @params.Add(new ReportParameter("LogoPath", ""));
|
|
// }
|
|
|
|
|
|
// if (Tab.ActiveTabIndex == 0)
|
|
// {
|
|
// @params.Add(new ReportParameter("Filtro1", DdlCliente.SelectedItem.Text));
|
|
// @params.Add(new ReportParameter("Filtro2", DdlVendedores.SelectedItem.Text));
|
|
|
|
// ImprimirPDF("Empresas/Grales/Formatos/RepRotacionCarteraCliente.rdlc", DTDatosClientes, @params, "ReporteRotacionCarteraCliente", Formato);
|
|
// }
|
|
// else
|
|
// {
|
|
// @params.Add(new ReportParameter("Filtro1", DdlProveedor.SelectedItem.Text));
|
|
// @params.Add(new ReportParameter("Filtro2", DdlTipoProveedor.SelectedItem.Text));
|
|
|
|
// ImprimirPDF("Empresas/Grales/Formatos/RepRotacionCarteraProveedor.rdlc", DTDatosProveedores, @params, "ReporteRotacionCarteraProveedor", Formato);
|
|
// }
|
|
|
|
//}
|
|
|
|
//protected void ImgGenerarExcel_Click(object sender, EventArgs e)
|
|
//{
|
|
// //GeneraPDF("Excel");
|
|
//}
|
|
#endregion
|
|
|
|
} |