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

using DevExpress.XtraReports.UI;

namespace BeWo.LeiendeckerReports
{
    public partial class ServiceInvoiceReport : XtraReport, IBeWoReport<ServiceInvoiceRO>
    {
        public ServiceInvoiceReport()
        {
            this.InitializeComponent();
        }

        public void SetReportDataSource(ServiceInvoiceRO pRO)
        {
	        
	        lblAbrechnungstext.Text =
		        string.Format("Abrechnung Betreuungsleistungen für {0} {1}, geb. {2:dd.MM.yyyy}",
			        pRO.CustomerSalutation, pRO.CustomerName, pRO.CustomerBirthdate);

	        decimal hoursTotal = 0;
	        decimal einzelbetrag = 0;
	        decimal gesamt = 0;

			if (pRO.ServiceInvoicePeriods != null)
	        {
		        foreach (var sip in pRO.ServiceInvoicePeriods)
		        {
			        if (sip.ServiceInvoiceItems != null)
			        {
				        foreach (var sii in sip.ServiceInvoiceItems)
				        {
					        if (sii.Hours.HasValue)
						        hoursTotal += sii.Hours.Value;

					        if (sii.HourlyRate.HasValue && einzelbetrag == 0)
						        einzelbetrag = sii.HourlyRate.Value;
							
							if (sii.NetAmount.HasValue)
								gesamt += sii.NetAmount.Value;
				        }
			        }
		        }
	        }

	        cellHours.Text = String.Format("{0:0.##}", hoursTotal);
			cellHourlyRate.Text = String.Format("{0:c}", einzelbetrag);
			cellTotal.Text = String.Format("{0:c}", gesamt);

            this.bindingSource1.DataSource = pRO;
        }
    }
}