using System;
using BeWo.Report.ReportObjects;
using BeWo.Report;

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

        public void SetReportDataSource(Settlement2RO pRO)
        {
			bool replaceFF = true;

			if (String.IsNullOrEmpty(pRO.RecipientOrganisation) || !pRO.RecipientOrganisation.ToLower().StartsWith("lwl"))
			{
				lblAZ.Text = "";
				lblAZLabel.Text = "";
			}

			//if (!pRO.HourlyRateNew.HasValue && pRO.DifferentHourlyRateCount > 0 && pRO.InvoiceItems != null &&
			//	pRO.InvoiceItems.Count > 0)
			//{
			//	pRO.RateFactor = 1;
			//	replaceFF = true;

			//	cellBewilligteFLSText.Text = "Bewilligte FLS";
			//	cellRateFactorFLSText.Text = "";
			//	cellApprovedFLSWithRF.Text = "";

			//}
			cellBewilligteFLSText.Text = "Bewilligte FLS";
			cellRateFactorFLSText.Text = "";
			cellApprovedFLSWithRF.Text = "";

	        

	        if (!String.IsNullOrEmpty(pRO.SenderContactPersonMail))
	        {
		        pRO.SenderContactPersonMail = pRO.SenderContactPersonMail.Replace("Email: ", "").Trim();
	        }
			if (!String.IsNullOrEmpty(pRO.SenderContactPersonPhone))
			{
				pRO.SenderContactPersonPhone = pRO.SenderContactPersonPhone.Replace("Tel.: ", "").Trim();
			}

			decimal ratefactor = 0;

	        if (pRO.InvoiceItems != null)
	        {
		        foreach (var ii in pRO.InvoiceItems)
		        {
			        ii.DetailDescription = String.Format("{0:dd.MM.yyyy} bis {1:dd.MM.yyyy}",
				        ii.PeriodStartDate, ii.PeriodEndDate);
			        ii.DetailDescription += String.Format(": {0:0.##} FF x {1:c}",
				        ii.UnitCount, ii.AmountPerUnit);

					if (replaceFF)
					{
						ii.DetailDescription = ii.DetailDescription.Replace(" FF ", " FLS ");
					}
			        ratefactor = ii.RateFactor ?? 1;
		        }
	        }
	        pRO.ApprovedFLSTotal *= (100 + ratefactor) / 100;
			
	        this.bindingSource1.DataSource = pRO;
        }
    }
}
