214 lines
5.3 KiB
C#
214 lines
5.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Data.Access;
|
|
using System.Collections.Generic;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using DevExpress.XtraPrinting;
|
|
using SHKServiceSBD.Service;
|
|
|
|
namespace SHKServiceSBD.Reports
|
|
{
|
|
public partial class VergleichArbeitszeitStundenplanReport : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<QueryRO>
|
|
{
|
|
|
|
public VergleichArbeitszeitStundenplanReport()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(QueryRO pRO)
|
|
{
|
|
|
|
this.bindingSource1.DataSource = CreateDataSource(pRO);
|
|
}
|
|
|
|
private QueryRO CreateDataSource(QueryRO ro)
|
|
{
|
|
QueryRO newQueryRo = new QueryRO();
|
|
|
|
DateTime datum = DateTime.Now.Date;
|
|
|
|
if (ro.Rows != null && ro.Rows.Count > 0)
|
|
{
|
|
if (ro.Rows[0].Field1 != null)
|
|
{
|
|
if (DateTime.TryParse(ro.Rows[0].Field1.ToString(), out var dt))
|
|
{
|
|
if (dt > DateTime.MinValue)
|
|
{
|
|
datum = dt;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
lblZeitraum.Text = String.Format("Stichtag {0:dd.MM.yyyy}", datum);
|
|
|
|
var alleRows = ErstelleRows(datum);
|
|
|
|
|
|
foreach (var aus in alleRows)
|
|
{
|
|
QueryRO.Row row = new QueryRO.Row();
|
|
|
|
|
|
row.Field1 = aus.Employee;
|
|
row.Field2 = aus.Customer;
|
|
row.Field3 = String.Format("{0:0.00}", aus.BetreuungszeitKind);
|
|
row.Field4 = String.Format("{0:0.00}", aus.WochenstundenVertrag);
|
|
row.Field5 = String.Format("{0:0.00}", aus.BetreuungszeitKind - aus.WochenstundenVertrag);
|
|
|
|
newQueryRo.Rows.Add(row);
|
|
}
|
|
|
|
newQueryRo.Rows.Sort((a, b) => a.Field1.ToString().CompareTo(b.Field1));
|
|
|
|
|
|
return newQueryRo;
|
|
}
|
|
|
|
|
|
private List<VergleichRow> ErstelleRows(DateTime datum)
|
|
{
|
|
var result = new List<VergleichRow>();
|
|
|
|
var martinsschule = SucheMartinsschule();
|
|
var teamMartinsschule = SucheTeamMartinsschule();
|
|
var allEmployees = DAOFactory.GenericDAO.GetAllActive<Employee>();
|
|
|
|
|
|
foreach (var emp in allEmployees)
|
|
{
|
|
var row = new VergleichRow();
|
|
row.Employee = String.Format("{0}", emp.Person.LastNameFirstName);
|
|
if (row.Employee.Contains("Hollmann"))
|
|
{
|
|
int test = 0;
|
|
}
|
|
var clist = GetBetreuteKinder(emp, datum);
|
|
row.Customer = "";
|
|
foreach (var c in clist)
|
|
{
|
|
if (row.Customer.Length > 0)
|
|
{
|
|
row.Customer += ", ";
|
|
}
|
|
row.Customer += String.Format("{0} {1}", c.Person.FirstName, c.Person.LastName);
|
|
|
|
row.BetreuungszeitKind += GetStundenplanStunden(c, emp, datum);
|
|
}
|
|
|
|
if (IstMartinsschule(emp, datum, teamMartinsschule))
|
|
{
|
|
row.Customer = "Martinsschule";
|
|
row.BetreuungszeitKind = GetStundenplanStunden(martinsschule, datum);
|
|
}
|
|
row.WochenstundenVertrag = GetWochenstundenAusVertrag(emp, datum);
|
|
|
|
result.Add(row);
|
|
}
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
private decimal GetWochenstundenAusVertrag(Employee emp, DateTime datum)
|
|
{
|
|
var c = emp.GetValidContractForDate(datum);
|
|
if (c != null)
|
|
{
|
|
return c.WeeklyTotalHours ?? 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private Organisation SucheMartinsschule()
|
|
{
|
|
return DAOFactory.SearchDAO.FindOrganisation("Martinsschule", false).FirstOrDefault();
|
|
|
|
}
|
|
|
|
private Team SucheTeamMartinsschule()
|
|
{
|
|
return DAOFactory.GenericDAO.GetAllActive<Team>().FirstOrDefault(t => t.Name.Contains("Martinsschule"));
|
|
|
|
}
|
|
private bool IstMartinsschule(Employee emp, DateTime datum, Team teamMartinsschule)
|
|
{
|
|
var c = emp.GetValidContractForDate(datum);
|
|
if (c != null && c.ContractTypeValueListEntry != null && c.ContractTypeValueListEntry.Value.Contains("Martinsschule"))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return teamMartinsschule.MemberList.Any(e => e.Oid == emp.Oid);
|
|
}
|
|
|
|
private decimal GetStundenplanStunden(Customer c, Employee e, DateTime datum)
|
|
{
|
|
decimal stunden = 0;
|
|
var az = ReportHelper.GetArbeitszeit(c, datum, datum);
|
|
|
|
if (az != null)
|
|
{
|
|
foreach (var item in az.ArbeitszeitEintraege)
|
|
{
|
|
if (item.Employee == null || item.Employee.Oid == e.Oid)
|
|
{
|
|
stunden += item.BerechneStunden();
|
|
}
|
|
}
|
|
}
|
|
return stunden;
|
|
}
|
|
|
|
private decimal GetStundenplanStunden(Organisation o, DateTime datum)
|
|
{
|
|
decimal stunden = 0;
|
|
var az = ReportHelper.GetArbeitszeit(o, datum, datum);
|
|
|
|
if (az != null)
|
|
{
|
|
foreach (var item in az.ArbeitszeitEintraege)
|
|
{
|
|
stunden += item.BerechneStunden();
|
|
}
|
|
}
|
|
return stunden;
|
|
}
|
|
|
|
private IList<Customer> GetBetreuteKinder(Employee emp, DateTime datum)
|
|
{
|
|
var customerList = new List<Customer>();
|
|
|
|
foreach (var e2c in emp.Employee2CustomerList.Where(e => e.IsActive == ActivationTypeId.Active
|
|
&& (!e.StartDate.HasValue || e.StartDate.Value.Date <= datum)
|
|
&& (!e.EndDate.HasValue || e.EndDate.Value.Date >= datum)
|
|
&& e.ValueList.Any(v => v.Entry.Type == ValueListEntryType.StaffRoleType && v.Entry.Value.StartsWith("Hauptbetreu"))))
|
|
{
|
|
if (e2c.Customer.IsActive == ActivationTypeId.Active)
|
|
{
|
|
customerList.Add(e2c.Customer);
|
|
}
|
|
}
|
|
|
|
return customerList;
|
|
}
|
|
|
|
|
|
class VergleichRow
|
|
{
|
|
public String Employee { get; set; }
|
|
public String Customer { get; set; }
|
|
public decimal BetreuungszeitKind { get; set; }
|
|
public decimal WochenstundenVertrag { get; set; }
|
|
}
|
|
}
|
|
|
|
}
|