Browse Source

- Fixed lookup definition for salegl code
- Fixed RequiredColumn stuff, and neatened expression calculator.

Kenric Nugteren 10 months ago
parent
commit
d17a850280

+ 0 - 1
prs.classes/Entities/Customer/Customer.cs

@@ -103,7 +103,6 @@ namespace Comal.Classes
         public PaymentTermsLink Terms { get; set; }
         public PaymentTermsLink Terms { get; set; }
         
         
         [EditorSequence("Accounts", 5)]
         [EditorSequence("Accounts", 5)]
-        [LookupDefinition(typeof(AccountsReceivablePaymentTermsLookup<Customer>))]
         public SalesGLCodeLink GLCode { get; set; }
         public SalesGLCodeLink GLCode { get; set; }
         
         
         [EditorSequence("Accounts", 5)]
         [EditorSequence("Accounts", 5)]

+ 8 - 12
prs.classes/Entities/Invoice/Invoice.cs

@@ -30,6 +30,7 @@ namespace Comal.Classes
         public JobLink JobLink { get; set; }
         public JobLink JobLink { get; set; }
 
 
         [EditorSequence(5)]
         [EditorSequence(5)]
+        [RequiredColumn]
         public CustomerLink CustomerLink { get; set; }
         public CustomerLink CustomerLink { get; set; }
 
 
         private class ClaimedFormula : ComplexFormulaGenerator<Invoice, double>
         private class ClaimedFormula : ComplexFormulaGenerator<Invoice, double>
@@ -105,6 +106,7 @@ namespace Comal.Classes
         
         
         [EditorSequence(13)]
         [EditorSequence(13)]
         [LookupDefinition(typeof(AccountsReceivablePaymentTermsLookup<Invoice>))]
         [LookupDefinition(typeof(AccountsReceivablePaymentTermsLookup<Invoice>))]
+        [RequiredColumn]
         public PaymentTermsLink Terms { get; set; }
         public PaymentTermsLink Terms { get; set; }
         
         
         [EditorSequence(14)]
         [EditorSequence(14)]
@@ -164,27 +166,21 @@ namespace Comal.Classes
                 DueDate =  CalculateTerms((DateTime)(after ?? ""),Terms.Calculation);
                 DueDate =  CalculateTerms((DateTime)(after ?? ""),Terms.Calculation);
             else if (name.Equals(TERMSCALCULATION))
             else if (name.Equals(TERMSCALCULATION))
                 DueDate =  CalculateTerms(Date, (string)(after ?? ""));
                 DueDate =  CalculateTerms(Date, (string)(after ?? ""));
-            else if (name.Equals(CUSTOMERLINKTERMSCALCULATION))
-                DueDate =  CalculateTerms(Date, (string)(after ?? ""));
         }
         }
 
 
         private DateTime CalculateTerms(DateTime date, string calculation)
         private DateTime CalculateTerms(DateTime date, string calculation)
         {
         {
             if (string.IsNullOrWhiteSpace(calculation))
             if (string.IsNullOrWhiteSpace(calculation))
                 return date;
                 return date;
+
+            var model = new PaymentTermsCalculationModel { Date = date };
             
             
-            var variables = new Dictionary<string, object?>()
-            {
-                { "Date", date }
-            };
-            
-            try
+            var expr = new CoreExpression<PaymentTermsCalculationModel, DateTime>(calculation);
+            if(expr.Evaluate(model).Get(out var eval, out var e))
             {
             {
-                var expr = new CoreExpression(calculation);
-                var eval = expr.Evaluate(variables);
-                return (DateTime)(CoreUtils.ChangeType(eval, typeof(DateTime)) ?? date);
+                return eval;
             }
             }
-            catch (Exception e)
+            else
             {
             {
                 Logger.Send(LogType.Information, "", $"Error in Formula: [{calculation}] ({e.Message})");
                 Logger.Send(LogType.Information, "", $"Error in Formula: [{calculation}] ({e.Message})");
                 return date;
                 return date;

+ 2 - 8
prs.classes/Entities/Role/Role.cs

@@ -6,12 +6,6 @@ namespace Comal.Classes
     public class OrgChartSettings<TEntityLink> : EnclosedEntity
     public class OrgChartSettings<TEntityLink> : EnclosedEntity
         where TEntityLink : IEntityLink, new()
         where TEntityLink : IEntityLink, new()
     {
     {
-        public OrgChartSettings()
-        {
-            Color = "#00000000";
-            Visible = true;
-        }
-
         [EditorSequence("Org Chart", 1)]
         [EditorSequence("Org Chart", 1)]
         [Caption("Reports To", IncludePath = false)]
         [Caption("Reports To", IncludePath = false)]
         public TEntityLink ReportsTo { get; set; }
         public TEntityLink ReportsTo { get; set; }
@@ -19,12 +13,12 @@ namespace Comal.Classes
         [EditorSequence("Org Chart", 2)]
         [EditorSequence("Org Chart", 2)]
         [ColorEditor]
         [ColorEditor]
         [Caption("Color", IncludePath = false)]
         [Caption("Color", IncludePath = false)]
-        public string Color { get; set; }
+        public string Color { get; set; } = "#00000000";
 
 
         [EditorSequence("Org Chart", 3)]
         [EditorSequence("Org Chart", 3)]
         [CheckBoxEditor]
         [CheckBoxEditor]
         [Caption("Visible", IncludePath = false)]
         [Caption("Visible", IncludePath = false)]
-        public bool Visible { get; set; }
+        public bool Visible { get; set; } = true;
     }
     }
 
 
     public interface IOrgChart<TEntityLink> where TEntityLink : IEntityLink, new()
     public interface IOrgChart<TEntityLink> where TEntityLink : IEntityLink, new()