Example #1
0
        public void UpdateReturnedOperations_WhenSetAmountOfExistingNomenclatureToZero_ThenDeleteItsSelfDeliveryDocumentReturnedObject()
        {
            // arrange
            //Order order = Substitute.For<Order>();
            Nomenclature nomenclatureMock = Substitute.For <Nomenclature>();

            nomenclatureMock.Id.Returns(19);
            Dictionary <int, decimal> returnedNomenclatures = new Dictionary <int, decimal> {
                { 19, 0 }
            };

            SelfDeliveryDocument selfDelivery = new SelfDeliveryDocument {
                TimeStamp     = new DateTime(2000, 01, 01, 12, 00, 00),
                Order         = Substitute.For <Order>(),
                Warehouse     = Substitute.For <Warehouse>(),
                ReturnedItems = new List <SelfDeliveryDocumentReturned> {
                    new SelfDeliveryDocumentReturned {
                        Amount       = 2,
                        Nomenclature = nomenclatureMock,
                        WarehouseMovementOperation = Substitute.For <WarehouseMovementOperation>()
                    }
                }
            };

            // act
            selfDelivery.UpdateReturnedOperations(Substitute.For <IUnitOfWork>(), returnedNomenclatures);

            // assert
            Assert.That(selfDelivery.ReturnedItems.Count, Is.EqualTo(0));
        }
Example #2
0
        public int GetEmptyBottlesFromClientByOrder(IUnitOfWork uow, INomenclatureRepository nomenclatureRepository, Order order, int?excludeDocument = null)
        {
            if (nomenclatureRepository == null)
            {
                throw new ArgumentNullException(nameof(nomenclatureRepository));
            }

            var routeListItems = uow.Session.QueryOver <RouteListItem>()
                                 .Where(rli => rli.Order == order)
                                 .List();

            if (routeListItems.Any())
            {
                return(routeListItems.Sum(q => q.BottlesReturned));
            }

            var defBottle = nomenclatureRepository.GetDefaultBottle(uow);
            SelfDeliveryDocument selfDeliveryDocumentAlias = null;

            var query = uow.Session.QueryOver <SelfDeliveryDocumentReturned>()
                        .Left.JoinAlias(d => d.Document, () => selfDeliveryDocumentAlias)
                        .Where(() => selfDeliveryDocumentAlias.Order == order)
                        .Where(r => r.Nomenclature == defBottle);

            if (excludeDocument.HasValue && excludeDocument.Value > 0)
            {
                query.Where(() => selfDeliveryDocumentAlias.Id != excludeDocument.Value);
            }

            var bttls = query.Select(Projections.Sum <SelfDeliveryDocumentReturned>(s => s.Amount))
                        .SingleOrDefault <decimal>();

            return((int)bttls);
        }
Example #3
0
        public void UpdateReturnedOperations_WhenAddNewNomenclatureToReturn_CreateNewSelfDeliveryDocumentReturnedAndNewWarehouseMovementOperation()
        {
            // arrange
            Nomenclature nomenclatureMock = Substitute.For <Nomenclature>();

            nomenclatureMock.Id.Returns(15);
            Dictionary <int, decimal> returnedNomenclatures = new Dictionary <int, decimal> {
                { 15, 4 }
            };

            SelfDeliveryDocument selfDelivery = new SelfDeliveryDocument {
                TimeStamp     = new DateTime(2000, 01, 01, 12, 00, 00),
                Order         = Substitute.For <Order>(),
                Warehouse     = Substitute.For <Warehouse>(),
                ReturnedItems = new List <SelfDeliveryDocumentReturned>()
            };

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

            uow.GetById <Nomenclature>(15).Returns(nomenclatureMock);

            // act
            selfDelivery.UpdateReturnedOperations(uow, returnedNomenclatures);

            // assert
            Assert.That(selfDelivery.ReturnedItems.Count, Is.EqualTo(1));
            Assert.That(selfDelivery.ReturnedItems.FirstOrDefault(s => s.Nomenclature == nomenclatureMock).Amount, Is.EqualTo(4));
            Assert.That(selfDelivery.ReturnedItems.FirstOrDefault(s => s.Nomenclature == nomenclatureMock).WarehouseMovementOperation.Amount, Is.EqualTo(4));
        }
Example #4
0
        public void UpdateReturnedOperations_WhenUpdateAmountOfNomenclatures_ThenUpdatesAmountInSelfDeliveryDocumentReturnedAndAmountInWarehouseMovementOperation()
        {
            // arrange
            Nomenclature nomenclatureMock = Substitute.For <Nomenclature>();

            nomenclatureMock.Id.Returns(10);
            Dictionary <int, decimal> returnedNomenclatures = new Dictionary <int, decimal> {
                { 10, 6 }
            };

            SelfDeliveryDocument selfDelivery = new SelfDeliveryDocument {
                TimeStamp     = new DateTime(2000, 01, 01, 12, 00, 00),
                Order         = Substitute.For <Order>(),
                Warehouse     = Substitute.For <Warehouse>(),
                ReturnedItems = new List <SelfDeliveryDocumentReturned> {
                    new SelfDeliveryDocumentReturned {
                        Amount       = 1,
                        Nomenclature = nomenclatureMock,
                        WarehouseMovementOperation = new WarehouseMovementOperation {
                            Amount = 1
                        },
                        CounterpartyMovementOperation = Substitute.For <CounterpartyMovementOperation>()
                    }
                }
            };

            // act
            selfDelivery.UpdateReturnedOperations(Substitute.For <IUnitOfWork>(), returnedNomenclatures);

            // assert
            Assert.That(selfDelivery.ReturnedItems.Count, Is.EqualTo(1));
            Assert.That(selfDelivery.ReturnedItems.FirstOrDefault(s => s.Nomenclature == nomenclatureMock).Amount, Is.EqualTo(6));
            Assert.That(selfDelivery.ReturnedItems.FirstOrDefault(s => s.Nomenclature == nomenclatureMock).WarehouseMovementOperation.Amount, Is.EqualTo(6));
        }
        public Dictionary <int, decimal> OrderNomenclaturesLoaded(IUnitOfWork uow, Order order)
        {
            SelfDeliveryDocument     docAlias      = null;
            SelfDeliveryDocumentItem docItemsAlias = null;

            ItemInStock inLoaded   = null;
            var         loadedlist = uow.Session.QueryOver <SelfDeliveryDocument>(() => docAlias)
                                     .Where(d => d.Order.Id == order.Id)
                                     .JoinAlias(d => d.Items, () => docItemsAlias)
                                     .SelectList(list => list
                                                 .SelectGroup(() => docItemsAlias.Nomenclature.Id).WithAlias(() => inLoaded.Id)
                                                 .SelectSum(() => docItemsAlias.Amount).WithAlias(() => inLoaded.Added)
                                                 ).TransformUsing(Transformers.PassThrough).List <object[]>();
            var result = new Dictionary <int, decimal>();

            foreach (var loadedItem in loadedlist)
            {
                result.Add((int)loadedItem[0], (decimal)loadedItem[1]);
            }
            return(result);
        }
Example #6
0
        public void UpdateReturnedOperations_WhenAddNewNomenclatureToReturnWithZeroAmount_ThenSelfDeliveryDocumentReturnedAndWarehouseMovementOperationWillNotBeCreated()
        {
            // arrange
            Nomenclature nomenclatureMock = Substitute.For <Nomenclature>();

            nomenclatureMock.Id.Returns(33);
            Dictionary <int, decimal> returnedNomenclatures = new Dictionary <int, decimal> {
                { 33, 0 }
            };

            SelfDeliveryDocument selfDelivery = new SelfDeliveryDocument {
                TimeStamp     = new DateTime(2000, 01, 01, 12, 00, 00),
                Order         = Substitute.For <Order>(),
                Warehouse     = Substitute.For <Warehouse>(),
                ReturnedItems = new List <SelfDeliveryDocumentReturned>()
            };

            // act
            selfDelivery.UpdateReturnedOperations(Substitute.For <IUnitOfWork>(), returnedNomenclatures);

            // assert
            Assert.That(selfDelivery.ReturnedItems.Count, Is.EqualTo(0));
        }
Example #7
0
        public override void UpdateNodes()
        {
            IncomingInvoice              invoiceAlias          = null;
            IncomingWater                waterAlias            = null;
            MovementDocument             movementAlias         = null;
            WriteoffDocument             writeoffAlias         = null;
            InventoryDocument            inventoryAlias        = null;
            ShiftChangeWarehouseDocument shiftchangeAlias      = null;
            SelfDeliveryDocument         selfDeliveryAlias     = null;
            RegradingOfGoodsDocument     regradingOfGoodsAlias = null;
            DocumentVMNode               resultAlias           = null;
            Counterparty  counterpartyAlias       = null;
            Counterparty  secondCounterpartyAlias = null;
            Warehouse     warehouseAlias          = null;
            Warehouse     secondWarehouseAlias    = null;
            MovementWagon wagonAlias = null;

            Nomenclature productAlias = null;

            CarLoadDocument   loadCarAlias   = null;
            CarUnloadDocument unloadCarAlias = null;
            RouteList         routeListAlias = null;
            Car      carAlias        = null;
            Employee driverAlias     = null;
            Employee authorAlias     = null;
            Employee lastEditorAlias = null;

            Domain.Orders.Order orderAlias = null;

            List <DocumentVMNode> result = new List <DocumentVMNode> ();

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.IncomingInvoice) && Filter.RestrictDriver == null)
            {
                var invoiceQuery = UoW.Session.QueryOver <IncomingInvoice>(() => invoiceAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    invoiceQuery.Where(x => x.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    invoiceQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    invoiceQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var invoiceList = invoiceQuery.JoinQueryOver(() => invoiceAlias.Contractor, () => counterpartyAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                  .JoinQueryOver(() => invoiceAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                  .JoinAlias(() => invoiceAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                  .JoinAlias(() => invoiceAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                  .SelectList(list => list
                                              .Select(() => invoiceAlias.Id).WithAlias(() => resultAlias.Id)
                                              .Select(() => invoiceAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                              .Select(() => invoiceAlias.Comment).WithAlias(() => resultAlias.Comment)
                                              .Select(() => DocumentType.IncomingInvoice).WithAlias(() => resultAlias.DocTypeEnum)
                                              .Select(Projections.Conditional(
                                                          Restrictions.Where(() => counterpartyAlias.Name == null),
                                                          Projections.Constant("Не указан", NHibernateUtil.String),
                                                          Projections.Property(() => counterpartyAlias.Name)))
                                              .WithAlias(() => resultAlias.Counterparty)
                                              .Select(Projections.Conditional(
                                                          Restrictions.Where(() => warehouseAlias.Name == null),
                                                          Projections.Constant("Не указан", NHibernateUtil.String),
                                                          Projections.Property(() => warehouseAlias.Name)))
                                              .WithAlias(() => resultAlias.Warehouse)
                                              .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                              .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                              .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                              .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                              .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                              .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                              .Select(() => invoiceAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime)
                                              )
                                  .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                  .List <DocumentVMNode> ();

                result.AddRange(invoiceList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.IncomingWater) && Filter.RestrictDriver == null)
            {
                var waterQuery = UoW.Session.QueryOver <IncomingWater>(() => waterAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    waterQuery.Where(x => x.IncomingWarehouse.Id == Filter.RestrictWarehouse.Id || x.WriteOffWarehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    waterQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    waterQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var waterList = waterQuery
                                .JoinQueryOver(() => waterAlias.IncomingWarehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                .JoinAlias(() => waterAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                .JoinAlias(() => waterAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                .Left.JoinAlias(() => waterAlias.Product, () => productAlias)
                                .SelectList(list => list
                                            .Select(() => waterAlias.Id).WithAlias(() => resultAlias.Id)
                                            .Select(() => waterAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                            .Select(() => DocumentType.IncomingWater).WithAlias(() => resultAlias.DocTypeEnum)
                                            .Select(Projections.Conditional(
                                                        Restrictions.Where(() => warehouseAlias.Name == null),
                                                        Projections.Constant("Не указан", NHibernateUtil.String),
                                                        Projections.Property(() => warehouseAlias.Name)))
                                            .WithAlias(() => resultAlias.Warehouse)
                                            .Select(() => productAlias.Name).WithAlias(() => resultAlias.ProductName)
                                            .Select(() => waterAlias.Amount).WithAlias(() => resultAlias.Amount)
                                            .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                            .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                            .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                            .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                            .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                            .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                            .Select(() => waterAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                .List <DocumentVMNode> ();

                result.AddRange(waterList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.MovementDocument) && Filter.RestrictDriver == null)
            {
                var movementQuery = UoW.Session.QueryOver <MovementDocument>(() => movementAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    movementQuery.Where(x => x.FromWarehouse.Id == Filter.RestrictWarehouse.Id || x.ToWarehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    movementQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    movementQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }
                if (Filter.RestrictMovementStatus.HasValue && Filter.RestrictDocumentType == DocumentType.MovementDocument)
                {
                    movementQuery.Where(o => o.Status == Filter.RestrictMovementStatus.Value);
                }

                var movementList = movementQuery
                                   .JoinQueryOver(() => movementAlias.FromWarehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinQueryOver(() => movementAlias.ToWarehouse, () => secondWarehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinAlias(() => movementAlias.MovementWagon, () => wagonAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinAlias(() => movementAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinAlias(() => movementAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .SelectList(list => list
                                               .Select(() => movementAlias.Id).WithAlias(() => resultAlias.Id)
                                               .Select(() => movementAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                               .Select(() => DocumentType.MovementDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                               .Select(() => movementAlias.Status).WithAlias(() => resultAlias.MovementDocumentStatus)
                                               .Select(() => movementAlias.HasDiscrepancy).WithAlias(() => resultAlias.MovementDocumentDiscrepancy)
                                               .Select(() => wagonAlias.Name).WithAlias(() => resultAlias.CarNumber)
                                               .Select(Projections.Conditional(
                                                           Restrictions.Where(() => warehouseAlias.Name == null),
                                                           Projections.Constant("Не указан", NHibernateUtil.String),
                                                           Projections.Property(() => warehouseAlias.Name)))
                                               .WithAlias(() => resultAlias.Warehouse)
                                               .Select(Projections.Conditional(
                                                           Restrictions.Where(() => secondWarehouseAlias.Name == null),
                                                           Projections.Constant("Не указан", NHibernateUtil.String),
                                                           Projections.Property(() => secondWarehouseAlias.Name)))
                                               .WithAlias(() => resultAlias.SecondWarehouse)
                                               .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                               .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                               .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                               .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                               .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                               .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                               .Select(() => movementAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                   .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                   .List <DocumentVMNode> ();

                result.AddRange(movementList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.WriteoffDocument) && Filter.RestrictDriver == null)
            {
                var writeoffQuery = UoW.Session.QueryOver <WriteoffDocument>(() => writeoffAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    writeoffQuery.Where(x => x.WriteoffWarehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    writeoffQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    writeoffQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var writeoffList = writeoffQuery
                                   .JoinQueryOver(() => writeoffAlias.Client, () => counterpartyAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinQueryOver(() => writeoffAlias.WriteoffWarehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinAlias(() => writeoffAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinAlias(() => writeoffAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .SelectList(list => list
                                               .Select(() => writeoffAlias.Id).WithAlias(() => resultAlias.Id)
                                               .Select(() => writeoffAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                               .Select(() => DocumentType.WriteoffDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                               .Select(Projections.Conditional(
                                                           Restrictions.Where(() => counterpartyAlias.Name == null),
                                                           Projections.Constant(string.Empty, NHibernateUtil.String),
                                                           Projections.Property(() => counterpartyAlias.Name)))
                                               .WithAlias(() => resultAlias.Counterparty)
                                               .Select(Projections.Conditional(
                                                           Restrictions.Where(() => warehouseAlias.Name == null),
                                                           Projections.Constant(string.Empty, NHibernateUtil.String),
                                                           Projections.Property(() => warehouseAlias.Name)))
                                               .WithAlias(() => resultAlias.Warehouse)
                                               .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                               .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                               .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                               .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                               .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                               .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                               .Select(() => writeoffAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                   .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                   .List <DocumentVMNode> ();

                result.AddRange(writeoffList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.InventoryDocument) && Filter.RestrictDriver == null)
            {
                var inventoryQuery = UoW.Session.QueryOver <InventoryDocument>(() => inventoryAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    inventoryQuery.Where(x => x.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    inventoryQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    inventoryQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var inventoryList = inventoryQuery
                                    .JoinQueryOver(() => inventoryAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                    .JoinAlias(() => inventoryAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                    .JoinAlias(() => inventoryAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                    .SelectList(list => list
                                                .Select(() => inventoryAlias.Id).WithAlias(() => resultAlias.Id)
                                                .Select(() => inventoryAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                                .Select(() => DocumentType.InventoryDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                                .Select(() => warehouseAlias.Name).WithAlias(() => resultAlias.Warehouse)
                                                .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                                .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                                .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                                .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                                .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                                .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                                .Select(() => inventoryAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                    .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                    .List <DocumentVMNode> ();

                result.AddRange(inventoryList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.ShiftChangeDocument) && Filter.RestrictDriver == null)
            {
                var shiftchangeQuery = UoW.Session.QueryOver <ShiftChangeWarehouseDocument>(() => shiftchangeAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    shiftchangeQuery.Where(x => x.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    shiftchangeQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    shiftchangeQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var shiftchangeList = shiftchangeQuery
                                      .JoinQueryOver(() => shiftchangeAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                      .JoinAlias(() => shiftchangeAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                      .JoinAlias(() => shiftchangeAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                      .SelectList(list => list
                                                  .Select(() => shiftchangeAlias.Id).WithAlias(() => resultAlias.Id)
                                                  .Select(() => shiftchangeAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                                  .Select(() => DocumentType.ShiftChangeDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                                  .Select(() => warehouseAlias.Name).WithAlias(() => resultAlias.Warehouse)
                                                  .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                                  .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                                  .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                                  .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                                  .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                                  .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                                  .Select(() => shiftchangeAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                      .TransformUsing(Transformers.AliasToBean <DocumentVMNode>())
                                      .List <DocumentVMNode>();

                result.AddRange(shiftchangeList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.RegradingOfGoodsDocument) && Filter.RestrictDriver == null)
            {
                var regrandingQuery = UoW.Session.QueryOver <RegradingOfGoodsDocument>(() => regradingOfGoodsAlias);
                if (Filter.RestrictWarehouse != null)
                {
                    regrandingQuery.Where(x => x.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    regrandingQuery.Where(o => o.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    regrandingQuery.Where(o => o.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var regrandingList = regrandingQuery
                                     .JoinQueryOver(() => regradingOfGoodsAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                     .JoinAlias(() => regradingOfGoodsAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                     .JoinAlias(() => regradingOfGoodsAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                     .SelectList(list => list
                                                 .Select(() => regradingOfGoodsAlias.Id).WithAlias(() => resultAlias.Id)
                                                 .Select(() => regradingOfGoodsAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                                 .Select(() => DocumentType.RegradingOfGoodsDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                                 .Select(() => warehouseAlias.Name).WithAlias(() => resultAlias.Warehouse)
                                                 .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                                 .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                                 .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                                 .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                                 .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                                 .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                                 .Select(() => regradingOfGoodsAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                     .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                     .List <DocumentVMNode> ();

                result.AddRange(regrandingList);
            }

            if ((Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.SelfDeliveryDocument) && Filter.RestrictDriver == null)
            {
                var selfDeliveryQuery = UoW.Session.QueryOver <SelfDeliveryDocument>(() => selfDeliveryAlias)
                                        .JoinQueryOver(() => selfDeliveryAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                        .JoinQueryOver(() => selfDeliveryAlias.Order, () => orderAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                        .JoinQueryOver(() => orderAlias.Client, () => counterpartyAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin);

                if (Filter.RestrictWarehouse != null)
                {
                    selfDeliveryQuery.Where(() => selfDeliveryAlias.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    selfDeliveryQuery.Where(() => selfDeliveryAlias.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    selfDeliveryQuery.Where(() => selfDeliveryAlias.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }

                var selfDeliveryList = selfDeliveryQuery
                                       .JoinAlias(() => selfDeliveryAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                       .JoinAlias(() => selfDeliveryAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                       .SelectList(list => list
                                                   .Select(() => selfDeliveryAlias.Id).WithAlias(() => resultAlias.Id)
                                                   .Select(() => orderAlias.Id).WithAlias(() => resultAlias.OrderId)
                                                   .Select(() => selfDeliveryAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                                   .Select(() => DocumentType.SelfDeliveryDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                                   .Select(() => counterpartyAlias.Name).WithAlias(() => resultAlias.Counterparty)
                                                   .Select(() => warehouseAlias.Name).WithAlias(() => resultAlias.Warehouse)
                                                   .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                                   .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                                   .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                                   .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                                   .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                                   .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                                   .Select(() => selfDeliveryAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                       .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                       .List <DocumentVMNode> ();

                result.AddRange(selfDeliveryList);
            }

            if (Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.CarLoadDocument)
            {
                var carLoadQuery = UoW.Session.QueryOver <CarLoadDocument>(() => loadCarAlias)
                                   .JoinQueryOver(() => loadCarAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinQueryOver(() => loadCarAlias.RouteList, () => routeListAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinQueryOver(() => routeListAlias.Car, () => carAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                   .JoinQueryOver(() => routeListAlias.Driver, () => driverAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin);

                if (Filter.RestrictWarehouse != null)
                {
                    carLoadQuery.Where(() => loadCarAlias.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    carLoadQuery.Where(() => loadCarAlias.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    carLoadQuery.Where(() => loadCarAlias.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }
                if (Filter.RestrictDriver != null)
                {
                    carLoadQuery.Where(() => routeListAlias.Driver.Id == Filter.RestrictDriver.Id);
                }

                var carLoadList = carLoadQuery
                                  .JoinAlias(() => loadCarAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                  .JoinAlias(() => loadCarAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                  .SelectList(list => list
                                              .Select(() => loadCarAlias.Id).WithAlias(() => resultAlias.Id)
                                              .Select(() => loadCarAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                              .Select(() => DocumentType.CarLoadDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                              .Select(() => carAlias.Model).WithAlias(() => resultAlias.CarModel)
                                              .Select(() => carAlias.RegistrationNumber).WithAlias(() => resultAlias.CarNumber)
                                              .Select(() => driverAlias.LastName).WithAlias(() => resultAlias.DirverSurname)
                                              .Select(() => driverAlias.Name).WithAlias(() => resultAlias.DirverName)
                                              .Select(() => driverAlias.Patronymic).WithAlias(() => resultAlias.DirverPatronymic)
                                              .Select(() => warehouseAlias.Name).WithAlias(() => resultAlias.Warehouse)
                                              .Select(() => routeListAlias.Id).WithAlias(() => resultAlias.RouteListId)
                                              .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                              .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                              .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                              .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                              .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                              .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                              .Select(() => loadCarAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                  .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                  .List <DocumentVMNode> ();

                result.AddRange(carLoadList);
            }

            if (Filter.RestrictDocumentType == null || Filter.RestrictDocumentType == DocumentType.CarUnloadDocument)
            {
                var carUnloadQuery = UoW.Session.QueryOver <CarUnloadDocument>(() => unloadCarAlias)
                                     .JoinQueryOver(() => unloadCarAlias.Warehouse, () => warehouseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                     .JoinQueryOver(() => unloadCarAlias.RouteList, () => routeListAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                     .JoinQueryOver(() => routeListAlias.Car, () => carAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                     .JoinQueryOver(() => routeListAlias.Driver, () => driverAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin);

                if (Filter.RestrictWarehouse != null)
                {
                    carUnloadQuery.Where(() => unloadCarAlias.Warehouse.Id == Filter.RestrictWarehouse.Id);
                }
                if (Filter.RestrictStartDate.HasValue)
                {
                    carUnloadQuery.Where(() => unloadCarAlias.TimeStamp >= Filter.RestrictStartDate.Value);
                }
                if (Filter.RestrictEndDate.HasValue)
                {
                    carUnloadQuery.Where(() => unloadCarAlias.TimeStamp < Filter.RestrictEndDate.Value.AddDays(1));
                }
                if (Filter.RestrictDriver != null)
                {
                    carUnloadQuery.Where(() => routeListAlias.Driver.Id == Filter.RestrictDriver.Id);
                }

                var carUnloadList = carUnloadQuery
                                    .JoinAlias(() => unloadCarAlias.Author, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                    .JoinAlias(() => unloadCarAlias.LastEditor, () => lastEditorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                                    .SelectList(list => list
                                                .Select(() => unloadCarAlias.Id).WithAlias(() => resultAlias.Id)
                                                .Select(() => unloadCarAlias.TimeStamp).WithAlias(() => resultAlias.Date)
                                                .Select(() => DocumentType.CarUnloadDocument).WithAlias(() => resultAlias.DocTypeEnum)
                                                .Select(() => carAlias.Model).WithAlias(() => resultAlias.CarModel)
                                                .Select(() => carAlias.RegistrationNumber).WithAlias(() => resultAlias.CarNumber)
                                                .Select(() => driverAlias.LastName).WithAlias(() => resultAlias.DirverSurname)
                                                .Select(() => driverAlias.Name).WithAlias(() => resultAlias.DirverName)
                                                .Select(() => driverAlias.Patronymic).WithAlias(() => resultAlias.DirverPatronymic)
                                                .Select(() => warehouseAlias.Name).WithAlias(() => resultAlias.Warehouse)
                                                .Select(() => routeListAlias.Id).WithAlias(() => resultAlias.RouteListId)
                                                .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname)
                                                .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName)
                                                .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic)
                                                .Select(() => lastEditorAlias.LastName).WithAlias(() => resultAlias.LastEditorSurname)
                                                .Select(() => lastEditorAlias.Name).WithAlias(() => resultAlias.LastEditorName)
                                                .Select(() => lastEditorAlias.Patronymic).WithAlias(() => resultAlias.LastEditorPatronymic)
                                                .Select(() => unloadCarAlias.LastEditedTime).WithAlias(() => resultAlias.LastEditedTime))
                                    .TransformUsing(Transformers.AliasToBean <DocumentVMNode> ())
                                    .List <DocumentVMNode> ();

                result.AddRange(carUnloadList);
            }

            result.Sort((x, y) => {
                if (x.Date < y.Date)
                {
                    return(1);
                }
                if (x.Date == y.Date)
                {
                    return(0);
                }
                return(-1);
            });

            SetItemsSource(result);
        }
 public static Dictionary <int, decimal> OrderNomenclaturesUnloaded(IUnitOfWork uow, Order order, SelfDeliveryDocument notSavedDoc = null)
 {
     return(new EntityRepositories.Store.SelfDeliveryRepository().OrderNomenclaturesUnloaded(uow, order, notSavedDoc));
 }
 public static Dictionary <int, decimal> NomenclatureUnloaded(IUnitOfWork uow, Order order, SelfDeliveryDocument excludeDoc)
 {
     return(new EntityRepositories.Store.SelfDeliveryRepository().NomenclatureUnloaded(uow, order, excludeDoc));
 }
Example #10
0
        public void UpdateReceptions_WhenShipWaterFirstThenGoodsWithTwoDifferentSelfDeliveryDocuments_BottlesCountWillNotBeSetToZeroInBottleMovementOperation()
        {
            // arrange
            Order order = new Order {
                ReturnedTare = 1
            };
            Nomenclature nomenclatureMock = Substitute.For <Nomenclature>();

            nomenclatureMock.Id.Returns(99);
            Warehouse warehouseMock01 = Substitute.For <Warehouse>();

            warehouseMock01.CanReceiveBottles.Returns(true);
            warehouseMock01.CanReceiveEquipment.Returns(false);
            Warehouse warehouseMock02 = Substitute.For <Warehouse>();

            warehouseMock02.CanReceiveBottles.Returns(false);
            warehouseMock02.CanReceiveEquipment.Returns(true);

            SelfDeliveryDocument selfDelivery01 = new SelfDeliveryDocument {
                TimeStamp     = new DateTime(2000, 01, 01, 12, 00, 00),
                Order         = order,
                Warehouse     = warehouseMock01,
                ReturnedItems = new List <SelfDeliveryDocumentReturned> {
                    new SelfDeliveryDocumentReturned {
                        Amount       = 1,
                        Nomenclature = nomenclatureMock,
                        WarehouseMovementOperation    = Substitute.For <WarehouseMovementOperation>(),
                        CounterpartyMovementOperation = Substitute.For <CounterpartyMovementOperation>()
                    },
                    Substitute.For <SelfDeliveryDocumentReturned>()
                }
            };

            SelfDeliveryDocument selfDelivery02 = new SelfDeliveryDocument {
                TimeStamp     = new DateTime(2000, 01, 01, 12, 10, 00),
                Order         = order,
                Warehouse     = warehouseMock02,
                ReturnedItems = new List <SelfDeliveryDocumentReturned> {
                    new SelfDeliveryDocumentReturned {
                        Amount       = 0,
                        Nomenclature = nomenclatureMock,
                        WarehouseMovementOperation = Substitute.For <WarehouseMovementOperation>()
                    },
                    new SelfDeliveryDocumentReturned {
                        Amount       = 0,
                        Nomenclature = Substitute.For <Nomenclature>(),
                        WarehouseMovementOperation = Substitute.For <WarehouseMovementOperation>()
                    }
                }
            };

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

            uow.GetById <Nomenclature>(112).Returns(Substitute.For <Nomenclature>());
            uow.GetById <Nomenclature>(99).Returns(nomenclatureMock);

            INomenclatureRepository nomenclatureRepository = Substitute.For <INomenclatureRepository>();

            nomenclatureRepository.GetDefaultBottleNomenclature(uow).Returns(nomenclatureMock);

            IBottlesRepository bottlesRepository = Substitute.For <IBottlesRepository>();

            bottlesRepository.GetEmptyBottlesFromClientByOrder(uow, nomenclatureRepository, order, 1).ReturnsForAnyArgs(order.ReturnedTare.Value);

            // act
            selfDelivery01.TareToReturn = 2;
            selfDelivery01.InitializeDefaultValues(uow, nomenclatureRepository);
            selfDelivery01.UpdateReceptions(
                uow,
                new List <GoodsReceptionVMNode>(),
                nomenclatureRepository,
                bottlesRepository
                );

            selfDelivery02.InitializeDefaultValues(uow, nomenclatureRepository);
            selfDelivery02.UpdateReceptions(
                uow,
                new List <GoodsReceptionVMNode> {
                new GoodsReceptionVMNode {
                    Amount         = 1,
                    NomenclatureId = 112,
                    Category       = NomenclatureCategory.equipment
                }
            },
                nomenclatureRepository,
                bottlesRepository
                );

            // assert
            Assert.That(order.ReturnedTare, Is.EqualTo(3));
        }
        public Dictionary <int, decimal> OrderNomenclaturesUnloaded(IUnitOfWork uow, Order order, SelfDeliveryDocument notSavedDoc = null)
        {
            SelfDeliveryDocumentItem docItemsAlias = null;
            ItemInStock inUnload = null;

            var unloadedQuery = uow.Session.QueryOver <SelfDeliveryDocument>()
                                .JoinAlias(d => d.Items, () => docItemsAlias)
                                .Where(d => d.Order.Id == order.Id);

            var unloadedDict = unloadedQuery.SelectList(list => list
                                                        .SelectGroup(() => docItemsAlias.Nomenclature.Id).WithAlias(() => inUnload.Id)
                                                        .SelectSum(() => docItemsAlias.Amount).WithAlias(() => inUnload.Added)
                                                        )
                               .TransformUsing(Transformers.PassThrough)
                               .List <object[]>()
                               .GroupBy(o => (int)o[0], o => (decimal)o[1])
                               .ToDictionary(g => g.Key, g => g.Sum());

            if (notSavedDoc != null && notSavedDoc.Id <= 0)
            {
                foreach (var i in notSavedDoc.Items)
                {
                    if (unloadedDict.ContainsKey(i.Nomenclature.Id))
                    {
                        unloadedDict[i.Nomenclature.Id] += i.Amount;
                    }
                    else
                    {
                        unloadedDict.Add(i.Nomenclature.Id, i.Amount);
                    }
                }
            }

            return(unloadedDict);
        }