@Override
  public final void reverseEntries(final Map<String, Object> pAddParam,
    final IDoc pReversing,
      final IDoc pReversed) throws Exception {
    List<AccountingEntry> sources = getSrvOrm().retrieveListWithConditions(
      pAddParam, AccountingEntry.class, " where SOURCETYPE="
        + pReversing.constTypeCode() + " and SOURCEID="
          + pReversing.getReversedId() + " and SOURCEDATABASEBIRTH="
            + pReversing.getReversedIdDatabaseBirth());
    Long itsDateLong = null;
    String langDef = (String) pAddParam.get("langDef");
    DateFormat dateFormat = DateFormat.getDateTimeInstance(
      DateFormat.MEDIUM, DateFormat.SHORT, new Locale(langDef));
    for (AccountingEntry source : sources) {
      if (!source.getIdDatabaseBirth()
        .equals(getSrvDatabase().getIdDatabase())) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "can_not_reverse_foreign_acconting_entries");
      }
      if (itsDateLong == null) {
        itsDateLong = pReversing.getItsDate().getTime();
        getSrvBalance().handleNewAccountEntry(pAddParam, null, null,
          new Date(itsDateLong)); //This is for SrvBalanceStd only!!!
      }
      AccountingEntry accEntry = new AccountingEntry();
      accEntry.setItsDate(new Date(itsDateLong++));
      accEntry.setIdDatabaseBirth(getSrvDatabase().getIdDatabase());
      accEntry.setSourceType(pReversing.constTypeCode());
      Long reversingDocId = pReversing.getItsId();
      if (pReversing.getIdBirth() != null) {
        reversingDocId = pReversing.getIdBirth();
      }
      accEntry.setSourceId(reversingDocId);
      accEntry.setSourceDatabaseBirth(pReversing.getIdDatabaseBirth());
      accEntry.setAccDebit(source.getAccDebit());
      accEntry.setSubaccDebitType(source.getSubaccDebitType());
      accEntry.setSubaccDebitId(source.getSubaccDebitId());
      accEntry.setSubaccDebit(source.getSubaccDebit());
      if (source.getDebit() != null) {
        accEntry.setDebit(source.getDebit().negate());
      }
      accEntry.setAccCredit(source.getAccCredit());
      accEntry.setSubaccCreditType(source.getSubaccCreditType());
      accEntry.setSubaccCreditId(source.getSubaccCreditId());
      accEntry.setSubaccCredit(source.getSubaccCredit());
      if (source.getCredit() != null) {
        accEntry.setCredit(source.getCredit().negate());
      }
      accEntry.setDescription(getSrvI18n().getMsg("made_at", langDef) + " "
    + dateFormat.format(new Date()) + " " + getSrvI18n()
  .getMsg("by", langDef) + " " + getSrvI18n().getMsg(pReversing.getClass()
.getSimpleName() + "short", langDef) + " #" + pReversing.getIdDatabaseBirth()
  + "-" + reversingDocId + ", " + dateFormat.format(pReversing.getItsDate())
    // reversed from  current DB:
    + ", " + getSrvI18n().getMsg("reversed_entry_n", langDef) + source
      .getIdDatabaseBirth() + "-" + source.getItsId());
      accEntry.setReversedId(source.getItsId());
      accEntry.setReversedIdDatabaseBirth(source.getIdDatabaseBirth());
      srvOrm.insertEntity(pAddParam, accEntry);
      accEntry.setIsNew(false);
      source.setDescription(source.getDescription().trim()
        + " " + getSrvI18n().getMsg("reversing_entry_n", langDef) + accEntry
          .getIdDatabaseBirth() + "-"
            + accEntry.getItsId()); // new in current DB
      source.setReversedId(accEntry.getItsId());
      source.setReversedIdDatabaseBirth(accEntry.getIdDatabaseBirth());
      srvOrm.updateEntity(pAddParam, source);
    }
    pReversing.setHasMadeAccEntries(true);
    srvOrm.updateEntity(pAddParam, pReversing);
  }
@ Override public final void reverseEntries ( final Map < String , Object > pAddParam , final IDoc pReversing , final IDoc pReversed ) throws Exception { List < AccountingEntry > sources = getSrvOrm ( ) . retrieveListWithConditions ( pAddParam , AccountingEntry . class , " where SOURCETYPE=" + pReversing . constTypeCode ( ) + " and SOURCEID=" + pReversing . getReversedId ( ) + " and SOURCEDATABASEBIRTH=" + pReversing . getReversedIdDatabaseBirth ( ) ) ; Long itsDateLong = null ; String langDef = ( String ) pAddParam . get ( "langDef" ) ; DateFormat dateFormat = DateFormat . getDateTimeInstance ( DateFormat . MEDIUM , DateFormat . SHORT , new Locale ( langDef ) ) ; for ( AccountingEntry source : sources ) { if ( ! source . getIdDatabaseBirth ( ) . equals ( getSrvDatabase ( ) . getIdDatabase ( ) ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "can_not_reverse_foreign_acconting_entries" ) ; } if ( itsDateLong == null ) { itsDateLong = pReversing . getItsDate ( ) . getTime ( ) ; getSrvBalance ( ) . handleNewAccountEntry ( pAddParam , null , null , new Date ( itsDateLong ) ) ; } AccountingEntry accEntry = new AccountingEntry ( ) ; accEntry . setItsDate ( new Date ( itsDateLong ++ ) ) ; accEntry . setIdDatabaseBirth ( getSrvDatabase ( ) . getIdDatabase ( ) ) ; accEntry . setSourceType ( pReversing . constTypeCode ( ) ) ; Long reversingDocId = pReversing . getItsId ( ) ; if ( pReversing . getIdBirth ( ) != null ) { reversingDocId = pReversing . getIdBirth ( ) ; } accEntry . setSourceId ( reversingDocId ) ; accEntry . setSourceDatabaseBirth ( pReversing . getIdDatabaseBirth ( ) ) ; accEntry . setAccDebit ( source . getAccDebit ( ) ) ; accEntry . setSubaccDebitType ( source . getSubaccDebitType ( ) ) ; accEntry . setSubaccDebitId ( source . getSubaccDebitId ( ) ) ; accEntry . setSubaccDebit ( source . getSubaccDebit ( ) ) ; if ( source . getDebit ( ) != null ) { accEntry . setDebit ( source . getDebit ( ) . negate ( ) ) ; } accEntry . setAccCredit ( source . getAccCredit ( ) ) ; accEntry . setSubaccCreditType ( source . getSubaccCreditType ( ) ) ; accEntry . setSubaccCreditId ( source . getSubaccCreditId ( ) ) ; accEntry . setSubaccCredit ( source . getSubaccCredit ( ) ) ; if ( source . getCredit ( ) != null ) { accEntry . setCredit ( source . getCredit ( ) . negate ( ) ) ; } accEntry . setDescription ( getSrvI18n ( ) . getMsg ( "made_at" , langDef ) + " " + dateFormat . format ( new Date ( ) ) + " " + getSrvI18n ( ) . getMsg ( "by" , langDef ) + " " + getSrvI18n ( ) . getMsg ( pReversing . getClass ( ) . getSimpleName ( ) + "short" , langDef ) + " #" + pReversing . getIdDatabaseBirth ( ) + "-" + reversingDocId + ", " + dateFormat . format ( pReversing . getItsDate ( ) ) + ", " + getSrvI18n ( ) . getMsg ( "reversed_entry_n" , langDef ) + source . getIdDatabaseBirth ( ) + "-" + source . getItsId ( ) ) ; accEntry . setReversedId ( source . getItsId ( ) ) ; accEntry . setReversedIdDatabaseBirth ( source . getIdDatabaseBirth ( ) ) ; srvOrm . insertEntity ( pAddParam , accEntry ) ; accEntry . setIsNew ( false ) ; source . setDescription ( source . getDescription ( ) . trim ( ) + " " + getSrvI18n ( ) . getMsg ( "reversing_entry_n" , langDef ) + accEntry . getIdDatabaseBirth ( ) + "-" + accEntry . getItsId ( ) ) ; source . setReversedId ( accEntry . getItsId ( ) ) ; source . setReversedIdDatabaseBirth ( accEntry . getIdDatabaseBirth ( ) ) ; srvOrm . updateEntity ( pAddParam , source ) ; } pReversing . setHasMadeAccEntries ( true ) ; srvOrm . updateEntity ( pAddParam , pReversing ) ; }
<p>Make accounting entries for reversing document.</p>
@param pAddParam additional param
@param pReversing a reversing document
@param pReversed a reversed document
@throws Exception - an exception