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); }
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; } } }
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()); } }
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"); } }
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; }
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"); } }