Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:org.adempiere.webui.dashboard.CalendarWindow.java

private void syncModel() {
    Hashtable<String, BigDecimal> ht = new Hashtable<String, BigDecimal>();

    List<?> list = calendars.getModel().get(calendars.getBeginDate(), calendars.getEndDate(), null);
    int size = list.size();
    for (Iterator<?> it = list.iterator(); it.hasNext();) {
        String key = ((ADCalendarEvent) it.next()).getR_RequestType_ID() + "";

        if (!ht.containsKey(key))
            ht.put(key, BigDecimal.ONE);
        else {//from  w  w  w.ja  v  a 2s  . c o m
            BigDecimal value = ht.get(key);
            ht.put(key, value.add(BigDecimal.ONE));
        }
    }

    Hashtable<Object, String> htTypes = new Hashtable<Object, String>();
    for (int i = 0; i < lbxRequestTypes.getItemCount(); i++) {
        Listitem li = lbxRequestTypes.getItemAtIndex(i);
        if (li != null && li.getValue() != null)
            htTypes.put(li.getValue(), li.getLabel());
    }

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    Enumeration<?> keys = ht.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        BigDecimal value = ht.get(key);
        String name = (String) htTypes.get(key);
        pieDataset.setValue(name == null ? "" : name,
                new Double(size > 0 ? value.doubleValue() / size * 100 : 0));
    }

    JFreeChart chart = ChartFactory.createPieChart3D(Msg.getMsg(Env.getCtx(), "EventsAnalysis"), pieDataset,
            true, true, true);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setForegroundAlpha(0.5f);
    BufferedImage bi = chart.createBufferedImage(600, 250);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
        AImage image = new AImage("Pie Chart", bytes);
        myChart.setContent(image);
    } catch (IOException e) {
        e.printStackTrace();
    }
    htTypes = null;
    ht = null;
}

From source file:com.opensourcestrategies.financials.accounts.GLAccountInTree.java

/**
 * Gets the credit of this GL account given child GL account.
 * @param childAccount a <code>GLAccountInTree</code> value
 * @return a <code>BigDecimal</code> value
 *///w  w w  .ja  va2 s.  co  m
private BigDecimal getCreditOfChildrenRec(GLAccountInTree childAccount) {
    if (childAccount == null) {
        return BigDecimal.ZERO;
    }
    BigDecimal creditOfChildren = BigDecimal.ZERO;
    if (childAccount.isCreditAccount) {
        creditOfChildren = childAccount.balance;
    }
    for (GLAccountInTree grandchildAccount : childAccount.childAccounts) {
        creditOfChildren = creditOfChildren.add(getCreditOfChildrenRec(grandchildAccount));
    }
    return creditOfChildren;
}

From source file:org.businessmanager.web.controller.page.invoice.InvoiceEditController.java

public BigDecimal getTotalVatAmount() {
    BigDecimal totalVatAmount = BigDecimal.ZERO;
    for (LineItemBean lineItem : bean.getLineItems()) {
        BigDecimal amount = lineItem.getVatAmount();
        totalVatAmount = totalVatAmount.add(amount);
    }/* ww  w.j a v a2s .c om*/

    return totalVatAmount.setScale(2, RoundingMode.HALF_UP);
}

From source file:org.businessmanager.web.controller.page.invoice.InvoiceEditController.java

public BigDecimal getTotalNetPrice() {
    BigDecimal totalNetPrice = BigDecimal.ZERO;
    for (LineItemBean lineItem : bean.getLineItems()) {
        BigDecimal sumPrice = lineItem.getSumPriceNet();
        totalNetPrice = totalNetPrice.add(sumPrice);
    }/*from w w  w .  j  av  a2  s  .  c om*/

    return totalNetPrice.setScale(2, RoundingMode.HALF_UP);
}

From source file:org.businessmanager.web.controller.page.invoice.InvoiceEditController.java

public BigDecimal getTotalGrossPrice() {
    BigDecimal totalGrossPrice = BigDecimal.ZERO;
    for (LineItemBean lineItem : bean.getLineItems()) {
        BigDecimal sumPrice = lineItem.getSumPriceGross();
        totalGrossPrice = totalGrossPrice.add(sumPrice);
    }/*  www.j a va 2  s . co m*/

    return totalGrossPrice.setScale(2, RoundingMode.HALF_UP);
}

From source file:fsm.series.Series_CC.java

@Override
public double getFirstDerivativeValue(double y, int m) {
    //        dY = alphaM*(km*sin(km*y) + km*sinh(km*y)) + km*cos(km*y) - km*cosh(km*y)

    double um = getMu_m(m);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double km = um / a;

    BigDecimal dYm;/*  w w  w.  jav  a2 s . c om*/

    BigDecimal cosh = new BigDecimal(-km * cosh(km * y));
    BigDecimal sinh = new BigDecimal(alphaM * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(alphaM * km * sin(km * y));
    BigDecimal cos = new BigDecimal(km * cos(km * y));

    dYm = (cos.add(sin).add(sinh).add(cosh));

    return dYm.doubleValue();

}

From source file:fsm.series.Series_CC.java

@Override
public strictfp double getFunctionValue(double y, int m) {

    double um = getMu_m(m);

    double alphaM = (sin(um) - sinh(um)) / (cos(um) - cosh(um));

    double km = um / a;

    BigDecimal Ym;//from  w w  w .ja va2s . c om

    BigDecimal cosh = new BigDecimal(-alphaM * -cosh(km * y));
    BigDecimal sinh = new BigDecimal(-sinh(km * y));
    BigDecimal sin = new BigDecimal(sin(km * y));
    BigDecimal cos = new BigDecimal(-alphaM * cos(km * y));

    Ym = (cos.add(sin).add(sinh).add(cosh));

    return Ym.doubleValue();
}

From source file:org.eqaula.glue.controller.accounting.PostingHome.java

public BigDecimal total(Long id, String amount) {
    BigDecimal total = new BigDecimal(0);
    try {/* w  ww.  jav a2 s  . co  m*/
        Posting p = postingService.find(id);
        for (Entry e : p.getEntries()) {
            if (amount.equals("credit")) {
                if (e.getCredit() != null) {
                    total = total.add(e.getCredit());
                }
            }
            if (amount.equals("debit")) {
                if (e.getDebit() != null) {
                    total = total.add(e.getDebit());
                }
            }
        }
    } catch (Exception e) {
    }
    return total;
}

From source file:com.autentia.tnt.businessobject.Project.java

public BigDecimal getTotalCost() {
    BigDecimal ret = new BigDecimal(0);

    if (getCosts() != null) {
        for (ProjectCost cost : getCosts()) {
            BigDecimal c = cost.getCost();
            if (c != null) {
                ret = ret.add(c);
            }//from w  ww  .ja v  a  2  s .c o m
        }
    }
    if (getRoles() != null) {
        for (ProjectRole role : getRoles()) {
            BigDecimal cph = role.getCostPerHour();
            if (cph != null) {
                BigDecimal eh = new BigDecimal(role.getExpectedHours());
                ret = ret.add(cph.multiply(eh));
            }
        }
    }

    return ret;
}

From source file:com.roncoo.pay.app.reconciliation.parser.ALIPAYParser.java

/**
 * ????//from   www  .j a  v a 2s. c o  m
 * 
 * @param file
 *            ??
 * @param billDate
 *            ?
 * @param batch
 *            
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<ReconciliationEntityVo> parser(File file, Date billDate, RpAccountCheckBatch batch)
        throws IOException {
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_STYLE);

    // xml?file
    SAXReader reader = new SAXReader();
    Document document;
    try {
        document = reader.read(file);
        // dom4jXpathAccountQueryAccountLogVO
        List projects = document.selectNodes(
                "alipay/response/account_page_query_result/account_log_list/AccountQueryAccountLogVO");

        Iterator it = projects.iterator();
        // ?
        List<AlipayAccountLogVO> tradeList = new ArrayList<AlipayAccountLogVO>();
        // ?
        List<AlipayAccountLogVO> otherAll = new ArrayList<AlipayAccountLogVO>();
        while (it.hasNext()) {
            AlipayAccountLogVO vo = new AlipayAccountLogVO();
            Element elm = (Element) it.next();
            List<Element> childElements = elm.elements();
            for (Element child : childElements) {
                String name = child.getName();
                // 
                switch (name) {
                case "balance":
                    vo.setBalance(new BigDecimal(child.getText()));
                    break;
                case "rate":
                    vo.setBankRate(new BigDecimal(("").equals(child.getText()) ? "0" : child.getText()));
                    break;
                case "buyer_account":
                    vo.setBuyerAccount(child.getText());
                    break;
                case "goods_title":
                    vo.setGoodsTitle(child.getText());
                    break;
                case "income":
                    vo.setIncome(new BigDecimal(("").equals(child.getText()) ? "0" : child.getText()));
                    break;
                case "outcome":
                    vo.setOutcome(new BigDecimal(("").equals(child.getText()) ? "0" : child.getText()));
                    break;
                case "merchant_out_order_no":
                    vo.setMerchantOrderNo(child.getText());
                    break;
                case "total_fee":
                    vo.setTotalFee(new BigDecimal(("").equals(child.getText()) ? "0" : child.getText()));
                    break;
                case "trade_no":// ?
                    vo.setTradeNo(child.getText());
                    break;
                case "trans_code_msg":// 
                    vo.setTransType(child.getText());
                    break;
                case "trans_date":
                    String dateStr = child.getText();
                    Date date;
                    try {
                        date = sdf.parse(dateStr);
                    } catch (ParseException e) {
                        date = billDate;
                    }
                    vo.setTransDate(date);
                    break;

                default:
                    break;
                }
            }

            // ??
            if ("".equals(vo.getTransType())) {
                tradeList.add(vo);
            } else {
                otherAll.add(vo);
            }
        }
        // ?????????
        // ?????????
        for (AlipayAccountLogVO trade : tradeList) {
            String tradeNo = trade.getTradeNo();
            for (AlipayAccountLogVO other : otherAll) {
                String otherTradeNo = other.getTradeNo();
                if (tradeNo.equals(otherTradeNo)) {
                    trade.setBankFee(other.getOutcome());
                }
            }
        }
        // AlipayAccountLogVOvoReconciliationEntityVo?list
        List<ReconciliationEntityVo> list = new ArrayList<ReconciliationEntityVo>();

        // ???
        int totalCount = 0;
        BigDecimal totalAmount = BigDecimal.ZERO;
        BigDecimal totalFee = BigDecimal.ZERO;

        for (AlipayAccountLogVO trade : tradeList) {
            // 
            totalCount++;
            totalAmount = totalAmount.add(trade.getTotalFee());
            totalFee = totalFee.add(trade.getBankFee());

            // AlipayAccountLogVOReconciliationEntityVo
            ReconciliationEntityVo vo = new ReconciliationEntityVo();
            vo.setAccountCheckBatchNo(batch.getBatchNo());
            vo.setBankAmount(trade.getTotalFee());
            vo.setBankFee(trade.getBankFee());
            vo.setBankOrderNo(trade.getMerchantOrderNo());
            vo.setBankRefundAmount(BigDecimal.ZERO);
            vo.setBankTradeStatus("SUCCESS");
            vo.setBankTradeTime(trade.getTransDate());
            vo.setBankTrxNo(trade.getTradeNo());
            vo.setBankType(PayWayEnum.ALIPAY.name());
            vo.setOrderTime(trade.getTransDate());
            list.add(vo);
        }
        batch.setBankTradeCount(totalCount);
        batch.setBankTradeAmount(totalAmount);
        batch.setBankRefundAmount(BigDecimal.ZERO);
        batch.setBankFee(totalFee);

        return list;

    } catch (DocumentException e) {
        LOG.warn("?", e);
        batch.setStatus(BatchStatusEnum.FAIL.name());
        batch.setCheckFailMsg("?, payway[" + PayWayEnum.ALIPAY.name() + "], billdata["
                + sdf.format(billDate) + "]");
        return null;
    }

}