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 Ventas_RepAnticipo_NC_IXCDetalle : 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(); TxtFecha.Text = DateTime.Today.ToString(); TxtFechaFCorte.Text = DateTime.Today.ToString(); CargaSucursales(); CargaClientes(); DdlCliente.SelectedValueExist(Request["CveCliente"] == null ? "-1" : Request["CveCliente"].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(); DdlConSaldo.SelectedValueExist(Request["ConSaldo"] == null ? "-1" : Request["ConSaldo"].ToString()); 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(); CargaVendedores(); if (Request["CveVendedor"]!=null) { DdlVendedor.SelectedValue = Request["CveVendedor"]; } } 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 CargaClientes() { DdlCliente.DataSource = get_GlobalDTCliente(UsuarioActual.CveEmpresa, -1); DdlCliente.DataBind(); DdlCliente.Items.Insert(0, new ListItem("Todos", "-1")); DdlCliente.SelectedValue = "-1"; } protected void CargaVendedores() { DdlVendedor.DataSource = get_GlobalDTVendedores(UsuarioActual.CveEmpresa); DdlVendedor.DataBind(); DdlVendedor.Items.Insert(0, new ListItem("Todos", "-1")); //DdlVendedor.SelectedValueExist(UsuarioActual.CveVendedor); } 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; } ClsVentas ObjVenta = new ClsVentas(); if (ObjVenta.GetRepAnticiposNCIXCDetalle(DdlCliente.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 = ObjVenta.DtResultados; DtDatos = ObjVenta.DtResultados; } ObjVenta.Dispose(); GvDatos.DataBind(); UpDatos.Update(); if (TxtFechaFCorte.Text != DateTime.Now.ToShortDateString() && txtFechaI.Text != "") { LnkHabilitarSaldar.Visible = false; LnkSaldar.Visible = false; } else { LnkHabilitarSaldar.Visible = true; } if (LnkSaldar.Visible) { HabilitarCheckbox(); } 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 = $" Fecha Inicial: {txtFechaI.Text}"; } String FechaF; if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = $" Fecha Final: {txtFechaF.Text}"; } String FechaICorte; if (TxtFechaICorte.Text == "" || TxtFechaICorte.Text == "__/__/____") { FechaICorte = ""; } else { FechaICorte = $" Fecha Inicial Corte: {TxtFechaICorte.Text}"; } String FechaFCorte; if (TxtFechaFCorte.Text == "" || TxtFechaFCorte.Text == "__/__/____") { FechaFCorte = ""; } else { FechaFCorte = $" Fecha Final Corte: {TxtFechaFCorte.Text}"; } String Sucursal; if (DdlSucursal.SelectedValue != "-1") { Sucursal = $" Sucursal: {DdlSucursal.SelectedItem.Text}"; } else { Sucursal = ""; } String Cliente; if (DdlCliente.SelectedValue != "-1") { Cliente = $" Cliente: {DdlCliente.SelectedItem.Text}"; } else { Cliente = ""; } String ConSaldo; if (DdlConSaldo.SelectedValue != "-1") { ConSaldo = $" Con Saldo: {DdlConSaldo.SelectedItem.Text}"; } else { ConSaldo = ""; } String Tipo2; if (DdlTipo.SelectedValue != "-1") { Tipo2 = $" Tipo: {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 para = new List(); 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", $"Agrupado Por: {Cliente}{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-IXCDetalle.rdlc", DtDatos, para, "Reporte de Anticipos - NCXAplicar - IXC 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(); } else if (e.Row.DataKey("CveCliente").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 = "Ingresos X Comprobar"; break; } } else if (e.Row.DataKey("CveVentaAmortizacion").ToEntero() < 1 && e.Row.DataKey("CveVenta").ToEntero() < 1 && e.Row.DataKey("CveIE").ToEntero() < 1) { e.Row.CssClass = "Totales"; e.Row.Cells[2].Text = e.Row.DataKey("NombreComercial"); e.Row.Cells[7].Text = ""; } else if (e.Row.DataKey("CveVentaAmortizacion").ToEntero() < 1 && e.Row.DataKey("CveVenta").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(); if (DdlTipo.SelectedValue.ToEntero() == 1) { e.Row.Cells[4].Text = "$" + e.Row.DataKey("SubTotal").FormatoNumero(); } else if (DdlTipo.SelectedValue.ToEntero() == 2) { e.Row.Cells[4].Text = "$" + e.Row.DataKey("Total").FormatoNumero(); } Liga = $"/Ventas/Ventas.aspx?&CveVenta={e.Row.DataKey("CveVenta")}"; e.Row.Cells[2].Text = "" + e.Row.Cells[2].Text + ""; } else if (e.Row.DataKey("CveIE").ToEntero() > 0 && e.Row.DataKey("CveVentaAmortizacion").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 = "" + e.Row.Cells[2].Text + ""; } 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 = $"/Ventas/Ventas.aspx?&CveVenta={e.Row.DataKey("CveVentaAmortizacion")}"; e.Row.Cells[2].Text = "" + e.Row.Cells[2].Text + ""; } } } #region SALDAR private void HabilitarCheckbox() { foreach (GridViewRow Gv in GvDatos.Rows) { if ((Gv.DataKey("CveVenta").ToEntero() > 0 || Gv.DataKey("CveIE").ToEntero() > 0) && (Gv.DataKey("CveVentaAmortizacion").ToEntero() < 1)) { Gv.FCCheckBox("Chk").Visible = true; } } } protected void LnkHabilitarSaldar_Click(object sender, EventArgs e) { HabilitarCheckbox(); LnkSaldar.Visible = true; LnkHabilitarSaldar.Visible = false; UpLnkAgregar.Update(); UpDatos.Update(); } protected void LnkSaldar_Click(object sender, EventArgs e) { if (Tipo == 1) { TxtConcepto.Text = "Cancelación de Anticipos"; } else if (Tipo == 2) { TxtConcepto.Text = "Cancelación de Saldo de Nota de crédito"; } else if (Tipo == 3) { TxtConcepto.Text = "Cancelación de Ingresos por Comprobar"; } UPModalCort.Update(); RegistraScript("$('#DivModalSaldar').modal();"); } protected void BtnSaldar_Click(object sender, EventArgs e) { ClsContabilidad ObjConta = new ClsContabilidad(); ObjConta.IniciaTransacSQL(); int CvePrePoliza = 0, ConceptoContable1 = 0, ConceptoContable2 = 0, CveVenta = -1, CveIE = -1; decimal Saldo = 0; string MsgError = ""; if (Tipo == 2) { ConceptoContable1 = 91; ConceptoContable2 = 12; } else if (Tipo == 1) { ConceptoContable1 = 11; ConceptoContable2 = 3; } else if (Tipo == 3) { ConceptoContable1 = 92; ConceptoContable2 = 92; } foreach (GridViewRow Gv in GvDatos.Rows) { if (Gv.FCCheckBox("Chk").Checked) { if (Tipo == 1 || Tipo == 2) { CveVenta = Gv.DataKey("CveVenta").ToEntero(); Saldo = -Gv.DataKey("Saldo").ToDecimal(); } else if (Tipo == 3) { CveIE = Gv.DataKey("CveIE").ToEntero(); Saldo = Gv.DataKey("Saldo").ToDecimal(); } int IdCtaContable = 0, CveCuenta = 0; if (ObjConta.GetRetCuenta(ConceptoContable1, Gv.DataKey("CveCliente").ToEntero())) { if (ObjConta.DtResultados.Rows.Count > 0) { if (Tipo == 1 || Tipo == 2) { IdCtaContable = ObjConta.DtResultados.Rows[0]["IdCtaContable"].ToString().ToEntero(); CveCuenta = ObjConta.DtResultados.Rows[0]["IdCtaContableSIG"].ToString().ToEntero(); } else if (Tipo == 3) { IdCtaContable = ObjConta.DtResultados.Rows[0]["IdCtaContClientes"].ToString().ToEntero(); CveCuenta = ObjConta.DtResultados.Rows[0]["CveCuentaCliente"].ToString().ToEntero(); } } } else { break; } CvePrePoliza = ObjConta.AddPrePolizas("Bancos/RepNCXAplicar", 6, Gv.DataKey("Saldo").ToDouble(), Gv.DataKey("Saldo").ToDouble(), Gv.DataKey("CveMoneda").ToEntero(), TxtFecha.Text.ToDate(), "Saldo de NC por Sistema", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa); if (!ObjConta.AddPrePolizasDetalle(CvePrePoliza, true, Saldo, Gv.DataKey("Folio").ToString(), ConceptoContable2, TxtConcepto.Text, TxtFecha.Text.ToDate(), IdCtaContable, -1, CveIE, CveVenta, CveCliente: Gv.DataKey("CveCliente").ToEntero(), ImporteMX: Saldo, CveCuenta: CveCuenta)) { MsgError = "Ocurrio un error al saldar el movimiento"; break; } if (!ObjConta.AddPrePolizasDetalle(CvePrePoliza, true, Gv.DataKey("Saldo").ToDecimal(), Gv.DataKey("Folio").ToString(), 78, TxtConcepto.Text, TxtFecha.Text.ToDate(), UsuarioActual.Empresa.IdCuentaOtrosIngresos, -1, CveIE, CveVenta, ImporteMX: Gv.DataKey("Saldo").ToDecimal(), CveCuenta: -1, CveSubProyecto: Gv.DataKey("CveSubProyecto").ToEntero())) { MsgError = "Ocurrio un error al saldar el movimiento"; break; } } } if (MsgError == "") { ObjConta.Commit(); Alert("Los movimientos se saldaron correctamente."); } else { ObjConta.RollBack(); Alert(MsgError, ModExtensiones.TipoMensaje.MsgError); } LnkSaldar.Visible = false; LnkHabilitarSaldar.Visible = true; CargaDatos(); UpLnkAgregar.Update(); ObjConta.Dispose(); RegistraScript("$('#DivModalSaldar').modal('hide');"); TxtFecha.Text = DateTime.Today.ToString(); UPModalCort.Update(); } #endregion #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 }