public int getDecimals(int int0) { if (currencyVO != null) return currencyVO.getDecimalsREG03().intValue(); else return 0; }
public String getCurrencySymbol(int int0) { if (currencyVO != null) return currencyVO.getCurrencySymbolREG03(); else return "E"; }
/** * Navigate tree and fetch item purchase price and production costs. * * @param node current analyzed node */ private static Response expandNode( Connection conn, CurrencyVO currVO, PreparedStatement pstmt, PreparedStatement pstmt2, DefaultMutableTreeNode node) throws Exception { ResultSet rset = null; try { MaterialVO vo = (MaterialVO) node.getUserObject(); if (node.getChildCount() == 0) { // the current node is a leaf, so it cannot be constructed: it will be purchased... pstmt.setString(1, vo.getCompanyCodeSys01ITM03()); pstmt.setString(2, vo.getItemCodeItm01ITM03()); pstmt.setDate(3, new java.sql.Date(System.currentTimeMillis())); pstmt.setDate(4, new java.sql.Date(System.currentTimeMillis() + 86400 * 1000 - 1)); rset = pstmt.executeQuery(); BigDecimal totPrice = new BigDecimal(0); BigDecimal totNum = new BigDecimal(0); BigDecimal price = null; BigDecimal num = null; String currencyCode = null; while (rset.next()) { price = rset.getBigDecimal(1); num = rset.getBigDecimal(2); currencyCode = rset.getString(3); price = CurrencyConversionUtils.convertCurrencyToCurrency( new java.sql.Date(System.currentTimeMillis()), price, currencyCode, currVO.getCurrencyCodeREG03(), conn); if (price != null && num != null) { totPrice = totPrice.add(price); totNum = totNum.add(num); } } rset.close(); if (totPrice.doubleValue() > 0) { vo.setValuePUR04( vo.getQtyITM03() .multiply(totPrice) .divide(num, BigDecimal.ROUND_HALF_UP) .setScale(5, BigDecimal.ROUND_HALF_UP)); vo.setTotalPrices(vo.getValuePUR04()); } } else { // the current node is not a leaf, so it will be constructed: now it will be calculated // production costs... pstmt2.setString(1, vo.getCompanyCodeSys01ITM03()); pstmt2.setString(2, vo.getItemCodeItm01ITM03()); rset = pstmt2.executeQuery(); BigDecimal cost = null; if (rset.next()) { cost = rset.getBigDecimal(1); } rset.close(); if (cost != null && cost.doubleValue() > 0) { vo.setValuePRO02(vo.getQtyITM03().multiply(cost).setScale(5, BigDecimal.ROUND_HALF_UP)); } // navigate through children nodes... Response res = null; for (int i = 0; i < node.getChildCount(); i++) { res = expandNode(conn, currVO, pstmt, pstmt2, (DefaultMutableTreeNode) node.getChildAt(i)); if (res.isError()) return res; } if (res.isError()) return res; // calculate total costs + total prices... MaterialVO childVO = null; BigDecimal totalPrices = new BigDecimal(0); BigDecimal totalCosts = vo.getValuePRO02(); for (int i = 0; i < node.getChildCount(); i++) { childVO = (MaterialVO) ((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject(); if (childVO.getTotalPrices() != null && totalPrices != null) // totalPrices = // totalPrices.add(childVO.getTotalPrices().multiply(childVO.getQtyITM03())); totalPrices = totalPrices.add(childVO.getTotalPrices()); else totalPrices = null; if (childVO.getTotalCosts() != null && totalCosts != null) // totalCosts = // totalCosts.add(childVO.getTotalCosts().multiply(childVO.getQtyITM03())); totalCosts = totalCosts.add(childVO.getTotalCosts()); } if (totalCosts != null) vo.setTotalCosts(totalCosts.setScale(5, BigDecimal.ROUND_HALF_UP)); if (totalPrices != null && totalPrices != null) vo.setTotalPrices(totalPrices.setScale(5, BigDecimal.ROUND_HALF_UP)); } return new VOResponse(Boolean.TRUE); } catch (Exception ex) { ex.printStackTrace(); throw new Exception(ex.getMessage()); } finally { try { if (rset != null) rset.close(); } catch (Exception ex1) { } } }