Exemple #1
0
		private void Page_Load(object sender, System.EventArgs e)
		{
			Usr.KickUserIfNotLoggedIn();
			ContainerPage.SslPage = true;

			if (!Page.IsPostBack)
			{
				DonateLoggedOut.Visible = Usr.Current == null;
				DonateLoggedIn.Visible = Usr.Current != null;

				if (Usr.Current != null)
				{
					UsrDonationIcon udi = new UsrDonationIcon
					{
						DonationIconK = DonationIcon.K,
						UsrK = Usr.Current.K,
						BuyableLockDateTime = DateTime.Now,
						Enabled = false
					};
					udi.Update();

					InvoiceDataHolder i = new InvoiceDataHolder();
					InvoiceItemDataHolder iidh = new InvoiceItemDataHolder();
					if (DonationIcon.Vatable.Value)
						iidh.VatCode = InvoiceItem.VATCodes.T1;
					else
						iidh.VatCode = InvoiceItem.VATCodes.T9;

					if (DonationIcon.Charity)
					{
						iidh.Type = InvoiceItem.Types.CharityDonation;
						iidh.Description = "Charity donation";
						iidh.ShortDescription = "Charity donation";
					}
					else
					{
						iidh.Type = InvoiceItem.Types.UsrDonate;
						iidh.Description = "Profile icon";
						iidh.ShortDescription = "Profile icon";
					}

					iidh.SetTotal(DonationIcon.Price);
					iidh.KeyData = Usr.Current.K;
					iidh.BuyableObjectK = udi.K;
					iidh.BuyableObjectType = Model.Entities.ObjectType.UsrDonationIcon;
					iidh.RevenueStartDate = DateTime.Today;
					iidh.RevenueEndDate = DateTime.Today;
					i.InvoiceItemDataHolderList.Add(iidh);
					i.Type = Invoice.Types.Invoice;
					i.UsrK = Usr.Current.K;

					Payment.Invoices.Clear();
					Payment.Invoices.Add(i);
					Payment.PromoterK = 0;
					Payment.Initialize();
				}
			}
		}
		private void ProcessInvoiceTotals()
		{
			invoiceTotalDone = true;

			invoiceTotal = 0.0m;
			invoiceTotalAsCampaignCredits = 0;
			decimal totalMoneyForFixedDiscountCampaignCredits = 0;
			int totalNumberOfFixedDiscountCampaignCredits = 0;

			if (CampaignCredits.Count > 0)
			{
				string invoiceItemDescription = "";

				paymentTypeIsCampaignCredits = true;
				bool fixedDiscountUsed = false;
				foreach (CampaignCredit cc in CampaignCredits)
				{
					if (cc.BuyableObject != null && cc.BuyableObject is IBuyableCredits)
					{
						// We need to regenerate campaign credits from saved buyable object to verify any price changes.
						List<CampaignCredit> generatedCampaignCredits = ((IBuyableCredits)cc.BuyableObject).ToCampaignCredits(Usr.Current, CurrentPromoter.K, false);
						foreach (CampaignCredit genCC in generatedCampaignCredits)
						{
							if (genCC.InvoiceItemType == cc.InvoiceItemType)
							{
								cc.Credits = genCC.Credits;
								cc.IsPriceFixed = genCC.IsPriceFixed;
								cc.FixedDiscount = genCC.FixedDiscount;
								cc.Description = genCC.Description;
								cc.Update();
								break;
							}
						}

						invoiceItemDescription += cc.Description + " | ";
					}
					// campaign credits come in negative
					invoiceTotalAsCampaignCredits += (-cc.Credits);
					if (cc.IsPriceFixed)
					{
						fixedDiscountUsed = true;
						totalMoneyForFixedDiscountCampaignCredits += CampaignCredit.CalculateTotalCostForCredits(-cc.Credits, cc.FixedDiscount, cc.Promoter);
						totalNumberOfFixedDiscountCampaignCredits += -cc.Credits;
					}
				}

				if (invoiceItemDescription.Length > 2)
					invoiceItemDescription = invoiceItemDescription.Substring(0, invoiceItemDescription.Length - 3);

				AllowPayWithCampaignCredits = !fixedDiscountUsed;
				this.PayOptionRadioButtonPayWithCampaignCredit.Enabled = AllowPayWithCampaignCredits;

				if (!fixedDiscountUsed)
				{
					invoiceTotalAsCampaignCredits -= CampaignCreditsApplied;
				}
				double nonFixedCampaignCreditDiscount = CampaignCredit.GetDiscountForCredits(invoiceTotalAsCampaignCredits, CurrentPromoter);
				totalCampaignCreditsAsMoney = Math.Round(CampaignCredit.CalculateTotalCostForCredits(invoiceTotalAsCampaignCredits - totalNumberOfFixedDiscountCampaignCredits, nonFixedCampaignCreditDiscount, CurrentPromoter) + totalMoneyForFixedDiscountCampaignCredits, 2);


				// then we actually want to make the equivalent money cost to be the cost of the total credits
				// including bulk discount
				
				totalVatOnCampaignCreditsAsMoney = Math.Round(((decimal)Invoice.VATRate(Invoice.VATCodes.T1, DateTime.Now)) * totalCampaignCreditsAsMoney, 2);
				invoiceTotal = Math.Round(totalCampaignCreditsAsMoney + totalVatOnCampaignCreditsAsMoney, 2);
                //ViewState["InvoiceTotal"] = invoiceTotal;

				// avoid adding this invoice item multiple times
                if (Invoices.Count == 0)
                {
					SetInvoiceTotalAsCampaignCreditsDiscount(fixedDiscountUsed);
                    // Generate Positive Campaign Credit to balance account and an invoice to pay for it
                    CampaignCredit campaignCredit = new CampaignCredit()
                    {
                        Credits = invoiceTotalAsCampaignCredits,
                        ActionDateTime = DateTime.Now,
                        BuyableLockDateTime = DateTime.Now,
                        BuyableObjectType = Model.Entities.ObjectType.Invoice,
                        Description = invoiceTotalAsCampaignCredits.ToString() + " credits",
                        Enabled = false,
                        PromoterK = CurrentPromoter.K,
                        InvoiceItemType = InvoiceItem.Types.CampaignCredits,
                        DisplayOrder = 0
                    };
					if(invoiceItemDescription.Length > 0)
						campaignCredit.Description += " [" + invoiceItemDescription + "]";

					if (fixedDiscountUsed)
						campaignCredit.FixedDiscount = invoiceTotalAsCampaignCreditsDiscount;
					campaignCredit.SetUsrAndActionUsr(Usr.Current, false);
                    campaignCredit.Update();
                    InvoiceDataHolder idh = new InvoiceDataHolder()
                    {
                        ActionUsrK = Usr.Current.K,
                        CreatedDateTime = DateTime.Now,
                        DueDateTime = DateTime.Now,
                        Paid = false,
                        PromoterK = CurrentPromoter.K,
                        Type = Invoice.Types.Invoice,
                        VatCode = Invoice.VATCodes.T1
                    };
                    InvoiceItemDataHolder iidh = new InvoiceItemDataHolder()
                    {
                        BuyableObjectK = campaignCredit.K,
                        BuyableObjectType = Model.Entities.ObjectType.CampaignCredit,
                        Description = campaignCredit.Credits.ToString() + " credits",
                        PriceBeforeDiscount = campaignCredit.Credits * CurrentPromoter.CostPerCampaignCredit,
                        RevenueStartDate = DateTime.Today,
                        RevenueEndDate = DateTime.Today,
                        ShortDescription = campaignCredit.Credits.ToString() + " credits",
                        State = DataHolderState.Added,
                        Type = InvoiceItem.Types.CampaignCredits,
                        VatCode = InvoiceItem.VATCodes.T1
                    };
					if (invoiceItemDescription.Length > 0)
						iidh.Description += " [" + invoiceItemDescription + "]";
					
                    iidh.Discount = invoiceTotalAsCampaignCreditsDiscount;

                    idh.InvoiceItemDataHolderList.Add(iidh);
                    this.Invoices.Add(idh);
                }

                else if(Invoices.Count == 1 && Invoices[0].InvoiceItemDataHolderList.Count > 0)
                {
                    if (Invoices[0].InvoiceItemDataHolderList[0].BuyableObjectType == Model.Entities.ObjectType.CampaignCredit && Invoices[0].InvoiceItemDataHolderList[0].BuyableObjectK > 0)
                    {
						SetInvoiceTotalAsCampaignCreditsDiscount(fixedDiscountUsed);

                        CampaignCredit campaignCredit = new CampaignCredit(Invoices[0].InvoiceItemDataHolderList[0].BuyableObjectK);
                        campaignCredit.Credits = invoiceTotalAsCampaignCredits;
                        campaignCredit.ActionDateTime = DateTime.Now;
                        campaignCredit.BuyableLockDateTime = DateTime.Now;
                        campaignCredit.Description = invoiceTotalAsCampaignCredits.ToString() + " credits";
						campaignCredit.FixedDiscount = invoiceTotalAsCampaignCreditsDiscount;
						campaignCredit.IsPriceFixed = true;
						Invoices[0].InvoiceItemDataHolderList[0].Description = campaignCredit.Description;
                        Invoices[0].InvoiceItemDataHolderList[0].ShortDescription = campaignCredit.Description;
						Invoices[0].InvoiceItemDataHolderList[0].PriceBeforeDiscount = campaignCredit.Credits * CurrentPromoter.CostPerCampaignCredit;
                        Invoices[0].InvoiceItemDataHolderList[0].Discount = invoiceTotalAsCampaignCreditsDiscount;

						if (invoiceItemDescription.Length > 0)
						{
							campaignCredit.Description += " [" + invoiceItemDescription + "]";
							Invoices[0].InvoiceItemDataHolderList[0].Description += " [" + invoiceItemDescription + "]";
						}

						campaignCredit.SetUsrAndActionUsr(Usr.Current, false);
                        campaignCredit.Update();
                    }
                }
			}
			else
			{
				paymentTypeIsCampaignCredits = false;

				foreach (InvoiceDataHolder idh in Invoices)
				{
					invoiceTotal += idh.AmountDue;
				}
			}
		}
		private void SetUsrAndActionUsr(InvoiceDataHolder idh)
		{
			// for new invoices
			if (idh.K == 0)
			{
				idh.Promoter = CurrentPromoter;
				idh.SetUsrAndActionUsr(CurrentUsr, false);
			}
		}
		private void SetInvoiceDatesUsrsGuid(InvoiceDataHolder idh)
		{
			if (idh.CreatedDateTime == DateTime.MinValue)
				idh.CreatedDateTime = DateTime.Now;
			if (idh.TaxDateTime == DateTime.MinValue)
				idh.TaxDateTime = idh.CreatedDateTime;
			if (idh.DueDateTime == DateTime.MinValue)
				idh.DueDateTime = idh.TaxDateTime.AddDays(InvoiceDueDays);
			SetUsrAndActionUsr(idh);
			idh.DuplicateGuid = (Guid)ViewState["DuplicateGuidInvoice"];
		}
		public void Buy_Click(object o, System.EventArgs e)
		{
			EnsureSecure();
			if (Page.IsValid)
			{
				GuestlistCredit gc = new GuestlistCredit();
				gc.DateTimeCreated = DateTime.Now;
				gc.Credits = int.Parse(BuyCredits.Text);
				gc.PromoterK = CurrentPromoter.K;
				gc.TotalPrice = CurrentPromoter.GuestlistCharge * int.Parse(BuyCredits.Text);
				gc.Done = false;
				gc.Update();

				ChangePanel(PanelPay);

				this.ViewState["GuestlistCreditK"] = gc.K;

				InvoiceDataHolder i = new InvoiceDataHolder();
				InvoiceItemDataHolder iidh = new InvoiceItemDataHolder();
				iidh.VatCode = InvoiceItem.VATCodes.T1;
				iidh.PriceBeforeDiscount = gc.TotalPrice;
				iidh.Type = InvoiceItem.Types.GuestlistCredit;
				iidh.KeyData = gc.K;
				iidh.BuyableObjectK = gc.K;
				iidh.BuyableObjectType = Model.Entities.ObjectType.GuestlistCredit;
				iidh.RevenueStartDate = DateTime.Today;
				iidh.RevenueEndDate = DateTime.Today;
				iidh.Description = gc.Credits.ToString("#,###") + " guestlist credits";
				i.InvoiceItemDataHolderList.Add(iidh);
				
				i.PromoterK = CurrentPromoter.K;
				i.UsrK = Usr.Current.K;
				i.VatCode = Invoice.VATCodes.T1;
				
				Payment.Invoices.Clear();
				Payment.Invoices.Add(i);
				Payment.PromoterK = CurrentPromoter.K;
				Payment.Initialize();
				ContainerPage.SslPage = true;

				//Response.Redirect("https://www.paypal.com/xclick/business=paypal%40dontstayin.com&item_name=Payment+for+"+int.Parse(BuyCredits.Text).ToString()+"+guestlist+credits+code+guestlist-"+gc.K.ToString()+"&amount="+gc.TotalPrice.ToString("0.00")+"&no_note=1&currency_code=GBP");
			}
		}
		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();
		}
Exemple #7
0
		public static void Refund(Usr actionUsr, List<Ticket> tickets, bool refundIncludeBookingFee, decimal chargeToPromoter)
        {
            try
            {
                if (tickets.Count > 0 && actionUsr.IsSuperAdmin)
                {
                    chargeToPromoter = Math.Abs(chargeToPromoter);

                    List<int> ticketRunKs = new List<int>();

                    int promoterK = tickets[0].TicketRun.PromoterK;
                    int eventK = tickets[0].TicketRun.EventK;
                    foreach (Ticket ticket in tickets)
                    {
                        if (promoterK != ticket.TicketRun.PromoterK)
                            throw new Exception("Cannot automate refund for tickets belonging to more than 1 promoter.");
                        if (eventK != ticket.TicketRun.EventK)
                            throw new Exception("Cannot automate refund for tickets belonging to more than 1 event.");
                    }
                    TicketPromoterEvent ticketPromoterEvent = new TicketPromoterEvent(promoterK, eventK);

                    bool chargePromoterTicketPrice = ticketPromoterEvent.FundsReleased && ticketPromoterEvent.FundsTransfer != null && ticketPromoterEvent.FundsTransfer.Status == Transfer.StatusEnum.Success;
					bool areFundsAlreadyReleased = chargePromoterTicketPrice;
					decimal sumTicketPrice = 0;

                    string failedTicketKs = "";
                    List<Exception> failedRefundExceptions = new List<Exception>();
                    int successfulRefundTransferCount = 0;
                    int successfulRefundQuantity = 0;

                    foreach (Ticket ticket in tickets)
                    {
                        try
                        {
							RefundTicket(actionUsr, ticket, refundIncludeBookingFee, areFundsAlreadyReleased);

                            if (ticket.Cancelled)
                            {
                                if (!ticketRunKs.Contains(ticket.TicketRunK))
                                    ticketRunKs.Add(ticket.TicketRunK);

                                successfulRefundTransferCount++;
                                successfulRefundQuantity += ticket.Quantity;

                                if (chargePromoterTicketPrice)
                                    sumTicketPrice += ticket.Price;
                            }
                        }
                        catch (Exception ex)
                        {
                            failedRefundExceptions.Add(ex);
                            failedTicketKs += ticket.K.ToString() + ", ";
                        }
                    }

                    if (successfulRefundTransferCount > 0 && (chargePromoterTicketPrice || chargeToPromoter > 0))
                    {
                        // create invoice with tickets.count * chargeToPromoter invoice item for refund.
                        DateTime now = DateTime.Now;

                        InvoiceDataHolder refundChargeInvoiceDH = new InvoiceDataHolder();
                        refundChargeInvoiceDH.ActionUsrK = Usr.Current.K;
                        refundChargeInvoiceDH.CreatedDateTime = now;
                        refundChargeInvoiceDH.DueDateTime = now.AddDays(tickets[0].TicketRun.Promoter.InvoiceDueDaysEffective > Vars.InvoiceDueDaysDefault ? tickets[0].TicketRun.Promoter.InvoiceDueDaysEffective : Vars.InvoiceDueDaysDefault);
                        refundChargeInvoiceDH.DuplicateGuid = Guid.NewGuid();
                        refundChargeInvoiceDH.PromoterK = tickets[0].TicketRun.PromoterK;
                        refundChargeInvoiceDH.TaxDateTime = now;
                        refundChargeInvoiceDH.Type = Invoice.Types.Invoice;
                        if (tickets[0].TicketRun.Promoter.PrimaryUsrK != 0)
                            refundChargeInvoiceDH.UsrK = tickets[0].TicketRun.Promoter.PrimaryUsrK;
                        else
                            refundChargeInvoiceDH.UsrK = Usr.Current.K;
                        refundChargeInvoiceDH.VatCode = Invoice.VATCodes.T1;

                        if (chargePromoterTicketPrice)
                        {
                            InvoiceItemDataHolder iidhPrice = new InvoiceItemDataHolder();
                            iidhPrice.RevenueStartDate = now;
                            iidhPrice.RevenueEndDate = now;
                            iidhPrice.Description = "Ticket price refund charge for " + successfulRefundQuantity.ToString() + " ticket" + (successfulRefundQuantity > 1 ? "s" : "");
                            iidhPrice.ShortDescription = "Ticket price refund charge";
                            iidhPrice.Type = InvoiceItem.Types.Misc;
                            iidhPrice.VatCode = InvoiceItem.VATCodes.T9;
                            iidhPrice.SetTotal(Math.Round(sumTicketPrice, 2));

                            refundChargeInvoiceDH.InvoiceItemDataHolderList.Add(iidhPrice);
                        }

                        InvoiceItemDataHolder iidh = new InvoiceItemDataHolder();
                        iidh.RevenueStartDate = now;
                        iidh.RevenueEndDate = now;
                        iidh.Description = "Ticket refund charge for " + successfulRefundTransferCount.ToString() + " ticket" + (successfulRefundTransferCount > 1 ? "s" : "") + " transfers";
                        iidh.ShortDescription = "Ticket refund charge";
                        iidh.Type = InvoiceItem.Types.Misc;
                        iidh.VatCode = InvoiceItem.VATCodes.T1;
                        iidh.SetTotal(Math.Round(successfulRefundTransferCount * chargeToPromoter, 2));

                        refundChargeInvoiceDH.InvoiceItemDataHolderList.Add(iidh);

                        Invoice refundChargeInovice = refundChargeInvoiceDH.UpdateInsertDelete();

                        foreach (int ticketRunK in ticketRunKs)
                        {
                            new TicketRun(ticketRunK).CalculateSoldTicketsAndUpdate();
                        }

                        refundChargeInovice.UpdateAndAutoApplySuccessfulTransfersWithAvailableMoney();

                        Utilities.EmailInvoice(refundChargeInovice, true);

						if (areFundsAlreadyReleased)
							ticketPromoterEvent.CalculateTotalFundsAndVat();
                    }

                    failedTicketKs = failedTicketKs.Trim();

                    if (failedTicketKs.Length > 0)
                    {
                        string exceptionMessages = "";
                        foreach (Exception ex in failedRefundExceptions)
                            exceptionMessages += ex.Message + "\n\n";

                        failedTicketKs = failedTicketKs.Substring(0, failedTicketKs.Length - 1);

                        throw new Exception("Failed to refund the following tickets #" + failedTicketKs + ". Exception messages: " + exceptionMessages);
                    }
                }
            }
            catch (Exception ex)
            {
				Utilities.AdminEmailAlert("Exception in Ticket.Refund(List<Ticket> tickets)", "Exception in Ticket.Refund(List<Ticket> tickets)", ex, tickets.ConvertAll(ticket => (IBobAsHTML)ticket));
                throw ex;
            }
        }
Exemple #8
0
		public CampaignCredit PurchaseCampaignCreditsWithRemainingFunds(Usr actionUsr, double discountForCredits)
		{
			decimal total = this.AmountRemaining();
			if (actionUsr.IsAdmin && total > 0)
			{
				DateTime now = Time.Now;

				InvoiceDataHolder idh = new InvoiceDataHolder()
				{
					CreatedDateTime = now,
					DueDateTime = now,
					DuplicateGuid = new Guid(),
					PromoterK = this.PromoterK,
					SalesUsrK = this.Promoter.SalesUsrK,
					TaxDateTime = now,
					Type = Invoice.Types.Invoice,
					VatCode = Invoice.VATCodes.T1
				};
				InvoiceItemDataHolder iidh = new InvoiceItemDataHolder()
				{
					//BuyableObjectK = campaingCredit.K,
					BuyableObjectType = Model.Entities.ObjectType.CampaignCredit,
					//Description = campaingCredit.Description,
					Discount = discountForCredits,
					RevenueStartDate = now,
					RevenueEndDate = now,
					//ShortDescription = campaingCredit.Description,
					Type = InvoiceItem.Types.CampaignCredits,
					VatCode = InvoiceItem.VATCodes.T1
				};
				iidh.SetTotal(total);
				int credits = CampaignCredit.CalculateTotalCreditsForMoney(iidh.Price, discountForCredits, this.Promoter);
				if (credits > 0)
				{
					iidh.Discount = 1 - (double)Math.Round(iidh.Price / credits, 4);
					iidh.SetTotal(total);
					string description = credits.ToString() + " credits";
					iidh.Description = description;
					iidh.ShortDescription = description;
					idh.InvoiceItemDataHolderList.Add(iidh);
					Invoice invoice = idh.UpdateInsertDelete();
					invoice.SetUsrAndActionUsr(actionUsr);
					invoice.AssignSalesUsrAndAmount();
					invoice.ApplyTransfersToThisInvoice(this);
					invoice.UpdateAndSetPaidStatus();

					CampaignCredit campaingCredit = new CampaignCredit()
					{
						ActionDateTime = now,
						ActionUsrK = actionUsr.K,
						BuyableObjectK = invoice.K,
						BuyableObjectType = Model.Entities.ObjectType.Invoice,
						Credits = credits,
						Description = description,
						DisplayOrder = 0,
						Enabled = true,
						FixedDiscount = iidh.Discount,
						InvoiceItemType = InvoiceItem.Types.CampaignCredits,
						IsPriceFixed = true,
						PromoterK = this.PromoterK
					};
					campaingCredit.SetUsrAndActionUsr(actionUsr);
					campaingCredit.UpdateWithRecalculateBalance();

					invoice.Items[0].BuyableObjectK = campaingCredit.K;
					invoice.Items[0].Update();

					return campaingCredit;
				}
				else
					return null;
			}
			else
				return null;
		}
Exemple #9
0
		private void LoadTicketsToPaymentControl()
		{	

			Payment.Reset();

			if (Usr.Current == null)
				throw new DsiUserFriendlyException("You must be logged in to purchase tickets.");

			InvoiceDataHolder idh = new InvoiceDataHolder();
			idh.ActionUsrK = Usr.Current.K;
			idh.CreatedDateTime = DateTime.Now;
			idh.DuplicateGuid = (Guid)ViewState["DuplicateGuid"];
			idh.PromoterK = 0;
			idh.Type = Invoice.Types.Invoice;
			idh.VatCode = Invoice.VATCodes.T1;
			DateTime now = DateTime.Now;

			foreach (Ticket ticket in TicketsToPurchase)
			{
				InvoiceItemDataHolder iidhTicket = new InvoiceItemDataHolder();
				InvoiceItemDataHolder iidhBookingFee = new InvoiceItemDataHolder();

				if (ticket.TicketRun.Promoter.VatStatus == Promoter.VatStatusEnum.Registered)
					iidhTicket.VatCode = InvoiceItem.VATCodes.T1;
				else
					iidhTicket.VatCode = InvoiceItem.VATCodes.T0;
				iidhTicket.SetTotal(ticket.Price);
				iidhTicket.Type = InvoiceItem.Types.EventTickets;
				iidhTicket.KeyData = ticket.K;
				iidhTicket.BuyableObjectK = ticket.K;
				iidhTicket.BuyableObjectType = Model.Entities.ObjectType.Ticket;
				iidhTicket.RevenueStartDate = now;
				iidhTicket.RevenueEndDate = now;
				iidhTicket.Description = ticket.Description;
				iidhTicket.ShortDescription = ticket.ShortDescription;

				iidhBookingFee.VatCode = InvoiceItem.VATCodes.T1;
				iidhBookingFee.SetTotal(ticket.BookingFee);
				iidhBookingFee.Type = InvoiceItem.Types.EventTicketsBookingFee;
				iidhBookingFee.KeyData = ticket.K;
				iidhBookingFee.BuyableObjectK = ticket.K;
				iidhBookingFee.BuyableObjectType = Model.Entities.ObjectType.Ticket;
				iidhBookingFee.RevenueStartDate = now;
				iidhBookingFee.RevenueEndDate = now;
				iidhBookingFee.Description = "Booking fee";
				iidhBookingFee.ShortDescription = "Booking fee";

				idh.InvoiceItemDataHolderList.Add(iidhTicket);
				idh.InvoiceItemDataHolderList.Add(iidhBookingFee);
			}

			//how many visits has this user had?
			Query qVisits = new Query();
			qVisits.QueryCondition = new Q(Visit.Columns.UsrK, Usr.Current.K);
			qVisits.ReturnCountOnly = true;
			VisitSet vsCount = new VisitSet(qVisits);

			if (vsCount.Count <= 20)
				Payment.FraudCheck = Transfer.FraudCheckEnum.Strict;

			Payment.Invoices.Add(idh);
			Payment.PromoterK = 0;
			Payment.AllowPayWithBalance = false;
			Payment.ShowItemsIncVat = true;
			Payment.UsrK = Usr.Current.K;
			Payment.Initialize();
			Payment.LoadBuyerDetailsToScreen();

			//this.TicketsPanel.Visible = false;
			//this.PayForTicketsPanel.Visible = true;
		}
		private void LoadPaymentControl()
		{
			int credits = int.Parse(SelectedCredits.Value);

			Payment.Reset();
			if (CurrentCampaignCredit == null)
			{
				CampaignCredit cc = new CampaignCredit()
				{
					Credits = credits,
					Enabled = false,
					ActionDateTime = Time.Now,
					PromoterK = CurrentPromoter.K,
					Description = credits.ToString() + " credits",
					DisplayOrder = 0,
					BuyableObjectType = Model.Entities.ObjectType.Invoice
				};
				cc.SetUsrAndActionUsr(Usr.Current);
				cc.UpdateWithRecalculateBalance();
				CurrentCampaignCredit = cc;
			}
			if (CurrentCampaignCredit.Credits != credits)
			{
				CurrentCampaignCredit.Credits = credits;
				CurrentCampaignCredit.UpdateWithRecalculateBalance();
			}

			InvoiceDataHolder idh = new InvoiceDataHolder()
			{
				CreatedDateTime = Time.Now,
				PromoterK = CurrentPromoter.K,
                VatCode = Invoice.VATCodes.T1,
                ActionUsrK = Usr.Current.K,
                Type = Invoice.Types.Invoice,
                UsrK = Usr.Current.K
			};

			InvoiceItemDataHolder iidh = new InvoiceItemDataHolder()
			{
				Description = credits + " credits",
				ShortDescription = credits + " credits",
				BuyableObjectK = CurrentCampaignCredit.K,
				BuyableObjectType = Model.Entities.ObjectType.CampaignCredit,
                VatCode = InvoiceItem.VATCodes.T1,
                Type = InvoiceItem.Types.CampaignCredits,
                RevenueStartDate = Time.Now,
                RevenueEndDate = Time.Now
			};

			iidh.PriceBeforeDiscount = (credits * CurrentPromoter.CostPerCampaignCredit);
			if (CurrentCampaignCredit.IsPriceFixed)
				iidh.Discount = CurrentCampaignCredit.FixedDiscount;
			else
				iidh.Discount = CampaignCredit.GetDiscountForCredits(credits, CurrentPromoter);
			
			idh.InvoiceItemDataHolderList.Add(iidh);
            
			idh.DuplicateGuid = DuplicateGuid;
			Payment.Invoices.Add(idh);

			Payment.PromoterK = CurrentPromoter.K;

			Payment.Initialize();

			CreditsPanel.Visible = false;
			PaymentPanel.Visible = true;
			SuccessPanel.Visible = false;
		}
        public void LoadTicketsToPaymentControl(TicketSet ticketsToPurchase)
        {
            Payment.Reset();

            if (Usr.Current == null)
                throw new DsiUserFriendlyException("You must be logged in to purchase tickets.");

			if (!Usr.Current.IsEmailVerified || Usr.Current.IsEmailBroken)
				HttpContext.Current.Response.Redirect("/pages/emailverify?url=" + HttpContext.Current.Server.UrlEncode(HttpContext.Current.Request.Url.ToString()) + "&er=" + HttpContext.Current.Server.UrlEncode("You need to verify your email to buy tickets"));

            InvoiceDataHolder idh = new InvoiceDataHolder();
            idh.ActionUsrK = Usr.Current.K;
            idh.CreatedDateTime = DateTime.Now;
            idh.DuplicateGuid = (Guid)ViewState["DuplicateGuid"];
            idh.PromoterK = 0;
			idh.Type = Invoice.Types.Invoice;
            idh.VatCode = Invoice.VATCodes.T1;
            DateTime now = DateTime.Now;
			bool requiresDeliveryAddress = false;
            foreach (Ticket ticket in ticketsToPurchase)
            {
                InvoiceItemDataHolder ticketInvoiceItem = new InvoiceItemDataHolder();
                InvoiceItemDataHolder bookingFeeInvoiceItem = new InvoiceItemDataHolder();

                if (ticket.TicketRun.Promoter.VatStatus == Promoter.VatStatusEnum.Registered)
                    ticketInvoiceItem.VatCode = InvoiceItem.VATCodes.T1;
                else
                    ticketInvoiceItem.VatCode = InvoiceItem.VATCodes.T0;
                ticketInvoiceItem.SetTotal(ticket.Price);
                ticketInvoiceItem.Type = InvoiceItem.Types.EventTickets;
                ticketInvoiceItem.KeyData = ticket.K;
                ticketInvoiceItem.BuyableObjectK = ticket.K;
                ticketInvoiceItem.BuyableObjectType = Model.Entities.ObjectType.Ticket;
                ticketInvoiceItem.RevenueStartDate = now;
                ticketInvoiceItem.RevenueEndDate = now;
                ticketInvoiceItem.Description = ticket.Description;
                ticketInvoiceItem.ShortDescription = ticket.ShortDescription;

                bookingFeeInvoiceItem.VatCode = InvoiceItem.VATCodes.T1;
                bookingFeeInvoiceItem.SetTotal(ticket.BookingFee);
                bookingFeeInvoiceItem.Type = InvoiceItem.Types.EventTicketsBookingFee;
                bookingFeeInvoiceItem.KeyData = ticket.K;
                bookingFeeInvoiceItem.BuyableObjectK = ticket.K;
                bookingFeeInvoiceItem.BuyableObjectType = Model.Entities.ObjectType.Ticket;
                bookingFeeInvoiceItem.RevenueStartDate = now;
                bookingFeeInvoiceItem.RevenueEndDate = now;
                bookingFeeInvoiceItem.Description = "Booking fee";
                bookingFeeInvoiceItem.ShortDescription = "Booking fee";

                idh.InvoiceItemDataHolderList.Add(ticketInvoiceItem);
                idh.InvoiceItemDataHolderList.Add(bookingFeeInvoiceItem);
				if (ticket.TicketRun.DeliveryMethod == TicketRun.DeliveryMethodType.SpecialDelivery) 
				{ 
					requiresDeliveryAddress = true;
				}
            }
			if (requiresDeliveryAddress){
				TicketRun ticketRun = ticketsToPurchase[0].TicketRun;
				InvoiceItemDataHolder deliveryFeeInvoiceItem = new InvoiceItemDataHolder()
				{
					VatCode = InvoiceItem.VATCodes.T1,
					Type = InvoiceItem.Types.EventTicketsDelivery,
					Description = "Delivery by " + ticketRun.DeliveryMethod.ToString(),
					ShortDescription = "Delivery by " + ticketRun.DeliveryMethod.ToString(),
					RevenueStartDate = now,
					RevenueEndDate = now/*,
					BuyableObjectK = ticketsToPurchase[0].K,
					BuyableObjectType = Model.Entities.ObjectType.Ticket*/
				};
				deliveryFeeInvoiceItem.SetTotal(Convert.ToDecimal(ticketsToPurchase[0].TicketRun.DeliveryCharge));
				idh.InvoiceItemDataHolderList.Add(deliveryFeeInvoiceItem);

				Payment.GetFullAddress = true;
				Payment.LockCountryK(224);
				Payment.FraudCheck = Transfer.FraudCheckEnum.Strict;
			}
			

			//how many visits has this user had?
			Query qVisits = new Query();
			qVisits.QueryCondition = new Q(Visit.Columns.UsrK, Usr.Current.K);
			qVisits.ReturnCountOnly = true;
			VisitSet vsCount = new VisitSet(qVisits);

			if (vsCount.Count <= 20)
				Payment.FraudCheck = Transfer.FraudCheckEnum.Strict;
			 
			Payment.Invoices.Add(idh);
            Payment.PromoterK = 0;
            Payment.AllowPayWithBalance = false;
            Payment.ShowItemsIncVat = true;
            Payment.UsrK = Usr.Current.K;
            Payment.Initialize();
            Payment.LoadBuyerDetailsToScreen();

            //this.TicketsPanel.Visible = false;
            this.PayForTicketsPanel.Visible = true;
        }
Exemple #12
0
		public InvoiceDataHolder CreateCredit()
		{
			if (this.Type.Equals(Invoice.Types.Credit))
				throw new Exception("Cannot credit a credit.");

			InvoiceDataHolder credit = new InvoiceDataHolder();
			credit.PromoterK = this.PromoterK;
			credit.UsrK = this.UsrK;
			credit.VatCode = this.VatCode;
			credit.Type = Invoice.Types.Credit;
			credit.CreatedDateTime = Time.Now;

			credit.InvoiceItemDataHolderList = CreateCreditInvoiceItems();

			return credit;
		}