Exemple #1
0
        public async Task <GarmentSubconCuttingOut> Handle(PlaceGarmentSubconCuttingOutCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true && item.Details.Count() > 0).ToList();

            GarmentSubconCuttingOut garmentCuttingOut = new GarmentSubconCuttingOut(
                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 GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name,
                request.EPOId,
                request.EPOItemId,
                request.POSerialNumber
                );

            Dictionary <Guid, double>         cuttingInDetailToBeUpdated = new Dictionary <Guid, double>();
            Dictionary <string, double>       cuttingSubconToBeUpdated   = new Dictionary <string, double>();
            Dictionary <string, List <Guid> > cuttingSubconToBeUpdatedId = new Dictionary <string, List <Guid> >();

            foreach (var item in request.Items)
            {
                GarmentSubconCuttingOutItem garmentCuttingOutItem = new GarmentSubconCuttingOutItem(
                    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)
                {
                    var detailId = Guid.NewGuid();
                    GarmentSubconCuttingOutDetail garmentCuttingOutDetail = new GarmentSubconCuttingOutDetail(
                        detailId,
                        garmentCuttingOutItem.Identity,
                        new SizeId(detail.Size.Id),
                        detail.Size.Size,
                        detail.Color,
                        detail.CuttingOutQuantity,
                        detail.CuttingOutQuantity,
                        new UomId(detail.CuttingOutUom.Id),
                        detail.CuttingOutUom.Unit,
                        detail.BasicPrice,
                        detail.Price,
                        detail.Remark.ToUpper()
                        );

                    string key = request.RONo + "~" + detail.Size.Id.ToString() + "~" + detail.Size.Size + "~"
                                 + item.Product.Id.ToString() + "~" + item.Product.Code + "~" + item.Product.Name + "~"
                                 + request.Comodity.Id.ToString() + "~" + request.Comodity.Code + "~" + request.Comodity.Name + "~"
                                 + item.DesignColor + "~" + detail.Remark.ToUpper() + "~" + detail.BasicPrice;

                    if (cuttingSubconToBeUpdated.ContainsKey(key))
                    {
                        cuttingSubconToBeUpdated[key] += detail.CuttingOutQuantity;
                        cuttingSubconToBeUpdatedId[key].Add(detailId);
                    }
                    else
                    {
                        cuttingSubconToBeUpdated.Add(key, detail.CuttingOutQuantity);
                        cuttingSubconToBeUpdatedId.Add(key, new List <Guid> {
                            detailId
                        });
                    }

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

                    await _garmentCuttingOutDetailRepository.Update(garmentCuttingOutDetail);
                }

                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);
            }

            foreach (var subconCutting in cuttingSubconToBeUpdated)
            {
                var RONo         = subconCutting.Key.Split("~")[0];
                var SizeId       = subconCutting.Key.Split("~")[1];
                var SizeName     = subconCutting.Key.Split("~")[2];
                var ProductId    = subconCutting.Key.Split("~")[3];
                var ProductCode  = subconCutting.Key.Split("~")[4];
                var ProductName  = subconCutting.Key.Split("~")[5];
                var ComodityId   = subconCutting.Key.Split("~")[6];
                var ComodityCode = subconCutting.Key.Split("~")[7];
                var ComodityName = subconCutting.Key.Split("~")[8];
                var designColor  = subconCutting.Key.Split("~")[9];
                var remark       = subconCutting.Key.Split("~")[10];
                var basicPrice   = subconCutting.Key.Split("~")[11];

                GarmentSubconCutting garmentSubconCutting = _garmentSubconCuttingRepository.Query.Where(a => a.RONo == RONo && a.SizeId == Convert.ToInt32(SizeId) && a.ComodityId == Convert.ToInt32(ComodityId) && a.ProductId == Convert.ToInt32(ProductId) && a.Remark == remark && a.DesignColor == designColor && a.BasicPrice == Convert.ToDouble(basicPrice)).Select(a => new GarmentSubconCutting(a)).FirstOrDefault();
                if (garmentSubconCutting == null)
                {
                    garmentSubconCutting = new GarmentSubconCutting(
                        Guid.NewGuid(),
                        request.RONo,
                        new SizeId(Convert.ToInt32(SizeId)),
                        SizeName,
                        subconCutting.Value,
                        new ProductId(Convert.ToInt32(ProductId)),
                        ProductCode,
                        ProductName,
                        new GarmentComodityId(Convert.ToInt32(ComodityId)),
                        ComodityCode,
                        ComodityName,
                        designColor,
                        remark,
                        Convert.ToDouble(basicPrice)
                        );
                    await _garmentSubconCuttingRepository.Update(garmentSubconCutting);
                }
                else
                {
                    garmentSubconCutting.SetQuantity(garmentSubconCutting.Quantity + subconCutting.Value);
                    garmentSubconCutting.Modify();
                    await _garmentSubconCuttingRepository.Update(garmentSubconCutting);
                }

                foreach (var detailId in cuttingSubconToBeUpdatedId[subconCutting.Key] ?? new List <Guid>())
                {
                    GarmentSubconCuttingRelation garmentSubconCuttingRelation = new GarmentSubconCuttingRelation(Guid.NewGuid(), garmentSubconCutting.Identity, detailId);
                    await _garmentSubconCuttingRelationRepository.Update(garmentSubconCuttingRelation);
                }
            }

            await _garmentCuttingOutRepository.Update(garmentCuttingOut);

            _storage.Save();

            return(garmentCuttingOut);
        }
Exemple #2
0
        public async Task <GarmentSubconCuttingOut> Handle(RemoveGarmentSubconCuttingOutCommand request, CancellationToken cancellationToken)
        {
            var cutOut = _garmentCuttingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentSubconCuttingOut(o)).Single();

            Dictionary <Guid, double>         cuttingInDetailToBeUpdated = new Dictionary <Guid, double>();
            Dictionary <string, double>       cuttingSubconToBeUpdated   = new Dictionary <string, double>();
            Dictionary <string, List <Guid> > cuttingSubconToBeUpdatedId = new Dictionary <string, List <Guid> >();

            _garmentCuttingOutItemRepository.Find(o => o.CutOutId == cutOut.Identity).ForEach(async cutOutItem =>
            {
                _garmentCuttingOutDetailRepository.Find(o => o.CutOutItemId == cutOutItem.Identity).ForEach(async cutOutDetail =>
                {
                    string key = cutOut.RONo + "~" + cutOutDetail.SizeId.Value.ToString() + "~" + cutOutDetail.SizeName + "~"
                                 + cutOutItem.ProductId.Value.ToString() + "~" + cutOutItem.ProductCode + "~" + cutOutItem.ProductName + "~"
                                 + cutOut.ComodityId.Value.ToString() + "~" + cutOut.ComodityCode + "~" + cutOut.ComodityName + "~"
                                 + cutOutItem.DesignColor + "~" + cutOutDetail.Remark + "~" + cutOutDetail.BasicPrice;

                    if (cuttingSubconToBeUpdated.ContainsKey(key))
                    {
                        cuttingSubconToBeUpdated[key] += cutOutDetail.CuttingOutQuantity;
                        cuttingSubconToBeUpdatedId[key].Add(cutOutDetail.Identity);
                    }
                    else
                    {
                        cuttingSubconToBeUpdated.Add(key, cutOutDetail.CuttingOutQuantity);
                        cuttingSubconToBeUpdatedId.Add(key, new List <Guid> {
                            cutOutDetail.Identity
                        });
                    }

                    if (cuttingInDetailToBeUpdated.ContainsKey(cutOutItem.CuttingInDetailId))
                    {
                        cuttingInDetailToBeUpdated[cutOutItem.CuttingInDetailId] += cutOutDetail.RemainingQuantity;
                    }
                    else
                    {
                        cuttingInDetailToBeUpdated.Add(cutOutItem.CuttingInDetailId, cutOutDetail.RemainingQuantity);
                    }

                    cutOutDetail.Remove();
                    await _garmentCuttingOutDetailRepository.Update(cutOutDetail);
                });

                cutOutItem.Remove();
                await _garmentCuttingOutItemRepository.Update(cutOutItem);
            });

            foreach (var cuttingInItem in cuttingInDetailToBeUpdated)
            {
                var garmentCuttingInDetail = _garmentCuttingInDetailRepository.Query.Where(x => x.Identity == cuttingInItem.Key).Select(s => new GarmentCuttingInDetail(s)).Single();
                garmentCuttingInDetail.SetRemainingQuantity(garmentCuttingInDetail.RemainingQuantity + cuttingInItem.Value);
                garmentCuttingInDetail.Modify();
                await _garmentCuttingInDetailRepository.Update(garmentCuttingInDetail);
            }

            foreach (var subconCutting in cuttingSubconToBeUpdated)
            {
                var RONo         = subconCutting.Key.Split("~")[0];
                var SizeId       = subconCutting.Key.Split("~")[1];
                var SizeName     = subconCutting.Key.Split("~")[2];
                var ProductId    = subconCutting.Key.Split("~")[3];
                var ProductCode  = subconCutting.Key.Split("~")[4];
                var ProductName  = subconCutting.Key.Split("~")[5];
                var ComodityId   = subconCutting.Key.Split("~")[6];
                var ComodityCode = subconCutting.Key.Split("~")[7];
                var ComodityName = subconCutting.Key.Split("~")[8];
                var designColor  = subconCutting.Key.Split("~")[9];
                var remark       = subconCutting.Key.Split("~")[10];
                var basicPrice   = subconCutting.Key.Split("~")[11];

                GarmentSubconCutting garmentSubconCutting = _garmentSubconCuttingRepository.Query.Where(a => a.RONo == RONo && a.SizeId == Convert.ToInt32(SizeId) && a.ComodityId == Convert.ToInt32(ComodityId) && a.ProductId == Convert.ToInt32(ProductId) && a.Remark == remark && a.DesignColor == designColor && a.BasicPrice == Convert.ToDouble(basicPrice)).Select(a => new GarmentSubconCutting(a)).FirstOrDefault();

                garmentSubconCutting.SetQuantity(garmentSubconCutting.Quantity - subconCutting.Value);
                garmentSubconCutting.Modify();
                await _garmentSubconCuttingRepository.Update(garmentSubconCutting);

                foreach (var detailId in cuttingSubconToBeUpdatedId[subconCutting.Key] ?? new List <Guid>())
                {
                    GarmentSubconCuttingRelation garmentSubconCuttingRelation = _garmentSubconCuttingRelationRepository.Query.Where(w => w.GarmentSubconCuttingId == garmentSubconCutting.Identity && w.GarmentCuttingOutDetailId == detailId).Select(s => new GarmentSubconCuttingRelation(s)).FirstOrDefault();
                    if (garmentSubconCuttingRelation != null)
                    {
                        garmentSubconCuttingRelation.Remove();
                        await _garmentSubconCuttingRelationRepository.Update(garmentSubconCuttingRelation);
                    }
                }
            }

            cutOut.Remove();
            await _garmentCuttingOutRepository.Update(cutOut);

            _storage.Save();

            return(cutOut);
        }