| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System;
- using System.Linq;
- using InABox.Core;
- namespace Comal.Classes
- {
- public enum SetoutStatus
- {
- Unapproved,
- Approved,
- Cancelled
- }
- [UserTracking(typeof(ManufacturingPacket))]
- public class Setout : Entity, IPersistent, IRemotable, ILicense<ManufacturingLicense>, IJobScopedItem, IProblems<ManagedProblem>
- {
- [EditorSequence(1)]
- [DateTimeEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
- public override DateTime Created
- {
- get => base.Created;
- set => base.Created = value;
- }
- [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
- [EditorSequence(2)]
- [RequiredColumn]
- public string Number { get; set; }
- [EntityRelationship(DeleteAction.Cascade)]
- [EditorSequence(3)]
- public JobLink JobLink { get; set; }
- [EditorSequence(4)]
- public SetoutGroupLink Group { get; set; }
- [MemoEditor]
- [EditorSequence(5)]
- public string Description { get; set; }
- [EditorSequence(6)]
- public DateTime DueDate { get; set; }
- private class JobStageLookup : LookupDefinitionGenerator<JobStage, Setout>
- {
- public override Filter<JobStage> DefineFilter(Setout[] items)
- {
- if (items.Length == 1)
- return Filter<JobStage>.Where(x => x.Job.ID).IsEqualTo(items.First().JobLink.ID).And(x => x.IsHeader).IsEqualTo(false);
- return Filter<JobStage>.Where(x => x.ID).IsEqualTo(Guid.Empty);
- }
- public override Columns<Setout> DefineFilterColumns()
- => Columns.None<Setout>().Add(x => x.JobLink.ID);
- }
- [LookupDefinition(typeof(JobStageLookup))]
- [EditorSequence(7)]
- public JobStageLink JobStage { get; set; }
- [EditorSequence(8)]
- [Editable(Editable.Disabled)]
- [LoggableProperty]
- public SetoutStatus Status { get; set; }
-
- [EditorSequence("Issues", 1)]
- public ManagedProblem Problem { get; set; }
- private class JobScopeLookup : LookupDefinitionGenerator<JobScope, Setout>
- {
- public override Filter<JobScope> DefineFilter(Setout[] items)
- {
- var item = items?.Length == 1 ? items[0] : null;
- if (item != null)
- return Filter<JobScope>.Where(x => x.Job.ID).IsEqualTo(item.JobLink.ID).And(x => x.Status.Approved).IsEqualTo(true);
- return Filter.None<JobScope>();
- }
-
- public override Columns<Setout> DefineFilterColumns()
- => Columns.None<Setout>().Add(x => x.JobLink.ID);
- }
- [LookupDefinition(typeof(JobScopeLookup))]
- public JobScopeLink JobScope { get; set; }
- #region Aggregates
- private class PacketsAggregate : ComplexFormulaGenerator<Setout, int>
- {
- public override IComplexFormulaNode<Setout, int> GetFormula() =>
- Count<ManufacturingPacket, Guid>(
- x => x.Property(x => x.ID))
- .WithLink(x => x.SetoutLink.ID, x => x.ID);
- }
- [NullEditor]
- [ComplexFormula(typeof(PacketsAggregate))]
- public int Packets { get; set; }
-
- private class UnprocessedPacketsAggregate : ComplexFormulaGenerator<Setout, int>
- {
- public override IComplexFormulaNode<Setout, int> GetFormula() =>
- Count<ManufacturingPacket, Guid>(
- x => x.Property(x => x.ID),
- Filter<ManufacturingPacket>.Where(x => x.Approved).IsEqualTo(DateTime.MinValue))
- .WithLink(x => x.SetoutLink.ID, x => x.ID);
- }
- [NullEditor]
- [ComplexFormula(typeof(UnprocessedPacketsAggregate))]
- public int UnapprovedPackets { get; set; }
- private class FormsAggregate : ComplexFormulaGenerator<Setout, int>
- {
- public override IComplexFormulaNode<Setout, int> GetFormula() =>
- Count<SetoutForm, Guid>(
- x => x.Property(x => x.ID))
- .WithLink(x => x.Parent.ID, x => x.ID);
- }
- [NullEditor]
- [ComplexFormula(typeof(FormsAggregate))]
- public int Forms { get; set; }
-
- private class OpenFormsAggregate : ComplexFormulaGenerator<Setout, int>
- {
- public override IComplexFormulaNode<Setout, int> GetFormula() =>
- Count<SetoutForm, Guid>(
- x => x.Property(x => x.ID),
- Filter<SetoutForm>.Where(x => x.FormCompleted).IsEqualTo(DateTime.MinValue))
- .WithLink(x => x.Parent.ID, x => x.ID);
- }
- [NullEditor]
- [ComplexFormula(typeof(OpenFormsAggregate))]
- public int OpenForms { get; set; }
- #endregion
- #region Obsolete Properties
- [Obsolete("Supreceded by ManufacturingPacket.Serial")]
- [NullEditor]
- public string Reference { get; set; }
- [Obsolete("Superceded by ManufacturingPacket.Location")]
- [NullEditor]
- public string Location { get; set; }
- #endregion
- public override string ToString()
- {
- return string.Format("{0}: {1}", Number, Reference);
- }
- static Setout()
- {
- DefaultColumns.Add<Setout>(x => x.Number);
- DefaultColumns.Add<Setout>(x => x.Description);
- DefaultColumns.Add<Setout>(x => x.DueDate);
- }
- }
- }
|