ReportService.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. using SqlSugar;
  2. using wms.sqlsugar.model.fj;
  3. using WMS.BZModels;
  4. using WMS.BZModels.Dto.FJ.BillInvDtos;
  5. using WMS.BZModels.Dto.FJ.ReportDtos;
  6. using WMS.BZSqlSugar;
  7. using WMS.Info;
  8. using WMS.Util;
  9. namespace WMS.BZServices.FJ
  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, BaseWarehouse>((warecell, warehouse) => new object[] {
  156. JoinType.Left,warecell.WarehouseId == warehouse.Id })
  157. .GroupBy((warecell, warehouse) => new
  158. {
  159. warecell.StateNum,
  160. warecell.IsStop,
  161. warecell.Tunnel,
  162. warehouse.Id,
  163. warehouse.Name
  164. }).Select((warecell, warehouse) => new
  165. {
  166. Status = warecell.StateNum,
  167. warecell.Tunnel,
  168. warecell.IsStop,
  169. HouseId = warehouse.Id,
  170. warehouse.Name,
  171. Total = SqlFunc.AggregateCount(warecell.Tunnel),
  172. })
  173. .MergeTable().ToList().OrderBy(o => o.Tunnel);
  174. int _sort = 1;
  175. //基表:巷道、货架标识和仓库名称为维度查找总货位
  176. var baseTemp = list.GroupBy(s => new { s.Tunnel, s.HouseId, s.Name }).Select(m => new { m.Key.Name, m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  177. //关联表:巷道和仓库名称为维度,查找可用货位:未停用.已锁定也算有效货位
  178. var useLocation = list.Where(s => s.IsStop == 0).GroupBy(s => new { s.Tunnel, s.HouseId, s.Name }).Select(m => new { m.Key.Name, m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  179. //关联表:巷道和仓库名称为维度,查找锁定货位
  180. 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.Tunnel, s.HouseId, s.Name }).Select(m => new { m.Key.Name, m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  181. //关联表:巷道和仓库名称为维度,查找停用货位
  182. var stopLocation = list.Where(s => s.IsStop == 1).GroupBy(s => new { s.Tunnel, s.HouseId, s.Name }).Select(m => new { m.Key.Name, m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  183. //关联表:巷道和仓库名称为维度,查找物料货位
  184. var materialLocation = list.Where(s => s.Status == (int)LocationState.LocationState_Full).GroupBy(s => new { s.Tunnel, s.HouseId, s.Name }).Select(m => new { m.Key.Name, m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  185. var locationUsageReportViewDtos = from basetemp in baseTemp
  186. join uselocation in useLocation on new { basetemp.Tunnel, basetemp.Name } equals new { uselocation.Tunnel, uselocation.Name } into useinfo
  187. join locklocation in lockLocation on new { basetemp.Tunnel, basetemp.Name } equals new { locklocation.Tunnel, locklocation.Name } into lockinfo
  188. from lockinfoif in lockinfo.DefaultIfEmpty()
  189. join stoplocation in stopLocation on new { basetemp.Tunnel, basetemp.Name } equals new { stoplocation.Tunnel, stoplocation.Name } into stopinfo
  190. from stopinfoif in stopinfo.DefaultIfEmpty()
  191. join materiallocation in materialLocation on new { basetemp.Tunnel, basetemp.Name } equals new { materiallocation.Tunnel, materiallocation.Name } into materialinfo
  192. from materialinfoif in materialinfo.DefaultIfEmpty()
  193. orderby basetemp.Name
  194. select new LocationUsageReportViewDto()
  195. {
  196. Sort = _sort++,
  197. Tunnel = basetemp.Tunnel.ToString(),
  198. WarehouseName = basetemp.Name,
  199. AllLocationTotal = basetemp.Total,
  200. CanUseLocation = useinfo.FirstOrDefault() == null ? 0 : useinfo.First().Total,
  201. LockLocation = lockinfoif == null ? 0 : lockinfoif.Total,
  202. StopLocation = stopinfoif == null ? 0 : stopinfoif.Total,
  203. MaterilLocation = materialinfoif == null ? 0 : materialinfoif.Total
  204. };
  205. return locationUsageReportViewDtos.OrderBy(p => p.WarehouseName).ToList();
  206. }
  207. public PagedInfo<StockKeepReportViewDto> GetStockKeepReportList(Pagination pagination, BillInvNowQueryDto billInvNowQueryDto)
  208. {
  209. ISugarQueryable<StockKeepReportViewDto> sugarQueryable = GetStockKeepReportQueryable(billInvNowQueryDto);
  210. var lists = sugarQueryable.ToPage(pagination);
  211. return lists;
  212. }
  213. public IList<StockKeepReportViewDto> GetStockKeepReports(BillInvNowQueryDto billInvNowQueryDto)
  214. {
  215. ISugarQueryable<StockKeepReportViewDto> sugarQueryable = GetStockKeepReportQueryable(billInvNowQueryDto);
  216. var list = sugarQueryable.ToList();
  217. return list;
  218. }
  219. private ISugarQueryable<StockKeepReportViewDto> GetStockKeepReportQueryable(BillInvNowQueryDto billInvNowQueryDto)
  220. {
  221. var predicate = Expressionable.Create<BillInvnow>();
  222. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.KeyWord), billInvnow => billInvnow.MatCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatName.Contains(billInvNowQueryDto.KeyWord));
  223. var sugarQueryable = _billInvnowrepository.Context.Queryable<BillInvnow>().Where(predicate.ToExpression())
  224. .GroupBy(it => new { it.MatCode, it.MatName })
  225. .Select(it => new StockKeepReportViewDto
  226. {
  227. 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)),
  228. 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)),
  229. 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)),
  230. StockKeepTime31 = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.DateDiff(DateType.Day, it.ProductTime, DateTime.Now) > 30, 1, 0)),
  231. MatName = it.MatName,
  232. MatCode = it.MatCode
  233. });
  234. return sugarQueryable;
  235. }
  236. /// <summary>
  237. /// 库内满托占比
  238. /// </summary>
  239. /// <param name="pagination"></param>
  240. /// <param name="mantuoBarCodeRateQueryDto"></param>
  241. /// <returns></returns>
  242. public PagedInfo<MantuoBarCodeRateDto> GetMantuoBarCodeRate(Pagination pagination, MantuoBarCodeRateQueryDto mantuoBarCodeRateQueryDto)
  243. {
  244. ISugarQueryable<MantuoBarCodeRateDto> sugarQueryable = GetMantuoBarCodeRateQueryable(mantuoBarCodeRateQueryDto);
  245. var list = sugarQueryable.ToPage(pagination);
  246. list.Result.ForEach(o =>
  247. {
  248. if (!string.IsNullOrWhiteSpace(o.BomMatCode))
  249. {
  250. var bomMatCode = o.BomMatCode.Trim();
  251. if (dicName.ContainsKey(bomMatCode))
  252. {
  253. o.BomMatName = dicName[bomMatCode];
  254. }
  255. }
  256. });
  257. return list;
  258. }
  259. public IList<MantuoBarCodeRateDto> GetMantuoBarCodeRates(MantuoBarCodeRateQueryDto mantuoBarCodeRateQueryDto)
  260. {
  261. ISugarQueryable<MantuoBarCodeRateDto> sugarQueryable = GetMantuoBarCodeRateQueryable(mantuoBarCodeRateQueryDto);
  262. var list = sugarQueryable.ToList();
  263. list.ForEach(o =>
  264. {
  265. if (!string.IsNullOrWhiteSpace(o.BomMatCode))
  266. {
  267. var bomMatCode = o.BomMatCode.Trim();
  268. if (dicName.ContainsKey(bomMatCode))
  269. {
  270. o.BomMatName = dicName[bomMatCode];
  271. }
  272. }
  273. });
  274. return list;
  275. }
  276. private ISugarQueryable<MantuoBarCodeRateDto> GetMantuoBarCodeRateQueryable(MantuoBarCodeRateQueryDto mantuoBarCodeRateQueryDto)
  277. {
  278. var predicate = Expressionable.Create<BillInvnow, BaseWarehouse, BaseMatinfo, BillBomsetgrp>();
  279. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => wareHouse.TypeNum == 1 || wareHouse.TypeNum == 3);
  280. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.Secondary == false);
  281. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => !SqlFunc.IsNullOrEmpty(billInvnow.BomMatCode));
  282. predicate = predicate.And((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.InvStateCode.ToLower().Equals(InvState.InvEcecState_In.ToString().ToLower()));
  283. predicate = predicate.AndIF(!string.IsNullOrWhiteSpace(mantuoBarCodeRateQueryDto.KeyWord), (billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.BomMatCode.Contains(mantuoBarCodeRateQueryDto.KeyWord));
  284. predicate = predicate.AndIF(!string.IsNullOrWhiteSpace(mantuoBarCodeRateQueryDto.SetGrpCode), (billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => billInvnow.SetGrpCode.Contains(mantuoBarCodeRateQueryDto.SetGrpCode));
  285. predicate = predicate.AndIF(!string.IsNullOrWhiteSpace(mantuoBarCodeRateQueryDto.WarehouseId), (billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => wareHouse.Id.Equals(mantuoBarCodeRateQueryDto.WarehouseId));
  286. var sugarQueryable = _billInvnowrepository.Context.Queryable<BillInvnow, BaseWarehouse, BaseMatinfo, BillBomsetgrp>((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => new object[] {
  287. JoinType.Left, billInvnow.WarehouseId == wareHouse.Id,
  288. JoinType.Left,billInvnow.BomMatCode== baseMatinfo.Code,
  289. JoinType.Left,billInvnow.SetGrpCode== billBomsetgrp.Code
  290. }).Where(predicate.ToExpression())
  291. .GroupBy((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => new { SetGrpCode = billBomsetgrp.Name, billInvnow.BomMatCode, BomMatName = baseMatinfo.Name })
  292. .Select((billInvnow, wareHouse, baseMatinfo, billBomsetgrp) => new MantuoBarCodeRateDto
  293. {
  294. SetGrpCode = billBomsetgrp.Name,
  295. BomMatCode = billInvnow.BomMatCode,
  296. Qty = SqlFunc.AggregateDistinctCount(billInvnow.ContGrpBarCode),
  297. //WarehouseName = wareHouse.Name,
  298. BomMatName = baseMatinfo.Name,
  299. });
  300. return sugarQueryable;
  301. }
  302. public PagedInfo<MatNameNetWeightCategory> GetMatNameNetWeightCategory(Pagination pagination, BillInvNowQueryDto billInvNowQueryDto)
  303. {
  304. ISugarQueryable<MatNameNetWeightCategory> sugarQueryable = GetMatNameNetWeightCategoryQueryable(billInvNowQueryDto);
  305. var lists = sugarQueryable.ToPage(pagination);
  306. return lists;
  307. }
  308. public IList<MatNameNetWeightCategory> GetMatNameNetWeightCategorys(BillInvNowQueryDto billInvNowQueryDto)
  309. {
  310. ISugarQueryable<MatNameNetWeightCategory> sugarQueryable = GetMatNameNetWeightCategoryQueryable(billInvNowQueryDto);
  311. var lists = sugarQueryable.ToList();
  312. return lists;
  313. }
  314. private ISugarQueryable<MatNameNetWeightCategory> GetMatNameNetWeightCategoryQueryable(BillInvNowQueryDto billInvNowQueryDto)
  315. {
  316. var predicate = Expressionable.Create<BillInvnow>();
  317. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.KeyWord), billInvnow => billInvnow.MatCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatName.Contains(billInvNowQueryDto.KeyWord));
  318. var sugarQueryable = _billInvnowrepository.Queryable().Where(o => o.InvStateCode == "InvEcecState_In" && o.ContGrpType == FJContGrpType.Material)
  319. .Where(predicate.ToExpression())
  320. .Select(it => new MatNameNetWeightCategory
  321. {
  322. MatName = it.MatName,
  323. MatCode = it.MatCode,
  324. NetWQty = SqlFunc.AggregateSum(it.TolWQty),
  325. Qty = SqlFunc.AggregateDistinctCount(it.Id)
  326. })
  327. .GroupBy(o => new { o.MatName, o.MatCode });
  328. return sugarQueryable;
  329. }
  330. }
  331. }