List of usage examples for java.math BigDecimal ROUND_HALF_UP
int ROUND_HALF_UP
To view the source code for java.math BigDecimal ROUND_HALF_UP.
Click Source Link
From source file:com.gp.cong.logisoft.lcl.report.LclAllBLPdfCreator.java
public void setCaribbenAndNonCaribben(LclBlPiece lclBlPiece, String impKeyValue, String metKeyValue, boolean iscaribben) throws Exception { String AWImp = "0.000", AVImp = "0.000"; String AWMet = "0.000", AVMet = "0.000"; if (lclBlPiece.getActualWeightImperial() != null) { AWImp = "Y".equalsIgnoreCase(impKeyValue) ? NumberUtils.convertToThreeDecimalhash(lclBlPiece.getActualWeightImperial().doubleValue()) : lclBlPiece.getActualWeightImperial().setScale(0, BigDecimal.ROUND_HALF_UP).toString(); }/* w w w . j av a 2 s .c o m*/ if (lclBlPiece.getActualVolumeImperial() != null) { AVImp = "Y".equalsIgnoreCase(impKeyValue) ? NumberUtils.convertToThreeDecimalhash(lclBlPiece.getActualVolumeImperial().doubleValue()) : lclBlPiece.getActualVolumeImperial().setScale(0, BigDecimal.ROUND_HALF_UP).toString(); } if ("N".equalsIgnoreCase(metKeyValue) && lclBlPiece.getActualWeightMetric() != null) { AWMet = NumberUtils.convertToThreeDecimalhash(lclBlPiece.getActualWeightMetric().doubleValue()); } if ("N".equalsIgnoreCase(metKeyValue) && lclBlPiece.getActualVolumeMetric() != null) { AVMet = NumberUtils.convertToThreeDecimalhash(lclBlPiece.getActualVolumeMetric().doubleValue()); } Paragraph p = null; cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); PdfPTable inner_Table = new PdfPTable(1); inner_Table.setWidthPercentage(100f); PdfPCell inner_Cell = null; inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); inner_Cell.setBorderWidthBottom(0.6f); p = new Paragraph(6f, iscaribben ? "LBS" : "KGS", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); p = new Paragraph(7f, iscaribben ? AWImp : AWMet, totalFontQuote); p.setAlignment(Element.ALIGN_CENTER); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); inner_Cell.setPaddingBottom(18f); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); if ("N".equalsIgnoreCase(metKeyValue)) { inner_Cell.setBorderWidthBottom(0.6f); p = new Paragraph(6f, iscaribben ? "KGS" : "LBS", blackBoldFont65); } else { AWMet = ""; AWImp = ""; p = new Paragraph(6f, "", blackBoldFont65); } p.setAlignment(Element.ALIGN_LEFT); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); p = new Paragraph(7f, iscaribben ? AWMet : AWImp, totalFontQuote); p.setAlignment(Element.ALIGN_CENTER); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); if (commodity_count != lclBlPiecesList.size()) { inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); inner_Cell.setPaddingBottom(16f); inner_Table.addCell(inner_Cell); } cell.addElement(inner_Table); table.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); inner_Table = new PdfPTable(1); inner_Table.setWidthPercentage(100f); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); inner_Cell.setBorderWidthBottom(0.6f); p = new Paragraph(6f, iscaribben ? "CU.FT." : "CBM", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); p = new Paragraph(7f, iscaribben ? AVImp : AVMet, totalFontQuote); p.setAlignment(Element.ALIGN_CENTER); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); inner_Cell.setPaddingBottom(18f); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); if ("N".equalsIgnoreCase(metKeyValue)) { inner_Cell.setBorderWidthBottom(0.6f); p = new Paragraph(6f, iscaribben ? "CBM" : "CU.FT.", blackBoldFont65); } else { AVMet = ""; AVImp = ""; p = new Paragraph(6f, "", blackBoldFont65); } p.setAlignment(Element.ALIGN_LEFT); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); p = new Paragraph(7f, iscaribben ? AVMet : AVImp, totalFontQuote); p.setAlignment(Element.ALIGN_CENTER); inner_Cell.addElement(p); inner_Table.addCell(inner_Cell); if (commodity_count != lclBlPiecesList.size()) { inner_Cell = new PdfPCell(); inner_Cell.setBorder(0); inner_Cell.setPaddingBottom(16f); inner_Table.addCell(inner_Cell); } cell.addElement(inner_Table); table.addCell(cell); }
From source file:org.egov.ptis.service.es.PropertyTaxElasticSearchIndexService.java
/** * Prepares DCB Details/* www . java2 s. c o m*/ * @param individualDmdDetails * @param demandDivisionMap */ private void prepareDCBDetailsMap(final StringTerms individualDmdDetails, final Map<String, Map<String, BigDecimal>> demandDivisionMap) { Map<String, BigDecimal> individualDmdMap; Sum arrearDmd; Sum currentDmd; Sum arrearInterestDmd; Sum currentInterestDmd; Sum totalDmd; Sum adjustment; Sum arrearColl; Sum currentColl; Sum arrearInterestColl; Sum currentInterestColl; Sum advanceColl; Sum rebate; Sum totalColl; if (individualDmdDetails != null) for (final Terms.Bucket entry : individualDmdDetails.getBuckets()) { individualDmdMap = new HashMap<>(); arrearDmd = entry.getAggregations().get(ARREAR_DMD_STR); currentDmd = entry.getAggregations().get(CURR_DMD); arrearInterestDmd = entry.getAggregations().get(ARREAR_INTEREST_DMD); currentInterestDmd = entry.getAggregations().get(CURR_INTEREST_DMD); totalDmd = entry.getAggregations().get("total_dmd"); adjustment = entry.getAggregations().get("adjustment"); arrearColl = entry.getAggregations().get("arrear_coll"); currentColl = entry.getAggregations().get("curr_coll"); arrearInterestColl = entry.getAggregations().get("arrear_interest_coll"); currentInterestColl = entry.getAggregations().get("curr_interest_coll"); advanceColl = entry.getAggregations().get("advance"); rebate = entry.getAggregations().get(REBATE_STR); totalColl = entry.getAggregations().get("total_coll"); individualDmdMap.put(ARREAR_DMD, BigDecimal.valueOf(arrearDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(CURRENT_DMD, BigDecimal.valueOf(currentDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(ARREAR_INT_DMD, BigDecimal.valueOf(arrearInterestDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(CURRENT_INT_DMD, BigDecimal.valueOf(currentInterestDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(TOTAL_DMD_STR, BigDecimal.valueOf(totalDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put("adjustment", BigDecimal.valueOf(adjustment.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(ARREAR_COLL_STR, BigDecimal.valueOf(arrearColl.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(CURRENT_COLL_STR, BigDecimal.valueOf(currentColl.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(ARREAR_INT_COLL, BigDecimal.valueOf(arrearInterestColl.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(CURRENT_INT_COLL, BigDecimal.valueOf(currentInterestColl.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(ADVANCE_COLL_STR, BigDecimal.valueOf(advanceColl.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(REBATE_STR, BigDecimal.valueOf(rebate.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(TOTAL_COLL_STR, BigDecimal.valueOf(totalColl.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); demandDivisionMap.put(String.valueOf(entry.getKey()), individualDmdMap); } }
From source file:coffeshop.PaymentPage.java
private void btnScanBTCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScanBTCActionPerformed timeStop = false;/*from w w w .j a v a 2 s .c om*/ btnScanBTC.setEnabled(false); btcTimer(); String btcPay = txtPayAmt.getText(); BigDecimal USD = new BigDecimal(btcPay); BigDecimal USDtoBTC = btcPriceIndex(); BigDecimal BTCDue = USD.divide(USDtoBTC, 5, BigDecimal.ROUND_HALF_UP); USDtoBTC = USDtoBTC.setScale(2, BigDecimal.ROUND_HALF_UP); lblUSDtoBTC.setText("USD/BTC = " + USDtoBTC); lblBTCDue.setText("BTC Due: " + BTCDue); try { generateQR(btcPay); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error generating QR Code"); ex.printStackTrace(); } try { BufferedImage image = ImageIO.read(new File("src/ImageRes/QR.jpg")); ImageIcon icon = new ImageIcon(image); icon.getImage().flush(); lblQRC.setIcon(icon); } catch (IOException ex) { System.out.println(ex.getMessage()); } if (lblQRC.getIcon() == null) { lblQRC.setIcon(defaultQR); JOptionPane.showMessageDialog(null, "Wrong QR Code. Please try again.", "Wrong QR Code", JOptionPane.PLAIN_MESSAGE); } }
From source file:org.egov.ptis.service.es.CollectionIndexElasticSearchService.java
private void setDemandBreakUpForTableData(CollTableData collIndData, BigDecimal arrearDemand, BigDecimal currentDemand, BigDecimal arrearInterestDemand, BigDecimal currentInterestDemand, int noOfMonths) { collIndData.setArrearDemand(arrearDemand); collIndData.setCurrentDemand(currentDemand); collIndData.setArrearInterestDemand(arrearInterestDemand); collIndData.setCurrentInterestDemand(currentInterestDemand); BigDecimal proportionalArrearDmd = (collIndData.getArrearDemand().divide(BigDecimal.valueOf(12), BigDecimal.ROUND_HALF_UP)).multiply(BigDecimal.valueOf(noOfMonths)); BigDecimal proportionalCurrDmd = (collIndData.getCurrentDemand().divide(BigDecimal.valueOf(12), BigDecimal.ROUND_HALF_UP)).multiply(BigDecimal.valueOf(noOfMonths)); collIndData.setProportionalArrearDemand(proportionalArrearDmd); collIndData.setProportionalCurrentDemand(proportionalCurrDmd); }
From source file:org.efaps.esjp.accounting.transaction.Create_Base.java
/** * @param _parameter Parameter as passed from the eFaps API * @param _doc Document// w ww .j a va 2s. c o m * @param _transInst Transaction Instance * @param _type CITYpe * @param _account TargetAccount * @return Instance of the new position * @throws EFapsException on error */ protected Instance insertPosition4Massiv(final Parameter _parameter, final DocumentInfo _doc, final Instance _transInst, final CIType _type, final AccountInfo _account) throws EFapsException { final boolean isDebitTrans = _type.equals(CIAccounting.TransactionPositionDebit); final Instance accInst = _account.getInstance(); Instance periodInst = _parameter.getCallInstance(); if (_parameter.getCallInstance().getType().isKindOf(CIAccounting.SubPeriod.getType())) { final PrintQuery print = new CachedPrintQuery(_parameter.getCallInstance(), SubPeriod_Base.CACHEKEY); final SelectBuilder selPeriodInst = SelectBuilder.get().linkto(CIAccounting.SubPeriod.PeriodLink) .instance(); print.addSelect(selPeriodInst); print.execute(); periodInst = print.<Instance>getSelect(selPeriodInst); } final Instance curInstance = new Period().getCurrency(periodInst).getInstance(); final Insert insert = new Insert(_type); insert.add(CIAccounting.TransactionPositionAbstract.TransactionLink, _transInst.getId()); insert.add(CIAccounting.TransactionPositionAbstract.AccountLink, accInst.getId()); insert.add(CIAccounting.TransactionPositionAbstract.CurrencyLink, curInstance); insert.add(CIAccounting.TransactionPositionAbstract.RateCurrencyLink, _account.getRateInfo().getCurrencyInstance()); insert.add(CIAccounting.TransactionPositionAbstract.Rate, new Object[] { _doc.getRateInfo().getRate(), _account.getRateInfo().getRate() }); final BigDecimal rateAmount = _account.getAmount(); insert.add(CIAccounting.TransactionPositionAbstract.RateAmount, isDebitTrans ? rateAmount.negate() : rateAmount); final BigDecimal amount = _account.getAmountRate(_parameter).setScale(2, BigDecimal.ROUND_HALF_UP); insert.add(CIAccounting.TransactionPositionAbstract.Amount, isDebitTrans ? amount.negate() : amount); insert.execute(); final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.Account2AccountAbstract); queryBldr.addWhereAttrEqValue(CIAccounting.Account2AccountAbstract.FromAccountLink, accInst.getId()); final MultiPrintQuery multi = queryBldr.getPrint(); multi.addAttribute(CIAccounting.Account2AccountAbstract.Numerator, CIAccounting.Account2AccountAbstract.Denominator, CIAccounting.Account2AccountAbstract.ToAccountLink, CIAccounting.Account2AccountAbstract.Config); multi.execute(); while (multi.next()) { final Instance instance = multi.getCurrentInstance(); boolean add = false; Insert insert3 = null; BigDecimal amount2 = amount.multiply( new BigDecimal(multi.<Integer>getAttribute(CIAccounting.Account2AccountAbstract.Numerator)) .divide(new BigDecimal( multi.<Integer>getAttribute(CIAccounting.Account2AccountAbstract.Denominator)), BigDecimal.ROUND_HALF_UP)); BigDecimal rateAmount2 = rateAmount.multiply( new BigDecimal(multi.<Integer>getAttribute(CIAccounting.Account2AccountAbstract.Numerator)) .divide(new BigDecimal( multi.<Integer>getAttribute(CIAccounting.Account2AccountAbstract.Denominator)), BigDecimal.ROUND_HALF_UP)); if (instance.getType().getUUID().equals(CIAccounting.Account2AccountCosting.uuid)) { add = true; insert3 = new Insert(_type); } else if (instance.getType().getUUID().equals(CIAccounting.Account2AccountCostingInverse.uuid)) { if (_type.equals(CIAccounting.TransactionPositionDebit)) { insert3 = new Insert(CIAccounting.TransactionPositionCredit); } else { insert3 = new Insert(CIAccounting.TransactionPositionDebit); } amount2 = amount2.negate(); rateAmount2 = rateAmount2.negate(); add = true; } else if (instance.getType().getUUID().equals(CIAccounting.Account2AccountCredit.uuid)) { if (isDebitTrans) { insert3 = new Insert(CIAccounting.TransactionPositionCredit); } else { insert3 = new Insert(CIAccounting.TransactionPositionDebit); amount2 = amount2.negate(); rateAmount2 = rateAmount2.negate(); } add = true; } else if (instance.getType().getUUID().equals(CIAccounting.Account2AccountDebit.uuid)) { if (isDebitTrans) { insert3 = new Insert(CIAccounting.TransactionPositionDebit); amount2 = amount2.negate(); rateAmount2 = rateAmount2.negate(); } else { insert3 = new Insert(CIAccounting.TransactionPositionCredit); } add = true; } final Collection<Accounting.Account2AccountConfig> configs = multi .getAttribute(CIAccounting.Account2AccountAbstract.Config); add = add && (isDebitTrans && configs != null && configs.contains(Accounting.Account2AccountConfig.APPLY4DEBIT) || !isDebitTrans && configs != null && configs.contains(Accounting.Account2AccountConfig.APPLY4CREDIT)); if (add) { insert3.add(CIAccounting.TransactionPositionAbstract.TransactionLink, _transInst.getId()); insert3.add(CIAccounting.TransactionPositionAbstract.AccountLink, multi.<Long>getAttribute(CIAccounting.Account2AccountAbstract.ToAccountLink)); insert3.add(CIAccounting.TransactionPositionAbstract.CurrencyLink, curInstance); insert3.add(CIAccounting.TransactionPositionAbstract.RateCurrencyLink, _account.getRateInfo().getCurrencyInstance()); insert3.add(CIAccounting.TransactionPositionAbstract.Rate, new Object[] { _doc.getRateInfo().getRate(), _account.getRateInfo().getRate() }); insert3.add(CIAccounting.TransactionPositionAbstract.Amount, amount2); insert3.add(CIAccounting.TransactionPositionAbstract.RateAmount, rateAmount2); insert3.execute(); } } return insert.getInstance(); }
From source file:org.kuali.kfs.module.purap.document.service.impl.PaymentRequestServiceImpl.java
/** * Generates a PurAP accounting line and adds to the specified tax item. * * @param taxItem The specified tax item the accounting line will be associated with. * @param taxableAmount The amount to which tax is computed against. * @return A fully populated PurApAccountingLine instance for the specified tax item. *///from w ww. j ava 2 s .c o m protected PurApAccountingLine addTaxAccountingLine(PurApItem taxItem, BigDecimal taxableAmount) { PaymentRequestDocument preq = taxItem.getPurapDocument(); PurApAccountingLine taxLine = null; try { taxLine = (PurApAccountingLine) taxItem.getAccountingLineClass().newInstance(); } catch (IllegalAccessException e) { throw new InfrastructureException("Unable to access sourceAccountingLineClass", e); } catch (InstantiationException e) { throw new InfrastructureException("Unable to instantiate sourceAccountingLineClass", e); } // tax item type indicators boolean isFederalTax = ItemTypeCodes.ITEM_TYPE_FEDERAL_TAX_CODE.equals(taxItem.getItemTypeCode()); boolean isFederalGross = ItemTypeCodes.ITEM_TYPE_FEDERAL_GROSS_CODE.equals(taxItem.getItemTypeCode()); boolean isStateTax = ItemTypeCodes.ITEM_TYPE_STATE_TAX_CODE.equals(taxItem.getItemTypeCode()); boolean isStateGross = ItemTypeCodes.ITEM_TYPE_STATE_GROSS_CODE.equals(taxItem.getItemTypeCode()); boolean isFederal = isFederalTax || isFederalGross; // true for federal tax/gross; false for state tax/gross boolean isGross = isFederalGross || isStateGross; // true for federal/state gross, false for federal/state tax // obtain accounting line info according to tax item type code String taxChart = null; String taxAccount = null; String taxObjectCode = null; if (isGross) { // for gross up tax items, use preq's first item's first accounting line, which shall exist at this point AccountingLine line1 = preq.getFirstAccount(); taxChart = line1.getChartOfAccountsCode(); taxAccount = line1.getAccountNumber(); taxObjectCode = line1.getFinancialObjectCode(); } else if (isFederalTax) { // for federal tax item, get chart, account, object code info from parameters taxChart = parameterService.getParameterValueAsString(PaymentRequestDocument.class, NRATaxParameters.FEDERAL_TAX_PARM_PREFIX + NRATaxParameters.TAX_PARM_CHART_SUFFIX); taxAccount = parameterService.getParameterValueAsString(PaymentRequestDocument.class, NRATaxParameters.FEDERAL_TAX_PARM_PREFIX + NRATaxParameters.TAX_PARM_ACCOUNT_SUFFIX); taxObjectCode = parameterService.getSubParameterValueAsString(PaymentRequestDocument.class, NRATaxParameters.FEDERAL_TAX_PARM_PREFIX + NRATaxParameters.TAX_PARM_OBJECT_BY_INCOME_CLASS_SUFFIX, preq.getTaxClassificationCode()); if (StringUtils.isBlank(taxChart) || StringUtils.isBlank(taxAccount) || StringUtils.isBlank(taxObjectCode)) { LOG.error("Unable to retrieve federal tax parameters."); throw new RuntimeException("Unable to retrieve federal tax parameters."); } } else if (isStateTax) { // for state tax item, get chart, account, object code info from parameters taxChart = parameterService.getParameterValueAsString(PaymentRequestDocument.class, NRATaxParameters.STATE_TAX_PARM_PREFIX + NRATaxParameters.TAX_PARM_CHART_SUFFIX); taxAccount = parameterService.getParameterValueAsString(PaymentRequestDocument.class, NRATaxParameters.STATE_TAX_PARM_PREFIX + NRATaxParameters.TAX_PARM_ACCOUNT_SUFFIX); taxObjectCode = parameterService.getSubParameterValueAsString(PaymentRequestDocument.class, NRATaxParameters.STATE_TAX_PARM_PREFIX + NRATaxParameters.TAX_PARM_OBJECT_BY_INCOME_CLASS_SUFFIX, preq.getTaxClassificationCode()); if (StringUtils.isBlank(taxChart) || StringUtils.isBlank(taxAccount) || StringUtils.isBlank(taxObjectCode)) { LOG.error("Unable to retrieve state tax parameters."); throw new RuntimeException("Unable to retrieve state tax parameters."); } } // calculate tax amount according to gross up indicator and federal/state tax type /* * The formula of tax and gross up amount are as follows: if (not gross up) gross not existing taxFederal/State = - amount * * rateFederal/State otherwise gross up grossFederal/State = amount * rateFederal/State / (1 - rateFederal - rateState) tax * = - gross */ // pick federal/state tax rate BigDecimal taxPercentFederal = preq.getTaxFederalPercent(); BigDecimal taxPercentState = preq.getTaxStatePercent(); BigDecimal taxPercent = isFederal ? taxPercentFederal : taxPercentState; // divider value according to gross up or not BigDecimal taxDivider = new BigDecimal(100); if (preq.getTaxGrossUpIndicator()) { taxDivider = taxDivider.subtract(taxPercentFederal.add(taxPercentState)); } // tax = amount * rate / divider BigDecimal taxAmount = taxableAmount.multiply(taxPercent); taxAmount = taxAmount.divide(taxDivider, 5, BigDecimal.ROUND_HALF_UP); // tax is always negative, since it reduces the total amount; while gross up is always the positive of tax if (!isGross) { taxAmount = taxAmount.negate(); } // populate necessary accounting line fields taxLine.setDocumentNumber(preq.getDocumentNumber()); taxLine.setSequenceNumber(preq.getNextSourceLineNumber()); taxLine.setChartOfAccountsCode(taxChart); taxLine.setAccountNumber(taxAccount); taxLine.setFinancialObjectCode(taxObjectCode); taxLine.setAmount(new KualiDecimal(taxAmount)); // add the accounting line to the item taxLine.setItemIdentifier(taxItem.getItemIdentifier()); taxLine.setPurapItem(taxItem); taxItem.getSourceAccountingLines().add(taxLine); return taxLine; }
From source file:com.selfsoft.business.service.impl.TbFixEntrustServiceImpl.java
public void printTbFixEntrustTemplate(OutputStream os, String tpl, Long tbFixEntrustId) { /*/* w ww . jav a 2 s .com*/ * Workbook wb = null; * * WritableWorkbook wwb = null; * * WritableSheet ws = null; * * try { * * wb = Workbook.getWorkbook(this.getClass().getResourceAsStream(tpl)); * * wwb = Workbook.createWorkbook(os, wb); * * ws = wwb.getSheet(0); * * WritableCellFormat wcf = new WritableCellFormat(); * * wcf.setVerticalAlignment(VerticalAlignment.CENTRE); * * wcf.setAlignment(Alignment.CENTRE); * * wcf.setWrap(true); * * TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); * * TbCustomer tbCustomer = * tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); * * TbCarInfo tbCarInfo = * tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); * * Label label = null; * * label = new Label(0, 10, tbFixEntrust.getEntrustCode(), wcf); * * ws.addCell(label); * * label = new Label(8, 10, tbCarInfo.getPurchaseDate()== null ? "" : * CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), * "yyyy-MM-dd"), wcf); * * ws.addCell(label); * * label = new Label(14, 10, tbFixEntrust.getTmUser().getUserRealName(), * wcf); * * ws.addCell(label); * * label = new Label(20, 10, tbCarInfo.getLicenseCode(), wcf); * * ws.addCell(label); * * label = new Label(27, 10, * tbCarInfo.getTmCarModelType().getModelName(), wcf); * * ws.addCell(label); * * label = new Label(32, 10, tbFixEntrust.getEnterStationKilo() == null * ? "" : tbFixEntrust.getEnterStationKilo().toString(), wcf); * * ws.addCell(label); * * label = new Label(41, 10, tbCarInfo.getColor() == null ? "" : * tbCarInfo.getColor().toString(), wcf); * * ws.addCell(label); * * label = new Label(45, 10, tbFixEntrust.getFixDate() == null ? "" : * CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), * "yyyy-MM-dd HH:mm:ss"), wcf); * * ws.addCell(label); * * label = new Label(0, 15, tbCustomer.getCustomerName() == null ? "" : * tbCustomer.getCustomerName(), wcf); * * ws.addCell(label); * * label = new Label(8, 15, tbCustomer.getTelephone() == null ? "" : * tbCustomer.getTelephone(), wcf); * * ws.addCell(label); * * label = new Label(14, 15, tbCustomer.getPhone() == null ? "" : * tbCustomer.getPhone(), wcf); * * ws.addCell(label); * * label = new Label(20, 15, tbCarInfo.getChassisCode() == null ? "" : * tbCarInfo.getChassisCode(), wcf); * * ws.addCell(label); * * label = new Label(32, 15, tbCarInfo.getEngineCode() == null ? "" : * tbCarInfo.getEngineCode(),wcf); * * ws.addCell(label); * * label = new Label(45, 15, tbFixEntrust.getEstimateDate() == null ? "" * : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), * "yyyy-MM-dd HH:mm:ss"),wcf); * * ws.addCell(label); * * label = new Label(8, 18, tbCustomer.getCustomerName() == null ? "" : * tbCustomer.getCustomerName(), wcf); * * ws.addCell(label); * * label = new Label(0, 22, tbCustomer.getAddress() == null ? "" : * tbCustomer.getAddress(), wcf); * * ws.addCell(label); * * label = new Label(8, 25, tbCustomer.getZipCode() == null ? "" : * tbCustomer.getZipCode(), wcf); * * ws.addCell(label); * * label = new Label(20, 20, (tbFixEntrust.getWrongDescribe() == * null?"":tbFixEntrust.getWrongDescribe()) +";" + * (tbFixEntrust.getBeforeFixState * ()==null?"":tbFixEntrust.getBeforeFixState()) + ";" + * (tbFixEntrust.getCheckResult * ()==null?"":tbFixEntrust.getCheckResult()) + ";" + * (tbFixEntrust.getRemark()==null?"":tbFixEntrust.getRemark()), wcf); * * ws.addCell(label); * * wwb.write(); * * } catch (BiffException e) { * * e.printStackTrace(); } catch (IOException e) { * * e.printStackTrace(); } catch (RowsExceededException e) { // TODO * Auto-generated catch block e.printStackTrace(); } catch * (WriteException e) { // TODO Auto-generated catch block * e.printStackTrace(); } finally { * * if (null != wb) { * * wb.close(); * * } * * if (null != wwb) { * * try { wwb.close(); } catch (WriteException e) { * * e.printStackTrace(); } catch (IOException e) { * * e.printStackTrace(); } } * * } */ try { TbFixEntrust tbFixEntrust = this.findById(tbFixEntrustId); TbCustomer tbCustomer = tbCustomerService.findById(tbFixEntrust.getTbCustomer().getId()); TbCarInfo tbCarInfo = tbCarInfoService.findById(tbFixEntrust.getTbCarInfo().getId()); List<TbFixEntrustContent> tbFixEntrustContentList = tbFixEntrustContentService .findTbFixEnTrustContentListByTbFixEntrustId(tbFixEntrustId); /* * List<TbMaintainPartContent> maintainList = * tbMaintainPartContentService * .getViewEntrustMaintianContent(tbFixEntrustId); * * * List<TmStockOutDetVo> solePartList = * tmStockOutService.getSellByEntrustCode * (tbFixEntrust.getEntrustCode()); */ /** * ?? */ List<TbMaintianVo> maintianvos = tbMaintainPartContentService .getTbMaintianDetailVosByEntrustId(tbFixEntrust.getId(), Constants.BALANCE_ALL); /** * ? */ List<TmStockOutDetVo> tmStockOutDetVos = tmStockOutService .getSellDetailByEntrustCode(tbFixEntrust.getEntrustCode(), Constants.BALANCE_ALL); /** * ?? */ List<TbMaintianVo> partAll = new ArrayList<TbMaintianVo>(); if (null != maintianvos && maintianvos.size() > 0) { for (TbMaintianVo tbMaintianVo : maintianvos) { partAll.add(tbMaintianVo); } } if (null != tmStockOutDetVos && tmStockOutDetVos.size() > 0) { for (TmStockOutDetVo tmStockOutDetVo : tmStockOutDetVos) { TbMaintianVo tbMaintianVo = new TbMaintianVo(); tbMaintianVo.setPartId(tmStockOutDetVo.getPartinfoId()); tbMaintianVo.setHouseName(tmStockOutDetVo.getHouseName()); tbMaintianVo.setPartCode(tmStockOutDetVo.getPartCode()); tbMaintianVo.setPartName(tmStockOutDetVo.getPartName()); tbMaintianVo.setUnitName(tmStockOutDetVo.getUnitName()); tbMaintianVo.setPrice(tmStockOutDetVo.getPrice()); tbMaintianVo.setPartQuantity(tmStockOutDetVo.getQuantity()); tbMaintianVo.setTotal(tmStockOutDetVo.getTotal()); tbMaintianVo.setIsFree(tmStockOutDetVo.getIsFree()); tbMaintianVo.setProjectType(tmStockOutDetVo.getProjectType()); tbMaintianVo.setZl(tmStockOutDetVo.getZl()); tbMaintianVo.setXmlx(tmStockOutDetVo.getXmlx()); partAll.add(tbMaintianVo); } } int fixSize = (tbFixEntrustContentList == null ? 0 : tbFixEntrustContentList.size()); int maintainSize = (maintianvos == null ? 0 : maintianvos.size()); int solePartSize = (tmStockOutDetVos == null ? 0 : tmStockOutDetVos.size()); int partAllSize = (partAll == null ? 0 : partAll.size()); HSSFWorkbook workbook = new HSSFWorkbook(this.getClass().getResourceAsStream(tpl)); HSSFSheet sheet = workbook.getSheetAt(0); sheet.setMargin(HSSFSheet.LeftMargin, (double) 0.5); sheet.setMargin(HSSFSheet.RightMargin, (double) 0.5); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontName(""); font.setFontHeightInPoints((short) 9); style.setFont(font); HSSFRow row = null; HSSFCell cell = null; ByteArrayOutputStream byteArrayOutImgLion = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutDBZF = new ByteArrayOutputStream(); BufferedImage bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/lion.png")); BufferedImage bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/dfbz.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 48, 0, (short) 53, 7); HSSFClientAnchor anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 8, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); row = sheet.getRow(10); cell = row.getCell(0); String entrustCode = tbFixEntrust.getEntrustCode(); String[] es = entrustCode.split("-"); String newCode = "RO" + es[0].substring(2, 6) + es[1]; // cell.setCellValue(tbFixEntrust.getEntrustCode()); cell.setCellValue(newCode); row = sheet.getRow(10); cell = row.getCell(8); cell.setCellValue(tbCarInfo.getPurchaseDate() == null ? "" : CommonMethod.parseDateToString(tbCarInfo.getPurchaseDate(), "yyyy-MM-dd")); row = sheet.getRow(10); cell = row.getCell(14); cell.setCellValue( tbFixEntrust.getTmUser().getUserRealName() == null ? tbFixEntrust.getTmUser().getUserName() : tbFixEntrust.getTmUser().getUserRealName()); row = sheet.getRow(10); cell = row.getCell(19); cell.setCellValue(tbCarInfo.getLicenseCode()); row = sheet.getRow(10); cell = row.getCell(27); cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getTmCarModelType().getModelName()); row = sheet.getRow(10); cell = row.getCell(32); cell.setCellValue( tbFixEntrust.getEnterStationKilo() == null ? "" : new BigDecimal(tbFixEntrust.getEnterStationKilo().toString()) .divide(new BigDecimal("1.00"), 0, BigDecimal.ROUND_HALF_UP).toString() + " Km"); row = sheet.getRow(10); cell = row.getCell(41); cell.setCellValue(tbCarInfo.getColor() == null ? "" : tbCarInfo.getColor().toString()); row = sheet.getRow(10); cell = row.getCell(45); cell.setCellValue(tbFixEntrust.getFixDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getFixDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(15); cell = row.getCell(0); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getContractPerson()); row = sheet.getRow(15); cell = row.getCell(8); cell.setCellValue(tbCustomer.getTelephone() == null ? "" : tbCustomer.getTelephone()); row = sheet.getRow(15); cell = row.getCell(14); cell.setCellValue(tbCustomer.getPhone() == null ? "" : tbCustomer.getPhone()); row = sheet.getRow(15); cell = row.getCell(20); cell.setCellValue(tbCarInfo.getChassisCode() == null ? "" : tbCarInfo.getChassisCode()); row = sheet.getRow(15); cell = row.getCell(32); // cell.setCellStyle(style); cell.setCellValue(tbCarInfo.getEngineCode() == null ? "" : tbCarInfo.getEngineCode()); row = sheet.getRow(15); cell = row.getCell(45); // cell.setCellStyle(style); cell.setCellValue(tbFixEntrust.getEstimateDate() == null ? "" : CommonMethod.parseDateToString(tbFixEntrust.getEstimateDate(), Constants.TIMEFORMATOFMINUTE)); row = sheet.getRow(18); cell = row.getCell(8); cell.setCellValue(tbCustomer.getCustomerName() == null ? "" : tbCustomer.getCustomerName()); row = sheet.getRow(20); cell = row.getCell(8); cell.setCellStyle(style); cell.setCellValue(tbCustomer.getAddress() == null ? "" : tbCustomer.getAddress()); row = sheet.getRow(25); cell = row.getCell(8); cell.setCellValue(tbCustomer.getZipCode() == null ? "" : tbCustomer.getZipCode()); row = sheet.getRow(20); cell = row.getCell(23); cell.setCellStyle(style); cell.setCellValue((tbFixEntrust.getWrongDescribe() == null || "".equals(tbFixEntrust.getWrongDescribe()) ? "" : tbFixEntrust.getWrongDescribe() + ";") + (tbFixEntrust.getBeforeFixState() == null || "".equals(tbFixEntrust.getBeforeFixState()) ? "" : tbFixEntrust.getBeforeFixState() + ";")); Double fixCount = tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(tbFixEntrustId); row = sheet.getRow(70); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(fixCount).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP) .toString()); row = sheet.getRow(70); cell = row.getCell(48); cell.setCellStyle(style); cell.setCellValue("0.00"); BigDecimal partPriceAll = new BigDecimal("0.00"); if (partAllSize > 0) { for (int i = 0; i < partAllSize; i++) { TbMaintianVo tbMaintianVo = partAll.get(i); BigDecimal total = new BigDecimal(tbMaintianVo.getPrice()) .multiply(new BigDecimal(tbMaintianVo.getPartQuantity())); partPriceAll = partPriceAll.add(total); } } row = sheet.getRow(73); cell = row.getCell(33); cell.setCellStyle(style); cell.setCellValue(partPriceAll.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); BigDecimal total = new BigDecimal(fixCount).add(partPriceAll).divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP); row = sheet.getRow(76); cell = row.getCell(34); cell.setCellStyle(style); cell.setCellValue(total.toString()); int page = 1; if (fixSize / 5 >= (maintainSize + solePartSize) / 13) { page = fixSize / 5; } else { page = (maintainSize + solePartSize) / 13; } for (int i = 0; i < page; i++) { int p = 0; int k = 0; HSSFSheet sheetClone = workbook.cloneSheet(0); byteArrayOutImgLion = new ByteArrayOutputStream(); byteArrayOutDBZF = new ByteArrayOutputStream(); bufferImgLion = ImageIO.read(this.getClass().getResourceAsStream("/lion.png")); bufferImgDFBZ = ImageIO.read(this.getClass().getResourceAsStream("/dfbz.png")); ImageIO.write(bufferImgLion, "png", byteArrayOutImgLion); ImageIO.write(bufferImgDFBZ, "png", byteArrayOutDBZF); patriarch = sheetClone.createDrawingPatriarch(); anchorLion = new HSSFClientAnchor(0, 0, 1023, 200, (short) 48, 0, (short) 53, 7); anchorDBZF = new HSSFClientAnchor(0, 0, 1023, 200, (short) 0, 0, (short) 8, 7); patriarch.createPicture(anchorLion, workbook.addPicture(byteArrayOutImgLion.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); patriarch.createPicture(anchorDBZF, workbook.addPicture(byteArrayOutDBZF.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); if (fixSize > 5) { int printFixSize = (fixSize > (i + 2) * 5 ? (i + 2) * 5 : fixSize); for (int j = 5 * (i + 1); j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheetClone.getRow(31 + p * 6); cell = row.getCell(0); cell.setCellStyle(style); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(content.getXmlx() == null ? "" : content.getXmlx()); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(fixPersons); p++; } } if (partAllSize > 13) { int prinPartSize = (partAllSize > (i + 2) * 13 ? (i + 2) * 13 : partAllSize); for (int j = 13 * (i + 1); j < prinPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheetClone.getRow(31 + k * 3); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(t.getPartQuantity()); cell = row.getCell(44); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); k++; } } } if (fixSize > 0) { int printFixSize = (fixSize > 5 ? 5 : fixSize); for (int j = 0; j < printFixSize; j++) { TbFixEntrustContent content = tbFixEntrustContentList.get(j); List<TbFixShare> tbFixShareList = tbFixShareService .findTbFixShareListByTbFixEntrustContentId(content.getId()); String fixPersons = ""; if (null != tbFixShareList && tbFixShareList.size() > 0) { for (TbFixShare tbFixShare : tbFixShareList) { if (null != tbFixShare.getTmUser()) { TmUser tmUser = tmUserService.findById(tbFixShare.getTmUser().getId()); fixPersons += (tmUser.getUserRealName() == null || "".equals(tmUser.getUserRealName()) ? tmUser.getUserName() : tmUser.getUserRealName()) + " "; } } } row = sheet.getRow(31 + j * 6); cell = row.getCell(0); cell.setCellStyle(style); cell.setCellValue(content.getStationCode() + " " + content.getStationName()); cell = row.getCell(20); cell.setCellStyle(style); cell.setCellValue(content.getXmlx() == null ? "" : content.getXmlx()); cell = row.getCell(26); cell.setCellStyle(style); cell.setCellValue(fixPersons); } } if (partAllSize > 0) { int printPartSize = (partAllSize > 13 ? 13 : partAllSize); for (int j = 0; j < printPartSize; j++) { TbMaintianVo t = partAll.get(j); row = sheet.getRow(31 + j * 3); cell = row.getCell(32); cell.setCellStyle(style); cell.setCellValue(t.getPartName()); cell = row.getCell(40); cell.setCellStyle(style); cell.setCellValue(t.getPartQuantity()); cell = row.getCell(44); cell.setCellStyle(style); cell.setCellValue(new BigDecimal(t.getPrice()) .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP).toString()); } } workbook.write(os); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fragment.web.AbstractProductsControllerTest.java
@Test public void testEditProductCharges() throws Exception { Product product = productsService.locateProductById("1"); String viewResult = productsController.viewProductPlannedCharges(product.getCode(), map); Assert.assertNotNull(viewResult);//from w ww.ja va2s . co m Assert.assertEquals("view.product.planned.charges", viewResult); List<ProductCharge> productChargesOriginal = (List<ProductCharge>) map.get("productChargesList"); List<ProductCharge> productChargesEdited = (List<ProductCharge>) map.get("productChargesList"); List<CurrencyValue> currenciesList = new ArrayList<CurrencyValue>(); for (ProductCharge pc : productChargesEdited) { // pc.setPrice(BigDecimal.valueOf(500.00)); pc.setPrice(BigDecimal.valueOf(500.00).setScale(4, BigDecimal.ROUND_HALF_UP)); currenciesList.add(pc.getCurrencyValue()); } ProductForm form = new ProductForm(product); Map<Product, List<ProductCharge>> currentProductChargesMap = new HashMap<Product, List<ProductCharge>>(); currentProductChargesMap.put(product, productChargesOriginal); form.setCurrentProductChargesMap(currentProductChargesMap); form.updateProductChargesFormList(product, productChargesEdited, currenciesList, channelService.getFutureRevision(null), false); BindingResult result = validate(form); String editResult = productsController.editPlannedCharges(form, result, map); Assert.assertNotNull(editResult); Assert.assertEquals("success", editResult); String viewResult1 = productsController.viewProductPlannedCharges(product.getCode(), map); Assert.assertNotNull(viewResult1); Assert.assertEquals("view.product.planned.charges", viewResult1); List<ProductCharge> productChargesafter = (List<ProductCharge>) map.get("productChargesList"); for (ProductCharge pc : productChargesafter) { Assert.assertEquals(BigDecimal.valueOf(500.00).setScale(4, BigDecimal.ROUND_HALF_UP), pc.getPrice()); } }
From source file:org.egov.ptis.service.es.CollectionIndexElasticSearchService.java
/** * Prepares the map for individual demands * @param individualDmdDetails/* ww w .j a v a 2 s.com*/ * @param demandDivisionMap */ public void prepareIndividualDemandsMap(StringTerms individualDmdDetails, Map<String, Map<String, BigDecimal>> demandDivisionMap) { Map<String, BigDecimal> individualDmdMap; Sum arrearDmd; Sum currentDmd; Sum arrearInterestDmd; Sum currentInterestDmd; if (individualDmdDetails != null) { for (Terms.Bucket entry : individualDmdDetails.getBuckets()) { individualDmdMap = new HashMap<>(); arrearDmd = entry.getAggregations().get(ARREARDMD); currentDmd = entry.getAggregations().get(CURR_DMD); arrearInterestDmd = entry.getAggregations().get(ARREAR_INTEREST_DMD); currentInterestDmd = entry.getAggregations().get(CURR_INTEREST_DMD); individualDmdMap.put(ARREAR_DMD, BigDecimal.valueOf(arrearDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(CURRENT_DMD, BigDecimal.valueOf(currentDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(ARREAR_INT_DMD, BigDecimal.valueOf(arrearInterestDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); individualDmdMap.put(CURRENT_INT_DMD, BigDecimal.valueOf(currentInterestDmd.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP)); demandDivisionMap.put(String.valueOf(entry.getKey()), individualDmdMap); } } }
From source file:act.reports.dao.AllInvoicesDAO.java
public String roundUp(float d, int decimalPlace) { BigDecimal bd = new BigDecimal(Float.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.toString(); }