Hello Team,
I want to implement data filtering, by using date range to filter the booking and the final column will sum up below as shown on the screenshot.

CONTROLLER METHOD.
public ActionResult GetAllBookingHistoryPDF(string RoomNumber, string sDate = null, string eDate = null)
{
DateTime? startDate = null;
if (!string.IsNullOrEmpty(sDate))
startDate = Convert.ToDateTime(sDate);
DateTime? endDate = null;
if (!string.IsNullOrEmpty(eDate))
endDate = Convert.ToDateTime(eDate);
var bookingList = objHotelDbEntities.RoomBookings.Join(objHotelDbEntities.Rooms,
booking => booking.AssignRoomId,
room => room.RoomId,
(booking, room) => new { booking = booking, room = room });
var modifiedData = bookingList.GroupBy(x => new { x.booking.BookingFrom, x.booking.BookingTo, x.booking.BookingId }).Select(x => new AllBookingDetail
{
CustomerName = x.FirstOrDefault().booking.CustomerName,
Address = x.FirstOrDefault().booking.Address,
PhoneNo = x.FirstOrDefault().booking.PhoneNo,
BookingFrom = x.Key.BookingFrom,
BookingTo = x.Key.BookingTo,
BookingId = x.FirstOrDefault().booking.BookingId,
RoomNumber = x.FirstOrDefault().room.RoomNumber,
NoOfMembers = x.FirstOrDefault().booking.NoOfMembers,
numberOfDays = System.Data.Entity.DbFunctions.DiffDays(x.Key.BookingFrom, x.Key.BookingTo).Value,
RoomPrice = x.FirstOrDefault().room.RoomPrice,
TotalAmount = x.Sum(a=>a.booking.TotalAmount)
}).ToList();
if (!string.IsNullOrEmpty(sDate) && !string.IsNullOrEmpty(eDate))
{
DateTime fromDate = DateTime.Parse(sDate);
DateTime toDate = DateTime.Parse(eDate);
modifiedData = modifiedData.Where(a => (a.BookingFrom) >= fromDate && (a.BookingTo) <= toDate).OrderBy(x => x.BookingFrom).ToList();
}
decimal total = 0;
if (modifiedData != null && modifiedData.Count() > 0)
{
total = modifiedData.Sum(a => a.TotalAmount)
}
return Json(modifiedData, JsonRequestBehavior.AllowGet);
}
Emmmanuel FIADUFEPosted Dec 3, 2024, 2:18 PM
Hello team ,
Please any further help will be highly appreciated
Emmmanuel FIADUFEPosted Nov 28, 2024, 10:09 AM
Hello Sangeetha S
Thank you for your response, but however this code is causing the data not to even load again, as you can see in the screenshot
// Return the JSON result
return Json(new { bookings = modifiedData, totalAmount = total }, JsonRequestBehavior.AllowGet);
Sangeetha SPosted Nov 28, 2024, 5:27 AM
Hi,
Emmmanuel FIADUFEPosted Nov 27, 2024, 3:18 PM
JS Function
HTML