using System;
using System.Collections;
using System.ComponentModel;
using BeWo.Service.ServiceImplementations;
using BS.Shared.Core;
using DevExpress.XtraReports.UI;
using BeWo.Report.ReportObjects;
using BeWo.Report;
using System.Collections.Generic;

namespace BeWo.SKFAlsdorf
{
    public partial class QuittungStaedteRegionAachen : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
    {
		public QuittungStaedteRegionAachen()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
	        var geleistetGesamt = GetGeleisteteMinuten(pRO);
	        pRO.FreeMinutesThisMonth = geleistetGesamt;

            if (pRO.Services != null)
            {
                foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
                {
	                s.ServiceCategoryAbbr = "";

	                String firstLine = "";
					if (!String.IsNullOrEmpty(s.Notice))
					{
						if (s.Notice.IndexOf(Environment.NewLine) >= 0)
							firstLine = s.Notice.Substring(0, s.Notice.IndexOf(Environment.NewLine));
						else
							firstLine = s.Notice;
					}
					s.Notice = firstLine;

				}

            }

            this.bindingSource1.DataSource = pRO;
        }

		private decimal GetGeleisteteMinuten(ServicesOverviewRO pRO)
		{
			if (pRO.CostBearer2SupportConceptList != null && pRO.CostBearer2SupportConceptList.Count > 0)
			{
				var service = new OperationsServiceImp();
				var stats = service.CreateSupportConceptStatistics(pRO.CostBearer2SupportConceptList[0].Oid.Value, pRO.EndDate);
				if (stats != null)
				{
					return stats.MinutesProvidedTotalRounded;
				}
			}
			return 0;
		}
    }
}
