Ejemplo n.º 1
0
        protected override void New()
        {
            if (requestType == OrderRequestType.InsertNewOrder)
            {
                OrderMaster om = (OrderMaster)request.TransactionEntityList[0];
                om.OrderStatus = OrderStatus.CREATED;
                om.CreatedUser = Context.UserName;
                orderMan.InsertOrder(om);


                if (request.MessageDataExtension.ContainsKey(MessageDataExtensionKeys.CREATE_INVOICE))
                {
                    if (request.MessageDataExtension[MessageDataExtensionKeys.CREATE_INVOICE].Equals(bool.TrueString.ToLower()))
                    {
                        ExportQb();
                    }
                    else
                    {
                        QuickBooksInvoiceLog log = qim.CreateInvoiceLog(om, QbIntegrationLogStatus.WAITING);
                        qim.InsertIntegrationLog(log);
                    }
                }
                response.TransactionResult = om;
            }
            else
            {
                long newId = new OrderManager(Context).GetNewOrderId();
                this.response.TransactionResult = newId;
            }
        }
Ejemplo n.º 2
0
        QuickBooksInvoiceLog ReadInvoice(DataRow row)
        {
            QuickBooksInvoiceLog result = null;

            if (row != null)
            {
                result = new QuickBooksInvoiceLog()
                {
                    BatchId              = row.Field <long>("BATCH_ID"),
                    CreateDate           = row.Field <DateTime>("CREATE_DATE"),
                    CreatedUser          = row.Field <string>("CREATE_USER"),
                    Customer             = CustomerCache.Instance[row.Field <long>("MAESTRO_CUSTOMER_ID")],
                    ErrorLog             = row.Field <string>("ERROR_LOG"),
                    Id                   = row.Field <long>("ID"),
                    IntegrationDate      = row.Field <DateTime>("INTEGRATION_DATE"),
                    IntegrationStatus    = row.Field <string>("INTEGRATION_STATUS"),
                    OrderId              = row.Field <long>("ORDER_ID"),
                    QuickBooksInvoiceId  = row.Field <string>("QB_INVOICE_NO"),
                    QuickBooksTxnId      = row.Field <string>("QB_TXN_ID"),
                    QuickBooksCustomerId = row.Field <string>("QB_CUSTOMER_ID"),
                    RecordStatus         = row.Field <string>("RECORD_STATUS"),
                    UpdateDate           = row.Field <DateTime>("UPDATE_DATE"),
                    UpdatedUser          = row.Field <string>("UPDATE_USER")
                };
            }

            return(result);
        }
        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);
        }
        public void UpdateInvoiceLog(QuickBooksInvoiceLog log)
        {
            SpCall spCall = new SpCall("DAT.QB_INVOICE_LOG_UPDATE");

            spCall.SetBigInt("@ID", log.Id);
            spCall.SetVarchar("@INTEGRATION_STATUS", log.IntegrationStatus);
            spCall.SetDateTime("@INTEGRATION_DATE", log.IntegrationDate);
            spCall.SetBigInt("@BATCH_ID", log.BatchId);
            spCall.SetVarchar("@QB_INVOICE_NO", log.QuickBooksInvoiceId);
            spCall.SetVarchar("@QB_TXN_ID", log.QuickBooksTxnId);
            spCall.SetVarchar("@ERROR_LOG", log.ErrorLog);
            spCall.SetDateTime("@UPDATE_DATE", log.CreateDate);
            spCall.SetVarchar("@UPDATE_USER", context.UserName);
            spCall.SetVarchar("@RECORD_STATUS", log.RecordStatus);
            db.ExecuteNonQuery(spCall);
        }
        public QuickBooksInvoiceLog GetInvoiceLog(string txnId)
        {
            SpCall spCall = new SpCall("DAT.QB_INVOICE_LOG_SELECT_BY_TXN_ID");

            spCall.SetVarchar("@TXN_ID", txnId);

            QuickBooksInvoiceLog result = null;

            using (SqlReader reader = db.ExecuteReader(spCall))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    result = GetLogFromReader(reader);
                }
                reader.Close();
            }
            return(result);
        }
Ejemplo n.º 6
0
        protected override void Delete()
        {
            long orderId = ValidateEntityIdFromDataExtension();
            //Context.TransactionObject = new Framework.ManagerRepository.OrderManager(Context).GetOrder(id);
            QuickBooksInvoiceLog log = qim.GetInvoiceLog(orderId);

            if (log.IntegrationStatus == QbIntegrationLogStatus.OK || log.IntegrationStatus == QbIntegrationLogStatus.REVOKED)
            {
                Context.TransactionObject = log;
                qim.CancelInvoice(log);
            }

            SpCall spCall = new SpCall("DAT.ORDER_MASTER_DELETE");

            spCall.SetBigInt("@ID", orderId);
            spCall.SetDateTime("@UPDATE_DATE", DateTime.Now);
            spCall.SetVarchar("@UPDATE_USER", Context.UserName);
            db.ExecuteNonQuery(spCall);
        }
        public void InsertIntegrationLog(QuickBooksInvoiceLog log)
        {
            SpCall spCall = new SpCall("DAT.QB_INVOICE_LOG_INSERT");

            spCall.SetBigInt("@ORDER_ID", log.OrderId);
            spCall.SetBigInt("@MAESTRO_CUSTOMER_ID", log.Customer.Id);
            spCall.SetVarchar("@QB_CUSTOMER_ID", log.Customer.QuickBooksId);
            spCall.SetVarchar("@INTEGRATION_STATUS", log.IntegrationStatus);
            spCall.SetDateTime("@INTEGRATION_DATE", log.IntegrationDate);
            spCall.SetBigInt("@BATCH_ID", log.BatchId);
            spCall.SetVarchar("@QB_INVOICE_NO", log.QuickBooksInvoiceId);
            spCall.SetVarchar("@QB_TXN_ID", log.QuickBooksTxnId);
            spCall.SetVarchar("@ERROR_LOG", log.ErrorLog);
            spCall.SetDateTime("@CREATE_DATE", log.CreateDate);
            spCall.SetVarchar("@CREATE_USER", context.UserName);

            long result = db.ExecuteScalar <long>(spCall);

            log.Id = result;
        }
Ejemplo n.º 8
0
        protected override void Update()
        {
            OrderMaster om = (OrderMaster)request.TransactionEntityList[0];

            om.UpdatedUser = Context.UserName;
            bool cleanItems = extendedData.ContainsKey(MessageDataExtensionKeys.CLEAN_ORDER_ITEMS);

            orderMan.UpdateOrder(om, cleanItems);

            //refresh order with id's
            om = orderMan.GetOrder(om.Id);
            QuickBooksInvoiceLog log = om.InvoiceLog;

            Context.TransactionObject = om;

            if (log.IntegrationStatus == QbIntegrationLogStatus.OK || log.IntegrationStatus == QbIntegrationLogStatus.REVOKED)
            {
                qim.UpdateQuickBooksInvoice();
            }
        }
        public QuickBooksInvoiceLog CreateInvoiceLog(OrderMaster om, string status)
        {
            QuickBooksInvoiceLog log = new QuickBooksInvoiceLog()
            {
                BatchId              = 0,
                CreateDate           = DateTime.Now,
                CreatedUser          = context.UserName,
                Customer             = om.Customer,
                QuickBooksInvoiceId  = context.Bag.ContainsKey("QB_INVOICE_ID") ? context.Bag["QB_INVOICE_ID"].ToString() : string.Empty,
                QuickBooksTxnId      = context.Bag.ContainsKey("QB_TXN_ID") ? context.Bag["QB_TXN_ID"].ToString() : string.Empty,
                QuickBooksCustomerId = om.Customer.QuickBooksId,
                ErrorLog             = string.Empty,
                IntegrationDate      = DateTime.Now,
                OrderId              = om.Id,
                RecordStatus         = "A",
                UpdateDate           = DateTime.Now,
                UpdatedUser          = context.UserName,
                IntegrationStatus    = status
            };

            return(log);
        }
        QuickBooksInvoiceLog GetLogFromReader(SqlReader reader)
        {
            QuickBooksInvoiceLog result = new QuickBooksInvoiceLog()
            {
                Id                   = reader.GetInt64("ID"),
                BatchId              = reader.GetInt64("BATCH_ID"),
                CreateDate           = reader.GetDateTime("CREATE_DATE"),
                CreatedUser          = reader.GetString("CREATE_USER"),
                Customer             = CustomerCache.Instance[reader.GetInt64("MAESTRO_CUSTOMER_ID")],
                ErrorLog             = reader.GetString("ERROR_LOG"),
                IntegrationDate      = reader.GetDateTime("INTEGRATION_DATE"),
                IntegrationStatus    = reader.GetString("INTEGRATION_STATUS"),
                OrderId              = reader.GetInt64("ORDER_ID"),
                QuickBooksCustomerId = reader.GetString("QB_CUSTOMER_ID"),
                QuickBooksInvoiceId  = reader.GetString("QB_INVOICE_NO"),
                QuickBooksTxnId      = reader.GetString("QB_TXN_ID"),
                RecordStatus         = reader.GetString("RECORD_STATUS"),
                UpdateDate           = reader.GetDateTime("UPDATE_DATE"),
                UpdatedUser          = reader.GetString("UPDATE_USER")
            };

            return(result);
        }
        public QuickBooksInvoiceLog GetInvoiceLog(long orderId)
        {
            SpCall spCall = new SpCall("DAT.QB_INVOICE_LOG_SELECT_BY_ORDER_ID");

            spCall.SetBigInt("@ORDER_ID", orderId);

            QuickBooksInvoiceLog result = null;

            using (SqlReader reader = db.ExecuteReader(spCall))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    result = GetLogFromReader(reader);
                }
                else
                {
                    throw new Exception(string.Format("Integration log for order {0} could not be found.", orderId));
                }
                reader.Close();
            }
            return(result);
        }
        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;
        }