Example #1
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;
		}
		protected void uiRaiseButton_Click(object sender, EventArgs e)
		{
			Page.Validate("OnRaiseValidators");
			if (Page.IsValid)
			{
				
				
				
				
				InsertionOrder duplicate = InsertionOrderWithMatchingDuplicateGuid;
				if (duplicate != null)
				{
					Response.Redirect(ContainerPage.Url.CurrentUrl("K", duplicate.K));
				}
				else
				{
					
					InsertionOrder.Status = InsertionOrder.InsertionOrderStatus.Raised;
					InsertionOrder.DuplicateGuid = DuplicateGuid.Value;
					SaveForm();
					CampaignCredit credit = new CampaignCredit()
											{
												ActionDateTime = DateTime.Now,
												Credits = InsertionOrder.CampaignCredits,
                                                BuyableObjectK = InsertionOrder.K,
                                                BuyableObjectType = Model.Entities.ObjectType.InsertionOrder,
												PromoterK = InsertionOrder.PromoterK,
												Enabled = true
											};
					credit.UpdateWithRecalculateBalance();
														
												     
					
					Response.Redirect(ContainerPage.Url.CurrentUrl("K", InsertionOrder.K)); 
				}
			}
		}
		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;
		}
Example #4
0
		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();
			}
		}