Selaa lähdekoodia

Converted StockMovement.IsRemnant and JobScope.UninvoicedMaterial to be ComplexFormula

Kenric Nugteren 10 kuukautta sitten
vanhempi
commit
5f1f59b9d7

+ 11 - 16
prs.classes/Entities/Job/JobScopes/JobScope.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq.Expressions;
+using System.Security;
 using InABox.Clients;
 using InABox.Core;
 
@@ -55,21 +56,6 @@ namespace Comal.Classes
         public FormulaType Type => FormulaType.Virtual;
     }
 
-    public class JobScopeUninvoicedMaterialExTax : CoreAggregate<JobScope, StockMovement, double>
-    {
-        public override Expression<Func<StockMovement, double>> Aggregate => x => x.Value;
-
-        public override Dictionary<Expression<Func<StockMovement, object?>>, Expression<Func<JobScope, object?>>> Links => new Dictionary<Expression<Func<StockMovement, object?>>, Expression<Func<JobScope, object?>>>()
-        {
-            { mvt => mvt.JobScope.ID, scope => scope.ID }
-        };
-
-        public override Filter<StockMovement>? Filter => new Filter<StockMovement>(x => x.Invoice.ID).IsEqualTo(Guid.Empty)
-            .And(x => x.Type).IsEqualTo(StockMovementType.Issue);
-
-        public override AggregateCalculation Calculation => AggregateCalculation.Sum;
-    }
-
     public interface IJobScopedItem
     {
         JobLink JobLink { get; set; }
@@ -151,8 +137,17 @@ namespace Comal.Classes
         [Formula(typeof(JobScopeUninvoicedExTax))]
         public double UninvoiceIncTax { get; set; }
 
+        private class UninvoicedMaterial : ComplexFormulaGenerator<JobScope, double>
+        {
+            public override IComplexFormulaNode<JobScope, double> GetFormula() =>
+                Aggregate<StockMovement>(AggregateCalculation.Sum, x => x.Formula(FormulaOperator.Subtract, x.Constant(0.0), x.Property(x => x.Value)))
+                    .WithFilter(
+                        new Filter<StockMovement>(x => x.Invoice.ID).IsEqualTo(Guid.Empty)
+                            .And(x => x.Type).IsEqualTo(StockMovementType.Issue))
+                    .WithLink(x => x.JobScope.ID, x => x.ID);
+        }
         [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Hidden, Summary = Summary.Sum)]
-        [Aggregate(typeof(JobScopeUninvoicedMaterialExTax))]
+        [ComplexFormula(typeof(UninvoicedMaterial))]
         public double UninvoicedMaterialsExTax { get; set; }
 
         public Expression<Func<JobScope, string>> AutoIncrementField() => x => x.Number;

+ 12 - 17
prs.classes/Entities/Stock/StockMovement/StockMovement.cs

@@ -60,21 +60,6 @@ namespace Comal.Classes
         public FormulaType Type => FormulaType.Virtual;
     }
 
-    public class StockMovementIsRemnantCondition : ICondition<StockHolding, double, object>
-    {
-        public Expression<Func<StockHolding, double>> Left => x => x.Dimensions.Value;
-
-        public Condition Condition => Condition.LessThan;
-
-        public Expression<Func<StockHolding, double>> Right => x => x.Product.DefaultInstance.Dimensions.Value;
-
-        public Expression<Func<StockHolding, object>> True => x => true;
-
-        public Expression<Func<StockHolding, object>> False => x => null;
-        
-        public ConditionType Type => ConditionType.Virtual;
-    }
-
     [UserTracking("Warehousing")]
     public class StockMovement : StockEntity, IRemotable, IPersistent, IOneToMany<StockLocation>, IOneToMany<Product>, 
         ILicense<WarehouseLicense>, IStockHolding, IJobMaterial, IExportable, IImportable, IPostable
@@ -127,10 +112,20 @@ namespace Comal.Classes
         [DoubleEditor(Visible=Visible.Optional, Editable = Editable.Hidden, Summary= Summary.Sum)]
         public double Units { get; set; }
 
-        
+        private class IsRemnantCondition : ComplexFormulaGenerator<StockMovement, bool>
+        {
+            public override IComplexFormulaNode<StockMovement, bool> GetFormula() =>
+                If<double>(
+                    x => x.Property(x => x.Dimensions.Value),
+                    Condition.LessThan,
+                    x => x.Property(x => x.Product.DefaultInstance.Dimensions.Value))
+                .Then(Constant(true))
+                .Else(Constant(false));
+        }
+
         // IsRemnant = Dimensions.Value < Product.Dimensions.Value
         [CheckBoxEditor(Editable = Editable.Hidden)]
-        [Condition(typeof(StockMovementIsRemnantCondition))]
+        [ComplexFormula(typeof(IsRemnantCondition))]
         [EditorSequence(7)]
         public bool IsRemnant { get; set; }
         

+ 3 - 3
prs.desktop/Panels/Invoices/InvoiceGrid.cs

@@ -153,9 +153,9 @@ namespace PRSDesktop
                     invoice.Retained = window.Retained;
                     Client.Save(invoice,"Progress claim updated by user.");
                     
-                    var lines = Client.Query<InvoiceLine>(
-                        new Filter<InvoiceLine>(x=>x.InvoiceLink.ID).IsEqualTo(invoiceid),
-                        Columns.None<InvoiceLine>().Add(x=>x.ID)).ToObjects<InvoiceLine>().ToList();
+                    var lines = Client.Query(
+                        new Filter<InvoiceLine>(x => x.InvoiceLink.ID).IsEqualTo(invoiceid),
+                        Columns.None<InvoiceLine>().Add(x=>x.ID)).ToList<InvoiceLine>();
                     
                     Client.Delete(lines,"Invoice Updated");
                     lines.Clear();