示例#1
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);
						}
					}
				}
			}
		}