public List <SumPtdByFunctionDto> GetSumPtdByFunctionData(SumPtdFuncGetByParamInput filter) { var data = _ExecSummService.GetAllSumPtdByFunction(filter); var listData = Mapper.Map <List <SumPtdByFunctionDto> >(data); var groupData = listData.GroupBy(x => new { x.REGION, x.FUNCTION, x.VEHICLE_TYPE, x.REPORT_MONTH, x.REPORT_YEAR }) .Select(p => new SumPtdByFunctionDto() { REGION = p.FirstOrDefault().REGION, FUNCTION = p.FirstOrDefault().FUNCTION, VEHICLE_TYPE = p.FirstOrDefault().VEHICLE_TYPE, REPORT_MONTH = p.FirstOrDefault().REPORT_MONTH, REPORT_YEAR = p.FirstOrDefault().REPORT_YEAR, TOTAL_VEHICLE = p.Sum(c => c.TOTAL_VEHICLE), TOTAL_VEHICLE_COST = p.Sum(c => c.TOTAL_VEHICLE_COST), TOTAL_FUEL_AMOUNT = p.Sum(c => c.TOTAL_FUEL_AMOUNT), TOTAL_FUEL_COST = p.Sum(c => c.TOTAL_FUEL_COST), TOTAL_KM = p.Max(c => c.TOTAL_KM), TOTAL_OPERATIONAL_COST = p.Sum(c => c.TOTAL_OPERATIONAL_COST), ACCIDENT_COUNT = p.Sum(c => c.ACCIDENT_COUNT) }).ToList(); return(groupData); }
public List <SUM_REPORT_DATA> GetAllSumPtdByFunction(SumPtdFuncGetByParamInput filter) { Expression <Func <SUM_REPORT_DATA, bool> > queryFilter = PredicateHelper.True <SUM_REPORT_DATA>(); if (filter != null) { if (filter.MonthFrom > 0) { queryFilter = queryFilter.And(c => c.REPORT_MONTH >= filter.MonthFrom); } if (filter.MonthTo > 0) { queryFilter = queryFilter.And(c => c.REPORT_MONTH <= filter.MonthTo); } if (filter.YearFrom > 0) { queryFilter = queryFilter.And(c => c.REPORT_YEAR >= filter.YearFrom); } if (filter.YearTo > 0) { queryFilter = queryFilter.And(c => c.REPORT_YEAR <= filter.YearTo); } if (!string.IsNullOrEmpty(filter.Region)) { queryFilter = queryFilter.And(c => c.REGION.ToUpper() == filter.Region.ToUpper()); } if (!string.IsNullOrEmpty(filter.Function)) { var listFunction = filter.Function.ToUpper().Split(',').ToList(); if (listFunction.Contains("OTHERS")) { queryFilter = queryFilter.And(c => listFunction.Contains(c.FUNCTION.ToUpper()) || (c.FUNCTION.ToUpper() != "SALES" && c.FUNCTION.ToUpper() != "MARKETING" && c.FUNCTION.ToUpper() != "OPERATIONS")); } else { queryFilter = queryFilter.And(c => listFunction.Contains(c.FUNCTION.ToUpper())); } } if (!string.IsNullOrEmpty(filter.VehicleType)) { queryFilter = queryFilter.And(c => c.VEHICLE_TYPE.ToUpper() == filter.VehicleType.ToUpper()); } } return(_sumPtdByFuncRepository.Get(queryFilter, null, "").ToList()); }