Browse Source

PRS CLASSES - Setout / Manufacturing Packet grouping

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
91ae060df5

+ 4 - 0
prs.classes/Entities/Manufacturing/ManufacturingPacket/ManufacturingPacket.cs

@@ -173,6 +173,8 @@ namespace Comal.Classes
         [LoggableProperty]
         public string Issues { get; set; }
 
+        public SetoutGroupLink SetoutGroup { get; set; }
+
         protected override void Init()
         {
             base.Init();
@@ -197,6 +199,8 @@ namespace Comal.Classes
             OrderItem = new PurchaseOrderItemLink();
 
             ITP = new JobITPLink();
+
+            SetoutGroup = new SetoutGroupLink();
         }
 
         public override string ToString()

+ 3 - 0
prs.classes/Entities/Setout/Setout.cs

@@ -31,10 +31,13 @@ namespace Comal.Classes
 
         public JobStageLink JobStage { get; set; }
 
+        public SetoutGroupLink Group { get; set; }
+
         protected override void Init()
         {
             base.Init();
             JobLink = new JobLink();
+            Group = new SetoutGroupLink();
             //Items = new PackableList<FactoryTemplateItem>();
             //Manufacturing = new PackableList<ManufacturingItem>();
             JobStage = new JobStageLink();

+ 27 - 0
prs.classes/Entities/Setout/SetoutGroup.cs

@@ -0,0 +1,27 @@
+using Comal.Classes.Entities;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class SetoutGroup : Entity, IPersistent, IRemotable, ILicense<ManufacturingLicense>
+    {
+        [TextBoxEditor(Editable = Editable.Enabled)]
+        public string Name { get; set; }
+
+        public JobLink Job { get; set; }
+
+        [Caption("Optimization Document")]
+        public DocumentLink OptimizationDocument { get; set; }
+
+        protected override void Init()
+        {
+            Name = "";
+            Job = new JobLink();
+            OptimizationDocument = new DocumentLink();
+            base.Init();
+        }
+    }
+}

+ 24 - 0
prs.classes/Entities/Setout/SetoutGroupLink.cs

@@ -0,0 +1,24 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class SetoutGroupLink : EntityLink<SetoutGroup>
+    {
+        [LookupEditor(typeof(SetoutGroup))]
+        public override Guid ID { get; set; }
+
+        public string Name { get; set; }
+
+        public DocumentLink OptimizationDocument { get; set; }
+
+        protected override void Init()
+        {
+            Name = "";
+            OptimizationDocument = new DocumentLink();
+            base.Init();
+        }
+    }
+}

+ 4 - 0
prs.classes/Entities/Staging/Setout/StagingSetout.cs

@@ -21,12 +21,16 @@ namespace Comal.Classes
         [NullEditor]
         public KanbanLink Task { get; set; }
 
+        public SetoutGroupLink Group { get; set; }
+
+    
         protected override void Init()
         {
             Number = "";
             JobLink = new JobLink();
             Setout = new SetoutLink();
             Task = new KanbanLink();
+            Group = new SetoutGroupLink();
             base.Init();
         }
     }

+ 5 - 0
prs.classes/SecurityDescriptors/Project_Descriptors.cs

@@ -57,4 +57,9 @@ namespace Comal.Classes
     {
     }
 
+    [Caption("Can approve setouts with no group")]
+    public class CanApproveSetoutsWithoutGroup : DisabledSecurityDescriptor<ProjectManagementLicense, Setout>
+    { 
+    }
+
 }

+ 29 - 0
prs.stores/SetoutStore.cs

@@ -1,4 +1,8 @@
 using Comal.Classes;
+using System;
+using InABox.Core;
+using System.Collections.Generic;
+using System.Linq;
 
 namespace Comal.Stores
 {
@@ -6,6 +10,31 @@ namespace Comal.Stores
     {
         protected override void AfterSave(Setout entity)
         {
+            if (entity.Group.ID != Guid.Empty)
+            {
+                var table = Provider.Query<SetoutGroup>(new Filter<SetoutGroup>(x => x.ID).IsEqualTo(entity.Group.ID),
+                    new Columns<SetoutGroup>(x => x.OptimizationDocument.ID));
+                if (table.Rows.Any())
+                {
+                    var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
+                    List<Guid> ids = new List<Guid>();
+                    var docsTable = Provider.Query<SetoutDocument>(
+                        new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(entity.ID),
+                        new Columns<SetoutDocument>(x => x.DocumentLink.ID)
+                        );
+                    foreach (var row in docsTable.Rows)
+                        ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
+
+                    if (!ids.Contains(docID))
+                    {
+                        var setoutdoc = new SetoutDocument();
+                        setoutdoc.EntityLink.ID = entity.ID;
+                        setoutdoc.DocumentLink.ID = docID;
+
+                        FindSubStore<SetoutDocument>().Save(setoutdoc, "Added optimsation document from Group");
+                    }
+                }
+            }
             base.AfterSave(entity);
         }