Files
BeWoPlaner/ReportImp/KetteReports/CustomReportCreator.cs

227 lines
6.4 KiB
C#

using BeWo.Data;
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 DevExpress.XtraReports.UI;
using DevExpress.XtraRichEdit.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Runtime.InteropServices.ComTypes;
namespace KetteReports
{
public class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateServiceOverviewAllCustomersReport(int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay)
{
List<ServicesOverviewRO> lROs = ServicesOverviewRO.Create(month, year, orgaOid, empOid, startDay, endDay, serviceCategoryOid);
if (lROs.Count > 0)
{
var rootReport = CreateServicesOverviewReportForRo(lROs[0], serviceCategoryOid);
if (rootReport.Pages.Count == 0)
{
rootReport.CreateDocument();
}
for (int i = 1; i < lROs.Count; i++)
{
var lNext = CreateServicesOverviewReportForRo(lROs[i], serviceCategoryOid);
if (lNext.Pages.Count == 0)
{
lNext.CreateDocument();
}
rootReport.Pages.AddRange(lNext.Pages);
}
return rootReport;
}
return new XtraReport();
}
public override XtraReport CreateServiceOverviewSingleCustomerReport(long customerOid, int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay)
{
var ro = ServicesOverviewRO.Create(customerOid, month, year, false, orgaOid, empOid, startDay, endDay, serviceCategoryOid);
return CreateServicesOverviewReportForRo(ro, serviceCategoryOid);
}
public override XtraReport CreateServiceOverviewReportForCustomers(IList<long> customerOids, int month, int year, long? orgaOid, long? empOid, long? serviceCategoryOid, int startDay, int endDay, bool nurFehlende)
{
var roList = new List<ServicesOverviewRO>();
foreach (var coid in customerOids)
{
var ro = ServicesOverviewRO.Create(coid, month, year, true, orgaOid ?? 0, empOid ?? 0, startDay, endDay, serviceCategoryOid);
if (ro != null)
{
roList.Add(ro);
}
}
if (roList.Count > 0)
{
var rootReport = CreateServicesOverviewReportForRo(roList[0], serviceCategoryOid);
rootReport.CreateDocument();
for (int i = 1; i < roList.Count; i++)
{
var lNext = CreateServicesOverviewReportForRo(roList[i], serviceCategoryOid);
lNext.CreateDocument();
rootReport.Pages.AddRange(lNext.Pages);
}
return rootReport;
}
return new XtraReport();
}
private XtraReport CreateServicesOverviewReportForRo(ServicesOverviewRO ro, long? serviceCategoryOid)
{
ServicesOverviewRO defaultRo = ServicesOverviewRO.CopyFromRO(ro);
ServicesOverviewRO sozioRo = ServicesOverviewRO.CopyFromRO(ro);
if (ro.Services != null)
{
foreach (ServicesOverviewRO.ServiceDetail s in ro.Services)
{
ServicesOverviewRO.CreateSignatureString(s);
if (s.ServiceCategory.ToLower().Contains("sozio"))
{
sozioRo.Services.Add(s);
}
else
{
defaultRo.Services.Add(s);
}
}
}
XtraReport report = null;
report = AddReportToReport<Quittierungsbeleg>(report, defaultRo);
report = AddReportToReport<LeistungsnachweisSoziotherapie>(report, sozioRo);
if (report == null)
report = new XtraReport();
return report;
}
public override XtraReport CreateReportForServicesOverviewRo(ServicesOverviewRO ro, string reportId)
{
return CreateServicesOverviewReportForRo(ro, null);
}
private XtraReport AddReportToReport<T>(XtraReport report, ServicesOverviewRO ro) where T : XtraReport, IBeWoReport<ServicesOverviewRO>, new()
{
if (ro.Services.Count > 0)
{
if (report == null)
{
report = new T();
((T)report).SetReportDataSource(ro);
}
else
{
if (report.Pages.Count == 0)
{
report.CreateDocument();
}
XtraReport newReport = new T();
((T)newReport).SetReportDataSource(ro);
newReport.CreateDocument();
report.Pages.AddRange(newReport.Pages);
}
}
return report;
}
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
{
if (queryOid == 100)
{
return CreateTeamStundenkonto(queryOid, queryReportId);
}
if (queryOid == 101)
{
return CreateTeamStundenkonto(queryOid, queryReportId);
}
return base.CreateQueryReport(queryOid, queryReportId);
}
private XtraReport CreateTeamStundenkonto(long queryOid, string queryReportId)
{
var query = DAOFactory.GenericDAO.LoadByID<Query>(queryOid);
if (query == null)
return new XtraReport();
var path = Path.Combine(TempPath, queryReportId + ".xml");
var table = Utils.XMLDeserialize<DataTable>(path);
var qro = QueryRO.Create(query, table);
if (qro.Rows.Count > 0)
{
DateTime monat = DateTime.Parse(qro.Rows[0].Field1.ToString());
DateTimeSpan span = new DateTimeSpan();
span.StartDateTime = monat;
span.EndDateTime = monat.AddMonths(1).AddTicks(-1);
var report = new BerichtTeamstunden();
if (queryOid == 100)
{
IList<long> teamOids = new List<long>();
teamOids = GetMeineTeamOids();
MitarbeiterstundenkontoRO ro = MitarbeiterstundenkontoRO.Create(null, teamOids, monat, monat.AddMonths(1), null);
report.SetReportDataSource(ro);
}
else
{
MitarbeiterstundenkontoRO ro = MitarbeiterstundenkontoRO.Create(null, null, monat, monat.AddMonths(1), null);
report.SetReportDataSource(ro);
}
return report as XtraReport;
}
return new XtraReport();
}
public virtual IList<long> GetMeineTeamOids()
{
IList<long> teamOids = new List<long>();
ApplicationUser loggedInUser;
if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null)
{
loggedInUser = LoggedInUserOperationContextExt.Current.User;
}
else
{
loggedInUser = SessionFacade.LoggedInUser;
}
if (loggedInUser?.Employee != null)
{
var teams = new List<Team>();
teams.AddRange(DAOFactory.SearchDAO.FindTeamsOfEmployee(loggedInUser.Employee.Oid.Value));
foreach (var team in teams)
{
if (!teamOids.Contains(team.Oid.Value))
{
teamOids.Add(team.Oid.Value);
}
}
}
return teamOids;
}
}
}