protected DataTable SetBookingsList(Staff staff = null)
    {
        if (txtStartDate.Text.Length > 0 && !Utilities.IsValidDate(txtStartDate.Text, "dd-mm-yyyy"))
        {
            SetErrorMessage("Start date must be empty or valid and of the format dd-mm-yyyy");
            return(null);
        }
        if (txtEndDate.Text.Length > 0 && !Utilities.IsValidDate(txtEndDate.Text, "dd-mm-yyyy"))
        {
            SetErrorMessage("End date must be empty or valid and of the format dd-mm-yyyy");
            return(null);
        }
        DateTime startDate = txtStartDate.Text.Length == 0 ? DateTime.MinValue : Utilities.GetDate(txtStartDate.Text, "dd-mm-yyyy");
        DateTime endDate   = txtEndDate.Text.Length == 0 ? DateTime.MinValue : Utilities.GetDate(txtEndDate.Text, "dd-mm-yyyy");

        UserView userView        = UserView.GetInstance();
        int      loggedInStaffID = Session["StaffID"] == null ? -1 : Convert.ToInt32(Session["StaffID"]);

        if (staff == null)
        {
            staff = StaffDB.GetByID(GetFormID());
        }



        DataTable tblBookingList = BookingDB.GetDataTable_Between(startDate, endDate, null, null, null, staff, true);

        int[] booking_ids = new int[tblBookingList.Rows.Count];
        for (int i = 0; i < tblBookingList.Rows.Count; i++)
        {
            booking_ids[i] = Convert.ToInt32(tblBookingList.Rows[i]["booking_booking_id"]);
        }
        Hashtable changeHistoryHash = BookingDB.GetChangeHistoryCountHash(booking_ids);

        lblBookingListCount.Text = "(" + tblBookingList.Rows.Count + ")";
        if (tblBookingList.Rows.Count == 0)
        {
            lblBookingsList_NoRowsMessage.Visible = true;
            pnlBookingsList.Visible = false;
        }
        else
        {
            lblBookingsList_NoRowsMessage.Visible = false;
            pnlBookingsList.Visible = true;


            System.Collections.Hashtable staffHash            = StaffDB.GetAllInHashtable(true, true, true, false);
            System.Collections.ArrayList bookingsWithInvoices = new System.Collections.ArrayList();


            tblBookingList.Columns.Add("notes_text", typeof(string));
            tblBookingList.Columns.Add("invoice_text", typeof(string));
            tblBookingList.Columns.Add("booking_url", typeof(string));
            tblBookingList.Columns.Add("hide_booking_link", typeof(Boolean));
            tblBookingList.Columns.Add("show_invoice_row", typeof(int));
            tblBookingList.Columns.Add("show_notes_row", typeof(int));
            tblBookingList.Columns.Add("show_printletter_row", typeof(int));
            tblBookingList.Columns.Add("show_bookingsheet_row", typeof(int));
            tblBookingList.Columns.Add("inv_type_text", typeof(string));
            tblBookingList.Columns.Add("inv_outstanding_text", typeof(string));
            tblBookingList.Columns.Add("added_by_deleted_by_row", typeof(string));
            tblBookingList.Columns.Add("booking_change_history_link", typeof(string));
            tblBookingList.Columns.Add("hide_change_history_link", typeof(Boolean));
            tblBookingList.Columns.Add("show_change_history_row", typeof(string));
            bool hasInvoiceRows      = false;
            bool hasNotesRows        = false;
            bool hasPrintLetterRows  = false;
            bool hasBookingSheetRows = false;
            for (int i = 0; i < tblBookingList.Rows.Count; i++)
            {
                Booking curBooking = BookingDB.LoadFull(tblBookingList.Rows[i]);

                tblBookingList.Rows[i]["notes_text"] = Note.GetPopupLinkTextV2(15, curBooking.EntityID, curBooking.NoteCount > 0, true, 1050, 530, "images/notes-bw-24.jpg", "images/notes-24.png", "btnUpdateBookingList.click()");

                bool canSeeInvoiceInfo = userView.IsAdminView || userView.IsPrincipal || (curBooking.Provider != null && curBooking.Provider.StaffID == loggedInStaffID && curBooking.DateStart > DateTime.Today.AddMonths(-2));
                if (canSeeInvoiceInfo && Convert.ToInt32(tblBookingList.Rows[i]["booking_inv_count"]) > 0)
                {
                    string onclick = @"onclick=""javascript:window.showModalDialog('Invoice_ViewV2.aspx?booking_id=" + curBooking.BookingID + @"', '', 'dialogWidth:820px;dialogHeight:860px;center:yes;resizable:no; scroll:no');return false;""";
                    tblBookingList.Rows[i]["invoice_text"] = "<a " + onclick + " href=\"\">View Inv.</a>";

                    if (curBooking.DateDeleted == DateTime.MinValue && curBooking.DeletedBy == null)
                    {
                        hasInvoiceRows = true;
                    }

                    bookingsWithInvoices.Add(curBooking.BookingID);
                }
                else
                {
                    tblBookingList.Rows[i]["invoice_text"] = "";
                }

                tblBookingList.Rows[i]["hide_booking_link"] = !((userView.IsClinicView && curBooking.Organisation.OrganisationType.OrganisationTypeID == 218) ||
                                                                (userView.IsAgedCareView && (new List <int> {
                    139, 367, 372
                }).Contains(curBooking.Organisation.OrganisationType.OrganisationTypeID)));

                if (curBooking.DateDeleted == DateTime.MinValue && curBooking.DeletedBy == null)
                {
                    hasNotesRows       = true;
                    hasPrintLetterRows = true;
                    if (!Convert.ToBoolean(tblBookingList.Rows[i]["hide_booking_link"]))
                    {
                        hasBookingSheetRows = true;
                    }
                }

                string urlParams = string.Empty;
                if (curBooking.Organisation != null)
                {
                    urlParams += (urlParams.Length == 0 ? "?" : "&") + "orgs=" + curBooking.Organisation.OrganisationID;
                }
                if (curBooking.Patient != null)
                {
                    urlParams += (urlParams.Length == 0 ? "?" : "&") + "patient=" + curBooking.Patient.PatientID;
                }
                urlParams += (urlParams.Length == 0 ? "?" : "&") + "scroll_to_cell=" + "td_" + (curBooking.Organisation != null ? "" : curBooking.Organisation.OrganisationID.ToString()) + "_" + curBooking.Provider.StaffID + "_" + curBooking.DateStart.ToString("yyyy_MM_dd_HHmm");
                urlParams += (urlParams.Length == 0 ? "?" : "&") + "date=" + curBooking.DateStart.ToString("yyyy_MM_dd");
                tblBookingList.Rows[i]["booking_url"] = curBooking.GetBookingSheetLinkV2();



                string addedBy                 = curBooking.AddedBy == null || staffHash[curBooking.AddedBy.StaffID] == null ? "" : (((Staff)staffHash[curBooking.AddedBy.StaffID]).IsExternal ? "[External Staff] " : "") + ((Staff)staffHash[curBooking.AddedBy.StaffID]).Person.FullnameWithoutMiddlename;
                string addedDate               = curBooking.DateCreated == DateTime.MinValue                                       ? "" : curBooking.DateCreated.ToString("MMM d, yyyy");
                string deletedBy               = curBooking.DeletedBy == null || staffHash[curBooking.DeletedBy.StaffID] == null ? "" : ((Staff)staffHash[curBooking.DeletedBy.StaffID]).Person.FullnameWithoutMiddlename;
                string deletedDate             = curBooking.DateDeleted == DateTime.MinValue                                       ? "" : curBooking.DateDeleted.ToString("MMM d, yyyy");
                string added_by_deleted_by_row = string.Empty;
                added_by_deleted_by_row += "Added By: " + addedBy + " (" + addedDate + ")";
                if (deletedBy.Length > 0 || deletedDate.Length > 0)
                {
                    added_by_deleted_by_row += "\r\nDeleted By: " + deletedBy + " (" + deletedDate + ")";
                }
                tblBookingList.Rows[i]["added_by_deleted_by_row"] = added_by_deleted_by_row;

                tblBookingList.Rows[i]["booking_change_history_link"] = curBooking.GetBookingChangeHistoryPopupLinkImage();
                tblBookingList.Rows[i]["hide_change_history_link"]    = changeHistoryHash[curBooking.BookingID] == null;
            }

            System.Collections.Hashtable hashHasMedicareOrDVAInvoices = BookingDB.GetHashHasMedicareDVA((int[])bookingsWithInvoices.ToArray(typeof(int)));

            for (int i = 0; i < tblBookingList.Rows.Count; i++)
            {
                tblBookingList.Rows[i]["show_invoice_row"]        = hasInvoiceRows              ? 1 : 0;
                tblBookingList.Rows[i]["show_notes_row"]          = hasNotesRows                ? 1 : 0;
                tblBookingList.Rows[i]["show_printletter_row"]    = hasPrintLetterRows          ? 1 : 0;
                tblBookingList.Rows[i]["show_bookingsheet_row"]   = hasBookingSheetRows         ? 1 : 0;
                tblBookingList.Rows[i]["show_change_history_row"] = changeHistoryHash.Count > 0 ? 1 : 0;

                int  booking_id   = Convert.ToInt32(tblBookingList.Rows[i]["booking_booking_id"]);
                bool has_medicare = hashHasMedicareOrDVAInvoices[new Hashtable2D.Key(booking_id, -1)] != null && Convert.ToBoolean(hashHasMedicareOrDVAInvoices[new Hashtable2D.Key(booking_id, -1)]);
                bool has_dva      = hashHasMedicareOrDVAInvoices[new Hashtable2D.Key(booking_id, -2)] != null && Convert.ToBoolean(hashHasMedicareOrDVAInvoices[new Hashtable2D.Key(booking_id, -2)]);
                if (has_medicare)
                {
                    tblBookingList.Rows[i]["inv_type_text"] = "Medicare";
                }
                else if (has_dva)
                {
                    tblBookingList.Rows[i]["inv_type_text"] = "DVA";
                }
                else
                {
                    tblBookingList.Rows[i]["inv_type_text"] = string.Empty;
                }
            }
            tblBookingList.DefaultView.Sort = "booking_date_start DESC";
            tblBookingList            = tblBookingList.DefaultView.ToTable();
            lstBookingList.DataSource = tblBookingList;
            lstBookingList.DataBind();
        }

        return(tblBookingList);
    }