List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:com.lp.server.lieferschein.ejbfac.LieferscheinFacBean.java
private BigDecimal berechneWertMitZuUndAbschlaegenAusKonditionen(BigDecimal bdWertI, Integer iIdLieferscheinI, TheClientDto theClientDto) throws EJBExceptionLP { LieferscheinDto oDto = lieferscheinFindByPrimaryKey(iIdLieferscheinI, theClientDto); // zuerst den versteckten Aufschlag aufschlagen ... if (oDto.getFVersteckterAufschlag().doubleValue() != (double) 0) { BigDecimal versteckterAufschlag = bdWertI .multiply(new BigDecimal(oDto.getFVersteckterAufschlag().doubleValue()).movePointLeft(2)); versteckterAufschlag = Helper.rundeKaufmaennisch(versteckterAufschlag, 4); bdWertI = bdWertI.add(versteckterAufschlag); }/*from w ww.ja va 2 s .c o m*/ // dann den rabatt beruecksichtigen ... if (oDto.getFAllgemeinerRabattsatz().doubleValue() != (double) 0) { BigDecimal allgRabatt = bdWertI .multiply(new BigDecimal(oDto.getFAllgemeinerRabattsatz().doubleValue()).movePointLeft(2)); allgRabatt = Helper.rundeKaufmaennisch(allgRabatt, 4); bdWertI = bdWertI.subtract(allgRabatt); } return bdWertI; }
From source file:model.experiments.stickyprices.StickyPricesCSVPrinter.java
private static void woodMonopolistSweep(final BigDecimal minimumP, final BigDecimal maximumP, final BigDecimal minimumI, final BigDecimal maximumI, final BigDecimal increment, final int runsPerParameterCombination) throws IOException { CSVWriter writer = new CSVWriter(new FileWriter(Paths.get("runs", "rawdata", "monoSweep.csv").toFile())); writer.writeNext(new String[] { "P", "I", "distance", "variance", "success" }); BigDecimal currentP = minimumP; while (currentP.compareTo(maximumP) <= 0) { BigDecimal currentI = minimumI; while (currentI.compareTo(maximumI) <= 0) { SummaryStatistics averageSquaredDistance = new SummaryStatistics(); SummaryStatistics averageVariance = new SummaryStatistics(); int successes = 0; for (int run = 0; run < runsPerParameterCombination; run++) { //create the run MacroII macroII = new MacroII(run); MonopolistScenario scenario = new MonopolistScenario(macroII); macroII.setScenario(scenario); //set the demand scenario.setDemandIntercept(102); scenario.setDemandSlope(2); scenario.setDailyWageSlope(1); scenario.setDailyWageIntercept(0); scenario.setAskPricingStrategy(SimpleFlowSellerPID.class); scenario.setWorkersToBeRehiredEveryDay(true); scenario.setControlType( MonopolistScenario.MonopolistScenarioIntegratedControlEnum.MARGINAL_PLANT_CONTROL); scenario.setBuyerDelay(0); //start it and have one step macroII.start();//from www. j a va 2 s.c o m macroII.schedule.step(macroII); //now set the right parameters final SalesDepartment salesDepartment = scenario.getMonopolist() .getSalesDepartment(UndifferentiatedGoodType.GENERIC); final SimpleFlowSellerPID strategy = new SimpleFlowSellerPID(salesDepartment, currentP.floatValue(), currentI.floatValue(), 0f, 0, salesDepartment.getMarket(), salesDepartment.getRandom().nextInt(100), salesDepartment.getFirm().getModel()); // strategy.setInitialPrice(102); //start them all at the same price, otherwise you advantage the slow by being so slow initially that they end up being right later salesDepartment.setAskPricingStrategy(strategy); //and make it learned! salesDepartment.setPredictorStrategy(new FixedDecreaseSalesPredictor(2)); final HumanResources hr = scenario.getMonopolist().getHRs().iterator().next(); hr.setPredictor(new FixedIncreasePurchasesPredictor(1)); float totalDistance = 0; SummaryStatistics prices = new SummaryStatistics(); //run the model double price = 0; double quantity = 0; for (int i = 0; i < 1000; i++) { macroII.schedule.step(macroII); price = strategy.getTargetPrice(); quantity = salesDepartment.getTodayInflow(); totalDistance += Math .pow(Math.min(price - (102 - 2 * quantity), price - (102 - 2 * quantity - 1)), 2); prices.addValue(price); } //Model over, now compute statistics averageSquaredDistance.addValue(Math.sqrt(totalDistance)); averageVariance.addValue(prices.getVariance()); if (price <= 68 && price >= 67) successes++; // System.out.println(salesDepartment.getLatestObservation(SalesDataType.LAST_ASKED_PRICE)); macroII.finish(); } String[] csvLine = new String[5]; csvLine[0] = currentP.toString(); csvLine[1] = currentI.toString(); csvLine[2] = String.valueOf(averageSquaredDistance.getMean()); csvLine[3] = String.valueOf(averageVariance.getMean()); csvLine[4] = String.valueOf(successes); writer.writeNext(csvLine); writer.flush(); System.out.println(Arrays.toString(csvLine)); currentI = currentI.add(increment).setScale(2); System.out.println(); } currentP = currentP.add(increment).setScale(2); } }
From source file:com.centeractive.ws.builder.soap.SampleXmlUtil.java
private String formatDecimal(String start, SchemaType sType) { BigDecimal result = new BigDecimal(start); XmlDecimal xmlD;/*w ww . j ava 2 s . co 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(); 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:com.lp.server.auftrag.ejbfac.AuftragFacBean.java
@Override public BigDecimal berechneBestellwertAuftrag(Integer iIdAuftrag) throws EJBExceptionLP, RemoteException { BigDecimal bestellwert = new BigDecimal(0); BestellungDto[] besDtos = getBestellungFac().bestellungFindByAuftragIId(iIdAuftrag); if (besDtos == null) return bestellwert; for (BestellungDto bestellungDto : besDtos) { if (bestellungDto.getNBestellwert() != null) bestellwert = bestellwert.add(bestellungDto.getNBestellwert()); }//from ww w. ja v a2 s . com return bestellwert; }
From source file:com.lp.server.lieferschein.ejbfac.LieferscheinFacBean.java
/** * Einen bestehenden Lieferschein aktualisieren. <br> * Ein Lieferschein kann zu mehreren Auftraegen liefern. <br> * Der Bezug zu einem Auftrag wird in einer Kreuztabelle eingetragen. * //from w ww.j a v a 2s.c o m * @param lieferscheinDtoI * die Daten des Lieferscheins * @param aAuftragIIdI * der Bezug zu 0..n Auftraegen * @param waehrungOriCNrI * die urspruengliche Belegwaehrung * @param theClientDto * der aktuelle Benutzer * @throws EJBExceptionLP * Ausnahme */ public boolean updateLieferschein(LieferscheinDto lieferscheinDtoI, Integer[] aAuftragIIdI, String waehrungOriCNrI, TheClientDto theClientDto) throws EJBExceptionLP { checkLieferscheinDto(lieferscheinDtoI); boolean bMwstSatzWurdeVonNullGeaendertUndEsGibtHandeingaben = false; try { // wenn die Waehrung geaendert wurde, muessen die Belegwerte neu // berechnet werden if (waehrungOriCNrI != null && !waehrungOriCNrI.equals(lieferscheinDtoI.getWaehrungCNr())) { LieferscheinpositionDto[] aLieferscheinpositionDto = getLieferscheinpositionFac() .lieferscheinpositionFindByLieferscheinIId(lieferscheinDtoI.getIId()); // die Positionswerte neu berechnen und abspeichern BigDecimal ffWechselkurs = getLocaleFac().getWechselkurs2(waehrungOriCNrI, lieferscheinDtoI.getWaehrungCNr(), theClientDto); for (int i = 0; i < aLieferscheinpositionDto.length; i++) { if (aLieferscheinpositionDto[i].getNMenge() != null && aLieferscheinpositionDto[i].getNEinzelpreis() != null) { BigDecimal nNettoeinzelpreisInNeuerWaehrung = aLieferscheinpositionDto[i].getNEinzelpreis() .multiply(ffWechselkurs); VerkaufspreisDto verkaufspreisDto = getVkPreisfindungFac().berechnePreisfelder( nNettoeinzelpreisInNeuerWaehrung, aLieferscheinpositionDto[i].getFRabattsatz(), aLieferscheinpositionDto[i].getFZusatzrabattsatz(), aLieferscheinpositionDto[i].getMwstsatzIId(), 4, // @todo // Konstante // PJ // 4390 theClientDto); aLieferscheinpositionDto[i].setNEinzelpreis(verkaufspreisDto.einzelpreis); aLieferscheinpositionDto[i].setNRabattbetrag(verkaufspreisDto.rabattsumme); aLieferscheinpositionDto[i].setNNettoeinzelpreis(verkaufspreisDto.nettopreis); aLieferscheinpositionDto[i].setNMwstbetrag(verkaufspreisDto.mwstsumme); aLieferscheinpositionDto[i].setNBruttoeinzelpreis(verkaufspreisDto.bruttopreis); // alle Preisfelder incl. der zusaetzlichen Preisfelder // befuellen getLieferscheinpositionFac().updateLieferscheinpositionOhneWeitereAktion( aLieferscheinpositionDto[i], theClientDto); } } } lieferscheinDtoI.setPersonalIIdAendern(theClientDto.getIDPersonal()); lieferscheinDtoI.setTAendern(getTimestamp()); Lieferschein lieferschein = em.find(Lieferschein.class, lieferscheinDtoI.getIId()); if (lieferschein == null) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_BEI_FINDBYPRIMARYKEY, ""); } LieferscheinDto lsDto_vorher = lieferscheinFindByPrimaryKey(lieferscheinDtoI.getIId()); HvDtoLogger<LieferscheinDto> erLogger = new HvDtoLogger<LieferscheinDto>(em, lieferscheinDtoI.getIId(), theClientDto); erLogger.log(lsDto_vorher, lieferscheinDtoI); // Wird der kunde geaendert muss man die Konditionen neu holen // CK: 2013-06-04 Gilt nicht mehr, da die Konditionen nun // vorher am Client bestaetigt werden muessen /* * if (!lieferscheinDtoI.getKundeIIdLieferadresse().equals( * lieferschein.getKundeIIdLieferadresse())) { KundeDto kundeDto = * getKundeFac().kundeFindByPrimaryKey( * lieferscheinDtoI.getKundeIIdLieferadresse(), theClientDto); * Double dAllgemeinerrabattsatz = new Double(0); if * (kundeDto.getFRabattsatz() != null) { dAllgemeinerrabattsatz = * kundeDto.getFRabattsatz(); } lieferscheinDtoI * .setFAllgemeinerRabattsatz(dAllgemeinerrabattsatz); if * (kundeDto.getLieferartIId() != null) { lieferscheinDtoI * .setLieferartIId(kundeDto.getLieferartIId()); } if * (kundeDto.getZahlungszielIId() != null) { * lieferscheinDtoI.setZahlungszielIId(kundeDto * .getZahlungszielIId()); } if (kundeDto.getSpediteurIId() != null) * { lieferscheinDtoI .setSpediteurIId(kundeDto.getSpediteurIId()); * } } */ if (!lieferscheinDtoI.getKundeIIdRechnungsadresse() .equals(lieferschein.getKundeIIdRechnungsadresse())) { KundeDto kundeDto = getKundeFac() .kundeFindByPrimaryKey(lieferscheinDtoI.getKundeIIdRechnungsadresse(), theClientDto); KundeDto kundeDtoVorher = getKundeFac() .kundeFindByPrimaryKey(lieferschein.getKundeIIdRechnungsadresse(), theClientDto); ParametermandantDto parameterPositionskontierung = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_KUNDEN, ParameterFac.PARAMETER_KUNDEN_POSITIONSKONTIERUNG); boolean bDefaultMwstsatzAusArtikel = (Boolean) parameterPositionskontierung.getCWertAsObject(); LieferscheinpositionDto[] aLieferscheinpositionDto = getLieferscheinpositionFac() .lieferscheinpositionFindByLieferscheinIId(lieferscheinDtoI.getIId()); for (int i = 0; i < aLieferscheinpositionDto.length; i++) { if (aLieferscheinpositionDto[i].getPositionsartCNr() .equals(LieferscheinpositionFac.LIEFERSCHEINPOSITIONSART_IDENT) || aLieferscheinpositionDto[i].getPositionsartCNr() .equals(LieferscheinpositionFac.LIEFERSCHEINPOSITIONSART_HANDEINGABE)) { MwstsatzDto mwstsatzDto = getMandantFac().mwstsatzFindByMwstsatzbezIIdAktuellster( kundeDto.getMwstsatzbezIId(), theClientDto); if (bDefaultMwstsatzAusArtikel && aLieferscheinpositionDto[i].getPositionsartCNr() .equals(LieferscheinpositionFac.LIEFERSCHEINPOSITIONSART_IDENT)) { ArtikelDto artikelDto = getArtikelFac().artikelFindByPrimaryKeySmall( aLieferscheinpositionDto[i].getArtikelIId(), theClientDto); if (artikelDto.getMwstsatzbezIId() != null) { mwstsatzDto = getMandantFac().mwstsatzFindByMwstsatzbezIIdAktuellster( artikelDto.getMwstsatzbezIId(), theClientDto); } } // SP503 if (bDefaultMwstsatzAusArtikel && aLieferscheinpositionDto[i].getPositionsartCNr() .equals(LieferscheinpositionFac.LIEFERSCHEINPOSITIONSART_HANDEINGABE)) { // Wenn alter und neuer Kunde den gleichen MWST-Satz // haben, dann nichts tun MwstsatzDto mwstsatzDtoKundeNeu = getMandantFac() .mwstsatzFindByMwstsatzbezIIdAktuellster(kundeDto.getMwstsatzbezIId(), theClientDto); MwstsatzDto mwstsatzDtoKundeVorher = getMandantFac() .mwstsatzFindByMwstsatzbezIIdAktuellster(kundeDtoVorher.getMwstsatzbezIId(), theClientDto); if (mwstsatzDtoKundeVorher.getFMwstsatz() == 0 && mwstsatzDtoKundeNeu.getFMwstsatz() > 0) { bMwstSatzWurdeVonNullGeaendertUndEsGibtHandeingaben = true; } if (mwstsatzDtoKundeNeu.getIId().equals(mwstsatzDtoKundeVorher.getIId())) { continue; } } if (!aLieferscheinpositionDto[i].getMwstsatzIId().equals(mwstsatzDto.getIId())) { aLieferscheinpositionDto[i].setMwstsatzIId(mwstsatzDto.getIId()); BigDecimal mwstBetrag = aLieferscheinpositionDto[i] .getNNettoeinzelpreisplusversteckteraufschlagminusrabatte() .multiply(new BigDecimal(mwstsatzDto.getFMwstsatz().doubleValue()) .movePointLeft(2)); aLieferscheinpositionDto[i].setNMwstbetrag(mwstBetrag); aLieferscheinpositionDto[i] .setNBruttoeinzelpreis(mwstBetrag.add(aLieferscheinpositionDto[i] .getNNettoeinzelpreisplusversteckteraufschlagminusrabatte())); getLieferscheinpositionFac().updateLieferscheinpositionOhneWeitereAktion( aLieferscheinpositionDto[i], theClientDto); } } } Double dAllgemeinerrabattsatz = new Double(0); if (kundeDto.getFRabattsatz() != null) { dAllgemeinerrabattsatz = kundeDto.getFRabattsatz(); } lieferscheinDtoI.setFAllgemeinerRabattsatz(dAllgemeinerrabattsatz); if (kundeDto.getLieferartIId() != null) { lieferscheinDtoI.setLieferartIId(kundeDto.getLieferartIId()); } if (kundeDto.getZahlungszielIId() != null) { lieferscheinDtoI.setZahlungszielIId(kundeDto.getZahlungszielIId()); } if (kundeDto.getSpediteurIId() != null) { lieferscheinDtoI.setSpediteurIId(kundeDto.getSpediteurIId()); } } if (!lieferschein.getTBelegdatum().equals(lieferscheinDtoI.getTBelegdatum())) { try { getLagerFac().updateTBelegdatumEinesBelegesImLager(LocaleFac.BELEGART_LIEFERSCHEIN, lieferscheinDtoI.getIId(), lieferscheinDtoI.getTBelegdatum(), theClientDto); } catch (RemoteException ex1) { throwEJBExceptionLPRespectOld(ex1); } } setLieferscheinFromLieferscheinDto(lieferschein, lieferscheinDtoI); // die Zuordnung zu den Auftraegen kann geaendert werden, solange es // keine // mengenbehafteten Positionen gibt if (lieferscheinDtoI.getLieferscheinartCNr().equals(LieferscheinFac.LSART_AUFTRAG)) { if (aAuftragIIdI == null || aAuftragIIdI.length == 0) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_PARAMETER_IS_NULL, new Exception("Lieferscheinart ist Auftrag, aber aAuftragIIdI ist leer.")); } } pruefeUndSetzeLieferscheinstatusBeiAenderung(lieferscheinDtoI.getIId()); } catch (RemoteException ex) { throwEJBExceptionLPRespectOld(ex); } return bMwstSatzWurdeVonNullGeaendertUndEsGibtHandeingaben; }
From source file:com.gst.portfolio.loanproduct.serialization.LoanProductDataValidator.java
private void validateGuaranteeParams(final JsonElement element, final DataValidatorBuilder baseDataValidator, final LoanProduct loanProduct) { BigDecimal mandatoryGuarantee = BigDecimal.ZERO; BigDecimal minimumGuaranteeFromOwnFunds = BigDecimal.ZERO; BigDecimal minimumGuaranteeFromGuarantor = BigDecimal.ZERO; if (loanProduct != null) { mandatoryGuarantee = loanProduct.getLoanProductGuaranteeDetails().getMandatoryGuarantee(); minimumGuaranteeFromOwnFunds = loanProduct.getLoanProductGuaranteeDetails() .getMinimumGuaranteeFromOwnFunds(); minimumGuaranteeFromGuarantor = loanProduct.getLoanProductGuaranteeDetails() .getMinimumGuaranteeFromGuarantor(); }/*from w ww. j av a 2s . c o m*/ if (loanProduct == null || this.fromApiJsonHelper .parameterExists(LoanProductConstants.mandatoryGuaranteeParamName, element)) { mandatoryGuarantee = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed(LoanProductConstants.mandatoryGuaranteeParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.mandatoryGuaranteeParamName) .value(mandatoryGuarantee).notNull(); if (mandatoryGuarantee == null) { mandatoryGuarantee = BigDecimal.ZERO; } } if (loanProduct == null || this.fromApiJsonHelper .parameterExists(LoanProductConstants.minimumGuaranteeFromGuarantorParamName, element)) { minimumGuaranteeFromGuarantor = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed( LoanProductConstants.minimumGuaranteeFromGuarantorParamName, element); if (minimumGuaranteeFromGuarantor == null) { minimumGuaranteeFromGuarantor = BigDecimal.ZERO; } } if (loanProduct == null || this.fromApiJsonHelper .parameterExists(LoanProductConstants.minimumGuaranteeFromOwnFundsParamName, element)) { minimumGuaranteeFromOwnFunds = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed( LoanProductConstants.minimumGuaranteeFromOwnFundsParamName, element); if (minimumGuaranteeFromOwnFunds == null) { minimumGuaranteeFromOwnFunds = BigDecimal.ZERO; } } if (mandatoryGuarantee.compareTo(minimumGuaranteeFromOwnFunds.add(minimumGuaranteeFromGuarantor)) == -1) { baseDataValidator.parameter(LoanProductConstants.mandatoryGuaranteeParamName) .failWithCode("must.be.greter.than.sum.of.min.funds"); } }
From source file:com.roncoo.pay.app.reconciliation.biz.ReconciliationCheckBiz.java
/** * ?/*w w w . ja v a2 s.co m*/ * * @param bankList * ?? * * @param misTakeList * list * * @param platScreatchRecordList * ?? * * @param batch * */ private void baseOnBank(List<RpTradePaymentRecord> platAllDateList, List<ReconciliationEntityVo> bankList, List<RpAccountCheckMistakeScratchPool> platScreatchRecordList, List<RpAccountCheckMistake> misTakeList, RpAccountCheckBatch batch, List<RpAccountCheckMistakeScratchPool> removeScreatchRecordList) { BigDecimal platTradeAmount = BigDecimal.ZERO;// ?? BigDecimal platFee = BigDecimal.ZERO;// ? Integer tradeCount = 0;// ?? Integer mistakeCount = 0; // ? for (ReconciliationEntityVo bankRecord : bankList) { boolean flag = false;// ?? for (RpTradePaymentRecord record : platAllDateList) { /** step1 ?? **/ if (bankRecord.getBankOrderNo().equals(record.getBankOrderNo())) { flag = true; /** step2 ???? **/ /** ????????????? **/ // ?? if (!TradeStatusEnum.SUCCESS.name().equals(record.getStatus())) { RpAccountCheckMistake misktake1 = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_STATUS_MISMATCH, batch); misTakeList.add(misktake1); mistakeCount++; // break; /** ???????????? **/ // ?? /** step1:??? **/ // ?? if (record.getOrderAmount().compareTo(bankRecord.getBankAmount()) == 1) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_OVER_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } // ?? else if (record.getOrderAmount().compareTo(bankRecord.getBankAmount()) == -1) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step2:?? **/ if (record.getPlatCost().compareTo(bankRecord.getBankFee()) != 0) { // ??? RpAccountCheckMistake misktake = createMisktake(null, record, bankRecord, ReconciliationMistakeTypeEnum.FEE_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } } } } /** step3 ?? **/ if (!flag) { // (?????) if (platScreatchRecordList != null) for (RpAccountCheckMistakeScratchPool scratchRecord : platScreatchRecordList) { // ? if (scratchRecord.getBankOrderNo().equals(bankRecord.getBankOrderNo())) { // ?? platTradeAmount = platTradeAmount.add(scratchRecord.getOrderAmount()); platFee = platFee.add(scratchRecord.getPlatCost() == null ? BigDecimal.ZERO : scratchRecord.getPlatCost()); tradeCount++; flag = true; // ?? /** step1:??? **/ // ?? if (scratchRecord.getOrderAmount().compareTo(bankRecord.getBankAmount()) == 1) { // ??? RpAccountCheckMistake misktake = createMisktake(scratchRecord, null, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_OVER_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } // ?? else if (scratchRecord.getOrderAmount().compareTo(bankRecord.getBankAmount()) == -1) { // ??? RpAccountCheckMistake misktake = createMisktake(scratchRecord, null, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_SHORT_CASH_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step2:?? **/ if (scratchRecord.getPlatCost().compareTo(bankRecord.getBankFee()) != 0) { // ??? RpAccountCheckMistake misktake = createMisktake(scratchRecord, null, bankRecord, ReconciliationMistakeTypeEnum.FEE_MISMATCH, batch); misTakeList.add(misktake); mistakeCount++; break; } /** step3:? **/ removeScreatchRecordList.add(scratchRecord); } } } // ?, PLATFORM_MISS("???") if (!flag) { RpAccountCheckMistake misktake = createMisktake(null, null, bankRecord, ReconciliationMistakeTypeEnum.PLATFORM_MISS, batch); misTakeList.add(misktake); mistakeCount++; } } // ?? batch.setTradeAmount(batch.getTradeAmount().add(platTradeAmount)); batch.setTradeCount(batch.getTradeCount() + tradeCount); batch.setFee(batch.getFee().add(platFee)); batch.setMistakeCount(batch.getMistakeCount() + mistakeCount); }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
@Override public Motransaction getResultingBalance(Integer theMoAccountID) throws BankingException { Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); String date = ft.format(dNow); //System.out.println(ft.format(dNow)); String resultingbalSelectQry = null; String aJobCountStr = null;/*w w w .java 2 s. com*/ String currentbalSelectQry = "select distinct (select SUM(Amount) from moTransaction where moTransactionTypeID=0 and moAccountID=" + theMoAccountID + " AND Void=0 AND status=0) 'depositamount',(select SUM(Amount) from moTransaction where moTransactionTypeID>0 and moAccountID=" + theMoAccountID + " AND Void=0 AND STATUS=0) 'withdrawel amount' from moTransaction"; itsLogger.info("Currentbalanceqry=" + currentbalSelectQry); Session aSession = itsSessionFactory.openSession(); BigDecimal currentbalance = new BigDecimal(0.00); Motransaction moacc = new Motransaction(); try { Query aQuery1 = aSession.createSQLQuery(currentbalSelectQry.toString()); Iterator<?> aIterator1 = aQuery1.list().iterator(); if (aIterator1.hasNext()) { Object[] aObj1 = (Object[]) aIterator1.next(); BigDecimal currentdepositAmount = new BigDecimal(0.00); BigDecimal currentwithdrawelAmount = new BigDecimal(0.00); if (aObj1[0] != null) { currentdepositAmount = (BigDecimal) aObj1[0]; } if (aObj1[1] != null) { currentwithdrawelAmount = (BigDecimal) aObj1[1]; } currentbalance = currentdepositAmount.add(currentwithdrawelAmount); } moacc.setCurrentbalance(currentbalance); resultingbalSelectQry = "select distinct (select SUM(Amount) from moTransaction where moTransactionTypeID=0 and moAccountID=" + theMoAccountID + " AND Void=0 AND STATUS=0) 'depositamount',(select SUM(Amount) from moTransaction where moTransactionTypeID>0 and moAccountID=" + theMoAccountID + " AND Void=0 AND STATUS=0) 'withdrawel amount' from moTransaction"; itsLogger.info("resultingbalQry=" + resultingbalSelectQry); BigDecimal resultingbalance = new BigDecimal(0.00); Query aQuery = aSession.createSQLQuery(resultingbalSelectQry.toString()); Iterator<?> aIterator = aQuery.list().iterator(); if (aIterator.hasNext()) { Object[] aObj = (Object[]) aIterator.next(); BigDecimal depositAmount = new BigDecimal(0.00); BigDecimal withdrawelAmount = new BigDecimal(0.00); if (aObj[0] != null) { depositAmount = (BigDecimal) aObj[0]; } if (aObj[1] != null) { withdrawelAmount = (BigDecimal) aObj[1]; } resultingbalance = depositAmount.add(withdrawelAmount); } // aSession.close(); aJobCountStr = "SELECT SUM(ApplyingAmount) FROM veBillPay WHERE moAccountId=" + theMoAccountID; BigDecimal approveVal = new BigDecimal(0.00); // aSession = itsSessionFactory.openSession(); Query appQuery = aSession.createSQLQuery(aJobCountStr); List<?> aList = appQuery.list(); approveVal = (BigDecimal) aList.get(0); moacc.setWithDrawel(approveVal); moacc.setResultingbalance(resultingbalance); } catch (Exception e) { itsLogger.error(e.getMessage(), e); throw new BankingException(e.getMessage(), e); } finally { aSession.flush(); aSession.close(); resultingbalSelectQry = null; aJobCountStr = null; currentbalSelectQry = null; } return moacc; }
From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java
private void insertFees(final LockHandler lockHandler, final Transfer transfer, final boolean forced, final BigDecimal originalAmount, final boolean simulation, final Set<ChargedFee> chargedFees) { final TransferType transferType = transfer.getType(); final Account from = transfer.getFrom(); final Account to = transfer.getTo(); final TransactionFeeQuery query = new TransactionFeeQuery(); query.setTransferType(transferType); final List<? extends TransactionFee> fees = transactionFeeService.search(query); BigDecimal totalPercentage = BigDecimal.ZERO; BigDecimal feeTotalAmount = BigDecimal.ZERO; Transfer topMost = getTopMost(transfer); final Calendar date = topMost.getDate(); transfer.setChildren(new ArrayList<Transfer>()); for (final TransactionFee fee : fees) { final Account fromAccount = fetchService.fetch(from, Account.Relationships.TYPE, MemberAccount.Relationships.MEMBER); final Account toAccount = fetchService.fetch(to, Account.Relationships.TYPE, MemberAccount.Relationships.MEMBER); final ChargedFee key = new ChargedFee(fee, fromAccount, toAccount); if (chargedFees.contains(key)) { throw new ValidationException("payment.error.circularFees"); }//from w w w . j a v a2 s . c o m chargedFees.add(key); // Build the fee transfer final BuildTransferWithFeesDTO params = new BuildTransferWithFeesDTO(date, fromAccount, toAccount, originalAmount, fee, false); // rate stuff; buildTransfer MUST have these set. params.setEmissionDate(transfer.getEmissionDate()); params.setExpirationDate(transfer.getExpirationDate()); final Transfer feeTransfer = transactionFeeService.buildTransfer(params); // If the fee transfer is null, the fee should not be applied if (feeTransfer == null) { continue; } // Ensure the last fee when 100% will be the exact amount left if (fee instanceof SimpleTransactionFee && fee.getAmount().isPercentage()) { final BigDecimal feeValue = fee.getAmount().getValue(); // Only when it's not a single fee if (!(totalPercentage.equals(BigDecimal.ZERO) && feeValue.doubleValue() == 100.0)) { totalPercentage = totalPercentage.add(feeValue); // TODO: shouldn't this be >= 0 in stead of == 0 (Rinke) ? if (totalPercentage.compareTo(new BigDecimal(100)) == 0 && feeTransfer != null) { feeTransfer.setAmount(originalAmount.subtract(feeTotalAmount)); } } } // Insert the fee transfer if (feeTransfer != null && feeTransfer.getAmount().floatValue() > PRECISION_DELTA) { feeTotalAmount = feeTotalAmount.add(feeTransfer.getAmount()); feeTransfer.setParent(transfer); feeTransfer.setDate(transfer.getDate()); feeTransfer.setStatus(transfer.getStatus()); feeTransfer.setNextAuthorizationLevel(transfer.getNextAuthorizationLevel()); feeTransfer.setProcessDate(transfer.getProcessDate()); feeTransfer.setExternalTransfer(transfer.getExternalTransfer()); feeTransfer.setBy(transfer.getBy()); // Copy custom values of common custom fields from the parent to the fee transfer final List<PaymentCustomField> customFields = paymentCustomFieldService.list(feeTransfer.getType(), false); if (!CollectionUtils.isEmpty(transfer.getCustomValues())) { final Collection<PaymentCustomFieldValue> feeTransferCustomValues = new ArrayList<PaymentCustomFieldValue>(); for (final PaymentCustomFieldValue fieldValue : transfer.getCustomValues()) { final CustomField field = fieldValue.getField(); if (customFields.contains(field)) { final PaymentCustomFieldValue newFieldValue = new PaymentCustomFieldValue(); newFieldValue.setField(field); newFieldValue.setValue(fieldValue.getValue()); feeTransferCustomValues.add(newFieldValue); } } feeTransfer.setCustomValues(feeTransferCustomValues); } insertTransferAndPayFees(lockHandler, feeTransfer, forced, simulation, chargedFees); transfer.getChildren().add(feeTransfer); } } }