Exemplo n.º 1
0
        public async Task <GarmentLoading> Handle(UpdateGarmentLoadingCommand request, CancellationToken cancellationToken)
        {
            var loading = _garmentLoadingRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentLoading(o)).Single();

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

            _garmentLoadingItemRepository.Find(o => o.LoadingId == loading.Identity).ForEach(async loadingItem =>
            {
                var itemToBeDeleted = request.Items.Where(o => o.Id == loadingItem.Identity && o.IsSave == false).SingleOrDefault();

                var item = request.Items.Where(o => o.Id == loadingItem.Identity).Single();

                var diffSewingDOQuantity = itemToBeDeleted == null ? Math.Round(loadingItem.Quantity - item.Quantity, 2) : Math.Round(itemToBeDeleted.Quantity, 2);

                if (sewingDOItemToBeUpdated.ContainsKey(loadingItem.SewingDOItemId))
                {
                    sewingDOItemToBeUpdated[loadingItem.SewingDOItemId] += diffSewingDOQuantity;
                }
                else
                {
                    sewingDOItemToBeUpdated.Add(loadingItem.SewingDOItemId, diffSewingDOQuantity);
                }

                loadingItem.SetPrice(item.Price);
                loadingItem.SetQuantity(item.Quantity);
                loadingItem.SetRemainingQuantity(item.RemainingQuantity);

                loadingItem.Modify();

                if (itemToBeDeleted != null)
                {
                    loadingItem.Remove();
                }

                await _garmentLoadingItemRepository.Update(loadingItem);
            });

            foreach (var sewingDOItem in sewingDOItemToBeUpdated)
            {
                var garmentSewingDOItem = _garmentSewingDOItemRepository.Query.Where(x => x.Identity == sewingDOItem.Key).Select(s => new GarmentSewingDOItem(s)).Single();
                garmentSewingDOItem.setRemainingQuantity(Math.Round(garmentSewingDOItem.RemainingQuantity + sewingDOItem.Value, 2));
                garmentSewingDOItem.Modify();

                await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
            }

            loading.Modify();
            await _garmentLoadingRepository.Update(loading);

            _storage.Save();

            return(loading);
        }
        public async Task <GarmentSewingDO> Handle(PlaceGarmentSewingDOCommand request, CancellationToken cancellationToken)
        {
            //request.Items = request.Items.Where(item => item.IsSave == true && item.Details.Count() > 0).ToList();

            GarmentSewingDO garmentSewingDO = new GarmentSewingDO(
                Guid.NewGuid(),
                GenerateSewingDONo(request),
                request.CuttingOutId,
                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.SewingDODate.GetValueOrDefault()
                );

            foreach (var item in request.Items)
            {
                GarmentSewingDOItem garmentSewingDOItem = new GarmentSewingDOItem(
                    Guid.NewGuid(),
                    garmentSewingDO.Identity,
                    item.CuttingOutDetailId,
                    item.CuttingOutItemId,
                    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.RemainingQuantity,
                    item.BasicPrice,
                    item.Price
                    );
                await _garmentSewingDOItemRepository.Update(garmentSewingDOItem);
            }

            await _garmentSewingDORepository.Update(garmentSewingDO);

            _storage.Save();

            return(garmentSewingDO);
        }
Exemplo n.º 3
0
        public async Task <GarmentCuttingOut> Handle(RemoveGarmentCuttingOutCommand request, CancellationToken cancellationToken)
        {
            var cutOut   = _garmentCuttingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentCuttingOut(o)).Single();
            var sewingDO = _garmentSewingDORepository.Query.Where(o => o.CuttingOutId == request.Identity).Select(o => new GarmentSewingDO(o)).Single();

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

            _garmentCuttingOutItemRepository.Find(o => o.CutOutId == cutOut.Identity).ForEach(async cutOutItem =>
            {
                _garmentCuttingOutDetailRepository.Find(o => o.CutOutItemId == cutOutItem.Identity).ForEach(async cutOutDetail =>
                {
                    if (cuttingInDetailToBeUpdated.ContainsKey(cutOutItem.CuttingInDetailId))
                    {
                        cuttingInDetailToBeUpdated[cutOutItem.CuttingInDetailId] += cutOutDetail.CuttingOutQuantity;
                    }
                    else
                    {
                        cuttingInDetailToBeUpdated.Add(cutOutItem.CuttingInDetailId, cutOutDetail.CuttingOutQuantity);
                    }

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

            _garmentSewingDOItemRepository.Find(o => o.SewingDOId == sewingDO.Identity).ForEach(async sewingDOItem =>
            {
                sewingDOItem.Remove();
                await _garmentSewingDOItemRepository.Update(sewingDOItem);
            });

            sewingDO.Remove();
            await _garmentSewingDORepository.Update(sewingDO);

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

            _storage.Save();

            return(cutOut);
        }
Exemplo n.º 4
0
        public async Task <GarmentLoading> Handle(RemoveGarmentLoadingCommand request, CancellationToken cancellationToken)
        {
            var loading = _garmentLoadingRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentLoading(o)).Single();

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

            _garmentLoadingItemRepository.Find(o => o.LoadingId == loading.Identity).ForEach(async loadingItem =>
            {
                if (sewingDOItemToBeUpdated.ContainsKey(loadingItem.SewingDOItemId))
                {
                    sewingDOItemToBeUpdated[loadingItem.SewingDOItemId] += loadingItem.Quantity;
                }
                else
                {
                    sewingDOItemToBeUpdated.Add(loadingItem.SewingDOItemId, loadingItem.Quantity);
                }

                loadingItem.Remove();

                await _garmentLoadingItemRepository.Update(loadingItem);
            });

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

            loading.Remove();
            await _garmentLoadingRepository.Update(loading);

            _storage.Save();

            return(loading);
        }
        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);
        }
Exemplo n.º 6
0
        public async Task <GarmentLoading> Handle(PlaceGarmentLoadingCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.ToList();

            GarmentLoading garmentLoading = new GarmentLoading(
                Guid.NewGuid(),
                GenerateLoadingNo(request),
                request.SewingDOId,
                request.SewingDONo,
                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.LoadingDate,
                new GarmentComodityId(request.Comodity.Id),
                request.Comodity.Code,
                request.Comodity.Name
                );

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

            foreach (var item in request.Items)
            {
                if (item.IsSave)
                {
                    GarmentLoadingItem garmentLoadingItem = new GarmentLoadingItem(
                        Guid.NewGuid(),
                        garmentLoading.Identity,
                        item.SewingDOItemId,
                        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,
                        item.BasicPrice,
                        new UomId(item.Uom.Id),
                        item.Uom.Unit,
                        item.Color,
                        item.Price
                        );

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

                    await _garmentLoadingItemRepository.Update(garmentLoadingItem);
                }
            }

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

            await _garmentLoadingRepository.Update(garmentLoading);

            _storage.Save();

            return(garmentLoading);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }