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

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

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
	        bool hatKKontakte = false;
			Dictionary<String, ServicesOverviewRO.ServiceDetail> dict = new Dictionary<string, ServicesOverviewRO.ServiceDetail>();
			Dictionary<String, ServicesOverviewRO.ServiceDetail> dictKK = new Dictionary<string, ServicesOverviewRO.ServiceDetail>();
			if (pRO.Services != null)
			{
				foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
				{
					if (s.IsBillable)
					{
						if (dict.ContainsKey(s.ServiceDescription))
						{
							dict[s.ServiceDescription].Minutes += s.Minutes;
						}
						else
						{
							dict.Add(s.ServiceDescription, s);
						}
					}
					else
					{
						if (dictKK.ContainsKey(s.ServiceDescription))
						{
							dictKK[s.ServiceDescription].Minutes += s.Minutes;
						}
						else
						{
							dictKK.Add(s.ServiceDescription, s);
						}
					}
				}

				
			}
	        pRO.Services = dict.Values.OrderBy(s => s.ServiceDescription).ToList();
            bindingSource1.DataSource = pRO;

			if (dictKK.Count == 0)
	        {
		        GroupFooter1.Visible = false;
	        }
	        else
	        {
				var subReport = xrSubreport1.ReportSource as QuittierungsbelegJAHammKooperationsKontakte;

				ServicesOverviewRO roKK = new ServicesOverviewRO();
				roKK.Services = dictKK.Values.OrderBy(s => s.ServiceDescription).ToList();
				if (subReport != null)
					subReport.SetReportDataSource(roKK);
	        }
        }
    }
}
