2016-06-27 01:45:38 +02:00
|
|
|
|
using System;
|
2017-02-01 13:53:59 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2017-12-14 18:33:17 -04:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
using BeWo.Scheduler.View;
|
2022-12-30 16:28:23 +01:00
|
|
|
|
using BeWo.ServiceProxy;
|
2018-03-05 15:27:18 +01:00
|
|
|
|
using BS.Shared.Core;
|
2017-02-01 13:53:59 +01:00
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
|
|
using BS.Shared.DataContracts.Compact;
|
2017-12-14 18:33:17 -04:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
using DevExpress.XtraScheduler;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BeWo.Scheduler.ViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
public class NewSchedulerViewModel
|
|
|
|
|
|
{
|
2022-04-26 10:00:34 +02:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public event EventHandler<EventArgs<ISchedulerViewModel>> ViewModelChanged;
|
|
|
|
|
|
|
2018-03-05 15:27:18 +01:00
|
|
|
|
private ISchedulerViewModel _ActiveAppointmentViewModel;
|
|
|
|
|
|
|
2017-02-01 13:53:59 +01:00
|
|
|
|
public ISchedulerViewModel ActiveAppointmentViewModel
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
2018-03-05 15:27:18 +01:00
|
|
|
|
get => _ActiveAppointmentViewModel;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2017-11-21 13:28:06 +01:00
|
|
|
|
set
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
2017-04-18 15:11:45 +02:00
|
|
|
|
if(value != null)
|
2017-05-15 09:11:13 +02:00
|
|
|
|
{
|
2018-03-05 15:27:18 +01:00
|
|
|
|
_ActiveAppointmentViewModel = value;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2017-11-21 13:28:06 +01:00
|
|
|
|
ViewModelChanged?.Invoke(this, new EventArgs<ISchedulerViewModel>(value));
|
2017-04-12 10:55:32 +02:00
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-01 13:53:59 +01:00
|
|
|
|
public AbstractAppointmentEditForm GetEditAppointmentForm(DevExpress.Xpf.Scheduler.SchedulerControl control, Appointment appointment)
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
2017-11-21 13:28:06 +01:00
|
|
|
|
return ActiveAppointmentViewModel?.GetEditAppointmentForm(control, appointment);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void InitNewAppointment(Appointment appointment)
|
|
|
|
|
|
{
|
2017-11-21 13:28:06 +01:00
|
|
|
|
ActiveAppointmentViewModel?.InitNewAppointment(appointment);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-28 12:38:29 +01:00
|
|
|
|
internal void InitNewTask(Appointment pAppointment, DateTime? pDueDate, IEnumerable<Employee2SchedulerAppointmentDC> pSelectedEmployees, List<CompactCustomerDC> pSelectedCustomers, List<ResourceDC> pSelectedResources, List<CompactSupportConceptDC> pSelectedSupportConcepts)
|
2019-01-05 17:03:44 -04:00
|
|
|
|
{
|
2019-02-28 12:38:29 +01:00
|
|
|
|
ActiveAppointmentViewModel?.InitNewTask(pAppointment, pDueDate, pSelectedEmployees, pSelectedCustomers, pSelectedResources, pSelectedSupportConcepts);
|
2019-01-05 17:03:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public SchedulerSettings SchedulerSettings { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public SchedulerSettings GetActiveSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
return ActiveAppointmentViewModel == null ? null : SchedulerSettings ?? ActiveAppointmentViewModel.GetDefaultSchedulerSettings();
|
|
|
|
|
|
}
|
2017-08-28 16:41:19 +02:00
|
|
|
|
|
2022-12-30 16:28:23 +01:00
|
|
|
|
public IEnumerable<SchedulerAppointmentVM> ConvertAbsenceTimesToAppointments(IEnumerable<AbsenceTimeDC> pAbsenceTimes, DateTime pIntervalEnd, List<CompactEmployeeDC> allEmployees, List<CompactCustomerDC> allCustomers)
|
2017-08-28 16:41:19 +02:00
|
|
|
|
{
|
2019-12-20 12:37:08 +01:00
|
|
|
|
return pAbsenceTimes.Where(w => w.AbsenceTimeOid.HasValue && w.Start.HasValue).Select(abwesenheit =>
|
2022-12-30 16:28:23 +01:00
|
|
|
|
{
|
|
|
|
|
|
var isEmployeeAbsenceTime = abwesenheit.EmployeeOid.HasValue;
|
|
|
|
|
|
|
2018-03-05 15:27:18 +01:00
|
|
|
|
var subject = $"{abwesenheit.Reason.Description}";
|
2022-10-11 16:48:36 +02:00
|
|
|
|
var employee = abwesenheit.EmployeeOid.HasValue ? allEmployees.FirstOrDefault(f => f.EmployeeOid == abwesenheit.EmployeeOid.Value) : null;
|
2022-12-30 16:28:23 +01:00
|
|
|
|
var customer = abwesenheit.CustomerOid.HasValue ? allCustomers.FirstOrDefault(f => f.CustomerOid == abwesenheit.CustomerOid.Value) : null;
|
2018-03-05 15:27:18 +01:00
|
|
|
|
|
2022-12-30 16:28:23 +01:00
|
|
|
|
IFilterableDC dc = employee;
|
|
|
|
|
|
var originator = employee;
|
|
|
|
|
|
if(!isEmployeeAbsenceTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
dc = customer;
|
|
|
|
|
|
ServiceFacade.DoEmployeeServiceSync(s => originator = s.FindCompactEmployeeByFullname(abwesenheit.InsUser));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!(dc is null))
|
|
|
|
|
|
{
|
|
|
|
|
|
subject += $" ({dc.SimpleDescription})";
|
|
|
|
|
|
}
|
2018-03-05 15:27:18 +01:00
|
|
|
|
|
2019-12-20 12:37:08 +01:00
|
|
|
|
var absenceTimeEnd = abwesenheit.End?.AddTicks(1);
|
2022-12-30 16:28:23 +01:00
|
|
|
|
|
|
|
|
|
|
if(originator is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
originator = BeWoApp.CompactLoggedOnEmployee;
|
|
|
|
|
|
}
|
2019-12-20 12:37:08 +01:00
|
|
|
|
|
2022-12-30 16:28:23 +01:00
|
|
|
|
return new SchedulerAppointmentVM(
|
|
|
|
|
|
true,
|
|
|
|
|
|
subject,
|
|
|
|
|
|
abwesenheit.Start.Value,
|
|
|
|
|
|
abwesenheit.End ?? pIntervalEnd,
|
|
|
|
|
|
originator,
|
|
|
|
|
|
abwesenheit.Start,
|
|
|
|
|
|
absenceTimeEnd,
|
|
|
|
|
|
abwesenheit.AbsenceTimeOid.Value,
|
|
|
|
|
|
!isEmployeeAbsenceTime);
|
|
|
|
|
|
}).ToList();
|
2017-08-28 16:41:19 +02:00
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|