Files
BeWoPlaner/ReportImp/LebenshilfeFrankfurtOder/LeistungsnachweisEntlastungsleistungen.cs
2020-11-10 02:25:15 +01:00

168 lines
5.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Service.DCEntityMapper;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.Extensions;
using DevExpress.Entity.Model.Metadata;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using LebenshilfeFrankfurtOder.Utils;
namespace LebenshilfeFrankfurtOder
{
public partial class LeistungsnachweisEntlastungsleistungen : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
{
public LeistungsnachweisEntlastungsleistungen()
{
InitializeComponent();
}
public void SetReportDataSource(ServicesOverviewRO pRO)
{
SetzeDaten(pRO);
if (pRO.Services != null)
{
List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();
foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
{
if (s.IsBillable)
{
servicesBillable.Add(s);
}
}
if (servicesBillable.Count < 16)
{
for (int i = servicesBillable.Count; i < 16; i++)
{
ServicesOverviewRO.ServiceDetail emptyDetail = new ServicesOverviewRO.ServiceDetail();
servicesBillable.Add(emptyDetail);
}
}
if (servicesBillable.Count % 2 == 1)
{
ServicesOverviewRO.ServiceDetail emptyDetail = new ServicesOverviewRO.ServiceDetail();
servicesBillable.Add(emptyDetail);
}
decimal? gesamtPreis = null;
decimal? gesamtDauer = null;
decimal? gesamtKm = null;
foreach (ServicesOverviewRO.ServiceDetail s in servicesBillable)
{
s.Notice3 = "";
s.Notice4 = "";
s.Notice5 = "";
if (s.StartDate > DateTime.MinValue)
{
s.Notice4 = String.Format("{0:dd.MM.yyyy}", s.StartDate);
s.Notice3 = String.Format("{0:0.00}", s.Minutes / 60);
if (s.ServiceRecordOid > 0)
{
var preis = FrankfurtOderHelper.GetFudPreisUndSetzeDauer(s);
if (preis != null)
{
s.Notice5 = String.Format("{0:0.00}", preis.Einzelpreis);
gesamtPreis = (gesamtPreis ?? 0) + preis.Gesamtpreis;
}
gesamtDauer = (gesamtDauer ?? 0) + (decimal)s.Minutes;
if (!String.IsNullOrWhiteSpace(s.GefahreneKilometer) && s.GefahreneKilometer != "0")
{
decimal km = 0;
if (Decimal.TryParse(s.GefahreneKilometer, out km))
{
gesamtKm = (gesamtKm ?? 0) + km;
}
}
}
}
}
cellKmGesamt.Text = String.Format("{0:0.##}", gesamtKm);
//cellStundenGesamt.Text = String.Format("{0:0.00}", gesamtDauer / 60);
cellPreisGesamt.Text = String.Format("{0:0.00}€", gesamtPreis);
servicesBillable = SortServices(servicesBillable);
pRO.Services = servicesBillable;
}
bindingSource1.DataSource = pRO;
}
private List<ServicesOverviewRO.ServiceDetail> SortServices(List<ServicesOverviewRO.ServiceDetail> servicesBillable)
{
List<ServicesOverviewRO.ServiceDetail> sorted = new List<ServicesOverviewRO.ServiceDetail>();
int halb = servicesBillable.Count / 2;
for (int i = 1; i <= halb; i++)
{
int targetIdx = i;
sorted.Add(servicesBillable[targetIdx-1]);
sorted.Add(servicesBillable[targetIdx + halb - 1]);
}
return sorted;
}
public void SetzeDaten(ServicesOverviewRO pRO)
{
if (pRO.CostBearer2SupportConceptList != null && pRO.CostBearer2SupportConceptList.Count > 0)
{
var c2s = pRO.CostBearer2SupportConceptList[0];
Customer c = c2s.SupportConcept.Customer;
if (c.Pflegegrad.HasValue && c.Pflegegrad.Value != Pflegegrad.KeinGrad &&
c.Pflegegrad.Value != Pflegegrad.PflegegradBeantragt)
{
lblPflegegrad.Text = EnumTranslations.PflegegradTranslations[c.Pflegegrad].Replace("Pflegegrad", "")
.Trim();
}
else
{
lblPflegegrad.Text = "";
}
String kvnummer = ""; // Oid = 4
foreach (var vv in c.VarFieldValueList)
{
var varFieldValue =
BS.Shared.Core.Utils.XMLDeserializeFromString(vv.SerializedValue, Type.GetType(vv.TypeName));
if (varFieldValue != null)
{
if (vv.VarFieldDefOid.Value == 4)
{
kvnummer = varFieldValue.ToString();
}
}
}
lblKvNummer.Text = kvnummer;
}
}
}
}