Exemple #1
0
 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 ReportOrderDetails FromOrder(Order order)
        {
            var details = new ReportOrderDetails
            {
                OrderId        = order.OrderId,
                Client         = order.Client,
                Description    = order.Description,
                ExpectedCost   = order.Cost,
                Cost_Hours     = order.WorkOrders.Where(o => o.UserId == order.TeamLeaderId || o.UserApprove != null).Sum(o => o.Cost),
                Cost_Vehicles  = order.WorkVehicles.Where(v => v.UserId == order.TeamLeaderId || v.UserApprove != null).Sum(v => v.Cost_Total),
                Cost_Expenses  = 0,
                Cost_Materials = order.Materials.Sum(m => m.Total_Used),
                Cost_Various   = 0,
                FinishDate     = order.FinishDate,
                TeamLeaderInfo = order.TeamLeader.LastName + ' ' + order.TeamLeader.FirstName,
                UsersInfo      = order.Users.Where(x => x.UserId != order.TeamLeaderId).Select(x => x.User.LastName + " " + x.User.FirstName).OrderBy(x => x).ToArray(),
            };

            // calcolo costo totale
            details.Cost_Labor = details.Cost_Hours + details.Cost_Vehicles + details.Cost_Expenses;
            details.Cost_Total = details.Cost_Labor + details.Cost_Materials + details.Cost_Various;
            return(details);
        }