284 lines
11 KiB
C#
284 lines
11 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 Ventas_RepNCxAplicar : ClsPaginas
|
|
{
|
|
#region "PROPIEDADES"
|
|
private DataTable DTDatos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTDatos"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DTDatos"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
InicializaDatos();
|
|
}
|
|
}
|
|
|
|
#region "CARGA DATOS"
|
|
protected void InicializaDatos()
|
|
{
|
|
txtFechaI.Text = DateTime.Today.AddDays(-30).ToString();
|
|
txtFechaF.Text = DateTime.Today.ToString();
|
|
TxtFecha.Text = DateTime.Today.ToString();
|
|
TxtConcepto.Text = "Cancelación de Saldo de Nota de crédito";
|
|
|
|
CargaSucursales();
|
|
CargaClientes();
|
|
|
|
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 CargaClientes()
|
|
{
|
|
DdlCliente.DataSource = get_GlobalDTCliente(UsuarioActual.CveEmpresa);
|
|
DdlCliente.DataBind();
|
|
DdlCliente.Items.Insert(0, new ListItem("Todos", "-1"));
|
|
DdlCliente.SelectedValue = "-1";
|
|
}
|
|
|
|
protected void CargaDatos()
|
|
{
|
|
ClsVentas ObjVentas = new ClsVentas();
|
|
|
|
int CveSucursal = -1;
|
|
int CveCliente = DdlCliente.SelectedValue.ToEntero();
|
|
int CveSubProyecto = DdlSucursal.SelectedValue.ToEntero();
|
|
int ConSaldo = DdlConSaldo.SelectedValue.ToEntero();
|
|
|
|
DateTime FechaI = Convert.ToDateTime(txtFechaI.Text);
|
|
DateTime FechaF = Convert.ToDateTime(txtFechaF.Text);
|
|
|
|
|
|
if (ObjVentas.GetRepNCxAplicar(CveSucursal, CveSubProyecto, CveCliente, FechaI, FechaF, ConSaldo, UsuarioActual.CveEmpresa))
|
|
{
|
|
DTDatos = ObjVentas.DtResultados;
|
|
GvDatos.DataSource = DTDatos;
|
|
}
|
|
ObjVentas.Dispose();
|
|
GvDatos.DataBind();
|
|
if (LnkSaldar.Visible) { HabilitarCheckbox(); }
|
|
UPDatos.Update();
|
|
}
|
|
#endregion
|
|
|
|
#region "Botones"
|
|
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (String.IsNullOrEmpty(e.Row.DBCampo("CveVenta")))
|
|
{
|
|
e.Row.CssClass = "SubTotales2";
|
|
e.Row.FCHyperLink("HypClienteFolio").Text = e.Row.DBCampo("NombreComercial");
|
|
e.Row.FCHyperLink("HypClienteFolio").NavigateUrl = string.Format("/Ventas/Clientes.aspx?CveCliente={0}", e.Row.DBCampo("CveCliente"));
|
|
}
|
|
else
|
|
{
|
|
e.Row.FCHyperLink("HypClienteFolio").NavigateUrl = string.Format("/Ventas/Ventas.aspx?CveVenta={0}", e.Row.DBCampo("CveVenta"));
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
#endregion
|
|
|
|
#region "PDF"
|
|
protected void GeneraPDF(string Formato = "PDF")
|
|
{
|
|
List<ReportParameter> @params = new List<ReportParameter>();
|
|
|
|
System.IO.FileInfo Imagen = new System.IO.FileInfo(string.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta));
|
|
var logouri = string.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
|
|
string Sucursal = (DdlSucursal.SelectedValue == "-1" ? "" : $"<b>Sucursal:</b> {DdlSucursal.SelectedItem.Text}");
|
|
string Cliente = (DdlCliente.SelectedValue == "-1" ? "" : $" <b>Cliente:</b> {DdlCliente.SelectedItem.Text}");
|
|
string FechaI = (txtFechaI.Text == "" ? "" : $" <b>Fecha Inicial:</b> {txtFechaI.Text}");
|
|
string FechaF = (txtFechaF.Text == "" ? "" : $" <b>Fecha Final:</b> {txtFechaF.Text}");
|
|
string Saldo = (DdlConSaldo.SelectedValue == "-1" ? "" : $" <b>Con Saldo:</b> {DdlConSaldo.SelectedItem.Text}");
|
|
|
|
@params.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa));
|
|
@params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
@params.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToString()));
|
|
|
|
@params.Add(new ReportParameter("Filtros", $"{Sucursal}{Cliente}{FechaI}{FechaF}{Saldo}"));
|
|
//@params.Add(new ReportParameter("Sucursal", DdlSucursal.SelectedItem.Text));
|
|
//@params.Add(new ReportParameter("Cliente", DdlCliente.SelectedItem.Text));
|
|
//@params.Add(new ReportParameter("FechaInicio", txtFechaI.Text));
|
|
//@params.Add(new ReportParameter("FechaFin", txtFechaF.Text));
|
|
|
|
if (Imagen.Exists)
|
|
{
|
|
@params.Add(new ReportParameter("LogoPath", logouri));
|
|
}
|
|
else
|
|
{
|
|
@params.Add(new ReportParameter("LogoPath", ""));
|
|
}
|
|
|
|
this.ImprimirPDF("Empresas/Grales/Formatos/RepNCxAplicar.rdlc", DTDatos, @params, "Reporte de Notas de Credito por Aplicar", Formato);
|
|
|
|
}
|
|
|
|
protected void LnkImprimirPDF_Click(object sender, EventArgs e)
|
|
{
|
|
GeneraPDF();
|
|
}
|
|
#endregion
|
|
|
|
#region SALDAR
|
|
|
|
private void HabilitarCheckbox()
|
|
{
|
|
|
|
foreach (GridViewRow Gv in GvDatos.Rows)
|
|
{
|
|
if (Gv.DataKey("CveVenta").ToEntero() > 0)
|
|
{
|
|
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)
|
|
{
|
|
RegistraScript("$('#DivModalSaldar').modal();");
|
|
}
|
|
|
|
protected void BtnSaldar_Click(object sender, EventArgs e)
|
|
{
|
|
ClsContabilidad ObjConta = new ClsContabilidad();
|
|
ObjConta.IniciaTransacSQL();
|
|
int CvePrePoliza = 0;
|
|
string MsgError = "";
|
|
bool UsaComplementaria = false;
|
|
if (UsuarioActual.CveEmpresa == 119) UsaComplementaria = true;
|
|
|
|
foreach (GridViewRow Gv in GvDatos.Rows)
|
|
{
|
|
if (Gv.FCCheckBox("Chk").Checked)
|
|
{
|
|
int IdCtaContable = 0;
|
|
if (ObjConta.GetRetCuenta(91, Gv.DataKey("CveCliente").ToEntero()))
|
|
{
|
|
if (ObjConta.DtResultados.Rows.Count > 0)
|
|
{
|
|
|
|
if (Gv.DataKey("CveMoneda").ToEntero() > 1)
|
|
{
|
|
IdCtaContable = ObjConta.DtResultados.Rows[0]["IdCtaContMonedaExtranjera"].ToString().ToEntero();
|
|
}
|
|
else
|
|
{
|
|
IdCtaContable = ObjConta.DtResultados.Rows[0]["IdCtaContable"].ToString().ToEntero();
|
|
}
|
|
|
|
}
|
|
}
|
|
string TextAdicionalJAM = Gv.DataKey("Fecha").ToDate().Year <= 2017 && UsuarioActual.CveEmpresa == 119 ? "Anticipo 2017" : "";
|
|
string ConceptoPartida = string.Format("{0} {1} ", TxtConcepto.Text, Gv.DataKey("Folio").ToString());
|
|
CvePrePoliza = ObjConta.AddPrePolizas("Bancos/RepNCXAplicar", 11, Gv.DataKey("Saldo").ToDouble(), Gv.DataKey("Saldo").ToDouble(), Gv.DataKey("CveMoneda").ToEntero(), TxtFecha.Text.ToDate(), $"{TextAdicionalJAM} {TxtConcepto.Text}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
|
|
|
|
if (!ObjConta.AddPrePolizasDetalle(CvePrePoliza, true, -Gv.DataKey("Saldo").ToDecimal(), Gv.DataKey("Folio").ToString(), 12, TxtConcepto.Text, TxtFecha.Text.ToDate(), IdCtaContable, -1, -1, Gv.DataKey("CveVenta").ToEntero(), CveCliente: Gv.DataKey("CveCliente").ToEntero(), ImporteMX: -Gv.DataKey("Saldo").ToDecimal()))
|
|
{
|
|
MsgError = "Ocurrio un error al saldar el movimiento";
|
|
}
|
|
|
|
if (Gv.DataKey("CveMoneda").ToEntero()>1 && UsaComplementaria)
|
|
{
|
|
if (ObjConta.GetRetCuenta(93, Gv.DataKey("CveCliente").ToEntero()))
|
|
{
|
|
if (ObjConta.DtResultados.Rows.Count > 0)
|
|
{
|
|
IdCtaContable = ObjConta.DtResultados.Rows[0]["IdCtaContable"].ToString().ToEntero();
|
|
}
|
|
}
|
|
if (!ObjConta.AddPrePolizasDetalle(CvePrePoliza, true, -Gv.DataKey("Saldo").ToDecimal(), Gv.DataKey("Folio").ToString(), 203, TxtConcepto.Text, TxtFecha.Text.ToDate(), IdCtaContable, -1, -1, Gv.DataKey("CveVenta").ToEntero(), CveCliente: Gv.DataKey("CveCliente").ToEntero(), ImporteMX: -((Gv.DataKey("Saldo").ToDecimal() * Gv.DataKey("TipoCambioValuacion").ToDecimal()) - Gv.DataKey("Saldo").ToDecimal()), TipoCambio: Gv.DataKey("TipoCambioValuacion").ToString().ToDecimal(), ImporteME: -Gv.DataKey("Saldo").ToDecimal()))
|
|
{
|
|
MsgError = "Ocurrio un error al saldar el movimiento";
|
|
}
|
|
}
|
|
|
|
if (!ObjConta.AddPrePolizasDetalle(CvePrePoliza, true, Gv.DataKey("Saldo").ToDecimal(), Gv.DataKey("Folio").ToString(), 78, TxtConcepto.Text, TxtFecha.Text.ToDate(), UsuarioActual.Empresa.IdCuentaOtrosIngresos, -1, -1, Gv.DataKey("CveVenta").ToEntero(), ImporteMX: Gv.DataKey("Saldo").ToDecimal() * Gv.DataKey("TipoCambioValuacion").ToDecimal(), CveCuenta: -1))
|
|
{
|
|
MsgError = "Ocurrio un error al saldar el movimiento";
|
|
}
|
|
|
|
if (ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, -1))
|
|
{
|
|
if (ObjConta.ValorPolizaDescuadre > 0)
|
|
{
|
|
MsgError = ObjConta.MensajePolizaDescuadre;
|
|
$"Bancos/RepNCXAplicar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}".GuardaLogAD("LogPrePolizas");
|
|
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();
|
|
TxtConcepto.Text = "Cancelación de Saldo de Nota de crédito";
|
|
UPModalCort.Update();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|