268 lines
9.8 KiB
C#
268 lines
9.8 KiB
C#
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 ReportViewerModel()
|
|
{
|
|
SessionModel = new ReportViewerSessionModel();
|
|
}
|
|
|
|
public ReportViewerSessionModel ReportViewerSessionModel
|
|
{
|
|
get
|
|
{
|
|
return SessionModel as ReportViewerSessionModel;
|
|
}
|
|
}
|
|
|
|
public List<CompactEmployeeDC> AllEmployees { get; set; }
|
|
public List<CompactTeamDC> AllTeams { get; set; }
|
|
public List<QueryDC> Queries { get; set; }
|
|
public AbstractReportCreator ReportCreator { get; set; }
|
|
|
|
[Display(Name = "Monat")]
|
|
public int? SelectedMonth { get { return ReportViewerSessionModel.SelectedMonth; } set { ReportViewerSessionModel.SelectedMonth = value; } }
|
|
public List<SelectListItem> Months
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>();
|
|
|
|
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 { return ReportViewerSessionModel.SelectedYear; } set { ReportViewerSessionModel.SelectedYear = value; } }
|
|
public List<SelectListItem> Years
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>();
|
|
|
|
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 { return ReportViewerSessionModel.SelectedReportType; } set { ReportViewerSessionModel.SelectedReportType = value; } }
|
|
public List<SelectListItem> ReportTypes { get; set; }
|
|
|
|
|
|
[Display(Name = "Bericht")]
|
|
public ReportSelectListItem SelectedCustomReport { get; set; }
|
|
public List<ReportSelectListItem> CustomReports
|
|
{
|
|
get
|
|
{
|
|
var result = new List<ReportSelectListItem>();
|
|
|
|
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 { get { return ReportViewerSessionModel.SelectedEmployeeOid; } set { ReportViewerSessionModel.SelectedEmployeeOid = value; } }
|
|
public CompactEmployeeDC SelectedEmployee { get; set; }
|
|
public List<SelectListItem> Employees
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>();
|
|
|
|
if(AllEmployees is null)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
if(HasRightMitarbeiterstundenkontoViewSelf && !HasRightMitarbeiterstundenkontoViewAll)
|
|
{
|
|
result.Add(new SelectListItem{ Text = LoggedInEmployee.LastNameFirstName, Value = LoggedInEmployee.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 { get { return ReportViewerSessionModel.SelectedTeamOid; } set { ReportViewerSessionModel.SelectedTeamOid = value; } }
|
|
public CompactTeamDC SelectedTeam { get; set; }
|
|
public List<SelectListItem> Teams
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>();
|
|
|
|
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<CompactEmployeeDC> SelectedEmployees { get; set; }
|
|
//public List<CompactTeamDC> SelectedTeams { get; set; }
|
|
|
|
public long? SelectedQueryOid { get { return ReportViewerSessionModel.SelectedQueryOid; } set { ReportViewerSessionModel.SelectedQueryOid = value; } }
|
|
public QueryDC SelectedQuery { get; set; }
|
|
|
|
|
|
|
|
public List<SupportConceptDC> SupportConcepts { get; set; }
|
|
|
|
public CostBearer2SupportConceptRelListObject SelectedCostBearer2SupportConceptRelListObject { get; set; }
|
|
|
|
public IEnumerable<CostBearer2SupportConceptRelListObject> CostBearer2SupportConceptRelListObjects
|
|
{
|
|
get
|
|
{
|
|
var allCostBearerRelations = new List<CostBearer2SupportConceptRelListObject> { 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.Value,
|
|
cb.SupportConcept.IsAboutToExpire,
|
|
cb.SupportConcept.ExpiresIn3MonthOrLess))
|
|
);
|
|
}
|
|
return allCostBearerRelations;
|
|
}
|
|
}
|
|
|
|
public List<ServiceCategoryDC> AllServiceCategoriesForQueries { get; set; } = new List<ServiceCategoryDC>();
|
|
|
|
public List<CompactCustomerDC> AllCustomersForQueries { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public List<CompactEmployeeDC> AllEmployeesForQueries { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<CompactTeamDC> AllTeamsForQueries { get; set; } = new List<CompactTeamDC>();
|
|
|
|
public List<CompactOrganisationDC> AllOrganisationForQuery { get; set; } = new List<CompactOrganisationDC>();
|
|
|
|
public List<ValueListEntryDC> AllValueListEntriesForQuery { get; set; } = new List<ValueListEntryDC>();
|
|
|
|
public List<string> AllCustomValuesForQuery { get; set; } = new List<string>();
|
|
|
|
public Dictionary<long, SelectedValue> SelectedValues { get; set; } = new Dictionary<long, SelectedValue>();
|
|
|
|
public Dictionary<ValueListEntryType, List<ValueListEntryDC>> ValueListEntryTypes2ValueListEntries { get; set; } = new Dictionary<ValueListEntryType, List<ValueListEntryDC>>();
|
|
|
|
public List<SupportConceptCostBearerRelDC> CostBearer2SupportConceptRels { get; set; } = new List<SupportConceptCostBearerRelDC>();
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
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
|
|
}
|
|
} |