using System;

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

namespace IndroABW
{
    public partial class Spitzabrechnung : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<SettlementRO>
    {
        public Spitzabrechnung()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(SettlementRO pRO)
        {
            if (pRO.DifferentHourlyRateCount == 3)
            {
                //Erbrachte Leistungen (FLS) - bis [HourlyRateOldEndDateString] à [HourlyRateOldString] €

                pRO.Abrechnungstext1 = String.Format("{0} bis {1}", 
                    pRO.AccountingStartDateString, pRO.HourlyRate3EndDateString);

                pRO.Abrechnungstext1 += String.Format(": {0:0.##} FLS {1}x {2:c}",
                    pRO.GeleisteteFLSMitStundensatz3, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRate3);

               //[AccountingStartDateString] - [HourlyRate3EndDateString] sind [RecordedFLSWithHourlyRate3String] Std. x [HourlyRate3String] € =";

                pRO.Betrag1 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatz3 * (decimal)pRO.RateFactor * pRO.HourlyRate3);


                pRO.Abrechnungstext2 = String.Format("{0} bis {1}",
                    pRO.HourlyRateOldStartDateString, pRO.HourlyRateOldEndDateString);
                pRO.Abrechnungstext2 += String.Format(": {0:0.##} FLS {1}x {2:c}",
                    pRO.GeleisteteFLSMitStundensatzAlt, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateOld);

                pRO.Betrag2 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAlt * (decimal)pRO.RateFactor * pRO.HourlyRateOld);


                pRO.Abrechnungstext3 = String.Format("{0} bis {1}",
                    pRO.HourlyRateNewStartDateString, pRO.AccountingEndDateString);
                pRO.Abrechnungstext3 += String.Format(": {0:0.##} FLS {1}x {2:c}",
                    pRO.GeleisteteFLSMitStundensatzAktuell, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateNew);

                pRO.Betrag3 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAktuell * (decimal)pRO.RateFactor * pRO.HourlyRateNew);



				cellStart1.Text = pRO.AccountingStartDateString;
				cellEnd1.Text = pRO.HourlyRate3EndDateString;
				cellHourlyRate1.Text = pRO.HourlyRate3String;
				cellFLS1.Text = pRO.RecordedFLSWithHourlyRate3String;

				cellStart2.Text = pRO.HourlyRateOldStartDateString;
				cellEnd2.Text = pRO.HourlyRateOldEndDateString;
				cellHourlyRate2.Text = pRO.HourlyRateOldString;
				cellFLS2.Text = pRO.RecordedFLSWithOldHourlyRateString;

				cellStart3.Text = pRO.HourlyRateNewStartDateString;
				cellEnd3.Text = pRO.AccountingEndDateString;
				cellHourlyRate3.Text = pRO.HourlyRateNewString;
				cellFLS3.Text = pRO.RecordedFLSWithNewHourlyRateString;
            }
            else if (pRO.DifferentHourlyRateCount == 2)
            {
                
                pRO.Abrechnungstext2 = String.Format("{0} bis {1}",
                    pRO.AccountingStartDateString, pRO.HourlyRateOldEndDateString);
                pRO.Abrechnungstext2 += String.Format(": {0:0.##} FLS {1}x {2:c}",
                    pRO.GeleisteteFLSMitStundensatzAlt, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateOld);

                pRO.Betrag2 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAlt * (decimal)pRO.RateFactor * pRO.HourlyRateOld);


                pRO.Abrechnungstext3 = String.Format("{0} bis {1}",
                    pRO.HourlyRateNewStartDateString, pRO.AccountingEndDateString);
                pRO.Abrechnungstext3 += String.Format(": {0:0.##} FLS {1}x {2:c}",
                    pRO.GeleisteteFLSMitStundensatzAktuell, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateNew);

                pRO.Betrag3 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAktuell * (decimal)pRO.RateFactor * pRO.HourlyRateNew);


				cellStart1.Text = pRO.AccountingStartDateString;
				cellEnd1.Text = pRO.HourlyRateOldEndDateString;
				cellHourlyRate1.Text = pRO.HourlyRateOldString;
				cellFLS1.Text = pRO.RecordedFLSWithOldHourlyRateString;

				cellStart2.Text = pRO.HourlyRateNewStartDateString;
				cellEnd2.Text = pRO.AccountingEndDateString;
				cellHourlyRate2.Text = pRO.HourlyRateNewString;
				cellFLS2.Text = pRO.RecordedFLSWithNewHourlyRateString;
            }
            else
            {
				cellStart1.Text = pRO.AccountingStartDateString;
				cellEnd1.Text = pRO.AccountingEndDateString;
				cellHourlyRate1.Text = pRO.HourlyRateNewString;
				cellFLS1.Text = pRO.RecordedFLSWithNewHourlyRateString;

                pRO.Abrechnungstext3 = String.Format("{0} bis {1}",
                    pRO.AccountingStartDateString, pRO.AccountingEndDateString);
                pRO.Abrechnungstext3 += String.Format(": {0:0.##} FLS {1}x {2:c}",
                    pRO.GeleisteteFLSMitStundensatzAktuell, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateNew);

                pRO.Betrag3 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAktuell * (decimal)pRO.RateFactor * pRO.HourlyRateNew);
            }

            bindingSource1.DataSource = pRO;
        }
    }
}
