Beispiel #1
0
    public void FillOfferingGrid()
    {
        Booking.InvoiceType invType = InvoiceType;

        decimal GST_Percent  = Convert.ToDecimal(((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["GST_Percent"].Value);
        decimal GST_Modifier = GST_Percent / (decimal)100;

        bool hasGstItems_HC = false;
        bool hasGstItems_PT = false;

        DataTable dt_offering;
        DataTable dt_org_offering = null; // just to get the prices if there is a specific price for this clinic

        try
        {
            if (this.booking == null)
            {
                dt_offering = OrganisationOfferingsDB.GetDataTable_OfferingsByOrg(true, 0);  // get empty datatable
            }
            else
            {
                if (booking.Organisation.OrganisationType.OrganisationTypeGroup.ID == 5) // clinics
                {
                    dt_offering     = OfferingDB.GetDataTable(false, "1,3", "63");
                    dt_org_offering = OrganisationOfferingsDB.GetDataTable_OfferingsByOrg(true, booking.Organisation.OrganisationID, "1,3", "63,89"); // dt_offering = OfferingDB.GetDataTable(1);
                }
                else if (booking.Organisation.OrganisationType.OrganisationTypeGroup.ID == 6)                                                         // aged care
                {
                    dt_offering     = OfferingDB.GetDataTable(false, "3,4", "63");
                    dt_org_offering = OrganisationOfferingsDB.GetDataTable_OfferingsByOrg(true, booking.Organisation.OrganisationID, "3,4", "63,89");  // dt_offering = OfferingDB.GetDataTable(4);
                }
                else
                {
                    throw new Exception("Unknown booking screen type");
                }


                // If row exists in org-offering table, then use that price
                for (int i = 0; i < dt_org_offering.Rows.Count; i++)
                {
                    for (int j = 0; j < dt_offering.Rows.Count; j++)
                    {
                        if (Convert.ToInt32(dt_offering.Rows[j]["o_offering_id"]) == Convert.ToInt32(dt_org_offering.Rows[i]["o_offering_id"]))
                        {
                            dt_offering.Rows[j]["o_default_price"] = dt_org_offering.Rows[i]["o_default_price"];
                        }
                    }
                }
            }


            for (int i = dt_offering.Rows.Count - 1; i >= 0; i--)
            {
                // remove service they are here for
                if (booking.Offering.OfferingID == Convert.ToInt32(dt_offering.Rows[i]["o_offering_id"]))
                {
                    dt_offering.Rows.RemoveAt(i);
                }
                else
                {
                    // if pt pays  invoice, use default price for all (so no change)
                    // if medicare invoice, use default price for all offerings OTHER than the service they are here for (so no change)
                    // if dva      invoice, use dva price for all

                    // Remove this ... and show pt price and hc price on the screen and use that on the data tables
                    //
                    //if (invType == Booking.InvoiceType.DVA)
                    //    dt_offering.Rows[i]["o_default_price"] = dt_offering.Rows[i]["o_dva_charge"];
                }
            }


            // add all products (by invoice type id  1 or 4, and offering_type_ids for only products : "89")
            DataTable dt_products = null;
            if (this.booking == null)
            {
                dt_products = OfferingDB.GetDataTable(false, UserView.GetInstance().IsAgedCareView ? "3,4" : "1,3", "89");
            }
            else
            {
                if (booking.Organisation.OrganisationType.OrganisationTypeGroup.ID == 5)
                {
                    dt_products = OfferingDB.GetDataTable(false, "1,3", "89");
                }
                else if (booking.Organisation.OrganisationType.OrganisationTypeGroup.ID == 6)
                {
                    dt_products = OfferingDB.GetDataTable(false, "3,4", "89");
                }
                else
                {
                    throw new Exception("Unknown booking screen type");
                }

                //
                // If row exists in org-offering table, then use that price
                //
                if (dt_org_offering != null)
                {
                    for (int i = 0; i < dt_org_offering.Rows.Count; i++)
                    {
                        for (int j = 0; j < dt_products.Rows.Count; j++)
                        {
                            if (Convert.ToInt32(dt_products.Rows[j]["o_offering_id"]) == Convert.ToInt32(dt_org_offering.Rows[i]["o_offering_id"]))
                            {
                                dt_products.Rows[j]["o_default_price"] = dt_org_offering.Rows[i]["o_default_price"];
                            }
                        }
                    }
                }
            }


            for (int i = 0; i < dt_products.Rows.Count; i++)
            {
                dt_offering.ImportRow(dt_products.Rows[i]);
            }


            bool invoiceGapPayments = Convert.ToInt32(SystemVariableDB.GetByDescr("InvoiceGapPayments").Value) == 1;

            dt_offering.Columns.Add("hc_paid");
            dt_offering.Columns.Add("pt_price", typeof(decimal));
            dt_offering.Columns.Add("hc_price", typeof(decimal));
            dt_offering.Columns.Add("pt_gst", typeof(decimal));
            dt_offering.Columns.Add("hc_gst", typeof(decimal));
            for (int i = 0; i < dt_offering.Rows.Count; i++)
            {
                bool isGstExempt = Convert.ToBoolean(dt_offering.Rows[i]["o_is_gst_exempt"]);

                string medicare_company_code = dt_offering.Rows[i]["o_medicare_company_code"].ToString();
                string dva_company_code      = dt_offering.Rows[i]["o_dva_company_code"].ToString();
                string tac_company_code      = dt_offering.Rows[i]["o_tac_company_code"].ToString();

                bool incGstOnPTInvoices = IncGstOnInvoices_Private && !isGstExempt;
                bool incGstOnHCInvoices = (invType == Booking.InvoiceType.Medicare && IncGstOnInvoices_MC && !isGstExempt) ||
                                          (invType == Booking.InvoiceType.DVA && IncGstOnInvoices_DVA && !isGstExempt) ||
                                          (invType == Booking.InvoiceType.Insurance && IncGstOnInvoices_Insurance && !isGstExempt);

                dt_offering.Rows[i]["pt_price"] = Convert.ToDecimal(dt_offering.Rows[i]["o_default_price"]);
                dt_offering.Rows[i]["hc_price"] = 0;
                dt_offering.Rows[i]["pt_gst"]   = !incGstOnPTInvoices ? 0 : Convert.ToDecimal(dt_offering.Rows[i]["pt_price"]) * GST_Modifier;
                dt_offering.Rows[i]["hc_gst"]   = !incGstOnHCInvoices ? 0 : Convert.ToDecimal(dt_offering.Rows[i]["hc_price"]) * GST_Modifier;



                if (invType == Booking.InvoiceType.DVA)
                {
                    dt_offering.Rows[i]["hc_paid"] = dva_company_code.Length > 0;

                    if (dva_company_code.Length > 0)
                    {
                        decimal default_price = Convert.ToDecimal(dt_offering.Rows[i]["o_default_price"]);
                        decimal dva_price     = Convert.ToDecimal(dt_offering.Rows[i]["o_dva_charge"]);

                        dt_offering.Rows[i]["pt_price"] = (invoiceGapPayments && default_price > dva_price) ? default_price - dva_price : 0;
                        dt_offering.Rows[i]["hc_price"] = dva_price;
                        dt_offering.Rows[i]["pt_gst"]   = !incGstOnPTInvoices ? 0 : Convert.ToDecimal(dt_offering.Rows[i]["pt_price"]) * GST_Modifier;
                        dt_offering.Rows[i]["hc_gst"]   = !incGstOnHCInvoices ? 0 : Convert.ToDecimal(dt_offering.Rows[i]["hc_price"]) * GST_Modifier;
                    }
                }
                if (invType == Booking.InvoiceType.Insurance)
                {
                    dt_offering.Rows[i]["hc_paid"] = tac_company_code.Length > 0;

                    //if (tac_company_code.Length > 0)
                    //{
                    decimal default_price = Convert.ToDecimal(dt_offering.Rows[i]["o_default_price"]);
                    decimal tac_price     = (tac_company_code.Length > 0) ? Convert.ToDecimal(dt_offering.Rows[i]["o_tac_charge"]) : default_price;

                    dt_offering.Rows[i]["pt_price"] = (invoiceGapPayments && default_price > tac_price) ? default_price - tac_price : 0;
                    dt_offering.Rows[i]["hc_price"] = tac_price;
                    dt_offering.Rows[i]["pt_gst"]   = !incGstOnPTInvoices ? 0 : Convert.ToDecimal(dt_offering.Rows[i]["pt_price"]) * GST_Modifier;
                    dt_offering.Rows[i]["hc_gst"]   = !incGstOnHCInvoices ? 0 : Convert.ToDecimal(dt_offering.Rows[i]["hc_price"]) * GST_Modifier;
                    //}
                }
                else if (InvoiceType == Booking.InvoiceType.Medicare)
                {
                    dt_offering.Rows[i]["hc_paid"] = false; // medicare invoice - all items to add beyond booking offering are privately invoiced
                }
                else
                {
                    dt_offering.Rows[i]["hc_paid"] = false;
                }


                if (!isGstExempt && Convert.ToDecimal(dt_offering.Rows[i]["hc_gst"]) > 0)
                {
                    hasGstItems_HC = true;
                }
                if (!isGstExempt && Convert.ToDecimal(dt_offering.Rows[i]["pt_gst"]) > 0)
                {
                    hasGstItems_PT = true;
                }
            }
        }
        catch (Exception ex)
        {
            SetErrorMessage("", ex.ToString());
            //return;
            throw;
        }

        Session["data_offering"] = dt_offering;


        if (!hasGstItems_HC && !hasGstItems_PT)
        {
            GrdOffering.Columns[7].Visible = false;
            GrdOffering.Columns[5].Visible = false;
        }


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


            try
            {
                GrdOffering.DataBind();



                // add items for javascript live search so can have
                // dropdown that when chosing an item, it clicks the right button

                string fieldsSep = "[[fieldsSep]]";
                string itemSep   = "[[itemSep]]";

                string output = string.Empty;
                for (int i = 0; i < GrdOffering.Rows.Count; i++)
                {
                    Label  lblShortName = (Label)GrdOffering.Rows[i].FindControl("lblShortName");
                    Button btnAdd       = (Button)GrdOffering.Rows[i].FindControl("btnAdd");
                    output += (i == 0 ? "" : itemSep) + lblShortName.Text + fieldsSep + btnAdd.ClientID;
                }

                hiddenItemList.Value = output;

                // end live search data
            }
            catch (Exception)
            {
                //SetErrorMessage("", ex.ToString()); // already should be showing in page containing this control

                this.HideElementsForError();
                throw;
            }
        }
        else
        {
            dt_offering.Rows.Add(dt_offering.NewRow());
            GrdOffering.DataSource = dt_offering;
            GrdOffering.DataBind();

            int TotalColumns = GrdOffering.Rows[0].Cells.Count;
            GrdOffering.Rows[0].Cells.Clear();
            GrdOffering.Rows[0].Cells.Add(new TableCell());
            GrdOffering.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdOffering.Rows[0].Cells[0].Text       = "No Items Found";
        }
    }
Beispiel #2
0
    public DataTable GetSelectedList()
    {
        DataTable dt_selected_list = Session["data_selected"] as DataTable;

        string areaTreated = string.Empty;

        if (InvoiceType == Booking.InvoiceType.DVA || InvoiceType == Booking.InvoiceType.Insurance)
        {
            areaTreated = HealthCardDB.GetActiveByPatientID(Booking.Patient.PatientID).AreaTreated;
        }

        if (dt_selected_list == null)
        {
            dt_selected_list = new DataTable();
            dt_selected_list.Columns.Add(new DataColumn("offering_id"));
            dt_selected_list.Columns.Add(new DataColumn("hc_paid"));
            dt_selected_list.Columns.Add(new DataColumn("short_name"));
            dt_selected_list.Columns.Add(new DataColumn("name"));
            dt_selected_list.Columns.Add(new DataColumn("area_treated"));
            dt_selected_list.Columns.Add(new DataColumn("service_reference"));
            dt_selected_list.Columns.Add(new DataColumn("show_area_treated", typeof(Boolean)));
            dt_selected_list.Columns.Add(new DataColumn("show_service_reference", typeof(Boolean)));
            dt_selected_list.Columns.Add(new DataColumn("default_price"));
            dt_selected_list.Columns.Add(new DataColumn("pt_price"));                // added
            dt_selected_list.Columns.Add(new DataColumn("hc_price"));                // added
            dt_selected_list.Columns.Add(new DataColumn("pt_gst"));                  // added
            dt_selected_list.Columns.Add(new DataColumn("hc_gst"));                  // added
            dt_selected_list.Columns.Add(new DataColumn("quantity"));
            dt_selected_list.Columns.Add(new DataColumn("total_line_price"));
            dt_selected_list.Columns.Add(new DataColumn("total_line_gst"));
            dt_selected_list.Columns.Add(new DataColumn("total_pt_price"));          // added
            dt_selected_list.Columns.Add(new DataColumn("total_hc_price"));          // added
            dt_selected_list.Columns.Add(new DataColumn("total_pt_gst"));            // added
            dt_selected_list.Columns.Add(new DataColumn("total_hc_gst"));            // added
            dt_selected_list.Columns.Add(new DataColumn("on_order", typeof(Boolean)));


            if (this.booking != null)
            {
                Booking.InvoiceType invType = InvoiceType;

                Offering orgOffering = OrganisationOfferingsDB.GetOfferingByOrgAndOffering(this.booking.Organisation.OrganisationID, this.booking.Offering.OfferingID);
                if (orgOffering == null)
                {
                    orgOffering = this.booking.Offering;
                }

                bool    invoiceGapPayments = Convert.ToInt32(SystemVariableDB.GetByDescr("InvoiceGapPayments").Value) == 1;
                decimal GST_Percent        = Convert.ToDecimal(((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["GST_Percent"].Value);
                decimal GST_Modifier       = GST_Percent / (decimal)100;

                bool incGstOnPTInvoices = IncGstOnInvoices_Private && !orgOffering.IsGstExempt;
                bool incGstOnHCInvoices = (invType == Booking.InvoiceType.Medicare && IncGstOnInvoices_MC && !orgOffering.IsGstExempt) ||
                                          (invType == Booking.InvoiceType.DVA && IncGstOnInvoices_DVA && !orgOffering.IsGstExempt) ||
                                          (invType == Booking.InvoiceType.Insurance && IncGstOnInvoices_Insurance && !orgOffering.IsGstExempt);


                decimal pt_price = orgOffering.DefaultPrice;
                decimal hc_price = 0;
                decimal pt_tax   = !incGstOnPTInvoices ? 0 : pt_price * GST_Modifier;
                decimal hc_tax   = !incGstOnHCInvoices ? 0 : hc_price * GST_Modifier;

                if (invType == Booking.InvoiceType.Medicare)
                {
                    pt_price = invoiceGapPayments && orgOffering.DefaultPrice > orgOffering.MedicareCharge ? orgOffering.DefaultPrice - orgOffering.MedicareCharge : 0;
                    hc_price = orgOffering.MedicareCharge;
                    pt_tax   = !incGstOnPTInvoices ? 0 : pt_price * GST_Modifier;
                    hc_tax   = !incGstOnHCInvoices ? 0 : hc_price * GST_Modifier;
                }
                if (invType == Booking.InvoiceType.DVA)
                {
                    pt_price = invoiceGapPayments && orgOffering.DefaultPrice > orgOffering.DvaCharge ? orgOffering.DefaultPrice - orgOffering.DvaCharge : 0;
                    hc_price = orgOffering.DvaCharge;
                    pt_tax   = !incGstOnPTInvoices ? 0 : pt_price * GST_Modifier;
                    hc_tax   = !incGstOnHCInvoices ? 0 : hc_price * GST_Modifier;
                }
                if (invType == Booking.InvoiceType.Insurance)
                {
                    hc_price = orgOffering.TacCompanyCode.Length > 0 ? orgOffering.TacCharge : orgOffering.DefaultPrice;
                    pt_price = invoiceGapPayments && orgOffering.DefaultPrice > hc_price ? orgOffering.DefaultPrice - hc_price : 0;
                    pt_tax   = !incGstOnPTInvoices ? 0 : pt_price * GST_Modifier;
                    hc_tax   = !incGstOnHCInvoices ? 0 : hc_price * GST_Modifier;
                }


                DataRow row = dt_selected_list.NewRow();
                row["offering_id"]            = booking.Offering.OfferingID;
                row["hc_paid"]                = (this.InvoiceType == Booking.InvoiceType.DVA || this.InvoiceType == Booking.InvoiceType.Medicare);
                row["short_name"]             = booking.Offering.ShortName;
                row["name"]                   = booking.Offering.Name;
                row["area_treated"]           = areaTreated;
                row["service_reference"]      = "";
                row["show_area_treated"]      = InvoiceType == Booking.InvoiceType.DVA || InvoiceType == Booking.InvoiceType.Insurance;
                row["show_service_reference"] = InvoiceType == Booking.InvoiceType.Insurance;
                row["default_price"]          = row["total_line_price"] = orgOffering.DefaultPrice;
                row["pt_price"]               = row["total_pt_price"] = pt_price;                      // added
                row["pt_gst"]                 = row["total_pt_gst"] = pt_tax;                          // added
                row["hc_price"]               = row["total_hc_price"] = hc_price;                      // added
                row["hc_gst"]                 = row["total_hc_gst"] = hc_tax;                          // added
                row["quantity"]               = "1";
                row["on_order"]               = false;
                dt_selected_list.Rows.Add(row);
            }

            Session["data_selected"] = dt_selected_list;
        }

        if (dt_selected_list.Rows.Count == 1 && dt_selected_list.Rows[0][0] == DBNull.Value)
        {
            dt_selected_list.Rows.RemoveAt(0);
        }

        return(dt_selected_list);
    }
    public static BulkLetterSendingQueueAdditionalLetter GetFileInfo(Letter.FileFormat fileFormat, Booking booking, Patient patient, HealthCard hc, Letter.TreatmentLetterType treatmentLetterType, Booking.InvoiceType invType, int fieldID, int siteID, int staffID, Referrer referrer, bool keepInHistory, int letterPrintHistorySendMethodID)
    {
        // 1. Add to healthcardaction
        int healthCardActionID = -1;

        if (treatmentLetterType == Letter.TreatmentLetterType.First || treatmentLetterType == Letter.TreatmentLetterType.Last || treatmentLetterType == Letter.TreatmentLetterType.LastWhenReplacingEPC)
        {
            healthCardActionID = HealthCardActionDB.Insert(hc.HealthCardID, Letter.GetHealthCardActionTypeID(treatmentLetterType), DateTime.Now);
        }

        // 2.create document and put it in history
        int letterID = Letter.GetLetterIDByTreatmentLetterTypeAndInvoiceType(treatmentLetterType, invType, fieldID, siteID);

        if (letterID == -1)
        {
            return(null);
        }


        string lettersDir = Letter.GetLettersDirectory();

        if (!Directory.Exists(lettersDir))
        {
            throw new CustomMessageException("Letters directory doesn't exist");
        }

        Letter letter             = LetterDB.GetByID(letterID);
        bool   useDefaultDocs     = letter.Organisation == null ? true : !LetterDB.OrgHasdocs(letter.Organisation.OrganisationID);
        string sourceTemplatePath = lettersDir + (useDefaultDocs ? @"Default\" + letter.Site.SiteID + @"\" : letter.Organisation.OrganisationID + @"\") + letter.Docname;

        if (!File.Exists(sourceTemplatePath))
        {
            throw new CustomMessageException("File doesn't exist: " + Path.GetFileName(sourceTemplatePath));
        }

        // get temp directory
        string tmpLettersDirectory = Letter.GetTempLettersDirectory();

        if (!Directory.Exists(tmpLettersDirectory))
        {
            throw new CustomMessageException("Temp letters directory doesn't exist");
        }

        return(new BulkLetterSendingQueueAdditionalLetter(
                   -1,
                   -1,
                   letter.LetterID,
                   keepInHistory && Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["StoreLettersHistoryInDB"]),
                   keepInHistory && Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["StoreLettersHistoryInFlatFile"]),
                   letterPrintHistorySendMethodID,
                   Letter.GetLettersHistoryDirectory(booking.Organisation.OrganisationID),
                   letter.Docname.Replace(".dot", ".doc"),
                   siteID,
                   booking.Organisation.OrganisationID,
                   booking.BookingID,
                   patient.PatientID,
                   -1, // register_referrer_id_to_use_instead_of_patients_reg_ref
                   staffID,
                   healthCardActionID,
                   sourceTemplatePath,
                   tmpLettersDirectory + letter.Docname.Replace(".dot", ".doc"),
                   true,
                   "",
                   ""
                   ));
    }