que tenga folio fiscal

This commit is contained in:
2020-12-29 17:40:05 -07:00
parent 7726177eda
commit 65f3181806

View File

@@ -1,47 +1,47 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.ServiceModel; using System.ServiceModel;
using System.Text; using System.Text;
using System.Web; using System.Web;
using System.Web.UI; using System.Web.UI;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using Extensiones; using Extensiones;
using static Extensiones.ModExtensiones; using static Extensiones.ModExtensiones;
using Microsoft.Reporting.WebForms; using Microsoft.Reporting.WebForms;
public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
{ {
private DataTable DtVentas private DataTable DtVentas
{ {
get { return (ViewState["DtVentas"] == null) ? null : (DataTable)ViewState["DtVentas"]; } get { return (ViewState["DtVentas"] == null) ? null : (DataTable)ViewState["DtVentas"]; }
set { ViewState["DtVentas"] = value; } set { ViewState["DtVentas"] = value; }
} }
private int CveVenta private int CveVenta
{ {
get { return (ViewState["CveVenta"] == null) ? -1 : ViewState["CveVenta"].ToString().ToEntero(); } get { return (ViewState["CveVenta"] == null) ? -1 : ViewState["CveVenta"].ToString().ToEntero(); }
set { ViewState["CveVenta"] = value; } set { ViewState["CveVenta"] = value; }
} }
protected void Page_Load(object sender, EventArgs e) protected void Page_Load(object sender, EventArgs e)
{ {
if (!IsPostBack) if (!IsPostBack)
{ {
CargaDatos(); CargaDatos();
} }
} }
private void CargaDatos() private void CargaDatos()
{ {
HdnLigaRefacturar.Value = ""; HdnLigaRefacturar.Value = "";
if (Request["CveVenta"] != null) if (Request["CveVenta"] != null)
{ {
this.CveVenta = Request["CveVenta"].ToString().ToEntero(); this.CveVenta = Request["CveVenta"].ToString().ToEntero();
} }
var ObjVentas = new ClsVentas(); var ObjVentas = new ClsVentas();
if (ObjVentas.GetVentas(UsuarioActual.CveEmpresa, "-1", "-1", -1, "-1", -1, -1, -2, -1, "-1", "-1", "-1", CveUsuarioConsulta: UsuarioActual.CveUsuario)) if (ObjVentas.GetVentas(UsuarioActual.CveEmpresa, "-1", "-1", -1, "-1", -1, -1, -2, -1, "-1", "-1", "-1", CveUsuarioConsulta: UsuarioActual.CveUsuario))
{ {
if (Request["CveVenta"] != null && Request["CveVenta"].ToString().ToEntero() > 0) if (Request["CveVenta"] != null && Request["CveVenta"].ToString().ToEntero() > 0)
@@ -51,42 +51,42 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
else else
{ {
DtVentas = ObjVentas.DtResultados.Copy(); DtVentas = ObjVentas.DtResultados.Copy();
} }
} }
ObjVentas.Dispose(); ObjVentas.Dispose();
GvDatos.DataSource = DtVentas.FiltraParametros("CveEstatusFactura = 20 AND CveEstatusRefacturacion = 0"); GvDatos.DataSource = DtVentas.FiltraParametros("CveEstatusFactura = 20 AND CveEstatusRefacturacion = 0");
var DtRefacturar = DtVentas.FiltraParametros("CveEstatusRefacturacion IN (1,3)"); var DtRefacturar = DtVentas.FiltraParametros("CveEstatusRefacturacion IN (1,3)");
if (DtRefacturar != null && DtRefacturar.Rows.Count > 0) if (DtRefacturar != null && DtRefacturar.Rows.Count > 0)
{ {
DivRefacturar.Visible = true; DivRefacturar.Visible = true;
GvRefacturaciones.DataSource = DtRefacturar; GvRefacturaciones.DataSource = DtRefacturar;
GvRefacturaciones.DataBind(); GvRefacturaciones.DataBind();
} }
GvDatos.DataBind(); GvDatos.DataBind();
UPDatos.Update(); UPDatos.Update();
} }
protected void BtnValidar_Click(object sender, EventArgs e) protected void BtnValidar_Click(object sender, EventArgs e)
{ {
this.HdnLigaRefacturar.Value = ""; this.HdnLigaRefacturar.Value = "";
this.CveVenta = -1; this.CveVenta = -1;
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
this.CveVenta = GvRow.DataKey("CveVenta").ToEntero(); this.CveVenta = GvRow.DataKey("CveVenta").ToEntero();
int CveCliente = GvRow.DataKey("CveCliente").ToEntero(); int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
string Total = GvRow.DataKey("Total"); string Total = GvRow.DataKey("Total");
string SubTotal = GvRow.DataKey("SubTotal"); string SubTotal = GvRow.DataKey("SubTotal");
string Uuid = GvRow.DataKey("FolioFiscal"); string Uuid = GvRow.DataKey("FolioFiscal");
string RFCCliente = GvRow.DataKey("RFCCliente"); string RFCCliente = GvRow.DataKey("RFCCliente");
string Folio = GvRow.DataKey("Folio"); string Folio = GvRow.DataKey("Folio");
string TipoDocto = GvRow.DataKey("TipoDocto"); string TipoDocto = GvRow.DataKey("TipoDocto");
string Nombre = GvRow.DataKey("Nombre"); string Nombre = GvRow.DataKey("Nombre");
if (CveVenta > 0) if (CveVenta > 0 && Uuid != "")
{ {
var resp = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCCliente, Total); var resp = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCCliente, Total);
if (resp.EnviarAcuse) if (resp.EnviarAcuse)
{ {
Alert(resp.Mensaje,TipoMensaje.MsgConfirmacion,"BtnEnviarMailCancelacion();"); Alert(resp.Mensaje,TipoMensaje.MsgConfirmacion,"BtnEnviarMailCancelacion();");
@@ -94,30 +94,31 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
else else
{ {
Alert(resp.Mensaje); Alert(resp.Mensaje);
} }
} }
CargaDatos(); CargaDatos();
} }
protected void BtnValidarRefacturacion_Click(object sender, EventArgs e) protected void BtnValidarRefacturacion_Click(object sender, EventArgs e)
{ {
this.HdnLigaRefacturar.Value = ""; this.HdnLigaRefacturar.Value = "";
this.CveVenta = -1; this.CveVenta = -1;
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
this.CveVenta = GvRow.DataKey("CveVenta").ToEntero(); this.CveVenta = GvRow.DataKey("CveVenta").ToEntero();
int CveCliente = GvRow.DataKey("CveCliente").ToEntero(); int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
string Total = GvRow.DataKey("Total"); string Total = GvRow.DataKey("Total");
string SubTotal = GvRow.DataKey("SubTotal"); string SubTotal = GvRow.DataKey("SubTotal");
string Uuid = GvRow.DataKey("FolioFiscal"); string Uuid = GvRow.DataKey("FolioFiscal");
string RFCCliente = GvRow.DataKey("RFCCliente"); string RFCCliente = GvRow.DataKey("RFCCliente");
string Folio = GvRow.DataKey("Folio"); string Folio = GvRow.DataKey("Folio");
string TipoDocto = GvRow.DataKey("TipoDocto"); string TipoDocto = GvRow.DataKey("TipoDocto");
string Nombre = GvRow.DataKey("Nombre"); string Nombre = GvRow.DataKey("Nombre");
if (CveVenta > 0)
{ if (CveVenta > 0 && Uuid != "")
{
var respuesta = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCCliente, Total, true); var respuesta = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCCliente, Total, true);
CargaDatos(); CargaDatos();
if (respuesta.CveEstatus.Contiene(4,5)) if (respuesta.CveEstatus.Contiene(4,5))
@@ -129,7 +130,7 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
{ {
Alert(respuesta.Mensaje,TipoMensaje.MsgAdvertencia); Alert(respuesta.Mensaje,TipoMensaje.MsgAdvertencia);
} }
//if (respuesta.IrARefacturar) //if (respuesta.IrARefacturar)
//{ //{
// Server.Transfer(respuesta.LigaRefacturacion); // Server.Transfer(respuesta.LigaRefacturacion);
@@ -138,46 +139,46 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
//{ //{
// Alert(respuesta.Mensaje); // Alert(respuesta.Mensaje);
// CargaDatos(); // CargaDatos();
//} //}
} }
UPDatos.Update(); UPDatos.Update();
} }
private MRespuestaSAT VerificarVigenciaSAT(int CveVenta, int CveCliente, string Folio, string TipoDocto, string uuid, string emisor, string receptor, string total, bool EsRefacturacion = false) private MRespuestaSAT VerificarVigenciaSAT(int CveVenta, int CveCliente, string Folio, string TipoDocto, string uuid, string emisor, string receptor, string total, bool EsRefacturacion = false)
{ {
HdnLigaRefacturar.Value = ""; HdnLigaRefacturar.Value = "";
var retorno = new MRespuestaSAT() var retorno = new MRespuestaSAT()
{ {
Mensaje = "", Mensaje = "",
EnviarAcuse = false, EnviarAcuse = false,
LigaRefacturacion = "", LigaRefacturacion = "",
IrARefacturar = false IrARefacturar = false
}; };
var sb = new StringBuilder(); var sb = new StringBuilder();
string CancelacionAcuse = ""; string CancelacionAcuse = "";
DateTime CancelacionFecha = DateTime.Now; DateTime CancelacionFecha = DateTime.Now;
int CveEstatus = 4; int CveEstatus = 4;
try try
{ {
var resp = Timbrado.VerificarVigenciaSAT(uuid, UsuarioActual.Empresa.RFC, receptor, total, true); var resp = Timbrado.VerificarVigenciaSAT(uuid, UsuarioActual.Empresa.RFC, receptor, total, true);
if (resp != null) if (resp != null)
{ {
if (resp.Estado == null) if (resp.Estado == null)
{ {
sb.Append("No se pudo comprobar el estado de la factura. El servicio del sat no esta disponible"); sb.Append("No se pudo comprobar el estado de la factura. El servicio del sat no esta disponible");
retorno.Mensaje = sb.ToString(); retorno.Mensaje = sb.ToString();
return retorno; return retorno;
} }
sb.AppendFormat("Folio Fiscal: {0} <br/>", uuid); sb.AppendFormat("Folio Fiscal: {0} <br/>", uuid);
sb.AppendFormat("Codigo Estado: {0} <br/>", resp.CodigoEstatus); sb.AppendFormat("Codigo Estado: {0} <br/>", resp.CodigoEstatus);
sb.AppendFormat("Estado: {0} <br/>", resp.Estado); sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
sb.AppendFormat("Es Cancelable: {0} <br/>", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EsCancelable); sb.AppendFormat("Es Cancelable: {0} <br/>", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EsCancelable);
sb.AppendFormat("Estatus de Cancelación: {0} <br/><br/>", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EstatusCancelacion); sb.AppendFormat("Estatus de Cancelación: {0} <br/><br/>", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EstatusCancelacion);
if (!UsuarioActual.Empresa.FacturaProduccion && (string.IsNullOrEmpty(uuid) || uuid.Contains("test"))) if (!UsuarioActual.Empresa.FacturaProduccion && (string.IsNullOrEmpty(uuid) || uuid.Contains("test")))
@@ -253,31 +254,31 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
} }
ObjVentas.Dispose(); ObjVentas.Dispose();
} }
} }
} }
else else
{ {
sb.Append("No se pudo comprobar la vigencia de la factura."); sb.Append("No se pudo comprobar la vigencia de la factura.");
retorno.Mensaje = sb.ToString(); retorno.Mensaje = sb.ToString();
return retorno; return retorno;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
sb.Append("Error al consumir el servicio: " + ex.Message); sb.Append("Error al consumir el servicio: " + ex.Message);
retorno.Mensaje = sb.ToString(); retorno.Mensaje = sb.ToString();
return retorno; return retorno;
} }
retorno.CveEstatus = CveEstatus; retorno.CveEstatus = CveEstatus;
retorno.Mensaje = sb.ToString(); retorno.Mensaje = sb.ToString();
return retorno; return retorno;
} }
private Modelos.Factura.MCancelacionVentaMensaje CancelarDocumento(int CveVenta, int CveEstatus, int CveCliente, string Folio, string FolioFiscal, string CancelacionAcuse, DateTime CancelacionFecha, string TipoComprobante, double Total, int CvePACCancelacion, bool EsRefacturacion = false) private Modelos.Factura.MCancelacionVentaMensaje CancelarDocumento(int CveVenta, int CveEstatus, int CveCliente, string Folio, string FolioFiscal, string CancelacionAcuse, DateTime CancelacionFecha, string TipoComprobante, double Total, int CvePACCancelacion, bool EsRefacturacion = false)
{ {
Modelos.Factura.MCancelacionVentaMensaje retorno = null; Modelos.Factura.MCancelacionVentaMensaje retorno = null;
var factura = new Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:true); var factura = new Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:true);
if (EsRefacturacion) if (EsRefacturacion)
{ {
retorno = factura.CancelarPorRefacturacion(); retorno = factura.CancelarPorRefacturacion();
@@ -285,63 +286,63 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
else else
{ {
retorno = factura.EjecutarCancelacionPendiente(CveEstatus, CancelacionFecha, CancelacionAcuse); retorno = factura.EjecutarCancelacionPendiente(CveEstatus, CancelacionFecha, CancelacionAcuse);
} }
return retorno; return retorno;
} }
private string DecodeBase64(string strXMLCodificado) private string DecodeBase64(string strXMLCodificado)
{ {
try try
{ {
byte[] decbuff = Convert.FromBase64String(strXMLCodificado); byte[] decbuff = Convert.FromBase64String(strXMLCodificado);
return System.Text.Encoding.UTF8.GetString(decbuff); return System.Text.Encoding.UTF8.GetString(decbuff);
} }
catch catch
{ {
return ""; return "";
} }
} }
protected void LnkValidar_Click(object sender, EventArgs e) protected void LnkValidar_Click(object sender, EventArgs e)
{ {
this.HdnLigaRefacturar.Value = ""; this.HdnLigaRefacturar.Value = "";
this.CveVenta = -1; this.CveVenta = -1;
if (DtVentas != null) if (DtVentas != null)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (DataRow Row in DtVentas.Rows) foreach (DataRow Row in DtVentas.Rows)
{ {
int CveVenta = Row["CveVenta"].ToEntero(); int CveVenta = Row["CveVenta"].ToEntero();
string Total = Row["Total"].ToString(); string Total = Row["Total"].ToString();
string SubTotal = Row["SubTotal"].ToString(); string SubTotal = Row["SubTotal"].ToString();
string Uuid = Row["FolioFiscal"].ToString(); string Uuid = Row["FolioFiscal"].ToString();
string RFCCliente = Row["RFCCliente"].ToString(); string RFCCliente = Row["RFCCliente"].ToString();
string Folio = Row["Folio"].ToString(); string Folio = Row["Folio"].ToString();
string TipoDocto = Row["TipoDocto"].ToString(); string TipoDocto = Row["TipoDocto"].ToString();
string Nombre = Row["Nombre"].ToString(); string Nombre = Row["Nombre"].ToString();
int CveCliente = Row["CveCliente"].ToEntero(); int CveCliente = Row["CveCliente"].ToEntero();
if (CveVenta > 0) if (CveVenta > 0)
{ {
sb.AppendFormat("{0}<br/>", VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCCliente, SubTotal)); sb.AppendFormat("{0}<br/>", VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCCliente, SubTotal));
} }
} }
Alert(sb.ToString()); Alert(sb.ToString());
} }
CargaDatos(); CargaDatos();
} }
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e) protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
{ {
if (e.Row.RowType == DataControlRowType.DataRow) if (e.Row.RowType == DataControlRowType.DataRow)
{ {
if (e.Row.DBCampo("PuedeRefacturar").ToString().ToEntero() == 0) if (e.Row.DBCampo("PuedeRefacturar").ToString().ToEntero() == 0)
{ {
e.Row.Cells[10].Text = ""; e.Row.Cells[10].Text = "";
} }
} }
} }
public void BtnEnviarMailCancelacion_Click(object sender, EventArgs e) public void BtnEnviarMailCancelacion_Click(object sender, EventArgs e)
{ {
if (this.CveVenta > 0) if (this.CveVenta > 0)
@@ -353,7 +354,7 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
Alert("No se encontro la factura para enviar el acuse", TipoMensaje.MsgAdvertencia); Alert("No se encontro la factura para enviar el acuse", TipoMensaje.MsgAdvertencia);
} }
} }
public void ImprimeCancelacion(int CveVenta) public void ImprimeCancelacion(int CveVenta)
{ {
var Archivo = new System.IO.FileInfo(ModExtensiones.DirectorioBaseEmpresas + @"Empresas\Grales\Formatos\AcuseCancelacion.rdlc"); var Archivo = new System.IO.FileInfo(ModExtensiones.DirectorioBaseEmpresas + @"Empresas\Grales\Formatos\AcuseCancelacion.rdlc");
@@ -457,7 +458,7 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
} }
} }
} }
public class MRespuestaSAT public class MRespuestaSAT
{ {
public int CveEstatus { get; set; } public int CveEstatus { get; set; }