diff --git a/BeWoPlanerMobil/Controllers/MainController.cs b/BeWoPlanerMobil/Controllers/MainController.cs index 139b380be..a76ecd2de 100644 --- a/BeWoPlanerMobil/Controllers/MainController.cs +++ b/BeWoPlanerMobil/Controllers/MainController.cs @@ -561,7 +561,7 @@ namespace BeWoPlanerMobil.Controllers Model.SelectedServiceCategoryOid = scm.ServiceCategoryOid; } - return SerializeObject(scm != null ? scm.ServiceDescriptions : new List()); + return SerializeObject(scm != null ? scm.ServiceDescriptions.OrderBy(serviceDescription => serviceDescription.Position).ToList() : new List()); } catch(Exception exception) { @@ -1528,6 +1528,11 @@ namespace BeWoPlanerMobil.Controllers Model.SelectedSupportConceptListObject = Model.SupportConceptListObjects.First(f => f.CostBearer2SupportConceptOid.Equals(cb2ScOid.ToString())); Model.ServiceCategories.Clear(); } + + if(Model.ServiceCategories != null) + { + Model.ServiceCategories = Model.ServiceCategories.OrderBy(serviceCategory => serviceCategory.Position).ToList(); + } } [HttpPost] diff --git a/BeWoPlanerMobil/Controllers/SchedulerController.cs b/BeWoPlanerMobil/Controllers/SchedulerController.cs index 0cf1c8eb2..1fc9673be 100644 --- a/BeWoPlanerMobil/Controllers/SchedulerController.cs +++ b/BeWoPlanerMobil/Controllers/SchedulerController.cs @@ -116,69 +116,65 @@ namespace BeWoPlanerMobil.Controllers (date.InBetween(w.StartDate.Value, w.EndDate.Value, false) || date.CompareShortDates(w.StartDate.Value)))).ToList(); - var deletedOccurrences = holySweetFlyingFuck.Where(w => w.Type == 4).Select(s => GetOccurrenceId(s.RecurrenceInfo)).ToList(); - var changedOccurrences = holySweetFlyingFuck.Where(w => w.Type == 3).Select(s => GetOccurrenceId(s.RecurrenceInfo)).ToList(); + var deletedOccurrences = holySweetFlyingFuck.Where(w => w.Type == 4).Select(s => BS.Shared.Core.Utils.GetOccurrenceId(s.RecurrenceInfo)).ToList(); + var changedOccurrences = holySweetFlyingFuck.Where(w => w.Type == 3).Select(s => BS.Shared.Core.Utils.GetOccurrenceId(s.RecurrenceInfo)).ToList(); holySweetFlyingFuck = holySweetFlyingFuck.Where(w => w.Type != 4).ToList(); - var numberOfPatterns = appointments.Count(appointment => appointment.RecurrenceInfo != null && appointment.Type == 1); - foreach(var appointment in appointments) + + foreach(var appointment in appointments.Where(app => app.RecurrenceInfo != null && app.Type == 1)) { - if(appointment.RecurrenceInfo != null && appointment.Type == 1) + var recurrenceInfo = new RecurrenceInfo(); + recurrenceInfo.FromXml(appointment.RecurrenceInfo); + var occurrenceCalculator = OccurrenceCalculator.CreateInstance(recurrenceInfo); + + var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern); + pattern.RecurrenceInfo.FromXml(appointment.RecurrenceInfo); + pattern.Start = pattern.RecurrenceInfo.Start; + pattern.End = pattern.RecurrenceInfo.End; + var patternId = pattern.RecurrenceInfo.Id.ToString(); + + var interval = new TimeInterval(date, date.AddDays(1)); + + var occurrences = occurrenceCalculator.CalcOccurrences(interval, pattern); + + if(occurrences.Count > 0) { - var recurrenceInfo = new RecurrenceInfo(); - recurrenceInfo.FromXml(appointment.RecurrenceInfo); - var occurrenceCalculator = OccurrenceCalculator.CreateInstance(recurrenceInfo); - - var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern); - pattern.RecurrenceInfo.FromXml(appointment.RecurrenceInfo); - pattern.Start = pattern.RecurrenceInfo.Start; - pattern.End = pattern.RecurrenceInfo.End; - var patternId = pattern.RecurrenceInfo.Id.ToString(); - - var interval = new TimeInterval(date, date.AddDays(1)); - - var occurrences = occurrenceCalculator.CalcOccurrences(interval, pattern); - - if(occurrences.Count > 0) + foreach(var termin in occurrences.GetAppointments(interval)) { - foreach(var termin in occurrences.GetAppointments(interval)) + var index = termin.RecurrenceIndex; + + var duration = (appointment.EndDate.Value - appointment.StartDate.Value).TotalMinutes; + + if(!date.InBetween(termin.Start.GetShortDateTime(), termin.Start.AddMinutes(duration), true) || + changedOccurrences.Any(a => a.PatternId.Equals(patternId) && a.Index == index) || + deletedOccurrences.Any(a => a.PatternId.Equals(patternId) && a.Index == index)) { - var index = termin.RecurrenceIndex; - - var duration = (appointment.EndDate.Value - appointment.StartDate.Value).TotalMinutes; - - if(!date.InBetween(termin.Start.GetShortDateTime(), termin.Start.AddMinutes(duration), - true) || changedOccurrences.Any(a => - a.PatternId.Equals(patternId) && a.Index == index) || - deletedOccurrences.Any(a => a.PatternId.Equals(patternId) && a.Index == index)) - { - continue; - } - - var recurringAppointment = new SchedulerAppointmentDC - { - AllDay = appointment.AllDay, - CustomerList = appointment.CustomerList, - Description = appointment.Description, - EmployeeList = appointment.EmployeeList, - EndDate = termin.Start.AddMinutes(duration), - FormerBookingSequenceOid = appointment.FormerBookingSequenceOid, - IsPrivate = appointment.IsPrivate, - LabelId = appointment.LabelId, - Location = appointment.Location, - Originator = appointment.Originator, - RecurrenceInfo = termin.RecurrenceInfo.ToXml(), - ReminderInfo = appointment.ReminderInfo, - ResourceList = appointment.ResourceList, - StartDate = termin.Start, - Subject = appointment.Subject ?? "", - Type = appointment.Type - }; - - Model.RecurringAppointments.AddIfNotIn(recurringAppointment); - - holySweetFlyingFuck.AddIfNotIn(recurringAppointment); + continue; } + + var recurringAppointment = new SchedulerAppointmentDC + { + AllDay = appointment.AllDay, + CustomerList = appointment.CustomerList, + Description = appointment.Description, + EmployeeList = appointment.EmployeeList, + EndDate = termin.Start.AddMinutes(duration), + FormerBookingSequenceOid = appointment.FormerBookingSequenceOid, + IsPrivate = appointment.IsPrivate, + LabelId = appointment.LabelId, + Location = appointment.Location, + Originator = appointment.Originator, + RecurrenceInfo = termin.RecurrenceInfo.ToXml(), + ReminderInfo = appointment.ReminderInfo, + ResourceList = appointment.ResourceList, + StartDate = termin.Start, + Subject = appointment.Subject ?? "", + Type = appointment.Type + }; + + Model.RecurringAppointments.AddIfNotIn(recurringAppointment); + + holySweetFlyingFuck.AddIfNotIn(recurringAppointment); } } } diff --git a/BeWoPlanerMobil/Util/MobileUtils.cs b/BeWoPlanerMobil/Util/MobileUtils.cs index 687f433e3..ede4c88b9 100644 --- a/BeWoPlanerMobil/Util/MobileUtils.cs +++ b/BeWoPlanerMobil/Util/MobileUtils.cs @@ -12,8 +12,6 @@ using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; -using DevExpress.XtraScheduler; - using Newtonsoft.Json; using RestSharp; using static System.Int32; @@ -159,25 +157,6 @@ namespace BeWoPlanerMobil.Util return null; } - public static RecurrenceInformation GetOccurrenceId(string pRecurrenceInfoString) - { - var regex = new Regex("Index=\"[0-9]+\""); - - var match = regex.Match(pRecurrenceInfoString); - - var recurrenceInfo = new RecurrenceInfo(); - recurrenceInfo.FromXml(pRecurrenceInfoString); - - var index = 0; - - if (!match.Value.IsNullOrEmpty()) - { - index = Parse(match.Value.Split('"')[1]); - } - - return new RecurrenceInformation(recurrenceInfo.Id.ToString(), index); - } - public static bool IsBillable(long serviceDescriptionOid, List serviceDescriptions) { var description = serviceDescriptions.FirstOrDefault(f => f.ServiceDescriptionOid.Equals(serviceDescriptionOid)); diff --git a/Data/Access/SearchDAO.cs b/Data/Access/SearchDAO.cs index 53a80cec4..cf9cbf15b 100644 --- a/Data/Access/SearchDAO.cs +++ b/Data/Access/SearchDAO.cs @@ -19,8 +19,12 @@ using NHibernate.SqlCommand; using BS.Shared.Core; using BS.Shared; using BS.Shared.DataContracts; +using DevExpress.XtraScheduler; +using DevExpress.XtraScheduler.Compatibility; using static System.String; +using Appointment = BeWo.Data.Entities.Appointment; using Login = BeWo.Data.Entities.Login; +using Resource = BeWo.Data.Entities.Resource; namespace BeWo.Data.Access { @@ -1254,7 +1258,7 @@ namespace BeWo.Data.Access public bool OverlappingAppointmentsExist(DateTime start, DateTime end, IEnumerable employees, IEnumerable customers, IEnumerable resources, long originator, long? appointmentOid, string recurrenceId = "", int occurrenceIndex = 0) { var criteria = CreateCriteria() - .Add(Restrictions.Eq(BeWoEntityBase.PropertyName_IsActive, ActivationTypeId.Active)) + .Add(Restrictions.Eq(nameof(BeWoEntityBase.IsActive), ActivationTypeId.Active)) .Add(Restrictions.Eq(nameof(SchedulerAppointment.IsTask), false)) .Add(Restrictions.Or( Restrictions.Or( @@ -1279,8 +1283,8 @@ namespace BeWo.Data.Access ) ) ); - - if (appointmentOid != null) + + if (appointmentOid != null) { criteria.Add(Restrictions.Not(Restrictions.Eq(BeWoEntityBase.PropertyName_Oid, appointmentOid))); } @@ -1303,7 +1307,75 @@ namespace BeWo.Data.Access var schedulerAppointments = appointments as IList ?? appointments.ToList(); - var oidList = new List(); + // Serientermine anhand der RecurrenceInfo erzeugen und den schedulerAppointments hinzufügen + var deletedOccurences = schedulerAppointments.Where(app => app.Type == 4).Select(app => Utils.GetOccurrenceId(app.RecurrenceInfo)).ToList(); + var changedOccurences = schedulerAppointments.Where(app => app.Type == 3).Select(app => Utils.GetOccurrenceId(app.RecurrenceInfo)).ToList(); + + var recurringAppointmentsCriteria = CreateRecurrenceCriteria(start, end) + .Add(Restrictions.Eq(nameof(SchedulerAppointment.Type), 1)); + + var recurringAppointments = recurringAppointmentsCriteria.List().ToList(); + + foreach(var appointment in recurringAppointments) + { + var recurrenceInfo = new RecurrenceInfo(); + recurrenceInfo.FromXml(appointment.RecurrenceInfo); + + var occurenceCalculator = OccurrenceCalculator.CreateInstance(recurrenceInfo); + + var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern); + pattern.RecurrenceInfo.FromXml(appointment.RecurrenceInfo); + pattern.Start = pattern.RecurrenceInfo.Start; + pattern.End = pattern.RecurrenceInfo.End; + + var patternId = pattern.RecurrenceInfo.Id.ToString(); + + var interval = new TimeInterval(start, end); + + var occurences = occurenceCalculator.CalcOccurrences(interval, pattern); + + foreach(var occurence in occurences.GetAppointments(interval)) + { + if(appointment.EndDate == null || appointment.StartDate == null) + { + continue; + } + + var index = occurence.RecurrenceIndex; + var duration = (appointment.EndDate.Value - appointment.StartDate.Value).TotalMinutes; + + if(!start.InBetweenOrAround(end, occurence.Start, occurence.Start.AddMinutes(duration)) || + changedOccurences.Any(changedOccurence => changedOccurence.PatternId.Equals(patternId) && changedOccurence.Index == index) || + deletedOccurences.Any(deletedOccurence => deletedOccurence.PatternId.Equals(patternId) && deletedOccurence.Index == index)) + { + continue; + } + + var recurringAppointment = new SchedulerAppointment + { + AllDay = occurence.AllDay, + CustomerList = appointment.CustomerList, + Notice = appointment.Notice, + EmployeeList = appointment.EmployeeList, + EndDate = occurence.Start.AddMinutes(duration), + FormerBookingSequenceOid = appointment.FormerBookingSequenceOid, + IsPrivate = appointment.IsPrivate, + Location = appointment.Location, + Originator = appointment.Originator, + RecurrenceInfo = occurence.RecurrenceInfo.ToXml(), + ReminderInfo = appointment.ReminderInfo, + ResourceList = appointment.ResourceList, + StartDate = occurence.Start, + Subject = appointment.Subject ?? "", + Type = appointment.Type + }; + + schedulerAppointments.AddIfNotIn(recurringAppointment); + } + } + // -------------------------------------------------------------------------------------------------------------------------------------- + + var oidList = new List(); foreach (var appointment in schedulerAppointments) { oidList.AddRange(appointment.EmployeeList.Select(rel => rel.ParticipationAnswer != ParticipationAnswer.Absage && rel.Employee.Oid != null ? rel.Employee.Oid.Value : 0)); @@ -1315,7 +1387,7 @@ namespace BeWo.Data.Access var ori = schedulerAppointments.Any(app => app.Originator.Oid.HasValue && app.Originator.Oid.Value == originator && (app.EmployeeList.Count == 0 || app.EmployeeList.Any(a => a.Employee.Oid.HasValue && a.Employee.Oid.Value == originator))); - return emp || cus || res || ori; + return emp || cus || res || ori; } public IEnumerable GetAllActiveAppointmentsForEmployeeInInterval(DateTime start, DateTime end, long pEmployeeOid) @@ -2393,13 +2465,15 @@ namespace BeWo.Data.Access } } + var test = criteria.List().ToList(); + return criteria.List(); } public IEnumerable LoadFilteredAppointmentsForEmployee(bool pHasRightToSeeAllEmployeeAppointments, long? pEmployeeOid, DateTime pIntervalStart, DateTime pIntervalEnd, List pSelectedEmployees, List pSelectedCustomers, List pSelectedResources, bool pEmployeesOnly, bool pCustomersOnly, bool pResourcesOnly, bool pPrivateAppointmentsOnly, bool pOnlyMyAppointments, bool pIncludeInactiveOnes) { var mainCriteria = CreateRecurrenceCriteria(pIntervalStart, pIntervalEnd, pIncludeInactiveOnes); - + ICriterion ownAppointmentCriterion = null; ICriterion employeeCriterion = null; ICriterion customerCriterion = null; @@ -2580,7 +2654,7 @@ namespace BeWo.Data.Access var changedOrDeletedOccurences = FindAppointmentsByRecurrenceId(ExtractRecurrenceIdFromRecurrenceInfo(allExceptionalRecurrenceInfos.Select(s => s.RecurrenceInfo).ToList()), true); appointments.AddRangeIfElementsNotIn(changedOrDeletedOccurences); - + return appointments; } diff --git a/Data/Data.csproj b/Data/Data.csproj index 6cdc87814..9632dd3b7 100644 --- a/Data/Data.csproj +++ b/Data/Data.csproj @@ -76,6 +76,14 @@ false + + False + ..\BeWoPlanerMobil\bin\DevExpress.Data.v17.1.dll + + + False + + ..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.dll diff --git a/Report/DefaultReports/KilometerauswertungsReport.designer.cs b/Report/DefaultReports/KilometerauswertungsReport.designer.cs index 62adf7856..9210b0314 100644 --- a/Report/DefaultReports/KilometerauswertungsReport.designer.cs +++ b/Report/DefaultReports/KilometerauswertungsReport.designer.cs @@ -265,7 +265,7 @@ namespace BeWo.Report.DefaultReports // xrLabel2 // this.xrLabel2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { - new DevExpress.XtraReports.UI.XRBinding("Text", null, "MonthInformation", "Zeitraum: {0:}")}); + new DevExpress.XtraReports.UI.XRBinding("Text", null, "MonthInformation", "Zeitraum: {0:MMMM yyyy}")}); this.xrLabel2.Font = new System.Drawing.Font("Arial", 12F); this.xrLabel2.LocationFloat = new DevExpress.Utils.PointFloat(0F, 24.99999F); this.xrLabel2.Name = "xrLabel2"; diff --git a/Service/ServiceImplementations/ResourceServiceImp.cs b/Service/ServiceImplementations/ResourceServiceImp.cs index 983a59c7c..e7c71bc1a 100644 --- a/Service/ServiceImplementations/ResourceServiceImp.cs +++ b/Service/ServiceImplementations/ResourceServiceImp.cs @@ -1126,6 +1126,8 @@ namespace BeWo.Service.ServiceImplementations var appointments = DAOFactory.SearchDAO.LoadFilteredAppointmentsForEmployee(pHasRightToSeeAllEmployeeAppointments, ownerOid, pIntervalStart, pIntervalEnd, pSelectedEmployees, pSelectedCustomer, pSelectedResources, pEmployeesOnly, pCustomersOnly, pResourcesOnly, pPrivateAppointmentsOnly, pOnlyMyAppointments, false).ToList(); + var serientermine = appointments.Where(app => app.RecurrenceInfo != null && app.Type == 1).ToList(); + var all = MapperFactory.SchedulerAppointmentDCSchedulerAppointment.MapToNewDCs(appointments).OrderBy(a => a.StartDate).ToList(); var filteredEmployeeOids = new List(); @@ -1341,8 +1343,6 @@ namespace BeWo.Service.ServiceImplementations result.Add(kosmetisch); } - var test = result.Where(w => w.SchedulerAppointmentOid == null).ToList(); - return result; } catch(Exception e) diff --git a/Shared/Core/RecurrenceInformation.cs b/Shared/Core/RecurrenceInformation.cs new file mode 100644 index 000000000..bfcfaa23a --- /dev/null +++ b/Shared/Core/RecurrenceInformation.cs @@ -0,0 +1,14 @@ +namespace BS.Shared.Core +{ + public class RecurrenceInformation + { + public string PatternId { get; set; } + public int Index { get; set; } + + public RecurrenceInformation(string pPatternId, int pIndex) + { + PatternId = pPatternId; + Index = pIndex; + } + } +} diff --git a/Shared/Core/Utils.cs b/Shared/Core/Utils.cs index eb9f5afae..fdda2db05 100644 --- a/Shared/Core/Utils.cs +++ b/Shared/Core/Utils.cs @@ -8,11 +8,13 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Xml.Serialization; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using DevExpress.XtraScheduler; +using DevExpress.XtraScheduler.Compatibility; namespace BS.Shared.Core { @@ -947,10 +949,30 @@ namespace BS.Shared.Core return lowerCase ? result.ToLowerInvariant() : result; } + public static bool ContainsKey(string[] array, string key) { return array.Any(keyEntry => keyEntry.Equals(key)); } + + public static RecurrenceInformation GetOccurrenceId(string pRecurrenceInfoString) + { + var regex = new Regex("Index=\"[0-9]+\""); + + var match = regex.Match(pRecurrenceInfoString); + + var recurrenceInfo = new RecurrenceInfo(); + recurrenceInfo.FromXml(pRecurrenceInfoString); + + var index = 0; + + if(!match.Value.IsNullOrEmpty()) + { + index = int.Parse(match.Value.Split('"')[1]); + } + + return new RecurrenceInformation(recurrenceInfo.Id.ToString(), index); + } } public struct NullCompareResult diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index c8a1aa172..4c47aec90 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -135,6 +135,7 @@ +