/// <summary>
        /// Serialize Transaction
        /// <param name="transactionType"></param>
        /// </summary>
        private string SerializeRMTransaction(RMTransactionType transactionType)
        {
            try
            {
                eConnectType        eConnect = new eConnectType();
                RMTransactionType[] TranType = { transactionType };
                eConnect.RMTransactionType = 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>
        /// Create RM transaction
        /// <param name="transaction">Header of RM transaction</param>
        /// <param name="Distribution">Distribution Account of RM Transaction</param>
        /// <param name="Taxes">Taxes of RM transaction</param>
        /// <param name="company">COMPANY SHORT NAME</param>
        /// <returns>Response Class</returns>
        /// </summary>
        // Log4NetMR.classClsRegistrarLog logW = new Log4NetMR.classClsRegistrarLog();
        public Response TransactionCreate(RMTransactionHeader transaction, RMTransactionDist[] Distribution, RMDocumentTaxes[] Taxes, 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();
            RMTransactionType rmTranType     = new RMTransactionType();

            var getnext = new GetNextDocNumbers();

            getnext.RequireServiceProxy = false;

            try
            {
                string DOCNUMBR = string.Empty;

                if (string.IsNullOrEmpty(transaction.DOCNUMBR))
                {
                    DOCNUMBR = getnext.GetNextRMNumber(IncrementDecrement.Increment, RMPaymentType.RMCreditMemo, CNX);
                }
                else
                {
                    DOCNUMBR = transaction.DOCNUMBR;
                }

                rmTranType.taRMTransaction = SetTransactionValues(transaction, DOCNUMBR);

                if (transaction.CREATEDIST == 0)
                {
                    rmTranType.taRMDistribution_Items = SetDistributionValues(Distribution, DOCNUMBR);
                }
                if (transaction.CreateTaxes == 1)
                {
                    rmTranType.taRMTransactionTaxInsert_Items = SetTaxValues(Taxes, DOCNUMBR);
                }

                transactionXML = SerializeRMTransaction(rmTranType);

                response = eConnect.CreateGPTransaction(CNX, transactionXML);
                return(response);
            }
            catch (Exception ex)
            {
                //logW.LogExeption("Econnect", 2, ex);
                response         = new Response();
                response.SUCCESS = false;
                response.MESSAGE = ex.Message;
                response.STACK   = ex.StackTrace;
                return(response);
            }
            finally
            {
                getnext.Dispose();
            }
        }
示例#3
0
        /// <summary>
        /// save new receivable transaction
        /// </summary>
        /// <param name="receivable"></param>
        /// <returns></returns>
        public OperationResult SaveReceivableTransaction(RM20101 receivable)
        {
            var operationResult = new OperationResult();

            logger.Debug("Receivable is being created...");

            using (eConnectMethods e = new eConnectMethods())
            {
                try
                {
                    // Instantiate a taPMTransactionInsert XML node object
                    taRMTransaction transaction = new taRMTransaction();

                    //Populate elements of the taUpdateCreateItemRcd XML node object
                    transaction.RMDTYPAL = receivable.RMDTYPAL;
                    transaction.DOCNUMBR = receivable.DOCNUMBR;
                    transaction.DOCDATE  = receivable.DOCDATE.ToShortDateString();
                    transaction.BACHNUMB = receivable.BACHNUMB;
                    transaction.CUSTNMBR = receivable.CUSTNMBR;
                    transaction.DOCAMNT  = receivable.DOCAMNT;
                    transaction.SLSAMNT  = receivable.SLSAMNT;

                    // Instantiate a PMTransactionType schema object
                    RMTransactionType transactiontype = new RMTransactionType();

                    // Populate the PMTransactionType schema with the taPMTransactionInsert XML node
                    transactiontype.taRMTransaction = transaction;
                    RMTransactionType[] receivableTransaction = { transactiontype };

                    // Instantiate an eConnectType schema object
                    eConnectType eConnect = new eConnectType();

                    // Instantiate a Memory Stream object
                    MemoryStream memoryStream = new MemoryStream();

                    // Create an XML serializer object
                    XmlSerializer serializer = new XmlSerializer(eConnect.GetType());

                    // Populate the eConnectType object with the PMTransactionType schema object
                    eConnect.RMTransactionType = receivableTransaction;

                    // Serialize the eConnectType.
                    serializer.Serialize(memoryStream, eConnect);

                    // Reset the position of the memory stream to the start.
                    memoryStream.Position = 0;

                    // Create an XmlDocument from the serialized eConnectType in memory.
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(memoryStream);
                    memoryStream.Close();

                    // Call eConnect to process the XmlDocument.
                    e.CreateEntity(_dynamicsConnection, xmlDocument.OuterXml);

                    operationResult.Success = true;
                    operationResult.Message = "Success";
                }
                // The eConnectException class will catch eConnect business logic errors.
                // display the error message on the console
                catch (eConnectException exc)
                {
                    Console.Write(exc.ToString());
                    operationResult.Success = false;
                    operationResult.Message = "Error";
                    logger.ErrorFormat("Error saving new payables transaction: {0} ", exc.ToString());
                }
                // Catch any system error that might occurr.
                // display the error message on the console
                catch (System.Exception ex)
                {
                    Console.Write(ex.ToString());
                    operationResult.Success = false;
                    operationResult.Message = "Error";
                    logger.ErrorFormat("Error saving new payables transaction: {0} ", ex.ToString());
                }
                finally
                {
                    // Call the Dispose method to release the resources
                    // of the eConnectMethds object
                    e.Dispose();
                }
            } // end of using statement

            return(operationResult);
        }
        /// <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." });
        }