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

namespace BeWo.HolsingerReports
{
	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} - {1:dd.MM.yyyy}: {2:0.##} x {3:c}",
					ii.PeriodStartDate,
					ii.PeriodEndDate,
					ii.UnitCount,
					ii.AmountPerUnit);
				if (ii.RateFactor.HasValue && ii.RateFactor.Value != 0)
				{
					ii.DetailDescription += String.Format(" x {0:0.##}", (ii.RateFactor + 100) / 100);
				}

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

			if (rateFactor != 1)
			{
				cellRateFactorText.Text = string.Format("Inkl. pauschaler Faktor", rateFactor);
				cellRateFactorAmount.Text = string.Format("{0:c}", pRO.AmountBillableTotal - (pRO.AmountBillableTotal / rateFactor));
			}
            this.bindingSource1.DataSource = pRO;
        }
    }
}
