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

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

        public void SetReportDataSource(Settlement2RO pRO)
        {
			if (String.IsNullOrEmpty(pRO.Notice))
			{
				lblNotice.Visible = false;
			}

			if (pRO.Claim < 0)
			{
				pRO.FinalSentence = "Die geleistete Überzahlung wird nach Ihrer Abrechnung Ihrem Konto gutgeschrieben.";
			}


			decimal rateFactor = 1;

			foreach (var ii in pRO.InvoiceItems)
			{
				if (ii.RateFactor.HasValue)
				{
					rateFactor = (100 + ii.RateFactor.Value) / 100;
				}
			}
			pRO.RateFactor = (double)rateFactor;

			StringBuilder sb = new StringBuilder();
			if (!String.IsNullOrEmpty(pRO.RecipientOrganisation) && !String.IsNullOrEmpty(pRO.RecipientOrganisation.Trim()))
			{
				sb.AppendLine(pRO.RecipientOrganisation);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientContactPerson) && !String.IsNullOrEmpty(pRO.RecipientContactPerson.Trim()))
			{
				sb.AppendLine(pRO.RecipientContactPerson);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientDivision) && !String.IsNullOrEmpty(pRO.RecipientDivision.Trim()))
			{
				sb.AppendLine(pRO.RecipientDivision);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientStreet) && !String.IsNullOrEmpty(pRO.RecipientStreet.Trim()))
			{
				sb.AppendLine(pRO.RecipientStreet);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown) && !String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown.Trim()))
			{
				sb.AppendLine(pRO.RecipientPostCodeAndTown);
			}

			lblAddress.Text = sb.ToString();

            this.bindingSource1.DataSource = pRO;
        }
    }
}
