using System;
using System.Text;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BS.Shared.Core;
using DevExpress.XtraReports.UI;

namespace LebenshilfeCoburg
{
	[IDSpecificClass(Identifier = "PersoenlichesBudget")]
    public partial class PersoenlichesBudgetRechnung : XtraReport, IBeWoReport<ServiceInvoiceRO>
    {
		public PersoenlichesBudgetRechnung()
        {
            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)
		        {
					if (ii.ServiceDescription == "Fachkraft für ambulant unterstütztes Wohnen")
			        {
				        ii.UnitDescription = String.Format("{0:0.00}", ii.UnitCount);
			        }
					else if (ii.ServiceDescription == "Persönliche Assistenz")
					{
						ii.UnitDescription = String.Format("{0:0.00}", ii.UnitCount);
					}
					//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;
	        }
			 * 
			 */

			StringBuilder sb = new StringBuilder();

			if (!String.IsNullOrEmpty(pRO.RecipientOrganisation))
			{
				sb.AppendLine(pRO.RecipientOrganisation);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientContactPerson))
			{
				sb.AppendLine(pRO.RecipientContactPerson);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientDivision))
			{
				sb.AppendLine(pRO.RecipientDivision);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientStreet))
			{
				sb.AppendLine(pRO.RecipientStreet);
			}
			if (!String.IsNullOrEmpty(pRO.RecipientPoBox))
			{
				sb.Append("Postfach ");
				sb.AppendLine(pRO.RecipientPoBox.Replace("Postfach", "").Trim());
			}
			if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown))
			{
				sb.AppendLine(pRO.RecipientPostCodeAndTown);
			}
			lblAnschrift.Text = sb.ToString();


			if (pRO.AccountingPeriodStart.Date.Year == pRO.AccountingPeriodEnd.Date.Year
				&& pRO.AccountingPeriodStart.Date.Month == pRO.AccountingPeriodEnd.Date.Month)
			{
				lblMonth.Text = String.Format("{0:MMMM yyyy}", pRO.AccountingPeriodStart);
			}
			else
			{
				lblMonth.Text = String.Format("{0:MMMM yyyy} - {1:MMMM yyyy}", pRO.AccountingPeriodStart,
					pRO.AccountingPeriodEnd);
			}

		


            this.bindingSource1.DataSource = pRO;
        }
    }
}