Example #1
0
        public wsfex.FEXResponseAuthorize FEXAuthRequest(RequestBatch docBatch, Settings oSettings )
        {
            wsfex.ClsFEXRequest objFEXRequest = new wsfex.ClsFEXRequest();
            wsfex.FEXResponseAuthorize objFEXResponseAuthorize = new wsfex.FEXResponseAuthorize();
            wsfex.FEXResponse_LastID objFEXResponseLastID = null;

            DBEngine.SQLEngine sqlEngine = new FacturaElectronica.DBEngine.SQLEngine();

            int i = 0;

            try
            {
                //Debug Line
                Utils.Utils.DebugLine(Utils.Utils.SerializeObject(objFEXAuthRequest), oSettings.PathDebug + "\\ClsFEXAuthRequest-" + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + DateTime.Now.Millisecond.ToString("000") + ".xml");

                //Si no tiene identificador único hay que generarlo
                if (docBatch.BatchUniqueId == "AUTO")
                {
                    objFEXResponseLastID = GetLastBatchUniqueId();
                    if (objFEXResponseLastID.FEXResultGet == null)
                    {
                        sqlEngine.LogError(docBatch.RequestHeaders[0].SQLID, "0", "Autorización", "Error AFIP al obtener el último nro de requerimiento (" + objFEXResponseLastID.FEXErr.ErrCode + ") " + objFEXResponseLastID.FEXErr.ErrMsg);
                    }
                    else
                    {
                        objFEXResponseLastID.FEXResultGet.Id = objFEXResponseLastID.FEXResultGet.Id + 1;
                        docBatch.BatchUniqueId = (objFEXResponseLastID.FEXResultGet.Id).ToString();

                        //Guardar Unique Batch ID que luego se utilizara para reprocesos y obtener CAE
                        sqlEngine.UpdateCabeceraBatchUniqueId(docBatch.RequestHeaders[0].SQLID, docBatch.BatchUniqueId);
                    }
                }

                //Debug Line
                Utils.Utils.DebugLine(Utils.Utils.SerializeObject(docBatch), oSettings.PathDebug + "\\DocumentBatch-" + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + DateTime.Now.Millisecond.ToString("000") + ".xml");

                string fieldName = "";
                string seccionName = "";

                try
                {
                    seccionName = "Cabecera";
                    objFEXRequest.Id = (long)Convert.ToDouble(docBatch.BatchUniqueId);
                    objFEXRequest.Tipo_cbte = Convert.ToInt16(docBatch.RequestHeaders[0].TipoComprobante);
                    objFEXRequest.Punto_vta = Convert.ToInt16(docBatch.RequestHeaders[0].PuntoVenta);
                    objFEXRequest.Cbte_nro = (long)Convert.ToDouble(docBatch.RequestHeaders[0].NroComprobanteDesde);
                    objFEXRequest.Tipo_expo = Convert.ToInt16((docBatch.RequestHeaders[0].TipoExportacion == string.Empty) ? "1" : docBatch.RequestHeaders[0].TipoExportacion);

                    if (objFEXRequest.Tipo_cbte == 19)
                        objFEXRequest.Permiso_existente = (docBatch.RequestHeaders[0].PermisoExistente == string.Empty) ? "N" : docBatch.RequestHeaders[0].PermisoExistente;
                    else
                        objFEXRequest.Permiso_existente = string.Empty;

                    objFEXRequest.Dst_cmp = Convert.ToInt16(docBatch.RequestHeaders[0].CompradorPais);
                    objFEXRequest.Cliente = docBatch.RequestHeaders[0].CompradorRazonSocial;
                    objFEXRequest.Domicilio_cliente = docBatch.RequestHeaders[0].CompradorDireccion;
                    objFEXRequest.Moneda_Id = docBatch.RequestHeaders[0].CodigoMoneda;
                    objFEXRequest.Moneda_ctz = Convert.ToDouble(docBatch.RequestHeaders[0].TasaCambio);
                    objFEXRequest.Imp_total = Convert.ToDouble(docBatch.RequestHeaders[0].ImporteMonedaFacturacion);
                    objFEXRequest.Idioma_cbte = Convert.ToInt16((docBatch.RequestHeaders[0].Idioma == string.Empty) ? "01" : docBatch.RequestHeaders[0].Idioma);
                    objFEXRequest.Id_impositivo = docBatch.RequestHeaders[0].CompradorNroDocumento;
                    objFEXRequest.Fecha_cbte = Convert.ToDateTime(docBatch.RequestHeaders[0].FechaComprobante).ToString("yyyyMMdd");
                    objFEXRequest.Forma_pago = docBatch.RequestHeaders[0].FormaPagoDescripcion;
                    objFEXRequest.Obs = docBatch.RequestHeaders[0].Observaciones2;
                    objFEXRequest.Obs_comerciales = docBatch.RequestHeaders[0].Observaciones1;
                    objFEXRequest.Incoterms = docBatch.RequestHeaders[0].IncoTerms;

                    objFEXRequest.Items = new FacturaElectronica.WebServices.wsfex.Item[Convert.ToInt32(docBatch.RequestHeaders[0].CantidadRegistrosDetalle)];

                    for (i = 0; i < objFEXRequest.Items.Length; i++)
                    {
                        seccionName = "Línea " + i.ToString();
                        objFEXRequest.Items[i] = new wsfex.Item();
                        objFEXRequest.Items[i].Pro_codigo = docBatch.RequestHeaders[0].RequestLines[i].CodigoProductoEmpresa;
                        objFEXRequest.Items[i].Pro_ds = docBatch.RequestHeaders[0].RequestLines[i].Descripcion;
                        objFEXRequest.Items[i].Pro_umed = Convert.ToInt32(docBatch.RequestHeaders[0].RequestLines[i].UnidadMedida);
                        objFEXRequest.Items[i].Pro_qty = Convert.ToDouble(docBatch.RequestHeaders[0].RequestLines[i].Cantidad);
                        objFEXRequest.Items[i].Pro_precio_uni = Convert.ToDouble(docBatch.RequestHeaders[0].RequestLines[i].ImportePrecioUnitarioMonedaFacturacion);
                        objFEXRequest.Items[i].Pro_total_item = Convert.ToDouble(docBatch.RequestHeaders[0].RequestLines[i].ImporteSubtotalMonedaFacturacion);
                    }
                }
                catch (Exception ex)
                {
                    sqlEngine.LogError("0", "0", "Autorización", "Error al asignar el campo: " + seccionName + "." + fieldName + ", " + ex.Message);
                }

                //Debug Line
                Utils.Utils.DebugLine(Utils.Utils.SerializeObject(objFEXRequest), oSettings.PathDebug + "\\ClsFEXRequest-" + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + DateTime.Now.Millisecond.ToString("000") + ".xml");

                objFEXResponseAuthorize = fexService.FEXAuthorize(objFEXAuthRequest, objFEXRequest);
            }
            catch (Exception ex)
            {
                int iElement = 0;
                if (i > 0)
                    iElement = i - 1;
                else
                    iElement = 0;

                sqlEngine.LogError(docBatch.RequestHeaders[iElement].SQLID, "0", "Autorización", "Error no conocido: (AfipFEX) " + ex.Message);

                objFEXResponseAuthorize.FEXErr = new FacturaElectronica.WebServices.wsfex.ClsFEXErr();

                if (docBatch.BatchUniqueId == "AUTO" || objFEXResponseLastID.FEXResultGet == null)
                {
                    objFEXResponseAuthorize.FEXErr.ErrCode = 667;
                    objFEXResponseAuthorize.FEXErr.ErrMsg = ex.Message + "Error en AFIP al obtener el último nro de requerimiento (" + objFEXResponseLastID.FEXErr.ErrCode.ToString() + ") " + objFEXResponseLastID.FEXErr.ErrMsg;
                }
                else
                {
                    objFEXResponseAuthorize.FEXErr.ErrCode = 668;
                    objFEXResponseAuthorize.FEXErr.ErrMsg = ex.Message;
                    sqlEngine.LogError(docBatch.RequestHeaders[iElement].SQLID, "0", "Autorización", "Error no conocido: (AfipFEX) " + ex.Message);
                }
            }

            return objFEXResponseAuthorize;
        }
Example #2
0
 /// <remarks/>
 public void FEXAuthorizeAsync(ClsFEXAuthRequest Auth, ClsFEXRequest Cmp) {
     this.FEXAuthorizeAsync(Auth, Cmp, null);
 }
Example #3
0
 /// <remarks/>
 public void FEXAuthorizeAsync(ClsFEXAuthRequest Auth, ClsFEXRequest Cmp, object userState) {
     if ((this.FEXAuthorizeOperationCompleted == null)) {
         this.FEXAuthorizeOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFEXAuthorizeOperationCompleted);
     }
     this.InvokeAsync("FEXAuthorize", new object[] {
                 Auth,
                 Cmp}, this.FEXAuthorizeOperationCompleted, userState);
 }
Example #4
0
 public FEXResponseAuthorize FEXAuthorize(ClsFEXAuthRequest Auth, ClsFEXRequest Cmp) {
     object[] results = this.Invoke("FEXAuthorize", new object[] {
                 Auth,
                 Cmp});
     return ((FEXResponseAuthorize)(results[0]));
 }