List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:de.appsolve.padelcampus.utils.BookingUtil.java
public List<TimeSlot> getTimeSlotsForDate(LocalDate selectedDate, List<CalendarConfig> allCalendarConfigs, List<Booking> existingBookings, Boolean onlyFutureTimeSlots, Boolean preventOverlapping) throws CalendarConfigException { List<CalendarConfig> calendarConfigs = calendarConfigUtil.getCalendarConfigsMatchingDate(allCalendarConfigs, selectedDate);/*from w ww . j a va 2 s .c o m*/ Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (isHoliday(selectedDate, calendarConfig)) { iterator.remove(); } } List<TimeSlot> timeSlots = new ArrayList<>(); if (calendarConfigs.size() > 0) { LocalDate today = new LocalDate(DEFAULT_TIMEZONE); //sort all calendar configurations for selected date by start time Collections.sort(calendarConfigs); CalendarConfig previousConfig = null; LocalDateTime time = null; LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE); //generate list of bookable time slots int i = 0; for (CalendarConfig config : calendarConfigs) { i++; LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime()); if (time == null) { //on first iteration time = startDateTime; } else if (!time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) { //reset basePriceLastConfig as this is a non contiguous offer previousConfig = null; time = startDateTime; } LocalDateTime endDateTime = getLocalDateTime(selectedDate, config.getEndTime()); while (time.plusMinutes(config.getMinDuration()).compareTo(endDateTime) <= 0) { BigDecimal pricePerMinDuration; if (previousConfig == null) { pricePerMinDuration = config.getBasePrice(); } else { BigDecimal previousConfigBasePricePerMinute = getPricePerMinute(previousConfig); pricePerMinDuration = previousConfigBasePricePerMinute .multiply(new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128); BigDecimal basePricePerMinute = getPricePerMinute(config); pricePerMinDuration = pricePerMinDuration.add(basePricePerMinute.multiply( new BigDecimal(config.getMinDuration() - previousConfig.getMinInterval()), MathContext.DECIMAL128)); previousConfig = null; } pricePerMinDuration = pricePerMinDuration.setScale(2, RoundingMode.HALF_EVEN); if (onlyFutureTimeSlots) { if (selectedDate.isAfter(today) || time.isAfter(now)) { addTimeSlot(timeSlots, time, config, pricePerMinDuration); } } else { addTimeSlot(timeSlots, time, config, pricePerMinDuration); } time = time.plusMinutes(config.getMinInterval()); } //make sure to display the last min interval of the day if (config.getMinInterval() < config.getMinDuration() && i == calendarConfigs.size()) { if (time.plusMinutes(config.getMinInterval()).compareTo(endDateTime) <= 0) { addTimeSlot(timeSlots, time, config, null); } } previousConfig = config; } //sort time slots by time Collections.sort(timeSlots); //decrease court count for every blocking booking for (TimeSlot timeSlot : timeSlots) { checkForBookedCourts(timeSlot, existingBookings, preventOverlapping); } } return timeSlots; }
From source file:com.cssweb.android.trade.util.TradeUtil.java
/** * ??/*w w w . j a va2s .c om*/ */ public static String formatNum(String str, int len) { if (str == null) return ""; int flag = 1; if (str.charAt(0) == '-' && str.charAt(1) == '.') { str = str.replace("-.", "-0."); flag = -1; } if (str.charAt(0) == '.') str = "0" + str; if (len < 0) len = 0; BigDecimal small = new BigDecimal("0"); BigDecimal big = new BigDecimal("0"); if (("0").equals(str) && len == 0) return "0"; if (str.indexOf(".") != -1) { String[] ary = str.split("\\."); big = BigDecimal.valueOf(Double.parseDouble(ary[0])); small = BigDecimal.valueOf(Double.parseDouble("0." + ary[1])); small = small.setScale(len > 0 ? len : 1, BigDecimal.ROUND_HALF_UP); if (str.charAt(0) == '-') { return big.subtract(small).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP) .toString(); } return big.add(small).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP).toString(); } else { return new BigDecimal(str).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP) .toString(); } }
From source file:com.axelor.apps.account.service.MoveLineExportService.java
public BigDecimal getSumCredit(List<MoveLine> moveLineList) { BigDecimal sumCredit = BigDecimal.ZERO; for (MoveLine moveLine : moveLineList) { sumCredit = sumCredit.add(moveLine.getCredit()); }/*from w w w . j a va 2 s .c om*/ return sumCredit; }
From source file:com.gst.portfolio.loanaccount.domain.LoanAccountDomainServiceJpa.java
private void generateLoanScheduleAccrualData(final LocalDate accruedTill, final Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas, final Long loanId, Long officeId, final LocalDate accrualStartDate, final PeriodFrequencyType repaymentFrequency, final Integer repayEvery, final LocalDate interestCalculatedFrom, final Long loanProductId, final MonetaryCurrency currency, final CurrencyData currencyData, final Set<LoanCharge> loanCharges, final LoanRepaymentScheduleInstallment installment) { if (!accruedTill.isBefore(installment.getDueDate()) || (accruedTill.isAfter(installment.getFromDate()) && !accruedTill.isAfter(installment.getDueDate()))) { BigDecimal dueDateFeeIncome = BigDecimal.ZERO; BigDecimal dueDatePenaltyIncome = BigDecimal.ZERO; LocalDate chargesTillDate = installment.getDueDate(); if (!accruedTill.isAfter(installment.getDueDate())) { chargesTillDate = accruedTill; }/*w w w.j av a 2 s .com*/ for (final LoanCharge loanCharge : loanCharges) { if (loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), chargesTillDate)) { if (loanCharge.isFeeCharge()) { dueDateFeeIncome = dueDateFeeIncome.add(loanCharge.amount()); } else if (loanCharge.isPenaltyCharge()) { dueDatePenaltyIncome = dueDatePenaltyIncome.add(loanCharge.amount()); } } } LoanScheduleAccrualData accrualData = new LoanScheduleAccrualData(loanId, officeId, installment.getInstallmentNumber(), accrualStartDate, repaymentFrequency, repayEvery, installment.getDueDate(), installment.getFromDate(), installment.getId(), loanProductId, installment.getInterestCharged(currency).getAmount(), installment.getFeeChargesCharged(currency).getAmount(), installment.getPenaltyChargesCharged(currency).getAmount(), installment.getInterestAccrued(currency).getAmount(), installment.getFeeAccrued(currency).getAmount(), installment.getPenaltyAccrued(currency).getAmount(), currencyData, interestCalculatedFrom, installment.getInterestWaived(currency).getAmount()); loanScheduleAccrualDatas.add(accrualData); } }
From source file:com.heliumv.api.inventory.InventoryApi.java
/** * Mengen überprüfen</b> * <p>Die Gesamtsumme der identity.amount muss ident mit der angegebenen Menge sein<p> * <p>Es dürfen nur positive Mengen in den identities vorhanden sein.</p> * <p>Seriennummernbehaftete Artikel dürfen nur die Menge 1.0 haben</p> * @param amount//from w w w.ja v a2 s .c o m * @param identities * @return */ private boolean verifyAmounts(ArtikelDto itemDto, BigDecimal amount, List<IdentityAmountEntry> identities) { if (!itemDto.istArtikelSnrOderchargentragend()) return true; if (identities == null || identities.size() == 0) { respondBadRequestValueMissing("identities"); return false; } BigDecimal amountIdentities = BigDecimal.ZERO; for (IdentityAmountEntry entry : identities) { if (entry.getAmount() == null) { respondBadRequestValueMissing("amount"); appendBadRequestData(entry.getIdentity(), "amount missing"); return false; } if (entry.getAmount().signum() != 1) { respondBadRequest("amount", "positive"); appendBadRequestData(entry.getIdentity(), entry.getAmount().toPlainString()); return false; } if (itemDto.isSeriennrtragend()) { if (BigDecimal.ONE.compareTo(entry.getAmount()) != 0) { respondBadRequest("snr-amount", "1 (is: " + entry.getAmount().toPlainString() + ")"); return false; } } amountIdentities = amountIdentities.add(entry.getAmount()); } if (amountIdentities.compareTo(amount.abs()) != 0) { respondBadRequest("totalamount != identityamount", amount.toPlainString()); appendBadRequestData("identityamount", amountIdentities.toPlainString()); return false; } return true; }
From source file:edu.byu.softwareDist.manager.impl.PurchaseManagerImpl.java
@Override public PurchaseHelper purchase(PurchaseHelper purchaseHelper) { Purchase purchase = new Purchase(); boolean purchaseCreated = false; final PersonInfo personInfo = loadPersonInfo(); if (purchaseHelper.getFreeItems().size() > 0) { LOG.debug("Purchasing free items size=" + purchaseHelper.getFreeItems().size()); final List<AcquireLicenses> acquireLicensesList = doAcquireLicenses(purchaseHelper.getFreeItems()); purchase = createPurchase(purchase, personInfo, null); purchaseCreated = true;/* w w w. j a va 2 s . c o m*/ purchaseHelper = updatePurchase(purchase, acquireLicensesList, personInfo); purchaseDao.update(purchaseHelper.getCheckOutResults().getPurchase()); } if (purchaseHelper.getAccountCodeItems().size() > 0) { LOG.debug("Purchasing account code items, size=" + purchaseHelper.getAccountCodeItems().size()); final List<AcquireLicenses> acquireLicensesList = doAcquireLicenses( purchaseHelper.getAccountCodeItems()); if (!purchaseCreated) { purchase = createPurchase(purchase, personInfo, purchaseHelper.getAccountCode()); purchaseCreated = true; } else { purchase.setAccountCode(purchaseHelper.getAccountCode()); } final List<AcquireLicenses> success = new LinkedList<AcquireLicenses>(); for (final AcquireLicenses al : acquireLicensesList) { final LineItem lineItem = soaMgr.submitOITOrderRequest(al.getLineItem(), purchaseHelper.getAccountCode(), personInfo); al.getLineItem().setOrderId(lineItem.getOrderId()); success.add(al); } purchaseHelper = updatePurchase(purchase, success, personInfo); purchaseDao.update(purchaseHelper.getCheckOutResults().getPurchase()); } if (purchaseHelper.getCreditCardItems().size() > 0) { LOG.debug("Purchasing credit card items, size=" + purchaseHelper.getCreditCardItems().size()); final List<AcquireLicenses> acquireLicensesList = doAcquireLicenses( purchaseHelper.getCreditCardItems()); final PendingPurchase pendingPurchase = createPendingPurchase(purchase.getPurchaseId(), personInfo.getPersonId()); purchaseHelper.setPendingPurchase(pendingPurchase); BigDecimal totalAmount = BigDecimal.ZERO; final List<Items> itemTypes = new ArrayList<Items>(); for (final AcquireLicenses al : acquireLicensesList) { final PendingLineItem pendingLineItem = createPendingLineItem( purchaseHelper.getPendingPurchase().getPendingPurchaseId(), al.getLineItem(), CASHNET, null); createPendingPurchaseKey(al.getLicenseList(), pendingLineItem.getPendingLineItemId(), al.getLineItem().getQty()); final BigDecimal quantity = new BigDecimal(al.getLineItem().getQty()); final BigDecimal costLineItem = al.getLineItem().getTotalPrice().multiply(quantity); totalAmount = totalAmount.add(costLineItem); itemTypes.add(setItemType(totalAmount, al.getLineItem().getQty())); } final CheckoutURL checkoutURL = ccpClient.getCheckoutURL( createCheckoutURL(personInfo, itemTypes, pendingPurchase.getPendingPurchaseId().toString())); purchaseHelper.setCreditCardUrl("redirect:" + checkoutURL.getCompleteURL()); } purchaseHelper.setCheckOutResults(new CheckOutResults(purchase, null)); try { final LicenseCountRunner runner = new LicenseCountRunner(purchaseHelper, licenseCountChecker); executor.submit(runner); } catch (final Throwable t) { } return purchaseHelper; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.StudentLine.java
public BigDecimal getNumberOfEnrolledEctsOneYearAgo() { ExecutionYear oneYearAgo = getForExecutionYear().getPreviousExecutionYear(); BigDecimal result = BigDecimal.ZERO; if (student == null) { return BigDecimal.ZERO; }/*w w w.j av a 2 s .c om*/ for (final Registration registration : student.getRegistrationsSet()) { if (registration.isBolonha() && registration.hasAnyEnrolmentsIn(oneYearAgo)) { result = result.add(new BigDecimal(getEnrolmentsEctsCredits(registration, oneYearAgo))); } } return result; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.StudentLine.java
public BigDecimal getNumberOfApprovedEctsOneYearAgo() { ExecutionYear oneYearAgo = getForExecutionYear().getPreviousExecutionYear(); BigDecimal result = BigDecimal.ZERO; if (student == null) { return BigDecimal.ZERO; }//from ww w .j a v a 2 s .co m for (final Registration registration : student.getRegistrationsSet()) { if (registration.isBolonha() && registration.hasAnyEnrolmentsIn(oneYearAgo)) { result = result .add(calculateApprovedECTS(registration.getLastStudentCurricularPlan() .getAprovedEnrolmentsInExecutionPeriod(oneYearAgo.getFirstExecutionPeriod()))) .add(calculateApprovedECTS(registration.getLastStudentCurricularPlan() .getAprovedEnrolmentsInExecutionPeriod(oneYearAgo.getLastExecutionPeriod()))); } } return result; }
From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java
@Override @Transactional(value = "jpaTransactionManager") public BigDecimal getBedragAtDate(Date date, Rekeningen rekening) { BigDecimal rekeningStand; List<BedragenDaoPojo> lstBedragen; if (rekening != null) { lstBedragen = bedragenDao.getBedragenUntilDate(date, rekening.getPk_id(), userInfo.getPersoon().getPk_id()); rekeningStand = rekening.getWaarde(); } else {/*from ww w.jav a 2s .c o m*/ lstBedragen = bedragenDao.getBedragenUntilDate(date, null, userInfo.getPersoon().getPk_id()); rekeningStand = rekeningenDao.totalAllRekeningen(userInfo.getPersoon().getPk_id()); } for (BedragenDaoPojo bedrag : lstBedragen) { if (bedrag.getGroep().getNegatief().equals(1)) { rekeningStand = rekeningStand.add(bedrag.getBedrag()); } if (bedrag.getGroep().getNegatief().equals(0)) { rekeningStand = rekeningStand.subtract(bedrag.getBedrag()); } } return rekeningStand; }
From source file:com.esd.cs.audit.AuditsController.java
/** * ?/*from ww w . ja v a2s . c o m*/ * * @param year * @param companyCode * @param total * @return */ private BigDecimal getUnAudits(String year, Integer companyId, BigDecimal total, List<AccountModel> sb) { BigDecimal amount = new BigDecimal(0.00); // ?? AuditParameter auditParameter = auditParameterService.getByYear(year); BigDecimal averageSalary = auditParameter.getAverageSalary(); // ? // BigDecimal putScale = auditParameter.getPutScale(); // ??*(?*)?? BigDecimal payableAmount = averageSalary.multiply(total.multiply(putScale)); String[] unAudits = companyService.getUnauditYearByCompany(companyId, year); if (unAudits != null) { for (String unYear : unAudits) { AuditParameter oldAuditParameter = auditParameterService.getByYear(unYear); Date auditDelayDate = oldAuditParameter.getAuditDelayDate(); int days = CalendarUtil.getDaySub(auditDelayDate, new Date()); // =?** BigDecimal penalty = payableAmount.multiply(oldAuditParameter.getAuditDelayRate()) .multiply(new BigDecimal(days)); BigDecimal unYearTotal = payableAmount.add(penalty); logger.debug("payableAmount:{},year:{} date:{} penalty:{} unYearTotal:{}", payableAmount, unYear, days, penalty, unYearTotal); AccountModel am = new AccountModel(); am.setYear(unYear); am.setDays(String.valueOf(days)); am.setMoney(df.format(payableAmount)); am.setPenalty(df.format(penalty)); am.setProp(df4.format(oldAuditParameter.getAuditDelayRate())); am.setTotal(df.format(unYearTotal)); sb.add(am); amount = amount.add(unYearTotal); } } if (amount.compareTo(new BigDecimal(0.00)) != 0) { AccountModel am = new AccountModel(); am.setTotal(df.format(amount)); sb.add(am); } return amount; }