Example #1
0
 public GarmentComodityPriceDto(GarmentComodityPrice garmentComodityPrice)
 {
     Id       = garmentComodityPrice.Identity;
     Comodity = new GarmentComodity(garmentComodityPrice.ComodityId.Value, garmentComodityPrice.ComodityCode, garmentComodityPrice.ComodityName);
     IsValid  = garmentComodityPrice.IsValid;
     Unit     = new UnitDepartment(garmentComodityPrice.UnitId.Value, garmentComodityPrice.UnitCode, garmentComodityPrice.UnitName);
     Date     = garmentComodityPrice.Date;
     Price    = garmentComodityPrice.Price;
 }
Example #2
0
        public async Task <GarmentExpenditureGood> Handle(RemoveGarmentExpenditureGoodCommand request, CancellationToken cancellationToken)
        {
            var ExpenditureGood = _garmentExpenditureGoodRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentExpenditureGood(o)).Single();
            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && new UnitDepartmentId(a.UnitId) == ExpenditureGood.UnitId && new GarmentComodityId(a.ComodityId) == ExpenditureGood.ComodityId).Select(s => new GarmentComodityPrice(s)).Single();

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

            _garmentExpenditureGoodItemRepository.Find(o => o.ExpenditureGoodId == ExpenditureGood.Identity).ForEach(async expenditureItem =>
            {
                if (finStockToBeUpdated.ContainsKey(expenditureItem.FinishedGoodStockId))
                {
                    finStockToBeUpdated[expenditureItem.FinishedGoodStockId] += expenditureItem.Quantity;
                }
                else
                {
                    finStockToBeUpdated.Add(expenditureItem.FinishedGoodStockId, expenditureItem.Quantity);
                }

                GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(a => a.ExpenditureGoodItemId == expenditureItem.Identity).Select(a => new GarmentFinishedGoodStockHistory(a)).Single();
                garmentFinishedGoodStockHistory.Remove();
                await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);

                expenditureItem.Remove();
                await _garmentExpenditureGoodItemRepository.Update(expenditureItem);
            });

            foreach (var finStock in finStockToBeUpdated)
            {
                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);
            }

            ExpenditureGood.Remove();
            await _garmentExpenditureGoodRepository.Update(ExpenditureGood);

            _storage.Save();

            return(ExpenditureGood);
        }
Example #3
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid id = Guid.NewGuid();
            UpdateGarmentComodityPriceCommandHandler unitUnderTest = CreateUpdateGarmentComodityPriceCommandHandler();
            CancellationToken cancellationToken       = CancellationToken.None;
            UpdateGarmentComodityPriceCommand request = new UpdateGarmentComodityPriceCommand()
            {
                Unit = new UnitDepartment()
                {
                    Id   = 1,
                    Code = "Code",
                    Name = "Name"
                },
                Date  = DateTimeOffset.Now,
                Items = new List <GarmentComodityPriceItemValueObject>()
                {
                    new GarmentComodityPriceItemValueObject()
                    {
                        Id       = id,
                        IsValid  = true,
                        Comodity = new GarmentComodity()
                        {
                            Id   = 1,
                            Code = "Code",
                            Name = "Name"
                        },
                        Date     = DateTimeOffset.Now,
                        NewPrice = 2,
                        Price    = 2,
                        Unit     = new UnitDepartment()
                        {
                            Id   = 1,
                            Code = "Code",
                            Name = "Name"
                        }
                    }
                }
            };

            request.SetIdentity(id);

            GarmentComodityPrice garmentComodityPrice = new GarmentComodityPrice(id, true, DateTimeOffset.Now, new UnitDepartmentId(1), "unitCode", "unitName", new GarmentComodityId(1), "comodityCode", "comodityName", 1);

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>()
            {
                garmentComodityPrice.GetReadModel()
            }.AsQueryable());

            _mockComodityPriceRepository
            .Setup(s => s.Update(It.IsAny <GarmentComodityPrice>()))
            .Returns(Task.FromResult(It.IsAny <GarmentComodityPrice>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(request, cancellationToken);

            // Assert
            result.Should().NotBeNull();
            result.Count().Should().BeGreaterThan(0);
        }
Example #4
0
        public async Task <GarmentSewingOut> Handle(PlaceGarmentSewingOutCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true).ToList();

            Guid   sewingOutId = Guid.NewGuid();
            string sewingOutNo = GenerateSewOutNo(request);


            GarmentSewingOut garmentSewingOut = new GarmentSewingOut(
                sewingOutId,
                sewingOutNo,
                new BuyerId(request.Buyer.Id),
                request.Buyer.Code,
                request.Buyer.Name,
                new UnitDepartmentId(request.UnitTo.Id),
                request.UnitTo.Code,
                request.UnitTo.Name,
                request.SewingTo,
                request.SewingOutDate.GetValueOrDefault(),
                request.RONo,
                request.Article,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                request.IsDifferentSize
                );

            Dictionary <Guid, double> sewingInItemToBeUpdated = new Dictionary <Guid, double>();

            foreach (var item in request.Items)
            {
                if (item.IsSave)
                {
                    GarmentSewingOutItem garmentSewingOutItem = new GarmentSewingOutItem(
                        Guid.NewGuid(),
                        garmentSewingOut.Identity,
                        item.SewingInId,
                        item.SewingInItemId,
                        new ProductId(item.Product.Id),
                        item.Product.Code,
                        item.Product.Name,
                        item.DesignColor,
                        new SizeId(item.Size.Id),
                        item.Size.Size,
                        request.IsDifferentSize? item.TotalQuantity : item.Quantity,
                        new UomId(item.Uom.Id),
                        item.Uom.Unit,
                        item.Color,
                        request.IsDifferentSize ? item.TotalQuantity : item.Quantity,
                        item.BasicPrice,
                        item.Price
                        );
                    item.Id = garmentSewingOutItem.Identity;
                    if (request.IsDifferentSize)
                    {
                        foreach (var detail in item.Details)
                        {
                            GarmentSewingOutDetail garmentSewingOutDetail = new GarmentSewingOutDetail(
                                Guid.NewGuid(),
                                garmentSewingOutItem.Identity,
                                new SizeId(detail.Size.Id),
                                detail.Size.Size,
                                detail.Quantity,
                                new UomId(detail.Uom.Id),
                                detail.Uom.Unit
                                );
                            detail.Id = garmentSewingOutDetail.Identity;
                            if (sewingInItemToBeUpdated.ContainsKey(item.SewingInItemId))
                            {
                                sewingInItemToBeUpdated[item.SewingInItemId] += detail.Quantity;
                            }
                            else
                            {
                                sewingInItemToBeUpdated.Add(item.SewingInItemId, detail.Quantity);
                            }

                            await _garmentSewingOutDetailRepository.Update(garmentSewingOutDetail);
                        }
                    }
                    else
                    {
                        if (sewingInItemToBeUpdated.ContainsKey(item.SewingInItemId))
                        {
                            sewingInItemToBeUpdated[item.SewingInItemId] += item.Quantity;
                        }
                        else
                        {
                            sewingInItemToBeUpdated.Add(item.SewingInItemId, item.Quantity);
                        }
                    }



                    await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
                }
            }

            foreach (var sewInItem in sewingInItemToBeUpdated)
            {
                var garmentSewingInItem = _garmentSewingInItemRepository.Query.Where(x => x.Identity == sewInItem.Key).Select(s => new GarmentSewingInItem(s)).Single();
                garmentSewingInItem.SetRemainingQuantity(garmentSewingInItem.RemainingQuantity - sewInItem.Value);
                garmentSewingInItem.Modify();

                await _garmentSewingInItemRepository.Update(garmentSewingInItem);
            }


            await _garmentSewingOutRepository.Update(garmentSewingOut);

            #region CreateCuttingIn

            if (request.SewingTo == "CUTTING")
            {
                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();

                var now   = DateTime.Now;
                var year  = now.ToString("yy");
                var month = now.ToString("MM");

                var prefix = $"DC{request.UnitTo.Code.Trim()}{year}{month}";

                var lastCutInNo = _garmentCuttingInRepository.Query.Where(w => w.CutInNo.StartsWith(prefix))
                                  .OrderByDescending(o => o.CutInNo)
                                  .Select(s => int.Parse(s.CutInNo.Replace(prefix, "")))
                                  .FirstOrDefault();
                var CutInNo = $"{prefix}{(lastCutInNo + 1).ToString("D4")}";

                GarmentCuttingIn garmentCuttingIn = new GarmentCuttingIn(
                    Guid.NewGuid(),
                    CutInNo,
                    null,
                    "SEWING",
                    request.RONo,
                    request.Article,
                    new UnitDepartmentId(request.UnitTo.Id),
                    request.UnitTo.Code,
                    request.UnitTo.Name,
                    request.SewingOutDate.GetValueOrDefault(),
                    0
                    );

                foreach (var item in request.Items)
                {
                    if (item.IsSave)
                    {
                        GarmentCuttingInItem garmentCuttingInItem = new GarmentCuttingInItem(
                            Guid.NewGuid(),
                            garmentCuttingIn.Identity,
                            Guid.Empty,
                            0,
                            null,
                            sewingOutId,
                            sewingOutNo
                            );

                        if (request.IsDifferentSize)
                        {
                            foreach (var detail in item.Details)
                            {
                                GarmentCuttingInDetail garmentCuttingInDetail = new GarmentCuttingInDetail(
                                    Guid.NewGuid(),
                                    garmentCuttingInItem.Identity,
                                    Guid.Empty,
                                    item.Id,
                                    detail.Id,
                                    new ProductId(item.Product.Id),
                                    item.Product.Code,
                                    item.Product.Name,
                                    item.DesignColor,
                                    null,
                                    0,
                                    new UomId(0),
                                    null,
                                    Convert.ToInt32(detail.Quantity),
                                    new UomId(detail.Uom.Id),
                                    detail.Uom.Unit,
                                    detail.Quantity,
                                    item.BasicPrice,
                                    (item.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * detail.Quantity,
                                    0,
                                    item.Color
                                    );

                                await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail);
                            }
                        }
                        else
                        {
                            GarmentCuttingInDetail garmentCuttingInDetail = new GarmentCuttingInDetail(
                                Guid.NewGuid(),
                                garmentCuttingInItem.Identity,
                                Guid.Empty,
                                item.Id,
                                Guid.Empty,
                                new ProductId(item.Product.Id),
                                item.Product.Code,
                                item.Product.Name,
                                item.DesignColor,
                                null,
                                0,
                                new UomId(0),
                                null,
                                Convert.ToInt32(item.Quantity),
                                new UomId(item.Uom.Id),
                                item.Uom.Unit,
                                item.Quantity,
                                item.BasicPrice,
                                (item.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * item.Quantity,
                                0,
                                item.Color
                                );
                            await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail);
                        }

                        await _garmentCuttingInItemRepository.Update(garmentCuttingInItem);
                    }
                }

                await _garmentCuttingInRepository.Update(garmentCuttingIn);
            }

            #endregion

            _storage.Save();

            return(garmentSewingOut);
        }
Example #5
0
        public async Task <GarmentFinishingOut> Handle(RemoveGarmentFinishingOutCommand request, CancellationToken cancellationToken)
        {
            var finishOut = _garmentFinishingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentFinishingOut(o)).Single();

            Dictionary <Guid, double> finishingInItemToBeUpdated  = new Dictionary <Guid, double>();
            Dictionary <GarmentFinishedGoodStock, double> finGood = new Dictionary <GarmentFinishedGoodStock, double>();

            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && new UnitDepartmentId(a.UnitId) == finishOut.UnitToId && new GarmentComodityId(a.ComodityId) == finishOut.ComodityId).Select(s => new GarmentComodityPrice(s)).Single();

            _garmentFinishingOutItemRepository.Find(o => o.FinishingOutId == finishOut.Identity).ForEach(async finishOutItem =>
            {
                if (finishOut.IsDifferentSize)
                {
                    _garmentFinishingOutDetailRepository.Find(o => o.FinishingOutItemId == finishOutItem.Identity).ForEach(async finishOutDetail =>
                    {
                        if (finishingInItemToBeUpdated.ContainsKey(finishOutItem.FinishingInItemId))
                        {
                            finishingInItemToBeUpdated[finishOutItem.FinishingInItemId] += finishOutDetail.Quantity;
                        }
                        else
                        {
                            finishingInItemToBeUpdated.Add(finishOutItem.FinishingInItemId, finishOutDetail.Quantity);
                        }

                        if (finishOut.FinishingTo == "GUDANG JADI")
                        {
                            var garmentFinishedGoodExist = _garmentFinishedGoodStockRepository.Query.Where(
                                a => a.RONo == finishOut.RONo &&
                                a.Article == finishOut.Article &&
                                a.BasicPrice == finishOutItem.BasicPrice &&
                                new UnitDepartmentId(a.UnitId) == finishOut.UnitToId &&
                                new SizeId(a.SizeId) == finishOutDetail.SizeId &&
                                new GarmentComodityId(a.ComodityId) == finishOut.ComodityId &&
                                new UomId(a.UomId) == finishOutDetail.UomId
                                ).Select(s => new GarmentFinishedGoodStock(s)).Single();

                            if (finGood.ContainsKey(garmentFinishedGoodExist))
                            {
                                finGood[garmentFinishedGoodExist] += finishOutDetail.Quantity;
                            }
                            else
                            {
                                finGood.Add(garmentFinishedGoodExist, finishOutDetail.Quantity);
                            }

                            GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(a => a.FinishingOutDetailId == finishOutDetail.Identity).Select(a => new GarmentFinishedGoodStockHistory(a)).Single();
                            garmentFinishedGoodStockHistory.Remove();
                            await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);
                        }

                        finishOutDetail.Remove();
                        await _garmentFinishingOutDetailRepository.Update(finishOutDetail);
                    });
                }
                else
                {
                    if (finishingInItemToBeUpdated.ContainsKey(finishOutItem.FinishingInItemId))
                    {
                        finishingInItemToBeUpdated[finishOutItem.FinishingInItemId] += finishOutItem.Quantity;
                    }
                    else
                    {
                        finishingInItemToBeUpdated.Add(finishOutItem.FinishingInItemId, finishOutItem.Quantity);
                    }

                    if (finishOut.FinishingTo == "GUDANG JADI")
                    {
                        var garmentFinishedGoodExist = _garmentFinishedGoodStockRepository.Query.Where(
                            a => a.RONo == finishOut.RONo &&
                            a.Article == finishOut.Article &&
                            a.BasicPrice == finishOutItem.BasicPrice &&
                            new UnitDepartmentId(a.UnitId) == finishOut.UnitToId &&
                            new SizeId(a.SizeId) == finishOutItem.SizeId &&
                            new GarmentComodityId(a.ComodityId) == finishOut.ComodityId &&
                            new UomId(a.UomId) == finishOutItem.UomId
                            ).Select(s => new GarmentFinishedGoodStock(s)).Single();

                        if (finGood.ContainsKey(garmentFinishedGoodExist))
                        {
                            finGood[garmentFinishedGoodExist] += finishOutItem.Quantity;
                        }
                        else
                        {
                            finGood.Add(garmentFinishedGoodExist, finishOutItem.Quantity);
                        }
                        GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(a => a.FinishingOutItemId == finishOutItem.Identity).Select(a => new GarmentFinishedGoodStockHistory(a)).Single();
                        garmentFinishedGoodStockHistory.Remove();

                        await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);
                    }
                }


                finishOutItem.Remove();
                await _garmentFinishingOutItemRepository.Update(finishOutItem);
            });

            foreach (var finInItem in finishingInItemToBeUpdated)
            {
                var garmentSewInItem = _garmentFinishingInItemRepository.Query.Where(x => x.Identity == finInItem.Key).Select(s => new GarmentFinishingInItem(s)).Single();
                garmentSewInItem.SetRemainingQuantity(garmentSewInItem.RemainingQuantity + finInItem.Value);
                garmentSewInItem.Modify();
                await _garmentFinishingInItemRepository.Update(garmentSewInItem);
            }
            if (finishOut.FinishingTo == "GUDANG JADI")
            {
                foreach (var finGoodStock in finGood)
                {
                    var garmentFinishedGoodExist = _garmentFinishedGoodStockRepository.Query.Where(
                        a => a.Identity == finGoodStock.Key.Identity
                        ).Select(s => new GarmentFinishedGoodStock(s)).Single();

                    var qty = garmentFinishedGoodExist.Quantity - finGoodStock.Value;

                    garmentFinishedGoodExist.SetQuantity(qty);
                    garmentFinishedGoodExist.SetPrice((garmentFinishedGoodExist.BasicPrice + (double)garmentComodityPrice.Price) * (qty));
                    garmentFinishedGoodExist.Modify();

                    await _garmentFinishedGoodStockRepository.Update(garmentFinishedGoodExist);
                }
            }


            finishOut.Remove();
            await _garmentFinishingOutRepository.Update(finishOut);

            _storage.Save();

            return(finishOut);
        }
Example #6
0
        public async Task <GarmentCuttingOut> Handle(PlaceGarmentCuttingOutCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true && item.Details.Count() > 0).ToList();

            GarmentCuttingOut garmentCuttingOut = new GarmentCuttingOut(
                Guid.NewGuid(),
                GenerateCutOutNo(request),
                request.CuttingOutType,
                new UnitDepartmentId(request.UnitFrom.Id),
                request.UnitFrom.Code,
                request.UnitFrom.Name,
                request.CuttingOutDate.GetValueOrDefault(),
                request.RONo,
                request.Article,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name
                );

            GarmentSewingDO garmentSewingDO = new GarmentSewingDO(
                Guid.NewGuid(),
                GenerateSewingDONo(request),
                garmentCuttingOut.Identity,
                new UnitDepartmentId(request.UnitFrom.Id),
                request.UnitFrom.Code,
                request.UnitFrom.Name,
                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,
                request.CuttingOutDate.GetValueOrDefault()
                );

            Dictionary <Guid, double> cuttingInDetailToBeUpdated = new Dictionary <Guid, double>();

            foreach (var item in request.Items)
            {
                GarmentCuttingOutItem garmentCuttingOutItem = new GarmentCuttingOutItem(
                    Guid.NewGuid(),
                    item.CuttingInId,
                    item.CuttingInDetailId,
                    garmentCuttingOut.Identity,
                    new ProductId(item.Product.Id),
                    item.Product.Code,
                    item.Product.Name,
                    item.DesignColor,
                    item.TotalCuttingOutQuantity
                    );

                foreach (var detail in item.Details)
                {
                    GarmentCuttingOutDetail garmentCuttingOutDetail = new GarmentCuttingOutDetail(
                        Guid.NewGuid(),
                        garmentCuttingOutItem.Identity,
                        new SizeId(detail.Size.Id),
                        detail.Size.Size,
                        detail.Color.ToUpper(),
                        0,
                        detail.CuttingOutQuantity,
                        new UomId(detail.CuttingOutUom.Id),
                        detail.CuttingOutUom.Unit,
                        detail.BasicPrice,
                        detail.Price
                        );

                    if (cuttingInDetailToBeUpdated.ContainsKey(item.CuttingInDetailId))
                    {
                        cuttingInDetailToBeUpdated[item.CuttingInDetailId] += detail.CuttingOutQuantity;
                    }
                    else
                    {
                        cuttingInDetailToBeUpdated.Add(item.CuttingInDetailId, detail.CuttingOutQuantity);
                    }

                    await _garmentCuttingOutDetailRepository.Update(garmentCuttingOutDetail);

                    GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && a.UnitId == request.Unit.Id && a.ComodityId == request.Comodity.Id).OrderBy(o => o.ModifiedDate).Select(s => new GarmentComodityPrice(s)).Last();
                    double price = (detail.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * detail.CuttingOutQuantity;
                    GarmentSewingDOItem garmentSewingDOItem = new GarmentSewingDOItem(
                        Guid.NewGuid(),
                        garmentSewingDO.Identity,
                        garmentCuttingOutDetail.Identity,
                        garmentCuttingOutItem.Identity,
                        new ProductId(item.Product.Id),
                        item.Product.Code,
                        item.Product.Name,
                        item.DesignColor,
                        new SizeId(detail.Size.Id),
                        detail.Size.Size,
                        detail.CuttingOutQuantity,
                        new UomId(detail.CuttingOutUom.Id),
                        detail.CuttingOutUom.Unit,
                        detail.Color.ToUpper(),
                        detail.CuttingOutQuantity,
                        detail.BasicPrice,
                        price
                        );

                    await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
                }

                await _garmentCuttingOutItemRepository.Update(garmentCuttingOutItem);
            }

            foreach (var cuttingInDetail in cuttingInDetailToBeUpdated)
            {
                var garmentCuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(x => x.Identity == cuttingInDetail.Key).Select(s => new GarmentCuttingInDetail(s)).Single();
                garmentCuttingInDetail.SetRemainingQuantity(garmentCuttingInDetail.RemainingQuantity - cuttingInDetail.Value);
                garmentCuttingInDetail.Modify();

                await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail);
            }

            await _garmentCuttingOutRepository.Update(garmentCuttingOut);

            await _garmentSewingDORepository.Update(garmentSewingDO);

            _storage.Save();

            return(garmentCuttingOut);
        }
Example #7
0
        public async Task Handle_StateUnderTest_ExpectedBehavior_GudangJadi()
        {
            // Arrange
            Guid finishingInItemGuid = Guid.NewGuid();
            PlaceGarmentFinishingOutCommandHandler unitUnderTest = CreatePlaceGarmentFinishingOutCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            PlaceGarmentFinishingOutCommand placeGarmentFinishingOutCommand = new PlaceGarmentFinishingOutCommand()
            {
                RONo             = "RONo",
                Unit             = new UnitDepartment(1, "UnitCode", "UnitName"),
                UnitTo           = new UnitDepartment(1, "UnitCode2", "UnitName2"),
                Article          = "Article",
                IsDifferentSize  = true,
                FinishingTo      = "GUDANG JADI",
                Comodity         = new GarmentComodity(1, "ComoCode", "ComoName"),
                FinishingOutDate = DateTimeOffset.Now,
                Items            = new List <GarmentFinishingOutItemValueObject>
                {
                    new GarmentFinishingOutItemValueObject
                    {
                        Product           = new Product(1, "ProductCode", "ProductName"),
                        Uom               = new Uom(1, "UomUnit"),
                        FinishingInId     = new Guid(),
                        FinishingInItemId = finishingInItemGuid,
                        Color             = "Color",
                        Size              = new SizeValueObject(1, "Size"),
                        IsSave            = true,
                        Quantity          = 1,
                        DesignColor       = "ColorD",
                        Details           = new List <GarmentFinishingOutDetailValueObject>
                        {
                            new GarmentFinishingOutDetailValueObject
                            {
                                Size     = new SizeValueObject(1, "Size"),
                                Uom      = new Uom(1, "UomUnit"),
                                Quantity = 1
                            }
                        }
                    }
                },
            };

            _mockFinishingOutRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishingOutReadModel>().AsQueryable());
            _mockFinishingInItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishingInItemReadModel>
            {
                new GarmentFinishingInItemReadModel(finishingInItemGuid)
            }.AsQueryable());

            _mockFinishedGoodStockRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockReadModel>().AsQueryable());

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(placeGarmentFinishingOutCommand.Unit.Id),
                placeGarmentFinishingOutCommand.Unit.Code,
                placeGarmentFinishingOutCommand.Unit.Name,
                new GarmentComodityId(placeGarmentFinishingOutCommand.Comodity.Id),
                placeGarmentFinishingOutCommand.Comodity.Code,
                placeGarmentFinishingOutCommand.Comodity.Name,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockFinishingOutRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingOut>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingOut>()));
            _mockFinishingOutItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingOutItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingOutItem>()));
            _mockFinishingOutDetailRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingOutDetail>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingOutDetail>()));
            _mockFinishingInItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingInItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingInItem>()));

            _mockFinishedGoodStockRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>()));

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>()));


            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(placeGarmentFinishingOutCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Example #8
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);
        }
Example #9
0
        public async Task Handle_StateUnderTest_ExpectedBehavior_LOADING()
        {
            // Arrange
            Guid adjustmentGuid   = Guid.NewGuid();
            Guid sewingDOItemGuid = Guid.NewGuid();
            Guid sewingInItemGuid = Guid.NewGuid();
            Guid sewingDOGuid     = Guid.NewGuid();
            RemoveGarmentAdjustmentCommandHandler unitUnderTest = CreateRemoveGarmentAdjustmentCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            RemoveGarmentAdjustmentCommand RemoveGarmentAdjustmentCommand = new RemoveGarmentAdjustmentCommand(adjustmentGuid);

            GarmentAdjustment garmentAdjustment = new GarmentAdjustment(
                adjustmentGuid, null, "LOADING", "roNo", null, new UnitDepartmentId(1), null, null, DateTimeOffset.Now,
                new GarmentComodityId(1), null, null, null);

            _mockAdjustmentRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentAdjustmentReadModel>()
            {
                garmentAdjustment.GetReadModel()
            }.AsQueryable());

            _mockAdjustmentItemRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentAdjustmentItemReadModel, bool> > >()))
            .Returns(new List <GarmentAdjustmentItem>()
            {
                new GarmentAdjustmentItem(Guid.Empty, Guid.Empty, sewingDOItemGuid, sewingInItemGuid, Guid.Empty, Guid.Empty, new SizeId(1), null, new ProductId(1), null, null, null, 1, 10, new UomId(1), null, null, 1)
            });


            _mockSewingDOItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingDOItemReadModel>
            {
                new GarmentSewingDOItemReadModel(sewingDOItemGuid)
            }.AsQueryable());

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(garmentAdjustment.UnitId.Value),
                garmentAdjustment.UnitCode,
                garmentAdjustment.UnitName,
                new GarmentComodityId(garmentAdjustment.ComodityId.Value),
                garmentAdjustment.ComodityCode,
                garmentAdjustment.ComodityName,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockAdjustmentRepository
            .Setup(s => s.Update(It.IsAny <GarmentAdjustment>()))
            .Returns(Task.FromResult(It.IsAny <GarmentAdjustment>()));
            _mockAdjustmentItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentAdjustmentItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentAdjustmentItem>()));
            _mockSewingDOItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDOItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDOItem>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(RemoveGarmentAdjustmentCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Example #10
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid finStockGuid   = Guid.NewGuid();
            Guid exGoodGuid     = Guid.NewGuid();
            Guid exGoodItemGuid = Guid.NewGuid();
            Guid returId        = Guid.NewGuid();
            Guid returItemId    = Guid.NewGuid();
            RemoveGarmentExpenditureGoodCommandHandler unitUnderTest = CreateRemoveGarmentExpenditureGoodCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            RemoveGarmentExpenditureGoodCommand RemoveGarmentFinishingOutCommand = new RemoveGarmentExpenditureGoodCommand(exGoodGuid);

            GarmentExpenditureGood expenditureGood = new GarmentExpenditureGood(
                exGoodGuid, "no", "export", new UnitDepartmentId(1), "uCode", "Uname", "roNo", "art", new GarmentComodityId(1),
                "cCode", "cName", new BuyerId(1), "nam", "bCode", DateTimeOffset.Now, "inv", "con", 0, null, false);

            GarmentFinishedGoodStock garmentFinishedGoodStock = new GarmentFinishedGoodStock(finStockGuid,
                                                                                             "no", "ro", "article", expenditureGood.UnitId, expenditureGood.UnitCode, expenditureGood.UnitName,
                                                                                             expenditureGood.ComodityId, expenditureGood.ComodityCode, expenditureGood.ComodityName,
                                                                                             new SizeId(1), null, new UomId(1), null, 1, 1, 1);

            GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(Guid.NewGuid(), garmentFinishedGoodStock.Identity,
                                                                                                                  Guid.Empty, Guid.Empty, exGoodGuid, exGoodItemGuid, Guid.Empty, Guid.Empty, returId, returItemId, null, "ro", "article", expenditureGood.UnitId, expenditureGood.UnitCode, expenditureGood.UnitName,
                                                                                                                  expenditureGood.ComodityId, expenditureGood.ComodityCode, expenditureGood.ComodityName,
                                                                                                                  new SizeId(1), null, new UomId(1), null, 1, 1, 1);

            _mockFinishedGoodStockRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockReadModel>
            {
                garmentFinishedGoodStock.GetReadModel()
            }.AsQueryable());
            _mockExpenditureGoodRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodReadModel>
            {
                expenditureGood.GetReadModel()
            }.AsQueryable());

            _mockExpenditureGoodItemRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentExpenditureGoodItemReadModel, bool> > >()))
            .Returns(new List <GarmentExpenditureGoodItem>()
            {
                new GarmentExpenditureGoodItem(exGoodItemGuid, exGoodGuid, finStockGuid, new SizeId(1), null, 1, 0, new UomId(1), null, null, 1, 1)
            });

            //_mockExpenditureGoodItemRepository
            //    .Setup(s => s.Query)
            //    .Returns(new List<GarmentExpenditureGoodItemReadModel>
            //    {
            //        new GarmentExpenditureGoodItemReadModel(exGoodItemGuid)
            //    }.AsQueryable());

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockHistoryReadModel>
            {
                garmentFinishedGoodStockHistory.GetReadModel()
            }.AsQueryable());

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(expenditureGood.UnitId.Value),
                expenditureGood.UnitCode,
                expenditureGood.UnitName,
                new GarmentComodityId(expenditureGood.ComodityId.Value),
                expenditureGood.ComodityCode,
                expenditureGood.ComodityName,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockExpenditureGoodRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGood>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGood>()));
            _mockExpenditureGoodItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodItem>()));

            _mockFinishedGoodStockRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>()));

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(RemoveGarmentFinishingOutCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Example #11
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid cuttingInDetailGuid = Guid.NewGuid();
            Guid cuttingInGuid       = Guid.NewGuid();
            PlaceGarmentCuttingOutCommandHandler unitUnderTest          = CreatePlaceGarmentCuttingOutCommandHandler();
            CancellationToken             cancellationToken             = CancellationToken.None;
            PlaceGarmentCuttingOutCommand placeGarmentCuttingOutCommand = new PlaceGarmentCuttingOutCommand()
            {
                RONo           = "RONo",
                UnitFrom       = new UnitDepartment(1, "UnitCode", "UnitName"),
                Comodity       = new GarmentComodity(1, "ComoCode", "ComoName"),
                Unit           = new UnitDepartment(1, "UnitCode", "UnitName"),
                CuttingOutDate = DateTimeOffset.Now,
                Items          = new List <GarmentCuttingOutItemValueObject>
                {
                    new GarmentCuttingOutItemValueObject
                    {
                        Product           = new Product(1, "ProductCode", "ProductName"),
                        CuttingInDetailId = cuttingInDetailGuid,
                        IsSave            = true,
                        CuttingInId       = cuttingInGuid,
                        Details           = new List <GarmentCuttingOutDetailValueObject>
                        {
                            new GarmentCuttingOutDetailValueObject
                            {
                                CuttingOutUom      = new Uom(2, "PCS"),
                                CuttingOutQuantity = 1,
                                Size  = new SizeValueObject(1, "Size"),
                                Color = "kajsj"
                            }
                        }
                    }
                },
            };

            _mockCuttingOutRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentCuttingOutReadModel>().AsQueryable());

            _mockSewingDORepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingDOReadModel>().AsQueryable());

            _mockCuttingInDetailRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentCuttingInDetailReadModel>
            {
                new GarmentCuttingInDetailReadModel(cuttingInDetailGuid)
            }.AsQueryable());

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(placeGarmentCuttingOutCommand.Unit.Id),
                placeGarmentCuttingOutCommand.Unit.Code,
                placeGarmentCuttingOutCommand.Unit.Name,
                new GarmentComodityId(placeGarmentCuttingOutCommand.Comodity.Id),
                placeGarmentCuttingOutCommand.Comodity.Code,
                placeGarmentCuttingOutCommand.Comodity.Name,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockCuttingOutRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingOut>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingOut>()));
            _mockCuttingOutItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingOutItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingOutItem>()));
            _mockCuttingOutDetailRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingOutDetail>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingOutDetail>()));
            _mockCuttingInDetailRepository
            .Setup(s => s.Update(It.IsAny <GarmentCuttingInDetail>()))
            .Returns(Task.FromResult(It.IsAny <GarmentCuttingInDetail>()));

            _mockSewingDORepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDO>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDO>()));
            _mockSewingDOItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingDOItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingDOItem>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(placeGarmentCuttingOutCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Example #12
0
        public async Task <GarmentAdjustment> Handle(RemoveGarmentAdjustmentCommand request, CancellationToken cancellationToken)
        {
            var adjustment = _garmentAdjustmentRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentAdjustment(o)).Single();
            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && new UnitDepartmentId(a.UnitId) == adjustment.UnitId && new GarmentComodityId(a.ComodityId) == adjustment.ComodityId).Select(s => new GarmentComodityPrice(s)).Single();

            Dictionary <Guid, double>       sewingDOItemToBeUpdated     = new Dictionary <Guid, double>();
            Dictionary <Guid, double>       sewingInItemToBeUpdated     = new Dictionary <Guid, double>();
            Dictionary <Guid, double>       finishingInItemToBeUpdated  = new Dictionary <Guid, double>();
            Dictionary <Guid, double>       finishedGoodItemToBeUpdated = new Dictionary <Guid, double>();
            List <GarmentFinishedGoodStock> finGoodStocks = new List <GarmentFinishedGoodStock>();

            _garmentAdjustmentItemRepository.Find(o => o.AdjustmentId == adjustment.Identity).ForEach(async adjustmentItem =>
            {
                if (adjustment.AdjustmentType == "LOADING")
                {
                    if (sewingDOItemToBeUpdated.ContainsKey(adjustmentItem.SewingDOItemId))
                    {
                        sewingDOItemToBeUpdated[adjustmentItem.SewingDOItemId] += adjustmentItem.Quantity;
                    }
                    else
                    {
                        sewingDOItemToBeUpdated.Add(adjustmentItem.SewingDOItemId, adjustmentItem.Quantity);
                    }
                }
                else if (adjustment.AdjustmentType == "SEWING")
                {
                    if (sewingInItemToBeUpdated.ContainsKey(adjustmentItem.SewingInItemId))
                    {
                        sewingInItemToBeUpdated[adjustmentItem.SewingInItemId] += adjustmentItem.Quantity;
                    }
                    else
                    {
                        sewingInItemToBeUpdated.Add(adjustmentItem.SewingInItemId, adjustmentItem.Quantity);
                    }
                }
                else if (adjustment.AdjustmentType == "FINISHING")
                {
                    if (finishingInItemToBeUpdated.ContainsKey(adjustmentItem.FinishingInItemId))
                    {
                        finishingInItemToBeUpdated[adjustmentItem.FinishingInItemId] += adjustmentItem.Quantity;
                    }
                    else
                    {
                        finishingInItemToBeUpdated.Add(adjustmentItem.FinishingInItemId, adjustmentItem.Quantity);
                    }
                }
                else
                {
                    if (finishedGoodItemToBeUpdated.ContainsKey(adjustmentItem.FinishedGoodStockId))
                    {
                        finishedGoodItemToBeUpdated[adjustmentItem.FinishedGoodStockId] += adjustmentItem.Quantity;
                    }
                    else
                    {
                        finishedGoodItemToBeUpdated.Add(adjustmentItem.FinishedGoodStockId, adjustmentItem.Quantity);
                    }
                }

                adjustmentItem.Remove();

                await _garmentAdjustmentItemRepository.Update(adjustmentItem);
            });

            if (adjustment.AdjustmentType == "LOADING")
            {
                foreach (var sewingDOItem in sewingDOItemToBeUpdated)
                {
                    var garmentSewingDOItem = _garmentSewingDOItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingDOItem(s)).Single();
                    garmentSewingDOItem.setRemainingQuantity(garmentSewingDOItem.RemainingQuantity + sewingDOItem.Value);
                    garmentSewingDOItem.Modify();

                    await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
                }
            }
            else if (adjustment.AdjustmentType == "SEWING")
            {
                foreach (var sewingInItem in sewingInItemToBeUpdated)
                {
                    var garmentSewingInItem = _garmentSewingInItemRepository.Query.Where(x => x.Identity == sewingInItem.Key).Select(s => new GarmentSewingInItem(s)).Single();
                    garmentSewingInItem.SetRemainingQuantity(garmentSewingInItem.RemainingQuantity + sewingInItem.Value);
                    garmentSewingInItem.Modify();

                    await _garmentSewingInItemRepository.Update(garmentSewingInItem);
                }
            }
            else if (adjustment.AdjustmentType == "FINISHING")
            {
                foreach (var finishingInItem in finishingInItemToBeUpdated)
                {
                    var garmentFinishingInItem = _garmentFinishingInItemRepository.Query.Where(x => x.Identity == finishingInItem.Key).Select(s => new GarmentFinishingInItem(s)).Single();
                    garmentFinishingInItem.SetRemainingQuantity(garmentFinishingInItem.RemainingQuantity + finishingInItem.Value);
                    garmentFinishingInItem.Modify();

                    await _garmentFinishingInItemRepository.Update(garmentFinishingInItem);
                }
            }
            else
            {
                foreach (var data in finishedGoodItemToBeUpdated)
                {
                    var garmentFinishedGoodstock = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == data.Key).Select(s => new GarmentFinishedGoodStock(s)).Single();
                    var qty = garmentFinishedGoodstock.Quantity + data.Value;
                    garmentFinishedGoodstock.SetQuantity(qty);
                    garmentFinishedGoodstock.SetPrice((garmentFinishedGoodstock.BasicPrice + (double)garmentComodityPrice.Price) * (qty));

                    garmentFinishedGoodstock.Modify();
                    await _garmentFinishedGoodStockRepository.Update(garmentFinishedGoodstock);
                }
                var stockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(o => o.AdjustmentId == adjustment.Identity).Select(o => new GarmentFinishedGoodStockHistory(o));
                foreach (var data in stockHistory)
                {
                    var dataStockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(o => o.Identity == data.Identity).Select(o => new GarmentFinishedGoodStockHistory(o)).Single();
                    dataStockHistory.Remove();
                    await _garmentFinishedGoodStockHistoryRepository.Update(dataStockHistory);
                }
            }

            adjustment.Remove();
            await _garmentAdjustmentRepository.Update(adjustment);

            _storage.Save();
            return(adjustment);
        }
Example #13
0
        public async Task <GarmentFinishingOut> Handle(PlaceGarmentFinishingOutCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true).ToList();

            GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && a.UnitId == request.UnitTo.Id && a.ComodityId == request.Comodity.Id).Select(s => new GarmentComodityPrice(s)).Single();
            Guid garmentFinishingOutId = Guid.NewGuid();
            GarmentFinishingOut garmentFinishingOut = new GarmentFinishingOut(
                garmentFinishingOutId,
                GenerateFinOutNo(request),
                new UnitDepartmentId(request.UnitTo.Id),
                request.UnitTo.Code,
                request.UnitTo.Name,
                request.FinishingTo,
                request.FinishingOutDate.GetValueOrDefault(),
                request.RONo,
                request.Article,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                request.IsDifferentSize
                );

            Dictionary <Guid, double> finishingInItemToBeUpdated = new Dictionary <Guid, double>();

            Dictionary <string, double> finGood = new Dictionary <string, double>();

            foreach (var item in request.Items)
            {
                if (item.IsSave)
                {
                    Guid garmentFinishingOutItemId = Guid.NewGuid();
                    GarmentFinishingOutItem garmentFinishingOutItem = new GarmentFinishingOutItem(
                        garmentFinishingOutItemId,
                        garmentFinishingOut.Identity,
                        item.FinishingInId,
                        item.FinishingInItemId,
                        new ProductId(item.Product.Id),
                        item.Product.Code,
                        item.Product.Name,
                        item.DesignColor,
                        new SizeId(item.Size.Id),
                        item.Size.Size,
                        request.IsDifferentSize ? item.TotalQuantity : item.Quantity,
                        new UomId(item.Uom.Id),
                        item.Uom.Unit,
                        item.Color,
                        request.IsDifferentSize ? item.TotalQuantity : item.Quantity,
                        item.BasicPrice,
                        item.Price
                        );
                    item.Id = garmentFinishingOutItemId;
                    if (request.IsDifferentSize)
                    {
                        foreach (var detail in item.Details)
                        {
                            Guid garmentFinishingOutDetailId = Guid.NewGuid();
                            GarmentFinishingOutDetail garmentFinishingOutDetail = new GarmentFinishingOutDetail(
                                garmentFinishingOutDetailId,
                                garmentFinishingOutItem.Identity,
                                new SizeId(detail.Size.Id),
                                detail.Size.Size,
                                detail.Quantity,
                                new UomId(detail.Uom.Id),
                                detail.Uom.Unit
                                );
                            detail.Id = garmentFinishingOutDetailId;
                            if (finishingInItemToBeUpdated.ContainsKey(item.FinishingInItemId))
                            {
                                finishingInItemToBeUpdated[item.FinishingInItemId] += detail.Quantity;
                            }
                            else
                            {
                                finishingInItemToBeUpdated.Add(item.FinishingInItemId, detail.Quantity);
                            }

                            await _garmentFinishingOutDetailRepository.Update(garmentFinishingOutDetail);

                            if (request.FinishingTo == "GUDANG JADI")
                            {
                                string finStock = detail.Size.Id + "~" + detail.Size.Size + "~" + detail.Uom.Id + "~" + detail.Uom.Unit + "~" + item.BasicPrice;

                                if (finGood.ContainsKey(finStock))
                                {
                                    finGood[finStock] += detail.Quantity;
                                }
                                else
                                {
                                    finGood.Add(finStock, detail.Quantity);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (finishingInItemToBeUpdated.ContainsKey(item.FinishingInItemId))
                        {
                            finishingInItemToBeUpdated[item.FinishingInItemId] += item.Quantity;
                        }
                        else
                        {
                            finishingInItemToBeUpdated.Add(item.FinishingInItemId, item.Quantity);
                        }

                        if (request.FinishingTo == "GUDANG JADI")
                        {
                            string finStock = item.Size.Id + "~" + item.Size.Size + "~" + item.Uom.Id + "~" + item.Uom.Unit + "~" + item.BasicPrice;

                            if (finGood.ContainsKey(finStock))
                            {
                                finGood[finStock] += item.Quantity;
                            }
                            else
                            {
                                finGood.Add(finStock, item.Quantity);
                            }
                        }
                    }
                    await _garmentFinishingOutItemRepository.Update(garmentFinishingOutItem);
                }
            }

            foreach (var finInItem in finishingInItemToBeUpdated)
            {
                var garmentFinishingInItem = _garmentFinishingInItemRepository.Query.Where(x => x.Identity == finInItem.Key).Select(s => new GarmentFinishingInItem(s)).Single();
                garmentFinishingInItem.SetRemainingQuantity(garmentFinishingInItem.RemainingQuantity - finInItem.Value);
                garmentFinishingInItem.Modify();

                await _garmentFinishingInItemRepository.Update(garmentFinishingInItem);
            }

            if (request.FinishingTo == "GUDANG JADI")
            {
                int count = 1;
                List <GarmentFinishedGoodStock> finGoodStocks = new List <GarmentFinishedGoodStock>();
                foreach (var finGoodStock in finGood)
                {
                    SizeId sizeId     = new SizeId(Convert.ToInt32(finGoodStock.Key.Split("~")[0]));
                    string sizeName   = finGoodStock.Key.Split("~")[1];
                    UomId  uomId      = new UomId(Convert.ToInt32(finGoodStock.Key.Split("~")[2]));
                    string uomUnit    = finGoodStock.Key.Split("~")[3];
                    double basicPrice = Convert.ToDouble(finGoodStock.Key.Split("~")[4]);
                    var    garmentFinishedGoodExist = _garmentFinishedGoodStockRepository.Query.Where(
                        a => a.RONo == request.RONo &&
                        a.Article == request.Article &&
                        a.BasicPrice == basicPrice &&
                        a.UnitId == request.UnitTo.Id &&
                        new SizeId(a.SizeId) == sizeId &&
                        a.ComodityId == request.Comodity.Id &&
                        new UomId(a.UomId) == uomId
                        ).Select(s => new GarmentFinishedGoodStock(s)).SingleOrDefault();

                    double qty = garmentFinishedGoodExist == null ? finGoodStock.Value : (finGoodStock.Value + garmentFinishedGoodExist.Quantity);

                    double price = (basicPrice + (double)garmentComodityPrice.Price) * qty;

                    if (garmentFinishedGoodExist == null)
                    {
                        var now    = DateTime.Now;
                        var year   = now.ToString("yy");
                        var month  = now.ToString("MM");
                        var prefix = $"ST{request.UnitTo.Code.Trim()}{year}{month}";

                        var lastFnGoodNo = _garmentFinishedGoodStockRepository.Query.Where(w => w.FinishedGoodStockNo.StartsWith(prefix))
                                           .OrderByDescending(o => o.FinishedGoodStockNo)
                                           .Select(s => int.Parse(s.FinishedGoodStockNo.Replace(prefix, "")))
                                           .FirstOrDefault();
                        var FinGoodNo = $"{prefix}{(lastFnGoodNo + count).ToString("D4")}";
                        GarmentFinishedGoodStock finishedGood = new GarmentFinishedGoodStock(
                            Guid.NewGuid(),
                            FinGoodNo,
                            request.RONo,
                            request.Article,
                            new UnitDepartmentId(request.UnitTo.Id),
                            request.UnitTo.Code,
                            request.UnitTo.Name,
                            new GarmentComodityId(request.Comodity.Id),
                            request.Comodity.Code,
                            request.Comodity.Name,
                            sizeId,
                            sizeName,
                            uomId,
                            uomUnit,
                            qty,
                            basicPrice,
                            price
                            );
                        count++;
                        await _garmentFinishedGoodStockRepository.Update(finishedGood);

                        finGoodStocks.Add(finishedGood);
                    }
                    else
                    {
                        garmentFinishedGoodExist.SetQuantity(qty);
                        garmentFinishedGoodExist.SetPrice(price);
                        garmentFinishedGoodExist.Modify();

                        await _garmentFinishedGoodStockRepository.Update(garmentFinishedGoodExist);

                        var stock = finGoodStocks.Where(a => a.RONo == request.RONo &&
                                                        a.Article == request.Article &&
                                                        a.BasicPrice == garmentFinishedGoodExist.BasicPrice &&
                                                        a.UnitId == new UnitDepartmentId(request.UnitTo.Id) &&
                                                        a.SizeId == garmentFinishedGoodExist.SizeId &&
                                                        a.ComodityId == new GarmentComodityId(request.Comodity.Id) &&
                                                        a.UomId == garmentFinishedGoodExist.UomId).SingleOrDefault();
                        finGoodStocks.Add(garmentFinishedGoodExist);
                    }
                }

                foreach (var item in request.Items)
                {
                    if (item.IsSave)
                    {
                        if (request.IsDifferentSize)
                        {
                            foreach (var detail in item.Details)
                            {
                                var stock = finGoodStocks.Where(a => a.RONo == request.RONo &&
                                                                a.Article == request.Article &&
                                                                a.BasicPrice == item.BasicPrice &&
                                                                a.UnitId == new UnitDepartmentId(request.UnitTo.Id) &&
                                                                a.SizeId == new SizeId(detail.Size.Id) &&
                                                                a.ComodityId == new GarmentComodityId(request.Comodity.Id) &&
                                                                a.UomId == new UomId(detail.Uom.Id)).Single();

                                double price = (stock.BasicPrice + (double)garmentComodityPrice.Price) * detail.Quantity;

                                GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(
                                    Guid.NewGuid(),
                                    stock.Identity,
                                    item.Id,
                                    detail.Id,
                                    Guid.Empty,
                                    Guid.Empty,
                                    Guid.Empty,
                                    Guid.Empty,
                                    Guid.Empty,
                                    Guid.Empty,
                                    "IN",
                                    stock.RONo,
                                    stock.Article,
                                    stock.UnitId,
                                    stock.UnitCode,
                                    stock.UnitName,
                                    stock.ComodityId,
                                    stock.ComodityCode,
                                    stock.ComodityName,
                                    stock.SizeId,
                                    stock.SizeName,
                                    stock.UomId,
                                    stock.UomUnit,
                                    detail.Quantity,
                                    stock.BasicPrice,
                                    price
                                    );
                                await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);
                            }
                        }
                        else
                        {
                            var stock = finGoodStocks.Where(a => a.RONo == request.RONo &&
                                                            a.Article == request.Article &&
                                                            a.BasicPrice == item.BasicPrice &&
                                                            a.UnitId == new UnitDepartmentId(request.UnitTo.Id) &&
                                                            a.SizeId == new SizeId(item.Size.Id) &&
                                                            a.ComodityId == new GarmentComodityId(request.Comodity.Id) &&
                                                            a.UomId == new UomId(item.Uom.Id)).Single();

                            double price = (stock.BasicPrice + (double)garmentComodityPrice.Price) * item.Quantity;

                            GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(
                                Guid.NewGuid(),
                                stock.Identity,
                                item.Id,
                                Guid.Empty,
                                Guid.Empty,
                                Guid.Empty,
                                Guid.Empty,
                                Guid.Empty,
                                Guid.Empty,
                                Guid.Empty,
                                "IN",
                                stock.RONo,
                                stock.Article,
                                stock.UnitId,
                                stock.UnitCode,
                                stock.UnitName,
                                stock.ComodityId,
                                stock.ComodityCode,
                                stock.ComodityName,
                                stock.SizeId,
                                stock.SizeName,
                                stock.UomId,
                                stock.UomUnit,
                                item.Quantity,
                                stock.BasicPrice,
                                price
                                );
                            await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);
                        }
                    }
                }
            }

            await _garmentFinishingOutRepository.Update(garmentFinishingOut);

            _storage.Save();

            return(garmentFinishingOut);
        }
        public async Task Handle_StateUnderTest_ExpectedBehavior_BARANGJADI()
        {
            // Arrange
            Guid finishedGoodStockId = Guid.NewGuid();
            Guid sewingDOGuid        = Guid.NewGuid();
            PlaceGarmentAdjustmentCommandHandler unitUnderTest          = CreatePlaceGarmentAdjustmentCommandHandler();
            CancellationToken             cancellationToken             = CancellationToken.None;
            PlaceGarmentAdjustmentCommand placeGarmentAdjustmentCommand = new PlaceGarmentAdjustmentCommand()
            {
                RONo           = "RONo",
                Unit           = new UnitDepartment(1, "UnitCode", "UnitName"),
                AdjustmentType = "BARANG JADI",
                AdjustmentDate = DateTimeOffset.Now,
                Article        = "Article",
                Comodity       = new GarmentComodity(1, "ComoCode", "ComoName"),
                Items          = new List <GarmentAdjustmentItemValueObject>
                {
                    new GarmentAdjustmentItemValueObject
                    {
                        IsSave              = true,
                        FinishingInItemId   = Guid.Empty,
                        FinishedGoodStockId = finishedGoodStockId,
                        Size              = new SizeValueObject(1, "Size"),
                        Quantity          = 1,
                        RemainingQuantity = 2,
                        Product           = new Product(1, "ProdCode", "ProdName"),
                        Uom   = new Uom(1, "Uom"),
                        Color = "www"
                    }
                },
            };

            _mockFinishedGoodStockRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockReadModel>
            {
                new GarmentFinishedGoodStock(finishedGoodStockId, "", "RONo", "article", new UnitDepartmentId(1), "code", "name", new GarmentComodityId(1), "", "", new SizeId(1), "", new UomId(1), "", 10, 100, 100).GetReadModel()
            }.AsQueryable());

            _mockAdjustmentRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentAdjustmentReadModel>().AsQueryable());

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(placeGarmentAdjustmentCommand.Unit.Id),
                placeGarmentAdjustmentCommand.Unit.Code,
                placeGarmentAdjustmentCommand.Unit.Name,
                new GarmentComodityId(placeGarmentAdjustmentCommand.Comodity.Id),
                placeGarmentAdjustmentCommand.Comodity.Code,
                placeGarmentAdjustmentCommand.Comodity.Name,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockAdjustmentRepository
            .Setup(s => s.Update(It.IsAny <GarmentAdjustment>()))
            .Returns(Task.FromResult(It.IsAny <GarmentAdjustment>()));
            _mockAdjustmentItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentAdjustmentItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentAdjustmentItem>()));
            _mockFinishedGoodStockRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>()));
            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>()));
            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(placeGarmentAdjustmentCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Example #15
0
        public async Task Handle_StateUnderTest_ExpectedBehavior_GUDANGJADI()
        {
            // Arrange
            Guid finishingInItemGuid    = Guid.NewGuid();
            Guid finishingOutGuid       = Guid.NewGuid();
            Guid finishingOutItemGuid   = Guid.NewGuid();
            Guid finishingOutDetailGuid = Guid.NewGuid();
            RemoveGarmentFinishingOutCommandHandler unitUnderTest = CreateRemoveGarmentFinishingOutCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            RemoveGarmentFinishingOutCommand RemoveGarmentFinishingOutCommand = new RemoveGarmentFinishingOutCommand(finishingOutGuid);

            GarmentFinishingOut garmentFinishingOut = new GarmentFinishingOut(
                finishingOutGuid,
                "no", new UnitDepartmentId(1), "uCode", "Uname", "GUDANG JADI", DateTimeOffset.Now, "ro", "article",
                new UnitDepartmentId(1), "uCode", "Uname", new GarmentComodityId(1), "cCode", "cName", false);

            _mockFinishingOutRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishingOutReadModel>()
            {
                garmentFinishingOut.GetReadModel()
            }.AsQueryable());
            _mockFinishingOutItemRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentFinishingOutItemReadModel, bool> > >()))
            .Returns(new List <GarmentFinishingOutItem>()
            {
                new GarmentFinishingOutItem(finishingOutItemGuid, finishingOutGuid, Guid.Empty, finishingInItemGuid, new ProductId(1), null, null, null, new SizeId(1), null, 1, new UomId(1), null, null, 1, 1, 1)
            });
            //_mockFinishingOutDetailRepository
            //    .Setup(s => s.Find(It.IsAny<Expression<Func<GarmentFinishingOutDetailReadModel, bool>>>()))
            //    .Returns(new List<GarmentFinishingOutDetail>()
            //    {
            //        new GarmentFinishingOutDetail(Guid.Empty, Guid.Empty,new SizeId(1), null, 1, new UomId(1),null )
            //    });

            _mockFinishingInItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishingInItemReadModel>
            {
                new GarmentFinishingInItemReadModel(finishingInItemGuid)
            }.AsQueryable());

            GarmentFinishedGoodStock garmentFinishedGoodStock = new GarmentFinishedGoodStock(Guid.NewGuid(),
                                                                                             "no", "ro", "article", garmentFinishingOut.UnitId, garmentFinishingOut.UnitCode, garmentFinishingOut.UnitName,
                                                                                             garmentFinishingOut.ComodityId, garmentFinishingOut.ComodityCode, garmentFinishingOut.ComodityName,
                                                                                             new SizeId(1), null, new UomId(1), null, 1, 1, 1);

            _mockFinishedGoodStockRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockReadModel>
            {
                garmentFinishedGoodStock.GetReadModel()
            }.AsQueryable());

            GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(Guid.NewGuid(), garmentFinishedGoodStock.Identity,
                                                                                                                  finishingOutItemGuid, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, null, "ro", "article", garmentFinishingOut.UnitId, garmentFinishingOut.UnitCode, garmentFinishingOut.UnitName,
                                                                                                                  garmentFinishingOut.ComodityId, garmentFinishingOut.ComodityCode, garmentFinishingOut.ComodityName,
                                                                                                                  new SizeId(1), null, new UomId(1), null, 1, 1, 1);

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockHistoryReadModel>
            {
                garmentFinishedGoodStockHistory.GetReadModel()
            }.AsQueryable());

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                garmentFinishingOut.UnitId,
                garmentFinishingOut.UnitCode,
                garmentFinishingOut.UnitName,
                garmentFinishingOut.ComodityId,
                garmentFinishingOut.ComodityCode,
                garmentFinishingOut.ComodityName,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockFinishingOutRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingOut>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingOut>()));
            _mockFinishingOutItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingOutItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingOutItem>()));
            //_mockFinishingOutDetailRepository
            //    .Setup(s => s.Update(It.IsAny<GarmentFinishingOutDetail>()))
            //    .Returns(Task.FromResult(It.IsAny<GarmentFinishingOutDetail>()));
            _mockFinishingInItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishingInItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishingInItem>()));

            _mockFinishedGoodStockRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>()));

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(RemoveGarmentFinishingOutCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
        public async Task <GarmentExpenditureGood> Handle(PlaceGarmentExpenditureGoodCommand 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();

            GarmentExpenditureGood garmentExpenditureGood = new GarmentExpenditureGood(
                Guid.NewGuid(),
                GenerateExpenditureGoodNo(request),
                request.ExpenditureType,
                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.ExpenditureDate,
                request.Invoice,
                request.ContractNo,
                request.Carton,
                request.Description,
                request.IsReceived
                );

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

            foreach (var item in request.Items)
            {
                if (item.isSave)
                {
                    double StockQty = 0;
                    var    garmentFinishingGoodStock = _garmentFinishedGoodStockRepository.Query.Where(x => x.SizeId == item.Size.Id && x.UomId == item.Uom.Id && x.RONo == request.RONo && x.UnitId == request.Unit.Id && x.Quantity > 0).OrderBy(a => a.CreatedDate).ToList();

                    double qty = item.Quantity;
                    foreach (var finishedGood in garmentFinishingGoodStock)
                    {
                        if (!finstockQty.ContainsKey(finishedGood.Identity))
                        {
                            finstockQty.Add(finishedGood.Identity, finishedGood.Quantity);
                        }
                        string key = finishedGood.Identity.ToString() + "~" + item.Description;
                        if (qty > 0)
                        {
                            double remainQty = finstockQty[finishedGood.Identity] - qty;
                            if (remainQty < 0)
                            {
                                qty -= finstockQty[finishedGood.Identity];
                                finStockToBeUpdated.Add(key, 0);
                                finstockQty[finishedGood.Identity] = 0;
                            }
                            else if (remainQty == 0)
                            {
                                finStockToBeUpdated.Add(key, 0);
                                finstockQty[finishedGood.Identity] = remainQty;
                                break;
                            }
                            else if (remainQty > 0)
                            {
                                finStockToBeUpdated.Add(key, remainQty);
                                finstockQty[finishedGood.Identity] = remainQty;
                                break;
                            }
                        }
                    }
                }
            }

            foreach (var finStock in finStockToBeUpdated)
            {
                var keyString = finStock.Key.Split("~");

                var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == Guid.Parse(keyString[0])).Select(s => new GarmentFinishedGoodStock(s)).Single();

                var item = request.Items.Where(a => new SizeId(a.Size.Id) == garmentFinishingGoodStockItem.SizeId && new UomId(a.Uom.Id) == garmentFinishingGoodStockItem.UomId && a.Description == keyString[1]).Single();

                item.Price = (item.BasicPrice + ((double)garmentComodityPrice.Price * 1)) * item.Quantity;
                var qty = garmentFinishingGoodStockItem.Quantity - finStock.Value;

                GarmentExpenditureGoodItem garmentExpenditureGoodItem = new GarmentExpenditureGoodItem(
                    Guid.NewGuid(),
                    garmentExpenditureGood.Identity,
                    garmentFinishingGoodStockItem.Identity,
                    new SizeId(item.Size.Id),
                    item.Size.Size,
                    qty,
                    0,
                    new UomId(item.Uom.Id),
                    item.Uom.Unit,
                    item.Description,
                    garmentFinishingGoodStockItem.BasicPrice,
                    (garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * qty
                    );

                await _garmentExpenditureGoodItemRepository.Update(garmentExpenditureGoodItem);

                GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(
                    Guid.NewGuid(),
                    garmentFinishingGoodStockItem.Identity,
                    Guid.Empty,
                    Guid.Empty,
                    garmentExpenditureGood.Identity,
                    garmentExpenditureGoodItem.Identity,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    Guid.Empty,
                    "OUT",
                    garmentExpenditureGood.RONo,
                    garmentExpenditureGood.Article,
                    garmentExpenditureGood.UnitId,
                    garmentExpenditureGood.UnitCode,
                    garmentExpenditureGood.UnitName,
                    garmentExpenditureGood.ComodityId,
                    garmentExpenditureGood.ComodityCode,
                    garmentExpenditureGood.ComodityName,
                    garmentExpenditureGoodItem.SizeId,
                    garmentExpenditureGoodItem.SizeName,
                    garmentExpenditureGoodItem.UomId,
                    garmentExpenditureGoodItem.UomUnit,
                    garmentExpenditureGoodItem.Quantity,
                    garmentExpenditureGoodItem.BasicPrice,
                    garmentExpenditureGoodItem.Price
                    );
                await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);

                garmentFinishingGoodStockItem.SetQuantity(finStock.Value);
                garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (finStock.Value));
                garmentFinishingGoodStockItem.Modify();

                await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem);
            }

            await _garmentExpenditureGoodRepository.Update(garmentExpenditureGood);

            _storage.Save();

            return(garmentExpenditureGood);
        }
        public async Task <GarmentAdjustment> Handle(PlaceGarmentAdjustmentCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();
            Guid AdjustmentId = Guid.NewGuid();

            GarmentAdjustment garmentAdjustment = new GarmentAdjustment(
                AdjustmentId,
                GenerateAdjustmentNo(request),
                request.AdjustmentType,
                request.RONo,
                request.Article,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.AdjustmentDate.GetValueOrDefault(),
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                request.AdjustmentDesc
                );

            Dictionary <Guid, double>       sewingDOItemToBeUpdated     = new Dictionary <Guid, double>();
            Dictionary <Guid, double>       sewingInItemToBeUpdated     = new Dictionary <Guid, double>();
            Dictionary <Guid, double>       finishingInItemToBeUpdated  = new Dictionary <Guid, double>();
            Dictionary <Guid, double>       finishedGoodItemToBeUpdated = new Dictionary <Guid, double>();
            List <GarmentFinishedGoodStock> finGoodStocks = new List <GarmentFinishedGoodStock>();

            foreach (var item in request.Items)
            {
                if (item.IsSave)
                {
                    if (request.AdjustmentType != "BARANG JADI")
                    {
                        Guid AdjutmentItemId = Guid.NewGuid();
                        GarmentAdjustmentItem garmentAdjustmentItem = new GarmentAdjustmentItem(
                            AdjutmentItemId,
                            AdjustmentId,
                            item.SewingDOItemId,
                            item.SewingInItemId,
                            item.FinishingInItemId,
                            Guid.Empty,
                            new SizeId(item.Size.Id),
                            item.Size.Size,
                            item.Product != null ? new ProductId(item.Product.Id) : new ProductId(0),
                            item.Product != null ? item.Product.Code : null,
                            item.Product != null ? item.Product.Name : null,
                            item.DesignColor,
                            item.Quantity,
                            item.BasicPrice,
                            new UomId(item.Uom.Id),
                            item.Uom.Unit,
                            item.Color,
                            item.Price
                            );
                        await _garmentAdjustmentItemRepository.Update(garmentAdjustmentItem);
                    }
                    else
                    {
                        var    garmentFinishingGoodStock = _garmentFinishedGoodStockRepository.Query.Where(x => x.SizeId == item.Size.Id && x.UomId == item.Uom.Id && x.RONo == request.RONo && x.UnitId == request.Unit.Id && x.Quantity > 0).OrderBy(a => a.CreatedDate).ToList();
                        double qty = item.Quantity;
                        foreach (var finishedGood in garmentFinishingGoodStock)
                        {
                            if (qty > 0)
                            {
                                double remainQty = finishedGood.Quantity - qty;
                                if (remainQty < 0)
                                {
                                    qty -= finishedGood.Quantity;
                                    finishedGoodItemToBeUpdated.Add(finishedGood.Identity, 0);
                                }
                                else if (remainQty == 0)
                                {
                                    finishedGoodItemToBeUpdated.Add(finishedGood.Identity, 0); break;
                                }
                                else if (remainQty > 0)
                                {
                                    finishedGoodItemToBeUpdated.Add(finishedGood.Identity, remainQty); break;
                                }
                            }
                        }
                    }

                    if (request.AdjustmentType == "LOADING")
                    {
                        if (sewingDOItemToBeUpdated.ContainsKey(item.SewingDOItemId))
                        {
                            sewingDOItemToBeUpdated[item.SewingDOItemId] += item.Quantity;
                        }
                        else
                        {
                            sewingDOItemToBeUpdated.Add(item.SewingDOItemId, item.Quantity);
                        }
                    }
                    else if (request.AdjustmentType == "SEWING")
                    {
                        if (sewingInItemToBeUpdated.ContainsKey(item.SewingInItemId))
                        {
                            sewingInItemToBeUpdated[item.SewingInItemId] += item.Quantity;
                        }
                        else
                        {
                            sewingInItemToBeUpdated.Add(item.SewingInItemId, item.Quantity);
                        }
                    }
                    else if (request.AdjustmentType == "FINISHING")
                    {
                        if (finishingInItemToBeUpdated.ContainsKey(item.FinishingInItemId))
                        {
                            finishingInItemToBeUpdated[item.FinishingInItemId] += item.Quantity;
                        }
                        else
                        {
                            finishingInItemToBeUpdated.Add(item.FinishingInItemId, item.Quantity);
                        }
                    }
                }
            }

            if (request.AdjustmentType == "LOADING")
            {
                foreach (var sewingDOItem in sewingDOItemToBeUpdated)
                {
                    var garmentSewingDOItem = _garmentSewingDOItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingDOItem(s)).Single();
                    garmentSewingDOItem.setRemainingQuantity(garmentSewingDOItem.RemainingQuantity - sewingDOItem.Value);
                    garmentSewingDOItem.Modify();

                    await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
                }
            }
            else if (request.AdjustmentType == "SEWING")
            {
                foreach (var sewingInItem in sewingInItemToBeUpdated)
                {
                    var garmentSewingInItem = _garmentSewingInItemRepository.Query.Where(x => x.Identity == sewingInItem.Key).Select(s => new GarmentSewingInItem(s)).Single();
                    garmentSewingInItem.SetRemainingQuantity(garmentSewingInItem.RemainingQuantity - sewingInItem.Value);
                    garmentSewingInItem.Modify();

                    await _garmentSewingInItemRepository.Update(garmentSewingInItem);
                }
            }
            else if (request.AdjustmentType == "FINISHING")
            {
                foreach (var finishingInItem in finishingInItemToBeUpdated)
                {
                    var garmentFinishingInItem = _garmentFinishingInItemRepository.Query.Where(x => x.Identity == finishingInItem.Key).Select(s => new GarmentFinishingInItem(s)).Single();
                    garmentFinishingInItem.SetRemainingQuantity(garmentFinishingInItem.RemainingQuantity - finishingInItem.Value);
                    garmentFinishingInItem.Modify();

                    await _garmentFinishingInItemRepository.Update(garmentFinishingInItem);
                }
            }
            else
            {
                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();

                foreach (var data in finishedGoodItemToBeUpdated)
                {
                    var garmentFinishedGoodstock = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == data.Key).Select(s => new GarmentFinishedGoodStock(s)).Single();
                    var item = request.Items.Where(a => new SizeId(a.Size.Id) == garmentFinishedGoodstock.SizeId && new UomId(a.Uom.Id) == garmentFinishedGoodstock.UomId).Single();

                    var qty = garmentFinishedGoodstock.Quantity - data.Value;

                    Guid AdjutmentItemId = Guid.NewGuid();
                    GarmentAdjustmentItem garmentAdjustmentItem = new GarmentAdjustmentItem(
                        AdjutmentItemId,
                        AdjustmentId,
                        item.SewingDOItemId,
                        item.SewingInItemId,
                        item.FinishingInItemId,
                        garmentFinishedGoodstock.Identity,
                        new SizeId(item.Size.Id),
                        item.Size.Size,
                        item.Product != null ? new ProductId(item.Product.Id) : new ProductId(0),
                        item.Product != null ? item.Product.Code : null,
                        item.Product != null ? item.Product.Name : null,
                        item.DesignColor,
                        qty,
                        item.BasicPrice,
                        new UomId(item.Uom.Id),
                        item.Uom.Unit,
                        item.Color,
                        (garmentFinishedGoodstock.BasicPrice + (double)garmentComodityPrice.Price) * qty
                        );
                    GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory(
                        Guid.NewGuid(),
                        garmentFinishedGoodstock.Identity,
                        Guid.Empty,
                        Guid.Empty,
                        Guid.Empty,
                        Guid.Empty,
                        AdjustmentId,
                        AdjutmentItemId,
                        Guid.Empty,
                        Guid.Empty,
                        "ADJUSTMENT",
                        garmentFinishedGoodstock.RONo,
                        garmentFinishedGoodstock.Article,
                        garmentFinishedGoodstock.UnitId,
                        garmentFinishedGoodstock.UnitCode,
                        garmentFinishedGoodstock.UnitName,
                        garmentFinishedGoodstock.ComodityId,
                        garmentFinishedGoodstock.ComodityCode,
                        garmentFinishedGoodstock.ComodityName,
                        garmentFinishedGoodstock.SizeId,
                        garmentFinishedGoodstock.SizeName,
                        garmentFinishedGoodstock.UomId,
                        garmentFinishedGoodstock.UomUnit,
                        garmentFinishedGoodstock.Quantity,
                        garmentFinishedGoodstock.BasicPrice,
                        garmentFinishedGoodstock.Price
                        );
                    await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);

                    await _garmentAdjustmentItemRepository.Update(garmentAdjustmentItem);


                    garmentFinishedGoodstock.SetPrice((garmentFinishedGoodstock.BasicPrice + (double)garmentComodityPrice.Price) * (data.Value));
                    garmentFinishedGoodstock.SetQuantity(data.Value);
                    garmentFinishedGoodstock.Modify();
                    await _garmentFinishedGoodStockRepository.Update(garmentFinishedGoodstock);
                }
            }

            await _garmentAdjustmentRepository.Update(garmentAdjustment);

            _storage.Save();

            return(garmentAdjustment);
        }
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid sewingInItemGuid = Guid.NewGuid();
            Guid sewingOutGuid    = Guid.NewGuid();
            Guid sewingInId       = Guid.NewGuid();
            UpdateGarmentSewingOutCommandHandler unitUnderTest          = CreateUpdateGarmentSewingOutCommandHandler();
            CancellationToken             cancellationToken             = CancellationToken.None;
            UpdateGarmentSewingOutCommand UpdateGarmentSewingOutCommand = new UpdateGarmentSewingOutCommand()
            {
                RONo            = "RONo",
                Unit            = new UnitDepartment(1, "UnitCode", "UnitName"),
                UnitTo          = new UnitDepartment(2, "UnitCode2", "UnitName2"),
                Article         = "Article",
                IsDifferentSize = true,
                Buyer           = new Buyer(1, "BuyerCode", "BuyerName"),
                SewingTo        = "FINISHING",
                Comodity        = new GarmentComodity(1, "ComoCode", "ComoName"),
                SewingOutDate   = DateTimeOffset.Now,
                Items           = new List <GarmentSewingOutItemValueObject>
                {
                    new GarmentSewingOutItemValueObject
                    {
                        Product        = new Product(1, "ProductCode", "ProductName"),
                        Uom            = new Uom(1, "UomUnit"),
                        SewingInId     = sewingInId,
                        SewingInItemId = sewingInItemGuid,
                        Color          = "Color",
                        Size           = new SizeValueObject(1, "Size"),
                        IsSave         = true,
                        Quantity       = 1,
                        DesignColor    = "ColorD",
                        Details        = new List <GarmentSewingOutDetailValueObject>
                        {
                            new GarmentSewingOutDetailValueObject
                            {
                                Size     = new SizeValueObject(1, "Size"),
                                Uom      = new Uom(1, "UomUnit"),
                                Quantity = 1
                            }
                        }
                    }
                },
            };

            UpdateGarmentSewingOutCommand.SetIdentity(sewingOutGuid);

            _mockSewingOutRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingOutReadModel>()
            {
                new GarmentSewingOutReadModel(sewingOutGuid)
            }.AsQueryable());
            _mockSewingOutItemRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentSewingOutItemReadModel, bool> > >()))
            .Returns(new List <GarmentSewingOutItem>()
            {
                new GarmentSewingOutItem(Guid.Empty, sewingOutGuid, Guid.Empty, sewingInItemGuid, new ProductId(1), null, null, null, new SizeId(1), null, 1, new UomId(1), null, null, 1, 1, 1)
            });
            _mockSewingOutDetailRepository
            .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentSewingOutDetailReadModel, bool> > >()))
            .Returns(new List <GarmentSewingOutDetail>()
            {
                new GarmentSewingOutDetail(Guid.Empty, Guid.Empty, new SizeId(1), null, 1, new UomId(1), null)
            });

            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(UpdateGarmentSewingOutCommand.Unit.Id),
                UpdateGarmentSewingOutCommand.Unit.Code,
                UpdateGarmentSewingOutCommand.Unit.Name,
                new GarmentComodityId(UpdateGarmentSewingOutCommand.Comodity.Id),
                UpdateGarmentSewingOutCommand.Comodity.Code,
                UpdateGarmentSewingOutCommand.Comodity.Name,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockSewingInItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingInItemReadModel>
            {
                new GarmentSewingInItemReadModel(sewingInItemGuid)
            }.AsQueryable());

            _mockSewingOutRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingOut>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingOut>()));
            _mockSewingOutItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingOutItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingOutItem>()));
            _mockSewingOutDetailRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingOutDetail>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingOutDetail>()));
            _mockSewingInItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentSewingInItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentSewingInItem>()));

            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(UpdateGarmentSewingOutCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
Example #19
0
        public async Task <GarmentSewingOut> Handle(UpdateGarmentSewingOutCommand request, CancellationToken cancellationToken)
        {
            var sewOut = _garmentSewingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentSewingOut(o)).Single();
            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();

            if (sewOut.SewingTo == "CUTTING")
            {
                Guid cutInId = _garmentCuttingInItemRepository.Query.Where(a => a.SewingOutId == sewOut.Identity).First().CutInId;

                var cutIn = _garmentCuttingInRepository.Query.Where(a => a.Identity == cutInId).Select(a => new GarmentCuttingIn(a)).Single();

                _garmentCuttingInItemRepository.Find(o => o.CutInId == cutIn.Identity).ForEach(async cutInItem =>
                {
                    cutInItem.Modify();
                    await _garmentCuttingInItemRepository.Update(cutInItem);
                });
                cutIn.SetDate(request.SewingOutDate.GetValueOrDefault());
                cutIn.Modify();
                await _garmentCuttingInRepository.Update(cutIn);
            }

            Dictionary <Guid, double> sewInItemToBeUpdated = new Dictionary <Guid, double>();

            _garmentSewingOutItemRepository.Find(o => o.SewingOutId == sewOut.Identity).ForEach(async sewOutItem =>
            {
                var item = request.Items.Where(o => o.Id == sewOutItem.Identity).Single();

                var diffSewInQuantity = item.IsSave ? (sewOutItem.Quantity - (request.IsDifferentSize ? item.TotalQuantity : item.Quantity)): sewOutItem.Quantity;

                if (sewInItemToBeUpdated.ContainsKey(sewOutItem.SewingInItemId))
                {
                    sewInItemToBeUpdated[sewOutItem.SewingInItemId] += diffSewInQuantity;
                }
                else
                {
                    sewInItemToBeUpdated.Add(sewOutItem.SewingInItemId, diffSewInQuantity);
                }

                if (!item.IsSave)
                {
                    item.Quantity = 0;

                    if (request.IsDifferentSize)
                    {
                        _garmentSewingOutDetailRepository.Find(o => o.SewingOutItemId == sewOutItem.Identity).ForEach(async sewOutDetail =>
                        {
                            if (sewOut.SewingTo == "CUTTING")
                            {
                                GarmentCuttingInDetail cuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutDetailId == sewOutDetail.Identity).Select(a => new GarmentCuttingInDetail(a)).Single();
                                cuttingInDetail.Remove();
                                await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                            }

                            sewOutDetail.Remove();
                            await _garmentSewingOutDetailRepository.Update(sewOutDetail);
                        });

                        if (sewOut.SewingTo == "CUTTING")
                        {
                            Guid cuttingInItemId = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutDetailId == item.Details.First().Id).Select(a => new GarmentCuttingInDetail(a)).First().CutInItemId;
                            GarmentCuttingInItem cuttingInItem = _garmentCuttingInItemRepository.Query.Where(a => a.Identity == cuttingInItemId).Select(a => new GarmentCuttingInItem(a)).Single();
                            cuttingInItem.Remove();
                            await _garmentCuttingInItemRepository.Update(cuttingInItem);
                        }
                    }
                    else
                    {
                        if (sewOut.SewingTo == "CUTTING")
                        {
                            GarmentCuttingInDetail cuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutItemId == sewOutItem.Identity).Select(a => new GarmentCuttingInDetail(a)).Single();
                            GarmentCuttingInItem cuttingInItem     = _garmentCuttingInItemRepository.Query.Where(a => a.Identity == cuttingInDetail.CutInItemId).Select(a => new GarmentCuttingInItem(a)).Single();
                            cuttingInDetail.Remove();
                            await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                            cuttingInItem.Remove();
                            await _garmentCuttingInItemRepository.Update(cuttingInItem);
                        }
                    }

                    sewOutItem.Remove();
                }
                else
                {
                    if (request.IsDifferentSize)
                    {
                        _garmentSewingOutDetailRepository.Find(o => o.SewingOutItemId == sewOutItem.Identity).ForEach(async sewOutDetail =>
                        {
                            if (sewOutDetail.Identity != Guid.Empty)
                            {
                                var detail = item.Details.Where(o => o.Id == sewOutDetail.Identity).SingleOrDefault();

                                if (detail != null)
                                {
                                    if (sewOut.SewingTo == "CUTTING")
                                    {
                                        GarmentCuttingInDetail cuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutDetailId == sewOutDetail.Identity).Select(a => new GarmentCuttingInDetail(a)).Single();
                                        cuttingInDetail.SetCuttingInQuantity(Convert.ToInt32(detail.Quantity));
                                        cuttingInDetail.SetPrice((item.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * detail.Quantity);
                                        cuttingInDetail.SetRemainingQuantity(Convert.ToInt32(detail.Quantity));
                                        cuttingInDetail.Modify();
                                        await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                                    }
                                    sewOutDetail.SetQuantity(detail.Quantity);
                                    sewOutDetail.SetSizeId(new SizeId(detail.Size.Id));
                                    sewOutDetail.SetSizeName(detail.Size.Size);

                                    sewOutDetail.Modify();
                                }
                                else
                                {
                                    if (sewOut.SewingTo == "CUTTING")
                                    {
                                        GarmentCuttingInDetail cuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutDetailId == sewOutDetail.Identity).Select(a => new GarmentCuttingInDetail(a)).Single();
                                        cuttingInDetail.Remove();
                                        await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                                    }
                                    sewOutDetail.Remove();
                                }
                                await _garmentSewingOutDetailRepository.Update(sewOutDetail);
                            }
                            else
                            {
                                GarmentSewingOutDetail garmentSewingOutDetail = new GarmentSewingOutDetail(
                                    Guid.NewGuid(),
                                    sewOutItem.Identity,
                                    sewOutDetail.SizeId,
                                    sewOutDetail.SizeName,
                                    sewOutDetail.Quantity,
                                    sewOutDetail.UomId,
                                    sewOutDetail.UomUnit
                                    );
                                await _garmentSewingOutDetailRepository.Update(garmentSewingOutDetail);

                                if (sewOut.SewingTo == "CUTTING")
                                {
                                    Guid cuttingInItemId = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutItemId == sewOutItem.Identity).Select(a => new GarmentCuttingInDetail(a)).First().CutInItemId;
                                    GarmentCuttingInDetail garmentCuttingInDetail = new GarmentCuttingInDetail(
                                        Guid.NewGuid(),
                                        cuttingInItemId,
                                        Guid.Empty,
                                        sewOutItem.Identity,
                                        garmentSewingOutDetail.Identity,
                                        new ProductId(item.Product.Id),
                                        item.Product.Code,
                                        item.Product.Name,
                                        item.DesignColor,
                                        null,
                                        0,
                                        new UomId(0),
                                        null,
                                        Convert.ToInt32(garmentSewingOutDetail.Quantity),
                                        garmentSewingOutDetail.UomId,
                                        garmentSewingOutDetail.UomUnit,
                                        garmentSewingOutDetail.Quantity,
                                        item.BasicPrice,
                                        (item.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * garmentSewingOutDetail.Quantity,
                                        0,
                                        item.Color
                                        );

                                    await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail);
                                }
                            }
                        });

                        foreach (var detail in item.Details)
                        {
                            if (detail.Id == Guid.Empty)
                            {
                                GarmentSewingOutDetail garmentSewingOutDetail = new GarmentSewingOutDetail(
                                    Guid.NewGuid(),
                                    sewOutItem.Identity,
                                    new SizeId(detail.Size.Id),
                                    detail.Size.Size,
                                    detail.Quantity,
                                    new UomId(detail.Uom.Id),
                                    detail.Uom.Unit
                                    );
                                await _garmentSewingOutDetailRepository.Update(garmentSewingOutDetail);

                                if (sewOut.SewingTo == "CUTTING")
                                {
                                    Guid cuttingInItemId = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutItemId == sewOutItem.Identity).Select(a => new GarmentCuttingInDetail(a)).First().CutInItemId;
                                    GarmentCuttingInDetail garmentCuttingInDetail = new GarmentCuttingInDetail(
                                        Guid.NewGuid(),
                                        cuttingInItemId,
                                        Guid.Empty,
                                        sewOutItem.Identity,
                                        garmentSewingOutDetail.Identity,
                                        new ProductId(item.Product.Id),
                                        item.Product.Code,
                                        item.Product.Name,
                                        item.DesignColor,
                                        null,
                                        0,
                                        new UomId(0),
                                        null,
                                        Convert.ToInt32(garmentSewingOutDetail.Quantity),
                                        garmentSewingOutDetail.UomId,
                                        garmentSewingOutDetail.UomUnit,
                                        garmentSewingOutDetail.Quantity,
                                        item.BasicPrice,
                                        (item.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * garmentSewingOutDetail.Quantity,
                                        0,
                                        item.Color
                                        );

                                    await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail);
                                }
                            }
                        }
                        sewOutItem.SetQuantity(item.TotalQuantity);
                        sewOutItem.SetRemainingQuantity(item.TotalQuantity);
                    }
                    else
                    {
                        sewOutItem.SetQuantity(item.Quantity);
                        sewOutItem.SetRemainingQuantity(item.Quantity);
                        if (sewOut.SewingTo == "CUTTING")
                        {
                            GarmentCuttingInDetail cuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(a => a.SewingOutItemId == sewOutItem.Identity).Select(a => new GarmentCuttingInDetail(a)).Single();
                            cuttingInDetail.SetCuttingInQuantity(Convert.ToInt32(sewOutItem.Quantity));
                            cuttingInDetail.SetPrice((item.BasicPrice + ((double)garmentComodityPrice.Price * 25 / 100)) * sewOutItem.Quantity);
                            cuttingInDetail.SetRemainingQuantity(Convert.ToInt32(sewOutItem.Quantity));

                            cuttingInDetail.Modify();
                            await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                        }
                    }

                    sewOutItem.SetPrice(item.Price);
                    sewOutItem.Modify();
                }


                await _garmentSewingOutItemRepository.Update(sewOutItem);
            });

            foreach (var sewingInItem in sewInItemToBeUpdated)
            {
                var garmentSewInItem = _garmentSewingInItemRepository.Query.Where(x => x.Identity == sewingInItem.Key).Select(s => new GarmentSewingInItem(s)).Single();
                garmentSewInItem.SetRemainingQuantity(garmentSewInItem.RemainingQuantity + sewingInItem.Value);
                garmentSewInItem.Modify();
                await _garmentSewingInItemRepository.Update(garmentSewInItem);
            }

            sewOut.SetDate(request.SewingOutDate.GetValueOrDefault());
            sewOut.Modify();
            await _garmentSewingOutRepository.Update(sewOut);

            _storage.Save();

            return(sewOut);
        }
Example #20
0
        public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            Guid finStockGuid = Guid.NewGuid();
            PlaceGarmentExpenditureGoodCommandHandler unitUnderTest = CreatePlaceGarmentExpenditureGoodCommandHandler();
            CancellationToken cancellationToken = CancellationToken.None;
            PlaceGarmentExpenditureGoodCommand placeGarmentExpenditureGoodCommand = new PlaceGarmentExpenditureGoodCommand()
            {
                RONo            = "RONo",
                Unit            = new UnitDepartment(1, "UnitCode", "UnitName"),
                Article         = "Article",
                Comodity        = new GarmentComodity(1, "ComoCode", "ComoName"),
                Buyer           = new Buyer(1, "buyerCode", "buyerName"),
                ExpenditureDate = DateTimeOffset.Now,
                Items           = new List <GarmentExpenditureGoodItemValueObject>
                {
                    new GarmentExpenditureGoodItemValueObject
                    {
                        Uom = new Uom(1, "UomUnit"),
                        FinishedGoodStockId = finStockGuid,
                        Description         = "Color",
                        Size     = new SizeValueObject(1, "Size"),
                        isSave   = true,
                        Quantity = 1,
                    }
                },
            };

            _mockExpenditureGoodRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentExpenditureGoodReadModel>().AsQueryable());

            GarmentFinishedGoodStock garmentFinishedGoodStock = new GarmentFinishedGoodStock(finStockGuid,
                                                                                             "no", placeGarmentExpenditureGoodCommand.RONo, "article", new UnitDepartmentId(placeGarmentExpenditureGoodCommand.Unit.Id), placeGarmentExpenditureGoodCommand.Unit.Code, placeGarmentExpenditureGoodCommand.Unit.Name,
                                                                                             new GarmentComodityId(placeGarmentExpenditureGoodCommand.Comodity.Id), placeGarmentExpenditureGoodCommand.Comodity.Code, placeGarmentExpenditureGoodCommand.Comodity.Name,
                                                                                             new SizeId(1), null, new UomId(1), null, 1, 1, 1);


            _mockFinishedGoodStockRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentFinishedGoodStockReadModel>()
            {
                garmentFinishedGoodStock.GetReadModel()
            }.AsQueryable());
            GarmentComodityPrice garmentComodity = new GarmentComodityPrice(
                Guid.NewGuid(),
                true,
                DateTimeOffset.Now,
                new UnitDepartmentId(placeGarmentExpenditureGoodCommand.Unit.Id),
                placeGarmentExpenditureGoodCommand.Unit.Code,
                placeGarmentExpenditureGoodCommand.Unit.Name,
                new GarmentComodityId(placeGarmentExpenditureGoodCommand.Comodity.Id),
                placeGarmentExpenditureGoodCommand.Comodity.Code,
                placeGarmentExpenditureGoodCommand.Comodity.Name,
                1000
                );

            _mockComodityPriceRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentComodityPriceReadModel>
            {
                garmentComodity.GetReadModel()
            }.AsQueryable());

            _mockExpenditureGoodRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGood>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGood>()));
            _mockExpenditureGoodItemRepository
            .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodItem>()))
            .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodItem>()));

            _mockFinishedGoodStockRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>()));

            _mockFinishedGoodStockHistoryRepository
            .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>()))
            .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>()));


            _MockStorage
            .Setup(x => x.Save())
            .Verifiable();

            // Act
            var result = await unitUnderTest.Handle(placeGarmentExpenditureGoodCommand, cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }