/// <summary> /// Obtiene la cotizacion de la divisa solicitada. En valores de divisa no de billete /// </summary> /// <param name="strIdMoneda"></param> /// <param name="strToken"></param> /// <param name="strFirma"></param> /// <returns>El valor de la moneda en texto</returns> public static string CotizacionDivisa(string strIdMoneda, string strToken, string strFirma) { //Dimensiono la variable para obtener la respuesta de la cotizacion. servicios1.afip.gov.ar.FECotizacionResponse objFEParamCotizacionResponse; //web service de Facturacion Electronica servicios1.afip.gov.ar.Service objWSFE = new servicios1.afip.gov.ar.Service(); //Facturacion Electronica Requerimiento de Autorizacion servicios1.afip.gov.ar.FEAuthRequest objFEAuthRequest = new servicios1.afip.gov.ar.FEAuthRequest(); //Este es el CUIT guardado en el registro del sistema. objFEAuthRequest.Cuit = Convert.ToInt64("30708466200"); //TODO:Luego ponerlo en las opciones del sistema objFEAuthRequest.Token = strToken; objFEAuthRequest.Sign = strFirma; // Invoco al método FEParamGetCotizacion try { objFEParamCotizacionResponse = objWSFE.FEParamGetCotizacion(objFEAuthRequest, strIdMoneda); return(objFEParamCotizacionResponse.ResultGet.MonCotiz.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); //Si no encuentra la cotizacion devuelve vacio return("1"); } }
/// <summary> /// Busca el Ultimo comprobante /// </summary> /// <param name="strToken">Paso el Token</param> /// <param name="strFirma"> Paso la Firma</param> /// <param name="intPtoVenta">Paso el punto de venta</param> /// <param name="intTipoCbe">Paso el tipo de comprobante</param> /// <returns></returns> public static int UltimoComprobante(string strToken, string strFirma, int intPtoVenta, int intTipoCbe) { //Esto recupera el ultimo comprobante realizado //Crea el objeto para Recuperar el ultimo combrobante servicios1.afip.gov.ar.FERecuperaLastCbteResponse objFERecuperarLastCbte = null; //web service de Facturacion Electronica servicios1.afip.gov.ar.Service objWSFE = new servicios1.afip.gov.ar.Service(); //Facturacion Electronica Requerimiento de Autorizacion servicios1.afip.gov.ar.FEAuthRequest objFEAuthRequest = new servicios1.afip.gov.ar.FEAuthRequest(); //Este es el CUIT guardado en el registro del sistema. objFEAuthRequest.Cuit = Convert.ToInt64("30708466200"); objFEAuthRequest.Token = strToken; objFEAuthRequest.Sign = strFirma; // Invoco al método FECompUltimoAutorizado try { objFERecuperarLastCbte = objWSFE.FECompUltimoAutorizado(objFEAuthRequest, intPtoVenta, intTipoCbe); return(Convert.ToInt32(objFERecuperarLastCbte.CbteNro.ToString()) + 1); } catch (Exception ex) { MessageBox.Show(ex.Message); //Devuelve 0 return(0); } }
/// <summary> /// /// </summary> /// <param name="strToken"></param> /// <param name="strFirma"></param> /// <param name="lngNumCbte"></param> /// <returns></returns> public static servicios1.afip.gov.ar.FECompConsultaResponse ComprobantesAutorizados(string strToken, string strFirma, long lngNumCbte) { //Esto recupera el ultimo comprobante realizado //Crea el objeto para Recuperar el ultimo combrobante servicios1.afip.gov.ar.FECompConsultaReq objFERecuperarCbtesReq = new servicios1.afip.gov.ar.FECompConsultaReq(); servicios1.afip.gov.ar.FECompConsultaResponse objFERecuperarCbtesResp = new servicios1.afip.gov.ar.FECompConsultaResponse(); //web service de Facturacion Electronica servicios1.afip.gov.ar.Service objWSFE = new servicios1.afip.gov.ar.Service(); //Facturacion Electronica Requerimiento de Autorizacion servicios1.afip.gov.ar.FEAuthRequest objFEAuthRequest = new servicios1.afip.gov.ar.FEAuthRequest(); //Este es el CUIT guardado en el registro del sistema. objFEAuthRequest.Cuit = Convert.ToInt64("30708466200"); objFEAuthRequest.Token = strToken; objFEAuthRequest.Sign = strFirma; objFERecuperarCbtesReq.PtoVta = 3; objFERecuperarCbtesReq.CbteTipo = 1; objFERecuperarCbtesReq.CbteNro = lngNumCbte; // Invoco al método FECompConsultaResponse try { objFERecuperarCbtesResp = objWSFE.FECompConsultar(objFEAuthRequest, objFERecuperarCbtesReq); return(objFERecuperarCbtesResp); } catch (Exception ex) { MessageBox.Show(ex.Message); //Devuelve 0 return(null); } }
/// <summary> /// Envia una Factura a la AFIP /// </summary> /// <param name="Factura"></param> /// <param name="strToken"></param> /// <param name="strSign"></param> /// <returns></returns> public static servicios1.afip.gov.ar.FECAEResponse EnviarFacturaAFIP(VariablesPropias.VariablesPropias.vpFactura Factura, string strToken, string strSign) { //web service de Facturacion Electronica servicios1.afip.gov.ar.Service objWSFE = new servicios1.afip.gov.ar.Service(); //Crea el objeto de respuesta de la factura servicios1.afip.gov.ar.FECAEResponse objFECAEResponse = new servicios1.afip.gov.ar.FECAEResponse(); servicios1.afip.gov.ar.FECAEDetResponse objFECAEDetResponse = new servicios1.afip.gov.ar.FECAEDetResponse(); //Crea el objeto para Armar la factura //Request General servicios1.afip.gov.ar.FECAERequest objFECAERequest = new servicios1.afip.gov.ar.FECAERequest(); //Request de la Cabecera servicios1.afip.gov.ar.FECAECabRequest objFECAECabRequest = new servicios1.afip.gov.ar.FECAECabRequest(); //Request del Detalle int indice = 0; //Cantidad de documentos a enviar int indIVA = 0; servicios1.afip.gov.ar.FECAEDetRequest[] objFECAEDetRequestArray = new servicios1.afip.gov.ar.FECAEDetRequest[indice + 1]; servicios1.afip.gov.ar.FECAEDetRequest objFECAEDetRequest = new servicios1.afip.gov.ar.FECAEDetRequest(); servicios1.afip.gov.ar.AlicIva[] objFECAEDetIVAArray = new servicios1.afip.gov.ar.AlicIva[indIVA + 1]; servicios1.afip.gov.ar.AlicIva objFECAEDetIVA = new servicios1.afip.gov.ar.AlicIva(); //Armar la Cabecera de la factura int cantregistros = 1; var _with1 = objFECAECabRequest; _with1.CantReg = cantregistros; _with1.PtoVta = Convert.ToInt32(Factura.intSucursal); _with1.CbteTipo = Convert.ToInt32(Factura.strCodFc); var _with2 = objFECAEDetIVA; /* * El Id tiene varios tipos * 0% = 3 * 10,5% = ?? * 21% = 5 * */ _with2.Id = Factura.IdIVA; _with2.BaseImp = Convert.ToDouble(Factura.curSubTotal); _with2.Importe = Convert.ToDouble(Factura.curIVA); objFECAEDetIVAArray[0] = objFECAEDetIVA; //Armar el detalle de la factura var _with3 = objFECAEDetRequest; //este es el Request para la unica factura //Ingreso los datos del cliente _with3.Concepto = 1; // Esto es productos _with3.DocTipo = 80; // Esto es Cuit _with3.DocNro = Convert.ToInt64(Factura.Cliente.dblCUIT); // El CUIT del cliente //.CbteDesde = CLng(cmbSucursal.Text & "-" & txtNumFact.Text) _with3.CbteDesde = Convert.ToInt64(Factura.dblNumFact); //.CbteHasta = CLng(cmbSucursal.Text & "-" & txtNumFact.Text) _with3.CbteHasta = Convert.ToInt64(Factura.dblNumFact); //.ImpTotal = CDbl(lblTotalUSD.Text) _with3.ImpTotal = Convert.ToDouble(Factura.curTotal); _with3.ImpTotConc = 0; //No se que es //.ImpNeto = CDbl(lblSubtotalUSD.Text) _with3.ImpNeto = Convert.ToDouble(Factura.curSubTotal); _with3.ImpOpEx = 0; //.ImpIVA = CDbl(lblIvaUSD.Text) _with3.ImpIVA = Convert.ToDouble(Factura.curIVA); _with3.ImpTrib = _with3.ImpTotConc + _with3.ImpOpEx; //+ .ImpIVA //.MonId = "DOL" //.MonCotiz = CDbl(FormatNumber(lblDolar.Text, 6)) _with3.MonId = "PES"; _with3.MonCotiz = Convert.ToDouble("1"); //Utiliza la funcion de FechaInversa para darle el formato correcto _with3.CbteFch = FechaInversa(DateTime.Today); _with3.Iva = objFECAEDetIVAArray; //.Iva = CDbl(lblIvaUSD.Text) objFECAEDetRequestArray[0] = objFECAEDetRequest; // Carga el Request en un array (de un solo item) //Arma el Request para todas las facturas que se manden var _with4 = objFECAERequest; //Cabecera _with4.FeCabReq = objFECAECabRequest; //Cuerpo _with4.FeDetReq = objFECAEDetRequestArray; //Facturacion Electronica Requerimiento de Autorizacion servicios1.afip.gov.ar.FEAuthRequest objFEAuthRequest = new servicios1.afip.gov.ar.FEAuthRequest(); objFEAuthRequest.Cuit = Convert.ToInt64("30708466200"); //TODO Cambiar //este es el CUIT guardado en la compu objFEAuthRequest.Token = strToken; objFEAuthRequest.Sign = strSign; // Invoco al método FECAESolicitar try { objFECAEResponse = objWSFE.FECAESolicitar(objFEAuthRequest, objFECAERequest); MessageBox.Show("***CONTENIDO DE RESPUESTA:" + System.Environment.NewLine + " CUIT:" + Convert.ToString(objFECAEResponse.FeCabResp.Cuit) + System.Environment.NewLine + " Pto Vta:" + Convert.ToString(objFECAEResponse.FeCabResp.PtoVta) + System.Environment.NewLine + " Fch Proceso:" + objFECAEResponse.FeCabResp.FchProceso + System.Environment.NewLine + " Cant reg:" + Convert.ToString(objFECAEResponse.FeCabResp.CantReg) + System.Environment.NewLine + " Resultado:" + objFECAEResponse.FeCabResp.Resultado + System.Environment.NewLine + " Reproceso:" + objFECAEResponse.FeCabResp.Reproceso + System.Environment.NewLine); } catch (Exception ex) { MessageBox.Show(ex.Message); return(objFECAEResponse); } // Obtengo los XML de request/response y los escribo en el disco XmlSerializer writer1 = new XmlSerializer(typeof(servicios1.afip.gov.ar.FECAERequest)); StreamWriter file1 = new StreamWriter("C:\\" + Factura.intSucursal + "-" + Factura.dblNumFact + " - " + Factura.Cliente.strNombre + " - wsfe_FERequest.xml"); writer1.Serialize(file1, objFECAERequest); file1.Close(); XmlSerializer writer2 = new XmlSerializer(typeof(servicios1.afip.gov.ar.FECAEResponse)); StreamWriter file2 = new StreamWriter("C:\\" + Factura.intSucursal + "-" + Factura.dblNumFact + " - " + Factura.Cliente.strNombre + " - wsfe_FEResponse.xml"); writer2.Serialize(file2, objFECAEResponse); file2.Close(); return(objFECAEResponse); }