- Se agrupan y resaltan las columnas correctamente Se actualizó PA_SAT_SolicitudTimbreIngresosRep en SIG_Resp_MLR - Se hizo un poco más ancha la vista de la tabla
914 lines
35 KiB
C#
914 lines
35 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
public partial class SAT_SolicitudesIngresoSat : ClsPaginas
|
|
{
|
|
#region Propiedades
|
|
|
|
public string clasegrid
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["clasegrid"] == null) { return ""; }
|
|
else { return ViewState["clasegrid"].ToString(); }
|
|
}
|
|
set { ViewState["clasegrid"] = value; }
|
|
}
|
|
public string fechaInicio
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["fechaInicio"] == null) { return ""; }
|
|
else { return ViewState["fechaInicio"].ToString(); }
|
|
}
|
|
set { ViewState["fechaInicio"] = value; }
|
|
}
|
|
public string fechaFin
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["fechaFin"] == null) { return ""; }
|
|
else { return ViewState["fechaFin"].ToString(); }
|
|
}
|
|
set { ViewState["fechaFin"] = value; }
|
|
}
|
|
public int TipoDescarga // 0 sin descarga 1 resumen 2 desglose
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["TipoDescarga"] == null) { return 0; }
|
|
else { return ViewState["TipoDescarga"].ToString().ToEntero(); }
|
|
}
|
|
set { ViewState["TipoDescarga"] = (int)value; }
|
|
}
|
|
|
|
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
TxtRpdFechaInicio.Text = string.Format("01/{0:MM/yyyy}", DateTime.Now.AddMonths(-1));
|
|
TxtRpdFechaFin.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now.AddMonths(-1).LastDayOfMonth());
|
|
LnkConsultar_Click(null, null);
|
|
|
|
//if (UsuarioActual.CveRol == 1)
|
|
//{
|
|
// GVSolicitudesNominas.Columns[8].Visible = true;
|
|
//}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
protected void LnkDownloadExcel_Click(object sender, EventArgs e)
|
|
{
|
|
if(TipoDescarga == 1) {
|
|
GvResumen.ExportToExcel2($"Resumen{DateTime.Now.ToString("yyyyMMddhhmmss")}");
|
|
}
|
|
|
|
if (TipoDescarga == 2)
|
|
{
|
|
GvDatos.ExportToExcel2($"PorComprobante{DateTime.Now.ToString("yyyyMMddhhmmss")}");
|
|
}
|
|
}
|
|
protected void LnkConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
DvDatos1.Visible = false;
|
|
DvDatos2.Visible = false;
|
|
DVResumen1.Visible = false;
|
|
DVResumen2.Visible = false;
|
|
|
|
TipoDescarga = 0;
|
|
|
|
LnkDownloadExcel.Visible = false;
|
|
|
|
if (DdlReporte.SelectedValue.ToEntero() == 1 || DdlReporte.SelectedValue.ToEntero() == 3)
|
|
{
|
|
DVResumen1.Visible = true;
|
|
DVResumen2.Visible = true;
|
|
DvDatos1.Visible = false;
|
|
DvDatos2.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
DVResumen1.Visible = false;
|
|
DVResumen2.Visible = false;
|
|
DvDatos1.Visible = true;
|
|
DvDatos2.Visible = true;
|
|
}
|
|
|
|
using (ClsNominas ObjNom = new ClsNominas())
|
|
{
|
|
if (ObjNom.SATSolicitudTimbreIngresosRep(UsuarioActual.CveEmpresa, TxtRpdFechaInicio.Text.ToDate(), TxtRpdFechaFin.Text.ToDate(), DdlReporte.SelectedValue.ToEntero(),DdlVista.SelectedValue.ToEntero()))
|
|
{
|
|
if (DdlReporte.SelectedValue.ToEntero() == 1 || DdlReporte.SelectedValue.ToEntero() == 3)
|
|
{
|
|
GvResumen.DataSource = ObjNom.DtResultados;
|
|
TipoDescarga = ObjNom.DtResultados.Rows.Count > 0 ? 1:0;
|
|
LnkDownloadExcel.Visible = true;
|
|
}
|
|
else if (DdlReporte.SelectedValue.ToEntero() == 2)
|
|
{
|
|
GvDatos.DataSource = ObjNom.DtResultados;
|
|
TipoDescarga = ObjNom.DtResultados.Rows.Count > 0 ? 2 : 0;
|
|
LnkDownloadExcel.Visible = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
GvResumen.DataBind();
|
|
GvDatos.DataBind();
|
|
UpDatos.Update();
|
|
UpAcciones.Update();
|
|
}
|
|
|
|
private void cargasolicitudes()
|
|
{
|
|
LnkverificarSolicitudes.Visible = false;
|
|
using (ClsNominas nom = new ClsNominas())
|
|
{
|
|
|
|
if (nom.SolicitudesGet(-1, UsuarioActual.CveEmpresa, CveTipoSolicitud: 3, Estatus: 0,Top:50))
|
|
{
|
|
GVSolicitudesPendientes.DataSource = nom.DtResultados;
|
|
if (nom.DtResultados.Rows.Count > 0)
|
|
{
|
|
LnkverificarSolicitudes.Visible = true;
|
|
}
|
|
GVSolicitudesPendientes.DataBind();
|
|
}
|
|
|
|
if (nom.SolicitudesGet(-1, UsuarioActual.CveEmpresa, CveTipoSolicitud: 3, Estatus:1,Top:50))
|
|
{
|
|
GVSolicitudesNominas.DataSource = nom.DtResultados;
|
|
GVSolicitudesNominas.DataBind();
|
|
}
|
|
}
|
|
UPModalViewSolicitudes.Update();
|
|
}
|
|
protected void LnkShowSolicitudes_Click(object sender, EventArgs e)
|
|
{
|
|
TabPanel.ActiveTabIndex = 0;
|
|
cargasolicitudes();
|
|
|
|
this.RegistraScript("$('#ModalViewSolicitudes').modal();");
|
|
}
|
|
|
|
protected void LnkSolicitarSat_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
StringBuilder sbResultado = new StringBuilder();
|
|
int idSolicitudCFDI = 0;
|
|
int idSolicitudMetadata = 0;
|
|
int estatus = 0;
|
|
string observaciones = "";
|
|
DateTime fechaInicio = txtFechaIAdd.Text.ToDateTime();
|
|
DateTime fechaFin = txtFechaFAdd.Text.ToDateTime();
|
|
int cveUsuarioIng = UsuarioActual.CveUsuario;
|
|
int cveEmpresa = UsuarioActual.CveEmpresa;
|
|
int CveSolicitudAgregada = -1;
|
|
int Folio = -1;
|
|
|
|
using (ClsNominas nom = new ClsNominas())
|
|
{
|
|
int CveTipoSolicitud = ChkMetaDatos.Checked ? 203 :3;
|
|
CveSolicitudAgregada = nom.SolicitudesAdd2(idSolicitudCFDI, idSolicitudMetadata, estatus, observaciones, fechaInicio, fechaFin, cveUsuarioIng, cveEmpresa, CveTipoSolicitud: CveTipoSolicitud);
|
|
|
|
if(CveSolicitudAgregada > 0)
|
|
{
|
|
Folio = nom.FolioSolicitud;
|
|
}
|
|
}
|
|
|
|
if (CveSolicitudAgregada > 0)
|
|
{
|
|
var api = new GeneralesAPII();
|
|
JToken ObjApiSolicitud = (JToken)api.GeneraSolicitud(UsuarioActual.CveEmpresa, 3, CveSolicitudAgregada);
|
|
List<string> resultSolicitud = new List<string>();
|
|
List<string> resultVerificacion = new List<string>();
|
|
|
|
var TipoMensaje = ModExtensiones.TipoMensaje.MsgInformacion;
|
|
var ResultadoSolicitudOK = false;
|
|
|
|
if (!(ObjApiSolicitud == null))
|
|
{
|
|
resultSolicitud = ObjApiSolicitud.Select(token => token.Values().Aggregate((i, j) => $"{i}|{j}").Value<string>()).ToList();
|
|
ResultadoSolicitudOK = bool.Parse(resultSolicitud[0]);
|
|
}
|
|
else
|
|
{
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
|
|
|
|
if (ResultadoSolicitudOK)
|
|
{
|
|
sbResultado.Append($"Solicitud registrada. {resultSolicitud[1]}<br> Folio: {Folio}");
|
|
}
|
|
else{
|
|
|
|
|
|
if(ObjApiSolicitud != null && resultSolicitud.Count == 4)
|
|
{
|
|
sbResultado.Append($"Solicitud registrada, pendiente de verificar en SAT <br> Folio: {Folio} <br>({resultSolicitud[1]})<br>");
|
|
}
|
|
else
|
|
{
|
|
sbResultado.Append($"Solicitud registrada, pendiente de verificar en SAT <br> Folio: {Folio}");
|
|
}
|
|
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert(sbResultado.ToString(), TipoMensaje);
|
|
}
|
|
else
|
|
{
|
|
Alert("No se puedo registrar la solictud".ToString(), ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
|
|
if (CveSolicitudAgregada > 0)
|
|
{
|
|
txtFechaIAdd.Text = "";
|
|
txtFechaFAdd.Text = "";
|
|
ChkMetaDatos.Checked = false;
|
|
this.RegistraScript("$('#ModalAgregarSolicitud').modal('hide');");
|
|
cargasolicitudes();
|
|
|
|
}
|
|
}
|
|
|
|
protected void LnkverificarSolicitudes_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
|
|
StringBuilder sbResultado = new StringBuilder();
|
|
|
|
|
|
foreach(GridViewRow GvRow in GVSolicitudesPendientes.Rows)
|
|
{
|
|
|
|
int CveSolicitudActual = GvRow.DataKey("CveSolicitud").ToEntero();
|
|
string idSolicitud = GvRow.DataKey("idSolicitud").Trim();
|
|
int CveTipoSolicitud = GvRow.DataKey("CveTipoSolicitud").ToEntero();
|
|
int Folio = GvRow.DataKey("Folio").ToEntero();
|
|
|
|
|
|
List<string> resultSolicitud = new List<string>();
|
|
List<string> resultVerificacion = new List<string>();
|
|
var ResultadoVerificaionOK = false;
|
|
var SeVerifico = false;
|
|
var TipoMensaje = ModExtensiones.TipoMensaje.MsgInformacion;
|
|
var ResultadoSolicitudOK = false;
|
|
|
|
|
|
var api = new GeneralesAPII();
|
|
|
|
|
|
if (idSolicitud.Length == 0)
|
|
{
|
|
JToken ObjApiSolicitud = (JToken)api.GeneraSolicitud(UsuarioActual.CveEmpresa, CveTipoSolicitud, CveSolicitudActual);
|
|
if (!(ObjApiSolicitud == null))
|
|
{
|
|
resultSolicitud = ObjApiSolicitud.Select(token => token.Values().Aggregate((i, j) => $"{i}|{j}").Value<string>()).ToList();
|
|
ResultadoSolicitudOK = bool.Parse(resultSolicitud[0]);
|
|
sbResultado.Append($"Solicitud {Folio} solicitada a SAT.<br>");
|
|
}
|
|
else
|
|
{
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
resultSolicitud = new List<string>();
|
|
resultSolicitud.Add("true");
|
|
resultSolicitud.Add("");
|
|
resultSolicitud.Add("");
|
|
resultSolicitud.Add("");
|
|
|
|
ResultadoSolicitudOK = true;
|
|
}
|
|
|
|
|
|
|
|
if (ResultadoSolicitudOK)
|
|
{
|
|
|
|
JToken ObjApiVerificacion = (JToken)api.VerificaSolicitudesNominas(UsuarioActual.CveEmpresa, CveTipoSolicitud, CveSolicitudActual);
|
|
|
|
|
|
if (!(ObjApiVerificacion == null))
|
|
{
|
|
resultVerificacion = ObjApiVerificacion.Select(token => token.Values().Aggregate((i, j) => $"{i}|{j}").Value<string>()).ToList();
|
|
ResultadoVerificaionOK = bool.Parse(resultVerificacion[0]);
|
|
SeVerifico = true;
|
|
}
|
|
else
|
|
{
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
if(resultSolicitud.Count == 4)
|
|
{
|
|
sbResultado.Append($"({resultSolicitud[1]})<br> Folio:{Folio} <br> ");
|
|
}
|
|
else
|
|
{
|
|
sbResultado.Append($"Solicitud pendiente de verificar en SAT <br> Folio:{Folio} <br>");
|
|
}
|
|
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
|
|
|
|
if (SeVerifico && resultVerificacion.Count == 4)
|
|
{
|
|
if (ResultadoVerificaionOK)
|
|
{
|
|
sbResultado.Append($"Solicitud procesada.<br> Folio: {Folio} <br> {resultVerificacion[1]}");
|
|
}
|
|
else
|
|
{
|
|
sbResultado.Append($"Solicitud no verificada <br> Folio: {Folio}{resultVerificacion[1]}.<br>");
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sbResultado.Append($"Se presento un error al verificar la solicitud <br> Folio: {Folio}.");
|
|
TipoMensaje = ModExtensiones.TipoMensaje.MsgAdvertencia;
|
|
}
|
|
|
|
Alert(sbResultado.ToString(), TipoMensaje);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cargasolicitudes();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Alert(ex.StackTrace);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
protected void LnkAgregarSolictud_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
txtFechaIAdd.Text = "";
|
|
txtFechaFAdd.Text = "";
|
|
ChkMetaDatos.Checked = false;
|
|
UPModalViewSolicitudesAgregar.Update();
|
|
this.RegistraScript("$('#ModalAgregarSolicitud').modal('show');");
|
|
}
|
|
|
|
protected void GvResumen_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if(e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if(e.Row.DataKey("Fecha") == "")
|
|
{
|
|
// e.Row.Cells[0].Text = "Total";
|
|
e.Row.Attributes.Add("class", "Totales");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void GvDatos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
|
|
if(e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
|
|
|
|
if (e.Row.DataKey("UUID") == "Totales")
|
|
{
|
|
e.Row.Font.Bold = true;
|
|
e.Row.Cells[1].Text = e.Row.DataKey("CountRegistrosSIG");
|
|
e.Row.Cells[2].Text = e.Row.DataKey("CountRegistrosSAT");
|
|
e.Row.Attributes.Add("class", "Totales");
|
|
}
|
|
|
|
if(e.Row.DataKey("UUID").ToUpper() != "TOTALES")
|
|
{
|
|
StringBuilder SBMsgToolTip = new StringBuilder();
|
|
|
|
if (e.Row.DataKey("DifImporte").ToDecimal() != 0 || (e.Row.DataKey("Abreviatura").ToUpper() != e.Row.DataKey("CBTMoneda").ToUpper()))
|
|
{
|
|
e.Row.CssClass = "bg-yellow-casablanca bg-font-yellow-casablanca";
|
|
}
|
|
|
|
|
|
e.Row.Attributes.Add("data-html", "true");
|
|
e.Row.Attributes.Add("data-toggle", "tooltip");
|
|
e.Row.Attributes.Add("data-placement", "top");
|
|
|
|
|
|
if (e.Row.DataKey("Sistema").ToUpper() == "NO" || e.Row.DataKey("CFDIData").ToUpper() == "NO")
|
|
{
|
|
if (e.Row.DataKey("Sistema").ToUpper() == "NO")
|
|
{
|
|
SBMsgToolTip.AppendLine("Comprobante no se encuentra en SIG.<br>");
|
|
}
|
|
if (e.Row.DataKey("CFDIData").ToUpper() == "NO")
|
|
{
|
|
SBMsgToolTip.AppendLine("Comprobante no se encuentra en descargas de SAT.<br>");
|
|
}
|
|
}
|
|
else {
|
|
if (e.Row.DataKey("DifImporte").ToDecimal() != 0)
|
|
{
|
|
SBMsgToolTip.AppendLine($" Diferencia importes {e.Row.DataKey("DifImporte").ToDecimal().ToString("###,###,###.00")}");
|
|
}
|
|
|
|
if (e.Row.DataKey("Abreviatura").ToUpper() != e.Row.DataKey("CBTMoneda").ToUpper())
|
|
{
|
|
SBMsgToolTip.AppendLine($"Diferencia en monedas.");
|
|
}
|
|
}
|
|
|
|
if (SBMsgToolTip.ToString().Length > 0)
|
|
{
|
|
e.Row.Attributes.Add("title", SBMsgToolTip.ToString());
|
|
}
|
|
|
|
LinkButton LnkCFDIData = e.Row.FCLinkButton("LnkCFDIData");
|
|
if((e.Row.DataKey("CFDIData").ToUpper() == "SI"))
|
|
{
|
|
ScriptManager.GetCurrent(this).RegisterPostBackControl(LnkCFDIData);
|
|
LnkCFDIData.CssClass = "Texto";
|
|
}
|
|
else
|
|
{
|
|
LnkCFDIData.PostBackUrl = "#";
|
|
}
|
|
|
|
//if(e.Row.DataKey("CveVenta").ToEntero() > 0)
|
|
//{
|
|
// e.Row.Cells[1].Text = $"<a href='/Ventas/Ventas.aspx?CveVenta={e.Row.DataKey("CveVenta").ToEntero()}'class='Texto' target='_blank' >Si</a>";
|
|
// e.Row.Cells[3].Text = $"<a href='/Ventas/Ventas.aspx?CveVenta={e.Row.DataKey("CveVenta").ToEntero()}'class='Texto' target='_blank' >{e.Row.DataKey("VSerieFolio")}</a>";
|
|
//}
|
|
}
|
|
}
|
|
|
|
if (e.Row.RowType == DataControlRowType.Header)
|
|
{
|
|
|
|
e.Row.Cells[1].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[2].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
|
|
|
|
e.Row.Cells[4].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[5].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[6].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[7].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[8].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[9].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
e.Row.Cells[10].BackColor = System.Drawing.Color.FromName("#3598dc"); //Azul
|
|
|
|
|
|
|
|
//e.Row.Cells[11].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
//e.Row.Cells[12].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
//e.Row.Cells[13].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
//e.Row.Cells[14].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
//e.Row.Cells[15].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
//e.Row.Cells[16].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
//e.Row.Cells[17].BackColor = System.Drawing.Color.FromName("#900"); //Rojo
|
|
|
|
e.Row.Cells[11].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
e.Row.Cells[12].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
e.Row.Cells[13].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
e.Row.Cells[14].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
e.Row.Cells[15].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
e.Row.Cells[16].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
e.Row.Cells[17].BackColor = System.Drawing.Color.FromName("#C46B06"); //Rojo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e.Row.Cells[1].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[2].ForeColor = System.Drawing.Color.FromName("white");
|
|
|
|
e.Row.Cells[4].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[5].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[7].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[8].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[9].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[10].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[11].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[12].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[13].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[14].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[15].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[16].ForeColor = System.Drawing.Color.FromName("white");
|
|
e.Row.Cells[17].ForeColor = System.Drawing.Color.FromName("white");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected void LnkDescargaXML_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
|
|
var UrlDescarga = $"{UsuarioActual.Empresa.Ruta}NomXMLSAT\\Descargas\\{GvRow.DataKey("ArchivoXML")}";
|
|
|
|
var Archivo = new System.IO.FileInfo(UrlDescarga);
|
|
|
|
if (Archivo.Exists)
|
|
{
|
|
Response.Clear();
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + Archivo.Name);
|
|
Response.AddHeader("Content-Length", Archivo.Length.ToString());
|
|
Response.ContentType = "text/octet-stream";
|
|
Response.Flush();
|
|
Response.TransmitFile(Archivo.FullName);
|
|
Response.End();
|
|
}
|
|
|
|
}
|
|
|
|
protected void GVSolicitudesNominas_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DataKey("ArchivoXML").Length > 0)
|
|
{
|
|
var UrlDescarga = $"{UsuarioActual.Empresa.Ruta}NomXMLSAT\\Descargas\\{e.Row.DataKey("ArchivoXML")}";
|
|
|
|
if (System.IO.File.Exists(UrlDescarga)){
|
|
LinkButton LnkDescargaXML = e.Row.FCLinkButton("LnkDescargaXML");
|
|
ScriptManager.GetCurrent(this).RegisterPostBackControl(LnkDescargaXML);
|
|
LnkDescargaXML.Visible = true;
|
|
}
|
|
}
|
|
|
|
Label lblobservaciones = e.Row.FCLabel("lblobservaciones");
|
|
Label lBLTipoDescarga = e.Row.FCLabel("lBLTipoDescarga");
|
|
|
|
lblobservaciones.Attributes.Add("data-html", "true");
|
|
lblobservaciones.Attributes.Add("data-toggle", "tooltip");
|
|
lblobservaciones.Attributes.Add("data-placement", "top");
|
|
lblobservaciones.Attributes.Add("title", e.Row.DataKey("Observaciones"));
|
|
|
|
lBLTipoDescarga.Attributes.Add("data-html", "true");
|
|
lBLTipoDescarga.Attributes.Add("data-toggle", "tooltip");
|
|
lBLTipoDescarga.Attributes.Add("data-placement", "top");
|
|
lBLTipoDescarga.Attributes.Add("title", e.Row.DataKey("TipoDescargaStr"));
|
|
|
|
}
|
|
}
|
|
|
|
private void CargaComprobanteXML(string DirectoryPath, int CveSolicitudDetalle)
|
|
{
|
|
|
|
int Contador = 0;
|
|
|
|
System.IO.DirectoryInfo DirInfo = new System.IO.DirectoryInfo(DirectoryPath);
|
|
IEnumerable<System.IO.FileInfo> files = DirInfo.EnumerateFiles();
|
|
|
|
foreach (var f in files)
|
|
{
|
|
|
|
if(f.Extension.ToUpper() == ".XML")
|
|
{
|
|
string UUID = "";
|
|
System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument();
|
|
try
|
|
{
|
|
XMLDoc.Load(f.FullName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
var oReader = new System.IO.StreamReader(f.FullName, System.Text.Encoding.GetEncoding("ISO-8859-1"));
|
|
XMLDoc.Load(oReader);
|
|
oReader.Dispose();
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
// GuardaLog("Error al intentar leer el XML del SAT. Error:" + ex2.ToString());
|
|
ModExtensiones.GuardaLog(ex2.StackTrace);
|
|
}
|
|
}
|
|
|
|
|
|
System.Xml.XmlNode nodo = XMLDoc.DocumentElement;
|
|
string Version = ValorXML(nodo, "version");
|
|
|
|
System.Xml.XmlNamespaceManager namespaces = new System.Xml.XmlNamespaceManager(XMLDoc.NameTable);
|
|
string Prefijo = XMLDoc.DocumentElement.Prefix == "" ? "cfd" : XMLDoc.DocumentElement.Prefix;
|
|
string cfdVer = "";
|
|
|
|
if (Version == "3.2")
|
|
{
|
|
Prefijo = "cfd";
|
|
cfdVer = "http://www.sat.gob.mx/cfd/2";
|
|
}
|
|
else if (Version == "3.3")
|
|
cfdVer = "http://www.sat.gob.mx/cfd/3";
|
|
else
|
|
cfdVer = "http://www.sat.gob.mx/cfd/4";
|
|
|
|
namespaces.AddNamespace(Prefijo, cfdVer);
|
|
namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital");
|
|
namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal");
|
|
namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal");
|
|
|
|
System.Xml.XmlNode node;
|
|
node = XMLDoc.SelectSingleNode(string.Format("//{0}:Emisor", Prefijo), namespaces);
|
|
|
|
System.Xml.XmlNode nodeComp = XMLDoc.SelectSingleNode(string.Format("//{0}:Complemento", Prefijo), namespaces);
|
|
if (node != null )
|
|
{
|
|
System.Xml.XmlNode nodeTFD = nodeComp.SelectSingleNode(string.Format("//{0}:TimbreFiscalDigital", "tfd"), namespaces);
|
|
UUID = ValorXML(nodeTFD, "UUID", "");
|
|
}
|
|
|
|
if (UUID.Length > 0)
|
|
{
|
|
try {
|
|
System.IO.File.Move(f.FullName, $@"{f.DirectoryName}\{UUID.ToUpper()}.XML");
|
|
Contador++;
|
|
} catch (Exception ex3)
|
|
{
|
|
ModExtensiones.GuardaLog(ex3.StackTrace);
|
|
}
|
|
|
|
|
|
//ClsNominas objNominas = new ClsNominas();
|
|
//objNominas.UpdateSolicitudDetalleCveSolicitudDetalle(UsuarioActual.CveEmpresa, UUID, CveSolicitudDetalle);
|
|
//objNominas.Dispose();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
Alert("Archivos Renombrados ");
|
|
}
|
|
|
|
private string ValorXML(System.Xml.XmlNode n, string Campo, string Retorno = "")
|
|
{
|
|
System.Xml.XmlNode o = n.Attributes.Cast<System.Xml.XmlAttribute>().SingleOrDefault(a => string.Compare(a.Name, Campo, true) == 0);
|
|
if (o == null)
|
|
return Retorno;
|
|
else
|
|
return o.Value;
|
|
}
|
|
|
|
protected void LnkRenombrarArchivos_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
var CveSolicitudDetalle = GvRow.DataKey("CveSolicitudDetalle").ToEntero();
|
|
var UrlDirectorio = $"{UsuarioActual.Empresa.Ruta}DescargasSATXML\\Ingresos\\{CveSolicitudDetalle}";
|
|
CargaComprobanteXML(UrlDirectorio, CveSolicitudDetalle);
|
|
|
|
}
|
|
|
|
protected void LnkCFDIData_Click(object sender, EventArgs e)
|
|
{
|
|
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
|
|
|
|
var CveSolicitudDetalle = GvRow.DataKey("CveSolicitudDetalle");
|
|
|
|
var UrlDescargaXML = $"{UsuarioActual.Empresa.Ruta}DescargasSATXML\\Ingresos\\{CveSolicitudDetalle}\\{GvRow.DataKey("UUID")}.XML";
|
|
|
|
var ArchivoXML = new System.IO.FileInfo(UrlDescargaXML);
|
|
|
|
if (ArchivoXML.Exists)
|
|
{
|
|
Response.Clear();
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + ArchivoXML.Name);
|
|
Response.AddHeader("Content-Length", ArchivoXML.Length.ToString());
|
|
Response.ContentType = "text/octet-stream";
|
|
Response.Flush();
|
|
Response.TransmitFile(ArchivoXML.FullName);
|
|
Response.End();
|
|
}
|
|
else
|
|
{
|
|
//if(UsuarioActual.CveRol == 1)
|
|
//{
|
|
// Alert(UrlDescargaXML);
|
|
//}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class GeneralesAPII : ADSNetLibraryzI.HelpersI.ConexionesI.SIGAPII.BaseSIGAPII
|
|
{
|
|
public GeneralesAPII(string domainApi = "http://localhost:4001/", string token = "") : base(domainApi, token) { }
|
|
|
|
|
|
public object GeneraSolicitud(int CveEmpresa, int CveTipoSolicitud, int CveSolicitud)
|
|
{
|
|
return getData<object>($"GeneraSolicitud/{CveEmpresa}/{CveTipoSolicitud}/{CveSolicitud}", null, ADSNetLibraryzI.HelpersI.ConexionesI.SIGAPII.requestMethod.GET, false);
|
|
}
|
|
public object VerificaSolicitudesNominas(int CveEmpresa, int CveTipoSolicitud, int CveSolicitud)
|
|
{
|
|
return getData<object>($"VerificaSolicitudesNominas/{CveEmpresa}/{CveTipoSolicitud}/{CveSolicitud}", null, ADSNetLibraryzI.HelpersI.ConexionesI.SIGAPII.requestMethod.GET, false);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
namespace ADSNetLibraryzI.HelpersI.ConexionesI.SIGAPII
|
|
{
|
|
|
|
public enum requestMethod
|
|
{
|
|
POST = 1,
|
|
GET = 2
|
|
}
|
|
public class BaseSIGAPII
|
|
{
|
|
private const string tituloLog = " ADSNetLibraryzI.HelpersI.ConexionesI.SIGAPII";
|
|
public string domainApi;
|
|
public string authorization;
|
|
protected string RouteController = "";
|
|
protected string FullRoute = "";
|
|
public string GetRoutbyclass()
|
|
{
|
|
string classname = this.GetType().Name;
|
|
return classname.Substring(0, classname.Length - 4);
|
|
}
|
|
public string GetRoute(string path)
|
|
{
|
|
if (string.IsNullOrEmpty(FullRoute))
|
|
{
|
|
return string.Format("api/{0}/{1}", (string.IsNullOrEmpty(RouteController) ? GetRoutbyclass() : RouteController), path);
|
|
}
|
|
else
|
|
{
|
|
return string.Format("{0}{1}", FullRoute, path);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// nueva instancia de conexion para una api
|
|
/// </summary>
|
|
/// <param name="domainApi"> url de la api</param>
|
|
/// <param name="authorization"> llenar si se tiene si se desea obtner usuar campos usuario y pasword</param>
|
|
public BaseSIGAPII(string domainApi, string authorization = null, string fullRoute = null)
|
|
{
|
|
if (string.IsNullOrEmpty(domainApi))
|
|
{
|
|
domainApi = "http://localhost:4001/";//"http://jam.adssistemas.mx:4001/";//Helpers.ModVars.UrlApi;
|
|
}
|
|
this.authorization = authorization;
|
|
this.domainApi = domainApi;
|
|
this.FullRoute = fullRoute;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Obtiene datos de la api asincrono.
|
|
/// </summary>
|
|
/// <typeparam name="T">Clase genérica en donde se obtiene la información del SqlDataReader.</typeparam>
|
|
/// <param name="path">ruta sin domino ejemplo "/api/usuarios/login".</param>
|
|
/// <param name="requestobject">request object.</param>
|
|
/// <returns>Lista de objetos.</returns>
|
|
public async Task<T> getDataAsync<T>(string path, object requestobject, requestMethod reqmet = requestMethod.POST, bool needauthorization = true, bool isfullpath = false) where T : class, new()
|
|
{
|
|
T objreturn = null;
|
|
using (
|
|
HttpClient client = new HttpClient())
|
|
{
|
|
// Setting Base address.
|
|
client.BaseAddress = new Uri(domainApi);
|
|
// Setting content type.
|
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
// Setting Authorization.
|
|
if (needauthorization) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authorization); }
|
|
client.Timeout = TimeSpan.FromMinutes(15);
|
|
HttpResponseMessage response = new HttpResponseMessage();
|
|
|
|
var strjsonreq = Newtonsoft.Json.JsonConvert.SerializeObject(requestobject);
|
|
StringContent content = new StringContent(strjsonreq, Encoding.UTF8, "application/json");
|
|
string route = isfullpath ? path : GetRoute(path);
|
|
try
|
|
{
|
|
|
|
switch (reqmet)
|
|
{
|
|
case requestMethod.POST:
|
|
response = await client.PostAsync(route, content);
|
|
break;
|
|
case requestMethod.GET:
|
|
response = await client.GetAsync(route);
|
|
break;
|
|
}
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string jsondata = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings
|
|
{
|
|
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
|
|
MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore
|
|
};
|
|
objreturn = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsondata, settings);
|
|
}
|
|
else
|
|
{
|
|
//ModExtensiones.GuardaLog(string.Format("{0}{1}{2}{1}StatusCode:{3}{1}{4}{1}{5}{1}", tituloLog, ModVars.NewLine, route, response.StatusCode, response.RequestMessage, strjsonreq), ModVars.ADSNetLibraryLog);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//ModExtensiones.GuardaLog(string.Format("{0}{1}{2}{1}{3}{1}{4}{1}", tituloLog, ModVars.NewLine, route, e, strjsonreq), ModVars.ADSNetLibraryLog);
|
|
}
|
|
|
|
}
|
|
return objreturn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Obtiene datos de la api.
|
|
/// </summary>
|
|
/// <typeparam name="T">Clase genérica en donde se obtiene la información del SqlDataReader.</typeparam>
|
|
/// <param name="path">ruta sin domino ejemplo "/api/usuarios/login".</param>
|
|
/// <param name="requestobject">request object.</param>
|
|
/// <returns>Lista de objetos.</returns>
|
|
//public T getData<T> (string path, object requestobject, requestMethod reqmet = requestMethod.POST, bool needauthorization = true, bool isfullpath = false) where T : class, new()
|
|
public T getData<T>(string path, object requestobject, requestMethod reqmet = requestMethod.POST, bool needauthorization = true, bool isfullpath = false) where T : class, new()
|
|
{
|
|
return AsyncHelper.RunSync<T>(() => getDataAsync<T>(path, requestobject, reqmet, needauthorization, isfullpath));
|
|
}
|
|
}
|
|
internal static class AsyncHelper
|
|
{
|
|
private static readonly TaskFactory _myTaskFactory = new
|
|
TaskFactory(CancellationToken.None,
|
|
TaskCreationOptions.None,
|
|
TaskContinuationOptions.None,
|
|
TaskScheduler.Default);
|
|
|
|
public static TResult RunSync<TResult>(Func<Task<TResult>> func)
|
|
{
|
|
return AsyncHelper._myTaskFactory
|
|
.StartNew<Task<TResult>>(func)
|
|
.Unwrap<TResult>()
|
|
.GetAwaiter()
|
|
.GetResult();
|
|
}
|
|
|
|
public static void RunSync(Func<Task> func)
|
|
{
|
|
AsyncHelper._myTaskFactory
|
|
.StartNew<Task>(func)
|
|
.Unwrap()
|
|
.GetAwaiter()
|
|
.GetResult();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|