Assignment.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. [RequiredColumn]
  68. [EditorSequence(12)]
  69. public DateTime Completed { get; set; }
  70. [EditorSequence("Processing",1)]
  71. public ActualCharge Charge { get; set; }
  72. [TimestampEditor]
  73. [EditorSequence("Processing",2)]
  74. public DateTime Processed { get; set; }
  75. [NullEditor]
  76. [EntityRelationship(DeleteAction.Cascade)]
  77. public LeaveRequestLink LeaveRequestLink { get; set; }
  78. [NullEditor]
  79. public DeliveryLink Delivery { get; set; }
  80. [NullEditor]
  81. [EntityRelationship(DeleteAction.SetNull)]
  82. public InvoiceLink Invoice { get; set; }
  83. [NullEditor]
  84. public MeetingDetails Meeting { get; set; }
  85. public JobScopeLink JobScope { get; set; }
  86. public Expression<Func<Assignment, int>> AutoIncrementField()
  87. {
  88. return x => x.Number;
  89. }
  90. public Filter<Assignment> AutoIncrementFilter()
  91. {
  92. return null;
  93. }
  94. protected override void Init()
  95. {
  96. base.Init();
  97. JobLink = new JobLink();
  98. ITP = new JobITPLink();
  99. EmployeeLink = new EmployeeLink();
  100. LeaveRequestLink = new LeaveRequestLink();
  101. ActivityLink = new AssignmentActivityLink();
  102. Invoice = new InvoiceLink();
  103. Delivery = new DeliveryLink();
  104. Task = new KanbanLink();
  105. Booked = new TimeBlock();
  106. Actual = new TimeBlock();
  107. Charge = new ActualCharge();
  108. Meeting = new MeetingDetails();
  109. JobScope = new JobScopeLink(() => this);
  110. }
  111. public static TimeSpan EffectiveTime(TimeSpan actual, TimeSpan booked) => actual.Ticks != 0L ? actual : booked;
  112. public TimeSpan EffectiveStartTime()
  113. {
  114. return EffectiveTime(Actual.Start, Booked.Start);
  115. }
  116. public DateTime EffectiveStart()
  117. {
  118. return Date.Add(EffectiveStartTime());
  119. }
  120. public TimeSpan EffectiveFinishTime()
  121. {
  122. // If we have an actual finish, always use that
  123. // otherwise use EffectiveStart() + booked.duration
  124. return EffectiveTime(
  125. Actual.Finish,
  126. EffectiveTime(Actual.Start, Booked.Start)
  127. .Add(Booked.Duration)
  128. );
  129. }
  130. public DateTime EffectiveFinish()
  131. {
  132. return Date.Add(
  133. EffectiveFinishTime()
  134. );
  135. }
  136. static Assignment()
  137. {
  138. LinkedProperties.Register<Assignment, ActivityCharge, bool>(ass => ass.ActivityLink.Charge, chg => chg.Chargeable, ass => ass.Charge.Chargeable);
  139. Classes.JobScope.LinkScopeProperties<Assignment>();
  140. }
  141. }
  142. }