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

using DevExpress.XtraReports.UI;
using BS.Shared.Core;

namespace BeWo.GpzBiberachReports
{
    [IDSpecificClass(Identifier = "SammelrechnungWfB")]
	public partial class SammelrechnungWfB : XtraReport, IBeWoReport<ServiceInvoiceRO>
    {
        public SammelrechnungWfB()
        {
            this.InitializeComponent();
        }

        public void SetReportDataSource(ServiceInvoiceRO pRO)
        {
			pRO.InvoiceNumber = String.Format("8203-{0:yyyy}-{1}", pRO.InvoiceDateTime, pRO.InvoiceNumber);

	        foreach (var sip in pRO.ServiceInvoicePeriods)
	        {
		        
			    foreach (var ii in sip.ServiceInvoiceItems)
			    {
				    if (sip.Customer != null)
				    {
						ii.ServiceDescription = String.Format("{0} {1}", sip.Customer.FirstName, sip.Customer.LastName);
				    }
				    ii.Notice = String.Format("{0:MMM}", pRO.AccountingPeriodStart);
				    ii.Hours = (decimal)pRO.AccountingPeriodEnd.Subtract(pRO.AccountingPeriodStart).TotalDays + 1;
		        }
	        }
            this.bindingSource1.DataSource = pRO;
        }
    }
}