Files
BeWoPlaner/ReportImp/BloemelingUndTeckhaus/CustomReportCreator.cs
2024-06-19 16:13:56 +02:00

123 lines
5.6 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Service.DCEntityMapper;
using BS.Shared.DataContracts;
using DevExpress.XtraReports.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BloemelingUndTeckhaus
{
class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateServiceInvoiceReport(String dcIds, long? invoiceBaseOid)
{
#region standard
if (String.IsNullOrEmpty(dcIds) && invoiceBaseOid.HasValue)
{
var serviceInvoice = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(invoiceBaseOid.Value);
dcIds = String.Format("{0}", serviceInvoice.Oid);
}
if (!string.IsNullOrEmpty(dcIds))
{
var serviceInvoiceOid2CostbearerId = new Dictionary<long, string>();
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);
if (serviceInvoiceOid2CostbearerId.ContainsKey(oid))
continue;
if (!String.IsNullOrEmpty(invoice.InvoiceBase.InvoiceId))
serviceInvoiceOid2CostbearerId.Add(oid, invoice.InvoiceBase.InvoiceId);
else
{
foreach (var period in invoice.ServiceInvoicePeriodList)
{
try
{
if (period.SupportConceptApprovalPeriod != null)
{
AddCostBearerIdToDict(oid, serviceInvoiceOid2CostbearerId,
period.SupportConceptApprovalPeriod.CostBearer2SupportConcept);
}
foreach (var item in period.InvoiceItemList)
{
if (item.SupportConceptApprovalPeriodOid.HasValue)
{
var approvalPeriod =
DAOFactory.GenericDAO.LoadByID<SupportConceptApprovalPeriod>(item.SupportConceptApprovalPeriodOid.Value);
if (approvalPeriod.CostBearer2SupportConcept != null)
{
AddCostBearerIdToDict(oid, serviceInvoiceOid2CostbearerId, approvalPeriod.CostBearer2SupportConcept);
}
}
}
}
catch (Exception)
{
//ignore
}
}
}
}
#endregion
IBeWoReport<ServiceInvoiceRO> allReports = null;
foreach (var iDC in dcList)
{
String reportId = null;
if (serviceInvoiceOid2CostbearerId.ContainsKey(iDC.ServiceInvoiceOid.Value))
reportId = serviceInvoiceOid2CostbearerId[iDC.ServiceInvoiceOid.Value];
IBeWoReport<ServiceInvoiceRO> singleReport = new ServiceInvoiceReport();
if (iDC.ServiceInvoicePeriods.Count > 0)
{
String serviceCategory = "";
if (iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod == null)
{
if (iDC.InvoiceBase.SupportConceptCostBearerRelDc.ApprovalPeriodList.Count == 1 && iDC.InvoiceBase.SupportConceptCostBearerRelDc.ApprovalPeriodList[0].ServiceCategory != null)
{
//serviceCategory = iDC.InvoiceBase.SupportConceptCostBearerRelDc.ApprovalPeriodList[0].ServiceCategory.Name.ToLower();
}
}
else if (iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod.ServiceCategory != null)
{
serviceCategory = iDC.ServiceInvoicePeriods[0].SupportConceptApprovalPeriod.ServiceCategory.Name.ToLower();
}
if (serviceCategory.Contains("soziotherapie"))
singleReport = new SoziotherapieRechnung();
else if (serviceCategory.Contains("assistenz"))
singleReport = new RechnungAssistenzstunden();
else
singleReport = new ServiceInvoiceReport();
}
singleReport.SetReportDataSource(ServiceInvoiceRO.Create(iDC));
((XtraReport)singleReport).CreateDocument();
if (allReports == null)
allReports = singleReport;
else
((XtraReport)allReports).Pages.AddRange(((XtraReport)singleReport).Pages);
}
return allReports as XtraReport;
}
return new XtraReport();
}
}
}