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);
            }
        }