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

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

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
            String text = "";
            if (pRO.RateFactor > 1)
            {
                text = String.Format("bew. FLS.p.M *{0:0.0}", pRO.RateFactor);
            }
            lblFLSproMonatMitFaktor.Text = text;

            if (pRO.Services != null)
            {
                DateTime dt = DateTime.Now.Date.AddMinutes(pRO.TotalFLMBillable);
                TimeSpan tspan = dt.Subtract(DateTime.Now.Date);

                double d = tspan.TotalHours;

                d = Math.Floor(d);

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


                List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();
                

                foreach (var item in pRO.Services)
                {
                    String hhmm = "00:00";

                    if (item.IsBillable) 
                    {
                        dt = DateTime.Now.Date.AddMinutes(item.Minutes);
                        tspan = dt.Subtract(DateTime.Now.Date);

                        d = tspan.TotalHours;

                        d = Math.Floor(d);

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

                        servicesBillable.Add(item);
                    }
                    item.StartDateString = hhmm;
                }

                pRO.Services = servicesBillable;
            }
            
            this.bindingSource1.DataSource = pRO;
        }

    }
}
