public static void Reverse(int receipt_id, int reversed_by) { Receipt receipt = ReceiptDB.GetByID(receipt_id); if (receipt == null) { throw new ArgumentException("Invalid receipt id :" + receipt_id); } if (receipt.IsReversed) { throw new ArgumentException("Receipt already reversed"); } if (receipt.IsReconciled) { throw new ArgumentException("Can not reverse a receipt that has been reconciled"); } // remove any overpayment records for this receipt OverpaymentDB.DeleteByReceiptID(receipt_id); // set total=0, set not overpaid, set who and when it was reversed, and original amount string sql = "UPDATE Receipt SET total = 0, is_overpaid = 0 ,reversed_by = " + reversed_by + ",reversed_date = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',pre_reversed_amount = " + receipt.Total + " WHERE receipt_id = " + receipt_id.ToString(); DBBase.ExecuteNonResult(sql); // set invoice as not paid InvoiceDB.UpdateIsPaid(null, receipt.Invoice.InvoiceID, false); // update the GL for the year this was done }
protected void btnSubmit_Click(object sender, EventArgs e) { if (GetUrlParamType() == UrlParamType.View) { Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit")); } //else if (GetUrlParamType() == UrlParamType.Edit) //{ // if (!IsValidFormID()) // { // HideTableAndSetErrorMessage(); // return; // } // Receipt receipt = ReceiptDB.GetByID(GetFormID()); // if (receipt == null) // { // HideTableAndSetErrorMessage("Invalid receipt ID"); // return; // } // ReceiptDB.Update(receipt.ReceiptID, Convert.ToInt32(ddlPaymentType.SelectedValue), Convert.ToDecimal(txtTotal.Text), Convert.ToDecimal(txtAmountReconciled.Text), chkFailedToClear.Checked, receipt.IsOverpaid, GetBankProcessedDateFromForm()); // Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "view_only")); // // close this window // //Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>"); //} else if (GetUrlParamType() == UrlParamType.Reconcile) { if (!IsValidFormID()) { HideTableAndSetErrorMessage(); return; } Receipt receipt = ReceiptDB.GetByID(GetFormID()); if (receipt == null) { HideTableAndSetErrorMessage("Invalid receipt ID"); return; } ReceiptDB.Update(receipt.ReceiptID, receipt.ReceiptPaymentType.ID, receipt.Total, Convert.ToDecimal(txtAmountReconciled.Text), chkFailedToClear.Checked, receipt.IsOverpaid, DateTime.Now, receipt.ReversedBy == null ? -1 : receipt.ReversedBy.StaffID, receipt.ReversedDate, receipt.PreReversedAmount); // close this window Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>"); } else if (GetUrlParamType() == UrlParamType.Add) { if (!IsValidFormID()) { HideTableAndSetErrorMessage(); return; } Invoice invoice = InvoiceDB.GetByID(GetFormID()); if (invoice == null) { HideTableAndSetErrorMessage("Invalid invoice ID"); return; } decimal thisReceitptAmount = Convert.ToDecimal(txtTotal.Text); decimal totalOwed = invoice.TotalDue - thisReceitptAmount; bool isOverPaid = totalOwed < 0; bool isPaid = totalOwed <= 0; int receipt_id = ReceiptDB.Insert(null, Convert.ToInt32(ddlPaymentType.SelectedValue), invoice.InvoiceID, thisReceitptAmount, Convert.ToDecimal(0.00), false, isOverPaid, DateTime.MinValue, Convert.ToInt32(Session["StaffID"])); if (isPaid) { InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true); } if (isOverPaid) { OverpaymentDB.Insert(receipt_id, -1 * totalOwed, Convert.ToInt32(Session["StaffID"])); } //string url = Request.RawUrl; //url = UrlParamModifier.AddEdit(url, "type", "view_only"); //url = UrlParamModifier.AddEdit(url, "id", receipt_id.ToString()); //Response.Redirect(url); //return; // close this window Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>"); } else { HideTableAndSetErrorMessage("", "Invalid URL Parameters"); } }