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; } }
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; } } }
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; }
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 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; }
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; }
public void Refund(int remainingImpressions, int actionUsrK, int displayOrder) { if (this.Refunded) { throw new DsiUserFriendlyException("This banner has already been refunded."); } int refundCredits; if (this.PriceCreditsStored > 0 && this.TotalRequiredImpressions - remainingImpressions == 0) { refundCredits = this.PriceCreditsStored; } else { refundCredits = Banner.GetImpressionsValueInCampaignCredits(remainingImpressions, this.Position); } if (refundCredits > 0) { CampaignCredit cc = new CampaignCredit() { Credits = refundCredits, PromoterK = this.PromoterK, ActionDateTime = Time.Now, Description = string.Format("Refund for Banner: {0} (banner-{1})", this.Name, this.K), DisplayOrder = displayOrder, Enabled = true, BuyableObjectK = this.K, BuyableObjectType = Model.Entities.ObjectType.Banner }; Usr actionUsr; try { actionUsr = new Usr(actionUsrK); } catch { actionUsr = Usr.SystemUsr; } cc.SetUsrAndActionUsr(actionUsr); cc.UpdateWithRecalculateBalance(); this.RefundCampaignCreditK = cc.K; this.Refunded = true; this.RefundedCredits = refundCredits; this.Update(); } }