Esempio n. 1
0
    protected void FillGrid()
    {
        UserView userView = UserView.GetInstance();

        DateTime fromDate = IsValidDate(txtStartDate.Text) ? GetDate(txtStartDate.Text)                              : DateTime.MinValue;
        DateTime toDate   = IsValidDate(txtEndDate.Text)   ? GetDate(txtEndDate.Text).Add(new TimeSpan(23, 59, 59))  : DateTime.MinValue;


        int organisation_type_group_id = -1;

        if (userView.IsClinicView)
        {
            organisation_type_group_id = 5;
        }
        if (userView.IsAgedCareView)
        {
            organisation_type_group_id = 6;
        }

        DataTable dt = null;

        if (rblDateType.SelectedValue == "Bookings")
        {
            dt = BookingDB.GetReport_InvoiceLines(fromDate, toDate, DateTime.MinValue, DateTime.MinValue, Convert.ToInt32(ddlOrgs.SelectedValue), Convert.ToInt32(ddlProviders.SelectedValue), Convert.ToInt32(ddlOfferings.SelectedValue), organisation_type_group_id);
        }
        else if (rblDateType.SelectedValue == "Invoices")
        {
            dt = BookingDB.GetReport_InvoiceLines(DateTime.MinValue, DateTime.MinValue, fromDate, toDate, Convert.ToInt32(ddlOrgs.SelectedValue), Convert.ToInt32(ddlProviders.SelectedValue), Convert.ToInt32(ddlOfferings.SelectedValue), organisation_type_group_id);
        }
        else
        {
            SetErrorMessage("Please select date range to be treatment date or invoice date.");
            return;
        }



        dt.Columns.Add("booking_duration_total_minutes", typeof(string));
        dt.Columns.Add("organisation_name", typeof(string));
        dt.Columns.Add("patient_id", typeof(int));
        dt.Columns.Add("patient_firstname", typeof(string));
        dt.Columns.Add("patient_surname", typeof(string));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["booking_id"] == DBNull.Value)
            {
                dt.Rows[i]["booking_duration_total_minutes"] = "";
                dt.Rows[i]["organisation_name"] = dt.Rows[i]["non_booking_organisation_name"];
                dt.Rows[i]["patient_id"]        = dt.Rows[i]["non_booking_patient_id"];
                dt.Rows[i]["patient_firstname"] = dt.Rows[i]["non_booking_patient_firstname"];
                dt.Rows[i]["patient_surname"]   = dt.Rows[i]["non_booking_patient_surname"];
            }
            else
            {
                DateTime bookingStart = Convert.ToDateTime(dt.Rows[i]["booking_date_start"]);
                DateTime bookingEnd   = Convert.ToDateTime(dt.Rows[i]["booking_date_end"]);
                dt.Rows[i]["booking_duration_total_minutes"] = bookingEnd.Subtract(bookingStart).TotalMinutes.ToString();
                dt.Rows[i]["organisation_name"] = dt.Rows[i]["booking_organisation_name"];
                dt.Rows[i]["patient_id"]        = dt.Rows[i]["booking_patient_id"];
                dt.Rows[i]["patient_firstname"] = dt.Rows[i]["booking_patient_firstname"];
                dt.Rows[i]["patient_surname"]   = dt.Rows[i]["booking_patient_surname"];
            }
        }


        Hashtable staffOfferingHash = StaffOfferingsDB.Get2DHash(true, Convert.ToInt32(ddlProviders.SelectedValue));

        dt.Columns.Add("commission_percent_text", typeof(string));
        dt.Columns.Add("fixed_rate_text", typeof(string));
        dt.Columns.Add("commission_percent_amount", typeof(decimal));
        dt.Columns.Add("fixed_rate_amount", typeof(decimal));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["booking_id"] == DBNull.Value)
            {
                dt.Rows[i]["commission_percent_text"]   = "";
                dt.Rows[i]["fixed_rate_text"]           = "";
                dt.Rows[i]["commission_percent_amount"] = 0;
                dt.Rows[i]["fixed_rate_amount"]         = 0;
            }
            else
            {
                StaffOfferings staffOffering = (StaffOfferings)staffOfferingHash[new Hashtable2D.Key(Convert.ToInt32(dt.Rows[i]["provider_staff_id"]), dt.Rows[i]["offering_id"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[i]["offering_id"]))];
                //dt.Rows[i]["commission_percent_text"]   = staffOffering == null || !staffOffering.IsCommission ? "" : Math.Round(staffOffering.CommissionPercent * Convert.ToDecimal(dt.Rows[i]["invoice_line_price"]) / 100, 2).ToString() + " (" + staffOffering.CommissionPercent + "%)";
                dt.Rows[i]["commission_percent_text"]   = staffOffering == null || !staffOffering.IsCommission ? "" : Math.Round(staffOffering.CommissionPercent * Convert.ToDecimal(dt.Rows[i]["invoice_line_price"]) / 100, 2).ToString();
                dt.Rows[i]["fixed_rate_text"]           = staffOffering == null || !staffOffering.IsFixedRate  ? "" : staffOffering.FixedRate.ToString();
                dt.Rows[i]["commission_percent_amount"] = staffOffering == null || !staffOffering.IsCommission ? Convert.ToDecimal(0.00) : Math.Round(staffOffering.CommissionPercent * Convert.ToDecimal(dt.Rows[i]["invoice_line_price"]) / 100, 2);
                dt.Rows[i]["fixed_rate_amount"]         = staffOffering == null || !staffOffering.IsFixedRate  ? Convert.ToDecimal(0.00) : staffOffering.FixedRate;
            }
        }



        Session["data_summaryReport"] = dt;

        if (!IsPostBack)
        {
            chkUsePaging.Checked = dt.Rows.Count > 50;
        }

        this.GrdSummaryReport.AllowPaging = chkUsePaging.Checked;

        if (dt.Rows.Count > 0)
        {
            if (IsPostBack && Session["sortExpression_summaryReport"] != null && Session["sortExpression_summaryReport"].ToString().Length > 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort = Session["sortExpression_summaryReport"].ToString();
                GrdSummaryReport.DataSource = dataView;
            }
            else
            {
                GrdSummaryReport.DataSource = dt;
            }


            try
            {
                GrdSummaryReport.DataBind();
                GrdSummaryReport.PagerSettings.FirstPageText = "1";
                GrdSummaryReport.PagerSettings.LastPageText  = GrdSummaryReport.PageCount.ToString();
                GrdSummaryReport.DataBind();
            }
            catch (Exception ex)
            {
                HideTableAndSetErrorMessage("", ex.ToString());
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdSummaryReport.DataSource = dt;
            GrdSummaryReport.DataBind();

            int TotalColumns = GrdSummaryReport.Rows[0].Cells.Count;
            GrdSummaryReport.Rows[0].Cells.Clear();
            GrdSummaryReport.Rows[0].Cells.Add(new TableCell());
            GrdSummaryReport.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdSummaryReport.Rows[0].Cells[0].Text       = "No Record Found";
        }
    }