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

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

        public void SetReportDataSource(Settlement2RO pRO)
        {
			decimal rateFactor = 1;

			foreach (var ii in pRO.InvoiceItems)
			{
				
				ii.DetailDescription = String.Format("{0:dd.MM.yyyy} bis {1:dd.MM.yyyy}: {2:0.##} FLS {4}x {3:c}",
					ii.PeriodStartDate,
					ii.PeriodEndDate,
					ii.UnitCount,
					ii.AmountPerUnit,
					ii.RateFactor.HasValue && ii.RateFactor.Value != 0 ? String.Format("x {0:0.##} ", (ii.RateFactor + 100) / 100) : "");
				
				if (ii.RateFactor.HasValue)
				{
					rateFactor = (100 + ii.RateFactor.Value) / 100;
				}
			}
			pRO.RateFactor = (double)rateFactor;

			if (pRO.Claim < 0)
			{
				pRO.FinalSentence = "";
			}

            this.bindingSource1.DataSource = pRO;
        }
    }
}
