Calculation VAT Amount and Withholding Tax Amount

CapturePV.PNG

From the Picture uploaded, I set VAT Code to VAT Posting Setup. Once I chose any of the VAT, it automatically turn Net Amount and Total Amount to zero.

This is my code on PV Lines / Amount

Amount - OnValidate()

CSetup.GET;
CSetup.TESTFIELD("Rounding Precision");
IF CSetup."Rounding Type"=CSetup."Rounding Type"::Up THEN
Direction:='>'
ELSE IF CSetup."Rounding Type"=CSetup."Rounding Type"::Nearest THEN
Direction:='='
ELSE IF CSetup."Rounding Type"=CSetup."Rounding Type"::Down THEN
Direction:='<';
CASE "Account Type" OF
"Account Type"::"G/L Account":
BEGIN
IF "VAT Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."VAT Bus. Posting Group","VAT Code") THEN BEGIN
IF VATSetup."VAT %"<>0 THEN BEGIN
//VATAmount := ROUND(Amount * VATSetup."VAT %" / (100 + VATSetup."VAT %"),CSetup."Rounding Precision",Direction);
VATAmount := ROUND((Amount/(1+VATSetup."VAT %"/100)*VATSetup."VAT %"/100),CSetup."Rounding Precision",Direction);
NetAmount := Amount-VATAmount;
"VAT Amount" := VATAmount;
//NetAmount := Amount - "VAT Amount";
IF CSetup."Post VAT" THEN
"Net Amount" := Amount-VATAmount
ELSE
"Net Amount" := Amount;

//Withholding Tax Amount
IF "Withholding Tax Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount-"W/TAmount";
IF CSetup."Post VAT" THEN
"Net Amount" := NetAmount
ELSE
"Net Amount" := Amount-"W/TAmount";
END;
END;
END ELSE BEGIN
"Net Amount" := Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;
END
ELSE BEGIN
"Net Amount":= Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;

"Account Type"::Customer:
BEGIN
IF "VAT Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."VAT Bus. Posting Group","VAT Code") THEN BEGIN
VATAmount := ROUND((Amount/(1+VATSetup."VAT %"/100)*VATSetup."VAT %"/100),CSetup."Rounding Precision",Direction);
IF VATSetup."VAT %"<>0 THEN BEGIN
NetAmount := Amount-VATAmount;
"VAT Amount" := VATAmount;
IF CSetup."Post VAT" THEN
"Net Amount" := Amount-VATAmount
ELSE
"Net Amount" := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount-"W/TAmount";
IF CSetup."Post VAT" THEN
"Net Amount" := NetAmount
ELSE
"Net Amount" := Amount-"W/TAmount";
END;
END;
END ELSE BEGIN
"Net Amount" := Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;
END
ELSE BEGIN
"Net Amount":= Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;

"Account Type"::Vendor:
BEGIN
IF "VAT Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."VAT Bus. Posting Group","VAT Code") THEN BEGIN
IF VATSetup."VAT %"<>0 THEN BEGIN
VATAmount := ROUND((Amount/(1+VATSetup."VAT %"/100)*VATSetup."VAT %"/100),CSetup."Rounding Precision",Direction);
NetAmount := Amount-VATAmount;
"VAT Amount" := VATAmount;
IF CSetup."Post VAT" THEN
"Net Amount" := Amount-VATAmount
ELSE
"Net Amount" := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount-"W/TAmount";
IF CSetup."Post VAT" THEN
"Net Amount" := NetAmount
ELSE
"Net Amount" := Amount-"W/TAmount";
END;
END;
END ELSE BEGIN
"Net Amount" := Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;
END
ELSE BEGIN
"Net Amount":= Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;

"Account Type"::"Bank Account":
"Net Amount":= Amount;
END;

Please I help your assistance on this, Sir.

With so much code no one should be in doubt, that this is a DEVELOPER FORUM question, not a general discussion topic. At least someone who have been a member for so long. [;)]And when you copy/paste code, then it presents much better if you use the Insert → Insert Code function when you create your question.

As to your question, then that’s too much code for 10pm.

Save

Ok, Thanks.

Amount - OnValidate()

CSetup.GET;
CSetup.TESTFIELD("Rounding Precision");
IF CSetup."Rounding Type"=CSetup."Rounding Type"::Up THEN
Direction:='>'
ELSE IF CSetup."Rounding Type"=CSetup."Rounding Type"::Nearest THEN
Direction:='='
ELSE IF CSetup."Rounding Type"=CSetup."Rounding Type"::Down THEN
Direction:='<';
CASE "Account Type" OF
"Account Type"::"G/L Account":
BEGIN
IF "VAT Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."VAT Bus. Posting Group","VAT Code") THEN BEGIN
IF VATSetup."VAT %"<>0 THEN BEGIN
//VATAmount := ROUND(Amount * VATSetup."VAT %" / (100 + VATSetup."VAT %"),CSetup."Rounding Precision",Direction);
VATAmount := ROUND((Amount/(1+VATSetup."VAT %"/100)*VATSetup."VAT %"/100),CSetup."Rounding Precision",Direction);
NetAmount := Amount-VATAmount;
"VAT Amount" := VATAmount;
//NetAmount := Amount - "VAT Amount";
IF CSetup."Post VAT" THEN
"Net Amount" := Amount-VATAmount
ELSE
"Net Amount" := Amount;

//Withholding Tax Amount
IF "Withholding Tax Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount-"W/TAmount";
IF CSetup."Post VAT" THEN
"Net Amount" := NetAmount
ELSE
"Net Amount" := Amount-"W/TAmount";
END;
END;
END ELSE BEGIN
"Net Amount" := Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;
END
ELSE BEGIN
"Net Amount":= Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF GLAccount.GET("Account No.") THEN
IF VATSetup.GET(GLAccount."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;

"Account Type"::Customer:
BEGIN
IF "VAT Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."VAT Bus. Posting Group","VAT Code") THEN BEGIN
VATAmount := ROUND((Amount/(1+VATSetup."VAT %"/100)*VATSetup."VAT %"/100),CSetup."Rounding Precision",Direction);
IF VATSetup."VAT %"<>0 THEN BEGIN
NetAmount := Amount-VATAmount;
"VAT Amount" := VATAmount;
IF CSetup."Post VAT" THEN
"Net Amount" := Amount-VATAmount
ELSE
"Net Amount" := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount-"W/TAmount";
IF CSetup."Post VAT" THEN
"Net Amount" := NetAmount
ELSE
"Net Amount" := Amount-"W/TAmount";
END;
END;
END ELSE BEGIN
"Net Amount" := Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;
END
ELSE BEGIN
"Net Amount":= Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Customer.GET("Account No.") THEN
IF VATSetup.GET(Customer."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;

"Account Type"::Vendor:
BEGIN
IF "VAT Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."VAT Bus. Posting Group","VAT Code") THEN BEGIN
IF VATSetup."VAT %"<>0 THEN BEGIN
VATAmount := ROUND((Amount/(1+VATSetup."VAT %"/100)*VATSetup."VAT %"/100),CSetup."Rounding Precision",Direction);
NetAmount := Amount-VATAmount;
"VAT Amount" := VATAmount;
IF CSetup."Post VAT" THEN
"Net Amount" := Amount-VATAmount
ELSE
"Net Amount" := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount-"W/TAmount";
IF CSetup."Post VAT" THEN
"Net Amount" := NetAmount
ELSE
"Net Amount" := Amount-"W/TAmount";
END;
END;
END ELSE BEGIN
"Net Amount" := Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;
END
ELSE BEGIN
"Net Amount":= Amount;
NetAmount := Amount;
IF "Withholding Tax Code"<>'' THEN BEGIN
IF Vendor.GET("Account No.") THEN
IF VATSetup.GET(Vendor."Gen. Bus. Posting Group","Withholding Tax Code") THEN BEGIN
"W/TAmount" := ROUND(NetAmount*VATSetup."VAT %"/100,CSetup."Rounding Precision",Direction);
"WTX Amount" := "W/TAmount";
NetAmount := NetAmount - "W/TAmount";
"Net Amount" := Amount-"W/TAmount";
END;
END;
END;
END;

"Account Type"::"Bank Account":
"Net Amount":= Amount;
END;

Hi. I can’t see type of the document on the picture, but maybe better to develop something like standard function for VAT and amount calculation?

E.g. Sales report has functions:

CLEAR(SalesLine);
CLEAR(SalesPost);
VATAmountLine.DELETEALL;
SalesLine.DELETEALL;
SalesPost.GetSalesLines(“Sales Header”,SalesLine,0);
SalesLine.CalcVATAmountLines(0,“Sales Header”,SalesLine,VATAmountLine);
SalesLine.UpdateVATOnLines(0,“Sales Header”,SalesLine,VATAmountLine);
VATAmount := VATAmountLine.GetTotalVATAmount;
VATBaseAmount := VATAmountLine.GetTotalVATBase;
VATDiscountAmount :=
VATAmountLine.GetTotalVATDiscount(“Sales Header”.“Currency Code”,“Sales Header”.“Prices Including VAT”);
TotalAmountInclVAT := VATAmountLine.GetTotalAmountInclVAT;

CaptureVATPosting.PNG

CaptureGen.PNG

Am getting the VAT Amount

CaptureBus.PNG

Am not getting WHT. Should customized a WHT Product Posting Group and WHT Posting Setup?

Thanks

IF VATSetup.GET(GLAccount.“Gen. Bus. Posting Group”,“W/Tax Code”) THEN BEGIN.

I changed the above code to this: IF VATSetup.GET(GLAccount.“VAT Bus. Posting Group”,“W/Tax Code”) THEN BEGIN

Its working fine now. Thank you, all