private void SetUnitAndQuantity(DXInfo.Models.RdRecords rdRecords, DXInfo.Models.ClientRetailOutStockDetail detail) { DXInfo.Models.Inventory inv = uow.Inventory.GetById(g => g.Id == detail.InvId); DXInfo.Models.MeasurementUnitGroup group = uow.MeasurementUnitGroup.GetById(g => g.Id == inv.MeasurementUnitGroup); if (group.Category == (int)DXInfo.Models.UnitGroupCategory.No) { rdRecords.MainUnit = inv.MainUnit; rdRecords.STUnit = inv.MainUnit; rdRecords.ExchRate = 1; rdRecords.Quantity = rdRecords.Num; } else { if (!inv.StockUnit.HasValue) { throw new DXInfo.Models.BusinessException("请设置库存单位"); } DXInfo.Models.UnitOfMeasures uom = uow.UnitOfMeasures.GetById(g => g.Id == inv.StockUnit); rdRecords.MainUnit = inv.MainUnit; rdRecords.STUnit = inv.StockUnit.Value; rdRecords.ExchRate = uom.Rate; rdRecords.Quantity = rdRecords.Num * uom.Rate; } }
private void RetailOtherInStock(List <RetailTemp> q2) { var g2 = (from d in q2 group d by new { d.DeptId, d.CurStock.WhId, d.UserId, d.CreateDate.Date } into g select new { g.Key.DeptId, g.Key.WhId, g.Key.UserId, g.Key.Date }).ToList(); foreach (var rd in g2) { if (common.IsBalance(rd.Date, rd.WhId)) { continue; } var lRdRecord = uow.RdRecord.GetAll().Where(w => w.WhId == rd.WhId && w.DeptId == rd.DeptId && w.Maker == rd.UserId && w.RdDate == rd.Date && w.VouchType == DXInfo.Models.VouchTypeCode.OtherInStock && w.RdCode == "013" && w.BusType == "013").ToList(); var rdRecord = lRdRecord.Where(w => w.IsVerify).FirstOrDefault(); if (rdRecord == null) { rdRecord = NewOtherInStock(rd.Date, rd.WhId, true); uow.RdRecord.Add(rdRecord); uow.Commit(); } var q3 = (from d in q2 where d.DeptId == rd.DeptId && d.CurStock.WhId == rd.WhId && d.UserId == rd.UserId select d).ToList(); foreach (var rds in q3) { decimal exchRate = 1; decimal quantity = 0; Guid sTUnit = Guid.Empty; DXInfo.Models.Inventory inv = uow.Inventory.GetById(g => g.Id == rds.InvId); DXInfo.Models.MeasurementUnitGroup group = uow.MeasurementUnitGroup.GetById(g => g.Id == inv.MeasurementUnitGroup); if (group.Category == (int)DXInfo.Models.UnitGroupCategory.No) { quantity = rds.Num; sTUnit = inv.MainUnit; } else { if (!inv.StockUnit.HasValue) { continue; } DXInfo.Models.UnitOfMeasures uom = uow.UnitOfMeasures.GetById(g => g.Id == inv.StockUnit); sTUnit = inv.StockUnit.Value; exchRate = uom.Rate; quantity = rds.Num * uom.Rate; } bool ret = RetailUpdateCurrent(rds.CurStock, 1, rds.Num, quantity); if (ret) { AddRetailRdRecords(rds.ConsumeListId, rdRecord.Id, 1, rds.InvId, inv.MainUnit, sTUnit, exchRate, rds.Batch, rds.Num, rds.Price, rds.CurStock); } } uow.Commit(); } }