internal OrderDetailsViewModel Build(OrderOverview orderOverview)
        {
            var order = orderOverview.SalesOrder;

            if (order == null)
            {
                return(new OrderDetailsViewModel());
            }
            var includeVat = IncludeVat(order);
            var currency   = _currencyService.Get(order.CurrencyCode);

            var            paymentOptionName  = string.Empty;
            var            shippingOptionName = string.Empty;
            DateTimeOffset?deliveryDate       = null;

            if (order.ChannelSystemId.HasValue)
            {
                var paymentOption = _orderHelperService.GetPaymentOption(order);
                paymentOptionName = paymentOption?.Name.NullIfWhiteSpace() ?? paymentOption?.Id?.ToString();

                var shippingOption = _orderHelperService.GetShippingOption(order);
                shippingOptionName = shippingOption?.Name.NullIfWhiteSpace() ?? shippingOption?.Id?.ToString();
            }

            var shippingInfo = order.ShippingInfo.FirstOrDefault();

            if (shippingInfo != null)
            {
                var shippingOption = _shippingProviderService.Get(shippingInfo.ShippingOption.ProviderId)?.Options.FirstOrDefault(x => x.Id == shippingInfo.ShippingOption.OptionId);
                if (shippingOption != null)
                {
                    deliveryDate = order.OrderDate.AddDays(shippingOption.DeliveryTimeInDays);
                }
            }

            var    orderState               = _stateTransitionsService.GetState <SalesOrder>(order.SystemId);
            var    statusTranslation        = ("sales.order.status." + orderState).AsWebsiteText();
            var    orderTotalFee            = includeVat ? order.TotalFeesIncludingVat : order.TotalFeesExcludingVat;
            var    orderTotalDiscountAmount = includeVat ? order.TotalPromotionsAndDiscountsIncludingVat : order.TotalPromotionsAndDiscountsExcludingVat;
            var    orderTotalDeliveryCost   = includeVat ? order.ShippingCostIncludingVat : order.ShippingCostExcludingVat;
            var    totalVat         = order.TotalVat;
            var    grandTotal       = order.GrandTotal;
            string organizationName = string.Empty;

            if (order.CustomerInfo.OrganizationSystemId.HasValue)
            {
                var organization = _organizationService.Get(order.CustomerInfo.OrganizationSystemId.Value);
                organizationName = organization != null ? organization.Name : order.ShippingInfo.FirstOrDefault()?.ShippingAddress.OrganizationName;
            }
            var shippingAddress = order.ShippingInfo.First()?.ShippingAddress;
            var orderDetails    = new OrderDetailsViewModel
            {
                OrderId                  = order.SystemId,
                ExternalOrderID          = order.Id,
                OrderDate                = order.OrderDate,
                OrderStatus              = orderState,
                Status                   = statusTranslation,
                OrderTotalFee            = currency.Format(orderTotalFee, true, CultureInfo.CurrentUICulture),
                OrderTotalDiscountAmount = orderTotalDiscountAmount < 0 ? currency.Format(orderTotalDiscountAmount, true, CultureInfo.CurrentUICulture) : string.Empty,
                OrderTotalDeliveryCost   = currency.Format(orderTotalDeliveryCost, true, CultureInfo.CurrentUICulture),
                OrderTotalVat            = currency.Format(totalVat, true, CultureInfo.CurrentUICulture),
                OrderGrandTotal          = currency.Format(grandTotal, true, CultureInfo.CurrentUICulture),
                OrderRows                = order.Rows.Where(x => x.OrderRowType == OrderRowType.Product).Select(x => BuildOrderRow(x, includeVat, currency, order)).ToList(),
                PaymentMethod            = paymentOptionName,
                DeliveryMethod           = shippingOptionName,
                ActualDeliveryDate       = deliveryDate,
                Deliveries               = order.ShippingInfo.Select(x => BuildDeliveryRow(orderOverview, x, includeVat, currency)).ToList(),
                CustomerInfo             = new OrderDetailsViewModel.CustomerInfoModel
                {
                    CustomerNumber = order.CustomerInfo?.CustomerNumber,
                    FirstName      = order.CustomerInfo?.FirstName,
                    LastName       = order.CustomerInfo?.LastName,
                    Address1       = shippingAddress?.Address1,
                    Zip            = shippingAddress?.ZipCode,
                    City           = shippingAddress?.City,
                    Country        = string.IsNullOrEmpty(shippingAddress?.Country) ? string.Empty : new RegionInfo(shippingAddress.Country).DisplayName
                },
                MerchantOrganizationNumber = _personStorage.CurrentSelectedOrganization?.Id,
                CompanyName = organizationName
            };

            return(orderDetails);
        }