List of usage examples for java.math BigDecimal ROUND_HALF_EVEN
int ROUND_HALF_EVEN
To view the source code for java.math BigDecimal ROUND_HALF_EVEN.
Click Source Link
From source file:com.funambol.pushlistener.service.taskexecutor.ScheduledTaskExecutor.java
/** * Returns the average execution time/*from ww w . ja v a 2 s . c o m*/ * @return the average execution time */ public double getAverageExecutionTime() { long completedTask = getCompletedTaskCount(); if (completedTask == 0) { return 0; } double average = totalExecutionTime.doubleValue() / completedTask; BigDecimal bd = new BigDecimal(average); bd = bd.setScale(1, BigDecimal.ROUND_HALF_EVEN); return bd.doubleValue(); }
From source file:org.apache.flink.table.codegen.SortCodeGeneratorTest.java
private Object[] generateValues(InternalType type) { Random rnd = new Random(); int seedNum = RECORD_NUM / 5; Object[] seeds = new Object[seedNum]; seeds[0] = null;//from w w w .jav a 2 s. c om seeds[1] = value1(type, rnd); seeds[2] = value2(type, rnd); seeds[3] = value3(type, rnd); for (int i = 4; i < seeds.length; i++) { if (type.equals(InternalTypes.BOOLEAN)) { seeds[i] = rnd.nextBoolean(); } else if (type.equals(InternalTypes.BYTE)) { seeds[i] = (byte) rnd.nextLong(); } else if (type.equals(InternalTypes.SHORT)) { seeds[i] = (short) rnd.nextLong(); } else if (type.equals(InternalTypes.INT)) { seeds[i] = rnd.nextInt(); } else if (type.equals(InternalTypes.LONG)) { seeds[i] = rnd.nextLong(); } else if (type.equals(InternalTypes.FLOAT)) { seeds[i] = rnd.nextFloat() * rnd.nextLong(); } else if (type.equals(InternalTypes.DOUBLE)) { seeds[i] = rnd.nextDouble() * rnd.nextLong(); } else if (type.equals(InternalTypes.STRING)) { seeds[i] = BinaryString.fromString(RandomStringUtils.random(rnd.nextInt(20))); } else if (type instanceof DecimalType) { DecimalType decimalType = (DecimalType) type; BigDecimal decimal = new BigDecimal(rnd.nextInt()).divide( new BigDecimal(ThreadLocalRandom.current().nextInt(1, 256)), ThreadLocalRandom.current().nextInt(1, 30), BigDecimal.ROUND_HALF_EVEN); seeds[i] = Decimal.fromBigDecimal(decimal, decimalType.precision(), decimalType.scale()); } else if (type instanceof ArrayType || type.equals(InternalTypes.BINARY)) { byte[] bytes = new byte[rnd.nextInt(16) + 1]; rnd.nextBytes(bytes); seeds[i] = type.equals(InternalTypes.BINARY) ? bytes : BinaryArray.fromPrimitiveArray(bytes); } else if (type instanceof RowType) { RowType rowType = (RowType) type; if (rowType.getTypeAt(0).equals(InternalTypes.INT)) { seeds[i] = GenericRow.of(rnd.nextInt()); } else { seeds[i] = GenericRow.of(GenericRow.of(rnd.nextInt())); } } else if (type instanceof GenericType) { seeds[i] = new BinaryGeneric<>(rnd.nextInt(), IntSerializer.INSTANCE); } else { throw new RuntimeException("Not support!"); } } // result values Object[] results = new Object[RECORD_NUM]; for (int i = 0; i < RECORD_NUM; i++) { results[i] = seeds[rnd.nextInt(seedNum)]; } return results; }
From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java
public static BigDecimal getBigDecimalForPriceTag(BigDecimal amount) { if (amount == null) { return null; }// ww w . ja v a2s . co m return amount.setScale(PRICE_NUMBER_OF_DECIMALS, BigDecimal.ROUND_HALF_EVEN); }
From source file:org.egov.stms.web.controller.masters.DonationMasterController.java
@RequestMapping(value = "/success/{id}", method = RequestMethod.GET) public String getSeweragerates(@ModelAttribute final DonationMaster donationMaster, @PathVariable("id") final Long id, final Model model) { final DonationMaster donationMaster1 = donationMasterService.findById(id); for (final DonationDetailMaster ddm : donationMaster1.getDonationDetail()) ddm.setAmount(//from ww w.java 2 s . c o m BigDecimal.valueOf(ddm.getAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); Collections.sort(donationMaster1.getDonationDetail(), new DonationRateComparatorOrderById()); model.addAttribute(DONATIONMASTER, donationMaster1); return "donation-master-success"; }
From source file:com.opengamma.bloombergexample.loader.DemoEquityOptionCollarPortfolioLoader.java
private void addNodes(ManageablePortfolioNode rootNode, String underlying, boolean includeUnderlying, Period[] expiries) {/*from w w w . j av a 2 s.c om*/ ExternalId ticker = ExternalSchemes.bloombergTickerSecurityId(underlying); ManageableSecurity underlyingSecurity = null; if (includeUnderlying) { underlyingSecurity = getOrLoadEquity(ticker); } ExternalIdBundle bundle = underlyingSecurity == null ? ExternalIdBundle.of(ticker) : underlyingSecurity.getExternalIdBundle(); HistoricalTimeSeriesInfoDocument timeSeriesInfo = getOrLoadTimeSeries(ticker, bundle); double estimatedCurrentStrike = getOrLoadMostRecentPoint(timeSeriesInfo); Set<ExternalId> optionChain = getOptionChain(ticker); //TODO: reuse positions/nodes? String longName = underlyingSecurity == null ? "" : underlyingSecurity.getName(); String formattedName = MessageFormatter.format("[{}] {}", underlying, longName); ManageablePortfolioNode equityNode = new ManageablePortfolioNode(formattedName); BigDecimal underlyingAmount = VALUE_OF_UNDERLYING.divide(BigDecimal.valueOf(estimatedCurrentStrike), BigDecimal.ROUND_HALF_EVEN); if (includeUnderlying) { addPosition(equityNode, underlyingAmount, ticker); } TreeMap<LocalDate, Set<BloombergTickerParserEQOption>> optionsByExpiry = new TreeMap<LocalDate, Set<BloombergTickerParserEQOption>>(); for (ExternalId optionTicker : optionChain) { s_logger.debug("Got option {}", optionTicker); BloombergTickerParserEQOption optionInfo = BloombergTickerParserEQOption.getOptionParser(optionTicker); s_logger.debug("Got option info {}", optionInfo); LocalDate key = optionInfo.getExpiry(); Set<BloombergTickerParserEQOption> set = optionsByExpiry.get(key); if (set == null) { set = new HashSet<BloombergTickerParserEQOption>(); optionsByExpiry.put(key, set); } set.add(optionInfo); } Set<ExternalId> tickersToLoad = new HashSet<ExternalId>(); BigDecimal expiryCount = BigDecimal.valueOf(expiries.length); BigDecimal defaultAmountAtExpiry = underlyingAmount.divide(expiryCount, BigDecimal.ROUND_DOWN); BigDecimal spareAmountAtExpiry = defaultAmountAtExpiry.add(BigDecimal.ONE); int spareCount = underlyingAmount.subtract(defaultAmountAtExpiry.multiply(expiryCount)).intValue(); for (int i = 0; i < expiries.length; i++) { Period bucketPeriod = expiries[i]; ManageablePortfolioNode bucketNode = new ManageablePortfolioNode(bucketPeriod.toString().substring(1)); LocalDate nowish = LocalDate.now().withDayOfMonth(20); //This avoids us picking different options every time this script is run LocalDate targetExpiry = nowish.plus(bucketPeriod); LocalDate chosenExpiry = optionsByExpiry.floorKey(targetExpiry); if (chosenExpiry == null) { s_logger.warn("No options for {} on {}", targetExpiry, underlying); continue; } s_logger.info("Using time {} for bucket {} ({})", new Object[] { chosenExpiry, bucketPeriod, targetExpiry }); Set<BloombergTickerParserEQOption> optionsAtExpiry = optionsByExpiry.get(chosenExpiry); TreeMap<Double, Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>> optionsByStrike = new TreeMap<Double, Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>>(); for (BloombergTickerParserEQOption option : optionsAtExpiry) { // s_logger.info("option {}", option); double key = option.getStrike(); Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption> pair = optionsByStrike.get(key); if (pair == null) { pair = Pair.of(null, null); } if (option.getOptionType() == OptionType.CALL) { pair = Pair.of(option, pair.getSecond()); } else { pair = Pair.of(pair.getFirst(), option); } optionsByStrike.put(key, pair); } //cascading collar? BigDecimal amountAtExpiry = spareCount-- > 0 ? spareAmountAtExpiry : defaultAmountAtExpiry; s_logger.info(" est strike {}", estimatedCurrentStrike); Double[] strikes = optionsByStrike.keySet().toArray(new Double[0]); int strikeIndex = Arrays.binarySearch(strikes, estimatedCurrentStrike); if (strikeIndex < 0) { strikeIndex = -(1 + strikeIndex); } s_logger.info("strikes length {} index {} strike of index {}", new Object[] { Integer.valueOf(strikes.length), Integer.valueOf(strikeIndex), Double.valueOf(strikes[strikeIndex]) }); int minIndex = strikeIndex - _numOptions; minIndex = Math.max(0, minIndex); int maxIndex = strikeIndex + _numOptions; maxIndex = Math.min(strikes.length - 1, maxIndex); s_logger.info("min {} max {}", Integer.valueOf(minIndex), Integer.valueOf(maxIndex)); StringBuffer sb = new StringBuffer("strikes: ["); for (int j = minIndex; j <= maxIndex; j++) { sb.append(" "); sb.append(strikes[j]); } sb.append(" ]"); s_logger.info(sb.toString()); //Short Calls ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>> calls = new ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>>(); for (int j = minIndex; j < strikeIndex; j++) { Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption> pair = optionsByStrike .get(strikes[j]); if (pair == null) { throw new OpenGammaRuntimeException("no pair for strike" + strikes[j]); } calls.add(pair); } spreadOptions(bucketNode, calls, OptionType.CALL, -1, tickersToLoad, amountAtExpiry, includeUnderlying, calls.size()); // Long Puts ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>> puts = new ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>>(); for (int j = strikeIndex + 1; j <= maxIndex; j++) { Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption> pair = optionsByStrike .get(strikes[j]); if (pair == null) { throw new OpenGammaRuntimeException("no pair for strike" + strikes[j]); } puts.add(pair); } spreadOptions(bucketNode, puts, OptionType.PUT, 1, tickersToLoad, amountAtExpiry, includeUnderlying, puts.size()); if (bucketNode.getChildNodes().size() + bucketNode.getPositionIds().size() > 0) { equityNode.addChildNode(bucketNode); //Avoid generating empty nodes } } for (ExternalId optionTicker : tickersToLoad) { ManageableSecurity loaded = getOrLoadSecurity(optionTicker); if (loaded == null) { throw new OpenGammaRuntimeException("Unexpected option type " + loaded); } //TODO [LAPANA-29] Should be able to do this for index options too if (includeUnderlying) { try { HistoricalTimeSeriesInfoDocument loadedTs = getOrLoadTimeSeries(optionTicker, loaded.getExternalIdBundle()); if (loadedTs == null) { throw new OpenGammaRuntimeException("Failed to get time series for " + loaded); } } catch (Exception ex) { s_logger.error("Failed to get time series for " + loaded, ex); } } } if (equityNode.getPositionIds().size() + equityNode.getChildNodes().size() > 0) { rootNode.addChildNode(equityNode); } }
From source file:com.opengamma.examples.bloomberg.loader.DemoEquityOptionCollarPortfolioLoader.java
private void addNodes(final ManageablePortfolioNode rootNode, final String underlying, final boolean includeUnderlying, final Period[] expiries) { final ExternalId ticker = ExternalSchemes.bloombergTickerSecurityId(underlying); ManageableSecurity underlyingSecurity = null; if (includeUnderlying) { underlyingSecurity = getOrLoadEquity(ticker); }/*from w w w .ja v a 2 s . com*/ final ExternalIdBundle bundle = underlyingSecurity == null ? ExternalIdBundle.of(ticker) : underlyingSecurity.getExternalIdBundle(); final HistoricalTimeSeriesInfoDocument timeSeriesInfo = getOrLoadTimeSeries(ticker, bundle); final double estimatedCurrentStrike = getOrLoadMostRecentPoint(timeSeriesInfo); final Set<ExternalId> optionChain = getOptionChain(ticker); //TODO: reuse positions/nodes? final String longName = underlyingSecurity == null ? "" : underlyingSecurity.getName(); final String formattedName = MessageFormatter.format("[{}] {}", underlying, longName).getMessage(); final ManageablePortfolioNode equityNode = new ManageablePortfolioNode(formattedName); final BigDecimal underlyingAmount = VALUE_OF_UNDERLYING.divide(BigDecimal.valueOf(estimatedCurrentStrike), BigDecimal.ROUND_HALF_EVEN); if (includeUnderlying) { addPosition(equityNode, underlyingAmount, ticker); } final TreeMap<LocalDate, Set<BloombergTickerParserEQOption>> optionsByExpiry = new TreeMap<LocalDate, Set<BloombergTickerParserEQOption>>(); for (final ExternalId optionTicker : optionChain) { s_logger.debug("Got option {}", optionTicker); final BloombergTickerParserEQOption optionInfo = BloombergTickerParserEQOption .getOptionParser(optionTicker); s_logger.debug("Got option info {}", optionInfo); final LocalDate key = optionInfo.getExpiry(); Set<BloombergTickerParserEQOption> set = optionsByExpiry.get(key); if (set == null) { set = new HashSet<BloombergTickerParserEQOption>(); optionsByExpiry.put(key, set); } set.add(optionInfo); } final Set<ExternalId> tickersToLoad = new HashSet<ExternalId>(); final BigDecimal expiryCount = BigDecimal.valueOf(expiries.length); final BigDecimal defaultAmountAtExpiry = underlyingAmount.divide(expiryCount, BigDecimal.ROUND_DOWN); final BigDecimal spareAmountAtExpiry = defaultAmountAtExpiry.add(BigDecimal.ONE); int spareCount = underlyingAmount.subtract(defaultAmountAtExpiry.multiply(expiryCount)).intValue(); for (final Period bucketPeriod : expiries) { final ManageablePortfolioNode bucketNode = new ManageablePortfolioNode( bucketPeriod.toString().substring(1)); final LocalDate nowish = LocalDate.now().withDayOfMonth(20); //This avoids us picking different options every time this script is run final LocalDate targetExpiry = nowish.plus(bucketPeriod); final LocalDate chosenExpiry = optionsByExpiry.floorKey(targetExpiry); if (chosenExpiry == null) { s_logger.info("No options for {} on {}", targetExpiry, underlying); continue; } s_logger.info("Using time {} for bucket {} ({})", new Object[] { chosenExpiry, bucketPeriod, targetExpiry }); final Set<BloombergTickerParserEQOption> optionsAtExpiry = optionsByExpiry.get(chosenExpiry); final TreeMap<Double, Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>> optionsByStrike = new TreeMap<>(); for (final BloombergTickerParserEQOption option : optionsAtExpiry) { // s_logger.info("option {}", option); final double key = option.getStrike(); Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption> pair = optionsByStrike.get(key); if (pair == null) { pair = Pair.of(null, null); } if (option.getOptionType() == OptionType.CALL) { pair = Pair.of(option, pair.getSecond()); } else { pair = Pair.of(pair.getFirst(), option); } optionsByStrike.put(key, pair); } //cascading collar? final BigDecimal amountAtExpiry = spareCount-- > 0 ? spareAmountAtExpiry : defaultAmountAtExpiry; s_logger.info(" est strike {}", estimatedCurrentStrike); final Double[] strikes = optionsByStrike.keySet().toArray(new Double[0]); int strikeIndex = Arrays.binarySearch(strikes, estimatedCurrentStrike); if (strikeIndex < 0) { strikeIndex = -(1 + strikeIndex); } s_logger.info("strikes length {} index {} strike of index {}", new Object[] { Integer.valueOf(strikes.length), Integer.valueOf(strikeIndex), Double.valueOf(strikes[strikeIndex]) }); int minIndex = strikeIndex - _numOptions; minIndex = Math.max(0, minIndex); int maxIndex = strikeIndex + _numOptions; maxIndex = Math.min(strikes.length - 1, maxIndex); s_logger.info("min {} max {}", Integer.valueOf(minIndex), Integer.valueOf(maxIndex)); final StringBuffer sb = new StringBuffer("strikes: ["); for (int j = minIndex; j <= maxIndex; j++) { sb.append(" "); sb.append(strikes[j]); } sb.append(" ]"); s_logger.info(sb.toString()); //Short Calls final ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>> calls = new ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>>(); for (int j = minIndex; j < strikeIndex; j++) { final Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption> pair = optionsByStrike .get(strikes[j]); if (pair == null) { throw new OpenGammaRuntimeException("no pair for strike" + strikes[j]); } calls.add(pair); } spreadOptions(bucketNode, calls, OptionType.CALL, -1, tickersToLoad, amountAtExpiry, includeUnderlying, calls.size()); // Long Puts final ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>> puts = new ArrayList<Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption>>(); for (int j = strikeIndex + 1; j <= maxIndex; j++) { final Pair<BloombergTickerParserEQOption, BloombergTickerParserEQOption> pair = optionsByStrike .get(strikes[j]); if (pair == null) { throw new OpenGammaRuntimeException("no pair for strike" + strikes[j]); } puts.add(pair); } spreadOptions(bucketNode, puts, OptionType.PUT, 1, tickersToLoad, amountAtExpiry, includeUnderlying, puts.size()); if (bucketNode.getChildNodes().size() + bucketNode.getPositionIds().size() > 0) { equityNode.addChildNode(bucketNode); //Avoid generating empty nodes } } for (final ExternalId optionTicker : tickersToLoad) { final ManageableSecurity loaded = getOrLoadSecurity(optionTicker); if (loaded == null) { throw new OpenGammaRuntimeException("Unexpected option type " + loaded); } //TODO [LAPANA-29] Should be able to do this for index options too if (includeUnderlying) { try { final HistoricalTimeSeriesInfoDocument loadedTs = getOrLoadTimeSeries(optionTicker, loaded.getExternalIdBundle()); if (loadedTs == null) { throw new OpenGammaRuntimeException("Failed to get time series for " + loaded); } } catch (final Exception ex) { s_logger.info("Failed to get time series for " + loaded, ex); } } } if (equityNode.getPositionIds().size() + equityNode.getChildNodes().size() > 0) { rootNode.addChildNode(equityNode); } }
From source file:org.egov.stms.web.controller.masters.SewerageRateMasterController.java
@RequestMapping(value = "/getseweragerates/{id}", method = RequestMethod.GET) public String getSeweragerates(@PathVariable("id") final Long id, final Model model) { final SewerageRatesMaster sewerageRatesMaster = sewerageRatesMasterService.findBy(id); if (getAppconfigValue() != null && !getAppconfigValue()) { for (final SewerageRatesMasterDetails swdm : sewerageRatesMaster.getSewerageDetailmaster()) swdm.setAmount(// w w w.j a v a 2s . c o m BigDecimal.valueOf(swdm.getAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); Collections.sort(sewerageRatesMaster.getSewerageDetailmaster(), new SewerageRateComparatorOrderById()); } model.addAttribute(SEWERAGE_RATES_MASTER, sewerageRatesMaster); if (getAppconfigValue()) return "sewerageRates-success"; else return "seweragemonthlyRates-success"; }
From source file:org.egov.adtax.service.notice.AdvertisementNoticeService.java
private Map<String, Object> buildParametersForDemandDetails( final AdvertisementPermitDetail advertisementPermitDetail) { final Map<String, Object> reportParams = new HashMap<>(); BigDecimal curntInsAdvertisement = BigDecimal.ZERO; BigDecimal curntInsEncrocFee = BigDecimal.ZERO; BigDecimal curntInsPenaltyFee = BigDecimal.ZERO; BigDecimal curntInsServiceTax = BigDecimal.ZERO; BigDecimal curntInsSwachBharatCess = BigDecimal.ZERO; BigDecimal curntInsKrishiKalyanCess = BigDecimal.ZERO; BigDecimal curntInsTotalTaxableAmt = BigDecimal.ZERO; BigDecimal curntInsNetTotal;// w ww . j a va 2 s.c o m BigDecimal arrInsNetTotal; BigDecimal arrInsGrossTotal; BigDecimal curntInsGrossTotal; BigDecimal arrInsAdvertisement = BigDecimal.ZERO; BigDecimal arrInsEncrocFee = BigDecimal.ZERO; BigDecimal arrInsPenaltyFee = BigDecimal.ZERO; BigDecimal arrInsServiceTax = BigDecimal.ZERO; BigDecimal arrInsSwachBharatCess = BigDecimal.ZERO; BigDecimal arrInsKrishiKalyanCess = BigDecimal.ZERO; BigDecimal arrInsTotalTaxableAmt = BigDecimal.ZERO; String previousInstallmentDesc = null; Installment currentInstallemnt = advertisementPermitDetail.getAdvertisement().getDemandId() .getEgInstallmentMaster(); List<Installment> previousInstallemnt = advertisementDemandService .getPreviousInstallment(currentInstallemnt.getFromDate()); Map<Installment, BigDecimal> penaltyAmountMap = advertisementPenaltyCalculator .getPenaltyByInstallment(advertisementPermitDetail); final Map<String, BigDecimal> additionalTaxes = new HashMap<>(); final List<AdvertisementAdditionalTaxRate> additionalTaxRates = advertisementAdditinalTaxRateService .getAllActiveAdditinalTaxRates(); if (previousInstallemnt.isEmpty()) { String currentFinYear = currentInstallemnt.getFinYearRange(); String[] currentFinYearValues = currentFinYear.split("-"); Integer from = Integer.parseInt(currentFinYearValues[0]) - 1; Integer to = Integer.parseInt(currentFinYearValues[1]) - 1; previousInstallmentDesc = from.toString() + "-" + to.toString(); } for (final AdvertisementAdditionalTaxRate taxRates : additionalTaxRates) additionalTaxes.put(taxRates.getReasonCode(), taxRates.getPercentage()); for (final EgDemandDetails demandDtl : advertisementPermitDetail.getAdvertisement().getDemandId() .getEgDemandDetails()) { if (demandDtl.getBalance().compareTo(BigDecimal.ZERO) > 0) { if (currentInstallemnt != null && currentInstallemnt.getDescription() .equals(demandDtl.getEgDemandReason().getEgInstallmentMaster().getDescription())) { if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_ARREAR_ADVERTISEMENTTAX)) { arrInsAdvertisement = arrInsAdvertisement.add(demandDtl.getBalance()); arrInsTotalTaxableAmt = arrInsTotalTaxableAmt.add(demandDtl.getBalance()); } else if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_ADVERTISEMENTTAX)) { curntInsAdvertisement = curntInsAdvertisement.add(demandDtl.getBalance()); reportParams.put("curntInsAdvertisement", curntInsAdvertisement.setScale(2, BigDecimal.ROUND_HALF_EVEN)); curntInsTotalTaxableAmt = curntInsTotalTaxableAmt.add(demandDtl.getBalance()); } else if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_ENCROCHMENTFEE)) { curntInsEncrocFee = demandDtl.getBalance(); reportParams.put("curntInsEncrocFee", curntInsEncrocFee.setScale(2, BigDecimal.ROUND_HALF_EVEN)); curntInsTotalTaxableAmt = curntInsTotalTaxableAmt.add(curntInsEncrocFee); } else if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_PENALTY)) { curntInsPenaltyFee = demandDtl.getBalance(); reportParams.put("curntInsPenaltyFee", curntInsPenaltyFee.setScale(2, BigDecimal.ROUND_HALF_EVEN)); } } else { if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_ARREAR_ADVERTISEMENTTAX) || demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_ADVERTISEMENTTAX)) { arrInsAdvertisement = arrInsAdvertisement.add(demandDtl.getBalance()); reportParams.put("arrInsAdvertisement", arrInsAdvertisement.setScale(2, BigDecimal.ROUND_HALF_EVEN)); arrInsTotalTaxableAmt = arrInsTotalTaxableAmt.add(demandDtl.getBalance()); } else if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_ENCROCHMENTFEE)) { arrInsEncrocFee = arrInsEncrocFee.add(demandDtl.getBalance()); reportParams.put("arrInsEncrocFee", arrInsEncrocFee.setScale(2, BigDecimal.ROUND_HALF_EVEN)); arrInsTotalTaxableAmt = arrInsTotalTaxableAmt.add(demandDtl.getBalance()); } else if (demandDtl.getEgDemandReason().getEgDemandReasonMaster().getCode() .equalsIgnoreCase(DEMANDREASON_PENALTY)) { arrInsPenaltyFee = arrInsPenaltyFee.add(demandDtl.getBalance()); reportParams.put("arrInsPenaltyFee", arrInsPenaltyFee.setScale(2, BigDecimal.ROUND_HALF_EVEN)); } } } } // Add penalty into reports for (final Map.Entry<Installment, BigDecimal> penaltyMap : penaltyAmountMap.entrySet()) if (currentInstallemnt != null && currentInstallemnt.getDescription().equalsIgnoreCase(penaltyMap.getKey().getDescription())) { curntInsPenaltyFee = curntInsPenaltyFee.add(penaltyMap.getValue()); reportParams.put("curntInsPenaltyFee", curntInsPenaltyFee); } else { arrInsPenaltyFee = arrInsPenaltyFee.add(penaltyMap.getValue()); reportParams.put("arrInsPenaltyFee", arrInsPenaltyFee); } for (final Map.Entry<String, BigDecimal> entry : additionalTaxes.entrySet()) { if ("Service_Tax".equalsIgnoreCase(entry.getKey())) { curntInsServiceTax = calculateAdditionalTaxes(curntInsTotalTaxableAmt, entry.getValue()); arrInsServiceTax = calculateAdditionalTaxes(arrInsTotalTaxableAmt, entry.getValue()); } else if ("ADTAX_SB_CESS".equalsIgnoreCase(entry.getKey())) { curntInsSwachBharatCess = calculateAdditionalTaxes(curntInsTotalTaxableAmt, entry.getValue()); arrInsSwachBharatCess = calculateAdditionalTaxes(arrInsTotalTaxableAmt, entry.getValue()); } else if ("ADTAX_KRISHI_CES".equalsIgnoreCase(entry.getKey())) { curntInsKrishiKalyanCess = calculateAdditionalTaxes(curntInsTotalTaxableAmt, entry.getValue()); arrInsKrishiKalyanCess = calculateAdditionalTaxes(arrInsTotalTaxableAmt, entry.getValue()); } } // set additional taxes details and installment reportParams.put("currentInstallmentDesc", currentInstallemnt.getDescription()); reportParams.put("previousInstallmentDesc", previousInstallemnt.isEmpty() ? previousInstallmentDesc : previousInstallemnt.get(0).getDescription()); reportParams.put("curntInsServiceTax", curntInsServiceTax.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("curntInsKrishiKalyanCess", curntInsKrishiKalyanCess.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("curntInsSwachBharatCess", curntInsSwachBharatCess.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("arrInsServiceTax", arrInsServiceTax.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("arrInsSwachBharatCess", arrInsSwachBharatCess.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("arrInsKrishiKalyanCess", arrInsKrishiKalyanCess.setScale(2, BigDecimal.ROUND_HALF_EVEN)); // sum demand details reportParams.put("curntInsTotalTaxableAmt", curntInsTotalTaxableAmt.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("arrInsTotalTaxableAmt", arrInsTotalTaxableAmt.setScale(2, BigDecimal.ROUND_HALF_EVEN)); curntInsGrossTotal = curntInsTotalTaxableAmt.add(curntInsServiceTax).add(curntInsSwachBharatCess) .add(curntInsKrishiKalyanCess); reportParams.put("curntInsGrossTotal", curntInsGrossTotal.setScale(2, BigDecimal.ROUND_HALF_EVEN)); curntInsNetTotal = curntInsGrossTotal.add(curntInsPenaltyFee); reportParams.put("curntInsNetTotal", curntInsNetTotal.setScale(2, BigDecimal.ROUND_HALF_EVEN)); arrInsGrossTotal = arrInsTotalTaxableAmt.add(arrInsServiceTax).add(arrInsSwachBharatCess) .add(arrInsKrishiKalyanCess); reportParams.put("arrInsGrossTotal", arrInsGrossTotal.setScale(2, BigDecimal.ROUND_HALF_EVEN)); arrInsNetTotal = arrInsGrossTotal.add(arrInsPenaltyFee); reportParams.put("arrInsNetTotal", arrInsNetTotal.setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("advertisementTaxSum", curntInsAdvertisement.add(arrInsAdvertisement).setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("encrochmentFeeSum", curntInsEncrocFee.add(arrInsEncrocFee).setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("serviceTaxSum", curntInsServiceTax.add(arrInsServiceTax).setScale(0, BigDecimal.ROUND_HALF_UP)); reportParams.put("swachBharatCessSum", curntInsSwachBharatCess.add(arrInsSwachBharatCess).setScale(0, BigDecimal.ROUND_HALF_UP)); reportParams.put("krishiKalyanCessSum", curntInsKrishiKalyanCess.add(arrInsKrishiKalyanCess).setScale(0, BigDecimal.ROUND_HALF_UP)); reportParams.put("penalitySum", curntInsPenaltyFee.add(arrInsPenaltyFee).setScale(2, BigDecimal.ROUND_HALF_EVEN)); reportParams.put("adParticular", advertisementPermitDetail.getAdvertisementParticular()); reportParams.put("durationOfAdvt", advertisementPermitDetail.getAdvertisementDuration()); reportParams.put("class", advertisementPermitDetail.getAdvertisement().getRateClass().getDescription()); reportParams.put("revenueWard", advertisementPermitDetail.getAdvertisement().getWard().getName()); reportParams.put("electionWard", advertisementPermitDetail.getAdvertisement().getElectionWard() != null ? advertisementPermitDetail.getAdvertisement().getElectionWard().getName() : ""); return reportParams; }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
private String percentage(double numer, double denom) { return new BigDecimal(numer / denom * 100).setScale(2, BigDecimal.ROUND_HALF_EVEN).toPlainString() + "%"; }
From source file:org.egov.egf.web.actions.report.BillRegisterReportAction.java
@SuppressWarnings("unused") protected void formatSearchResult() throws Exception { if (LOGGER.isDebugEnabled()) LOGGER.debug("BillRegisterReportAction | formatSearchResult | start"); billRegReportList = new ArrayList<BillRegisterReportBean>(); final EgovPaginatedList egovPaginatedList = (EgovPaginatedList) searchResult; final List<Object[]> list = egovPaginatedList.getList(); if (LOGGER.isDebugEnabled()) LOGGER.debug("BillRegisterReportAction | formatSearchResult | list size : " + list.size()); for (final Object[] object : list) try {//from ww w. ja v a2 s .com final BillRegisterReportBean billRegReport = new BillRegisterReportBean(); billRegReport.setBillNumber(object[0].toString()); billRegReport.setVoucherNumber(object[1] != null ? object[1].toString() : ""); billRegReport.setPartyName(object[2] != null ? object[2].toString() : ""); billRegReport.setGrossAmount(null != object[3] ? new BigDecimal(object[3].toString()).setScale(2, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_EVEN)); billRegReport.setNetAmount(null != object[4] ? new BigDecimal(object[4].toString()).setScale(2, BigDecimal.ROUND_HALF_EVEN) : BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_EVEN)); billRegReport .setDeductionAmount(billRegReport.getGrossAmount().subtract(billRegReport.getNetAmount())); billRegReport.setStatus(null != object[5] ? object[5].toString().toUpperCase() : ""); billRegReport.setBillDate(DDMMYYYYFORMATS.format((Date) object[6])); if (!StringUtils.isEmpty(billRegReport.getVoucherNumber())) { final List<Miscbilldetail> miscBillList = persistenceService.findAllBy( " from Miscbilldetail mis where mis.billnumber=? " + " and mis.billVoucherHeader.voucherNumber=?", billRegReport.getBillNumber(), billRegReport.getVoucherNumber()); if (null != miscBillList && miscBillList.size() > 0) { BigDecimal paidAmount = null; final StringBuffer payMentVoucherNumber = new StringBuffer(""); final StringBuffer chequeNoAndDate = new StringBuffer(""); preVoucherId = miscBillList.get(0).getPayVoucherHeader().getId(); for (final Miscbilldetail miscbilldetail : miscBillList) { if (null != miscbilldetail.getPayVoucherHeader() && (miscbilldetail.getPayVoucherHeader().getStatus() .equals(Integer.valueOf(FinancialConstants.CREATEDVOUCHERSTATUS)) || miscbilldetail.getPayVoucherHeader().getStatus().equals( Integer.valueOf(FinancialConstants.PREAPPROVEDVOUCHERSTATUS)))) if (!StringUtils.isEmpty(payMentVoucherNumber.toString())) { payMentVoucherNumber.append("|") .append(miscbilldetail.getPayVoucherHeader().getVoucherNumber()); paidAmount = paidAmount.add(miscbilldetail.getPaidamount()).setScale(2, BigDecimal.ROUND_HALF_EVEN); final Paymentheader paymentMode = (Paymentheader) persistenceService.find( "from Paymentheader where voucherheader=?", miscbilldetail.getPayVoucherHeader()); if (!paymentMode.getType().equals(FinancialConstants.MODEOFPAYMENT_RTGS)) { final Query qry = persistenceService.getSession().createQuery( "from InstrumentVoucher iv where iv.voucherHeaderId.id=:vhId and" + " iv.instrumentHeaderId.statusId.id not in(:cancelledChequeList)"); qry.setLong("vhId", miscbilldetail.getPayVoucherHeader().getId()); qry.setParameterList("cancelledChequeList", cancelledChequeStatus); final List<InstrumentVoucher> instrumentVoucherList = qry.list(); if (instrumentVoucherList.size() > 0) for (final InstrumentVoucher inst : instrumentVoucherList) // chequeStatus=inst.getInstrumentHeaderId().getStatusId().getId(); // if(!cancelledChequeStatus.contains(chequeStatus)){ if (!StringUtils.isEmpty(chequeNoAndDate.toString())) { if (preVoucherId.equals(inst.getVoucherHeaderId().getId())) chequeNoAndDate.append(chqdelimitSP) .append(inst.getInstrumentHeaderId() .getInstrumentNumber()) .append(" ") .append(DDMMYYYYFORMATS .format(inst.getInstrumentHeaderId() .getInstrumentDate())); else chequeNoAndDate.append(chqdelimitDP) .append(inst.getInstrumentHeaderId() .getInstrumentNumber()) .append(" ") .append(DDMMYYYYFORMATS .format(inst.getInstrumentHeaderId() .getInstrumentDate())); } else chequeNoAndDate .append(inst.getInstrumentHeaderId() .getInstrumentNumber()) .append(" ").append(DDMMYYYYFORMATS.format(inst .getInstrumentHeaderId().getInstrumentDate())); } else { final Query qry = persistenceService.getSession().createQuery( "from InstrumentVoucher iv where iv.voucherHeaderId.id=:vhId and" + " iv.instrumentHeaderId.statusId.id not in(:cancelledChequeList)"); qry.setLong("vhId", miscbilldetail.getPayVoucherHeader().getId()); qry.setParameterList("cancelledChequeList", cancelledChequeStatus); final List<InstrumentVoucher> instrumentVoucherList = qry.list(); if (instrumentVoucherList.size() > 0) for (final InstrumentVoucher inst : instrumentVoucherList) if (!StringUtils.isEmpty(chequeNoAndDate.toString())) { if (preVoucherId.equals(inst.getVoucherHeaderId().getId())) chequeNoAndDate.append(chqdelimitSP) .append(inst.getInstrumentHeaderId() .getTransactionNumber() != null ? inst.getInstrumentHeaderId() .getTransactionNumber() : "") .append(" ") .append(inst.getInstrumentHeaderId() .getTransactionDate() != null ? DDMMYYYYFORMATS.format(inst .getInstrumentHeaderId() .getTransactionDate()) : ""); else chequeNoAndDate.append(chqdelimitDP) .append(inst.getInstrumentHeaderId() .getTransactionNumber() != null ? inst.getInstrumentHeaderId() .getTransactionNumber() : "") .append(" ") .append(inst.getInstrumentHeaderId() .getTransactionDate() != null ? DDMMYYYYFORMATS.format(inst .getInstrumentHeaderId() .getTransactionDate()) : ""); } else chequeNoAndDate .append(inst.getInstrumentHeaderId() .getTransactionNumber() != null ? inst.getInstrumentHeaderId() .getTransactionNumber() : "") .append(" ") .append(inst.getInstrumentHeaderId() .getTransactionDate() != null ? DDMMYYYYFORMATS .format(inst.getInstrumentHeaderId() .getTransactionDate()) : ""); } } else { paidAmount = miscbilldetail.getPaidamount().setScale(2, BigDecimal.ROUND_HALF_EVEN); payMentVoucherNumber .append(miscbilldetail.getPayVoucherHeader().getVoucherNumber()); final Paymentheader paymentMode = (Paymentheader) persistenceService.find( "from Paymentheader where voucherheader=?", miscbilldetail.getPayVoucherHeader()); if (!paymentMode.getType().equals(FinancialConstants.MODEOFPAYMENT_RTGS)) { // List<InstrumentVoucher> // instrumentVoucherList=(List<InstrumentVoucher>)persistenceService.findAllBy(" from InstrumentVoucher where voucherHeaderId=?", // miscbilldetail.getPayVoucherHeader()); final Query qry = persistenceService.getSession().createQuery( "from InstrumentVoucher iv where iv.voucherHeaderId.id=:vhId and" + " iv.instrumentHeaderId.statusId.id not in(:cancelledChequeList)"); qry.setLong("vhId", miscbilldetail.getPayVoucherHeader().getId()); qry.setParameterList("cancelledChequeList", cancelledChequeStatus); final List<InstrumentVoucher> instrumentVoucherList = qry.list(); if (instrumentVoucherList.size() > 0) for (final InstrumentVoucher inst : instrumentVoucherList) if (!StringUtils.isEmpty(chequeNoAndDate.toString())) { if (preVoucherId.equals(inst.getVoucherHeaderId().getId())) chequeNoAndDate.append(chqdelimitSP) .append(inst.getInstrumentHeaderId() .getInstrumentNumber()) .append(" ") .append(DDMMYYYYFORMATS .format(inst.getInstrumentHeaderId() .getInstrumentDate())); else chequeNoAndDate.append(chqdelimitDP).append( inst.getInstrumentHeaderId().getInstrumentNumber()) .append(" ") .append(inst.getInstrumentHeaderId() .getInstrumentDate() != null ? DDMMYYYYFORMATS.format(inst .getInstrumentHeaderId() .getInstrumentDate()) : ""); } else chequeNoAndDate .append(inst .getInstrumentHeaderId().getInstrumentNumber()) .append(" ") .append(inst.getInstrumentHeaderId() .getInstrumentDate() != null ? DDMMYYYYFORMATS .format(inst.getInstrumentHeaderId() .getInstrumentDate()) : ""); } else { final Query qry = persistenceService.getSession().createQuery( "from InstrumentVoucher iv where iv.voucherHeaderId.id=:vhId and" + " iv.instrumentHeaderId.statusId.id not in(:cancelledChequeList)"); qry.setLong("vhId", miscbilldetail.getPayVoucherHeader().getId()); qry.setParameterList("cancelledChequeList", cancelledChequeStatus); final List<InstrumentVoucher> instrumentVoucherList = qry.list(); if (instrumentVoucherList.size() > 0) for (final InstrumentVoucher inst : instrumentVoucherList) if (!StringUtils.isEmpty(chequeNoAndDate.toString())) { if (preVoucherId.equals(inst.getVoucherHeaderId().getId())) chequeNoAndDate.append(chqdelimitSP) .append(inst.getInstrumentHeaderId() .getTransactionNumber() != null ? inst.getInstrumentHeaderId() .getTransactionNumber() : "") .append(" ") .append(inst.getInstrumentHeaderId() .getTransactionDate() != null ? DDMMYYYYFORMATS.format(inst .getInstrumentHeaderId() .getTransactionDate()) : ""); else chequeNoAndDate.append(chqdelimitDP) .append(inst.getInstrumentHeaderId() .getTransactionNumber() != null ? inst.getInstrumentHeaderId() .getTransactionNumber() : "") .append(" ") .append(inst.getInstrumentHeaderId() .getTransactionDate() != null ? DDMMYYYYFORMATS.format(inst .getInstrumentHeaderId() .getTransactionDate()) : ""); } else chequeNoAndDate .append(inst.getInstrumentHeaderId() .getTransactionNumber() != null ? inst.getInstrumentHeaderId() .getTransactionNumber() : "") .append(" ") .append(inst.getInstrumentHeaderId() .getTransactionDate() != null ? DDMMYYYYFORMATS .format(inst.getInstrumentHeaderId() .getTransactionDate()) : ""); } } preVoucherId = miscbilldetail.getPayVoucherHeader().getId(); if (isCompleteBillRegisterReport) getRemittancePaymentDetail(billRegReport); } billRegReport.setPaidAmount(paidAmount); billRegReport.setPaymentVoucherNumber(payMentVoucherNumber.toString()); billRegReport.setChequeNumAndDate(chequeNoAndDate.toString()); } else if (isCompleteBillRegisterReport) getRemittancePaymentDetail(billRegReport); } billRegReportList.add(billRegReport); } catch (final Exception e) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Failed while processing bill number :" + object[0].toString()); throw e; } egovPaginatedList.setList(billRegReportList); }