예제 #1
0
        public RouteListDto convertToAPIRouteList(RouteList routeList, IEnumerable <KeyValuePair <string, int> > itemsToReturn)
        {
            var result = new RouteListDto()
            {
                ForwarderFullName = routeList.Forwarder?.FullName ?? "Нет",
                CompletionStatus  = _routeListCompletionStatusConverter.convertToAPIRouteListCompletionStatus(routeList.Status)
            };

            if (result.CompletionStatus == RouteListDtoCompletionStatus.Completed)
            {
                result.CompletedRouteList = new CompletedRouteListDto()
                {
                    RouteListId     = routeList.Id,
                    RouteListStatus = _routeListStatusConverter.convertToAPIRouteListStatus(routeList.Status),
                    CashMoney       = routeList.Addresses
                                      .Where(rla => rla.Status == RouteListItemStatus.Completed &&
                                             rla.Order.PaymentType == Vodovoz.Domain.Client.PaymentType.cash)
                                      .Sum(rla => rla.Order.ActualTotalSum),
                    TerminalMoney = routeList.Addresses
                                    .Where(rla => rla.Status == RouteListItemStatus.Completed &&
                                           rla.Order.PaymentType == Vodovoz.Domain.Client.PaymentType.Terminal)
                                    .Sum(rla => rla.Order.ActualTotalSum),
                    TerminalOrdersCount = routeList.Addresses
                                          .Where(rla => rla.Status == RouteListItemStatus.Completed &&
                                                 rla.Order.PaymentType == Vodovoz.Domain.Client.PaymentType.Terminal)
                                          .Count(),
                    FullBottlesToReturn = routeList.Addresses
                                          .Where(rla => rla.Status == RouteListItemStatus.Canceled ||
                                                 rla.Status == RouteListItemStatus.Overdue)
                                          .Sum(rla => rla.Order.Total19LBottlesToDeliver),
                    EmptyBottlesToReturn = routeList.Addresses
                                           .Sum(rla => rla.DriverBottlesReturned ?? 0),
                };

                result.CompletedRouteList.OrdersReturnItems = itemsToReturn.Select(pair => new OrdersReturnItemDto()
                {
                    Name = pair.Key, Count = pair.Value
                });
            }
            else
            {
                if (result.CompletionStatus == RouteListDtoCompletionStatus.Incompleted)
                {
                    var routelistAddresses = new List <RouteListAddressDto>();

                    foreach (var address in routeList.Addresses.OrderBy(address => address.IndexInRoute))
                    {
                        routelistAddresses.Add(convertToAPIRouteListAddress(address));
                    }

                    result.IncompletedRouteList = new IncompletedRouteListDto()
                    {
                        RouteListId        = routeList.Id,
                        RouteListStatus    = _routeListStatusConverter.convertToAPIRouteListStatus(routeList.Status),
                        RouteListAddresses = routelistAddresses
                    };
                }
            }

            return(result);
        }
예제 #2
0
        public RouteListDto convertToAPIRouteList(RouteList routeList, IEnumerable <KeyValuePair <string, int> > itemsToReturn)
        {
            var result = new RouteListDto()
            {
                ForwarderFullName = routeList.Forwarder?.FullName ?? "Нет",
                CompletionStatus  = _routeListCompletionStatusConverter.convertToAPIRouteListCompletionStatus(routeList.Status)
            };

            if (result.CompletionStatus == RouteListDtoCompletionStatus.Completed)
            {
                var ownOrders = routeList.Addresses
                                .Where(rla => !rla.Order.IsFastDelivery && !rla.WasTransfered)
                                .Sum(rla => rla.Order.Total19LBottlesToDeliver);

                var additionalBalance = routeList.AdditionalLoadingDocument?.Items
                                        .Where(ai => ai.Nomenclature.IsWater19L)
                                        .Sum(ai => ai.Amount) ?? 0;

                var deliveredOrders = routeList.Addresses
                                      .Where(rla =>
                                             rla.Status != RouteListItemStatus.Canceled && rla.Status != RouteListItemStatus.Overdue
                                             // и не перенесённые к водителю; либо перенесённые с погрузкой; либо перенесённые и это экспресс-доставка (всегда без погрузки)
                                             && (!rla.WasTransfered || rla.NeedToReload || rla.Order.IsFastDelivery)
                                             // и не перенесённые от водителя; либо перенесённые и не нужна погрузка и не экспресс-доставка (остатки по экспресс-доставке не переносятся)
                                             && (rla.Status != RouteListItemStatus.Transfered || (!rla.TransferedTo.NeedToReload && !rla.Order.IsFastDelivery)))
                                      .Sum(rla => rla.Order.Total19LBottlesToDeliver);

                var fullBottlesToReturn = ownOrders + additionalBalance - deliveredOrders;

                result.CompletedRouteList = new CompletedRouteListDto()
                {
                    RouteListId     = routeList.Id,
                    RouteListStatus = _routeListStatusConverter.convertToAPIRouteListStatus(routeList.Status),
                    CashMoney       = routeList.Addresses
                                      .Where(rla => rla.Status == RouteListItemStatus.Completed &&
                                             rla.Order.PaymentType == Vodovoz.Domain.Client.PaymentType.cash)
                                      .Sum(rla => rla.Order.OrderSum),
                    TerminalMoney = routeList.Addresses
                                    .Where(rla => rla.Status == RouteListItemStatus.Completed &&
                                           rla.Order.PaymentType == Vodovoz.Domain.Client.PaymentType.Terminal)
                                    .Sum(rla => rla.Order.OrderSum),
                    TerminalOrdersCount = routeList.Addresses
                                          .Where(rla => rla.Status == RouteListItemStatus.Completed &&
                                                 rla.Order.PaymentType == Vodovoz.Domain.Client.PaymentType.Terminal)
                                          .Count(),
                    FullBottlesToReturn  = (int)fullBottlesToReturn,
                    EmptyBottlesToReturn = routeList.Addresses
                                           .Sum(rla => rla.DriverBottlesReturned ?? 0),
                };

                result.CompletedRouteList.OrdersReturnItems = itemsToReturn.Select(pair => new OrdersReturnItemDto()
                {
                    Name = pair.Key, Count = pair.Value
                });
            }
            else
            {
                if (result.CompletionStatus == RouteListDtoCompletionStatus.Incompleted)
                {
                    var routelistAddresses = new List <RouteListAddressDto>();

                    foreach (var address in routeList.Addresses.OrderBy(address => address.IndexInRoute))
                    {
                        routelistAddresses.Add(convertToAPIRouteListAddress(address));
                    }

                    result.IncompletedRouteList = new IncompletedRouteListDto()
                    {
                        RouteListId        = routeList.Id,
                        RouteListStatus    = _routeListStatusConverter.convertToAPIRouteListStatus(routeList.Status),
                        RouteListAddresses = routelistAddresses
                    };
                }
            }

            return(result);
        }