Setout.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Linq;
  3. using InABox.Core;
  4. namespace Comal.Classes
  5. {
  6. public enum SetoutStatus
  7. {
  8. Unapproved,
  9. Approved,
  10. Cancelled
  11. }
  12. [UserTracking(typeof(ManufacturingPacket))]
  13. public class Setout : Entity, IPersistent, IRemotable, ILicense<ManufacturingLicense>, IJobScopedItem, IProblems<ManagedProblem>
  14. {
  15. [EditorSequence(1)]
  16. [DateTimeEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
  17. public override DateTime Created
  18. {
  19. get => base.Created;
  20. set => base.Created = value;
  21. }
  22. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  23. [EditorSequence(2)]
  24. [RequiredColumn]
  25. public string Number { get; set; }
  26. [EntityRelationship(DeleteAction.Cascade)]
  27. [EditorSequence(3)]
  28. public JobLink JobLink { get; set; }
  29. [EditorSequence(4)]
  30. public SetoutGroupLink Group { get; set; }
  31. [MemoEditor]
  32. [EditorSequence(5)]
  33. public string Description { get; set; }
  34. [EditorSequence(6)]
  35. public DateTime DueDate { get; set; }
  36. private class JobStageLookup : LookupDefinitionGenerator<JobStage, Setout>
  37. {
  38. public override Filter<JobStage> DefineFilter(Setout[] items)
  39. {
  40. if (items.Length == 1)
  41. return Filter<JobStage>.Where(x => x.Job.ID).IsEqualTo(items.First().JobLink.ID).And(x => x.IsHeader).IsEqualTo(false);
  42. return Filter<JobStage>.Where(x => x.ID).IsEqualTo(Guid.Empty);
  43. }
  44. public override Columns<Setout> DefineFilterColumns()
  45. => Columns.None<Setout>().Add(x => x.JobLink.ID);
  46. }
  47. [LookupDefinition(typeof(JobStageLookup))]
  48. [EditorSequence(7)]
  49. public JobStageLink JobStage { get; set; }
  50. [EditorSequence(8)]
  51. [Editable(Editable.Disabled)]
  52. [LoggableProperty]
  53. public SetoutStatus Status { get; set; }
  54. [EditorSequence("Issues", 1)]
  55. public ManagedProblem Problem { get; set; }
  56. private class JobScopeLookup : LookupDefinitionGenerator<JobScope, Setout>
  57. {
  58. public override Filter<JobScope> DefineFilter(Setout[] items)
  59. {
  60. var item = items?.Length == 1 ? items[0] : null;
  61. if (item != null)
  62. return Filter<JobScope>.Where(x => x.Job.ID).IsEqualTo(item.JobLink.ID).And(x => x.Status.Approved).IsEqualTo(true);
  63. return Filter.None<JobScope>();
  64. }
  65. public override Columns<Setout> DefineFilterColumns()
  66. => Columns.None<Setout>().Add(x => x.JobLink.ID);
  67. }
  68. [LookupDefinition(typeof(JobScopeLookup))]
  69. public JobScopeLink JobScope { get; set; }
  70. #region Aggregates
  71. private class PacketsAggregate : ComplexFormulaGenerator<Setout, int>
  72. {
  73. public override IComplexFormulaNode<Setout, int> GetFormula() =>
  74. Count<ManufacturingPacket, Guid>(
  75. x => x.Property(x => x.ID))
  76. .WithLink(x => x.SetoutLink.ID, x => x.ID);
  77. }
  78. [NullEditor]
  79. [ComplexFormula(typeof(PacketsAggregate))]
  80. public int Packets { get; set; }
  81. private class UnprocessedPacketsAggregate : ComplexFormulaGenerator<Setout, int>
  82. {
  83. public override IComplexFormulaNode<Setout, int> GetFormula() =>
  84. Count<ManufacturingPacket, Guid>(
  85. x => x.Property(x => x.ID),
  86. Filter<ManufacturingPacket>.Where(x => x.Approved).IsEqualTo(DateTime.MinValue))
  87. .WithLink(x => x.SetoutLink.ID, x => x.ID);
  88. }
  89. [NullEditor]
  90. [ComplexFormula(typeof(UnprocessedPacketsAggregate))]
  91. public int UnapprovedPackets { get; set; }
  92. private class FormsAggregate : ComplexFormulaGenerator<Setout, int>
  93. {
  94. public override IComplexFormulaNode<Setout, int> GetFormula() =>
  95. Count<SetoutForm, Guid>(
  96. x => x.Property(x => x.ID))
  97. .WithLink(x => x.Parent.ID, x => x.ID);
  98. }
  99. [NullEditor]
  100. [ComplexFormula(typeof(FormsAggregate))]
  101. public int Forms { get; set; }
  102. private class OpenFormsAggregate : ComplexFormulaGenerator<Setout, int>
  103. {
  104. public override IComplexFormulaNode<Setout, int> GetFormula() =>
  105. Count<SetoutForm, Guid>(
  106. x => x.Property(x => x.ID),
  107. Filter<SetoutForm>.Where(x => x.FormCompleted).IsEqualTo(DateTime.MinValue))
  108. .WithLink(x => x.Parent.ID, x => x.ID);
  109. }
  110. [NullEditor]
  111. [ComplexFormula(typeof(OpenFormsAggregate))]
  112. public int OpenForms { get; set; }
  113. #endregion
  114. #region Obsolete Properties
  115. [Obsolete("Supreceded by ManufacturingPacket.Serial")]
  116. [NullEditor]
  117. public string Reference { get; set; }
  118. [Obsolete("Superceded by ManufacturingPacket.Location")]
  119. [NullEditor]
  120. public string Location { get; set; }
  121. #endregion
  122. public override string ToString()
  123. {
  124. return string.Format("{0}: {1}", Number, Reference);
  125. }
  126. static Setout()
  127. {
  128. DefaultColumns.Add<Setout>(x => x.Number);
  129. DefaultColumns.Add<Setout>(x => x.Description);
  130. DefaultColumns.Add<Setout>(x => x.DueDate);
  131. }
  132. }
  133. }