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

namespace BeWo.Report.DerKarren
{
    public partial class Leistungen : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServiceRecordListRO>
    {
        public Leistungen()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(ServiceRecordListRO pRO)
        {
			if (pRO.Statistics == null || pRO.Statistics.Count == 0)
				Detail2.Visible = false;

            decimal total = 0;
            Dictionary<String, decimal> zielZuMinuten = new Dictionary<String, decimal>();

            if (pRO.ServiceRecordDetailList != null)
            {
                foreach (var sr in pRO.ServiceRecordDetailList)
                {
                    
                    

                    sr.Goals = "";
                    foreach (var goalPath in sr.GoalPaths)
                    {

                        if (!zielZuMinuten.ContainsKey(goalPath))
                        {
                            zielZuMinuten.Add(goalPath, 0);
                        }
                        if (sr.IsBillable)
                        {
                            zielZuMinuten[goalPath] += sr.RoundedDuration;
                        }
                        if (sr.Goals.Length > 0)
                        {
                            sr.Goals += Environment.NewLine;
                        }
                        sr.Goals += goalPath;
                    }
                    if (sr.IsBillable)
                    {
                        total += sr.RoundedDuration;
                    }
                }
            }

            StringBuilder sb = new StringBuilder();
            foreach (var ziel in zielZuMinuten.Keys.OrderBy(k => k))
            {
                decimal minuten = zielZuMinuten[ziel];

                decimal prozent = (minuten/total)*100;

                sb.AppendLine(String.Format("{0}: {1:0.00}%", ziel, prozent));

            }
            lblZielVerteilung.Text = sb.ToString();

            this.bindingSource1.DataSource = pRO;
        }
    }
}
