Calculation VAT Amount and Withholding Tax Amount

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.

Related