371 lines
15 KiB
C#
371 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.Activities.Expressions;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
public partial class Contabilidad_RepIVA : ClsPaginas
|
|
{
|
|
#region PROPIEDADES
|
|
|
|
private DataTable DtIVATrasladado
|
|
{
|
|
get { return DtIVATrasladado = (DataTable)ViewState["DtIVATrasladado"]; }
|
|
set { ViewState["DtIVATrasladado"] = value; }
|
|
}
|
|
private DataTable DtIVAAcreditable
|
|
{
|
|
get { return DtIVAAcreditable = (DataTable)ViewState["DtIVAAcreditable"]; }
|
|
set { ViewState["DtIVAAcreditable"] = value; }
|
|
}
|
|
private DataTable DtIEPSA
|
|
{
|
|
get { return DtIVAAcreditable = (DataTable)ViewState["DtIEPSA"]; }
|
|
set { ViewState["DtIEPSA"] = value; }
|
|
}
|
|
private DataTable DtIVAA
|
|
{
|
|
get { return DtIVAAcreditable = (DataTable)ViewState["DtIVAA"]; }
|
|
set { ViewState["DtIVAA"] = 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)
|
|
{
|
|
InicializaValores();
|
|
|
|
}
|
|
}
|
|
|
|
public void InicializaValores()
|
|
{
|
|
TipoCambio = 1;
|
|
TCEspecifico = -1;
|
|
txtFechaI.Text = $"01/{DateTime.Now.Month}/{DateTime.Now.Year}";
|
|
txtFechaF.Text = DateTime.Now.ToShortDateString();
|
|
|
|
LnkAccionesDIOT.Visible = true;
|
|
|
|
}
|
|
|
|
public void Consulta()
|
|
{
|
|
if (TipoCambio == 3 && TxtEspecifico.Text != "") { TCEspecifico = TxtEspecifico.Text.ToDouble(); } else { TCEspecifico = -1; }
|
|
int Conciliado = DdlTipoMovto.SelectedValue.ToEntero();
|
|
LblMsgAcreditable.Text = ""; // lbl de mensajes de negativos
|
|
|
|
ClsContabilidad ObjCont = new ClsContabilidad();
|
|
if (ObjCont.GetRepIVA(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), 1, UsuarioActual.CveUsuario, -1, Conciliado, UsuarioActual.CveEmpresa, TipoCambio, TCEspecifico))
|
|
{
|
|
GvT.DataSource = ObjCont.DtResultados;
|
|
DtIVATrasladado = ObjCont.DtResultados;
|
|
if (ObjCont.GetRepIVAAcumulado(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), Conciliado, 1, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
GvIEPSA.DataSource = ObjCont.DtResultados;
|
|
DtIEPSA = ObjCont.DtResultados;
|
|
}
|
|
|
|
if (ObjCont.GetRepIVAAcumulado(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), Conciliado, 2, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
GvIVAA.DataSource = ObjCont.DtResultados;
|
|
DtIVAA = ObjCont.DtResultados;
|
|
}
|
|
|
|
}
|
|
if (ObjCont.GetRepIVA(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), 2, UsuarioActual.CveUsuario, -1, Conciliado, UsuarioActual.CveEmpresa, TipoCambio, TCEspecifico))
|
|
{
|
|
GvA.DataSource = ObjCont.DtResultados;
|
|
DtIVAAcreditable = ObjCont.DtResultados;
|
|
if (DtIVAAcreditable.FiltraParametros("IVA < 0 OR IEPS < 0 ").Rows.Count > 0)
|
|
{
|
|
LblMsgAcreditable.Text = "La información presenta importes en negativo, estos no se incluirán en el archivo generado para DIOT";
|
|
}
|
|
|
|
|
|
if (ObjCont.GetRepIVAAcumulado(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), Conciliado, 3, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
GvIVA2.DataSource = ObjCont.DtResultados;
|
|
}
|
|
|
|
|
|
}
|
|
ObjCont.Dispose();
|
|
GvT.DataBind();
|
|
GvA.DataBind();
|
|
GvIEPSA.DataBind();
|
|
GvIVAA.DataBind();
|
|
GvIVA2.DataBind();
|
|
UpDatos.Update();
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
Consulta();
|
|
}
|
|
|
|
protected void GvIVATrasladado_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DBCampo("CveVenta").ToEntero() < 1)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvIVAAcreditable_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DBCampo("CveCompra").ToEntero() < 1)
|
|
{
|
|
e.Row.CssClass = "Totales";
|
|
}
|
|
if (e.Row.DBCampo("PorcentajeIVA").ToDecimal() > 0)
|
|
{
|
|
Decimal SubTotal = (e.Row.DBCampo("SubTotal16").ToDecimal() > 0 ? e.Row.DBCampo("SubTotal16").ToDecimal() : (e.Row.DBCampo("SubTotal8").ToDecimal() > 0 ? e.Row.DBCampo("SubTotal8").ToDecimal() : (Decimal)0.0));
|
|
|
|
Decimal dif = Math.Round(SubTotal * e.Row.DBCampo("PorcentajeIVA").ToDecimal(), 2) - Math.Round(e.Row.DBCampo("IVA").ToDecimal() + Math.Round(e.Row.DBCampo("IVANoDeducible").ToDecimal()), 2);
|
|
if (dif > 1)
|
|
{
|
|
e.Row.ForeColor = System.Drawing.Color.Red;
|
|
e.Row.Cells[0].Text = e.Row.Cells[0].Text + "Err";
|
|
|
|
e.Row.ToolTip = "Dif:" + dif.ToString() + "- Sub:" + SubTotal + " - IVA:" + e.Row.DBCampo("IVA");
|
|
}
|
|
}
|
|
if (e.Row.DBCampo("IVA").ToDecimal() < 0 || e.Row.DBCampo("IEPS").ToDecimal() < 0 || e.Row.DBCampo("SubTotal16").ToDecimal() < 0 || e.Row.DBCampo("SubTotal8").ToDecimal() < 0 || e.Row.DBCampo("valorActosImp0").ToDecimal() < 0)
|
|
{
|
|
e.Row.ForeColor = System.Drawing.Color.Red;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void LnkPdf_Click(object sender, EventArgs e)
|
|
{
|
|
Imprimir("PDF");
|
|
}
|
|
|
|
protected void LnkExcel_Click(object sender, EventArgs e)
|
|
{
|
|
Imprimir("EXCEL");
|
|
}
|
|
protected void LnkExcel2_Click(object sender, EventArgs e)
|
|
{
|
|
Imprimir("EXCEL2");
|
|
}
|
|
|
|
public void Imprimir(String Opcion)
|
|
{
|
|
String FechaF;
|
|
if (txtFechaF.Text == "" || txtFechaF.Text == "__/__/____") { FechaF = "-1"; } else { FechaF = $" <b>Fecha Final:</b> {txtFechaF.Text}"; }
|
|
String FechaI;
|
|
if (txtFechaI.Text == "" || txtFechaI.Text == "__/__/____") { FechaI = "-1"; } else { FechaI = $" <b>Fecha Inicial:</b> {txtFechaI.Text}"; }
|
|
if (DtIVATrasladado.Rows.Count > 0 || DtIVAAcreditable.Rows.Count > 0)
|
|
{
|
|
System.IO.FileInfo Imagen;
|
|
String logouri = "";
|
|
|
|
if (UsuarioActual.CveEmpresa.Contiene(119))
|
|
{
|
|
Imagen = new System.IO.FileInfo(String.Format("{0}/Logo.jpg", UsuarioActual.Empresa.Ruta));
|
|
logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.jpg", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
}
|
|
else
|
|
{
|
|
Imagen = new System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta));
|
|
logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
}
|
|
|
|
List<CrystalParametro> para = new List<CrystalParametro>();
|
|
para.Add(new CrystalParametro("Empresa", UsuarioActual.Empresa.Empresa));
|
|
para.Add(new CrystalParametro("UsuarioImprimio", UsuarioActual.Nombre));
|
|
para.Add(new CrystalParametro("Filtros", $"<b>Filtros:</b> {FechaI}{FechaF}"));
|
|
if (Imagen.Exists)
|
|
{
|
|
para.Add(new CrystalParametro("LogoPath", logouri));
|
|
}
|
|
else
|
|
{
|
|
para.Add(new CrystalParametro("LogoPath", ""));
|
|
}
|
|
|
|
DataTable Dt = TT.ActiveTabIndex == 0 ? DtIVATrasladado.Copy() : DtIVAAcreditable.Copy();
|
|
string Formato = TT.ActiveTabIndex == 0 ? "RepIVA.rpt" : (Opcion == "EXCEL2" ? "RepIVAAcreditable2.rpt" : "RepIVAAcreditable.rpt");
|
|
Opcion = (Opcion == "EXCEL2" ? "EXCEL" : Opcion);
|
|
para.Add(new CrystalParametro("Excel", Formato));
|
|
System.IO.FileInfo Archivo = new System.IO.FileInfo(string.Format("{0}/Formatos/{1}", UsuarioActual.Empresa.Ruta, Formato));
|
|
string Ruta;// = (Archivo.Exists ? string.Format("{0}/{1}", UsuarioActual.Empresa.Ruta, Formato ): ModExtensiones.DirectorioBaseEmpresas + $@"Empresas\Grales\Formatos\{Formato}");
|
|
|
|
Alert(string.Format("{0}/Formatos/{1}", UsuarioActual.Empresa.Ruta, Formato));
|
|
if (Archivo.Exists)
|
|
{
|
|
Ruta = string.Format("{0}/Formatos/{1}", UsuarioActual.Empresa.Ruta, Formato);
|
|
ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion);
|
|
}else
|
|
{
|
|
Ruta = ModExtensiones.DirectorioBaseEmpresas + $@"Empresas\Grales\Formatos\{Formato}";
|
|
ImprimirbytesPDF(ImprimirSubRepPDFCrystal(Ruta,Dt,para, DtIEPSA,DtIVAA,"RepIEPSPorcentaje.rpt","RepIVAPorcentaje.rpt", "Reporte de IVA", Opcion), "Reporte de IVA", Opcion);
|
|
}
|
|
Ruta.GuardaLogAD();
|
|
//ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion);
|
|
}
|
|
else
|
|
{
|
|
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
|
|
protected void BtnTipoCambio_Click(object sender, EventArgs e)
|
|
{
|
|
Consulta();
|
|
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();
|
|
}
|
|
|
|
|
|
protected string GenerarDIOT()
|
|
{
|
|
System.Text.StringBuilder Respuesta = new System.Text.StringBuilder();
|
|
|
|
|
|
|
|
return Respuesta.ToString();
|
|
}
|
|
|
|
protected void LnkAccionesDIOT_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
ClsContabilidad Objconta = new ClsContabilidad();
|
|
StringBuilder SBDIOT = new StringBuilder();
|
|
int Conciliado = DdlTipoMovto.SelectedValue.ToEntero();
|
|
|
|
if (Objconta.GetRepIVA(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), 2, UsuarioActual.CveUsuario, -1, Conciliado, UsuarioActual.CveEmpresa, TipoCambio, TCEspecifico))
|
|
{
|
|
|
|
foreach (DataRow Drow in Objconta.DtResultados.FiltraParametros("CveCompra is null and CveProveedor > 0 and SubTotal >= 1 ").Rows) // and(IVA > 1 OR IEPS > 0)
|
|
{
|
|
SBDIOT.AppendLine(
|
|
Drow["TipoTercero"].ToString() + "|" +
|
|
Drow["TipoOperacion"].ToString() + "|" +
|
|
Drow["RFC"].ToString() + "|" +
|
|
Drow["NumeroIDFiscal"].ToString() + "|" +
|
|
Drow["NombreExtranjero"].ToString() + "|" +
|
|
Drow["PaisResidencia"].ToString() + "|" +
|
|
Drow["Nacionalidad"].ToString() + "|" +
|
|
LV(Drow["valorActos1516"].ToString()) + "|" +
|
|
LV(Drow["valorActos15"].ToString()) + "|" +
|
|
LV(Drow["ValorIvaNo1516"].ToString()) + "|" +
|
|
|
|
LV(Drow["valorActos1011"].ToString()) + "|" +
|
|
LV(Drow["valorActos10"].ToString()) + "|" +
|
|
LV(Drow["valorActosImp8"].ToString()) + "|" +
|
|
LV(Drow["ValorIvaNo10"].ToString()) + "|" +
|
|
LV(Drow["ValorIvaNo08"].ToString()) + "|" +
|
|
|
|
LV(Drow["valorActosImp1516"].ToString()) + "|" +
|
|
LV(Drow["ValorIvaNoImp16"].ToString()) + "|" +
|
|
|
|
LV(Drow["valorActosImp10"].ToString()) + "|" +
|
|
LV(Drow["ValorIvaNoImp10"].ToString()) + "|" +
|
|
|
|
LV(Drow["IvaExentoImpo"].ToString()) + "|" +
|
|
LV(Drow["IVACero"].ToString()) + "|" +
|
|
LV(Drow["IvaExento"].ToString()) + "|" +
|
|
LV(Drow["IvaRetenido"].ToString()) + "|" +
|
|
LV(Drow["IvaDevoluciones"].ToString()) + "|");
|
|
}
|
|
}
|
|
|
|
Objconta.Dispose();
|
|
|
|
//MemoryStream ms = new MemoryStream();
|
|
//TextWriter tw = new StreamWriter(ms, System.Text.Encoding.UTF8);
|
|
|
|
//tw.Write(SBDIOT.ToString());
|
|
|
|
//tw.Flush();
|
|
|
|
//byte[] bytes = ms.ToArray();
|
|
//ms.Close();
|
|
|
|
//Response.Clear();
|
|
//Response.AppendHeader("Content-Length", text.Length.ToString());
|
|
//Response.ContentType = "text/plain";
|
|
//Response.AddHeader("content-disposition", $"attachment; filename=DIOT_{ txtFechaI.Text.ToDate().ToString("ddMMyyyy") }_{txtFechaI.Text.ToDate().ToString("ddMMyyyy") }.txt");
|
|
//Response.BinaryWrite(bytes);
|
|
//Response.End();
|
|
|
|
Response.Clear();
|
|
Response.ClearHeaders();
|
|
|
|
Response.AppendHeader("Content-Length", SBDIOT.ToString().Length.ToString());
|
|
Response.ContentType = "text/plain";
|
|
Response.AppendHeader("Content-Disposition", $"attachment;filename=DIOT_{ txtFechaI.Text.ToDate().ToString("ddMMyyyy") }_{txtFechaI.Text.ToDate().ToString("ddMMyyyy") }.txt");
|
|
|
|
Response.Write(SBDIOT.ToString());
|
|
Response.End();
|
|
}
|
|
|
|
|
|
|
|
protected void LnkModalCompara_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
ClsContabilidad Objconta = new ClsContabilidad();
|
|
|
|
int Conciliado = DdlTipoMovto.SelectedValue.ToEntero();
|
|
|
|
if (Objconta.GetRepIVAComparativo(txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), UsuarioActual.CveUsuario, -1, Conciliado, UsuarioActual.CveEmpresa ))
|
|
{
|
|
GvCompara.DataSource = Objconta.DtResultados;
|
|
}
|
|
|
|
Objconta.Dispose();
|
|
GvCompara.DataBind();
|
|
RegistraScript("$('#ModalCompara').modal('show')");
|
|
UpCompara.Update();
|
|
}
|
|
|
|
|
|
protected string LV(string Valor)
|
|
{
|
|
return (Valor.ToDecimal() > 0) ? Valor.ToDecimal().ToString().FormatoNumero(0).Replace(",", string.Empty) : "";
|
|
}
|
|
} |