Ver Fonte

Fixed Progress Claim calculations

frogsoftware há 6 dias atrás
pai
commit
7947f729b5

+ 1 - 3
prs.classes/Entities/Job/JobScopes/JobScope.cs

@@ -326,9 +326,7 @@ namespace Comal.Classes
                     .WithLink(x => x.Scope.ID, x => x.ID);
         }
         
-        [ComplexFormula(typeof(LabourSellAggregate))]
-        
-        [Aggregate(typeof(JobScopeInvoiceExTax))]
+        [ComplexFormula(typeof(InvoiceExTaxAggregate))]
         [EditorSequence(17)]
         [CurrencyEditor(Visible = Visible.Default, Editable = Editable.Hidden, Summary = Summary.Sum)]
         public double InvoiceExTax { get; set; }

+ 53 - 30
prs.desktop/Panels/Invoices/ProgressClaim/ProgressClaimGrid.cs

@@ -160,15 +160,24 @@ public class ProgressClaimGrid : DynamicItemsListGrid<ProgressClaim>
 
         query.Add(
             Filter<Invoice>.Where(x =>x.JobLink.ID).IsEqualTo(JobID),
-            Columns.None<Invoice>().Add(x => x.ID).Add(x => x.Retained));
+            Columns.None<Invoice>()
+                .Add(x => x.ID)
+                .Add(x => x.Retained)
+                .Add(x=>x.Number)
+                .Add(x=>x.Date)
+        );
         
-        if (InvoiceID != Guid.Empty)
-            query.Add(
-                Filter<InvoiceLine>.Where(x =>x.InvoiceLink.ID).IsEqualTo(InvoiceID),
-                Columns.None<InvoiceLine>()
-                    .Add(x => x.ID)
-                    .Add(x => x.Scope.ID)
-                    .Add(x => x.ExTax));
+        query.Add(
+            Filter<InvoiceLine>.Where(x =>x.InvoiceLink.JobLink.ID).IsEqualTo(JobID),
+            Columns.None<InvoiceLine>()
+                .Add(x => x.ID)
+                .Add(x=>x.InvoiceLink.ID)
+                .Add(x=>x.InvoiceLink.Number)
+                .Add(x=>x.InvoiceLink.Date)
+                .Add(x => x.Scope.ID)
+                .Add(x => x.ExTax),
+            new SortOrder<InvoiceLine>(x=>x.InvoiceLink.Number)
+        );
         
         query.Query();
 
@@ -182,35 +191,49 @@ public class ProgressClaimGrid : DynamicItemsListGrid<ProgressClaim>
 
         Invoices = query.Get<Invoice>().ToArray<Invoice>();
         
-        Invoice = Invoices.FirstOrDefault(x => x.ID == InvoiceID) ?? new Invoice();
-        
-        InvoiceLines = InvoiceID != Guid.Empty
-            ? query.Get<InvoiceLine>().ToObjects<InvoiceLine>().ToList()
-            : new List<InvoiceLine>();
-        
+        Invoice = Invoices.FirstOrDefault(x => x.ID == InvoiceID) ?? new Invoice() { Date = DateTime.Today };
+
+        InvoiceLines = query.Get<InvoiceLine>().ToObjects<InvoiceLine>().ToList();
         
         var items = new List<ProgressClaim>();
         foreach(var scope in Scopes)
         {
             var newItem = new ProgressClaim();
             newItem.JobScope.CopyFrom(scope);
+
+            var prev = Invoice.ID == Guid.Empty
+                ? InvoiceLines
+                : InvoiceLines.Where(x => x.Scope.ID == scope.ID && x.InvoiceLink.Date < Invoice.Date);
+                
+            var current = InvoiceLines.Where(x => x.InvoiceLink.ID == Invoice.ID && x.Scope.ID == scope.ID);
+            
+            
+            newItem.PreviouslyClaimed = prev.Sum(x=>x.ExTax);
+            newItem.PreviouslyClaimedPercent = scope.ExTax.IsEffectivelyEqual(0.0) 
+                ? 0.0 
+                : newItem.PreviouslyClaimed / scope.ExTax * 100;
+            
+            newItem.Cost = current.Sum(x => x.ExTax);
+            newItem.PercentCost = scope.ExTax.IsEffectivelyEqual(0.0) 
+                ? 0.0 
+                : (newItem.PreviouslyClaimed + newItem.Cost) / scope.ExTax * 100;
+            
+            
+            // if (invoiceline != null)
+            // {
+            //     newItem.PreviouslyClaimed = scope.InvoiceExTax - invoiceline.ExTax;
+            //     newItem.PreviouslyClaimedPercent = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : (scope.InvoiceExTax - invoiceline.ExTax) / scope.ExTax * 100;
+            //     newItem.PercentCost = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : scope.InvoiceExTax / scope.ExTax * 100;
+            //     newItem.Cost = invoiceline.ExTax;
+            // }
+            // else
+            // {
+            //     newItem.PreviouslyClaimed = scope.InvoiceExTax;
+            //     newItem.PreviouslyClaimedPercent = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : scope.InvoiceExTax / scope.ExTax * 100;
+            //     newItem.PercentCost = newItem.PreviouslyClaimedPercent;
+            //     newItem.Cost = 0;
+            // }
             
-            var invoiceline = InvoiceLines.FirstOrDefault(x =>
-                x.Scope.ID == scope.ID || (x.Scope.ID == Guid.Empty && scope.ID == scope.Job.DefaultScope.ID));
-            if (invoiceline != null)
-            {
-                newItem.PreviouslyClaimed = scope.InvoiceExTax - invoiceline.ExTax;
-                newItem.PreviouslyClaimedPercent = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : (scope.InvoiceExTax - invoiceline.ExTax) / scope.ExTax * 100;
-                newItem.PercentCost = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : scope.InvoiceExTax / scope.ExTax * 100;
-                newItem.Cost = invoiceline.ExTax;
-            }
-            else
-            {
-                newItem.PreviouslyClaimed = scope.InvoiceExTax;
-                newItem.PreviouslyClaimedPercent = scope.ExTax.IsEffectivelyEqual(0.0) ? 0.0 : scope.InvoiceExTax / scope.ExTax * 100;
-                newItem.PercentCost = newItem.PreviouslyClaimedPercent;
-                newItem.Cost = 0;
-            }
             newItem.Materials = scope.MaterialsExTax;
             newItem.Labour = assignments.GetValueOrDefault(scope.ID);
             newItem.GLCodeID = Job.Account.ID != Guid.Empty