Files
BeWoPlaner/ReportImp/SynpraxReports/SynpraxReportCreator.cs

181 lines
7.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.DefaultReports;
using BeWo.Report.ReportObjects;
using BeWo.Service.DCEntityMapper;
using DevExpress.XtraReports.UI;
namespace SynpraxReports
{
public class SynpraxReportCreator : DefaultReportCreator
{
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
{
if (queryOid == 500)
{
return CreateLwlPruefliste(CreateQueryRO(queryOid, queryReportId));
}
return base.CreateQueryReport(queryOid, queryReportId);
}
private LwlPruefliste CreateLwlPruefliste(QueryRO queryRo)
{
var liste = new LwlPruefliste();
if (queryRo.Rows.Count > 0)
{
DateTime start = DateTime.MaxValue;
DateTime end = DateTime.MinValue;
if (queryRo.Rows[0].Field1 != null)
{
DateTime.TryParse(queryRo.Rows[0].Field1.ToString(), out start);
}
if (queryRo.Rows[0].Field2 != null)
{
DateTime.TryParse(queryRo.Rows[0].Field2.ToString(), out end);
}
long? customerOid = null;
if (queryRo.Rows[0].Field3.ToString() == "0")
{
var masterReport = new LwlPruefliste();
//masterReport.CreateDocument();
var customerList = DAOFactory.GenericDAO.GetAllActive<Customer>();
var customerListOrd = customerList.OrderBy(c => c.Person.LastNameFirstName).ToList();
foreach (var c in customerListOrd)
{
var ro = LwlPrueflisteRO.Create(start, end, "9011113", c.Oid);
if (ro.ServiceRecords != null && ro.ServiceRecords.Count > 0)
{
try
{
liste = new LwlPruefliste();
liste.SetReportDataSource(ro);
liste.CreateDocument();
masterReport.Pages.AddRange(liste.Pages);
}
catch
{
// ignore - z.B. kein Hilfeplan
}
}
}
return (LwlPruefliste)masterReport;
}
if (queryRo.Rows[0].Field3 != null)
{
if (Int64.TryParse(queryRo.Rows[0].Field3.ToString(), out var oidOut))
{
customerOid = oidOut;
}
var ro = LwlPrueflisteRO.Create(start, end, "9011113", customerOid);
liste.SetReportDataSource(ro);
return liste;
}
}
return liste;
}
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)
{
lROs.Sort((a, b) =>
{
if (a.MainAttendant == null)
a.MainAttendant = "";
if (b.MainAttendant == null)
b.MainAttendant = "";
var c = a.MainAttendant.CompareTo(b.MainAttendant);
if (c == 0)
{
c = a.CustomerLastName.CompareTo(b.CustomerLastName);
}
return c;
});
String reportId = null;
if (orgaOid > 0)
{
var organisation = DAOFactory.GenericDAO.LoadByID<Organisation>(orgaOid);
if (organisation != null)
reportId = organisation.Name;
}
var lServiceOverviewAllCustomersReport = this.FindReportImp<ServicesOverviewRO>(reportId);
lServiceOverviewAllCustomersReport.SetReportDataSource(lROs[0]);
(lServiceOverviewAllCustomersReport as XtraReport).CreateDocument();
var Report = lServiceOverviewAllCustomersReport as XtraReport;
for (int i = 1; i < lROs.Count; i++)
{
var lNext = FindReportImp<ServicesOverviewRO>(reportId);
lNext.SetReportDataSource(lROs[i]);
(lNext as XtraReport).CreateDocument();
Report.Pages.AddRange((lNext as XtraReport).Pages);
}
return lServiceOverviewAllCustomersReport as XtraReport;
}
return new XtraReport();
}
public override XtraReport CreateSettlementReport(string dcId, long? invoiceBaseOid)
{
return base.CreateSettlementReport(dcId, invoiceBaseOid, true);
}
public override XtraReport CreateEmployeeHourReport(long? employeeOid, IList<long> teamOids, DateTime startDate, DateTime endDate, int ansicht)
{
IBeWoReport<MitarbeiterstundenkontoRO> report = null;
if (ansicht == 1)
{
if (employeeOid != null)
{
string vertragsart = "";
var emp = MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.GetByID<Employee>(employeeOid.Value));
foreach (var c in emp.Contracts)
{
if (startDate >= c.EntryDate && !c.ContractEndDate.HasValue || startDate >= c.EntryDate && endDate <= c.ContractEndDate.Value)
{
var contracttype = c.ContractTypeValueListEntry;
if (contracttype != null)
vertragsart = contracttype.DisplayName;
}
}
if (vertragsart == "Werkstudent" || vertragsart == "Minijob")
report = new MitarbeiterarbeitszeitkontoMitTimeStamp();
else
report = new Mitarbeiterarbeitszeitkonto();
}
var ro = MitarbeiterstundenkontoRO.Create(employeeOid, teamOids, startDate, endDate, null);
if (report == null)
report = new Mitarbeiterarbeitszeitkonto();
report.SetReportDataSource(ro);
return report as XtraReport;
}
else
{
return base.CreateEmployeeHourReport(employeeOid, teamOids, startDate, endDate, ansicht);
}
}
}
}