示例#1
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_CtzAsync(ClsFEXAuthRequest Auth, string Mon_id) {
     this.FEXGetPARAM_CtzAsync(Auth, Mon_id, null);
 }
示例#2
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXAuthorizeAsync(ClsFEXAuthRequest Auth, ClsFEXRequest Cmp) {
     this.FEXAuthorizeAsync(Auth, Cmp, null);
 }
示例#3
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_Ctz FEXGetPARAM_Ctz(ClsFEXAuthRequest Auth, string Mon_id) {
     object[] results = this.Invoke("FEXGetPARAM_Ctz", new object[] {
                 Auth,
                 Mon_id});
     return ((FEXResponse_Ctz)(results[0]));
 }
示例#4
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXCheck_PermisoAsync(ClsFEXAuthRequest Auth, string ID_Permiso, int Dst_merc) {
     this.FEXCheck_PermisoAsync(Auth, ID_Permiso, Dst_merc, null);
 }
示例#5
0
        public string ProcesarLoteFacturasExportacion(string EmpresaID, string xmlDocument)
        {
            #region Inicialización

            Settings oSettings = new Settings(EmpresaID);

            wsfex.Service afipFexService = new wsfex.Service();
            afipFexService.Url = oSettings.UrlAFIPwsfex;

            wsfex.ClsFEXAuthRequest afipObjFEXAuthRequest = new wsfex.ClsFEXAuthRequest();
            wsfex.FEXResponseAuthorize fexResponseAuthorize = new wsfex.FEXResponseAuthorize();

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

            string SQLID = "0";
            string estadoDocumento = string.Empty;
            string cae = string.Empty;
            string FechaVencimiento = string.Empty;
            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(loteDocs), 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

            //Si pudo crear el registro en la base continuo
            if (bRegistrarInicio)
            {
                #region Verificar Login con AFIP

                AfipConnection afipConn = new AfipConnection("wsfex", oSettings);
                if (afipConn.ConnectionErrorDescription == string.Empty)
                {
                    //Inicializo el objeto AuthRequest de la Afip
                    afipObjFEXAuthRequest.Cuit = afipConn.Cuit;
                    afipObjFEXAuthRequest.Sign = afipConn.Sign;
                    afipObjFEXAuthRequest.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);
                    }
                }

                AfipFEX afipFEX = new AfipFEX(ref afipFexService, ref afipObjFEXAuthRequest, oSettings);

                #endregion

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

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

                    #endregion

                    //Si no hay errore de equivalencia continuo
                    if (!bEquivalenciaError)
                    {
                        #region Realizar Validaciones
                        #endregion

                        #region Hacer el pedido a AFIP

                        try
                        {
                            if (afipConn.IsConnected)
                            {
                                fexResponseAuthorize = afipFEX.FEXAuthRequest(loteDocs, oSettings);
                                if (fexResponseAuthorize.FEXErr == null)
                                {
                                    sqlEngine.LogError(SQLID, "0", "Respuesta AFIP", "AFIP no pudo procesar por un error previo. Vea el log de errores.");
                                    fexResponseAuthorize.FEXErr = new wsfex.ClsFEXErr();
                                    fexResponseAuthorize.FEXErr.ErrCode = 0;
                                    fexResponseAuthorize.FEXErr.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);
                                fexResponseAuthorize.FEXErr = new wsfex.ClsFEXErr();
                                fexResponseAuthorize.FEXErr.ErrCode = 0;
                                fexResponseAuthorize.FEXErr.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 (fexResponseAuthorize.FEXResultAuth != null)
                {
                    batchResponse.BatchUniqueId = loteDocs.BatchUniqueId;
                    batchResponse.BatchUniqueId = fexResponseAuthorize.FEXResultAuth.Id.ToString();
                    batchResponse.CUITInformante = fexResponseAuthorize.FEXResultAuth.Cuit.ToString();
                    batchResponse.FechaCAE = fexResponseAuthorize.FEXResultAuth.Fch_venc_Cae;
                    batchResponse.CantidadComprobantes = "1";
                    batchResponse.Resultado = fexResponseAuthorize.FEXResultAuth.Resultado;
                    batchResponse.Reproceso = fexResponseAuthorize.FEXResultAuth.Reproceso;
                    batchResponse.SonServicios = "";
                    batchResponse.CodigoError = fexResponseAuthorize.FEXErr.ErrCode.ToString();
                    batchResponse.MensajeError = fexResponseAuthorize.FEXErr.ErrMsg.ToString();

                    if (fexResponseAuthorize.FEXResultAuth.Reproceso.ToLower() == "s")
                    {
                        batchResponse.Resultado = "R";
                        batchResponse.Motivo = "12";
                        batchResponse.MotivoDescripcion = "EL RANGO INFORMADO SE ENCUENTRA AUTORIZADO CON ANTERIOIRIDAD PARA LA MISMA CUIT, TIPO DE COMPROBANTE Y PUNTO DE VENTA.";
                    }
                    else
                    {
                        batchResponse.Motivo = fexResponseAuthorize.FEXResultAuth.Motivos_Obs;
                        batchResponse.MotivoDescripcion = "";
                    }

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

                    thisHeader.CAE = fexResponseAuthorize.FEXResultAuth.Cae;
                    thisHeader.NroComprobanteDesde = fexResponseAuthorize.FEXResultAuth.Cbte_nro.ToString();
                    thisHeader.NroComprobanteHasta = fexResponseAuthorize.FEXResultAuth.Cbte_nro.ToString();
                    thisHeader.FechaComprobante = fexResponseAuthorize.FEXResultAuth.Fch_cbte;
                    thisHeader.FechaVencimiento = fexResponseAuthorize.FEXResultAuth.Fch_venc_Cae;
                    thisHeader.PuntoVenta = fexResponseAuthorize.FEXResultAuth.Punto_vta.ToString();
                    thisHeader.TipoComprobante = fexResponseAuthorize.FEXResultAuth.Tipo_cbte.ToString();
                    thisHeader.NroInternoERP = loteDocs.RequestHeaders[0].NroInternoERP;
                    thisHeader.LetraComprobante = loteDocs.RequestHeaders[0].LetraComprobante;
                    thisHeader.SQLID = loteDocs.RequestHeaders[0].SQLID;
                    thisHeader.Resultado = fexResponseAuthorize.FEXResultAuth.Resultado;
                    thisHeader.Importe = loteDocs.RequestHeaders[0].Importe;

                    if (fexResponseAuthorize.FEXResultAuth.Reproceso.ToLower() == "s")
                    {
                        thisHeader.Resultado = "R";
                        thisHeader.Motivo = "12";
                        thisHeader.MotivoDescripcion = AfipFEX.GetMotivoDescripcion(thisHeader.Motivo, string.Empty);
                    }
                    else
                    {
                        thisHeader.Motivo = fexResponseAuthorize.FEXResultAuth.Motivos_Obs;
                        thisHeader.MotivoDescripcion = "";
                    }

                    batchResponse.ResponseHeaders.Add(thisHeader);
                }
                else
                {
                    batchResponse.BatchUniqueId = "0";
                    batchResponse.CUITInformante = "";
                    batchResponse.FechaCAE = "";
                    batchResponse.CantidadComprobantes = "1";
                    batchResponse.Resultado = "R";
                    batchResponse.Motivo = "";
                    batchResponse.MotivoDescripcion = "";
                    batchResponse.Reproceso = "";
                    batchResponse.SonServicios = "";

                    if (fexResponseAuthorize.FEXErr != null)
                    {
                        batchResponse.CodigoError = fexResponseAuthorize.FEXErr.ErrCode.ToString();
                        batchResponse.MensajeError = fexResponseAuthorize.FEXErr.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.NroComprobanteHasta = loteDocs.RequestHeaders[0].NroComprobanteHasta;
                    thisHeader.FechaComprobante = loteDocs.RequestHeaders[0].FechaComprobante;
                    thisHeader.FechaVencimiento = "";
                    thisHeader.Motivo = batchResponse.CodigoError;
                    thisHeader.MotivoDescripcion = batchResponse.MensajeError;
                    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.Resultado = "R";
                    thisHeader.SQLID = loteDocs.RequestHeaders[0].SQLID;

                    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 (batchResponse.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();
        }
示例#6
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_PtoVenta FEXGetPARAM_PtoVenta(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetPARAM_PtoVenta", new object[] {
                 Auth});
     return ((FEXResponse_PtoVenta)(results[0]));
 }
示例#7
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_PtoVentaAsync(ClsFEXAuthRequest Auth, object userState) {
     if ((this.FEXGetPARAM_PtoVentaOperationCompleted == null)) {
         this.FEXGetPARAM_PtoVentaOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFEXGetPARAM_PtoVentaOperationCompleted);
     }
     this.InvokeAsync("FEXGetPARAM_PtoVenta", new object[] {
                 Auth}, this.FEXGetPARAM_PtoVentaOperationCompleted, userState);
 }
示例#8
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_IncotermsAsync(ClsFEXAuthRequest Auth) {
     this.FEXGetPARAM_IncotermsAsync(Auth, null);
 }
示例#9
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_Idi FEXGetPARAM_Idiomas(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetPARAM_Idiomas", new object[] {
                 Auth});
     return ((FEXResponse_Idi)(results[0]));
 }
示例#10
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_Tex FEXGetPARAM_Tipo_Expo(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetPARAM_Tipo_Expo", new object[] {
                 Auth});
     return ((FEXResponse_Tex)(results[0]));
 }
示例#11
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_Tipo_ExpoAsync(ClsFEXAuthRequest Auth) {
     this.FEXGetPARAM_Tipo_ExpoAsync(Auth, null);
 }
示例#12
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetCMPAsync(ClsFEXAuthRequest Auth, ClsFEXGetCMP Cmp, object userState) {
     if ((this.FEXGetCMPOperationCompleted == null)) {
         this.FEXGetCMPOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFEXGetCMPOperationCompleted);
     }
     this.InvokeAsync("FEXGetCMP", new object[] {
                 Auth,
                 Cmp}, this.FEXGetCMPOperationCompleted, userState);
 }
示例#13
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetCMPAsync(ClsFEXAuthRequest Auth, ClsFEXGetCMP Cmp) {
     this.FEXGetCMPAsync(Auth, Cmp, null);
 }
示例#14
0
文件: Reference.cs 项目: javierlov/FE
 public FEXGetCMPResponse FEXGetCMP(ClsFEXAuthRequest Auth, ClsFEXGetCMP Cmp) {
     object[] results = this.Invoke("FEXGetCMP", new object[] {
                 Auth,
                 Cmp});
     return ((FEXGetCMPResponse)(results[0]));
 }
示例#15
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_LastID FEXGetLast_ID(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetLast_ID", new object[] {
                 Auth});
     return ((FEXResponse_LastID)(results[0]));
 }
示例#16
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_Umed FEXGetPARAM_UMed(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetPARAM_UMed", new object[] {
                 Auth});
     return ((FEXResponse_Umed)(results[0]));
 }
示例#17
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetLast_IDAsync(ClsFEXAuthRequest Auth) {
     this.FEXGetLast_IDAsync(Auth, null);
 }
示例#18
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_UMedAsync(ClsFEXAuthRequest Auth) {
     this.FEXGetPARAM_UMedAsync(Auth, null);
 }
示例#19
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_PtoVentaAsync(ClsFEXAuthRequest Auth) {
     this.FEXGetPARAM_PtoVentaAsync(Auth, null);
 }
示例#20
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_DST_cuit FEXGetPARAM_DST_CUIT(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetPARAM_DST_CUIT", new object[] {
                 Auth});
     return ((FEXResponse_DST_cuit)(results[0]));
 }
示例#21
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_CheckPermiso FEXCheck_Permiso(ClsFEXAuthRequest Auth, string ID_Permiso, int Dst_merc) {
     object[] results = this.Invoke("FEXCheck_Permiso", new object[] {
                 Auth,
                 ID_Permiso,
                 Dst_merc});
     return ((FEXResponse_CheckPermiso)(results[0]));
 }
示例#22
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXGetPARAM_DST_CUITAsync(ClsFEXAuthRequest Auth) {
     this.FEXGetPARAM_DST_CUITAsync(Auth, null);
 }
示例#23
0
文件: Reference.cs 项目: javierlov/FE
 /// <remarks/>
 public void FEXCheck_PermisoAsync(ClsFEXAuthRequest Auth, string ID_Permiso, int Dst_merc, object userState) {
     if ((this.FEXCheck_PermisoOperationCompleted == null)) {
         this.FEXCheck_PermisoOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFEXCheck_PermisoOperationCompleted);
     }
     this.InvokeAsync("FEXCheck_Permiso", new object[] {
                 Auth,
                 ID_Permiso,
                 Dst_merc}, this.FEXCheck_PermisoOperationCompleted, userState);
 }
示例#24
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponse_Mon FEXGetPARAM_MON(ClsFEXAuthRequest Auth) {
     object[] results = this.Invoke("FEXGetPARAM_MON", new object[] {
                 Auth});
     return ((FEXResponse_Mon)(results[0]));
 }
示例#25
0
文件: AfipFEX.cs 项目: javierlov/FE
 public AfipFEX(ref wsfex.Service afipFexService, ref wsfex.ClsFEXAuthRequest afipObjFEXAuthRequest, Settings oSettings)
 {
     fexService = afipFexService;
     fexService.Url = oSettings.UrlAFIPwsfex;
     objFEXAuthRequest = afipObjFEXAuthRequest;
 }
示例#26
0
文件: Reference.cs 项目: javierlov/FE
 public FEXResponseAuthorize FEXAuthorize(ClsFEXAuthRequest Auth, ClsFEXRequest Cmp) {
     object[] results = this.Invoke("FEXAuthorize", new object[] {
                 Auth,
                 Cmp});
     return ((FEXResponseAuthorize)(results[0]));
 }