public async Task <GarmentSewingIn> Handle(RemoveGarmentSewingInCommand request, CancellationToken cancellationToken)
        {
            var garmentSewingIn = _garmentSewingInRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentSewingIn(o)).Single();

            if (garmentSewingIn == null)
            {
                throw Validator.ErrorValidation(("Id", "Invalid Id: " + request.Identity));
            }

            var garmentSewingInItems = _garmentSewingInItemRepository.Find(x => x.SewingInId == request.Identity);

            foreach (var item in garmentSewingInItems)
            {
                item.Remove();

                if (garmentSewingIn.SewingFrom == "CUTTING")
                {
                    var garmentLoadingItem = _garmentLoadingItemRepository.Query.Where(o => o.Identity == item.LoadingItemId).Select(s => new GarmentLoadingItem(s)).Single();

                    garmentLoadingItem.SetRemainingQuantity(garmentLoadingItem.RemainingQuantity + item.Quantity);

                    garmentLoadingItem.Modify();
                    await _garmentLoadingItemRepository.Update(garmentLoadingItem);
                }
                else if (garmentSewingIn.SewingFrom == "SEWING")
                {
                    var garmentSewingOutItem = _garmentSewingOutItemRepository.Query.Where(s => s.Identity == item.SewingOutItemId).Select(s => new GarmentSewingOutItem(s)).Single();

                    garmentSewingOutItem.SetRemainingQuantity(garmentSewingOutItem.RemainingQuantity + item.Quantity);

                    garmentSewingOutItem.Modify();
                    await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
                }
                else if (garmentSewingIn.SewingFrom == "FINISHING")
                {
                    var garmentFinishingOutItem = _garmentFinishingOutItemRepository.Query.Where(s => s.Identity == item.FinishingOutItemId).Select(s => new GarmentFinishingOutItem(s)).Single();

                    garmentFinishingOutItem.SetRemainingQuantity(garmentFinishingOutItem.RemainingQuantity + item.Quantity);

                    garmentFinishingOutItem.Modify();
                    await _garmentFinishingOutItemRepository.Update(garmentFinishingOutItem);
                }

                await _garmentSewingInItemRepository.Update(item);
            }

            garmentSewingIn.Remove();

            await _garmentSewingInRepository.Update(garmentSewingIn);

            _storage.Save();

            return(garmentSewingIn);
        }
        public async Task <GarmentFinishingIn> Handle(RemoveGarmentFinishingInCommand request, CancellationToken cancellationToken)
        {
            var finIn = _garmentFinishingInRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentFinishingIn(o)).Single();

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

            _garmentFinishingInItemRepository.Find(o => o.FinishingInId == finIn.Identity).ForEach(async finishingInItem =>
            {
                if (sewingOutItemToBeUpdated.ContainsKey(finishingInItem.SewingOutItemId))
                {
                    sewingOutItemToBeUpdated[finishingInItem.SewingOutItemId] += finishingInItem.Quantity;
                }
                else
                {
                    sewingOutItemToBeUpdated.Add(finishingInItem.SewingOutItemId, finishingInItem.Quantity);
                }

                finishingInItem.Remove();

                await _garmentFinishingInItemRepository.Update(finishingInItem);
            });

            foreach (var sewingOutItem in sewingOutItemToBeUpdated)
            {
                var garmentSewingOutItem = _garmentSewingOutItemRepository.Query.Where(x => x.Identity == sewingOutItem.Key).Select(s => new GarmentSewingOutItem(s)).Single();
                garmentSewingOutItem.SetRemainingQuantity(garmentSewingOutItem.RemainingQuantity + sewingOutItem.Value);
                garmentSewingOutItem.Modify();

                await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
            }

            finIn.Remove();
            await _garmentFinishingInRepository.Update(finIn);

            _storage.Save();

            return(finIn);
        }
コード例 #3
0
        public async Task <GarmentAvalComponent> Handle(PlaceGarmentAvalComponentCommand request, CancellationToken cancellationToken)
        {
            GarmentComodity garmentComodity = request.Comodity ?? new GarmentComodity(0, null, null);

            var avalComponentNo = GenerateNo(request);

            GarmentAvalComponent garmentAvalComponent = new GarmentAvalComponent(
                Guid.NewGuid(),
                avalComponentNo,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.AvalComponentType,
                request.RONo,
                request.Article,
                new GarmentComodityId(garmentComodity.Id),
                garmentComodity.Code,
                garmentComodity.Name,
                request.Date.GetValueOrDefault()
                );

            foreach (var item in request.Items.Where(w => w.IsSave))
            {
                SizeValueObject sizeValueObject = item.Size ?? new SizeValueObject(0, null);

                GarmentAvalComponentItem garmentAvalComponentItem = new GarmentAvalComponentItem(
                    Guid.NewGuid(),
                    garmentAvalComponent.Identity,
                    item.CuttingInDetailId,
                    item.SewingOutItemId,
                    item.SewingOutDetailId,
                    new ProductId(item.Product.Id),
                    item.Product.Code,
                    item.Product.Name,
                    item.DesignColor,
                    item.Color,
                    item.Quantity,
                    item.Quantity,
                    new SizeId(sizeValueObject.Id),
                    sizeValueObject.Size,
                    item.Price,
                    item.BasicPrice
                    );

                await _garmentAvalComponentItemRepository.Update(garmentAvalComponentItem);

                if (garmentAvalComponent.AvalComponentType == "CUTTING")
                {
                    var cuttingInDetail = _garmentCuttingInDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.CuttingInDetailId).SingleOrDefault();

                    if (cuttingInDetail == null)
                    {
                        throw new Exception($"CuttingInDetail {garmentAvalComponentItem.CuttingInDetailId} not found");
                    }
                    else
                    {
                        cuttingInDetail.SetRemainingQuantity(cuttingInDetail.RemainingQuantity - garmentAvalComponentItem.Quantity);
                        cuttingInDetail.Modify();
                        await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                    }
                }
                else if (garmentAvalComponent.AvalComponentType == "SEWING")
                {
                    //if (item.IsDifferentSize)
                    //{
                    //    var sewingOutDetail = _garmentSewingOutDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutDetailId).SingleOrDefault();

                    //    if (sewingOutDetail == null)
                    //    {
                    //        throw new Exception($"SewingOutDetail {garmentAvalComponentItem.SewingOutDetailId} not found");
                    //    }
                    //    //else
                    //    //{
                    //    //    sewingOutDetail.Modify();
                    //    //    await _garmentSewingOutDetailRepository.Update(sewingOutDetail);
                    //    //}
                    //}
                    //else
                    //{
                    var sewingOutItem = _garmentSewingOutItemRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutItemId).SingleOrDefault();

                    if (sewingOutItem == null)
                    {
                        throw new Exception($"SewingOutItem {garmentAvalComponentItem.SewingOutItemId} not found");
                    }
                    else
                    {
                        sewingOutItem.SetRemainingQuantity(sewingOutItem.RemainingQuantity - garmentAvalComponentItem.Quantity);
                        sewingOutItem.Modify();
                        await _garmentSewingOutItemRepository.Update(sewingOutItem);
                    }
                    //}
                }
            }

            await _garmentAvalComponentRepository.Update(garmentAvalComponent);

            _storage.Save();

            return(garmentAvalComponent);
        }
コード例 #4
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);
        }
コード例 #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);
        }
        public async Task <GarmentFinishingIn> Handle(PlaceGarmentFinishingInCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();

            GarmentFinishingIn garmentFinishingIn = new GarmentFinishingIn(
                Guid.NewGuid(),
                GenerateFinishingInNo(request),
                request.FinishingInType,
                new UnitDepartmentId(request.UnitFrom.Id),
                request.UnitFrom.Code,
                request.UnitFrom.Name,
                request.RONo,
                request.Article,
                new UnitDepartmentId(request.Unit.Id),
                request.Unit.Code,
                request.Unit.Name,
                request.FinishingInDate.GetValueOrDefault(),
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                request.DOId,
                request.DONo
                );

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

            foreach (var item in request.Items)
            {
                GarmentFinishingInItem garmentFinishingInItem = new GarmentFinishingInItem(
                    Guid.NewGuid(),
                    garmentFinishingIn.Identity,
                    item.SewingOutItemId,
                    item.SewingOutDetailId,
                    Guid.Empty,
                    new SizeId(item.Size.Id),
                    item.Size.Size,
                    new ProductId(item.Product.Id),
                    item.Product.Code,
                    item.Product.Name,
                    item.DesignColor,
                    item.Quantity,
                    item.RemainingQuantity,
                    new UomId(item.Uom.Id),
                    item.Uom.Unit,
                    item.Color,
                    item.BasicPrice,
                    item.Price
                    );

                if (sewingOutItemToBeUpdated.ContainsKey(item.SewingOutItemId))
                {
                    sewingOutItemToBeUpdated[item.SewingOutItemId] += item.Quantity;
                }
                else
                {
                    sewingOutItemToBeUpdated.Add(item.SewingOutItemId, item.Quantity);
                }

                await _garmentFinishingInItemRepository.Update(garmentFinishingInItem);
            }

            foreach (var sewingDOItem in sewingOutItemToBeUpdated)
            {
                var garmentSewingOutItem = _garmentSewingOutItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingOutItem(s)).Single();
                garmentSewingOutItem.SetRemainingQuantity(garmentSewingOutItem.RemainingQuantity - sewingDOItem.Value);
                garmentSewingOutItem.Modify();

                await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
            }

            await _garmentFinishingInRepository.Update(garmentFinishingIn);

            _storage.Save();

            return(garmentFinishingIn);
        }
        public async Task <GarmentSewingIn> Handle(PlaceGarmentSewingInCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true).ToList();

            GarmentSewingIn garmentSewingIn = new GarmentSewingIn(
                Guid.NewGuid(),
                GenerateSewingInNo(request),
                request.SewingFrom,
                request.LoadingId,
                request.LoadingNo,
                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.SewingInDate.GetValueOrDefault()
                );

            foreach (var item in request.Items)
            {
                GarmentSewingInItem garmentSewingInItem = new GarmentSewingInItem(
                    Guid.NewGuid(),
                    garmentSewingIn.Identity,
                    item.SewingOutItemId,
                    item.SewingOutDetailId,
                    item.LoadingItemId,
                    item.FinishingOutItemId,
                    item.FinishingOutDetailId,
                    new ProductId(item.Product.Id),
                    item.Product.Code,
                    item.Product.Name,
                    item.DesignColor,
                    new SizeId(item.Size.Id),
                    item.Size.Size,
                    item.Quantity,
                    new UomId(item.Uom.Id),
                    item.Uom.Unit,
                    item.Color,
                    item.Quantity,
                    item.BasicPrice,
                    item.Price
                    );

                if (request.SewingFrom == "CUTTING")
                {
                    var garmentLoadingItem = _garmentLoadingItemRepository.Query.Where(o => o.Identity == item.LoadingItemId).Select(s => new GarmentLoadingItem(s)).Single();

                    garmentLoadingItem.SetRemainingQuantity(garmentLoadingItem.RemainingQuantity - item.Quantity);

                    garmentLoadingItem.Modify();
                    await _garmentLoadingItemRepository.Update(garmentLoadingItem);
                }
                else if (request.SewingFrom == "SEWING")
                {
                    var garmentSewingOutItem = _garmentSewingOutItemRepository.Query.Where(s => s.Identity == item.SewingOutItemId).Select(s => new GarmentSewingOutItem(s)).Single();

                    garmentSewingOutItem.SetRemainingQuantity(garmentSewingOutItem.RemainingQuantity - item.Quantity);

                    garmentSewingOutItem.Modify();
                    await _garmentSewingOutItemRepository.Update(garmentSewingOutItem);
                }
                else if (request.SewingFrom == "FINISHING")
                {
                    var garmentFinishingOutItem = _garmentFinishingOutItemRepository.Query.Where(s => s.Identity == item.FinishingOutItemId).Select(s => new GarmentFinishingOutItem(s)).Single();

                    garmentFinishingOutItem.SetRemainingQuantity(garmentFinishingOutItem.RemainingQuantity - item.Quantity);

                    garmentFinishingOutItem.Modify();
                    await _garmentFinishingOutItemRepository.Update(garmentFinishingOutItem);
                }

                await _garmentSewingInItemRepository.Update(garmentSewingInItem);
            }

            await _garmentSewingInRepository.Update(garmentSewingIn);

            _storage.Save();

            return(garmentSewingIn);
        }
コード例 #8
0
        public async Task <GarmentSewingOut> Handle(RemoveGarmentSewingOutCommand request, CancellationToken cancellationToken)
        {
            var sewOut = _garmentSewingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentSewingOut(o)).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 =>
                {
                    _garmentCuttingInDetailRepository.Find(o => o.CutInItemId == cutInItem.Identity).ForEach(async cutInDetail =>
                    {
                        cutInDetail.Remove();
                        await _garmentCuttingInDetailRepository.Update(cutInDetail);
                    });

                    cutInItem.Remove();
                    await _garmentCuttingInItemRepository.Update(cutInItem);
                });

                cutIn.Remove();
                await _garmentCuttingInRepository.Update(cutIn);
            }

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

            _garmentSewingOutItemRepository.Find(o => o.SewingOutId == sewOut.Identity).ForEach(async sewOutItem =>
            {
                if (sewOut.IsDifferentSize)
                {
                    _garmentSewingOutDetailRepository.Find(o => o.SewingOutItemId == sewOutItem.Identity).ForEach(async sewOutDetail =>
                    {
                        if (sewInItemToBeUpdated.ContainsKey(sewOutItem.SewingInItemId))
                        {
                            sewInItemToBeUpdated[sewOutItem.SewingInItemId] += sewOutDetail.Quantity;
                        }
                        else
                        {
                            sewInItemToBeUpdated.Add(sewOutItem.SewingInItemId, sewOutDetail.Quantity);
                        }

                        sewOutDetail.Remove();
                        await _garmentSewingOutDetailRepository.Update(sewOutDetail);
                    });
                }
                else
                {
                    if (sewInItemToBeUpdated.ContainsKey(sewOutItem.SewingInItemId))
                    {
                        sewInItemToBeUpdated[sewOutItem.SewingInItemId] += sewOutItem.Quantity;
                    }
                    else
                    {
                        sewInItemToBeUpdated.Add(sewOutItem.SewingInItemId, sewOutItem.Quantity);
                    }
                }


                sewOutItem.Remove();
                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.Remove();
            await _garmentSewingOutRepository.Update(sewOut);

            _storage.Save();

            return(sewOut);
        }
コード例 #9
0
        public async Task <GarmentAvalComponent> Handle(RemoveGarmentAvalComponentCommand request, CancellationToken cancellationToken)
        {
            GarmentAvalComponent garmentAvalComponent = _garmentAvalComponentRepository.Query.Where(w => w.Identity == request.Identity).Select(s => new GarmentAvalComponent(s)).Single();

            _garmentAvalComponentItemRepository.Find(f => f.AvalComponentId == garmentAvalComponent.Identity).ForEach(async garmentAvalComponentItem =>
            {
                garmentAvalComponentItem.Remove();
                await _garmentAvalComponentItemRepository.Update(garmentAvalComponentItem);

                if (garmentAvalComponent.AvalComponentType == "CUTTING")
                {
                    var cuttingInDetail = _garmentCuttingInDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.CuttingInDetailId).SingleOrDefault();

                    if (cuttingInDetail == null)
                    {
                        throw new Exception($"CuttingInDetail {garmentAvalComponentItem.CuttingInDetailId} not found");
                    }
                    else
                    {
                        cuttingInDetail.SetRemainingQuantity(cuttingInDetail.RemainingQuantity + garmentAvalComponentItem.Quantity);
                        cuttingInDetail.Modify();
                        await _garmentCuttingInDetailRepository.Update(cuttingInDetail);
                    }
                }
                else if (garmentAvalComponent.AvalComponentType == "SEWING")
                {
                    //if (item.IsDifferentSize)
                    //{
                    //    var sewingOutDetail = _garmentSewingOutDetailRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutDetailId).SingleOrDefault();

                    //    if (sewingOutDetail == null)
                    //    {
                    //        throw new Exception($"SewingOutDetail {garmentAvalComponentItem.SewingOutDetailId} not found");
                    //    }
                    //    //else
                    //    //{
                    //    //    sewingOutDetail.Modify();
                    //    //    await _garmentSewingOutDetailRepository.Update(sewingOutDetail);
                    //    //}
                    //}
                    //else
                    //{
                    var sewingOutItem = _garmentSewingOutItemRepository.Find(f => f.Identity == garmentAvalComponentItem.SewingOutItemId).SingleOrDefault();

                    if (sewingOutItem == null)
                    {
                        throw new Exception($"SewingOutItem {garmentAvalComponentItem.SewingOutItemId} not found");
                    }
                    else
                    {
                        sewingOutItem.SetRemainingQuantity(sewingOutItem.RemainingQuantity + garmentAvalComponentItem.Quantity);
                        sewingOutItem.Modify();
                        await _garmentSewingOutItemRepository.Update(sewingOutItem);
                    }
                    //}
                }
            });

            garmentAvalComponent.Remove();
            await _garmentAvalComponentRepository.Update(garmentAvalComponent);

            _storage.Save();

            return(garmentAvalComponent);
        }