Assignment.cs 4.4 KB

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