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

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

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
			pRO.CalculateFLSSollIst();

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

				foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
				{
					if (s.IsBillable)
						servicesBillable.Add(s);
				}

				pRO.Services = servicesBillable;
			}

			DateTime dt = DateTime.Now.Date.AddMinutes(pRO.TotalFLMBillable * (double)pRO.RateFactor);
            TimeSpan tspan = dt.Subtract(DateTime.Now.Date);

            double d = tspan.TotalHours;

            d = Math.Floor(d);

			//lblFLSMitFaktor.Text = String.Format("{0}:{1:00}", d, tspan.Minutes);

			//###########################################
			dt = DateTime.Now.Date.AddMinutes((double)pRO.ApprovedFLSTotal * 60);
			tspan = dt.Subtract(DateTime.Now.Date);

			d = tspan.TotalHours;

			d = Math.Floor(d);

			cellBewStunden.Text = String.Format("{0}:{1:00}", d, tspan.Minutes);

			//###########################################
			dt = DateTime.Now.Date.AddMinutes((double)pRO.ApprovedFLSPerMonth * 60);
			tspan = dt.Subtract(DateTime.Now.Date);

			d = tspan.TotalHours;

			d = Math.Floor(d);

			cellSollMonat.Text = String.Format("{0}:{1:00}", d, tspan.Minutes);


			//###########################################
			//dt = DateTime.Now.Date.AddMinutes((double)(pRO.FreeMinutesThisMonth ?? 0));
			dt = DateTime.Now.Date.AddMinutes(((double)pRO.ApprovedFLSPerMonth * 60) - (double)pRO.TotalFLMBillable);
			tspan = dt.Subtract(DateTime.Now.Date);

			d = tspan.TotalHours;

			d = Math.Floor(d);

			cellRestMonat.Text = String.Format("{0}:{1:00}", d, tspan.Minutes);

			//###########################################
			dt = DateTime.Now.Date.AddMinutes(((double)pRO.ApprovedFLSTotal * 60) - (double)pRO.MinutenGeleistetGesamt);
			tspan = dt.Subtract(DateTime.Now.Date);

			d = tspan.TotalHours;

			d = Math.Floor(d);

			cellRestGesamt.Text = String.Format("{0}:{1:00}", d, tspan.Minutes);

			this.bindingSource1.DataSource = pRO;
        }

    }
}
