1035 lines
50 KiB
C#
1035 lines
50 KiB
C#
using Extensiones;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Activities.Expressions;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.UI.WebControls;
|
|
using static Extensiones.ModExtensiones;
|
|
using static Stimulsoft.Report.Export.DeflaterHuffman;
|
|
|
|
public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas
|
|
{
|
|
private DataTable DtVentas
|
|
{
|
|
get { return (ViewState["DtVentas"] == null) ? null : (DataTable)ViewState["DtVentas"]; }
|
|
set { ViewState["DtVentas"] = value; }
|
|
}
|
|
private int CveVenta
|
|
{
|
|
get { return (ViewState["CveVenta"] == null) ? -1 : ViewState["CveVenta"].ToString().ToEntero(); }
|
|
set { ViewState["CveVenta"] = value; }
|
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
}
|
|
private void CargaDatos()
|
|
{
|
|
//HdnLigaRefacturar.Value = "";
|
|
|
|
if (Request["CveVenta"] != null)
|
|
{
|
|
this.CveVenta = Request["CveVenta"].ToString().ToEntero();
|
|
}
|
|
|
|
var ObjVentas = new ClsVentas();
|
|
//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)
|
|
// {
|
|
// DtVentas = ObjVentas.DtResultados.FiltraParametros($"CveVenta={Request["CveVenta"].ToString().ToEntero()}");
|
|
// }
|
|
// else
|
|
// {
|
|
// DtVentas = ObjVentas.DtResultados.Copy();
|
|
// }
|
|
//}
|
|
if (ObjVentas.GetVentasPendientesCancelacion(UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario))
|
|
{
|
|
|
|
if (Request["CveVenta"] != null && Request["CveVenta"].ToString().ToEntero() > 0)
|
|
{
|
|
DtVentas = ObjVentas.DtResultados.FiltraParametros($"CveVenta={Request["CveVenta"].ToString().ToEntero()}");
|
|
}
|
|
else
|
|
{
|
|
DtVentas = ObjVentas.DtResultados.Copy();
|
|
}
|
|
}
|
|
|
|
ObjVentas.Dispose();
|
|
GvDatos.DataSource = DtVentas.FiltraParametros("(CveEstatusFactura IN (20,23) AND CveEstatusRefacturacion IN (0,4))");
|
|
|
|
var DtRefacturar = DtVentas.FiltraParametros("CveEstatusRefacturacion IN (1,3) OR (CveEstatusFactura IN (20,23) AND CveEstatusRefacturacion IN (1,2,3))");
|
|
if (DtRefacturar != null && DtRefacturar.Rows.Count > 0)
|
|
{
|
|
DivRefacturar.Visible = true;
|
|
GvRefacturaciones.DataSource = DtRefacturar;
|
|
GvRefacturaciones.DataBind();
|
|
}
|
|
|
|
|
|
GvDatos.DataBind();
|
|
UPDatos.Update();
|
|
}
|
|
protected void BtnValidar_Click(object sender, EventArgs e)
|
|
{
|
|
//this.HdnLigaRefacturar.Value = "";
|
|
this.CveVenta = -1;
|
|
|
|
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
this.CveVenta = GvRow.DataKey("CveVenta").ToEntero();
|
|
|
|
int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
|
|
string Total = GvRow.DataKey("Total");
|
|
string SubTotal = GvRow.DataKey("SubTotal");
|
|
string Uuid = GvRow.DataKey("FolioFiscal");
|
|
string RFCReceptor = GvRow.DataKey("RFCReceptor");
|
|
string Folio = GvRow.DataKey("Folio");
|
|
string TipoDocto = GvRow.DataKey("TipoDocto");
|
|
string Nombre = GvRow.DataKey("Nombre");
|
|
string CveEstatusRefact = GvRow.DataKey("CveEstatusRefacturacion");
|
|
string Msg;
|
|
if (CveVenta > 0 && Uuid != "")
|
|
{
|
|
var resp = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCReceptor, Total);
|
|
if (resp.EnviarAcuse)
|
|
{
|
|
Msg = resp.Mensaje;
|
|
if (CveEstatusRefact == "4")
|
|
{
|
|
Msg = Msg + "<br/><a class='Texto' href='/Ventas/Ventas.aspx?CveDevolucion=" + CveVenta + "&NuevaFactura=1'> Refacturar</a>";
|
|
}
|
|
|
|
Alert(Msg, TipoMensaje.MsgConfirmacion, "BtnEnviarMailCancelacion();", TextoConfirmacion: "Enviar", TextoSegundoBoton: "Cancelar");
|
|
}
|
|
else
|
|
{
|
|
Msg = resp.Mensaje;
|
|
if (CveEstatusRefact == "4")
|
|
{
|
|
Msg = Msg + "<br/><a class='Texto' href='/Ventas/Ventas.aspx?CveDevolucion=" + CveVenta + "&NuevaFactura=1'> Refacturar</a>";
|
|
}
|
|
Alert(Msg);
|
|
}
|
|
|
|
}
|
|
CargaDatos();
|
|
}
|
|
protected void BtnValidarRefacturacion_Click(object sender, EventArgs e)
|
|
{
|
|
//this.HdnLigaRefacturar.Value = "";
|
|
this.CveVenta = -1;
|
|
|
|
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
this.CveVenta = GvRow.DataKey("CveVenta").ToEntero();
|
|
|
|
int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
|
|
string Total = GvRow.DataKey("Total");
|
|
string SubTotal = GvRow.DataKey("SubTotal");
|
|
string Uuid = GvRow.DataKey("FolioFiscal");
|
|
string RFCReceptor = GvRow.DataKey("RFCReceptor");
|
|
string Folio = GvRow.DataKey("Folio");
|
|
string TipoDocto = GvRow.DataKey("TipoDocto");
|
|
string Nombre = GvRow.DataKey("Nombre");
|
|
int CveEstatusFactura = GvRow.DataKey("CveEstatusFactura").ToEntero();
|
|
|
|
string FolioSustitucion = GvRow.DataKey("FolioFiscalSustitucion");
|
|
int CveVentaSustitucion = GvRow.DataKey("CveVentaSustitucion").ToEntero();
|
|
string RFCReceptorSustitucion = GvRow.DataKey("RFCReceptorSustitucion");
|
|
|
|
int CveMotivoSustitucion = 0;
|
|
|
|
if (CveVentaSustitucion > 0)
|
|
{
|
|
//VERIFICA EL ESTATUS DE LA FACTURA NUEVA, SI ESTA ESTÁ CANCELADA, SE MANDA UNA CANCELACIÓN SIN FOLIO DE SUSTITUCIÓN Y CON EL CÓDIGO 02
|
|
Timbrado.AcuseCancelacionSAT VigenciaExtra = Timbrado.VerificarVigenciaSAT(FolioSustitucion, UsuarioActual.Empresa.RFC, RFCReceptorSustitucion, Total.ToString(), true);
|
|
if (VigenciaExtra != null)
|
|
{
|
|
if (VigenciaExtra.Estado.ToUpper() == "CANCELADO")
|
|
{
|
|
FolioSustitucion = "";
|
|
CveMotivoSustitucion = get_GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveSATMotivoCancelacion: 2).FiltroPrimeroValor("CveMotivoCancelacion").ToEntero();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert("No se pudo comprobar la vigencia de la factura ante el SAT. El servicio no se encuentra disponible", TipoMensaje.MsgError);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (CveVenta > 0 && Uuid != "")
|
|
{
|
|
var respuesta = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCReceptor, Total, EsRefacturacion: true, FolioSustitucion: FolioSustitucion, CveEstatusFactura: CveEstatusFactura, CveMotivoSustitucion: CveMotivoSustitucion);
|
|
CargaDatos();
|
|
if (respuesta.CveEstatus.Contiene(4, 5))
|
|
{
|
|
//HdnLigaRefacturar.Value = respuesta.LigaRefacturacion;
|
|
Alert(respuesta.Mensaje, JSBtnAceptar: $"RefacturarDocumento();");
|
|
}
|
|
else
|
|
{
|
|
Alert(respuesta.Mensaje, TipoMensaje.MsgAdvertencia);
|
|
}
|
|
|
|
//if (respuesta.IrARefacturar)
|
|
//{
|
|
// Server.Transfer(respuesta.LigaRefacturacion);
|
|
//}
|
|
//else
|
|
//{
|
|
// Alert(respuesta.Mensaje);
|
|
// CargaDatos();
|
|
//}
|
|
}
|
|
UPDatos.Update();
|
|
|
|
}
|
|
|
|
protected void BtnCancelarDocumento_Click(object sender, EventArgs e)
|
|
{
|
|
//this.HdnLigaRefacturar.Value = "";
|
|
this.CveVenta = -1;
|
|
|
|
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
this.CveVenta = GvRow.DataKey("CveVenta").ToEntero();
|
|
|
|
int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
|
|
string Total = GvRow.DataKey("Total");
|
|
string SubTotal = GvRow.DataKey("SubTotal");
|
|
string Uuid = GvRow.DataKey("FolioFiscal");
|
|
string RFCReceptor = GvRow.DataKey("RFCReceptor");
|
|
string Folio = GvRow.DataKey("Folio");
|
|
string TipoDocto = GvRow.DataKey("TipoDocto");
|
|
string Nombre = GvRow.DataKey("Nombre");
|
|
string FolioSustitucion = GvRow.DataKey("FolioFiscalSustitucion");
|
|
int CveVentaSustitucion = GvRow.DataKey("CveVentaSustitucion").ToEntero();
|
|
string RFCReceptorSustitucion = GvRow.DataKey("RFCReceptorSustitucion");
|
|
|
|
int CveMotivoCancelacion = -1;
|
|
int CveEstatusRefacturacion = GvRow.DataKey("CveEstatusRefacturacion").ToEntero();
|
|
int CveEstatusFacturaSustitucion = GvRow.DataKey("CveEstatusFacturaSustitucion").ToEntero();
|
|
|
|
if (CveEstatusRefacturacion > 0)
|
|
{
|
|
CveMotivoCancelacion = get_GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveSATMotivoCancelacion: 1).FiltroPrimeroValor("CveMotivoCancelacion").ToEntero();
|
|
}
|
|
//CveEstatusRefacturacion = 2;
|
|
|
|
if (CveVenta > 0)
|
|
{
|
|
//VERIFICA EL ESTATUS DE LA FACTURA NUEVA, SI ESTA ESTÁ CANCELADA, SE MANDA UNA CANCELACIÓN SIN FOLIO DE SUSTITUCIÓN Y CON EL CÓDIGO 02
|
|
Timbrado.AcuseCancelacionSAT VigenciaExtra = Timbrado.VerificarVigenciaSAT(FolioSustitucion, UsuarioActual.Empresa.RFC, RFCReceptorSustitucion, Total.ToString(), true);
|
|
if (VigenciaExtra != null)
|
|
{
|
|
if (VigenciaExtra.Estado.ToUpper() == "CANCELADO")
|
|
{
|
|
FolioSustitucion = "";
|
|
CveMotivoCancelacion = get_GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveSATMotivoCancelacion: 2).FiltroPrimeroValor("CveMotivoCancelacion").ToEntero();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert("No se pudo comprobar la vigencia de la factura ante el SAT. El servicio no se encuentra disponible", TipoMensaje.MsgError);
|
|
return;
|
|
}
|
|
|
|
|
|
var respCancelacion = CancelarDocumento(CveVenta, -1, CveCliente, Folio, Uuid, "", NowADS(), TipoDocto, Total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: true, FolioSustitucion: FolioSustitucion, CveEstatusRefacturacion: CveEstatusRefacturacion, CveMotivoCancelacion: CveMotivoCancelacion);
|
|
|
|
if (!respCancelacion.HuboError)
|
|
{
|
|
var sb = new StringBuilder();
|
|
var EnviarAcuse = false;
|
|
if (respCancelacion.CveEstatus > 0)
|
|
{
|
|
if (respCancelacion.CveEstatus.Contiene(5, 20))
|
|
{
|
|
EnviarAcuse = true;
|
|
}
|
|
|
|
var CveEstatus = respCancelacion.CveEstatus;
|
|
var ObjVentas = new ClsVentas();
|
|
if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa))
|
|
{
|
|
if (respCancelacion.CveEstatus == 20)
|
|
{
|
|
sb.Append("El estatus de la factura fue cambiado a <b>'Cancelación en proceso'</b>.");
|
|
sb.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>");
|
|
}
|
|
else if (respCancelacion.CveEstatus == 23)
|
|
{
|
|
sb.Append("La solicitud de cancelación no la aplicó el SAT, intente cancelar de nuevo.");
|
|
}
|
|
else
|
|
{
|
|
sb.Append("El estatus de la factura fue cambiado a <b>'Cancelada'</b>.");
|
|
sb.Append("El documento se canceló correctamente.");
|
|
sb.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
sb.Append("Ocurrió un error al cambiar el estatus de la factura.");
|
|
}
|
|
ObjVentas.Dispose();
|
|
|
|
if (respCancelacion.CveEstatus == 23)
|
|
{
|
|
var resp = Timbrado.VerificarVigenciaSAT(Uuid, UsuarioActual.Empresa.RFC, RFCReceptor, Total, true);
|
|
if (resp != null)
|
|
{
|
|
sb.AppendFormat("<br/> Folio Fiscal: {0} <br/>", Uuid);
|
|
sb.AppendFormat("Código Estado: {0} <br/>", resp.CodigoEstatus);
|
|
sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(Uuid))
|
|
{
|
|
var resp = Timbrado.VerificarVigenciaSAT(Uuid, UsuarioActual.Empresa.RFC, RFCReceptor, Total, true);
|
|
if (resp != null)
|
|
{
|
|
sb.AppendFormat("Folio Fiscal: {0} <br/>", Uuid);
|
|
sb.AppendFormat("Código Estado: {0} <br/>", resp.CodigoEstatus);
|
|
sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
|
|
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.Append(respCancelacion.Mensaje);
|
|
}
|
|
|
|
if (EnviarAcuse)
|
|
{
|
|
sb.Append("</br></br> ¿Desea enviar el Acuse de Cancelación al Cliente?");
|
|
Alert(sb.ToString(), TipoMensaje.MsgConfirmacion, "BtnEnviarMailCancelacion();", TextoConfirmacion: "Enviar", TextoSegundoBoton: "Cancelar");
|
|
}
|
|
else
|
|
{
|
|
Alert(sb.ToString());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert(respCancelacion.Mensaje, TipoMensaje.MsgError);
|
|
}
|
|
|
|
CargaDatos();
|
|
}
|
|
|
|
UPDatos.Update();
|
|
|
|
}
|
|
private MRespuestaSAT VerificarVigenciaSAT(int CveVenta, int CveCliente, string Folio, string TipoDocto, string uuid, string emisor, string receptor, string total, bool EsRefacturacion = false, string FolioSustitucion = "", int CveEstatusFactura = -1, int CveMotivoSustitucion = 0)
|
|
{
|
|
//HdnLigaRefacturar.Value = "";
|
|
|
|
var retorno = new MRespuestaSAT()
|
|
{
|
|
Mensaje = "",
|
|
EnviarAcuse = false,
|
|
LigaRefacturacion = "",
|
|
IrARefacturar = false
|
|
};
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
string CancelacionAcuse = "";
|
|
DateTime CancelacionFecha = NowADS();
|
|
int CveEstatus = 4;
|
|
|
|
try
|
|
{
|
|
var resp = Timbrado.VerificarVigenciaSAT(uuid, UsuarioActual.Empresa.RFC, receptor, total, true);
|
|
if (resp != null)
|
|
{
|
|
|
|
if (resp.Estado == null)
|
|
{
|
|
sb.Append("No se pudo comprobar el estado de la factura. El servicio del sat no esta disponible");
|
|
retorno.Mensaje = sb.ToString();
|
|
return retorno;
|
|
}
|
|
|
|
sb.AppendFormat("Folio Fiscal: {0} <br/>", uuid);
|
|
sb.AppendFormat("Código Estado: {0} <br/>", resp.CodigoEstatus);
|
|
sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
|
|
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);
|
|
|
|
if (!UsuarioActual.Empresa.FacturaProduccion && (string.IsNullOrEmpty(uuid) || uuid.Contains("test")))
|
|
{
|
|
var respCancelacion = CancelarDocumento(CveVenta, CveEstatus, CveCliente, Folio, uuid, CancelacionAcuse, CancelacionFecha, TipoDocto, total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: EsRefacturacion, FolioSustitucion: FolioSustitucion, CveMotivoCancelacion : CveMotivoSustitucion);
|
|
|
|
//sb.AppendFormat("{0} <br/>", respCancelacion.Mensaje);
|
|
if (!respCancelacion.HuboError)
|
|
{
|
|
CveEstatus = respCancelacion.CveEstatus;
|
|
retorno.EnviarAcuse = true;
|
|
|
|
sb.Append("El documento se canceló correctamente.");
|
|
sb.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>");
|
|
if (!EsRefacturacion)
|
|
{
|
|
sb.Append("</br></br> ¿Desea enviar el Acuse de Cancelación al Cliente?");
|
|
}
|
|
}
|
|
|
|
//if (respCancelacion.CveEstatus.Contiene(4, 5) && EsRefacturacion)
|
|
//{
|
|
// retorno.IrARefacturar = true;
|
|
// retorno.LigaRefacturacion = string.Format("Ventas.aspx?CveDevolucion={0}&NuevaFactura=1", CveVenta);
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
//SI ES REFACTURACION Y SE MANDO LA SOLICITUD, PERO NO APARECE EL ESTATUS DE CANCELACION, DEBE PONERSE COMO CANCELACION PENDIENTE
|
|
if (EsRefacturacion && CveEstatusFactura == 20 && resp.Estado.ToUpper().Trim() == "VIGENTE" && string.IsNullOrEmpty(resp.EstatusCancelacion))
|
|
{
|
|
CveEstatus = 23;
|
|
var ObjVentas = new ClsVentas();
|
|
if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa))
|
|
{
|
|
sb.Append("El estatus de la factura fue cambiado a 'Cancelación Pendiente'.");
|
|
}
|
|
else
|
|
{
|
|
sb.Append("Ocurrió un error al cambiar el estatus de la factura.");
|
|
}
|
|
ObjVentas.Dispose();
|
|
}
|
|
else if (resp.Estado.ToUpper().Trim() == "CANCELADO" || resp.EstatusCancelacion.ToUpper() == "PLAZO VENCIDO")
|
|
{
|
|
CveEstatus = 5;
|
|
|
|
var respCancelacion = CancelarDocumento(CveVenta, CveEstatus, CveCliente, Folio, uuid, CancelacionAcuse, CancelacionFecha, TipoDocto, total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: EsRefacturacion, FolioSustitucion: FolioSustitucion, CveMotivoCancelacion: CveMotivoSustitucion);
|
|
|
|
//sb.AppendFormat("{0} <br/>", respCancelacion.Mensaje);
|
|
if (!respCancelacion.HuboError)
|
|
{
|
|
if (respCancelacion.CveEstatus > 0)
|
|
{
|
|
retorno.EnviarAcuse = true;
|
|
CveEstatus = respCancelacion.CveEstatus;
|
|
var ObjVentas = new ClsVentas();
|
|
if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa))
|
|
{
|
|
if (respCancelacion.CveEstatus == 20)
|
|
{
|
|
sb.Append("El estatus de la factura fue cambiado a 'Cancelación en proceso'.");
|
|
}
|
|
else if (respCancelacion.CveEstatus == 23)
|
|
{
|
|
sb.Append("La solicitud de cancelación no la aplicó el SAT, intente cancelar de nuevo.<br/>");
|
|
|
|
sb.AppendFormat("Folio Fiscal: {0} <br/>", uuid);
|
|
sb.AppendFormat("Código Estado: {0} <br/>", resp.CodigoEstatus);
|
|
sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
sb.Append("El estatus de la factura fue cambiado a 'Cancelada'.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sb.Append("Ocurrió un error al cambiar el estatus de la factura.");
|
|
}
|
|
ObjVentas.Dispose();
|
|
sb.Append("El documento se canceló correctamente.");
|
|
sb.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>");
|
|
if (!EsRefacturacion)
|
|
{
|
|
sb.Append("</br></br> ¿Desea enviar el Acuse de Cancelación al Cliente?");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sb.Append(respCancelacion.Mensaje);
|
|
}
|
|
|
|
}
|
|
|
|
//if (respCancelacion.CveEstatus.Contiene(4, 5) && EsRefacturacion)
|
|
//{
|
|
// retorno.IrARefacturar = true;
|
|
// retorno.LigaRefacturacion = string.Format("Ventas.aspx?CveDevolucion={0}&NuevaFactura=1", CveVenta);
|
|
//}
|
|
}
|
|
else if (resp.EstatusCancelacion.ToUpper() == "SOLICITUD RECHAZADA")
|
|
{
|
|
//ASIGNAMOS ESTATUS EMITIDA
|
|
CveEstatus = 3;
|
|
string Estatus = "Emitida";
|
|
//SI ES REFACTURACION, DEBE QUEDAR COMO CANCELACION PENDIENTE PARA ENVIAR LA CANCELACION DE NUEVO
|
|
if (EsRefacturacion)
|
|
{
|
|
CveEstatus = 23;
|
|
Estatus = "Cancelación pendiente";
|
|
}
|
|
var ObjVentas = new ClsVentas();
|
|
if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa))
|
|
{
|
|
sb.Append($"El estatus de la factura fue cambiado a '{Estatus}'.");
|
|
}
|
|
else
|
|
{
|
|
sb.Append("Ocurrió un error al cambiar el estatus de la factura.");
|
|
}
|
|
ObjVentas.Dispose();
|
|
}
|
|
else if (resp.Estado.ToUpper().Trim() == "VIGENTE" && string.IsNullOrEmpty(resp.EstatusCancelacion) && !EsRefacturacion)
|
|
{
|
|
//ASIGNAMOS ESTATUS EMITIDA
|
|
CveEstatus = 3;
|
|
string Estatus = "Emitida";
|
|
//SI ES REFACTURACION, DEBE QUEDAR COMO CANCELACION PENDIENTE PARA ENVIAR LA CANCELACION DE NUEVO
|
|
if (EsRefacturacion)
|
|
{
|
|
CveEstatus = 23;
|
|
Estatus = "Cancelación pendiente";
|
|
}
|
|
var ObjVentas = new ClsVentas();
|
|
if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa))
|
|
{
|
|
sb.Append($"El estatus de la factura fue cambiado a '{Estatus}'.");
|
|
}
|
|
else
|
|
{
|
|
sb.Append("Ocurrió un error al cambiar el estatus de la factura.");
|
|
}
|
|
ObjVentas.Dispose();
|
|
}
|
|
else if ((resp.EsCancelable.ToUpper() == "NO CANCELABLE"))
|
|
{
|
|
sb.Append("Esta factura no es cancelable.");
|
|
retorno.Mensaje = sb.ToString();
|
|
return retorno;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sb.Append("No se pudo comprobar la vigencia de la factura.");
|
|
retorno.Mensaje = sb.ToString();
|
|
return retorno;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sb.Append("Error al consumir el servicio: " + ex.Message);
|
|
retorno.Mensaje = sb.ToString();
|
|
return retorno;
|
|
}
|
|
|
|
retorno.CveEstatus = CveEstatus;
|
|
|
|
retorno.Mensaje = sb.ToString();
|
|
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, string FolioSustitucion = "", int CveEstatusRefacturacion = 0, int CveMotivoCancelacion = 0)
|
|
{
|
|
Modelos.Factura.MCancelacionVentaMensaje retorno = null;
|
|
var factura = new Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion: true, VerificaAlmacen : true);
|
|
|
|
if (factura.ErrorList.Count > 0) { retorno.HuboError = true; return retorno; }
|
|
|
|
if (EsRefacturacion)
|
|
{
|
|
//SI YA FUE REFACTURADA MARCALA COMO REFACTURADA
|
|
if (!string.IsNullOrEmpty(FolioSustitucion))
|
|
{
|
|
CveEstatusRefacturacion = 2;
|
|
}
|
|
|
|
if (CveEstatusRefacturacion > 0)
|
|
{
|
|
factura.CveEstatusRefacturacion = CveEstatusRefacturacion;
|
|
}
|
|
|
|
if (CveMotivoCancelacion > 0)
|
|
{
|
|
factura.CveMotivoCancelacion = CveMotivoCancelacion;
|
|
}
|
|
|
|
int CveEstatusFactura = -1;
|
|
//SI LA FACTURA YA ESTA CANCELADA, LA ASIGNA YA COMO CANCELADA
|
|
if (CveEstatus == 5)
|
|
{
|
|
CveEstatusFactura = CveEstatus;
|
|
}
|
|
//NO DEBE DE ASIGNAR ESTATUS
|
|
if (CveEstatus == -2)
|
|
{
|
|
CveEstatusFactura = -1;
|
|
}
|
|
|
|
retorno = factura.CancelarPorRefacturacion(factura.CveMotivoCancelacion, factura.MotivoCancelacion, FolioSustitucion: FolioSustitucion, CveEstadoCancelacion: CveEstatusFactura);
|
|
}
|
|
else
|
|
{
|
|
//EN BDH, SI ES DEVOLUCION, QUE REALICE LA SALIDA DE ALMACEN
|
|
if (UsuarioActual.Empresa.Funcionalidad(531) == "1" && factura.TipoDocto == "Dev" && factura.SaldoAlmacen != 0)
|
|
{
|
|
factura.RealizarDevolucionAlmacen = 1;
|
|
}
|
|
|
|
//SI REGISTRA SALIDA DE ALMACÉN EN AUTOMÁTICO, QUE REALIZE EL MOVIMIENTO DE ALMACEN EN AUTOMATICO
|
|
if (UsuarioActual.Empresa.Funcionalidad(567) == "1" && factura.TipoDocto.Contiene("Ing", "Dev") && factura.SaldoAlmacen != 0)
|
|
{
|
|
factura.RealizarDevolucionAlmacen = 1;
|
|
}
|
|
|
|
//SI TIENE PERMISO 'PERMITE DEVOLVER PRODUCTO EN UNA CANCELACION', QUE REALIZE EL MOVIMIENTO DE ALMACEN EN AUTOMATICO
|
|
if (UsuarioActual.TienePermisoProceso(269) && factura.TipoDocto.Contiene("Ing", "Dev") && factura.SaldoAlmacen != 0)
|
|
{
|
|
factura.RealizarDevolucionAlmacen = 1;
|
|
}
|
|
|
|
//EN TODAS LAS EMPRESAS. SI ES REMISION FACTURADA DEBE REALIZAR EL MOVIMIENTO DE ALMACEN EN AUTOMATICO
|
|
if (factura.TipoDocto == "Ing")
|
|
{
|
|
using (var ObjVentas = new ClsVentas())
|
|
{
|
|
if (ObjVentas.GetRemisionesRelacionadas(CveVenta, factura.TipoDocto))
|
|
{
|
|
if (ObjVentas.DtResultados.Copy().Rows.Count > 0)
|
|
{
|
|
factura.RealizarDevolucionAlmacen = 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
retorno = new Modelos.Factura.MCancelacionVentaMensaje();
|
|
retorno.Mensaje = "No se pudo verificar si tiene remisiones relacionadas";
|
|
retorno.HuboError = true;
|
|
return retorno;
|
|
}
|
|
}
|
|
}
|
|
|
|
var CancelacionPagos = Modelos.OpcionesCancelacionPagos.SinPagos;
|
|
|
|
if (UsuarioActual.Empresa.Funcionalidad(109) == "1" || UsuarioActual.Empresa.Funcionalidad(382) == "1")
|
|
{
|
|
CancelacionPagos = Modelos.OpcionesCancelacionPagos.ConPagos_CancelarIE;
|
|
}
|
|
|
|
//if (UsuarioActual.Empresa.Funcionalidad(382) == "1")
|
|
//{
|
|
// CancelacionPagos = Modelos.OpcionesCancelacionPagos.ConPagos_GenerarIxC;
|
|
//}
|
|
|
|
retorno = factura.EjecutarCancelacionPendiente(CveEstatus, CancelacionFecha, CancelacionAcuse, CancelacionPagos: CancelacionPagos);
|
|
|
|
}
|
|
|
|
return retorno;
|
|
}
|
|
|
|
private string DecodeBase64(string strXMLCodificado)
|
|
{
|
|
try
|
|
{
|
|
byte[] decbuff = Convert.FromBase64String(strXMLCodificado);
|
|
return System.Text.Encoding.UTF8.GetString(decbuff);
|
|
}
|
|
catch
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
protected void LnkValidar_Click(object sender, EventArgs e)
|
|
{
|
|
//this.HdnLigaRefacturar.Value = "";
|
|
this.CveVenta = -1;
|
|
|
|
if (DtVentas != null)
|
|
{
|
|
var sb = new StringBuilder();
|
|
foreach (DataRow Row in DtVentas.FiltraParametros("(CveEstatusFactura IN (20) AND CveEstatusRefacturacion IN (0,4))").Rows)
|
|
{
|
|
int CveVenta = Row["CveVenta"].ToEntero();
|
|
string Total = Row["Total"].ToString();
|
|
string SubTotal = Row["SubTotal"].ToString();
|
|
string Uuid = Row["FolioFiscal"].ToString();
|
|
string RFCReceptor = Row["RFCReceptor"].ToString();
|
|
string Folio = Row["Folio"].ToString();
|
|
string TipoDocto = Row["TipoDocto"].ToString();
|
|
string Nombre = Row["Nombre"].ToString();
|
|
int CveCliente = Row["CveCliente"].ToEntero();
|
|
if (CveVenta > 0)
|
|
{
|
|
var resp = VerificarVigenciaSAT(CveVenta, CveCliente, Folio, TipoDocto, Uuid, UsuarioActual.Empresa.RFC, RFCReceptor, SubTotal);
|
|
sb.AppendFormat("{0}<br/>",resp.Mensaje);
|
|
}
|
|
}
|
|
Alert(sb.ToString());
|
|
}
|
|
CargaDatos();
|
|
}
|
|
|
|
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
GridView gv = (GridView)sender;
|
|
if (!(e.Row.DBCampo("PuedeRefacturar").ToEntero() == 0 || !string.IsNullOrEmpty(e.Row.DBCampo("FolioFiscalSustitucion"))))
|
|
{
|
|
e.Row.FCHyperLink("HplRefact").NavigateUrl = string.Format("/Ventas/Ventas.aspx?CveDevolucion={0}&NuevaFactura=1", e.Row.DBCampo("CveVenta"));
|
|
e.Row.FCHyperLink("HplRefact").Visible = true;
|
|
}
|
|
|
|
if (e.Row.DBCampo("CveEstatusRefacturacion") == "4" && gv.ID == "GvDatos")
|
|
{
|
|
e.Row.FCLinkButton("BtnValidar").Text = "<i class='fa fa-check'>02</i>";
|
|
e.Row.FCLinkButton("BtnValidar").CssClass = "btn btn-circle btn-sm blue";
|
|
}
|
|
//if (e.Row.DBCampo("CveEstatusRefacturacion") == "4" && gv.ID == "GvDatos")
|
|
//{
|
|
// e.Row.FCLinkButton("BtnValidar").CssClass = "btn btn-circle btn-sm blue" ;
|
|
//}
|
|
|
|
//
|
|
|
|
//if (e.Row.DBCampo("CveEstatusFactura").ToString().ToEntero() == 23)
|
|
//{
|
|
// e.Row.FCLinkButton("LnkValidarRefac").Visible = false;
|
|
//}
|
|
|
|
|
|
|
|
if (e.Row.DBCampo("PuedeRefacturar") == "0" && e.Row.DBCampo("CveEstatusFactura") == "23" && e.Row.DBCampo("CveVentaSustitucion").ToEntero() > 0)
|
|
{
|
|
if (e.Row.FCLinkButton("LnkCancelar") != null) e.Row.FCLinkButton("LnkCancelar").Visible = true;
|
|
//SOLO MOSTRAR SI LA FACTURA NUEVA ESTA EMITIDA
|
|
//if (e.Row.DBCampo("CveEstatusRefacturacion") != "4" && e.Row.DBCampo("CveEstatusFacturaSustitucion") == "3")
|
|
//{
|
|
// if (e.Row.FCLinkButton("LnkCancelarFolioSustitucion") != null) e.Row.FCLinkButton("LnkCancelarFolioSustitucion").Visible = true;
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvRefacturaciones_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
GridView gv = (GridView)sender;
|
|
if (!(e.Row.DBCampo("PuedeRefacturar").ToEntero() == 0 || !string.IsNullOrEmpty(e.Row.DBCampo("FolioFiscalSustitucion"))))
|
|
{
|
|
e.Row.FCHyperLink("HplRefact").NavigateUrl = string.Format("/Ventas/Ventas.aspx?CveDevolucion={0}&NuevaFactura=1", e.Row.DBCampo("CveVenta"));
|
|
e.Row.FCHyperLink("HplRefact").Visible = true;
|
|
}
|
|
|
|
if (e.Row.DBCampo("CveEstatusFactura").ToString().ToEntero() == 23)
|
|
{
|
|
e.Row.FCLinkButton("LnkValidarRefac").Visible = false;
|
|
}
|
|
|
|
if (e.Row.DBCampo("PuedeRefacturar") == "0" && e.Row.DBCampo("CveEstatusFactura") == "23" && e.Row.DBCampo("CveVentaSustitucion").ToEntero() > 0)
|
|
{
|
|
if (e.Row.FCLinkButton("LnkCancelar") != null) e.Row.FCLinkButton("LnkCancelar").Visible = true;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(e.Row.DBCampo("FolioFiscal")))
|
|
{
|
|
e.Row.FCLinkButton("LnkValidarRefac").Visible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void BtnEnviarMailCancelacion_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.CveVenta > 0)
|
|
{
|
|
ImprimeCancelacion(this.CveVenta);
|
|
}
|
|
else
|
|
{
|
|
Alert("No se encontro la factura para enviar el acuse", TipoMensaje.MsgAdvertencia);
|
|
}
|
|
}
|
|
private byte[] DescargarPDF(string Parametros)
|
|
{
|
|
var Url = new Uri(string.Format("{0}Compras/PopUpVerFactura.aspx?P={1}", ClsPaginas.UrlSitio, Parametros));
|
|
byte[] File = null;
|
|
try
|
|
{
|
|
using (var httpClient = new HttpClient())
|
|
{
|
|
httpClient.Timeout = new TimeSpan(0, 15, 0);
|
|
using (var request = new HttpRequestMessage(HttpMethod.Get, Url))
|
|
{
|
|
request.Headers.Add("ADSToken", Encripta(string.Format("CVEEMPRESA={0}&TICKS={1}&CVEUSUARIO={2}", UsuarioActual.CveEmpresa, DateTime.UtcNow.Ticks, UsuarioActual.CveUsuario)));
|
|
var response = httpClient.SendAsync(request).Result;
|
|
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
File = response.Content.ReadAsByteArrayAsync().Result;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
File = null;
|
|
this.OnError("Ocurrió un error al descargar la factura", ex);
|
|
}
|
|
|
|
return File;
|
|
}
|
|
|
|
public void ImprimeCancelacion(int CveVenta)
|
|
{
|
|
var Archivo = new System.IO.FileInfo(ModExtensiones.DirectorioBaseEmpresas + @"Empresas\Grales\Formatos\AcuseCancelacion.rdlc");
|
|
if (Archivo.Exists)
|
|
{
|
|
var ObjFactura = new Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa);
|
|
|
|
//string SelloCancelacion = "";
|
|
//string FechaCancelacion = "";
|
|
//DataTable DtDatos = null;
|
|
|
|
//using (ClsVentas ObjVentas = new ClsVentas())
|
|
//{
|
|
// if (ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa))
|
|
// {
|
|
// DtDatos = ObjVentas.DtResultados.Copy();
|
|
|
|
// DataRow drv = DtDatos.Rows[0];
|
|
// SelloCancelacion = drv["SelloCancelacion"].ToString();
|
|
// FechaCancelacion = drv["FechaCancelacion"].ToString().ToDateTime().ToString("dd/MM/yyyy HH:mm:ss");
|
|
// }
|
|
//}
|
|
|
|
//List<ReportParameter> parametros = new List<ReportParameter>();
|
|
//parametros.Add(new ReportParameter("FechaCancelacion", FechaCancelacion.ToString()));
|
|
//parametros.Add(new ReportParameter("FolioFiscal", ObjFactura.FolioFiscal));
|
|
//parametros.Add(new ReportParameter("RFCEmisor", UsuarioActual.Empresa.RFC));
|
|
//parametros.Add(new ReportParameter("SelloCancelacion", SelloCancelacion));
|
|
|
|
//byte[] ObjetoPDF = StreamPDF(@"Empresas\Grales\Formatos\AcuseCancelacion.rdlc", DtDatos, parametros, "AcuseCancelacion" + CveVenta);
|
|
|
|
byte[] ObjetoPDF = DescargarPDF(Encripta(String.Format("OP=CAN&CVEVTA={0}", CveVenta)));
|
|
|
|
|
|
List<ClsSisMail.ArchivoMail> LSRutasMail = new List<ClsSisMail.ArchivoMail>();
|
|
string Asunto = string.Empty;
|
|
string Cuerpo = string.Empty;
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
if (UsuarioActual.CveEmpresa == 119)
|
|
{
|
|
sb.Append("<!DOCTYPE html>");
|
|
sb.Append("<html>");
|
|
sb.Append("<head>");
|
|
sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
|
|
sb.Append(" <title>Acuse De Cancelación</title>");
|
|
sb.Append(" <meta charset=\"utf-8\" />");
|
|
sb.Append("</head>");
|
|
sb.Append("<body>");
|
|
sb.Append(" <font face=\"calibri\">");
|
|
sb.Append($" Estimado Cliente <b>{ObjFactura.Cliente.Nombre}</b>,<br /><br />");
|
|
sb.Append($" Le informamos que Agroquímicos JAM, S.A. DE C.V ha cancelado el CFDI <b>{ObjFactura.SerieFolio}</b>, el cual ha quedado sin Efectos Fiscales y encontrará adjunto en este correo el Acuse de <br />");
|
|
sb.Append($" cancelación del SAT.<br />");
|
|
sb.Append(" POR LO QUE PEDIMOS ELIMINARLO Y NO INCLUIRLO EN SU CONTABILIDAD, YA QUE PUEDE REPRESENTAR UN PROBLEMA FISCAL PARA USTED O SU EMPRESA CUANDO EL SAT REALICE UNA FUTURA AUDITORIA <br /> ");
|
|
sb.Append(" EN SU CONTABILIDAD. </font> ");
|
|
sb.Append(" <font face=\"calibri\" size=\"2\">");
|
|
sb.Append(" <br /><br /><br /><br /><br />");
|
|
sb.Append(" <i>Este correo se generó automaticamente, favor de no responder este mensaje.</i>");
|
|
sb.Append(" </font>");
|
|
sb.Append("</body>");
|
|
sb.Append("</html>");
|
|
}
|
|
else
|
|
{
|
|
sb.Append("<!DOCTYPE html>");
|
|
sb.Append("<html>");
|
|
sb.Append("<head>");
|
|
sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
|
|
sb.Append(" <title>Acuse De Cancelación</title>");
|
|
sb.Append(" <meta charset=\"utf-8\" />");
|
|
sb.Append("</head>");
|
|
sb.Append("<body>");
|
|
sb.Append(" <font face=\"calibri\">");
|
|
sb.Append($" Estimado Cliente <b>{ObjFactura.Cliente.Nombre}</b>,<br /><br />");
|
|
sb.Append($" A través del presente medio la Empresa <b>{UsuarioActual.Empresa.Empresa} - {UsuarioActual.Empresa.RFC}</b>, canceló el documento tipo <b>{ObjFactura.TipodeComprobante}</b> <br />");
|
|
sb.Append($" con folio <b>{ObjFactura.SerieFolio}</b> y el Importe de <b>${ObjFactura.Total}</b>. <br /><br />");
|
|
sb.Append(" Le hacemos llegar el acuse de cancelación. </font> ");
|
|
sb.Append(" <font face=\"calibri\" size=\"2\">");
|
|
sb.Append(" <br /><br /><br /><br /><br />");
|
|
sb.Append(" <i>Este correo se generó automaticamente, favor de no responder este mensaje.</i>");
|
|
sb.Append(" </font>");
|
|
sb.Append("</body>");
|
|
sb.Append("</html>");
|
|
}
|
|
Asunto = $"Acuse de Cancelacion {ObjFactura.SerieFolio}";
|
|
Cuerpo = sb.ToString();
|
|
string DisplayName = "";
|
|
if (UsuarioActual.CveEmpresa == 119)
|
|
DisplayName = "Facturación Agroquímicos JAM";
|
|
|
|
LSRutasMail.Add(new ClsSisMail.ArchivoMail() { ArchivoBinario = ObjetoPDF, NombreArchivo = $"AcuseCancelacion{ObjFactura.SerieFolio}.pdf" });
|
|
|
|
ClsSisMail ObjMail = new ClsSisMail();
|
|
if (ObjMail.SendMail(UsuarioActual.Empresa, ObjFactura.Cliente.Mail, Asunto, Cuerpo, "", LSRutasMail, Displayname: DisplayName))
|
|
{
|
|
Alert("El acuse de cancelación ha sido envíado correctamente.");
|
|
}
|
|
else
|
|
{
|
|
Alert("El acuse de cancelación no pudo ser enviado.", TipoMensaje.MsgError);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//protected void LnkCancelarFolioSustitucion_Click(object sender, EventArgs e)
|
|
//{
|
|
// //this.HdnLigaRefacturar.Value = "";
|
|
// this.CveVenta = -1;
|
|
|
|
// GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
// this.CveVenta = GvRow.DataKey("CveVentaSustitucion").ToEntero();
|
|
|
|
// int CveCliente = GvRow.DataKey("CveClienteSustitucion").ToEntero();
|
|
// string Total = GvRow.DataKey("TotalSustitucion");
|
|
// string RFCReceptor = GvRow.DataKey("RFCReceptorSustitucion");
|
|
// string TipoDocto = GvRow.DataKey("TipoDocto");
|
|
// string Nombre = GvRow.DataKey("Nombre");
|
|
// string FolioSustitucion = GvRow.DataKey("FolioFiscalSustitucion");
|
|
// string SerieFolioSustitucion = GvRow.DataKey("SerieFolioSustitucion");
|
|
|
|
// int CveVentaOriginal = GvRow.DataKey("CveVenta").ToEntero();
|
|
// string SerieFolioOriginal = GvRow.DataKey("SerieFolio");
|
|
|
|
// //CUANDO LAS REFACTURACIONES NO SE PUEDEN CANCELAR, DEBE SER CANCELADO CON EL MOTIVO 02
|
|
// int CveMotivoCancelacion = get_GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveSATMotivoCancelacion: 2).FiltroPrimeroValor("CveMotivoCancelacion").ToEntero();
|
|
|
|
// if (CveVenta > 0 && FolioSustitucion != "")
|
|
// {
|
|
// var respCancelacion = CancelarDocumento(CveVenta, -2, CveCliente, "", FolioSustitucion, "", NowADS(), TipoDocto, Total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: true, FolioSustitucion: "", CveEstatusRefacturacion: 4, CveMotivoCancelacion: CveMotivoCancelacion);
|
|
|
|
// if (!respCancelacion.HuboError)
|
|
// {
|
|
// var sb = new StringBuilder();
|
|
// var EnviarAcuse = false;
|
|
// if (respCancelacion.CveEstatus > 0)
|
|
// {
|
|
// if (respCancelacion.CveEstatus.Contiene(5, 20))
|
|
// {
|
|
// EnviarAcuse = true;
|
|
// }
|
|
|
|
// var CveEstatus = respCancelacion.CveEstatus;
|
|
// var ObjVentas = new ClsVentas();
|
|
// if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa))
|
|
// {
|
|
// if (respCancelacion.CveEstatus == 20)
|
|
// {
|
|
// sb.Append($"El estatus de la factura <b>{SerieFolioSustitucion}</b> fue cambiado a <b>'Cancelación en proceso'</b>.");
|
|
|
|
// sb.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>");
|
|
// }
|
|
// else if (respCancelacion.CveEstatus == 23)
|
|
// {
|
|
// sb.Append("La solicitud de cancelación no la aplicó el SAT, intente cancelar de nuevo.");
|
|
// }
|
|
// else if (respCancelacion.CveEstatus == 5)
|
|
// {
|
|
// sb.Append($"El estatus de la factura <b>{SerieFolioSustitucion}</b> fue cambiado a <b>'Cancelada'</b>.");
|
|
// sb.Append("El documento se canceló correctamente.");
|
|
// sb.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>");
|
|
// }
|
|
|
|
// if (respCancelacion.CveEstatus.Contiene(5, 20))
|
|
// {
|
|
// if (ObjVentas.UpdateEstatusVenta(CveVentaOriginal, 23, UsuarioActual.CveEmpresa, CveEstatusRefacturacion: 4, CveMotivoCancelacion: CveMotivoCancelacion))
|
|
// {
|
|
// sb.Append($"</br>La Factura <b>{SerieFolioOriginal}</b> fue desligada.");
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// sb.Append("Ocurrió un error al cambiar el estatus de la factura.");
|
|
// }
|
|
// ObjVentas.Dispose();
|
|
|
|
// if (respCancelacion.CveEstatus == 23)
|
|
// {
|
|
// var resp = Timbrado.VerificarVigenciaSAT(FolioSustitucion, UsuarioActual.Empresa.RFC, RFCReceptor, Total, true);
|
|
// if (resp != null)
|
|
// {
|
|
// sb.AppendFormat("<br/> Folio Fiscal: {0} <br/>", FolioSustitucion);
|
|
// sb.AppendFormat("Código Estado: {0} <br/>", resp.CodigoEstatus);
|
|
// sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
|
|
// 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);
|
|
// }
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// var resp = Timbrado.VerificarVigenciaSAT(FolioSustitucion, UsuarioActual.Empresa.RFC, RFCReceptor, Total, true);
|
|
// if (resp != null)
|
|
// {
|
|
// sb.AppendFormat("Folio Fiscal: {0} <br/>", FolioSustitucion);
|
|
// sb.AppendFormat("Código Estado: {0} <br/>", resp.CodigoEstatus);
|
|
// sb.AppendFormat("Estado: {0} <br/>", resp.Estado);
|
|
// 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.Append(respCancelacion.Mensaje);
|
|
// }
|
|
|
|
// if (EnviarAcuse)
|
|
// {
|
|
// sb.Append("</br></br> ¿Desea enviar el Acuse de Cancelación al Cliente?");
|
|
// Alert(sb.ToString(), TipoMensaje.MsgConfirmacion, "BtnEnviarMailCancelacion();", TextoConfirmacion: "Enviar", TextoSegundoBoton: "Cancelar");
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert(sb.ToString());
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert(respCancelacion.Mensaje, TipoMensaje.MsgError);
|
|
// }
|
|
|
|
// CargaDatos();
|
|
// }
|
|
// UPDatos.Update();
|
|
|
|
//}
|
|
}
|
|
public class MRespuestaSAT
|
|
{
|
|
public int CveEstatus { get; set; }
|
|
public bool EnviarAcuse { get; set; }
|
|
public string LigaRefacturacion { get; set; }
|
|
public bool IrARefacturar { get; set; }
|
|
public string Mensaje { get; set; }
|
|
} |