Files
SIG/Compras/RepAnt-NC-EXCDetalle.aspx.cs
JORGE LUIS CAUDILLO ESPARZA c35cf91883 Commit inicial Ventas Productivo
2019-08-14 16:40:54 -07:00

267 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Extensiones;
using Microsoft.Reporting.WebForms;
public partial class Compras_RepAnt_NC_EXCDetalle : ClsPaginas
{
#region PROPIEDADES
private DataTable DtDatos
{
get { return DtDatos = (DataTable)ViewState["DtDatos"]; }
set { ViewState["DtDatos"] = value; }
}
private int Tipo
{
get { return Tipo = (int)ViewState["Tipo"]; }
set { ViewState["Tipo"] = value; }
}
private int CveMoneda
{
get { return CveMoneda = (int)ViewState["CveMoneda"]; }
set { ViewState["CveMoneda"] = value; }
}
private double TCEspecifico
{
get { return TCEspecifico = (double)ViewState["TCEspecifico"]; }
set { ViewState["TCEspecifico"] = value; }
}
private int TipoCambio
{
get { return TipoCambio = (int)ViewState["TipoCambio"]; }
set { ViewState["TipoCambio"] = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InicializaDatos();
}
}
protected void InicializaDatos()
{
txtFechaI.Text = "01/01/2000";
txtFechaF.Text = DateTime.Today.ToString();
TxtFechaFCorte.Text = DateTime.Today.ToString();
CargaSucursales();
CargaProveedores();
DdlProveedor.SelectedValueExist(Request["CveProveedor"] == null ? "-1" : Request["CveProveedor"].ToString());
DdlSucursal.SelectedValueExist(Request["CveSubProyecto"] == null ? "-1" : Request["CveSubProyecto"].ToString());
DdlTipo.SelectedValueExist(Request["Tipo"] == null ? "-1" : Request["Tipo"].ToString());
CveMoneda = Request["CveMoneda"] == null ? -1 : Request["CveMoneda"].ToString().ToEntero();
txtFechaI.Text = Request["FechaI"] == null ? DateTime.Now.ToString() : Request["FechaI"].ToString();
txtFechaF.Text = Request["FechaF"] == null ? DateTime.Now.ToString() : Request["FechaF"].ToString();
TipoCambio = Request["TipoCambio"] == null ? 1 : Request["TipoCambio"].ToString().ToEntero();
TCEspecifico = Request["TCEspecifico"] == null ? -1 : Request["TCEspecifico"].ToString().ToDouble();
RblTipoCambio.SelectedValue = TipoCambio.ToString();
LiEspecifico.InnerText = TCEspecifico.FormatoNumero();
DateTime FechaICorte;
FechaICorte = Request["FechaICorte"] == null ? DateTime.MinValue : Request["FechaICorte"].ToString().ToDate();
if (FechaICorte <= DateTime.MinValue) { TxtFechaICorte.Text = ""; } else { TxtFechaICorte.Text = FechaICorte.ToShortDateString(); }
DateTime FechaFCorte;
FechaFCorte = Request["FechaFCorte"] == null ? DateTime.MaxValue : Request["FechaFCorte"].ToString().ToDate();
if (FechaFCorte >= DateTime.MaxValue) { TxtFechaFCorte.Text = ""; } else { TxtFechaFCorte.Text = FechaFCorte.ToShortDateString(); }
CargaDatos();
}
protected void CargaSucursales()
{
DdlSucursal.DataSource = get_GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa);
DdlSucursal.DataBind();
DdlSucursal.Items.Insert(0, new ListItem("Todos", "-1"));
DdlSucursal.SelectedValue = "-1";
}
protected void CargaProveedores()
{
DdlProveedor.DataSource = get_GlobalDTCompProveedores(UsuarioActual.CveEmpresa);
DdlProveedor.DataBind();
DdlProveedor.Items.Insert(0, new ListItem("Todos", "-1"));
DdlProveedor.SelectedValue = "-1";
}
protected void CargaDatos()
{
if (TipoCambio == 3 && TxtEspecifico.Text != "") { TCEspecifico = TxtEspecifico.Text.ToDouble(); } else { TCEspecifico = -1; }
if (TipoCambio != 1) { CveMoneda = -1; }
DateTime FechaICorte;
if (TxtFechaICorte.Text != "") { FechaICorte = TxtFechaICorte.Text.ToDate(); } else { FechaICorte = DateTime.MinValue; }
DateTime FechaFCorte;
if (TxtFechaFCorte.Text != "") { FechaFCorte = TxtFechaFCorte.Text.ToDate(); } else { FechaFCorte = DateTime.MaxValue; }
ClsCompras ObjCompra = new ClsCompras();
if (ObjCompra.GetRepAnticiposNCEXCDetalle(DdlProveedor.SelectedValue.ToEntero(), DdlSucursal.SelectedValue.ToEntero(), txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(),
UsuarioActual.CveEmpresa, DdlConSaldo.SelectedValue.ToEntero(), DdlTipo.SelectedValue.ToEntero(), CveMoneda, FechaICorte, FechaFCorte, TipoCambio, TCEspecifico))
{
GvDatos.DataSource = ObjCompra.DtResultados;
DtDatos = ObjCompra.DtResultados;
}
ObjCompra.Dispose();
GvDatos.DataBind();
UpDatos.Update();
Tipo = DdlTipo.SelectedValue.ToEntero();
}
protected void BtnConsultar_Click(object sender, EventArgs e)
{
CargaDatos();
}
protected void LnkExcel_Click(object sender, EventArgs e)
{
GenerarPDF("EXCEL");
}
protected void LnkPdf_Click(object sender, EventArgs e)
{
GenerarPDF("PDF");
}
protected void GenerarPDF(String Opcion)
{
String FechaI;
if (txtFechaI.Text == "" || txtFechaI.Text == "__/__/____") { FechaI = "-1"; } else { FechaI = $"&emsp;<b>Fecha Inicial:</b> {txtFechaI.Text}"; }
String FechaF;
if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = $"&emsp;<b>Fecha Final:</b> {txtFechaF.Text}"; }
String FechaICorte;
if (TxtFechaICorte.Text == "" || TxtFechaICorte.Text == "__/__/____") { FechaICorte = ""; } else { FechaICorte = $"&emsp;<b>Fecha Inicial Corte:</b> {TxtFechaICorte.Text}"; }
String FechaFCorte;
if (TxtFechaFCorte.Text == "" || TxtFechaFCorte.Text == "__/__/____") { FechaFCorte = ""; } else { FechaFCorte = $"&emsp;<b>Fecha Final Corte:</b> {TxtFechaFCorte.Text}"; }
String Sucursal;
if (DdlSucursal.SelectedValue != "-1") { Sucursal = $"&emsp;<b>Sucursal:</b> {DdlSucursal.SelectedItem.Text}"; } else { Sucursal = ""; }
String Proveedor;
if (DdlProveedor.SelectedValue != "-1") { Proveedor = $"&emsp;<b>Cliente:</b> {DdlProveedor.SelectedItem.Text}"; } else { Proveedor = ""; }
String ConSaldo;
if (DdlConSaldo.SelectedValue != "-1") { ConSaldo = $"&emsp;<b>Con Saldo:</b> {DdlConSaldo.SelectedItem.Text}"; } else { ConSaldo = ""; }
String Tipo2;
if (DdlTipo.SelectedValue != "-1") { Tipo2 = $"&emsp;<b>Tipo:</b> {DdlTipo.SelectedItem.Text}"; } else { Tipo2 = ""; }
if (DtDatos.Rows.Count > 0)
{
System.IO.FileInfo Imagen = new System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta));
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.ToString()));
para.Add(new ReportParameter("Tipo", Tipo.ToString()));
para.Add(new ReportParameter("AgrupadoPor", $"<b>Agrupado Por:</b> {Proveedor}{Sucursal}{ConSaldo}{Tipo2}{FechaI}{FechaF}{FechaICorte}{FechaFCorte}"));
if (Imagen.Exists)
{
para.Add(new ReportParameter("LogoPath", logouri));
}
else
{
para.Add(new ReportParameter("LogoPath", ""));
}
ImprimirPDF("Empresas/Grales/Formatos/RepAnt-NC-EXCDetalle.rdlc", DtDatos, para, "Reporte de Anticipos - NCXAplicar - EXC Detalle", Opcion);
}
else
{
Alert("No hay datos consultados", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
String Css = "Texto";
String Liga = "";
if (e.Row.DataKey("Tipo").ToEntero() < 1)
{
e.Row.CssClass = "SubTotales3";
e.Row.Cells[2].Text = e.Row.DBCampo("Moneda").ToString();
e.Row.Cells[4].Text = "$" + e.Row.DataKey("Total").FormatoNumero();
}
else if (e.Row.DataKey("CveProveedor").ToEntero() < 1)
{
e.Row.CssClass = "SubTotales2";
switch (e.Row.DataKey("Tipo").ToEntero())
{
case 1:
e.Row.Cells[2].Text = "Anticipos";
break;
case 2:
e.Row.Cells[2].Text = "NC X Aplicar";
break;
case 3:
e.Row.Cells[2].Text = "Egresos X Comprobar";
break;
}
e.Row.Cells[4].Text = "$" + e.Row.DataKey("Total").FormatoNumero();
}
else if (e.Row.DataKey("CveCompraAmortizacion").ToEntero() < 1 && e.Row.DataKey("CveCompra").ToEntero() < 1 && e.Row.DataKey("CveIE").ToEntero() < 1)
{
e.Row.CssClass = "Totales";
e.Row.Cells[2].Text = e.Row.DataKey("RazonSocial");
e.Row.Cells[7].Text = "";
e.Row.Cells[4].Text = "$" + e.Row.DataKey("Total").FormatoNumero();
}
else if (e.Row.DataKey("CveCompraAmortizacion").ToEntero() < 1 && e.Row.DataKey("CveCompra").ToEntero() > 0)
{
e.Row.CssClass = "SubTotales";
e.Row.Cells[2].Text = e.Row.DataKey("SerieFolio");
e.Row.Cells[3].Text = e.Row.DataKey("Fecha").ToDate().ToShortDateString();
e.Row.Cells[4].Text = "$" + e.Row.DataKey("Total").FormatoNumero();
Liga = $"/Compras/Compras.aspx?&CveCompra={e.Row.DataKey("CveCompra")}";
e.Row.Cells[2].Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.Cells[2].Text + "</a>";
}
else if (e.Row.DataKey("CveIE").ToEntero() > 0 && e.Row.DataKey("CveCompraAmortizacion").ToEntero() < 1)
{
e.Row.CssClass = "SubTotales";
e.Row.Cells[2].Text = e.Row.DataKey("SerieFolio");
e.Row.Cells[3].Text = e.Row.DataKey("Fecha").ToDate().ToShortDateString();
e.Row.Cells[4].Text = "$" + e.Row.DataKey("Total").FormatoNumero();
Liga = $"/Bancos/IE.aspx?&CveIE={e.Row.DataKey("CveIE")}";
e.Row.Cells[2].Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.Cells[2].Text + "</a>";
}
else
{
e.Row.Cells[2].Text = e.Row.DataKey("SerieFolioAmortizacion");
e.Row.Cells[3].Text = e.Row.DataKey("FechaAmortizacion").ToDate().ToShortDateString();
e.Row.Cells[4].Text = "$" + e.Row.DataKey("ImporteAmortizacion").FormatoNumero();
e.Row.Cells[5].Text = "$" + e.Row.DataKey("ImporteAmortizacion").FormatoNumero();
e.Row.Cells[6].Text = "$" + e.Row.DataKey("SaldoAcumulativo").FormatoNumero();
Liga = $"/Compras/Compras.aspx?&CveCompra={e.Row.DataKey("CveCompraAmortizacion")}";
e.Row.Cells[2].Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.Cells[2].Text + "</a>";
}
}
}
#region TIPO DE CAMBIO
protected void BtnTipoCambio_Click(object sender, EventArgs e)
{
CargaDatos();
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivTipoCambio"));
}
protected void RblTipoCambio_SelectedIndexChanged(object sender, EventArgs e)
{
TipoCambio = RblTipoCambio.SelectedValue.ToEntero();
if (TipoCambio == 3)
{
LiEspecifico.Visible = true;
TCEspecifico = get_GlobalTipoCambio(DateTime.Now).ToString().ToDouble();
TxtEspecifico.Text = TCEspecifico.ToString();
}
else
{
LiEspecifico.Visible = false;
}
UpBodyTipoCambio.Update();
}
#endregion
}