using System;
using System.Collections.Generic;
using System.Text;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BS.Shared.Core;
using DevExpress.XtraReports.UI;

namespace BeWo.GpzBiberachReports
{
	[IDSpecificClass(Identifier = "Pflege")]
	public partial class RechnungPflege : XtraReport, IBeWoReport<ServiceInvoiceRO>
    {
		public RechnungPflege()
        {
            this.InitializeComponent();
        }

        public void SetReportDataSource(ServiceInvoiceRO pRO)
        {
			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.RecipientPoBox) && !String.IsNullOrEmpty(pRO.RecipientPoBox.Trim()))
	        {
		        sb.AppendLine(pRO.RecipientPoBox);
	        }
			if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown) && !String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown.Trim()))
			{
				sb.AppendLine("");
		        sb.AppendLine(pRO.RecipientPostCodeAndTown);
	        }

	        lblAddress.Text = sb.ToString();

	        decimal minutesGespraeche = 0;
			decimal betragGespraeche = 0;
			
			pRO.InvoiceNumber = String.Format("8200-{0}", pRO.InvoiceNumber);

	        if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
	        {
		        foreach (var p in pRO.ServiceInvoicePeriods)
		        {
			        
					if (p.ServiceInvoiceItems != null && p.ServiceInvoiceItems.Count > 0)
					{
						
						foreach (var i in p.ServiceInvoiceItems)
						{
							if (!String.IsNullOrEmpty(i.ServiceDescription))
							{
								
								i.Hours = i.Hours * 60;

								//if (i.ServiceDescription.ToLower().IndexOf("ET") >= 0)
								//{
								minutesGespraeche += i.Hours ?? 0;
								betragGespraeche += i.NetAmount ?? 0;
								//}
								
							}
							
						}
						
						

						cellGespraecheGesamt.Text = String.Format("{0:0} Minuten", minutesGespraeche);
						
						cellGespraecheBetrag.Text = String.Format("{0:c}", betragGespraeche);
						
					}    

		        }
		        
	        }

			cellBetrag.Text = pRO.GrossClaim;

	        this.bindingSource1.DataSource = pRO;
        }
    }
}