123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using System.Linq.Expressions;
- using InABox.Core;
- namespace Comal.Classes
- {
- //public class DeliveryAssignments : CoreAggregate<Assignment, Delivery, Guid>
- //{
- // public override Expression<Func<Delivery, Guid>> Aggregate => Delivery => Delivery.ID;
- // //public Expression<Func<Delivery, Guid>> Link => x => x.Assignment.ID;
- // public override AggregateCalculation Calculation => AggregateCalculation.Count;
- // public override Dictionary<Expression<Func<Delivery, object>>, Expression<Func<Assignment, object>>> Links =>
- // new Dictionary<Expression<Func<Delivery, object>>, Expression<Func<Assignment, object>>>
- // {
- // { Delivery => Delivery.Assignment.ID, x => x.ID }
- // };
- //}
- /// <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
- {
- private bool bChanging;
- [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; }
- [TextBoxEditor]
- [EditorSequence(4)]
- public string Title { get; set; }
- [MemoEditor]
- [EditorSequence(5)]
- public string Description { get; set; }
- [EditorSequence(6)]
- public AssignmentActivityLink ActivityLink { get; set; }
- [EditorSequence(7)]
- [EntityRelationship(DeleteAction.SetNull)]
- public KanbanLink Task { get; set; }
- [EditorSequence(8)]
- public JobLink JobLink { get; set; }
- [EditorSequence(9)]
- 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(10)]
- [CoreTimeEditor]
- public TimeBlock Booked { get; set; }
- [EditorSequence(11)]
- [CoreTimeEditor]
- public TimeBlock Actual { get; set; }
-
- [TimestampEditor]
- [RequiredColumn]
- [EditorSequence(12)]
- 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; }
-
- public JobScopeLink JobScope { get; set; }
-
- public Expression<Func<Assignment, int>> AutoIncrementField()
- {
- return x => x.Number;
- }
- public Filter<Assignment> AutoIncrementFilter()
- {
- return null;
- }
-
- protected override void Init()
- {
- base.Init();
- JobLink = new JobLink();
- ITP = new JobITPLink();
- EmployeeLink = new EmployeeLink();
- LeaveRequestLink = new LeaveRequestLink();
- ActivityLink = new AssignmentActivityLink();
- Invoice = new InvoiceLink();
- Delivery = new DeliveryLink();
- Task = new KanbanLink();
- Booked = new TimeBlock();
- Actual = new TimeBlock();
- Charge = new ActualCharge();
- Meeting = new MeetingDetails();
- JobScope = new JobScopeLink(() => this);
- }
-
- 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>();
- }
-
- }
- }
|