445 lines
21 KiB
C#
445 lines
21 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report;
|
|
using BeWo.Report.DefaultReports;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Invoicing;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace PerspektivenEV
|
|
{
|
|
public class CustomReportCreator : DefaultReportCreator
|
|
{
|
|
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
|
|
{
|
|
if (queryOid == 207)
|
|
{
|
|
return CreateTestRechnungslauf(queryOid, queryReportId);
|
|
}
|
|
|
|
return base.CreateQueryReport(queryOid, queryReportId);
|
|
}
|
|
|
|
private XtraReport CreateTestRechnungslauf(long queryOid, string queryReportId)
|
|
{
|
|
var query = DAOFactory.GenericDAO.LoadByID<Query>(queryOid);
|
|
|
|
if (query == null)
|
|
return new XtraReport();
|
|
|
|
// ggf. noch nach Kostenträger differenzieren
|
|
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 start = DateTime.Parse(qro.Rows[0].Field1.ToString());
|
|
DateTime end = start.AddMonths(1).AddDays(-1);
|
|
|
|
DateTimeSpan span = new DateTimeSpan();
|
|
span.StartDate = start.Date;
|
|
span.EndDate = end.Date; //.AddDays(1).AddTicks(-1);
|
|
var costBearers = DAOFactory.GenericDAO.GetAllActive<CostBearer>();
|
|
var cBBthg = costBearers.Where(c => c.Organisation.Function != null && c.Organisation.Function.Value.ToString().ToLower().Contains("bthg") && c.Organisation.Name != "SELBSTZAHLER").ToList();
|
|
var anhang = new FinanzauswertungTabBthgIntern();
|
|
List<ServiceInvoiceDC> firstInv = new List<ServiceInvoiceDC>();
|
|
foreach (var cb in cBBthg)
|
|
{
|
|
var invs = GenerateInitialServiceInvoices(cb.Oid.Value, span);
|
|
if (invs != null)
|
|
{
|
|
if (firstInv.Count == 0)
|
|
{
|
|
var count = 0;
|
|
foreach (var i in invs)
|
|
{
|
|
count += 1;
|
|
if (count > 1 && i.ServiceInvoicePeriods != null && i.ServiceInvoicePeriods.Count > 0)
|
|
{
|
|
foreach (var sip in i.ServiceInvoicePeriods)
|
|
{
|
|
invs[0].ServiceInvoicePeriods.Add(sip);
|
|
}
|
|
}
|
|
}
|
|
ServiceInvoiceRO roSingle = ServiceInvoiceRO.Create(invs[0]);
|
|
if (roSingle.GrossClaim != "0,00 €")
|
|
{
|
|
firstInv.Add(invs[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var i in invs)
|
|
{
|
|
if (i.ServiceInvoicePeriods != null && i.ServiceInvoicePeriods.Count > 0)
|
|
{
|
|
foreach (var sip in i.ServiceInvoicePeriods)
|
|
{
|
|
firstInv[0].ServiceInvoicePeriods.Add(sip);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ServiceInvoiceRO ro = ServiceInvoiceRO.Create(firstInv[0]);
|
|
anhang.SetReportDataSource(ro);
|
|
anhang.CreateDocument();
|
|
if (queryOid == 207) // die wollen die Rechnungsvorschau nur in Excel sprich Trennung von Sammelrechnung Spitzabrechnungsreports
|
|
{
|
|
return (XtraReport)anhang;
|
|
}
|
|
else
|
|
{
|
|
var anhang2 = new LwvKASpitzabrechnung();
|
|
return (XtraReport)anhang2;
|
|
}
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
public List<ServiceInvoiceDC> GenerateInitialServiceInvoices(long costBearerOid, DateTimeSpan invoicePeriod)
|
|
{
|
|
var cs = PluginLoader.FindClass<CustomerService>();
|
|
IEnumerable<CompactSupportConceptDC> supportConcepts;
|
|
// GetAllActiveSupportConceptCostbearer returns a "Flat" SupportConcept List, one for each CostBearer2SupportConcept!
|
|
supportConcepts = cs.GetAllActiveSupportConceptCostbearer(false, true, 0)
|
|
.Where(i => i.CostBearerOids2CostBearerRelOids.ContainsKey(costBearerOid));
|
|
|
|
supportConcepts = supportConcepts.Where(sc => sc.StartDate < invoicePeriod.EndDateTime && sc.EndDate >= invoicePeriod.StartDate);
|
|
|
|
var supportConcepts2ServiceRecords = supportConcepts.ToDictionary(
|
|
i => i,
|
|
i => MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDCs(
|
|
DAOFactory.SearchDAO.FindServiceRecordsInSpan(i.CostBearerRelOids[0], invoicePeriod)));
|
|
var cb = DAOFactory.GenericDAO.LoadByID<CostBearer>(costBearerOid);
|
|
String tenant = PluginLoader.Tenant;
|
|
var factory = PluginLoader.FindClass<InvoiceFactory>(cb.ID);
|
|
if (factory == null)
|
|
{
|
|
factory = InvoiceFactory.GetInstance(cb.ID, tenant);
|
|
}
|
|
|
|
var creator = factory.CreateInvoiceCreator(cb.ID, tenant, supportConcepts2ServiceRecords);
|
|
var newInvoices = creator.GenerateServiceInvoices(costBearerOid, invoicePeriod, supportConcepts2ServiceRecords);
|
|
|
|
return newInvoices;
|
|
}
|
|
|
|
public override XtraReport CreateServiceInvoiceReport(string dcIds, long? invoiceBaseOid)
|
|
{
|
|
if (String.IsNullOrEmpty(dcIds) && invoiceBaseOid.HasValue)
|
|
{
|
|
var serviceInvoice = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(invoiceBaseOid.Value);
|
|
dcIds = String.Format("{0}", serviceInvoice.Oid);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(dcIds))
|
|
{
|
|
|
|
var dcList = new List<ServiceInvoiceDC>();
|
|
var dcidStrs = dcIds.Split(';');
|
|
|
|
foreach (var oidStr in dcidStrs)
|
|
{
|
|
var oid = long.Parse(oidStr);
|
|
var invoice = DAOFactory.GenericDAO.LoadByID<ServiceInvoice>(oid);
|
|
var dc = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(invoice);
|
|
dcList.Add(dc);
|
|
}
|
|
|
|
return CreateInvoiceReport(dcList);
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
private XtraReport CreateInvoiceReport(List<ServiceInvoiceDC> invoices)
|
|
{
|
|
XtraReport allReports = null;
|
|
|
|
foreach (var iDC in invoices)
|
|
{
|
|
XtraReport invoiceReport = null;
|
|
IBeWoReport<ServiceInvoiceRO> singleReport = FindReportImp<ServiceInvoiceRO>(iDC.InvoiceBase.InvoiceId);
|
|
|
|
if (iDC.InvoiceBase != null && iDC.InvoiceBase.InvoiceId != null && iDC.InvoiceBase.InvoiceId == "Sammelrechnung"|| (iDC.InvoiceBase.InvoiceId == "SammelrechnungBthg"))
|
|
{
|
|
var ro = ServiceInvoiceRO.Create(iDC);
|
|
singleReport.SetReportDataSource(ro);
|
|
((XtraReport)singleReport).CreateDocument();
|
|
invoiceReport = singleReport as XtraReport;
|
|
|
|
if (iDC.InvoiceBase.InvoiceId == "Sammelrechnung")
|
|
{
|
|
var anhang = new SammelrechnungTab();
|
|
anhang.SetReportDataSource(ro);
|
|
anhang.CreateDocument();
|
|
((XtraReport)singleReport).Pages.AddRange(((XtraReport)anhang).Pages);
|
|
invoiceReport = singleReport as XtraReport;
|
|
}
|
|
if (iDC.InvoiceBase.InvoiceId == "SammelrechnungBthg")
|
|
{
|
|
var anhang = new SammelrechnungTabBthg();
|
|
anhang.SetReportDataSource(ro);
|
|
anhang.CreateDocument();
|
|
((XtraReport)singleReport).Pages.AddRange(((XtraReport)anhang).Pages);
|
|
|
|
if (ro.ServiceInvoicePeriods != null && ro.ServiceInvoicePeriods.Count > 0)
|
|
{
|
|
foreach (var sip in ro.ServiceInvoicePeriods)
|
|
{
|
|
if (sip.ServiceInvoiceItems != null && sip.ServiceInvoiceItems.Count > 1
|
|
&& sip.SupportConceptApprovalPeriod.ServiceCategory.Abbreviation.Substring(sip.SupportConceptApprovalPeriod.ServiceCategory.Abbreviation.Length - 2) == "KA"
|
|
&& iDC.InvoiceBase.AccountingPeriodStart.HasValue && iDC.InvoiceBase.AccountingPeriodStart.Value < new DateTime(2026, 7, 1)) // KA-Spitzabrechnung entfaellt ab 01.07.2026
|
|
{
|
|
var anhang2 = new LwvKASpitzabrechnung();
|
|
var kaRo = LwvKASpitzabrechnungRO.Create(sip.CostBearer2SupportConcept.Oid.Value, ro.AccountingPeriodEnd, sip.SupportConceptApprovalPeriod.Oid.Value, null);
|
|
anhang2.SetReportDataSource(kaRo);
|
|
anhang2.CreateDocument();
|
|
((XtraReport)singleReport).Pages.AddRange(((XtraReport)anhang2).Pages);
|
|
}
|
|
}
|
|
}
|
|
invoiceReport = singleReport as XtraReport;
|
|
}
|
|
}
|
|
|
|
else if (iDC.InvoiceBase.RecipientOrganisation != "Landeswohlfahrtsverband Hessen" && iDC.InvoiceBase.Type.ToString() == "Service"
|
|
&& iDC.ServiceInvoicePeriods.Count > 0 && iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod != null
|
|
&& iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod.ServiceCategory != null
|
|
&& (iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod.ServiceCategory.Name.Contains("BW")
|
|
|| iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod.ServiceCategory.Name.Contains("TS")))
|
|
{
|
|
//XtraReport masterReport = new XtraReport();
|
|
//masterReport.CreateDocument();
|
|
|
|
var seite1 = new ServiceInvoiceReport();
|
|
var ro = ServiceInvoiceRO.Create(iDC);
|
|
seite1.SetReportDataSource(ro);
|
|
seite1.CreateDocument();
|
|
|
|
//masterReport.Pages.AddRange(seite1.Pages);
|
|
//foreach (DevExpress.XtraPrinting.Page item in masterReport.Pages)
|
|
//{
|
|
// item.AssignWatermark(seite1.Watermark);
|
|
//}
|
|
int month = iDC.InvoiceBase.AccountingPeriodStart.Value.Month;
|
|
int year = iDC.InvoiceBase.AccountingPeriodStart.Value.Year;
|
|
long cOid = iDC.InvoiceBase.SupportConceptCostBearerRelDc.SupportConcept.Customer.CustomerOid;
|
|
long oOid = iDC.InvoiceBase.RecipientOrganisationOid ?? 0;
|
|
|
|
var qb = CreateServiceOverviewSingleCustomerReport(cOid, month, year, oOid, 0, null, 1, DateTime.DaysInMonth(year, month));
|
|
qb.CreateDocument();
|
|
seite1.Pages.AddRange(qb.Pages);
|
|
|
|
invoiceReport = seite1;
|
|
|
|
}
|
|
else
|
|
{
|
|
var ro = ServiceInvoiceRO.Create(iDC);
|
|
singleReport.SetReportDataSource(ro);
|
|
((XtraReport)singleReport).CreateDocument();
|
|
invoiceReport = singleReport as XtraReport;
|
|
|
|
if (iDC.InvoiceBase.InvoiceId == "Sammelrechnung")
|
|
{
|
|
var anhang = new SammelrechnungTab();
|
|
anhang.SetReportDataSource(ro);
|
|
anhang.CreateDocument();
|
|
((XtraReport)singleReport).Pages.AddRange(((XtraReport)anhang).Pages);
|
|
invoiceReport = singleReport as XtraReport;
|
|
}
|
|
if (iDC.InvoiceBase.InvoiceId == "SammelrechnungBthg")
|
|
{
|
|
var anhang = new SammelrechnungTabBthg();
|
|
anhang.SetReportDataSource(ro);
|
|
anhang.CreateDocument();
|
|
((XtraReport)singleReport).Pages.AddRange(((XtraReport)anhang).Pages);
|
|
invoiceReport = singleReport as XtraReport;
|
|
}
|
|
|
|
if (iDC.InvoiceBase.SupportConceptCostBearerRelDc != null)
|
|
{
|
|
var customerDC = MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.GetByID<Customer>(iDC.InvoiceBase.SupportConceptCostBearerRelDc.SupportConcept.Customer.CustomerOid));
|
|
if (customerDC.RelatedTeams.Any(t => t.Team.Name.ToLower().Contains("pfk")))
|
|
{
|
|
int month = iDC.InvoiceBase.AccountingPeriodStart.Value.Month;
|
|
int year = iDC.InvoiceBase.AccountingPeriodStart.Value.Year;
|
|
long cOid = iDC.InvoiceBase.SupportConceptCostBearerRelDc.SupportConcept.Customer.CustomerOid;
|
|
long oOid = iDC.InvoiceBase.RecipientOrganisationOid ?? 0;
|
|
|
|
var qb = CreateServiceOverviewSingleCustomerReport(cOid, month, year, oOid, 0, null, 1, DateTime.DaysInMonth(year, month));
|
|
qb.CreateDocument();
|
|
invoiceReport.Pages.AddRange(qb.Pages);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (allReports == null)
|
|
allReports = invoiceReport;
|
|
else
|
|
((XtraReport)allReports).Pages.AddRange(invoiceReport.Pages);
|
|
}
|
|
|
|
return allReports as XtraReport;
|
|
}
|
|
|
|
public override XtraReport CreateUserListReport(List<long> oids)
|
|
{
|
|
var queryReport = FindReportImp<QueryRO>(null, "Benutzergruppen");
|
|
|
|
var lUser = DAOFactory.GenericDAO.LoadByIDs<ApplicationUser>(oids);
|
|
var teams = DAOFactory.GenericDAO.GetAllActive<Team>();
|
|
|
|
string[] lHeaderCaption = {
|
|
"Mitarbeiter", // 0
|
|
"Login", // 1
|
|
"zugeordnete Benutzergruppen", // 2
|
|
"Teams", // 3
|
|
};
|
|
|
|
string[][] lContent = new string[lUser.Count][];
|
|
|
|
for (int iRowCount = 0; iRowCount < lUser.Count; iRowCount++)
|
|
{
|
|
lContent[iRowCount] = new string[lHeaderCaption.Count()];
|
|
|
|
if (lUser[iRowCount].Employee != null)
|
|
lContent[iRowCount][0] = lUser[iRowCount].Employee.Person.FirstNameLastName;
|
|
else
|
|
lContent[iRowCount][0] = string.Empty;
|
|
|
|
if (lUser[iRowCount].LoginName != null)
|
|
lContent[iRowCount][1] = lUser[iRowCount].LoginName;
|
|
else
|
|
lContent[iRowCount][1] = string.Empty;
|
|
|
|
if (lUser[iRowCount].UserGroups != null && lUser[iRowCount].UserGroups.Count > 0)
|
|
lContent[iRowCount][2] = string.Join(", ", lUser[iRowCount].UserGroups.Select(
|
|
r => r.Name).OrderBy(s => s).ToArray());
|
|
else
|
|
lContent[iRowCount][2] = string.Empty;
|
|
|
|
// ZUSÄTZLICHE SPALTE FÜR TEAMS
|
|
|
|
string teamsString = "";
|
|
foreach (var team in teams)
|
|
{
|
|
if (team.MemberList.Any(m => m.Oid == lUser[iRowCount].Employee.Oid))
|
|
teamsString += team.Name + ", ";
|
|
}
|
|
|
|
if (teamsString != "")
|
|
{
|
|
teamsString = teamsString.Remove(teamsString.Length - 2, 2);
|
|
lContent[iRowCount][3] = teamsString;
|
|
}
|
|
else
|
|
lContent[iRowCount][3] = string.Empty;
|
|
}
|
|
|
|
// Zweidimensionales Array zu DataTable konvertieren
|
|
DataTable table = new DataTable();
|
|
int columnNumber = 4;
|
|
for (int i = 0; i < columnNumber; i++)
|
|
table.Columns.Add(lHeaderCaption[i], typeof(string));
|
|
|
|
|
|
int rowNumber = lContent.GetLength(0);
|
|
for (int i = 0; i < rowNumber; i++)
|
|
{
|
|
DataRow row = table.NewRow();
|
|
for (int j = 0; j < columnNumber; j++)
|
|
{
|
|
row[j] = lContent[i][j];
|
|
}
|
|
table.Rows.Add(row);
|
|
}
|
|
|
|
var queryReportObject = QueryRO.Create(new Query() { Title = "Benutzer inkl. Teams" }, table);
|
|
queryReportObject.Name = "Benutzer inkl. Teams";
|
|
queryReport.SetReportDataSource(queryReportObject);
|
|
|
|
return queryReport as XtraReport;
|
|
}
|
|
|
|
public override XtraReport CreateServiceRecordListReport(long employeeOid, long customerOid, long supportConceptOid, long costbearer2SupportConceptOid, bool isLimitedToAdditionalServices, DateTimeSpan limitingTimeSpan)
|
|
{
|
|
IBeWoReport<ServiceRecordListRO> lServiceRecordListReport = new Leistungen();
|
|
|
|
if (customerOid > 0)
|
|
{
|
|
var customer = MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.GetByID<Customer>(customerOid));
|
|
if (customer.RelatedTeams.Any(t => t.Team.Name.ToLower().Contains("pfk")))
|
|
lServiceRecordListReport = new LeistungenPFK();
|
|
}
|
|
|
|
var ro = ServiceRecordListRO.Create(employeeOid, customerOid, supportConceptOid, costbearer2SupportConceptOid, isLimitedToAdditionalServices, limitingTimeSpan);
|
|
lServiceRecordListReport.SetReportDataSource(ro);
|
|
|
|
return lServiceRecordListReport as XtraReport;
|
|
}
|
|
|
|
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);
|
|
|
|
if (lROs.Count > 0)
|
|
{
|
|
|
|
var rootReport = CreateServicesOverviewReportForRo(lROs[0], serviceCategoryOid);
|
|
rootReport.CreateDocument();
|
|
|
|
for (int i = 1; i < lROs.Count; i++)
|
|
{
|
|
var lNext = CreateServicesOverviewReportForRo(lROs[i], serviceCategoryOid);
|
|
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);
|
|
|
|
}
|
|
|
|
private XtraReport CreateServicesOverviewReportForRo(ServicesOverviewRO ro, long? serviceCategoryOid)
|
|
{
|
|
IBeWoReport<ServicesOverviewRO> report = null;
|
|
|
|
var customer = MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.GetByID<Customer>(ro.CustomerOid));
|
|
if (customer.RelatedTeams.Any(t => t.Team.Name.ToLower().Contains("pfk")))
|
|
{
|
|
report = new QuittierungsbelegPfk();
|
|
}
|
|
|
|
if (report == null)
|
|
report = new Quittierungsbeleg();
|
|
report.SetReportDataSource(ro);
|
|
|
|
return report as XtraReport;
|
|
}
|
|
}
|
|
}
|