public Acuse ConsultaCFDIService(string consulta) { try { using (var client = new ConsultaCFDIServiceClient(_myBinding, new EndpointAddress(this.Url))) { return(client.Consulta(consulta)); } } catch (Exception ex) { throw ex; } }
private void btnIniciar_Click(object sender, EventArgs e) { disable_UI(); int cont = 0; try { ConsultaCFDIServiceClient consultar = new ConsultaCFDIServiceClient(); consultar.Open(); foreach (XMLRow row in ArchivosXML) { cont++; if (!(row.XML_Esquema_CFDI == "Esquema Invalido" || row.XML_Complemento_TFD == "Complemento Invalido")) { Acuse acuse = new Acuse(); lblStatus.Text = "Archivo " + cont.ToString() + " de " + ArchivosXML.Count().ToString() + " Comprobando " + row.XML_Nombre_Archivo + " con UUID :" + row.XML_UUID + "..."; statusStrip1.Refresh(); if (consultar.State == CommunicationState.Opened) { acuse = consultar.Consulta("?re=" + row.XML_RFC_Emisor.Replace("&", "&") + "&rr=" + row.XML_RFC_Receptor.Replace("&", "&") + "&tt=" + row.XML_Total + "&id=" + row.XML_UUID); row.XML_Status = acuse.CodigoEstatus; } if (consultar.State == CommunicationState.Closed) { row.XML_Status = "Comunicacion cerrada, error"; } if (consultar.State == CommunicationState.Faulted) { row.XML_Status = "Comunicacion fallida, error. Reintente"; } if (consultar.State == CommunicationState.Closed) { row.XML_Status = "Comunicacion cerrada, error. Reintente"; } } } ActualizaGrid(); } catch (Exception ex) { MessageBox.Show("Error:" + ex.Message); } lblStatus.Text = ""; statusStrip1.Refresh(); enable_UI(); }
private void btnMostrar_Click(object sender, EventArgs e) { var id = txtId.Text; WSPersonasClient client = new WSPersonasClient(); ConsultaCFDIServiceClient cliente = new ConsultaCFDIServiceClient("BasicHttpBinding_IConsultaCFDIService"); var acuse = cliente.Consulta("?re=[RFC_Emisor]&rr=[RFC_Receptor]&tt=[Total]&id=[UUID]"); lblError.Text = acuse.CodigoEstatus; lblNombre.Text = acuse.Estado; /*var persona = client.ObtenerPersona(id); * * lblNombre.Text = persona.Nombre; * lblEdad.Text = persona.Edad.ToString(); * lblError.Text = persona.Error;*/ }
private void procesar() { int cont = 0; try { ConsultaCFDIServiceClient consultar = new ConsultaCFDIServiceClient(); consultar.Open(); foreach (XMLRow row in ArchivosXML) { cont++; if (!(row.XML_Esquema_CFDI == "Esquema Invalido" || row.XML_Complemento_TFD == "Complemento Invalido")) { Acuse acuse = new Acuse(); if (consultar.State == CommunicationState.Opened) { acuse = consultar.Consulta("?re=" + row.XML_RFC_Emisor.Replace("&", "&") + "&rr=" + row.XML_RFC_Receptor.Replace("&", "&") + "&tt=" + row.XML_Total + "&id=" + row.XML_UUID); row.XML_Status = acuse.CodigoEstatus; } if (consultar.State == CommunicationState.Closed) { row.XML_Status = "Comunicacion cerrada, error"; } if (consultar.State == CommunicationState.Faulted) { row.XML_Status = "Comunicacion fallida, error. Reintente"; } if (consultar.State == CommunicationState.Closed) { row.XML_Status = "Comunicacion cerrada, error. Reintente"; } } } ActualizaGrid(); } catch (Exception ex) { } }
public string ConsultaEstatusCFDI(string expresion) { string result; try { ConsultaCFDIServiceClient CFDI = new ConsultaCFDIServiceClient(); int i = expresion.IndexOf("&rr="); i += 4; int j = expresion.IndexOf("&tt="); string c = expresion.Substring(i, j - i); string z = c.Replace("&", "&"); expresion = expresion.Replace(c, z); i = expresion.IndexOf("&re="); i += 4; j = expresion.IndexOf("&rr="); c = expresion.Substring(i, j - i); z = c.Replace("&", "&"); expresion = expresion.Replace(c, z); SAT.CFDI.Cliente.Procesamiento.ServicioConsultaCFDI.Acuse x = CFDI.Consulta(expresion); result = string.Concat(new string[] { x.Estado, "|", x.EsCancelable, "|", x.EstatusCancelacion }); } catch (Exception exception) { AccesoServicios.Log.Error("(ConsultaCFDI) Error al consultar los CFDI's " + exception.ToString()); result = "Error en la consulta al sat"; } return(result); }
private void btnIniciar_Click(object sender, EventArgs e) { disable_UI(); int cont = 0; try { ConsultaCFDIServiceClient consultar = new ConsultaCFDIServiceClient(); consultar.Open(); foreach (XMLRow row in ArchivosXML) { cont++; if (!(row.XML_Esquema_CFDI == "Esquema Invalido" || row.XML_Complemento_TFD == "Complemento Invalido")) { Acuse acuse = new Acuse(); lblStatus.Text = "Archivo " + cont.ToString() + " de " + ArchivosXML.Count().ToString() + " Comprobando "+row.XML_Nombre_Archivo+" con UUID :" + row.XML_UUID + "..."; statusStrip1.Refresh(); if (consultar.State == CommunicationState.Opened) { acuse = consultar.Consulta("?re=" + row.XML_RFC_Emisor.Replace("&", "&") + "&rr=" + row.XML_RFC_Receptor.Replace("&", "&") + "&tt=" + row.XML_Total + "&id=" + row.XML_UUID); row.XML_Status = acuse.CodigoEstatus; } if (consultar.State == CommunicationState.Closed) { row.XML_Status = "Comunicacion cerrada, error"; } if (consultar.State == CommunicationState.Faulted) { row.XML_Status = "Comunicacion fallida, error. Reintente"; } if (consultar.State == CommunicationState.Closed) { row.XML_Status = "Comunicacion cerrada, error. Reintente"; } } } ActualizaGrid(); } catch(Exception ex) { MessageBox.Show("Error:" + ex.Message); } lblStatus.Text = ""; statusStrip1.Refresh(); enable_UI(); }
protected void btnAceptarImportar_Click(object sender, EventArgs e) { string tmp; try { //Copia los archivos en la carpeta destino //string dirDestino = @System.Configuration.ConfigurationSettings.AppSettings["PathArchivos"].ToString(); string dirDestino = Server.MapPath("") + "\\Facturas\\"; string dirDestPDF = dirDestino; string dirDestXML = dirDestino; if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { dirDestPDF += System.IO.Path.GetFileName(File1.PostedFile.FileName); try { File1.PostedFile.SaveAs(dirDestPDF); } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgErrorCopiarArchivo")); } } if ((File2.PostedFile != null) && (File2.PostedFile.ContentLength > 0)) { dirDestXML += System.IO.Path.GetFileName(File2.PostedFile.FileName); try { File2.PostedFile.SaveAs(dirDestXML); } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgErrorCopiarArchivo")); } } if ((File3.PostedFile != null) && (File3.PostedFile.ContentLength > 0)) { dirDestino += System.IO.Path.GetFileName(File3.PostedFile.FileName); try { File3.PostedFile.SaveAs(dirDestino); } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgErrorCopiarArchivo")); } } if ((File4.PostedFile != null) && (File4.PostedFile.ContentLength > 0)) { dirDestino += System.IO.Path.GetFileName(File4.PostedFile.FileName); try { File4.PostedFile.SaveAs(dirDestino); } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgErrorCopiarArchivo")); } } if ((File5.PostedFile != null) && (File5.PostedFile.ContentLength > 0)) { dirDestino += System.IO.Path.GetFileName(File5.PostedFile.FileName); try { File5.PostedFile.SaveAs(dirDestino); } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgErrorCopiarArchivo")); } } NegocioPF.Factura oFactura = new NegocioPF.Factura(); XmlReader xmlReader = XmlReader.Create(dirDestXML); try { XmlDocument doc = new XmlDocument(); doc.Load(xmlReader); //doc.Load(dirDestino); oFactura.Sociedad = cboSociedades.SelectedValue; string version = Rutinas.ObtenerValorAtributo(ref doc, "Version"); tmp = Rutinas.ObtenerValorAtributo(ref doc, "folio"); oFactura.NumFactura = (tmp != "" ? tmp : ""); tmp = Rutinas.ObtenerValorAtributo(ref doc, "serie"); oFactura.Serie = tmp; tmp = Rutinas.ObtenerValorAtributo(ref doc, "fecha"); oFactura.Fecha = (tmp != "" ? new DateTime(Convert.ToInt32(tmp.Substring(0, 4)), Convert.ToInt32(tmp.Substring(5, 2)), Convert.ToInt32(tmp.Substring(8, 2))) : new DateTime(1900, 1, 1)); tmp = Rutinas.ObtenerValorAtributo(ref doc, "total"); if (tmp != "") { oFactura.Importe = Convert.ToDouble(tmp); } tmp = Rutinas.ObtenerValorAtributo(ref doc, "moneda"); oFactura.Moneda = tmp; NegocioPF.UnidadMedida oUnidadMedida = new UnidadMedida(); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { if (node.Name == "cfdi:Emisor") { oFactura.Emisor = Rutinas.ObtenerValorAtributoNodo(node, "rfc"); oFactura.NomEmisor = Rutinas.ObtenerValorAtributoNodo(node, "nombre"); } if (node.Name == "cfdi:Receptor") { oFactura.Receptor = Rutinas.ObtenerValorAtributoNodo(node, "rfc"); oFactura.NomReceptor = Rutinas.ObtenerValorAtributoNodo(node, "nombre"); } if (node.Name == "cfdi:Conceptos") { foreach (XmlNode child in node.ChildNodes) { if (child.Name == "cfdi:Concepto") { DataRow r = oFactura.Materiales.NewRow(); r["Posicion"] = 0; r["Descripcion"] = Rutinas.ObtenerValorAtributoNodo(child, "descripcion"); //child.Attributes["descripcion"].Value; tmp = Rutinas.ObtenerValorAtributoNodo(child, "cantidad"); if (tmp != "") { r["Cantidad"] = Convert.ToDouble(tmp); //Convert.ToDouble(child.Attributes["cantidad"].Value); } tmp = Rutinas.ObtenerValorAtributoNodo(child, "valorUnitario"); if (tmp != "") { r["ValorUnitario"] = Convert.ToDouble(tmp); //child.Attributes["valorUnitario"].Value } tmp = Rutinas.ObtenerValorAtributoNodo(child, "importe"); if (tmp != "") { r["Importe"] = Convert.ToDouble(tmp); } tmp = Rutinas.ObtenerValorAtributoNodo(child, "unidad"); if (tmp != "") { oUnidadMedida.Buscar(tmp); r["Unidad"] = oUnidadMedida.UnidadSAP; } r["Anio_ent"] = "0"; r["Entrega"] = ""; r["Pos_ent"] = 0; oFactura.Materiales.Rows.Add(r); } } } if (node.Name == "cfdi:Impuestos") { //oFactura.Impuestos = Convert.ToDouble(node.Attributes["totalImpuestosTrasladados"].Value); foreach (XmlNode child in node.ChildNodes) { if (child.Name == "cfdi:Traslados") { foreach (XmlNode child1 in child.ChildNodes) { if (child1.Name == "cfdi:Traslado") { tmp = Rutinas.ObtenerValorAtributoNodo(child1, "tasa"); if (tmp != "") { oFactura.Tasa = Convert.ToInt32(Convert.ToDouble(tmp)); } else { tmp = Rutinas.ObtenerValorAtributoNodo(child1, "tasaOCuota"); if (tmp != "") { oFactura.Tasa = Convert.ToInt32(Convert.ToDouble(tmp) * 100); } } if (oFactura.Tasa < 1) { oFactura.Tasa = oFactura.Tasa * 100; } } } } } } if (node.Name == "cfdi:Complemento") { foreach (XmlNode child in node.ChildNodes) { if (child.Name == "tfd:TimbreFiscalDigital") { oFactura.UUID = Rutinas.ObtenerValorAtributoNodo(child, "UUID"); } } } } xmlReader.Dispose(); //Busca la clave SAP de la moneda NegocioPF.Moneda oMoneda = new NegocioPF.Moneda(); oMoneda.Buscar(oFactura.Moneda); if (oMoneda.ID != "") { oFactura.Moneda = oMoneda.MonedaSAP; cboMoneda.SelectedValue = oMoneda.MonedaSAP; } //Busca la clave del indicador de impuesto NegocioPF.Indicador oIndicador = new Indicador(); oIndicador.Buscar(oFactura.Tasa); if (oIndicador.ID != "") { oFactura.IndImpuestos = oIndicador.ID; } //Valida que esté cargando una factura el proveedor NegocioPF.Proveedor oProveedor = new Proveedor(((Usuario)Session["oUsuario"]).Id); oProveedor.Cargar(); //Si es un proveedor if (oProveedor.RFC != "") { if (oProveedor.RFC != oFactura.Emisor) { if (oProveedor.Intermediario == false) { throw new Exception("MsgErrFacDifProv"); } } } //Escribe los datos de la factura en los controles txtFactura.Text = oFactura.NumFactura.ToString(); txtFecha.Text = oFactura.Fecha.ToString("yyyy-MM-dd"); txtImporte.Text = oFactura.Importe.ToString("###,##0.#0"); txtEmisor.Text = oFactura.Emisor + " " + oFactura.NomEmisor; txtReceptor.Text = oFactura.Receptor + " " + oFactura.NomReceptor; txtUUID.Text = oFactura.UUID; cboMoneda.SelectedValue = "0"; try { cboMoneda.SelectedValue = oFactura.Moneda; } catch { /*Maneja error*/ } //Inhabilita los controles txtFactura.Enabled = (txtFactura.Text.Trim().Length == 0); txtFecha.Enabled = (txtFecha.Text.Trim().Length == 0); txtImporte.Enabled = (txtImporte.Text.Trim().Length == 0); cboMoneda.Enabled = (cboMoneda.SelectedValue == "0"); txtEmisor.Enabled = (txtEmisor.Text.Trim().Length == 0); txtReceptor.Enabled = (txtReceptor.Text.Trim().Length == 0); txtUUID.Enabled = false; Session["oFactura"] = oFactura; } catch (Exception ex) { xmlReader.Dispose(); if (ex.Message.Length > 3) { if (ex.Message.Substring(0, 3) == "Msg") { throw new Exception(ex.Message); } else { throw new Exception("MsgErrLeerXML"); } } } //Verifica si existe ya en el grid foreach (GridViewRow f in grdFacturas.Rows) { if (f.Cells[1].Text == oFactura.UUID) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgFactDuplicada")); return; } //Valida si es el mismo proveedor if (f.Cells[3].Text != oFactura.Emisor) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgFactDifProveedor")); return; } } //Valida si debe hacer la validación ante el SAT NegocioPF.Configuracion oConfig = new NegocioPF.Configuracion(); oConfig.Cargar(); if (oConfig.ValidacionSAT) { //Manda a validar el archivo CFD //wsSAT.WsValidacionCFDsExtSoapClient obj = new WsValidacionCFDsExtSoapClient(); //resultado = obj.ValidarXmlCFD(doc.InnerXml); //resultado = obj.ValidarXmlCFD(xml); //Manda a verificar si exite el folio en el SAT wsValidaCFDIs.Acuse objAcuse; wsValidaCFDIs.ConsultaCFDIServiceClient obj = new ConsultaCFDIServiceClient(); //Arma la cadena string cadena = "?re=" + oFactura.Emisor + "&rr=" + oFactura.Receptor + "&tt=" + oFactura.Importe.ToString() + "&id=" + oFactura.UUID; //objAcuse = obj.Consulta("?re=CBJ030505UR7&rr=DEM8801152E9&tt=244.00&id=5B8281DD-4CE8-4CCB-8077-445B9D2AD750"); objAcuse = obj.Consulta(cadena); txtValidacion.Text = objAcuse.CodigoEstatus; obj.Close(); btnAgregarFactura.Visible = (objAcuse.CodigoEstatus.Substring(0, 1) == "S"); } else { btnAgregarFactura.Visible = true; } //Muestra la factura en el visor if (File1.PostedFile.FileName.Length > 0) { oViewer.Attributes.Add("src", "Facturas/" + System.IO.Path.GetFileName(File1.PostedFile.FileName)); oViewer.Visible = true; divVisor.Visible = true; } oFactura.Archivos.Add(new NegocioPF.Archivo(System.IO.Path.GetFileName(File1.PostedFile.FileName), 1)); oFactura.Archivos.Add(new NegocioPF.Archivo(System.IO.Path.GetFileName(File2.PostedFile.FileName), 2)); if (File3.PostedFile.FileName != "") { oFactura.Archivos.Add(new NegocioPF.Archivo(System.IO.Path.GetFileName(File3.PostedFile.FileName), 3)); } if (File4.PostedFile.FileName != "") { oFactura.Archivos.Add(new NegocioPF.Archivo(System.IO.Path.GetFileName(File4.PostedFile.FileName), 4)); } if (File5.PostedFile.FileName != "") { oFactura.Archivos.Add(new NegocioPF.Archivo(System.IO.Path.GetFileName(File5.PostedFile.FileName), 5)); } //oFactura.PDF = System.IO.Path.GetFileName(File1.PostedFile.FileName); //oFactura.XML = System.IO.Path.GetFileName(File2.PostedFile.FileName); Session["pdf"] = System.IO.Path.GetFileName(File1.PostedFile.FileName); Session["xml"] = System.IO.Path.GetFileName(File2.PostedFile.FileName); divDetalle.Visible = true; divImportar.Visible = false; } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto(ex.Message)); } }
public string ConsultaCFDI(string expresion, string uuid, string rfcReceptor, SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asig) { string result; try { /* * if (expresion.Contains("&id=")) * { * expresion = expresion.Replace("&id=", "&id="); * } * if (expresion.Contains("&re=")) * { * expresion = expresion.Replace("&re=", "&re="); * } * if (expresion.Contains("&rr=")) * { * expresion = expresion.Replace("&rr=", "&rr="); * } * if (expresion.Contains("&tt=")) * { * expresion = expresion.Replace("&tt=", "&tt="); * } * if (expresion.Contains("&fe=")) * { * expresion = expresion.Replace("&fe=", "&fe="); * } */ int i = expresion.IndexOf("&rr="); i += 4; int j = expresion.IndexOf("&tt="); string c = expresion.Substring(i, j - i); string z = c.Replace("&", "&"); expresion = expresion.Replace(c, z); i = expresion.IndexOf("&re="); i += 4; j = expresion.IndexOf("&rr="); c = expresion.Substring(i, j - i); z = c.Replace("&", "&"); expresion = expresion.Replace(c, z); ConsultaCFDIServiceClient CFDI = new ConsultaCFDIServiceClient(); SAT.CFDI.Cliente.Procesamiento.ServicioConsultaCFDI.Acuse x = CFDI.Consulta(expresion); if (x.Estado != "No Encontrado") { if (x.Estado == "Vigente") { if (x.EsCancelable != "No Cancelable") { result = "OK"; } else { result = x.EsCancelable; } } else if (x.Estado == "Cancelado") { result = "OK"; } else { result = x.Estado; } } else { result = x.Estado; } } catch (Exception exception) { AccesoServicios.Log.Error("(ConsultaCFDI) Error al consultar los CFDI's expresion:" + expresion + "---" + exception.ToString()); result = null; } return(result); }