Ejemplo n.º 1
0
        public AfipBFE(ref wsbfe.Service afipBfexService, ref wsbfe.ClsBFEAuthRequest afipObjBFEAuthRequest, Settings oSettings)
        {
            bfeService = afipBfexService;
            bfeService.Url = oSettings.UrlAFIPwsbfe;
            bfeService.Timeout = 10000;

            objBFEAuthRequest = afipObjBFEAuthRequest;
            objLastCMP.Token = afipObjBFEAuthRequest.Token;
            objLastCMP.Cuit = afipObjBFEAuthRequest.Cuit;
            objLastCMP.Sign = afipObjBFEAuthRequest.Sign;
        }
Ejemplo n.º 2
0
 /// <remarks/>
 public void BFEGetLast_IDAsync(ClsBFEAuthRequest Auth, object userState) {
     if ((this.BFEGetLast_IDOperationCompleted == null)) {
         this.BFEGetLast_IDOperationCompleted = new System.Threading.SendOrPostCallback(this.OnBFEGetLast_IDOperationCompleted);
     }
     this.InvokeAsync("BFEGetLast_ID", new object[] {
                 Auth}, this.BFEGetLast_IDOperationCompleted, userState);
 }
Ejemplo n.º 3
0
 /// <remarks/>
 public void BFEGetLast_IDAsync(ClsBFEAuthRequest Auth) {
     this.BFEGetLast_IDAsync(Auth, null);
 }
Ejemplo n.º 4
0
 public BFEResponse_LastID BFEGetLast_ID(ClsBFEAuthRequest Auth) {
     object[] results = this.Invoke("BFEGetLast_ID", new object[] {
                 Auth});
     return ((BFEResponse_LastID)(results[0]));
 }
Ejemplo n.º 5
0
 /// <remarks/>
 public void BFEGetPARAM_MONAsync(ClsBFEAuthRequest auth) {
     this.BFEGetPARAM_MONAsync(auth, null);
 }
Ejemplo n.º 6
0
 public BFEResponse_Mon BFEGetPARAM_MON(ClsBFEAuthRequest auth) {
     object[] results = this.Invoke("BFEGetPARAM_MON", new object[] {
                 auth});
     return ((BFEResponse_Mon)(results[0]));
 }
Ejemplo n.º 7
0
 /// <remarks/>
 public void BFEGetPARAM_NCMAsync(ClsBFEAuthRequest Auth) {
     this.BFEGetPARAM_NCMAsync(Auth, null);
 }
Ejemplo n.º 8
0
 /// <remarks/>
 public void BFEAuthorizeAsync(ClsBFEAuthRequest Auth, ClsBFERequest Cmp) {
     this.BFEAuthorizeAsync(Auth, Cmp, null);
 }
Ejemplo n.º 9
0
 public BFEResponse_Umed BFEGetPARAM_UMed(ClsBFEAuthRequest auth) {
     object[] results = this.Invoke("BFEGetPARAM_UMed", new object[] {
                 auth});
     return ((BFEResponse_Umed)(results[0]));
 }
Ejemplo n.º 10
0
 /// <remarks/>
 public void BFEGetPARAM_Tipo_CbteAsync(ClsBFEAuthRequest auth, object userState) {
     if ((this.BFEGetPARAM_Tipo_CbteOperationCompleted == null)) {
         this.BFEGetPARAM_Tipo_CbteOperationCompleted = new System.Threading.SendOrPostCallback(this.OnBFEGetPARAM_Tipo_CbteOperationCompleted);
     }
     this.InvokeAsync("BFEGetPARAM_Tipo_Cbte", new object[] {
                 auth}, this.BFEGetPARAM_Tipo_CbteOperationCompleted, userState);
 }
Ejemplo n.º 11
0
 /// <remarks/>
 public void BFEGetPARAM_Tipo_CbteAsync(ClsBFEAuthRequest auth) {
     this.BFEGetPARAM_Tipo_CbteAsync(auth, null);
 }
Ejemplo n.º 12
0
 public BFEResponse_Tipo_Cbte BFEGetPARAM_Tipo_Cbte(ClsBFEAuthRequest auth) {
     object[] results = this.Invoke("BFEGetPARAM_Tipo_Cbte", new object[] {
                 auth});
     return ((BFEResponse_Tipo_Cbte)(results[0]));
 }
Ejemplo n.º 13
0
 /// <remarks/>
 public void BFEGetCMPAsync(ClsBFEAuthRequest Auth, ClsBFEGetCMP Cmp) {
     this.BFEGetCMPAsync(Auth, Cmp, null);
 }
Ejemplo n.º 14
0
 public BFEGetCMPResponse BFEGetCMP(ClsBFEAuthRequest Auth, ClsBFEGetCMP Cmp) {
     object[] results = this.Invoke("BFEGetCMP", new object[] {
                 Auth,
                 Cmp});
     return ((BFEGetCMPResponse)(results[0]));
 }
Ejemplo n.º 15
0
        public string ProcesarLoteFacturasBienesCapital(string EmpresaID, string xmlDocument)
        {
            #region Inicialización

            Settings oSettings = new Settings(EmpresaID);

            wsbfe.Service afipBfexService = new wsbfe.Service();
            afipBfexService.Url = oSettings.UrlAFIPwsbfe;

            wsbfe.ClsBFEAuthRequest afipObjBFEAuthRequest = new wsbfe.ClsBFEAuthRequest();
            wsbfe.BFEResponseAuthorize bfeResponseAuthorize = new wsbfe.BFEResponseAuthorize();

            ResponseBatch batchResponse = new ResponseBatch();
            RequestBatch loteDocs = new RequestBatch();

            string SQLID = "0";
            string estadoDocumento = "";
            string cae = "";
            string FechaVencimiento = "";
            string strEquivalenciaErrorFields = string.Empty;

            bool bRegistrarInicio = false;
            bool bEquivalenciaError = false;

            //Cargar el lote recibido
            loteDocs.LoadXMLString(xmlDocument);

            #endregion

            #region Registrar pedido

            try
            {
                bRegistrarInicio = sqlEngine.LogBatchStart(ref loteDocs);

                SQLID = loteDocs.RequestHeaders[0].SQLID;

                //DEBUG LINE
                if (Convert.ToBoolean(oSettings.ActivarDebug))
                    Utils.Utils.DebugLine(Utils.Utils.SerializeObject(batchResponse), oSettings.PathDebug + "\\" + SQLID + "-FERequestBatch-" + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + DateTime.Now.Millisecond.ToString("000") + ".xml");
            }
            catch (Exception ex)
            {
                bRegistrarInicio = false;
                sqlEngine.LogError(SQLID, "0", "Procesando lote", "Error: " + ex.Message);
            }

            #endregion

            if (bRegistrarInicio)
            {
                #region Verificar Login con AFIP

                AfipConnection afipConn = new AfipConnection("wsbfe", oSettings);
                if (afipConn.ConnectionErrorDescription == string.Empty)
                {
                    //Inicializo el objeto AuthRequest de la Afip
                    afipObjBFEAuthRequest.Cuit = afipConn.Cuit;
                    afipObjBFEAuthRequest.Sign = afipConn.Sign;
                    afipObjBFEAuthRequest.Token = afipConn.Token;
                }
                else
                {
                    try
                    {
                        sqlEngine.LogError(SQLID, "0", "AfipConnection", afipConn.ConnectionErrorDescription);

                        sqlEngine.LogBatchEnd(SQLID, "Error", cae, FechaVencimiento);
                    }
                    catch (Exception ex)
                    {
                        sqlEngine.LogError(SQLID, "0", "FEService-AFIP Login", "Error: " + ex.Message);
                    }
                }

                AfipBFE afipBFE = new AfipBFE(ref afipBfexService, ref afipObjBFEAuthRequest, oSettings);

                #endregion

                if (afipConn.ConnectionErrorDescription == string.Empty)
                {
                    #region Buscar Equivalencias

                    bEquivalenciaError = BuscarEquivalencias(ref loteDocs, oSettings, ref strEquivalenciaErrorFields);

                    #endregion

                    if (!bEquivalenciaError)
                    {
                        #region Realizar Validaciones
                        #endregion

                        #region Hacer el pedido a AFIP

                        try
                        {
                            if (afipConn.IsConnected)
                            {
                                bfeResponseAuthorize = afipBFE.BFEAuthorize(loteDocs, oSettings);

                                if (bfeResponseAuthorize.BFEErr == null)
                                {
                                    sqlEngine.LogError(SQLID, "0", "Respuesta AFIP", "AFIP no pudo procesar por un error previo. Vea el log de errores.");
                                    bfeResponseAuthorize.BFEErr = new wsbfe.ClsBFEErr();
                                    bfeResponseAuthorize.BFEErr.ErrCode = 0;
                                    bfeResponseAuthorize.BFEErr.ErrMsg = "AFIP no pudo procesar por un error previo. Vea el log de errores.";
                                }
                            }
                            else
                            {
                                sqlEngine.LogError(SQLID, "0", "Respuesta AFIP", "Sin Conexion. Descripcion: " + afipConn.ConnectionErrorDescription);
                                bfeResponseAuthorize.BFEErr = new wsbfe.ClsBFEErr();
                                bfeResponseAuthorize.BFEErr.ErrCode = 0;
                                bfeResponseAuthorize.BFEErr.ErrMsg = afipConn.ConnectionErrorDescription;
                            }
                        }
                        catch (Exception ex)
                        {
                            sqlEngine.LogError(SQLID, "0", "Respuesta AFIP", "Error: " + ex.Message);
                        }

                        #endregion
                    }
                }

                #region Armar y devolver respuesta

                //Armar info del lote
                if (bfeResponseAuthorize.BFEResultAuth != null && bfeResponseAuthorize.BFEResultAuth.Cae != null )
                {
                    batchResponse.BatchUniqueId = loteDocs.BatchUniqueId;
                    batchResponse.BatchUniqueId = bfeResponseAuthorize.BFEResultAuth.Id.ToString();
                    batchResponse.Resultado = bfeResponseAuthorize.BFEResultAuth.Resultado;
                    batchResponse.Reproceso = bfeResponseAuthorize.BFEResultAuth.Reproceso;
                    batchResponse.CUITInformante = bfeResponseAuthorize.BFEResultAuth.Cuit.ToString();
                    batchResponse.CantidadComprobantes = "1";

                    //Armar info del documento
                    ResponseHeader thisHeader = new ResponseHeader();

                    thisHeader.CAE = bfeResponseAuthorize.BFEResultAuth.Cae;
                    thisHeader.NroComprobanteDesde = loteDocs.RequestHeaders[0].NroComprobanteDesde.ToString();
                    thisHeader.NroComprobanteHasta = loteDocs.RequestHeaders[0].NroComprobanteHasta.ToString();
                    thisHeader.FechaComprobante = bfeResponseAuthorize.BFEResultAuth.Fch_cbte;
                    thisHeader.FechaVencimiento = bfeResponseAuthorize.BFEResultAuth.Fch_venc_Cae;

                    thisHeader.PuntoVenta = loteDocs.RequestHeaders[0].PuntoVenta.ToString();
                    thisHeader.TipoComprobante = loteDocs.RequestHeaders[0].TipoComprobante.ToString();
                    thisHeader.NroInternoERP = loteDocs.RequestHeaders[0].NroInternoERP;
                    thisHeader.LetraComprobante = loteDocs.RequestHeaders[0].LetraComprobante;
                    thisHeader.SQLID = loteDocs.RequestHeaders[0].SQLID;
                    thisHeader.UltimoIDUsado = "";

                    //Obtengo el último último comprobante
                    wsbfe.BFEResponseLast_CMP bfeLastCMPRespose = afipBFE.BFERecuperaLastCMPRequest(thisHeader.TipoComprobante, thisHeader.PuntoVenta);
                    thisHeader.UltimoNroComprobanteUsado = bfeLastCMPRespose.BFEResult_LastCMP.Cbte_nro.ToString();

                    batchResponse.ResponseHeaders.Add(thisHeader);

                    if (bfeResponseAuthorize.BFEResultAuth.Reproceso.ToLower() == "s")
                    {
                        thisHeader.Resultado = "R";
                        thisHeader.Motivo = "12";
                        thisHeader.MotivoDescripcion = AfipBFE.GetMotivoDescripcion(thisHeader.Motivo);
                    }
                    else
                    {
                        thisHeader.Motivo = bfeResponseAuthorize.BFEResultAuth.Obs;
                        thisHeader.MotivoDescripcion = AfipBFE.GetMotivoDescripcion(bfeResponseAuthorize.BFEResultAuth.Obs);
                    }
                }
                else
                {
                    batchResponse.BatchUniqueId = "0";
                    batchResponse.Resultado = "R";
                    batchResponse.Reproceso = "";
                    batchResponse.CUITInformante = "";
                    batchResponse.CantidadComprobantes = "1";

                    if (bfeResponseAuthorize.BFEErr != null)
                    {
                        batchResponse.CodigoError = bfeResponseAuthorize.BFEErr.ErrCode.ToString();
                        batchResponse.MensajeError = bfeResponseAuthorize.BFEErr.ErrMsg.ToString();
                    }
                    else if (afipConn.ConnectionErrorDescription != string.Empty)
                    {
                        batchResponse.CodigoError = "669";
                        batchResponse.MensajeError = afipConn.ConnectionErrorDescription;
                    }
                    else if (bEquivalenciaError)
                    {
                        batchResponse.Resultado = "E";
                        batchResponse.CodigoError = "Equivalencias";
                        batchResponse.MensajeError = "No se encontró equivalencia con AFIP. Campos: " + strEquivalenciaErrorFields;
                    }

                    //Devolver los documentos originales
                    ResponseHeader thisHeader = new ResponseHeader();
                    thisHeader.CAE = "";
                    thisHeader.NroComprobanteDesde = loteDocs.RequestHeaders[0].NroComprobanteDesde;
                    thisHeader.FechaComprobante = loteDocs.RequestHeaders[0].FechaComprobante;
                    thisHeader.FechaVencimiento = "";
                    thisHeader.Motivo = "";
                    thisHeader.MotivoDescripcion = "";
                    thisHeader.PuntoVenta = loteDocs.RequestHeaders[0].PuntoVenta;
                    thisHeader.TipoComprobante = loteDocs.RequestHeaders[0].TipoComprobante;
                    thisHeader.NroInternoERP = loteDocs.RequestHeaders[0].NroInternoERP;
                    thisHeader.LetraComprobante = loteDocs.RequestHeaders[0].LetraComprobante;
                    thisHeader.SQLID = loteDocs.RequestHeaders[0].SQLID;

                    //Obtengo el último último comprobante
                    if (afipConn.ConnectionErrorDescription == string.Empty)
                    {
                        wsbfe.BFEResponseLast_CMP bfeLastCMPRespose = afipBFE.BFERecuperaLastCMPRequest(thisHeader.TipoComprobante, thisHeader.PuntoVenta);
                        thisHeader.UltimoNroComprobanteUsado = bfeLastCMPRespose.BFEResult_LastCMP.Cbte_nro.ToString();
                    }

                    batchResponse.ResponseHeaders.Add(thisHeader);
                }

                #endregion

                #region Registrar respuesta recibida

                if (batchResponse.Resultado == "A" || batchResponse.Resultado == "R")
                {
                    switch (batchResponse.Resultado)
                    {
                        case "A":
                            estadoDocumento = "Aceptado";
                            cae = batchResponse.ResponseHeaders[0].CAE;
                            FechaVencimiento = batchResponse.ResponseHeaders[0].FechaVencimiento;

                            break;
                        case "R":
                            estadoDocumento = "Rechazado";
                            cae = "";
                            FechaVencimiento = "";
                            break;
                    }
                }
                else if (bfeResponseAuthorize.BFEResultAuth.Reproceso.ToLower() == "s")
                {
                    estadoDocumento = "Rechazado";
                    cae = batchResponse.ResponseHeaders[0].CAE;
                    FechaVencimiento = batchResponse.ResponseHeaders[0].FechaVencimiento;
                }
                else
                {
                    estadoDocumento = "Error";
                    cae = "";
                    FechaVencimiento = "";
                }

                try
                {
                    sqlEngine.LogBatchEnd(SQLID, estadoDocumento, cae, FechaVencimiento);
                }
                catch (Exception ex)
                {
                    sqlEngine.LogError(SQLID, "0", "Respuesta Recibida", "Error: " + ex.Message);
                }
                #endregion
            }
            return batchResponse.GetXMLString();
        }
Ejemplo n.º 16
0
 public BFEResponse_NCM BFEGetPARAM_NCM(ClsBFEAuthRequest Auth) {
     object[] results = this.Invoke("BFEGetPARAM_NCM", new object[] {
                 Auth});
     return ((BFEResponse_NCM)(results[0]));
 }
Ejemplo n.º 17
0
 public BFEResponseAuthorize BFEAuthorize(ClsBFEAuthRequest Auth, ClsBFERequest Cmp) {
     object[] results = this.Invoke("BFEAuthorize", new object[] {
                 Auth,
                 Cmp});
     return ((BFEResponseAuthorize)(results[0]));
 }