Update Totals on Subform

mysamzamysamza Posts: 47Member
I have created 2 fields by extending the Sales Line table.
  1. Premium % (Decimal)
  2. Premium Amount (Decimal)
These two fields will be shown on the Sales Order Subform and will function like how Line Discount % works. It is just that, it will add the Premium Amount value to the Line Amount instead of how Discount % subtracts Line Discount Amount from Line Amount.

Here is the code I have written on the Sales Order Subform;
layout
    {
        addafter("Line Discount %")
        {
            field("Premium %"; "Premium %")
            {
                ApplicationArea = All;
                BlankZero = true;
                trigger OnValidate()
                begin
                    Update_Premium_Amount();
                end;
            }
            field("Premium Amount"; "Premium Amount")
            {
                ApplicationArea = All;
                BlankZero = true;
                trigger OnValidate()
                begin
                    Update_Premium_Percentage();
                end;
            }
        }

    }
    
    
    
     local procedure Update_Premium_Amount()
    var
        percValue: Decimal;
    begin
        Clear(percValue);
        percValue := rec."Premium %" / 100;
        rec."Premium Amount" := rec."Line Amount" * percValue;
        rec."Line Amount" := rec."Line Amount" + rec."Premium Amount";
        CurrPage.Update();
        UpdateAmounts();
        CalcLineAmount();
    end;

    local procedure Update_Premium_Percentage()
    begin
        if rec."Line Amount" <> 0 then begin
            rec."Premium %" := (rec."Premium Amount" * 100) / rec."Line Amount";
            rec."Line Amount" := rec."Line Amount" + rec."Premium Amount";
        end;
        CurrPage.Update();
        UpdateAmounts();
        CalcLineAmount();
    end;

My Subtotal Excl. VAT on the Subform gets updated, however, Total Excl VAT and Total Incl. VAT remains unchanged. Now I can't figure out how to solve this.

Answers

Sign In or Register to comment.