protected void rptEvents_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is SailExpense)
            {
                var expense = (SailExpense)e.Item.DataItem;

                IList <EventCode> list = new List <EventCode>();

                int groups = expense.NumberOfGroup;
                if (groups == 0)
                {
                    groups = 1;
                }

                for (int ii = 1; ii <= groups; ii++)
                {
                    var eventCode = new EventCode(Module);
                    eventCode.SailExpense = expense;
                    eventCode.Group       = ii;
                    list.Add(eventCode);
                }

                var rptGroups = (Repeater)e.Item.FindControl("rptGroups");
                rptGroups.DataSource = list;
                rptGroups.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["expenseid"] != null && Request.QueryString["group"] != null)
                {
                    var expense = Module.ExpenseGetById(Convert.ToInt32(Request.QueryString["expenseid"]));
                    int group   = Convert.ToInt32(Request.QueryString["group"]);

                    var code = new EventCode(Module)
                    {
                        SailExpense = expense, Group = group
                    };

                    litDate.Text          = expense.Date.ToString("dd/MM/yyyy");
                    titleBookingView.Text = string.Format("{0}{1:ddMMyy}-{2:00}", expense.Trip.TripCode, expense.Date, group);
                    litTrip.Text          = expense.Trip.Name;

                    int    pax               = 0;
                    double revenuePaid       = 0;
                    double revenueReceivable = 0;
                    double revenueTotal      = 0;

                    double expensePaid    = 0;
                    double expensePayable = 0;
                    double expenseTotal   = 0;
                    foreach (Booking booking in code.Bookings)
                    {
                        pax += booking.Pax;

                        double paid = booking.Total * booking.CurrencyRate - booking.TotalReceivable;
                        revenuePaid       += paid;
                        revenueReceivable += booking.TotalReceivable;
                        revenueTotal      += booking.Total * booking.CurrencyRate;
                    }

                    foreach (ExpenseService service in code.Services)
                    {
                        expensePaid    += service.Paid;
                        expensePayable += service.Cost - service.Paid;
                        expenseTotal   += service.Cost;
                    }

                    litPax.Text          = pax.ToString();
                    litRevenueTotal.Text = revenueTotal.ToString("#,0.#");
                    litRevenuePaid.Text  = revenuePaid.ToString("#,0.#");
                    litReceivable.Text   = revenueReceivable.ToString("#,0.#");
                    litPayableTotal.Text = expenseTotal.ToString("#,0.#");
                    litPayablePaid.Text  = expensePaid.ToString("#,0.#");
                    litPayable.Text      = expensePayable.ToString("#,0.#");
                    litExpected.Text     = (revenueTotal - expenseTotal).ToString("#,0.#");
                    litRealCash.Text     = (revenuePaid - expensePaid).ToString("#,0.#");

                    rptExpenseServices.DataSource = code.Services;
                    rptExpenseServices.DataBind();

                    rptBookingList.DataSource = code.Bookings;
                    rptBookingList.DataBind();
                }
            }
        }