432 lines
18 KiB
C#
432 lines
18 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
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 BS.Shared.DataContracts;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace DomizielAnsbach
|
|
{
|
|
public class CustomReportCreator : DefaultReportCreator
|
|
{
|
|
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
|
|
{
|
|
if (queryOid == 100)
|
|
return CreateEinschaetzungsbogenZV(queryOid, queryReportId);
|
|
else if (queryOid == 101)
|
|
return CreateKlientenstammblattZV(queryOid, queryReportId);
|
|
else if (queryOid == 200)
|
|
return CreateArbeitszeitberechnungZV(queryOid, queryReportId);
|
|
|
|
else if (queryOid == 201)
|
|
return CreateBerichtBezirkZV(queryOid, queryReportId);
|
|
|
|
return base.CreateQueryReport(queryOid, queryReportId);
|
|
}
|
|
|
|
private XtraReport CreateEinschaetzungsbogenZV(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 dt = DateTime.Now;
|
|
DateTime.TryParse(qro.Rows[0].Field1.ToString(), out dt);
|
|
dt = dt.AddMonths(1).AddDays(-1);
|
|
|
|
long? customerOid = null;
|
|
if (qro.Rows[0].Field2 != null && qro.Rows[0].Field2.ToString() != "0")
|
|
{
|
|
customerOid = Int64.Parse(qro.Rows[0].Field2.ToString());
|
|
var customer = DAOFactory.GenericDAO.LoadByID<Customer>(customerOid.Value);
|
|
var ro = (CustomerDataRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(customer)));
|
|
var cRo = CreateKlientenStammdatenRO(dt, ro);
|
|
var druck = new Selbsteinschaetzung();
|
|
druck.SetReportDataSource(cRo);
|
|
return druck;
|
|
}
|
|
if (customerOid == null)
|
|
{
|
|
XtraReport masterReport = new XtraReport();
|
|
masterReport.CreateDocument();
|
|
|
|
var customerList = DAOFactory.GenericDAO.GetAllActive<Customer>();
|
|
foreach (var c in customerList)
|
|
{
|
|
foreach (var v2o in c.ValueList)
|
|
{
|
|
if (v2o.Entry.Type == ValueListEntryType.CustomerCareType && v2o.Entry.Value.Contains("Zuverdienst"))
|
|
{
|
|
var ro = (CustomerDataRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(c)));
|
|
var cRo = CreateKlientenStammdatenRO(dt, ro);
|
|
var seite1 = new Selbsteinschaetzung();
|
|
seite1.SetReportDataSource(cRo);
|
|
seite1.CreateDocument();
|
|
masterReport.Pages.AddRange(seite1.Pages);
|
|
}
|
|
}
|
|
}
|
|
return masterReport;
|
|
}
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
private XtraReport CreateKlientenstammblattZV(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 dt = DateTime.Now;
|
|
DateTime.TryParse(qro.Rows[0].Field1.ToString(), out dt);
|
|
dt = dt.AddMonths(1).AddDays(-1);
|
|
|
|
long? customerOid = null;
|
|
if (qro.Rows[0].Field2 != null && qro.Rows[0].Field2.ToString() != "0")
|
|
{
|
|
customerOid = Int64.Parse(qro.Rows[0].Field2.ToString());
|
|
var c = DAOFactory.GenericDAO.LoadByID<Customer>(customerOid.Value);
|
|
var ro = (CustomerDataRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(c)));
|
|
var cRo = CreateKlientenStammdatenRO(dt, ro);
|
|
var druck = new KlientenstammblattZV();
|
|
druck.SetReportDataSource(cRo);
|
|
return druck;
|
|
}
|
|
if (customerOid == null)
|
|
{
|
|
XtraReport masterReport = new XtraReport();
|
|
masterReport.CreateDocument();
|
|
|
|
var customerList = DAOFactory.GenericDAO.GetAllActive<Customer>();
|
|
foreach (var c in customerList)
|
|
{
|
|
foreach (var v2o in c.ValueList)
|
|
{
|
|
if (v2o.Entry.Type == ValueListEntryType.CustomerCareType && v2o.Entry.Value.Contains("Zuverdienst"))
|
|
{
|
|
var ro = (CustomerDataRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(c)));
|
|
var cRo = CreateKlientenStammdatenRO(dt, ro);
|
|
var seite1 = new KlientenstammblattZV();
|
|
seite1.SetReportDataSource(cRo);
|
|
seite1.CreateDocument();
|
|
masterReport.Pages.AddRange(seite1.Pages);
|
|
}
|
|
}
|
|
}
|
|
return masterReport;
|
|
}
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
private KlientenStammdatenRO CreateKlientenStammdatenRO(DateTime dt, CustomerDataRO ro)
|
|
{
|
|
KlientenStammdatenRO newRo = new KlientenStammdatenRO();
|
|
|
|
newRo.Datum = dt;
|
|
newRo.CustomerDataRO = ro;
|
|
|
|
return newRo;
|
|
}
|
|
|
|
private XtraReport CreateArbeitszeitberechnungZV(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());
|
|
DateTime start = new DateTime(monat.Year, 1, 1);
|
|
DateTime end = monat.AddMonths(1).AddDays(-1);
|
|
|
|
var ro = FinanceRO.Create(start, end);
|
|
var druck = new Arbeitszeitberechnung();
|
|
druck.SetReportDataSource(ro);
|
|
return druck;
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
private XtraReport CreateBerichtBezirkZV(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());
|
|
DateTime start = new DateTime(monat.Year, 1, 1);
|
|
DateTime end = monat.AddMonths(1).AddDays(-1);
|
|
|
|
var ro = FinanceRO.Create(start, end);
|
|
var druck = new BerichtBezirkZV();
|
|
druck.SetReportDataSource(ro);
|
|
return druck;
|
|
}
|
|
return new XtraReport();
|
|
}
|
|
|
|
//public override XtraReport CreateCustomerDataReport(long customerOid)
|
|
//{
|
|
// var lCustomerDataReport = FindReportImp<CustomerDataRO>();
|
|
// if (TemplateOid == 2)
|
|
// lCustomerDataReport = new DomizielAnsbach.KlientenstammblattZV();
|
|
// else
|
|
// lCustomerDataReport = new Klientenstammblatt();
|
|
// lCustomerDataReport.SetReportDataSource(CustomerDataRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.LoadByID<Customer>(customerOid))));
|
|
// return lCustomerDataReport as XtraReport;
|
|
//}
|
|
|
|
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 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
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = FindReportImp<ServiceInvoiceRO>(reportId);
|
|
|
|
singleReport.SetReportDataSource(ServiceInvoiceRO.Create(iDC));
|
|
((XtraReport)singleReport).CreateDocument();
|
|
if (allReports == null)
|
|
allReports = singleReport;
|
|
else
|
|
((XtraReport)allReports).Pages.AddRange(((XtraReport)singleReport).Pages);
|
|
|
|
if (reportId == "RgBezirkDetail")
|
|
{
|
|
singleReport = FindReportImp<ServiceInvoiceRO>("RgBezirk");
|
|
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();
|
|
}
|
|
|
|
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);
|
|
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;
|
|
}
|
|
// er müsste durch alle Hilfepläne laufen -> nicht schön...
|
|
//else if (lROs.Count == 0 && serviceCategoryOid == 24)
|
|
//{
|
|
// var rootReport = CreateServicesOverviewReportForRo(lROs[0], serviceCategoryOid);
|
|
// 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);
|
|
if (ro.EndDate > DateTime.Now.AddDays(1) && serviceCategoryOid == 24)
|
|
CheckeHilfeplan(ro);
|
|
|
|
return CreateServicesOverviewReportForRo(ro, serviceCategoryOid);
|
|
}
|
|
|
|
private XtraReport CreateServicesOverviewReportForRo(ServicesOverviewRO ro, long? serviceCategoryOid)
|
|
{
|
|
XtraReport report = null;
|
|
|
|
if (ro.EndDate > DateTime.Now.AddDays(1) && serviceCategoryOid == 24)
|
|
{
|
|
IBeWoReport<ServicesOverviewRO> beleg = new DomizielAnsbach.QuittierungsbelegZV();
|
|
ro.Services = new List<ServicesOverviewRO.ServiceDetail>();
|
|
for (int i = 0; i < 31; i++)
|
|
{
|
|
ro.Services.Add(new ServicesOverviewRO.ServiceDetail());
|
|
}
|
|
report = AddSubServicesOverviewReportToReport(report, new QuittierungsbelegZV(), ro);
|
|
|
|
return report;
|
|
}
|
|
else
|
|
{
|
|
ServicesOverviewRO bewoRo = ServicesOverviewRO.CopyFromRO(ro);
|
|
ServicesOverviewRO pbRo = ServicesOverviewRO.CopyFromRO(ro);
|
|
ServicesOverviewRO zvRo = ServicesOverviewRO.CopyFromRO(ro);
|
|
|
|
if (ro.Services != null)
|
|
{
|
|
foreach (ServicesOverviewRO.ServiceDetail s in ro.Services)
|
|
{
|
|
if (s.ServiceCategory.Contains("Ambulant Betreutes ") || s.ServiceCategory.Contains("Indirekt"))
|
|
bewoRo.Services.Add(s);
|
|
else if (s.ServiceCategory.Contains("Zuverdienst - Arbeitszeit"))
|
|
zvRo.Services.Add(s);
|
|
else
|
|
pbRo.Services.Add(s);
|
|
}
|
|
}
|
|
|
|
report = AddSubServicesOverviewReportToReport(report, new QuittierungsbelegAbw(), bewoRo);
|
|
report = AddSubServicesOverviewReportToReport(report, new QuittierungsbelegZV(), zvRo);
|
|
report = AddSubServicesOverviewReportToReport(report, new QuittierungsbelegPB(), pbRo);
|
|
|
|
if (report == null)
|
|
report = new XtraReport();
|
|
|
|
return report as XtraReport;
|
|
}
|
|
}
|
|
|
|
private void CheckeHilfeplan(ServicesOverviewRO ro)
|
|
{
|
|
if (ro.CostBearer2SupportConceptList.Count == 0)
|
|
{
|
|
//Suche Hilfeplan
|
|
var customer = DAOFactory.GenericDAO.LoadByID<Customer>(ro.CustomerOid);
|
|
|
|
foreach (var sc in customer.SupportConcepts)
|
|
{
|
|
foreach (var c2s in sc.CostBearer2SupportConceptList)
|
|
{
|
|
if (c2s.StartDate.HasValue && c2s.EndDate.HasValue && c2s.StartDate.Value < ro.EndDate && c2s.EndDate.Value >= ro.StartDate)
|
|
{
|
|
ro.ReferenceNumber = c2s.CustomerReferenceNumber;
|
|
|
|
foreach (var ap in c2s.ApprovalPeriodList)
|
|
{
|
|
if (ap.ApprovedBETotal.HasValue)
|
|
{
|
|
ro.ApprovedFLSPerWeekTotal = ap.ApprovedBETotal.Value;
|
|
}
|
|
else if (ap.ApprovedBEPerInterval.HasValue)
|
|
{
|
|
ro.ApprovedFLSPerWeekTotal = ap.ApprovedBEPerInterval.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|