/// <summary> /// 批量删除损益细单 /// </summary> /// <param name="profitLossBillMaster">损益主单</param> public void DeleteProfitLossBillDetail(ProfitLossBillMaster profitLossBillMaster) { if (profitLossBillMaster != null) { foreach (var detail in profitLossBillMaster.ProfitLossBillDetails) { var Storage = Locker.LockStorage(detail.Storage, detail.Product); if (Storage != null) { if (detail.Quantity > 0) { Storage.InFrozenQuantity -= detail.Quantity; } else { Storage.OutFrozenQuantity -= Math.Abs(detail.Quantity); } Storage.LockTag = string.Empty; detail.Quantity = 0; } } var details = profitLossBillMaster.ProfitLossBillDetails.Where(d => d.Quantity == 0) .Select(d => d); ProfitLossBillDetailRepository.Delete(details.ToArray()); ProfitLossBillDetailRepository.SaveChanges(); } }
/// <summary> /// 修改损益细单 /// </summary> /// <param name="profitLossBillDetail">损益细单</param> /// <returns></returns> public bool Save(ProfitLossBillDetail profitLossBillDetail, out string strResult) { strResult = string.Empty; bool result = false; try { IQueryable <ProfitLossBillDetail> profitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); var pbd = profitLossBillDetailQuery.FirstOrDefault(i => i.ID == profitLossBillDetail.ID && i.BillNo == profitLossBillDetail.BillNo); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == profitLossBillDetail.UnitCode); var cell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == profitLossBillDetail.CellCode); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == pbd.ProductCode); var storage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == pbd.StorageCode); if (Locker.LockStorage(storage, product) != null) { if (IsQuntityRight(profitLossBillDetail.Quantity * unit.Count, storage.InFrozenQuantity - Math.Abs(pbd.Quantity), storage.OutFrozenQuantity - Math.Abs(pbd.Quantity), cell.MaxQuantity * unit.Count, storage.Quantity)) { pbd.CellCode = profitLossBillDetail.CellCode; pbd.StorageCode = profitLossBillDetail.StorageCode; pbd.ProductCode = profitLossBillDetail.ProductCode; pbd.UnitCode = profitLossBillDetail.UnitCode; pbd.Price = profitLossBillDetail.Price; //原来的数量撤销 if (pbd.Quantity > 0) { storage.InFrozenQuantity -= pbd.Quantity; } else { storage.OutFrozenQuantity -= Math.Abs(pbd.Quantity); } //新的数量生效 if (profitLossBillDetail.Quantity > 0) { storage.InFrozenQuantity += profitLossBillDetail.Quantity * unit.Count; } else { storage.OutFrozenQuantity += Math.Abs(profitLossBillDetail.Quantity * unit.Count); } pbd.Quantity = profitLossBillDetail.Quantity * unit.Count; pbd.Description = profitLossBillDetail.Description; ProfitLossBillDetailRepository.SaveChanges(); result = true; } } strResult = resultStr; } catch (Exception ex) { strResult = "修改失败,原因:" + ex.Message; } return(result); }
/// <summary> /// 删除损益细单 /// </summary> /// <param name="ID">损益单细单ID</param> /// <returns></returns> public bool Delete(string ID, out string strResult) { strResult = string.Empty; bool result = false; try { IQueryable <ProfitLossBillDetail> profitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); int intID = Convert.ToInt32(ID); var pbd = profitLossBillDetailQuery.FirstOrDefault(i => i.ID == intID); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == pbd.UnitCode); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == pbd.ProductCode); var storage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == pbd.StorageCode); if (pbd != null) { if (Locker.LockStorage(storage, product) != null) { if (pbd.Quantity > 0) { storage.InFrozenQuantity -= pbd.Quantity; } else { storage.OutFrozenQuantity -= Math.Abs(pbd.Quantity); } storage.LockTag = string.Empty; StorageRepository.SaveChanges(); ProfitLossBillDetailRepository.Delete(pbd); ProfitLossBillDetailRepository.SaveChanges(); result = true; } else { strResult = "库存加锁失败!"; result = false; } } else { strResult = "删除失败,找不到该条单据!"; result = false; } } catch (Exception ex) { strResult = "删除失败,原因:" + ex.Message; } return(result); }
/// <summary> /// 新增损益单明细 /// </summary> /// <param name="profitLossBillDetail">损益单细表</param> /// <returns></returns> public bool Add(ProfitLossBillDetail profitLossBillDetail, out string strResult) { bool result = false; try { IQueryable <ProfitLossBillDetail> profitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == profitLossBillDetail.UnitCode); var cell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == profitLossBillDetail.CellCode); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == profitLossBillDetail.ProductCode); var storage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == profitLossBillDetail.StorageCode); if (Locker.LockStorage(storage, product) != null) { if (IsQuntityRight(profitLossBillDetail.Quantity * unit.Count, storage.InFrozenQuantity, storage.OutFrozenQuantity, cell.MaxQuantity * unit.Count, storage.Quantity)) { var pbd = new ProfitLossBillDetail(); pbd.BillNo = profitLossBillDetail.BillNo; pbd.CellCode = profitLossBillDetail.CellCode; pbd.StorageCode = profitLossBillDetail.StorageCode; pbd.ProductCode = profitLossBillDetail.ProductCode; pbd.UnitCode = profitLossBillDetail.UnitCode; pbd.Price = profitLossBillDetail.Price; pbd.Quantity = profitLossBillDetail.Quantity * unit.Count; pbd.Description = profitLossBillDetail.Description; if (profitLossBillDetail.Quantity > 0) { storage.InFrozenQuantity += profitLossBillDetail.Quantity * unit.Count; } else { storage.OutFrozenQuantity += Math.Abs(profitLossBillDetail.Quantity * unit.Count); } ProfitLossBillDetailRepository.Add(pbd); ProfitLossBillDetailRepository.SaveChanges(); storage.LockTag = string.Empty; StorageRepository.SaveChanges(); result = true; } } strResult = resultStr == "" ? "该库存的当前库存-出库冻结量小于0或者已经处于编辑状态!" : resultStr; } catch (Exception ex) { strResult = "新增失败,原因:" + ex.Message; } return(result); }
/// <summary> /// 盘点确认 /// </summary> /// <param name="billNo">单据号</param> /// <returns></returns> public bool confirmCheck(string billNo, string userName, out string errorInfo) { bool result = false; errorInfo = string.Empty; var checkbm = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo); var checkDetail = CheckBillDetailRepository.GetQueryable().Where(c => c.BillNo == checkbm.BillNo && c.ProductCode == c.RealProductCode && c.Quantity != c.RealQuantity && c.Status == "2"); using (var scope = new TransactionScope()) { try { if (checkDetail.Count() > 0) { string billno = GenProfitLossBillNo(userName).ToString(); //添加损益主表 var pbm = new ProfitLossBillMaster(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (employee != null) { pbm.BillNo = billno; pbm.BillDate = DateTime.Now; pbm.BillTypeCode = "5002"; pbm.WarehouseCode = checkbm.WarehouseCode; pbm.OperatePersonID = employee.ID; pbm.Status = "1"; pbm.IsActive = "1"; pbm.UpdateTime = DateTime.Now; ProfitLossBillMasterRepository.Add(pbm); ProfitLossBillMasterRepository.SaveChanges(); } //添加损益细表 foreach (var item in checkDetail.ToArray()) { decimal differQuantity = item.RealQuantity - item.Quantity; //损益数量 if (Locker.LockNoEmptyStorage(item.Storage, item.Product) != null) //锁库存 { var pbd = new ProfitLossBillDetail(); pbd.BillNo = billno; pbd.CellCode = item.CellCode; pbd.StorageCode = item.StorageCode; pbd.ProductCode = item.ProductCode; pbd.UnitCode = item.UnitCode; pbd.Price = item.Product != null ? item.Product.CostPrice : 0; pbd.Quantity = differQuantity; if (differQuantity > 0) { item.Storage.InFrozenQuantity += differQuantity; } else { item.Storage.OutFrozenQuantity += Math.Abs(differQuantity); } ProfitLossBillDetailRepository.Add(pbd); item.Storage.LockTag = string.Empty; ProfitLossBillDetailRepository.SaveChanges(); } scope.Complete(); } } var checkBillDetail = CheckBillDetailRepository.GetQueryable().Where(c => c.BillNo == checkbm.BillNo);//解锁盘点锁定 foreach (var item in checkBillDetail.ToArray()) { item.Storage.IsLock = "0"; } if (checkbm != null && checkbm.Status == "4") { checkbm.Status = "5"; checkbm.VerifyDate = DateTime.Now; checkbm.UpdateTime = DateTime.Now; CheckBillMasterRepository.SaveChanges(); result = true; } } catch (Exception e) { errorInfo = "确认盘点损益失败!原因:" + e.Message; } scope.Complete(); } return(result); }