Exemplo n.º 1
0
        private AcumaticaSalesOrder FindAndUpsertSalesOrderData(SalesOrder order)
        {
            using (var transaction = _orderRepository.BeginTransaction())
            {
                var orderNbr       = order.OrderNbr.value;
                var shopifyOrderId = order.CustomerOrder.value.ToLongAlt(-1);
                var orderRecord    = _orderRepository.RetrieveSalesOrder(orderNbr);

                bool unknownRef = false;

                if (orderRecord == null)
                {
                    // Skip Sales Orders that were not intentionally loaded into Acumatica
                    //
                    orderRecord = _orderRepository.FindSalesOrderByShopifyId(shopifyOrderId);

                    if (orderRecord == null)
                    {
                        return(null);
                    }

                    unknownRef = true;
                }

                if (unknownRef)
                {
                    _executionLogService.Log(
                        LogBuilder.FillingUnknownAcumaticaSalesOrderRef(orderRecord.ShopifyOrder, orderRecord));
                }

                _executionLogService.Log(LogBuilder.DetectedUpdateAcumaticaOrder(orderRecord));

                _acumaticaJsonService.Upsert(
                    AcumaticaJsonType.SalesOrderShipments,
                    orderNbr,
                    SalesOrderType.SO,
                    order.SerializeToJson());

                // Again, to be tested
                //
                // orderRecord.AcumaticaQtyTotal = (int)order.Details.Sum(x => x.OrderQty.value);

                orderRecord.Ingest(order);
                orderRecord.LastUpdated = DateTime.UtcNow;

                _orderRepository.SaveChanges();
                transaction.Commit();

                return(orderRecord);
            }
        }
Exemplo n.º 2
0
        private void CorrectSalesOrderWithUnknownRef(long shopifyOrderId)
        {
            var shopifyOrderRecord = _syncOrderRepository.RetrieveShopifyOrder(shopifyOrderId);

            if (!shopifyOrderRecord.HasSyncWithUnknownNbr())
            {
                return;
            }

            var salesOrderRecord = shopifyOrderRecord.AcumaticaSalesOrder;

            var customerOrderRef = shopifyOrderRecord.ShopifyOrderId.ToString();
            var findOrders       = _salesOrderClient.FindSalesOrder(customerOrderRef);

            if (findOrders.Count == 0)
            {
                _logService.Log(LogBuilder.ClearingUnknownAcumaticaSalesOrderRef(shopifyOrderRecord));
                _acumaticaOrderRepository.DeleteSalesOrder(shopifyOrderRecord.AcumaticaSalesOrder);
                return;
            }

            // Heuristic for now
            //
            var salesOrder = findOrders.OrderBy(x => x.OrderNbr.value).First();

            salesOrderRecord.Ingest(salesOrder);
            _logService.Log(LogBuilder.FillingUnknownAcumaticaSalesOrderRef(shopifyOrderRecord, salesOrderRecord));
            _acumaticaOrderRepository.SaveChanges();
        }
Exemplo n.º 3
0
        private void UpdateCustomerToPersist(Customer acumaticaCustomer)
        {
            var existingRecord = _orderRepository.RetrieveCustomer(acumaticaCustomer.CustomerID.value);

            if (existingRecord != null)
            {
                using (var transaction = _orderRepository.BeginTransaction())
                {
                    _acumaticaJsonService.Upsert(
                        AcumaticaJsonType.Customer,
                        acumaticaCustomer.CustomerID.value,
                        acumaticaCustomer.SerializeToJson());
                    existingRecord.AcumaticaMainContactEmail = acumaticaCustomer.MainContact.Email.value;
                    existingRecord.LastUpdated = DateTime.UtcNow;
                    _orderRepository.SaveChanges();
                    transaction.Commit();
                }
            }
        }