Job.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using System.ComponentModel;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public interface IJob : IEntity
  8. {
  9. }
  10. [UserTracking("Project Management")]
  11. public class Job : Entity, IJob, IPersistent, IRemotable, IScheduleAction, IOneToMany<Schedule>, IStringAutoIncrement<Job>,
  12. ILicense<ProjectManagementLicense>, IExportable, IImportable, IMergeable, IDataEntryInstance
  13. {
  14. public const string NotesPage = "Notes";
  15. #region General
  16. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  17. [EditorSequence(0)]
  18. public string JobNumber { get; set; }
  19. //[Obsolete("Replaced by JobNumber", true)]
  20. //[IntegerEditor(Editable = Editable.Hidden)]
  21. //public int Number { get; set; }
  22. [TextBoxEditor]
  23. [EditorSequence(1)]
  24. public string Name { get; set; }
  25. [EditorSequence(2)]
  26. [DateEditor]
  27. public DateTime Date { get; set; }
  28. [SecondaryIndex]
  29. [EnumLookupEditor(typeof(JobType))]
  30. [EditorSequence(3)]
  31. public JobType JobType { get; set; } = JobType.Project;
  32. [EditorSequence(4)]
  33. public CustomerLink Customer { get; set; }
  34. [EditorSequence(5)]
  35. public Address SiteAddress { get; set; }
  36. [EditorSequence(6)]
  37. public ContactLink Contact { get; set; }
  38. [EditorSequence(7)]
  39. [Caption("Bill To")]
  40. public AccountLink Account { get; set; }
  41. [EditorSequence(8)]
  42. [TextBoxEditor]
  43. public String ClientReference { get; set; }
  44. [EditorSequence(9)]
  45. public JobStatusLink JobStatus { get; set; }
  46. #endregion
  47. [NotesEditor]
  48. [EditorSequence(NotesPage, 1)]
  49. public string[] Notes { get; set; } = Array.Empty<string>();
  50. #region Other
  51. [TextBoxEditor]
  52. [EditorSequence("Other", 1)]
  53. public string URL { get; set; }
  54. [ColorEditor]
  55. [EditorSequence("Other", 2)]
  56. public string Color { get; set; }
  57. [EditorSequence("Other", 3)]
  58. [TimestampEditor]
  59. public DateTime DataEntered { get; set; }
  60. #endregion
  61. #region Project Management
  62. [Caption("Project Lead")]
  63. [EditorSequence("Project Management", 1)]
  64. public EmployeeLink ProjectLead { get; set; }
  65. [Caption("Drafting Lead")]
  66. [EditorSequence("Project Management", 2)]
  67. public EmployeeLink DraftingLead { get; set; }
  68. [Caption("Site Lead")]
  69. [EditorSequence("Project Management", 3)]
  70. public EmployeeLink SiteLead { get; set; }
  71. [TextBoxEditor]
  72. [EditorSequence("Project Management", 4)]
  73. public string SetoutsFolder { get; set; }
  74. [TimeOfDayEditor]
  75. [EditorSequence("Project Management", 5)]
  76. public TimeSpan UsualStart { get; set; }
  77. [TimeOfDayEditor]
  78. [EditorSequence("Project Management", 5)]
  79. public TimeSpan UsualFinish { get; set; }
  80. // This is the Activity to which the Usual Start/Finish Applies
  81. // Other activitiy timesheets are not affected by this
  82. [EditorSequence("Project Management", 6)]
  83. public ActivityLink UsualActivity { get; set; }
  84. [EditorSequence("Project Management", 7)]
  85. public DateTime ExpectedCompletionDate { get; set; }
  86. [EditorSequence("Project Management", 8)]
  87. public DateTime Completed { get; set; }
  88. private class JobScopeLookup : LookupDefinitionGenerator<JobScope, Job>
  89. {
  90. public override Filter<JobScope> DefineFilter(Job[] items)
  91. {
  92. var item = items?.Length == 1 ? items[0] : null;
  93. if (item != null)
  94. return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(item.ID).And(x => x.Status.Approved).IsEqualTo(true);
  95. return new Filter<JobScope>(x => x.ID).None();
  96. }
  97. public override Columns<Job> DefineFilterColumns()
  98. => Columns.None<Job>().Add(x=>x.ID);
  99. }
  100. [LookupDefinition(typeof(JobScopeLookup))]
  101. [EditorSequence("Project Management", 10)]
  102. public JobScopeLink DefaultScope { get; set; }
  103. #endregion
  104. [TimeOfDayEditor(Editable = Editable.Hidden)]
  105. public TimeSpan LabourHours { get; set; }
  106. [NullEditor]
  107. [Obsolete("Why does this even exist?")]
  108. public ProductStyleLink Style { get; set; }
  109. [NullEditor]
  110. [Aggregate(typeof(JobAssignmentCount))]
  111. public int Assignments { get; set; }
  112. [NullEditor]
  113. [Aggregate(typeof(JobOpenAssignmentCount))]
  114. public int OpenAssignments { get; set; }
  115. [NullEditor]
  116. public ScheduleLink ScheduleLink { get; set; }
  117. [DoNotPersist]
  118. [DoNotSerialize]
  119. public static String JobNumberPrefix { get; set; }
  120. public Expression<Func<Job, string>> AutoIncrementField() => x => x.JobNumber;
  121. public Filter<Job>? AutoIncrementFilter() => null;
  122. public String AutoIncrementPrefix() => JobNumberPrefix;
  123. public string AutoIncrementFormat() => "{0:D4}";
  124. [NullEditor]
  125. [Obsolete("Replaced with ProjectLead", true)]
  126. public EmployeeLink ManagerLink { get; set; }
  127. [NullEditor]
  128. [Obsolete("Replaced with SiteLead", true)]
  129. public EmployeeLink EmployeeLink { get; set; }
  130. protected override void Init()
  131. {
  132. base.Init();
  133. Customer.Account.PropertyChanged += Account_PropertyChanged;
  134. Customer.Delivery.PropertyChanged += Delivery_PropertyChanged;
  135. }
  136. private void Delivery_PropertyChanged(object sender, PropertyChangedEventArgs e)
  137. {
  138. var value = CoreUtils.GetPropertyValue(Customer.Delivery, e.PropertyName);
  139. CoreUtils.SetPropertyValue(SiteAddress, e.PropertyName, value);
  140. }
  141. private void Account_PropertyChanged(object sender, PropertyChangedEventArgs e)
  142. {
  143. if (e.PropertyName.Equals("ID"))
  144. Account.ID = Customer.Account.ID;
  145. else if (e.PropertyName.Equals("Code"))
  146. Account.Code = Customer.Account.Code;
  147. else if (e.PropertyName.Equals("Name"))
  148. Account.Name = Customer.Account.Name;
  149. }
  150. public override string ToString()
  151. {
  152. return string.Format("{0}: {1}", JobNumber, Name);
  153. }
  154. static Job()
  155. {
  156. LinkedProperties.Register<Job, ContactLink, Guid>(x => x.Customer.DefaultContact, x => x.ID, x => x.Contact.ID);
  157. LinkedProperties.Register<Job,Address,String>(x=>x.Customer.Delivery, x=>x.Street, x=>x.SiteAddress.Street);
  158. LinkedProperties.Register<Job,Address,String>(x=>x.Customer.Delivery, x=>x.City, x=>x.SiteAddress.City);
  159. LinkedProperties.Register<Job,Address,String>(x=>x.Customer.Delivery, x=>x.PostCode, x=>x.SiteAddress.PostCode);
  160. LinkedProperties.Register<Job,Address,String>(x=>x.Customer.Delivery, x=>x.State, x=>x.SiteAddress.State);
  161. LinkedProperties.Register<Job,Address,String>(x=>x.Customer.Delivery, x=>x.Location.Address, x=>x.SiteAddress.Location.Address);
  162. LinkedProperties.Register<Job,Address,double>(x=>x.Customer.Delivery, x=>x.Location.Latitude, x=>x.SiteAddress.Location.Latitude);
  163. LinkedProperties.Register<Job,Address,double>(x=>x.Customer.Delivery, x=>x.Location.Longitude, x=>x.SiteAddress.Location.Longitude);
  164. LinkedProperties.Register<Job,Address,DateTime>(x=>x.Customer.Delivery, x=>x.Location.Timestamp, x=>x.SiteAddress.Location.Timestamp);
  165. }
  166. }
  167. }