public async Task <GarmentExpenditureGood> Handle(RemoveGarmentExpenditureGoodCommand request, CancellationToken cancellationToken) { var ExpenditureGood = _garmentExpenditureGoodRepository.Query.Where(o => o.Identity == request.Identity).Select(o => new GarmentExpenditureGood(o)).Single(); GarmentComodityPrice garmentComodityPrice = _garmentComodityPriceRepository.Query.Where(a => a.IsValid == true && new UnitDepartmentId(a.UnitId) == ExpenditureGood.UnitId && new GarmentComodityId(a.ComodityId) == ExpenditureGood.ComodityId).Select(s => new GarmentComodityPrice(s)).Single(); Dictionary <Guid, double> finStockToBeUpdated = new Dictionary <Guid, double>(); _garmentExpenditureGoodItemRepository.Find(o => o.ExpenditureGoodId == ExpenditureGood.Identity).ForEach(async expenditureItem => { if (finStockToBeUpdated.ContainsKey(expenditureItem.FinishedGoodStockId)) { finStockToBeUpdated[expenditureItem.FinishedGoodStockId] += expenditureItem.Quantity; } else { finStockToBeUpdated.Add(expenditureItem.FinishedGoodStockId, expenditureItem.Quantity); } GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = _garmentFinishedGoodStockHistoryRepository.Query.Where(a => a.ExpenditureGoodItemId == expenditureItem.Identity).Select(a => new GarmentFinishedGoodStockHistory(a)).Single(); garmentFinishedGoodStockHistory.Remove(); await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory); expenditureItem.Remove(); await _garmentExpenditureGoodItemRepository.Update(expenditureItem); }); foreach (var finStock in finStockToBeUpdated) { var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == finStock.Key).Select(s => new GarmentFinishedGoodStock(s)).Single(); var qty = garmentFinishingGoodStockItem.Quantity + finStock.Value; garmentFinishingGoodStockItem.SetQuantity(qty); garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (qty)); garmentFinishingGoodStockItem.Modify(); await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem); } ExpenditureGood.Remove(); await _garmentExpenditureGoodRepository.Update(ExpenditureGood); _storage.Save(); return(ExpenditureGood); }
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); }
public async Task <GarmentExpenditureGood> Handle(PlaceGarmentExpenditureGoodCommand request, CancellationToken cancellationToken) { request.Items = request.Items.ToList(); 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(); GarmentExpenditureGood garmentExpenditureGood = new GarmentExpenditureGood( Guid.NewGuid(), GenerateExpenditureGoodNo(request), request.ExpenditureType, 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, new BuyerId(request.Buyer.Id), request.Buyer.Code, request.Buyer.Name, request.ExpenditureDate, request.Invoice, request.ContractNo, request.Carton, request.Description, request.IsReceived ); Dictionary <string, double> finStockToBeUpdated = new Dictionary <string, double>(); Dictionary <Guid, double> finstockQty = new Dictionary <Guid, double>(); foreach (var item in request.Items) { if (item.isSave) { double StockQty = 0; 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 (!finstockQty.ContainsKey(finishedGood.Identity)) { finstockQty.Add(finishedGood.Identity, finishedGood.Quantity); } string key = finishedGood.Identity.ToString() + "~" + item.Description; if (qty > 0) { double remainQty = finstockQty[finishedGood.Identity] - qty; if (remainQty < 0) { qty -= finstockQty[finishedGood.Identity]; finStockToBeUpdated.Add(key, 0); finstockQty[finishedGood.Identity] = 0; } else if (remainQty == 0) { finStockToBeUpdated.Add(key, 0); finstockQty[finishedGood.Identity] = remainQty; break; } else if (remainQty > 0) { finStockToBeUpdated.Add(key, remainQty); finstockQty[finishedGood.Identity] = remainQty; break; } } } } } foreach (var finStock in finStockToBeUpdated) { var keyString = finStock.Key.Split("~"); var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == Guid.Parse(keyString[0])).Select(s => new GarmentFinishedGoodStock(s)).Single(); var item = request.Items.Where(a => new SizeId(a.Size.Id) == garmentFinishingGoodStockItem.SizeId && new UomId(a.Uom.Id) == garmentFinishingGoodStockItem.UomId && a.Description == keyString[1]).Single(); item.Price = (item.BasicPrice + ((double)garmentComodityPrice.Price * 1)) * item.Quantity; var qty = garmentFinishingGoodStockItem.Quantity - finStock.Value; GarmentExpenditureGoodItem garmentExpenditureGoodItem = new GarmentExpenditureGoodItem( Guid.NewGuid(), garmentExpenditureGood.Identity, garmentFinishingGoodStockItem.Identity, new SizeId(item.Size.Id), item.Size.Size, qty, 0, new UomId(item.Uom.Id), item.Uom.Unit, item.Description, garmentFinishingGoodStockItem.BasicPrice, (garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * qty ); await _garmentExpenditureGoodItemRepository.Update(garmentExpenditureGoodItem); GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory( Guid.NewGuid(), garmentFinishingGoodStockItem.Identity, Guid.Empty, Guid.Empty, garmentExpenditureGood.Identity, garmentExpenditureGoodItem.Identity, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, "OUT", garmentExpenditureGood.RONo, garmentExpenditureGood.Article, garmentExpenditureGood.UnitId, garmentExpenditureGood.UnitCode, garmentExpenditureGood.UnitName, garmentExpenditureGood.ComodityId, garmentExpenditureGood.ComodityCode, garmentExpenditureGood.ComodityName, garmentExpenditureGoodItem.SizeId, garmentExpenditureGoodItem.SizeName, garmentExpenditureGoodItem.UomId, garmentExpenditureGoodItem.UomUnit, garmentExpenditureGoodItem.Quantity, garmentExpenditureGoodItem.BasicPrice, garmentExpenditureGoodItem.Price ); await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory); garmentFinishingGoodStockItem.SetQuantity(finStock.Value); garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (finStock.Value)); garmentFinishingGoodStockItem.Modify(); await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem); } await _garmentExpenditureGoodRepository.Update(garmentExpenditureGood); _storage.Save(); return(garmentExpenditureGood); }
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 <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); }
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 <GarmentExpenditureGoodReturn> Handle(PlaceGarmentExpenditureGoodReturnCommand request, CancellationToken cancellationToken) { request.Items = request.Items.ToList(); 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(); GarmentExpenditureGoodReturn garmentExpenditureGoodReturn = new GarmentExpenditureGoodReturn( Guid.NewGuid(), GenerateExpenditureGoodReturnNo(request), request.ReturType, 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, new BuyerId(request.Buyer.Id), request.Buyer.Code, request.Buyer.Name, request.ReturDate.GetValueOrDefault(), request.Invoice, request.ReturDesc ); Dictionary <Guid, double> finstockQty = new Dictionary <Guid, double>(); Dictionary <string, double> finStockToBeUpdated = new Dictionary <string, double>(); Dictionary <Guid, double> exGoodToBeUpdated = new Dictionary <Guid, double>(); foreach (var item in request.Items) { if (item.isSave) { var garmentexGood = _garmentExpenditureGoodRepository.Query.Where(x => x.UnitId == request.Unit.Id && x.RONo == request.RONo).OrderBy(a => a.CreatedDate).ToList(); var garmentexGoodItem = _garmentExpenditureGoodItemRepository.Query.Where(x => x.SizeId == item.Size.Id && x.UomId == item.Uom.Id && (x.Quantity - x.ReturQuantity) > 0 && x.Description == item.Description).OrderBy(a => a.CreatedDate).ToList(); var join = (from a in garmentexGoodItem join b in garmentexGood on a.ExpenditureGoodId equals b.Identity select a).ToList(); double qty = item.Quantity; foreach (var exGood in join) { string key = exGood.FinishedGoodStockId.ToString() + "~" + item.Description; if (qty > 0) { double exGoodQty = exGood.Quantity - exGood.ReturQuantity; double remainQty = exGoodQty - qty; if (!finstockQty.ContainsKey(exGood.FinishedGoodStockId)) { finstockQty.Add(exGood.FinishedGoodStockId, 0); } //double stockQty = exGoodQty - qty; if (remainQty < 0) { qty -= exGood.Quantity; exGoodToBeUpdated.Add(exGood.Identity, exGoodQty); finstockQty[exGood.FinishedGoodStockId] += exGoodQty; //finStockToBeUpdated.Add(key, exGoodQty); } else if (remainQty == 0) { exGoodToBeUpdated.Add(exGood.Identity, exGoodQty); finstockQty[exGood.FinishedGoodStockId] += exGoodQty; //finStockToBeUpdated.Add(key, exGoodQty); break; } else if (remainQty > 0) { exGoodToBeUpdated.Add(exGood.Identity, qty); finstockQty[exGood.FinishedGoodStockId] += qty; //finStockToBeUpdated.Add(key, qty); break; } } } } } foreach (var exGood in exGoodToBeUpdated) { var garmentExpenditureGoodItem = _garmentExpenditureGoodItemRepository.Query.Where(x => x.Identity == exGood.Key).Select(s => new GarmentExpenditureGoodItem(s)).Single(); //var dup= request.Items.Where(a => new SizeId(a.Size.Id) == garmentExpenditureGoodItem.SizeId && new UomId(a.Uom.Id) == garmentExpenditureGoodItem.UomId && a.isSave == true).FirstOrDefault(); var item = request.Items.Where(a => a.Description.Trim() == garmentExpenditureGoodItem.Description.Trim() && new SizeId(a.Size.Id) == garmentExpenditureGoodItem.SizeId && new UomId(a.Uom.Id) == garmentExpenditureGoodItem.UomId && a.isSave == true).Single(); var quantityRetur = garmentExpenditureGoodItem.ReturQuantity + exGood.Value; double price = (garmentExpenditureGoodItem.BasicPrice + ((double)garmentComodityPrice.Price * 1)) * quantityRetur; GarmentExpenditureGoodReturnItem garmentExpenditureGoodReturnItem = new GarmentExpenditureGoodReturnItem( Guid.NewGuid(), garmentExpenditureGoodReturn.Identity, garmentExpenditureGoodItem.ExpenditureGoodId, garmentExpenditureGoodItem.Identity, garmentExpenditureGoodItem.FinishedGoodStockId, new SizeId(item.Size.Id), item.Size.Size, exGood.Value, new UomId(item.Uom.Id), item.Uom.Unit, item.Description, garmentExpenditureGoodItem.BasicPrice, price ); GarmentFinishedGoodStockHistory garmentFinishedGoodStockHistory = new GarmentFinishedGoodStockHistory( Guid.NewGuid(), item.FinishedGoodStockId, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, Guid.Empty, garmentExpenditureGoodReturn.Identity, garmentExpenditureGoodReturnItem.Identity, "RETUR", garmentExpenditureGoodReturn.RONo, garmentExpenditureGoodReturn.Article, garmentExpenditureGoodReturn.UnitId, garmentExpenditureGoodReturn.UnitCode, garmentExpenditureGoodReturn.UnitName, garmentExpenditureGoodReturn.ComodityId, garmentExpenditureGoodReturn.ComodityCode, garmentExpenditureGoodReturn.ComodityName, garmentExpenditureGoodReturnItem.SizeId, garmentExpenditureGoodReturnItem.SizeName, garmentExpenditureGoodReturnItem.UomId, garmentExpenditureGoodReturnItem.UomUnit, garmentExpenditureGoodReturnItem.Quantity, garmentExpenditureGoodReturnItem.BasicPrice, garmentExpenditureGoodReturnItem.Price ); await _garmentFinishedGoodStockHistoryRepository.Update(garmentFinishedGoodStockHistory); await _garmentExpenditureGoodReturnItemRepository.Update(garmentExpenditureGoodReturnItem); var qty = garmentExpenditureGoodItem.ReturQuantity + exGood.Value; garmentExpenditureGoodItem.SetReturQuantity(qty); garmentExpenditureGoodItem.Modify(); await _garmentExpenditureGoodItemRepository.Update(garmentExpenditureGoodItem); } foreach (var finStock in finstockQty) { //var keyString = finStock.Key.Split("~"); var garmentFinishingGoodStockItem = _garmentFinishedGoodStockRepository.Query.Where(x => x.Identity == finStock.Key).Select(s => new GarmentFinishedGoodStock(s)).Single(); var qty = garmentFinishingGoodStockItem.Quantity + finStock.Value; garmentFinishingGoodStockItem.SetQuantity(qty); garmentFinishingGoodStockItem.SetPrice((garmentFinishingGoodStockItem.BasicPrice + (double)garmentComodityPrice.Price) * (qty)); garmentFinishingGoodStockItem.Modify(); await _garmentFinishedGoodStockRepository.Update(garmentFinishingGoodStockItem); } await _garmentExpenditureGoodReturnRepository.Update(garmentExpenditureGoodReturn); _storage.Save(); return(garmentExpenditureGoodReturn); }