Exemple #1
0
        public void Generate_Return_Success()
        {
            Guid id  = Guid.NewGuid();
            var  dto = new GarmentSewingOutDto(new GarmentSewingOut(id, "sewingOutNo", new BuyerId(1), "BuyerCode", "BuyerName", new UnitDepartmentId(1), "unitToCode", "unitToName", "SewingTo", DateTimeOffset.Now, "RoNo", "Article", new UnitDepartmentId(1), "unitCode", "unitName", new GarmentComodityId(1), "comodityCode", "ComodityName", false));

            var garmentSewingOutItem = new GarmentSewingOutItem(id, id, id, id, new ProductId(1), "productCode", "productName", "designColor", new SizeId(1), "sizeName", 1, new UomId(1), "uomUnit", "Color", 1, 1, 1);
            var items = new List <GarmentSewingOutItemDto>()
            {
                new GarmentSewingOutItemDto(garmentSewingOutItem)
            };

            dto.GetType().GetProperty("Items").SetValue(dto, items);

            var result = GarmentSewingOutPDFTemplate.Generate(dto, "Buyer");

            Assert.NotNull(result);
        }
        public async Task Get_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateGarmentSewingOutController();

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

            Guid sewingOutGuid = Guid.NewGuid();

            _mockGarmentSewingOutRepository
            .Setup(s => s.Find(It.IsAny <IQueryable <GarmentSewingOutReadModel> >()))
            .Returns(new List <GarmentSewingOut>()
            {
                new GarmentSewingOut(sewingOutGuid, null, new BuyerId(1), null, null, new UnitDepartmentId(1), null, null, "Finishing", DateTimeOffset.Now, "RONo", null, new UnitDepartmentId(1), null, null, new GarmentComodityId(1), null, null, true)
            });

            Guid sewingInItemGuid  = Guid.NewGuid();
            Guid sewingInGuid      = Guid.NewGuid();
            Guid sewingOutItemGuid = Guid.NewGuid();
            GarmentSewingOutItem garmentSewingOutItem = new GarmentSewingOutItem(sewingOutItemGuid, sewingOutGuid, sewingInGuid, sewingInItemGuid, new ProductId(1), null, null, null, new SizeId(1), null, 1, new UomId(1), null, null, 1, 1, 1);

            _mockGarmentSewingOutItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingOutItemReadModel>()
            {
                garmentSewingOutItem.GetReadModel()
            }.AsQueryable());

            GarmentSewingOutDetail garmentSewingOutDetail = new GarmentSewingOutDetail(Guid.NewGuid(), sewingOutItemGuid, new SizeId(1), null, 1, new UomId(1), null);

            _mockGarmentSewingOutDetailRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingOutDetailReadModel>()
            {
                garmentSewingOutDetail.GetReadModel()
            }.AsQueryable());

            // Act
            var result = await unitUnderTest.Get();

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result));
        }
        public GarmentSewingOutItemDto(GarmentSewingOutItem garmentSewingOutItem)
        {
            Id                = garmentSewingOutItem.Identity;
            SewingOutId       = garmentSewingOutItem.SewingOutId;
            SewingInId        = garmentSewingOutItem.SewingInId;
            SewingInItemId    = garmentSewingOutItem.SewingInItemId;
            Product           = new Product(garmentSewingOutItem.ProductId.Value, garmentSewingOutItem.ProductCode, garmentSewingOutItem.ProductName);
            Size              = new SizeValueObject(garmentSewingOutItem.SizeId.Value, garmentSewingOutItem.SizeName);
            DesignColor       = garmentSewingOutItem.DesignColor;
            Quantity          = garmentSewingOutItem.Quantity;
            Uom               = new Uom(garmentSewingOutItem.UomId.Value, garmentSewingOutItem.UomUnit);
            Color             = garmentSewingOutItem.Color;
            RemainingQuantity = garmentSewingOutItem.RemainingQuantity;
            BasicPrice        = garmentSewingOutItem.BasicPrice;
            Price             = garmentSewingOutItem.Price;

            Details = new List <GarmentSewingOutDetailDto>();
        }
        public async Task GetComplete_Return_Success()
        {
            var  unitUnderTest = CreateGarmentSewingOutController();
            Guid id            = Guid.NewGuid();

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


            _mockGarmentSewingOutRepository
            .Setup(s => s.Find(It.IsAny <IQueryable <GarmentSewingOutReadModel> >()))
            .Returns(new List <GarmentSewingOut>()
            {
                new GarmentSewingOut(id, null, new BuyerId(1), null, null, new UnitDepartmentId(1), null, null, "Finishing", DateTimeOffset.Now, "RONo", null, new UnitDepartmentId(1), null, null, new GarmentComodityId(1), null, null, true)
            });

            GarmentSewingOutItem garmentSewingOutItem = new GarmentSewingOutItem(id, id, id, id, new ProductId(1), null, null, null, new SizeId(1), null, 1, new UomId(1), null, null, 1, 1, 1);

            _mockGarmentSewingOutItemRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingOutItemReadModel>()
            {
                garmentSewingOutItem.GetReadModel()
            }.AsQueryable());

            _mockGarmentSewingOutItemRepository
            .Setup(s => s.Find(It.IsAny <IQueryable <GarmentSewingOutItemReadModel> >()))
            .Returns(new List <GarmentSewingOutItem>()
            {
                new GarmentSewingOutItem(id, id, id, id, new ProductId(1), "productCode", "productName", "designColor", new SizeId(1), "sizeName", 1, new UomId(1), "uomUnit", "color", 1, 1, 1)
            });


            GarmentSewingOutDetail garmentSewingOutDetail = new GarmentSewingOutDetail(id, id, new SizeId(1), "sizeName", 1, new UomId(1), "uomUnit");

            _mockGarmentSewingOutDetailRepository
            .Setup(s => s.Query)
            .Returns(new List <GarmentSewingOutDetailReadModel>()
            {
                garmentSewingOutDetail.GetReadModel()
            }.AsQueryable());

            _mockGarmentSewingOutDetailRepository
            .Setup(s => s.Find(It.IsAny <IQueryable <GarmentSewingOutDetailReadModel> >()))
            .Returns(new List <GarmentSewingOutDetail>()
            {
                new GarmentSewingOutDetail(id, id, new SizeId(1), "sizeName", 1, new UomId(1), "uomUnit")
            });

            // Act
            var orderData = new
            {
                article = "desc",
            };

            string order  = JsonConvert.SerializeObject(orderData);
            var    result = await unitUnderTest.GetComplete(1, 25, order, new List <string>(), "", "{}");

            // Assert
            GetStatusCode(result).Should().Equals((int)HttpStatusCode.OK);
        }
Exemple #5
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);
        }