using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using BS.Shared.Extensions;
using BeWo.Report.ReportObjects;
using BeWo.Report;

namespace BeWo.DiakonieLennepReports
{
    public partial class Hilfeplanuebersicht : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<SupportConceptListRO>
    {
        public Hilfeplanuebersicht()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(SupportConceptListRO pRO)
        {
	        int count = 1;
	        decimal totalWeekSoll = 0;
	        foreach (var sc in pRO.SupportConceptDetailList)
	        {
		        if (sc.FLSOpenPerWeek != 0)
		        {
			        sc.DurationPercentage = (sc.FLSPerWeekSoll/sc.FLSOpenPerWeek)*100;
		        }
		        else
		        {
			        sc.DurationPercentage = 0;
		        }

		        sc.TotalWeeks = 0;
		        if (!sc.SupportConceptSendDate.HasValue)
		        {
			        var days = DateTime.Now.Subtract(sc.StartDate).TotalDays + 1;
			        sc.TotalWeeks = (decimal)days/7;
		        }

		        if (sc.EndDate >= DateTime.Now && sc.StartDate <= DateTime.Now)
		        {
					totalWeekSoll += sc.FLSPerWeekSoll;
		        }
	        }
			foreach (var sc in pRO.SupportConceptDetailList)
			{
				sc.WeeksPassed = totalWeekSoll;
			}

			foreach (var ed in pRO.EmployeeSupportConceptDetailList)
		    {
				totalWeekSoll = 0;
			    foreach (var edsc in ed.SupportConceptDetailList)
			    {
					if (edsc.FLSOpenPerWeek != 0)
					{
						edsc.DurationPercentage = (edsc.FLSPerWeekSoll/edsc.FLSOpenPerWeek)*100;
					}
					else
					{
						edsc.DurationPercentage = 0;
					}

					edsc.TotalWeeks = 0;
					if (!edsc.SupportConceptSendDate.HasValue)
					{
						var days = DateTime.Now.Subtract(edsc.StartDate).TotalDays + 1;
						edsc.TotalWeeks = (decimal)days / 7;
					}

					if (edsc.EndDate >= DateTime.Now && edsc.StartDate <= DateTime.Now)
					{
						totalWeekSoll += edsc.FLSPerWeekSoll;
					}
			    }
				foreach (var edsc in ed.SupportConceptDetailList)
				{
					edsc.WeeksPassed = totalWeekSoll;
				}
		    }
			
            this.bindingSource1.DataSource = pRO;
        }

		
    }
}
