| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq.Expressions;
 
- using InABox.Core;
 
- namespace Comal.Classes
 
- {
 
-     public enum LeaveRequestStatus
 
-     {
 
-         NotSubmitted,
 
-         InProgress,
 
-         Approved,
 
-         Rejected
 
-     }
 
-     
 
-     public class LeaveRequestOpenFormCount : CoreAggregate<LeaveRequest, LeaveRequestForm, Guid>
 
-     {
 
-         public override Expression<Func<LeaveRequestForm, Guid>> Aggregate => x => x.ID;
 
-         public override AggregateCalculation Calculation => AggregateCalculation.Count;
 
-         public override Filter<LeaveRequestForm>? Filter =>
 
-             new Filter<LeaveRequestForm>(x => x.FormCompleted).IsEqualTo(DateTime.MinValue);
 
-         public override Dictionary<Expression<Func<LeaveRequestForm, object>>, Expression<Func<LeaveRequest, object>>> Links =>
 
-             new Dictionary<Expression<Func<LeaveRequestForm, object>>, Expression<Func<LeaveRequest, object>>>()
 
-             {
 
-                 { LeaveRequestForm => LeaveRequestForm.Parent.ID, LeaveRequest => LeaveRequest.ID }
 
-             };
 
-     }
 
-     
 
-     public class LeaveRequestTotalFormCount : CoreAggregate<LeaveRequest, LeaveRequestForm, Guid>
 
-     {
 
-         public override Expression<Func<LeaveRequestForm, Guid>> Aggregate => x => x.ID;
 
-         public override AggregateCalculation Calculation => AggregateCalculation.Count;
 
-         
 
-         public override Dictionary<Expression<Func<LeaveRequestForm, object>>, Expression<Func<LeaveRequest, object>>> Links =>
 
-             new Dictionary<Expression<Func<LeaveRequestForm, object>>, Expression<Func<LeaveRequest, object>>>()
 
-             {
 
-                 { LeaveRequestForm => LeaveRequestForm.Parent.ID, LeaveRequest => LeaveRequest.ID }
 
-             };
 
-     }
 
-     [UserTracking("Holiday Calendar")]
 
-     [Caption("Leave Requests")]
 
-     public class LeaveRequest : Entity, IRemotable, IPersistent, ILicense<LeaveManagementLicense>, IDataEntryInstance
 
-     {
 
-         [EditorSequence(1)]
 
-         [RequiredColumn]
 
-         public EmployeeLink EmployeeLink { get; set; }
 
-         [EditorSequence(2)]
 
-         public LeaveRequestActivityLink LeaveType { get; set; }
 
-         [DateEditor]
 
-         [RequiredColumn]
 
-         [EditorSequence(3)]
 
-         public DateTime From { get; set; }
 
-         [TimeOfDayEditor]
 
-         [EditorSequence(4)]
 
-         public TimeSpan FromTime { get; set; }
 
-         [DateEditor]
 
-         [RequiredColumn]
 
-         [EditorSequence(5)]
 
-         public DateTime To { get; set; }
 
-         [TimeOfDayEditor]
 
-         [EditorSequence(6)]
 
-         public TimeSpan ToTime { get; set; } = new TimeSpan(23, 59, 59);
 
-         [EditorSequence(7)]
 
-         public DocumentLink Request { get; set; }
 
-         [MemoEditor]
 
-         [EditorSequence(8)]
 
-         public string Notes { get; set; }
 
-         
 
-         [EditorSequence(9)]
 
-         [Caption("Approval Set")]
 
-         public LeaveRequestApprovalSetLink ApprovalSet { get; set; }
 
-         
 
-         private class OutstandingApprovalsFormula : ComplexFormulaGenerator<LeaveRequest, string>
 
-         {
 
-             public override IComplexFormulaNode<LeaveRequest, string> GetFormula() =>
 
-                 Aggregate(AggregateCalculation.Concat,
 
-                         x => x.Property(x => x.Employee.Code),
 
-                         filter: new Filter<LeaveRequestApproval>(x => x.Status).IsEqualTo(LeaveRequestApprovalStatus.NotYetApproved))
 
-                     .WithLink(x => x.LeaveRequest.ID, x => x.ID);
 
-         }
 
-         [ComplexFormula(typeof(OutstandingApprovalsFormula))]
 
-         [Editable(Editable.Hidden)]
 
-         public string OutstandingApprovals { get; set; }
 
-         
 
-         private class ApprovalStatusFormula : ComplexFormulaGenerator<LeaveRequest, LeaveRequestApprovalStatus>
 
-         {
 
-             public override IComplexFormulaNode<LeaveRequest, LeaveRequestApprovalStatus> GetFormula() =>
 
-                 Aggregate<LeaveRequestApproval>(
 
-                     AggregateCalculation.Maximum, 
 
-                     x=>x.Property(p=>p.Status)
 
-                 ).WithLink(x=>x.LeaveRequest.ID,x=>x.ID);
 
-         }
 
-         [Editable(Editable.Hidden)]
 
-         [ComplexFormula(typeof(ApprovalStatusFormula))]
 
-         public LeaveRequestApprovalStatus ApprovalStatus { get; set; }
 
-         
 
-         [LoggableProperty]
 
-         [EditorSequence(10)]
 
-         [RequiredColumn]
 
-         [EnumLookupEditor(typeof(LeaveRequestStatus))]
 
-         public LeaveRequestStatus Status { get; set; } = LeaveRequestStatus.InProgress;
 
-         [Caption("Response")]
 
-         [MemoEditor]
 
-         [EditorSequence(11)]
 
-         public string StatusNotes { get; set; }
 
-         
 
-         [EditorSequence("Internal Notes", 1)]
 
-         [TimestampEditor]
 
-         public DateTime DataEntered { get; set; }
 
-         [MemoEditor]
 
-         [EditorSequence("Internal Notes", 2)]
 
-         public string InternalNotes { get; set; }
 
-         
 
-         [TimestampEditor(Editable = Editable.Disabled)]
 
-         [EditorSequence("Internal Notes", 3)]
 
-         [RequiredColumn]
 
-         public DateTime Processed { get; set; }
 
-         [Obsolete("Replaced By Status", true)]
 
-         [NullEditor]
 
-         public DateTime Approved { get; set; }
 
-         [Obsolete("Replaced By StatusNotes", true)]
 
-         [NullEditor]
 
-         public string ApprovalNotes { get; set; }
 
-         [NullEditor]
 
-         [EntityRelationship(DeleteAction.Cascade)]
 
-         public StandardLeaveLink PublicHoliday { get; set; }
 
-         
 
-         [IntegerEditor(Visible = Visible.Optional,Editable = Editable.Hidden)]
 
-         [Aggregate(typeof(LeaveRequestOpenFormCount))]
 
-         public int OpenForms { get; set; }
 
-         
 
-         [IntegerEditor(Visible = Visible.Optional,Editable = Editable.Hidden)]
 
-         [Aggregate(typeof(LeaveRequestTotalFormCount))]
 
-         public int FormCount { get; set; }
 
-         //protected override void DoPropertyChanged(string name, object? before, object? after)
 
-         //{
 
-         //    base.DoPropertyChanged(name, before, after);
 
-         //    if (String.Equals(name,"Status"))
 
-         //    {
 
-         //        var status = (LeaveRequestStatus)after;
 
-         //        if (status == LeaveRequestStatus.Approved)
 
-         //            Approved = Approved.IsEmpty() ? DateTime.Now : Approved;
 
-         //        else
 
-         //            Approved = DateTime.MinValue;
 
-         //    }
 
-         //}
 
-         public LeaveRequest LoadFrom(StandardLeave standardleave)
 
-         {
 
-             PublicHoliday.ID = standardleave.ID;
 
-             From = standardleave.From;
 
-             FromTime = standardleave.FromTime;
 
-             To = standardleave.To;
 
-             ToTime = standardleave.ToTime;
 
-             LeaveType.ID = standardleave.LeaveType.ID;
 
-             Notes = standardleave.Name;
 
-             return this;
 
-         }
 
-         //protected override string ToSort()
 
-         //{
 
-         //    if (Approved == DateTime.MinValue)
 
-         //        return String.Format("0{0:yyyyMMdd}{1}",From,EmployeeLink.Name);
 
-         //    else
 
-         //        return String.Format("1{0:yyyyMMdd}{1}", DateTime.MinValue.Add(DateTime.MaxValue.Subtract(From)), EmployeeLink.Name);
 
-         //}
 
-         public static SortOrder<LeaveRequest> SortOrder()
 
-         {
 
-             return new SortOrder<LeaveRequest>(x => x.From, SortDirection.Descending).ThenBy(x => x.EmployeeLink.Name);
 
-         }
 
-         public override string ToString()
 
-         {
 
-             return string.Format("{0}: {1} {2:dd MMM yy} - {3:dd MMM yy} {4}", EmployeeLink.Name, LeaveType.Description, From, To, Status);
 
-         }
 
-         static LeaveRequest()
 
-         {
 
-             LinkedProperties.Register<LeaveRequest,LeaveRequestApprovalSetLink,Guid>(x=>x.EmployeeLink.LeaveRequestApprovalSet, x=>x.ID, x=>x.ApprovalSet.ID);
 
-             LinkedProperties.Register<LeaveRequest,LeaveRequestApprovalSetLink,string>(x=>x.EmployeeLink.LeaveRequestApprovalSet, x=>x.Code, x=>x.ApprovalSet.Code);
 
-             LinkedProperties.Register<LeaveRequest,LeaveRequestApprovalSetLink,string>(x=>x.EmployeeLink.LeaveRequestApprovalSet, x=>x.Description, x=>x.ApprovalSet.Description);
 
-         }
 
-     }
 
- }
 
 
  |