using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report.ReportObjects;
using BeWo.Report;
using BS.Shared;

namespace BeWo.SchillingerReports
{
    public partial class Spitzabrechnung : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<SettlementRO>
    {
        public Spitzabrechnung()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(SettlementRO pRO)
        {
            if (pRO.ClaimWithEigenbeteiligung >= 0)
                lblClaimText.Text = "Rückzahlungsanspruch";

            pRO.ApprovedFLSWeekly *= (decimal)pRO.RateFactor;
            pRO.ApprovedFLSWeekly = Math.Round(pRO.ApprovedFLSWeekly, 2);

            DateTime dt1;
            DateTime dt2;
            DateTime.TryParse(pRO.AccountingStartDateString, out dt1);
            DateTime.TryParse(pRO.AccountingEndDateString, out dt2);

            TimeSpan sp = dt2.Subtract(dt1);
            lblTage3.Text = String.Format("{0:0.#}", sp.TotalDays + 1);
            lblWeeks3.Text = String.Format("{0:0.##}", (sp.TotalDays + 1) * 0.1427);
            lblFLSTotal3.Text = String.Format("{0:0.##} FLS", Math.Round((sp.TotalDays + 1) * 0.1427, 2) * (double)pRO.ApprovedFLSWeekly);

            lblTage1.Text = lblTage3.Text;
            lblWeeks1.Text = lblWeeks3.Text;
            lblFLSTotal1.Text = lblFLSTotal3.Text;

            lblTage2.Text = lblTage3.Text;
            lblWeeks2.Text = lblWeeks3.Text;
            lblFLSTotal2.Text = lblFLSTotal3.Text;
            
            //pRO.ApprovedFLS *= (decimal)pRO.RateFactor;

            

            panel1.Location = panel3.Location;
            panel2.Location = panel3.Location;

            if (pRO.DifferentHourlyRateCount == 1)
            {
                pRO.TotalApprovedFLSWithNewHourlyRate = Math.Round(pRO.ApprovedFLSWeekly * pRO.WeeksWithNewHourlyRate, 2);
                pRO.TotalApprovedFLSWithNewHourlyRateString = string.Format("{0:0.00}", pRO.TotalApprovedFLSWithNewHourlyRate);

                panel3.Visible = false;
                panel2.Visible = false;
                panel1.Visible = true;
            }

            else if (pRO.DifferentHourlyRateCount == 2)
            {
                panel2.Visible = true;
                panel1.Visible = false;
                panel3.Visible = false;
            }
            else
            {
                panel2.Visible = false;
                panel1.Visible = false;
                panel3.Visible = true;
            }

			var ba = GetBetreuungsart(pRO);
			if (!String.IsNullOrEmpty(ba) && ba.ToLower().Contains("essen"))
			{
				lblAnbieter1.Text = "TaB Essen";
				lblAnbieter2.Text = "Meißener Str. 27";
				lblAnbieter3.Text = "45145 Essen";
			}
			else
			{
				lblAnbieter1.Text = "Die Hilfe Daheim ProBeWo";
				lblAnbieter2.Text = "Ripshorster Str. 130";
				lblAnbieter3.Text = "46117 Oberhausen";
			}

            this.bindingSource1.DataSource = pRO;
        }

		public String GetBetreuungsart(SettlementRO pRO)
		{
			
			var c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(pRO.CostBearer2SupportConceptOid);

			foreach (var v2o in c2s.SupportConcept.Customer.ValueList)
			{
				if (v2o.Entry.Type == ValueListEntryType.CustomerCareType)
				{
					return v2o.Entry.Value;
				}
			}

			return "";
		}
    }
}
