Assignment.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Linq.Expressions;
  3. using InABox.Core;
  4. namespace Comal.Classes
  5. {
  6. //public class DeliveryAssignments : CoreAggregate<Assignment, Delivery, Guid>
  7. //{
  8. // public override Expression<Func<Delivery, Guid>> Aggregate => Delivery => Delivery.ID;
  9. // //public Expression<Func<Delivery, Guid>> Link => x => x.Assignment.ID;
  10. // public override AggregateCalculation Calculation => AggregateCalculation.Count;
  11. // public override Dictionary<Expression<Func<Delivery, object>>, Expression<Func<Assignment, object>>> Links =>
  12. // new Dictionary<Expression<Func<Delivery, object>>, Expression<Func<Assignment, object>>>
  13. // {
  14. // { Delivery => Delivery.Assignment.ID, x => x.ID }
  15. // };
  16. //}
  17. /// <summary>
  18. /// An assignment represents an anticipated booking for an employee, much like a diary entry
  19. /// <exclude />
  20. /// </summary>
  21. [UserTracking("Assignments")]
  22. [Caption("Assignments")]
  23. public class Assignment : Entity, IPersistent, IRemotable, INumericAutoIncrement<Assignment>, IOneToMany<Employee>, IOneToMany<Job>,
  24. IOneToMany<Kanban>, ILicense<SchedulingControlLicense>, IJobActivity, IOneToMany<Invoice>, IJobScopedItem
  25. {
  26. private bool bChanging;
  27. [IntegerEditor(Editable = Editable.Hidden)]
  28. [EditorSequence(1)]
  29. public int Number { get; set; }
  30. [DateEditor]
  31. [EditorSequence(2)]
  32. public DateTime Date { get; set; }
  33. [EntityRelationship(DeleteAction.Cascade)]
  34. [EditorSequence(3)]
  35. public EmployeeLink EmployeeLink { get; set; }
  36. [TextBoxEditor]
  37. [EditorSequence(4)]
  38. public string Title { get; set; }
  39. [MemoEditor]
  40. [EditorSequence(5)]
  41. public string Description { get; set; }
  42. [EditorSequence(6)]
  43. public AssignmentActivityLink ActivityLink { get; set; }
  44. [EditorSequence(7)]
  45. [EntityRelationship(DeleteAction.SetNull)]
  46. public KanbanLink Task { get; set; }
  47. [EditorSequence(8)]
  48. public JobLink JobLink { get; set; }
  49. [EditorSequence(9)]
  50. public JobITPLink ITP { get; set; }
  51. [NullEditor]
  52. [Obsolete("Replaced with Actual.Start", true)]
  53. public TimeSpan Start { get; set; }
  54. [NullEditor]
  55. [Obsolete("Replaced with Actual.Duration", true)]
  56. public TimeSpan Duration { get; set; }
  57. [NullEditor]
  58. [Obsolete("Replaced with Actual.Finish", true)]
  59. public TimeSpan Finish { get; set; }
  60. [EditorSequence(10)]
  61. [CoreTimeEditor]
  62. public TimeBlock Booked { get; set; }
  63. [EditorSequence(11)]
  64. [CoreTimeEditor]
  65. public TimeBlock Actual { get; set; }
  66. [TimestampEditor]
  67. [EditorSequence(12)]
  68. public DateTime Completed { get; set; }
  69. [EditorSequence("Processing",1)]
  70. public ActualCharge Charge { get; set; }
  71. [TimestampEditor]
  72. [EditorSequence("Processing",2)]
  73. public DateTime Processed { get; set; }
  74. [NullEditor]
  75. [EntityRelationship(DeleteAction.Cascade)]
  76. public LeaveRequestLink LeaveRequestLink { get; set; }
  77. [NullEditor]
  78. public DeliveryLink Delivery { get; set; }
  79. [NullEditor]
  80. [EntityRelationship(DeleteAction.SetNull)]
  81. public InvoiceLink Invoice { get; set; }
  82. [NullEditor]
  83. public MeetingDetails Meeting { get; set; }
  84. public JobScopeLink JobScope { get; set; }
  85. public Expression<Func<Assignment, int>> AutoIncrementField()
  86. {
  87. return x => x.Number;
  88. }
  89. public Filter<Assignment> AutoIncrementFilter()
  90. {
  91. return null;
  92. }
  93. protected override void Init()
  94. {
  95. base.Init();
  96. JobLink = new JobLink();
  97. ITP = new JobITPLink();
  98. EmployeeLink = new EmployeeLink();
  99. LeaveRequestLink = new LeaveRequestLink();
  100. ActivityLink = new AssignmentActivityLink();
  101. Invoice = new InvoiceLink();
  102. Delivery = new DeliveryLink();
  103. Task = new KanbanLink();
  104. Booked = new TimeBlock();
  105. Actual = new TimeBlock();
  106. Charge = new ActualCharge();
  107. Meeting = new MeetingDetails();
  108. JobScope = new JobScopeLink(() => this);
  109. }
  110. public static TimeSpan EffectiveTime(TimeSpan actual, TimeSpan booked) => actual.Ticks != 0L ? actual : booked;
  111. public TimeSpan EffectiveStartTime()
  112. {
  113. return EffectiveTime(Actual.Start, Booked.Start);
  114. }
  115. public DateTime EffectiveStart()
  116. {
  117. return Date.Add(EffectiveStartTime());
  118. }
  119. public TimeSpan EffectiveFinishTime()
  120. {
  121. // If we have an actual finish, always use that
  122. // otherwise use EffectiveStart() + booked.duration
  123. return EffectiveTime(
  124. Actual.Finish,
  125. EffectiveTime(Actual.Start, Booked.Start)
  126. .Add(Booked.Duration)
  127. );
  128. }
  129. public DateTime EffectiveFinish()
  130. {
  131. return Date.Add(
  132. EffectiveFinishTime()
  133. );
  134. }
  135. static Assignment()
  136. {
  137. LinkedProperties.Register<Assignment, ActivityCharge, bool>(ass => ass.ActivityLink.Charge, chg => chg.Chargeable, ass => ass.Charge.Chargeable);
  138. Classes.JobScope.LinkScopeProperties<Assignment>();
  139. }
  140. }
  141. }