public Response ApplyTransaction(RMApply applyTran, string company)
        {
            Response    response;
            string      server         = ConfigKey.ReadSetting("SERVER");
            string      transactionXML = string.Empty;
            string      CNX            = "data source=" + server + ";initial catalog=" + company + ";integrated security=SSPI;persist security info=False;packet size=4096";
            var         eConnect       = new eConnectRequest();
            RMApplyType rmapplytype    = new RMApplyType();

            try
            {
                rmapplytype.taRMApply = SetApplyValues(applyTran);
                transactionXML        = SerializeRMApply(rmapplytype);
                response = eConnect.CreateGPTransaction(CNX, transactionXML);

                return(response);
            }
            catch (Exception ex)
            {
                response         = new Response();
                response.SUCCESS = false;
                response.MESSAGE = ex.Message;
                response.STACK   = ex.StackTrace;
                return(response);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="rmapply"></param>
        /// <returns></returns>
        private string SerializeRMApply(RMApplyType rmapply)
        {
            try
            {
                eConnectType  eConnect = new eConnectType();
                RMApplyType[] TranType = { rmapply };
                eConnect.RMApplyType = TranType;

                MemoryStream ms = new MemoryStream();

                XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
                serializer.Serialize(ms, eConnect);
                ms.Position = 0;
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(ms);

                string TransactionXML = xmldoc.OuterXml;

                return(TransactionXML);
            }
            catch (Exception)
            {
                // logW.LogExeption("Econnect", 2, ex);
                throw;
            }
        }
        /// <summary>
        /// Integra nc de AR y aplica facturas
        /// </summary>
        /// <param name="worker"></param>
        /// <param name="e"></param>
        private void IntegraRMNotaCreditoYAplicaciones(BackgroundWorker worker, DoWorkEventArgs e)
        {
            string mensajeOk    = "";
            string mensajeError = "";

            Model.RMFactura docGP = null;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            string nroLote = DateTime.Now.ToString("yyyyMMdd.HHmmss");

            worker.ReportProgress(0, new string[] { "Credit memo batch " + nroLote, "Credit memo Batch " + nroLote });
            cantidad = 0;
            foreach (var dato in _cobros.LBoletosBrasil)
            {
                mensajeOk    = "";
                mensajeError = "";
                DateTime fechaCobro = dato.FechaTotalLiquidado.AddDays(parametrosCobrosXL.FechaTotalLiquidadoAddDays);
                using (eConnectMethods eConnectMethods = new eConnectMethods())
                {
                    eConnectMethods.RequireProxyService = true;
                    List <RMTransactionType> masterRMTransactionType = new List <RMTransactionType>();
                    List <RMApplyType>       masterRMApplyType       = new List <RMApplyType>();

                    try
                    {
                        bool    error       = false;
                        decimal valorBoleto = decimal.Round(dato.ValorBoleto, 2);
                        decimal valorPago   = decimal.Round(dato.ValorPago, 2);
                        decimal juros       = decimal.Round(dato.Juros, 2);

                        //RMCashReceiptsType RMCashReceiptsTypeEntry = new RMCashReceiptsType();
                        RMTransactionType RMTransactionTypeEntry = new RMTransactionType();

                        taRMTransaction rmTransactionItem = new taRMTransaction();
                        //el número de la planilla puede venir así: B-10201, B-10201., B-10201 01, B-10201. 01
                        //string numFactura = dato.NumeroFactura.Trim().Length > 7 ? Model.Utiles.Izquierda(dato.NumeroFactura, 8) : Model.Utiles.Izquierda( dato.NumeroFactura, 7);
                        docGP = this.getCustnmbrDocnumbr(dato.NumeroFactura.Trim(), dato.FechaVencimientoPago);

                        rmTransactionItem.CUSTNMBR = docGP.Custnmbr;                                       // custData["custnmbr"].ToString(); //_custnmbr;
                        rmTransactionItem.DOCNUMBR = "CC" + dato.NumeroCobro;
                        rmTransactionItem.DOCDATE  = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); //System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]);
                        rmTransactionItem.RMDTYPAL = 7;
                        rmTransactionItem.DOCAMNT  = juros;
                        rmTransactionItem.SLSAMNT  = juros;

                        rmTransactionItem.BACHNUMB = nroLote;
                        rmTransactionItem.DOCDESCR = dato.NumeroFacturaYCuota;
                        rmTransactionItem.CSTPONBR = dato.NombrePagador;

                        RMApplyType RMApplyTypeEntry = new RMApplyType();

                        taRMApply ApplyItem = new taRMApply();
                        ApplyItem.APTODCNM  = docGP.Docnmbr; // custData["docnumbr"].ToString();   // _docnmbr.Trim();
                        ApplyItem.APFRDCNM  = "CC" + dato.NumeroCobro;
                        ApplyItem.APPTOAMT  = juros - Convert.ToDecimal(docGP.Amount) > 0 ? Convert.ToDecimal(docGP.Amount) : juros;
                        ApplyItem.APFRDCTY  = 7;
                        ApplyItem.APTODCTY  = 1;
                        ApplyItem.APPLYDATE = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha);     // System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]);
                        ApplyItem.GLPOSTDT  = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha);     // System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]);

                        cantidad++;

                        if (!error)
                        {
                            eConnectType eConnDoc = new eConnectType();
                            RMTransactionTypeEntry.taRMTransaction = rmTransactionItem;
                            masterRMTransactionType.Add(RMTransactionTypeEntry);
                            eConnDoc.RMTransactionType = masterRMTransactionType.ToArray();

                            RMApplyTypeEntry.taRMApply = ApplyItem;
                            masterRMApplyType.Add(RMApplyTypeEntry);
                            eConnDoc.RMApplyType = masterRMApplyType.ToArray();

                            XmlDocument xmlDoc = Serializa(eConnDoc);
                            eConnectMethods.CreateEntity(parametrosCobrosXL.ConnStringTarget, xmlDoc.OuterXml);

                            mensajeOk = dato.NumeroFactura + " - " + dato.NumeroCobro + ": Credit Memo OK" + Environment.NewLine;
                        }
                        else
                        {
                            mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + ": Error" + Environment.NewLine;
                        }

                        System.Threading.Thread.Sleep(100);
                    }
                    catch (eConnectException ec)
                    {
                        mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + " eConn: " + ec.Message + Environment.NewLine + ec.StackTrace;
                    }
                    catch (Exception ex)
                    {
                        mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + ": " + ex.Message + Environment.NewLine + ex.StackTrace;
                    }
                    finally
                    {
                        eConnectMethods.Dispose();

                        worker.ReportProgress(0, new string[] { mensajeError, mensajeOk });
                    }
                }
            }
            worker.ReportProgress(0, new string[] { "Credit memo uploading finished.", "Credit memo uploading finished." });
        }