412 lines
18 KiB
C#
412 lines
18 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.ComponentModel;
|
||
using BS.Shared.Core;
|
||
using DevExpress.XtraReports.UI;
|
||
using BeWo.Report.ReportObjects;
|
||
using BeWo.Report;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using BeWo.Data.Access;
|
||
using BeWo.Data.Entities;
|
||
using BeWo.SBBMainzReports.Calculations;
|
||
using BeWo.Service.DCEntityMapper;
|
||
using BeWo.Service.Plugins;
|
||
using BS.Shared;
|
||
using BS.Shared.Services;
|
||
using DevExpress.XtraPrinting;
|
||
using BS.Shared.DataContracts;
|
||
using System.Text;
|
||
using System.Linq;
|
||
|
||
namespace SBBMainzReports
|
||
{
|
||
public partial class QuittierungsbelegJaMainz : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
|
||
{
|
||
public QuittierungsbelegJaMainz()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
public void SetReportDataSource(ServicesOverviewRO pRO)
|
||
{
|
||
xrCheckBox1.Visible = false;
|
||
xrCheckBox2.Visible = false;
|
||
xrCheckBox3.Visible = false;
|
||
xrCheckBox4.Visible = false;
|
||
|
||
decimal anteilBetreuungsstundenProzent = 100;
|
||
decimal anteilOverheadProzent = 0;
|
||
double TotalMin = 0.00;
|
||
|
||
if (pRO.Services != null)
|
||
{
|
||
List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();
|
||
|
||
foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
|
||
{
|
||
CreateGoalList(s);
|
||
var serviceRecord = DAOFactory.GenericDAO.LoadByID<ServiceRecord>(s.ServiceRecordOid);
|
||
var srDc = MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDC(serviceRecord);
|
||
s.ServiceCategory = "";
|
||
|
||
if (s.IsBillable)
|
||
{
|
||
TotalMin += s.Minutes/60;
|
||
}
|
||
}
|
||
}
|
||
|
||
SetKopfbereich(pRO);
|
||
|
||
pRO.ApprovedFLSPerMonth = pRO.ApprovedFLSPerWeek * 4.33m;
|
||
DateTime start = pRO.StartDate;
|
||
DateTime end = pRO.EndDate;
|
||
|
||
|
||
var hp = GetCurrentC2S(pRO);
|
||
if (hp != null)
|
||
{
|
||
if (hp.StartDate > start)
|
||
start = hp.StartDate.Value;
|
||
if (hp.EndDate < end)
|
||
end = hp.EndDate.Value;
|
||
}
|
||
decimal days = (decimal)end.Subtract(start).TotalDays + 1;
|
||
|
||
pRO.ApprovedFLSPerMonth *= days / DateTime.DaysInMonth(pRO.StartDate.Year, pRO.StartDate.Month);
|
||
|
||
decimal gesamt = (decimal)TotalMin;
|
||
decimal mehrMinusStunden = gesamt - pRO.ApprovedFLSPerMonth;
|
||
decimal uebertragVormonat = BerechneUebertragVormonat(pRO, anteilBetreuungsstundenProzent, anteilOverheadProzent);
|
||
|
||
bool uebertrag = MussUebertragBerechnen(pRO);
|
||
|
||
cellMehrMinusStunden.Text = String.Format("{0:0.000}", mehrMinusStunden);
|
||
cellUebertragVormonat.Text = String.Format("{0:0.000}", uebertragVormonat);
|
||
if (uebertrag)
|
||
cellUebertragNaechsterMonat.Text = String.Format("{0:0.000}", mehrMinusStunden + uebertragVormonat);
|
||
else
|
||
cellUebertragNaechsterMonat.Text = String.Format("{0:0.000}", 0);
|
||
|
||
// cellWoechentlichKlientenbezogen.Text = String.Format("{0:0.00}", (pRO.ApprovedFLSPerMonth - uebertragVormonat) * 0.7m / 4.33m);
|
||
// cellMonatlichKlientenbezogen.Text = String.Format("{0:0.00}", pRO.ApprovedFLSPerMonth * 0.7m);
|
||
|
||
cellBetreuungstunden.Text = String.Format("{0:0.##}% Betreuungsstunden", anteilBetreuungsstundenProzent);
|
||
|
||
var minutes = (decimal)Math.Round(pRO.TotalFLMBillable / 60, 3, MidpointRounding.AwayFromZero);
|
||
var pausch = Math.Round(((decimal)pRO.TotalFLMBillable / anteilBetreuungsstundenProzent * anteilOverheadProzent) / 60, 3, MidpointRounding.AwayFromZero);
|
||
|
||
cellMinutes.Text = String.Format("{0:0.000}", minutes);
|
||
|
||
this.bindingSource1.DataSource = pRO;
|
||
}
|
||
|
||
private CostBearer2SupportConcept GetCurrentC2S(ServicesOverviewRO ro)
|
||
{
|
||
if (ro.CostBearer2SupportConceptList != null && ro.CostBearer2SupportConceptList.Count > 0)
|
||
{
|
||
foreach (var c2sc in ro.CostBearer2SupportConceptList)
|
||
{
|
||
var cbName = c2sc.CostBearer.Organisation.Name;
|
||
if ((cbName.ToLower().Contains("jugendamt der landeshauptstadt mainz") || ro.Costbearer.ToLower().Contains("jugend und familie mainz – amt 51") ||
|
||
cbName.Equals("Landeshauptstadt Wiesbaden Amt für Soziale Arbeit und ambulante Erziehungshilfen") ||
|
||
cbName.Contains("EZB -Landeshauptstadt Wiesbaden - Amt für Soziale Arbeit"))
|
||
&& c2sc.StartDate <= ro.StartDate && c2sc.EndDate >= ro.StartDate)
|
||
{
|
||
if (cbName.Equals("Landeshauptstadt Wiesbaden Amt für Soziale Arbeit und ambulante Erziehungshilfen") ||
|
||
cbName.Contains("EZB -Landeshauptstadt Wiesbaden - Amt für Soziale Arbeit"))
|
||
{
|
||
lblReceiver.Text = "Landeshauptstadt Wiesbaden";
|
||
}
|
||
return c2sc;
|
||
}
|
||
}
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
private void SetKopfbereich(ServicesOverviewRO pRO)
|
||
{
|
||
String betreuer1 = "";
|
||
long betreuer1EOid = 0;
|
||
String betreuer2 = "";
|
||
long betreuer2EOid = 0;
|
||
int i = 0;
|
||
|
||
var c2s = GetCurrentC2S(pRO);
|
||
if (c2s != null)
|
||
{
|
||
SupportConceptApprovalPeriod2Employee p2e;
|
||
foreach (var rating in c2s.SupportConcept.Ratings)
|
||
{
|
||
if (rating.StartDate >= pRO.StartDate && rating.StartDate < pRO.EndDate.AddDays(1))
|
||
{
|
||
foreach (var item in rating.GoalRatingList)
|
||
{
|
||
ValueListEntry entry = null;
|
||
string ratingName = null;
|
||
string ratingErgebnis = null;
|
||
|
||
if (item.ValueListEntryOid != null)
|
||
entry = DAOFactory.GenericDAO.LoadByID<ValueListEntry>(item.ValueListEntryOid.Value);
|
||
if (entry != null)
|
||
ratingName = entry.Value;
|
||
if (item.RatingType != null)
|
||
ratingErgebnis = item.RatingType.DisplayName;
|
||
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
lblZiel1.Text = ratingName;
|
||
if (ratingErgebnis != null && ratingErgebnis.ToLower() == "erledigt")
|
||
{
|
||
xrCheckBox1.Checked = true;
|
||
xrCheckBox1.Visible = true;
|
||
}
|
||
else
|
||
lblBewertung1.Text = ratingErgebnis; break;
|
||
case 1:
|
||
lblZiel2.Text = ratingName;
|
||
if (ratingErgebnis != null && ratingErgebnis.ToLower() == "erledigt")
|
||
{
|
||
xrCheckBox2.Checked = true;
|
||
xrCheckBox2.Visible = true;
|
||
}
|
||
else
|
||
lblBewertung2.Text = ratingErgebnis; break;
|
||
case 2:
|
||
lblZiel3.Text = ratingName;
|
||
if (ratingErgebnis != null && ratingErgebnis.ToLower() == "erledigt")
|
||
{
|
||
xrCheckBox3.Checked = true;
|
||
xrCheckBox3.Visible = true;
|
||
}
|
||
else
|
||
lblBewertung3.Text = ratingErgebnis; break;
|
||
case 3:
|
||
lblZiel4.Text = ratingName;
|
||
if (ratingErgebnis != null && ratingErgebnis.ToLower() == "erledigt")
|
||
{
|
||
xrCheckBox4.Checked = true;
|
||
xrCheckBox4.Visible = true;
|
||
}
|
||
else
|
||
lblBewertung4.Text = ratingErgebnis; break;
|
||
}
|
||
i++;
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach (var scap in c2s.ApprovalPeriodList)
|
||
{
|
||
if (scap.SupportConceptApprovalPeriod2Employee != null)
|
||
{
|
||
var sortedScs = scap.SupportConceptApprovalPeriod2Employee.OrderByDescending(s => s.Betreuungsschluessel).ToList();
|
||
if (sortedScs.Count > 0)
|
||
{
|
||
p2e = sortedScs[0];
|
||
betreuer1 = p2e.Employee.Person.FirstNameLastName;
|
||
betreuer1EOid = (long)p2e.Employee.Oid;
|
||
}
|
||
|
||
if (sortedScs.Count > 1)
|
||
{
|
||
p2e = sortedScs[1];
|
||
betreuer2 = p2e.Employee.Person.FirstNameLastName;
|
||
betreuer2EOid = (long)p2e.Employee.Oid;
|
||
}
|
||
}
|
||
}
|
||
|
||
lblBetreuer1.Text = betreuer1;
|
||
lblBetreuer2.Text = betreuer2;
|
||
|
||
String qualifikation1 = "";
|
||
String qualifikation2 = "";
|
||
|
||
if (betreuer1EOid != 0)
|
||
{
|
||
var employee = DAOFactory.GenericDAO.LoadByID<Employee>(betreuer1EOid);
|
||
foreach (var valueEntry in employee.ValueList)
|
||
{
|
||
if (valueEntry.Entry.Type == ValueListEntryType.StaffQualificationsType)
|
||
if (valueEntry.Entry.Value.StartsWith("Q") && valueEntry.Entry.Value.Length < 4)
|
||
qualifikation1 = valueEntry.Entry.Value.ToString();
|
||
}
|
||
|
||
}
|
||
|
||
if (betreuer2EOid != 0)
|
||
{
|
||
var employee = DAOFactory.GenericDAO.LoadByID<Employee>(betreuer2EOid);
|
||
foreach (var valueEntry in employee.ValueList)
|
||
{
|
||
if (valueEntry.Entry.Type == ValueListEntryType.StaffQualificationsType)
|
||
if (valueEntry.Entry.Value.StartsWith("Q") && valueEntry.Entry.Value.Length < 4)
|
||
qualifikation2 = valueEntry.Entry.Value.ToString();
|
||
}
|
||
|
||
}
|
||
lblQualifikation1.Text = qualifikation1;
|
||
lblQualifikation2.Text = qualifikation2;
|
||
|
||
if (c2s.CostBearerContactPerson != null)
|
||
{
|
||
if (c2s.CostBearerContactPerson.Sex.HasValue &&
|
||
c2s.CostBearerContactPerson.Sex.Value == Sex.Female)
|
||
lblAnsprechpartner.Text = "Frau ";
|
||
else if (c2s.CostBearerContactPerson.Sex.HasValue &&
|
||
c2s.CostBearerContactPerson.Sex.Value == Sex.Male)
|
||
lblAnsprechpartner.Text = "Herr ";
|
||
|
||
lblAnsprechpartner.Text += c2s.CostBearerContactPerson.LastName;
|
||
}
|
||
}
|
||
}
|
||
|
||
private decimal BerechneUebertragVormonat(ServicesOverviewRO pRO, decimal anteilBetreuungsstundenProzent, decimal anteilOverheadProzent)
|
||
{
|
||
var calc = new SBBMainzCalculations();
|
||
|
||
decimal uebertrag = 0;
|
||
if (pRO.CostBearer2SupportConceptList != null && pRO.CostBearer2SupportConceptList.Count > 0)
|
||
{
|
||
var c2s = pRO.CostBearer2SupportConceptList[0];
|
||
|
||
IList<ServiceRecord> allServiceRecords = c2s.ServiceRecords;
|
||
|
||
decimal flmSoll = 0;
|
||
|
||
|
||
DateTime start = c2s.StartDate.Value;
|
||
int months = 0;
|
||
while (start < pRO.StartDate)
|
||
{
|
||
var dc = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(c2s);
|
||
|
||
var approvedPerWeek = calc.GetApprovedHoursPerWeek(dc, start, false) ?? 0;
|
||
|
||
decimal soll = approvedPerWeek * 4.33m;
|
||
if (start.Day != 1)
|
||
{
|
||
DateTime end = new DateTime(start.AddMonths(1).Year, start.AddMonths(1).Month, 1);
|
||
|
||
decimal days = (decimal)end.Subtract(start).TotalDays;
|
||
|
||
soll *= days / DateTime.DaysInMonth(start.Year, start.Month);
|
||
}
|
||
flmSoll += soll;
|
||
decimal ist = GetIstImMonat(allServiceRecords, start);
|
||
ist += ist / anteilBetreuungsstundenProzent * anteilOverheadProzent;
|
||
ist /= 60;
|
||
var uebertragMonat = ist - soll;
|
||
|
||
uebertrag += uebertragMonat;
|
||
start = start.AddMonths(1);
|
||
start = new DateTime(start.Year, start.Month, 1);
|
||
months++;
|
||
var mod = months % 3;
|
||
if (mod == 0)
|
||
uebertrag = 0;
|
||
}
|
||
|
||
|
||
}
|
||
return uebertrag;
|
||
}
|
||
|
||
private decimal GetIstImMonat(IList<ServiceRecord> allServiceRecords, DateTime start)
|
||
{
|
||
DateTime monatEnd = start.AddMonths(1);
|
||
monatEnd = new DateTime(monatEnd.Year, monatEnd.Month, 1);
|
||
|
||
decimal ist = 0;
|
||
|
||
Dictionary<long, bool> groupBookingDict = new Dictionary<long, bool>();
|
||
foreach (var item in allServiceRecords)
|
||
{
|
||
if (!item.GroupOid.HasValue || !groupBookingDict.ContainsKey(item.GroupOid.Value))
|
||
{
|
||
if (item.Start != null)
|
||
{
|
||
if (item.Start >= start && item.Start.Value < monatEnd)
|
||
{
|
||
if (item.ServiceDescription != null && item.ServiceDescription.ServiceCategory != null && item.ServiceDescription.ServiceCategory.IsBillable)
|
||
{
|
||
var p = item.ServiceDescription.ServiceCategory.ProzentAbrechnung;
|
||
if (item.ServiceDescription.ProzentAbrechnung.HasValue)
|
||
{
|
||
p = item.ServiceDescription.ProzentAbrechnung.Value;
|
||
|
||
}
|
||
ist += (item.RoundedDuration * p) / 100;
|
||
|
||
if (item.GroupOid.HasValue)
|
||
groupBookingDict.Add(item.GroupOid.Value, true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return ist;
|
||
}
|
||
|
||
private bool MussUebertragBerechnen(ServicesOverviewRO pRO)
|
||
{
|
||
if (pRO.CostBearer2SupportConceptList != null && pRO.CostBearer2SupportConceptList.Count > 0)
|
||
{
|
||
var c2s = pRO.CostBearer2SupportConceptList[0];
|
||
|
||
int months = 0;
|
||
|
||
DateTime start = c2s.StartDate.Value;
|
||
|
||
while (start < pRO.EndDate)
|
||
{
|
||
months++;
|
||
start = start.AddMonths(1);
|
||
}
|
||
|
||
var mod = months % 3;
|
||
if (mod == 0)
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public static void CreateGoalList(ServicesOverviewRO.ServiceDetail sd)
|
||
{
|
||
var serviceRecord = DAOFactory.GenericDAO.LoadByID<ServiceRecord>(sd.ServiceRecordOid);
|
||
var srDc = MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDC(serviceRecord);
|
||
|
||
sd.GoalList = String.Empty;
|
||
if (srDc.Goals != null && srDc.Goals.Count > 0)
|
||
{
|
||
foreach (var goal in srDc.Goals)
|
||
{
|
||
// Ohne diese Abfrage wird das selbe Ziel so oft eingefügt wie die Anzahl der Gruppenmitglieder ist
|
||
if (sd.CustomerCount > 1 && !string.IsNullOrEmpty(goal.TypeDescription) && sd.GoalList.Contains(goal.TypeDescription))
|
||
continue;
|
||
|
||
if (sd.GoalList.Length > 0)
|
||
{
|
||
sd.GoalList += ", ";
|
||
}
|
||
if (!string.IsNullOrEmpty(goal.Abbreviation))
|
||
{
|
||
sd.GoalList += goal.Abbreviation;
|
||
}
|
||
//else // Das wird sonst tot hässlich
|
||
//{
|
||
// sd.GoalList += goal.TypeDescription;
|
||
//}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|