예제 #1
0
    public static void UnDelete(int credit_id)  // If exceptions thrown when deleting multiple invoices of a booking, need to un-delete it back to being in use
    {
        Credit credit = CreditDB.GetByID(credit_id);

        if (credit == null)
        {
            throw new CustomMessageException("Invalid credit id :" + credit.CreditID);
        }
        if (!credit.IsDeleted)
        {
            throw new CustomMessageException("Credit can not be un-deleted because it is not deleted. ID :" + credit.CreditID);
        }

        CreditHistoryDB.Insert(
            credit.CreditID,
            credit.CreditType.ID,
            credit.Amount,
            credit.VoucherDescr,
            credit.ExpiryDate,
            credit.VoucherCredit == null ? -1 : credit.VoucherCredit.CreditID,
            credit.InvoiceID,
            credit.TyroPaymentPendingID,
            credit.AddedBy.StaffID,
            credit.DateAdded,
            credit.DeletedBy == null ? -1 : credit.DeletedBy.StaffID,
            credit.DateDeleted,
            credit.PreDeletedAmount,
            credit.ModifiedBy == null ? -1 : credit.ModifiedBy.StaffID,
            credit.DateModified);

        // set total=0, set not overpaid, set who and when it was reversed, and original amount
        string sql = "UPDATE Credit SET amount = " + credit.PreDeletedAmount + ", pre_deleted_amount = 0,  deleted_by = NULL, date_deleted = NULL" + ",modified_by = " + credit.ModifiedBy.StaffID + ",date_modified = " + ("'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'") + " WHERE credit_id = " + credit_id.ToString();

        DBBase.ExecuteNonResult(sql);
    }
예제 #2
0
    protected void GrdCredit_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "_Delete")
        {
            try
            {
                int    credit_id = Convert.ToInt32(e.CommandArgument);
                Credit credit    = CreditDB.GetByID(credit_id);

                UserView userview = UserView.GetInstance();

                if (userview.IsProviderView && Convert.ToInt32(Session["StaffID"]) != credit.AddedBy.StaffID)
                {
                    throw new CustomMessageException("You Can Not Delete Vouchers Entered By Other Providers.");
                }

                CreditDB.SetAsDeleted(credit_id, Convert.ToInt32(Session["StaffID"]));

                FillCreditGrid();
                FillPayments();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
    }
예제 #3
0
    public static Credit[] GetByInvoiceID(int invoice_id)
    {
        DataTable tbl = GetDataTable_ByInvoiceID(invoice_id);

        Credit[] list = new Credit[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = CreditDB.LoadAll(tbl.Rows[i]);
        }

        return(list);
    }
예제 #4
0
    public static Credit[] GetByVoucherCreditID(int voucher_entity_id, bool inc_deleted = false)
    {
        DataTable tbl = GetDataTable_ByVoucherCreditID(voucher_entity_id, inc_deleted);

        Credit[] list = new Credit[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = CreditDB.LoadAll(tbl.Rows[i]);
        }

        return(list);
    }
예제 #5
0
    public static Credit[] GetByEntityID(int entity_id, string credit_type_ids = null, bool inc_deleted = false)
    {
        DataTable tbl = GetDataTable_ByEntityID(entity_id, credit_type_ids, inc_deleted);

        Credit[] list = new Credit[tbl.Rows.Count];
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            list[i] = CreditDB.LoadAll(tbl.Rows[i]);
        }

        return(list);
    }
예제 #6
0
    public static Credit LoadAll(DataRow row)
    {
        Credit credit = Load(row, "credit_");

        credit.CreditType = new IDandDescr(Convert.ToInt32(row["credittype_credit_type_id"]), Convert.ToString(row["credittype_descr"]));

        if (row["vouchercredit_credit_id"] != DBNull.Value)
        {
            credit.VoucherCredit            = CreditDB.Load(row, "vouchercredit_");
            credit.VoucherCredit.CreditType = new IDandDescr(Convert.ToInt32(row["vouchercredittype_credit_type_id"]), Convert.ToString(row["vouchercredittype_descr"]));
        }

        if (row["added_by_staff_id"] != DBNull.Value)
        {
            credit.AddedBy = StaffDB.Load(row, "added_by_");
        }
        if (row["person_added_by_person_id"] != DBNull.Value)
        {
            credit.AddedBy.Person       = PersonDB.Load(row, "person_added_by_");
            credit.AddedBy.Person.Title = IDandDescrDB.Load(row, "title_added_by_title_id", "title_added_by_descr");
        }

        if (row["deleted_by_staff_id"] != DBNull.Value)
        {
            credit.DeletedBy = StaffDB.Load(row, "deleted_by_");
        }
        if (row["person_deleted_by_person_id"] != DBNull.Value)
        {
            credit.DeletedBy.Person.Title = IDandDescrDB.Load(row, "title_deleted_by_title_id", "title_deleted_by_descr");
            credit.DeletedBy.Person       = PersonDB.Load(row, "person_deleted_by_");
        }

        if (row["modified_by_staff_id"] != DBNull.Value)
        {
            credit.ModifiedBy = StaffDB.Load(row, "modified_by_");
        }
        if (row["person_modified_by_person_id"] != DBNull.Value)
        {
            credit.ModifiedBy.Person.Title = IDandDescrDB.Load(row, "title_modified_by_title_id", "title_modified_by_descr");
            credit.ModifiedBy.Person       = PersonDB.Load(row, "person_modified_by_");
        }

        return(credit);
    }
예제 #7
0
    protected void FillCreditGrid()
    {
        UserView userview = UserView.GetInstance();
        int      staffID  = Convert.ToInt32(Session["StaffID"]);

        DataTable tbl = CreditDB.GetDataTable_ByEntityID(224413, "1,2");

        tbl.Columns.Add("can_delete", typeof(Boolean));
        for (int i = 0; i < tbl.Rows.Count; i++)
        {
            tbl.Rows[i]["can_delete"] =
                (Convert.ToInt32(tbl.Rows[i]["credit_credit_type_id"]) == 1 || Convert.ToInt32(tbl.Rows[i]["credit_credit_type_id"]) == 2) &&
                tbl.Rows[i]["credit_deleted_by"] == DBNull.Value &&
                (!userview.IsProviderView || staffID == Convert.ToInt32(tbl.Rows[i]["credit_added_by"]));
        }

        GrdCredit.DataSource = tbl;
        GrdCredit.DataBind();
    }
예제 #8
0
    protected void ReverseVoucher_Command(object sender, CommandEventArgs e)
    {
        try
        {
            // for some reason, it doesn't keep the command argument when set in
            // the code behind in a nested repeater, so set it in a hidden control and its fine

            //int creditID = Convert.ToInt32(e.CommandArgument);

            int creditID = -1;
            foreach (Control c in ((Control)sender).Parent.Controls)
            {
                if (c.ID == "lblHiddenVoucherID")
                {
                    creditID = Convert.ToInt32(((HiddenField)c).Value);
                }
            }


            Credit credit = CreditDB.GetByID(creditID);
            if (credit == null)
            {
                throw new CustomMessageException("Invalid voucher - does not exist");
            }
            if (credit.IsDeleted)
            {
                throw new CustomMessageException("Voucher already reversed");
            }

            CreditDB.SetAsDeleted(credit.CreditID, Convert.ToInt32(Session["StaffID"]));

            FillInvoicesList();
        }
        catch (CustomMessageException cmEx)
        {
            SetErrorMessage(cmEx.Message);
        }
        catch (Exception ex)
        {
            SetErrorMessage("", ex.ToString());
        }
    }
예제 #9
0
    protected void btn_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == "Add Voucher")
        {
            try
            {
                decimal amount;
                if (!decimal.TryParse(txtAddAmount.Text, out amount))
                {
                    throw new CustomMessageException("Not a valid amount");
                }
                CreditDB.Insert_AddVoucher(224413, amount, txtAddDescr.Text, DateTime.MinValue, Convert.ToInt32(Session["StaffID"]));
                FillCreditGrid();
                FillPayments();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
        if (e.CommandArgument == "Tyro Cashout")
        {
            try
            {
                decimal amount;
                if (!decimal.TryParse(txtCashAmount.Text, out amount))
                {
                    throw new CustomMessageException("Not a valid amount");
                }

                int tyro_payment_pending_id = 6;
                CreditDB.Insert_Cashout(amount, tyro_payment_pending_id, Convert.ToInt32(Session["StaffID"]));
                FillCreditGrid();
                FillPayments();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
    }
예제 #10
0
    private void FillPayments()
    {
        // get by entity id : 224413

        DataTable dt = CreditDB.GetUnusedVouchers(224413);

        lstPayments.DataSource = dt;
        lstPayments.DataBind();

        for (int i = lstPayments.Items.Count - 1; i >= 0; i--)
        {
            TextBox txtAmount = (TextBox)lstPayments.Items[i].FindControl("txtAmount");
            Utilities.SetEditControlBackColour(txtAmount, true, System.Drawing.Color.LightGoldenrodYellow, System.Drawing.Color.Empty);
        }

        //if (lstPayments.Items.Count > 0)
        //{
        //    TextBox txtReceiptPaymentTypeAmount = (TextBox)lstPayments.Items[0].FindControl("txtAmount");
        //    SetFocus(txtReceiptPaymentTypeAmount);
        //}
    }
예제 #11
0
    public static InvoiceLine LoadAll(DataRow row)
    {
        InvoiceLine line = Load(row);

        if (row["offering_id"] != DBNull.Value)
        {
            line.Offering = OfferingDB.Load(row);
        }
        if (row["credit_id"] != DBNull.Value)
        {
            line.Credit = CreditDB.Load(row, "credit_");
        }
        if (row["patient_id"] != DBNull.Value)
        {
            line.Patient              = PatientDB.Load(row, "patient_");
            line.Patient.Person       = PersonDB.Load(row, "patient_person_");
            line.Patient.Person.Title = IDandDescrDB.Load(row, "title_patient_title_id", "title_patient_descr");
        }

        return(line);
    }
예제 #12
0
    protected void Update()
    {
        string tyro_transaction_id      = UrlTyroTransactionID;
        string out_result               = UrlOutResult;
        string out_cardType             = UrlOutCardType;
        string out_transactionReference = UrlOutTransactionReference;
        string out_authorisationCode    = UrlOutAuthorisationCode;
        string out_issuerActionCode     = UrlOutIssuerActionCode;

        if (tyro_transaction_id == null)
        {
            throw new Exception("Invalid url field tyro_transaction_id");
        }
        if (out_result == null)
        {
            throw new Exception("Invalid url field out_result");
        }
        if (out_cardType == null)
        {
            throw new Exception("Invalid url field out_cardType");
        }
        if (out_transactionReference == null)
        {
            throw new Exception("Invalid url field out_transactionReference");
        }
        if (out_authorisationCode == null)
        {
            throw new Exception("Invalid url field out_authorisationCode");
        }
        if (out_issuerActionCode == null)
        {
            throw new Exception("Invalid url field out_issuerActionCode");
        }

        TyroPaymentPendingDB.UpdateByTyroTransactionID(null, tyro_transaction_id, out_result, out_cardType, out_transactionReference, out_authorisationCode, out_issuerActionCode, DateTime.Now);

        if (out_result == "APPROVED")
        {
            TyroPaymentPending tyroPaymentPending = TyroPaymentPendingDB.GetByByTyroTransactionID(null, tyro_transaction_id);

            Invoice invoice = InvoiceDB.GetByID(tyroPaymentPending.InvoiceID);

            int staffID = Session == null || Session["StaffID"] == null ? -8 : Convert.ToInt32(Session["StaffID"]);

            if (tyroPaymentPending.TyroPaymentTypeID == 1) // payment
            {
                decimal totalOwed  = invoice.TotalDue - tyroPaymentPending.Amount;
                bool    isOverPaid = totalOwed < 0;
                bool    isPaid     = totalOwed <= 0;

                ReceiptDB.Insert(null, 364, tyroPaymentPending.InvoiceID, tyroPaymentPending.Amount, 0, false, isOverPaid, DateTime.MaxValue, staffID);

                if (tyroPaymentPending.Cashout > 0)
                {
                    CreditDB.Insert_Cashout(tyroPaymentPending.Cashout, tyroPaymentPending.TyroPaymentPendingID, staffID);
                }

                if (isPaid)
                {
                    InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
                }

                if (isOverPaid)
                {
                    // send email to someone .. to fix up the overpayment....
                    Emailer.SimpleAlertEmail(
                        "Invoice tyro payment added and is overpaid.<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + (Session == null || Session["DB"] == null ? "" : Session["DB"]),
                        "Tyro Invoice OverPaid: " + invoice.InvoiceID,
                        true);
                }
            }
            if (tyroPaymentPending.TyroPaymentTypeID == 2) // refund
            {
                decimal totalOwed = invoice.TotalDue + tyroPaymentPending.Amount;
                bool    isPaid    = totalOwed <= 0;

                RefundDB.Insert(tyroPaymentPending.InvoiceID, tyroPaymentPending.Amount, 308, "", staffID);

                if (totalOwed > 0)
                {
                    InvoiceDB.UpdateIsPaid(null, tyroPaymentPending.InvoiceID, false);
                }
            }
        }

        Response.Write("1"); // to indicate it was successful
    }
예제 #13
0
    protected void Repeater19_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView dr = (DataRowView)e.Item.DataItem;
            if (dr == null || dr.Row == null)
            {
                return;
            }
            DataRow row     = dr.Row;
            Invoice invoice = InvoiceDB.LoadAll(row);


            // get controls
            Repeater           lstVouchers       = (Repeater)e.Item.FindControl("lstVouchers");
            HtmlGenericControl div_vouchers_list = (HtmlGenericControl)e.Item.FindControl("div_vouchers_list");
            HtmlGenericControl span_vouchers_trailing_space_row = (HtmlGenericControl)e.Item.FindControl("span_vouchers_trailing_space_row");
            Label      lnkAddVoucher        = (Label)e.Item.FindControl("lnkAddVoucher");
            LinkButton showHideVouchersList = (LinkButton)e.Item.FindControl("showHideVouchersList");


            // get refunds
            DataTable tblCredit = CreditDB.GetDataTable_ByInvoiceID(invoice.InvoiceID);
            lstVouchers.Visible = tblCredit.Rows.Count > 0;
            span_vouchers_trailing_space_row.Visible = tblCredit.Rows.Count > 0;
            if (tblCredit.Rows.Count > 0)
            {
                tblCredit.Columns.Add("voucher_url", typeof(string));
                tblCredit.Columns.Add("show_status", typeof(string));
                tblCredit.Columns.Add("status", typeof(string));
                tblCredit.Columns.Add("show_reconcile_link", typeof(string));
                tblCredit.Columns.Add("reconcile_link", typeof(string));
                tblCredit.Columns.Add("show_reverse_link", typeof(string));
                for (int i = 0; i < tblCredit.Rows.Count; i++)
                {
                    Credit voucher = CreditDB.LoadAll(tblCredit.Rows[i]);

                    tblCredit.Rows[i]["voucher_url"] = voucher.GetViewVoucherUsePopupLinkV2();

                    bool isReversed = voucher.IsDeleted;
                    tblCredit.Rows[i]["status"]            = "Reversed";
                    tblCredit.Rows[i]["show_status"]       = isReversed  ? "1" : "0";
                    tblCredit.Rows[i]["reconcile_link"]    = "";
                    tblCredit.Rows[i]["show_reverse_link"] = voucher.IsDeleted ? "0" : "1";
                }

                lstVouchers.DataSource = tblCredit;
                lstVouchers.DataBind();
            }

            if (!invoice.IsPaID) // can add items
            {
                lnkAddVoucher.Text = Receipt.GetAddReceiptPopupLinkV2(invoice.InvoiceID, "Add Voucher Use", "window.location.href = window.location.href;");
            }
            else
            {
                lnkAddVoucher.Text = tblCredit.Rows.Count > 0 ? string.Empty : "No Vouchers";
            }
            //span_add_vouchers_row.Style["text-align"] = (tblReciepts.Rows.Count > 0) ? "center" : null;  // if have table, center add link, else left align
            lnkAddVoucher.Visible = lnkAddVoucher.Text.Length > 0;
            showHideVouchersList.OnClientClick   = "javascript:show_hide_byname('div_vouchers_list_" + invoice.InvoiceID + "'); return false;";
            showHideVouchersList.Visible         = tblCredit.Rows.Count > 0;
            div_vouchers_list.Attributes["name"] = "div_vouchers_list_" + invoice.InvoiceID;
        }
    }
예제 #14
0
    private void FillEditViewForm(bool isEditMode)
    {
        Credit credit = CreditDB.GetByID(GetFormID());

        if (credit == null)
        {
            HideTableAndSetErrorMessage("Invalid ID");
            return;
        }

        FillCreditGrid(credit);

        string heading = "";

        if (credit.CreditType.ID == 1)
        {
            heading = "Voucher";
        }
        if (credit.CreditType.ID == 2)
        {
            heading = "Use Of Voucher";
        }
        if (credit.CreditType.ID == 3)
        {
            heading = "Cashout - Tyro To Mediclinic";
        }
        if (credit.CreditType.ID == 4)
        {
            heading = "Cashout - Mediclinic To Patient";
        }
        lblHeading.Text = isEditMode ? "Edit " + heading : "View " + heading;

        if (isEditMode && credit.CreditType.ID != 1)
        {
            throw new CustomMessageException("Can no edit a '" + heading + "'");
        }

        lblId.Text        = credit.CreditID.ToString();
        lblType.Text      = credit.CreditType.Descr;
        idRow.Visible     = Utilities.IsDev();
        typeRow.Visible   = Utilities.IsDev();
        clinicRow.Visible = false;

        bool isMobileDevice = Utilities.IsMobileDevice(Request);

        lblInvoice.Text = GetInvoiceLink(isMobileDevice, credit);
        lblVoucher.Text = GetVoucherLink(isMobileDevice, credit);

        lblAddedBy.Text          = credit.AddedBy.Person.FullnameWithoutMiddlename;
        lblDateAdded.Text        = credit.DateAdded.ToString("d MMM, yyyy");
        lblModifiedBy.Text       = credit.ModifiedBy == null ? "" : credit.ModifiedBy.Person.FullnameWithoutMiddlename;
        lblDateModified.Text     = credit.DateModified == DateTime.MinValue  ? "" : credit.DateModified.ToString("d MMM, yyyy");
        lblDeletedBy.Text        = credit.DeletedBy == null ? string.Empty : credit.DeletedBy.Person.FullnameWithoutMiddlename;
        lblDateDeleted.Text      = credit.DateDeleted == DateTime.MinValue  ? "" : credit.DateDeleted.ToString("d MMM, yyyy");
        lblPreDeletedAmount.Text = ((credit.CreditType.ID == 1 || credit.CreditType.ID == 3 ? 1 : -1) * credit.PreDeletedAmount).ToString();

        bool isDeleted = credit.DeletedBy != null || credit.DateDeleted != DateTime.MinValue;

        if (!isDeleted)
        {
            deletedSpaceRow.Visible     = false;
            deletedbyRow.Visible        = false;
            dateDeletedRow.Visible      = false;
            preDeletedAmountRow.Visible = false;
        }

        bool isModified = credit.ModifiedBy != null || credit.DateModified != DateTime.MinValue;

        if (!isModified)
        {
            modifiedbyRow.Visible   = false;
            dateModifiedRow.Visible = false;
        }

        invoiceListSpaceRow.Visible = false;
        invoiceListRow.Visible      = false;
        amountUsedRow.Visible       = false;
        amountRemainingRow.Visible  = false;

        if (credit.CreditType.ID == 1)
        {
            Credit[] payments = CreditDB.GetByVoucherCreditID(credit.CreditID);
            if (payments.Length > 0)
            {
                string invoicesText = string.Empty;
                foreach (Credit payment in payments)
                {
                    string invoiceLink = GetInvoiceLink(isMobileDevice, payment);
                    if (invoiceLink != null && invoiceLink.Length > 0)
                    {
                        invoicesText += (invoicesText.Length == 0 ? "" : "<br />") + invoiceLink + " $" + (-1 * payment.Amount);
                    }
                }

                if (invoicesText.Length > 0)
                {
                    invoiceListSpaceRow.Visible      = true;
                    invoiceListRow.Visible           = true;
                    lblInvoicesUsingThisVoucher.Text = invoicesText;
                }
            }


            decimal totalUsed = CreditDB.GetTotalUsed(credit.CreditID);
            amountUsedRow.Visible      = true;
            amountRemainingRow.Visible = true;
            lblAmountUsed.Text         = (-1 * totalUsed).ToString();
            lblRemainingUsed.Text      = (credit.Amount + totalUsed).ToString();
        }



        if (isEditMode)
        {
            txtAmount.Visible = false;
            lblAmount.Text    = credit.Amount.ToString();

            txtDescr.Text = credit.VoucherDescr;

            if (credit.ExpiryDate != DateTime.MinValue)
            {
                ddlExpiry_Day.SelectedValue   = credit.ExpiryDate.Day.ToString();
                ddlExpiry_Month.SelectedValue = credit.ExpiryDate.Month.ToString();
                ddlExpiry_Year.SelectedValue  = credit.ExpiryDate.Year.ToString();
            }

            lblDescr.Visible  = false;
            lblExpiry.Visible = false;
        }
        else
        {
            lblAmount.Text = ((credit.CreditType.ID == 1 || credit.CreditType.ID == 3 ? 1 : -1) * credit.Amount).ToString();
            lblDescr.Text  = credit.VoucherDescr;
            lblExpiry.Text = credit.ExpiryDate == DateTime.MinValue ? "No Date Set" : credit.ExpiryDate.ToString("d MMM, yyyy");

            txtAmount.Visible       = false;
            txtDescr.Visible        = false;
            ddlExpiry_Day.Visible   = false;
            ddlExpiry_Month.Visible = false;
            ddlExpiry_Year.Visible  = false;
        }


        if (credit.CreditType.ID != 1)
        {
            descrRow.Visible  = false;
            expiryRow.Visible = false;
        }
        if (credit.CreditType.ID != 2)
        {
            voucherUsedRow.Visible = false;
            invoiceRow.Visible     = false;
        }

        btnSubmit.Text = isEditMode ? "Update Details" : "Edit Details";
        btnCancel.Text = isEditMode ? "Cancel" : "Close";

        btnSubmit.Visible = !isDeleted && credit.CreditType.ID == 1;
    }
예제 #15
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (GetUrlParamType() == UrlParamType.View)
        {
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it redirects
            Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit"));
        }
        else if (GetUrlParamType() == UrlParamType.Edit)
        {
            try
            {
                UrlParamCreditType urlParamCreditType = GetUrlParamCreditType();

                if (urlParamCreditType != UrlParamCreditType.Add)
                {
                    throw new CustomMessageException("Can no edit a '" + GetUrlParamCreditType().ToString() + "'");
                }

                if (!ddlExpiryValidateAllOrNoneSet.IsValid)
                {
                    return;
                }

                Credit credit = CreditDB.GetByID(GetFormID());

                /*
                 * txtAmount.Text = txtAmount.Text.Trim();
                 * if (txtAmount.Text.StartsWith("$")) txtAmount.Text = txtAmount.Text.Substring(1);
                 * decimal amount;
                 * if (!decimal.TryParse(txtAmount.Text, out amount))
                 *  throw new CustomMessageException("Amount must be a valid amount.");
                 */

                if (urlParamCreditType == UrlParamCreditType.Add)
                {
                    CreditDB.Update(credit.CreditID, credit.CreditType.ID, credit.EntityID, credit.Amount, txtDescr.Text.Trim(), GetExpiryFromForm(), credit.VoucherCredit == null ? -1 : credit.VoucherCredit.CreditID, credit.InvoiceID, credit.TyroPaymentPendingID, Convert.ToInt32(Session["StaffID"]));
                }


                Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "view"));
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.Message);
            }
        }
        else if (GetUrlParamType() == UrlParamType.Add)
        {
            try
            {
                UrlParamCreditType urlParamCreditType = GetUrlParamCreditType();

                if (urlParamCreditType != UrlParamCreditType.Add)
                {
                    throw new CustomMessageException("Can no add a '" + GetUrlParamCreditType().ToString() + "'");
                }

                if (!ddlExpiryValidateAllOrNoneSet.IsValid)
                {
                    return;
                }

                int entityID = GetFormID();

                txtAmount.Text = txtAmount.Text.Trim();
                if (txtAmount.Text.StartsWith("$"))
                {
                    txtAmount.Text = txtAmount.Text.Substring(1);
                }
                decimal amount;
                if (!decimal.TryParse(txtAmount.Text, out amount))
                {
                    throw new CustomMessageException("Amount must be a valid amount.");
                }

                int credit_type_id = -1;
                if (urlParamCreditType == UrlParamCreditType.Add)
                {
                    credit_type_id = 1;
                }
                else if (urlParamCreditType == UrlParamCreditType.Use)
                {
                    credit_type_id = 2;
                }
                else if (urlParamCreditType == UrlParamCreditType.CashoutTyroToMC)
                {
                    credit_type_id = 3;
                }
                else if (urlParamCreditType == UrlParamCreditType.CashoutMCtoPT)
                {
                    credit_type_id = 4;
                }
                else
                {
                    throw new CustomMessageException("Invalid URL Field ct");
                }


                bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

                if (urlParamCreditType == UrlParamCreditType.Add)
                {
                    int creditID = CreditDB.Insert_AddVoucher(entityID, amount, txtDescr.Text.Trim(), GetExpiryFromForm(), Convert.ToInt32(Session["StaffID"]));

                    // need non booking org .. to put on invoice .....
                    // so need to put it in gui .. only for adding type 1

                    Patient patient       = PatientDB.GetByEntityID(entityID);
                    int     invID         = InvoiceDB.Insert(108, -1, 0, patient.PatientID, Convert.ToInt32(ddlClinic.SelectedValue), "", "", Convert.ToInt32(Session["StaffID"]), Convert.ToInt32(Session["SiteID"]), amount, 0, false, false, false, DateTime.MinValue);
                    int     invoiceLineID = InvoiceLineDB.Insert(invID, patient.PatientID, -1, creditID, 1, amount, 0, "", "", -1);

                    System.Drawing.Size size = Receipt.GetPopupWindowAddSize();
                    size = new System.Drawing.Size(size.Width + 15, size.Height + 60);
                    Response.Redirect("~/Invoice_ReceiptAndCreditNoteAddV2.aspx?id=" + invID + "&returnValue=false&window_size=" + size.Width + "_" + size.Height + (refresh_on_close ? "&refresh_on_close=1" : ""), false);
                    return;
                }



                // close this window

                maintable.Visible = false;

                if (refresh_on_close)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
                }
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.Message);
            }
        }
        else
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
        }
    }
예제 #16
0
    private void FillEmptyAddForm()
    {
        Invoice invoice = InvoiceDB.GetByID(GetFormID());

        if (invoice == null)
        {
            HideTableAndSetErrorMessage("Invalid invoice ID");
            return;
        }

        lblInvoiceNbr.Text  = invoice.InvoiceID.ToString();
        lblAmountOwing.Text = "$" + invoice.TotalDue.ToString();


        DataTable dt = DBBase.GetGenericDataTable(null, "ReceiptPaymentType", "receipt_payment_type_id", "descr");

        // add column for displaying data in first few rows with invoice id and invoice amount owing
        dt.Columns.Add("text");
        dt.Columns.Add("tab_index");
        for (int i = dt.Rows.Count - 1; i >= 0; i--)
        {
            dt.Rows[i]["text"] = "";
            if (Convert.ToInt32(dt.Rows[i]["receipt_payment_type_id"]) == 363)
            {
                dt.Rows.RemoveAt(i);
            }
        }

        lstPayments.DataSource = dt;
        lstPayments.DataBind();

        for (int i = lstPayments.Items.Count - 1; i >= 0; i--)
        {
            Label   lblReceiptPaymentTypeID     = (Label)lstPayments.Items[i].FindControl("lblTypeID");
            TextBox txtReceiptPaymentTypeAmount = (TextBox)lstPayments.Items[i].FindControl("txtAmount");
            Button  btnWebPay = (Button)lstPayments.Items[i].FindControl("btnWebPay");

            if (lblReceiptPaymentTypeID.Text != "133" && lblReceiptPaymentTypeID.Text != "362")
            {
                btnWebPay.Visible = false;
            }

            if (((SystemVariables)Session["SystemVariables"])["EziDebit_Enabled"].Value != "1")
            {
                btnWebPay.Visible = false;
            }

            Utilities.SetEditControlBackColour(txtReceiptPaymentTypeAmount, true, System.Drawing.Color.LightGoldenrodYellow, System.Drawing.Color.Empty);
        }

        if (lstPayments.Items.Count > 0)
        {
            TextBox txtReceiptPaymentTypeAmount = (TextBox)lstPayments.Items[0].FindControl("txtAmount");
            SetFocus(txtReceiptPaymentTypeAmount);
        }



        int entityID = -1;

        if (invoice.PayerOrganisation != null)
        {
            entityID = invoice.PayerOrganisation.EntityID;
        }
        else if (invoice.PayerPatient != null)
        {
            entityID = invoice.PayerPatient.Person.EntityID;
        }
        else if (invoice.Booking != null && invoice.Booking.Patient != null)
        {
            entityID = BookingDB.GetByID(invoice.Booking.BookingID).Patient.Person.EntityID;
        }

        DataTable dt_vouchers = CreditDB.GetUnusedVouchers(entityID);

        lstVouchers.DataSource = dt_vouchers;
        lstVouchers.DataBind();

        for (int i = lstVouchers.Items.Count - 1; i >= 0; i--)
        {
            TextBox txtAmount = (TextBox)lstVouchers.Items[i].FindControl("txtAmount");
            Utilities.SetEditControlBackColour(txtAmount, true, System.Drawing.Color.LightGoldenrodYellow, System.Drawing.Color.Empty);
        }

        if (lstVouchers.Items.Count == 0)
        {
            divVouchers.Visible = false;
        }



        Utilities.SetEditControlBackColour(txtCreditNoteTotal, true, System.Drawing.Color.LightGoldenrodYellow, System.Drawing.Color.Empty);
        Utilities.SetEditControlBackColour(txtCreditCardReason, true, System.Drawing.Color.LightGoldenrodYellow, System.Drawing.Color.Empty);

        btnSubmit.Text    = "Add Payment(s)";
        btnCancel.Visible = true;
    }
예제 #17
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!IsValidFormID())
        {
            HideTableAndSetErrorMessage();
            return;
        }
        Invoice invoice = InvoiceDB.GetByID(GetFormID());

        if (invoice == null)
        {
            HideTableAndSetErrorMessage("Invalid invoice ID");
            return;
        }


        decimal total = 0;


        ArrayList receipts = new ArrayList();

        for (int i = 0; i < lstPayments.Items.Count; i++)
        {
            Label   lblTypeID = (Label)lstPayments.Items[i].FindControl("lblTypeID");
            TextBox txtAmount = (TextBox)lstPayments.Items[i].FindControl("txtAmount");

            txtAmount.Text = txtAmount.Text.Trim();
            if (txtAmount.Text.Length > 0 && lblTypeID != null)
            {
                receipts.Add(new Tuple <int, decimal>(Convert.ToInt32(lblTypeID.Text), Convert.ToDecimal(txtAmount.Text)));
                total += Convert.ToDecimal(txtAmount.Text);
            }
        }


        ArrayList vouchers = new ArrayList();

        for (int i = 0; i < lstVouchers.Items.Count; i++)
        {
            HiddenField hiddenCreditID = (HiddenField)lstVouchers.Items[i].FindControl("hiddenCreditID");
            HiddenField hiddenEntityID = (HiddenField)lstVouchers.Items[i].FindControl("hiddenEntityID");
            TextBox     txtAmount      = (TextBox)lstVouchers.Items[i].FindControl("txtAmount");

            txtAmount.Text = txtAmount.Text.Trim();
            if (txtAmount.Text.Length > 0)
            {
                vouchers.Add(new Tuple <int, int, decimal>(Convert.ToInt32(hiddenCreditID.Value), Convert.ToInt32(hiddenEntityID.Value), Convert.ToDecimal(txtAmount.Text)));
                total += Convert.ToDecimal(txtAmount.Text);
            }
        }


        if (txtCreditNoteTotal.Text == string.Empty)
        {
            txtCreditNoteTotal.Text = "0";
        }
        total += Convert.ToDecimal(txtCreditNoteTotal.Text);

        decimal totalOwed  = invoice.TotalDue - total;
        bool    isOverPaid = totalOwed < 0;
        bool    isPaid     = totalOwed <= 0;

        if (isOverPaid)
        {
            SetErrorMessage("Total can not be more than the amount owing.");
            return;
        }


        // put in try/catch block in case someone just used the vouchers and there is more being used than is remaining in the voucher
        ArrayList creditIDsAdded = new ArrayList();

        try
        {
            foreach (Tuple <int, int, decimal> item in vouchers)
            {
                int creditID = CreditDB.Insert_UseVoucher(item.Item2, item.Item3, item.Item1, invoice.InvoiceID, Convert.ToInt32(Session["StaffID"]));
                creditIDsAdded.Add(creditID);
            }
        }
        catch (Exception ex)
        {
            // roll back
            foreach (int creditID in creditIDsAdded)
            {
                CreditDB.Delete(creditID);
            }

            SetErrorMessage(ex.Message);
            return;
        }

        foreach (Tuple <int, decimal> item in receipts)
        {
            ReceiptDB.Insert(null, item.Item1, invoice.InvoiceID, item.Item2, Convert.ToDecimal(0.00), false, isOverPaid, DateTime.MinValue, Convert.ToInt32(Session["StaffID"]));
        }

        if (Convert.ToDecimal(txtCreditNoteTotal.Text) > 0)
        {
            CreditNoteDB.Insert(invoice.InvoiceID, Convert.ToDecimal(txtCreditNoteTotal.Text), txtCreditCardReason.Text, Convert.ToInt32(Session["StaffID"]));
        }

        if (isPaid)
        {
            InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
        }

        FillEmptyAddForm();

        // close this window
        string returnValue = Request.QueryString["returnValue"] != null ? Request.QueryString["returnValue"] : "false";

        Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=" + returnValue + ";window.opener.location.href = window.opener.location.href;self.close();</script>");
    }
예제 #18
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (GetUrlParamType() == UrlParamType.View)
        {
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it redirects
            Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit"));
        }
        else if (GetUrlParamType() == UrlParamType.Edit)
        {
            try
            {
                UrlParamCreditType urlParamCreditType = GetUrlParamCreditType();

                if (urlParamCreditType != UrlParamCreditType.Add)
                {
                    throw new CustomMessageException("Can no edit a '" + GetUrlParamCreditType().ToString() + "'");
                }

                if (!ddlExpiryValidateAllOrNoneSet.IsValid)
                {
                    return;
                }

                Credit credit = CreditDB.GetByID(GetFormID());

                txtAmount.Text = txtAmount.Text.Trim();
                if (txtAmount.Text.StartsWith("$"))
                {
                    txtAmount.Text = txtAmount.Text.Substring(1);
                }
                decimal amount;
                if (!decimal.TryParse(txtAmount.Text, out amount))
                {
                    throw new CustomMessageException("Amount must be a valid amount.");
                }

                if (urlParamCreditType == UrlParamCreditType.Add)
                {
                    CreditDB.Update(credit.CreditID, credit.CreditType.ID, credit.EntityID, amount, txtDescr.Text.Trim(), GetExpiryFromForm(), credit.VoucherCredit == null ? -1 : credit.VoucherCredit.CreditID, credit.InvoiceID, credit.TyroPaymentPendingID, Convert.ToInt32(Session["StaffID"]));
                }


                Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "view"));
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.Message);
            }
        }
        else if (GetUrlParamType() == UrlParamType.Add)
        {
            try
            {
                UrlParamCreditType urlParamCreditType = GetUrlParamCreditType();

                if (urlParamCreditType != UrlParamCreditType.Add)
                {
                    throw new CustomMessageException("Can no add a '" + GetUrlParamCreditType().ToString() + "'");
                }

                if (!ddlExpiryValidateAllOrNoneSet.IsValid)
                {
                    return;
                }

                int entityID = GetFormID();

                txtAmount.Text = txtAmount.Text.Trim();
                if (txtAmount.Text.StartsWith("$"))
                {
                    txtAmount.Text = txtAmount.Text.Substring(1);
                }
                decimal amount;
                if (!decimal.TryParse(txtAmount.Text, out amount))
                {
                    throw new CustomMessageException("Amount must be a valid amount.");
                }

                int credit_type_id = -1;
                if (urlParamCreditType == UrlParamCreditType.Add)
                {
                    credit_type_id = 1;
                }
                else if (urlParamCreditType == UrlParamCreditType.Use)
                {
                    credit_type_id = 2;
                }
                else if (urlParamCreditType == UrlParamCreditType.CashoutTyroToMC)
                {
                    credit_type_id = 3;
                }
                else if (urlParamCreditType == UrlParamCreditType.CashoutMCtoPT)
                {
                    credit_type_id = 4;
                }
                else
                {
                    throw new CustomMessageException("Invalid URL Field ct");
                }


                if (urlParamCreditType == UrlParamCreditType.Add)
                {
                    CreditDB.Insert_AddVoucher(entityID, amount, txtDescr.Text.Trim(), GetExpiryFromForm(), Convert.ToInt32(Session["StaffID"]));
                }



                // close this window

                maintable.Visible = false;

                bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

                if (refresh_on_close)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
                }
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.Message);
            }
        }
        else
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
        }
    }
예제 #19
0
    protected void btnPay_Click(object sender, EventArgs e)
    {
        try
        {
            int invoiceID = 336368;
            int entityID  = 224413;

            Invoice invoice = InvoiceDB.GetByID(invoiceID);
            if (invoice == null)
            {
                HideTableAndSetErrorMessage("Invalid invoice ID");
                return;
            }


            ArrayList useVouchers = new ArrayList();
            decimal   total       = 0;
            for (int i = 0; i < lstPayments.Items.Count; i++)
            {
                HiddenField hiddenCreditID = (HiddenField)lstPayments.Items[i].FindControl("hiddenCreditID");
                TextBox     txtAmount      = (TextBox)lstPayments.Items[i].FindControl("txtAmount");

                txtAmount.Text = txtAmount.Text.Trim();
                if (txtAmount.Text.Length > 0)
                {
                    useVouchers.Add(new Tuple <int, decimal>(Convert.ToInt32(hiddenCreditID.Value), Convert.ToDecimal(txtAmount.Text)));
                    total += Convert.ToDecimal(txtAmount.Text);
                }
            }


            decimal totalOwed  = invoice.TotalDue - total;
            bool    isOverPaid = totalOwed < 0;
            bool    isPaid     = totalOwed <= 0;

            if (isOverPaid)
            {
                SetErrorMessage("Total can not be more than the amount owing.");
                return;
            }



            ArrayList creditIDsAdded = new ArrayList();
            try
            {
                foreach (Tuple <int, decimal> item in useVouchers)
                {
                    int creditID = CreditDB.Insert_UseVoucher(entityID, item.Item2, item.Item1, invoiceID, Convert.ToInt32(Session["StaffID"]));
                    creditIDsAdded.Add(creditID);
                }
            }
            catch (Exception ex)
            {
                // roll back
                foreach (int creditID in creditIDsAdded)
                {
                    CreditDB.Delete(creditID);
                }
                throw;
            }


            if (isPaid)
            {
                InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
            }

            FillCreditGrid();
            FillPayments();
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = ex.Message;
        }
    }