@Override
  public final void makeEntries(final Map<String, Object> pAddParam,
    final IDoc pEntity) throws Exception {
    Calendar calCurrYear = Calendar.getInstance(new Locale("en", "US"));
    calCurrYear.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam)
      .getCurrentAccYear());
    calCurrYear.set(Calendar.MONTH, 0);
    calCurrYear.set(Calendar.DAY_OF_MONTH, 1);
    calCurrYear.set(Calendar.HOUR_OF_DAY, 0);
    calCurrYear.set(Calendar.MINUTE, 0);
    calCurrYear.set(Calendar.SECOND, 0);
    calCurrYear.set(Calendar.MILLISECOND, 0);
    Calendar calDoc = Calendar.getInstance(new Locale("en", "US"));
    calDoc.setTime(pEntity.getItsDate());
    calDoc.set(Calendar.MONTH, 0);
    calDoc.set(Calendar.DAY_OF_MONTH, 1);
    calDoc.set(Calendar.HOUR_OF_DAY, 0);
    calDoc.set(Calendar.MINUTE, 0);
    calDoc.set(Calendar.SECOND, 0);
    calDoc.set(Calendar.MILLISECOND, 0);
    if (calCurrYear.getTime().getTime() != calDoc.getTime().getTime()) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "wrong_year");
    }
    StringBuffer sb = new StringBuffer();
    List<AccEntriesSourcesLine> sourcesLines = srvAccSettings
      .lazyGetAccSettings(pAddParam).getAccEntriesSources();
    java.util.Collections.sort(sourcesLines, this.cmprAccSourcesByType);
    int i = 0;
    for (AccEntriesSourcesLine sourcesLine : sourcesLines) {
      if (sourcesLine.getIsUsed()
        && sourcesLine.getSourceType().equals(pEntity.constTypeCode())) {
        String query = lazyGetQuery(sourcesLine.getFileName());
        String idName = "ITSID";
        if (pEntity.getIdBirth() != null) {
          idName = "IDBIRTH";
        }
        query = query.replace(":IDNAME", idName);
        //for foreign document this algorithm is also right:
        String strWhereDocId = sourcesLine.getSourceIdName() + " = "
          + pEntity.getItsId().toString();
        if (query.contains(":WHEREADD")) {
          query = query.replace(":WHEREADD", " and " + strWhereDocId);
        } else if (query.contains(":WHERE")) {
          query = query.replace(":WHERE", " where " + strWhereDocId);
        }
        if (i++ > 0) {
          sb.append("\nunion all\n\n");
        }
        sb.append(query);
      }
    }
    String langDef = (String) pAddParam.get("langDef");
    DateFormat dateFormat = DateFormat.getDateTimeInstance(
      DateFormat.MEDIUM, DateFormat.SHORT, new Locale(langDef));
    String query = sb.toString();
    if (query.trim().length() == 0) {
      throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
        "there_is_no_accounting_sources");
    }
    IRecordSet<RS> recordSet = null;
    try {
      recordSet = getSrvDatabase().retrieveRecords(query);
      if (recordSet.moveToFirst()) {
        Long itsDateLong = null;
        do {
          AccountingEntry accEntry = new AccountingEntry();
          accEntry.setIdDatabaseBirth(getSrvDatabase().getIdDatabase());
          if (itsDateLong == null) {
            itsDateLong = pEntity.getItsDate().getTime();
            getSrvBalance().handleNewAccountEntry(pAddParam, null, null,
              new Date(itsDateLong)); //This is for SrvBalanceStd only!!!
          }
          Date itsDate = new Date(itsDateLong++);
          accEntry.setItsDate(itsDate);
          accEntry.setSourceType(pEntity.constTypeCode());
          if (pEntity.getIdBirth() != null) { //accounting foreign document
            accEntry.setSourceId(pEntity.getIdBirth());
          } else {
            accEntry.setSourceId(pEntity.getItsId());
          }
          accEntry.setSourceDatabaseBirth(pEntity.getIdDatabaseBirth());
          String accDebitId = recordSet.getString("ACCDEBIT");
          Account accDebit = new Account();
          accDebit.setItsId(accDebitId);
          accEntry.setAccDebit(accDebit);
          accEntry.setSubaccDebitType(recordSet.getInteger("SUBACCDEBITTYPE"));
          accEntry.setSubaccDebitId(recordSet.getLong("SUBACCDEBITID"));
          accEntry.setSubaccDebit(recordSet.getString("SUBACCDEBIT"));
          accEntry.setDebit(BigDecimal.valueOf(recordSet.getDouble("DEBIT"))
            .setScale(getSrvAccSettings().lazyGetAccSettings(pAddParam)
              .getCostPrecision(), getSrvAccSettings()
                .lazyGetAccSettings(pAddParam).getRoundingMode()));
          String accCreditId = recordSet.getString("ACCCREDIT");
          Account accCredit = new Account();
          accCredit.setItsId(accCreditId);
          accEntry.setAccCredit(accCredit);
          accEntry
            .setSubaccCreditType(recordSet.getInteger("SUBACCCREDITTYPE"));
          accEntry.setSubaccCreditId(recordSet.getLong("SUBACCCREDITID"));
          accEntry.setSubaccCredit(recordSet.getString("SUBACCCREDIT"));
          accEntry.setCredit(BigDecimal
            .valueOf(recordSet.getDouble("CREDIT")).setScale(
              getSrvAccSettings().lazyGetAccSettings(pAddParam)
                .getCostPrecision(), getSrvAccSettings()
                  .lazyGetAccSettings(pAddParam).getRoundingMode()));
          String docId = pEntity.getItsId().toString();
          if (pEntity.getIdBirth() != null) {
            docId = pEntity.getIdBirth().toString();
          }
          String descr = "";
          if (pEntity.getDescription() != null) {
            descr = " " + pEntity.getDescription();
          }
          accEntry.setDescription(getSrvI18n().getMsg(pEntity.getClass().
      getSimpleName() + "short", langDef) + " #" + pEntity.getIdDatabaseBirth()
    + "-" + docId + ", " + dateFormat.format(pEntity.getItsDate()) + descr);
          this.srvOrm.insertEntity(pAddParam, accEntry);
          accEntry.setIsNew(false);
        } while (recordSet.moveToNext());
      }
    } finally {
      if (recordSet != null) {
        recordSet.close();
      }
    }
    pEntity.setHasMadeAccEntries(true);
    srvOrm.updateEntity(pAddParam, pEntity);
  }
@ Override public final void makeEntries ( final Map < String , Object > pAddParam , final IDoc pEntity ) throws Exception { Calendar calCurrYear = Calendar . getInstance ( new Locale ( "en" , "US" ) ) ; calCurrYear . setTime ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getCurrentAccYear ( ) ) ; calCurrYear . set ( Calendar . MONTH , 0 ) ; calCurrYear . set ( Calendar . DAY_OF_MONTH , 1 ) ; calCurrYear . set ( Calendar . HOUR_OF_DAY , 0 ) ; calCurrYear . set ( Calendar . MINUTE , 0 ) ; calCurrYear . set ( Calendar . SECOND , 0 ) ; calCurrYear . set ( Calendar . MILLISECOND , 0 ) ; Calendar calDoc = Calendar . getInstance ( new Locale ( "en" , "US" ) ) ; calDoc . setTime ( pEntity . getItsDate ( ) ) ; calDoc . set ( Calendar . MONTH , 0 ) ; calDoc . set ( Calendar . DAY_OF_MONTH , 1 ) ; calDoc . set ( Calendar . HOUR_OF_DAY , 0 ) ; calDoc . set ( Calendar . MINUTE , 0 ) ; calDoc . set ( Calendar . SECOND , 0 ) ; calDoc . set ( Calendar . MILLISECOND , 0 ) ; if ( calCurrYear . getTime ( ) . getTime ( ) != calDoc . getTime ( ) . getTime ( ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "wrong_year" ) ; } StringBuffer sb = new StringBuffer ( ) ; List < AccEntriesSourcesLine > sourcesLines = srvAccSettings . lazyGetAccSettings ( pAddParam ) . getAccEntriesSources ( ) ; java . util . Collections . sort ( sourcesLines , this . cmprAccSourcesByType ) ; int i = 0 ; for ( AccEntriesSourcesLine sourcesLine : sourcesLines ) { if ( sourcesLine . getIsUsed ( ) && sourcesLine . getSourceType ( ) . equals ( pEntity . constTypeCode ( ) ) ) { String query = lazyGetQuery ( sourcesLine . getFileName ( ) ) ; String idName = "ITSID" ; if ( pEntity . getIdBirth ( ) != null ) { idName = "IDBIRTH" ; } query = query . replace ( ":IDNAME" , idName ) ; String strWhereDocId = sourcesLine . getSourceIdName ( ) + " = " + pEntity . getItsId ( ) . toString ( ) ; if ( query . contains ( ":WHEREADD" ) ) { query = query . replace ( ":WHEREADD" , " and " + strWhereDocId ) ; } else if ( query . contains ( ":WHERE" ) ) { query = query . replace ( ":WHERE" , " where " + strWhereDocId ) ; } if ( i ++ > 0 ) { sb . append ( "\nunion all\n\n" ) ; } sb . append ( query ) ; } } String langDef = ( String ) pAddParam . get ( "langDef" ) ; DateFormat dateFormat = DateFormat . getDateTimeInstance ( DateFormat . MEDIUM , DateFormat . SHORT , new Locale ( langDef ) ) ; String query = sb . toString ( ) ; if ( query . trim ( ) . length ( ) == 0 ) { throw new ExceptionWithCode ( ExceptionWithCode . CONFIGURATION_MISTAKE , "there_is_no_accounting_sources" ) ; } IRecordSet < RS > recordSet = null ; try { recordSet = getSrvDatabase ( ) . retrieveRecords ( query ) ; if ( recordSet . moveToFirst ( ) ) { Long itsDateLong = null ; do { AccountingEntry accEntry = new AccountingEntry ( ) ; accEntry . setIdDatabaseBirth ( getSrvDatabase ( ) . getIdDatabase ( ) ) ; if ( itsDateLong == null ) { itsDateLong = pEntity . getItsDate ( ) . getTime ( ) ; getSrvBalance ( ) . handleNewAccountEntry ( pAddParam , null , null , new Date ( itsDateLong ) ) ; } Date itsDate = new Date ( itsDateLong ++ ) ; accEntry . setItsDate ( itsDate ) ; accEntry . setSourceType ( pEntity . constTypeCode ( ) ) ; if ( pEntity . getIdBirth ( ) != null ) { accEntry . setSourceId ( pEntity . getIdBirth ( ) ) ; } else { accEntry . setSourceId ( pEntity . getItsId ( ) ) ; } accEntry . setSourceDatabaseBirth ( pEntity . getIdDatabaseBirth ( ) ) ; String accDebitId = recordSet . getString ( "ACCDEBIT" ) ; Account accDebit = new Account ( ) ; accDebit . setItsId ( accDebitId ) ; accEntry . setAccDebit ( accDebit ) ; accEntry . setSubaccDebitType ( recordSet . getInteger ( "SUBACCDEBITTYPE" ) ) ; accEntry . setSubaccDebitId ( recordSet . getLong ( "SUBACCDEBITID" ) ) ; accEntry . setSubaccDebit ( recordSet . getString ( "SUBACCDEBIT" ) ) ; accEntry . setDebit ( BigDecimal . valueOf ( recordSet . getDouble ( "DEBIT" ) ) . setScale ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getCostPrecision ( ) , getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getRoundingMode ( ) ) ) ; String accCreditId = recordSet . getString ( "ACCCREDIT" ) ; Account accCredit = new Account ( ) ; accCredit . setItsId ( accCreditId ) ; accEntry . setAccCredit ( accCredit ) ; accEntry . setSubaccCreditType ( recordSet . getInteger ( "SUBACCCREDITTYPE" ) ) ; accEntry . setSubaccCreditId ( recordSet . getLong ( "SUBACCCREDITID" ) ) ; accEntry . setSubaccCredit ( recordSet . getString ( "SUBACCCREDIT" ) ) ; accEntry . setCredit ( BigDecimal . valueOf ( recordSet . getDouble ( "CREDIT" ) ) . setScale ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getCostPrecision ( ) , getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getRoundingMode ( ) ) ) ; String docId = pEntity . getItsId ( ) . toString ( ) ; if ( pEntity . getIdBirth ( ) != null ) { docId = pEntity . getIdBirth ( ) . toString ( ) ; } String descr = "" ; if ( pEntity . getDescription ( ) != null ) { descr = " " + pEntity . getDescription ( ) ; } accEntry . setDescription ( getSrvI18n ( ) . getMsg ( pEntity . getClass ( ) . getSimpleName ( ) + "short" , langDef ) + " #" + pEntity . getIdDatabaseBirth ( ) + "-" + docId + ", " + dateFormat . format ( pEntity . getItsDate ( ) ) + descr ) ; this . srvOrm . insertEntity ( pAddParam , accEntry ) ; accEntry . setIsNew ( false ) ; } while ( recordSet . moveToNext ( ) ) ; } } finally { if ( recordSet != null ) { recordSet . close ( ) ; } } pEntity . setHasMadeAccEntries ( true ) ; srvOrm . updateEntity ( pAddParam , pEntity ) ; }
<p>Make accounting entries for document.</p>
@param pAddParam additional param
@param pEntity a document
@throws Exception - an exception