public static ReportOrderVM GetFromOrder(Order order) { return(new ReportOrderVM { Order = ReportOrderDetails.FromOrder(order), Users = ReportOrderLabor_User.GetFromOrder(order), Months = ReportOrderLabor_Month.GetFromOrder(order), Materials = order.Materials.ToArray().OrderBy(x => x.Supplier).ThenByDescending(x => x.Date), }); }
public static IEnumerable <ReportOrderLabor_Month> GetFromOrder(Order order) { var YearsMonths = order.WorkOrders.Select(x => new { Year = x.Date.Year, Month = x.Date.Month }) .Union(order.WorkVehicles.Select(x => new { Year = x.Date.Year, Month = x.Date.Month })); return(YearsMonths.Select(x => { var rep = new ReportOrderLabor_Month(); rep.Year = x.Year; rep.Month = x.Month; rep.Users = ReportOrderLabor_User.GetFromOrder(order, x.Year, x.Month); rep.HoursApproved = TimeSpan.FromSeconds(rep.Users.Sum(u => u.HoursApproved.TotalSeconds)); rep.HoursNotApproved = TimeSpan.FromSeconds(rep.Users.Sum(u => u.HoursNotApproved.TotalSeconds)); rep.Cost_Hours = rep.Users.Sum(u => u.Cost_Hours); rep.Cost_Vehicles = rep.Users.Sum(u => u.Cost_Vehicles); rep.Cost_Expenses = rep.Users.Sum(u => u.Cost_Expenses); return rep; }) .ToArray() .OrderByDescending(x => x.Year) .ThenByDescending(x => x.Month)); }