Files
SIG/Compras/RepProductosServiciosPeriodo.aspx.cs
rrene 1c14bceea9 -- cambio de GlobalDTSubProyectos
- cambio en GlobalDTUsuarios
2024-08-01 05:46:28 -07:00

365 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Extensiones;
using System.Data;
using static Extensiones.ModExtensiones;
using Microsoft.Reporting.WebForms;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class Compras_RepProductosServiciosPeriodo : ClsPaginas
{
#region PROPIEDADES
private int TipoCambio
{
get { return (ViewState["TipoCambio"] == null) ? -1 : ViewState["TipoCambio"].ToEntero(); }
set { ViewState["TipoCambio"] = value; }
}
private double TCEspecifico
{
get { return (ViewState["TCEspecifico"] == null) ? 0 : ViewState["TCEspecifico"].ToString().ToDouble(); }
set { ViewState["TCEspecifico"] = value; }
}
private DataTable DtDatos
{
get { return DtDatos = (DataTable)ViewState["DtDatos"]; }
set { ViewState["DtDatos"] = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InicializaValores();
}
}
#region CARGAS
private void InicializaValores()
{
CargaCombos();
}
private void CargaGrupo()
{
DdlGrupo.Items.Insert(0, new ListItem("Categoria", "3"));
DdlGrupo.Items.Insert(1, new ListItem("Clasificación", "4"));
DdlGrupo.Items.Insert(2, new ListItem("Productos-Servicios", "5"));
DdlGrupo.Items.Insert(3, new ListItem("Año", "6"));
DdlGrupo.Items.Insert(4, new ListItem("Mes", "7"));
DdlGrupo.Items.Insert(5, new ListItem("Año/Mes", "8"));
DdlGrupo.Items.Insert(6, new ListItem("Fecha", "9"));
DdlGrupo.Items.Insert(7, new ListItem("Proveedor", "10"));
DdlGrupo.Items.Insert(8, new ListItem("Usuario", "11"));
DdlGrupo.Items.Insert(9, new ListItem("Estatus Fact.", "12"));
DdlGrupo.DataBind();
DdlGrupo.SelectedValueExist("8");
}
private void CargaCombos()
{
//Carga Tipo Centro de Costo
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto: DivProyecto);
//Carga Proveedores
DdlProveedores.DataSource = get_GlobalDTCompProveedores(UsuarioActual.CveEmpresa);
DdlProveedores.DataBind();
//Carga Tipo de Gasto
DdlTipoGasto.DataSource = get_GlobalDTTiposGastos(UsuarioActual.CveEmpresa);
DdlTipoGasto.DataBind();
//Carga Usuarios Responsable
DdlUsuario.DataSource = get_GlobalDTUsuarioResponsable(UsuarioActual.CveEmpresa);
DdlUsuario.DataBind();
//Carga Usuarios Captura
DDlUsuarioCaptura.DataSource = get_GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa);
DDlUsuarioCaptura.DataBind();
//Carga Monedas
DdlMonedas.DataSource = GlobalDTMonedas;
DdlMonedas.DataBind();
//Cargo Categorias
DdlCategoria.DataSource = get_GlobalDTGralCategorias(UsuarioActual.CveEmpresa);
DdlCategoria.DataBind();
//Cargo Clasificaciones
DdlClasificacion.DataSource = get_GlobalDTClasificaciones(UsuarioActual.CveEmpresa);
DdlClasificacion.DataBind();
//Carga Productos
DdlPS.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) == "1");
if (UsuarioActual.Empresa.Funcionalidad(105) == "1") {
DdlPS.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue);
DdlPS.SelectedText = "";
DdlPS.SelectedValue = "-1";
}
else
{
DdlPS.ddl.Items.Clear();
DdlPS.ddl.DataSource = get_GlobalDTPSSimplificado(UsuarioActual.CveEmpresa);
DdlPS.ddl.DataBind();
DdlPS.ddl.Items.Insert(0, new ListItem("Todos", "-1"));
}
//Carga Tipos AF
DdlTipoAF.DataSource = get_GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa);
DdlTipoAF.DataBind();
//Carga SubTipos AF
DdlSubTipoAF.DataSource = get_GlobalDTSubTipoActivoFijo(UsuarioActual.CveEmpresa);
DdlSubTipoAF.DataBind();
//CARGA COSTOS
if (UsuarioActual.CveEmpresa == 66) {
int NumItems = DdlGrupo.Items.Count;
//COSTOS PROYECTO
DdlGrupo.Items.Insert(NumItems, new ListItem("Costos", "13"));
RowCostos.Visible = true;
//Carga Familias
DdlFamilia.DataSource = get_GlobalDTFamilias(66);
DdlFamilia.DataBind();
//Carga SubFamilias
DdlSubFamilia.DataSource = get_GlobalDTSubFamilias(66);
DdlSubFamilia.DataBind();
//COSTOS AF
DdlGrupo.Items.Insert(NumItems + 1, new ListItem("Costos por Activo Fijo", "14"));
}
RowActivoFijo.Visible = true;
//Carga Grupo
CargaGrupo();
}
private void CargaDatos()
{
ClsCompras ObjCompras = new ClsCompras();
string FechaI, FechaF, FechaICaptura, FechaFCaptura;
if (txtFechaI.Text.Trim() != "") { FechaI= txtFechaI.Text.Trim(); } else { FechaI= "-1"; }
if (txtFechaF.Text.Trim() != "") { FechaF = txtFechaF.Text.Trim(); } else { FechaF = "-1"; }
if (TxtFechaICaptura.Text.Trim() != "") { FechaICaptura = TxtFechaICaptura.Text.Trim(); } else { FechaICaptura = "-1"; }
if (TxtFechaFCaptura.Text.Trim() != "") { FechaFCaptura = TxtFechaFCaptura.Text.Trim(); } else { FechaFCaptura = "-1"; }
if (RblTipoCambio.SelectedValue.ToEntero() == 3 && TxtEspecifico.Text != "")
{
TCEspecifico = TxtEspecifico.Text.ToDouble();
}
else
{
TCEspecifico = -1;
}
int VerEn = -1;
if (RbSubTotal.Checked) { VerEn = 1; }
if (RbTotal.Checked) { VerEn = 2; }
if (RbIVA.Checked) { VerEn = 3; }
if (ObjCompras.GetRepComprasPeriodoPS(FechaI, FechaF, DdlProveedores.SelectedValue.ToEntero(), DdlUsuario.SelectedValue.ToEntero(), DDlUsuarioCaptura.SelectedValue.ToEntero(), FechaICaptura, FechaFCaptura,
DdlMonedas.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, DdlGrupo.SelectedValue.ToEntero(), DdlSubProyecto.SelectedValue.ToEntero(),
RblTipoCambio.SelectedValue.ToEntero(), TCEspecifico, DdlTipoGasto.SelectedValue.ToEntero(), CveUsuarioConsulta: UsuarioActual.CveUsuario, VerEn: VerEn,
CveProyecto:DdlProyecto.SelectedValue.ToEntero(),CvePS:DdlPS.SelectedValue.ToEntero(),CveClasificacion:DdlClasificacion.SelectedValue.ToEntero(),
CveCategoria:DdlCategoria.SelectedValue.ToEntero(),CveFamilia: DdlFamilia.SelectedValue.ToEntero(),CveSubFamilia: DdlSubFamilia.SelectedValue.ToEntero(),
CveTipoAF:DdlTipoAF.SelectedValue.ToEntero(), CveSubTipoAF:DdlSubTipoAF.SelectedValue.ToEntero(), CveActivoFijo: DdlAF.SelectedValue.ToEntero()))
{
GvDatos.DataSource = ObjCompras.DtResultados;
DtDatos= ObjCompras.DtResultados;
}
ObjCompras.Dispose();
GvDatos.DataBind();
UPDatos.Update();
}
#endregion
#region SELECTED INDEX CHANGE
protected void DdlProyecto_SelectedIndexChanged(object sender, EventArgs e)
{
CargarSubProyecto(DdlSubProyecto, DdlProyecto.SelectedValue);
}
protected void RblTipoCambio_SelectedIndexChanged(object sender, EventArgs e)
{
if (RblTipoCambio.SelectedValue.ToEntero() == 3) {
double TipoCambio=0;
LiEspecifico.Visible = true;
TipoCambio = get_GlobalTipoCambio(NowADS());
TxtEspecifico.Text = TipoCambio.ToString();
}
else
{
LiEspecifico.Visible = false;
}
UpBodyTipoCambio.Update();
}
protected void DdlFamilia_SelectedIndexChanged(object sender, EventArgs e)
{
DdlSubFamilia.Items.Clear();
if( DdlFamilia.SelectedValue != "-1")
{
DdlSubFamilia.DataSource = get_GlobalDTSubFamilias(UsuarioActual.CveEmpresa, DdlFamilia.SelectedValue.ToEntero());
DdlSubFamilia.DataBind();
}else
{
DdlSubFamilia.DataSource = get_GlobalDTSubFamilias(UsuarioActual.CveEmpresa);
DdlSubFamilia.DataBind();
}
DdlSubFamilia.Items.Insert(0, new ListItem("Sin Asignar", "-2"));
DdlSubFamilia.Items.Insert(0, new ListItem("Todas", "-1"));
}
protected void DdlTipoAF_SelectedIndexChanged(object sender, EventArgs e)
{
DdlSubTipoAF.Items.Clear();
if (DdlTipoAF.SelectedValue != "-1") {
DdlSubTipoAF.DataSource = get_GlobalDTSubTipoActivoFijo(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveTipoActivoFijo = {0}", DdlTipoAF.SelectedValue.ToEntero()));
DdlSubTipoAF.DataBind();
}else
{
DdlSubTipoAF.DataSource = get_GlobalDTSubTipoActivoFijo(UsuarioActual.CveEmpresa);
DdlSubTipoAF.DataBind();
}
DdlSubTipoAF.Items.Insert(0, new ListItem("Todas", "-1"));
}
protected void DdlSubTipoAF_SelectedIndexChanged(object sender, EventArgs e)
{
DdlAF.Items.Clear();
if( DdlSubTipoAF.SelectedValue != "-1")
{
DdlAF.DataSource = get_GlobalDTActivoFijos(UsuarioActual.CveEmpresa, DdlSubTipoAF.SelectedValue.ToEntero());
DdlAF.DataBind();
}
//else
//{
// // DdlAF.DataSource = get_GlobalDTSubTipoActivoFijo(66);
// // DdlAF.DataBind();
//}
DdlAF.Items.Insert(0, new ListItem("Todas", "-1"));
}
#endregion
#region CONSULTAR
protected void BtnConsultar_Click(object sender, EventArgs e)
{
CargaDatos();
}
#endregion
#region GRIDVIEW
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.DBCampo("GPO") == "")
{
e.Row.CssClass = "Totales";
if (e.Row.DBCampo("CveMoneda").ToEntero() == 1) { e.Row.Cells[0].Text = "Pesos"; }
if (e.Row.DBCampo("CveMoneda").ToEntero() == 2) { e.Row.Cells[0].Text = "Dolares"; }
}
if (e.Row.Cells[2].Text.ToDouble() == 0) { e.Row.Cells[2].Text = ""; }
if (e.Row.Cells[3].Text.ToDouble() == 0) { e.Row.Cells[3].Text = ""; }
if (e.Row.Cells[4].Text.ToDouble() == 0) { e.Row.Cells[4].Text = ""; }
if (e.Row.Cells[5].Text.ToDouble() == 0) { e.Row.Cells[5].Text = ""; }
if (e.Row.Cells[6].Text.ToDouble() == 0) { e.Row.Cells[6].Text = ""; }
if (e.Row.Cells[7].Text.ToDouble() == 0) { e.Row.Cells[7].Text = ""; }
if (e.Row.Cells[8].Text.ToDouble() == 0) { e.Row.Cells[8].Text = ""; }
if (e.Row.Cells[9].Text.ToDouble() == 0) { e.Row.Cells[9].Text = ""; }
if (e.Row.Cells[10].Text.ToDouble() == 0) { e.Row.Cells[10].Text = ""; }
if (e.Row.Cells[11].Text.ToDouble() == 0) { e.Row.Cells[11].Text = ""; }
if (e.Row.Cells[12].Text.ToDouble() == 0) { e.Row.Cells[12].Text = ""; }
if (e.Row.Cells[13].Text.ToDouble() == 0) { e.Row.Cells[13].Text = ""; }
if (e.Row.Cells[14].Text.ToDouble() == 0) { e.Row.Cells[14].Text = ""; }
}
}
#endregion
#region PERSONALIZAR
protected void BtnPersonalizar_Click(object sender, EventArgs e)
{
CargaDatos();
UPDatos.Update();
}
#endregion
#region IMPRESION
protected void LnkPdf_Click(object sender, EventArgs e)
{
string Proveedor, Capturo, Grupo, Moneda, FechaIn, FechaFn, Proyecto, SubProyecto;
if (DdlProveedores.SelectedValue == "-1") { Proveedor = ""; } else { Proveedor = $"&emsp;<b>Proveedor:</b> {DdlProveedores.SelectedItem.Text}"; }
if (DDlUsuarioCaptura.SelectedValue == "-1") { Capturo = ""; } else { Capturo = $"&emsp;<b>Capturó:</b> {DDlUsuarioCaptura.SelectedItem.Text}"; }
Grupo = DdlGrupo.SelectedItem.Text;
if (DdlMonedas.SelectedValue == "-1") { Moneda = ""; } else { Moneda = $"&emsp;<b>Monedas:</b> {DdlMonedas.SelectedItem.Text}"; }
FechaIn = $"&emsp;<b>Fecha Inicio:</b> {txtFechaI.Text}";
FechaFn = $"&emsp;<b>Fecha Fin:</b> {txtFechaF.Text}";
if (txtFechaI.Text == "") { FechaIn = ""; }
if (txtFechaF.Text == "") { FechaFn = ""; }
if (DdlProyecto.SelectedValue == "-1") { Proyecto = ""; } else { Proyecto = $"&emsp;<b>Proyecto:</b> {DdlProyecto.SelectedItem.Text}"; }
if (DdlSubProyecto.SelectedValue == "-1") { SubProyecto = ""; } else { SubProyecto = $"&emsp;<b>SubProyecto:</b> {DdlSubProyecto.SelectedItem.Text}"; }
if (DtDatos.Rows.Count > 0)
{
System.IO.FileInfo Imagen = new System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png");
string logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
DataTable dt = DtDatos.FiltraParametros("", "Orden");
string FechaI, FechaF;
if (txtFechaI.Text == "" || txtFechaI.Text == "__/__/____") { FechaI = "-1"; } else { FechaI = txtFechaI.Text; }
if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = txtFechaF.Text; }
List<ReportParameter> para = new List<ReportParameter>();
para.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
para.Add(new ReportParameter("FechaInicio", FechaI));
para.Add(new ReportParameter("FechaFin", FechaF));
para.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
para.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
para.Add(new ReportParameter("FechaImpresion", NowADS().ToString()));
para.Add(new ReportParameter("AgrupadoPor", $"<b>Agrupado Por:</b> {Proveedor}{Capturo}{Grupo}{Moneda}{FechaIn}{FechaFn}{Proyecto}{SubProyecto}"));
if (Imagen.Exists)
{
para.Add(new ReportParameter("LogoPath", logouri));
}
else
{
para.Add(new ReportParameter("LogoPath", ""));
}
ImprimirPDF("Empresas/Grales/Formatos/RepComprasPeriodo.rdlc", dt, para, "RepComprasPeriodo");
}
else
{
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia);
}
}
protected void LnkExportar_Click(object sender, EventArgs e)
{
GvDatos.ExportToExcel($"ReporteComprasPeriodo_{NowADS().ToShortDateString()}");
}
#endregion
}