private OrderDetailsViewModel.DeliveryItem BuildDeliveryRow(OrderOverview orderOverview, ShippingInfo shippingInfo, bool includeVat, Currency currency)
        {
            var shipmentRows = orderOverview.Shipments?.SelectMany(x => x.Rows.Where(y => y.ShippingInfoSystemId.GetValueOrDefault() == shippingInfo.SystemId));
            var shipmentCost = shipmentRows == null ? 0 :
                               includeVat?shipmentRows.Select(x => x.TotalIncludingVat).Sum() : shipmentRows.Select(x => x.TotalExcludingVat).Sum();

            var order              = orderOverview.SalesOrder;
            var channel            = _channelService.Get(order.ChannelSystemId.Value);
            var shippingOptionName = string.Empty;

            if (channel is not null)
            {
                var country     = _countryService.Get(order.CountryCode);
                var countryLink = channel.CountryLinks.FirstOrDefault(x => x.CountrySystemId == country.SystemId);

                if (shippingInfo != null)
                {
                    shippingOptionName = countryLink?.ShippingOptions.FirstOrDefault(x => x.Id.Equals(shippingInfo.ShippingOption))?.Name;
                }
            }

            var model = new OrderDetailsViewModel.DeliveryItem
            {
                DeliveryId           = shippingInfo.SystemId,
                DeliveryMethodTitle  = shippingOptionName,
                DeliveryRowTotalCost = currency.Format(shipmentCost, true, CultureInfo.CurrentUICulture)
            };

            model.Address.MapFrom(shippingInfo.ShippingAddress);

            return(model);
        }
        private bool HasAllShipmentsShipped(OrderOverview order)
        {
            var orderCountPerArticle = order.SalesOrder.Rows.Where(x => x.OrderRowType == Sales.OrderRowType.Product)
                                       .GroupBy(r => r.ArticleNumber).ToDictionary(g => g.Key, g => g.Sum(t => t.Quantity));
            var shippedCountPerArticle = order.Shipments.Where(x => _stateTransitionsService.GetState <Sales.Shipment>(x.SystemId) == ShipmentState.Shipped)
                                         .SelectMany(x => x.Rows.Where(r => r.OrderRowType == Sales.OrderRowType.Product))
                                         .GroupBy(r => r.ArticleNumber).ToDictionary(g => g.Key, g => g.Sum(t => t.Quantity));

            return(shippedCountPerArticle.Sum(x => x.Value) == orderCountPerArticle.Sum(x => x.Value) &&
                   orderCountPerArticle.All(x => shippedCountPerArticle.TryGetValue(x.Key, out var value) && value == x.Value));
        }
Exemplo n.º 3
0
        Error Validate(Member member, OrderOverview order)
        {
            if (member == null || order == null)
            {
                return(NotFound());
            }

            var alllowedUnits = new[] { order.FromUnitId, order.ToUnitId };

            if (!alllowedUnits.Contains(member.UnitID))
            {
                return(UnauthorizedError());
            }

            return(null);
        }
Exemplo n.º 4
0
        string GenerateMailBody(Member member, OrderOverview order, string desc)
        {
            var vm = new ProblemReportMailModel
            {
                CurrentStatus    = order.StatusName,
                Description      = desc,
                FromUnit         = order.FromUnit,
                ItemName         = order.ItemName,
                OrderCreatedDate = order.OrderDate,
                MemberUnitId     = member.UnitID,
                OrderId          = order.Id,
                ReportDate       = DateTime.Now,
                ReportingMember  = $"{member.FirstName} {member.LastName}",
                ToUnit           = order.ToUnit
            };

            var html = FakeController.RenderViewToString("Mail", "OrderProblem", vm);

            return(html);
        }
        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);
        }