public IList<DepartmentInventoryChecking> FindInventoryChecking(DateTime fromDate, DateTime toDate) { ObjectCriteria<DepartmentInventoryChecking> criteria = new ObjectCriteria<DepartmentInventoryChecking>(); criteria.Add(a => a.CreateDate >= fromDate); criteria.Add(a => a.CreateDate <= toDate); criteria.Add(a => a.Fixed == 0); criteria.Add(a => a.ExFld2 == 0); return DepartmentInventoryCheckingDao.FindAll(criteria); }
public MainStock FindByProductId(string productId) { ObjectCriteria<MainStock> objectCriteria = new ObjectCriteria<MainStock>(); objectCriteria.Add(mstk => mstk.Product.ProductId == productId); return (MainStock)MainStockDao.FindFirst(objectCriteria); }
public void Update(StockOut data) { long definitionStatusId = data.DefinitionStatus.DefectStatusId; if (definitionStatusId == DefinitionStatus.TEMP_STOCKOUT || definitionStatusId == DefinitionStatus.PROTOTYPE) return; foreach (StockOutDetail outDetail in data.StockOutDetails) { string productId = outDetail.Product.ProductId; ObjectCriteria<MainStock> findStock = new ObjectCriteria<MainStock>(); findStock.Add(stk => stk.Product.ProductId == productId); MainStock currentStock = MainStockDao.FindFirst(findStock) as MainStock; /*MainStock currentStock = (MainStock)MainStockDao.ExecuteExposedSession(delegate(ISession session) { var query = session.QueryOver<MainStock>() .Where( stk => stk.Product.ProductId == productId); return query.SingleOrDefault(); });*/ if (currentStock == null) // create new stock { throw new DataIntegrityViolationException("Could not find the product id in stock"); } else // update current stock { // * ---- CHUA CO PHAN XUAT HANG HU LOI HONG MAT O DAY -------- currentStock.Quantity -= outDetail.Quantity; currentStock.GoodQuantity -= outDetail.Quantity; currentStock.ExclusiveKey += 1; if (currentStock.Quantity < 0 || currentStock.GoodQuantity < 0) throw new DataIntegrityViolationException("Stock quantity of " + currentStock.Product.ProductId + " is zero."); MainStockDao.Update(currentStock); } } }
public StockIn Add(StockIn data) { IDictionary<string,MainPrice> prices = new Dictionary<string, MainPrice>(); var maxIdResult = StockInDao.SelectSpecificType(null, Projections.Max("StockInId")); long nextStockInId = maxIdResult != null ? Int64.Parse(maxIdResult.ToString()) + 1 : 1; // add or update stock var maxStockIdResult = MainStockDao.SelectSpecificType(null, Projections.Max("StockId")); long nextStockId = maxStockIdResult != null ? Int64.Parse(maxStockIdResult.ToString()) + 1 : 1; data.StockInId = nextStockInId.ToString(); StockInDao.Add(data); foreach (StockInDetail inDetail in data.StockInDetails) { inDetail.StockInDetailPK.StockInId = nextStockInId.ToString(); Product current = ProductDao.FindById(inDetail.Product.ProductId); if (current != null) { inDetail.Product = current; } else { ProductDao.Add(inDetail.Product); } StockInDetailDao.Add(inDetail); ObjectCriteria<MainStock> findStock = new ObjectCriteria<MainStock>(); string productId = inDetail.Product.ProductId; findStock.Add(stk => stk.Product.ProductId==productId); MainStock currentStock = MainStockDao.FindFirst(findStock) as MainStock; if(currentStock == null) // create new stock { MainStock newStock = new MainStock { StockId = nextStockId++, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, CreateId = "admin", UpdateId = "admin", DelFlg = 0, ExclusiveKey = 1, Product = inDetail.Product, ProductMaster = inDetail.ProductMaster, Quantity = inDetail.Quantity, GoodQuantity = inDetail.Quantity }; MainStockDao.Add(newStock); } else // update current stock { currentStock.Quantity += inDetail.Quantity; currentStock.GoodQuantity += inDetail.Quantity; currentStock.ExclusiveKey += 1; MainStockDao.Update(currentStock); } // add price for update later prices[inDetail.MainPrice.MainPricePK.ProductMasterId] = inDetail.MainPrice; } // update price if have foreach (KeyValuePair<string, MainPrice> mainPrice in prices) { ObjectCriteria<MainPrice> findPrice = new ObjectCriteria<MainPrice>(); string productMasterId = mainPrice.Key; findPrice.Add( price => price.MainPricePK.ProductMasterId == productMasterId); MainPrice currentPrice = MainPriceDao.FindFirst(findPrice) as MainPrice; if (currentPrice == null) { MainPriceDao.Add(mainPrice.Value); } else { currentPrice.Price = mainPrice.Value.Price; currentPrice.WholeSalePrice = mainPrice.Value.WholeSalePrice; MainPriceDao.Update(currentPrice); } } // color and size // the updating informs that specialized object has been used in stock in so it can not be deleted. IList<ExProductColor> colors = data.StockInDetails.Select(x => x.Product.ProductColor).Distinct().ToList(); foreach (ExProductColor exProductColor in colors) { if(exProductColor.ExFld1 == 1) continue; exProductColor.ExFld1 = 1; ExProductColorDao.Update(exProductColor); } IList<ExProductSize> sizes = data.StockInDetails.Select(x => x.Product.ProductSize).Distinct().ToList(); foreach (ExProductSize exProductSize in sizes) { if(exProductSize.ExFld1 == 1) continue; exProductSize.ExFld1 = 1; ExProductSizeDao.Update(exProductSize); } return data; }