Cambodia, has new regulation by changing the standard tax to use based on unit cost (COGS) , I have try to find the way and which code I need to subscribe for my custom logic, and I came up with but not sure it is the right way, anyone please help and advice, thanks
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnRunOnBeforeCalcVATAmountLines', '', false, false)]
local procedure AdjustVATBasedOnUnitCost(SalesHeader: Record "Sales Header")
var
SalesLine: Record "Sales Line";
VATPostingSetup: Record "VAT Posting Setup";
begin
// Filter Sales Lines related to the current Sales Header
SalesLine.SetRange("Document Type", SalesHeader."Document Type");
SalesLine.SetRange("Document No.", SalesHeader."No.");
// Loop through the filtered Sales Lines
if SalesLine.FindSet() then
repeat
// Ensure VAT calculation applies only to lines with a VAT %
if SalesLine."VAT %" > 0 then begin
// Retrieve the VAT Posting Setup record for the VAT Prod. Posting Group and VAT Bus. Posting Group
if VATPostingSetup.Get(SalesLine."VAT Prod. Posting Group", SalesLine."VAT Bus. Posting Group") then begin
// Use the VAT Posting Setup to calculate VAT Base Amount and Amount Including VAT
// Here, using Unit Cost instead of Unit Price
SalesLine."VAT Base Amount" := SalesLine."Unit Cost" * SalesLine.Quantity;
// Calculate the Amount Including VAT
SalesLine."Amount Including VAT" :=
SalesLine."VAT Base Amount" +
(SalesLine."VAT Base Amount" * VATPostingSetup."VAT %" / 100); // Use VAT % from the setup
// Save changes to the Sales Line
SalesLine.Modify();
end;
end;
until SalesLine.Next() = 0;
end;