protected void DeleteCardLinkButton_Click(object sender, EventArgs eventArgs) { Transfer t = new Transfer(int.Parse(SavedCardDropDownList.SelectedValue)); if (t.UsrK != Usr.Current.K) throw new Exception("Wrong user!"); if (t.CardSaved) { t.CardSaved = false; t.Update(); BindSavedCards(); } ContainerPage.AnchorSkip(this.ClientID + "_PaymentAnchor"); }
//protected void GenBannerStats_Click(object sender, EventArgs eventArgs) //{ // Banner.GeneratePositionStats(); //} #endregion #region UpdateOldDBInvoices_Click public void UpdateOldDBInvoices_Click(object o, System.EventArgs e) { Cambro.Web.Helpers.WriteAlertHeader(); Cambro.Web.Helpers.WriteAlert("Selecting xxx...", 1); Query InvoiceQuery = new Query(); InvoiceQuery.OrderBy = new OrderBy(Invoice.Columns.K, OrderBy.OrderDirection.Ascending); InvoiceSet bs = new InvoiceSet(InvoiceQuery); for (int count = 0; count < bs.Count; count++) { Invoice invoice = bs[count]; try { invoice.Type = Invoice.Types.Invoice; invoice.IsImmediateCreditCardPayment = true; invoice.ActionUsrK = invoice.UsrK; invoice.VatCode = Invoice.VATCodes.T1; decimal invoicePrice = 0; decimal invoiceVat = 0; decimal invoiceTotal = 0; foreach (InvoiceItem invoiceItem in invoice.Items) { //invoiceItem.Price = Math.Round(invoiceItem.Price, 2); //invoiceItem.Vat = Math.Round(invoiceItem.Vat, 2); //invoiceItem.Total = Math.Round(invoiceItem.Total, 2); invoicePrice += invoiceItem.Price; invoiceVat += invoiceItem.Vat; invoiceTotal += invoiceItem.Total; if (invoiceItem.Type == InvoiceItem.Types.CharityDonation) invoiceItem.VatCode = InvoiceItem.VATCodes.T9; else if(invoiceItem.Vat.Equals(0)) invoiceItem.VatCode = InvoiceItem.VATCodes.T0; else invoiceItem.VatCode = InvoiceItem.VATCodes.T1; if (invoiceItem.Type == InvoiceItem.Types.Banner || invoiceItem.Type == InvoiceItem.Types.BannerEmail || invoiceItem.Type == InvoiceItem.Types.BannerHotbox || invoiceItem.Type == InvoiceItem.Types.BannerPhoto || invoiceItem.Type == InvoiceItem.Types.BannerSkyscraper || invoiceItem.Type == InvoiceItem.Types.BannerTop) { try { Banner banner = new Banner(invoiceItem.KeyData); invoiceItem.RevenueStartDate = banner.FirstDay; invoiceItem.RevenueEndDate = banner.LastDay; } catch (Exception) { } } else { invoiceItem.RevenueStartDate = invoice.CreatedDateTime; invoiceItem.RevenueEndDate = invoice.CreatedDateTime; } invoiceItem.Update(); } invoice.Price = Math.Round(invoicePrice,2); invoice.Vat = Math.Round(invoiceVat,2); invoice.Total = Math.Round(invoiceTotal, 2); if (invoice.DueDateTime.Equals(DateTime.MinValue)) invoice.DueDateTime = invoice.CreatedDateTime.AddDays(30); invoice.UpdateAndSetPaidStatus(); // If there arent transfers paying for this invoices yet, then create them. decimal amountPaid = invoice.AmountPaid; if (Math.Round(invoice.Total,2) > Math.Round(amountPaid,2)) { InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(new Query(new Q(InvoiceTransfer.Columns.InvoiceK, invoice.K))); if (invoiceTransferSet.Count == 0) { Transfer transfer = new Transfer(); transfer.ActionUsrK = invoice.UsrK; transfer.Amount = Math.Round(invoice.Total - amountPaid, 2); transfer.DateTimeComplete = invoice.CreatedDateTime; transfer.DateTimeCreated = invoice.CreatedDateTime; transfer.Method = Transfer.Methods.Card; transfer.AddNote("Autogenerated Transfer to create transfer for old system invoice.", "System"); transfer.PromoterK = invoice.PromoterK; transfer.Status = Transfer.StatusEnum.Success; transfer.Type = Transfer.TransferTypes.Payment; transfer.UsrK = invoice.UsrK; // Will be fully applied transfer.IsFullyApplied = true; transfer.CardAddress1 = invoice.Address; transfer.CardName = invoice.Name; transfer.CardPostcode = invoice.Postcode; transfer.Update(); InvoiceTransfer invoiceTransfer = new InvoiceTransfer(); invoiceTransfer.InvoiceK = invoice.K; invoiceTransfer.TransferK = transfer.K; invoiceTransfer.Amount = transfer.Amount; invoiceTransfer.Update(); invoice.UpdateAndSetPaidStatus(); } } invoice.PaidDateTime = invoice.CreatedDateTime; invoice.Update(); if (count % 10 == 0) Cambro.Web.Helpers.WriteAlert("Done " + count + "/" + bs.Count, 2); } catch (Exception ex) { Cambro.Web.Helpers.WriteAlert("Exception " + count + "/" + bs.Count + " - " + ex.ToString(), 3); } bs.Kill(count); } Cambro.Web.Helpers.WriteAlert("Done!", 3); Cambro.Web.Helpers.WriteAlertFooter(); }
protected void InvoiceTransferGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { this.InvoiceTransferGridView.EditIndex = -1; this.InvoiceTransferGridView.ShowFooter = true; if (InvoiceTransferDataHolderList.Count >= e.RowIndex) { InvoiceTransferDataHolder deleteInvoiceTransferDataHolder = InvoiceTransferDataHolderList[e.RowIndex]; // Delete row from List InvoiceTransferDataHolderList.Remove(deleteInvoiceTransferDataHolder); if (!InvoiceTransferDataHolderDeleteList.Contains(deleteInvoiceTransferDataHolder)) { bool contains = false; foreach (InvoiceTransferDataHolder itdh in InvoiceTransferDataHolderDeleteList) { if (itdh.TransferK == deleteInvoiceTransferDataHolder.TransferK) { contains = true; break; } } if (contains == false) { InvoiceTransferDataHolderDeleteList.Add(deleteInvoiceTransferDataHolder); if (CurrentInvoice.K > 0) { deleteInvoiceTransferDataHolder.State = DataHolderState.Deleted; deleteInvoiceTransferDataHolder.UpdateInsertDelete(); if (Math.Round(deleteInvoiceTransferDataHolder.Amount, 2) != 0) { Transfer t = new Transfer(deleteInvoiceTransferDataHolder.TransferK); t.IsFullyApplied = false; t.Update(); //if (t.Method == Transfer.Methods.TicketSales) //{ // Bobs.BankExport.GenerateBankExportForTicketFundsUsed(t, -1 * deleteInvoiceTransferDataHolder.Amount, CurrentInvoice); //} CurrentInvoice.AddNote("Transfer #" + t.K.ToString() + " was unapplied from " + (CurrentInvoice.Paid ? "paid" : "saved") + " invoice", Usr.Current.NickName); CurrentInvoice.UpdateAndSetPaidStatus(); LoadScreenFromInvoice(); } SetAddTransfersOptions(); } } } } CalculateInvoiceItemVatAndTotals(); ShowHideControls(CurrentInvoice.K > 0); }
//public static void GenerateBankExportsForBookingFeesToDate() //{ // DateTime startDateRange = Utilities.CardnetDelay(GetDateOfLastNonTicketFundsBankExport()).AddDays(1); // DateTime endDateRange = Utilities.CardnetDelay().AddDays(1); // Query untransferedBookingFeesQuery = new Query(new And(new Q(InvoiceItem.Columns.Type, InvoiceItem.Types.EventTicketsBookingFee), // new Q(InvoiceItem.Columns.RevenueStartDate, QueryOperator.GreaterThanOrEqualTo, startDateRange), // new Q(InvoiceItem.Columns.RevenueStartDate, QueryOperator.LessThan, endDateRange))); // untransferedBookingFeesQuery.ExtraSelectElements.Add("SumBookingFeeAmounts", "SUM([InvoiceItem].[Total])"); // untransferedBookingFeesQuery.ExtraSelectElements.Add("TheDate", "dateadd(day, 0, datediff(day, 0, [InvoiceItem].[RevenueStartDate]))"); // untransferedBookingFeesQuery.GroupBy = new GroupBy("dateadd(day, 0, datediff(day, 0, [InvoiceItem].[RevenueStartDate]))"); // untransferedBookingFeesQuery.Columns = new ColumnSet(); // InvoiceItemSet untransferedBookingFeeItems = new InvoiceItemSet(untransferedBookingFeesQuery); // foreach (InvoiceItem ii in untransferedBookingFeeItems) // { // GenerateBankExportForBookingFees(ii); // } //} #region I this this sets up the transfers between the current and client accounts. I've disabled it. //public static void GenerateBankExportsForAllNonTicketFundsToDate() //{ // DateTime startDateRange = Utilities.CardnetDelay(GetDateOfLastNonTicketFundsBankExport()).AddDays(1); // DateTime endDateRange = Utilities.CardnetDelay().AddDays(1); // GenerateBankExportsForNonTicketFunds(startDateRange, endDateRange, true); // GenerateBankExportsForNonTicketFunds(startDateRange, endDateRange, false); //} //private static void GenerateBankExportsForNonTicketFunds(DateTime startDateRange, DateTime endDateRange, bool positiveCashFlow) //{ // startDateRange = Utilities.GetStartOfDay(startDateRange); // endDateRange = Utilities.GetStartOfDay(endDateRange); // Query nonTicketCardMoneyQuery = new Query(new And(new Q(Transfer.Columns.Method, Transfer.Methods.Card), // new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success), // new Q(Transfer.Columns.DateTimeComplete, QueryOperator.GreaterThanOrEqualTo, startDateRange), // new Q(Transfer.Columns.DateTimeComplete, QueryOperator.LessThan, endDateRange))); // nonTicketCardMoneyQuery.ExtraSelectElements.Add("SumAmounts", "SUM([Transfer].[Amount])"); // nonTicketCardMoneyQuery.ExtraSelectElements.Add("TheDate", "dateadd(day, 0, datediff(day, 0, [Transfer].[DateTimeComplete]))"); // nonTicketCardMoneyQuery.OrderBy = new OrderBy("dateadd(day, 0, datediff(day, 0, [Transfer].[DateTimeComplete]))"); // nonTicketCardMoneyQuery.GroupBy = new GroupBy("dateadd(day, 0, datediff(day, 0, [Transfer].[DateTimeComplete]))"); // nonTicketCardMoneyQuery.Columns = new ColumnSet(); // Query ticketCardMoneyQuery = new Query(new And(new Q(InvoiceItem.Columns.Type, InvoiceItem.Types.EventTickets), // new Q(InvoiceItem.Columns.RevenueStartDate, QueryOperator.GreaterThanOrEqualTo, startDateRange), // new Q(InvoiceItem.Columns.RevenueStartDate, QueryOperator.LessThan, endDateRange))); // ticketCardMoneyQuery.ExtraSelectElements.Add("SumAmounts", "SUM([InvoiceItem].[Total])"); // ticketCardMoneyQuery.ExtraSelectElements.Add("TheDate", "dateadd(day, 0, datediff(day, 0, [InvoiceItem].[RevenueStartDate]))"); // ticketCardMoneyQuery.OrderBy = new OrderBy("dateadd(day, 0, datediff(day, 0, [InvoiceItem].[RevenueStartDate]))"); // ticketCardMoneyQuery.GroupBy = new GroupBy("dateadd(day, 0, datediff(day, 0, [InvoiceItem].[RevenueStartDate]))"); // ticketCardMoneyQuery.Columns = new ColumnSet(); // if(positiveCashFlow) // { // nonTicketCardMoneyQuery.QueryCondition = new And(nonTicketCardMoneyQuery.QueryCondition, // new Q(Transfer.Columns.Amount, QueryOperator.GreaterThan, 0)); // ticketCardMoneyQuery.QueryCondition = new And(ticketCardMoneyQuery.QueryCondition, // new Q(InvoiceItem.Columns.Total, QueryOperator.GreaterThan, 0)); // } // else // { // nonTicketCardMoneyQuery.QueryCondition = new And(nonTicketCardMoneyQuery.QueryCondition, // new Q(Transfer.Columns.Amount, QueryOperator.LessThan, 0)); // ticketCardMoneyQuery.QueryCondition = new And(ticketCardMoneyQuery.QueryCondition, // new Q(InvoiceItem.Columns.Total, QueryOperator.LessThan, 0)); // } // TransferSet nonTicketCardMoneyTransfers = new TransferSet(nonTicketCardMoneyQuery); // InvoiceItemSet ticketCardMoneyItems = new InvoiceItemSet(ticketCardMoneyQuery); // Hashtable hash = new Hashtable(); // foreach (Transfer t in nonTicketCardMoneyTransfers) // { // hash.Add(Convert.ToDateTime(t.ExtraSelectElements["TheDate"]).ToString("dd-MM-yyyy"), t.ExtraSelectElements["SumAmounts"]); // } // foreach (InvoiceItem ii in ticketCardMoneyItems) // { // if (hash.ContainsKey(Convert.ToDateTime(ii.ExtraSelectElements["TheDate"]).ToString("dd-MM-yyyy"))) // hash[Convert.ToDateTime(ii.ExtraSelectElements["TheDate"]).ToString("dd-MM-yyyy")] = ((double)(Convert.ToDouble(hash[Convert.ToDateTime(ii.ExtraSelectElements["TheDate"]).ToString("dd-MM-yyyy")]) - Convert.ToDouble(ii.ExtraSelectElements["SumAmounts"]))).ToString(); // else // hash.Add(Convert.ToDateTime(ii.ExtraSelectElements["TheDate"]).ToString("dd-MM-yyyy"), ((double)(-1 * Convert.ToDouble(ii.ExtraSelectElements["SumAmounts"]))).ToString()); // } // while (startDateRange < endDateRange) // { // if (hash.ContainsKey(startDateRange.ToString("dd-MM-yyyy"))) // { // BankExport be = new BankExport(); // be.Amount = Math.Round(Convert.ToDecimal(hash[startDateRange.ToString("dd-MM-yyyy")]), 2); // if (be.Amount != 0) // { // be.ReferenceDateTime = startDateRange; // StringBuilder sb = new StringBuilder(); // sb.Append("Client account to current account: "); // sb.Append(be.Amount.ToString("c")); // sb.Append(" from "); // sb.Append(be.ReferenceDateTime.ToString("ddd dd/MM/yyyy")); // be.Details = sb.ToString(); // be.AddedDateTime = DateTime.Now; // if (be.Amount > 0) // { // be.BankAccountNumber = Vars.DSI_BANK_ACCOUNT_NUMBER; // be.BankAccountSortCode = Vars.DSI_BANK_SORT_CODE; // be.BankName = Vars.DSI_BANK_NAME; // } // else // { // be.BankAccountNumber = Vars.DSI_CLIENT_BANK_ACCOUNT_NUMBER; // be.BankAccountSortCode = Vars.DSI_CLIENT_BANK_SORT_CODE; // be.BankName = Vars.DSI_CLIENT_BANK_NAME; // } // be.Amount = Math.Abs(be.Amount); // be.Status = Statuses.Added; // be.Type = Types.InternalTransferNonTicketFunds; // be.Update(); // be.Validate(); // } // } // startDateRange = startDateRange.AddDays(1); // } //} //private static void GenerateBankExportForBookingFees(InvoiceItem invoiceItem) //{ // BankExport be = new BankExport(); // be.Amount = Math.Round(Convert.ToDecimal(invoiceItem.ExtraSelectElements["SumBookingFeeAmounts"]), 2); // if (be.Amount != 0) // { // be.ReferenceDateTime = (DateTime)invoiceItem.ExtraSelectElements["TheDate"]; // StringBuilder sb = new StringBuilder(); // sb.Append("Ticket booking fees of "); // sb.Append(be.Amount.ToString("c")); // sb.Append(" from "); // sb.Append(be.ReferenceDateTime.ToString("ddd dd/MM/yyyy")); // be.Details = sb.ToString(); // be.AddedDateTime = DateTime.Now; // if (be.Amount > 0) // { // be.BankAccountNumber = Vars.DSI_BANK_ACCOUNT_NUMBER; // be.BankAccountSortCode = Vars.DSI_BANK_SORT_CODE; // be.BankName = Vars.DSI_BANK_NAME; // } // else // { // be.BankAccountNumber = Vars.DSI_CLIENT_BANK_ACCOUNT_NUMBER; // be.BankAccountSortCode = Vars.DSI_CLIENT_BANK_SORT_CODE; // be.BankName = Vars.DSI_CLIENT_BANK_NAME; // } // be.Amount = Math.Abs(be.Amount); // be.Status = Statuses.Added; // be.Type = Types.InternalTransferNonTicketFunds; // be.Update(); // be.Validate(); // } //} #endregion public static void GenerateBankExportForRefundTransfer(Transfer refundTransfer) { BankExport be = new BankExport(); be.AddedDateTime = DateTime.Now; be.Amount = Math.Abs(refundTransfer.Amount); be.BankName = Cambro.Misc.Utility.Snip(refundTransfer.BankName, 35); be.BankAccountNumber = refundTransfer.BankAccountNumber; be.BankAccountSortCode = refundTransfer.BankSortCode; be.PromoterK = refundTransfer.PromoterK; be.Status = BankExport.Statuses.Added; if (refundTransfer.TransferRefunded != null && refundTransfer.TransferRefunded.Method == Transfer.Methods.TicketSales) { //if (refundTransfer.BankName.ToUpper().Contains(Vars.DSI_BANK_NAME.ToUpper())) // be.Type = BankExport.Types.InternalTransferTicketFundsToPromoter; //else be.Type = BankExport.Types.ExternalBACSTicketFundsToPromoter; } else { //if (refundTransfer.BankName.ToUpper().Contains(Vars.DSI_BANK_NAME.ToUpper())) // be.Type = BankExport.Types.InternalTransferRefundToPromoter; //else be.Type = Types.ExternalBACSRefundToPromoter; } be.TransferK = refundTransfer.K; StringBuilder sb = new StringBuilder(); sb.Append("Promoter "); sb.Append(refundTransfer.Promoter.Name); sb.Append(" requested a refund of "); sb.Append(refundTransfer.Amount.ToString("c")); sb.Append("."); sb.Append(refundTransfer.Promoter.AsHTML()); sb.Append(refundTransfer.AsHTML()); be.Details = sb.ToString(); be.Update(); be.Validate(); refundTransfer.BankTransferReference = be.PaymentRef; refundTransfer.Update(); }
public static Transfer RefundViaBACS(Transfer refundTransfer) { refundTransfer.Method = Methods.BankTransfer; refundTransfer.GetBankDetailsFromPromoterAccount(); try { if (refundTransfer.BankSortCode.Trim().Length > 0 && refundTransfer.BankAccountNumber.Trim().Length > 0) { refundTransfer.Update(); BankExport.GenerateBankExportForRefundTransfer(refundTransfer); } else throw new DsiUserFriendlyException("Insufficient bank details to refund via BACS." + refundTransfer.AsHTML()); } catch (Exception ex) { Utilities.AdminEmailAlert("Unable to refund via BACS because of insufficient bank details.", "BACS refund failed", ex, refundTransfer); throw ex; } return refundTransfer; }
//private InvoiceTransferSet successfulInvoiceTransfers; #endregion #region UpdateAndAutoApplySuccessfulTransfersWithAvailableMoney public void UpdateAndAutoApplySuccessfulTransfersWithAvailableMoney() { if (this.Type.Equals(Invoice.Types.Invoice) && this.Paid == false) { decimal amountDue = this.AmountDue; if (amountDue > 0) { decimal availableMoney = 0m; if (this.Promoter != null) availableMoney = this.Promoter.GetAvailableMoney(); else if (this.Usr != null) availableMoney = this.Usr.GetBalance(); // Only apply if they have positive available money if (Math.Round(availableMoney, 2) > 0) { Query transferQuery = new Query(); if (this.Promoter != null) { transferQuery = new Query(new And(new Q(Transfer.Columns.IsFullyApplied, false), new Q(Transfer.Columns.PromoterK, this.PromoterK), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success), new Q(Transfer.Columns.Type, Transfer.TransferTypes.Payment))); if (this.Promoter.OverrideApplyTicketFundsToInvoices) { transferQuery.QueryCondition = new And(transferQuery.QueryCondition, new Q(Transfer.Columns.Method, QueryOperator.NotEqualTo, Transfer.Methods.TicketSales)); } } else if (this.Usr != null) { transferQuery = new Query(new And(new Q(Transfer.Columns.IsFullyApplied, false), new Q(Transfer.Columns.PromoterK, 0), new Q(Transfer.Columns.UsrK, this.UsrK), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success), new Q(Transfer.Columns.Type, Transfer.TransferTypes.Payment))); } transferQuery.OrderBy = new OrderBy(Transfer.Columns.DateTimeComplete, OrderBy.OrderDirection.Ascending); TransferSet transferSet = new TransferSet(transferQuery); if (transferSet.Count > 0) { bool complete = false; ApplyTransfersToThisInvoice(transferSet); this.UpdateAndSetPaidStatus(); // Remove or decrease amount of any Pending Invoice Transfers that, if successful, would bring the amount paid over the total invoice cost Query invoiceTransferPendingQuery = new Query(); invoiceTransferPendingQuery.QueryCondition = new And(new Q(InvoiceTransfer.Columns.InvoiceK, this.K), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Pending)); invoiceTransferPendingQuery.TableElement = new Join(InvoiceTransfer.Columns.TransferK, Transfer.Columns.K); InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(invoiceTransferPendingQuery); var amountPaid = this.AmountPaid; var amountPending = 0m; foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet) { var invoiceTransferAmount = Math.Round(invoiceTransfer.Amount, 2); amountPending += Math.Round(invoiceTransfer.Amount, 2); Transfer transfer = new Transfer(invoiceTransfer.TransferK); if (Math.Round(amountPaid, 2) >= Math.Round(Total, 2)) { invoiceTransfer.Delete(); this.AddNote("Transfer #" + invoiceTransfer.TransferK.ToString() + " has been unapplied from this invoice", "System"); } else if (Math.Round(amountPaid + amountPending, 2) > Math.Round(Total, 2)) { invoiceTransfer.Amount += Math.Round((Total - amountPaid) - amountPending, 2); amountPending += Math.Round(invoiceTransfer.Amount - invoiceTransferAmount, 2); if (Math.Round(invoiceTransfer.Amount, 2) == 0) { this.AddNote("Transfer #" + invoiceTransfer.TransferK.ToString() + " has been unapplied from this invoice", "System"); invoiceTransfer.Delete(); } else { this.AddNote("Transfer #" + invoiceTransfer.TransferK.ToString() + " amount applied has been updated", "System"); invoiceTransfer.Update(); } } if (invoiceTransferAmount != 0 && transfer.IsFullyApplied == true) { transfer.IsFullyApplied = false; transfer.Update(); } } } } } } this.UpdateAndSetPaidStatus(); }
public void UpdateAndSetPaidStatus() { decimal totalPaid = this.AmountPaid; if (Math.Round(this.Total, 2) == Math.Round(totalPaid, 2)) { this.SetPaidAndPaidDateTime(true); } // If Invoice has been overpaid, remove InvoiceTransfer link amounts until totalPaid == this.Total else if (Math.Round(this.Total, 2) < Math.Round(totalPaid, 2) && this.Type.Equals(Invoice.Types.Invoice)) { Query invoiceTransfersAppliedQuery = new Query(new And(new Q(InvoiceTransfer.Columns.InvoiceK, this.K), new Q(Transfer.Columns.Type, Transfer.TransferTypes.Payment))); invoiceTransfersAppliedQuery.TableElement = new Join(InvoiceTransfer.Columns.TransferK, Transfer.Columns.K); invoiceTransfersAppliedQuery.OrderBy = new OrderBy(Transfer.Columns.DateTimeComplete, OrderBy.OrderDirection.Ascending); InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(invoiceTransfersAppliedQuery); string invoiceNote = "Invoice overpaid by " + ((double)(totalPaid - this.Total)).ToString("c") + "."; decimal amountToUnApply = 0; for (int i = invoiceTransferSet.Count - 1; i >= 0; i--) { if (totalPaid > this.Total) { Transfer transfer = new Transfer(invoiceTransferSet[i].TransferK); if (invoiceTransferSet[i].Amount <= totalPaid - this.Total) { amountToUnApply = invoiceTransferSet[i].Amount; invoiceTransferSet[i].Delete(); } else { amountToUnApply = totalPaid - this.Total; invoiceTransferSet[i].Amount -= amountToUnApply; invoiceTransferSet[i].Update(); } // if(transfer.Method == Transfer.Methods.TicketSales) // BankExport.GenerateBankExportForTicketFundsUsed(transfer, -1 * amountToUnApply, this); invoiceNote += string.Format("\nAutomatically unapplied {0} from transfer #{1}.", amountToUnApply.ToString("c"), transfer.K); totalPaid -= amountToUnApply; transfer.AddNote(string.Format("Invoice #{0} was overpaid. {1:} has been unapplied from this transfer.", this.K, amountToUnApply.ToString("c")), "System"); transfer.IsFullyApplied = false; transfer.Update(); } } this.AddNote(invoiceNote, "System"); this.SetPaidAndPaidDateTime(true); //this.AddNote("This invoice has been overpaid by the sum of " + ((decimal)Math.Round(totalPaid - this.Total, 2)).ToString("0.00"), "Admin"); } else this.SetPaidAndPaidDateTime(false); this.Update(); }
protected void SaveButton_Click(object sender, EventArgs e) { Page.Validate(""); if (Page.IsValid) { this.ErrorLabel.Visible = false; this.ErrorLabel.Text = ""; for (int i=0; i< this.TransferDataHolderList.Count; i++) { try { if (!this.CompletedTransferKList.Contains(TransferDataHolderList[i].K)) { Transfer transfer = new Transfer(TransferDataHolderList[i].K); if (transfer.Amount != TransferDataHolderList[i].Amount) { this.ErrorLabel.Text += "ERROR: Transfer #" + transfer.K.ToString() + " has amount " + transfer.Amount.ToString("c") + "\n. You've entered " + TransferDataHolderList[i].Amount.ToString("c") + ". Please resolve.\n"; this.ErrorLabel.Visible = true; } else if (!transfer.Status.Equals(Transfer.StatusEnum.Pending)) { this.ErrorLabel.Text += "ERROR: Transfer #" + transfer.K.ToString() + " has status " + transfer.Status.ToString() + "\n. Only Pending transfers allowed to be made successful.\n"; this.ErrorLabel.Visible = true; } else { transfer.Status = Transfer.StatusEnum.Success; transfer.DateTimeComplete = DateTime.Now; transfer = TransferDataHolderList[i].SetReferenceNumber(transfer); transfer.Update(); transfer.UpdateAffectedInvoices(); Utilities.EmailTransfer(transfer, false, true); TransferDataHolderList[i] = new TransferDataHolder(transfer); this.CompletedTransferKList.Add(transfer.K); } } else { this.ErrorLabel.Text += "ERROR: Transfer #" + TransferDataHolderList[i].K.ToString() + " has already been successfully updated.\n"; this.ErrorLabel.Visible = true; } } catch (Exception ex) { // Display error message this.ErrorLabel.Text += ex.Message + "\n"; this.ErrorLabel.Visible = true; } } this.Completed = true; ShowResults(); } }
public void ConfirmButton_Click(object o, System.EventArgs e) { if (Usr.Current != null) { // Check for duplicate invoices int transferK = GetDuplicateGuidTransferK(); // Create new transfer if (transferK == 0) { CurrentTransfer = new Transfer(); try { CurrentTransfer.Status = Transfer.StatusEnum.Pending; decimal totalAmountDue = 0; foreach (InvoiceDataHolder idh in Invoices) { totalAmountDue += idh.AmountDue; } CurrentTransfer.Amount = Math.Round(totalAmountDue, 2); CurrentTransfer.UsrK = Usr.Current.K; CurrentTransfer.ActionUsrK = Usr.Current.K; CurrentTransfer.DuplicateGuid = (Guid)this.ViewState["DuplicateGuidTransfer"]; if (this.PayOptionRadioButtonSetupBankTransferPayment.Checked) CurrentTransfer.Method = Transfer.Methods.BankTransfer; else if (this.PayOptionRadioButtonSetupChequePayment.Checked) CurrentTransfer.Method = Transfer.Methods.Cheque; CurrentTransfer.PromoterK = PromoterK; CurrentTransfer.Type = Transfer.TransferTypes.Payment; CurrentTransfer.DateTimeCreated = DateTime.Now; CurrentTransfer.Update(); CurrentTransfer = CurrentTransfer; foreach (InvoiceDataHolder idh in Invoices) { InvoiceTransfer invoiceTransfer = new InvoiceTransfer(); invoiceTransfer.Amount = idh.AmountDue; invoiceTransfer.InvoiceK = idh.K; invoiceTransfer.TransferK = CurrentTransfer.K; invoiceTransfer.Update(); totalAmountDue -= idh.AmountDue; } if (Math.Round(totalAmountDue, 2) != 0) { throw new Exception("Transfer amount not correctly applied. Difference = " + Math.Round(totalAmountDue, 2).ToString("c")); } Utilities.EmailTransfer(CurrentTransfer, true, false); CheckCompleted(); } catch (Exception ex) { // Rollback transfer and invoiceTransfers this.RollbackTransfer(); Utilities.AdminEmailAlert("<p>Exception occurred during setup of transfer in SetupPayment control</p><p>Transfer K=" + CurrentTransfer.K.ToString() + "</p>", "Exception occurred during setup of transfer (K=" + CurrentTransfer.K.ToString() + ") in SetupPayment control", ex, CurrentTransfer); } } else if (CurrentTransfer == null) { CurrentTransfer = new Transfer(transferK); CheckCompleted(); } } if (ContainerPage != null) ContainerPage.AnchorSkip(this.ClientID + "_SetupPaymentAnchor"); }