public static void GenerateBankExportForTicketFundsUsed(Transfer ticketFundsTransfer, decimal amount, Invoice invoiceAppliedTo) { //BankExport be = new BankExport(); //be.Amount = Math.Round(amount, 2); //if (be.Amount != 0) //{ // be.AddedDateTime = DateTime.Now; // be.BankAccountNumber = Vars.DSI_BANK_ACCOUNT_NUMBER; // be.BankAccountSortCode = Vars.DSI_BANK_SORT_CODE; // be.BankName = Vars.DSI_BANK_NAME; // be.Amount = Math.Abs(be.Amount); // be.PromoterK = ticketFundsTransfer.PromoterK; // be.TransferK = ticketFundsTransfer.K; // be.Status = Statuses.Added; // be.Type = Types.InternalTransferTicketFundsUsed; // StringBuilder sb = new StringBuilder(); // sb.Append("Promoter "); // sb.Append(ticketFundsTransfer.Promoter.Name); // sb.Append(" used ticket funds transfer #"); // sb.Append(ticketFundsTransfer.K.ToString()); // sb.Append(" and applied "); // sb.Append(amount.ToString("c")); // sb.Append(" to invoice #"); // sb.Append(invoiceAppliedTo.K.ToString()); // //sb.Append(ticketFundsTransfer.AmountRemaining().ToString("c")); // //sb.Append(" remaining.<br>Invoice is "); // //if(!invoiceAppliedTo.Paid) // // sb.Append("not"); // //sb.Append(" fully paid.<br><br>"); // sb.Append(ticketFundsTransfer.Promoter.AsHTML()); // if (ticketFundsTransfer.TicketPromoterEvent != null && ticketFundsTransfer.TicketPromoterEvent.Event != null) // { // sb.Append(ticketFundsTransfer.TicketPromoterEvent.Event.AsHTML()); // } // sb.Append(ticketFundsTransfer.AsHTML()); // be.Details = sb.ToString(); // be.Update(); // be.Validate(); // ticketFundsTransfer.BankTransferReference = be.PaymentRef; // ticketFundsTransfer.Update(); //} }
public static IBob Get(Model.Entities.ObjectType type, int k) { IBob b = null; bool wrongType = false; try { switch (type) { case Model.Entities.ObjectType.Photo: b = new Photo(k); break; case Model.Entities.ObjectType.Event: b = new Event(k); break; case Model.Entities.ObjectType.Venue: b = new Venue(k); break; case Model.Entities.ObjectType.Place: b = new Place(k); break; case Model.Entities.ObjectType.Thread: b = new Thread(k); break; case Model.Entities.ObjectType.Country: b = new Country(k); break; case Model.Entities.ObjectType.Article: b = new Article(k); break; case Model.Entities.ObjectType.Para: b = new Para(k); break; case Model.Entities.ObjectType.Brand: b = new Brand(k); break; case Model.Entities.ObjectType.Promoter: b = new Promoter(k); break; case Model.Entities.ObjectType.Usr: b = new Usr(k); break; case Model.Entities.ObjectType.Region: b = new Region(k); break; case Model.Entities.ObjectType.Gallery: b = new Gallery(k); break; case Model.Entities.ObjectType.Group: b = new Group(k); break; case Model.Entities.ObjectType.Banner: b = new Banner(k); break; case Model.Entities.ObjectType.GuestlistCredit: b = new GuestlistCredit(k); break; case Model.Entities.ObjectType.Ticket: b = new Ticket(k); break; case Model.Entities.ObjectType.Invoice: b = new Invoice(k); break; case Model.Entities.ObjectType.InsertionOrder: b = new InsertionOrder(k); break; case Model.Entities.ObjectType.CampaignCredit: b = new CampaignCredit(k); break; case Model.Entities.ObjectType.UsrDonationIcon: b = new UsrDonationIcon(k); break; default: wrongType = true; b = null; break; } } catch { } if (wrongType) throw new Exception("Bob.Get attempted to get " + type.ToString() + " - can't do it!!! DUH!"); return b; }
public static bool EmailInvoice(Invoice invoice, string emailSubject, bool invoiceCreated) { bool emailSuccessful = true; try { Mailer mailer = new Mailer(); mailer.Subject = emailSubject; mailer.Body = "<h2>" + emailSubject + "</h2>"; if (invoice.Promoter != null) { mailer.Body += invoice.Promoter.LinkEmailFull; } AddInvoicesToEmail(mailer, new InvoiceSet(new Query(new Q(Invoice.Columns.K, invoice.K)))); if (invoice.Promoter != null) { mailer.Body += @"<p><a href=""[LOGIN(" + invoice.Promoter.UrlApp("invoices") + "\")]>Click here to view all " + invoice.Promoter.Name + " invoices</a></p>"; mailer.RedirectUrl = invoice.Promoter.UrlApp("invoices"); } try { // Send email to each user in the AdminUsrs for the Promoter account. When invoice is paid, it will appear as an attachment to the transfer email that completed its payment if (!Vars.DevEnv && invoice.Promoter != null && Math.Round(invoice.Total) != 0) { mailer.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; foreach (Usr usr in invoice.Promoter.AdminUsrs) { mailer.UsrRecipient = usr; mailer.Send(); } if (invoice.Usr != null && !invoice.Usr.IsPromoterK(invoice.PromoterK)) { mailer.UsrRecipient = invoice.Usr; mailer.Send(); } if (invoice.Promoter.AccountsEmail != null && invoice.Promoter.AccountsEmail.Length > 0) { try { string body = "<p>" + emailSubject + "</p><p>Account: " + invoice.Promoter.Name + "</p>"; Utilities.EmailToNonUser(invoice.Promoter.AccountsEmail, mailer.Subject, body, mailer.Attachments.ToArray()); } catch (Exception ex) { emailSuccessful = false; string additionalDetails = "Occurred in Utilities.EmailInvoice(invoice, emailSubject, invoiceCreated): Promoter.AccountsEmail = " + invoice.Promoter.AccountsEmail; EmailException(ex, additionalDetails, invoice); } } } } catch (Exception ex) { emailSuccessful = false; string additionalDetails = "Occurred in Utilities.EmailInvoice(invoice, emailSubject, invoiceCreated): Promoter.AccountsEmail = " + invoice.Promoter.AccountsEmail; EmailException(ex, additionalDetails, invoice); } // Change subject for internal use mailer.Subject = ""; if (Vars.DevEnv) mailer.Subject = "TEST - "; mailer.Subject += "DontStayIn "; if (invoice.IsImmediateCreditCardPayment) mailer.Subject += "WEB "; mailer.Subject += invoice.TypeToString + " #" + invoice.K.ToString() + ", " + Math.Abs(invoice.Total).ToString("c"); if (invoice.Usr != null) mailer.Subject += " from " + invoice.Usr.Name; if (invoice.Promoter != null) mailer.Subject += " (" + invoice.Promoter.Name + ")"; if (invoiceCreated == true) mailer.Subject += " created"; else mailer.Subject += " updated"; // now send to our accounts email address mailer.UsrRecipient = null; mailer.TemplateType = Mailer.TemplateTypes.AdminNote; mailer.To = "*****@*****.**"; mailer.Send(); } catch (Exception ex) { EmailException(ex, "Occurred in Utilities.EmailInvoice(invoice, emailSubject, invoiceCreated)", invoice); emailSuccessful = false; } return emailSuccessful; }
protected void Page_Load(object sender, EventArgs e) { ContainerPage.SslPage = true; try { if (ViewState["TransferK"] != null && (int)ViewState["TransferK"] > 0) TransferK = (int)ViewState["TransferK"]; else { if (ContainerPage.Url["K"].IsInt) { TransferK = Convert.ToInt32(ContainerPage.Url["K"].Value); ViewState["TransferK"] = TransferK; } else if (ContainerPage.Url["InvoiceK"].IsInt) { Invoice invoice = new Invoice(Convert.ToInt32(ContainerPage.Url["InvoiceK"].Value)); this.InvoiceK = invoice.K; if (!this.IsPostBack) LoadScreenFromInvoice(invoice); } else if (ContainerPage.Url["TransferRefundK"].IsInt) { Transfer transferToRefund = new Transfer(Convert.ToInt32(ContainerPage.Url["TransferRefundK"].Value)); decimal refundAmount = 0; if (!this.IsPostBack && !ContainerPage.Url["RefundAmount"].IsNull) { try { refundAmount = Convert.ToDecimal(ContainerPage.Url["RefundAmount"].Value) / 100m; } catch (Exception) { } } else if (this.AmountTextBox.Text.Length > 0 && Utilities.ConvertMoneyStringToDecimal(this.AmountTextBox.Text) != 0) { refundAmount = Utilities.ConvertMoneyStringToDecimal(this.AmountTextBox.Text); } currentTransfer = transferToRefund.RefundThisTransfer(refundAmount); // Dont set DateTimeCreated until it is saved currentTransfer.DateTimeCreated = DateTime.MinValue; loadRefundTransfer = true; } if (ContainerPage.Url["FailedTransferK"].IsInt) { Transfer failedTransfer = new Transfer(Convert.ToInt32(ContainerPage.Url["FailedTransferK"].Value)); currentTransfer = failedTransfer.CopyThisTransfer(); // Since we cant store card numbers and the SecPay transaction failed, then user must re-enter card number currentTransfer.Notes = failedTransfer.Notes; currentTransfer.CardNumberEnd = ""; currentTransfer.Status = Transfer.StatusEnum.Pending; redoFailedTransfer = true; } } if (TransferK > 0) { try { currentTransfer = new Transfer(TransferK); } catch (Exception) { // TODO: add popup error message, then redirect Response.Redirect(Transfer.UrlAdminNewTransfer()); } } } catch { // if no Transfer K, then assume we are creating a new Transfer TransferK = 0; } this.DownloadButton.Enabled = TransferK > 0; var currentTransferAmountRemaining = currentTransfer.AmountRemaining(); this.CreateCampaignCreditsButton.Visible = currentTransfer.Method == Transfer.Methods.TicketSales && currentTransferAmountRemaining > 0; if (this.CreateCampaignCreditsButton.Visible) { int numberOfCredits = CampaignCredit.CalculateTotalCreditsForMoney(currentTransferAmountRemaining / (decimal)(1 + Invoice.VATRate(Invoice.VATCodes.T1, DateTime.Now)), 0.5, currentTransfer.Promoter); CreateCampaignCreditsButton.InnerHtml = "Buy " + numberOfCredits.ToString("N0") + " campaign credits"; } if (!this.IsPostBack) { ViewState["DuplicateGuid"] = Guid.NewGuid(); this.RefundAmountTextBox.Style["text-align"] = "right"; NotesAddOnlyTextBox.ReadOnlyTextBox.CssClass = "readOnlyNotesTextBox"; NotesAddOnlyTextBox.AddTextBox.CssClass = "addNotesTextBox"; NotesAddOnlyTextBox.TimeStampFormat = "dd/MM/yy HH:mm"; NotesAddOnlyTextBox.AuthorName = Usr.Current.NickName; NotesAddOnlyTextBox.InsertOption = AddOnlyTextBox.InsertOptions.AddAtBeginning; CreateCampaignCreditsButton.Attributes["onclick"] = "if(confirm('Are you sure you want to use ticket funds to buy campaign credits?')){__doPostBack('" + CreateCampaignCreditsButton.UniqueID + "','');return false;}else{return false;};"; SetupTypeDropDownList(); if (currentTransfer != null) this.TypeDropDownList.SelectedValue = Convert.ToInt32(currentTransfer.Type).ToString(); SetupMethodDropDownList(); SetupCardTypeDropDownList(); if (currentTransfer.K > 0 || loadRefundTransfer == true || redoFailedTransfer == true) { // Setup screen rules for updating transfer only LoadScreenFromTransfer(); //if(loadRefundTransfer == true) // SetupStatusDropDownList(); } else { SetupStatusDropDownList(); this.TransferKValueLabel.Visible = false; this.TransferKLabel.Visible = false; // Setup screen for new transfer data input this.CreatedDateTextBox.Text = DateTime.Now.ToShortDateString(); if (Usr.Current != null) { this.uiActionUserAutoComplete.Value = Usr.Current.K.ToString(); this.uiActionUserAutoComplete.Text = Usr.Current.Name; this.ActionUserValueLabel.Text = Usr.Current.Link(); } } ShowHidePanels(); } SetBankDetailValidators(); }
protected void Page_Load(object sender, EventArgs e) { try { if (ViewState["CreditK"] != null) CreditK = (int)ViewState["CreditK"]; else { CreditK = Convert.ToInt32(ContainerPage.Url["K"].Value); ViewState["CreditK"] = CreditK; } if(CreditK > 0) CurrentCredit = new Invoice(CreditK); } catch { // if no Credit K, then assume we are creating a new Credit CreditK = 0; } if (!this.IsPostBack) { PriceTextBox.Style["text-align"] = "right"; VATTextBox.Style["text-align"] = "right"; TotalTextBox.Style["text-align"] = "right"; CreatedDateTextBox.Style["text-align"] = "right"; PaidDateTextBox.Style["text-align"] = "right"; TaxDateValueLabel.Style["text-align"] = "right"; OverrideTaxDateCheckBox.Style["text-align"] = "right"; NotesAddOnlyTextBox.ReadOnlyTextBox.CssClass = "readOnlyNotesTextBox"; NotesAddOnlyTextBox.AddTextBox.CssClass = "addNotesTextBox"; NotesAddOnlyTextBox.TimeStampFormat = "dd/MM/yy HH:mm"; NotesAddOnlyTextBox.AuthorName = Usr.Current.NickName; NotesAddOnlyTextBox.InsertOption = AddOnlyTextBox.InsertOptions.AddAtBeginning; this.SearchForTransferHyperLink.NavigateUrl = UrlInfo.PageUrl(UrlInfo.PageTypes.Admin, "adminmainaccounting", new string[] { }); ViewState["DuplicateGuid"] = Guid.NewGuid(); if (ContainerPage.Url["invoiceK"].IsInt) { InvoiceK = Convert.ToInt32(ContainerPage.Url["invoiceK"].Value); InvoiceDataHolder creditDataHolder = CurrentInvoice.CreateCredit(); CurrentCredit = creditDataHolder.Invoice; CreditItemDataHolderList = creditDataHolder.InvoiceItemDataHolderList; } // Must have at least one if (CreditK == 0 && InvoiceK == 0) { string response = "<script type=\"text/javascript\">alert('Credit must be created from an invoice'); open('" + UrlInfo.PageUrl(UrlInfo.PageTypes.Admin, "adminmainaccounting") + ", '_self');</script>"; Response.Write(response); Response.End(); } if (Usr.Current != null && CurrentCredit.K == 0) { CurrentCredit.ActionUsr = Usr.Current; } if (CreditK > 0) { CreditAndSubItemsBindData(); } LoadScreenFromCredit(); if(CreditK == 0) { // Setup screen for new data input this.CreatedDateTextBox.Text = DateTime.Now.ToShortDateString(); this.PaidCheckBox.Checked = false; this.SetPaidImage(false); } CalculateCreditItemVatAndTotals(); } SetupAvailableTransfersDropDownList(); // Setup screen rules for updating only if (CreditK > 0) { if (CurrentCredit.Type.Equals(Invoice.Types.Invoice)) Response.Redirect(CurrentCredit.UrlAdmin()); DisableForPreviouslySaved(); } ShowHideControls(CreditK > 0); EnableSalesUsrAndAmount(); if (CreditK > 0 && Math.Round(CurrentCredit.AmountPaid, 2) == Math.Round(CurrentCredit.Total, 2)) { CreditTransferGridView.FooterRow.Visible = false; this.CreateTransferHyperLink.Visible = false; this.SearchForTransferHyperLink.Visible = false; } }
public static bool EmailInvoice(Invoice invoice, string emailAddress) { try { emailAddress = emailAddress.Trim(); Regex EmailRegex = new Regex(Cambro.Misc.RegEx.Email); if (!EmailRegex.IsMatch(emailAddress)) throw new Exception("Invalid email address: " + emailAddress); string emailSubject = ""; if (Vars.DevEnv) emailSubject += "TEST - "; emailSubject += "DontStayIn "; if (invoice.IsImmediateCreditCardPayment) emailSubject += "WEB "; emailSubject += invoice.TypeToString + " #" + invoice.K.ToString() + ", " + Math.Abs(invoice.Total).ToString("c"); Attachment[] attachments = new Attachment[] { new System.Net.Mail.Attachment(Utilities.GenerateReportMemoryStream(false, invoice), "DontStayIn " + invoice.TypeToString + " #" + invoice.K.ToString() + ".doc", "application/word") }; string body = "<p>" + emailSubject + "</p>"; if (invoice.Promoter != null) body += "<p>Account: " + invoice.Promoter.Name + "</p>"; else if (invoice.Usr != null) body += "<p>Account: " + invoice.Usr.NickName + "</p>"; Utilities.EmailToNonUser(emailAddress, emailSubject, body, attachments); } catch (Exception ex) { string additionalDetails = "Occurred in Utilities.EmailInvoice(invoice, emailAddress): Invoice K= "; if (invoice != null) additionalDetails += invoice.K.ToString(); else additionalDetails += "null"; EmailException(ex, additionalDetails, invoice); return false; } return true; }
public void UpdateAndResolveOverapplied() { decimal amountRemaining = AmountRemaining(); if (Math.Round(amountRemaining,2) < 0) { Query invoiceTransfersAppliedQuery = new Query(new And(new Q(InvoiceTransfer.Columns.TransferK, this.K), new Q(Invoice.Columns.Type, Invoice.Types.Invoice))); invoiceTransfersAppliedQuery.TableElement = new Join(InvoiceTransfer.Columns.InvoiceK, Invoice.Columns.K); invoiceTransfersAppliedQuery.OrderBy = new OrderBy(Invoice.Columns.DueDateTime, OrderBy.OrderDirection.Ascending); InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(invoiceTransfersAppliedQuery); string transferNote = "Transfer overapplied by " + ((double)(-1 * amountRemaining)).ToString("c") + "."; decimal amountToUnApply = 0; for (int i = invoiceTransferSet.Count - 1; i >= 0; i--) { if (Math.Round(amountRemaining,2) < 0) { Invoice invoice = new Invoice(invoiceTransferSet[i].InvoiceK); if (invoiceTransferSet[i].Amount <= -1 * amountRemaining) { amountToUnApply = invoiceTransferSet[i].Amount; invoiceTransferSet[i].Delete(); } else { amountToUnApply = -1 * amountRemaining; invoiceTransferSet[i].Amount -= amountToUnApply; invoiceTransferSet[i].Amount = Math.Round(invoiceTransferSet[i].Amount, 2); invoiceTransferSet[i].Update(); } transferNote += string.Format("\nAutomatically unapplied {0} from invoice #{1}.", amountToUnApply.ToString("c"), invoice.K); amountRemaining += amountToUnApply; //if (this.Method == Methods.TicketSales) // BankExport.GenerateBankExportForTicketFundsUsed(this, -1 * amountToUnApply, new Invoice(invoiceTransferSet[i].InvoiceK)); invoice.AddNote(string.Format("Transfer #{0} was overapplied. {1} has been unapplied from transfer #{0}.", this.K, amountToUnApply.ToString("c")), "System"); invoice.UpdateAndSetPaidStatus(); } } this.AddNote(transferNote, "System"); if (Math.Round(amountRemaining, 2) == 0) this.IsFullyApplied = true; else this.IsFullyApplied = false; this.Update(); } }
protected void SetupTransferButton_Click(object sender, EventArgs e) { SetupAllOutstandingInvoices(); SetupPayment.Reset(); List<int> invoiceKList = new List<int>(); // Loop through Repeater dataset, get all checked, and pass those K's to the payment screen foreach (RepeaterItem rpi in this.PromoterAccountItemRepeater.Items) { CheckBox outstandingCheckBox = (CheckBox)rpi.FindControl("OutstandingCheckBox"); if (outstandingCheckBox.Checked == true) { Label invoiceKLabel = (Label)rpi.FindControl("InvoiceKLabel"); invoiceKList.Add(Convert.ToInt32(invoiceKLabel.Text)); } } foreach (int invoiceK in invoiceKList) { Invoice invoice = new Invoice(invoiceK); InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(new Query(new Q(InvoiceCredit.Columns.InvoiceK, invoice.K))); InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(new Query(new Q(InvoiceTransfer.Columns.InvoiceK, invoice.K))); var total = invoice.Total; var vat = invoice.Vat; var price = invoice.Price; foreach (InvoiceCredit invoiceCredit in invoiceCreditSet) { Invoice credit = new Invoice(invoiceCredit.CreditInvoiceK); //price += credit.Price; //vat += credit.Vat; total += credit.Total; } foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet) { Transfer transfer = new Transfer(invoiceTransfer.TransferK); if (transfer.Status.Equals(Transfer.StatusEnum.Success)) { total -= transfer.Amount; } } InvoiceDataHolder idh = new InvoiceDataHolder(invoice); //idh.K = 0; this.SetupPayment.Invoices.Add(idh); } this.SetupPayment.PromoterK = CurrentPromoter.K; this.SummaryPanel.Visible = false; this.SetupTransferPanel.Visible = true; // this.SetupPayment.Initialize(); }
public List<Ticket> UpdateTicketsFromPaymentControl() { List<Ticket> ticketsPurchased = new List<Ticket>(); foreach (InvoiceDataHolder idh in this.Payment.Invoices) { if (idh.K > 0) { Invoice invoice = new Invoice(idh.K); //string ticketPurchaseMessage = "You just purchased "; //int ticketCounter = 0; foreach (InvoiceItem invoiceItem in invoice.Items) { if (invoiceItem.BuyableObjectType.Equals(Model.Entities.ObjectType.Ticket) && invoiceItem.Type.Equals(InvoiceItem.Types.EventTickets)) { Ticket ticket = new Ticket(invoiceItem.BuyableObjectK); // Only update once. If page is refreshed, it shouldnt redo the updating of this ticket. if (ticket.InvoiceItemK == 0) { Transfer transfer = new Transfer(); if (this.Payment.SecPay != null && this.Payment.SecPay.Transfer != null && this.Payment.SecPay.Transfer.K > 0) transfer = this.Payment.SecPay.Transfer; else if (invoice.SuccessfulAppliedTransfers.Count > 0 && invoice.SuccessfulAppliedTransfers[0].K > 0) transfer = invoice.SuccessfulAppliedTransfers[0]; if (transfer.K > 0) { bool ticketWasEnabled = ticket.Enabled; ticket.AddressArea = Payment.CurrentUsr.AddressArea; if (ticket.AddressCountryK == 0) ticket.AddressCountryK = Payment.CurrentUsr.AddressCountryK; ticket.AddressPostcode = transfer.CardPostcode; ticket.AddressStreet = transfer.CardAddress1; ticket.AddressTown = Payment.CurrentUsr.AddressTown; ticket.CardNumberDigits = transfer.CardDigits; ticket.CardNumberEnd = transfer.CardNumberEnd; ticket.CardNumberHash = transfer.CardNumberHash; ticket.CardCV2 = transfer.CardCV2; string cardName = Utilities.StripTitleFromName(transfer.CardName); ticket.FirstName = Cambro.Misc.Utility.Snip(Utilities.GetFirstName(cardName), 100); ticket.LastName = Cambro.Misc.Utility.Snip(Utilities.GetLastName(cardName), 100); if (!ticket.Enabled && invoiceItem.K > 0 && transfer.Status == Transfer.StatusEnum.Success && Math.Round(transfer.Amount, 2) >= Math.Round(ticket.Price + ticket.BookingFee, 2) && ticket.Invoice != null && ticket.Invoice.Paid) { ticket.Enabled = true; } ticket.InvoiceItemK = invoiceItem.K; ticket.Mobile = Payment.CurrentUsr.Mobile; ticket.MobileCountryCode = Payment.CurrentUsr.MobileCountryCode; ticket.Update(); if (ticket.Enabled) { Utilities.EmailStyledTicket(this.StyledObject, ticket); ticketsPurchased.Add(ticket); } if (!ticketWasEnabled && ticket.Enabled) { ticket.TicketRun.CalculateSoldTicketsAndUpdate(); } } else { Utilities.AdminEmailAlert("<p>Error in Styled.Pay.UpdateTicketsFromPaymentControl(). Transfer not found.</p>", "Error in Styled.Pay.UpdateTicketsFromPaymentControl(). Transfer not found.", new DsiUserFriendlyException("Error in UpdateTicketsFromPaymentControl()"), new List<IBobAsHTML>() { ticket, invoice }, new string[] { Vars.EMAIL_ADDRESS_TIMI }); } } } } } } return ticketsPurchased; }
public StringBuilder GenerateReportStringBuilder(bool linksEnabled) { StringBuilder sb = new StringBuilder(); sb.Append(@"<form id='form1' runat='server'><div style='font-family:Verdana;'><table width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><tr><td valign='top'> <table width='100%'>"); sb.Append(Utilities.GenerateHTMLHeaderRowString(this.Type.Equals(TransferTypes.Payment) ? "RECEIPT" : "REMITTANCE ADVICE")); sb.Append(@"<tr> <td align='left' valign='top' style='padding-left:48px;'>"); if (this.Promoter != null) { if (this.Promoter.AccountsName.Length > 0) { sb.Append(this.Promoter.AccountsName); sb.Append("<br>"); } else if (this.Usr != null && this.Usr.FullName.Length > 0 && this.Usr.IsPromoter && this.Usr.IsPromoterK(this.K)) { sb.Append(this.Usr.FullName); sb.Append("<br>"); } else if (this.Promoter.PrimaryUsr != null && this.Promoter.PrimaryUsr.FullName.Length > 0) { sb.Append(this.Promoter.PrimaryUsr.FullName); sb.Append("<br>"); } if (this.Promoter.Name.Length > 0) { sb.Append(this.Promoter.Name); sb.Append("<br>"); } sb.Append(this.Promoter.AddressHtml); } else if (this.Usr != null) { if (this.Usr.FullName.Length > 0) { sb.Append(this.Usr.FullName); sb.Append("<br>"); } sb.Append(this.Usr.AddressHtml()); } sb.Append(@"</td><td width='350'></td><td valign='top' width='100'>Transfer No.<br><br>Acc No.<br><br>Date</td> <td align='right' valign='top' width='125'>"); sb.Append("TRN"); sb.Append(this.K.ToString()); sb.Append("<br><br>"); if (this.Promoter != null) sb.Append(this.PromoterK.ToString()); else if (this.Usr != null) sb.Append(this.UsrK.ToString()); else sb.Append(" "); sb.Append("<br><br>"); sb.Append(this.DateTimeCreated.ToString("dd/MM/yy")); sb.Append("</td></tr>"); //if (this.DateTimeComplete != null && this.DateTimeComplete > DateTime.MinValue) //{ // sb.Append(@"<br><br><b>Date Completed</b><br>" + this.DateTimeComplete.ToShortDateString()); //} sb.Append(@"</table><br><br> <table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='250'><b>Transfer</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85'><b>Method</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='160'><b>Method Ref#</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90'><b>Status</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' align='left' width='85'><b>Amount</b></td> </tr>"); sb.Append(@"<tr><td class='BorderBlack Left'>" + this.TypeToString + @"</td>" + "<td class='BorderBlack Left'>" + Utilities.CamelCaseToString(this.Method.ToString()).Replace(" ", " ") + @"</td> <td class='BorderBlack Left'>"); sb.Append(this.ReferenceNumberToHtml()); sb.Append(@"</td> <td class='BorderBlack Left'>" + this.Status.ToString() + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(this.Amount) + @"</td></tr></table><br><br>"); if (InvoiceTransfers.Count > 0) { // Rename "Date" to "Tax Date", as per Dave's request 7/2/07 sb.Append(@"<table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='305'><b>Items Applied To</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='65'><b>Tax Date</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='150'><b>Total Invoice Amount</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='150'><b>Amount Applied To Invoice</b></td> </tr>"); foreach (InvoiceTransfer invoiceTransfer in InvoiceTransfers) { Invoice invoice = new Invoice(invoiceTransfer.InvoiceK); sb.Append(@"<tr> <td class='BorderBlack Left'>"); if (linksEnabled) { sb.Append(invoice.Link()); } else sb.Append(invoice.TypeAndK); // Replacing CreatedDateTime with TaxDateTime, as per Gee's request for OASIS v1.5 sb.Append(@"</td> <td class='BorderBlack Left'>" + invoice.TaxDateTime.ToString("dd/MM/yy") + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(invoice.Total) + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(invoiceTransfer.Amount) + @"</td> </tr>"); } sb.Append(@"</table><br>"); } Query refundTransferQuery = new Query(); if(this.Type.Equals(TransferTypes.Payment)) refundTransferQuery.QueryCondition = new And(new Q(Transfer.Columns.TransferRefundedK, this.K), new Or(new Q(Transfer.Columns.Status, Transfer.StatusEnum.Pending), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success))); else refundTransferQuery.QueryCondition = new And(new Q(Transfer.Columns.K, this.TransferRefundedK), new Or(new Q(Transfer.Columns.Status, Transfer.StatusEnum.Pending), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success))); TransferSet refundTransferSet = new TransferSet(refundTransferQuery); if (refundTransferSet.Count > 0) { sb.Append(@"<br><table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='250'><b>"); if (this.Type.Equals(TransferTypes.Payment)) { if (this.Method == Methods.TicketSales) sb.Append(Utilities.CamelCaseToString(Methods.TicketSales.ToString()) + " Release"); else sb.Append(TransferTypes.Refund.ToString()); } else if (this.Type.Equals(TransferTypes.Refund)) sb.Append(TransferTypes.Payment.ToString()); sb.Append(@"</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85'><b>Method</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='160'><b>Method Ref#</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90'><b>Status</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' align='left' width='85'><b>Amount</b></td> </tr>"); foreach (Transfer refundTransfer in refundTransferSet) { sb.Append(@"<tr> <td class='BorderBlack Left'>"); if (linksEnabled) { if (refundTransfer.TicketPromoterEvent != null) sb.Append(Utilities.Link(refundTransfer.TicketPromoterEvent.UrlReport(), refundTransfer.TypeAndK)); else sb.Append(refundTransfer.Link()); } else sb.Append(refundTransfer.TypeAndK); sb.Append(@"</td> <td class='BorderBlack Left'>" + Utilities.CamelCaseToString(refundTransfer.Method.ToString()) + @"</td>" + "<td class='BorderBlack Left'>"); sb.Append(refundTransfer.ReferenceNumberToHtml()); sb.Append(@"</td> <td class='BorderBlack Left'>" + refundTransfer.Status.ToString() + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(refundTransfer.Amount) + @"</td></tr>"); } sb.Append(@"</table><br>"); } // DSI Registration Footer sb.Append(Utilities.GenerateHTMLFooterRowString()); sb.Append(@"</table></div></form>"); return sb; }
private void ProcessPaymentResults() { this.transfer.DateTimeComplete = this.transfer.DateTimeCreated; this.transfer.Update(); if (this.transfer.Status.Equals(Transfer.StatusEnum.Success)) { try { Invoice invoice = new Invoice(); // Apply to invoices foreach (InvoiceDataHolder idh in invoiceDataHolders) { bool creatingInvoice = false; // Get Invoice.K for unsaved invoices if (idh.K == 0) { creatingInvoice = true; idh.Type = Invoice.Types.Invoice; idh.VatCode = Invoice.VATCodes.T1; invoice = idh.UpdateInsertDelete(); } else { invoice = new Invoice(idh.K); } InvoiceTransfer invoiceTransfer = new InvoiceTransfer(); invoiceTransfer.InvoiceK = invoice.K; invoiceTransfer.TransferK = this.transfer.K; if (amount >= invoice.Total) invoiceTransfer.Amount = invoice.Total; else invoiceTransfer.Amount = amount; amount -= invoiceTransfer.Amount; invoiceTransfer.Update(); if (invoiceTransfer.Amount == invoice.Total && creatingInvoice) invoice.IsImmediateCreditCardPayment = true; invoice.AssignBuyerType(); invoice.UpdateAndAutoApplySuccessfulTransfersWithAvailableMoney();//.UpdateAndSetPaidStatus(); if (creatingInvoice) { if (invoice.Paid && invoice.DueDateTime > invoice.PaidDateTime) { invoice.DueDateTime = invoice.PaidDateTime; invoice.Update(); } invoice.Process(); } this.invoices.Add(invoice); } if (Math.Round(amount, 2) == 0) { this.transfer.IsFullyApplied = true; this.transfer.Update(); } Utilities.EmailTransfer(transfer, true, true); } catch (Exception ex) { EmailSecPayException(ex); } } }
public StringBuilder GenerateReportStringBuilder(bool linksEnabled) { DateTime taxDate = DateTime.Now; if (this.TaxDateTime != null && this.TaxDateTime > DateTime.MinValue) taxDate = this.TaxDateTime; StringBuilder sb = new StringBuilder(); decimal amountPaid = 0; sb.Append(@"<form id='form1' runat='server'><div style='font-family:Verdana;'><table width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><tr><td valign='top'> <table width='100%'>"); sb.Append(Utilities.GenerateHTMLHeaderRowString(this.Type.Equals(Invoice.Types.Credit) ? this.TypeToString.ToUpper() + " NOTE" : this.TypeToString.ToUpper())); sb.Append(@"<tr> <td colspan=1 align='left' valign='top' width='450' style='padding-left:48px;'>"); if (this.Promoter != null) { if (this.Promoter.AccountsName.Length > 0) { sb.Append(this.Promoter.AccountsName); sb.Append("<br>"); } else if (this.Usr != null && this.Usr.FullName.Length > 0 && this.Usr.IsPromoter && this.Usr.IsPromoterK(this.K)) { sb.Append(this.Usr.FullName); sb.Append("<br>"); } else if (this.Promoter.PrimaryUsr != null && this.Promoter.PrimaryUsr.FullName.Length > 0) { sb.Append(this.Promoter.PrimaryUsr.FullName); sb.Append("<br>"); } if (this.Promoter.Name.Length > 0) { sb.Append(this.Promoter.Name); sb.Append("<br>"); } sb.Append(this.Promoter.AddressHtml); } else if (this.Usr != null) { if (this.Usr.FullName.Length > 0) { sb.Append(this.Usr.FullName); sb.Append("<br>"); } sb.Append(this.Usr.AddressHtml()); } // Addition of Created and renaming of "Date" to "Tax Date", as per Dave's request 7/2/07 sb.Append(@"</td><td width='350'></td><td valign='top' width='100'>" + this.TypeToString + " No."); if (this.PurchaseOrderNumber.Length > 0) sb.Append("<br><br>Purchase Order No."); sb.Append("<br><br>Acc No.<br><br>Created<br><br>Tax Date"); if (this.Type.Equals(Invoice.Types.Invoice)) sb.Append("<br><br>Due Date"); sb.Append(@"</td><td align='right' valign='top' width='125'>"); if (this.Type.Equals(Invoice.Types.Invoice)) sb.Append("INV"); else sb.Append("CRD"); sb.Append(this.K.ToString()); if (this.PurchaseOrderNumber.Length > 0) sb.Append("<br><br><nobr>" + this.PurchaseOrderNumber.Replace("-", "‑")); sb.Append("</nobr><br><br>"); if (this.Promoter != null) sb.Append(this.PromoterK.ToString()); else if (this.Usr != null) sb.Append(this.UsrK.ToString()); else sb.Append(" "); // Addition of Created, as per Dave's request 7/2/07 sb.Append("<br><br>"); sb.Append(this.CreatedDateTime.ToString("dd/MM/yy")); sb.Append("<br><br>"); // Replacing CreatedDateTime with TaxDateTime, as per Gee's request for OASIS v1.5 //sb.Append(this.CreatedDateTime.ToString("dd/MM/yy")); sb.Append(this.TaxDateTime.ToString("dd/MM/yy")); if (this.Type.Equals(Invoice.Types.Invoice)) { sb.Append("<br><br>"); sb.Append(this.DueDateTime.ToString("dd/MM/yy")); } sb.Append("</td></tr>"); //if(this.PaidDateTime != null && this.PaidDateTime > DateTime.MinValue) //{ // sb.Append(@"<br><br><b>Date Completed</b><br>" + this.PaidDateTime.ToShortDateString()); //} sb.Append(@"</table><br><br> <table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Right Bottom'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='350'><b>Item</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='55' align='left'><b>Tax Code</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Price</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85' align='left'><b>VAT</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Total</b></td> </tr>"); Query InvoiceItemQuery = new Query(new Q(InvoiceItem.Columns.InvoiceK, this.K)); InvoiceItemSet invoiceItemSet = new InvoiceItemSet(InvoiceItemQuery); List<InvoiceItem.VATCodes> invoiceItemVatCodes = new List<InvoiceItem.VATCodes>(); foreach (InvoiceItem invoiceItem in invoiceItemSet) { if (!invoiceItemVatCodes.Contains(invoiceItem.VatCode)) invoiceItemVatCodes.Add(invoiceItem.VatCode); sb.Append(@"<tr> <td class='BorderBlack Left'>" + invoiceItem.Description + (invoiceItem.Discount > 0 ? " <small>@ " + invoiceItem.Discount.ToString("P2") + " discount</small>" : "") + @"</td>"); if (!this.VatCode.Equals(Invoice.VATCodes.T1)) { sb.Append(@"<td class='BorderBlack Left' width='55' align='left'>" + this.VatCode.ToString() + @"</td>"); } else { sb.Append(@"<td class='BorderBlack Left' width='55' align='left'>" + invoiceItem.VatCode.ToString() + @"</td>"); } sb.Append(@"<td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoiceItem.Price) + @"</td> <td class='BorderBlack Left' width='85' align='right'>" + Utilities.MoneyToHTML(invoiceItem.Vat) + @"</td> <td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoiceItem.Total) + @"</td> </tr>"); } sb.Append(@"<tr> <td class='BorderBlack Top Left' colspan='2' align='right'><b>TOTAL:</b></td> <td class='BorderBlack Top Left' width='90' align='right'><b>" + Utilities.MoneyToHTML(this.Price) + @"</b></td> <td class='BorderBlack Top Left' width='85' align='right'><b>" + Utilities.MoneyToHTML(this.Vat) + @"</b></td> <td class='BorderBlack Top Left' width='90' align='right'><b>" + Utilities.MoneyToHTML(this.Total) + @"</b></td> </tr></table>"); InvoiceItem.VATCodes[] invoiceItemVatCodeArray = invoiceItemVatCodes.ToArray(); Array.Sort(invoiceItemVatCodeArray); sb.Append("<small><i><b>VAT Rate:</b> "); if (this.VatCode.Equals(Invoice.VATCodes.T1) && invoiceItemVatCodeArray.Length > 0) { foreach (InvoiceItem.VATCodes vatCode in invoiceItemVatCodeArray) { sb.Append(vatCode.ToString()); sb.Append("="); sb.Append(InvoiceItem.VATRate(vatCode, taxDate).ToString("0.0%")); sb.Append(" "); } } else { sb.Append(this.VatCode.ToString()); sb.Append("="); sb.Append(Invoice.VATRate(this.VatCode, taxDate).ToString("0.0%")); } sb.Append("</i></small><br>"); sb.Append("<br>"); Query InvoiceTransferQuery = new Query(new And(new Q(InvoiceTransfer.Columns.InvoiceK, this.K), new Or(new Q(Transfer.Columns.Status, Transfer.StatusEnum.Pending), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success), new Q(Transfer.Columns.Status, Transfer.StatusEnum.Cancelled)))); InvoiceTransferQuery.TableElement = new Join(InvoiceTransfer.Columns.TransferK, Transfer.Columns.K); InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(InvoiceTransferQuery); bool nonSuccessfulTransfer = false; if (invoiceTransferSet.Count > 0) { sb.Append(@"<br><table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Right Bottom'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='205'><b>Transfer</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='65' align='left'><b>Date</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='75' align='left'><b>Method</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='150' align='left'><b>Method Ref#</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Status</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85' align='left'><b>Amount</b></td> </tr>"); foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet) { Transfer transfer = new Transfer(invoiceTransfer.TransferK); sb.Append(@"<tr> <td class='BorderBlack Left'>"); if (linksEnabled) sb.Append(Utilities.Link(transfer.UrlReport(), transfer.Type.ToString() + " #" + transfer.K.ToString())); else sb.Append(transfer.Type.ToString() + " #" + transfer.K.ToString()); sb.Append(@"</td> <td class='BorderBlack Left' width='65' align='left'>" + transfer.DateTimeCreated.ToString("dd/MM/yy") + @"</td> <td class='BorderBlack Left' width='75' align='left'><nobr>" + Utilities.CamelCaseToString(transfer.Method.ToString()) + @"</nobr></td> <td class='BorderBlack Left' width='150' align='left'>"); sb.Append(transfer.ReferenceNumberToHtml()); sb.Append(@"</td> <td class='BorderBlack Left' width='90' align='left'>" + transfer.Status.ToString() + @"</td> <td class='BorderBlack Left' width='85' align='right'>" + Utilities.MoneyToHTML(invoiceTransfer.Amount) + @"</td> </tr>"); if (!transfer.Status.Equals(Transfer.StatusEnum.Success)) nonSuccessfulTransfer = true; else amountPaid += invoiceTransfer.Amount; } sb.Append(@"</table>"); // For now, this note only pertains to Invoices if (this.Type.Equals(Invoice.Types.Invoice) && nonSuccessfulTransfer == true) sb.Append(@"<small><i>(<b>Note:</b> Only successful transfers will be applied to the payment total. Pending and cancelled transfers will not be applied)</i></small><br>"); sb.Append("<br>"); } Query InvoiceCreditQuery = new Query(); if (this.Type.Equals(Invoice.Types.Invoice)) { InvoiceCreditQuery = new Query(new Q(InvoiceCredit.Columns.InvoiceK, this.K)); } else { InvoiceCreditQuery = new Query(new Q(InvoiceCredit.Columns.CreditInvoiceK, this.K)); } InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(InvoiceCreditQuery); if (invoiceCreditSet.Count > 0) { string invoiceHeader = "Invoice"; Invoice invoice = new Invoice(); if (this.Type.Equals(Invoice.Types.Invoice)) invoiceHeader = "Credit"; sb.Append(@"<br><table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='335'><b>" + invoiceHeader + @"</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='70' align='left'><b>Date</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Price</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85' align='left'><b>VAT</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Total</b></td> </tr>"); foreach (InvoiceCredit invoiceCredit in invoiceCreditSet) { if (this.Type.Equals(Invoice.Types.Invoice)) { // Credit amounts are negative amountPaid -= invoiceCredit.Amount; invoice = new Invoice(invoiceCredit.CreditInvoiceK); } else invoice = new Invoice(invoiceCredit.InvoiceK); sb.Append(@"<tr> <td class='BorderBlack Left'>"); if (linksEnabled) sb.Append(Utilities.Link(invoice.UrlReport(), invoiceHeader + " #" + invoice.K.ToString())); else sb.Append(invoiceHeader + " #" + invoice.K.ToString()); // Replacing CreatedDateTime with TaxDateTime, as per Gee's request for OASIS v1.5 sb.Append(@"</td> <td class='BorderBlack Left' width='70' align='left'>" + invoice.TaxDateTime.ToString("dd/MM/yy") + @"</td> <td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoice.Price) + @"</td> <td class='BorderBlack Left' width='85' align='right'>" + Utilities.MoneyToHTML(invoice.Vat) + @"</td> <td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoice.Total) + @"</td> </tr>"); } sb.Append(@"</table><br><br>"); } if (this.Type.Equals(Invoice.Types.Invoice)) { // Invoice Summary sb.Append(@"<br><table width='250'> <tr> <td colspan=2><b>Summary</b></td> </tr> <tr> <td width='135'>Invoice Total:</td> <td width='115' align='right'>" + Utilities.MoneyToHTML(this.Total) + @"</td> </tr> <tr> <td width='135'>Payment Total:</td> <td width='115' align='right'>" + Utilities.MoneyToHTML(amountPaid) + @"</td> </tr> <tr> <td width='135'><b>Outstanding:</b></td> <td width='115' align='right'><b>" + Utilities.MoneyToHTML(this.Total - amountPaid) + @"</b></td> </tr></table><br><br>"); } sb.Append(@"</td></tr>"); sb.Append(@" <tr> <td valign='bottom' align='center'> <div style='width:50%;padding:20px;border:2px solid #000000;text-align:left;'> Bank details for payments:<br> Development Hell Limited<br> Barlcays Bank PLC, Commercial Bank Basingstoke<br> Sort Code: 20-37-63<br> Account number: 00478377<br> For international payments:<br> IBAN - GB04BARC20376300478377<br> Swift - BARCGB22 </div> </td> </tr>"); // DSI Registration Footer sb.Append(Utilities.GenerateHTMLFooterRowString()); sb.Append(@"</table></div></form>"); return sb; }
public void ApplyCreditToThisInvoice(Invoice credit) { InvoiceCredit invoiceCredit; try { invoiceCredit = new InvoiceCredit(this.K, credit.K); } catch (Exception) { invoiceCredit = new InvoiceCredit(); invoiceCredit.InvoiceK = this.K; invoiceCredit.CreditInvoiceK = credit.K; } invoiceCredit.Amount = credit.Total; invoiceCredit.Update(); this.UpdateAndSetPaidStatus(); }
public PromoterAccountItem(Invoice invoice) { this.K = invoice.K; if (invoice.Type.Equals(Invoice.Types.Invoice)) { this.OriginalType = Type.Invoice; this.Outstanding = invoice.AmountDue.ToString("c"); } else { this.OriginalType = Type.Credit; this.Outstanding = " "; } // Replacing TaxDateTime with CreatedDateTime, as per Dave's request 7/2/07 this.Date = invoice.CreatedDateTime; this.Total = Math.Abs(invoice.Total).ToString("c"); this.Status = FormatStatus(invoice); this.ViewLink = Utilities.LinkNewWindow(invoice.UrlReport(), "View"); this.EditLink = "<small>" + Utilities.LinkNewWindow(invoice.UrlAdmin(), "[Edit]") + "</small>"; }
protected void Page_Load(object sender, EventArgs e) { string type = ""; int k = 0; int pk = 0; if (ContainerPage.Url["type"].Exists) type = ContainerPage.Url["type"].Value; if (ContainerPage.Url["K"].Exists && ContainerPage.Url["K"].IsInt) k = Convert.ToInt32(ContainerPage.Url["K"].Value); if (ContainerPage.Url["PK"].Exists && ContainerPage.Url["PK"].IsInt) pk = Convert.ToInt32(ContainerPage.Url["PK"].Value); //Promoter CurrentPromoter = new Promoter(pk); Usr.KickUserIfNotLoggedIn(); //if (!Usr.Current.IsPromoter && !Usr.Current.IsAdmin) //{ // throw new Exception("You must be a promoter to view this page"); //} //if (CurrentPromoter != null) //{ // if (!Usr.Current.IsPromoterK(CurrentPromoter.K) && !Usr.Current.IsAdmin) // throw new Exception("You can't view these details."); //} if (type.ToUpper() == "STATEMENT") { Promoter promoter = new Promoter(pk); if (!promoter.IsUsrAllowedAccess(Usr.Current)) throw new Exception(Vars.CANT_VIEW_DETAILS); int month = DateTime.Now.Month; int year = DateTime.Now.Year; if (ContainerPage.Url["M"].Exists && ContainerPage.Url["M"].IsInt) month = Convert.ToInt32(ContainerPage.Url["M"].Value); if (ContainerPage.Url["Y"].Exists && ContainerPage.Url["Y"].IsInt) year = Convert.ToInt32(ContainerPage.Url["Y"].Value); Response.Write(promoter.GenerateMonthlyStatementStringBuilder(month, year, true).ToString()); } else if(type.ToUpper().Equals("TICKETFUNDSINVOICE")) { TicketPromoterEvent tpe = new TicketPromoterEvent(pk, k); if (!tpe.IsUsrAllowedAccess(Usr.Current)) throw new Exception(Vars.CANT_VIEW_DETAILS); Response.Write(tpe.GenerateReportStringBuilder(true).ToString()); } else { IBobReport bobReport; switch (type.ToUpper()) { case "TRANSFER": bobReport = new Transfer(k); break; case "INVOICE": // goto credit case "CREDIT": bobReport = new Bobs.Invoice(k); break; case "TICKET": bobReport = new Ticket(k); break; case "TICKETFORPRINTING": bobReport = new TicketForPrinting(k); break; case "INSERTIONORDER": bobReport = new InsertionOrder(k); break; default: bobReport = null; break; } if (bobReport != null) { if (!bobReport.IsUsrAllowedAccess(Usr.Current)) throw new Exception(Vars.CANT_VIEW_DETAILS); Response.Write(bobReport.GenerateReportStringBuilder(true).ToString()); } } }
public string FormatStatus(Invoice invoice) { string output = ""; if (invoice.Type.Equals(Invoice.Types.Invoice)) { if (invoice.Status.Equals(Invoice.Statuses.Outstanding)) output = "<b>" + invoice.Status.ToString() + ",<br />due " + invoice.DueDateTime.ToString("dd/MM/yy") + "</b>"; else if (invoice.Status.Equals(Invoice.Statuses.Overdue)) output = "<font color=\"#ff0000;\"><b>" + invoice.Status.ToString() + ",<br />due " + invoice.DueDateTime.ToString("dd/MM/yy") + "</b></font>"; else output = invoice.Status.ToString(); } else { if (invoice.Status.Equals(Invoice.Statuses.Paid)) output = "Refunded"; else output = "Credited"; } return output; }
public StringBuilder GenerateReportStringBuilder(bool linksEnabled) { StringBuilder sb = new StringBuilder(); string lineReturn = Vars.HTML_LINE_RETURN; if (this.FundsReleased && this.Promoter != null && this.Event != null && this.FundsTransfer != null) { this.CalculateTotalFundsAndVat(); sb.Append(@"<form id='form1' runat='server'><div style='font-family:Verdana;'><table width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><tr><td valign='top'> <table width='100%'>"); sb.Append(@"<tr> <td valign='bottom'>" + Vars.DSI_POSTAL_DETAILS_HTML + "</td>"); sb.Append(@" <td align='right'>"); sb.Append(@" <table> <tr> <td><b>"); sb.Append(lineReturn); if (linksEnabled) sb.Append(this.Promoter.Link()); else sb.Append(this.Promoter.Name); sb.Append("</b>"); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(this.Promoter.AddressHtml); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append("VAT #: "); if (this.Promoter.VatStatus == Promoter.VatStatusEnum.Registered) sb.Append(this.Promoter.VatNumber); else if (this.Promoter.VatStatus == Promoter.VatStatusEnum.NotRegistered) sb.Append("Not registered"); else // sb.Append("UNKNOWN"); throw new DsiUserFriendlyException("VAT Status is unknown."); sb.Append(lineReturn); sb.Append(@" <b>INVOICE</b> </td> </tr>"); sb.Append(@" <tr> <td>Invoice date:</td>"); sb.Append(" <td>" + this.FundsTransfer.DateTimeCreated.ToString("dd/MM/yyyy") + @"</td> </tr>"); sb.Append(@" <tr> <td>Invoice number:</td>"); sb.Append(" <td>" + this.FundsTransferK.ToString() + @"</td> </tr>"); sb.Append(@" <tr> <td>Your account number:</td>"); sb.Append(" <td>" + this.PromoterK.ToString() + @"</td> </tr> </table>"); sb.Append(@" </td> </tr> </table>"); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append("<b>EVENT: "); if (linksEnabled) sb.Append(this.Event.LinkFriendlyName); else sb.Append(this.Event.FriendlyName); sb.Append("</b>"); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(@"<table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85'><b>Ticket run #</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='365'><b>Details</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='40'><b>Sold</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='60'><b>Price</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='55'><b>VAT</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left Right' width='65'><b>Total</b></td> </tr>"); decimal totalPrice = 0; decimal totalVat = 0; decimal totalFunds = 0; int totalQuantity = 0; foreach (TicketRun tr in this.TicketRuns) { sb.Append(@"<tr> <td class='BorderBlack Left'>" + tr.K.ToString() + @"</td>"); sb.Append(@" <td class='BorderBlack Left'>"); if (linksEnabled) sb.Append(tr.LinkPriceBrandName); else sb.Append(tr.PriceBrandName); sb.Append(@" </td>"); decimal price = 0; decimal vat = 0; decimal total = 0; int quantity = 0; foreach (Ticket ticket in tr.Tickets) { if (!ticket.CancelledBeforeFundsRelease) { quantity += ticket.Quantity; price += ticket.InvoiceItem.Price; vat += ticket.InvoiceItem.Vat; total += ticket.InvoiceItem.Total; } } if (quantity != tr.SoldTickets - tr.CancelledTicketBeforeFundReleaseQuantity) throw new DsiUserFriendlyException("Error in calculating number of tickets sold. Please contact an administrator."); sb.Append(@" <td class='BorderBlack Left' align='right'>" + quantity.ToString() + @"</td>"); sb.Append(@" <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(price) + @"</td>"); sb.Append(@" <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(vat) + @"</td>"); sb.Append(@" <td class='BorderBlack Left Right' align='right'>" + Utilities.MoneyToHTML(total) + @"</td> </tr>"); totalQuantity += quantity; totalPrice += price; totalVat += vat; totalFunds += total; } if (Math.Round(totalPrice, 2) != Math.Round(this.TotalFundsReleased - this.TotalVatReleased, 2) || Math.Round(totalVat, 2) != Math.Round(this.TotalVatReleased, 2) || Math.Round(totalFunds, 2) != Math.Round(this.TotalFundsReleased, 2) || totalQuantity != this.SoldTickets - this.TotalCancelledTicketsBeforeRelease) throw new DsiUserFriendlyException("Error in calculating tickets funds. Please contact an administrator."); sb.Append(@"<tr style='border-top-width: 2px;' class='BorderBlack'> <td style='border-top-width: 2px;' class='BorderBlack' colspan='2'> </td>"); sb.Append(@" <td style='border-top-width: 2px; border-bottom-width: 2px;' class='BorderBlack Left' align='right'>" + totalQuantity.ToString() + @"</td>"); sb.Append(@" <td style='border-top-width: 2px; border-bottom-width: 2px;' class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(this.TotalFundsReleased - this.TotalVatReleased) + @"</td>"); sb.Append(@" <td style='border-top-width: 2px; border-bottom-width: 2px;' class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(this.TotalVatReleased) + @"</td>"); sb.Append(@" <td style='border-top-width: 2px; border-bottom-width: 2px;' class='BorderBlack Left Right' align='right'>" + Utilities.MoneyToHTML(this.TotalFundsReleased) + @"</td> </tr>"); if (this.Promoter.VatStatus == Promoter.VatStatusEnum.Registered) sb.Append("<tr><td colspan='6' align='center'>THE VAT SHOWN IS YOUR OUTPUT TAX DUE TO HM REVENUE & CUSTOMS</td></tr>"); sb.Append("</table>"); decimal appliedAmount = 0; if (this.FundsTransfer.InvoiceTransfers.Count > 0) { sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(@"<table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='305'><b>Items Applied To</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='65'><b>Tax Date</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='150'><b>Total Invoice Amount</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='150'><b>Amount Applied To Invoice</b></td> </tr>"); foreach (InvoiceTransfer invoiceTransfer in this.FundsTransfer.InvoiceTransfers) { Invoice invoice = new Invoice(invoiceTransfer.InvoiceK); sb.Append(@"<tr> <td class='BorderBlack Left'>"); if (linksEnabled) { sb.Append(invoice.Link()); } else sb.Append(invoice.TypeAndK); // Replacing CreatedDateTime with TaxDateTime, as per Gee's request for OASIS v1.5 sb.Append(@"</td> <td class='BorderBlack Left'>" + invoice.TaxDateTime.ToString("dd/MM/yy") + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(invoice.Total) + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(invoiceTransfer.Amount) + @"</td> </tr>"); appliedAmount += Math.Abs(invoiceTransfer.Amount); } sb.Append(@"</table>"); } decimal refundedAmount = 0; if (this.FundsTransfer.RefundTransfers.Count > 0) { sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(lineReturn); sb.Append(@"<table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'> <tr> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='250'><b>" + this.FundsTransfer.RefundTransfers[0].TypeToString); sb.Append(@"</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85'><b>Method</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='160'><b>Method Ref#</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90'><b>Status</b></td> <td style='vertical-align:bottom;' class='BorderBlack Bottom Left' align='left' width='85'><b>Amount</b></td> </tr>"); foreach (Transfer refundTransfer in this.FundsTransfer.RefundTransfers) { sb.Append(@"<tr> <td class='BorderBlack Left'>"); if (linksEnabled) sb.Append(refundTransfer.Link()); else sb.Append(refundTransfer.TypeAndK); sb.Append(@"</td> <td class='BorderBlack Left'>" + Utilities.CamelCaseToString(refundTransfer.Method.ToString()) + @"</td>" + "<td class='BorderBlack Left'>"); sb.Append(refundTransfer.ReferenceNumberToHtml()); sb.Append(@"</td> <td class='BorderBlack Left'>" + refundTransfer.Status.ToString() + @"</td> <td class='BorderBlack Left' align='right'>" + Utilities.MoneyToHTML(refundTransfer.Amount) + @"</td></tr>"); refundedAmount += Math.Abs(refundTransfer.Amount); } sb.Append(@"</table><br>"); } // TicketPromoterEvent Summary sb.Append(@"<br><table width='250'> <tr> <td colspan=2><b>Summary</b></td> </tr> <tr> <td width='135'>Ticket Sales Total:</td> <td width='115' align='right'>" + Utilities.MoneyToHTML(totalFunds) + @"</td> </tr> <tr> <td width='135'>Payment Total:</td> <td width='115' align='right'>" + Utilities.MoneyToHTML(appliedAmount + refundedAmount) + @"</td> </tr> <tr> <td width='135'><b>Outstanding:</b></td> <td width='115' align='right'><b>" + Utilities.MoneyToHTML(totalFunds - appliedAmount - refundedAmount) + @"</b></td> </tr></table>"); sb.Append("</td></tr>"); // sb.Append(@"<tr><td valign='bottom'><hr></td></tr>"); sb.Append(@"</table></div></form>"); } return sb; }
public InvoiceCreditDataHolder(InvoiceCredit invoiceCredit) { this.invoiceK = invoiceCredit.InvoiceK; this.creditK = invoiceCredit.CreditInvoiceK; this.amount = invoiceCredit.Amount; Invoice credit = new Invoice(invoiceCredit.CreditInvoiceK); this.createdDateTime = credit.CreatedDateTime; }
protected void Page_Load(object sender, EventArgs e) { try { if (ViewState["InvoiceK"] != null) InvoiceK = (int)ViewState["InvoiceK"]; else { if (ContainerPage.Url["K"].IsInt) { InvoiceK = Convert.ToInt32(ContainerPage.Url["K"].Value); ViewState["InvoiceK"] = InvoiceK; } } if(InvoiceK > 0) CurrentInvoice = new Invoice(InvoiceK); } catch { // if no Invoice K, then assume we are creating a new Invoice Response.Redirect(Invoice.UrlAdminNewInvoice()); } InvoiceItemsMessageLabel.Text = ""; InvoiceItemsMessageLabel.Visible = false; if (!this.IsPostBack) { PriceTextBox.Style["text-align"] = "right"; VATTextBox.Style["text-align"] = "right"; TotalTextBox.Style["text-align"] = "right"; DueDateValueLabel.Style["text-align"] = "right"; TaxDateValueLabel.Style["text-align"] = "right"; CreatedDateTextBox.Style["text-align"] = "right"; PaidDateTextBox.Style["text-align"] = "right"; OverrideDueDateCheckBox.Style["text-align"] = "right"; OverrideTaxDateCheckBox.Style["text-align"] = "right"; AmountDueTextBox.Style["text-align"] = "right"; uiAgencyDiscountTextBox.Style["text-align"] = "right"; NotesAddOnlyTextBox.ReadOnlyTextBox.CssClass = "readOnlyNotesTextBox"; NotesAddOnlyTextBox.AddTextBox.CssClass = "addNotesTextBox"; NotesAddOnlyTextBox.TimeStampFormat = "dd/MM/yy HH:mm"; NotesAddOnlyTextBox.AuthorName = Usr.Current.NickName; NotesAddOnlyTextBox.InsertOption = AddOnlyTextBox.InsertOptions.AddAtBeginning; this.SearchForTransferHyperLink.NavigateUrl = UrlInfo.PageUrl(UrlInfo.PageTypes.Admin, "adminmainaccounting", new string[] { }); ViewState["DuplicateGuid"] = Guid.NewGuid(); ViewState["InvoiceTransferDataHolderList"] = null; ViewState["InvoiceTransferDataHolderDeleteList"] = null; ViewState["InvoiceItemDataHolderList"] = null; ViewState["InvoiceItemDataHolderDeleteList"] = null; SetupVatCodeDropDownLists(); SetupSalesUsrDropDownList(); if (InvoiceK > 0) { CalculateInvoiceItemVatAndTotals(); LoadScreenFromInvoice(); if (CurrentInvoice.PromoterK > 0) EmailButton.Visible = true; } else { if (Usr.Current != null) { this.uiActionUserAutoComplete.Value = Usr.Current.K.ToString(); this.uiActionUserAutoComplete.Text = Usr.Current.Name; this.ActionUserValueLabel.Text = Usr.Current.Link(); this.ActionUserValueLabel.Visible = false; } // Setup screen for new data input this.SetPaidImage(false); } CalculateInvoiceItemVatAndTotals(); SetupAvailableTransfersDropDownList(); } // Setup screen rules for updating only if (InvoiceK > 0) { DisableForPreviouslySaved(); // Only allow invoice refund for invoices that were paid immediately by credit card and have not been credited if (this.InvoiceTransferDataHolderList.Count == 1 && CurrentInvoice.IsImmediateCreditCardPayment == true && InvoiceCreditDataHolderList.Count == 0 && InvoiceTransferDataHolderList[0].Method.Equals(Transfer.Methods.Card) && InvoiceTransferDataHolderList[0].Status.Equals(Transfer.StatusEnum.Success) && Math.Round(InvoiceTransferDataHolderList[0].Amount, 2) == Math.Round(CurrentInvoice.Total, 2)) { this.RefundInvoiceButton.Enabled = true; this.RefundInvoiceButton.Attributes.Clear(); this.RefundInvoiceButton.Attributes.Add("onclick", "javascript:return confirm('This will create a credit and refund the transfer via SecPay. Are you sure you want to refund this Invoice?')"); } } ShowHideControls(InvoiceK > 0); EnableSalesUsrAndAmount(); SetAddTransfersOptions(); SetPromoterAvailableFunds(); }
protected void SaveButton_Click(object sender, EventArgs e) { Page.Validate(""); if (Page.IsValid) { if (this.OverrideTaxDateCheckBox.Checked == true && !this.TaxDateCal.ValidateNow()) { this.TaxDateCustomValidator.IsValid = false; return; } bool succeeded = false; bool previouslyPaid = CurrentCredit.Paid; LoadCreditFromScreen(); try { if (!Invoice.DoesDuplicateGuidExistInDb((Guid)this.ViewState["DuplicateGuid"]) || CurrentCredit.K > 0) { if (this.CreditItemDataHolderList.Count == 0) throw new Exception("Must have at least one credit item!"); bool newCredit = CurrentCredit.K == 0; //Invoice invoiceToCredit = new Invoice(Convert.ToInt32(InvoiceKValueLabel.Text)); if (CurrentCredit.K == 0 && CurrentInvoice.AmountAllowedToCredit < Math.Abs(CurrentCredit.Total)) throw new Exception("Cannot credit more than " + CurrentInvoice.AmountAllowedToCredit.ToString("c") + " for Invoice #" + CurrentInvoice.K.ToString()); CurrentCredit.Update(); foreach (InvoiceItemDataHolder creditItemDataHolder in this.CreditItemDataHolderList) { creditItemDataHolder.InvoiceK = CurrentCredit.K; creditItemDataHolder.UpdateInsertDelete(); } foreach (InvoiceTransferDataHolder creditTransferDataHolder in this.CreditTransferDataHolderList) { creditTransferDataHolder.InvoiceK = CurrentCredit.K; creditTransferDataHolder.UpdateInsertDelete(); } foreach (InvoiceTransferDataHolder creditTransferDataHolderDelete in this.CreditTransferDataHolderDeleteList) { bool toBeDeleted = true; foreach (InvoiceTransferDataHolder creditTransferDataHolder in this.CreditTransferDataHolderList) { // Do not delete ones that are confirmed to be saved. This resolves issues when saved items are marked for deletion, then added again. if (creditTransferDataHolder.TransferK == creditTransferDataHolderDelete.TransferK) { toBeDeleted = false; break; } } if (toBeDeleted == true) { creditTransferDataHolderDelete.State = DataHolderState.Deleted; creditTransferDataHolderDelete.UpdateInsertDelete(); } } CurrentInvoice.ApplyCreditToThisInvoice(CurrentCredit); if (newCredit) { // Refresh CurrentCredit CurrentCredit = new Invoice(CurrentCredit.K); CurrentCredit.AssignBuyerType(); CurrentCredit.UpdatePromoterStatusAndSalesStatus(); CurrentCredit.Update(); } succeeded = true; } // Do not process if duplicate exists. User probably tried refreshing the page. else { throw new Exception("Duplicate credit already exists in the database."); } } catch (Exception ex) { // Display error message this.ProcessingVal.ErrorMessage = ex.Message; this.ProcessingVal.IsValid = false; } // Having Server.Transfer or Response.Redirect caused an error during debugging. if (succeeded == true) { // Send email to promoter and to DSI accounts bool creditCreated = false; if (CreditK == 0) creditCreated = true; // Only send out emails when invoice is created or when Paid status changes if (creditCreated || previouslyPaid != CurrentCredit.Paid) Utilities.EmailInvoice(CurrentCredit, creditCreated); string response = "<script type=\"text/javascript\">alert('Credit #" + CurrentCredit.K.ToString() + " saved successfully'); open('" + CurrentCredit.UrlAdmin() + "?" + Cambro.Misc.Utility.GenRandomText(5) + "', '_self');</script>"; ViewState["DuplicateGuid"] = Guid.NewGuid(); Response.Write(response); Response.End(); } } }
/// <summary> /// Loads InvoiceItem grid, InvoiceTransfer grid, and InvoiceCredit grid /// </summary> private void InvoiceAndSubItemsBindData() { if(!this.IsPostBack) { if (InvoiceK > 0) { CurrentInvoice = new Invoice(InvoiceK); if(CurrentInvoice.Type.Equals(Invoice.Types.Credit)) Response.Redirect(CurrentInvoice.UrlAdmin()); } else CurrentInvoice = new Invoice(); } BindInvoiceItemGridView(); // Invoice Transfer GridView loading if (InvoiceTransferDataHolderList.Count == 0) { this.TransfersPanel.Visible = !CurrentInvoice.Paid; InvoiceTransferDataHolderList.Add(null); } InvoiceTransferGridView.DataSource = InvoiceTransferDataHolderList; InvoiceTransferGridView.DataBind(); if (InvoiceCreditDataHolderList.Count == 0) this.CreditsPanel.Visible = false; else { this.CreditsPanel.Visible = true; InvoiceCreditGridView.DataSource = InvoiceCreditDataHolderList; InvoiceCreditGridView.DataBind(); } if (InvoiceK > 0) { //this.InvoiceTransferGridView.Visible = this.InvoiceTransferDataHolderList.Count > 0; // hide the update / delete column this.InvoiceItemsGridView.Columns[InvoiceItemsGridView.Columns.Count - 1].Visible = false; // Hide the add new footer row this.InvoiceItemsGridView.FooterRow.Visible = false; } SetupAvailableTransfersDropDownList(); }
public static bool EmailInvoice(Invoice invoice, bool invoiceCreated) { string emailSubject = ""; if (Vars.DevEnv) emailSubject += "TEST - "; emailSubject += "DontStayIn "; if (invoice.IsImmediateCreditCardPayment) emailSubject += "WEB "; emailSubject += invoice.TypeToString + " #" + invoice.K.ToString() + ", " + Math.Abs(invoice.Total).ToString("c"); if (invoiceCreated == true) emailSubject += " created"; else emailSubject += " updated"; return EmailInvoice(invoice, emailSubject, invoiceCreated); }
/// <summary> /// Recalculate all VAT and Totals /// </summary> public void CalculateInvoiceItemVatAndTotals() { //double InvoiceVATRate = Invoice.VATRate((Invoice.VATCodes)Convert.ToInt32(this.VatCodeDropDownList.SelectedValue)); decimal invoicePrice = 0; decimal invoiceVAT = 0; decimal invoiceTotal = 0; decimal salesUsrAmount = 0; //double InvoiceItemVATRate = 0; foreach (InvoiceItemDataHolder iidh in InvoiceItemDataHolderList) { decimal total = iidh.Total; //InvoiceItemVATRate = InvoiceVATRate <= InvoiceItem.VATRate(iidh.VatCode) ? InvoiceVATRate : InvoiceItem.VATRate(iidh.VatCode); iidh.InvoiceVatCode = (Invoice.VATCodes)Convert.ToInt32(this.VatCodeDropDownList.SelectedValue); iidh.SetTotal(total); //iidh.Price = Math.Round(iidh.Price, 2); //if (iidh.K > 0) // iidh.Vat = Math.Round(iidh.Vat, 2); //else // iidh.Vat = Math.Round(iidh.Price * InvoiceItemVATRate, 2); //iidh.Total = Math.Round(iidh.Price + iidh.Vat, 2); invoicePrice += iidh.Price; invoiceVAT += iidh.Vat; invoiceTotal += iidh.Total; if(iidh.DoesApplyToSalesUsrAmount) salesUsrAmount += iidh.Price; } this.PriceTextBox.Text = invoicePrice.ToString("c"); this.VATTextBox.Text = invoiceVAT.ToString("c"); this.TotalTextBox.Text = invoiceTotal.ToString("c"); if (InvoiceK == 0) { this.SalesAmountTextBox.Text = salesUsrAmount.ToString("c"); } //this.InvoiceItemsGridView.DataSource = this.InvoiceItemDataHolderList; //this.InvoiceItemsGridView.DataBind(); decimal amountPaid = 0; DateTime lastTransferDate = DateTime.MinValue; foreach (InvoiceTransferDataHolder itdh in InvoiceTransferDataHolderList) { if (new Transfer(itdh.TransferK).Status.Equals(Transfer.StatusEnum.Success)) { amountPaid += itdh.Amount; DateTime invoiceTransferCompletedDate = new Transfer(itdh.TransferK).DateTimeComplete; if (lastTransferDate <= invoiceTransferCompletedDate) lastTransferDate = invoiceTransferCompletedDate; } } foreach (InvoiceCreditDataHolder icdh in InvoiceCreditDataHolderList) { // Credit amounts will be negative amountPaid -= icdh.Amount; if (icdh.CreditK != 0) { amountPaid += new Invoice(icdh.CreditK).AmountPaid; } if (lastTransferDate <= icdh.CreatedDateTime) lastTransferDate = icdh.CreatedDateTime; } if (!CurrentInvoice.PaidDateTime.Equals(DateTime.MinValue)) lastTransferDate = CurrentInvoice.PaidDateTime; if (Math.Round(invoiceTotal, 2) > Math.Round(amountPaid, 2) || lastTransferDate.Equals(DateTime.MinValue)) { this.PaidCheckBox.Checked = false; this.SetPaidImage(false); this.PaidDateLabel.Visible = false; } else if (Math.Round(invoiceTotal, 2) == Math.Round(amountPaid, 2)) { this.PaidCheckBox.Checked = true; this.SetPaidImage(true); this.PaidDateTextBox.Text = lastTransferDate.ToString("HH:mm dd/MM/yy"); this.PaidDateLabel.Visible = true; ProcessingVal.IsValid = true; } else { this.PaidCheckBox.Checked = true; this.SetPaidImage(true); this.PaidDateTextBox.Text = lastTransferDate.ToString("HH:mm dd/MM/yy"); this.PaidDateLabel.Visible = true; ProcessingVal.ErrorMessage = "Transfer totals (" + amountPaid.ToString("c") + ") are greater than the total invoice amount (" + invoiceTotal.ToString("c") + ")."; ProcessingVal.IsValid = false; } this.AmountDueTextBox.Text = ((double)(invoiceTotal - amountPaid)).ToString("c"); InvoiceAndSubItemsBindData(); }
public static void AddInvoicesToEmail(Mailer mailer, Invoice invoice) { List<Invoice> invoices = new List<Invoice>(); invoices.Add(invoice); AddInvoicesToEmail(mailer, invoices); }
/// <summary> /// Setups the screen screen controls for a new transfer for a saved invoice /// </summary> private void LoadScreenFromInvoice(Invoice invoice) { //this.uiPromoterAutoComplete.AutoPostBack = false; this.uiPromoterAutoComplete.ValueChanged -= new EventHandler(uiPromoterAutoComplete_ValueChanged); // Transaction Details this.TransferKValueLabel.Text = Utilities.LinkNewWindow(currentTransfer.UrlReport(), currentTransfer.K.ToString()); if (invoice.Promoter != null) { this.uiPromoterAutoComplete.Value = invoice.Promoter.K.ToString(); this.uiPromoterAutoComplete.Text = invoice.Promoter.Name; this.PromoterValueLabel.Text = invoice.Promoter.Link(); ViewState["PromoterK"] = invoice.Promoter.K; // Cant change the promoter for a transfer that will be tied to a specific invoice this.uiPromoterAutoComplete.Visible = false; this.PromoterValueLabel.Visible = true; SetupUserDropDownList(); if (this.UserDropDownList.Items.Count > 0) { this.uiUsersAutoComplete.Visible = false; this.uiUsersAutoComplete.Visible = true; } } if (invoice.Usr != null) { this.UserDropDownList.SelectedValue = invoice.Usr.K.ToString(); this.UserValueLabel.Text = invoice.Usr.Link(); } if (invoice.Type.Equals(Invoice.Types.Invoice)) { this.TypeDropDownList.SelectedValue = Convert.ToInt32(Transfer.TransferTypes.Payment).ToString(); this.TypeTextBox.Text = Transfer.TransferTypes.Payment.ToString(); this.BankTransferNumberTextBox.Text = "IN" + invoice.K.ToString(); } else { this.TypeDropDownList.SelectedValue = Convert.ToInt32(Transfer.TransferTypes.Refund).ToString(); this.TypeTextBox.Text = Transfer.TransferTypes.Refund.ToString(); this.BankTransferNumberTextBox.Text = "CR" + invoice.K.ToString(); } this.AmountTextBox.Text = invoice.AmountDue.ToString("c"); //this.uiPromoterAutoComplete.AutoPostBack = true; this.uiPromoterAutoComplete.ValueChanged += new EventHandler(uiPromoterAutoComplete_ValueChanged); }