Intervallfinder überarbeitet & Bug gefixt, der zu einem Fehler beim Suchen nach freien Intervallen über mehrere Tage geführt hatte, wenn die Enduhrzeit vor der Startuhrzeit lag. Berichte mit Parametern. Verbesserte Mitarbeiter-, Klienten-, Team-, und Organisationsdropdowns mit Suche. Quittierungsbelegresultate (zum Unterschreiben) wird wie die Zeiterfassung paginiert. FaC: neuer Kalender noch nicht fertig.
256 lines
12 KiB
C#
256 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using BeWoPlanerMobil.Service;
|
|
using BeWoPlanerMobil.Util;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWoPlanerMobil.Models
|
|
{
|
|
public class SchedulerModel : AbstractModel
|
|
{
|
|
public List<long> TeamMemberCustomerOids { get; set; }
|
|
|
|
public DateTime SelectedDate { get; set; } = DateTime.Today;
|
|
|
|
public SchedulerAppointmentDC SelectedAppointment { get; set; }
|
|
|
|
private List<SchedulerAppointmentDC> _Appointments;
|
|
|
|
public List<SchedulerAppointmentDC> Appointments
|
|
{
|
|
get => _Appointments ?? (_Appointments = new List<SchedulerAppointmentDC>());
|
|
|
|
set
|
|
{
|
|
var oldAppointments = AppointmentListItems.Select(li => li.SchedulerAppointment).ToList();
|
|
|
|
_Appointments = value ?? new List<SchedulerAppointmentDC>();
|
|
|
|
if(_Appointments.AreListEqual(oldAppointments))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_AppointmentListItems = new List<AppointmentListItem>();
|
|
|
|
foreach(var appointment in _Appointments)
|
|
{
|
|
var listItem = new AppointmentListItem(appointment);
|
|
listItem.GenerateIdentifier(_AppointmentListItems.Select(a => a.Identifier).ToList());
|
|
|
|
_AppointmentListItems.Add(listItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
private List<AppointmentListItem> _AppointmentListItems;
|
|
public List<AppointmentListItem> AppointmentListItems => _AppointmentListItems ?? (_AppointmentListItems = new List<AppointmentListItem>());
|
|
|
|
public bool HasRightToEditAppointment(Guid identifier)
|
|
{
|
|
var appointment = AppointmentListItems.FirstOrDefault(app => app.Identifier.Equals(identifier))?.SchedulerAppointment; //Appointments.FirstOrDefault(app => app.SchedulerAppointmentOid.HasValue && app.SchedulerAppointmentOid.Value == appointmentOid);
|
|
|
|
return appointment != null && Utils.CheckSchedulerRights(appointment.CustomerList, appointment.ResourceList, appointment.EmployeeList, appointment.Originator, appointment.SchedulerAppointmentOid is null, SchedulerRightsCheckType.Edit, MobileSessionFacade.LoggedInUserDC, TeamMemberCustomerOids ?? new List<long>());
|
|
}
|
|
|
|
public string DescriptionToEdit => SelectedAppointment?.Description ?? string.Empty;
|
|
|
|
public string SubjectToEdit => SelectedAppointment?.Subject ?? string.Empty;
|
|
|
|
public string StartDateToEdit => SelectedAppointment?.StartDate?.ToShortDateString() ?? SelectedDate.ToShortDateString();
|
|
|
|
public string EndDateToEdit => SelectedAppointment?.EndDate?.ToShortDateString() ?? SelectedDate.ToShortDateString();
|
|
|
|
public string StartTimeToEdit => SelectedAppointment?.StartDate?.ToShortTimeString() ?? string.Empty;
|
|
|
|
public string EndTimeToEdit => SelectedAppointment?.EndDate?.ToShortTimeString() ?? string.Empty;
|
|
|
|
public string LocationToEdit => SelectedAppointment?.Location ?? string.Empty;
|
|
|
|
public List<ResourceDC> AllResources
|
|
{
|
|
get
|
|
{
|
|
var allResources = new List<ResourceDC>();
|
|
|
|
foreach(var cat2res in ResourceCategories2Resources)
|
|
{
|
|
allResources.AddRangeIfElementsNotIn(cat2res.Value);
|
|
}
|
|
|
|
return allResources.OrderBy(resource => resource.Name).ToList();
|
|
}
|
|
}
|
|
|
|
public List<ResourceDC> SelectedResources { get; set; } = new List<ResourceDC>();
|
|
|
|
public Dictionary<ValueListEntryDC, List<ResourceDC>> ResourceCategories2Resources { get; set; } = new Dictionary<ValueListEntryDC, List<ResourceDC>>();
|
|
|
|
|
|
[Display(Name = "Kalenderansicht")]
|
|
public string SelectedSchedulerView { get; set; } = "1";
|
|
|
|
public List<SelectListItem> SchedulerViewList
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>
|
|
{
|
|
new SelectListItem { Text = "1", Value = "1" },
|
|
new SelectListItem { Text = "5", Value = "5" },
|
|
new SelectListItem { Text = "7", Value = "7" }
|
|
};
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public WeekViewObject WeekViewObject { get; set; }
|
|
|
|
public List<CompactEmployeeDC> AllEmployees { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<CompactEmployeeDC> SelectedEmployees { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<CompactCustomerDC> AllCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public List<CompactCustomerDC> SelectedCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public bool IsInEditMode => SelectedAppointment != null;
|
|
|
|
// ToDo: Überarbeiten? Es kam das Ansehen hinzu
|
|
public bool HasResourcesEmployeesOrCustomers
|
|
{
|
|
get
|
|
{
|
|
var isOwnAppointment = !IsInEditMode || SelectedAppointment.Originator.EmployeeOid == Employee.EmployeeOid;
|
|
|
|
var v1 = HasRightToInsertEmployeeAppointments || IsInEditMode && HasRightToEditEmployeeAppointments;
|
|
|
|
var v2 = HasRightToInsertRessourceAppointments || IsInEditMode && HasRightToEditResourceAppointments;
|
|
|
|
if (IsInEditMode && !isOwnAppointment)
|
|
{
|
|
v2 = HasRightToEditOthersResourceAppointments;
|
|
}
|
|
|
|
var v3 = HasRightToInsertCustomerAppointments || IsInEditMode && HasRightToEditCustomerAppointments;
|
|
|
|
return v1 || v2 || v3;
|
|
}
|
|
}
|
|
|
|
public bool ShowEmployeeButton => IsInEditMode ? HasRightToInsertEmployeeAppointments : HasRightToEditEmployeeAppointments;
|
|
public bool ShowCustomerButton => IsInEditMode ? HasRightToInsertCustomerAppointments : HasRightToEditCustomerAppointments;
|
|
|
|
//IntervalFinder
|
|
public List<CompactEmployeeDC> SelectedEmployeesForIntervalFinder { get; set; } = new List<CompactEmployeeDC>();
|
|
public List<CompactCustomerDC> SelectedCustomersForIntervalFinder { get; set; } = new List<CompactCustomerDC>();
|
|
public List<ResourceDC> SelectedResourcesForIntervalFinder { get; set; } = new List<ResourceDC>();
|
|
|
|
public Dictionary<DateTimeSpan, Dictionary<DateTime, bool>> FreeIntervals { get; set; } = new Dictionary<DateTimeSpan, Dictionary<DateTime, bool>>();
|
|
|
|
public List<DateTime> FreeIntervalDays
|
|
{
|
|
get
|
|
{
|
|
var days = new List<DateTime>();
|
|
|
|
foreach(var date2HasFreeSlot in FreeIntervals.Values)
|
|
{
|
|
foreach(var date in date2HasFreeSlot.Keys)
|
|
{
|
|
days.AddIfNotIn(date.Date);
|
|
}
|
|
}
|
|
|
|
return days;
|
|
}
|
|
}
|
|
|
|
public bool IsInIntervalFinderMode { get; set; }
|
|
public DateTime? IntervalStartDate { get; set; }
|
|
public DateTime? IntervalEndDate { get; set; }
|
|
|
|
public string IntervalStartDateStr => IntervalStartDate.HasValue ? $"{IntervalStartDate:dd.MM.yyyy}" : string.Empty;
|
|
public string IntervalEndDateStr => IntervalEndDate.HasValue ? $"{IntervalEndDate:dd.MM.yyyy}" : string.Empty;
|
|
public string IntervalStartTimeStr => IntervalStartDate.HasValue ? $"{IntervalStartDate:HH:mm}" : string.Empty;
|
|
public string IntervalEndTimeStr => IntervalEndDate.HasValue ? $"{IntervalEndDate:HH:mm}" : string.Empty;
|
|
|
|
public int? IntervalDuration { get; set; }
|
|
|
|
public string IntervalDurationStr => IntervalDuration.HasValue ? $"{IntervalDuration}" : string.Empty;
|
|
|
|
[Display(Name = "Ganztägig")]
|
|
public bool IsAllDay { get; set; }
|
|
|
|
[Display(Name = "Privat")]
|
|
public bool IsPrivate { get; set; }
|
|
|
|
public List<CompactEmployeeDC> MyTeamEmployees { get; set; }
|
|
|
|
public List<ResourceDC> SelectedResourcesForFiltering { get; set; } = new List<ResourceDC>();
|
|
public List<CompactEmployeeDC> SelectedEmployeesForFiltering { get; set; } = new List<CompactEmployeeDC>();
|
|
public List<CompactCustomerDC> SelectedCustomersForFiltering { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
public List<CompactTeamDC> MyTeams { get; set; } = new List<CompactTeamDC>();
|
|
|
|
public bool ShouldLoadTasks { get; set; }
|
|
}
|
|
|
|
public class WeekViewObject
|
|
{
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> MondayAppointments { get; set; }
|
|
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> TuesdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> WednesdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> ThursdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> FridayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> SaturdayAppointments { get; set; }
|
|
public KeyValuePair<DateTime, List<AppointmentListItem>> SundayAppointments { get; set; }
|
|
|
|
public WeekViewObject(IEnumerable<SchedulerAppointmentDC> appointments, DateTime monday, EmployeeDC loggedInEmployee)
|
|
{
|
|
var first = monday.Date;
|
|
var last = first.AddDays(6);
|
|
|
|
var tuesday = first.AddDays(1);
|
|
var wednesday = first.AddDays(2);
|
|
var thursday = first.AddDays(3);
|
|
var friday = first.AddDays(4);
|
|
var saturday = first.AddDays(5);
|
|
|
|
var blubbtest = appointments.Where(a => a.StartDate >= first || a.StartDate <= last).ToList();
|
|
|
|
var mondays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Monday);
|
|
var tuesdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Tuesday);
|
|
var wednesdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Wednesday);
|
|
var thursdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Thursday);
|
|
var fridays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Friday);
|
|
var saturdays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Saturday);
|
|
var sundays = blubbtest.Where(a => a.StartDate.HasValue && a.StartDate.Value.DayOfWeek == DayOfWeek.Sunday);
|
|
|
|
MondayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(first, new List<AppointmentListItem>());
|
|
TuesdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(tuesday, new List<AppointmentListItem>());
|
|
WednesdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(wednesday, new List<AppointmentListItem>());
|
|
ThursdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(thursday, new List<AppointmentListItem>());
|
|
FridayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(friday, new List<AppointmentListItem>());
|
|
SaturdayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(saturday, new List<AppointmentListItem>());
|
|
SundayAppointments = new KeyValuePair<DateTime, List<AppointmentListItem>>(last, new List<AppointmentListItem>());
|
|
|
|
mondays.DoForEach(app => MondayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
tuesdays.DoForEach(app => TuesdayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
wednesdays.DoForEach(app => WednesdayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
thursdays.DoForEach(app => ThursdayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
fridays.DoForEach(app => FridayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
saturdays.DoForEach(app => SaturdayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
sundays.DoForEach(app => SundayAppointments.Value.Add(new AppointmentListItem(app)));
|
|
}
|
|
}
|
|
} |