using System;
using System.Collections.Generic;
using System.Text;
using BeWo.Report;
using BeWo.Report.ReportObjects;

using DevExpress.XtraReports.UI;

namespace BeWo.Club74
{
    public partial class ServiceInvoiceReport : XtraReport, IBeWoReport<ServiceInvoiceRO>
    {
        public ServiceInvoiceReport()
        {
            this.InitializeComponent();
        }

        public void SetReportDataSource(ServiceInvoiceRO pRO)
        {
			DateTime start = pRO.AccountingPeriodStart;
			DateTime end = pRO.AccountingPeriodEnd;
			if (start.Month == end.Month && start.Year == end.Year)
			{
				lblAbrechnungszeitraum.Text = String.Format("hiermit berechnen wir für den Monat {0:MMMM yyyy} folgende erbrachte Tätigkeiten:", start);
			}
			else
			{
				lblAbrechnungszeitraum.Text = String.Format("hiermit berechnen wir für den Zeitraum {0:MMMM yyyy} - {1:MMMM yyyy} folgende erbrachte Tätigkeiten:", start, end);
			}

	        if (String.IsNullOrWhiteSpace(pRO.Notice))
	        {
		        lblBemerkung.Visible = false;
	        }

			
			//Dictionary<decimal, ServiceInvoiceItemRO> itemByHourlyRate = new Dictionary<decimal, ServiceInvoiceItemRO>();

			//List<ServiceInvoicePeriodRO> newPeriodList = new List<ServiceInvoicePeriodRO>();

			//if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
			//{
			//	ServiceInvoicePeriodRO newPeriod = new ServiceInvoicePeriodRO();
			//	newPeriod.ServiceInvoiceItems = new List<ServiceInvoiceItemRO>();
			//	newPeriodList.Add(newPeriod);


			//	decimal anzahlStunden = 0;
			//	decimal betrag = 0;
			//	decimal gesamt = 0;

			//	foreach (var sip in pRO.ServiceInvoicePeriods)
			//	{
			//		if (sip.ServiceInvoiceItems != null)
			//		{
			//			foreach (var ii in sip.ServiceInvoiceItems)
			//			{
			//				decimal hourlyRate = ii.HourlyRate ?? 0;

			//				ServiceInvoiceItemRO newItem = null;
			//				if (itemByHourlyRate.ContainsKey(hourlyRate))
			//				{
			//					newItem = itemByHourlyRate[hourlyRate];
			//				}
			//				else
			//				{
			//					newItem = new ServiceInvoiceItemRO();
			//					newItem.HourlyRate = hourlyRate;
			//					newItem.Hours = 0;
			//					newItem.RateFactor = ii.RateFactor;
			//					newItem.NetAmount = 0;

			//					newPeriod.ServiceInvoiceItems.Add(newItem);
			//				}

							
			//			}
			//		}
			//	}
			//}
			//pRO.ServiceInvoicePeriods = newPeriodList;


			StringBuilder sb = new StringBuilder();
			if (!String.IsNullOrEmpty(pRO.RecipientOrganisation) && !String.IsNullOrEmpty(pRO.RecipientOrganisation.Trim()))
			{
				sb.AppendLine(pRO.RecipientOrganisation);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientContactPerson) && !String.IsNullOrEmpty(pRO.RecipientContactPerson.Trim()))
			{
				sb.AppendLine(pRO.RecipientContactPerson);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientDivision) && !String.IsNullOrEmpty(pRO.RecipientDivision.Trim()))
			{
				sb.AppendLine(pRO.RecipientDivision);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientStreet) && !String.IsNullOrEmpty(pRO.RecipientStreet.Trim()))
			{
				sb.AppendLine(pRO.RecipientStreet);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown) && !String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown.Trim()))
			{
				sb.AppendLine(pRO.RecipientPostCodeAndTown);
			}

			lblAddress.Text = sb.ToString();

            this.bindingSource1.DataSource = pRO;
        }
    }
}