261 lines
13 KiB
C#
261 lines
13 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_RepPágadoDetalle : ClsPaginas
|
|
{
|
|
|
|
#region PROPIEDADES
|
|
private DataTable DtPagado
|
|
{
|
|
get { return DtPagado = (DataTable)ViewState["DtPagado"]; }
|
|
set { ViewState["DtPagado"] = value; }
|
|
}
|
|
private string GPO
|
|
{
|
|
get { return (ViewState["GPO"] == null) ? "" : ViewState["GPO"].ToString(); }
|
|
set { ViewState["GPO"] = value; }
|
|
}
|
|
private int Tipo
|
|
{
|
|
get { return (ViewState["Tipo"] == null) ? -1 : ViewState["Tipo"].ToString().ToEntero(); }
|
|
set { ViewState["Tipo"] = value; }
|
|
}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
InicializaValores();
|
|
}
|
|
}
|
|
|
|
private void InicializaValores()
|
|
{
|
|
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto:DivProyecto);
|
|
|
|
//Carga Moneda
|
|
DdlMoneda.DataSource = GlobalDTMonedas;
|
|
DdlMoneda.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
DdlMoneda.DataBind();
|
|
|
|
//Carga Proveedor
|
|
DdlProveedores.setEsWebService(true);
|
|
DdlProveedores.Attributes.Add("data-metodo", "getproveedores");
|
|
DdlProveedores.SelectedText = "Todos";
|
|
DdlProveedores.SelectedValue = "-1";
|
|
|
|
//Carga Usuarios
|
|
DdlUsuario.DataSource = get_GlobalDTUsuarios(CveEmpresa: UsuarioActual.CveEmpresa);
|
|
DdlUsuario.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
DdlUsuario.DataBind();
|
|
|
|
//Carga Responsable
|
|
DdlResponsable.DataSource = get_GlobalDTUsuarios(CveEmpresa: UsuarioActual.CveEmpresa);
|
|
DdlResponsable.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
DdlResponsable.DataBind();
|
|
|
|
//Carga Bancos
|
|
DdlBanco.DataSource = GlobalDTBancos.FiltraParametros($"CveEmpresa = {UsuarioActual.CveEmpresa}");
|
|
DdlBanco.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
DdlBanco.DataBind();
|
|
|
|
CargaCuentasBancarias();
|
|
|
|
txtFechaI.Text = $"01/{DateTime.Now.Month}/{DateTime.Now.Year}";
|
|
txtFechaF.Text = DateTime.Now.ToShortDateString();
|
|
txtFechaI.Text = Request["FechaI"] == null ? "" : Request["FechaI"].ToString();
|
|
txtFechaF.Text = Request["FechaF"] == null ? "" : Request["FechaF"].ToString();
|
|
TxtFechaICompra.Text = Request["FechaICompra"] == null ? "" : Request["FechaICompra"].ToString();
|
|
TxtFechaFCompra.Text = Request["FechaFCompra"] == null ? "" : Request["FechaFCompra"].ToString();
|
|
DdlGrupo.SelectedValueExist(Request["Grupo"] == null ? "-1" : Request["Grupo"].ToString());
|
|
DdlProyecto.SelectedValueExist(Request["CveProyecto"] == null ? "-1" : Request["CveProyecto"].ToString());
|
|
DdlSubProyecto.SelectedValueExist(Request["CveSubProyecto"] == null ? "-1" : Request["CveSubProyecto"].ToString());
|
|
|
|
if (Request["CveProveedor"] != null && Request["CveProveedor"].ToString().ToEntero() > 0)
|
|
{
|
|
DataRow DrowProveedor;
|
|
int CveProveedor = Request["CveProveedor"].ToString().ToEntero();
|
|
|
|
DrowProveedor = get_GlobalDTCompProveedores(UsuarioActual.CveEmpresa, CveProveedor).Rows[0];
|
|
|
|
DdlProveedores.txtText.Value = DrowProveedor["RazonSocial"].ToString();
|
|
DdlProveedores.txtValue.Value = CveProveedor.ToString();
|
|
}
|
|
|
|
DdlUsuario.SelectedValueExist(Request["CveUsuario"] == null ? "-1" : Request["CveUsuario"].ToString());
|
|
DdlResponsable.SelectedValueExist(Request["CveResponsable"] == null ? "-1" : Request["CveResponsable"].ToString());
|
|
DdlBanco.SelectedValueExist(Request["CveBanco"] == null ? "-1" : Request["CveBanco"].ToString());
|
|
DdlCuentaBancaria.SelectedValueExist(Request["CveCuenta"] == null ? "-1" : Request["CveCuenta"].ToString());
|
|
DdlMoneda.SelectedValueExist(Request["CveMoneda"] == null ? "-1" : Request["CveMoneda"].ToString());
|
|
DdlTipoProveedor.SelectedValueExist(Request["CveTipoProveedor"] == null ? "-1" : Request["CveTipoProveedor"].ToString());
|
|
DdlComprobacion.SelectedValueExist(Request["ConComprobacion"] == null ? "-1" : Request["ConComprobacion"].ToString());
|
|
GPO = Request["GPO"] == null ? "" : Request["GPO"].ToString();
|
|
Tipo = Request["Tipo"] == null ? -1 : Request["Tipo"].ToString().ToEntero();
|
|
if (DdlGrupo.SelectedValue.ToEntero()==1) { txtFechaI.Text = $"01/01/{GPO}"; txtFechaF.Text = $"31/12/{GPO}"; }
|
|
if (DdlGrupo.SelectedValue.ToEntero() == 9) { TxtFechaICompra.Text = $"01/01/{GPO}"; TxtFechaFCompra.Text = $"31/12/{GPO}"; }
|
|
if (DdlGrupo.SelectedValue.ToEntero() == 11) {
|
|
string Mes = GPO.Substring(5, 2);
|
|
string DiaFinal = "";
|
|
if (Mes == "02") { DiaFinal = "28"; }else if (Mes.Contiene("01", "03", "05", "07", "08", "10", "12")){ DiaFinal = "31"; } else { DiaFinal = "30"; }
|
|
txtFechaI.Text = $"01/{GPO.Substring(5, 2)}/{GPO.Substring(0, 4)}";
|
|
txtFechaF.Text = $"{DiaFinal}/{GPO.Substring(5, 2)}/{GPO.Substring(0, 4)}";
|
|
}
|
|
if (DdlGrupo.SelectedValue.ToEntero() == 3)
|
|
{
|
|
string Mes = GPO.Substring(5, 2);
|
|
string DiaFinal = "";
|
|
if (Mes == "02") { DiaFinal = "28"; } else if (Mes.Contiene("01", "03", "05", "07", "08", "10", "12")) { DiaFinal = "31"; } else { DiaFinal = "30"; }
|
|
TxtFechaICompra.Text = $"01/{GPO.Substring(5, 2)}/{GPO.Substring(0, 4)}";
|
|
TxtFechaFCompra.Text = $"{DiaFinal}/{GPO.Substring(5, 2)}/{GPO.Substring(0, 4)}";
|
|
}
|
|
if (DdlGrupo.SelectedValue.ToEntero()==4) { txtFechaI.Text = $"{GPO.Substring(0, 2)}/{GPO.Substring(3, 2)}/{GPO.Substring(6, 4)}"; txtFechaF.Text = $"{GPO.Substring(0, 2)}/{GPO.Substring(3, 2)}/{GPO.Substring(6, 4)}"; }
|
|
if (DdlGrupo.SelectedValue.ToEntero()==12) { TxtFechaICompra.Text = $"{GPO.Substring(0, 2)}/{GPO.Substring(3, 2)}/{GPO.Substring(6, 4)}"; TxtFechaFCompra.Text = $"{GPO.Substring(0, 2)}/{GPO.Substring(3, 2)}/{GPO.Substring(6, 4)}"; }
|
|
if (DdlGrupo.SelectedValue.ToEntero().Contiene(2, 10)) { DivLblMes.Visible = true; DivChkMes.Visible = true; ChkMesSeleccionado.Checked = true; }
|
|
CargaDatos();
|
|
}
|
|
|
|
private void CargaCuentasBancarias()
|
|
{
|
|
DdlCuentaBancaria.Items.Clear();
|
|
if (DdlBanco.SelectedValue.ToEntero() > 0)
|
|
{
|
|
DdlCuentaBancaria.DataSource = get_GlobalDTBancosCuentas(-1, CveEmpresa: UsuarioActual.CveEmpresa).FiltraParametros($"CveBanco = {DdlBanco.SelectedValue.ToEntero()}");
|
|
}
|
|
DdlCuentaBancaria.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
DdlCuentaBancaria.DataBind();
|
|
}
|
|
|
|
protected void LnkPdf_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("PDF");
|
|
}
|
|
|
|
protected void LnkExcel_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("EXCEL");
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
|
|
protected void DdlProyecto_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargarSubProyecto(DdlSubProyecto, DdlProyecto.SelectedValue);
|
|
}
|
|
|
|
protected void DdlBanco_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargaCuentasBancarias();
|
|
}
|
|
|
|
private void CargaDatos()
|
|
{
|
|
ClsCompras ObjComp = new ClsCompras();
|
|
if (ObjComp.GetRepPagadoDetalle(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), DdlProveedores.SelectedValue.ToEntero(), DdlProyecto.SelectedValue.ToEntero(),
|
|
DdlSubProyecto.SelectedValue.ToEntero(), DdlUsuario.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, DdlGrupo.SelectedValue.ToEntero(),
|
|
DdlResponsable.SelectedValue.ToEntero(), UsuarioActual.CveUsuario, DdlBanco.SelectedValue.ToEntero(), DdlCuentaBancaria.SelectedValue.ToEntero(),
|
|
DdlMoneda.SelectedValue.ToEntero(),ChkMesSeleccionado.Checked,GPO, TxtFechaICompra.Text.ToDate(), TxtFechaFCompra.Text.ToDate(), Tipo, CveTipoProveedor: DdlTipoProveedor.SelectedValue.ToEntero(),
|
|
ConComprobacion: DdlComprobacion.SelectedValue.ToEntero()))
|
|
{
|
|
GvDatos.DataSource = ObjComp.DtResultados;
|
|
DtPagado = ObjComp.DtResultados;
|
|
}
|
|
ObjComp.Dispose();
|
|
if (UsuarioActual.Empresa.Tipo_CentroCosto == 1) { GvDatos.Columns[4].HeaderText = "Sucursal"; }
|
|
if (UsuarioActual.Empresa.Tipo_CentroCosto == 2) { GvDatos.Columns[4].HeaderText = "Proyecto"; }
|
|
if (UsuarioActual.Empresa.Tipo_CentroCosto == 4) { GvDatos.Columns[4].HeaderText = "Sucursal/Proyecto"; }
|
|
if (UsuarioActual.Empresa.Tipo_CentroCosto == 5) { GvDatos.Columns[4].HeaderText = "Proyecto/Sucursal"; }
|
|
GvDatos.DataBind();
|
|
UpDatos.Update();
|
|
}
|
|
|
|
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DBCampo("Tipo").ToEntero()==1)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("GPO").ToString();
|
|
}else if (e.Row.DBCampo("CveCompra").ToEntero() < 1)
|
|
{
|
|
e.Row.CssClass = "SubTotales";
|
|
e.Row.Cells[0].Text = e.Row.DBCampo("GPO").ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GenerarPDF(string Opcion)
|
|
{
|
|
if (DtPagado.Rows.Count < 1)
|
|
{
|
|
Alert("Tiene que haber datos consultados para imprimir.", TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
StringBuilder StrFiltro = new StringBuilder();
|
|
if (txtFechaI.Text != "")
|
|
StrFiltro.AppendFormat(" <b>Fecha Inicio </b>: {0}", txtFechaI.Text.ToDate().ToShortDateString());
|
|
if (txtFechaF.Text != "")
|
|
StrFiltro.AppendFormat(" <b>Fecha Fin </b>: {0}", txtFechaF.Text.ToDate().ToShortDateString());
|
|
if (TxtFechaICompra.Text != "")
|
|
StrFiltro.AppendFormat(" <b>Fecha Inicio Compra</b>: {0}", TxtFechaICompra.Text.ToDate().ToShortDateString());
|
|
if (TxtFechaFCompra.Text != "")
|
|
StrFiltro.AppendFormat(" <b>Fecha Fin Compra</b>: {0}", TxtFechaFCompra.Text.ToDate().ToShortDateString());
|
|
if (DdlProyecto.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Proyecto</b>: {0}", DdlProyecto.SelectedItem.Text);
|
|
if (DdlSubProyecto.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>SubProyecto</b>: {0}", DdlSubProyecto.SelectedItem.Text);
|
|
if (DdlGrupo.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Grupo</b>: {0}", DdlGrupo.SelectedItem.Text);
|
|
if (DdlProveedores.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Proveedor</b>: {0}", DdlProveedores.txtText.Value);
|
|
if (DdlUsuario.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Registro</b>: {0}", DdlUsuario.SelectedItem.Text);
|
|
if (DdlResponsable.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Responsable</b>: {0}", DdlResponsable.SelectedItem.Text);
|
|
if (DdlBanco.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Banco</b>: {0}", DdlBanco.SelectedItem.Text);
|
|
if (DdlCuentaBancaria.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Cuenta Bancaria</b>: {0}", DdlCuentaBancaria.SelectedItem.Text);
|
|
if (DdlMoneda.SelectedValue != "-1")
|
|
StrFiltro.AppendFormat(" <b>Moneda</b>: {0}", DdlMoneda.SelectedItem.Text);
|
|
|
|
string RutaPDF = "";
|
|
string Ruta = UsuarioActual.Empresa.Ruta;
|
|
RutaPDF = $"{Ruta}/Formatos/RepPagadoDetalle.rdlc";
|
|
if (!System.IO.File.Exists(RutaPDF))
|
|
{
|
|
RutaPDF = "Empresas/Grales/Formatos/RepPagadoDetalle.rdlc";
|
|
}
|
|
|
|
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);
|
|
List<ReportParameter> para = new List<ReportParameter>();
|
|
para.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
|
para.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
para.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString()));
|
|
para.Add(new ReportParameter("Filtros", StrFiltro.ToString()));
|
|
para.Add(new ReportParameter("TipoCentroCosto", UsuarioActual.Empresa.Tipo_CentroCosto.ToString()));
|
|
if (Imagen.Exists)
|
|
{
|
|
para.Add(new ReportParameter("LogoPath", logouri));
|
|
}
|
|
else
|
|
{
|
|
para.Add(new ReportParameter("LogoPath", ""));
|
|
}
|
|
ImprimirPDF(RutaPDF, DtPagado, para, "RepPagadoDetalle" + DateTime.Now.ToString("yyyyMMddhhmmss"), Opcion);
|
|
}
|
|
} |