/// <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> public System.Data.DataTable GetProfitLoassBillDetail(int page, int rows, string BillNo) { System.Data.DataTable dt = new System.Data.DataTable(); if (BillNo != "" && BillNo != null) { IQueryable <ProfitLossBillDetail> ProfitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); var profitLossBillDetail = ProfitLossBillDetailQuery.Where(i => i.BillNo.Contains(BillNo)).OrderBy(i => i.BillNo).Select(i => new { i.CellCode, i.StorageCode, i.ProductCode, i.Product.ProductName, i.UnitCode, i.Unit.UnitName, i.Price, Quantity = i.Quantity / i.Unit.Count, i.Description }); dt.Columns.Add("储位编码", typeof(string)); dt.Columns.Add("存储编码", typeof(string)); dt.Columns.Add("产品代码", typeof(string)); dt.Columns.Add("产品名称", typeof(string)); dt.Columns.Add("单位编码", typeof(string)); dt.Columns.Add("单位名称", typeof(string)); dt.Columns.Add("单价", typeof(string)); dt.Columns.Add("数量", typeof(string)); dt.Columns.Add("备注", typeof(string)); foreach (var p in profitLossBillDetail) { dt.Rows.Add ( p.CellCode, p.StorageCode, p.ProductCode, p.ProductName, p.UnitCode, p.UnitName, p.Price, p.Quantity, p.Description ); } } return(dt); }
/// <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); }
public object GetCellDetails(int page, int rows, string beginDate, string endDate, string type, string id) { IQueryable <InBillAllot> InBillAllotQuery = InBillAllotRepository.GetQueryable(); IQueryable <OutBillAllot> OutBillAllotQuery = OutBillAllotRepository.GetQueryable(); IQueryable <MoveBillDetail> MoveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); IQueryable <ProfitLossBillDetail> ProfitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); if (type == "cell") { var CellHistoryAllQuery = InBillAllotQuery.Where(i => i.Status == "2" && i.CellCode == id) .Select(i => new { i.CellCode, i.Cell.CellName, i.InBillMaster.BillDate, i.InBillMaster.BillType.BillTypeName, i.InBillMaster.BillNo, i.ProductCode, i.Product.ProductName, i.Unit.UnitName, i.RealQuantity, i.Unit.Count, IfMove = "0" }).Union(OutBillAllotQuery.Where(o => o.Status == "2" && o.CellCode == id) .Select(o => new { o.CellCode, o.Cell.CellName, o.OutBillMaster.BillDate, o.OutBillMaster.BillType.BillTypeName, o.OutBillMaster.BillNo, o.ProductCode, o.Product.ProductName, o.Unit.UnitName, o.RealQuantity, o.Unit.Count, IfMove = "0" })).Union(MoveBillDetailQuery.Where(m => m.Status == "2" && (m.InCellCode == id || m.OutCellCode == id)) .Select(m => new { CellCode = m.InCellCode == id ? m.InCellCode : m.OutCellCode, CellName = m.InCellCode == id ? m.InCell.CellName : m.OutCell.CellName, m.MoveBillMaster.BillDate, m.MoveBillMaster.BillType.BillTypeName, m.MoveBillMaster.BillNo, m.ProductCode, m.Product.ProductName, m.Unit.UnitName, m.RealQuantity, m.Unit.Count, IfMove = m.InCellCode == id ? "1":"2" } )).Union(ProfitLossBillDetailQuery.Where(p => p.ProfitLossBillMaster.Status == "3" && p.CellCode == id) .Select(p => new { p.CellCode, p.Storage.Cell.CellName, p.ProfitLossBillMaster.BillDate, p.ProfitLossBillMaster.BillType.BillTypeName, p.ProfitLossBillMaster.BillNo, p.ProductCode, p.Product.ProductName, p.Unit.UnitName, RealQuantity = p.Quantity, p.Unit.Count, IfMove = "0" })); if (!beginDate.Equals(string.Empty) && beginDate != "null01") { DateTime begin = Convert.ToDateTime(beginDate); CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate >= begin); } //else //{ // DateTime begin = DateTime.Now.AddDays(-30); // CellHistoryAllQuery = CellHistoryAllQuery.Where(i => i.BillDate >= begin); //} if (!endDate.Equals(string.Empty) && endDate != "null02")//null02 同null01 代表传回来的日期是空值 { DateTime end = Convert.ToDateTime(endDate); CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate <= end); } CellHistoryAllQuery = CellHistoryAllQuery.OrderByDescending(c => c.BillDate).Where(c => c.RealQuantity > 0); int total = CellHistoryAllQuery.Count(); CellHistoryAllQuery = CellHistoryAllQuery.Skip((page - 1) * rows).Take(rows); var CellHistoryAll = CellHistoryAllQuery.ToArray().ToArray().Select(c => new { c.CellCode, c.CellName, BillDate = c.BillDate.ToString("yyyy-MM-dd"), BillTypeName = c.IfMove == "0" ? c.BillTypeName.ToString() : c.IfMove == "1" ? c.BillTypeName.ToString() + "-移入" : c.BillTypeName.ToString() + "-移出", c.BillNo, c.ProductCode, c.ProductName, c.UnitName, Quantity = c.RealQuantity / c.Count }); return(new { total, rows = CellHistoryAll.ToArray() }); } return(null); }
public System.Data.DataTable GetCellHistory(int page, int rows, string beginDate, string endDate, string type, string id) { IQueryable <InBillAllot> InBillAllotQuery = InBillAllotRepository.GetQueryable(); IQueryable <OutBillAllot> OutBillAllotQuery = OutBillAllotRepository.GetQueryable(); IQueryable <MoveBillDetail> MoveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); IQueryable <ProfitLossBillDetail> ProfitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable(); if (type == "cell") { var CellHistoryAllQuery = InBillAllotQuery.Where(i => i.Status == "2" && i.CellCode == id) .Select(i => new { i.CellCode, i.Cell.CellName, i.InBillMaster.BillDate, i.InBillMaster.BillType.BillTypeName, i.InBillMaster.BillNo, i.ProductCode, i.Product.ProductName, i.Unit.UnitName, i.RealQuantity, i.Unit.Count, IfMove = "0" }).Union(OutBillAllotQuery.Where(o => o.Status == "2" && o.CellCode == id) .Select(o => new { o.CellCode, o.Cell.CellName, o.OutBillMaster.BillDate, o.OutBillMaster.BillType.BillTypeName, o.OutBillMaster.BillNo, o.ProductCode, o.Product.ProductName, o.Unit.UnitName, o.RealQuantity, o.Unit.Count, IfMove = "0" })).Union(MoveBillDetailQuery.Where(m => m.Status == "2" && (m.InCellCode == id || m.OutCellCode == id)) .Select(m => new { CellCode = m.InCellCode == id ? m.InCellCode : m.OutCellCode, CellName = m.InCellCode == id ? m.InCell.CellName : m.OutCell.CellName, m.MoveBillMaster.BillDate, m.MoveBillMaster.BillType.BillTypeName, m.MoveBillMaster.BillNo, m.ProductCode, m.Product.ProductName, m.Unit.UnitName, m.RealQuantity, m.Unit.Count, IfMove = m.InCellCode == id ? "1" : "2" } )).Union(ProfitLossBillDetailQuery.Where(p => p.ProfitLossBillMaster.Status == "3" && p.CellCode == id) .Select(p => new { p.CellCode, p.Storage.Cell.CellName, p.ProfitLossBillMaster.BillDate, p.ProfitLossBillMaster.BillType.BillTypeName, p.ProfitLossBillMaster.BillNo, p.ProductCode, p.Product.ProductName, p.Unit.UnitName, RealQuantity = p.Quantity, p.Unit.Count, IfMove = "0" })); if (!beginDate.Equals(string.Empty) && beginDate != "null01") { DateTime begin = Convert.ToDateTime(beginDate); CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate >= begin); } if (!endDate.Equals(string.Empty) && endDate != "null02") //null02 同null01 代表传回来的日期是空值 { DateTime end = Convert.ToDateTime(endDate); CellHistoryAllQuery = CellHistoryAllQuery.Where(c => c.BillDate <= end); } CellHistoryAllQuery = CellHistoryAllQuery.OrderByDescending(c => c.BillDate).Where(c => c.RealQuantity > 0); var CellHistoryAll = CellHistoryAllQuery.ToArray().ToArray().Select(c => new { c.CellCode, c.CellName, BillDate = c.BillDate.ToString("yyyy-MM-dd"), BillTypeName = c.IfMove == "0" ? c.BillTypeName.ToString() : c.IfMove == "1" ? c.BillTypeName.ToString() + "-移入" : c.BillTypeName.ToString() + "-移出", c.BillNo, c.ProductCode, c.ProductName, c.UnitName, Quantity = c.RealQuantity / c.Count }); System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("货位名称", typeof(string)); dt.Columns.Add("变动日期", typeof(string)); dt.Columns.Add("操作类型", typeof(string)); dt.Columns.Add("所属订单", typeof(string)); dt.Columns.Add("商品编码", typeof(string)); dt.Columns.Add("商品名称", typeof(string)); dt.Columns.Add("数量", typeof(string)); dt.Columns.Add("单位名称", typeof(string)); foreach (var item in CellHistoryAll) { dt.Rows.Add ( item.CellName, item.BillDate, item.BillTypeName, item.BillNo, item.ProductCode, item.ProductName, item.Quantity, item.UnitName ); } return(dt); } return(null); }
public Boolean DoDailyBalance(string warehouseCode, string settleDate, ref string errorInfo) { try { using (var scope = new TransactionScope()) { var inQuery = InBillDetailRepository.GetQueryable().AsEnumerable(); var outQuery = OutBillDetailRepository.GetQueryable().AsEnumerable(); var profitLossQuery = ProfitLossBillDetailRepository.GetQueryable().AsEnumerable(); var dailyBalanceQuery = DailyBalanceRepository.GetQueryable().AsEnumerable(); DateTime dt1 = Convert.ToDateTime(settleDate); if (DateTime.Now < dt1) { errorInfo = "选择日结日期大于当前日期,不可以进行日结!"; return(false); } var dailyBalance = dailyBalanceQuery.Where(d => d.SettleDate < dt1) .OrderByDescending(d => d.SettleDate) .FirstOrDefault(); string t = dailyBalance != null?dailyBalance.SettleDate.ToString("yyyy-MM-dd") : ""; var oldDailyBalance = dailyBalanceQuery.Where(d => (d.WarehouseCode == warehouseCode || string.IsNullOrEmpty(warehouseCode)) && d.SettleDate.ToString("yyyy-MM-dd") == settleDate) .ToArray(); DailyBalanceRepository.Delete(oldDailyBalance); DailyBalanceRepository.SaveChanges(); var query = inQuery.Where(a => (a.InBillMaster.WarehouseCode == warehouseCode || string.IsNullOrEmpty(warehouseCode)) && a.InBillMaster.BillDate.ToString("yyyy-MM-dd") == settleDate ).Select(a => new { BillDate = a.InBillMaster.BillDate.ToString("yyyy-MM-dd"), WarehouseCode = a.InBillMaster.Warehouse.WarehouseCode, ProductCode = a.ProductCode, UnitCode = a.Product.UnitCode, Beginning = decimal.Zero, EntryAmount = a.RealQuantity, DeliveryAmount = decimal.Zero, ProfitAmount = decimal.Zero, LossAmount = decimal.Zero, Ending = decimal.Zero }).Union(outQuery.Where(a => (a.OutBillMaster.WarehouseCode == warehouseCode || string.IsNullOrEmpty(warehouseCode)) && a.OutBillMaster.BillDate.ToString("yyyy-MM-dd") == settleDate ).Select(a => new { BillDate = a.OutBillMaster.BillDate.ToString("yyyy-MM-dd"), WarehouseCode = a.OutBillMaster.Warehouse.WarehouseCode, ProductCode = a.ProductCode, UnitCode = a.Product.UnitCode, Beginning = decimal.Zero, EntryAmount = decimal.Zero, DeliveryAmount = a.RealQuantity, ProfitAmount = decimal.Zero, LossAmount = decimal.Zero, Ending = decimal.Zero })).Union(profitLossQuery.Where(a => (a.ProfitLossBillMaster.WarehouseCode == warehouseCode || string.IsNullOrEmpty(warehouseCode)) && a.ProfitLossBillMaster.BillDate.ToString("yyyy-MM-dd") == settleDate ).Select(a => new { BillDate = a.ProfitLossBillMaster.BillDate.ToString("yyyy-MM-dd"), WarehouseCode = a.ProfitLossBillMaster.Warehouse.WarehouseCode, ProductCode = a.ProductCode, UnitCode = a.Product.UnitCode, Beginning = decimal.Zero, EntryAmount = decimal.Zero, DeliveryAmount = decimal.Zero, ProfitAmount = a.Quantity > 0 ? Math.Abs(a.Quantity) : decimal.Zero, LossAmount = a.Quantity < 0 ? Math.Abs(a.Quantity) : decimal.Zero, Ending = decimal.Zero })).Union(dailyBalanceQuery.Where(d => (d.WarehouseCode == warehouseCode || string.IsNullOrEmpty(warehouseCode)) && d.SettleDate.ToString("yyyy-MM-dd") == t && d.Ending > decimal.Zero ).Select(a => new { BillDate = settleDate, WarehouseCode = a.WarehouseCode, ProductCode = a.ProductCode, UnitCode = a.Product.UnitCode, Beginning = a.Ending, EntryAmount = decimal.Zero, DeliveryAmount = decimal.Zero, ProfitAmount = decimal.Zero, LossAmount = decimal.Zero, Ending = decimal.Zero } )); var newDailyBalance = query.GroupBy(a => new { a.BillDate, a.WarehouseCode, a.ProductCode, a.UnitCode }) .Select(a => new DailyBalance { SettleDate = Convert.ToDateTime(a.Key.BillDate), WarehouseCode = a.Key.WarehouseCode, ProductCode = a.Key.ProductCode, UnitCode = a.Key.UnitCode, Beginning = a.Sum(d => d.Beginning), EntryAmount = a.Sum(d => d.EntryAmount), DeliveryAmount = a.Sum(d => d.DeliveryAmount), ProfitAmount = a.Sum(d => d.ProfitAmount), LossAmount = a.Sum(d => d.LossAmount), Ending = a.Sum(d => d.Beginning) + a.Sum(d => d.EntryAmount) - a.Sum(d => d.DeliveryAmount) + a.Sum(d => d.ProfitAmount) - a.Sum(d => d.LossAmount), }).ToArray(); newDailyBalance.AsParallel().ForAll(b => b.ID = Guid.NewGuid()); foreach (var item in newDailyBalance) { item.ID = Guid.NewGuid(); DailyBalanceRepository.Add(item); } DailyBalanceRepository.SaveChanges(); scope.Complete(); } return(true); } catch (Exception e) { errorInfo = "日结时出现错误,详情:" + e.Message; return(false); } }
public object GetDailyBalanceInfos(int page, int rows, string warehouseCode, string settleDate) { var inQuery = InBillDetailRepository.GetQueryable().AsEnumerable(); var outQuery = OutBillDetailRepository.GetQueryable().AsEnumerable(); var profitLossQuery = ProfitLossBillDetailRepository.GetQueryable().AsEnumerable(); var query = inQuery.Where(a => a.InBillMaster.WarehouseCode.Contains(warehouseCode)).Select(a => new { BillDate = a.InBillMaster.BillDate.ToString("yyyy-MM-dd"), a.InBillMaster.Warehouse.WarehouseCode, a.InBillMaster.Warehouse.WarehouseName, a.BillNo, a.InBillMaster.BillType.BillTypeCode, a.InBillMaster.BillType.BillTypeName, a.ProductCode, a.Product.ProductName, RealQuantity = a.RealQuantity, Beginning = 0.00.ToString(), EntryAmount = a.RealQuantity.ToString(), ProfitAmount = 0.00.ToString(), LossAmount = 0.00.ToString(), Ending = 0.00.ToString(), a.Unit.UnitName }).Union(outQuery.Where(a => a.OutBillMaster.WarehouseCode.Contains(warehouseCode)).Select(a => new { BillDate = a.OutBillMaster.BillDate.ToString("yyyy-MM-dd"), a.OutBillMaster.Warehouse.WarehouseCode, a.OutBillMaster.Warehouse.WarehouseName, a.BillNo, a.OutBillMaster.BillType.BillTypeCode, a.OutBillMaster.BillType.BillTypeName, a.ProductCode, a.Product.ProductName, RealQuantity = a.RealQuantity, Beginning = 0.00.ToString(), EntryAmount = 0.00.ToString(), ProfitAmount = 0.00.ToString(), LossAmount = 0.00.ToString(), Ending = 0.00.ToString(), a.Unit.UnitName })).Union(profitLossQuery.Where(a => a.ProfitLossBillMaster.WarehouseCode.Contains(warehouseCode)).Select(a => new { BillDate = a.ProfitLossBillMaster.BillDate.ToString("yyyy-MM-dd"), a.ProfitLossBillMaster.Warehouse.WarehouseCode, a.ProfitLossBillMaster.Warehouse.WarehouseName, a.BillNo, a.ProfitLossBillMaster.BillType.BillTypeCode, a.ProfitLossBillMaster.BillType.BillTypeName, a.ProductCode, a.Product.ProductName, RealQuantity = a.Quantity, Beginning = 0.00.ToString(), EntryAmount = 0.00.ToString(), ProfitAmount = a.Quantity > 0 ? a.Quantity.ToString() : 0.00.ToString(), LossAmount = a.Quantity < 0 ? (-a.Quantity).ToString() : 0.00.ToString(), Ending = 0.00.ToString(), a.Unit.UnitName })); if (!settleDate.Equals(string.Empty)) { DateTime date = Convert.ToDateTime(settleDate); query = query.Where(i => Convert.ToDateTime(i.BillDate) == date); } int total = query.Count(); query = query.Skip((page - 1) * rows).Take(rows); return(new { total, rows = query.ToArray() }); }
public bool Add(DateTime datetime, out string strResult) { bool result = false; strResult = string.Empty; var profitLossBillMaster = ProfitLossBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime); var profitLossBillDetail = ProfitLossBillDetailRepository.GetQueryable().Where(i => i.ProfitLossBillMaster.BillDate <= datetime); if (profitLossBillMaster.Any()) { #region 主表移入历史表 try { foreach (var item in profitLossBillMaster.ToArray()) { ProfitLossBillMasterHistory history = new ProfitLossBillMasterHistory(); history.BillNo = item.BillNo; history.BillDate = item.BillDate; history.BillTypeCode = item.BillTypeCode; history.CheckBillNo = ""; history.WarehouseCode = item.WarehouseCode; history.Status = item.Status; history.VerifyPersonID = item.VerifyPersonID; history.VerifyDate = item.VerifyDate; history.Description = item.Description; history.IsActive = item.IsActive; history.UpdateTime = item.UpdateTime; history.OperatePersonID = item.OperatePersonID; history.LockTag = item.LockTag; history.RowVersion = item.RowVersion; ProfitLossBillMasterHistoryRepository.Add(history); } result = true; } catch (Exception e) { strResult = "主库单:" + e.InnerException.ToString(); result = false; } #endregion if (profitLossBillDetail.Any()) { #region 细表移入历史表 try { foreach (var item in profitLossBillDetail.ToArray()) { ProfitLossBillDetailHistory history = new ProfitLossBillDetailHistory(); history.BillNo = item.BillNo; history.CellCode = item.CellCode; history.StorageCode = item.StorageCode; history.ProductCode = item.ProductCode; history.UnitCode = item.UnitCode; history.Price = item.Price; history.Quantity = item.Quantity; history.Description = item.Description; ProfitLossBillDetailHistoryRepository.Add(history); } result = true; } catch (Exception e) { strResult = "细库单:" + e.InnerException.ToString();; } #endregion } if (result == true) { #region 除主细分配表 try { foreach (var item in profitLossBillMaster.ToList()) { Del(ProfitLossBillDetailRepository, item.ProfitLossBillDetails); ProfitLossBillMasterRepository.Delete(item); result = true; } } catch (Exception e) { strResult = "删除情况:" + e.InnerException.ToString(); } ProfitLossBillMasterHistoryRepository.SaveChanges(); #endregion } } else { strResult = "数据不存在!"; } return(result); }