Browse Source

More improvements to V6

frogsoftware 1 year ago
parent
commit
337c06fb3b

+ 5 - 1
prs.classes/Entities/Product/Attribute/ProductStyle.cs

@@ -5,7 +5,7 @@ using System.Linq;
 namespace Comal.Classes
 {
     [UserTracking(typeof(Product))]
-    public class ProductStyle : Entity, IRemotable, IPersistent, IProductStyle, ILicense<ProductManagementLicense>, IMergeable
+    public class ProductStyle : Entity, IRemotable, IPersistent, IProductStyle, ILicense<ProductManagementLicense>, IMergeable, IIssues
     {
         [EditorSequence(1)]
         [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
@@ -29,6 +29,9 @@ namespace Comal.Classes
         [LookupDefinition(typeof(TreatmentTypeLookup))]
         [EditorSequence(4)]
         public TreatmentTypeLink TreatmentType { get; set; }
+        
+        [NullEditor]
+        public string Issues { get; set; }
 
         private class TreatmentProductLookup : LookupDefinitionGenerator<Product, ProductStyle>
         {
@@ -57,5 +60,6 @@ namespace Comal.Classes
         public ProductLink StockTreatmentProduct { get; set; }
 
         public override string ToString() => $"{Code}: {Description}";
+
     }
 }

+ 13 - 5
prs.classes/Entities/V6/V6Settings.cs

@@ -24,7 +24,6 @@ namespace Comal.Classes
         [EditorSequence(4)]
         public string Password { get; set; }
         
-                    
         [EnumLookupEditor(typeof(V6ImportDesigns))]
         [EditorSequence(5)]
         public V6ImportDesigns ImportDesigns { get; set; }
@@ -33,6 +32,14 @@ namespace Comal.Classes
         [EditorSequence(6)]
         public V6ImportCosts ImportCosts { get; set; }
         
+        [EditorSequence(7)]
+        [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)]
+        public string JobStatus { get; set; }
+        
+        [EditorSequence(8)]
+        [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)]
+        public string TaxCode { get; set; }
+        
         // private abstract class AbstractUomLookupGenerator : LookupGenerator<object>
         // {
         //
@@ -62,7 +69,8 @@ namespace Comal.Classes
         // }
             
         //[ComboLookupEditor(typeof(ProfileUomLookupGenerator))]
-        [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)][EditorSequence(7)]
+        [EditorSequence(9)]
+        [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)]
         public String ProfileUom { get; set; }
         
         // private class ComponentUomLookupGenerator : AbstractUomLookupGenerator
@@ -76,7 +84,7 @@ namespace Comal.Classes
             
         //[ComboLookupEditor(typeof(ComponentLookupGenerator))]
         [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)]
-        [EditorSequence(8)]
+        [EditorSequence(10)]
         public String ComponentUom { get; set; }
         
         // private class GlassUomLookupGenerator : AbstractUomLookupGenerator
@@ -90,12 +98,12 @@ namespace Comal.Classes
         
         //[ComboLookupEditor(typeof(GlassUomLookupGenerator))]
         [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)]
-        [EditorSequence(9)]
+        [EditorSequence(11)]
         public String GlassUom { get; set; }
         
         //[ComboLookupEditor(typeof(GlassUomLookupGenerator))]
         [CodeEditor(Visible=Visible.Default, Editable=Editable.Enabled)]
-        [EditorSequence(10)]
+        [EditorSequence(12)]
         public String PacketTemplate { get; set; }
         
         [MemoEditor]

+ 141 - 24
prs.desktop/Panels/Jobs/V6ProjectImport.xaml.cs

@@ -11,6 +11,7 @@ using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.Wpf;
 using InABox.WPF;
+using NPOI.OpenXmlFormats.Wordprocessing;
 
 namespace PRSDesktop;
 
@@ -95,6 +96,9 @@ public partial class V6ProjectImport : Window
         var _importCosts = (V6ImportCosts)ImportCosts.SelectedValue;
         var _importDesigns = (V6ImportDesigns)ImportDesigns.SelectedValue;
 
+        JobStatus? _statusCode = new();
+        TaxCode? _taxCode = new();
+        
         ProductDimensionUnit? _profileUom = new();
         ProductDimensionUnit? _componentUom = new();
         ProductDimensionUnit? _glassUom = new();
@@ -103,6 +107,17 @@ public partial class V6ProjectImport : Window
         ManufacturingTemplateStage[] _stages = [];
         
         MultiQuery query = new MultiQuery();
+        
+        query.Add(
+            new Filter<JobStatus>(x=>x.Code).IsEqualTo(_client.Settings.JobStatus),
+            Columns.All<JobStatus>().Add(x=>x.ID)
+        );
+        
+        query.Add(
+            new Filter<TaxCode>(x=>x.Code).IsEqualTo(_client.Settings.TaxCode),
+            Columns.All<TaxCode>()
+        );
+        
         if (_importCosts != V6ImportCosts.None)
         {
             query.Add(
@@ -119,6 +134,22 @@ public partial class V6ProjectImport : Window
         }
         
         query.Query();
+
+        _statusCode = query.Get<JobStatus>().Rows.FirstOrDefault()?.ToObject<JobStatus>();
+        if (_statusCode == null)
+        {
+            MessageWindow.ShowMessage(
+                "Job Status setting has not been configured correctly!\nPlease correct this and try again.", "Error");
+            return;
+        }
+        
+        _taxCode = query.Get<TaxCode>().Rows.FirstOrDefault()?.ToObject<TaxCode>();
+        if (_taxCode == null)
+        {
+            MessageWindow.ShowMessage(
+                "Tax Code setting has not been configured correctly!\nPlease correct this and try again.", "Error");
+            return;
+        }
         
         if (_importDesigns == V6ImportDesigns.ToManufacturing)
         {
@@ -159,13 +190,15 @@ public partial class V6ProjectImport : Window
             MessageWindow.ShowMessage(
                 "Packet Template setting has not been configured correctly!\nPlease correct this and try again.", "Error");
             return;
-        }   
+        }
 
+        List<string> _finishes = new();
         List<V6Profile> _profiles = new();
         List<V6Component> _components = new();
         List<V6Glass> _glass = new();
         List<V6Labour> _labour = new();
-        
+
+        List<ProductStyle> _styles = new();
         List<Product> _products = new();
         List<Activity> _activities = new();
 
@@ -175,6 +208,7 @@ public partial class V6ProjectImport : Window
         List<V6Component> _missingComponents = new();
         List<V6Glass> _missingGlass = new();
         List<V6Labour> _missingLabour = new();
+        List<string> _missingFinishes = new();
 
         string exception = null;
 
@@ -216,14 +250,28 @@ public partial class V6ProjectImport : Window
                     exception = $"Error retrieving Glass : {_exception.Message}";
                     return;
                 }
+
+                progress.Report("Checking PRS Codes");
+
+                MultiQuery query = new MultiQuery();
+                
+                var _productStyles = _profiles.Select(x => x.Finish)
+                    .Union(_glass.Select(x => x.Treatment))
+                    .Distinct()
+                    .ToArray();
+
+                query.Add(
+                    new Filter<ProductStyle>(x => x.Code).InList(_productStyles),
+                    Columns.None<ProductStyle>().Add(x => x.ID).Add(x => x.Code)
+                );
                 
-                progress.Report("Checking Product List");
                 var _productcodes = _profiles.Select(x => x.Code)
                     .Union(_components.Select(x => x.Code))
                     .Union(_glass.Select(x => x.Code))
                     .Distinct()
                     .ToArray();
-                _products = Client.Query(
+
+                query.Add(
                     new Filter<Product>(x => x.Code).InList(_productcodes),
                     Columns.None<Product>()
                         .Add(x => x.ID)
@@ -236,10 +284,19 @@ public partial class V6ProjectImport : Window
                         .Add(x => x.UnitOfMeasure.HasLength)
                         .Add(x => x.UnitOfMeasure.HasWidth)
                         .Add(x => x.UnitOfMeasure.HasHeight)
-                        .Add(x=>x.UnitOfMeasure.Format)
-                        .Add(x=>x.UnitOfMeasure.Formula)
-                ).ToObjects<Product>().ToList();
+                        .Add(x => x.UnitOfMeasure.Format)
+                        .Add(x => x.UnitOfMeasure.Formula)
+                        .Add(x => x.TaxCode.ID)
+                        .Add(x => x.TaxCode.Code)
+                );
 
+                query.Query();
+
+                _styles = query.Get<ProductStyle>().ToObjects<ProductStyle>().ToList();
+                _products = query.Get<Product>().ToObjects<Product>().ToList();
+                
+                _missingFinishes.AddRange(_productStyles.Where(c => !string.IsNullOrWhiteSpace(c) && !_styles.Any(p => string.Equals(p.Code, c))));
+                
                 var _missingCodes = _productcodes.Where(c => !_products.Any(p => string.Equals(p.Code, c))).ToArray();
                 _missingProfiles.AddRange(_profiles.Where(x => _missingCodes.Contains(x.Code)));
                 _missingComponents.AddRange(_components.Where(x => _missingCodes.Contains(x.Code)));
@@ -266,6 +323,17 @@ public partial class V6ProjectImport : Window
                     return;
             }
 
+            if (_missingFinishes.Any())
+            {
+                if (!MessageWindow.ShowYesNo(
+                        $"The following styles do not exist in PRS\n" +
+                        $"- {string.Join("\n- ", _missingFinishes
+                            .Distinct().OrderBy(x => x))}\n\n" +
+                        $"Do you wish to create them now?",
+                        "Create Missing Styles"))
+                    return;
+            }
+
             Progress.ShowModal("Checking Labour", progress =>
             {
 
@@ -339,13 +407,14 @@ public partial class V6ProjectImport : Window
             try
             {
                 
-                var _scope = CreateJob(_project);
+                var _scope = CreateJob(_project, _statusCode, _taxCode);
             
                 if (_importCosts != V6ImportCosts.None)
                 {
-                    CreateMissingProducts<V6Profile>(_profileUom, _missingProfiles, _products);
-                    CreateMissingProducts<V6Component>(_componentUom, _missingComponents, _products);
-                    CreateMissingProducts<V6Glass>(_glassUom, _missingGlass, _products);
+                    CreateMissingStyles(_missingFinishes, _styles);
+                    CreateMissingProducts<V6Profile>(_profileUom, _taxCode, _missingProfiles, _products);
+                    CreateMissingProducts<V6Component>(_componentUom, _taxCode, _missingComponents, _products);
+                    CreateMissingProducts<V6Glass>(_glassUom, _taxCode, _missingGlass, _products);
                     CreateMissingLabour(_missingLabour, _activities);
 
                     progress.Report("Creating Bill of Materials");
@@ -353,7 +422,7 @@ public partial class V6ProjectImport : Window
                         _profiles, _profileUom, 
                         _components, _componentUom, 
                         _glass, _glassUom, 
-                        _products);
+                        _products, _styles);
 
                     if (_importCosts == V6ImportCosts.Requisitions)
                     {
@@ -393,6 +462,7 @@ public partial class V6ProjectImport : Window
         
         List<String> _missing = new();
         _missing.AddRange(_missingLabour.Select(x => $"- Activity {x.Code}: {x.Description}").Distinct().OrderBy(x => x));
+        _missing.AddRange(_missingFinishes.Select(x => $"- Style {x}").Distinct().OrderBy(x => x));
         _missing.AddRange(_missingProfiles.Select(x => $"- Product {x.Code}: {x.Description}")
             .Union(_missingComponents.Select(x => $"- Product {x.Code}: {x.Description}"))
             .Union(_missingGlass.Select(x => $"- Product {x.Code}: {x.Description}"))
@@ -421,8 +491,28 @@ public partial class V6ProjectImport : Window
         Client.Save(_updates, "Created by V6 Import");
         activitylist.AddRange(_updates);
     }
+    
+    private static void CreateMissingStyles( List<string> missingitems, List<ProductStyle> styleList)
+    {
+        
+        List<ProductStyle> _updates = new();
+        foreach (var _missingitem in missingitems)
+        {
+            if (!_updates.Any(x => String.Equals(x.Code, _missingitem)))
+            {
+                var _productstyle = new ProductStyle();
+                _productstyle.Code = _missingitem;
+                _productstyle.Description = _missingitem;
+                _productstyle.Issues = $"Created By V6 Import";
+                _updates.Add(_productstyle);
+            }
+        }
 
-    private static void CreateMissingProducts<T>(ProductDimensionUnit uom, List<T> missingitems, List<Product> productlist) where T : V6BOMItem
+        Client.Save(_updates, "Created by V6 Import");
+        styleList.AddRange(_updates);
+    }
+    
+    private static void CreateMissingProducts<T>(ProductDimensionUnit uom, TaxCode tax, List<T> missingitems, List<Product> productlist) where T : V6BOMItem
     {
         
         List<Product> _updates = new();
@@ -435,6 +525,7 @@ public partial class V6ProjectImport : Window
                 _product.Code = _missingitem.Code;
                 _product.Name = _missingitem.Description;
                 _product.Issues = $"Created By V6 Import";
+                _product.TaxCode.CopyFrom(tax);
                 _updates.Add(_product);
             }
         }
@@ -443,7 +534,7 @@ public partial class V6ProjectImport : Window
         productlist.AddRange(_updates);
     }
     
-    private static JobScope CreateJob(V6Quote quote)
+    private static JobScope CreateJob(V6Quote quote, JobStatus status, TaxCode tax)
     {
         var _jobno = $"V{quote.Number}";
         MultiQuery query = new MultiQuery();
@@ -460,6 +551,7 @@ public partial class V6ProjectImport : Window
             _job = new Job();
             _job.JobNumber = _jobno;
             _job.Name = quote.Title;
+            _job.JobStatus.CopyFrom(status);
             Client.Save(_job,"Imported From V6");
             _scope.ID = _job.DefaultScope.ID;
             _scope.CommitChanges();
@@ -471,6 +563,7 @@ public partial class V6ProjectImport : Window
             ? "Main Job"
             : quote.Title;
         _scope.ExTax = quote.SellPrice;
+        _scope.TaxCode.CopyFrom(tax);
         _scope.Type = string.IsNullOrWhiteSpace(quote.Variation)
             ? JobScopeType.Contract
             : JobScopeType.Variation;
@@ -478,11 +571,12 @@ public partial class V6ProjectImport : Window
         return _scope;
     }
     
-    private JobBillOfMaterials CreateBillofMaterials(V6Quote quote, JobScope scope, 
+    private JobBillOfMaterials CreateBillofMaterials(V6Quote quote, 
+        JobScope scope,
         List<V6Profile> profiles, ProductDimensionUnit profileUOM, 
         List<V6Component> components, ProductDimensionUnit componentUOM, 
         List<V6Glass> glass, ProductDimensionUnit glassUOM, 
-        List<Product> _products)
+        List<Product> _products, List<ProductStyle> _styles)
     {
         var _bom = new JobBillOfMaterials();
         _bom.Job.ID = scope.Job.ID;
@@ -505,10 +599,20 @@ public partial class V6ProjectImport : Window
                 _bomitem.Product.CopyFrom(_p);
                 _bomitem.Dimensions.Unit.CopyFrom(profileUOM);
                 _bomitem.Dimensions.Length = _profile.Length;
-                _bomitem.Quantity = _profile.Quantity;
             }
             else
                 _bomitem.Issues = $"Unable to Locate Product: {_profile.Quantity} x {_profile.Code}: {_profile.Description} ({_profile.Length})";
+
+            if (!string.IsNullOrWhiteSpace(_profile.Finish))
+            {
+                if (_styles.FirstOrDefault(x => x.Code == _profile.Finish) is { } _s)
+                    _bomitem.Style.CopyFrom(_s);
+                else
+                    _bomitem.Issues = $"Unable to Locate Style: {_profile.Finish}";
+            }
+
+            _bomitem.Quantity = _profile.Quantity;
+            _bomitem.UnitCost = _profile.Cost;
             _bomitems.Add(_bomitem);
         }
         
@@ -523,11 +627,13 @@ public partial class V6ProjectImport : Window
                 _bomitem.Product.CopyFrom(_s);
                 _bomitem.Dimensions.Unit.CopyFrom(componentUOM);
                 _bomitem.Dimensions.Quantity = 1;
-                _bomitem.Quantity = _component.Quantity * _component.PackSize;
                 _bomitems.Add(_bomitem);
             }
             else
-                _bomitem.Issues = $"Unable to Locate Profile: {_component.Quantity} x {_component.Code}: {_component.Description} ({_component.PackSize})";
+                _bomitem.Issues = $"Unable to Locate Product: {_component.Quantity} x {_component.Code}: {_component.Description} ({_component.PackSize})";
+            
+            _bomitem.Quantity = _component.Quantity * _component.PackSize;
+            _bomitem.UnitCost = _component.Cost;
         }
 
         foreach (var _glass in glass)
@@ -536,20 +642,31 @@ public partial class V6ProjectImport : Window
             _bomitem.BillOfMaterials.ID = _bom.ID;
             _bomitem.Job.ID = scope.Job.ID;
             _bomitem.Scope.ID = scope.ID;
-            if (_products.FirstOrDefault(x => x.Code == _glass.Code) is { } _s)
+            if (_products.FirstOrDefault(x => x.Code == _glass.Code) is { } _p)
             {
-                _bomitem.Product.CopyFrom(_s);
+                _bomitem.Product.CopyFrom(_p);
                 _bomitem.Dimensions.Unit.CopyFrom(glassUOM);
                 _bomitem.Dimensions.Height = _glass.Height * 25.4;
                 _bomitem.Dimensions.Width = _glass.Width * 25.4;
-                _bomitem.Quantity = _glass.Quantity;
                 _bomitems.Add(_bomitem);
             }
             else
                 _bomitem.Issues =
-                    $"Unable to Locate Profile: {_glass.Quantity} x {_glass.Code}: {_glass.Description} ({_glass.Height} x {_glass.Width})";
-        }
+                    $"Unable to Locate Product: {_glass.Code}: {_glass.Description} ({_glass.Height} x {_glass.Width})";
+
+            if (!string.IsNullOrWhiteSpace(_glass.Treatment))
+            {
+                if (_styles.FirstOrDefault(x => x.Code == _glass.Treatment) is { } _s)
+                    _bomitem.Style.CopyFrom(_s);
+                else
+                    _bomitem.Issues = $"Unable to Locate Style: {_glass.Treatment})";
+            }
 
+            _bomitem.Quantity = _glass.Quantity;
+            _bomitem.UnitCost = _glass.Cost;
+
+        }
+        
         Client.Save(_bomitems,"Imported From V6");
         return _bom;
     }

+ 5 - 1
prs.desktop/Utils/V6Utils/V6Client.cs

@@ -363,6 +363,8 @@ public class V6Client : IDisposable
         _result.Description = GetString(row, nameof(V6Profile.Description));
         _result.Length = GetDouble(row, nameof(V6Profile.Length));
         _result.Quantity = Math.Ceiling(GetDouble(row,nameof(V6Profile.Quantity)) / (_result.Length.IsEffectivelyEqual(0.0) ? 1.0 : _result.Length));
+        _result.Cost = GetDouble(row, nameof(V6Profile.Cost));
+        _result.Finish = GetString(row, nameof(V6Profile.Finish));
         return _result;
     }
 
@@ -400,6 +402,7 @@ public class V6Client : IDisposable
         _result.Description = GetString(row, nameof(V6Component.Description));
         _result.PackSize = GetDouble(row, nameof(V6Component.PackSize));
         _result.Quantity = GetDouble(row, nameof(V6Component.Quantity));
+        _result.Cost = GetDouble(row, nameof(V6Component.Cost));
         return _result;
     }
     
@@ -439,7 +442,8 @@ public class V6Client : IDisposable
             Height = GetDouble(row, nameof(V6Glass.Height)),
             Width = GetDouble(row, nameof(V6Glass.Width)),    
             Location = GetString(row, nameof(V6Glass.Location)),
-            Quantity = GetDouble(row, nameof(V6Glass.Quantity))   
+            Quantity = GetDouble(row, nameof(V6Glass.Quantity)),
+            Cost = GetDouble(row, nameof(V6Glass.Cost)),
         };
     }
 

+ 1 - 1
prs.desktop/prsdesktop.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Desktop"
-#define MyAppVersion "8.13b"
+#define MyAppVersion "8.14"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSDesktop.exe"

+ 1 - 1
prs.licensing/PRSLicensing.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Licensing"
-#define MyAppVersion "8.13b"
+#define MyAppVersion "8.14"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSLicensing.exe"

+ 1 - 1
prs.server/PRSServer.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Server"
-#define MyAppVersion "8.13b"
+#define MyAppVersion "8.14"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSServer.exe"