Пример #1
0
        private void LoadScreenFromCredit()
        {
            if (CurrentCredit.K != 0)
            {
                this.CreditKTextBox.Text = CurrentCredit.K.ToString();
				this.CreditKValueLabel.Text = Utilities.LinkNewWindow(CurrentCredit.UrlReport(), CurrentCredit.K.ToString());
                Query InvoiceCreditQuery = new Query();
                InvoiceCreditQuery.QueryCondition = new Q(InvoiceCredit.Columns.CreditInvoiceK, CurrentCredit.K);
                InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(InvoiceCreditQuery);
                if (invoiceCreditSet.Count > 0)
                    InvoiceK = invoiceCreditSet[0].InvoiceK;

				this.TaxDateCal.Date = CurrentCredit.TaxDateTime;
				if (!CurrentCredit.TaxDateTime.Equals(DateTime.MinValue))
					this.TaxDateValueLabel.Text = CurrentCredit.TaxDateTime.ToString("dd/MM/yy");
				else
					this.TaxDateValueLabel.Text = "";

				this.SalesUserKHiddenTextBox.Text = CurrentCredit.SalesUsrK.ToString();
				if (CurrentCredit.SalesUsr != null)
					this.SalesUsrValueLabel.Text = CurrentCredit.SalesUsr.Link();
				else
					this.SalesUsrValueLabel.Text = "";
				this.SalesAmountTextBox.Text = CurrentCredit.SalesUsrAmount.ToString("c");
            }

			if (CurrentInvoice != null)
            {
				this.InvoiceKValueLabel.Text = Utilities.LinkNewWindow(CurrentInvoice.UrlReport(), CurrentInvoice.K.ToString());
                this.ViewInvoiceHyperLink.Visible = true;
				this.ViewInvoiceHyperLink.Text = "<nobr>View invoice #" + CurrentInvoice.K.ToString() + "</nobr>";
				this.ViewInvoiceHyperLink.NavigateUrl = CurrentInvoice.UrlAdmin();

				this.SalesUserKHiddenTextBox.Text = CurrentInvoice.SalesUsrK.ToString();
				if(CurrentInvoice.SalesUsr != null)
					this.SalesUsrValueLabel.Text = CurrentInvoice.SalesUsr.Link();
				else
					this.SalesUsrValueLabel.Text = "";
            }
            if (CurrentCredit.Promoter != null)
            {
                this.PromoterValueLabel.Text = CurrentCredit.Promoter.Link();
                this.PromoterKHiddenTextBox.Text = CurrentCredit.Promoter.K.ToString();
            }
            if (CurrentCredit.Usr != null)
            {
				this.UserValueLabel.Text = CurrentCredit.Usr.Link();
                this.UserKHiddenTextBox.Text = CurrentCredit.Usr.K.ToString();
            }
            if (CurrentCredit.ActionUsr != null)
            {
                this.ActionUserValueLabel.Text = CurrentCredit.ActionUsr.Link();
                this.ActionUserKHiddenTextBox.Text = CurrentCredit.ActionUsr.K.ToString();
            }
            else
            {
                this.ActionUserValueLabel.Text = "";
                this.ActionUserKHiddenTextBox.Text = "0";
            }
			this.PaidCheckBox.Checked = CurrentCredit.Paid;
			this.SetPaidImage(CurrentCredit.Paid);

            this.VATCodeTextBox.Text = CurrentCredit.VatCode.ToString();
            this.VATCodeNumberHiddenTextBox.Text = Convert.ToInt32(CurrentCredit.VatCode).ToString();
			
			this.CreatedDateTextBox.Text = CurrentCredit.CreatedDateTime.ToString("HH:mm dd/MM/yy");
                            
            // DateTime.MinValue is the equivalent of NULL for PaidDateTime
			if (CurrentCredit.PaidDateTime == DateTime.MinValue)
			{
				this.PaidDateTextBox.Text = "";
				this.PaidDateLabel.Visible = false;
			}
			else
			{
				this.PaidDateTextBox.Text = CurrentCredit.PaidDateTime.ToString("HH:mm dd/MM/yy");
				this.PaidDateLabel.Visible = true;
			}

            this.PriceTextBox.Text = CurrentCredit.Price.ToString("c");
            this.VATTextBox.Text = CurrentCredit.Vat.ToString("c");
            this.TotalTextBox.Text = CurrentCredit.Total.ToString("c");
            this.NotesAddOnlyTextBox.ReadOnlyTextBox.Text = CurrentCredit.Notes;

			this.CreateTransferHyperLink.NavigateUrl = CurrentCredit.UrlAdminCreateTransfer();
        }
Пример #2
0
		void BindPromoterItems()
		{
			if (CurrentBuyer is Promoter)
			{
				this.UserItemListPanel.Visible = false;
				this.BuyerItemListPanel.Visible = true;

				if (PaymentTypeIsCampaignCredits)
				{
					this.TotalCreditsRow.Visible = true;
					this.TotalCreditsAsMoneyRow.Visible = true;

					this.BuyerItemListColumn1HeaderLabel.Text = "Items";
					this.BuyerItemListColumn2HeaderLabel.Text = "";
					this.BuyerItemListColumn3HeaderLabel.Text = "Credits";
                    VatRow.Visible = true;
					VatLabel.Text = Utilities.MoneyToHTML(TotalVatOnCampaignCreditsAsMoney);

					invoiceTotalAsCampaignCredits = 0;
					bool showPerItemDiscount = false;
					double? fixedDiscount = null;
					foreach (CampaignCredit cc in CampaignCredits)
					{
						invoiceTotalAsCampaignCredits += -cc.Credits;
						if (fixedDiscount == null)
							fixedDiscount = cc.FixedDiscount;

						if (cc.FixedDiscount >= 0)
						{
							if (Math.Round(fixedDiscount.Value * 100, 2) != Math.Round(cc.FixedDiscount * 100, 2))
								showPerItemDiscount = true;
						}
					}
					double nonFixedCampaignCreditDiscount = CampaignCredit.GetDiscountForCredits(invoiceTotalAsCampaignCredits, CurrentPromoter);
					foreach (CampaignCredit cc in CampaignCredits)
					{
						HtmlTableRow invoiceTr = new HtmlTableRow();
						InvoicesBody.Controls.Add(invoiceTr);

						HtmlTableCell invoiceNameTd = new HtmlTableCell();
						invoiceNameTd.Style["background-color"] = "transparent";
						string discountHtml = "";
						if (showPerItemDiscount)
						{
							double discount = cc.FixedDiscount > 0 ? cc.FixedDiscount : nonFixedCampaignCreditDiscount;
							string percentageFormat = Math.Round(discount * 100, 2) == Convert.ToInt32(discount * 100) ? "P0" : "P2";
							discountHtml = " <small>(@ <nobr>" + discount.ToString(percentageFormat) + "</nobr> discount)</small>";
						}
						invoiceNameTd.InnerHtml = HttpUtility.HtmlEncode(cc.Description) + discountHtml;

						HtmlTableCell invoicePriceTd = new HtmlTableCell();
						invoicePriceTd.Align = "right";
						invoicePriceTd.Style["background-color"] = "transparent";

						HtmlTableCell emptyTd = new HtmlTableCell();
						emptyTd.Style["background-color"] = "transparent";
						emptyTd.InnerHtml = "&nbsp;";

						// credits are negative on the campaign credit list
						invoicePriceTd.InnerHtml = "<nobr>" + HttpUtility.HtmlEncode((-cc.Credits).ToString("N0")) + "</nobr>";

						invoiceTr.Cells.Add(invoiceNameTd);
						invoiceTr.Cells.Add(emptyTd);
						invoiceTr.Cells.Add(invoicePriceTd);
					}
				}
				else if (Invoices.Count == 1 && Invoices[0].K == 0)
				{
					this.TotalCreditsRow.Visible = false;
					this.TotalCreditsAsMoneyRow.Visible = false;

					this.BuyerItemListColumn1HeaderLabel.Text = "Invoice";
					this.BuyerItemListColumn2HeaderLabel.Text = "";
					this.BuyerItemListColumn3HeaderLabel.Text = "Price";
					VatLabel.Text = Utilities.MoneyToHTML(Invoices[0].Vat);
                    VatRow.Visible = true;

					foreach (InvoiceItemDataHolder iidh in Invoices[0].InvoiceItemDataHolderList)
					{
						HtmlTableRow invoiceTr = new HtmlTableRow();
						InvoicesBody.Controls.Add(invoiceTr);

						HtmlTableCell invoiceNameTd = new HtmlTableCell();
						invoiceNameTd.Style["background-color"] = "transparent";

						string percentageFormat = Math.Round(iidh.Discount * 100, 2) == Convert.ToInt32(iidh.Discount * 100) ? "P0" : "P2";
						string discountHtml = " <small>(@ <nobr>" + iidh.Discount.ToString(percentageFormat) + "</nobr> discount)</small>";
						invoiceNameTd.InnerHtml = HttpUtility.HtmlEncode(iidh.ShortDescription) + discountHtml;

						HtmlTableCell invoicePriceTd = new HtmlTableCell();
						invoicePriceTd.Align = "right";
						invoicePriceTd.Style["background-color"] = "transparent";

						HtmlTableCell emptyTd = new HtmlTableCell();
						emptyTd.Style["background-color"] = "transparent";
						emptyTd.InnerHtml = "&nbsp;";
						invoicePriceTd.InnerHtml = Utilities.MoneyToHTML(iidh.Price);

						invoiceTr.Cells.Add(invoiceNameTd);
						invoiceTr.Cells.Add(emptyTd);
						invoiceTr.Cells.Add(invoicePriceTd);
					}
				}
				else
				{
					this.TotalCreditsRow.Visible = false;
					this.TotalCreditsAsMoneyRow.Visible = false;

					foreach (InvoiceDataHolder idh in Invoices)
					{
						idh.Type = Invoice.Types.Invoice;

						HtmlTableRow itemsTr = new HtmlTableRow();
						HtmlTableRow invoiceTr = new HtmlTableRow();
						InvoicesBody.Controls.Add(invoiceTr);
						InvoicesBody.Controls.Add(itemsTr);

						itemsTr.ID = "PaymentItem" + idh.K;
						itemsTr.Style["display"] = "none";

						#region Name
						HtmlTableCell invoiceNameTd = new HtmlTableCell();
						invoiceNameTd.Style["background-color"] = "transparent";
						string invoiceHtml = "New invoice";
						if (idh.K > 0 && idh.PromoterK > 0)
							invoiceHtml = Utilities.LinkNewWindow(idh.UrlReport(), "Invoice #" + idh.K.ToString());
						invoiceNameTd.InnerHtml = "<a href=\"#\" onclick=\"var elem = document.getElementById('" + itemsTr.ClientID + "'); var img = document.getElementById('" + this.ClientID + "_PaymentPlusMinus" + idh.K + "'); img.src = elem.style.display == 'none' ? '/gfx/minus.gif' : '/gfx/plus.gif'; elem.style.display = elem.style.display == 'none' ? '' : 'none'; return false;\"><img id=\"" + this.ClientID + "_PaymentPlusMinus" + idh.K + "\" src=\"/gfx/plus.gif\" alt=\"Show items\" border=\"0\" align=\"absmiddle\" style=\"margin-right:4px;\" /></a>" + invoiceHtml;
						#endregion

						#region Total
						HtmlTableCell invoiceTotalTd = new HtmlTableCell();
						invoiceTotalTd.Align = "right";
						invoiceTotalTd.Style["background-color"] = "transparent";
						invoiceTotalTd.InnerHtml = Utilities.MoneyToHTML(idh.Total);
						#endregion

						#region Due
						HtmlTableCell invoiceDueTd = new HtmlTableCell();
						invoiceDueTd.Align = "right";
						invoiceDueTd.Style["background-color"] = "transparent";
						invoiceDueTd.InnerHtml = Utilities.MoneyToHTML(idh.AmountDue);
						#endregion

						invoiceTr.Cells.Add(invoiceNameTd);
						invoiceTr.Cells.Add(invoiceTotalTd);
						invoiceTr.Cells.Add(invoiceDueTd);

						HtmlTableCell itemsTd = new HtmlTableCell();
						itemsTd.Style["background-color"] = "transparent";
						itemsTd.Style["padding"] = "0px";
						itemsTd.Style["padding-left"] = "14px";
						itemsTd.Style["width"] = "279px";
						itemsTd.ColSpan = 3;
						itemsTd.Align = "right";

						#region Items table
						StringBuilder sb = new StringBuilder();
						sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
						foreach (InvoiceItemDataHolder iidh in idh.InvoiceItemDataHolderList)
						{
							sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>");
							sb.Append(iidh.Description);
							sb.Append("</small></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>");
							// Show IncVat for Promoters and other users. As per David Brophy on Oct 24, 2006
							// Show ExVat for all, then add VAT as its own line item after all invoice items. this is for OASIS v1.5, Dec 12, 2006
							sb.Append(Utilities.MoneyToHTML(iidh.Price));
							sb.Append("</small></td></tr>");
						}

						VatLabel.Text = Utilities.MoneyToHTML(idh.Vat);

						//sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>VAT</small></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>");
						//sb.Append();
						//sb.Append("</nobr></small></td></tr>");

						// Only if the some money has been paid or credited, then we go to DB to get successful transfer applied
						if (idh.AmountDue != idh.Total)
						{
							Query invoiceTransferQuery = new Query();
							invoiceTransferQuery.QueryCondition = new And(new Q(InvoiceTransfer.Columns.InvoiceK, idh.K),
																		  new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success));
							invoiceTransferQuery.TableElement = new Join(InvoiceTransfer.Columns.TransferK, Transfer.Columns.K, QueryJoinType.Inner);
							invoiceTransferQuery.Columns = new ColumnSet(InvoiceTransfer.Columns.Amount, InvoiceTransfer.Columns.TransferK, Transfer.Columns.Type);

							InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(invoiceTransferQuery);
							decimal invoiceTransferTotal = 0;
							foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet)
							{
								decimal amount = invoiceTransfer.Amount;
								if (((Transfer.TransferTypes)invoiceTransfer.ExtraSelectElements["Transfer_Type"]).Equals(Transfer.TransferTypes.Payment))
									amount = -1 * Math.Abs(amount);
								else
									amount = Math.Abs(amount);
								sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>Transfer #");
								sb.Append(invoiceTransfer.TransferK.ToString());
								sb.Append("</nobr></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>");
								sb.Append(Utilities.MoneyToHTML(amount));
								sb.Append("</small></td></tr>");

								invoiceTransferTotal += invoiceTransfer.Amount;
							}

							// Test if there is still money unaccounted for, then go to DB for credits applied
							if (invoiceTransferTotal + idh.AmountDue < idh.Total)
							{
								Query invoiceCreditQuery = new Query();
								invoiceCreditQuery.QueryCondition = new Q(InvoiceCredit.Columns.InvoiceK, idh.K);
								invoiceCreditQuery.Columns = new ColumnSet(InvoiceCredit.Columns.Amount, InvoiceCredit.Columns.CreditInvoiceK);

								InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(invoiceCreditQuery);

								foreach (InvoiceCredit invoiceCredit in invoiceCreditSet)
								{
									sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>Credit #");
									sb.Append(invoiceCredit.CreditInvoiceK.ToString());
									sb.Append("</nobr></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>");
									sb.Append(Utilities.MoneyToHTML(invoiceCredit.Amount));
									sb.Append("</small></td></tr>");
								}
							}
						}

						sb.Append("</table>");
						#endregion

						//if (idh.K == 0)
						itemsTd.InnerHtml = sb.ToString();
						itemsTr.Cells.Add(itemsTd);
					}
				}
			}
		}
Пример #3
0
		public StringBuilder GenerateReportStringBuilder(bool linksEnabled)
		{
			DateTime taxDate = DateTime.Now;
			if (this.TaxDateTime != null && this.TaxDateTime > DateTime.MinValue)
				taxDate = this.TaxDateTime;


			StringBuilder sb = new StringBuilder();
			decimal amountPaid = 0;

			sb.Append(@"<form id='form1' runat='server'><div style='font-family:Verdana;'><table width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><tr><td valign='top'>
						<table width='100%'>");

			sb.Append(Utilities.GenerateHTMLHeaderRowString(this.Type.Equals(Invoice.Types.Credit) ? this.TypeToString.ToUpper() + "&nbsp;NOTE" : this.TypeToString.ToUpper()));

			sb.Append(@"<tr>
								<td colspan=1 align='left' valign='top' width='450' style='padding-left:48px;'>");
            if (this.Promoter != null)
            {
                if (this.Promoter.AccountsName.Length > 0)
                {
                    sb.Append(this.Promoter.AccountsName);
                    sb.Append("<br>");
                }
                else if (this.Usr != null && this.Usr.FullName.Length > 0 && this.Usr.IsPromoter && this.Usr.IsPromoterK(this.K))
                {
                    sb.Append(this.Usr.FullName);
                    sb.Append("<br>");
                }
                else if (this.Promoter.PrimaryUsr != null && this.Promoter.PrimaryUsr.FullName.Length > 0)
                {
                    sb.Append(this.Promoter.PrimaryUsr.FullName);
                    sb.Append("<br>");
                }

                if (this.Promoter.Name.Length > 0)
                {
                    sb.Append(this.Promoter.Name);
                    sb.Append("<br>");
                }
                sb.Append(this.Promoter.AddressHtml);
            }
            else if (this.Usr != null)
            {
                if (this.Usr.FullName.Length > 0)
                {
                    sb.Append(this.Usr.FullName);
                    sb.Append("<br>");
                }
                sb.Append(this.Usr.AddressHtml());
            }

			// Addition of Created and renaming of "Date" to "Tax Date", as per Dave's request 7/2/07
			sb.Append(@"</td><td width='350'></td><td valign='top' width='100'>" + this.TypeToString + "&nbsp;No.");
			if (this.PurchaseOrderNumber.Length > 0)
				sb.Append("<br><br>Purchase&nbsp;Order&nbsp;No.");
			sb.Append("<br><br>Acc&nbsp;No.<br><br>Created<br><br>Tax&nbsp;Date");
			if (this.Type.Equals(Invoice.Types.Invoice))
				sb.Append("<br><br>Due Date");
			sb.Append(@"</td><td align='right' valign='top' width='125'>");

			if (this.Type.Equals(Invoice.Types.Invoice))
				sb.Append("INV");
			else
				sb.Append("CRD");

			sb.Append(this.K.ToString());
			if (this.PurchaseOrderNumber.Length > 0)
				sb.Append("<br><br><nobr>" + this.PurchaseOrderNumber.Replace("-", "&#8209;"));
			sb.Append("</nobr><br><br>");
			if (this.Promoter != null)
				sb.Append(this.PromoterK.ToString());
			else if (this.Usr != null)
				sb.Append(this.UsrK.ToString());
			else
				sb.Append("&nbsp;");

			// Addition of Created, as per Dave's request 7/2/07
			sb.Append("<br><br>");
			sb.Append(this.CreatedDateTime.ToString("dd/MM/yy"));

			sb.Append("<br><br>");

			// Replacing CreatedDateTime with TaxDateTime, as per Gee's request for OASIS v1.5
			//sb.Append(this.CreatedDateTime.ToString("dd/MM/yy"));
			sb.Append(this.TaxDateTime.ToString("dd/MM/yy"));

			if (this.Type.Equals(Invoice.Types.Invoice))
			{
				sb.Append("<br><br>");
				sb.Append(this.DueDateTime.ToString("dd/MM/yy"));
			}
			sb.Append("</td></tr>");

			//if(this.PaidDateTime != null && this.PaidDateTime > DateTime.MinValue)
			//{
			//    sb.Append(@"<br><br><b>Date Completed</b><br>" + this.PaidDateTime.ToShortDateString());
			//}

			sb.Append(@"</table><br><br>
						<table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Right Bottom'>
							<tr>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='350'><b>Item</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='55' align='left'><b>Tax&nbsp;Code</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Price</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85' align='left'><b>VAT</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Total</b></td>
							</tr>");

			Query InvoiceItemQuery = new Query(new Q(InvoiceItem.Columns.InvoiceK, this.K));
			InvoiceItemSet invoiceItemSet = new InvoiceItemSet(InvoiceItemQuery);

			List<InvoiceItem.VATCodes> invoiceItemVatCodes = new List<InvoiceItem.VATCodes>();

			foreach (InvoiceItem invoiceItem in invoiceItemSet)
			{
				if (!invoiceItemVatCodes.Contains(invoiceItem.VatCode))
					invoiceItemVatCodes.Add(invoiceItem.VatCode);

				sb.Append(@"<tr>
								<td class='BorderBlack Left'>" + invoiceItem.Description +
								(invoiceItem.Discount > 0 ? " <small>@ " + invoiceItem.Discount.ToString("P2") + " discount</small>" : "") +
								@"</td>");

				if (!this.VatCode.Equals(Invoice.VATCodes.T1))
				{
					sb.Append(@"<td class='BorderBlack Left' width='55' align='left'>" + this.VatCode.ToString() + @"</td>");
				}
				else
				{
					sb.Append(@"<td class='BorderBlack Left' width='55' align='left'>" + invoiceItem.VatCode.ToString() + @"</td>");
				}

				sb.Append(@"<td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoiceItem.Price) + @"</td>
							<td class='BorderBlack Left' width='85' align='right'>" + Utilities.MoneyToHTML(invoiceItem.Vat) + @"</td>
							<td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoiceItem.Total) + @"</td>
						</tr>");
			}

			sb.Append(@"<tr>
							<td class='BorderBlack Top Left' colspan='2' align='right'><b>TOTAL:</b></td>
							<td class='BorderBlack Top Left' width='90' align='right'><b>" + Utilities.MoneyToHTML(this.Price) + @"</b></td>
							<td class='BorderBlack Top Left' width='85' align='right'><b>" + Utilities.MoneyToHTML(this.Vat) + @"</b></td>
							<td class='BorderBlack Top Left' width='90' align='right'><b>" + Utilities.MoneyToHTML(this.Total) + @"</b></td>
						</tr></table>");

			InvoiceItem.VATCodes[] invoiceItemVatCodeArray = invoiceItemVatCodes.ToArray();
			Array.Sort(invoiceItemVatCodeArray);

			sb.Append("<small><i><b>VAT Rate:</b> ");
			if (this.VatCode.Equals(Invoice.VATCodes.T1) && invoiceItemVatCodeArray.Length > 0)
			{
				foreach (InvoiceItem.VATCodes vatCode in invoiceItemVatCodeArray)
				{
					sb.Append(vatCode.ToString());
					sb.Append("=");
					sb.Append(InvoiceItem.VATRate(vatCode, taxDate).ToString("0.0%"));
					sb.Append("&nbsp;&nbsp;");
				}
			}
			else
			{
				sb.Append(this.VatCode.ToString());
				sb.Append("=");
				sb.Append(Invoice.VATRate(this.VatCode, taxDate).ToString("0.0%"));
			}
			sb.Append("</i></small><br>");

			sb.Append("<br>");

			Query InvoiceTransferQuery = new Query(new And(new Q(InvoiceTransfer.Columns.InvoiceK, this.K),
														   new Or(new Q(Transfer.Columns.Status, Transfer.StatusEnum.Pending),
																  new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success),
																  new Q(Transfer.Columns.Status, Transfer.StatusEnum.Cancelled))));
			InvoiceTransferQuery.TableElement = new Join(InvoiceTransfer.Columns.TransferK, Transfer.Columns.K);
			InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(InvoiceTransferQuery);

			bool nonSuccessfulTransfer = false;

			if (invoiceTransferSet.Count > 0)
			{
				sb.Append(@"<br><table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Right Bottom'>
							<tr>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='205'><b>Transfer</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='65' align='left'><b>Date</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='75' align='left'><b>Method</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='150' align='left'><b>Method Ref#</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Status</b></td>
								<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85' align='left'><b>Amount</b></td>
							</tr>");

				foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet)
				{
					Transfer transfer = new Transfer(invoiceTransfer.TransferK);

					sb.Append(@"<tr>
								<td class='BorderBlack Left'>");
					if (linksEnabled)
						sb.Append(Utilities.Link(transfer.UrlReport(), transfer.Type.ToString() + " #" + transfer.K.ToString()));
					else
						sb.Append(transfer.Type.ToString() + " #" + transfer.K.ToString());

					sb.Append(@"</td>
								<td class='BorderBlack Left' width='65' align='left'>" + transfer.DateTimeCreated.ToString("dd/MM/yy") + @"</td>
								<td class='BorderBlack Left' width='75' align='left'><nobr>" + Utilities.CamelCaseToString(transfer.Method.ToString()) + @"</nobr></td>
								<td class='BorderBlack Left' width='150' align='left'>");

					sb.Append(transfer.ReferenceNumberToHtml());

					sb.Append(@"</td>
								<td class='BorderBlack Left' width='90' align='left'>" + transfer.Status.ToString() + @"</td>
								<td class='BorderBlack Left' width='85' align='right'>" + Utilities.MoneyToHTML(invoiceTransfer.Amount) + @"</td>
							</tr>");

					if (!transfer.Status.Equals(Transfer.StatusEnum.Success))
						nonSuccessfulTransfer = true;
					else
						amountPaid += invoiceTransfer.Amount;
				}

				sb.Append(@"</table>");

				// For now, this note only pertains to Invoices
				if (this.Type.Equals(Invoice.Types.Invoice) && nonSuccessfulTransfer == true)
					sb.Append(@"<small><i>(<b>Note:</b> Only successful transfers will be applied to the payment total. Pending and cancelled transfers will not be applied)</i></small><br>");

				sb.Append("<br>");
			}

			Query InvoiceCreditQuery = new Query();

			if (this.Type.Equals(Invoice.Types.Invoice))
			{
				InvoiceCreditQuery = new Query(new Q(InvoiceCredit.Columns.InvoiceK, this.K));
			}
			else
			{
				InvoiceCreditQuery = new Query(new Q(InvoiceCredit.Columns.CreditInvoiceK, this.K));
			}

			InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(InvoiceCreditQuery);

			if (invoiceCreditSet.Count > 0)
			{
				string invoiceHeader = "Invoice";
				Invoice invoice = new Invoice();

				if (this.Type.Equals(Invoice.Types.Invoice))
					invoiceHeader = "Credit";

				sb.Append(@"<br><table width='100%' cellspacing='0' cellpadding='3' class='BorderBlack Top Bottom Right'>
						<tr>
							<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='335'><b>" + invoiceHeader + @"</b></td>
							<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='70' align='left'><b>Date</b></td>
							<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Price</b></td>
							<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='85' align='left'><b>VAT</b></td>
							<td style='vertical-align:bottom;' class='BorderBlack Bottom Left' width='90' align='left'><b>Total</b></td>
						</tr>");

				foreach (InvoiceCredit invoiceCredit in invoiceCreditSet)
				{
					if (this.Type.Equals(Invoice.Types.Invoice))
					{
						// Credit amounts are negative
						amountPaid -= invoiceCredit.Amount;

						invoice = new Invoice(invoiceCredit.CreditInvoiceK);
					}
					else
						invoice = new Invoice(invoiceCredit.InvoiceK);

					sb.Append(@"<tr>
							<td class='BorderBlack Left'>");
					if (linksEnabled)
						sb.Append(Utilities.Link(invoice.UrlReport(), invoiceHeader + " #" + invoice.K.ToString()));
					else
						sb.Append(invoiceHeader + " #" + invoice.K.ToString());

					// Replacing CreatedDateTime with TaxDateTime, as per Gee's request for OASIS v1.5
					sb.Append(@"</td>
							<td class='BorderBlack Left' width='70' align='left'>" + invoice.TaxDateTime.ToString("dd/MM/yy") + @"</td>
							<td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoice.Price) + @"</td>
							<td class='BorderBlack Left' width='85' align='right'>" + Utilities.MoneyToHTML(invoice.Vat) + @"</td>
							<td class='BorderBlack Left' width='90' align='right'>" + Utilities.MoneyToHTML(invoice.Total) + @"</td>
						</tr>");
				}
				sb.Append(@"</table><br><br>");
			}

			if (this.Type.Equals(Invoice.Types.Invoice))
			{
				// Invoice Summary
				sb.Append(@"<br><table width='250'>
							<tr>
								<td colspan=2><b>Summary</b></td>
							</tr>
							<tr>
								<td width='135'>Invoice&nbsp;Total:</td>
								<td width='115' align='right'>" + Utilities.MoneyToHTML(this.Total) + @"</td>
							</tr>
							<tr>
								<td width='135'>Payment&nbsp;Total:</td>
								<td width='115' align='right'>" + Utilities.MoneyToHTML(amountPaid) + @"</td>
							</tr>
							<tr>
								<td width='135'><b>Outstanding:</b></td>                                
								<td width='115' align='right'><b>" + Utilities.MoneyToHTML(this.Total - amountPaid) + @"</b></td>
							</tr></table><br><br>");
			}

			sb.Append(@"</td></tr>");

			sb.Append(@"
<tr>
	<td valign='bottom' align='center'>
		<div style='width:50%;padding:20px;border:2px solid #000000;text-align:left;'>
			Bank details for payments:<br>
			Development Hell Limited<br>
			Barlcays Bank PLC, Commercial Bank Basingstoke<br>
			Sort Code: 20-37-63<br>
			Account number: 00478377<br>
			For international payments:<br>
			IBAN - GB04BARC20376300478377<br>
			Swift - BARCGB22
		</div>
	</td>
</tr>");

			// DSI Registration Footer
			sb.Append(Utilities.GenerateHTMLFooterRowString());

			sb.Append(@"</table></div></form>");

			return sb;
		}
Пример #4
0
		protected void SetupTransferButton_Click(object sender, EventArgs e)
		{
			SetupAllOutstandingInvoices();

			SetupPayment.Reset();

			List<int> invoiceKList = new List<int>();

			// Loop through Repeater dataset, get all checked, and pass those K's to the payment screen
			foreach (RepeaterItem rpi in this.PromoterAccountItemRepeater.Items)
			{
				CheckBox outstandingCheckBox = (CheckBox)rpi.FindControl("OutstandingCheckBox");
				if (outstandingCheckBox.Checked == true)
				{
					Label invoiceKLabel = (Label)rpi.FindControl("InvoiceKLabel");
					invoiceKList.Add(Convert.ToInt32(invoiceKLabel.Text));
				}
			}

			foreach (int invoiceK in invoiceKList)
			{
				Invoice invoice = new Invoice(invoiceK);

				InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(new Query(new Q(InvoiceCredit.Columns.InvoiceK, invoice.K)));
				InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(new Query(new Q(InvoiceTransfer.Columns.InvoiceK, invoice.K)));
				var total = invoice.Total;
				var vat = invoice.Vat;
				var price = invoice.Price;

				foreach (InvoiceCredit invoiceCredit in invoiceCreditSet)
				{
					Invoice credit = new Invoice(invoiceCredit.CreditInvoiceK);
					//price += credit.Price;
					//vat += credit.Vat;
					total += credit.Total;
				}
				foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet)
				{
					Transfer transfer = new Transfer(invoiceTransfer.TransferK);
					if (transfer.Status.Equals(Transfer.StatusEnum.Success))
					{
						total -= transfer.Amount;
					}
				}
				InvoiceDataHolder idh = new InvoiceDataHolder(invoice);
				//idh.K = 0;
				this.SetupPayment.Invoices.Add(idh);

			}
			this.SetupPayment.PromoterK = CurrentPromoter.K;
			this.SummaryPanel.Visible = false;
			this.SetupTransferPanel.Visible = true;

	//		this.SetupPayment.Initialize();
		}
Пример #5
0
		void BindPromoterItems()
		{
			if (PromoterK > 0)
			{
				this.PromoterItemListPanel.Visible = true;

				if (Invoices.Count == 1 && Invoices[0].K == 0)
				{
					this.PromoterItemListColumn2HeaderLabel.Text = "";
					this.PromoterItemListColumn3HeaderLabel.Text = "Price";

					foreach (InvoiceItemDataHolder iidh in Invoices[0].InvoiceItemDataHolderList)
					{
						//HtmlTableRow itemsTr = new HtmlTableRow();
						HtmlTableRow invoiceTr = new HtmlTableRow();
						InvoicesBody.Controls.Add(invoiceTr);
						//InvoicesBody.Controls.Add(itemsTr);

						//itemsTr.ID = "PaymentItem" + idh.K;
						//itemsTr.Style["display"] = "none";

						#region Name
						HtmlTableCell invoiceNameTd = new HtmlTableCell();
						invoiceNameTd.Style["background-color"] = "transparent";
						invoiceNameTd.InnerHtml = iidh.Description;
						#endregion

						#region Price
						HtmlTableCell invoicePriceTd = new HtmlTableCell();
						invoicePriceTd.Align = "right";
						invoicePriceTd.Style["background-color"] = "transparent";
						invoicePriceTd.InnerHtml = iidh.Price.ToString("c");
						#endregion

						#region Empty HtmlTableCell
						HtmlTableCell emptyTd = new HtmlTableCell();
						emptyTd.Style["background-color"] = "transparent";
						emptyTd.InnerHtml = "&nbsp;";
						#endregion

						invoiceTr.Cells.Add(invoiceNameTd);
						invoiceTr.Cells.Add(emptyTd);
						invoiceTr.Cells.Add(invoicePriceTd);

						//if (idh.K == 0)

						//    itemsTd.InnerHtml = sb.ToString();
						//itemsTr.Cells.Add(itemsTd);
					}

					HtmlTableRow vatTr = new HtmlTableRow();
					InvoicesBody.Controls.Add(vatTr);
					vatTr.ID = "PaymentVATTotal";

					#region Empty HtmlTableCell
					HtmlTableCell emptyVatTd = new HtmlTableCell();
					emptyVatTd.Style["background-color"] = "transparent";
					emptyVatTd.InnerHtml = "&nbsp;";
					#endregion

					#region VAT Name
					HtmlTableCell vatNameTd = new HtmlTableCell();
					vatNameTd.Style["background-color"] = "transparent";
					vatNameTd.Align = "right";
					vatNameTd.InnerHtml = "VAT";
					#endregion

					#region VAT Total
					HtmlTableCell vatTotalTd = new HtmlTableCell();
					vatTotalTd.Align = "right";
					vatTotalTd.Style["background-color"] = "transparent";
					vatTotalTd.InnerHtml = Invoices[0].Vat.ToString("c");
					#endregion

					vatTr.Cells.Add(emptyVatTd);
					vatTr.Cells.Add(vatNameTd);
					vatTr.Cells.Add(vatTotalTd);
				}
				else
				{
					foreach (InvoiceDataHolder idh in Invoices)
					{
						HtmlTableRow itemsTr = new HtmlTableRow();
						HtmlTableRow invoiceTr = new HtmlTableRow();
						InvoicesBody.Controls.Add(invoiceTr);
						InvoicesBody.Controls.Add(itemsTr);

						itemsTr.ID = "PaymentItem" + idh.K;
						itemsTr.Style["display"] = "none";

						#region Name
						HtmlTableCell invoiceNameTd = new HtmlTableCell();
						invoiceNameTd.Style["background-color"] = "transparent";
						string invoiceHtml = "New invoice";
						if (idh.K > 0 && idh.PromoterK > 0)
                            invoiceHtml = Utilities.LinkNewWindow(idh.UrlReport(), "Invoice #" + idh.K.ToString());
						invoiceNameTd.InnerHtml = "<a href=\"#\" onclick=\"var elem = document.getElementById('" + itemsTr.ClientID + "'); var img = document.getElementById('" + this.ClientID + "_PaymentPlusMinus" + idh.K + "'); img.src = elem.style.display == 'none' ? '/gfx/minus.gif' : '/gfx/plus.gif'; elem.style.display = elem.style.display == 'none' ? '' : 'none'; return false;\"><img id=\"" + this.ClientID + "_PaymentPlusMinus" + idh.K + "\" src=\"/gfx/plus.gif\" alt=\"Show items\" border=\"0\" align=\"absmiddle\" style=\"margin-right:4px;\" /></a>" + invoiceHtml;
						#endregion

						#region Total
						HtmlTableCell invoiceTotalTd = new HtmlTableCell();
						invoiceTotalTd.Align = "right";
						invoiceTotalTd.Style["background-color"] = "transparent";
						invoiceTotalTd.InnerHtml = idh.Total.ToString("c");
						#endregion

						#region Due
						HtmlTableCell invoiceDueTd = new HtmlTableCell();
						invoiceDueTd.Align = "right";
						invoiceDueTd.Style["background-color"] = "transparent";
						invoiceDueTd.InnerHtml = idh.AmountDue.ToString("c");
						#endregion

						invoiceTr.Cells.Add(invoiceNameTd);
						invoiceTr.Cells.Add(invoiceTotalTd);
						invoiceTr.Cells.Add(invoiceDueTd);

						HtmlTableCell itemsTd = new HtmlTableCell();
						itemsTd.Style["background-color"] = "transparent";
						itemsTd.Style["padding"] = "0px";
						itemsTd.Style["padding-left"] = "14px";
						itemsTd.Style["width"] = "376px";
						itemsTd.ColSpan = 3;
						itemsTd.Align = "right";

						#region Items table
						StringBuilder sb = new StringBuilder();
						sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
						foreach (InvoiceItemDataHolder iidh in idh.InvoiceItemDataHolderList)
						{
							sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>");
							sb.Append(iidh.Description);
							sb.Append("</small></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>");
							// Show IncVat for Promoters and other users. As per David Brophy on Oct 24, 2006
							// Show ExVat for all, then add VAT as its own line item after all invoice items. this is for OASIS v1.5, Dec 12, 2006
							sb.Append(iidh.Price.ToString("c"));
							sb.Append("</nobr></small></td></tr>");
						}

						sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small>VAT</small></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>");
						sb.Append(idh.Vat.ToString("c"));
						sb.Append("</nobr></small></td></tr>");

						// Only if the some money has been paid or credited, then we go to DB to get successful transfer applied
						if (idh.AmountDue != idh.Total)
						{
							Query invoiceTransferQuery = new Query();
							invoiceTransferQuery.QueryCondition = new And(new Q(InvoiceTransfer.Columns.InvoiceK, idh.K),
																		  new Q(Transfer.Columns.Status, Transfer.StatusEnum.Success));
							invoiceTransferQuery.TableElement = new Join(InvoiceTransfer.Columns.TransferK, Transfer.Columns.K, QueryJoinType.Inner);
							invoiceTransferQuery.Columns = new ColumnSet(InvoiceTransfer.Columns.Amount, InvoiceTransfer.Columns.TransferK, Transfer.Columns.Type);

							InvoiceTransferSet invoiceTransferSet = new InvoiceTransferSet(invoiceTransferQuery);
							decimal invoiceTransferTotal = 0;
							foreach (InvoiceTransfer invoiceTransfer in invoiceTransferSet)
							{
								decimal amount = invoiceTransfer.Amount;
								if (((Transfer.TransferTypes)invoiceTransfer.ExtraSelectElements["Transfer_Type"]).Equals(Transfer.TransferTypes.Payment))
									amount = -1 * Math.Abs(amount);
								else
									amount = Math.Abs(amount);
								sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>Transfer #");
								sb.Append(invoiceTransfer.TransferK.ToString());
								sb.Append("</nobr></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>");
								sb.Append(amount.ToString("c"));
								sb.Append("</nobr></small></td></tr>");

								invoiceTransferTotal += invoiceTransfer.Amount;
							}

							// Test if there is still money unaccounted for, then go to DB for credits applied
							if (invoiceTransferTotal + idh.AmountDue < idh.Total)
							{
								Query invoiceCreditQuery = new Query();
								invoiceCreditQuery.QueryCondition = new Q(InvoiceCredit.Columns.InvoiceK, idh.K);
								invoiceCreditQuery.Columns = new ColumnSet(InvoiceCredit.Columns.Amount, InvoiceCredit.Columns.CreditInvoiceK);

								InvoiceCreditSet invoiceCreditSet = new InvoiceCreditSet(invoiceCreditQuery);

								foreach (InvoiceCredit invoiceCredit in invoiceCreditSet)
								{
									sb.Append("<tr><td align=\"left\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>Credit #");
									sb.Append(invoiceCredit.CreditInvoiceK.ToString());
									sb.Append("</nobr></td><td align=\"right\" style=\"background-color:transparent;padding-top:1px;padding-bottom:1px;\"><small><nobr>");
									sb.Append(invoiceCredit.Amount.ToString("c"));
									sb.Append("</nobr></small></td></tr>");
								}
							}
						}

						sb.Append("</table>");
						#endregion

						//if (idh.K == 0)
						itemsTd.InnerHtml = sb.ToString();
						itemsTr.Cells.Add(itemsTd);

					}
				}
				InvoiceTotalLabel.Text = InvoiceTotal.ToString("c");
			}
		}