示例#1
0
        public ActionResult BookingsReport(Booking booking)
        {
            List <BookingDetails> bookingsDetails = new List <BookingDetails>();
            var bookings = from t in db.Bookings select t;

            bookings = bookings.Where(b => b.CheckIn.CompareTo(booking.CheckIn) >= 0 &&
                                      b.CheckOut.CompareTo(booking.CheckOut) <= 0
                                      );
            foreach (var book in bookings)
            {
                Client client = dbClient.Clients.Find(book.ClientId);


                var roomBookings = from t in dbRoomBooking.RoomBookings select t;
                roomBookings = roomBookings.Where(r => r.BookingId == book.BookingId); //camerele ce aparti rezervarii curente

                int         totalPrice = 0;
                List <Room> rooms      = new List <Room>();
                foreach (var roomB in roomBookings)
                {
                    totalPrice += roomB.Price;
                    Room r = dbRoom.Rooms.Find(roomB.RoomId);
                    rooms.Add(r);
                }



                bookingsDetails.Add(new BookingDetails {
                    client = client, booking = book, totalPrice = totalPrice, rooms = rooms
                });
            }



            ReportFactory reportFact = ReportFactory.getInstance();

            if (Request.Form["CSVReportButton"] != null)
            {
                BookingReport r = reportFact.export(ReportFactory.ReportTypes.CSV);
                Response.Write(r.exportReport(bookingsDetails));
                Response.ContentType = "application/csv";
                Response.AppendHeader("Content-Disposition", "attachment; filename=booking.csv");
                Response.End();
            }
            else if (Request.Form["XMLReportButton"] != null)
            {
                BookingReport r = reportFact.export(ReportFactory.ReportTypes.XML);
                Response.Write(r.exportReport(bookingsDetails));
                Response.ContentType = "application/xml";
                Response.AppendHeader("Content-Disposition", "attachment; filename=booking.xml");
                Response.End();
            }

            return(RedirectToAction("AdminAfterLogin", "Account"));
        }
示例#2
0
        public BookingReport export(ReportTypes reportType)
        {
            BookingReport report = null;

            if (reportType.Equals(ReportTypes.CSV))
            {
                report = new CSVReport();
            }
            else if (reportType.Equals(ReportTypes.XML))
            {
                report = new XMLReport();
            }
            return(report);
        }
示例#3
0
        // GET: Report
        public ActionResult Index(string topEvent, string dateRange)
        {
            var events = db.Events;
            BookingReportList    reportList = new BookingReportList();
            List <BookingReport> reports    = new List <BookingReport>();
            DateTime             fromDate;

            if ((topEvent != null && topEvent == "weekly") || (dateRange != null && dateRange == "weekly"))
            {
                fromDate = DateTime.Today.AddDays(-7);
            }
            else if ((topEvent != null && topEvent == "monthly") || (dateRange != null && dateRange == "monthly"))
            {
                fromDate = DateTime.Today.AddDays(-30);
            }
            else
            {
                fromDate = DateTime.Today.AddDays(-365);
            }

            foreach (var eventDetail in events)
            {
                BookingReport bookingReport = new BookingReport();
                bookingReport.eventDetails = eventDetail;
                var bookings = db.Bookings.Where(x => x.EventID == eventDetail.EventID);
                if (topEvent != null || dateRange != null)
                {
                    bookings = bookings.Where(b => b.BookingDate >= fromDate && b.BookingDate <= DateTime.Today);
                }
                bookingReport.count = bookings.Count();
                double totalSale = 0.0;
                foreach (var booking in bookings)
                {
                    if (!eventDetail.EventLocation.ToUpper().Contains("MUSEUM"))
                    {
                        var seatBooking = db.SeatBookings.Find(booking.SeatBookingID);
                        var seat        = db.Seats.Find(seatBooking.SeatID);
                        if (seat.SeatLevel == "L2")
                        {
                            totalSale += eventDetail.BasePrice * 1.5;
                        }
                        else if (seat.SeatLevel == "L1")
                        {
                            totalSale += eventDetail.BasePrice * 3;
                        }
                        else
                        {
                            totalSale += eventDetail.BasePrice;
                        }
                    }
                    else
                    {
                        totalSale += eventDetail.BasePrice;
                    }
                }
                bookingReport.totalSale = totalSale;
                reports.Add(bookingReport);
            }
            reports = reports.OrderByDescending(x => x.count).ToList();
            if (topEvent != null)
            {
                if (topEvent == "weekly" || topEvent == "monthly")
                {
                    if (reports.Count() > 5)
                    {
                        reports = (List <BookingReport>)reports.Take(5).ToList();
                    }
                }
                else
                {
                    if (reports.Count() > 10)
                    {
                        reports = (List <BookingReport>)reports.Take(10).ToList();
                    }
                }
            }
            reportList.Reports = reports;
            return(View(reportList));
        }