Browse Source

V6 API Improvements

frogsoftware 10 tháng trước cách đây
mục cha
commit
71e2d756f4

+ 4 - 1
prs.classes/Entities/Activity/Activity.cs

@@ -4,7 +4,7 @@ using InABox.Core;
 namespace Comal.Classes
 {
     [UserTracking(typeof(User))]
-    public class Activity : Entity, IPersistent, IRemotable, ILicense<CoreLicense>, IExportable, IImportable, IMergeable
+    public class Activity : Entity, IPersistent, IRemotable, ILicense<CoreLicense>, IExportable, IImportable, IMergeable, IIssues
     {
         [EditorSequence(1)]
         [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
@@ -42,5 +42,8 @@ namespace Comal.Classes
         {
             return string.Format("{0}: {1}", Code, Description);
         }
+
+        [NullEditor]
+        public string Issues { get; set; }
     }
 }

+ 6 - 0
prs.classes/Entities/Job/InternalJobLink.cs

@@ -9,7 +9,13 @@ namespace Comal.Classes
         [NullEditor]
         public override Guid ID { get; set; }
         
+        [NullEditor]
+        public string JobNumber { get; set; }
+        
         [NullEditor]
         public InternalJobScopeLink DefaultScope { get; set; }
+        
+        [NullEditor]
+        public string SourceRef { get; set; }
     }
 }

+ 4 - 0
prs.classes/Entities/Job/Job.cs

@@ -85,6 +85,10 @@ namespace Comal.Classes
         [EditorSequence("Other", 3)]
         [TimestampEditor]
         public DateTime DataEntered { get; set; }
+        
+        [EditorSequence("Other", 4)]
+        [TextBoxEditor]
+        public string SourceRef { get; set; } 
 
         #endregion
 

+ 12 - 1
prs.classes/Entities/Job/JobBillOfMaterialsItem.cs

@@ -8,7 +8,7 @@ using PRSClasses;
 namespace Comal.Classes
 {
     public class JobBillOfMaterialsItem : StockEntity, IRemotable, IPersistent, IOneToMany<Job>, 
-        IOneToMany<JobBillOfMaterials>, ISequenceable, ILicense<ProjectManagementLicense>, IJobMaterial
+        IOneToMany<JobBillOfMaterials>, ISequenceable, ILicense<ProjectManagementLicense>, IJobMaterial, IIssues
     {
         [EntityRelationship(DeleteAction.Cascade)]
         [Editable(Editable.Hidden)]
@@ -36,6 +36,10 @@ namespace Comal.Classes
         [DimensionsEditor(typeof(StockDimensions))]
         public override StockDimensions Dimensions { get; set; }
         
+        [EditorSequence(4)]
+        [RequiredColumn]
+        public JobScopeLink Scope { get; set; }
+        
         [EditorSequence(4)]
         [DoubleEditor(Summary = Summary.Sum)]
         public double Quantity { get; set; }
@@ -77,6 +81,9 @@ namespace Comal.Classes
         public PurchaseOrderItemLink PurchaseOrderItem { get; set; }
 
         public ManufacturingPacketLink Packet { get; set; }
+        
+        [NullEditor]
+        public string Issues { get; set; }
 
         static JobBillOfMaterialsItem()
         {
@@ -86,6 +93,8 @@ namespace Comal.Classes
             
             LinkedProperties.Register<JobBillOfMaterialsItem, ProductInstanceLink, double>(x => x.Product.DefaultInstance, x => x.NettCost, x => x.UnitCost);
 
+            LinkedProperties.Register<JobBillOfMaterialsItem, JobLink, Guid>(x => x.Job, x => x.DefaultScope.ID, x => x.Scope.ID);
+            
             StockEntity.LinkStockDimensions<JobBillOfMaterialsItem>();
         }
         
@@ -197,6 +206,8 @@ namespace Comal.Classes
 
             }
         }
+
+
     }
     
 }

+ 3 - 0
prs.classes/Entities/Job/JobScopes/InternalJobScopeLink.cs

@@ -7,5 +7,8 @@ namespace Comal.Classes
     {
         [NullEditor]
         public override Guid ID { get; set; }
+        
+        [NullEditor]
+        public string SourceRef { get; set; }
     }
 }

+ 4 - 0
prs.classes/Entities/Job/JobScopes/JobScope.cs

@@ -80,6 +80,10 @@ namespace Comal.Classes
         [EditorSequence(3)]
         public string Description { get; set; }
         
+        [EditorSequence(4)]
+        [TextBoxEditor]
+        public string SourceRef{ get; set; } 
+        
         private class JobScopeLookup : LookupDefinitionGenerator<JobScope, JobScope>
         {
             public override Filter<JobScope> DefineFilter(JobScope[] items)

+ 94 - 1
prs.desktop/Setups/SystemSetupActions.cs

@@ -1,4 +1,7 @@
+using System;
+using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using Comal.Classes;
 using InABox.Clients;
 using InABox.Core;
@@ -7,8 +10,97 @@ using InABox.Wpf;
 
 namespace PRSDesktop;
 
+
 public static class SystemSetupActions
 {
+
+
+    private class V6SettingsGrid : DynamicItemsListGrid<V6Settings>
+    {
+
+        private void Validate<T>(string sql, List<string> errors) where T : V6Object, new()
+        {
+            var t = new T();
+            List<string> _e = new();
+            t.ValidateQuery(sql,_e);
+            if (_e.Any())
+            {
+                errors.Add($"The query for {typeof(T).Name} has some errors:");
+                errors.AddRange(_e);
+            }
+        }
+        
+        private static void ValidateUom(V6Settings settings, string uomcode, List<string> errors, IEnumerable<ProductDimensionUnit> uoms, params string[] checks)
+        {
+            var _uomvalue = CoreUtils.GetPropertyValue(settings, uomcode) as string;
+            if (string.IsNullOrWhiteSpace(_uomvalue))
+            {
+                errors.Add($"{uomcode.SplitCamelCase()} may not be blank!");
+                return;
+            }
+
+            var _uom = uoms.FirstOrDefault(x => string.Equals(x.Code, _uomvalue));
+            if (_uom == null)
+            {
+                errors.Add($"{uomcode.SplitCamelCase()}: {_uomvalue} is not a value Unit of Measure!");
+                return;
+            }
+
+            List<string> _missing = new();
+            foreach (var _check in checks)
+            {
+                var _enabled = (bool)(CoreUtils.GetPropertyValue(_uom, _check) ?? false);
+                if (!_enabled)
+                    _missing.Add(_check);
+            }
+            if (_missing.Any())
+                errors.Add($"{_uomvalue} is missing the following checks: {string.Join(", ",_missing)}");
+                
+        }
+        
+        protected override void DoValidate(V6Settings[] items, List<string> errors)
+        {
+            base.DoValidate(items, errors);
+
+            var _item = items.FirstOrDefault();
+            if (_item == null)
+                return;
+            
+            var _uoms = Client.Query(new Filter<ProductDimensionUnit>().All(), Columns.All<ProductDimensionUnit>()).ToObjects<ProductDimensionUnit>().ToArray();
+            if (_item.ImportCosts != V6ImportCosts.None)
+            {
+                ValidateUom(_item, nameof(V6Settings.ProfileUom), errors, _uoms, nameof(ProductDimensionUnit.HasLength));
+                ValidateUom(_item, nameof(V6Settings.ComponentUom), errors, _uoms, nameof(ProductDimensionUnit.HasQuantity));
+                ValidateUom(_item, nameof(V6Settings.GlassUom), errors, _uoms, nameof(ProductDimensionUnit.HasHeight), nameof(ProductDimensionUnit.HasWidth));
+            }
+
+            if (_item.ImportDesigns == V6ImportDesigns.ToManufacturing)
+            {
+                if (String.IsNullOrWhiteSpace(_item.PacketTemplate))
+                    errors.Add("Packet Template my not be blank!");
+                else
+                {
+                    var _found = Client
+                        .Query(new Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo(_item.PacketTemplate),
+                            Columns.None<ManufacturingTemplate>()).Rows.Any();
+                    if (!_found)
+                        errors.Add($"Packet Template [{_item.PacketTemplate}] does not exist!");
+                }
+            }
+
+            _item.CheckSQL();
+            Validate<V6Quote>(_item.QuoteSQL, errors);
+            Validate<V6Elevation>(_item.ElevationSQL, errors);
+            Validate<V6Drawings>(_item.DrawingsSQL, errors);
+            Validate<V6Profile>(_item.ProfileSQL, errors);
+            Validate<V6Component>(_item.ComponentSQL, errors);
+            Validate<V6Labour>(_item.LabourSQL, errors);
+            Validate<V6Glass>(_item.GlassSQL, errors);
+        }
+
+
+    }
+    
     public static void ERPStatuses(IPanelHost host)
     {
         host.CreateSetupActionIfCanView<LogikalSettings>("Logikal Settings", PRSDesktop.Resources.logikal, (action) =>
@@ -34,7 +126,8 @@ public static class SystemSetupActions
                 ).Rows
                 .FirstOrDefault()?
                 .ToObject<V6Settings>() ?? new V6Settings();
-            var grid = new DynamicItemsListGrid<V6Settings>();
+            v6.CheckSQL();
+            var grid = new V6SettingsGrid();
             if (grid.EditItems(new V6Settings[] { v6 }))
             {
                 Client.Save(v6, "Updated Settings");