diff --git a/Report/DefaultReportCreator.cs b/Report/DefaultReportCreator.cs index 588f56b06..af378d1e1 100644 --- a/Report/DefaultReportCreator.cs +++ b/Report/DefaultReportCreator.cs @@ -1845,40 +1845,28 @@ namespace BeWo.Report public override XtraReport CreateEmployeeListReport(List oids) { var queryReport = FindReportImp(null, "Mitarbeiter"); - var employees = DAOFactory.GenericDAO.LoadByIDs(oids); + var helper = PluginLoader.FindClass(); + + string[] lHeaderCaption = helper.PrepareHeaderArrayForEmployeeExport(); + string[][] lContent = helper.PrepareContentArrayForEmployeeExport(oids.ToArray()); + DataTable table = new DataTable(); - string[] spalten = new string[] { "Name", "Personalnummer", "Kürzel", "Anschrift", "Mobil", "Telefon", "Mail" }; - for (int i = 0; i < spalten.Length; i++) - table.Columns.Add(spalten[i], typeof(string)); + int columnNumber = lHeaderCaption.Count(); + // Spalten nur bis zur 10., da sonst der Druck nicht lesbar ist und weil in den ersten 9 die Kerninfos stehen + for (int i = 0; i < 10; i++) + table.Columns.Add(lHeaderCaption[i], typeof(string)); - for (int i = 0; i < employees.Count; i++) + + int rowNumber = lContent.GetLength(0); + for (int i = 0; i < rowNumber; i++) { DataRow row = table.NewRow(); - Employee employee = employees[i]; - row[1] = employee.PersonnelNumber; - - Person person = employee.Person; - if (person != null) + // Spalten nur bis zur 10., da sonst der Druck nicht lesbar ist und weil in den ersten 9 die Kerninfos stehen + for (int j = 0; j < 10; j++) { - row[0] = person.LastNameFirstName; - row[2] = person.Abbreviation; - - var address = person.Address; - if (address != null) - { - row[3] = address.Street + ", " + address.PostalCode + " " + address.Town; - } - - var contacts = person.Contacts; - if (contacts != null) - { - row[4] = contacts.FirstOrDefault(c => c.Type == BS.Shared.ContactType.business_MobilePhone)?.Value; - row[5] = contacts.FirstOrDefault(c => c.Type == BS.Shared.ContactType.business_Phone)?.Value; - row[6] = contacts.FirstOrDefault(c => c.Type == BS.Shared.ContactType.business_Mail)?.Value; - } + row[j] = lContent[i][j]; } - table.Rows.Add(row); } diff --git a/Service/Reporting/ExportAndPrintHelper.cs b/Service/Reporting/ExportAndPrintHelper.cs index cd5540656..0552aaeba 100644 --- a/Service/Reporting/ExportAndPrintHelper.cs +++ b/Service/Reporting/ExportAndPrintHelper.cs @@ -1,5 +1,7 @@ -using BeWo.Data.Access; +using BeWo.Data; +using BeWo.Data.Access; using BeWo.Data.Entities; +using BeWo.Service.Core; using BeWo.Service.DCEntityMapper; using BeWo.Service.Plugins; using BeWo.Service.ServiceUtils; @@ -491,5 +493,361 @@ namespace BeWo.Service.Reporting return lContent; } + public virtual string[] PrepareHeaderArrayForEmployeeExport() + { + bool darfVertragSehen = true; + int arrayCount = 37; + + string[] lHeaderCaption; + + if (!Utils.UserHasRight(GetLoggedInUser(), UserRightType.Employee_AllowEditContracts)) + { + arrayCount = 26; + darfVertragSehen = false; + } + + if (darfVertragSehen) + { + lHeaderCaption = new string[37] + { + "Nachname", // 0 + "Vorname", // 1 + "Personalnummer", // 2 + "Geburtsdatum", // 3 + "Beruf", // 4 + "Geschlecht", // 5 + "Familienstand", // 6 + "Krankenkasse", // 7 + "Steuernummer", // 8 + + "beschäftigt als", // 9 + "Probezeit (Tage)", // 10 + "Kündigungsfrist (Tage)", // 11 + "Urlaubstage", // 12 + "FLS/Woche", // 13 + "Gesamtstunden/Woche", // 14 + "Arbeitstage pro Woche", // 15 + "Eintrittsdatum", // 16 + "Enddatum", // 17 + "Versicherungsnummer", + "Stundensatz", + + "Telefon", + "Mobil", // 21 + "Mail", + "private Mail", + "Fax", + "Strasse", + "PLZ", // 26 + "Ort", // 27 + "Kontonummer", + "Bankleitzahl", + "Bank", + "BIC", // 31 + "IBAN", + "Bemerkung", // 33 + "Fachkraft", + "Qualifikation", + "Arbeitsschwerpunkte", + + }; + } + else + { + lHeaderCaption = new string[25] + { + "Nachname", // 0 + "Vorname", // 1 + "Personalnummer", // 2 + "Geburtsdatum", // 3 + "Beruf", // 4 + "Geschlecht", // 5 + "Familienstand", // 6 + "Krankenkasse", // 7 + "Steuernummer", // 8 + + "Telefon", + "Mobil", // 20 + "Mail", + "private Mail", + "Fax", + "Strasse", + "PLZ", // 25 + "Ort", // 26 + "Kontonummer", + "Bankleitzahl", + "Bank", + "BIC", // 30 + "IBAN", + + "Fachkraft", + "Qualifikation", + "Arbeitsschwerpunkte", + + }; + } + + return lHeaderCaption; + } + + public virtual string[][] PrepareContentArrayForEmployeeExport(long[] pSortedOids) + { + bool darfVertragSehen = true; + + string[] lHeaderCaption; + + if (!Utils.UserHasRight(GetLoggedInUser(), UserRightType.Employee_AllowEditContracts)) + { + darfVertragSehen = false; + } + + var lEmployees = DAOFactory.GenericDAO.LoadByIDs(pSortedOids); + + + + string[][] lContent = new string[lEmployees.Count][]; + + for (int iRowCount = 0; iRowCount < lEmployees.Count; iRowCount++) + { + lContent[iRowCount] = new string[PrepareHeaderArrayForEmployeeExport().Count()]; + + lContent[iRowCount][0] = lEmployees[iRowCount].Person.LastName; + lContent[iRowCount][1] = lEmployees[iRowCount].Person.FirstName; + lContent[iRowCount][2] = lEmployees[iRowCount].PersonnelNumber; + + lContent[iRowCount][3] = lEmployees[iRowCount].Person.DateOfBirth.DoIfNotNull(d => d.ToShortDateString()); + + lContent[iRowCount][4] = lEmployees[iRowCount].Person.Profession; + + lContent[iRowCount][5] = lEmployees[iRowCount].Person.Sex == Sex.Male + ? "männlich" + : "weiblich"; + + if (lEmployees[iRowCount].Person.FamilyStatus != null) + { + switch (lEmployees[iRowCount].Person.FamilyStatus.Value) + { + case FamilyStatus.Divorced: + lContent[iRowCount][6] = "geschieden"; + break; + case FamilyStatus.Married: + lContent[iRowCount][6] = "verheiratet"; + break; + case FamilyStatus.Single: + lContent[iRowCount][6] = "ledig"; + break; + case FamilyStatus.Widowed: + lContent[iRowCount][6] = "verwitwet"; + break; + case FamilyStatus.Partner: + lContent[iRowCount][6] = "in Partnerschaft"; + break; + case FamilyStatus.PartnerDivorced: + lContent[iRowCount][6] = "getrennt lebend"; + break; + case FamilyStatus.PartnerDead: + lContent[iRowCount][5] = "partnerhinterblieben"; + break; + case FamilyStatus.PartnerMarried: + lContent[iRowCount][5] = "verpartnert"; + break; + case FamilyStatus.Entpartnert: + lContent[iRowCount][5] = "entpartnert"; + break; + } + } + + lContent[iRowCount][7] = lEmployees[iRowCount].HealthInsurance; + lContent[iRowCount][8] = lEmployees[iRowCount].TaxNumber; + + if (darfVertragSehen) + { + if (lEmployees[iRowCount].Person.LastName.StartsWith("Ber")) + { + int test = 0; + } + Contract lastContract = lEmployees[iRowCount].LastContract; + + if (lastContract != null) + { + if (lastContract.EmploymentType != null) + { + lContent[iRowCount][9] = lastContract.EmploymentType.Name; + } + + lContent[iRowCount][10] = lastContract.ProbationPeriod.ToString(); + lContent[iRowCount][11] = lastContract.CancellationPeriod.ToString(); + + decimal? urlaubstage = null; + if (lastContract.EmploymentType != null && lastContract.EmploymentType.LeaveDays.HasValue) + { + urlaubstage = lastContract.EmploymentType.LeaveDays; + } + else + { + urlaubstage = lastContract.LeaveDays; + } + if (urlaubstage.HasValue) + { + lContent[iRowCount][12] = urlaubstage.Value.ToStringNullCheck(); + } + + if (lastContract.WeeklyFLS.HasValue) + { + lContent[iRowCount][13] = lastContract.WeeklyFLS.Value.ToStringNullCheck(); + } + + if (lastContract.WeeklyTotalHours.HasValue) + { + lContent[iRowCount][14] = lastContract.WeeklyTotalHours.Value.ToStringNullCheck(); + } + + var wd = lastContract.WeeklyDays ?? 5; + + if (wd == 0) + wd = 5; + + lContent[iRowCount][15] = String.Format("{0}", wd); + if (!lastContract.ContractEndDate.HasValue) + { + lContent[iRowCount][17] = "unbefristet"; + } + else + { + lContent[iRowCount][17] = lastContract.ContractEndDate.DoIfNotNull(d => d.ToShortDateString()); + } + + } + + var firstContract = lEmployees[iRowCount].FirstContract; + if (firstContract != null) + { + lContent[iRowCount][16] = firstContract.EntryDate.DoIfNotNull(d => d.ToShortDateString()); + } + + lContent[iRowCount][18] = lEmployees[iRowCount].InsuranceNumber; + + if (lastContract != null) + { + if (lastContract.HourlyRate.HasValue) + { + lContent[iRowCount][19] = lastContract.HourlyRate.Value.ToStringNullCheck(); + } + + lContent[iRowCount][33] = lastContract.Notice; + } + } + + int index = 9; + if (darfVertragSehen) + { + index = 20; + } + foreach (var iContact in lEmployees[iRowCount].Person.Contacts) + { + switch (iContact.Type) + { + case ContactType.business_Phone: + lContent[iRowCount][index] = iContact.Value; + break; + case ContactType.business_MobilePhone: + lContent[iRowCount][index + 1] = iContact.Value; + break; + case ContactType.business_Mail: + lContent[iRowCount][index + 2] = iContact.Value; + break; + case ContactType.private_Mail: + lContent[iRowCount][index + 3] = iContact.Value; + break; + case ContactType.business_Fax: + lContent[iRowCount][index + 4] = iContact.Value; + break; + } + } + + if (lEmployees[iRowCount].Person.Address != null) + { + lContent[iRowCount][index + 5] = lEmployees[iRowCount].Person.Address.Street; + lContent[iRowCount][index + 6] = lEmployees[iRowCount].Person.Address.PostalCode; + lContent[iRowCount][index + 7] = lEmployees[iRowCount].Person.Address.Town; + } + + if (lEmployees[iRowCount].Person.BankAccount != null) + { + lContent[iRowCount][index + 8] = lEmployees[iRowCount].Person.BankAccount.AccountNumber; + lContent[iRowCount][index + 9] = lEmployees[iRowCount].Person.BankAccount.BankCode; + lContent[iRowCount][index + 10] = lEmployees[iRowCount].Person.BankAccount.BankName; + lContent[iRowCount][index + 11] = lEmployees[iRowCount].Person.BankAccount.Bic; + lContent[iRowCount][index + 12] = lEmployees[iRowCount].Person.BankAccount.IBAN; + } + + if (darfVertragSehen) + { + index += 1; + } + if (lEmployees[iRowCount].IsQualified.HasValue) + { + lContent[iRowCount][index + 13] = lEmployees[iRowCount].IsQualified.Value ? "Ja" : "Nein"; + } + + var qualis = lEmployees[iRowCount].ValueList.FindByType(ValueListEntryType.StaffQualificationsType) + .Select(e2o => e2o.Entry); + + if (qualis != null && qualis.Count() > 0) + { + StringBuilder sb = new StringBuilder(); + + foreach (var entry in qualis) + { + if (sb.Length > 0) + { + sb.Append(", "); + } + sb.Append(entry.Value); + } + + lContent[iRowCount][index + 14] = sb.ToString(); + + } + + var focuses = lEmployees[iRowCount].ValueList.FindByType(ValueListEntryType.StaffActivityFocusType) + .Select(e2o => e2o.Entry); + + if (focuses != null && focuses.Count() > 0) + { + StringBuilder sb = new StringBuilder(); + + foreach (var entry in focuses) + { + if (sb.Length > 0) + { + sb.Append(", "); + } + sb.Append(entry.Value); + } + + lContent[iRowCount][index + 15] = sb.ToString(); + + } + } + + return lContent; + } + public static ApplicationUser GetLoggedInUser() + { + ApplicationUser loggedInUser; + + if (LoggedInUserOperationContextExt.Current != null && + LoggedInUserOperationContextExt.Current.User != null) + { + loggedInUser = LoggedInUserOperationContextExt.Current.User; + } + else + { + loggedInUser = SessionFacade.LoggedInUser; + } + + return loggedInUser; + } } } diff --git a/Service/ServiceImplementations/DownloadServiceImp.cs b/Service/ServiceImplementations/DownloadServiceImp.cs index 6572eae9f..3628c2a07 100644 --- a/Service/ServiceImplementations/DownloadServiceImp.cs +++ b/Service/ServiceImplementations/DownloadServiceImp.cs @@ -197,346 +197,17 @@ namespace BeWo.Service.ServiceImplementations } } - private static ApplicationUser GetLoggedInUser() - { - ApplicationUser loggedInUser; - - if (LoggedInUserOperationContextExt.Current != null && - LoggedInUserOperationContextExt.Current.User != null) - { - loggedInUser = LoggedInUserOperationContextExt.Current.User; - } - else - { - loggedInUser = SessionFacade.LoggedInUser; - } - - return loggedInUser; - } + public string PrepareExcelFileEmployeeExport(string pFileID, long[] pSortedOids) { try { - var lEmployees = DAOFactory.GenericDAO.LoadByIDs(pSortedOids); + string lPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, pFileID + ".tmp"); - bool darfVertragSehen = true; - int arrayCount = 37; - - string[] lHeaderCaption; - - if (!Utils.UserHasRight(GetLoggedInUser(), UserRightType.Employee_AllowEditContracts)) - { - arrayCount = 26; - darfVertragSehen = false; - } - - if (darfVertragSehen) - { - lHeaderCaption = new string[37] - { - "Nachname", // 0 - "Vorname", // 1 - "Personalnummer", // 2 - "Geburtsdatum", // 3 - "Beruf", // 4 - "Geschlecht", // 5 - "Familienstand", // 6 - "Krankenkasse", // 7 - "Steuernummer", // 8 - - "beschäftigt als", // 9 - "Probezeit (Tage)", // 10 - "Kündigungsfrist (Tage)", // 11 - "Urlaubstage", // 12 - "FLS/Woche", // 13 - "Gesamtstunden/Woche", // 14 - "Arbeitstage pro Woche", // 15 - "Eintrittsdatum", // 16 - "Enddatum", // 17 - "Versicherungsnummer", - "Stundensatz", - - "Telefon", - "Mobil", // 21 - "Mail", - "private Mail", - "Fax", - "Strasse", - "PLZ", // 26 - "Ort", // 27 - "Kontonummer", - "Bankleitzahl", - "Bank", - "BIC", // 31 - "IBAN", - "Bemerkung", // 33 - "Fachkraft", - "Qualifikation", - "Arbeitsschwerpunkte", - - }; - } - else - { - lHeaderCaption = new string[25] - { - "Nachname", // 0 - "Vorname", // 1 - "Personalnummer", // 2 - "Geburtsdatum", // 3 - "Beruf", // 4 - "Geschlecht", // 5 - "Familienstand", // 6 - "Krankenkasse", // 7 - "Steuernummer", // 8 - - "Telefon", - "Mobil", // 20 - "Mail", - "private Mail", - "Fax", - "Strasse", - "PLZ", // 25 - "Ort", // 26 - "Kontonummer", - "Bankleitzahl", - "Bank", - "BIC", // 30 - "IBAN", - - "Fachkraft", - "Qualifikation", - "Arbeitsschwerpunkte", - - }; - } - - string[][] lContent = new string[lEmployees.Count][]; - - for (int iRowCount = 0; iRowCount < lEmployees.Count; iRowCount++) - { - lContent[iRowCount] = new string[lHeaderCaption.Count()]; - - lContent[iRowCount][0] = lEmployees[iRowCount].Person.LastName; - lContent[iRowCount][1] = lEmployees[iRowCount].Person.FirstName; - lContent[iRowCount][2] = lEmployees[iRowCount].PersonnelNumber; - - lContent[iRowCount][3] = lEmployees[iRowCount].Person.DateOfBirth.DoIfNotNull(d => d.ToShortDateString()); - - lContent[iRowCount][4] = lEmployees[iRowCount].Person.Profession; - - lContent[iRowCount][5] = lEmployees[iRowCount].Person.Sex == Sex.Male - ? "männlich" - : "weiblich"; - - if (lEmployees[iRowCount].Person.FamilyStatus != null) - { - switch (lEmployees[iRowCount].Person.FamilyStatus.Value) - { - case FamilyStatus.Divorced: - lContent[iRowCount][6] = "geschieden"; - break; - case FamilyStatus.Married: - lContent[iRowCount][6] = "verheiratet"; - break; - case FamilyStatus.Single: - lContent[iRowCount][6] = "ledig"; - break; - case FamilyStatus.Widowed: - lContent[iRowCount][6] = "verwitwet"; - break; - case FamilyStatus.Partner: - lContent[iRowCount][6] = "in Partnerschaft"; - break; - case FamilyStatus.PartnerDivorced: - lContent[iRowCount][6] = "getrennt lebend"; - break; - case FamilyStatus.PartnerDead: - lContent[iRowCount][5] = "partnerhinterblieben"; - break; - case FamilyStatus.PartnerMarried: - lContent[iRowCount][5] = "verpartnert"; - break; - case FamilyStatus.Entpartnert: - lContent[iRowCount][5] = "entpartnert"; - break; - } - } - - lContent[iRowCount][7] = lEmployees[iRowCount].HealthInsurance; - lContent[iRowCount][8] = lEmployees[iRowCount].TaxNumber; - - if (darfVertragSehen) - { - if (lEmployees[iRowCount].Person.LastName.StartsWith("Ber")) - { - int test = 0; - } - Contract lastContract = lEmployees[iRowCount].LastContract; - - if (lastContract != null) - { - if (lastContract.EmploymentType != null) - { - lContent[iRowCount][9] = lastContract.EmploymentType.Name; - } - - lContent[iRowCount][10] = lastContract.ProbationPeriod.ToString(); - lContent[iRowCount][11] = lastContract.CancellationPeriod.ToString(); - - decimal? urlaubstage = null; - if (lastContract.EmploymentType != null && lastContract.EmploymentType.LeaveDays.HasValue) - { - urlaubstage = lastContract.EmploymentType.LeaveDays; - } - else - { - urlaubstage = lastContract.LeaveDays; - } - if (urlaubstage.HasValue) - { - lContent[iRowCount][12] = urlaubstage.Value.ToStringNullCheck(); - } - - if (lastContract.WeeklyFLS.HasValue) - { - lContent[iRowCount][13] = lastContract.WeeklyFLS.Value.ToStringNullCheck(); - } - - if (lastContract.WeeklyTotalHours.HasValue) - { - lContent[iRowCount][14] = lastContract.WeeklyTotalHours.Value.ToStringNullCheck(); - } - - var wd = lastContract.WeeklyDays ?? 5; - - if (wd == 0) - wd = 5; - - lContent[iRowCount][15] = String.Format("{0}", wd); - if (!lastContract.ContractEndDate.HasValue) - { - lContent[iRowCount][17] = "unbefristet"; - } - else - { - lContent[iRowCount][17] = lastContract.ContractEndDate.DoIfNotNull(d => d.ToShortDateString()); - } - - } - - var firstContract = lEmployees[iRowCount].FirstContract; - if (firstContract != null) - { - lContent[iRowCount][16] = firstContract.EntryDate.DoIfNotNull(d => d.ToShortDateString()); - } - - lContent[iRowCount][18] = lEmployees[iRowCount].InsuranceNumber; - - if (lastContract != null) - { - if (lastContract.HourlyRate.HasValue) - { - lContent[iRowCount][19] = lastContract.HourlyRate.Value.ToStringNullCheck(); - } - - lContent[iRowCount][33] = lastContract.Notice; - } - } - - int index = 9; - if (darfVertragSehen) - { - index = 20; - } - foreach (var iContact in lEmployees[iRowCount].Person.Contacts) - { - switch (iContact.Type) - { - case ContactType.business_Phone: - lContent[iRowCount][index] = iContact.Value; - break; - case ContactType.business_MobilePhone: - lContent[iRowCount][index + 1] = iContact.Value; - break; - case ContactType.business_Mail: - lContent[iRowCount][index + 2] = iContact.Value; - break; - case ContactType.private_Mail: - lContent[iRowCount][index + 3] = iContact.Value; - break; - case ContactType.business_Fax: - lContent[iRowCount][index + 4] = iContact.Value; - break; - } - } - - if (lEmployees[iRowCount].Person.Address != null) - { - lContent[iRowCount][index + 5] = lEmployees[iRowCount].Person.Address.Street; - lContent[iRowCount][index + 6] = lEmployees[iRowCount].Person.Address.PostalCode; - lContent[iRowCount][index + 7] = lEmployees[iRowCount].Person.Address.Town; - } - - if (lEmployees[iRowCount].Person.BankAccount != null) - { - lContent[iRowCount][index + 8] = lEmployees[iRowCount].Person.BankAccount.AccountNumber; - lContent[iRowCount][index + 9] = lEmployees[iRowCount].Person.BankAccount.BankCode; - lContent[iRowCount][index + 10] = lEmployees[iRowCount].Person.BankAccount.BankName; - lContent[iRowCount][index + 11] = lEmployees[iRowCount].Person.BankAccount.Bic; - lContent[iRowCount][index + 12] = lEmployees[iRowCount].Person.BankAccount.IBAN; - } - - if (darfVertragSehen) - { - index += 1; - } - if (lEmployees[iRowCount].IsQualified.HasValue) - { - lContent[iRowCount][index + 13] = lEmployees[iRowCount].IsQualified.Value ? "Ja" : "Nein"; - } - - var qualis = lEmployees[iRowCount].ValueList.FindByType(ValueListEntryType.StaffQualificationsType) - .Select(e2o => e2o.Entry); - - if (qualis != null && qualis.Count() > 0) - { - StringBuilder sb = new StringBuilder(); - - foreach (var entry in qualis) - { - if (sb.Length > 0) - { - sb.Append(", "); - } - sb.Append(entry.Value); - } - - lContent[iRowCount][index + 14] = sb.ToString(); - - } - - var focuses = lEmployees[iRowCount].ValueList.FindByType(ValueListEntryType.StaffActivityFocusType) - .Select(e2o => e2o.Entry); - - if (focuses != null && focuses.Count() > 0) - { - StringBuilder sb = new StringBuilder(); - - foreach (var entry in focuses) - { - if (sb.Length > 0) - { - sb.Append(", "); - } - sb.Append(entry.Value); - } - - lContent[iRowCount][index + 15] = sb.ToString(); - - } - } + var helper = PluginLoader.FindClass(); + var lHeaderCaption = helper.PrepareHeaderArrayForEmployeeExport(); + var lContent = helper.PrepareContentArrayForEmployeeExport(pSortedOids); return WriteHtmlFile(lHeaderCaption, lContent); }