using BeWo.Report; using BeWoPlanerMobil.Controllers; using BeWoPlanerMobil.Util; using BeWoPlanerMobil.Util.ReportUtils; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using DevExpress.XtraReports.UI; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; namespace BeWoPlanerMobil.Models { public class ReportModel : AbstractModel, ISignable { public ReportModel() { SessionModel = new ReportSessionModel(); } public ReportSessionModel ReportSessionModel => SessionModel as ReportSessionModel; public QbSignatureIntervalSelection SelectedIntervalSelection { get => ReportSessionModel.SelectedIntervalSelection; set => ReportSessionModel.SelectedIntervalSelection = value; } public List IntervalSelections => new List { new SelectListItem { Text = QbSignatureIntervalSelection.FirstHalf.GetEnumDescription(), Value = ((int) QbSignatureIntervalSelection.FirstHalf).ToString(), Selected = SelectedIntervalSelection == QbSignatureIntervalSelection.FirstHalf }, new SelectListItem { Text = QbSignatureIntervalSelection.SecondHalf.GetEnumDescription(), Value = ((int) QbSignatureIntervalSelection.SecondHalf).ToString(), Selected = SelectedIntervalSelection == QbSignatureIntervalSelection.SecondHalf }, new SelectListItem { Text = QbSignatureIntervalSelection.WholeMonth.GetEnumDescription(), Value = ((int) QbSignatureIntervalSelection.WholeMonth).ToString(), Selected = SelectedIntervalSelection == QbSignatureIntervalSelection.WholeMonth } }; [Display(Name = "Klient")] public long? SelectedCustomerOid { get { return ReportSessionModel.SelectedCustomerOid; } set { ReportSessionModel.SelectedCustomerOid = value; } } public CompactCustomerDC SelectedCustomer { get; set; } [Display(Name = "Monat")] public int? SelectedMonth { get => ReportSessionModel.SelectedMonth; set => ReportSessionModel.SelectedMonth = value; } [Display(Name = "Jahr")] public int? SelectedYear { get => ReportSessionModel.SelectedYear; set => ReportSessionModel.SelectedYear = value; } 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; } } 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; } } public List Days { get { var result = new List(); var month = SelectedMonth ?? DateTime.Today.Month; var year = SelectedYear ?? DateTime.Today.Year; var last = new DateTime(year, month, 1).AddMonths(1).AddDays(-1).Day; for(var i = 1; i <= last; i++) { result.Add(new SelectListItem { Value = i.ToString(), Text = i.ToString() }); } return result; } } [Display(Name = "Vom")] public int? SelectedStartDay { get => ReportSessionModel.SelectedStartDay; set => ReportSessionModel.SelectedStartDay = value; } [Display(Name = "Bis")] public int? SelectedEndDay { get => ReportSessionModel.SelectedEndDay; set => ReportSessionModel.SelectedEndDay = value; } public ConfirmationReceiptObject ConfirmationReceiptObject { get { return ReportSessionModel.ConfirmationReceiptObject; } set { ReportSessionModel.ConfirmationReceiptObject = value; } } [Display(Name = "Mitarbeiter")] public long? SelectedEmployeeOid { get { return ReportSessionModel.SelectedEmployeeOid; } set { ReportSessionModel.SelectedEmployeeOid = value; } } public CompactEmployeeDC SelectedEmployee { get; set; } [Display(Name="Kostenträger")] public long? SelectedOrganisationOid { get { return ReportSessionModel.SelectedOrganisationOid; } set { ReportSessionModel.SelectedOrganisationOid = value; } } public CompactOrganisationDC SelectedOrganisation { get; set; } public List Organisations { get; set; } = new List(); [Display(Name="Leistungskategorie")] public long? SelectedServiceCategoryOid { get { return ReportSessionModel.SelectedServiceCategoryOid; } set { ReportSessionModel.SelectedServiceCategoryOid = value; } } public ServiceCategoryDC SelectedServiceCategory { get; set; } public List ServiceCategories { get; set; } = new List(); public List ServiceCategoryItems { get { var result = new List(); foreach(var serviceCategory in ServiceCategories) { if(serviceCategory.ServiceCategoryOid == null) { continue; } result.AddIfNotIn(new SelectListItem { Value = serviceCategory.ServiceCategoryOid.ToString(), Text = serviceCategory.Name }); } return result; } } [Display(Name="Filter")] public QbFilterItem SelectedFilterItem { get { if (QbFilters == null || !SelectedFilterItemId.HasValue) { return null; } return QbFilters.FirstOrDefault(f => f.FilterEnum == SelectedFilterItemId.Value); } } public QBFilterEnum? SelectedFilterItemId { get => ReportSessionModel.SelectedFilterItemId; set => ReportSessionModel.SelectedFilterItemId = value; } public List QbFilters { get; set; } = new List(); public List QbFilterItems { get { var result = new List(); foreach(var qbFilter in QbFilters) { result.AddIfNotIn(new SelectListItem { Value = ((int) qbFilter.FilterEnum).ToString(), Text = qbFilter.Name }); } return result; } } [Display(Name = "Team")] public long? SelectedTeamOid { get { return ReportSessionModel.SelectedTeamOid; } set { ReportSessionModel.SelectedTeamOid = value; } } public CompactTeamDC SelectedTeam { get; set; } public List AllTeams { get; set; } public List Teams { get { var result = new List(); AllTeams?.DoForEach(team => { result.Add(new SelectListItem { Value = team.TeamOid.ToString(), Text = team.Name }); }); return result; } } public List ReportServiceRecordOids { get; set; } public List ConfirmationReceiptSignatures { get => ReportSessionModel.ConfirmationReceiptSignatures; set => ReportSessionModel.ConfirmationReceiptSignatures = value; } public ConfirmationReceiptSignatureDC GetConfirmationReceiptSignatureByOid(long confirmationReceiptSignatureOid) { return ConfirmationReceiptSignatures.FirstOrDefault(crs => crs.ConfirmationReceiptSignatureOid == confirmationReceiptSignatureOid); } public List GetConfirmationReceitSignaturesByOids(List confirmationReceiptSignatureOids) { return confirmationReceiptSignatureOids == null ? new List() : ConfirmationReceiptSignatures.Where(crs => crs.ConfirmationReceiptSignatureOid != null && confirmationReceiptSignatureOids.Contains(crs.ConfirmationReceiptSignatureOid.Value)).ToList(); } public bool IsForSelectedEmployeesOnly { get { return ReportSessionModel.IsForSelectedEmployeesOnly; } set { ReportSessionModel.IsForSelectedEmployeesOnly = value; } } public bool IsForSelectedCostbearersOnly { get { return ReportSessionModel.IsForSelectedCostbearersOnly; } set { ReportSessionModel.IsForSelectedCostbearersOnly = value; } } public bool IsForSelectedCategoryOnly { get { return ReportSessionModel.IsForSelectedCategoryOnly; } set { ReportSessionModel.IsForSelectedCategoryOnly = value; } } public List SelectedConfirmationReceiptSignatures { get { return ReportSessionModel.SelectedConfirmationReceiptSignatures; } set { ReportSessionModel.SelectedConfirmationReceiptSignatures = value; } } public Quittierungsbelegsunterschriftenobjekt Quittierungsbelegsunterschriftenobjekt { get { return ReportSessionModel.Quittierungsbelegsunterschriftenobjekt; } set { ReportSessionModel.Quittierungsbelegsunterschriftenobjekt = value; } } public AbstractReportCreator ReportCreator { get; set; } public QuittierungsbelegsReportSettings QuittierungsbelegsReportSettings { get => ReportSessionModel.QuittierungsbelegsReportSettings; set => ReportSessionModel.QuittierungsbelegsReportSettings = value; } public XtraReport QuittierungsbelegsReport { get; set; } public int QbEntryCount { get; set; } public int MaxResults { get; set; } = 10; public int QbEntryPageCount { get; set; } public int CurrentQbEntryPage { get; set; } public List GoalRatingTypes { get; set; } = new List(); public Dictionary> ServiceRecordOids2GoalHeader { get => ReportSessionModel.ServiceRecordOids2GoalHeader; set => ReportSessionModel.ServiceRecordOids2GoalHeader = value; } public ValueListEntryDC[] Dokutypes { get; set; } public int NumberOfDokuTypes => Dokutypes?.Length ?? 0; public string SignaturePopupTitle { get; set; } } }