ReportService.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. using SqlSugar;
  2. using WMS.BZModels;
  3. using WMS.BZModels.Dto.KLHC.BillInvDtos;
  4. using WMS.BZModels.Dto.KLHC.ReportDtos;
  5. using WMS.BZModels.Models.KLHC;
  6. using WMS.BZSqlSugar;
  7. using WMS.Info;
  8. using WMS.Util;
  9. namespace WMS.BZServices.KLHC
  10. {
  11. public class ReportService
  12. {
  13. private readonly Repository<BillInvflow> _reportrepository;
  14. private readonly Repository<BaseWarecell> _warecellRepository;
  15. private readonly Repository<BillInvnow> _billInvnowrepository;
  16. private readonly Dictionary<string, string> dicName = new Dictionary<string, string>
  17. {
  18. { "62100101","正常18"},{"string","异常09"} //,{"62100201","正常09"}
  19. };
  20. public ReportService(Repository<BillInvflow> reportrepository, Repository<BaseWarecell> warecellRepository, Repository<BillInvnow> billInvnowrepository)
  21. {
  22. _reportrepository = reportrepository;
  23. _warecellRepository = warecellRepository;
  24. _billInvnowrepository = billInvnowrepository;
  25. }
  26. public PagedInfo<ReportDto> GetPageList(Pagination pagination, ReportQueryDto reportQueryDto)
  27. {
  28. if (pagination.sord.ToUpper() != "ASC")
  29. {
  30. pagination.sidx = pagination.sidx.IsEmpty() ? "AddTime DESC" : pagination.sidx + " DESC";
  31. }
  32. if (pagination.sidx.IsEmpty())
  33. {
  34. pagination.sidx = "AddTime DESC";
  35. }
  36. ISugarQueryable<ReportDto> queryable = GetQueryable(reportQueryDto);
  37. //.OrderBy(pagination.sidx)
  38. var list = queryable.ToPage(pagination);
  39. return list;
  40. }
  41. private ISugarQueryable<ReportDto> GetQueryable(ReportQueryDto reportQueryDto)
  42. {
  43. var predicate = Expressionable.Create<BillInvflow, BaseWarehouse, BaseWarecell>();
  44. predicate = predicate.And((billInvflow, wareHouse, wareCell) => wareHouse.TypeNum == 1);
  45. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.KeyWord), (billInvflow, wareHouse, wareCell) => billInvflow.ContGrpBarCode.Contains(reportQueryDto.KeyWord) || billInvflow.MatCode.Contains(reportQueryDto.KeyWord) ||
  46. billInvflow.MatName.Contains(reportQueryDto.KeyWord) || billInvflow.RFIDBarCode.Contains(reportQueryDto.KeyWord) || wareCell.Code.Contains(reportQueryDto.KeyWord));
  47. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.ContGrpBarCode), (billInvflow, wareHouse, wareCell) => billInvflow.ContGrpBarCode.Contains(reportQueryDto.ContGrpBarCode));
  48. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.MatCode), (billInvflow, wareHouse, wareCell) => billInvflow.MatCode.Contains(reportQueryDto.MatCode));
  49. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.MatName), (billInvflow, wareHouse, wareCell) => billInvflow.MatName.Contains(reportQueryDto.MatName));
  50. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.RFIDBarCode), (billInvflow, wareHouse, wareCell) => billInvflow.RFIDBarCode.Contains(reportQueryDto.RFIDBarCode));
  51. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.CellCode), (billInvflow, wareHouse, wareCell) => wareCell.Code.Contains(reportQueryDto.CellCode));
  52. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.Tunnel), (billInvflow, wareHouse, wareCell) => wareCell.Tunnel == int.Parse(reportQueryDto.Tunnel));
  53. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.InvBarCode), (billInvflow, wareHouse, wareCell) => billInvflow.InvBarCode.Contains(reportQueryDto.InvBarCode));
  54. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.WarehouseId), (billInvflow, wareHouse, wareCell) => billInvflow.WarehouseId.Equals(reportQueryDto.WarehouseId));
  55. predicate = predicate.AndIF(reportQueryDto != null && reportQueryDto.AddTimeFrom.HasValue, (billInvflow, wareHouse, wareCell) => billInvflow.AddTime >= reportQueryDto.AddTimeFrom);
  56. predicate = predicate.AndIF(reportQueryDto != null && reportQueryDto.AddTimeTo.HasValue, (billInvflow, wareHouse, wareCell) => billInvflow.AddTime <= reportQueryDto.AddTimeTo);
  57. predicate = predicate.AndIF(reportQueryDto != null && reportQueryDto.EndTimeBegin.HasValue, (billInvflow, wareHouse, wareCell) => billInvflow.EditTime >= reportQueryDto.EndTimeBegin);
  58. predicate = predicate.AndIF(reportQueryDto != null && reportQueryDto.EndTimeEnd.HasValue, (billInvflow, wareHouse, wareCell) => billInvflow.EditTime <= reportQueryDto.EndTimeEnd);
  59. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.IsSurplus), (billInvflow, wareHouse, wareCell) => billInvflow.IsSurplus.Equals(reportQueryDto.IsSurplus));
  60. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.IsRework), (billInvflow, wareHouse, wareCell) => billInvflow.IsRework.Equals(reportQueryDto.IsRework));
  61. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.IsFast), (billInvflow, wareHouse, wareCell) => billInvflow.IsFast.Equals(reportQueryDto.IsFast));
  62. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.IsFail), (billInvflow, wareHouse, wareCell) => billInvflow.IsFail.Equals(reportQueryDto.IsFail));
  63. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.IsBack), (billInvflow, wareHouse, wareCell) => billInvflow.IsBack.Equals(reportQueryDto.IsBack));
  64. if (!string.IsNullOrEmpty(reportQueryDto?.InvStateCode))
  65. {
  66. var enums = (InvState)Enum.ToObject(typeof(InvState), Convert.ToInt32(reportQueryDto?.InvStateCode));
  67. predicate = predicate.AndIF(!string.IsNullOrEmpty(reportQueryDto?.InvStateCode), (billInvflow, wareHouse, wareCell) => billInvflow.InvStateCode.Equals(enums.ToString()));
  68. }
  69. var queryable = _reportrepository.Context.Queryable<BillInvflow, BaseWarehouse, BaseWarecell>((billInvflow, wareHouse, wareCell) => new object[] {
  70. JoinType.Left, billInvflow.WarehouseId == wareHouse.Id,
  71. JoinType.Left, billInvflow.PutRow == wareCell.Row && billInvflow.PutCol == wareCell.Col && billInvflow.PutLayer == wareCell.Layer,
  72. JoinType.Left,wareCell.WarehouseId==wareHouse.Id
  73. }).With(SqlWith.NoLock).Where(predicate.ToExpression())
  74. .Select((billInvflow, wareHouse, wareCell) => new ReportDto
  75. {
  76. Id = billInvflow.Id.ToString(),
  77. WarehouseName = wareHouse.Name,
  78. Memo = billInvflow.Memo,
  79. Tunnel = wareCell.Tunnel,
  80. Code = wareCell.Code,
  81. ContGrpId = billInvflow.ContGrpId.ToString(),
  82. ContGrpBarCode = billInvflow.ContGrpBarCode,
  83. ContGrpType = billInvflow.ContGrpType,
  84. InvStateCode = billInvflow.InvStateCode,
  85. BoxBarCode = billInvflow.BoxBarCode,
  86. BomDocsNo = billInvflow.BomDocsNo,
  87. BomMatId = billInvflow.BomMatId.ToString(),
  88. BomMatCode = billInvflow.BomMatCode,
  89. BomMatName = billInvflow.BomMatName,
  90. BomSetId = billInvflow.BomSetId.ToString(),
  91. ExecStateCode = billInvflow.ExecStateCode,
  92. ExecDocsNo = billInvflow.ExecDocsNo,
  93. ExecDocsRowNo = billInvflow.ExecDocsRowNo,
  94. ExecDocsTypeCode = billInvflow.ExecDocsTypeCode,
  95. InvBarCode = billInvflow.InvBarCode,
  96. InDocsNo = billInvflow.InDocsNo,
  97. InDocsRowNo = billInvflow.InDocsRowNo,
  98. SuppCode = billInvflow.SuppCode,
  99. SuppName = billInvflow.SuppName,
  100. CustCode = billInvflow.CustCode,
  101. CustName = billInvflow.CustName,
  102. IsFast = billInvflow.IsFast,
  103. IsFail = billInvflow.IsFail,
  104. FailReason = billInvflow.FailReason,
  105. PutRow = billInvflow.PutRow,
  106. PutCol = billInvflow.PutCol,
  107. PutLayer = billInvflow.PutLayer,
  108. MatId = billInvflow.MatId,
  109. MatCode = billInvflow.MatCode,
  110. MatName = billInvflow.MatName,
  111. TolWQty = billInvflow.TolWQty,
  112. NetWQty = billInvflow.NetWQty,
  113. TareWQty = billInvflow.TareWQty,
  114. LengthQty = billInvflow.LengthQty,
  115. CaQty = billInvflow.CaQty,
  116. SolderQty = billInvflow.SolderQty,
  117. ContUsageQty = billInvflow.ContUsageQty,
  118. BatchNo = billInvflow.BatchNo,
  119. ProductTime = billInvflow.ProductTime,
  120. OneInTime = billInvflow.OneInTime,
  121. RodBarCode = billInvflow.RodBarCode,
  122. HWBarCode = billInvflow.HWBarCode,
  123. RFIDBarCode = billInvflow.RFIDBarCode,
  124. CLBarCode = billInvflow.CLBarCode,
  125. HWTypeCode = billInvflow.HWTypeCode,
  126. BoilerNo = billInvflow.BoilerNo,
  127. PackNo = billInvflow.PackNo,
  128. BrandNo = billInvflow.BrandNo,
  129. ExecStd = billInvflow.ExecStd,
  130. LicenceCode = billInvflow.LicenceCode,
  131. SilkTypeCode = billInvflow.SilkTypeCode,
  132. Grade = billInvflow.Grade,
  133. IsBack = billInvflow.IsBack,
  134. BackReason = billInvflow.BackReason,
  135. ProcessDocsCode = billInvflow.ProcessDocsCode,
  136. ProductMachCode = billInvflow.ProductMachCode,
  137. ProductLineNo = billInvflow.ProductLineNo,
  138. AddTime = billInvflow.AddTime,
  139. EditTime = billInvflow.EditTime,
  140. }).MergeTable();
  141. return queryable;
  142. }
  143. public IList<ReportDto> GetList(ReportQueryDto reportQueryDto)
  144. {
  145. ISugarQueryable<ReportDto> sugarQueryable = GetQueryable(reportQueryDto);
  146. var list = sugarQueryable.ToList();
  147. return list;
  148. }
  149. /// <summary>
  150. /// 货位分析
  151. /// </summary>
  152. /// <returns></returns>
  153. public List<LocationUsageReportViewDto> GetLocationUsageReportList()
  154. {
  155. var list = _warecellRepository.Context.Queryable<BaseWarecell>()
  156. .GroupBy((warecell) => new
  157. {
  158. warecell.StateNum,
  159. warecell.IsStop,
  160. warecell.SCRel,
  161. }).Select((warecell) => new
  162. {
  163. Status = warecell.StateNum,
  164. warecell.SCRel,
  165. warecell.IsStop,
  166. Total = SqlFunc.AggregateCount(warecell.SCRel),
  167. })
  168. .MergeTable().ToList().OrderBy(o => o.SCRel);
  169. int _sort = 1;
  170. //基表:巷道、货架标识和仓库名称为维度查找总货位
  171. var baseTemp = list.GroupBy(s => new { s.SCRel }).Select(m => new { m.Key.SCRel, Total = m.Sum(n => n.Total) }).ToList();
  172. //关联表:巷道和仓库名称为维度,查找可用货位:未停用.已锁定也算有效货位
  173. var useLocation = list.Where(s => s.IsStop == 0).GroupBy(s => new { s.SCRel }).Select(m => new { m.Key.SCRel, Total = m.Sum(n => n.Total) }).ToList();
  174. //关联表:巷道和仓库名称为维度,查找锁定货位
  175. var lockLocation = list.Where(s => s.Status == (int)LocationState.LocationState_StockIn || s.Status == (int)LocationState.LocationState_StockOut || s.Status == (int)LocationState.LocationState_StockMove).GroupBy(s => new { s.SCRel }).Select(m => new { m.Key.SCRel, Total = m.Sum(n => n.Total) }).ToList();
  176. //关联表:巷道和仓库名称为维度,查找停用货位
  177. var stopLocation = list.Where(s => s.IsStop == 1).GroupBy(s => new { s.SCRel }).Select(m => new { m.Key.SCRel, Total = m.Sum(n => n.Total) }).ToList();
  178. //关联表:巷道和仓库名称为维度,查找物料货位
  179. var materialLocation = list.Where(s => s.Status == (int)LocationState.LocationState_Full).GroupBy(s => new { s.SCRel }).Select(m => new { m.Key.SCRel, Total = m.Sum(n => n.Total) }).ToList();
  180. var locationUsageReportViewDtos = from basetemp in baseTemp
  181. join uselocation in useLocation on new { basetemp.SCRel } equals new { uselocation.SCRel } into useinfo
  182. join locklocation in lockLocation on new { basetemp.SCRel } equals new { locklocation.SCRel } into lockinfo
  183. from lockinfoif in lockinfo.DefaultIfEmpty()
  184. join stoplocation in stopLocation on new { basetemp.SCRel } equals new { stoplocation.SCRel } into stopinfo
  185. from stopinfoif in stopinfo.DefaultIfEmpty()
  186. join materiallocation in materialLocation on new { basetemp.SCRel } equals new { materiallocation.SCRel } into materialinfo
  187. from materialinfoif in materialinfo.DefaultIfEmpty()
  188. select new LocationUsageReportViewDto()
  189. {
  190. Sort = _sort++,
  191. Tunnel = basetemp.SCRel.ToString(),
  192. AllLocationTotal = basetemp.Total,
  193. CanUseLocation = useinfo.FirstOrDefault() == null ? 0 : useinfo.First().Total,
  194. LockLocation = lockinfoif == null ? 0 : lockinfoif.Total,
  195. StopLocation = stopinfoif == null ? 0 : stopinfoif.Total,
  196. MaterilLocation = materialinfoif == null ? 0 : materialinfoif.Total
  197. };
  198. return locationUsageReportViewDtos.OrderBy(p => p.WarehouseName).ToList();
  199. }
  200. public PagedInfo<StockKeepReportViewDto> GetStockKeepReportList(Pagination pagination, BillInvNowQueryDto billInvNowQueryDto)
  201. {
  202. ISugarQueryable<StockKeepReportViewDto> sugarQueryable = GetStockKeepReportQueryable(billInvNowQueryDto);
  203. var lists = sugarQueryable.ToPage(pagination);
  204. return lists;
  205. }
  206. public IList<StockKeepReportViewDto> GetStockKeepReports(BillInvNowQueryDto billInvNowQueryDto)
  207. {
  208. ISugarQueryable<StockKeepReportViewDto> sugarQueryable = GetStockKeepReportQueryable(billInvNowQueryDto);
  209. var list = sugarQueryable.ToList();
  210. return list;
  211. }
  212. private ISugarQueryable<StockKeepReportViewDto> GetStockKeepReportQueryable(BillInvNowQueryDto billInvNowQueryDto)
  213. {
  214. var predicate = Expressionable.Create<BillInvnow>();
  215. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.KeyWord), billInvnow => billInvnow.MatCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatName.Contains(billInvNowQueryDto.KeyWord));
  216. var sugarQueryable = _billInvnowrepository.Context.Queryable<BillInvnow>().Where(predicate.ToExpression())
  217. .GroupBy(it => new { it.MatCode, it.MatName })
  218. .Select(it => new StockKeepReportViewDto
  219. {
  220. StockKeepTime7 = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) >= 0 && SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) <= 7, 1, 0)),
  221. StockKeepTime15 = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) > 7 && SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) <= 15, 1, 0)),
  222. StockKeepTime30 = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) > 15 && SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) <= 30, 1, 0)),
  223. StockKeepTime31 = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) > 30, 1, 0)),
  224. MatName = it.MatName,
  225. MatCode = it.MatCode
  226. });
  227. return sugarQueryable;
  228. }
  229. /// <summary>
  230. /// 库内满托占比
  231. /// </summary>
  232. /// <param name="pagination"></param>
  233. /// <param name="mantuoBarCodeRateQueryDto"></param>
  234. /// <returns></returns>
  235. public PagedInfo<MantuoBarCodeRateDto> GetMantuoBarCodeRate(Pagination pagination, MantuoBarCodeRateQueryDto mantuoBarCodeRateQueryDto)
  236. {
  237. ISugarQueryable<MantuoBarCodeRateDto> sugarQueryable = GetMantuoBarCodeRateQueryable(mantuoBarCodeRateQueryDto);
  238. var list = sugarQueryable.ToPage(pagination);
  239. list.Result.ForEach(o =>
  240. {
  241. if (!string.IsNullOrWhiteSpace(o.BomMatCode))
  242. {
  243. var bomMatCode = o.BomMatCode.Trim();
  244. if (dicName.ContainsKey(bomMatCode))
  245. {
  246. o.BomMatName = dicName[bomMatCode];
  247. }
  248. }
  249. });
  250. return list;
  251. }
  252. public IList<MantuoBarCodeRateDto> GetMantuoBarCodeRates(MantuoBarCodeRateQueryDto mantuoBarCodeRateQueryDto)
  253. {
  254. ISugarQueryable<MantuoBarCodeRateDto> sugarQueryable = GetMantuoBarCodeRateQueryable(mantuoBarCodeRateQueryDto);
  255. var list = sugarQueryable.ToList();
  256. list.ForEach(o =>
  257. {
  258. if (!string.IsNullOrWhiteSpace(o.BomMatCode))
  259. {
  260. var bomMatCode = o.BomMatCode.Trim();
  261. if (dicName.ContainsKey(bomMatCode))
  262. {
  263. o.BomMatName = dicName[bomMatCode];
  264. }
  265. }
  266. });
  267. return list;
  268. }
  269. private ISugarQueryable<MantuoBarCodeRateDto> GetMantuoBarCodeRateQueryable(MantuoBarCodeRateQueryDto mantuoBarCodeRateQueryDto)
  270. {
  271. var predicate = Expressionable.Create<BillInvnow, BaseWarehouse, BaseMatinfo, BillBomsetgrp>();
  272. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => wareHouse.TypeNum == 1 || wareHouse.TypeNum == 3);
  273. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.Secondary == false);
  274. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => !SqlFunc.IsNullOrEmpty(billInvnow.BomMatCode));
  275. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.InvStateCode.ToLower().Equals(InvState.InvEcecState_In.ToString().ToLower()));
  276. predicate = predicate.AndIF(!string.IsNullOrWhiteSpace(mantuoBarCodeRateQueryDto.KeyWord), (billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.BomMatCode.Contains(mantuoBarCodeRateQueryDto.KeyWord));
  277. predicate = predicate.AndIF(!string.IsNullOrWhiteSpace(mantuoBarCodeRateQueryDto.SetGrpCode), (billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.SetGrpCode.Contains(mantuoBarCodeRateQueryDto.SetGrpCode));
  278. predicate = predicate.AndIF(!string.IsNullOrWhiteSpace(mantuoBarCodeRateQueryDto.WarehouseId), (billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => wareHouse.Id.Equals(mantuoBarCodeRateQueryDto.WarehouseId));
  279. var sugarQueryable = _billInvnowrepository.Context.Queryable<BillInvnow, BaseWarehouse, BaseMatinfo, BillBomsetgrp>((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => new object[] {
  280. JoinType.Left, billInvnow.WarehouseId == wareHouse.Id,
  281. JoinType.Left,billInvnow.BomMatCode== baseMatinfo.Code,
  282. JoinType.Left,billInvnow.SetGrpCode== billBomsetgrp.Code
  283. }).Where(predicate.ToExpression())
  284. .GroupBy((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => new { SetGrpCode = billBomsetgrp.Name, billInvnow.BomMatCode, BomMatName = baseMatinfo.Name })
  285. .Select((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => new MantuoBarCodeRateDto
  286. {
  287. SetGrpCode = billBomsetgrp.Name,
  288. BomMatCode = billInvnow.BomMatCode,
  289. Qty = SqlFunc.AggregateDistinctCount(billInvnow.ContGrpBarCode),
  290. //WarehouseName = wareHouse.Name,
  291. BomMatName = baseMatinfo.Name,
  292. });
  293. return sugarQueryable;
  294. }
  295. public PagedInfo<MatNameNetWeightCategory> GetMatNameNetWeightCategory(Pagination pagination, BillInvNowQueryDto billInvNowQueryDto)
  296. {
  297. ISugarQueryable<MatNameNetWeightCategory> sugarQueryable = GetMatNameNetWeightCategoryQueryable(billInvNowQueryDto);
  298. var lists = sugarQueryable.ToPage(pagination);
  299. return lists;
  300. }
  301. public IList<MatNameNetWeightCategory> GetMatNameNetWeightCategorys(BillInvNowQueryDto billInvNowQueryDto)
  302. {
  303. ISugarQueryable<MatNameNetWeightCategory> sugarQueryable = GetMatNameNetWeightCategoryQueryable(billInvNowQueryDto);
  304. var lists = sugarQueryable.ToList();
  305. return lists;
  306. }
  307. private ISugarQueryable<MatNameNetWeightCategory> GetMatNameNetWeightCategoryQueryable(BillInvNowQueryDto billInvNowQueryDto)
  308. {
  309. var predicate = Expressionable.Create<BillInvnow>();
  310. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.KeyWord), billInvnow => billInvnow.MatCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatName.Contains(billInvNowQueryDto.KeyWord));
  311. var sugarQueryable = _billInvnowrepository.Queryable().Where(o => o.InvStateCode == "InvEcecState_In" && o.ContGrpType == FJContGrpType.Material)
  312. .Where(predicate.ToExpression())
  313. .Select(it => new MatNameNetWeightCategory
  314. {
  315. MatName = it.MatName,
  316. MatCode = it.MatCode,
  317. NetWQty = SqlFunc.AggregateSum(it.TolWQty),
  318. Qty = SqlFunc.AggregateDistinctCount(it.Id)
  319. })
  320. .GroupBy(o => new { o.MatName, o.MatCode });
  321. return sugarQueryable;
  322. }
  323. }
  324. }