| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 | using System;using System.Linq;using System.Linq.Expressions;using InABox.Core;namespace Comal.Classes{    /// <summary>    ///     An assignment represents an anticipated booking for an employee, much like a diary entry    ///     <exclude />    /// </summary>    [UserTracking("Assignments")]    [Caption("Assignments")]    public class Assignment : Entity, IPersistent, IRemotable, INumericAutoIncrement<Assignment>, IOneToMany<Employee>, IOneToMany<Job>,        IOneToMany<Kanban>, ILicense<SchedulingControlLicense>, IJobActivity, IOneToMany<Invoice>, IJobScopedItem    {        [IntegerEditor(Editable = Editable.Hidden)]        [EditorSequence(1)]        public int Number { get; set; }        [DateEditor]        [EditorSequence(2)]        public DateTime Date { get; set; }        [EntityRelationship(DeleteAction.Cascade)]        [EditorSequence(3)]        public EmployeeLink EmployeeLink { get; set; }        // [EntityRelationship(DeleteAction.Cascade)]        // [EditorSequence(4)]        // public EquipmentLink Equipment { get; set; }        [TextBoxEditor]        [EditorSequence(5)]        public string Title { get; set; }        [MemoEditor]        [EditorSequence(6)]        public string Description { get; set; }        [EditorSequence(7)]        public AssignmentActivityLink ActivityLink { get; set; }        private class KanbanLookup : LookupDefinitionGenerator<Kanban, Assignment>        {            public override Filter<Kanban> DefineFilter(Assignment[] items)            {                if (items == null || !items.Any())                    return LookupFactory.DefineFilter<Kanban>();                return new Filter<Kanban>(x => x.Closed).IsEqualTo(DateTime.MinValue).And(x => x.EmployeeLink.ID)                    .IsEqualTo(items.First().EmployeeLink.ID);            }            public override Columns<Assignment> DefineFilterColumns()                => Columns.None<Assignment>().Add(x => x.EmployeeLink.ID);        }        [LookupDefinition(typeof(KanbanLookup))]        [EditorSequence(8)]        [EntityRelationship(DeleteAction.SetNull)]        public KanbanLink Task { get; set; }        [EditorSequence(9)]        public JobLink JobLink { get; set; }                private class JobITPLookup : LookupDefinitionGenerator<JobITP, Assignment>        {            public override Filter<JobITP> DefineFilter(Assignment[] items)            {                if (items.Length == 1)                    return new Filter<JobITP>(x => x.Job.ID).IsEqualTo(items.First().JobLink.ID);                return LookupFactory.DefineFilter<JobITP>();            }                        public override Columns<Assignment> DefineFilterColumns()                => Columns.None<Assignment>().Add(x => x.JobLink.ID);        }        [LookupDefinition(typeof(JobITPLookup))]        [EditorSequence(10)]        public JobITPLink ITP { get; set; }        [NullEditor]        [Obsolete("Replaced with Actual.Start", true)]        public TimeSpan Start { get; set; }        [NullEditor]        [Obsolete("Replaced with Actual.Duration", true)]        public TimeSpan Duration { get; set; }        [NullEditor]        [Obsolete("Replaced with Actual.Finish", true)]        public TimeSpan Finish { get; set; }        [EditorSequence(11)]        [CoreTimeEditor]        public TimeBlock Booked { get; set; }        [EditorSequence(12)]        [CoreTimeEditor]        public TimeBlock Actual { get; set; }                [TimestampEditor]        [RequiredColumn]        [EditorSequence(13)]        public DateTime Completed { get; set; }                [EditorSequence("Processing",1)]        public ActualCharge Charge { get; set; }                [TimestampEditor]        [EditorSequence("Processing",2)]        public DateTime Processed { get; set; }                [NullEditor]        [EntityRelationship(DeleteAction.Cascade)]        public LeaveRequestLink LeaveRequestLink { get; set; }        [NullEditor]        public DeliveryLink Delivery { get; set; }                [NullEditor]        [EntityRelationship(DeleteAction.SetNull)]        public InvoiceLink Invoice { get; set; }                [NullEditor]        public MeetingDetails Meeting { get; set; }                private class JobScopeLookup : LookupDefinitionGenerator<JobScope, Assignment>        {            public override Filter<JobScope> DefineFilter(Assignment[] items)            {                var item = items?.Length == 1 ? items[0] : null;                if (item != null)                    return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(item.JobLink.ID).And(x => x.Status.Approved).IsEqualTo(true);                return new Filter<JobScope>(x => x.ID).None();            }                        public override Columns<Assignment> DefineFilterColumns()                => Columns.None<Assignment>().Add(x => x.JobLink.ID);        }        [LookupDefinition(typeof(JobScopeLookup))]        public JobScopeLink JobScope { get; set; }                public Expression<Func<Assignment, int>> AutoIncrementField()        {            return x => x.Number;        }        public Filter<Assignment> AutoIncrementFilter()        {            return null;        }                public int AutoIncrementDefault() => 1;                public static TimeSpan EffectiveTime(TimeSpan actual, TimeSpan booked) => actual.Ticks != 0L ? actual : booked;         public TimeSpan EffectiveStartTime()        {            return EffectiveTime(Actual.Start, Booked.Start);        }        public DateTime EffectiveStart()        {            return Date.Add(EffectiveStartTime());        }        public TimeSpan EffectiveFinishTime()        {            // If we have an actual finish, always use that            // otherwise use EffectiveStart() + booked.duration            return EffectiveTime(                    Actual.Finish,                    EffectiveTime(Actual.Start, Booked.Start)                        .Add(Booked.Duration)                );        }        public DateTime EffectiveFinish()        {            return Date.Add(                EffectiveFinishTime()            );        }                static Assignment()        {            LinkedProperties.Register<Assignment, ActivityCharge, bool>(ass => ass.ActivityLink.Charge, chg => chg.Chargeable, ass => ass.Charge.Chargeable);            Classes.JobScope.LinkScopeProperties<Assignment>();        }            }}
 |