public async Task Get_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateGarmentExpenditureGoodReturnController();
            var id            = Guid.NewGuid();

            _mockGarmentExpenditureGoodReturnRepository
            .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new List <GarmentExpenditureGoodReturnReadModel>().AsQueryable());

            _mockGarmentExpenditureGoodReturnRepository
            .Setup(s => s.Find(It.IsAny <IQueryable <GarmentExpenditureGoodReturnReadModel> >()))
            .Returns(new List <GarmentExpenditureGoodReturn>()
            {
                new GarmentExpenditureGoodReturn(id, "returNo", "returType", new UnitDepartmentId(1), "unitCode", "unitName", "roNo", "article", new GarmentComodityId(1), "comodityCode", "comodityName", new BuyerId(1), "buyerCode", "buyerName", DateTimeOffset.Now, "invoice", "returDesc")
            });

            GarmentExpenditureGoodReturnItem goodReturnItem = new GarmentExpenditureGoodReturnItem(id, id, id, id, id, new SizeId(1), "sizeName", 1, new UomId(1), "uomUnit", "description", 1, 1);

            _mockGarmentExpenditureGoodReturnItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodReturnItemReadModel>()
            {
                goodReturnItem.GetReadModel()
            }.AsQueryable());

            // Act
            var result = await unitUnderTest.Get(1, 25, "{}", new List <string>(), "", "{}");

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result));
        }
        public void should_success_instantiate()
        {
            Guid id = Guid.NewGuid();
            GarmentExpenditureGoodReturnItem item = new GarmentExpenditureGoodReturnItem(new GarmentExpenditureGoodReturnItemReadModel(id));

            item.Modify();
            Assert.NotNull(item);
        }
Ejemplo n.º 3
0
 public GarmentExpenditureGoodReturnItemDto(GarmentExpenditureGoodReturnItem garmentExpenditureGoodReturnItem)
 {
     Id                    = garmentExpenditureGoodReturnItem.Identity;
     ReturId               = garmentExpenditureGoodReturnItem.ReturId;
     ExpenditureGoodId     = garmentExpenditureGoodReturnItem.ExpenditureGoodId;
     ExpenditureGoodItemId = garmentExpenditureGoodReturnItem.ExpenditureGoodItemId;
     FinishedGoodStockId   = garmentExpenditureGoodReturnItem.FinishedGoodStockId;
     Size                  = new SizeValueObject(garmentExpenditureGoodReturnItem.SizeId.Value, garmentExpenditureGoodReturnItem.SizeName);
     Quantity              = garmentExpenditureGoodReturnItem.Quantity;
     Uom                   = new Uom(garmentExpenditureGoodReturnItem.UomId.Value, garmentExpenditureGoodReturnItem.UomUnit);
     Description           = garmentExpenditureGoodReturnItem.Description;
     BasicPrice            = garmentExpenditureGoodReturnItem.BasicPrice;
     Price                 = garmentExpenditureGoodReturnItem.Price;
 }
Ejemplo n.º 4
0
        public async Task <GarmentExpenditureGoodReturn> Handle(PlaceGarmentExpenditureGoodReturnCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();

            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && a.UnitId == request.Unit.Id && a.ComodityId == request.Comodity.Id).Select(s => new GarmentComodityPrice(s)).Single();

            GarmentExpenditureGoodReturn garmentExpenditureGoodReturn = new GarmentExpenditureGoodReturn(
                Guid.NewGuid(),
                GenerateExpenditureGoodReturnNo(request),
                request.ReturType,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.RONo,
                request.Article,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                new BuyerId(request.Buyer.Id),
                request.Buyer.Code,
                request.Buyer.Name,
                request.ReturDate.GetValueOrDefault(),
                request.Invoice,
                request.ReturDesc
                );

            Dictionary <Guid, double>   finstockQty         = new Dictionary <Guid, double>();
            Dictionary <string, double> finStockToBeUpdated = new Dictionary <string, double>();
            Dictionary <Guid, double>   exGoodToBeUpdated   = new Dictionary <Guid, double>();

            foreach (var item in request.Items)
            {
                if (item.isSave)
                {
                    var    garmentexGood     = _garmentExpenditureGoodRepository.Query.Where(x => x.UnitId == request.Unit.Id && x.RONo == request.RONo).OrderBy(a => a.CreatedDate).ToList();
                    var    garmentexGoodItem = _garmentExpenditureGoodItemRepository.Query.Where(x => x.SizeId == item.Size.Id && x.UomId == item.Uom.Id && (x.Quantity - x.ReturQuantity) > 0 && x.Description == item.Description).OrderBy(a => a.CreatedDate).ToList();
                    var    join = (from a in garmentexGoodItem join b in garmentexGood on a.ExpenditureGoodId equals b.Identity select a).ToList();
                    double qty  = item.Quantity;
                    foreach (var exGood in join)
                    {
                        string key = exGood.FinishedGoodStockId.ToString() + "~" + item.Description;
                        if (qty > 0)
                        {
                            double exGoodQty = exGood.Quantity - exGood.ReturQuantity;
                            double remainQty = exGoodQty - qty;

                            if (!finstockQty.ContainsKey(exGood.FinishedGoodStockId))
                            {
                                finstockQty.Add(exGood.FinishedGoodStockId, 0);
                            }
                            //double stockQty = exGoodQty - qty;
                            if (remainQty < 0)
                            {
                                qty -= exGood.Quantity;
                                exGoodToBeUpdated.Add(exGood.Identity, exGoodQty);
                                finstockQty[exGood.FinishedGoodStockId] += exGoodQty;
                                //finStockToBeUpdated.Add(key, exGoodQty);
                            }
                            else if (remainQty == 0)
                            {
                                exGoodToBeUpdated.Add(exGood.Identity, exGoodQty);
                                finstockQty[exGood.FinishedGoodStockId] += exGoodQty;
                                //finStockToBeUpdated.Add(key, exGoodQty);
                                break;
                            }
                            else if (remainQty > 0)
                            {
                                exGoodToBeUpdated.Add(exGood.Identity, qty);
                                finstockQty[exGood.FinishedGoodStockId] += qty;
                                //finStockToBeUpdated.Add(key, qty);
                                break;
                            }
                        }
                    }
                }
            }

            foreach (var exGood in exGoodToBeUpdated)
            {
                var garmentExpenditureGoodItem = _garmentExpenditureGoodItemRepository.Query.Where(x => x.Identity == exGood.Key).Select(s => new GarmentExpenditureGoodItem(s)).Single();

                //var dup= request.Items.Where(a =>  new SizeId(a.Size.Id) == garmentExpenditureGoodItem.SizeId && new UomId(a.Uom.Id) == garmentExpenditureGoodItem.UomId && a.isSave == true).FirstOrDefault();

                var item = request.Items.Where(a => a.Description.Trim() == garmentExpenditureGoodItem.Description.Trim() && new SizeId(a.Size.Id) == garmentExpenditureGoodItem.SizeId && new UomId(a.Uom.Id) == garmentExpenditureGoodItem.UomId && a.isSave == true).Single();

                var    quantityRetur = garmentExpenditureGoodItem.ReturQuantity + exGood.Value;
                double price         = (garmentExpenditureGoodItem.BasicPrice + ((double)garmentComodityPrice.Price * 1)) * quantityRetur;

                GarmentExpenditureGoodReturnItem garmentExpenditureGoodReturnItem = new GarmentExpenditureGoodReturnItem(
                    Guid.NewGuid(),
                    garmentExpenditureGoodReturn.Identity,
                    garmentExpenditureGoodItem.ExpenditureGoodId,
                    garmentExpenditureGoodItem.Identity,
                    garmentExpenditureGoodItem.FinishedGoodStockId,
                    new SizeId(item.Size.Id),
                    item.Size.Size,
                    exGood.Value,
                    new UomId(item.Uom.Id),
                    item.Uom.Unit,
                    item.Description,
                    garmentExpenditureGoodItem.BasicPrice,
                    price
                    );

                GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(
                    Guid.NewGuid(),
                    item.FinishedGoodStockId,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    garmentExpenditureGoodReturn.Identity,
                    garmentExpenditureGoodReturnItem.Identity,
                    "RETUR",
                    garmentExpenditureGoodReturn.RONo,
                    garmentExpenditureGoodReturn.Article,
                    garmentExpenditureGoodReturn.UnitId,
                    garmentExpenditureGoodReturn.UnitCode,
                    garmentExpenditureGoodReturn.UnitName,
                    garmentExpenditureGoodReturn.ComodityId,
                    garmentExpenditureGoodReturn.ComodityCode,
                    garmentExpenditureGoodReturn.ComodityName,
                    garmentExpenditureGoodReturnItem.SizeId,
                    garmentExpenditureGoodReturnItem.SizeName,
                    garmentExpenditureGoodReturnItem.UomId,
                    garmentExpenditureGoodReturnItem.UomUnit,
                    garmentExpenditureGoodReturnItem.Quantity,
                    garmentExpenditureGoodReturnItem.BasicPrice,
                    garmentExpenditureGoodReturnItem.Price
                    );
                await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);

                await _garmentExpenditureGoodReturnItemRepository.Update(garmentExpenditureGoodReturnItem);

                var qty = garmentExpenditureGoodItem.ReturQuantity + exGood.Value;
                garmentExpenditureGoodItem.SetReturQuantity(qty);
                garmentExpenditureGoodItem.Modify();

                await _garmentExpenditureGoodItemRepository.Update(garmentExpenditureGoodItem);
            }

            foreach (var finStock in finstockQty)
            {
                //var keyString = finStock.Key.Split("~");
                var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == finStock.Key).Select(s => new GarmentFinishedGoodStock(s)).Single();
                var qty = garmentFinishingGoodStockItem.Quantity + finStock.Value;
                garmentFinishingGoodStockItem.SetQuantity(qty);
                garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (qty));
                garmentFinishingGoodStockItem.Modify();

                await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem);
            }

            await _garmentExpenditureGoodReturnRepository.Update(garmentExpenditureGoodReturn);

            _storage.Save();

            return(garmentExpenditureGoodReturn);
        }