Esempio n. 1
0
        protected void CreditItemsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToUpper().Equals("ADD"))
            {
				Page.Validate("CreditItemNew");
				if (Page.IsValid)
				{
					try
					{
						// add new row from footer to db
						InvoiceItem newCreditItem = new InvoiceItem();

						GridViewRow row = CreditItemsGridView.FooterRow;

						newCreditItem.Description = ((TextBox)row.FindControl("NewDescriptionTextBox")).Text.Trim();
						newCreditItem.RevenueStartDate = ((Spotted.CustomControls.Cal)row.FindControl("NewRevenueStartDateCal")).Date;
						newCreditItem.RevenueEndDate = ((Spotted.CustomControls.Cal)row.FindControl("NewRevenueEndDateCal")).Date;
						if (((TextBox)row.FindControl("NewTotalTextBox")).Text.Length > 0)
							newCreditItem.SetTotal(Math.Abs(Utilities.ConvertMoneyStringToDecimal(((TextBox)row.FindControl("NewTotalTextBox")).Text)));
						else
							newCreditItem.PriceBeforeDiscount = Math.Abs(Utilities.ConvertMoneyStringToDecimal(((TextBox)row.FindControl("NewPriceTextBox")).Text));

						newCreditItem.VatCode = (InvoiceItem.VATCodes)Convert.ToInt32(((DropDownList)row.FindControl("NewVatCodeDropDownList")).SelectedValue);
						newCreditItem.Type = (InvoiceItem.Types)Convert.ToInt32(((DropDownList)row.FindControl("NewTypeDropDownList")).SelectedValue);

						CreditItemDataHolderList.Add(new InvoiceItemDataHolder(newCreditItem));

						ViewState["CreditItemDataHolderList"] = CreditItemDataHolderList;
					}
					catch (Exception)
					{ }
					finally
					{
						CalculateCreditItemVatAndTotals();
					}
				}
            }
        }
Esempio n. 2
0
		public void UpdateTicketInvoiceItemTaxCode()
		{
			if(this.VatStatus == VatStatusEnum.Registered)
			{
				InvoiceItem.VATCodes vatCode = InvoiceItem.VATCodes.T1;
				foreach (TicketPromoterEvent ticketPromoterEvent in TicketPromoterEvents)
				{
					bool updated = false;

					foreach (TicketRun ticketRun in ticketPromoterEvent.TicketRuns)
					{
						foreach (Ticket ticket in ticketRun.Tickets)
						{
							try
							{
								InvoiceItem ticketInvoiceItem = new InvoiceItem(ticket.InvoiceItemK);
								if (ticketInvoiceItem.VatCode != vatCode)
								{
									decimal total = ticketInvoiceItem.Total;
									ticketInvoiceItem.VatCode = vatCode;
									ticketInvoiceItem.SetTotal(total);
									ticketInvoiceItem.Update();
									ticketInvoiceItem.Invoice.UpdatePrice();
									ticketInvoiceItem.Invoice.Update();

									if (ticket.Cancelled)
									{
										foreach (Invoice credit in ticketInvoiceItem.Invoice.CreditsApplied)
										{
											foreach (InvoiceItem creditItem in credit.Items)
											{
												if (creditItem.Type == ticketInvoiceItem.Type && Math.Abs(Math.Round(creditItem.Total, 2)) == Math.Round(ticketInvoiceItem.Total, 2))
												{
													creditItem.VatCode = vatCode;
													creditItem.SetTotal(creditItem.Total);
													creditItem.Update();
													creditItem.Invoice.UpdatePrice();
													creditItem.Invoice.Update();
												}
											}
										}
									}

									updated = true;
								}
							}
							catch (Exception ex)
							{
								Utilities.AdminEmailAlert("Exception occurred for TicketK= " + ticket.K.ToString(), "Exception occurred in UpdateTicketInvoiceItemTaxCode()", ex, this);
							}
						}
					}

					if (updated)
					{
						ticketPromoterEvent.CalculateTotalFundsAndVat();
						ticketPromoterEvent.Update();
						if (ticketPromoterEvent.FundsTransfer != null && ticketPromoterEvent.FundsTransfer.Amount != ticketPromoterEvent.TotalFunds)
						{
							// Admin email alert
							Utilities.AdminEmailAlert("Funds do not match release transfer funds.<br>TransferK= " + ticketPromoterEvent.FundsTransfer.K.ToString()
														+ ", PromoterK= " + ticketPromoterEvent.PromoterK.ToString() + ", EventK= " + ticketPromoterEvent.EventK.ToString(), 
													  "Exception occurred in UpdateTicketInvoiceItemTaxCode()", new Exception(), this);
						}
					}
				}
			}
		}
        protected void InvoiceItemsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToUpper().Equals("ADD"))
            {
				GridViewRow row = InvoiceItemsGridView.FooterRow;

				CustomValidator revenueStartDateCustomValidator = ((CustomValidator)row.FindControl("NewRevenueStartDateCalCustomValidator"));
				CustomValidator revenueEndDateCustomValidator1 = ((CustomValidator)row.FindControl("NewRevenueEndDateCalCustomValidator1"));
				CustomValidator revenueEndDateCustomValidator2 = ((CustomValidator)row.FindControl("NewRevenueEndDateCalCustomValidator2"));
				
				revenueStartDateCustomValidator.Enabled = InvoiceItem.DoesTypeHaveRevenueDateRange((InvoiceItem.Types)Convert.ToInt32(((DropDownList)row.FindControl("NewTypeDropDownList")).SelectedValue));
				revenueEndDateCustomValidator1.Enabled = revenueStartDateCustomValidator.Enabled;
				revenueEndDateCustomValidator2.Enabled = revenueStartDateCustomValidator.Enabled;

				Page.Validate("InvoiceItemNew");
				if (Page.IsValid)
				{
					try
					{
						// add new row from footer to db
						InvoiceItem newInvoiceItem = new InvoiceItem();
						
						newInvoiceItem.Description = ((TextBox)row.FindControl("NewDescriptionTextBox")).Text.Trim();
						newInvoiceItem.RevenueStartDate = ((Spotted.CustomControls.Cal)row.FindControl("NewRevenueStartDateCal")).Date;
						newInvoiceItem.RevenueEndDate = ((Spotted.CustomControls.Cal)row.FindControl("NewRevenueEndDateCal")).Date;
						newInvoiceItem.VatCode = (InvoiceItem.VATCodes)Convert.ToInt32(((DropDownList)row.FindControl("NewVatCodeDropDownList")).SelectedValue);
						newInvoiceItem.Discount = Utilities.ConvertPercentageStringToDouble(((TextBox)row.FindControl("uiNewDiscountTextBox")).Text);
						newInvoiceItem.AgencyDiscount = Utilities.ConvertPercentageStringToDouble(uiAgencyDiscountTextBox.Text);
						if (((TextBox)row.FindControl("NewTotalTextBox")).Text.Length > 0)
						{	newInvoiceItem.SetTotal(Utilities.ConvertMoneyStringToDecimal(((TextBox)row.FindControl("NewTotalTextBox")).Text)); }
						else
						{ newInvoiceItem.PriceBeforeDiscount = Utilities.ConvertMoneyStringToDecimal(((TextBox)row.FindControl("NewPriceBeforeDiscountTextBox")).Text); }
						//newInvoiceItem.Price = Math.Abs(Utilities.ConvertMoneyStringToDecimal(((TextBox)row.FindControl("NewPriceBeforeDiscountTextBox")).Text));
						//newInvoiceItem.Vat = Convert.ToDouble(((TextBox)row.FindControl("NewVatTextBox")).Text);
						//newInvoiceItem.Total = Convert.ToDouble(((TextBox)row.FindControl("NewTotalTextBox")).Text);
						newInvoiceItem.Type = (InvoiceItem.Types)Convert.ToInt32(((DropDownList)row.FindControl("NewTypeDropDownList")).SelectedValue);

						string alertMessage = "";
						if (revenueStartDateCustomValidator.Enabled == false && Utilities.GetStartOfDay(newInvoiceItem.RevenueStartDate) != DateTime.Today)
						{
							newInvoiceItem.RevenueStartDate = DateTime.Now;
							alertMessage += Utilities.CamelCaseToString(newInvoiceItem.Type.ToString()) + " revenue start date autoset to " + Utilities.DateToString(DateTime.Now) + ". ";
						}
						if (revenueEndDateCustomValidator1.Enabled == false && Utilities.GetStartOfDay(newInvoiceItem.RevenueEndDate) != DateTime.Today)
						{
							newInvoiceItem.RevenueEndDate = DateTime.Now;
							alertMessage += Utilities.CamelCaseToString(newInvoiceItem.Type.ToString()) + " revenue end date autoset to " + Utilities.DateToString(DateTime.Now) + ".";
						}

						if (alertMessage.Length > 0)
						{
							InvoiceItemsMessageLabel.Text = "* " + alertMessage;
							InvoiceItemsMessageLabel.Visible = true;
						}
						InvoiceItemDataHolderList.Add(new InvoiceItemDataHolder(newInvoiceItem));

						ViewState["InvoiceItemDataHolderList"] = InvoiceItemDataHolderList;
						SetupUnprocessedBanners();
					}
					catch (Exception)
					{ }
					finally
					{
						CalculateInvoiceItemVatAndTotals();
					}
				}
            }
        }
Esempio n. 4
0
		public void SetTotal_Test()
		{
			InvoiceItem ii = new InvoiceItem();
			ii.SetTotal(5.00m);
			
		}