using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; using BeWo.Report; using BS.Shared; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; namespace BeWoPlanerMobil.Models { public class ReportViewerModel : AbstractModel { public List AllEmployees { get; set; } public List AllTeams { get; set; } public List Queries { get; set; } public AbstractReportCreator ReportCreator { get; set; } [Display(Name = "Monat")] public int? SelectedMonth { get; set; } public List Months { get { var result = new List(); for(var i = 1; i < 13; i++) { result.Add(new SelectListItem { Value = i.ToString(), Text = new DateTime(DateTime.Now.Year, i, 1).ToString("MMMM") }); } return result; } } [Display(Name = "Jahr")] public int? SelectedYear { get; set; } public List Years { get { var result = new List(); for(var i = DateTime.Today.Year; i > DateTime.Today.Year - 11; i--) { result.Add(new SelectListItem { Value = i.ToString(), Text = i.ToString() }); } return result; } } [Display(Name="Bericht")] public ReportType SelectedReportType { get; set; } public List ReportTypes { get; set; } [Display(Name = "Bericht")] public ReportSelectListItem SelectedCustomReport { get; set; } public List CustomReports { get { var result = new List(); if(Queries is null) { return result; } result.Add(new ReportSelectListItem(0, false) { Text = string.Empty, Value = "0_0" }); foreach(var query in Queries) { var hasParameters = query.Parameter != null && query.Parameter.Count > 0; result.Add(new ReportSelectListItem(query.Oid, hasParameters) { Text = query.Title, Value = $"{query.Oid}_{(hasParameters ? "1" : "0")}" }); } return result; } } [Display(Name = "Mitarbeiter")] public long? SelectedEmployeeOid => SelectedEmployee?.EmployeeOid; public CompactEmployeeDC SelectedEmployee { get; set; } public List Employees { get { var result = new List(); if(AllEmployees is null) { return result; } if(HasRightMitarbeiterstundenkontoViewSelf && !HasRightMitarbeiterstundenkontoViewAll) { result.Add(new SelectListItem{ Text = Employee.LastNameFirstName, Value = Employee.EmployeeOid.ToString()}); return result; } result.Add(new SelectListItem { Text = string.Empty, Value = "0" }); foreach(var employee in AllEmployees.OrderBy(e => e.SimpleDescription)) { result.Add(new SelectListItem { Text = employee.SimpleDescription, Value = employee.EmployeeOid.ToString() }); } return result; } } [Display(Name = "Team")] public long? SelectedTeamOid => SelectedTeam?.TeamOid; public CompactTeamDC SelectedTeam { get; set; } public List Teams { get { var result = new List(); if(AllTeams is null) { return result; } result.Add(new SelectListItem { Text = string.Empty, Value = "0" }); foreach(var team in AllTeams.OrderBy(t => t.Name)) { result.Add(new SelectListItem { Text = team.Name, Value = team.TeamOid.ToString() }); } return result; } } public List SelectedEmployees { get; set; } public List SelectedTeams { get; set; } public QueryDC SelectedQuery { get; set; } public List SupportConcepts { get; set; } public CostBearer2SupportConceptRelListObject SelectedCostBearer2SupportConceptRelListObject { get; set; } public IEnumerable CostBearer2SupportConceptRelListObjects { get { var allCostBearerRelations = new List { new CostBearer2SupportConceptRelListObject("Hilfeplan auswählen", "", "0", false, false) }; foreach(var sc in SupportConcepts.OrderBy(sc => sc.Customer.LastName)) { allCostBearerRelations.AddRange(sc.CostBearerRelations.Select( cb => new CostBearer2SupportConceptRelListObject( $"{sc.Customer.SimpleDescription} {(sc.Customer.DateOfBirth.HasValue ? "*" + sc.Customer.DateOfBirth.Value.ToString("dd.MM.yyyy") : string.Empty)}", $"{cb.AuswahlBezeichnung} {cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}{GetIsNotApproved(cb)}", cb.CostBearer2SupportConceptOid.ToString(), cb.SupportConcept.IsAboutToExpire, cb.SupportConcept.ExpiresIn3MonthOrLess)) ); } return allCostBearerRelations; } } public List AllServiceCategoriesForQueries { get; set; } = new List(); public List AllCustomersForQueries { get; set; } = new List(); public List AllEmployeesForQueries { get; set; } = new List(); public List AllTeamsForQueries { get; set; } = new List(); public List AllOrganisationForQuery { get; set; } = new List(); public List AllValueListEntriesForQuery { get; set; } = new List(); public List AllCustomValuesForQuery { get; set; } = new List(); public Dictionary SelectedValues { get; set; } = new Dictionary(); public Dictionary> ValueListEntryTypes2ValueListEntries { get; set; } = new Dictionary>(); public List CostBearer2SupportConceptRels { get; set; } = new List(); public ValueListEntryType GetValueListEntryTypeByQueryParameter(string parameterName) { foreach(var query in Queries.Where(q => q.Parameter.Any())) { var parameter = query.Parameter.FirstOrDefault(param => param.Name?.Equals(parameterName) ?? false); if((parameter?.Name.Equals(parameterName) ?? false) && parameter.Name.Contains("_")) { if(int.TryParse(parameter.Name.Split('_')[1], out var typeAsInt)) { return (ValueListEntryType)typeAsInt; } } } return ValueListEntryType.EmploymentType; } } public struct SelectedValue { public QueryParameterType ParameterType { get; } public object Parameter { get; } public SelectedValue(QueryParameterType parameterType, object parameter) { ParameterType = parameterType; Parameter = parameter; } } public class ReportSelectListItem : SelectListItem { public long? QueryOid { get; set; } public bool HasParameters { get; set; } public ReportSelectListItem(long? queryOid, bool hasParameters) { QueryOid = queryOid; HasParameters = hasParameters; } } public enum ReportType { Berichte = 0, Mitarbeiterstundenkonto = 1 } }