Last active
September 21, 2020 07:00
-
-
Save ranafaraz/098fcb077285cbaac1d5b13fcbce0451 to your computer and use it in GitHub Desktop.
This file contains callouts to calculate withholding taxes per invoice line within iDempiere.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Call out to calculate GST Base (17% of Income Tax of GST included price) | |
public String calc_GST_IT (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) | |
{ | |
// Storing TaxID in a variable. | |
Integer taxID = (Integer)mTab.getValue("C_Tax_ID"); | |
if (taxID == 1000015 || taxID == 1000016) { | |
// Resetting values to zero | |
mTab.setValue("PriceEntered", new BigDecimal("0")); | |
mTab.setValue("PriceActual", new BigDecimal("0")); // Unit Price | |
mTab.setValue("LineNetAmt", new BigDecimal("0")); | |
mTab.setValue("PriceLimit", new BigDecimal("0")); | |
mTab.setValue("TaxAmt", new BigDecimal("0")); | |
mTab.setValue("LineTotalAmt", new BigDecimal("0")); | |
mTab.setValue("TotalDeduction", new BigDecimal("0")); | |
// Calculating value of GST Base (17% of Income Tax (against GST) Base Amount) | |
BigDecimal GSTDivisor = new BigDecimal("100"); | |
BigDecimal GSTPercentage = new BigDecimal("17"); // Will be replaced by dynamic value in the future. | |
BigDecimal WH_GST_IT_Base = (BigDecimal)mTab.getValue("WH_GST_IT_Base"); | |
BigDecimal GSTBaseAmt = (GSTPercentage.divide(GSTDivisor)).multiply(WH_GST_IT_Base); | |
// Setting value of GST Base | |
mTab.setValue("WH_GST_BaseAmt", GSTBaseAmt); | |
// Calculating GST (17%) | |
BigDecimal WH_GST_Percent = (BigDecimal)mTab.getValue("WH_GST_Percent"); // Getting Value of GST % | |
BigDecimal WHGST = (WH_GST_Percent.divide(GSTDivisor)).multiply(GSTBaseAmt); | |
// Setting value of WH GST | |
mTab.setValue("WH_GST", WHGST); | |
// Calculating Income Tax (4.5) on Amount having GST | |
BigDecimal WH_GST_IT_Percent = (BigDecimal)mTab.getValue("WH_GST_IT_Percent"); // Getting Value of GST % | |
BigDecimal WHITGST = (WH_GST_IT_Percent.divide(GSTDivisor)).multiply(WH_GST_IT_Base); | |
// Setting value of WH IT on GST | |
mTab.setValue("WH_GST_IT", WHITGST); | |
// Adding up all the taxes | |
BigDecimal Sum = WH_GST_IT_Base.add(GSTBaseAmt); | |
// Setting Total Base Amount | |
mTab.setValue("PriceEntered", Sum); | |
mTab.setValue("PriceActual", Sum); // Unit Price | |
mTab.setValue("LineNetAmt", Sum); | |
mTab.setValue("LineTotalAmt", Sum); | |
} else { | |
} | |
return ""; | |
} | |
// Call out to calculate Withholding per invoice line. It is attached with Income Tax Base Amount Field. | |
public String customWithholding (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) | |
{ | |
// Storing TaxID in a variable. | |
Integer taxID = (Integer)mTab.getValue("C_Tax_ID"); | |
if (taxID == 1000015 || taxID == 1000016) { | |
// Resetting values to zero | |
mTab.setValue("PriceEntered", new BigDecimal("0")); | |
mTab.setValue("PriceActual", new BigDecimal("0")); // Unit Price | |
mTab.setValue("TaxAmt", new BigDecimal("0")); | |
mTab.setValue("LineNetAmt", new BigDecimal("0")); | |
mTab.setValue("LineTotalAmt", new BigDecimal("0")); | |
mTab.setValue("TotalDeduction", new BigDecimal("0")); | |
// Fetching Value of Income Tax Base Amount | |
BigDecimal WH_IncomeTax_BaseAmt = (BigDecimal)mTab.getValue("WH_IncomeTax_BaseAmt"); | |
// Setting value of PST Base | |
mTab.setValue("WH_PST_BaseAmt", WH_IncomeTax_BaseAmt); | |
// Fetching Value of PST Base Amount Field | |
BigDecimal WH_PST_BaseAmt = (BigDecimal)mTab.getValue("WH_PST_BaseAmt"); | |
BigDecimal PSTDivisor = new BigDecimal("100"); | |
// Fetching PST Percentage | |
BigDecimal PSTPercentage = (BigDecimal)mTab.getValue("WH_PST_Percent"); | |
// Calculating PST | |
BigDecimal WH_PST = (PSTPercentage.divide(PSTDivisor)).multiply(WH_PST_BaseAmt); | |
// Setting value of WH PST | |
mTab.setValue("WH_PST", WH_PST); | |
if (taxID == 1000015) { | |
// Setting value of Income Tax Percentage | |
mTab.setValue("WH_IncomeTax_Percent", new BigDecimal("10")); | |
// Fetching percentage of filer | |
BigDecimal Filer_Percentage = (BigDecimal)mTab.getValue("WH_IncomeTax_Percent"); | |
// Calculating Income Tax of Filer and Non Filer - WH_IncomeTax_Percent | |
BigDecimal IncomeTax = (Filer_Percentage.divide(PSTDivisor)).multiply(WH_IncomeTax_BaseAmt); | |
// Setting value of Income Tax | |
mTab.setValue("WH_IncomeTax", IncomeTax); | |
} else { | |
// Setting value of Income Tax Percentage | |
mTab.setValue("WH_IncomeTax_Percent", new BigDecimal("20")); | |
// Fetching percentage of Non Filer | |
BigDecimal Non_Filer_Percentage = (BigDecimal)mTab.getValue("WH_IncomeTax_Percent"); | |
// Calculating Income Tax of Filer and Non Filer - WH_IncomeTax_Percent | |
BigDecimal IncomeTax = (Non_Filer_Percentage.divide(PSTDivisor)).multiply(WH_IncomeTax_BaseAmt); | |
// Setting value of Income Tax | |
mTab.setValue("WH_IncomeTax", IncomeTax); | |
} | |
// Getting Values of GST Base and Income Tax with GST Base | |
// BigDecimal WH_GST_BaseAmt = (BigDecimal)mTab.getValue("WH_GST_BaseAmt"); | |
BigDecimal WH_GST_IT_Base = (BigDecimal)mTab.getValue("WH_GST_IT_Base"); | |
BigDecimal WH_GST = (BigDecimal)mTab.getValue("WH_GST"); | |
BigDecimal WH_GST_IT = (BigDecimal)mTab.getValue("WH_GST_IT"); | |
BigDecimal WH_IncomeTax = (BigDecimal)mTab.getValue("WH_IncomeTax"); | |
// Adding up all Base Amounts | |
BigDecimal Sum = WH_IncomeTax_BaseAmt.add(WH_GST_IT_Base); | |
// Adding up all Deductions | |
BigDecimal Deduction = WH_GST.add(WH_GST_IT).add(WH_PST).add(WH_IncomeTax); | |
// Setting Total Base Amount | |
mTab.setValue("PriceEntered", Sum); | |
mTab.setValue("PriceActual", Sum); // Unit Price | |
mTab.setValue("LineNetAmt", Sum); | |
mTab.setValue("LineTotalAmt", Sum); | |
mTab.setValue("TotalDeduction", Deduction); | |
} else { | |
} | |
return ""; | |
} | |
// Call out to calculate security | |
public String security (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) | |
{ | |
// Getting Base Amount | |
BigDecimal WH_Security_BaseAmt = (BigDecimal)mTab.getValue("WH_Security_BaseAmt"); | |
// Getting Percentage | |
BigDecimal WH_Security_Percent = (BigDecimal)mTab.getValue("WH_Security_Percent"); | |
// Setting Divisor to calculate percentage | |
BigDecimal Divisor = new BigDecimal("100"); | |
// Calculating Security | |
BigDecimal WH_Security = (WH_Security_Percent.divide(Divisor)).multiply(WH_Security_BaseAmt); | |
// Setting Value of Security | |
mTab.setValue("WH_Security", WH_Security); | |
// Getting Total Deduction | |
BigDecimal Deduction = (BigDecimal)mTab.getValue("TotalDeduction"); | |
// Adding Security to Deductions | |
BigDecimal Result = Deduction.add(WH_Security); | |
// Setting value of Total Deduction | |
mTab.setValue("TotalDeduction", Result); | |
return ""; | |
} | |
// Call out to calculate Penalty | |
public String penalty (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) | |
{ | |
// Getting Base Amount | |
BigDecimal WH_Penalty_BaseAmt = (BigDecimal)mTab.getValue("WH_Penalty_BaseAmt"); | |
// Getting Percentage | |
BigDecimal WH_Penalty_Percent = (BigDecimal)mTab.getValue("WH_Penalty_Percent"); | |
// Setting Divisor to calculate percentage | |
BigDecimal Divisor = new BigDecimal("100"); | |
// Calculating Security | |
BigDecimal Penalty = (WH_Penalty_Percent.divide(Divisor)).multiply(WH_Penalty_BaseAmt); | |
// Setting Value of Security | |
mTab.setValue("Penalty", Penalty); | |
// Getting Total Deduction | |
BigDecimal Deduction = (BigDecimal)mTab.getValue("TotalDeduction"); | |
// Adding Security to Deductions | |
BigDecimal Result = Deduction.add(Penalty); | |
// Setting value of Total Deduction | |
mTab.setValue("TotalDeduction", Result); | |
return ""; | |
} | |
// Call out to calculate Penalty | |
public String other_charge (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) | |
{ | |
// Getting Base Amount | |
BigDecimal WH_Other_BaseAmt = (BigDecimal)mTab.getValue("WH_Other_BaseAmt"); | |
// Getting Percentage | |
BigDecimal WH_Other_Percent = (BigDecimal)mTab.getValue("WH_Other_Percent"); | |
// Setting Divisor to calculate percentage | |
BigDecimal Divisor = new BigDecimal("100"); | |
// Calculating Security | |
BigDecimal Other_Charge = (WH_Other_Percent.divide(Divisor)).multiply(WH_Other_BaseAmt); | |
// Setting Value of Security | |
mTab.setValue("Other_Charge", Other_Charge); | |
// Getting Total Deduction | |
BigDecimal Deduction = (BigDecimal)mTab.getValue("TotalDeduction"); | |
// Adding Security to Deductions | |
BigDecimal Result = Deduction.add(Other_Charge); | |
// Setting value of Total Deduction | |
mTab.setValue("TotalDeduction", Result); | |
return ""; | |
} | |
Now place this code inside amt Callout: Start replacement from line # 685 (// Calculate Tax Amount for PO), till the end of method/callout. | |
// Calculate Tax Amount for PO | |
boolean IsSOTrx = "Y".equals(Env.getContext(Env.getCtx(), WindowNo, "IsSOTrx")); | |
if (!IsSOTrx) | |
{ | |
BigDecimal TaxAmt = Env.ZERO; // teo_sarca: [ 1656829 ] Problem when there is not tax selected in vendor invoice | |
if (mField.getColumnName().equals("TaxAmt")) | |
{ | |
TaxAmt = (BigDecimal)mTab.getValue("TaxAmt"); | |
} | |
else | |
{ | |
Integer taxID = (Integer)mTab.getValue("C_Tax_ID"); | |
if (taxID != null) | |
{ | |
int C_Tax_ID = taxID.intValue(); | |
MTax tax = new MTax (ctx, C_Tax_ID, null); | |
TaxAmt = tax.calculateTax(LineNetAmt, isTaxIncluded(WindowNo), StdPrecision); | |
mTab.setValue("TaxAmt", TaxAmt); | |
///////////////////////////////////// Code to calculate Withholding Amount by Faraz /////////////////////////////////// | |
if(C_Tax_ID == 1000009) { // C_Tax_ID == 1000009 (GST) | |
// Resetting Values to Zero | |
mTab.setValue("WH_GST_BaseAmt", new BigDecimal("0")); // Setting GST Base to Zero | |
mTab.setValue("WH_GST", new BigDecimal("0")); // Setting GST to Zero | |
mTab.setValue("WH_GST_IT_Base", new BigDecimal("0")); // Setting Income Tax on GST Base to Zero | |
mTab.setValue("WH_GST_IT", new BigDecimal("0")); // Setting Income Tax on GST to Zero | |
mTab.setValue("TotalDeduction", new BigDecimal("0")); // Setting Total Deduction to Zero | |
// Withholding GST & Income Tax - Auto Calculate | |
BigDecimal WHGSTPercent = (BigDecimal)mTab.getValue("WH_GST_Percent"); // Getting WH GST % | |
mTab.setValue("WH_GST_BaseAmt", TaxAmt); // Setting value of WH_GST Base | |
BigDecimal WHGSTBase = (BigDecimal)mTab.getValue("WH_GST_BaseAmt"); //Storing Base Amt in a Variable | |
BigDecimal Divisor = new BigDecimal("100"); | |
BigDecimal WHGSTAmt = (WHGSTPercent.divide(Divisor)).multiply(WHGSTBase); // Calculating x% of Base Tax Amount | |
mTab.setValue("WH_GST", WHGSTAmt); // Setting value of WH_GST | |
///////////////////////// Income Tax on GST ////////////////////////////// | |
BigDecimal WHGST_IT_Percent = (BigDecimal)mTab.getValue("WH_GST_IT_Percent"); // Getting WH Income Tax on GST - % | |
BigDecimal Multiplicant = TaxAmt.add(PriceEntered); // Entered Amount + TaxAmt | |
mTab.setValue("WH_GST_IT_Base", Multiplicant); // Setting value of Base GST Income Tax withholding equal to Price Entered | |
BigDecimal WH_IT_GSTAmt = (WHGST_IT_Percent.divide(Divisor)).multiply(Multiplicant); // Calculating x% of Base Tax Amount | |
mTab.setValue("WH_GST_IT", WH_IT_GSTAmt); // Setting value of Withholding Income Tax on GST | |
} | |
// Setting values to zero | |
else if (C_Tax_ID != 1000009 || C_Tax_ID == 1000015 || C_Tax_ID == 1000016) { // C_Tax_ID != 1000009 (GST) | |
mTab.setValue("WH_GST_IT_Base", new BigDecimal("0")); // Setting Income Tax on GST Base to Null | |
mTab.setValue("WH_GST", new BigDecimal("0")); // Setting GST to NUll | |
mTab.setValue("WH_GST_BaseAmt", new BigDecimal("0")); // Setting GST Base to Null | |
mTab.setValue("WH_GST_IT", new BigDecimal("0")); // Setting Income Tax on GST to Null | |
} else { | |
} | |
// Calculating WH PST and Income Tax (Filer 10%) | |
if (C_Tax_ID == 1000010) { // C_Tax_ID == 1000010 (PST - Non Filer) | |
// Resetting Values to Zero | |
mTab.setValue("TotalDeduction", new BigDecimal("0")); // Setting Total Deduction to Zero | |
mTab.setValue("WH_PST_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_PST", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax", new BigDecimal("0")); | |
// Calculating PST on Price Entered | |
BigDecimal WHPSTPercent = (BigDecimal)mTab.getValue("WH_PST_Percent"); // Getting WH PST % | |
mTab.setValue("WH_PST_BaseAmt", PriceEntered); // Setting value of WH_PST Base | |
BigDecimal WHPSTBase = (BigDecimal)mTab.getValue("WH_PST_BaseAmt"); //Storing Base Amt in a Variable | |
BigDecimal Divisor = new BigDecimal("100"); | |
BigDecimal WHPSTAmt = (WHPSTPercent.divide(Divisor)).multiply(WHPSTBase); // Calculating x% of Base Tax Amount | |
mTab.setValue("WH_PST", WHPSTAmt); // Setting value of WH_PST | |
// Calculating Income Tax of filer against Total Amount | |
mTab.setValue("WH_IncomeTax_Percent", new BigDecimal("10")); // Test Case - Amount Will be replaced by dynamic value in the future | |
BigDecimal WHIncomeTaxPercent = (BigDecimal)mTab.getValue("WH_IncomeTax_Percent"); // Getting Income Tax % | |
mTab.setValue("WH_IncomeTax_BaseAmt", PriceEntered); // Setting value of Income Tax Base | |
BigDecimal WHIncomeTaxBase = (BigDecimal)mTab.getValue("WH_IncomeTax_BaseAmt"); //Storing Base Amt in a Variable | |
BigDecimal WHITAmt = (WHIncomeTaxPercent.divide(Divisor)).multiply(WHIncomeTaxBase); // Calculating x% of Base Tax Amount | |
mTab.setValue("WH_IncomeTax", WHITAmt); // Setting value of WH_GST | |
} | |
// Setting values to Zero | |
else if (C_Tax_ID != 1000010 && C_Tax_ID != 1000014 || C_Tax_ID == 1000015 || C_Tax_ID == 1000016) { // C_Tax_ID != 1000010 (PST - Filer) | |
mTab.setValue("WH_PST_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_PST", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax", new BigDecimal("0")); | |
} else { | |
} | |
////////////////////// Calculating Withholding of Non Filer /////////////////////////////////// | |
// // Calculating WH PST and Income Tax (Non Filer 20%) | |
if (C_Tax_ID == 1000014) { // C_Tax_ID == 1000014 (PST - Non Filer) | |
// Resetting Values to Zero | |
mTab.setValue("TotalDeduction", new BigDecimal("0")); // Setting Total Deduction to Zero | |
mTab.setValue("WH_PST_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_PST", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax", new BigDecimal("0")); | |
// Calculating Non Filer's Income Tax and PST | |
BigDecimal WHPSTPercent = (BigDecimal)mTab.getValue("WH_PST_Percent"); // Getting WH PST % | |
mTab.setValue("WH_PST_BaseAmt", PriceEntered); // Setting value of WH_PST Base | |
BigDecimal WHPSTBase = (BigDecimal)mTab.getValue("WH_PST_BaseAmt"); //Storing Base Amt in a Variable | |
BigDecimal Divisor = new BigDecimal("100"); | |
BigDecimal WHPSTAmt = (WHPSTPercent.divide(Divisor)).multiply(WHPSTBase); // Calculating x% of Base Tax Amount | |
mTab.setValue("WH_PST", WHPSTAmt); // Setting value of WH_PST | |
// Calculating Income Tax of filer against Total Amount | |
mTab.setValue("WH_IncomeTax_Percent", new BigDecimal("20")); // Test Case - Will be replaced by dynamic value in the future | |
BigDecimal WHIncomeTaxPercent = (BigDecimal)mTab.getValue("WH_IncomeTax_Percent"); // Getting Income Tax % | |
mTab.setValue("WH_IncomeTax_BaseAmt", PriceEntered); // Setting value of Income Tax Base | |
BigDecimal WHIncomeTaxBase = (BigDecimal)mTab.getValue("WH_IncomeTax_BaseAmt"); //Storing Base Amt in a Variable | |
BigDecimal WHITAmt = (WHIncomeTaxPercent.divide(Divisor)).multiply(WHIncomeTaxBase); // Calculating x% of Base Tax Amount | |
mTab.setValue("WH_IncomeTax", WHITAmt); // Setting value of WH_GST | |
} | |
// Setting values to Zero | |
else if(C_Tax_ID != 1000010 && C_Tax_ID != 1000014 || C_Tax_ID == 1000015 || C_Tax_ID == 1000016) { // C_Tax_ID != 1000014 (PST - Non Filer) | |
mTab.setValue("WH_PST_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_PST", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax_BaseAmt", new BigDecimal("0")); | |
mTab.setValue("WH_IncomeTax", new BigDecimal("0")); | |
} else { | |
} | |
/////////////////////////////// Code by Faraz End /////////////////////////////////// | |
} | |
} | |
// Add it up | |
mTab.setValue("LineTotalAmt", LineNetAmt.add(TaxAmt)); | |
////////////////////////////////// Code by Faraz Start ///////////////////////////////////// | |
// Storing TaxID in a variable. | |
Integer taxID = (Integer)mTab.getValue("C_Tax_ID"); | |
// Calculating GST and Income Tax against GST on Total Amount | |
if (taxID == 1000009) { | |
BigDecimal WHGST = (BigDecimal)mTab.getValue("WH_GST"); // Getting Withheld GST | |
BigDecimal WHGSTIT = (BigDecimal)mTab.getValue("WH_GST_IT"); // Getting Withheld Income Tax on GST | |
// Subtracting Deductions from Total Line Amount | |
BigDecimal Result1 = WHGST.add(WHGSTIT); | |
mTab.setValue("TotalDeduction", Result1); // Updating Value of Total Line Amount | |
} else { | |
} | |
// Calculating Withheld PST and Filer's Income Tax | |
if (taxID == 1000010) { | |
BigDecimal WHPST = (BigDecimal)mTab.getValue("WH_PST"); // Getting Withheld GST | |
BigDecimal WH_IncomeTax = (BigDecimal)mTab.getValue("WH_IncomeTax"); // Getting Withheld Income Tax on GST | |
// Subtracting Deductions from Total Line Amount ////// - WHGST + WHGSTIT.doubleValue() + WHIT_Filer.doubleValue() + WHPST.doubleValue() | |
BigDecimal Result1 = WHPST.add(WH_IncomeTax); | |
mTab.setValue("TotalDeduction", Result1); // Updating Value of Total Line Amount | |
} else { | |
} | |
// Calculating Withheld PST and Non Filer's Income Tax | |
if (taxID == 1000014) { | |
BigDecimal WHPST = (BigDecimal)mTab.getValue("WH_PST"); // Getting Withheld PST | |
BigDecimal WH_IncomeTax = (BigDecimal)mTab.getValue("WH_IncomeTax"); // Getting Non Filer's Income Tax | |
// calculating Deductions against specific line / | |
BigDecimal Result1 = WHPST.add(WH_IncomeTax); | |
mTab.setValue("TotalDeduction", Result1); // Setting value to TotalDeduction field | |
} else { | |
} | |
///////////////////////////////// Withholding Code by Faraz End /////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment