Exemplo n.º 1
0
 public GarmentFinishingInItemDto(GarmentFinishingInItem garmentFinishingInItem)
 {
     Id                = garmentFinishingInItem.Identity;
     Product           = new Product(garmentFinishingInItem.ProductId.Value, garmentFinishingInItem.ProductCode, garmentFinishingInItem.ProductName);
     DesignColor       = garmentFinishingInItem.DesignColor;
     Size              = new SizeValueObject(garmentFinishingInItem.SizeId.Value, garmentFinishingInItem.SizeName);
     Quantity          = garmentFinishingInItem.Quantity;
     Uom               = new Uom(garmentFinishingInItem.UomId.Value, garmentFinishingInItem.UomUnit);
     Color             = garmentFinishingInItem.Color;
     RemainingQuantity = garmentFinishingInItem.RemainingQuantity;
     SewingOutItemId   = garmentFinishingInItem.SewingOutItemId;
     FinishingInId     = garmentFinishingInItem.FinishingInId;
     BasicPrice        = garmentFinishingInItem.BasicPrice;
     Price             = garmentFinishingInItem.Price;
 }
        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);
        }