protected void Repeater17_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 lstRefunds = (Repeater)e.Item.FindControl("lstRefunds"); HtmlGenericControl div_refunds_list = (HtmlGenericControl)e.Item.FindControl("div_refunds_list"); HtmlGenericControl span_refunds_trailing_space_row = (HtmlGenericControl)e.Item.FindControl("span_refunds_trailing_space_row"); Label lnkAddRefund = (Label)e.Item.FindControl("lnkAddRefund"); LinkButton showHideRefundsList = (LinkButton)e.Item.FindControl("showHideRefundsList"); // get refunds DataTable tblRefunds = RefundDB.GetDataTableByInvoice(invoice.InvoiceID); lstRefunds.Visible = tblRefunds.Rows.Count > 0; span_refunds_trailing_space_row.Visible = tblRefunds.Rows.Count > 0; if (tblRefunds.Rows.Count > 0) { tblRefunds.Columns.Add("refund_url", typeof(string)); for (int i = 0; i < tblRefunds.Rows.Count; i++) { Refund refund = RefundDB.LoadAll(tblRefunds.Rows[i]); tblRefunds.Rows[i]["refund_url"] = refund.GetViewPopupLinkV2(); } lstRefunds.DataSource = tblRefunds; lstRefunds.DataBind(); } lnkAddRefund.Visible = tblRefunds.Rows.Count == 0; //if (!invoice.IsPaID) // can add items if (tblRefunds.Rows.Count == 0) // can add items { lnkAddRefund.Text = Refund.GetAddPopupLinkV2(invoice.InvoiceID, "window.location.href = window.location.href;"); } else { lnkAddRefund.Text = tblRefunds.Rows.Count > 0 ? string.Empty : "No Refunds"; } //span_add_refunds_row.Style["text-align"] = (tblRefunds.Rows.Count > 0) ? "center" : null; // if have table, center add link, else left align lnkAddRefund.Visible = lnkAddRefund.Text.Length > 0 && invoice.ReceiptsTotal > 0; showHideRefundsList.OnClientClick = "javascript:show_hide_byname('div_refunds_list_" + invoice.InvoiceID + "'); return false;"; showHideRefundsList.Visible = tblRefunds.Rows.Count > 0; div_refunds_list.Attributes["name"] = "div_refunds_list_" + invoice.InvoiceID; } }
private void FillEditViewForm(bool isEditMode) { lblHeading.Text = isEditMode ? "Edit Refund" : "View Refund"; Page.Title = isEditMode ? "Edit Refund" : "View Refund"; Refund refund = RefundDB.GetByID(GetFormID()); if (refund == null) { HideTableAndSetErrorMessage("Invalid Refund ID"); return; } lblId.Text = refund.RefundID.ToString(); lblInvoiceId.Text = refund.Invoice.InvoiceID.ToString(); lblRefundDate.Text = refund.RefundDateAdded.ToString("d MMM, yyyy"); lblAddedBy.Text = refund.Staff.Person.FullnameWithoutMiddlename; lblTotal.Font.Bold = !isEditMode; if (isEditMode) { txtTotal.Text = refund.Total.ToString(); ddlRefundReason.SelectedValue = refund.RefundReason.ID.ToString(); lblAmountReceipted.Text = (InvoiceDB.GetByID(refund.Invoice.InvoiceID).ReceiptsTotal).ToString(); lblTotal.Visible = false; lblReason.Visible = false; lblComment.Visible = false; } else { lblTotal.Text = refund.Total.ToString(); lblReason.Text = refund.RefundReason.Descr; lblComment.Text = refund.Comment; amountReceiptedRow.Visible = false; txtTotal.Visible = false; ddlRefundReason.Visible = false; txtComment.Visible = false; } if (isEditMode) { btnSubmit.Text = "Update Details"; } else // is view mode { btnSubmit.Visible = false; btnCancel.Text = "Close"; } }
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 }
public static void Reconcile(string DB, DateTime date, string xml) { /* * string xmlString = * @"<?xml version=""1.0"" encoding=""UTF-8""?> * <reconciliation-detail mid=""200"" tid=""200"" terminal-business-day=""2015-04-14"" total=""1620.00""> * <transaction type=""purchase"" card-type=""visa"" amount=""100.00"" tip=""10.00"" transaction-local-date-time=""2015-04-14 12:30:30"" tyro-reference=""870020"" merchant-reference=""071061048231306351219677"" settlement-date=""2015-04-16""/> * <transaction type=""purchase"" card-type=""mastercard"" amount=""200.00"" transaction-local-date-time=""2015-04-14 12:31:20"" tyro-reference=""885214"" merchant-reference=""071061048231306351219678"" settlement-date=""2015-04-16""/> * <transaction type=""purchase"" card-type=""jcb"" amount=""40.00"" transaction-local-date-time=""2015-04-14 12:33:23"" tyro-reference=""896534"" merchant-reference=""071061048231306351219679""/> * <transaction type=""purchase"" card-type=""amex"" amount=""30.00"" transaction-local-date-time=""2015-04-14 12:36:35"" tyro-reference=""905845"" merchant-reference=""071061048231306351219680""/> * <transaction type=""purchase"" card-type=""eftpos"" amount=""650.00"" cash-out=""50.00"" transaction-local-date-time=""2015-04-14 12:40:30"" tyro-reference=""912556"" merchant-reference=""071061048231306351219681"" settlement-date=""2015-04-16""/> * <transaction type=""purchase"" card-type=""eftpos"" amount=""450.00"" transaction-local-date-time=""2015-04-14 12:50:30"" tyro-reference=""920187"" merchant-reference=""071061048231306351219682"" settlement-date=""2015-04-16""/> * <transaction type=""purchase"" card-type=""diners"" amount=""70.00"" transaction-local-date-time=""2015-04-14 13:30:30"" tyro-reference=""935587"" merchant-reference=""071061048231306351219683""/> * <transaction type=""void"" card-type=""mastercard"" amount=""-80.00"" transaction-local-date-time=""2015-04-14 13:50:30"" tyro-reference=""946585"" merchant-reference=""071061048231306351219684"" settlement-date=""2015-04-16""/> * <transaction type=""purchase"" card-type=""visa"" amount=""170.00"" transaction-local-date-time=""2015-04-14 14:23:25"" tyro-reference=""953594"" merchant-reference=""071061048231306351219685"" settlement-date=""2015-04-16""/> * <transaction type=""refund"" card-type=""visa"" amount=""-70.00"" transaction-local-date-time=""2015-04-14 15:41:12"" tyro-reference=""962548"" merchant-reference=""071061048231306351219685"" settlement-date=""2015-04-16""/> * </reconciliation-detail>"; */ StringBuilder debutOutput = new StringBuilder(); using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { reader.ReadToFollowing("reconciliation-detail"); string mid = reader.GetAttribute("mid"); string tid = reader.GetAttribute("tid"); string terminal_business_day = reader.GetAttribute("terminal-business-day"); string total = reader.GetAttribute("total"); debutOutput.AppendLine("reconciliation-detail : " + " mid:" + mid + " tid:" + tid + " terminal_business_day:" + terminal_business_day + " total:" + total); while (reader.ReadToFollowing("transaction")) { string type = reader.GetAttribute("type"); string card_type = reader.GetAttribute("card-type"); string _amount = reader.GetAttribute("amount"); string cash_out = reader.GetAttribute("cash-out"); string tip = reader.GetAttribute("tip"); string transaction_local_date_time = reader.GetAttribute("transaction-local-date-time"); string tyro_reference = reader.GetAttribute("tyro-reference"); string merchant_reference = reader.GetAttribute("merchant-reference"); // transactionId that we sent in = tyro_payment_pending_id string settlement_date = reader.GetAttribute("settlement-date"); debutOutput.AppendLine("transaction : " + " type:" + type + " card_type:" + card_type + " amount:" + _amount + " cash_out:" + cash_out + " tip:" + tip + " transaction_local_date_time:" + transaction_local_date_time + " tyro_reference:" + tyro_reference + " merchant_reference:" + merchant_reference + " settlement_date:" + settlement_date ); /* * select * from TyroPaymentPending * * update TyroPaymentPending * set * tyro_transaction_id = '071061048231306351219677', * amount = 101.00, * out_date_processed = NULL, * out_result = '', * out_cardType = '', * out_transactionReference = '', * out_authorisationCode = '', * out_issuerActionCode = '' * WHERE tyro_payment_pending_id = 1 */ TyroPaymentPending tyroPaymentPending = TyroPaymentPendingDB.GetByByTyroTransactionID(DB, merchant_reference); if (tyroPaymentPending == null) { continue; } if (tyroPaymentPending.OutDateProcessed != DateTime.MinValue) { continue; } int tyro_payment_type_id = -1; if (type == "purchase") { tyro_payment_type_id = 1; } else if (type == "refund") { tyro_payment_type_id = 2; } bool sucessfulTransaction = (tyro_payment_type_id == 1 || tyro_payment_type_id == 2); if (sucessfulTransaction) { decimal amount; if (!Decimal.TryParse(_amount, out amount)) { Emailer.SimpleAlertEmail( "Tyro invoice late payment added but amount is not decimal type (" + _amount + ")<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + tyroPaymentPending.InvoiceID + "<br />DB: " + DB + "<br /><br />" + xml.Replace("<", "<").Replace(">", ">").Replace(Environment.NewLine, "<br />"), "Tyro Reconcilliation Amount Not Decimal Type. Invoice : " + tyroPaymentPending.InvoiceID, true); continue; } DateTime transactionDateTime; if (!DateTime.TryParseExact(transaction_local_date_time, "yyyy-dd-MM hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out transactionDateTime)) { Emailer.SimpleAlertEmail( "Tyro invoice late payment added but transaction_local_date_time is not parsable (" + transaction_local_date_time + ")<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + tyroPaymentPending.InvoiceID + "<br />DB: " + DB + "<br /><br />" + xml.Replace("<", "<").Replace(">", ">").Replace(Environment.NewLine, "<br />"), "Tyro Reconcilliation Amount Not Decimal Type. Invoice : " + tyroPaymentPending.InvoiceID, true); continue; } TyroPaymentPendingDB.UpdateByTyroTransactionID(DB, merchant_reference, "APPROVED", card_type, tyro_reference, "", "", transactionDateTime); if (amount != tyroPaymentPending.Amount) { Emailer.SimpleAlertEmail( "Tyro invoice late payment added but initial payment amount and reconcilliation ammount differ (" + tyroPaymentPending.Amount + ", " + amount + ")<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + tyroPaymentPending.InvoiceID + "<br />DB: " + DB, "Tyro Reconcilliation Amounts Differ. Invoice : " + tyroPaymentPending.InvoiceID, true); } if (tyroPaymentPending.TyroPaymentTypeID != tyro_payment_type_id) { Emailer.SimpleAlertEmail( "Tyro invoice late payment added but payment types differ (" + tyroPaymentPending.TyroPaymentTypeID + ", " + tyro_payment_type_id + ")<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + tyroPaymentPending.InvoiceID + "<br />DB: " + DB, "Tyro Reconcilliation Types Differ. Invoice : " + tyroPaymentPending.InvoiceID, true); } Invoice invoice = InvoiceDB.GetByID(tyroPaymentPending.InvoiceID, DB); if (tyroPaymentPending.TyroPaymentTypeID == 1) // payment { decimal totalOwed = invoice.TotalDue - tyroPaymentPending.Amount; bool isOverPaid = totalOwed < 0; bool isPaid = totalOwed <= 0; ReceiptDB.Insert(DB, 364, tyroPaymentPending.InvoiceID, tyroPaymentPending.Amount, 0, false, isOverPaid, DateTime.MaxValue, -8); if (isPaid) { InvoiceDB.UpdateIsPaid(DB, invoice.InvoiceID, true); } if (isOverPaid) { // send email to someone .. to fix up the overpayment.... Emailer.SimpleAlertEmail( "Tyro invoice late payment added and is overpaid.<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + DB, "Tyro Invoice OverPaid: " + invoice.InvoiceID, true); } } if (tyroPaymentPending.TyroPaymentTypeID == 2) // refund { amount = amount * -1; // reconcilliation report shows refund amount as negative amounts decimal totalOwed = invoice.TotalDue + tyroPaymentPending.Amount; bool isPaid = totalOwed <= 0; RefundDB.Insert(tyroPaymentPending.InvoiceID, tyroPaymentPending.Amount, 308, "", -8, DB); if (totalOwed > 0) { InvoiceDB.UpdateIsPaid(DB, tyroPaymentPending.InvoiceID, false); } } Emailer.SimpleAlertEmail( "Tyro Invoice Payment Updated Asynchonously (ie Late). <br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + DB, "Tyro Invoice Payment Updated Asynchonously (ie Late). Invoice: " + invoice.InvoiceID, true); } } } Logger.LogQuery(debutOutput.ToString()); }
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.Add) { if (!IsValidFormID()) { HideTableAndSetErrorMessage(); return; } Invoice invoice = InvoiceDB.GetByID(GetFormID()); if (invoice == null) { HideTableAndSetErrorMessage("Invalid invoice ID"); return; } decimal thisRefundAmount = Convert.ToDecimal(txtTotal.Text); if (thisRefundAmount > invoice.ReceiptsTotal) { SetErrorMessage("Can not be more than the amount receipted."); return; } if (!invoice.IsPaID) { int credit_note_id = CreditNoteDB.Insert(invoice.InvoiceID, invoice.TotalDue, "Auto credit noted to set inv as paid so can refund.", Convert.ToInt32(Session["StaffID"])); InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true); } int refund_id = RefundDB.Insert(invoice.InvoiceID, thisRefundAmount, Convert.ToInt32(ddlRefundReason.SelectedValue), txtComment.Text, Convert.ToInt32(Session["StaffID"])); InvoiceDB.UpdateIsRefund(invoice.InvoiceID, true); // close this window Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>"); } else { HideTableAndSetErrorMessage("", "Invalid URL Parameters"); } }