using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using DevExpress.XtraReports.UI;

namespace CaritasUnnaWohnungslosenhilfe
{
    public partial class Stundenzettel : XtraReport, IBeWoReport<ServicesOverviewRO>
    {
        public Stundenzettel()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
			double minTotal = 0;

			if (pRO.Services != null)
			{
				List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();

				foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
				{
					if (s.IsBillable)
					{
						if (s.ServiceCategory.StartsWith("Direkt"))
						{
							minTotal += s.Minutes;
						}
						servicesBillable.Add(s);
					}
				}

				pRO.Services = servicesBillable;
			}
			MittelbareLeistungenReport subReport = xrSubreport1.ReportSource as MittelbareLeistungenReport;

			if (subReport != null)
				subReport.SetReportDataSource(pRO);
            bindingSource1.DataSource = pRO;
           // rechnungsDatum.Text = DateTime.Now.ToShortDateString();

			summeMinuten.Text = string.Format("{0:0.##}", minTotal);

            if (pRO.SupportConceptCostBearer != null)
                aktenzeichenLV.Text = pRO.SupportConceptCostBearer.CustomerReferenceNumber ?? string.Empty;

            bewilligteFLSW.Text = string.Format("{0:0.##}", pRO.ApprovedFLSPerWeek);
        }
    }
}
