public async Task <IActionResult> Edit(int id, [Bind("CarVersionID,version,CarModelID")] CarVersion carVersion)
        {
            if (id != carVersion.CarVersionID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carVersion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarVersionExists(carVersion.CarVersionID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarModelID"] = new SelectList(_context.CarModels, "CarModelID", "model", carVersion.CarModelID);
            return(View(carVersion));
        }
        public void CreateFuelCashExpenseTest()
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            CarVersion carVersionMock = Substitute.For <CarVersion>();

            carVersionMock.IsCompanyCar.Returns(false);

            Organization organisationMock = Substitute.For <Organization>();

            VodovozRouteList routeListMock      = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock    = Substitute.For <Subdivision>();
            IUnitOfWork      uowMock            = Substitute.For <IUnitOfWork>();
            IFuelRepository  fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            routeListMock.ClosingSubdivision = subdivisionMock;

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver          = Substitute.For <Employee>();
            fuelDocument.FuelPaymentType = FuelPaymentType.Cash;
            fuelDocument.Car             = carVersionMock.Car;
            fuelDocument.Date            = DateTime.Now;
            fuelDocument.LastEditDate    = DateTime.Now;
            fuelDocument.Fuel            = fuelTypeMock;
            fuelDocument.RouteList       = routeListMock;
            fuelDocument.UoW             = uowMock;
            fuelDocument.FuelCoupons     = 40;
            fuelDocument.PayedForFuel    = 500;
            fuelDocument.Subdivision     = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            AssertsAccumulator.Create
            .Accumulate(() => Assert.That(fuelDocument.FuelCashExpense.Casher, Is.SameAs(fuelDocument.Author)))
            .Accumulate(() => Assert.That(fuelDocument.FuelCashExpense.Employee, Is.SameAs(fuelDocument.Driver)))
            .Accumulate(() => Assert.That(fuelDocument.FuelCashExpense.RelatedToSubdivision, Is.SameAs(fuelDocument.RouteList.ClosingSubdivision)))
            .Release();
        }
        public void CreateFuelCashExpenseTest_Money(decimal payedForFuel, decimal result)
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            CarVersion carVersionMock = Substitute.For <CarVersion>();

            carVersionMock.IsCompanyCar.Returns(false);

            Organization organisationMock = Substitute.For <Organization>();

            IUnitOfWork uowMock = Substitute.For <IUnitOfWork>();

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            var organisationParametersProviderMock = Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            organisationParametersProviderMock.CommonCashDistributionOrganisationId.Returns(2);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver          = Substitute.For <Employee>();
            fuelDocument.Car             = carVersionMock.Car;
            fuelDocument.FuelPaymentType = FuelPaymentType.Cash;
            fuelDocument.Date            = DateTime.Now;
            fuelDocument.LastEditDate    = DateTime.Now;
            fuelDocument.Fuel            = fuelTypeMock;
            fuelDocument.RouteList       = routeListMock;
            fuelDocument.UoW             = uowMock;
            fuelDocument.FuelCoupons     = 40;
            fuelDocument.PayedForFuel    = payedForFuel;
            fuelDocument.Subdivision     = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            Assert.That(fuelDocument.FuelCashExpense.Money, Is.EqualTo(result));
        }
        public void CreateFuelCashExpenseTest__Incorrect_FuelCoupons_and_PayedForFuel__Thrown_ValidationException_and_FuelCashExpense_must_be_null()
        {
            // arrange
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            CarVersion carVersionMock = Substitute.For <CarVersion>();

            carVersionMock.IsCompanyCar.Returns(true);

            Organization organisationMock = Substitute.For <Organization>();

            IUnitOfWork uowMock = Substitute.For <IUnitOfWork>();

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver       = Substitute.For <Employee>();
            fuelDocument.Car          = carVersionMock.Car;
            fuelDocument.Date         = DateTime.Now;
            fuelDocument.LastEditDate = DateTime.Now;
            fuelDocument.Fuel         = fuelTypeMock;
            fuelDocument.RouteList    = routeListMock;
            fuelDocument.UoW          = uowMock;
            fuelDocument.PayedForFuel = 0;

            // act, assert
            Assert.Throws(typeof(ValidationException),
                          () => fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock));

            // additional assert
            Assert.That(fuelDocument.FuelCashExpense, Is.Null, "При исключении в момент создания операций, операции оплаты топлива не должно быть создано");
        }
        public async Task <IActionResult> Create([Bind("CarVersionID,version,CarModelID")] CarVersion carVersion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carVersion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarModelID"] = new SelectList(_context.CarModels, "CarModelID", "model", carVersion.CarModelID);
            return(View(carVersion));
        }
Ejemplo n.º 6
0
        private IList <CarEvent> GetEvents()
        {
            Car        carAlias        = null;
            CarEvent   carEventAlias   = null;
            CarModel   carModelAlias   = null;
            CarVersion carVersionAlias = null;

            return(UoW.Session.QueryOver(() => carEventAlias)
                   .JoinAlias(() => carEventAlias.Car, () => carAlias)
                   .JoinAlias(() => carAlias.CarModel, () => carModelAlias)
                   .JoinAlias(() => carAlias.CarVersions, () => carVersionAlias)
                   .WhereRestrictionOn(() => carEventAlias.CarEventType).IsInG(GetSelectedCarEventTypes())
                   .WhereRestrictionOn(() => carModelAlias.CarTypeOfUse).IsInG(SelectedCarTypeOfUse)
                   .WhereRestrictionOn(() => carVersionAlias.CarOwnType).IsInG(SelectedCarOwnTypes)
                   .Where(() => carVersionAlias.EndDate == null)
                   .And(() => Car == null || Car == carEventAlias.Car)
                   .And(() => carEventAlias.StartDate >= StartDate)
                   .And(() => carEventAlias.EndDate <= EndDate)
                   .And(() => !carEventAlias.DoNotShowInOperation)
                   .List <CarEvent>());
        }
Ejemplo n.º 7
0
        public static void Initialize(FaultsContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.CarMakes.Any())
            {
                return;   // DB has been seeded
            }

            var CarMakes = new CarMake[]
            {
                new CarMake {
                    make = "Audi"
                },
                new CarMake {
                    make = "Peugeot"
                },
                new CarMake {
                    make = "BMW"
                },
                new CarMake {
                    make = "Porsche"
                },
                new CarMake {
                    make = "Toyota"
                },
                new CarMake {
                    make = "Hyundai"
                },
                new CarMake {
                    make = "Fiat"
                },
            };

            foreach (CarMake s in CarMakes)
            {
                context.CarMakes.Add(s);
            }
            context.SaveChanges();

            var CarModels = new CarModel[]
            {
                new CarModel {
                    CarMakeID = 1, model = "A4"
                },
                new CarModel {
                    CarMakeID = 1, model = "A5"
                },
                new CarModel {
                    CarMakeID = 1, model = "A7"
                },
                new CarModel {
                    CarMakeID = 1, model = "S4"
                },
                new CarModel {
                    CarMakeID = 1, model = "RS4"
                },
                new CarModel {
                    CarMakeID = 2, model = "307"
                },
                new CarModel {
                    CarMakeID = 2, model = "207"
                },
                new CarModel {
                    CarMakeID = 2, model = "3008"
                },
                new CarModel {
                    CarMakeID = 3, model = "M3"
                },
                new CarModel {
                    CarMakeID = 3, model = "E86"
                },
                new CarModel {
                    CarMakeID = 4, model = "Boxter"
                },
                new CarModel {
                    CarMakeID = 4, model = "Cayenne"
                },
                new CarModel {
                    CarMakeID = 4, model = "Carrera 911"
                },
                new CarModel {
                    CarMakeID = 7, model = "500"
                },
                new CarModel {
                    CarMakeID = 7, model = "126p"
                }
            };

            foreach (CarModel s in CarModels)
            {
                context.CarModels.Add(s);
            }
            context.SaveChanges();

            var CarVersions = new CarVersion[]
            {
                new CarVersion {
                    CarModelID = 1, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 1, version = "Executive"
                },
                new CarVersion {
                    CarModelID = 2, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 3, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 4, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 5, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 6, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 7, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 8, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 9, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 10, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 11, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 12, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 13, version = "Standard"
                },
                new CarVersion {
                    CarModelID = 14, version = "Standard"
                },
            };

            foreach (CarVersion c in CarVersions)
            {
                context.CarVersion.Add(c);
            }
            context.SaveChanges();

            var Faults = new CarFault[]
            {
                new CarFault {
                    name = "AC Blowing up", fixCost = 2000, severity = CarFaultSeverity.SERIOUS
                },
                new CarFault {
                    name = "Coolant leaking", fixCost = 50, severity = CarFaultSeverity.MEDIUM
                },
                new CarFault {
                    name = "Car blows up", fixCost = 20000, severity = CarFaultSeverity.SERIOUS
                },
                new CarFault {
                    name = "Cup holder broken", fixCost = 10, severity = CarFaultSeverity.TRIVIAL
                },
            };

            foreach (CarFault f in Faults)
            {
                context.CarFaults.Add(f);
            }
            context.SaveChanges();

            var FaultConnections = new FaultConnection[]
            {
                new FaultConnection(1, 1),
                new FaultConnection(2, 1),
                new FaultConnection(3, 1),
                new FaultConnection(4, 1),
                new FaultConnection(2, 3),
            };

            foreach (FaultConnection f in FaultConnections)
            {
                context.FaultConnections.Add(f);
            }
            context.SaveChanges();
        }
        public void CreateFuelOperationTest_Car_IsCompanyHavings()
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            CarVersion carVersionMock = Substitute.For <CarVersion>();

            carVersionMock.IsCompanyCar.Returns(true);

            Car carMock = Substitute.For <Car>();

            carMock.GetActiveCarVersionOnDate(Arg.Any <DateTime>()).Returns(carVersionMock);

            Organization organisationMock = Substitute.For <Organization>();

            IUnitOfWork uowMock = Substitute.For <IUnitOfWork>();

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument
            {
                Driver       = Substitute.For <Employee>(),
                Car          = carMock,
                Date         = DateTime.Now,
                LastEditDate = DateTime.Now,
                Fuel         = fuelTypeMock,
                RouteList    = routeListMock,
                UoW          = uowMock,
                FuelCoupons  = 40,
                PayedForFuel = null,
                Subdivision  = subdivisionMock
            };

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            AssertsAccumulator.Create
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.LitersGived, Is.EqualTo(fuelDocument.FuelCoupons), "Количество топлива в операции не совпадает с количеством в документе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.PayedLiters, Is.EqualTo(fuelDocument.PayedLiters), "Количество топлива оплаченного деньгами не совпадает с количеством топлива оплаченного деньгами в документе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.Car, Is.SameAs(fuelDocument.Car), "Автомобиль в операции не совпадает с автомобилем в документе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.Driver, Is.Null, "Водитель не должен быть заполнен"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.Fuel, Is.SameAs(fuelDocument.Fuel), "Тип топлива в операции не совпадает с типом топлива в документе"))
            .Release();
        }
        public void CreateFuelExpenseOperationTest()
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            CarVersion carVersionMock = Substitute.For <CarVersion>();

            carVersionMock.IsCompanyCar.Returns(false);

            Organization organisationMock = Substitute.For <Organization>();

            IUnitOfWork uowMock = Substitute.For <IUnitOfWork>();

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver       = Substitute.For <Employee>();
            fuelDocument.Car          = carVersionMock.Car;
            fuelDocument.Date         = DateTime.Now;
            fuelDocument.LastEditDate = DateTime.Now;
            fuelDocument.Fuel         = fuelTypeMock;
            fuelDocument.RouteList    = routeListMock;
            fuelDocument.UoW          = uowMock;
            fuelDocument.FuelCoupons  = 40;
            fuelDocument.PayedForFuel = null;
            fuelDocument.Subdivision  = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            AssertsAccumulator.Create
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.FuelDocument, Is.SameAs(fuelDocument), "Документ в операции должен совпадать с документом выдачи топлива"))
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.FuelTransferDocument, Is.Null, "Документ перемещения топлива не должен быть заполнен"))
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.RelatedToSubdivision, Is.SameAs(fuelDocument.RouteList.ClosingSubdivision), "Подразделение в операции должно совпадать с подразделением в маршрутном листе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.FuelLiters, Is.EqualTo(fuelDocument.FuelCoupons), "Списанное топливо должно совпадать с топливом выданным талонами в документе выдачи"))
            .Release();
        }
Ejemplo n.º 10
0
        public override void UpdateNodes()
        {
            WorkingDriverVMNode resultAlias    = null;
            Employee            driverAlias    = null;
            RouteList           routeListAlias = null;
            Car        carAlias        = null;
            CarVersion carVersionAlias = null;

            Domain.Orders.Order orderAlias        = null;
            OrderItem           ordItemsAlias     = null;
            Nomenclature        nomenclatureAlias = null;

            var completedSubquery = QueryOver.Of <RouteListItem>()
                                    .Where(i => i.RouteList.Id == routeListAlias.Id)
                                    .Where(i => i.Status != RouteListItemStatus.EnRoute)
                                    .Select(Projections.RowCount());

            var addressesSubquery = QueryOver.Of <RouteListItem>()
                                    .Where(i => i.RouteList.Id == routeListAlias.Id)
                                    .Select(Projections.RowCount());

            var uncompletedBottlesSubquery = QueryOver.Of <RouteListItem>()             // Запрашивает количество ещё не доставленных бутылей.
                                             .Where(i => i.RouteList.Id == routeListAlias.Id)
                                             .Where(i => i.Status == RouteListItemStatus.EnRoute)
                                             .JoinAlias(rli => rli.Order, () => orderAlias)
                                             .JoinAlias(() => orderAlias.OrderItems, () => ordItemsAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                             .JoinAlias(() => ordItemsAlias.Nomenclature, () => nomenclatureAlias)
                                             .Where(() => nomenclatureAlias.Category == NomenclatureCategory.water && nomenclatureAlias.TareVolume == TareVolume.Vol19L)
                                             .Select(Projections.Sum(() => ordItemsAlias.Count));

            var trackSubquery = QueryOver.Of <Track>()
                                .Where(x => x.RouteList.Id == routeListAlias.Id)
                                .Select(x => x.Id);

            var isCompanyHavingProjection = Projections.Conditional(
                Restrictions.Eq(Projections.Property(() => carVersionAlias.CarOwnType), CarOwnType.Company),
                Projections.Constant(true),
                Projections.Constant(false));

            #region Water19LReserve

            RouteListItem routeListItemAlias = null;
            RouteListItem transferedToAlias  = null;
            OrderItem     orderItemAlias     = null;
            AdditionalLoadingDocumentItem additionalLoadingDocumentItemAlias = null;
            AdditionalLoadingDocument     additionalLoadingDocumentAlias     = null;

            var ownOrdersSubquery = QueryOver.Of <RouteListItem>(() => routeListItemAlias)
                                    .JoinAlias(() => routeListItemAlias.Order, () => orderAlias)
                                    .JoinEntityAlias(() => orderItemAlias, () => orderItemAlias.Order.Id == orderAlias.Id)
                                    .JoinAlias(() => orderItemAlias.Nomenclature, () => nomenclatureAlias)
                                    .Where(() => !orderAlias.IsFastDelivery && !routeListItemAlias.WasTransfered)
                                    .And(() => nomenclatureAlias.Category == NomenclatureCategory.water &&
                                         nomenclatureAlias.TareVolume == TareVolume.Vol19L)
                                    .And(() => routeListItemAlias.RouteList.Id == routeListAlias.Id)
                                    .Select(Projections.Sum(() => orderItemAlias.Count));

            var additionalBalanceSubquery = QueryOver.Of <AdditionalLoadingDocumentItem>(() => additionalLoadingDocumentItemAlias)
                                            .JoinAlias(() => additionalLoadingDocumentItemAlias.Nomenclature, () => nomenclatureAlias)
                                            .JoinAlias(() => additionalLoadingDocumentItemAlias.AdditionalLoadingDocument, () => additionalLoadingDocumentAlias)
                                            .Where(() => nomenclatureAlias.Category == NomenclatureCategory.water &&
                                                   nomenclatureAlias.TareVolume == TareVolume.Vol19L)
                                            .And(() => routeListAlias.AdditionalLoadingDocument.Id == additionalLoadingDocumentAlias.Id)
                                            .Select(Projections.Sum(() => additionalLoadingDocumentItemAlias.Amount));

            var deliveredOrdersSubquery = QueryOver.Of <RouteListItem>(() => routeListItemAlias)
                                          .JoinAlias(() => routeListItemAlias.Order, () => orderAlias)
                                          .JoinEntityAlias(() => orderItemAlias, () => orderItemAlias.Order.Id == orderAlias.Id)
                                          .JoinAlias(() => orderItemAlias.Nomenclature, () => nomenclatureAlias)
                                          .Left.JoinAlias(() => routeListItemAlias.TransferedTo, () => transferedToAlias)
                                          .Where(() =>
                                                 //не отменённые и не недовозы
                                                 routeListItemAlias.Status != RouteListItemStatus.Canceled && routeListItemAlias.Status != RouteListItemStatus.Overdue
                                                 // и не перенесённые к водителю; либо перенесённые с погрузкой; либо перенесённые и это экспресс-доставка (всегда без погрузки)
                                                 && (!routeListItemAlias.WasTransfered || routeListItemAlias.NeedToReload || orderAlias.IsFastDelivery)
                                                 // и не перенесённые от водителя; либо перенесённые и не нужна погрузка и не экспресс-доставка (остатки по экспресс-доставке не переносятся)
                                                 && (routeListItemAlias.Status != RouteListItemStatus.Transfered || (!transferedToAlias.NeedToReload && !orderAlias.IsFastDelivery)))
                                          .And(() => nomenclatureAlias.Category == NomenclatureCategory.water &&
                                               nomenclatureAlias.TareVolume == TareVolume.Vol19L)
                                          .And(() => routeListItemAlias.RouteList.Id == routeListAlias.Id)
                                          .Select(Projections.Sum(() => orderItemAlias.Count));

            var water19LReserveProjection =
                Projections.Conditional(Restrictions.Eq(Projections.Property(() => routeListAlias.AdditionalLoadingDocument), null),
                                        Projections.Constant(0m),
                                        Projections.SqlFunction(
                                            new SQLFunctionTemplate(NHibernateUtil.Decimal, "IFNULL(?1, 0) + IFNULL(?2, 0) - IFNULL(?3, 0)"),     //
                                            NHibernateUtil.Decimal,
                                            Projections.SubQuery(ownOrdersSubquery),
                                            Projections.SubQuery(additionalBalanceSubquery),
                                            Projections.SubQuery(deliveredOrdersSubquery)));

            #endregion

            var query = UoW.Session.QueryOver <RouteList>(() => routeListAlias);

            if (Filter.IsFastDeliveryOnly)
            {
                query.Where(() => routeListAlias.AdditionalLoadingDocument != null);
            }

            var result = query
                         .JoinAlias(rl => rl.Driver, () => driverAlias)
                         .JoinAlias(rl => rl.Car, () => carAlias)
                         .JoinEntityAlias(() => carVersionAlias,
                                          () => carVersionAlias.Car.Id == carAlias.Id &&
                                          carVersionAlias.StartDate <= routeListAlias.Date &&
                                          (carVersionAlias.EndDate == null || carVersionAlias.EndDate >= routeListAlias.Date))
                         .Where(rl => rl.Status == RouteListStatus.EnRoute)
                         .Where(rl => rl.Driver != null)
                         .Where(rl => rl.Car != null)
                         .SelectList(list => list
                                     .Select(() => driverAlias.Id).WithAlias(() => resultAlias.Id)
                                     .Select(() => driverAlias.Name).WithAlias(() => resultAlias.Name)
                                     .Select(() => driverAlias.LastName).WithAlias(() => resultAlias.LastName)
                                     .Select(() => driverAlias.Patronymic).WithAlias(() => resultAlias.Patronymic)
                                     .Select(() => carAlias.RegistrationNumber).WithAlias(() => resultAlias.CarNumber)
                                     .Select(isCompanyHavingProjection).WithAlias(() => resultAlias.IsVodovozAuto)
                                     .Select(() => routeListAlias.Id).WithAlias(() => resultAlias.RouteListNumber)
                                     .SelectSubQuery(addressesSubquery).WithAlias(() => resultAlias.AddressesAll)
                                     .SelectSubQuery(completedSubquery).WithAlias(() => resultAlias.AddressesCompleted)
                                     .SelectSubQuery(trackSubquery).WithAlias(() => resultAlias.TrackId)
                                     .SelectSubQuery(uncompletedBottlesSubquery).WithAlias(() => resultAlias.BottlesLeft)
                                     .Select(water19LReserveProjection).WithAlias(() => resultAlias.Water19LReserve)
                                     )
                         .TransformUsing(Transformers.AliasToBean <WorkingDriverVMNode>())
                         .List <WorkingDriverVMNode>();

            var summaryResult = new List <WorkingDriverVMNode>();
            int rowNum        = 0;
            foreach (var driver in result.GroupBy(x => x.Id).OrderBy(x => x.First().ShortName))
            {
                var savedRow = driver.First();
                savedRow.RouteListsText     = String.Join("; ", driver.Select(x => x.TrackId != null ? String.Format("<span foreground=\"green\"><b>{0}</b></span>", x.RouteListNumber) : x.RouteListNumber.ToString()));
                savedRow.RouteListsIds      = driver.ToDictionary(x => x.RouteListNumber, x => x.TrackId);
                savedRow.AddressesAll       = driver.Sum(x => x.AddressesAll);
                savedRow.AddressesCompleted = driver.Sum(x => x.AddressesCompleted);
                savedRow.Water19LReserve    = driver.Sum(x => x.Water19LReserve);
                savedRow.RowNumber          = ++rowNum;
                summaryResult.Add(savedRow);
            }

            SetItemsSource(summaryResult);
        }