using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Reflection; using BeWo.Report.DefaultReports; using BS.Shared; using BeWo.Data; using BeWo.Data.Access; using BeWo.Data.Entities; using BeWo.Report.ReportObjects; using BeWo.Service.DCEntityMapper; using BeWo.Service.ServiceImplementations; using BS.Shared.Core; using BS.Shared.DataContracts; using DevExpress.XtraReports.UI; using BS.Shared.DataContracts.Compact; using BeWo.Service.Plugins; namespace BeWo.Report { public class DefaultReportCreator : AbstractReportCreator { public IBeWoReport FindReportImp() { return FindReportImp(null, null); } public IBeWoReport FindReportImp(string specificReportId) { return this.FindReportImp(specificReportId, null); } public IBeWoReport FindReportImp(string specificReportId, string typename) { IBeWoReport result = null; if (TemplateOid.HasValue && TemplateOid.Value > 0) { var template = DAOFactory.GenericDAO.LoadByID(TemplateOid.Value); if (!String.IsNullOrEmpty(template.ReferenceClass)) { specificReportId = template.ReferenceClass; } else if (!String.IsNullOrEmpty(template.DisplayName)) { specificReportId = template.DisplayName; } } Type[] lAllReportTypes = null; if (Tenant != null && File.Exists(ReportPath)) { lAllReportTypes = Assembly.LoadFrom(ReportPath).GetTypes(); result = FindReportImp(lAllReportTypes, specificReportId, typename, true); } if (result == null) { lAllReportTypes = typeof(IBeWoReport).Assembly.GetTypes(); result = FindReportImp(lAllReportTypes, specificReportId, typename, false); } return result; } public IBeWoReport FindReportImp(Type[] lAllReportTypes, string specificReportId, string typename, bool doNotUseReportsWithIdentifier) { IBeWoReport result = null; var typeOfT = typeof(T); if (!string.IsNullOrEmpty(specificReportId) && !string.IsNullOrEmpty(typename)) { var cbSpecific = lAllReportTypes .Where(i => typeof(IBeWoReport).IsAssignableFrom(i)) .FirstOrDefault(t => t.GetCustomAttributes(typeof(IDSpecificClassAttribute), true) .ToList() .Exists(i => { var attr = (IDSpecificClassAttribute)i; if (attr.Identifiers != null) return attr.Identifiers.Contains(specificReportId); if (!String.IsNullOrEmpty(attr.Identifier)) return attr.Identifier.Equals(specificReportId); return false; } ) && t.FullName == typename); if (cbSpecific != null) result = Activator.CreateInstance(cbSpecific) as IBeWoReport; } if (!string.IsNullOrEmpty(typename)) { var cbSpecific = lAllReportTypes.FirstOrDefault(t => t.FullName == typename); if (cbSpecific != null) result = Activator.CreateInstance(cbSpecific) as IBeWoReport; } if (!string.IsNullOrEmpty(specificReportId)) { var cbSpecific = lAllReportTypes .Where(i => typeof(IBeWoReport).IsAssignableFrom(i)) .FirstOrDefault(t => t.GetCustomAttributes(typeof(IDSpecificClassAttribute), true) .ToList() .Exists(i => { var attr = (IDSpecificClassAttribute)i; if (attr.Identifiers != null) { return attr.Identifiers.Contains(specificReportId); } if (!String.IsNullOrEmpty(attr.Identifier)) { if (specificReportId == "SammelrechnungNachKlienten") { var test = attr.Identifier.Equals(specificReportId); } return attr.Identifier.Equals(specificReportId); } return false; } )); if (cbSpecific != null) result = Activator.CreateInstance(cbSpecific) as IBeWoReport; } if (result == null) { foreach (var iType in lAllReportTypes) if (typeof(IBeWoReport).IsAssignableFrom(iType)) if (iType.Name == specificReportId) result = Activator.CreateInstance(iType) as IBeWoReport; } if (result == null) { var list = lAllReportTypes.Where(t => typeof(IBeWoReport).IsAssignableFrom(t)).ToList(); if (list.Count == 1) { var type = list[0]; if (doNotUseReportsWithIdentifier) { var attrs = type.GetCustomAttributes(typeof(IDSpecificClassAttribute), true); if (attrs.Length == 0) return Activator.CreateInstance(type) as IBeWoReport; } else { result = Activator.CreateInstance(type) as IBeWoReport; } } else if (list.Count > 1) { foreach (var type in list) { var attrs = type.GetCustomAttributes(typeof(IDSpecificClassAttribute), true); if (attrs.Length == 0) return Activator.CreateInstance(type) as IBeWoReport; } if (!doNotUseReportsWithIdentifier) { result = Activator.CreateInstance(list[0]) as IBeWoReport; } } } return result; } public override XtraReport CreateCustomerDataReport(long customerOid) { var lCustomerDataReport = FindReportImp(); lCustomerDataReport.SetReportDataSource(CustomerDataRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.LoadByID(customerOid)))); return lCustomerDataReport as XtraReport; } public override XtraReport CreateCustomerInvoiceReport(long invoiceOid) { IBeWoReport lInvoiceCustomerReport = FindReportImp(); lInvoiceCustomerReport.SetReportDataSource(InvoiceCustomerRO.Create(MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDC(DAOFactory.GenericDAO.LoadByID(invoiceOid)))); return lInvoiceCustomerReport as XtraReport; } public override XtraReport CreateAssessmentSheetReport(long customerOid, int month, int year) { IBeWoReport report = FindReportImp(); report.SetReportDataSource(AssessmentSheetRO.Create(DAOFactory.GenericDAO.LoadByID(customerOid), new DateTime(year, month, 1))); return report as XtraReport; } public override XtraReport CreateFlsReport(String flsReportId, String subType) { string flsReportPath = BS.Shared.Core.Utils.CreateSavePath(TempPath, flsReportId + ".xml"); var lFLSAnalysisDataReportDC = Utils.XMLDeserialize(flsReportPath); IBeWoReport lFLSReportObject = null; if (!String.IsNullOrEmpty(subType)) lFLSReportObject = this.FindReportImp(subType); if (lFLSReportObject == null) lFLSReportObject = this.FindReportImp(lFLSAnalysisDataReportDC.ShowGroups ? "FLSAuswertung" : "Leistungsdokumentation"); lFLSReportObject.SetReportDataSource(FLSReportRO.Create(lFLSAnalysisDataReportDC)); return lFLSReportObject as XtraReport; } public override XtraReport CreateQueryReport(long queryOid, String queryReportId) { var query = DAOFactory.GenericDAO.LoadByID(queryOid); if (query == null) return new XtraReport(); var path = BS.Shared.Core.Utils.CreateSavePath(TempPath, queryReportId + ".xml"); var table = Utils.XMLDeserialize(path); var queryReport = FindReportImp(null, query.ReportTypeName); queryReport.SetReportDataSource(QueryRO.Create(query, table)); return queryReport 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(); var dcList = new List(); var dcidStrs = dcIds.Split(';'); foreach (var oidStr in dcidStrs) { var oid = long.Parse(oidStr); var invoice = DAOFactory.GenericDAO.LoadByID(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(item.SupportConceptApprovalPeriodOid.Value); if (approvalPeriod.CostBearer2SupportConcept != null) { AddCostBearerIdToDict(oid, serviceInvoiceOid2CostbearerId, approvalPeriod.CostBearer2SupportConcept); } } } } catch (Exception) { //ignore } } } } IBeWoReport allReports = null; foreach (var iDC in dcList) { String reportId = null; if (serviceInvoiceOid2CostbearerId.ContainsKey(iDC.ServiceInvoiceOid.Value)) reportId = serviceInvoiceOid2CostbearerId[iDC.ServiceInvoiceOid.Value]; IBeWoReport singleReport = FindReportImp(reportId); 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 virtual void AddCostBearerIdToDict(long serviceInvoiceOid, Dictionary serviceInvoiceOid2CostbearerId, CostBearer2SupportConcept c2s) { if (c2s != null && c2s.CostBearer != null) { var id = c2s.CostBearer.ID; if (String.IsNullOrEmpty(id) && c2s.CostBearer.IsSingleInvoicePerCustomer) id = "Sammelrechnung"; if (!serviceInvoiceOid2CostbearerId.ContainsKey(serviceInvoiceOid)) serviceInvoiceOid2CostbearerId.Add(serviceInvoiceOid, id); } } public virtual XtraReport CreateServiceOverviewAllCustomersReport(int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay) { return CreateServiceOverviewAllCustomersReport(month, year, orgaOid, empOid, serviceCategoryOid, startDay, endDay, false); } public override XtraReport CreateServiceOverviewAllCustomersReport(int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay, bool nurFehlende) { var os = new OperationsServiceImp(); var m = os.GetMandator2(false); if (m.AllowSbd) { return CreateSbdLeistungsnachweisForAllCustomers(month, year, orgaOid, empOid, serviceCategoryOid ?? 0, startDay, endDay, false, "nrw"); } List lROs = ServicesOverviewRO.Create(month, year, orgaOid, empOid, startDay, endDay, serviceCategoryOid, true, nurFehlende); if (lROs.Count > 0) { String reportId = null; if (orgaOid > 0) { var organisation = DAOFactory.GenericDAO.LoadByID(orgaOid); if (organisation != null) reportId = organisation.Name; } var lServiceOverviewAllCustomersReport = this.FindReportImp(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(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 CreateServiceOverviewSingleCustomerReport(long customerOid, int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay) { var os = new OperationsServiceImp(); var m = os.GetMandator2(false); if (m.AllowSbd) { return CreateSbdLeistungsnachweisForSingleCustomerReport(customerOid, month, year, orgaOid, empOid, serviceCategoryOid ?? 0, startDay, endDay, false, "nrw"); } String reportId = null; if (orgaOid > 0) { var organisation = DAOFactory.GenericDAO.LoadByID(orgaOid); if (organisation != null) reportId = organisation.Name; } var ro = ServicesOverviewRO.Create(customerOid, month, year, false, orgaOid, empOid, startDay, endDay, serviceCategoryOid); var lServiceOverviewSingleCustomerReport = this.FindReportImp(reportId); if (ro != null) { lServiceOverviewSingleCustomerReport.SetReportDataSource(ro); } return lServiceOverviewSingleCustomerReport as XtraReport; } public override XtraReport CreateServiceOverviewReportNew(int month, int year, QBFilterEnum filterType, long? customerOid, long? teamOid, long? empOid, long? orgaOid, long? serviceCategoryOid, int startDay, int endDay, bool nurFehlende) { switch (filterType) { case QBFilterEnum.AlleKlienten: if (!nurFehlende) { return CreateServiceOverviewAllCustomersReport(month, year, orgaOid ?? 0, empOid ?? 0, serviceCategoryOid, startDay, endDay); } return CreateServiceOverviewAllCustomersReport(month, year, orgaOid ?? 0, empOid ?? 0, serviceCategoryOid, startDay, endDay, nurFehlende); break; case QBFilterEnum.NurKlientenMeinesTeams: var list1 = GetKlientenOidsMeinesTeams(null); return CreateServiceOverviewReportForCustomers(list1, month, year, orgaOid, empOid, serviceCategoryOid, startDay, endDay, nurFehlende); break; case QBFilterEnum.MeineKlienten: var list2 = GetMeineKlientenOids(); return CreateServiceOverviewReportForCustomers(list2, month, year, orgaOid, empOid, serviceCategoryOid, startDay, endDay, nurFehlende); break; case QBFilterEnum.KlientenAuswahl: return CreateServiceOverviewSingleCustomerReport(customerOid ?? 0, month, year, orgaOid ?? 0, empOid ?? 0, serviceCategoryOid, startDay, endDay); break; case QBFilterEnum.TeamAuswahl: var list3 = GetKlientenOidsMeinesTeams(teamOid); return CreateServiceOverviewReportForCustomers(list3, month, year, orgaOid, empOid, serviceCategoryOid, startDay, endDay, nurFehlende); break; } return new XtraReport(); } public static IList GetMeineKlientenOids() { IList customerOids = new List(); ApplicationUser loggedInUser = null; if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null) { loggedInUser = LoggedInUserOperationContextExt.Current.User; } else { loggedInUser = SessionFacade.LoggedInUser; } if (loggedInUser != null && loggedInUser.Employee != null) { foreach (var e2c in loggedInUser.Employee.Employee2CustomerList) { if (e2c.Customer.IsActive == ActivationTypeId.Active) { foreach (var v2o in e2c.ValueList) { if (v2o.Entry.Type == ValueListEntryType.StaffRoleType && v2o.Entry.SystemEntryID.HasValue && v2o.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant) { if (!customerOids.Contains(e2c.Customer.Oid.Value)) { customerOids.Add(e2c.Customer.Oid.Value); } } } } } } return customerOids; } public virtual IList GetKlientenOidsMeinesTeams(long? teamOid) { IList customerOids = new List(); ApplicationUser loggedInUser = null; if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null) { loggedInUser = LoggedInUserOperationContextExt.Current.User; } else { loggedInUser = SessionFacade.LoggedInUser; } if (loggedInUser != null && loggedInUser.Employee != null) { var teams = new List(); if (teamOid.HasValue) { teams.Add(DAOFactory.GenericDAO.LoadByID(teamOid.Value)); } else { teams.AddRange(DAOFactory.SearchDAO.FindLeadingTeams(loggedInUser.Employee.Oid.Value)); teams.AddRange(DAOFactory.SearchDAO.FindTeamsOfEmployee(loggedInUser.Employee.Oid.Value)); } //1. Mitarbeiter der Teams durchlaufen oder //foreach (var team in teams) //{ // foreach (var employee in team.MemberList) // { // foreach (var e2c in employee.Employee2CustomerList) // { // if (e2c.Customer.IsActive == ActivationTypeId.Active) // { // foreach (var v2o in e2c.ValueList) // { // if (v2o.Entry.Type == ValueListEntryType.StaffRoleType && v2o.Entry.SystemEntryID.HasValue && v2o.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant) // { // if (!customerOids.Contains(e2c.Customer.Oid.Value)) // { // customerOids.Add(e2c.Customer.Oid.Value); // } // } // } // } // } // } //} //2. Klienten der Teams durchlaufen oder foreach (var team in teams) { var customers = DAOFactory.SearchDAO.FindCustomerOfTeam(team.Oid.Value); foreach (var c in customers) { if (c.IsActive == ActivationTypeId.Active) { if (!customerOids.Contains(c.Oid.Value)) { customerOids.Add(c.Oid.Value); } } } } } return customerOids; } public virtual XtraReport CreateServiceOverviewReportForCustomers(IList customerOids, int month, int year, long? orgaOid, long? empOid, long? serviceCategoryOid, int startDay, int endDay, bool nurFehlende) { var roList = new List(); 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); } } var sortedList = roList.OrderBy(r => r.CustomerLastName + ", " + r.CustomerFirstName).ToList(); if (sortedList.Count > 0) { String reportId = null; if (orgaOid.HasValue && orgaOid > 0) { var organisation = DAOFactory.GenericDAO.LoadByID(orgaOid.Value); if (organisation != null) reportId = organisation.Name; } var rootReport = CreateReportForServicesOverviewRo(sortedList[0], reportId); if (rootReport.Pages.Count == 0) { rootReport.CreateDocument(); } for (int i = 1; i < sortedList.Count; i++) { var lNext = CreateReportForServicesOverviewRo(sortedList[i], reportId); if (lNext.Pages.Count == 0) { lNext.CreateDocument(); } rootReport.Pages.AddRange(lNext.Pages); } return rootReport; } return new XtraReport(); } public virtual XtraReport CreateReportForServicesOverviewRo(ServicesOverviewRO ro, String reportId) { var serviceOverviewReport = this.FindReportImp(reportId); serviceOverviewReport.SetReportDataSource(ro); return serviceOverviewReport as XtraReport; } public virtual XtraReport AddSubServicesOverviewReportToReport(XtraReport masterReport, IBeWoReport newReport, ServicesOverviewRO ro) { if (ro.Services.Count > 0) { newReport.SetReportDataSource(ro); ((XtraReport)newReport).CreateDocument(); if (masterReport == null) { masterReport = newReport as XtraReport; } else { if (masterReport.Pages.Count == 0) { masterReport.CreateDocument(); } masterReport.Pages.AddRange(((XtraReport)newReport).Pages); } } return masterReport; } public override XtraReport CreateSbdLeistungsnachweisForAllCustomers(int month, int year, long orgaOid, long empOid, long serviceCategoryOid, int startDay, int endDay, bool checkServiceRecords, string bundesland) { return CreateReportForStundenaufstellungROs(SbdStundenaufstellungRO.Create(month, year, orgaOid, empOid, serviceCategoryOid, startDay, endDay, false, "nrw")); } public override XtraReport CreateSbdLeistungsnachweisForSingleCustomerReport(long customerOid, int month, int year, long orgaOid, long empOid, long serviceCategoryOid, int startDay, int endDay, bool checkServiceRecords, string bundesland) { return CreateReportForStundenaufstellungROs(SbdStundenaufstellungRO.Create(customerOid, month, year, orgaOid, empOid, serviceCategoryOid, startDay, endDay, false, "nrw", false)); } public virtual XtraReport CreateReportForStundenaufstellungROs(IList ros) { if (ros.Count > 0) { var lServiceOverviewAllCustomersReport = this.FindReportImp(); lServiceOverviewAllCustomersReport.SetReportDataSource(ros[0]); (lServiceOverviewAllCustomersReport as XtraReport).CreateDocument(); var Report = lServiceOverviewAllCustomersReport as XtraReport; for (int i = 1; i < ros.Count; i++) { var lNext = FindReportImp(); lNext.SetReportDataSource(ros[i]); (lNext as XtraReport).CreateDocument(); Report.Pages.AddRange((lNext as XtraReport).Pages); } return lServiceOverviewAllCustomersReport as XtraReport; } return new XtraReport(); } public override XtraReport CreateServiceRecordListReport(long employeeOid, long customerOid, long supportConceptOid, long costbearer2SupportConceptOid, bool isLimitedToAdditionalServices, DateTimeSpan limitingTimeSpan) { IBeWoReport lServiceRecordListReport = FindReportImp(); lServiceRecordListReport.SetReportDataSource(ServiceRecordListRO.Create(employeeOid, customerOid, supportConceptOid, costbearer2SupportConceptOid, isLimitedToAdditionalServices, limitingTimeSpan)); return lServiceRecordListReport as XtraReport; } public override XtraReport CreateSettlementReport(String dcId, long? invoiceBaseOid) { return CreateSettlementReport(dcId, invoiceBaseOid, false); } public virtual XtraReport CreateSettlementReport(String dcId, long? invoiceBaseOid, bool createAnhang) { XtraReport report = null; Settlement2DC lSettlementDC; long result; if (string.IsNullOrEmpty(dcId) && invoiceBaseOid.HasValue) { lSettlementDC = MapperFactory.SettlementDC_SettlementInvoice.MapToNewDC(DAOFactory.SearchDAO.GetSettlementInvoiceByInvoiceBaseOid(invoiceBaseOid.Value)); } else if (Int64.TryParse(dcId, out result)) { lSettlementDC = MapperFactory.SettlementDC_SettlementInvoice.MapToNewDC(DAOFactory.GenericDAO.LoadByID(result)); // = Utils.XMLDeserialize(lPath); } else { string lPath = BS.Shared.Core.Utils.CreateSavePath(TempPath, dcId); lSettlementDC = Utils.XMLDeserialize(lPath); } String reportId = null; if (lSettlementDC.CostBearer2SupportConceptOid.HasValue) { CostBearer2SupportConcept c2s = DAOFactory.GenericDAO.LoadByID(lSettlementDC.CostBearer2SupportConceptOid.Value); reportId = c2s.CostBearer.ID; } if (lSettlementDC.DifferentHourlyRateCount > 0) { IBeWoReport lSettlementReport = FindReportImp(reportId); var ro = SettlementRO.Create(lSettlementDC); lSettlementReport.SetReportDataSource(ro); report = lSettlementReport as XtraReport; } else { IBeWoReport lSettlementReport = FindReportImp(reportId); lSettlementReport.SetReportDataSource(Settlement2RO.Create(lSettlementDC)); report = lSettlementReport as XtraReport; } if (createAnhang) { if (report != null) { report.CreateDocument(); var anhang = CreateBudgetnachweisAnhang(lSettlementDC); if (anhang != null) { anhang.CreateDocument(); report.Pages.AddRange(anhang.Pages); } } } return report; } protected virtual XtraReport CreateBudgetnachweisAnhang(Settlement2DC settlementDC) { var ro = PluginLoader.FindClass(); ro.Create(settlementDC); IBeWoReport anhang = FindReportImp(); anhang.SetReportDataSource(ro); return anhang as XtraReport; } public override XtraReport CreateSupportConceptReport(IList c2sOids, long? employeeOid, long? teamOid, long? catOid, int? expiredMonths, bool archivedSupportConcepts, DateTime? startDate, DateTime? endDate) { var lSupportConceptReport = FindReportImp(); lSupportConceptReport.SetReportDataSource(SupportConceptListRO.Create(c2sOids, employeeOid, teamOid, catOid, expiredMonths, archivedSupportConcepts, startDate, endDate)); return lSupportConceptReport as XtraReport; } public override XtraReport CreateAdditionalServiceBookingReport(long addServiceRegionOid, Monat month, int year) { var report = FindReportImp(); var x = AdditionalServiceBookingRO.Create( DAOFactory.GenericDAO.LoadByID(addServiceRegionOid), month, year); report.SetReportDataSource(x); return report as XtraReport; } public override XtraReport CreateEmployeeHourReport(long? employeeOid, IList teamOids, DateTime startDate, DateTime endDate, int ansicht) { IBeWoReport report; if (ansicht == 1) { report = FindReportImp("Mitarbeiterarbeitszeitkonto"); } else if (ansicht == 2) { var reportjahr = FindReportImp("MitarbeiterstundenkontoJahr"); var jahrStart = new DateTime(startDate.Year, 1, 1); var ds = new MitarbeiterstundenkontoMonateRO(employeeOid, teamOids, jahrStart, endDate, null); reportjahr.SetReportDataSource(ds); return reportjahr as XtraReport; } else { if (teamOids != null && teamOids.Count > 0) { report = FindReportImp("Teamstundenkonto"); } else { report = FindReportImp("Mitarbeiterstundenkonto"); } } var x = MitarbeiterstundenkontoRO.Create(employeeOid, teamOids, startDate, endDate, null); report.SetReportDataSource(x); return report as XtraReport; } public override XtraReport CreateAuslastungReport(long? employeeOid, IList teamOids, DateTime startDate, DateTime endDate) { IBeWoReport report; if (teamOids != null && teamOids.Count > 0) report = FindReportImp("Teamauslastung"); else report = FindReportImp("Mitarbeiterauslastung"); var x = MitarbeiterauslastungRO.Create(employeeOid, teamOids, startDate, endDate); report.SetReportDataSource(x); return report as XtraReport; } public override XtraReport CreateMediVerordListenReport(long? mvlOid) { var report = FindReportImp(); report.SetReportDataSource(MedVerListRO.Create(mvlOid)); return report as XtraReport; } public override XtraReport CreateMediVerordListenMZfReport(long? mvlOid, bool mitZusatzfeldern) { var report = FindReportImp(); report.SetReportDataSource(MedVerListRO.Create(mvlOid, mitZusatzfeldern)); return report as XtraReport; } public override XtraReport CreateKalenderReport(long? employeeOid, AppointmentViewType viewType, DateTime rangeStartDate, DateTime rangeEndDate, List datesList, List userRights) { var report = new DailyAppointmentReportKalender(); //switch (viewType) //{ // case AppointmentViewType.Week: // var r = new WeeklyAppointmentReport(); // r.SetReportDataSource(KalenderRO.Create(employeeOid, viewType, rangeStartDate, rangeEndDate, datesList)); // return r; //} //throw new NotImplementedException("Wird umgebaut"); //report.SetReportDataSource(KalenderRO.Create(employeeOid, viewType, rangeStartDate, rangeEndDate, datesList, userRights)); return report; } public override XtraReport CreateFinanceReport(DateTime? start, DateTime? end, bool onlyNotApproved) { var report = FindReportImp(); report.SetReportDataSource(FinanceRO.Create(start, end, onlyNotApproved)); return report as XtraReport; } public override XtraReport CreateJahresberichtReport(int year, long? cbOid, long? teamOid, long? betreuungsartOid) { var report = FindReportImp(); report.SetReportDataSource(JahresReportRO.Create(year, cbOid, teamOid, betreuungsartOid)); return report as XtraReport; } public override XtraReport CreateEmployeeDataReport(long oid) { var report = FindReportImp(); report.SetReportDataSource(EmployeeDataRO.Create(MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.LoadByID(oid)))); return report as XtraReport; } public override XtraReport CreateEmployeeCustomerListReport(long? employeeOid) { var report = FindReportImp(); report.SetReportDataSource(EmployeeCustomerListRO.Create(employeeOid)); return report as XtraReport; } public override XtraReport CreateRatingReport(long ratingOid, long supportConceptOid) { var report = FindReportImp(); report.SetReportDataSource(RatingRO.Create(ratingOid, supportConceptOid)); return report as XtraReport; } public override XtraReport CreateNotizenReport(long kategorieOid, DateTime start, DateTime end) { var report = FindReportImp(); report.SetReportDataSource(NotizenRO.Create(start, end, MapperFactory.NotizenKategorieDC_NotizenKategorie.MapToNewDC(DAOFactory.GenericDAO.LoadByID(kategorieOid)))); return report as XtraReport; } public override XtraReport CreateBewertungsstatistikReport(DateTime? start, DateTime? end, SupportConceptDC supportConcept, bool inclZeiterfassung, List ziele, List scZiele) { var report = FindReportImp(); report.SetReportDataSource(BewertungsstatistikRO.Create(start, end, supportConcept, inclZeiterfassung, ziele, scZiele)); return report as XtraReport; } public override XtraReport CreateCustomReport(long employeeOid, String reportName) { if (String.IsNullOrEmpty(reportName)) { return new XtraReport(); } var report = FindReportImp(null, reportName); if (report == null) { return new XtraReport(); } return report as XtraReport; } public override XtraReport CreateSBDCharacteristicsReport(long customerOid) { var report = FindReportImp(); report.SetReportDataSource(SBDCharacteristicsRO.Create(MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.LoadByID(customerOid)))); return report as XtraReport; } public override XtraReport CreateKilometerauswertung(long customerOid, DateTime rangeDate) { var report = FindReportImp(); report.SetReportDataSource(KilometerauswertungsRO.Create(MapperFactory.CompactCustomerDC_CustomerCompact.MapToNewDC(DAOFactory.GenericDAO.LoadByID(customerOid)), rangeDate)); return report as XtraReport; } public override XtraReport CreateKilometerauswertungForAllCustomers(List customerOids, DateTime rangeDate) { var report = FindReportImp(); report.SetReportDataSource(KilometerauswertungsListRO.Create(MapperFactory.CompactCustomerDC_CustomerCompact.MapToNewDCs(DAOFactory.GenericDAO.LoadByIDs(customerOids)), rangeDate)); return report as XtraReport; } public override XtraReport CreateEmployeeKilometerauswertung(long employeeOid, DateTime range) { var report = FindReportImp(); report.SetReportDataSource(EmployeeKilometerauswertungsRO.Create(MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.LoadByID(employeeOid)), range)); return report as XtraReport; } public override XtraReport CreateKilometerauswertungForAllEmployees(List employeeOids, DateTime rangeDate) { var report = FindReportImp(); report.SetReportDataSource(EmployeeKilometerauswertungsListRO.Create(MapperFactory.CompactEmployeeDC_Employee.MapToNewDCs(DAOFactory.GenericDAO.LoadByIDs(employeeOids)), rangeDate)); return report as XtraReport; } public override XtraReport CreateAbsenceReport(DateTime dt, List abs, List empTypes, List teams, List feiertage) { var report = FindReportImp(); var service = new OperationsServiceImp(); var filter = new AbsenceOverviewFilterDC() { AbsenceReasons = abs, EmploymentType = empTypes, Year = dt.Year, Month = dt.Month, Teams = teams}; List compactTeams = new List(); if (teams != null) { if(teams.Count > 0) compactTeams = service.GetCertainTeamsById(teams); } report.SetReportDataSource(AbsenceRO.Create(service.GetAbsenceOverview(filter), filter, compactTeams, feiertage)); return report as XtraReport; } public override XtraReport CreateRosterReport(long wOid, DateTime dt, List feiertage, int sortingIndex, bool aufsteigend, long creator) { if (TemplateOid.HasValue && TemplateOid.Value == -2) { return CreateRosterReportIst(wOid, dt); } var service = new OperationsServiceImp(); var service2 = new CustomerServiceImp(); var report = FindReportImp(); var dienstEintraege = service.GetAllDienstEintraegeAsList(wOid, dt.Year, dt.Month); var vertretungen = service.GetAllDienstvertretungenAsList(wOid, dt.Year, dt.Month); List employeeOids = new List(); foreach (var eintrag in dienstEintraege) { if (!employeeOids.Contains(eintrag.EmployeeOid)) employeeOids.Add(eintrag.EmployeeOid); } foreach (var vertretung in vertretungen) { if (!employeeOids.Contains(vertretung.EmployeeOid)) employeeOids.Add(vertretung.EmployeeOid); } List employee = new List(); foreach (var oid in employeeOids) employee.Add(MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.GetByID(oid))); var creatorEmployee = MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.GetByID(creator)); //report.SetReportDataSource(RosterRO.Create(service.GetDienstEintraege(wOid, dt.Year, dt.Month), service.GetAllDienste(), service2.GetAllActiveWohnheimeCompact().First(x => x.WohnheimOid == wOid), dt.Year, dt.Month)); report.SetReportDataSource(RosterRO.CreateNew(dienstEintraege, vertretungen, employee, service.GetAllDienste(wOid), service2.GetAllActiveWohnheimeCompact().First(x => x.WohnheimOid == wOid), dt.Year, dt.Month, feiertage, sortingIndex, aufsteigend, creatorEmployee)); return report as XtraReport; } public override XtraReport CreateRosterReportIst(long wOid, DateTime dt) { var opertionsService = new OperationsServiceImp(); var customerService = new CustomerServiceImp(); var employeeService = new EmployeeServiceImp(); var report = FindReportImp(); var dienstEintraege = opertionsService.GetAllDienstEintraegeAsList(wOid, dt.Year, dt.Month); var vertretungen = opertionsService.GetAllDienstvertretungenAsList(wOid, dt.Year, dt.Month); List employeeOids = new List(); foreach (var eintrag in dienstEintraege) { if (!employeeOids.Contains(eintrag.EmployeeOid)) employeeOids.Add(eintrag.EmployeeOid); } foreach (var vertretung in vertretungen) { if (!employeeOids.Contains(vertretung.EmployeeOid)) employeeOids.Add(vertretung.EmployeeOid); } List employee = new List(); foreach (var oid in employeeOids) employee.Add(MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.GetByID(oid))); List absences = employeeService.GetMultipleEmployeeAbsenceTimesForMonth(dt.Year, dt.Month, employeeOids); List feiertageDCs = opertionsService.ErstelleDefaultFeiertage(dt.Year).Where(f => f.Datum.Month == dt.Month).ToList(); Dictionary stundenBeiAbwesenheit = new Dictionary(); foreach (var emp in employee) // Irgendwo hier drin Fehler { ContractDC currentContract = null; foreach (var c in emp.Contracts) { if (!c.ContractEndDate.HasValue) { if (dt >= c.EntryDate) { currentContract = c; break; } } else { if (dt >= c.EntryDate && dt <= c.ContractEndDate) { currentContract = c; break; } } } if (currentContract != null) { if (currentContract.WeeklyTotalHours == null || currentContract.WeeklyDays == null) continue; stundenBeiAbwesenheit.Add(emp.EmployeeOid, currentContract.WeeklyTotalHours.Value / currentContract.WeeklyDays); } } report.SetReportDataSource(RosterIstRO.Create(dienstEintraege, vertretungen, employee, opertionsService.GetAllDienste(wOid), customerService.GetAllActiveWohnheimeCompact().First(x => x.WohnheimOid == wOid), dt.Year, dt.Month, feiertageDCs, absences, stundenBeiAbwesenheit)); return report as XtraReport; } public override XtraReport CreateVorlagenReport(long template, List objectOids, long table) { string rtf = ""; var templateDC = MapperFactory.DokumentvorlageDC_Dokumentvorlage.MapToNewDC(DAOFactory.GenericDAO.GetByID(template)); OperationsServiceImp operations = new OperationsServiceImp(); XtraReport mainReport = null; foreach (var oid in objectOids) { string text = operations.ReplacePlaceholdersInTemplate(templateDC, oid, table); var report = FindReportImp(); report.SetReportDataSource(VorlageRO.Create(text)); ((XtraReport)report).CreateDocument(); if (mainReport == null) { mainReport = (XtraReport)report; } else { if (!text.Equals("")) mainReport.Pages.AddRange(((XtraReport)report).Pages); } } return mainReport; } public override XtraReport CreateAbwesenheitsPrintReport(List oids, string titel) { EmployeeServiceImp employeeService = new EmployeeServiceImp(); List list = employeeService.GetAbwesenheitsInformationPrints(oids); var report = FindReportImp(); report.SetReportDataSource(AbwesenheitsPrintRO.Create(list, titel)); ((XtraReport)report).CreateDocument(); return (XtraReport)report; } public override XtraReport CreateKassenbelegReport(BargeldtransaktionDC transaktion, long objectOid, TableID objectTid) { IBeWoReport report = FindReportImp(); var beguenstigter = LoadToBargeldkasseRelatedObject(objectTid, objectOid); report.SetReportDataSource(KassenbelegRO.Create(transaktion, beguenstigter)); return report as XtraReport; } private BeWoEntityBase LoadToBargeldkasseRelatedObject(TableID pObjectTid, long pObjectOid) { switch (pObjectTid) { case TableID.Customer: return DAOFactory.GenericDAO.LoadByID(pObjectOid); default: return null; } } } }