public Facede(Bll.Facede Application) { corporationExpenses = new CorporationExpenses(Application); corporationRevenues = new CorporationRevenues(Application); expenseItem = new ExpenseItem(Application); expenses = new Expenses(Application); memberExpenses = new MemberExpenses(Application); memberRevenues = new MemberRevenues(Application); revenueItem = new RevenueItem(Application); revenues = new Revenues(Application); }
protected RevenueItem GetRevenue(List <Bookings> bookings) { var revenue = new RevenueItem(); switch (ProductTypeDdl.SelectedValue) { case "DayPasses": revenue.AvgGuestPerBooking = bookings.Count > 0 ? (int)Math.Round(bookings.Average(b => b.Quantity)) : 0; break; case "Cabanas": case "Daybeds": case "SpaPasses": var firstBooking = bookings.FirstOrDefault(); int productId = firstBooking != null ? firstBooking.ProductId : 0; var firstProduct = _bookingRepository.ProductList.FirstOrDefault(p => p.ProductId == productId); revenue.AvgGuestPerBooking = firstProduct != null ? firstProduct.MaxGuest : 0; break; } // All Pass Redeemed revenue.TicketRedeemed = bookings.Sum(b => b.Quantity); revenue.TicketRevenue = bookings.Sum(x => x.PassRevenue); // Finish Survey var surveyFinish = bookings .Where(x => _bookingRepository.SurveyList.Where(sl => sl.BookingId == x.BookingId).Any(s => s.IsFinish)) .Select(x => _bookingRepository.SurveyList.FirstOrDefault(sl => sl.BookingId == x.BookingId)) .ToList(); if (surveyFinish.Any()) { surveyFinish.ForEach(item => { double spend = 0; if (item.IsBuyFoodAndDrink && item.FoodAndDrinkPrice.HasValue) { spend += item.FoodAndDrinkPrice.Value; } if (item.IsPayForParking) { spend += Constant.ParkingPrice; } if (item.IsBuySpaService && item.SpaServicePrice.HasValue) { spend += item.SpaServicePrice.Value; } if (item.IsBuyAdditionalService && item.AdditionalServicePrice.HasValue) { spend += item.AdditionalServicePrice.Value; } item.EstSpend = spend; item.RedeemedDate = item.Bookings.RedeemedDate; }); } var totalResponsed = bookings.Where(x => surveyFinish.Select(s => s.BookingId).Contains(x.BookingId)) .Sum(b => b.Quantity); // Breakdown Avg Ticket Spend revenue.FoodDrink = surveyFinish.Any() ? surveyFinish.Sum(s => s.FoodAndDrinkPrice ?? 0) / totalResponsed : 0; revenue.GiftShop = 0; revenue.AvgSpa = surveyFinish.Any() ? surveyFinish.Sum(s => s.SpaServicePrice ?? 0) / totalResponsed : 0; revenue.Parking = surveyFinish.Any() ? surveyFinish.Sum(s => s.ParkingPrice ?? 0) / totalResponsed : 0; revenue.Other = surveyFinish.Any() ? surveyFinish.Sum(s => s.AdditionalServicePrice ?? 0) / totalResponsed : 0; //revenue.AvgPerTicketSpend = revenue.FoodDrink + revenue.GiftShop + revenue.AvgSpa + revenue.Parking + revenue.Other; revenue.AvgPerTicketSpend = surveyFinish.Count > 0 ? surveyFinish.Sum(s => s.EstSpend) / totalResponsed : 0; var totalBookings = bookings.Count > 0 ? bookings.Count : 0; var nonSpender = surveyFinish.Count > 0 ? surveyFinish.Count(s => s.EstSpend.Equals(0.0)) : 0; var nonSpenderPercent = totalBookings > 0 ? nonSpender * 100 / totalBookings : 0; revenue.IncrementalRevenue = revenue.TicketRedeemed * revenue.AvgPerTicketSpend * (100 - nonSpenderPercent) / 100; revenue.TotalRevenue = revenue.TicketRevenue + revenue.IncrementalRevenue; // Calculate base on whose use those service and avg for whose used //var passUseFoodDrink = surveyFinish.Where(s => s.IsBuyFoodAndDrink).ToList(); //var passUseSpa = surveyFinish.Where(s => s.IsBuySpaService).ToList(); //var passUseParking = surveyFinish.Where(s => s.IsPayForParking).ToList(); //var passUseOther = surveyFinish.Where(s => s.IsBuyAdditionalService).ToList(); //revenue.FoodDrink = surveyFinish.Any() ? surveyFinish.Sum(s => s.FoodAndDrinkPrice ?? 0)/ totalResponsed : 0; //revenue.GiftShop = 0; //revenue.AvgSpa = surveyFinish.Any() ? surveyFinish.Sum(s => s.SpaServicePrice ?? 0) / totalResponsed : 0; //revenue.Parking = surveyFinish.Any() ? surveyFinish.Sum(s => s.ParkingPrice ?? 0) / totalResponsed : 0; //revenue.Other = surveyFinish.Any() ? surveyFinish.Sum(s => s.AdditionalServicePrice ?? 0) / totalResponsed : 0; // total Finish Survey var totalFinishSurvey = bookings.Count(x => _bookingRepository.SurveyList.Any(sl => sl.BookingId == x.BookingId && sl.IsFinish)); var usePool = bookings.Count(x => _bookingRepository.SurveyList.Where(sl => sl.BookingId == x.BookingId && sl.IsFinish).Count(s => s.UsePool) > 0); var useGym = bookings.Count(x => _bookingRepository.SurveyList.Where(sl => sl.BookingId == x.BookingId && sl.IsFinish).Count(s => s.UseGym) > 0); var useSpa = bookings.Count(x => _bookingRepository.SurveyList.Where(sl => sl.BookingId == x.BookingId && sl.IsFinish).Count(s => s.UseSpa) > 0); var userBc = bookings.Count(x => _bookingRepository.SurveyList.Where(sl => sl.BookingId == x.BookingId && sl.IsFinish).Count(s => s.UseBusinessCenter) > 0); revenue.PoolPercent = totalFinishSurvey > 0 ? (usePool * 100) / totalFinishSurvey : 0; revenue.GymPercent = totalFinishSurvey > 0 ? (useGym * 100) / totalFinishSurvey : 0; revenue.SpaPercent = totalFinishSurvey > 0 ? (useSpa * 100) / totalFinishSurvey : 0; revenue.BusinessCenterPercent = totalFinishSurvey > 0 ? (userBc * 100) / totalFinishSurvey : 0; return(revenue); }