1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 20 import org.compiere.util.*; 21 22 28 public class MTax extends X_C_Tax 29 { 30 35 public MTax (Properties ctx, int C_Tax_ID) 36 { 37 super (ctx, C_Tax_ID); 38 if (C_Tax_ID == 0) 39 { 40 setIsDefault (false); 42 setIsDocumentLevel (true); 43 setIsSummary (false); 44 setIsTaxExempt (false); 45 setRate (Env.ZERO); 47 setRequiresTaxCertificate (false); 48 setSOPOType (SOPOTYPE_Both); 50 setValidFrom (TimeUtil.getDay(1,1,1990)); 51 } 52 } 54 59 public MTax (Properties ctx, ResultSet rs) 60 { 61 super (ctx, rs); 62 } 64 71 public MTax (Properties ctx, String Name, BigDecimal Rate, int C_TaxCategory_ID) 72 { 73 this (ctx, 0); 74 setName (Name); 75 setRate (Rate == null ? Env.ZERO : Rate); 76 setC_TaxCategory_ID (C_TaxCategory_ID); } 79 private static BigDecimal ONEHUNDRED = new BigDecimal(100); 80 81 88 public BigDecimal calculateTax (BigDecimal amount, boolean fromNet, int scale) 89 { 90 if (getRate().compareTo(Env.ZERO) == 0) 92 return Env.ZERO; 93 94 double multiplier = getRate().doubleValue() / 100; 95 96 BigDecimal tax = null; 97 if (fromNet) { 99 double result = amount.doubleValue() * multiplier; 100 tax = new BigDecimal(result); 101 } 102 else { 104 multiplier += 1; 105 double base = amount.doubleValue() / multiplier; 106 tax = amount.subtract(new BigDecimal(base)); 107 } 108 tax = tax.setScale(scale, BigDecimal.ROUND_HALF_UP); 109 log.debug ("calculateTax " + amount + " (net=" + fromNet + " mult=" + multiplier + ") = " + tax); 110 return tax; 111 } 113 114 } | Popular Tags |