public void Donation_Click(object o, System.EventArgs e)
		{
            if (CurrentEvent.Donated)
                EventDonated();
            else
            {
                Usr.KickUserIfNotLoggedIn("You must be logged in to buy an event highlight!");
                
                Bobs.DataHolders.InvoiceDataHolder i = new Bobs.DataHolders.InvoiceDataHolder();
                Bobs.DataHolders.InvoiceItemDataHolder iidh = new Bobs.DataHolders.InvoiceItemDataHolder();

                CampaignCredit campaignCredit = new CampaignCredit()
                {
                    Description = "Event highlight " + CurrentEvent.K.ToString(),
                    BuyableObjectK = CurrentEvent.K,
                    BuyableObjectType = Model.Entities.ObjectType.Event,
                    Credits = -Vars.EventHighlightPriceCredits(CurrentEvent),
                    ActionDateTime = Time.Now,
                    PromoterK = CurrentPromoter.K,
                    InvoiceItemType = InvoiceItem.Types.EventDonate,
                    Enabled = false
                };
				campaignCredit.SetUsrAndActionUsr(Usr.Current);
                campaignCredit.Update();

                Payment.CampaignCredits.Clear();
                Payment.CampaignCredits.Add(campaignCredit);
                if (CurrentPromoter.K != 1)
                    Payment.PromoterK = CurrentPromoter.K;
                Payment.Initialize();

                ChoicePanel.Visible = false;
                PayPanel.Visible = true;
				
            }
		}
Esempio n. 2
0
		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;
				}
			}
		}
Esempio n. 3
0
		public List<CampaignCredit> ToCampaignCredits(Usr usr, int promoterK, bool saveToDatabase)
		{
			List<CampaignCredit> campaignCredits = new List<CampaignCredit>();
			CampaignCredit eventHighlightCampaignCredit = new CampaignCredit()
			{
				Description = "Event highlight " + this.K.ToString(),
				BuyableObjectK = this.K,
				BuyableObjectType = Model.Entities.ObjectType.Event,
				Credits = -Vars.EventHighlightPriceCredits(this),
				ActionDateTime = Time.Now,
				PromoterK = promoterK,
				InvoiceItemType = InvoiceItem.Types.EventDonate,
				Enabled = false,
				FixedDiscount = this.FixedDiscount,
				IsPriceFixed = this.IsPriceFixed
			};
			eventHighlightCampaignCredit.SetUsrAndActionUsr(usr);
			if (saveToDatabase)
				eventHighlightCampaignCredit.Update();
			campaignCredits.Add(eventHighlightCampaignCredit);

			return campaignCredits;
		}
Esempio n. 4
0
		public List<CampaignCredit> ToCampaignCredits(Usr usr, int promoterK, bool saveToDatabase)
		{
			List<CampaignCredit> campaignCredits = new List<CampaignCredit>();
			CampaignCredit bannerCampaignCredit = new CampaignCredit()
			{
				Description = this.Name + " - " + this.Position + " @ " + this.TotalRequiredImpressions.ToString("N0") + " impressions",
				BuyableObjectK = this.K,
				BuyableObjectType = Model.Entities.ObjectType.Banner,
				Credits = -this.PriceCredits,
				ActionDateTime = Time.Now,
				PromoterK = this.PromoterK,
				InvoiceItemType = Banner.GetInvoiceItemType(this.Position),
                Enabled = false,
				FixedDiscount = this.FixedDiscount,
				IsPriceFixed = this.IsPriceFixed
			};
			bannerCampaignCredit.SetUsrAndActionUsr(usr);
			if(saveToDatabase)
			bannerCampaignCredit.Update();
			campaignCredits.Add(bannerCampaignCredit);

			if (this.DesignType.Equals(Banner.DesignTypes.Jpg) || this.DesignType.Equals(Banner.DesignTypes.Gif) || this.DesignType.Equals(Banner.DesignTypes.Flash))
			{
				CampaignCredit bannerDesignCampaignCredit = new CampaignCredit()
				{
					Description = DesignToString(true),
					BuyableObjectK = this.K,
					BuyableObjectType = Model.Entities.ObjectType.Banner,
					Credits = -Vars.BannerDesignPriceCredits(this.DesignType),
					ActionDateTime = Time.Now,
					PromoterK = this.PromoterK,
					InvoiceItemType = Banner.GetInvoiceItemType(this.DesignType),
                    Enabled = false,
					FixedDiscount = this.FixedDiscount,
					IsPriceFixed = this.IsPriceFixed
				};
				bannerDesignCampaignCredit.SetUsrAndActionUsr(usr);
				if (saveToDatabase)
				bannerDesignCampaignCredit.Update();
				campaignCredits.Add(bannerDesignCampaignCredit);
			}

			return campaignCredits;
		}