using System;
using System.Collections;
using System.ComponentModel;
using BeWo.Data.Entities;
using BS.Shared;
using DevExpress.XtraReports.UI;
using BeWo.Report.ReportObjects;
using BeWo.Report;
using System.Collections.Generic;

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

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
			pRO.CalculateFLSSollIst();
			cellVerbrauchteFLS.Text = String.Format("{0:0.00}", pRO.MinutenGeleistetGesamt / 60);

            if (pRO.Services != null)
            {
                
                foreach (var item in pRO.Services)
                {
					if (item.ServiceDescription.ToLower().Trim() == "familienkontakt" || item.ServiceDescription.ToLower().Trim() == "elterngespräch"
						|| item.ServiceCategory.ToLower().Trim() == "direkte betreuungsleistungen")
	                {
		                item.CostBearer = "x";
	                }
	                else
	                {
						item.CostBearer = "";
	                }
                }
            }
	        lblMitarbeiter.Text = GetAsdMitarbeiter(pRO);
            this.bindingSource1.DataSource = pRO;
        }

	    public String GetAsdMitarbeiter(ServicesOverviewRO ro)
	    {
		    if (ro.CostBearer2SupportConceptList != null && ro.CostBearer2SupportConceptList.Count > 0)
		    {
			    var c2s = ro.CostBearer2SupportConceptList[0];

			    Customer c = c2s.SupportConcept.Customer;
			    foreach (var c2p in c.Customer2PersonList)
			    {
				    foreach (var v2o in c2p.ValueList)
				    {
						if (v2o.Entry.Type == ValueListEntryType.EnvironmentPersonType && v2o.Entry.Value == "ASD/ Jugendamt")
						{
							return c2p.Person.FirstNameLastName;
						}
				    }
					   
			    }
		    }

		    return "";
	    }
    }
}
