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

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

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
			StringBuilder sb = new StringBuilder();
			var c2o = GetKrankenkasse(pRO);
			if (c2o != null)
			{
				var org = c2o.Organisation;

		        sb.AppendLine(org.Name);
		        if (org.Address != null)
		        {
			        sb.AppendLine(org.Address.Street);
					sb.Append(org.Address.PostalCode);
			        sb.Append(" ");
					sb.Append(org.Address.Town);
		        }

				lblVersicherungsnummer.Text = String.Format("Versicherungsnr.: {0}", c2o.Info1);

			}
			lblAddress.Text = sb.ToString();

            this.bindingSource1.DataSource = pRO;
        }

		private Customer2Organisation GetKrankenkasse(ServicesOverviewRO pRO)
		{
			if (pRO.CostBearer2SupportConceptList != null && pRO.CostBearer2SupportConceptList.Count > 0)
			{
				var customer = pRO.CostBearer2SupportConceptList[0].SupportConcept.Customer;

				foreach (var c2o in customer.Customer2OrganisationList)
				{
					foreach (var v2e in c2o.ValueList)
					{
						if (v2e.Entry.Type == ValueListEntryType.EnvironmentOrganisationType && v2e.Entry.Value == "Krankenkasse")
						{
							return c2o;		
						}
					}
					
				}
				
			}

			return null;
		}
    }
}
