List of usage examples for java.math BigDecimal subtract
public BigDecimal subtract(BigDecimal subtrahend)
From source file:org.projectforge.fibu.OrderExport.java
private void addOrderMapping(final PropertyMapping mapping, final AuftragDO order, final Object... params) { auftragDao.calculateInvoicedSum(order); mapping.add(OrderCol.NUMMER, order.getNummer()); mapping.add(OrderCol.NUMBER_OF_POSITIONS, "#" + (order.getPositionen() != null ? order.getPositionen().size() : "0")); mapping.add(OrderCol.DATE, order.getAngebotsDatum()); mapping.add(OrderCol.ORDER_DATE, order.getBeauftragungsDatum()); mapping.add(OrderCol.STATUS,/* w w w . ja v a2 s.c o m*/ order.getAuftragsStatus() != null ? PFUserContext.getLocalizedString(order.getAuftragsStatus().getI18nKey()) : ""); mapping.add(OrderCol.PROJECT, order.getProjektAsString()); final ProjektDO project = order.getProjekt(); final String projectCustomer = KundeFormatter .formatKundeAsString(project != null ? project.getKunde() : null, order.getKundeText()); mapping.add(OrderCol.PROJECT_CUSTOMER, projectCustomer); mapping.add(OrderCol.TITLE, order.getTitel()); final BigDecimal netSum = order.getNettoSumme() != null ? order.getNettoSumme() : BigDecimal.ZERO; final BigDecimal invoicedSum = order.getFakturiertSum() != null ? order.getFakturiertSum() : BigDecimal.ZERO; final BigDecimal toBeInvoicedSum = netSum.subtract(invoicedSum); mapping.add(OrderCol.NETSUM, netSum); addCurrency(mapping, OrderCol.INVOICED, invoicedSum); addCurrency(mapping, OrderCol.TO_BE_INVOICED, toBeInvoicedSum); mapping.add(OrderCol.COMPLETELY_INVOICED, order.isVollstaendigFakturiert() == true ? "x" : ""); final Set<RechnungsPositionVO> invoicePositions = rechnungCache .getRechnungsPositionVOSetByAuftragId(order.getId()); mapping.add(OrderCol.INVOICES, getInvoices(invoicePositions)); final PFUserDO contactPerson = Registry.instance().getUserGroupCache().getUser(order.getContactPersonId()); mapping.add(OrderCol.CONTACT_PERSON, contactPerson != null ? contactPerson.getFullname() : ""); mapping.add(OrderCol.REFERENCE, order.getReferenz()); mapping.add(OrderCol.COMMENT, order.getBemerkung()); }
From source file:ch.algotrader.entity.security.SecurityFamilyImpl.java
@Override public BigDecimal adjustPrice(String broker, BigDecimal price, int ticks) { Validate.notNull(price, "Price cannot be null"); if (ticks > 0) { for (int i = 0; i < ticks; i++) { price = price.add(getTickSize(broker, price, true)); }/*from w w w . jav a 2s . c o m*/ } else if (ticks < 0) { for (int i = 0; i > ticks; i--) { price = price.subtract(getTickSize(broker, price, false)); } } return price; }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsAgingReportBuilderServiceImpl.java
/** * @param cgInvoiceReportEntry// w w w .j a v a 2 s . c o m * @param reportDetail */ protected void setReportData(ContractsGrantsInvoiceDocument cgInvoiceReportEntry, ContractsGrantsAgingReportDetailDataHolder reportDetail) { java.util.Date today = new java.util.Date(); Date sqlToday = new java.sql.Date(today.getTime()); reportDetail.setAgencyNumber( cgInvoiceReportEntry.getInvoiceGeneralDetail().getAward().getAgency().getAgencyNumber()); reportDetail.setAgencyName( cgInvoiceReportEntry.getInvoiceGeneralDetail().getAward().getAgency().getReportingName()); reportDetail.setCustomerNumber(cgInvoiceReportEntry.getCustomerNumber()); reportDetail .setProposalNumber(cgInvoiceReportEntry.getInvoiceGeneralDetail().getProposalNumber().toString()); reportDetail .setAwardEndDate(cgInvoiceReportEntry.getInvoiceGeneralDetail().getAward().getAwardEndingDate()); reportDetail.setDocumentNumber(cgInvoiceReportEntry.getDocumentNumber()); WorkflowDocument workflowDocument = cgInvoiceReportEntry.getDocumentHeader().getWorkflowDocument(); Date docCreateDate = new Date(workflowDocument.getDateCreated().toDate().getTime()); reportDetail.setInvoiceDate(docCreateDate); // last event date List<CollectionEvent> events = cgInvoiceReportEntry.getCollectionEvents(); if (ObjectUtils.isNotNull(events) && CollectionUtils.isNotEmpty(events)) { Collections.sort(events, new Comparator<CollectionEvent>() { @Override public int compare(CollectionEvent o1, CollectionEvent o2) { if (KfsDateUtils.isSameDay(o1.getActivityDate(), o2.getActivityDate())) { return 0; } return o2.getActivityDate().compareTo(o1.getActivityDate()); } }); reportDetail.setLastEventDate(events.get(0).getActivityDate()); } // calculate ageInDays : current date - created date final long MILLSECS_PER_DAY = 24 * 60 * 60 * 1000; reportDetail.setAgeInDays((sqlToday.getTime() - docCreateDate.getTime()) / MILLSECS_PER_DAY); BigDecimal invoiceAmount = cgInvoiceReportEntry.getTotalDollarAmount().bigDecimalValue(); reportDetail.setInvoiceAmount(invoiceAmount); BigDecimal paymentAmount = cgInvoiceReportEntry.getPaymentAmount().bigDecimalValue(); reportDetail.setPaymentAmount(paymentAmount); BigDecimal remainingAmount = invoiceAmount.subtract(paymentAmount); reportDetail.setRemainingAmount(remainingAmount); }
From source file:org.projectforge.business.fibu.OrderExport.java
private void addPosMapping(final PropertyMapping mapping, final AuftragDO order, final AuftragsPositionDO pos) { mapping.add(PosCol.NUMBER, order.getNummer()); mapping.add(PosCol.POS_NUMBER, "#" + pos.getNumber()); mapping.add(PosCol.DATE, order.getAngebotsDatum()); mapping.add(PosCol.PROJECT, order.getProjektAsString()); mapping.add(PosCol.ORDER_TITLE, order.getTitel()); mapping.add(PosCol.TITLE, pos.getTitel()); mapping.add(PosCol.TYPE,/*from w ww.j a v a 2 s . c o m*/ pos.getArt() != null ? ThreadLocalUserContext.getLocalizedString(pos.getArt().getI18nKey()) : ""); mapping.add(PosCol.STATUS, pos.getStatus() != null ? ThreadLocalUserContext.getLocalizedString(pos.getStatus().getI18nKey()) : ""); mapping.add(PosCol.PERSON_DAYS, pos.getPersonDays()); final BigDecimal netSum = pos.getNettoSumme() != null ? pos.getNettoSumme() : BigDecimal.ZERO; final BigDecimal invoicedSum = pos.getFakturiertSum() != null ? pos.getFakturiertSum() : BigDecimal.ZERO; final BigDecimal toBeInvoicedSum = netSum.subtract(invoicedSum); mapping.add(PosCol.NETSUM, netSum); addCurrency(mapping, PosCol.INVOICED, invoicedSum); addCurrency(mapping, PosCol.TO_BE_INVOICED, toBeInvoicedSum); mapping.add(PosCol.COMPLETELY_INVOICED, pos.isVollstaendigFakturiert() == true ? "x" : ""); final Set<RechnungsPositionVO> invoicePositions = rechnungCache .getRechnungsPositionVOSetByAuftragsPositionId(pos.getId()); mapping.add(PosCol.INVOICES, getInvoices(invoicePositions)); if (PeriodOfPerformanceType.OWN.equals(pos.getPeriodOfPerformanceType())) { // use "own" period -> from pos mapping.add(PosCol.PERIOD_OF_PERFORMANCE_BEGIN, pos.getPeriodOfPerformanceBegin()); mapping.add(PosCol.PERIOD_OF_PERFORMANCE_END, pos.getPeriodOfPerformanceEnd()); } else { // use "see above" period -> from order mapping.add(PosCol.PERIOD_OF_PERFORMANCE_BEGIN, order.getPeriodOfPerformanceBegin()); mapping.add(PosCol.PERIOD_OF_PERFORMANCE_END, order.getPeriodOfPerformanceEnd()); } final TaskNode node = getTenantRegistry().getTaskTree().getTaskNodeById(pos.getTaskId()); mapping.add(PosCol.TASK, node != null ? node.getTask().getTitle() : ""); mapping.add(PosCol.COMMENT, pos.getBemerkung()); }
From source file:org.openo.nfvo.resmanagement.service.base.openstack.impl.SitesImpl.java
private String accumOrFreeRes(String resUsed, String resOld, String action, String total, String type) throws ServiceException { BigDecimal iResUsed = new BigDecimal(resUsed); BigDecimal iResOld = new BigDecimal(resOld); BigDecimal itotal = new BigDecimal(total); if ("online".equals(action)) { if (iResOld.add(iResUsed).compareTo(itotal) > 0) { throw new ServiceException("Grant resource fail! The " + type + " resource not enough."); }//from w ww.ja v a 2s.c om return String.valueOf(iResOld.add(iResUsed)); } else { if (iResOld.subtract(iResUsed).compareTo(BigDecimal.ZERO) < 0) { throw new ServiceException("Grant resource fail! The " + type + " resource used below zero."); } return String.valueOf(iResOld.subtract(iResUsed)); } }
From source file:org.egov.adtax.web.controller.deactivate.DeactivateAdvertisementController.java
@RequestMapping(value = "/result/{id}", method = GET) public String viewHoardingByApplicationNumber(@PathVariable final Long id, final Model model) { AdvertisementPermitDetail advertisementPermitDetail = advertisementPermitDetailService.findById(id); if (advertisementPermitDetail != null && advertisementPermitDetail.getAdvertisement() != null && advertisementPermitDetail.getAdvertisement().getStatus() != null && advertisementPermitDetail .getAdvertisement().getStatus().equals(AdvertisementStatus.WORKFLOW_IN_PROGRESS)) { model.addAttribute("message", "msg.deactivate.alreadyInWorkFlow"); return "deactive-error"; }//from w w w .j a v a 2s . c om if (advertisementPermitDetail != null && advertisementPermitDetail.getAdvertisement() != null && advertisementPermitDetail.getAdvertisement().getStatus() != null && advertisementPermitDetail.getAdvertisement().getStatus().equals(AdvertisementStatus.ACTIVE) && advertisementPermitDetail.getStatus() != null && advertisementPermitDetail.getStatus().getCode() .equalsIgnoreCase(AdvertisementTaxConstants.APPLICATION_STATUS_APPROVED)) { model.addAttribute("message", "msg.deactivate.paymentPending"); return "deactive-error"; } Set<EgDemandDetails> demandDetails = new HashSet<EgDemandDetails>(); demandDetails = advertisementPermitDetail.getAdvertisement().getDemandId().getEgDemandDetails(); BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal totalCollectedAmount = BigDecimal.ZERO; BigDecimal pendingTax = BigDecimal.ZERO; for (EgDemandDetails demandObject : demandDetails) { totalAmount = totalAmount.add(demandObject.getAmount()); totalCollectedAmount = totalCollectedAmount.add(demandObject.getAmtCollected()); } pendingTax = totalAmount.subtract(totalCollectedAmount); advertisementPermitDetail.getAdvertisement().setPendingTax(pendingTax); model.addAttribute("advertisementPermitDetailStatus", advertisementPermitDetail); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); model.addAttribute("applicationDate", sdf.format(advertisementPermitDetail.getApplicationDate())); return "statusChange-deactivate"; }
From source file:org.openhab.binding.denonmarantz.internal.DenonMarantzState.java
public void setMainVolume(BigDecimal volume) { PercentType newVal = new PercentType(volume); if (!newVal.equals(this.mainVolume)) { this.mainVolume = newVal; handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_MAIN_VOLUME, this.mainVolume); // update the main volume in dB too this.mainVolumeDB = DecimalType .valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString()); handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_MAIN_VOLUME_DB, this.mainVolumeDB); }//from w w w .j av a2 s . c o m }
From source file:org.openhab.binding.denonmarantz.internal.DenonMarantzState.java
public void setZone2Volume(BigDecimal volume) { PercentType newVal = new PercentType(volume); if (!newVal.equals(this.zone2Volume)) { this.zone2Volume = newVal; handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE2_VOLUME, this.zone2Volume); // update the volume in dB too this.zone2VolumeDB = DecimalType .valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString()); handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE2_VOLUME_DB, this.zone2VolumeDB); }/* www. ja v a 2 s. c o m*/ }
From source file:org.openhab.binding.denonmarantz.internal.DenonMarantzState.java
public void setZone3Volume(BigDecimal volume) { PercentType newVal = new PercentType(volume); if (!newVal.equals(this.zone3Volume)) { this.zone3Volume = newVal; handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE3_VOLUME, this.zone3Volume); // update the volume in dB too this.zone3VolumeDB = DecimalType .valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString()); handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE3_VOLUME_DB, this.zone3VolumeDB); }//from www . j a v a 2 s .com }
From source file:org.egov.wtms.application.service.collection.WaterConnectionBillable.java
@Override public BigDecimal getTotalAmount() { final EgDemand currentDemand = getCurrentDemand(); final List instVsAmt = connectionDemandService.getDmdCollAmtInstallmentWise(currentDemand); BigDecimal balance = BigDecimal.ZERO; for (final Object object : instVsAmt) { final Object[] ddObject = (Object[]) object; final BigDecimal dmdAmt = new BigDecimal((Double) ddObject[2]); BigDecimal collAmt = BigDecimal.ZERO; if (ddObject[2] != null) collAmt = new BigDecimal((Double) ddObject[3]); balance = balance.add(dmdAmt.subtract(collAmt)); }/* ww w. j a v a 2 s. c o m*/ return balance; }