protected void Add(object sender, EventArgs eventArgs)
		{
			int errors = 0;
			string[] promoters = Csv.Text.Split('\n');
			foreach (string s in promoters)
			{
				try
				{
					string[] parts = s.Split(',');
					string name = parts[0].Trim();
					string number = parts[1].Trim();
					string notes = "";
					if (parts.Length > 2)
					{
						for (int i = 2; i < parts.Length; i++)
							notes += (notes.Length > 0 ? "\n" : "") + parts[i].Trim();
					}
					Bobs.Promoter CurrentPromoter = new Bobs.Promoter();
					CurrentPromoter.DateTimeSignUp = DateTime.Now;
					CurrentPromoter.AddedByUsrK = Usr.Current.K;
					CurrentPromoter.Status = Promoter.StatusEnum.Enabled;
					CurrentPromoter.PricingMultiplier = 1.0;
					CurrentPromoter.AddedMethod = Promoter.AddedMedhods.SalesUser;

					CurrentPromoter.Name = name;
					CurrentPromoter.PhoneNumber = number;
					CurrentPromoter.ClientSector = (Promoter.ClientSectorEnum)Convert.ToInt32(Sector.SelectedValue);
					CurrentPromoter.SalesCampaignK = int.Parse(SalesCampaignDropDown.SelectedValue);
					CurrentPromoter.IsSkeleton = true;
					CurrentPromoter.SalesStatus = Promoter.SalesStatusEnum.New;
					CurrentPromoter.SalesUsrK = Usr.Current.K;
					CurrentPromoter.SalesStatusExpires = DateTime.Today.AddMonths(3);
					CurrentPromoter.SalesNextCall = DateTime.Now;

					CurrentPromoter.CreateUniqueUrlName();

					CurrentPromoter.Update();

					if (notes.Length > 0)
					{
						CurrentPromoter.AddNote(notes, Guid.NewGuid(), Usr.Current);
						CurrentPromoter.SalesCallCount = 0;
						CurrentPromoter.Update();
					}
				}
				catch
				{
					errors++;
					Error.InnerHtml += "FAILED on \"" + s + "\" <br/>";
				}
			}
			if (errors == 0)
				Response.Redirect("/admin/salesnew");
		}
Ejemplo n.º 2
0
		void uiGoToPromoterPageByPromoterButton_Click(object sender, EventArgs e)
		{
			try
			{
				Promoter p = new Promoter(int.Parse(this.uiPromoterAutoComplete.Value));
				Response.Redirect(p.Url());
			}catch{

			}

		}
		void appendPromoter(StringBuilder sb, Promoter p, bool doneOne)
		{
			if (doneOne)
				sb.Append(", ");
			sb.Append(p.Link());
			if (p.SalesUsrK > 0)
			{
				sb.Append(" (");
				sb.Append(p.SalesUsr.NickName);
				sb.Append(")");
			}
			sb.Append(" ");
			sb.Append("<a");
			sb.AppendAttribute("href", p.Url("callnow", "true"));
			sb.AppendAttribute("target", "_blank");
			sb.Append(">");
			sb.Append(p.PhoneNumber);
			sb.Append("</a>");
		}
Ejemplo n.º 4
0
		public static EventSet GetUpcomingEventsWithTickets(Promoter promoter)
		{
			return new EventSet(GetEventsWithTicketsQuery(promoter, Time.Today, new DateTime(2099, 1, 1)));
		}
Ejemplo n.º 5
0
		protected void PanelBrandErrorNext_Click(object sender, EventArgs eventArgs)
		{
			if (IsEdit)
			{
				if (Usr.Current.IsAdmin)
					Response.Redirect(CurrentPromoter.Url());
				else
					ChangePanel(PanelEditDone);
			}
			else
			{
				CurrentPromoter = new Promoter((int)this.ViewState["CurrentPromoterK"]);
				Thread t = new Thread(CurrentPromoter.QuestionsThreadK);
				Response.Redirect(t.Url());
			}
		}
Ejemplo n.º 6
0
		protected void SalesUsrAlarmGridView_RowCommand(object sender, GridViewCommandEventArgs e)
		{
			if (e.CommandName.ToUpper().Equals("DELETEALL"))
			{
				try
				{
					//GridViewRow row = (GridViewRow)dropDownList.NamingContainer;
					foreach (GridViewRow row in this.SalesUsrAlarmGridView.Rows)
					{
						Promoter promoter = new Promoter(Convert.ToInt32(((Label)row.FindControl("PromoterKLabel")).Text));
						promoter.Alarm = false;
						promoter.Update();
					}
					SalesUsrAlarmPanelSetup();
				}
				catch
				{ }
			}
		}
Ejemplo n.º 7
0
		protected void SnoozeAllDropDownList_SelectedIndexChanged(object sender, EventArgs e)
		{
			DropDownList dropDownList = (DropDownList)sender;
			if (dropDownList.SelectedValue != "")
			{
				//GridViewRow row = (GridViewRow)dropDownList.NamingContainer;
				foreach (GridViewRow row in this.SalesUsrAlarmGridView.Rows)
				{
					Promoter promoter = new Promoter(Convert.ToInt32(((Label)row.FindControl("PromoterKLabel")).Text));
					promoter.SalesNextCall = DateTime.Now.AddMinutes(Convert.ToInt32(dropDownList.SelectedValue));
					promoter.Alarm = true;
					promoter.Update();
				}
				SalesUsrAlarmPanelSetup();
			}
		}
Ejemplo n.º 8
0
		public void RemovePromoter(DataGridCommandEventArgs eventArgs)
		{
			if (eventArgs.CommandName.Equals("Remove"))
			{
				Promoter p = new Promoter(int.Parse(eventArgs.CommandArgument.ToString()));
				p.SalesUsrK = 0;
				p.SalesStatusExpires = null;
				p.SalesStatus = Promoter.SalesStatusEnum.Idle;
				p.Update();
				p.FixQuestionsThreadUsrs();
			}
		}
Ejemplo n.º 9
0
		public string PromoterHtmlCompetition(Promoter p)
		{
			Query q = new Query();
			q.QueryCondition = new And(new Q(Comp.Columns.EventK, this.K), new Q(Comp.Columns.Status, Comp.StatusEnum.Enabled));
			q.ReturnCountOnly = true;
			CompSet cs = new CompSet(q);
			return TickCrossHtml(cs.Count > 0);
		}
Ejemplo n.º 10
0
		public string PromoterHtmlArticle(Promoter p)
		{
			Query q = new Query();
			q.QueryCondition = new And(new Q(Article.Columns.EventK, this.K), Article.EnabledQueryCondition);
			q.ReturnCountOnly = true;
			ArticleSet ars = new ArticleSet(q);
			return TickCrossHtml(ars.Count > 0);
		}
Ejemplo n.º 11
0
		public string PromoterHtmlNews(Promoter p)
		{
			Query q = new Query();
			q.QueryCondition = new And(new Q(Thread.Columns.EventK, this.K), new Q(Thread.Columns.IsNews, true), new Q(Brand.Columns.PromoterK, p.K));
			q.TableElement = new Join(
				new TableElement(TablesEnum.Thread),
				new Join(Group.Columns.BrandK, Brand.Columns.K),
				QueryJoinType.Inner,
				new Q(Thread.Columns.GroupK, Group.Columns.K, true)
			);
			q.ReturnCountOnly = true;
			ThreadSet ts = new ThreadSet(q);
			return TickCrossHtml(ts.Count > 0);
		}
Ejemplo n.º 12
0
		public string PromoterHtmlEmailBanner(Promoter p)
		{
			Query q = new Query();
			q.QueryCondition = new And(new Q(Banner.Columns.PromoterK, p.K), new Q(Banner.Columns.EventK, this.K), Banner.IsBookedQ, new Q(Banner.Columns.Position, Banner.Positions.EmailBanner));
			q.ReturnCountOnly = true;
			BannerSet bs = new BannerSet(q);
			return TickCrossHtml(bs.Count > 0);
		}
Ejemplo n.º 13
0
		public string PromoterHtmlTickets(Promoter p)
		{
			Query q = new Query();
			q.QueryCondition = new And(new Q(TicketRun.Columns.PromoterK, p.K), new Q(TicketRun.Columns.EventK, this.K));
			q.ReturnCountOnly = true;
			TicketRunSet ts = new TicketRunSet(q);
			return TickCrossHtml(ts.Count > 0);
		}
Ejemplo n.º 14
0
		public static EventSet GetUpcomingEvents(Promoter promoter)
		{
			Query upcomingEventsQuery = Event.GetUpcomingEventsQuery();
			upcomingEventsQuery.QueryCondition = new And(upcomingEventsQuery.QueryCondition,
														 new Q(Promoter.Columns.K, promoter.K));
			upcomingEventsQuery.TableElement = Event.PromoterJoinWithVenue;

			return new EventSet(upcomingEventsQuery);
		}
Ejemplo n.º 15
0
		public static Query GetEventsWithTicketsQuery(Promoter promoter, DateTime from, DateTime to)
		{
			Query upcomingEventsWithTicketsQuery = new Query(new And(new Q(Event.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, from),
																	 new Q(Event.Columns.DateTime, QueryOperator.LessThan, to),
																	 new Q(TicketPromoterEvent.Columns.PromoterK, promoter.K)));
			upcomingEventsWithTicketsQuery.OrderBy = new OrderBy(new OrderBy(Event.Columns.DateTime), new OrderBy(Event.Columns.StartTime));
			upcomingEventsWithTicketsQuery.Distinct = true;
			upcomingEventsWithTicketsQuery.DistinctColumn = Event.Columns.K;
			upcomingEventsWithTicketsQuery.TableElement = new Join(Event.Columns.K, TicketPromoterEvent.Columns.EventK);
			upcomingEventsWithTicketsQuery.Columns = new ColumnSet(Event.Columns.Name,
																   Event.Columns.VenueK,
																   Event.Columns.K,
																   Event.Columns.DateTime,
																   Event.Columns.UrlFragment,
																   Event.Columns.VenueK);
			return upcomingEventsWithTicketsQuery;
		}
Ejemplo n.º 16
0
		public string PromoterHtmlGuestlist(Promoter p)
		{
			return TickCrossHtml(this.HasGuestlist && !this.GuestlistFull);
		}
Ejemplo n.º 17
0
		protected void RedirectSaved()
		{
			if (ContainerPage.Url["promoterk"].IsInt && ContainerPage.Url["promoterk"] > 0)
			{
				Promoter p = new Promoter(ContainerPage.Url["promoterk"]);
				if (Usr.Current.IsAdmin || Usr.Current.IsPromoterK(ContainerPage.Url["promoterk"]))
					Response.Redirect(p.Url());
				else
					throw new DsiUserFriendlyException("Can't redirect to this promoter!");
			}
			else
				Response.Redirect(CurrentGroup.Url());
		}
Ejemplo n.º 18
0
		public string PromoterHtmlSpotterInvite(Promoter p)
		{
			return TickCrossHtml(this.SpotterRequest.HasValue && this.SpotterRequest.Value);
		}
Ejemplo n.º 19
0
		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());
				}
			}

		}
Ejemplo n.º 20
0
		public string PromoterHtmlEventDonate(Promoter p)
		{
			return TickCrossHtml(this.HasHilight);
		}
Ejemplo n.º 21
0
		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;
		}
Ejemplo n.º 22
0
		public static Misc UploadFile(HtmlInputFile inputFile, Usr uploadUsr, Promoter promoter, List<string> acceptedFileExtensions)
		{
			return UploadFile(inputFile, uploadUsr, promoter, null, "", acceptedFileExtensions);
		}
Ejemplo n.º 23
0
		protected void SalesUsrAlarmGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
		{
			try
			{
				Promoter promoter = new Promoter(Convert.ToInt32(((Label)this.SalesUsrAlarmGridView.Rows[e.RowIndex].FindControl("PromoterKLabel")).Text));
				promoter.Alarm = false;
				promoter.Update();
				SalesUsrAlarmPanelSetup();
			}
			catch
			{ }
		}
Ejemplo n.º 24
0
		public static Misc UploadFile(HtmlInputFile inputFile, Usr uploadUsr, Promoter promoter, Banner banner)
		{
			return UploadFile(inputFile, uploadUsr, promoter, banner, "");
		}
Ejemplo n.º 25
0
		void ResetCurrentBuyer()
		{
			currentBuyerBalance = 0.0m;
			currentBuyerBalanceDone = false;
			currentPromoter = null;
			currentUsr = null;
		}
Ejemplo n.º 26
0
		public static Misc UploadFile(HtmlInputFile inputFile, Usr uploadUsr, Promoter promoter, Banner banner, string folder)
		{
			return UploadFile(inputFile, uploadUsr, promoter, banner, "", new List<string>(){"jpg", "gif", "swf"});
		}
Ejemplo n.º 27
0
		public void PanelSignUpFormClick(object o, System.EventArgs e)
		{
			Page.Validate();
			if (Page.IsValid)
			{
				if (IsEdit)
				{
					if (!CanEdit)
						throw new Exception("You can't edit this promoter!");
					#region Store changes to promoter in admin note
					string oldDetails = "";
					if (!Cambro.Web.Helpers.StripHtml(Name.Text).Equals(CurrentPromoter.Name))
						oldDetails += "Name: [" + CurrentPromoter.Name + "] - [" + Cambro.Web.Helpers.StripHtml(Name.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(ContactName.Text).Equals(CurrentPromoter.ContactName))
						oldDetails += "ContactName: [" + CurrentPromoter.ContactName + "] - [" + Cambro.Web.Helpers.StripHtml(ContactName.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(PhoneNumber.Text).Equals(CurrentPromoter.PhoneNumber))
						oldDetails += "PhoneNumber: [" + CurrentPromoter.PhoneNumber + "] - [" + Cambro.Web.Helpers.StripHtml(PhoneNumber.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(AddressStreet.Text).Equals(CurrentPromoter.AddressStreet))
						oldDetails += "AddressStreet: [" + CurrentPromoter.AddressStreet + "] - [" + Cambro.Web.Helpers.StripHtml(AddressStreet.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(AddressArea.Text).Equals(CurrentPromoter.AddressArea))
						oldDetails += "AddressArea: [" + CurrentPromoter.AddressArea + "] - [" + Cambro.Web.Helpers.StripHtml(AddressArea.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(AddressTown.Text).Equals(CurrentPromoter.AddressTown))
						oldDetails += "AddressTown: [" + CurrentPromoter.AddressTown + "] - [" + Cambro.Web.Helpers.StripHtml(AddressTown.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(AddressCounty.Text).Equals(CurrentPromoter.AddressCounty))
						oldDetails += "AddressCounty: [" + CurrentPromoter.AddressCounty + "] - [" + Cambro.Web.Helpers.StripHtml(AddressCounty.Text) + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(AddressPostcode.Text).Equals(CurrentPromoter.AddressPostcode))
						oldDetails += "AddressPostcode: [" + CurrentPromoter.AddressPostcode + "] - [" + Cambro.Web.Helpers.StripHtml(AddressPostcode.Text) + "]\n";
					if (!int.Parse(AddressCountry.SelectedValue).Equals(CurrentPromoter.AddressCountryK))
						oldDetails += "CountryK: [" + CurrentPromoter.AddressCountryK + "] - [" + int.Parse(AddressCountry.SelectedValue).ToString() + "]\n";
					if (!((Promoter.VatStatusEnum)Convert.ToInt32(VatStatusDropDownList.SelectedValue)).Equals(CurrentPromoter.VatStatus))
						oldDetails += "VatStatus: [" + CurrentPromoter.VatStatus.ToString() + "] - [" + ((Promoter.VatStatusEnum)Convert.ToInt32(VatStatusDropDownList.SelectedValue)).ToString() + "]\n";
					if (!Cambro.Web.Helpers.StripHtml(VatNumberTextBox.Text.Trim()).Equals(CurrentPromoter.VatNumber))
						oldDetails += "VatNumber: [" + CurrentPromoter.VatNumber + "] - [" + Cambro.Web.Helpers.StripHtml(VatNumberTextBox.Text.Trim()) + "]\n";
					if (!Convert.ToInt32(VatCountryDropDownList.SelectedValue).Equals(CurrentPromoter.VatCountryK))
						oldDetails += "VatCountryK: [" + CurrentPromoter.VatCountryK.ToString() + "] - [" + Convert.ToInt32(VatCountryDropDownList.SelectedValue).ToString() + "]\n";
                    if (!Cambro.Web.Helpers.StripHtml(BankNameTextBox.Text).Equals(CurrentPromoter.BankName))
                        oldDetails += "BankName: [" + CurrentPromoter.BankName + "] - [" + Cambro.Web.Helpers.StripHtml(BankNameTextBox.Text) + "]\n";
                    if (!Cambro.Web.Helpers.StripHtml(BankAccountNameTextBox.Text).Equals(CurrentPromoter.BankAccountName))
                        oldDetails += "BankAccountName: [" + CurrentPromoter.BankAccountName + "] - [" + Cambro.Web.Helpers.StripHtml(BankAccountNameTextBox.Text) + "]\n";
                    if (!Cambro.Web.Helpers.StripHtml(BankAccountNumberTextBox.Text).Equals(CurrentPromoter.BankAccountNumber))
                        oldDetails += "BankAccountNumber: [" + CurrentPromoter.BankAccountNumber + "] - [" + Cambro.Web.Helpers.StripHtml(BankAccountNumberTextBox.Text) + "]\n";
                    if (!Cambro.Web.Helpers.StripHtml(BankAccountSortCodeTextBox.Text).Equals(CurrentPromoter.BankAccountSortCode))
                        oldDetails += "BankAccountSortCode: [" + CurrentPromoter.BankAccountSortCode + "] - [" + Cambro.Web.Helpers.StripHtml(BankNameTextBox.Text) + "]\n";
					if (uiAgency.Checked != CurrentPromoter.IsAgency)
						oldDetails += "IsAgency: [" + CurrentPromoter.IsAgency.ToString() + "] - [" + uiAgency.Checked.ToString() + "]\n";
					if (oldDetails.Length > 0)
						CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") changed these details on " + DateTime.Now.ToString() + ":\n" + oldDetails;
					#endregion
				}
				else
				{
					Guid DuplicateGuid = (Guid)ViewState["PromoterDuplicateGuid"];
					PromoterSet ps = new PromoterSet(new Query(new Q(Promoter.Columns.DuplicateGuid, DuplicateGuid)));
					if (ps.Count > 0)
					{
						Response.Redirect(ps[0].UrlApp("edit"));
						return;
					}
					else
					{
						#region Initialise promoter record
						CurrentPromoter = new Promoter();
						CurrentPromoter.DateTimeSignUp = DateTime.Now;
						CurrentPromoter.AddedByUsrK = Usr.Current.K;
						CurrentPromoter.HasGuestlist = true;
						CurrentPromoter.GuestlistCharge = 0.25m;
						CurrentPromoter.GuestlistCredit = 20;
						CurrentPromoter.GuestlistCreditLimit = 0;
						CurrentPromoter.Status = Promoter.StatusEnum.Enabled;
						CurrentPromoter.PricingMultiplier = 1.0;
						CurrentPromoter.TotalPaid = 0;
						CurrentPromoter.DuplicateGuid = (Guid)ViewState["PromoterDuplicateGuid"];
						
						CurrentPromoter.LetterType = Promoter.LetterTypes.CurrentNewPromoter;
						CurrentPromoter.LetterStatus = Promoter.LetterStatusEnum.New;
						CurrentPromoter.IsSkeleton = false;
						CurrentPromoter.OfferType = Promoter.OfferTypes.None;
						Random r = new Random();
						CurrentPromoter.AccessCodeRandom = r.Next(1000, 9999).ToString() + r.Next(1000, 9999).ToString();
						
						CurrentPromoter.ClientSector = (Promoter.ClientSectorEnum)Convert.ToInt32(Sector.SelectedValue);
						CurrentPromoter.SalesCampaignK = int.Parse(SalesCampaignDropDown.SelectedValue);
						

						if (!Usr.Current.IsAdmin)
						{
							CurrentPromoter.PrimaryUsrK = Usr.Current.K;
							CurrentPromoter.AddedMethod = Promoter.AddedMedhods.EndUser;
						}
						else
						{
							CurrentPromoter.AddedMethod = Promoter.AddedMedhods.SalesUser;
						}

						// assign new Promoter to Usr.Current if they are on a promoter sales team or to a randomly assigned promoter sales person, as requested by Dave 7/2/07
						if (Usr.Current.SalesTeam > 0)
						{
							CurrentPromoter.SalesStatus = Promoter.SalesStatusEnum.Proactive;
							CurrentPromoter.SalesUsrK = Usr.Current.K;
						}
						else
						{
							CurrentPromoter.SalesStatus = Promoter.SalesStatusEnum.New;
							// Randomly assign a sales usr
							List<Usr> promoterSalesUsrs;
							if (CurrentPromoter.ClientSector.Equals(Promoter.ClientSectorEnum.Promoter))
								promoterSalesUsrs = Usr.GetNewPromoterSalesUsrsNameAndK().ToList();
							else
								promoterSalesUsrs = new List<Usr>() { new Usr(1) };
							CurrentPromoter.SalesUsrK = promoterSalesUsrs[r.Next(0, promoterSalesUsrs.Count)].K;
						}											

						CurrentPromoter.SalesStatusExpires = DateTime.Today.AddMonths(3);
						CurrentPromoter.SalesNextCall = DateTime.Now.AddDays(3);
						// If first call is on a weekend, then make it Monday
						if(CurrentPromoter.SalesNextCall.DayOfWeek == DayOfWeek.Saturday)
							CurrentPromoter.SalesNextCall = DateTime.Now.AddDays(2);
						else if(CurrentPromoter.SalesNextCall.DayOfWeek == DayOfWeek.Sunday)
							CurrentPromoter.SalesNextCall = DateTime.Now.AddDays(1);

						#endregion
					}
				}
				#region Update promoter record with form contents
				CurrentPromoter.Name = Cambro.Web.Helpers.StripHtml(Name.Text);
				CurrentPromoter.ContactName = Cambro.Web.Helpers.StripHtml(ContactName.Text);
				CurrentPromoter.PhoneNumber = Cambro.Web.Helpers.StripHtml(PhoneNumber.Text);
				CurrentPromoter.AddressStreet = Cambro.Web.Helpers.StripHtml(AddressStreet.Text);
				CurrentPromoter.AddressArea = Cambro.Web.Helpers.StripHtml(AddressArea.Text);
				CurrentPromoter.AddressTown = Cambro.Web.Helpers.StripHtml(AddressTown.Text);
				CurrentPromoter.AddressCounty = Cambro.Web.Helpers.StripHtml(AddressCounty.Text);
				CurrentPromoter.AddressPostcode = Cambro.Web.Helpers.StripHtml(AddressPostcode.Text);

				bool updateTicketInvoices = false;
				// new VAT details, for Ticket System. 22/5/07
				if (CurrentPromoter.VatStatus != Promoter.VatStatusEnum.Registered && CurrentPromoter.VatStatus != (Promoter.VatStatusEnum)Convert.ToInt32(VatStatusDropDownList.SelectedValue))
					updateTicketInvoices = true;

				CurrentPromoter.VatStatus = (Promoter.VatStatusEnum)Convert.ToInt32(VatStatusDropDownList.SelectedValue);
				CurrentPromoter.VatCountryK = Convert.ToInt32(VatCountryDropDownList.SelectedValue);
				CurrentPromoter.VatNumber = Cambro.Web.Helpers.StripHtml(VatNumberTextBox.Text.Trim());
				
				// new Admin only data entry fields, as requested by Dave 7/2/07
				if (Usr.Current.IsAdmin || Usr.Current.IsSuperAdmin)
				{
					CurrentPromoter.AccountsEmail = Cambro.Web.Helpers.StripHtml(AccountsEmail.Text);
					CurrentPromoter.AccountsName = Cambro.Web.Helpers.StripHtml(AccountsName.Text);
					CurrentPromoter.AccountsPhone = Cambro.Web.Helpers.StripHtml(AccountsPhone.Text);
					CurrentPromoter.ContactPersonalTitle = Cambro.Web.Helpers.StripHtml(PersonalTitle.Text);
					CurrentPromoter.ContactTitle = Cambro.Web.Helpers.StripHtml(JobTitle.Text);
					CurrentPromoter.PhoneNumber2 = Cambro.Web.Helpers.StripHtml(PhoneNumber2.Text);
					CurrentPromoter.WebAddress = Cambro.Web.Helpers.StripHtml(WebAddress.Text);
					CurrentPromoter.ClientSector = (Promoter.ClientSectorEnum)Convert.ToInt32(Sector.SelectedValue);
					CurrentPromoter.SalesCampaignK = int.Parse(SalesCampaignDropDown.SelectedValue);
					CurrentPromoter.IsAgency = uiAgency.Checked;

                    // new admin only bank details, as requested by Dave 15/6/07
                    CurrentPromoter.BankName = Cambro.Web.Helpers.StripHtml(BankNameTextBox.Text);
                    CurrentPromoter.BankAccountName = Cambro.Web.Helpers.StripHtml(BankAccountNameTextBox.Text);
                    CurrentPromoter.BankAccountNumber = Cambro.Web.Helpers.StripHtml(BankAccountNumberTextBox.Text);
                    CurrentPromoter.BankAccountSortCode = Cambro.Web.Helpers.StripHtml(BankAccountSortCodeTextBox.Text);

					
					if (this.AccessMultiRadio.Checked && this.uiAccessUsersMultiSelector.Count > 0 && (Usr.Current.IsAdmin || Usr.Current.IsSuperAdmin)){
						CurrentPromoter.PrimaryUsrK = int.Parse(uiPrimaryUserDropDown.SelectedValue);
					}else
					{
						CurrentPromoter.PrimaryUsrK = 0;
						CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") has setup this account with no primary user - " + DateTime.Now.ToString() + "\n";
					}
				}

				if (!IsEdit)
				{
					if (CurrentPromoter.PrimaryUsrK > 0)
						CurrentPromoter.AddQuestionsThread(CurrentPromoter.PrimaryUsr, Cambro.Web.Helpers.StripHtml(Name.Text));
					else
						CurrentPromoter.AddQuestionsThread(Usr.Current, Cambro.Web.Helpers.StripHtml(Name.Text));
				}

				Country newCountry = new Country(int.Parse(AddressCountry.SelectedValue));
				CurrentPromoter.AddressCountryK = newCountry.K;
				CurrentPromoter.Update();
				if (updateTicketInvoices)
					CurrentPromoter.UpdateTicketInvoiceItemTaxCode();
				CurrentPromoter.CreateUniqueUrlName();
				#endregion
				#region Add / remove selected users
				if (CurrentPromoter.PrimaryUsrK == Usr.Current.K || Usr.Current.IsAdmin || Usr.Current.IsSuperAdmin)
				{
					ArrayList SelectedUsers = new ArrayList();
					ArrayList CurrentUsers = new ArrayList();
					if (CurrentPromoter.PrimaryUsrK > 0)
					{
						SelectedUsers.Add(CurrentPromoter.PrimaryUsrK);
					}
					if (AccessMultiRadio.Checked)
					{
						foreach (var pair in this.uiAccessUsersMultiSelector.Selections)
						{
							Usr u = new Usr(int.Parse(pair.Value));
							if (!SelectedUsers.Contains(u.K))
								SelectedUsers.Add(u.K);
						}
					}
					foreach (Usr u in CurrentPromoter.AdminUsrs)
					{
						if (!CurrentUsers.Contains(u.K))
							CurrentUsers.Add(u.K);
					}

					if (SelectedUsers.Count > 0)
					{
						Usr JohnB = new Usr(1);
						Thread t = new Thread(CurrentPromoter.QuestionsThreadK);
						foreach (int usrK in SelectedUsers)
						{
							if (!CurrentUsers.Contains(usrK))
							{
								PromoterUsr pu = new PromoterUsr();
								pu.PromoterK = CurrentPromoter.K;
								pu.UsrK = usrK;
								pu.Update();

								t.Invite(new List<int>(new int[] { usrK }), JohnB, DateTime.Now, new List<int>(), !IsEdit, null, false);

								ThreadUsr tu = new ThreadUsr(CurrentPromoter.QuestionsThreadK, usrK);
								tu.Favourite = true;
								tu.Update();

								CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") added new user to admins - " + DateTime.Now.ToString() + " - " + pu.UsrK.ToString() + " (" + pu.Usr.NickName + ")\n";
								CurrentPromoter.Update();

								pu.Usr.UpdateIsPromoter();
							}
						}
					}
					//if (!AccessNoAccountUsersRadio.Checked)
					//{
						foreach (int usrK in CurrentUsers)
						{
							if (!SelectedUsers.Contains(usrK))
							{
								PromoterUsr pu = new PromoterUsr(CurrentPromoter.K, usrK);

								CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") removed user from the admins - " + DateTime.Now.ToString() + " - " + pu.UsrK.ToString() + " (" + pu.Usr.NickName + ")\n";
								CurrentPromoter.Update();

								pu.Delete();
								pu.Update();

								pu.Usr.UpdateIsPromoter();

								try
								{
									ThreadUsr tu = new ThreadUsr(CurrentPromoter.QuestionsThreadK, usrK);
									tu.Delete();
									tu.Update();

									UpdateTotalParticipantsJob job = new UpdateTotalParticipantsJob(tu.Thread);
									job.ExecuteSynchronously();

								}
								catch { }
							}
						}
					//}
					//else
					//{
					//    foreach (int usrK in CurrentUsers)
					//    {
					//        PromoterUsr pu = new PromoterUsr(CurrentPromoter.K, usrK);

					//        CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") removed user from the admins - " + DateTime.Now.ToString() + " - " + pu.UsrK.ToString() + " (" + pu.Usr.NickName + ")\n";
					//        CurrentPromoter.Update();

					//        pu.Delete();
					//        pu.Update();

					//        pu.Usr.UpdateIsPromoter();

					//        try
					//        {
					//            ThreadUsr tu = new ThreadUsr(CurrentPromoter.QuestionsThreadK, usrK);
					//            tu.Delete();
					//            tu.Update();
					//            tu.Thread.UpdateTotalParticipants();
					//        }
					//        catch { }
					//    }
					//}
				}
				#endregion
				#region Add / remove selected brands
					ArrayList SelectedBrands = new ArrayList();
					ArrayList CurrentBrands = new ArrayList();
					if (AccountTypeRadioEvents.Checked)
					{
						foreach (var pair in this.uiBrandMultiSelector.Selections)
						{
							Brand b = new Brand(int.Parse(pair.Value));
							if (!SelectedBrands.Contains(b.K))
								SelectedBrands.Add(b.K);
						}
					}
					CurrentPromoter.AllBrands = null;
					foreach (Brand b in CurrentPromoter.AllBrands)
					{
						if (!CurrentBrands.Contains(b.K))
							CurrentBrands.Add(b.K);
					}

					string failedBrands = "";

					foreach (int brandK in SelectedBrands)
					{
						if (!CurrentBrands.Contains(brandK))
						{
							Brand b = new Brand(brandK);
							bool changeStatus = false;
							if (b.PromoterK == 0)
							{
								CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") added brand - " + DateTime.Now.ToString() + " - " + b.K + " (" + b.Name + ") - ";
								b.PromoterK = CurrentPromoter.K;
								changeStatus = true;
							}
							else if (b.PromoterStatus.Equals(Brand.PromoterStatusEnum.Unconfirmed))
							{
								CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") added brand - " + DateTime.Now.ToString() + " - " + b.K + " (" + b.Name + ") - removed from promoter " + b.PromoterK + " (" + b.Promoter.Name + ") - ";
								b.PromoterK = CurrentPromoter.K;
								changeStatus = true;
							}
							else //brand owned by someone else!
							{
								CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") attempted to add brand - " + DateTime.Now.ToString() + " - " + b.K + " (" + b.Name + "), but it's already confirmed to promoter " + b.PromoterK + " (" + b.Promoter.Name + ")\n";

								failedBrands = (failedBrands.Length == 0 ? "" : ", ") + b.Name;
							}
							if (changeStatus)
							{
								bool foundBrandOwner = false;
								CurrentPromoter.AdminUsrs = null;
								foreach (Usr u in CurrentPromoter.AdminUsrs)
								{
									if (b.OwnerUsrK == u.K)
										foundBrandOwner = true;
								}
								if (foundBrandOwner || Usr.Current.IsAdmin)
								{
									b.PromoterStatus = Brand.PromoterStatusEnum.Confirmed;
									CurrentPromoter.AdminNote += "(status confirmed)\n";
								}
								else
								{
									b.PromoterStatus = Brand.PromoterStatusEnum.Unconfirmed;
									CurrentPromoter.AdminNote += "(status new)\n";
								}
							}
							b.Update();
							CurrentPromoter.Update();
						}
					}
					foreach (int brandK in CurrentBrands)
					{
						if (!SelectedBrands.Contains(brandK))
						{
							Brand b = new Brand(brandK);
							CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") removed brand - " + DateTime.Now.ToString() + " - " + b.K + " (" + b.Name + ")";
							b.PromoterStatus = Brand.PromoterStatusEnum.Unconfirmed;
							b.PromoterK = 0;
							b.Update();
							CurrentPromoter.Update();
						}
					}
					#endregion
				#region Add / remove selected venues
				ArrayList SelectedVenues = new ArrayList();
				ArrayList CurrentVenues = new ArrayList();
				if (VenuesRadioYes.Checked)
				{
					foreach (var pair in this.uiVenuesMultiSelector.Selections)
					{
						Venue v = new Venue(int.Parse(pair.Value));
						if (!SelectedVenues.Contains(v.K))
							SelectedVenues.Add(v.K);
					}
				}
				CurrentPromoter.AllVenues = null;
				foreach (Venue v in CurrentPromoter.AllVenues)
				{
					if (!CurrentVenues.Contains(v.K))
						CurrentVenues.Add(v.K);
				}

				string failedVenues = "";

				foreach (int venueK in SelectedVenues)
				{
					if (!CurrentVenues.Contains(venueK))
					{
						Venue v = new Venue(venueK);
						bool changeStatus = false;
						if (v.PromoterK == 0)
						{
							CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") added venue - " + DateTime.Now.ToString() + " - " + v.K + " (" + v.Name + ") - ";
							v.PromoterK = CurrentPromoter.K;
							changeStatus = true;
						}
						else if (v.PromoterStatus.Equals(Venue.PromoterStatusEnum.Unconfirmed))
						{
							CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") added venue - " + DateTime.Now.ToString() + " - " + v.K + " (" + v.Name + ") - removed from promoter " + v.PromoterK + " (" + v.Promoter.Name + ") - ";
							v.PromoterK = CurrentPromoter.K;
							changeStatus = true;
						}
						else //venue owned by someone else!
						{
							CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") attempted to add venue - " + DateTime.Now.ToString() + " - " + v.K + " (" + v.Name + "), but it's already confirmed to promoter " + v.PromoterK + " (" + v.Promoter.Name + ")\n";

							failedVenues = (failedVenues.Length == 0 ? "" : ", ") + v.Name + " in " + v.Place.Name;
						}
						if (changeStatus)
						{
							bool foundVenueOwner = false;
							CurrentPromoter.AdminUsrs = null;
							foreach (Usr u in CurrentPromoter.AdminUsrs)
							{
								if (v.OwnerUsrK == u.K)
									foundVenueOwner = true;
							}
							if (foundVenueOwner || Usr.Current.IsAdmin)
							{
								v.PromoterStatus = Venue.PromoterStatusEnum.Confirmed;
								CurrentPromoter.AdminNote += "(status confirmed)\n";
							}
							else
							{
								v.PromoterStatus = Venue.PromoterStatusEnum.Unconfirmed;
								CurrentPromoter.AdminNote += "(status new)\n";
							}
						}
						v.Update();
						CurrentPromoter.Update();
					}
				}
				foreach (int venueK in CurrentVenues)
				{
					if (!SelectedVenues.Contains(venueK))
					{
						Venue v = new Venue(venueK);
						CurrentPromoter.AdminNote += "\n" + Usr.Current.NickName + " (" + Usr.Current.K.ToString() + ") removed venue - " + DateTime.Now.ToString() + " - " + v.K + " (" + v.Name + ")";
						v.PromoterStatus = Venue.PromoterStatusEnum.Unconfirmed;
						v.PromoterK = 0;
						v.Update();
						CurrentPromoter.Update();
					}
				}
				#endregion

				this.ViewState["CurrentPromoterK"] = CurrentPromoter.K;
				CurrentPromoter = new Promoter(CurrentPromoter.K);
				CurrentPromoter.FixQuestionsThreadUsrs();
				CurrentPromoter.UpdateModerators();

				Usr.Current.LegalTermsPromoter2 = true;
				Usr.Current.Update();


				if (failedBrands.Length > 0 || failedVenues.Length > 0)
				{
					//show error form...
					BrandErrorLabel.Text = failedBrands;
					VenueErrorLabel.Text = failedVenues;
					BrandErrorPanel.Visible = failedBrands.Length > 0;
					VenueErrorPanel.Visible = failedVenues.Length > 0;

					ChangePanel(PanelBrandVenueError);
				}
				else
				{
					if (IsEdit)
					{
						if (Usr.Current.IsAdmin)
							Response.Redirect(CurrentPromoter.Url());
						else
							ChangePanel(PanelEditDone);
					}
					else
					{
						if (!Usr.Current.IsAdmin)
						{
							Thread t = new Thread(CurrentPromoter.QuestionsThreadK);
							Response.Redirect(t.Url());
						}
						else
						{
							Response.Redirect(CurrentPromoter.Url());
						}
					}
				}

			}
		}
Ejemplo n.º 28
0
		public static Misc UploadFile(HtmlInputFile inputFile, Usr uploadUsr, Promoter promoter, Banner banner, string folder, List<string> acceptedFileExtensions)
		{
			if (inputFile.PostedFile != null)
			{
				#region Upload file
				Misc m = new Misc();

				m.UsrK = uploadUsr.K;

				if (promoter != null)
					m.PromoterK = promoter.K;

				m.DateTime = DateTime.Now;
				m.Folder = folder;

				m.Guid = Guid.NewGuid();


				if (inputFile.PostedFile.FileName.IndexOf(".") == -1)
					m.Extention = "";
				else
					m.Extention = inputFile.PostedFile.FileName.Substring(inputFile.PostedFile.FileName.LastIndexOf(".") + 1).ToLower();

				if (m.Extention.Equals("jpeg") || m.Extention.Equals("jpe"))
					m.Extention = "jpg";

				if (!acceptedFileExtensions.Contains(m.Extention))
				{
					string listOfFileExtensions = "";
					foreach(string s in acceptedFileExtensions)
						listOfFileExtensions += s + ", ";
					throw new DsiUserFriendlyException("You can only upload " + listOfFileExtensions.Substring(0, listOfFileExtensions.Length-2) + " files with this page.");
				}

				if (promoter != null && m.Extention.Equals("swf"))
				{
					if (m.Size <= 150 * 1024)
						m.NeedsAuth = true;
				}
				
				byte[] bytes = new byte[inputFile.PostedFile.InputStream.Length];
				inputFile.PostedFile.InputStream.Read(bytes, 0, (int)inputFile.PostedFile.InputStream.Length);
				
				m.Size = inputFile.PostedFile.ContentLength;

				m.Name = inputFile.PostedFile.FileName.Substring(inputFile.PostedFile.FileName.LastIndexOf("\\") + 1);

				if (m.Extention.Equals("jpg") || m.Extention.Equals("gif") || m.Extention.Equals("png"))
				{
					using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes)))
					{
						m.Width = image.Width;
						m.Height = image.Height;
					}
				}

				m.Update();

				try
				{
					Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, "");
				}
				catch (Exception ex)
				{
					m.Delete();
					throw ex;
				}

				if (promoter != null)
				{
					if (promoter != null && m.NeedsAuth)
					{
						Mailer adminMail = new Mailer();
						adminMail.Subject = "New files waiting to be approved!!! uploaded by" + uploadUsr.NickNameSafe;
						adminMail.To = "*****@*****.**";
						adminMail.Body += "<p>New FILES uploaded by <a href=\"[LOGIN(" + uploadUsr.Url() + ")]\">" + uploadUsr.NickNameSafe + "</a></p>";
						if (promoter != null)
							adminMail.Body += "<p>... for promoter <a href=\"[LOGIN(" + promoter.Url() + ")]\">" + promoter.Name + "</a></p>";
						adminMail.Body += "<h2>Files:</h2>";
						adminMail.Body += "<p><a href=\"" + m.Url() + "\">" + HttpUtility.HtmlEncode(m.Name) + "</a> - " + m.FileSizeString + "</p>";
						adminMail.TemplateType = Mailer.TemplateTypes.AdminNote;
						adminMail.RedirectUrl = uploadUsr.Url();
						adminMail.Send();
					}
				}

				if (banner != null)
					banner.AssignMisc(m);

				return m;

				#endregion
			}
			else
				return null;
		}
Ejemplo n.º 29
0
		private static void EmailUnpaidPromotersInvoicesToPromotersAndAccounts(DateTime fromDueDate, DateTime toDueDate)
		{
			try
			{
				// Get all promoterK's who have outstanding invoices within the date range
				Query promoterKQuery = new Query();
				promoterKQuery.QueryCondition = new And(new Q(Invoice.Columns.Type, Invoice.Types.Invoice),
														new Q(Invoice.Columns.Paid, false),
														new Q(Invoice.Columns.PromoterK, QueryOperator.NotEqualTo, 0),
														new Q(Invoice.Columns.DueDateTime, QueryOperator.GreaterThanOrEqualTo, fromDueDate),
														new Q(Invoice.Columns.DueDateTime, QueryOperator.LessThanOrEqualTo, toDueDate));

				promoterKQuery.Columns = new ColumnSet(Invoice.Columns.PromoterK);
				promoterKQuery.GroupBy = new GroupBy(Invoice.Columns.PromoterK);

				InvoiceSet promoterKInvoices = new InvoiceSet(promoterKQuery);

				Promoter promoter = null;
				// Foreach promoter, group together all their outstanding invoices within the date range and send one email with all invoices as attachments
				foreach (Invoice promoterKInvoice in promoterKInvoices)
				{

					try
					{
						promoter = new Promoter(promoterKInvoice.PromoterK);
						bool containsOverdue = false;
						promoter.ApplyAvailableMoneyToUnpaidInvoices();

						Query outstandingInvoicesQuery = new Query(new And(new Q(Invoice.Columns.Type, Invoice.Types.Invoice),
																		   new Q(Invoice.Columns.Paid, false),
																		   new Q(Invoice.Columns.DueDateTime, QueryOperator.GreaterThanOrEqualTo, fromDueDate),
																		   new Q(Invoice.Columns.DueDateTime, QueryOperator.LessThanOrEqualTo, toDueDate),
																		   new Q(Invoice.Columns.PromoterK, promoterKInvoice.PromoterK)));
						outstandingInvoicesQuery.OrderBy = new OrderBy(Invoice.Columns.DueDateTime, OrderBy.OrderDirection.Ascending);

						InvoiceSet outstandingInvoices = new InvoiceSet(outstandingInvoicesQuery);

						Mailer mailer = new Mailer();
						mailer.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;

						decimal totalAmountDue = 0;

						foreach (Invoice invoice in outstandingInvoices)
						{
							totalAmountDue += Math.Round(invoice.AmountDue, 2);
							if (invoice.Paid == false && new DateTime(invoice.DueDateTime.Year, invoice.DueDateTime.Month, invoice.DueDateTime.Day) <= new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day))
							{
								containsOverdue = true;
							}
						}

						string nonUserEmailBody = "";
						// If there are no outstanding/overdue invoices, then do not send warning message
						if (outstandingInvoices.Count > 0)
						{
							// For overdue invoices
							if (containsOverdue == true)
							{
								mailer.Subject = "DontStayIn overdue invoices require payment of " + totalAmountDue.ToString("c");
								mailer.Body = "<p>DontStayIn overdue invoices. Amount due " + Utilities.MoneyToHTML(totalAmountDue) + ". Payment required immediately for the following invoices:</p>";

							}
							// For outstanding invoices
							else
							{
                                mailer.Subject = "DontStayIn outstanding invoices require payment of " + totalAmountDue.ToString("c");
								mailer.Body = "<p>DontStayIn outstanding invoices. Amount due " + Utilities.MoneyToHTML(totalAmountDue) + ". Payment required before due date for the following invoices:</p>";
							}

							nonUserEmailBody = mailer.Body + "<p>Promoter: " + promoter.Name + "</p><p>Please pay invoices now</p>";
							mailer.Body += promoter.LinkEmailFull;

							Utilities.AddInvoicesToEmail(mailer, outstandingInvoices);
							mailer.Body += @"<p><a href=""[LOGIN(" + promoter.UrlApp("invoices", "pay", "true") + "\")]>Please pay invoices now</a>.</p>";
							if (!Vars.DevEnv)
							{
								if (!promoter.SuspendReminderEmails)
								{
									foreach (Usr usr in promoter.AdminUsrs)
									{
										mailer.UsrRecipient = usr;
										mailer.RedirectUrl = promoter.UrlApp("invoices");
										mailer.Send();
									}
								}

							}

							if (!Vars.DevEnv && promoter.AccountsEmail != null && promoter.AccountsEmail.Length > 0)
							{
								try
								{
									Utilities.EmailToNonUser(promoter.AccountsEmail, mailer.Subject, nonUserEmailBody, mailer.Attachments.ToArray());
								}
								catch (Exception ex)
								{
									string additionalDetails = "Occurred in Utilities.EmailAllPromoterOutstandingStatements(): Promoter.AccountsEmail = " + promoter.AccountsEmail;
									EmailException(ex, additionalDetails, promoter);
								}
							}

							// Change for internal use
							mailer.UsrRecipient = null;
							mailer.TemplateType = Mailer.TemplateTypes.AdminNote;
							mailer.Subject += " (" + promoter.Name + ")";
							// now send to our accounts email address
							mailer.To = "*****@*****.**";
							mailer.Send();
						}
					}
					catch (Exception ex)
					{
						string additionalDetails = "Occurred in Utilities.EmailUnpaidPromotersInvoicesToPromotersAndAccounts(): Promoter K= ";
						if (promoterKInvoice != null)
							additionalDetails += promoterKInvoice.PromoterK.ToString();
						else
							additionalDetails += "null";
						EmailException(ex, additionalDetails, promoter);
					}
				}
			}
			catch (Exception ex)
			{
				EmailException(ex, "Occurred in Utilities.EmailUnpaidPromotersInvoicesToPromotersAndAccounts()");
			}
		}
Ejemplo n.º 30
0
		protected void SavedRedirect()
		{
			if (ContainerPage.Url["promoterk"].IsInt && ContainerPage.Url["promoterk"] > 0)
			{
				Promoter p = new Promoter(ContainerPage.Url["promoterk"]);
				if (Usr.Current.IsAdmin || Usr.Current.IsPromoterK(ContainerPage.Url["promoterk"]))
					Response.Redirect(p.UrlEventOptions(CurrentEvent));
				else
					throw new Exception("Can't redirect to this promoter!");
			}
			else if (ContainerPage.Url["signup"] == 1)
				Response.Redirect(CurrentEvent.SpotterSignUpUrl);
			else
				Response.Redirect(CurrentEvent.Url()); 
		}