List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:com.mb.ext.core.service.impl.UserServiceImpl.java
@Override public BigDecimal getTotalTransferAmountByUser(String loginId) throws BusinessException { BigDecimal totalAmount = new BigDecimal(0); try {/* w ww.j ava 2s .c om*/ List<TransferDTO> transferEntityList = getTransfersByUser(loginId); for (Iterator<TransferDTO> iterator = transferEntityList.iterator(); iterator.hasNext();) { BigDecimal amount = iterator.next().getAmount(); totalAmount = totalAmount.add(amount); } } catch (BusinessException e) { throw e; } return totalAmount; }
From source file:com.autentia.intra.bean.billing.BillBean.java
private void calcTotals(List<Bill> res) { BigDecimal valor = new BigDecimal(0); BigDecimal valorNoTaxes = new BigDecimal(0); for (Bill elem : res) { valor = valor.add(elem.getTotal()); valorNoTaxes = valorNoTaxes.add(elem.getTotalNoTaxes()); }//from w w w . j a va 2 s . c om setTotals(valor); setTotalsNoTaxes(valorNoTaxes); setTotalsTaxes(valor.subtract(valorNoTaxes)); }
From source file:net.sourceforge.fenixedu.domain.Teacher.java
public BigDecimal getProjectsTutorialsCredits(ExecutionYear executionYear) { BigDecimal result = BigDecimal.ZERO; for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { TeacherService teacherService = getTeacherServiceByExecutionPeriod(executionSemester); if (teacherService != null) { for (DegreeProjectTutorialService degreeProjectTutorialService : teacherService .getDegreeProjectTutorialServices()) { result = result.add(degreeProjectTutorialService.getDegreeProjectTutorialServiceCredits()); }//from w w w .j av a 2s .c o m } } return result.setScale(2, BigDecimal.ROUND_HALF_UP); }
From source file:com.shengpay.website.common.service.impl.DepositeLimitServiceImpl.java
@Override public DepositLimitResponse queryLimit(String ptid, String ruleID, BigDecimal currentDepositAmount) { DepositLimitResponse response = new DepositLimitResponse(); DepositLimitDO limitDO = null;//w w w . j a v a 2 s . co m try { limitDO = depositLimitDAO.queryLimitRecordByRule(ruleID); if (null != limitDO) { String productCode = limitDO.getProductCode(); //?? String depositCode = limitDO.getDepositCode(); //? String depositChannel = limitDO.getDepositChannel(); //? Long validTimeType = limitDO.getValidTime(); // 0 1 2 if (null != validTimeType) { response.setValidTimeType(validTimeType.intValue()); } //?? FundsStatQueryRequest request = new FundsStatQueryRequest(); request.setMemberId(ptid); request.setRulePackageId(2L); ProductPaymentPackage[] productGroups = buildProductPaymentPackage(productCode, depositCode, depositChannel); request.setProductGroup(productGroups); StatisPeriodEnum requestStatisPeriodEnum = null; if (0L == validTimeType) { requestStatisPeriodEnum = StatisPeriodEnum.DAY; // } else if (1L == validTimeType) { requestStatisPeriodEnum = StatisPeriodEnum.MONTH; // } else if (2L == validTimeType) { requestStatisPeriodEnum = StatisPeriodEnum.YEAR; // } request.setPeriod(requestStatisPeriodEnum); String sourceCode = "442"; request.setSourceCode(sourceCode); FundsStatQueryResponse fundsStatQueryResponse = fundsStatQueryService.query(request); int limitTimes = -1; BigDecimal limitAmount = null; if (null != fundsStatQueryResponse) { String returnCode = fundsStatQueryResponse.getReturnCode(); if (null != returnCode) { if ("0000".equals(returnCode) || "0002".equals(returnCode)) { try { limitTimes = fundsStatQueryResponse.getStatTimes(); limitAmount = new BigDecimal(fundsStatQueryResponse.getStatResult()); response.setDepositeAmount(limitAmount); } catch (Throwable t) { logger.error("Execute limit amount from FundsStatQueryService.query() make error!", t); } } } } Long timesRule = limitDO.getDepositTimes(); Long amountRule = limitDO.getDepositAmount(); if (null != timesRule) { response.setRuleTimes(timesRule); if (limitTimes >= timesRule) { response.setTimesLimit(Boolean.TRUE); } } if (null != amountRule) { response.setRuleAmount(amountRule); if (null != limitAmount) { if (currentDepositAmount != null) { //??+?? ?? limitAmount = limitAmount.add(currentDepositAmount); } if (limitAmount.doubleValue() > amountRule) { response.setAmountLimit(Boolean.TRUE); } } } response.setSuccess(Boolean.TRUE); } else { response.setSuccess(Boolean.FALSE); response.setErrorMessage("By ruleID[" + ruleID + "] query db is null."); } } catch (Throwable t) { response.setSuccess(Boolean.FALSE); response.setErrorMessage("Not found ruleID [" + ruleID + "]."); logger.error("execute query depositlimit make error!", t); } return response; }
From source file:net.sourceforge.fenixedu.domain.credits.util.AnnualTeachingCreditsBean.java
public void calculateCredits() { masterDegreeThesesCredits = teacher.getMasterDegreeThesesCredits(executionYear); phdDegreeThesesCredits = teacher.getPhdDegreeThesesCredits(executionYear); projectsTutorialsCredits = teacher.getProjectsTutorialsCredits(executionYear); BigDecimal yearCreditsForFinalCredits = BigDecimal.ZERO; BigDecimal annualTeachingLoadFinalCredits = BigDecimal.ZERO; boolean hasOrientantionCredits = false; boolean hasFinalAndAccumulatedCredits = false; for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { if (getTeacher().isActiveForSemester(executionSemester) || getTeacher().hasTeacherAuthorization(executionSemester)) { BigDecimal thisSemesterManagementFunctionCredits = new BigDecimal( getTeacher().getManagementFunctionsCredits(executionSemester)); managementFunctionCredits = managementFunctionCredits.add(thisSemesterManagementFunctionCredits); serviceExemptionCredits = serviceExemptionCredits .add(new BigDecimal(getTeacher().getServiceExemptionCredits(executionSemester))); BigDecimal thisSemesterTeachingLoad = new BigDecimal( getTeacher().getMandatoryLessonHours(executionSemester)); annualTeachingLoad = annualTeachingLoad.add(thisSemesterTeachingLoad).setScale(2, BigDecimal.ROUND_HALF_UP); TeacherService teacherService = getTeacher().getTeacherServiceByExecutionPeriod(executionSemester); BigDecimal thisSemesterCreditsReduction = BigDecimal.ZERO; if (teacherService != null) { teachingCredits = teachingCredits .add(new BigDecimal(teacherService.getTeachingDegreeCredits())); thisSemesterCreditsReduction = teacherService.getReductionServiceCredits(); othersCredits = othersCredits.add(new BigDecimal(teacherService.getOtherServiceCredits())); }/*from w w w .java2 s . com*/ creditsReduction = creditsReduction.add(thisSemesterCreditsReduction); BigDecimal reductionAndManagement = thisSemesterManagementFunctionCredits .add(thisSemesterCreditsReduction); BigDecimal thisSemesterYearCredits = thisSemesterTeachingLoad; if (thisSemesterTeachingLoad.compareTo(reductionAndManagement) > 0) { thisSemesterYearCredits = reductionAndManagement; } else { setHasAnyLimitation(true); } yearCredits = yearCredits.add(thisSemesterYearCredits); if (getTeacher().isActiveForSemester(executionSemester) && !getTeacher().isMonitor(executionSemester)) { yearCreditsForFinalCredits = yearCreditsForFinalCredits.add(thisSemesterYearCredits); annualTeachingLoadFinalCredits = annualTeachingLoadFinalCredits.add(thisSemesterTeachingLoad); if (executionSemester.getSemester() == 2) { hasFinalAndAccumulatedCredits = true; } else { hasOrientantionCredits = true; } } } } yearCredits = yearCredits.add(teachingCredits).add(serviceExemptionCredits).add(othersCredits); yearCreditsForFinalCredits = yearCreditsForFinalCredits.add(teachingCredits).add(serviceExemptionCredits) .add(othersCredits); if (hasOrientantionCredits) { yearCredits = yearCredits.add(getMasterDegreeThesesCredits()).add(getPhdDegreeThesesCredits()) .add(getProjectsTutorialsCredits()).setScale(2, BigDecimal.ROUND_HALF_UP); yearCreditsForFinalCredits = yearCreditsForFinalCredits.add(getMasterDegreeThesesCredits()) .add(getPhdDegreeThesesCredits()).add(getProjectsTutorialsCredits()); } if (hasFinalAndAccumulatedCredits) { finalCredits = yearCreditsForFinalCredits.subtract(annualTeachingLoadFinalCredits); BigDecimal lastYearAccumulated = getPreviousAccumulatedCredits(); accumulatedCredits = (finalCredits.add(lastYearAccumulated)).setScale(2, BigDecimal.ROUND_HALF_UP); finalCredits = finalCredits.setScale(2, BigDecimal.ROUND_HALF_UP); } }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractBillingController.java
@RequestMapping(value = { "/usageBilling" }, method = RequestMethod.GET) public String usageBilling(@ModelAttribute("currentTenant") Tenant tenant, @RequestParam(value = "viewBy", required = false) String viewBy, @RequestParam(value = "tenant", required = false) String tenantParam, @RequestParam(value = "page", required = false, defaultValue = "1") String currentPage, @RequestParam(value = "accountStatementUuid", required = false) String accountStatementUuid, @RequestParam(value = "useruuid", required = false, defaultValue = "ALL_USERS") String useruuid, ModelMap map, HttpServletRequest request) { int page;//from ww w .j a va 2 s .co m int perPage; try { page = Integer.parseInt(currentPage); } catch (NumberFormatException nFE) { page = 1; } try { perPage = getDefaultPageSize(); if (perPage > 14) { perPage = 14; } } catch (NumberFormatException nFE) { perPage = 14; } User user = getCurrentUser(); if (tenantService.getSystemTenant().equals(user.getTenant())) { map.addAttribute("isSystemProviderUser", "Y"); } else { map.addAttribute("isSystemProviderUser", "N"); } AccountStatement accountStatement = null; if ((userService.hasAuthority(user, "ROLE_ACCOUNT_CRUD") || userService.hasAuthority(user, "ROLE_ACCOUNT_MGMT")) && (Boolean) request.getAttribute("isSurrogatedTenant")) { tenant = tenantService.get(tenantParam); user = tenant.getOwner(); setPage(map, Page.CRM_USAGE_BILLING); map.addAttribute("userHasCloudServiceAccount", userService.isUserHasAnyActiveCloudService(tenant.getOwner())); map.addAttribute("showUserProfile", true); } else { setPage(map, Page.DASHBOARD_USAGE_BILLING); map.addAttribute("userHasCloudServiceAccount", userService.isUserHasAnyActiveCloudService(user)); } if (accountStatementUuid == null) { accountStatement = billingAdminService.getOrCreateProvisionalAccountStatement(tenant); } else { accountStatement = billingAdminService.getAccountStatement(accountStatementUuid); } List<AccountStatement> accountStatements = billingAdminService.getAccountStatements(tenant, null, page, perPage, null, null, null); map.addAttribute("accountStatements", accountStatements); map.addAttribute("accountStatementUuid", accountStatement.getUuid()); map.addAttribute("accountStatementState", accountStatement.getState().name()); int accStatSize = billingAdminService.countAccountStatements(tenant, null, null); if (accStatSize - page * perPage > 0) { map.addAttribute("enable_next", true); } else { map.addAttribute("enable_next", false); } map.addAttribute("current_page", page); LinkedHashMap<ServiceResourceType, ArrayList<Invoice>> newChargesMap = new LinkedHashMap<ServiceResourceType, ArrayList<Invoice>>(); LinkedHashMap<ServiceResourceType, ArrayList<Invoice>> renewalChargesMap = new LinkedHashMap<ServiceResourceType, ArrayList<Invoice>>(); ArrayList<Invoice> utilityInvoiceList = new ArrayList<Invoice>(); ArrayList<Invoice> newServiceInvoiceList = new ArrayList<Invoice>(); ArrayList<Invoice> renewServiceInvoiceList = new ArrayList<Invoice>(); Set<Invoice> invoices = null; if (StringUtils.isNotBlank(useruuid) && !useruuid.equals("ALL_USERS")) { // if user does not have permission to access somebody else's invoice then change the uuid to his own uuid. if (!userService.hasAuthority(user, "ROLE_ACCOUNT_BILLING_ADMIN")) { useruuid = user.getUuid(); } User filterUser = userService.get(useruuid); invoices = accountStatement.getInvoices(filterUser); map.addAttribute("useruuid", useruuid); } else { if (userService.hasAuthority(user, "ROLE_ACCOUNT_CRUD") || userService.hasAuthority(user, "ROLE_ACCOUNT_MGMT") || userService.hasAuthority(user, "ROLE_ACCOUNT_BILLING_ADMIN")) { invoices = accountStatement.getInvoices(); } else { // For regular user send only their invoices regardless of what they call. invoices = accountStatement.getInvoices(user); } } BigDecimal newBigAmount = BigDecimal.ZERO; BigDecimal newBigDiscount = BigDecimal.ZERO; BigDecimal newBigSubTotal = BigDecimal.ZERO; BigDecimal newBigTax = BigDecimal.ZERO; BigDecimal newBigTotal = BigDecimal.ZERO; BigDecimal renewBigAmount = BigDecimal.ZERO; BigDecimal renewBigDiscount = BigDecimal.ZERO; BigDecimal renewBigSubTotal = BigDecimal.ZERO; BigDecimal renewBigTax = BigDecimal.ZERO; BigDecimal renewBigTotal = BigDecimal.ZERO; for (Invoice invoice : invoices) { if (invoice.getType().equals(com.vmops.model.Invoice.Type.Renewal)) { pushInvoiceToMap(renewalChargesMap, invoice.getSubscription().getProductBundle().getResourceType(), invoice, newServiceInvoiceList, renewServiceInvoiceList); renewBigAmount = renewBigAmount.add(invoice.getRawAmount()); renewBigDiscount = renewBigDiscount.add(invoice.getDiscountAmount()); renewBigSubTotal = renewBigSubTotal.add(invoice.getSubTotal()); renewBigTax = renewBigTax.add(invoice.getTaxAmount()); renewBigTotal = renewBigTotal.add(invoice.getAmount()); } else if (invoice.getType().equals(com.vmops.model.Invoice.Type.Subscription)) { pushInvoiceToMap(newChargesMap, invoice.getSubscription().getProductBundle().getResourceType(), invoice, newServiceInvoiceList, renewServiceInvoiceList); newBigAmount = newBigAmount.add(invoice.getRawAmount()); newBigDiscount = newBigDiscount.add(invoice.getDiscountAmount()); newBigSubTotal = newBigSubTotal.add(invoice.getSubTotal()); newBigTax = newBigTax.add(invoice.getTaxAmount()); newBigTotal = newBigTotal.add(invoice.getAmount()); } else { Collections.sort(invoice.getInvoiceItems()); utilityInvoiceList.add(invoice); newBigAmount = newBigAmount.add(invoice.getRawAmount()); newBigDiscount = newBigDiscount.add(invoice.getDiscountAmount()); newBigSubTotal = newBigSubTotal.add(invoice.getSubTotal()); newBigTax = newBigTax.add(invoice.getTaxAmount()); newBigTotal = newBigTotal.add(invoice.getAmount()); } } Collections.sort(utilityInvoiceList); newChargesMap.put(getNewDummyResourceType(serviceBundleInvoices), newServiceInvoiceList); newChargesMap.put(getNewDummyResourceType(utiltyInvoices), utilityInvoiceList); renewalChargesMap.put(getNewDummyResourceType(serviceBundleInvoices), renewServiceInvoiceList); map.addAttribute("newChargesMap", newChargesMap); map.addAttribute("renewalChargesMap", renewalChargesMap); map.addAttribute("newBigAmount", newBigAmount); map.addAttribute("newBigDiscount", newBigDiscount); map.addAttribute("newBigTax", newBigTax); map.addAttribute("newBigSubTotal", newBigSubTotal); map.addAttribute("newBigTotal", newBigTotal); map.addAttribute("renewBigAmount", renewBigAmount); map.addAttribute("renewBigDiscount", renewBigDiscount); map.addAttribute("renewBigTax", renewBigTax); map.addAttribute("renewBigSubTotal", renewBigSubTotal); map.addAttribute("renewBigTotal", renewBigTotal); map.addAttribute("tenant", tenant); map.addAttribute("user", user); map.addAttribute("accountStatement", accountStatement); map.addAttribute("current_page", page); List<SalesLedgerCreditRecord> creditRecords = accountStatement.getSalesLedgerCreditRecords(); List<SalesLedgerCreditRecord> payments = new ArrayList<SalesLedgerCreditRecord>(); List<SalesLedgerCreditRecord> creditsIssued = new ArrayList<SalesLedgerCreditRecord>(); BigDecimal bigPaymentsSum = BigDecimal.ZERO; for (SalesLedgerCreditRecord creditRecord : creditRecords) { if (!creditRecord.isVoided()) { if (creditRecord.getType().equals(Type.SERVICE_CREDIT)) { creditsIssued.add(creditRecord); } else { payments.add(creditRecord); } bigPaymentsSum = bigPaymentsSum.add(creditRecord.getTransactionAmount()); } } map.addAttribute("payments", payments); map.addAttribute("creditsIssued", creditsIssued); map.addAttribute("bigPaymentsSum", bigPaymentsSum); return "billing.usageBilling"; }
From source file:com.oneops.transistor.ws.rest.TransistorRestController.java
private Map<String, Object> getCostTotals(List<CostData> offerings) { Map<String, Object> map = new HashMap<>(); Map<String, BigDecimal> byCloud = new HashMap<>(); Map<String, BigDecimal> byPlatform = new HashMap<>(); Map<String, BigDecimal> byService = new HashMap<>(); BigDecimal total = BigDecimal.ZERO; for (CostData cost : offerings) { String cloud = cost.getCloud().getCiName(); String[] array = cost.getRfc().getNsPath().split("/"); String platform = ""; if (array.length > 1) { platform = String.join("/", array[array.length - 2], array[array.length - 1]); }//w w w. ja v a 2 s. co m for (CmsCISimple offering : cost.getOfferings()) { BigDecimal rate = new BigDecimal(offering.getCiAttributes().get("cost_rate")); String serviceType = offering.getCiAttributes().get("service_type"); byPlatform.put(platform, byPlatform.getOrDefault(platform, BigDecimal.ZERO).add(rate)); byService.put(serviceType, byService.getOrDefault(serviceType, BigDecimal.ZERO).add(rate)); byCloud.put(cloud, byCloud.getOrDefault(cloud, BigDecimal.ZERO).add(rate)); total = total.add(rate); } } map.put("by_cloud", byCloud); map.put("by_platform", byPlatform); map.put("by_service", byService); map.put("total", total); return map; }
From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java
/** * Extra precise sqrt function for use with BigDecimal class. Uses Newton's * method to roughly double the number of significant digits of typical * floating-point sqrt function. (This gem was found on StackOverflow.com) * * @param value/* w ww. ja v a 2 s .co m*/ * @param mc * @return square root of {@code value} */ public static final BigDecimal sqrt(BigDecimal value, MathContext mc) { BigDecimal x = new BigDecimal(Math.sqrt(value.doubleValue()), mc); return x.add(new BigDecimal(value.subtract(x.multiply(x)).doubleValue() / (x.doubleValue() * 2.0), mc)); }
From source file:com.wso2telco.dep.reportingservice.northbound.NbHostObjectUtils.java
/** * Apply payment charges by category.//from ww w .j a va2 s . co m * * @param opSubscription the op subscription * @param categoryCharge the category charge * @param paymentRequestSet the payment request set * @throws Exception */ private static void applyPaymentChargesByCategory(BillingSubscription.OperatorSubscription opSubscription, CategoryCharge categoryCharge, Set<PaymentRequestDTO> paymentRequestSet) throws Exception { TaxDAO taxDAO = new TaxDAO(); ChargeRate rate = opSubscription.getRate(); List<Tax> taxList = taxDAO.getTaxesForTaxList(rate.getTaxList()); BigDecimal totalCharge = BigDecimal.ZERO; BigDecimal totalPrice = BigDecimal.ZERO; BigDecimal totalTax = BigDecimal.ZERO; for (PaymentRequestDTO paymentRequest : paymentRequestSet) { totalCharge = totalCharge.add(paymentRequest.getAmount()); BigDecimal price = BigDecimal.ZERO; CategoryEntity rateCategories = new CategoryEntity(); if (rateCategories == null) { throw new APIManagementException( "Payment Categoreis required for QUOTA charging are not specified in rate-card.xml"); } BigDecimal catpercent = rate.getValue().divide(new BigDecimal(100)); Date date = new Date(paymentRequest.getDate().getTime()); for (Tax tax : taxList) { // check if the date of payment request falls between this tax // validity period if (!date.before(tax.getEffective_from()) && !date.after(tax.getEffective_to())) { // totalTax += taxFraction x paymentAmount totalTax = totalTax.add(tax.getValue().multiply(price)); } } } // Get the percentage from the rate value // BigDecimal percentage = rate.getValue().divide(new BigDecimal(100)); // apply category wise charge percentage }
From source file:com.esd.cs.audit.AuditsController.java
/** * /* w ww . j ava2 s .c o m*/ * * @param companyId * @param sb * @return */ private BigDecimal getUnpaid(String year, Integer companyId, List<AccountModel> sb) { BigDecimal amount = new BigDecimal(0.00); List<Accounts> accounts = accountsService.getByYearAndCompany(year, companyId, Constants.PROCESS_STATIC_WJK); Map<String, Accounts> map = new HashMap<>(); for (Accounts group : accounts) { Object obj = map.get(group.getYear()); if (obj == null) { map.put(group.getYear(), group); } else { Accounts a = (Accounts) obj; a.setTotalMoney(a.getTotalMoney().add(group.getTotalMoney())); } } for (Accounts a : map.values()) { BigDecimal total = a.getTotalMoney(); AuditParameter auditParameter = auditParameterService.getByYear(a.getYear()); Date auditDelayDate = auditParameter.getAuditDelayDate(); int days = CalendarUtil.getDaySub(auditDelayDate, new Date()); BigDecimal penalty = total.multiply(auditParameter.getAuditDelayRate()).multiply(new BigDecimal(days)); AccountModel am = new AccountModel(); am.setYear(a.getYear()); am.setDays(String.valueOf(days)); am.setMoney(df.format(total)); am.setPenalty(df.format(penalty)); am.setProp(df4.format(auditParameter.getAuditDelayRate())); am.setTotal(df.format(total)); sb.add(am); amount = amount.add(total); } if (amount.compareTo(new BigDecimal(0.00)) != 0) { AccountModel am = new AccountModel(); am.setTotal(df.format(amount)); sb.add(am); } return amount; }