List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:org.kuali.kfs.module.cab.service.impl.CapitalAssetBuilderModuleServiceImpl.java
protected boolean validateLevelCapitalAssetIndication(BigDecimal unitPrice, ObjectCode objectCode, String itemIdentifier) {/*from www. j a va 2 s . c o m*/ String capitalAssetPriceThresholdParam = this.getParameterService().getParameterValueAsString( AssetGlobal.class, CabParameterConstants.CapitalAsset.CAPITALIZATION_LIMIT_AMOUNT); BigDecimal priceThreshold = null; try { priceThreshold = new BigDecimal(capitalAssetPriceThresholdParam); } catch (NumberFormatException nfe) { throw new RuntimeException( "the parameter for CAPITAL_ASSET_OBJECT_LEVELS came was not able to be converted to a number.", nfe); } if (unitPrice.compareTo(priceThreshold) >= 0) { List<String> possibleCAMSObjectLevels = new ArrayList<String>(this.getParameterService() .getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSET_BUILDER_DOCUMENT.class, CabParameterConstants.CapitalAsset.POSSIBLE_CAPITAL_ASSET_OBJECT_LEVELS)); if (possibleCAMSObjectLevels.contains(objectCode.getFinancialObjectLevelCode())) { String warning = configurationService.getPropertyValueAsString( CabKeyConstants.WARNING_ABOVE_THRESHOLD_SUGESTS_CAPITAL_ASSET_LEVEL); warning = StringUtils.replace(warning, "{0}", itemIdentifier); warning = StringUtils.replace(warning, "{1}", priceThreshold.toString()); KNSGlobalVariables.getMessageList().add(warning); return false; } } return true; }
From source file:org.marketcetera.strategy.LanguageTestBase.java
/** * Executes a single iteration of the <code>getOptionPositionAsOf</code> test. * * @param inOptionRoot a <code>String</code> value * @param inExpiry a <code>String</code> value * @param inStrikePrice a <code>BigDecimal</code> value * @param inOptionType an <code>OptionType</code> value * @param inDate a <code>Date</code> value * @param inExpectedPosition a <code>BigDecimal</code> value * @throws Exception if an unexpected error occurs *///from w w w. jav a 2s. c o m private void doOptionPositionAsOfTest(String inOptionRoot, String inExpiry, BigDecimal inStrikePrice, OptionType inOptionType, Date inDate, BigDecimal inExpectedPosition) throws Exception { StrategyCoordinates strategy = getPositionsStrategy(); setPropertiesToNull(); AbstractRunningStrategy.setProperty("optionPositionAsOfDuringStop", "not-empty"); if (inOptionRoot != null) { AbstractRunningStrategy.setProperty("optionRoot", inOptionRoot); } if (inExpiry != null) { AbstractRunningStrategy.setProperty("expiry", inExpiry); } if (inStrikePrice != null) { AbstractRunningStrategy.setProperty("strikePrice", inStrikePrice.toPlainString()); } if (inOptionType != null) { AbstractRunningStrategy.setProperty("optionType", inOptionType.toString()); } if (inDate != null) { AbstractRunningStrategy.setProperty("date", Long.toString(inDate.getTime())); } verifyStrategyStartsAndStops(strategy.getName(), getLanguage(), strategy.getFile(), null, null, null); // verify expected results assertEquals((inExpectedPosition == null ? null : inExpectedPosition.toString()), AbstractRunningStrategy.getProperty("optionPositionAsOf")); assertNull(AbstractRunningStrategy.getProperty("optionPositionAsOfDuringStop")); }
From source file:org.kuali.ole.select.document.OleInvoiceDocument.java
public void loadInvoiceDocument() { try {/* w ww. j ava 2 s. c o m*/ long b1 = System.currentTimeMillis(); // super.processAfterRetrieve(); LOG.debug("###########inside OleInvoiceDocument processAfterRetrieve###########"); if (this.getPaymentMethodId() != null) { OlePaymentMethod olePaymentMethod = SpringContext.getBean(BusinessObjectService.class) .findBySinglePrimaryKey(OlePaymentMethod.class, this.getPaymentMethodId()); this.setPaymentMethod(olePaymentMethod); this.setPaymentMethodIdentifier(this.getPaymentMethodId().toString()); } if (this.getInvoiceTypeId() != null) { this.setInvoiceTypeHdnId(this.getInvoiceTypeId().toString()); } if (this.getInvoiceSubTypeId() != null) { this.setInvoiceSubTypeHdnId(this.getInvoiceSubTypeId().toString()); } if (this.getVendorInvoiceAmount() != null) { this.setInvoiceAmount(this.getVendorInvoiceAmount().toString()); } if (this.getForeignVendorInvoiceAmount() != null) { this.setForeignInvoiceAmount(this.getForeignVendorInvoiceAmount().toString()); } List<BigDecimal> newUnitPriceList = new ArrayList<BigDecimal>(); BigDecimal newUnitPrice = new BigDecimal(0); BigDecimal hundred = new BigDecimal(100); List<OleInvoiceItem> item = this.getItems(); String titleId = null; //int itemCount = 0; /* List<String> itemIds = new ArrayList<>(); for(OleInvoiceItem invoiceItem : (List<OleInvoiceItem>)this.getItems()){ if(invoiceItem.getItemTitleId()!=null){ itemIds.add(invoiceItem.getItemTitleId()); } } DocstoreClientLocator docstoreClientLocator = new DocstoreClientLocator(); List<Bib> bibs = new ArrayList<>(); if(itemIds.size()>0){ bibs = docstoreClientLocator.getDocstoreClient().retrieveBibs(itemIds); }*/ String itemDescription = ""; BigDecimal exchangeRate = new BigDecimal("0"); if (this.getInvoiceCurrencyTypeId() != null) { OleCurrencyType oleCurrencyType = SpringContext.getBean(BusinessObjectService.class) .findBySinglePrimaryKey(OleCurrencyType.class, this.getInvoiceCurrencyTypeId()); this.setOleCurrencyType(oleCurrencyType); this.setInvoiceCurrencyType(this.getInvoiceCurrencyTypeId().toString()); if (oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; this.setForeignCurrencyFlag(false); } else { currencyTypeIndicator = false; this.setForeignCurrencyFlag(true); } } else { if (this.getVendorDetail() != null && this.getVendorDetail().getCurrencyType() != null) { if (this.getVendorDetail().getCurrencyType().getCurrencyType() .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; this.setForeignCurrencyFlag(false); this.setInvoiceCurrencyType( this.getVendorDetail().getCurrencyType().getCurrencyTypeId().toString()); } else { currencyTypeIndicator = false; this.setForeignCurrencyFlag(true); this.setInvoiceCurrencyType( this.getVendorDetail().getCurrencyType().getCurrencyTypeId().toString()); } } } if (this.getInvoiceCurrencyTypeId() != null && (!currencyTypeIndicator)) { if (StringUtils.isBlank(this.getInvoiceCurrencyExchangeRate())) { exchangeRate = SpringContext.getBean(OleInvoiceService.class) .getExchangeRate(this.getInvoiceCurrencyType()).getExchangeRate(); this.setInvoiceCurrencyExchangeRate(exchangeRate.toString()); // items.setItemExchangeRate(new KualiDecimal(exchangeRate)); // items.setExchangeRate(exchangeRate.toString()); } } for (int i = 0; item.size() > i; i++) { OleInvoiceItem items = (OleInvoiceItem) this.getItem(i); if (this.getInvoiceCurrencyTypeId() != null) { items.setItemCurrencyType(oleCurrencyType.getCurrencyType()); items.setInvoicedCurrency(oleCurrencyType.getCurrencyType()); } else { if (this.getVendorDetail() != null && this.getVendorDetail().getCurrencyType() != null) { items.setItemCurrencyType(this.getVendorDetail().getCurrencyType().getCurrencyType()); items.setInvoicedCurrency(this.getVendorDetail().getCurrencyType().getCurrencyType()); } } if (this.getInvoiceCurrencyTypeId() != null && (!currencyTypeIndicator)) { if (StringUtils.isNotBlank(this.getInvoiceCurrencyExchangeRate())) { try { // Double.parseDouble(this.getInvoiceCurrencyExchangeRate()); items.setItemExchangeRate(new KualiDecimal(this.getInvoiceCurrencyExchangeRate())); items.setExchangeRate(this.getInvoiceCurrencyExchangeRate()); } catch (NumberFormatException nfe) { throw new RuntimeException("Invalid Exchange Rate", nfe); } } else { items.setItemExchangeRate(new KualiDecimal(exchangeRate)); items.setExchangeRate(exchangeRate.toString()); } if (items.getItemExchangeRate() != null && items.getItemForeignUnitCost() != null && !this.getApplicationDocumentStatus().equals("Department-Approved")) { items.setItemUnitCostUSD(new KualiDecimal(items.getItemForeignUnitCost().bigDecimalValue() .divide(new BigDecimal(items.getExchangeRate()), 4, BigDecimal.ROUND_HALF_UP))); items.setItemUnitPrice(items.getItemForeignUnitCost().bigDecimalValue() .divide(new BigDecimal(items.getExchangeRate()), 4, BigDecimal.ROUND_HALF_UP)); items.setItemListPrice(items.getItemUnitCostUSD()); items.setExtendedPrice(items.calculateExtendedPrice()); } //this.setForeignVendorInvoiceAmount(this.getVendorInvoiceAmount().bigDecimalValue().multiply(tempOleExchangeRate.getExchangeRate())); } if (LOG.isDebugEnabled()) { LOG.debug("Title id while retriving ------>" + items.getItemTitleId()); } if (items.getItemTitleId() != null) { BibInfoRecord bibInfoRecord = items.getBibInfoRecord(); if (bibInfoRecord != null) { items.setBibUUID(bibInfoRecord.getBibIdStr()); items.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(items.getItemTitleId())); itemDescription = ((bibInfoRecord.getTitle() != null && !bibInfoRecord.getTitle().isEmpty()) ? bibInfoRecord.getTitle().trim() + ", " : "") + ((bibInfoRecord.getAuthor() != null && !bibInfoRecord.getAuthor().isEmpty()) ? bibInfoRecord.getAuthor().trim() + ", " : "") + ((bibInfoRecord.getPublisher() != null && !bibInfoRecord.getPublisher().isEmpty()) ? bibInfoRecord.getPublisher().trim() + ", " : "") + ((bibInfoRecord.getIsxn() != null && !bibInfoRecord.getIsxn().isEmpty()) ? bibInfoRecord.getIsxn().trim() + ", " : ""); } if (itemDescription != null && !(itemDescription.equals(""))) { itemDescription = itemDescription.lastIndexOf(",") < 0 ? itemDescription : itemDescription.substring(0, itemDescription.lastIndexOf(",")); StringEscapeUtils stringEscapeUtils = new StringEscapeUtils(); itemDescription = stringEscapeUtils.unescapeXml(itemDescription); items.setItemDescription(itemDescription); } HashMap<String, String> queryMap = new HashMap<String, String>(); if (items.getPoItemIdentifier() != null) { queryMap.put(OLEConstants.OleCopy.PO_ITM_ID, items.getPoItemIdentifier().toString()); List<OLELinkPurapDonor> oleLinkPurapDonorList = (List<OLELinkPurapDonor>) getBusinessObjectService() .findMatching(OLELinkPurapDonor.class, queryMap); if (oleLinkPurapDonorList != null) { items.setOleDonors(oleLinkPurapDonorList); oleLinkPurapDonorList.clear(); } } } if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) { if (items.getItemDiscount() == null) { items.setItemDiscount(KualiDecimal.ZERO); } if (items.getItemListPrice() == null) { items.setItemListPrice(KualiDecimal.ZERO); } /* if (items.getItemDiscountType() != null && items.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) { newUnitPrice = (hundred.subtract(items.getItemDiscount().bigDecimalValue())).divide(hundred).multiply(items.getItemListPrice().bigDecimalValue()); } else { newUnitPrice = items.getItemListPrice().bigDecimalValue().subtract(items.getItemDiscount().bigDecimalValue()); } items.setItemSurcharge(items.getItemUnitPrice().subtract(newUnitPrice).setScale(4, RoundingMode.HALF_UP));*/ } /*else if (items.getItemType().isAdditionalChargeIndicator() && (!currencyTypeIndicator)) { if (items.getItemForeignUnitCost() != null) { items.setAdditionalForeignUnitCost(items.getItemForeignUnitCost().toString()); } }*/ items.setOleOpenQuantity(String.valueOf(items.getPoOutstandingQuantity())); } if (this.getVendorHeaderGeneratedIdentifier() != null && this.getVendorDetailAssignedIdentifier() != null) { this.setVendorId(this.getVendorHeaderGeneratedIdentifier().toString() + "-" + this.getVendorDetailAssignedIdentifier().toString()); } if (this.getProrateBy() != null) { this.setProrateQty(this.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)); this.setProrateManual(this.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)); this.setProrateDollar(this.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)); this.setNoProrate(this.getProrateBy().equals(OLEConstants.NO_PRORATE)); } long b2 = System.currentTimeMillis(); long tot = b2 - b1; LOG.info("loadInvoiceDocument" + tot); } catch (Exception e) { LOG.error("Exception during processAfterRetrieve in OleInvoiceDocument " + e); throw new RuntimeException(e); } }
From source file:com.ibm.soatf.component.soap.builder.SampleXmlUtil.java
private String formatDecimal(String start, SchemaType sType) { BigDecimal result = new BigDecimal(start); XmlDecimal xmlD;//from ww w. j a v a 2 s . c o m xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); BigDecimal min = xmlD != null ? xmlD.getBigDecimalValue() : null; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); BigDecimal max = xmlD != null ? xmlD.getBigDecimalValue() : null; boolean minInclusive = true, maxInclusive = true; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (xmlD != null) { BigDecimal minExcl = xmlD.getBigDecimalValue(); if (min == null || min.compareTo(minExcl) < 0) { min = minExcl; minInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (xmlD != null) { BigDecimal maxExcl = xmlD.getBigDecimalValue(); if (max == null || max.compareTo(maxExcl) > 0) { max = maxExcl; maxInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_TOTAL_DIGITS); int totalDigits = -1; if (xmlD != null) { totalDigits = xmlD.getBigDecimalValue().intValue(); StringBuilder sb = new StringBuilder(totalDigits); for (int i = 0; i < totalDigits; i++) sb.append('9'); BigDecimal digitsLimit = new BigDecimal(sb.toString()); if (max != null && max.compareTo(digitsLimit) > 0) { max = digitsLimit; maxInclusive = true; } digitsLimit = digitsLimit.negate(); if (min != null && min.compareTo(digitsLimit) < 0) { min = digitsLimit; minInclusive = true; } } int sigMin = min == null ? 1 : result.compareTo(min); int sigMax = max == null ? -1 : result.compareTo(max); boolean minOk = sigMin > 0 || sigMin == 0 && minInclusive; boolean maxOk = sigMax < 0 || sigMax == 0 && maxInclusive; // Compute the minimum increment xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_FRACTION_DIGITS); int fractionDigits = -1; BigDecimal increment; if (xmlD == null) increment = new BigDecimal(1); else { fractionDigits = xmlD.getBigDecimalValue().intValue(); if (fractionDigits > 0) { StringBuilder sb = new StringBuilder("0."); for (int i = 1; i < fractionDigits; i++) sb.append('0'); sb.append('1'); increment = new BigDecimal(sb.toString()); } else increment = new BigDecimal(1); } if (minOk && maxOk) { // OK } else if (minOk && !maxOk) { // TOO BIG if (maxInclusive) result = max; else result = max.subtract(increment); } else if (!minOk && maxOk) { // TOO SMALL if (minInclusive) result = min; else result = min.add(increment); } else { // MIN > MAX!! } // We have the number // Adjust the scale according to the totalDigits and fractionDigits int digits = 0; BigDecimal ONE = new BigDecimal(BigInteger.ONE); for (BigDecimal n = result; n.abs().compareTo(ONE) >= 0; digits++) n = n.movePointLeft(1); if (fractionDigits > 0) if (totalDigits >= 0) result.setScale(Math.max(fractionDigits, totalDigits - digits)); else result.setScale(fractionDigits); else if (fractionDigits == 0) result.setScale(0); return result.toString(); }
From source file:com.centeractive.ws.builder.soap.SampleXmlUtil.java
private String formatDecimal(String start, SchemaType sType) { BigDecimal result = new BigDecimal(start); XmlDecimal xmlD;/*from w ww .j a va 2 s. c om*/ xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE); BigDecimal min = xmlD != null ? xmlD.getBigDecimalValue() : null; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE); BigDecimal max = xmlD != null ? xmlD.getBigDecimalValue() : null; boolean minInclusive = true, maxInclusive = true; xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE); if (xmlD != null) { BigDecimal minExcl = xmlD.getBigDecimalValue(); if (min == null || min.compareTo(minExcl) < 0) { min = minExcl; minInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE); if (xmlD != null) { BigDecimal maxExcl = xmlD.getBigDecimalValue(); if (max == null || max.compareTo(maxExcl) > 0) { max = maxExcl; maxInclusive = false; } } xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_TOTAL_DIGITS); int totalDigits = -1; if (xmlD != null) { totalDigits = xmlD.getBigDecimalValue().intValue(); StringBuffer sb = new StringBuffer(totalDigits); for (int i = 0; i < totalDigits; i++) sb.append('9'); BigDecimal digitsLimit = new BigDecimal(sb.toString()); if (max != null && max.compareTo(digitsLimit) > 0) { max = digitsLimit; maxInclusive = true; } digitsLimit = digitsLimit.negate(); if (min != null && min.compareTo(digitsLimit) < 0) { min = digitsLimit; minInclusive = true; } } int sigMin = min == null ? 1 : result.compareTo(min); int sigMax = max == null ? -1 : result.compareTo(max); boolean minOk = sigMin > 0 || sigMin == 0 && minInclusive; boolean maxOk = sigMax < 0 || sigMax == 0 && maxInclusive; // Compute the minimum increment xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_FRACTION_DIGITS); int fractionDigits = -1; BigDecimal increment; if (xmlD == null) increment = new BigDecimal(1); else { fractionDigits = xmlD.getBigDecimalValue().intValue(); if (fractionDigits > 0) { StringBuffer sb = new StringBuffer("0."); for (int i = 1; i < fractionDigits; i++) sb.append('0'); sb.append('1'); increment = new BigDecimal(sb.toString()); } else increment = new BigDecimal(1); } if (minOk && maxOk) { // OK } else if (minOk && !maxOk) { // TOO BIG if (maxInclusive) result = max; else result = max.subtract(increment); } else if (!minOk && maxOk) { // TOO SMALL if (minInclusive) result = min; else result = min.add(increment); } else { // MIN > MAX!! } // We have the number // Adjust the scale according to the totalDigits and fractionDigits int digits = 0; BigDecimal ONE = new BigDecimal(BigInteger.ONE); for (BigDecimal n = result; n.abs().compareTo(ONE) >= 0; digits++) n = n.movePointLeft(1); if (fractionDigits > 0) if (totalDigits >= 0) result.setScale(Math.max(fractionDigits, totalDigits - digits)); else result.setScale(fractionDigits); else if (fractionDigits == 0) result.setScale(0); return result.toString(); }
From source file:org.openbravo.erpCommon.ad_forms.AcctServer.java
public BigDecimal convertAmount(BigDecimal _amount, boolean isReceipt, String dateAcct, String table_ID, String record_ID, String currencyIDFrom, String currencyIDTo, DocLine line, AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn, boolean bookDifferences) throws ServletException { BigDecimal amtDiff = BigDecimal.ZERO; if (_amount == null || _amount.compareTo(BigDecimal.ZERO) == 0) { return _amount; }//from w w w.j a v a 2 s.co m String conversionDate = dateAcct; String strDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties() .getProperty("dateFormat.java"); final SimpleDateFormat dateFormat = new SimpleDateFormat(strDateFormat); ConversionRateDoc conversionRateDoc = getConversionRateDoc(table_ID, record_ID, currencyIDFrom, currencyIDTo); BigDecimal amtFrom = BigDecimal.ZERO; BigDecimal amtFromSourcecurrency = BigDecimal.ZERO; BigDecimal amtTo = BigDecimal.ZERO; if (table_ID.equals(TABLEID_Invoice)) { Invoice invoice = OBDal.getInstance().get(Invoice.class, record_ID); conversionDate = dateFormat.format(invoice.getAccountingDate()); } else if (table_ID.equals(TABLEID_Payment)) { FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, record_ID); conversionDate = dateFormat.format(payment.getPaymentDate()); } else if (table_ID.equals(TABLEID_Transaction)) { FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class, record_ID); conversionDate = dateFormat.format(transaction.getDateAcct()); } if (conversionRateDoc != null && record_ID != null) { amtFrom = applyRate(_amount, conversionRateDoc, true); } else { // I try to find a reversal rate for the doc, if exists i apply it reversal as well conversionRateDoc = getConversionRateDoc(table_ID, record_ID, currencyIDTo, currencyIDFrom); if (conversionRateDoc != null) { amtFrom = applyRate(_amount, conversionRateDoc, false); } else { String convertedAmt = getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo, conversionDate, "", AD_Client_ID, AD_Org_ID, conn); if (convertedAmt != null && !"".equals(convertedAmt)) { amtFrom = new BigDecimal(convertedAmt); } else { throw new OBException("@NotConvertible@"); } } } ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDFrom, currencyIDTo); if (AD_Table_ID.equals(TABLEID_Invoice)) { Invoice invoice = OBDal.getInstance().get(Invoice.class, Record_ID); conversionDate = dateFormat.format(invoice.getAccountingDate()); } else if (AD_Table_ID.equals(TABLEID_Payment)) { FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, Record_ID); conversionDate = dateFormat.format(payment.getPaymentDate()); } else if (AD_Table_ID.equals(TABLEID_Transaction) || AD_Table_ID.equals(TABLEID_Reconciliation)) { String transactionID = Record_ID; // When TableID= Reconciliation info is loaded from transaction if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation) && line instanceof DocLine_FINReconciliation) { transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId(); } FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class, transactionID); conversionDate = dateFormat.format(transaction.getDateAcct()); conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(), currencyIDFrom, currencyIDTo); } else { conversionDate = dateAcct; } if (conversionRateCurrentDoc != null) { amtTo = applyRate(_amount, conversionRateCurrentDoc, true); amtFromSourcecurrency = applyRate(amtFrom, conversionRateCurrentDoc, false); } else { // I try to find a reversal rate for the doc, if exists i apply it reversal as well if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation) && line instanceof DocLine_FINReconciliation) { String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId(); conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transactionID, currencyIDTo, currencyIDFrom); } else { conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDTo, currencyIDFrom); } if (conversionRateCurrentDoc != null) { amtTo = applyRate(_amount, conversionRateCurrentDoc, false); amtFromSourcecurrency = applyRate(amtFrom, conversionRateCurrentDoc, true); } else { String convertedAmt = getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo, conversionDate, "", AD_Client_ID, AD_Org_ID, conn); if (convertedAmt != null && !"".equals(convertedAmt)) { amtTo = new BigDecimal(convertedAmt); } else { throw new OBException("@NotConvertible@"); } if (amtTo.compareTo(BigDecimal.ZERO) != 0) amtFromSourcecurrency = amtFrom.multiply(_amount).divide(amtTo, conversionRatePrecision, BigDecimal.ROUND_HALF_EVEN); else amtFromSourcecurrency = amtFrom; } } amtDiff = (amtTo).subtract(amtFrom); // Add differences related to Different rates for accounting among currencies // _amount * ((TrxRate * // AccountingRateCurrencyFromCurrencyTo)-AccountingRateCurrencyDocCurrencyTo) amtDiff = amtDiff.add(calculateMultipleRatesDifferences(_amount, currencyIDFrom, currencyIDTo, line, conn)); Currency currencyTo = OBDal.getInstance().get(Currency.class, currencyIDTo); amtDiff = amtDiff.setScale(currencyTo.getStandardPrecision().intValue(), BigDecimal.ROUND_HALF_EVEN); if (bookDifferences) { if ((!isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == 1) || (isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == -1)) { fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn), currencyIDTo, "", amtDiff.abs().toString(), Fact_Acct_Group_ID, seqNo, DocumentType, conn); } else if (amtDiff.compareTo(BigDecimal.ZERO) != 0) { fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn), currencyIDTo, amtDiff.abs().toString(), "", Fact_Acct_Group_ID, seqNo, DocumentType, conn); } else { return amtFromSourcecurrency; } } if (log4j.isDebugEnabled()) log4j.debug("Amt from: " + amtFrom + "[" + currencyIDFrom + "]" + " Amt to: " + amtTo + "[" + currencyIDTo + "] - amtFromSourcecurrency: " + amtFromSourcecurrency); // return value in original currency return amtFromSourcecurrency; }
From source file:pe.gob.mef.gescon.web.ui.PreguntaMB.java
public String save() throws Exception { String pagina = ""; try {//from w w w .j a v a2s . co m if (CollectionUtils.isEmpty(this.getListaPregunta())) { this.setListaPregunta(Collections.EMPTY_LIST); } BigDecimal idperfil; LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); Pregunta pregunta = new Pregunta(); PreguntaService service = (PreguntaService) ServiceFinder.findBean("PreguntaService"); pregunta.setNpreguntaid(service.getNextPK()); pregunta.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); pregunta.setVasunto(this.getAsunto().trim()); pregunta.setVdetalle(this.getDetalle().trim()); pregunta.setNentidadid(this.getEntidadId()); pregunta.setVdatoadicional(this.getDatoAdicional().trim()); pregunta.setNdestacado(BigDecimal.ZERO); pregunta.setNactivo(BigDecimal.ONE); pregunta.setDfechacreacion(new Date()); pregunta.setVusuariocreacion(user.getVlogin()); if (this.getSelectedCategoria().getNflagbp().equals(BigDecimal.ONE)) { pregunta.setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_POR_VERIFICAR))); } else { pregunta.setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_PUBLICADO))); pregunta.setDfechapublicacion(new Date()); } service.saveOrUpdate(pregunta); String ruta0 = this.path + pregunta.getNpreguntaid().toString() + "/" + BigDecimal.ZERO.toString() + "/"; String texto = pregunta.getVasunto() + " \n " + pregunta.getVdetalle() + " \n " + pregunta.getVrespuesta(); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", texto); if (this.getSelectedCategoria().getNflagpr().toString().equals("1")) { Asignacion asignacion = new Asignacion(); AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService"); asignacion.setNasignacionid(serviceasig.getNextPK()); asignacion.setNtipoconocimientoid(Constante.PREGUNTAS); asignacion.setNconocimientoid(pregunta.getNpreguntaid()); asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1"))); CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService"); asignacion.setNusuarioid( categoriaService.getCategoriaById(pregunta.getNcategoriaid()).getNmoderador()); asignacion.setDfechaasignacion(new Date()); asignacion.setDfechacreacion(new Date()); serviceasig.saveOrUpdate(asignacion); } idperfil = service.obtenerPerfilxUsuario(user.getNusuarioid()); if (Integer.parseInt(idperfil.toString()) != Constante.USUARIOEXTERNO) { pagina = "/pages/pregunta/lista?faces-redirect=true"; } else { pagina = "/index?faces-redirect=true"; } listaPregunta = service.getPreguntas(); RequestContext.getCurrentInstance().execute("PF('newDialog').hide();"); } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } return pagina; }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Set the given value as a parameter to the statement. *///from w ww.ja v a2 s .c o m public void setBigDecimal(PreparedStatement stmnt, int idx, BigDecimal val, Column col) throws SQLException { if ((col != null && col.isCompatible(Types.VARCHAR, null, 0, 0)) || (col == null && storeLargeNumbersAsStrings)) setString(stmnt, idx, val.toString(), col); else stmnt.setBigDecimal(idx, val); }
From source file:pcgen.core.Equipment.java
/** * return the list of modifier keys as a period-delimeted string * // ww w. j av a 2 s . c o m * @param bPrimary * Description of the Parameter * @return The eqModifierString value */ private String getEqModifierString(final boolean bPrimary) { final List<EquipmentModifier> eqModList = getEqModifierList(bPrimary); final StringBuilder aString = new StringBuilder(eqModList.size() * 10); for (EquipmentModifier eqMod : eqModList) { if (aString.length() != 0) { aString.append('.'); } aString.append(eqMod.getKeyName()); // Add the modifiers for (String strMod : getAssociationList(eqMod)) { aString.append('|').append(strMod.replace('|', '=')); } } if (bPrimary) { BigDecimal mod = get(ObjectKey.WEIGHT_MOD); if (mod != null) { if (aString.length() != 0) { aString.append('.'); } aString.append(EQMOD_WEIGHT).append('|').append(mod.toString().replace('.', ',')); } } String dmg = get(StringKey.DAMAGE_OVERRIDE); if (dmg != null) { if (aString.length() != 0) { aString.append('.'); } aString.append(EQMOD_DAMAGE).append('|').append(dmg.replace('.', ',')); } return aString.toString(); }
From source file:com.lp.server.lieferschein.ejbfac.LieferscheinFacBean.java
/** * Fuer die Nachkalkulation des Lieferscheins den Ist-Verkaufswert (= * NettoVerkaufspreisPlusAufschlaegeMinusRabatte pro Stueck * gelieferte * Menge) bezogen auf eine bestimmte Artikelart berechnen. <br> * Beruecksichtigt werden alle mengenbehafteten Lieferscheinpositionen. * /*from w ww . j a va2s.c o m*/ * @param iIdLieferscheinI * PK des Lieferscheins * @param sArtikelartI * die gewuenschte Artikelart * @param theClientDto * der aktuelle Benutzer * @return BigDecimal der Verkaufswert der Artikelart Ist in * Mandantenwaehrung * @throws EJBExceptionLP * Ausnahme */ public BigDecimal berechneVerkaufswertIst(Integer iIdLieferscheinI, HashMap lieferscheinpositionIIds, String sArtikelartI, TheClientDto theClientDto) throws EJBExceptionLP { final String METHOD_NAME = "berechneVerkaufswertIst"; myLogger.entry(); if (iIdLieferscheinI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("iIdLieferscheinI == null")); } if (sArtikelartI == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("sArtikelartI == null")); } BigDecimal bdVerkaufswertIstO = Helper.getBigDecimalNull(); try { LieferscheinpositionDto[] aLieferscheinpositionDtos = getLieferscheinpositionFac() .lieferscheinpositionFindByLieferscheinIId(iIdLieferscheinI); for (int i = 0; i < aLieferscheinpositionDtos.length; i++) { if (lieferscheinpositionIIds == null || lieferscheinpositionIIds.containsKey(aLieferscheinpositionDtos[i].getIId())) { // alle mengenbehafteten Positionen beruecksichtigen if (aLieferscheinpositionDtos[i].getNMenge() != null && aLieferscheinpositionDtos[i].getArtikelIId() != null) { ArtikelDto oArtikelDto = getArtikelFac().artikelFindByPrimaryKey( aLieferscheinpositionDtos[i].getArtikelIId(), theClientDto); BigDecimal bdBeitragDieserPosition = aLieferscheinpositionDtos[i].getNMenge() .multiply(aLieferscheinpositionDtos[i] .getNNettoeinzelpreisplusversteckteraufschlagminusrabatte()); // je nach Artikelart beruecksichtigen if (sArtikelartI.equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { if (oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdVerkaufswertIstO = bdVerkaufswertIstO.add(bdBeitragDieserPosition); } } else { if (!oArtikelDto.getArtikelartCNr().equals(ArtikelFac.ARTIKELART_ARBEITSZEIT)) { bdVerkaufswertIstO = bdVerkaufswertIstO.add(bdBeitragDieserPosition); } } } } } } catch (RemoteException ex) { throwEJBExceptionLPRespectOld(ex); } myLogger.exit("Verkaufswert " + sArtikelartI + " Ist : " + bdVerkaufswertIstO.toString()); return bdVerkaufswertIstO; }