Job.cs 7.6 KB

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