Example #1
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.GetDefaultBottleNomenclature(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 #2
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));
        }