Esempio n. 1
0
        public async Task <GarmentFinishingIn> Handle(RemoveGarmentSubconFinishingInCommand request, CancellationToken cancellationToken)
        {
            var finIn = _garmentFinishingInRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentFinishingIn(o)).Single();

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

            var finishingInItems = _garmentFinishingInItemRepository.Find(o => o.FinishingInId == finIn.Identity);

            finishingInItems.ForEach(async item =>
            {
                if (Guid.Empty != item.SubconCuttingId)
                {
                    subconCuttingSumQuantities[item.SubconCuttingId] = subconCuttingSumQuantities.GetValueOrDefault(item.SubconCuttingId) + item.Quantity;
                }

                item.Remove();

                await _garmentFinishingInItemRepository.Update(item);
            });

            //foreach (var item in finishingInItems)
            //{
            //    if (Guid.Empty != item.SubconCuttingId)
            //    {
            //        subconCuttingSumQuantities[item.SubconCuttingId] = subconCuttingSumQuantities.GetValueOrDefault(item.SubconCuttingId) + item.Quantity;
            //    }

            //    item.Remove();

            //    await _garmentFinishingInItemRepository.Update(item);
            //}

            foreach (var sumQuantity in subconCuttingSumQuantities)
            {
                var subconCutting = _garmentSubconCuttingRepository.Query.Where(x => x.Identity == sumQuantity.Key).Select(s => new GarmentSubconCutting(s)).Single();
                subconCutting.SetFinishingInQuantity(subconCutting.FinishingInQuantity - sumQuantity.Value);
                subconCutting.Modify();

                await _garmentSubconCuttingRepository.Update(subconCutting);
            }


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

            _storage.Save();

            return(finIn);
        }
        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);
        }
        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);
        }
Esempio n. 4
0
        public async Task <GarmentFinishingOut> Handle(RemoveGarmentFinishingOutCommand request, CancellationToken cancellationToken)
        {
            var finishOut = _garmentFinishingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentFinishingOut(o)).Single();

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

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

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

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

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

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

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

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

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

                        await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory);
                    }
                }


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

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

                    var qty = garmentFinishedGoodExist.Quantity - finGoodStock.Value;

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

                    await _garmentFinishedGoodStockRepository.Update(garmentFinishedGoodExist);
                }
            }


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

            _storage.Save();

            return(finishOut);
        }
        public async Task <GarmentFinishingIn> Handle(PlaceGarmentSubconFinishingInCommand request, CancellationToken cancellationToken)
        {
            var no = GenerateFinishingInNo();

            GarmentFinishingIn garmentFinishingIn = new GarmentFinishingIn(
                Guid.NewGuid(),
                no,
                request.FinishingInType,
                new UnitDepartmentId(0),
                null,
                null,
                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
                );

            var comodityPrice = _garmentComodityPriceRepository
                                .Query
                                .OrderByDescending(o => o.CreatedDate)
                                .Where(c => c.UnitId == request.Unit.Id && c.ComodityId == request.Comodity.Id)
                                .Select(c => c.Price)
                                .FirstOrDefault();

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

            foreach (var item in request.Items.Where(i => i.IsSave))
            {
                GarmentFinishingInItem garmentFinishingInItem = new GarmentFinishingInItem(
                    Guid.NewGuid(),
                    garmentFinishingIn.Identity,
                    Guid.Empty,
                    Guid.Empty,
                    item.SubconCuttingId,
                    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,
                    (double)(((decimal)item.BasicPrice + comodityPrice * (decimal)0.75) * (decimal)item.Quantity)
                    );

                if (Guid.Empty != item.SubconCuttingId)
                {
                    subconCuttingSumQuantities[item.SubconCuttingId] = subconCuttingSumQuantities.GetValueOrDefault(item.SubconCuttingId) + item.Quantity;
                }

                await _garmentFinishingInItemRepository.Update(garmentFinishingInItem);
            }

            foreach (var sumQuantity in subconCuttingSumQuantities)
            {
                var subconCutting = _garmentSubconCuttingRepository.Query.Where(x => x.Identity == sumQuantity.Key).Select(s => new GarmentSubconCutting(s)).Single();
                subconCutting.SetFinishingInQuantity(subconCutting.FinishingInQuantity + sumQuantity.Value);
                subconCutting.Modify();

                await _garmentSubconCuttingRepository.Update(subconCutting);
            }

            await _garmentFinishingInRepository.Update(garmentFinishingIn);

            _storage.Save();

            return(garmentFinishingIn);
        }
        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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public async Task <GarmentFinishingOut> Handle(PlaceGarmentFinishingOutCommand request, CancellationToken cancellationToken)
        {
            request.Items = request.Items.Where(item => item.IsSave == true).ToList();

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

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

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

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

                            await _garmentFinishingOutDetailRepository.Update(garmentFinishingOutDetail);

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

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

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

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

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

                await _garmentFinishingInItemRepository.Update(garmentFinishingInItem);
            }

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

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

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

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

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

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

                        await _garmentFinishedGoodStockRepository.Update(garmentFinishedGoodExist);

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

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

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

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

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

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

            await _garmentFinishingOutRepository.Update(garmentFinishingOut);

            _storage.Save();

            return(garmentFinishingOut);
        }
        public async Task <GarmentFinishingOut> Handle(UpdateGarmentFinishingOutCommand request, CancellationToken cancellationToken)
        {
            var finishOut = _garmentFinishingOutRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentFinishingOut(o)).Single();

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

            _garmentFinishingOutItemRepository.Find(o => o.FinishingOutId == finishOut.Identity).ForEach(async finishOutItem =>
            {
                var item = request.Items.Where(o => o.Id == finishOutItem.Identity).Single();

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

                if (finishingInItemToBeUpdated.ContainsKey(finishOutItem.FinishingInItemId))
                {
                    finishingInItemToBeUpdated[finishOutItem.FinishingInItemId] += diffSewInQuantity;
                }
                else
                {
                    finishingInItemToBeUpdated.Add(finishOutItem.FinishingInItemId, diffSewInQuantity);
                }

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

                    if (request.IsDifferentSize)
                    {
                        _garmentFinishingOutDetailRepository.Find(o => o.FinishingOutItemId == finishOutItem.Identity).ForEach(async finishOutDetail =>
                        {
                            finishOutDetail.Remove();
                            await _garmentFinishingOutDetailRepository.Update(finishOutDetail);
                        });
                    }

                    finishOutItem.Remove();
                }
                else
                {
                    if (request.IsDifferentSize)
                    {
                        _garmentFinishingOutDetailRepository.Find(o => o.FinishingOutItemId == finishOutItem.Identity).ForEach(async finishOutDetail =>
                        {
                            if (finishOutDetail.Identity != Guid.Empty)
                            {
                                var detail = item.Details.Where(o => o.Id == finishOutDetail.Identity).SingleOrDefault();

                                if (detail != null)
                                {
                                    finishOutDetail.SetQuantity(detail.Quantity);
                                    finishOutDetail.SetSizeId(new SizeId(detail.Size.Id));
                                    finishOutDetail.SetSizeName(detail.Size.Size);

                                    finishOutDetail.Modify();
                                }
                                else
                                {
                                    finishOutDetail.Remove();
                                }
                                await _garmentFinishingOutDetailRepository.Update(finishOutDetail);
                            }
                            else
                            {
                                GarmentFinishingOutDetail garmentFinishingOutDetail = new GarmentFinishingOutDetail(
                                    Guid.NewGuid(),
                                    finishOutItem.Identity,
                                    finishOutDetail.SizeId,
                                    finishOutDetail.SizeName,
                                    finishOutDetail.Quantity,
                                    finishOutDetail.UomId,
                                    finishOutDetail.UomUnit
                                    );
                                await _garmentFinishingOutDetailRepository.Update(garmentFinishingOutDetail);
                            }
                        });

                        foreach (var detail in item.Details)
                        {
                            if (detail.Id == Guid.Empty)
                            {
                                GarmentFinishingOutDetail garmentFinishingOutDetail = new GarmentFinishingOutDetail(
                                    Guid.NewGuid(),
                                    finishOutItem.Identity,
                                    new SizeId(detail.Size.Id),
                                    detail.Size.Size,
                                    detail.Quantity,
                                    new UomId(detail.Uom.Id),
                                    detail.Uom.Unit
                                    );
                                await _garmentFinishingOutDetailRepository.Update(garmentFinishingOutDetail);
                            }
                        }
                        finishOutItem.SetQuantity(item.TotalQuantity);
                        finishOutItem.SetRemainingQuantity(item.TotalQuantity);
                    }
                    else
                    {
                        finishOutItem.SetQuantity(item.Quantity);
                        finishOutItem.SetRemainingQuantity(item.Quantity);
                    }

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


                await _garmentFinishingOutItemRepository.Update(finishOutItem);
            });

            foreach (var finishingInItem in finishingInItemToBeUpdated)
            {
                var garmentSewInItem = _garmentFinishingInItemRepository.Query.Where(x => x.Identity == finishingInItem.Key).Select(s => new GarmentFinishingInItem(s)).Single();
                garmentSewInItem.SetRemainingQuantity(garmentSewInItem.RemainingQuantity + finishingInItem.Value);
                garmentSewInItem.Modify();
                await _garmentFinishingInItemRepository.Update(garmentSewInItem);
            }

            finishOut.SetDate(request.FinishingOutDate.GetValueOrDefault());
            finishOut.Modify();
            await _garmentFinishingOutRepository.Update(finishOut);

            _storage.Save();

            return(finishOut);
        }