public void UpdateQuickBooksInvoice()
 {
     using (QuickBooksInvoiceAgent agent = new QuickBooksInvoiceAgent(context))
     {
         agent.Update();
     }
 }
Esempio n. 2
0
        public void Execute()
        {
            /*DateTime lastExecution = (DateTime)context.Bag["LAST_EXECUTION"];
             * double intervall = (double)context.Bag["INTERVALL"];*/

            QuickBooksInvoiceAgent    agent    = new QuickBooksInvoiceAgent(context);
            List <ITransactionEntity> invoices = agent.Import();
        }
        public void CancelInvoice(QuickBooksInvoiceLog log)
        {
            context.TransactionObject = log;
            using (QuickBooksInvoiceAgent agent = new QuickBooksInvoiceAgent(context))
            {
                agent.Cancel();
            }

            log.IntegrationStatus = QbIntegrationLogStatus.CANCELLED;
            log.UpdatedUser       = context.UserName;
            log.UpdateDate        = DateTime.Now;
            UpdateInvoiceLog(log);
        }
Esempio n. 4
0
        protected override void ImportQb()
        {
            DateTime dt = DateTime.MinValue;

            if (!DateTime.TryParse(extendedData[MessageDataExtensionKeys.BEGIN_DATE], out dt))
            {
                throw new Exception(string.Format("Invalid begin date criteria `{0}`", extendedData[MessageDataExtensionKeys.BEGIN_DATE]));
            }
            Context.Bag.Add(MessageDataExtensionKeys.BEGIN_DATE, dt);

            if (!DateTime.TryParse(extendedData[MessageDataExtensionKeys.END_DATE], out dt))
            {
                throw new Exception(string.Format("Invalid end date criteria `{0}`", extendedData[MessageDataExtensionKeys.END_DATE]));
            }


            Context.Bag.Add(MessageDataExtensionKeys.END_DATE, dt);

            using (qbAgent = new QuickBooksInvoiceAgent(Context))
            {
                qbAgent.Import();
            }
        }
        public void IntegrateOrderToQuickBooks(List <OrderMaster> omList)
        {
            bool sendToQb = false;

            if (context.RequestMessage.MessageDataExtension.ContainsKey(MessageDataExtensionKeys.SEND_TO_QB))
            {
                bool.TryParse(context.RequestMessage.MessageDataExtension[MessageDataExtensionKeys.SEND_TO_QB], out sendToQb);
            }

            List <QuickBooksInvoiceLog> logs = new List <QuickBooksInvoiceLog>();
            long cnt = 0;

            using (QuickBooksInvoiceAgent agent = new QuickBooksInvoiceAgent(context))
            {
                foreach (OrderMaster om in omList)
                {
                    cnt++;
                    string status = sendToQb ? (string.IsNullOrWhiteSpace(om.IntegrationStatus) ? QbIntegrationLogStatus.OK : QbIntegrationLogStatus.REVOKED) : QbIntegrationLogStatus.WAITING;

                    QuickBooksInvoiceLog log = CreateInvoiceLog(om, status);
                    context.TransactionObject = om;
                    string qbInvoiceId = string.Empty;
                    string qbTxnId     = string.Empty;
                    try
                    {
                        agent.Export();
                        if (context.TransactionObject != null)
                        {
                            if (context.TransactionObject is Tuple <string, string> )
                            {
                                Tuple <string, string> tuple = context.TransactionObject as Tuple <string, string>;
                                qbInvoiceId = tuple.Item1;
                                qbTxnId     = tuple.Item2;
                            }
                            else
                            {
                                qbInvoiceId = context.Bag["REF_NUMBER"].ToString();
                                qbTxnId     = context.Bag["TXN_ID"].ToString();
                            }
                        }
                        log.QuickBooksInvoiceId = qbInvoiceId;
                        log.QuickBooksTxnId     = qbTxnId;
                        log.IntegrationStatus   = QbIntegrationLogStatus.OK;
                    }
                    catch (Exception ex)
                    {
                        string message = string.Format("Exception occured while integrating Order {0} to Quickbooks.", om.Id);
                        logger.Error(ex, message);
                        log.IntegrationStatus = QbIntegrationLogStatus.ERROR;
                        log.ErrorLog          = ex.ToString();
                        context.Warnings.Add(message);
                    }

                    InsertIntegrationLog(log);

                    logs.Add(log);

                    string eventMessage = string.Format("Order `{0}` integration complete. Status:{1}, QB Invoice Id:{2}", log.OrderId, log.IntegrationStatus, log.QuickBooksInvoiceId);

                    this.OnTransactionProgress(new TransactionProgressEventArgs(omList.Count, cnt, eventMessage));
                }
            }

            context.TransactionObject = logs;
        }
Esempio n. 6
0
        protected override void ExportQb()
        {
            string invoiceIdString = request.MessageDataExtension["INVOICE_LIST"];

            string[] invoiceIdListStr = invoiceIdString.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            List <long> invoiceIdList = invoiceIdListStr.Select(i => long.Parse(i)).ToList();

            OrderManager orderMan = new OrderManager(Context);

            List <QuickBooksInvoiceLog> list = invMan.List(invoiceIdList);

            List <OrderMaster> orders = orderMan.GetOrders(list.Select(l => l.OrderId).ToList());

            orders = orders.Where(om => om.IntegrationStatus == QbIntegrationLogStatus.WAITING || om.IntegrationStatus == QbIntegrationLogStatus.ERROR).ToList();
            long   counter     = 0;
            long   batchId     = CreateBatch(orders.Select(o => o.Id).ToList());
            string batchStatus = QbIntegrationLogStatus.OK;

            using (qbAgent = new QuickBooksInvoiceAgent(Context))
            {
                counter++;
                foreach (OrderMaster orderMaster in orders)
                {
                    Context.TransactionObject      = orderMaster;
                    orderMaster.InvoiceLog.BatchId = batchId;
                    string eventMessage = string.Empty;
                    try
                    {
                        qbAgent.Export();
                        orderMaster.InvoiceLog.IntegrationStatus   = orderMaster.InvoiceLog.IntegrationStatus == QbIntegrationLogStatus.ERROR ? QbIntegrationLogStatus.REVOKED : QbIntegrationLogStatus.OK;
                        orderMaster.InvoiceLog.ErrorLog            = string.Empty;
                        orderMaster.InvoiceLog.QuickBooksTxnId     = Context.Bag["TXN_ID"].ToString();
                        orderMaster.InvoiceLog.QuickBooksInvoiceId = Context.Bag["REF_NUMBER"].ToString();
                        orderMaster.OrderStatus = OrderStatus.INTEGRATED;
                        eventMessage            = string.Format("Invoice nr {0} created for order {1}", orderMaster.InvoiceLog.QuickBooksInvoiceId, orderMaster.Id);
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format("Exception occured while integrationg order to Quickbooks. Order id:{0}", orderMaster.Id);
                        logger.Error(ex, msg);
                        warnings.Add(msg);
                        orderMaster.InvoiceLog.ErrorLog          = ex.ToString();
                        orderMaster.InvoiceLog.IntegrationStatus = QbIntegrationLogStatus.ERROR;
                        orderMaster.OrderStatus = OrderStatus.ERROR;
                        batchStatus             = QbIntegrationLogStatus.ERROR;
                        eventMessage            = msg;
                    }
                    finally
                    {
                        invMan.UpdateInvoiceLog(orderMaster.InvoiceLog);
                        orderMan.UpdateOrder(orderMaster, false);
                    }
                    responseMessage += eventMessage + Environment.NewLine;

                    OnTransactionProgress(new TransactionProgressEventArgs(orders.Count, counter, eventMessage));
                }
            }

            invMan.UpdateBatch(batchId, batchStatus);
        }