<p>It prepares database after import.</p>
@param pAddParam additional params
@throws Exception - an exception
168407
@Override
  public final void make(
    final Map<String, Object> pAddParam) throws Exception {
    this.replicationMethod.setLastDateReplication(new Date());
    getSrvOrm().updateEntity(pAddParam, this.replicationMethod);
  }
1206406
protected final PrcPaymentToGfr<RS> createPutPrcPaymentToGfr(
    final Map<String, Object> pAddParam) throws Exception {
    PrcPaymentToGfr<RS> proc = new PrcPaymentToGfr<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<PaymentTo, Long> procDlg =
      (IEntityProcessor<PaymentTo, Long>)
        lazyGetPrcAccDocGetForReverse(pAddParam);
    proc.setPrcAccDocGetForReverse(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap.put(PrcPaymentToGfr.class.getSimpleName(), proc);
    return proc;
  }
762526
protected final PrcManufactureGfr<RS> createPutPrcManufactureGfr(
    final Map<String, Object> pAddParam) throws Exception {
    PrcManufactureGfr<RS> proc = new PrcManufactureGfr<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<Manufacture, Long> procDlg =
      (IEntityProcessor<Manufacture, Long>)
        lazyGetPrcAccDocGetForReverse(pAddParam);
    proc.setPrcAccDocGetForReverse(procDlg);
    //assigning fully initialized object:
    this.processorsMap.put(PrcManufactureGfr.class.getSimpleName(), proc);
    return proc;
  }
207448
@Override
  public final void makeWarehouseRest(final Map<String, Object> pAddParam,
    final IMakingWarehouseEntry pEntity,
      final WarehouseSite pWhSite,
        final BigDecimal pQuantity) throws Exception {
    if (!pEntity.getIdDatabaseBirth()
      .equals(getSrvOrm().getIdDatabase())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "can_not_make_ws_entry_for_foreign_src");
    }
    WarehouseRest wr = getSrvOrm().retrieveEntityWithConditions(pAddParam,
      WarehouseRest.class, "where WAREHOUSESITE="
        + pWhSite.getItsId() + " and INVITEM="
          + pEntity.getInvItem().getItsId() + " and UNITOFMEASURE="
            + pEntity.getUnitOfMeasure().getItsId());
    if (wr == null) {
      if (pQuantity.doubleValue() < 0) {
        throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
          "attempt_reverse_non_existent_good_in_warehouse");
      }
      wr = new WarehouseRest();
      wr.setIsNew(true);
      wr.setWarehouseSite(pWhSite);
      wr.setUnitOfMeasure(pEntity.getUnitOfMeasure());
      wr.setInvItem(pEntity.getInvItem());
    }
    wr.setTheRest(wr.getTheRest().add(pQuantity));
    if (wr.getTheRest().doubleValue() < 0) {
      throw new ExceptionWithCode(PurchaseInvoice.THERE_IS_NO_GOODS,
        "there_is_no_goods_in_stock");
    }
    if (wr.getIsNew()) {
      getSrvOrm().insertEntity(pAddParam, wr);
      wr.setIsNew(false);
    } else {
      if (this.fastLoc) {
        ColumnsValues cvs = new ColumnsValues();
        cvs.getFormula().add("itsVersion");
        cvs.getFormula().add("theRest");
        cvs.put("itsVersion", "ITSVERSION+1");
        if (pQuantity.compareTo(BigDecimal.ZERO) == -1) {
          cvs.put("theRest", "THEREST" + pQuantity);
        } else {
          cvs.put("theRest", "THEREST+" + pQuantity);
        }
        this.srvDb.executeUpdate("WAREHOUSEREST", cvs, "WAREHOUSESITE="
      + wr.getWarehouseSite().getItsId() + " and INVITEM=" + wr.getInvItem()
    .getItsId() + " and UNITOFMEASURE=" + wr.getUnitOfMeasure().getItsId());
      } else {
        getSrvOrm().updateEntity(pAddParam, wr);
      }
    }
  }
101849
protected final PrcAdditionCostLineSave<RS> lazyGetPrcAdditionCostLineSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcAdditionCostLineSave<RS> proc = (PrcAdditionCostLineSave<RS>)
      this.processorsMap.get(PrcAdditionCostLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcAdditionCostLineSave<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvDatabase(getSrvDatabase());
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcAdditionCostLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
543381
protected final PrcPaymentFromSave<RS> createPutPrcPaymentFromSave(
      final Map<String, Object> pAddParam) throws Exception {
    PrcPaymentFromSave<RS> proc = new PrcPaymentFromSave<RS>();
    proc.setSrvAccSettings(getSrvAccSettings());
    proc.setSrvAccEntry(getSrvAccEntry());
    proc.setSrvOrm(getSrvOrm());
    proc.setSrvI18n(getSrvI18n());
    proc.setPrcSalesInvoiceSave(lazyGetPrcSalesInvoiceSave(pAddParam));
    //assigning fully initialized object:
    this.processorsMap.put(PrcPaymentFromSave.class.getSimpleName(), proc);
    return proc;
  }
813989
@Override
  public final synchronized EPeriod evalBalanceStorePeriod(
    final Map<String, Object> pAddParam) throws Exception {
    if (!lazyGetBalanceAtAllDirtyCheck(pAddParam).getBalanceStorePeriod()
      .equals(getSrvAccSettings().lazyGetAccSettings(pAddParam)
        .getBalanceStorePeriod())) {
      getLogger().info(null, SrvBalanceStd.class,
        "changing period from " + this.balanceAtAllDirtyCheck
          .getBalanceStorePeriod() + " to " + getSrvAccSettings()
            .lazyGetAccSettings(pAddParam).getBalanceStorePeriod());
      this.balanceAtAllDirtyCheck
        .setBalanceStorePeriod(getSrvAccSettings().lazyGetAccSettings(pAddParam)
          .getBalanceStorePeriod());
      this.balanceAtAllDirtyCheck.setIsPeriodChanged(true);
      this.balanceAtAllDirtyCheck
        .setCurrentBalanceDate(initDate);
      getSrvOrm()
        .updateEntity(pAddParam, this.balanceAtAllDirtyCheck);
    }
    return this.balanceAtAllDirtyCheck.getBalanceStorePeriod();
  }
1029634
@Override
  public final IEntityProcessor lazyGet(final Map<String, Object> pAddParam,
    final String pBeanName) throws Exception {
    IEntityProcessor proc = this.processorsMap.get(pBeanName);
    if (proc == null) {
      // locking:
      synchronized (this.processorsMap) {
        // make sure again whether it's null after locking:
        proc = this.processorsMap.get(pBeanName);
        if (proc == null) {
          if (pBeanName.equals(PrcHasSeSellerSave.class.getSimpleName())) {
            proc = lazyGetPrcHasSeSellerSave(pAddParam);
          } else if (pBeanName.equals(PrcHasSeSellerDel
            .class.getSimpleName())) {
            proc = lazyGetPrcHasSeSellerDel(pAddParam);
          } else if (pBeanName.equals(PrcSeGoodsSpecSave
            .class.getSimpleName())) {
            proc = lazyGetPrcSeGoodsSpecSave(pAddParam);
          } else if (pBeanName.equals(PrCuOrSeSv
            .class.getSimpleName())) {
            proc = lazyGetPrCuOrSeSv(pAddParam);
          } else if (pBeanName.equals(PrcSeServiceSpecSave
            .class.getSimpleName())) {
            proc = lazyGetPrcSeServiceSpecSave(pAddParam);
          } else if (pBeanName.equals(PrcSeGdSpecEmbFlSave
            .class.getSimpleName())) {
            proc = lazyGetPrcSeGdSpecEmbFlSave(pAddParam);
          } else if (pBeanName.equals(PrcSeGdSpecEmbFlDel
            .class.getSimpleName())) {
            proc = lazyGetPrcSeGdSpecEmbFlDel(pAddParam);
          } else if (pBeanName.equals(PrcSeSrvSpecEmbFlSave
            .class.getSimpleName())) {
            proc = lazyGetPrcSeSrvSpecEmbFlSave(pAddParam);
          } else if (pBeanName.equals(PrcSeSrvSpecEmbFlDel
            .class.getSimpleName())) {
            proc = lazyGetPrcSeSrvSpecEmbFlDel(pAddParam);
          } else {
            proc = this.fctBnEntitiesProcessors.lazyGet(pAddParam, pBeanName);
          }
        }
      }
    }
    if (proc == null) {
      throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
        "There is no processor with name " + pBeanName);
    }
    return proc;
  }
542032
protected final PrcPaymentFromGfr<RS> createPutPrcPaymentFromGfr(
    final Map<String, Object> pAddParam) throws Exception {
    PrcPaymentFromGfr<RS> proc = new PrcPaymentFromGfr<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<PaymentFrom, Long> procDlg =
      (IEntityProcessor<PaymentFrom, Long>)
        lazyGetPrcAccDocGetForReverse(pAddParam);
    proc.setPrcAccDocGetForReverse(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap.put(PrcPaymentFromGfr.class.getSimpleName(), proc);
    return proc;
  }
441793
@Override
  public final Long fromString(final Map<String, Object> pAddParam,
    final String pStrVal) throws Exception {
    if (pStrVal == null || "".equals(pStrVal)) {
      return null;
    }
    if (pAddParam != null) {
      String dgsep = (String) pAddParam.get("decGrSepv");
      if (dgsep != null) {
        String strVal = pStrVal.replace(dgsep, "");
        return Long.valueOf(strVal);
      }
    }
    return Long.valueOf(pStrVal);
  }
798653
@Override
  public final <T> void updateEntity(
    final Map<String, Object> pAddParam,
      final T pEntity) throws Exception {
    ColumnsValues columnsValues = evalColumnsValues(pAddParam, pEntity);
    String whereStr = evalWhereForUpdate(pEntity, columnsValues);
    prepareColumnValuesForUpdate(columnsValues, pEntity);
    int result = getSrvDatabase().executeUpdate(pEntity.getClass()
      .getSimpleName().toUpperCase(), columnsValues, whereStr);
    if (result != 1) {
      if (result == 0 && columnsValues.ifContains(VERSION_NAME)) {
        throw new ExceptionWithCode(ISrvDatabase.DIRTY_READ, "dirty_read");
      } else {
        String query = hlpInsertUpdate.evalSqlUpdate(pEntity.getClass()
          .getSimpleName().toUpperCase(), columnsValues,
            whereStr);
        throw new ExceptionWithCode(ISrvDatabase.ERROR_INSERT_UPDATE,
          "It should be 1 row updated but it was "
            + result + ", query:\n" + query);
      }
    }
  }
93900
@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);
  }
549779
protected final PrcPrepaymentToGfr<RS> createPutPrcPrepaymentToGfr(
    final Map<String, Object> pAddParam) throws Exception {
    PrcPrepaymentToGfr<RS> proc = new PrcPrepaymentToGfr<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<PrepaymentTo, Long> procDlg =
      (IEntityProcessor<PrepaymentTo, Long>)
        lazyGetPrcAccDocGetForReverse(pAddParam);
    proc.setPrcAccDocGetForReverse(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap.put(PrcPrepaymentToGfr.class.getSimpleName(), proc);
    return proc;
  }
162679
protected final PrcPrepaymentToCopy<RS> createPutPrcPrepaymentToCopy(
    final Map<String, Object> pAddParam) throws Exception {
    PrcPrepaymentToCopy<RS> proc = new PrcPrepaymentToCopy<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<PrepaymentTo, Long> procDlg =
      (IEntityProcessor<PrepaymentTo, Long>)
        lazyGetPrcAccEntityPbWithSubaccCopy(pAddParam);
    proc.setPrcAccEntityPbWithSubaccCopy(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap.put(PrcPrepaymentToCopy.class.getSimpleName(), proc);
    return proc;
  }
656418
protected final PrcAccEntityPbWithSubaccEditDelete<RS, IPersistableBase>
    createPutPrcAccEntityPbWithSubaccEditDelete(
      final Map<String, Object> pAddParam) throws Exception {
    PrcAccEntityPbWithSubaccEditDelete<RS, IPersistableBase> proc =
      new PrcAccEntityPbWithSubaccEditDelete<RS, IPersistableBase>();
    @SuppressWarnings("unchecked")
    PrcEntityPbEditDelete<RS, IPersistableBase> procDlg =
      (PrcEntityPbEditDelete<RS, IPersistableBase>) this.fctBnEntitiesProcessors
        .lazyGet(pAddParam, PrcEntityPbEditDelete.class.getSimpleName());
    proc.setPrcAccEntityPbEditDelete(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap
      .put(PrcAccEntityPbWithSubaccEditDelete.class.getSimpleName(), proc);
    return proc;
  }
527414
public final synchronized BalanceAtAllDirtyCheck
    lazyGetBalanceAtAllDirtyCheck(
      final Map<String, Object> pAddParam) throws Exception {
    if (this.balanceAtAllDirtyCheck == null) {
      BalanceAtAllDirtyCheck balLoc = new BalanceAtAllDirtyCheck();
      balLoc.setItsId(1L);
      this.balanceAtAllDirtyCheck = getSrvOrm()
        .retrieveEntity(pAddParam, balLoc);
      if (this.balanceAtAllDirtyCheck == null) {
        getSrvOrm().insertEntity(pAddParam, balLoc);
        balLoc.setIsNew(false);
        this.balanceAtAllDirtyCheck = getSrvOrm()
          .retrieveEntity(pAddParam, balLoc);
      }
    }
    return this.balanceAtAllDirtyCheck;
  }
1084007
protected final PrcBankStatementLineSave<RS> lazyGetPrcBankStatementLineSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBankStatementLineSave<RS> proc = (PrcBankStatementLineSave<RS>)
      this.processorsMap.get(PrcBankStatementLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBankStatementLineSave<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvI18n(getSrvI18n());
      proc.setSrvAccEntry(getSrvAccEntry());
      proc.setPrcPurchaseInvoiceSave(lazyGetPrcPurchaseInvoiceSave(pAddParam));
      proc.setPrcSalesInvoiceSave(lazyGetPrcSalesInvoiceSave(pAddParam));
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcBankStatementLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }