Job.cs 7.7 KB

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