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

using DevExpress.XtraReports.UI;

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

        public void SetReportDataSource(ServiceInvoiceRO pRO)
        {
			DateTime start = pRO.AccountingPeriodStart;
			DateTime end = pRO.AccountingPeriodEnd;

	        if (pRO.CustomerSalutation == "Herr")
	        {
		        pRO.CustomerSalutation = "Herrn";
	        }
			//if (start.Month == end.Month && start.Year == end.Year)
			//{
			//	lblAbrechnungszeitraum.Text = String.Format("hiermit berechnen wir für den Monat {0:MMMM yyyy} folgende erbrachte Tätigkeiten:", start);
			//}
			//else
			//{
			//	lblAbrechnungszeitraum.Text = String.Format("hiermit berechnen wir für den Zeitraum {0:MMMM yyyy} - {1:MMMM yyyy} folgende erbrachte Tätigkeiten:", start, end);
			//}

	        decimal approved = 0;
	        decimal approvedFactor = 0;

	        //decimal amountTotal = 0;
	        
	        foreach (var sip in pRO.ServiceInvoicePeriods)
	        {
		        approved += sip.ApprovedHours ?? 0;
				
		        foreach (var ii in sip.ServiceInvoiceItems)
		        {
					ii.ServiceDescription = String.Format("{0:dd.MM.yyyy} bis {1:dd.MM.yyyy}: {2:0.##} Std. {3}x {4:c}", ii.AccountingPeriodStart, ii.AccountingPeriodEnd,
						ii.UnitCount, "", ii.AmountPerUnit);

			        //amountTotal += ii.NetAmount ?? 0;


		        }
	        }


	        cellApproved.Text = String.Format("{0:0.##}", approved);
			//cellApprovedWithFactor.Text = String.Format("{0:0.##}", approvedFactor);

			cellAmountTotal.Text = pRO.GrossClaim;
	        cellAbschlag.Text = pRO.AmountAdvancedPayments;

			cellRechnungsbetrag.Text = pRO.NetClaim;

	        if (String.IsNullOrEmpty(pRO.Notice))
	        {
		        lblNotice.Visible = false;
	        }
            this.bindingSource1.DataSource = pRO;
        }
    }
}