private static FunctionSheetReportBag PrerateFunctionSheetReportBag(EventModel eventModel) { var bag = new FunctionSheetReportBag() { EventName = eventModel.Name, NumberOfPeople = eventModel.Places, EventDate = eventModel.Date.ToString("D"), Time = DateTime.Now.ToString("G") }; if (eventModel.EventType != null) { bag.EventType = eventModel.EventType.Name; } if (eventModel.PrimaryContact != null) { bag.MainContact = eventModel.PrimaryContact.ContactName; bag.Telephone = eventModel.PrimaryContact.Contact.Phone1; } if (!string.IsNullOrWhiteSpace(eventModel.Event.InvoiceAddress)) { bag.CorrespondenceAddress = eventModel.Event.InvoiceAddress; } else if (eventModel.PrimaryContact != null && !string.IsNullOrWhiteSpace(eventModel.PrimaryContact.FullAddressSepareted)) { bag.CorrespondenceAddress = eventModel.PrimaryContact.FullAddressSepareted; } // Notes bag.Notes = new List <FunctionSheetEventNote>(eventModel.EventNotes.ToList().Select(x => new FunctionSheetEventNote() { Date = x.EventNote.Date.ToString("d"), Note = x.Note, Author = string.Format("by {0}", x.EventNote.User.FirstName) })); // Event items bag.Items = new List <FunctionSheetEventItem>(); eventModel.EventCaterings.ForEach(x => bag.Items.Add(new FunctionSheetEventItem() { Time = x.Time, Type = "Catering Option", DisplayTime = x.Time.ToString("t"), Note = x.EventCatering.Notes, Products = x.EventBookedProducts.Select(y => string.Format("{0} x {1}", y.Quantity, y.Product.Name)).ToList() })); eventModel.EventRooms.ForEach(x => bag.Items.Add(new FunctionSheetEventItem() { Time = x.StartTime, Type = "Room Option", DisplayTime = x.StartTime.ToString("t"), Note = x.EventRoom.Notes, Products = x.EventBookedProducts.Select(y => string.Format("{0} x {1}", y.Quantity, y.Product.Name)).ToList() })); eventModel.EventGolfs.ForEach(x => bag.Items.Add(new FunctionSheetEventItem() { Time = x.Time, Type = "Golf Option", DisplayTime = x.Time.ToString("t"), Note = x.EventGolf.Notes, Products = x.EventBookedProducts.Select(y => string.Format("{0} x {1}", y.Quantity, y.Product.Name)).ToList() })); eventModel.EventInvoices.ForEach(x => bag.Items.Add(new FunctionSheetEventItem() { Type = "Special Option", Note = x.EventInvoice.Notes, Products = x.EventBookedProducts.Select(y => string.Format("{0} x {1}", y.Quantity, y.Product.Name)).ToList(), })); bag.Items = bag.Items.OrderBy(x => x.Time).ToList(); var departmentItems = eventModel.EventBookedProducts.GroupBy(x => x.Product.ProductDepartment.Department) .Select(x => new { Department = x.Key, Value = x.Where(y => y.EventBookedProduct.Product.ProductOption.OptionName != "Invoice").Select(y => y.TotalPrice).Sum() }).ToList(); bag.TotalItems = departmentItems.Select(x => new { Department = x.Department, Value = x.Value.ToString("C") }).ToList(); bag.TotalExceptVAT = departmentItems.Select(x => x.Value).Sum(); bag.LessDepositPaid = eventModel.EventPayments.Where(x => x.IsDeposit).Sum(x => x.Amount); bag.BalanceToPay = bag.TotalExceptVAT - bag.LessDepositPaid; return(bag); }
public FunctionSheet(FunctionSheetReportBag bag) { InitializeComponent(); this.DataSource = bag; }