<p>Evaluate date start of next balance store period.
Tested in beige-common org.beigesoft.test.CalendarTest.</p>
@param pAddParam additional param
@param pDateFor date for
@return Start of next period nearest to pDateFor
@throws Exception - an exception
492134
public final synchronized Date evalDateNextPeriodStart(
    final Map<String, Object> pAddParam,
      final Date pDateFor) throws Exception {
    EPeriod period = evalBalanceStorePeriod(pAddParam);
    if (!(period.equals(EPeriod.MONTHLY)
      || period.equals(EPeriod.WEEKLY)
        || period.equals(EPeriod.DAILY))) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "stored_balance_period_must_be_dwm");
    }
    Calendar cal = Calendar.getInstance(new Locale("en", "US"));
    cal.setTime(pDateFor);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    if (period.equals(EPeriod.DAILY)) {
      cal.add(Calendar.DATE, 1);
    } else if (period.equals(EPeriod.MONTHLY)) {
      cal.add(Calendar.MONTH, 1);
      cal.set(Calendar.DAY_OF_MONTH, 1);
    } else if (period.equals(EPeriod.WEEKLY)) {
      cal.add(Calendar.DAY_OF_YEAR, 7);
      cal.set(Calendar.DAY_OF_WEEK, 1);
    }
    return cal.getTime();
  }
354229
protected final PrcSeSellerDel<RS> lazyGetPrcSeSellerDel(final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcSeSellerDel.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcSeSellerDel<RS> proc = (PrcSeSellerDel<RS>) this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcSeSellerDel<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setFindSeSeller(getFindSeSeller());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeEntitiesProcessors.class, beanName + " has been created.");
    }
    return proc;
  }
774735
protected final PrcPurchaseReturnSave<RS> lazyGetPrcPurchaseReturnSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcPurchaseReturnSave<RS> proc = (PrcPurchaseReturnSave<RS>)
      this.processorsMap.get(PrcPurchaseReturnSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcPurchaseReturnSave<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvAccEntry(getSrvAccEntry());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvI18n(getSrvI18n());
      proc.setSrvWarehouseEntry(getSrvWarehouseEntry());
      proc.setSrvUseMaterialEntry(getSrvUseMaterialEntry());
      //assigning fully initialized object:
      this.processorsMap.put(PrcPurchaseReturnSave.class.getSimpleName(), proc);
    }
    return proc;
  }
87288
@Override
  public final String toDateString(final Date pDate,
    final Map<String, Object> pAddParam) throws Exception {
    return this.dateFormat.format(pDate);
  }
59544
protected final PrcItSpecEmbFlDel<RS, IHasIdLongVersion, AItemSpecificsId<IHasIdLongVersion>>
    lazyGetPrcItSpecEmbFlDel(final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcItSpecEmbFlDel.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcItSpecEmbFlDel<RS, IHasIdLongVersion, AItemSpecificsId<IHasIdLongVersion>> proc =
      (PrcItSpecEmbFlDel<RS, IHasIdLongVersion, AItemSpecificsId<IHasIdLongVersion>>)
        this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcItSpecEmbFlDel<RS, IHasIdLongVersion, AItemSpecificsId<IHasIdLongVersion>>();
      proc.setSrvOrm(getSrvOrm());
      proc.setUploadDirectory(getUploadDirectory());
      proc.setWebAppPath(getWebAppPath());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeEntitiesProcessors.class, beanName + " has been created.");
    }
    return proc;
  }
780206
protected final PrcCheckOut<RS> lazyGetPrcCheckOut(
    final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcCheckOut.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcCheckOut<RS> proc = (PrcCheckOut<RS>)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcCheckOut<RS>();
      proc.setLog(getLogger());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvCart(getSrvShoppingCart());
      proc.setProcFac(this);
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnPublicTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
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);
  }
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;
  }
1323000
protected final InvTxMeth<SalesReturn, SalesReturnTaxLine>
    lazyGetSalRetTxMeth(final Map<String, Object> pAddParam) throws Exception {
    InvTxMeth<SalesReturn, SalesReturnTaxLine> salRetTxMe =
      this.salRetTxMeth;
    if (salRetTxMe == null) {
      salRetTxMe = new InvTxMeth<SalesReturn, SalesReturnTaxLine>();
      salRetTxMe.setGoodLnCl(SalesReturnLine.class);
      salRetTxMe.setInvTxLnCl(SalesReturnTaxLine.class);
      salRetTxMe.setIsTxByUser(true);
      salRetTxMe.setStWhereAdjGdLnInvBas(
        "where SALESRETURNLINE.TAXCATEGORY is not null and REVERSEDID "
          + "is null and ITSOWNER=");
      salRetTxMe.setFlTotals("invGdTotals.sql");
      salRetTxMe.setFlTxItBas("invGdTxItBas.sql");
      salRetTxMe.setFlTxItBasAggr("invGdTxItBasAggr.sql");
      salRetTxMe.setFlTxInvBas("invGdTxInvBas.sql");
      salRetTxMe.setFlTxInvAdj("invGdTxInvAdj.sql");
      salRetTxMe.setFlTxInvBasAggr("invGdTxInvBasAggr.sql");
      salRetTxMe.setTblNmsTot(new String[] {"SALESRETURNLINE",
        "SALESRETURNTAXLINE", "SALESRETURNGOODSTAXLINE"});
      FactoryPersistableBase<SalesReturnTaxLine> fctItl =
        new FactoryPersistableBase<SalesReturnTaxLine>();
      fctItl.setObjectClass(SalesReturnTaxLine.class);
      fctItl.setDatabaseId(getSrvDatabase().getIdDatabase());
      salRetTxMe.setFctInvTxLn(fctItl);
      //assigning fully initialized object:
      this.salRetTxMeth = salRetTxMe;
    }
    return salRetTxMe;
  }
581917
public final void lazyEvalReplicationMethod(
    final Map<String, Object> pAddParam) throws Exception {
    Long replicationMethodId;
    try {
      replicationMethodId = Long.parseLong(pAddParam
        .get("replicationMethodId").toString());
    } catch (Exception e) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "Wrong or missing parameter replicationMethodId (in pAddParam): "
          + pAddParam.get("replicationMethodId"));
    }
    if (this.replicationMethod == null || !this.replicationMethod
      .getItsId().equals(replicationMethodId)) {
      this.replicationMethod = new ReplicationAccMethod();
      this.replicationMethod.setItsId(replicationMethodId);
      this.replicationMethod = getSrvOrm()
        .retrieveEntity(pAddParam, this.replicationMethod);
      ReplExcludeAccountsDebit ead = new ReplExcludeAccountsDebit();
      ead.setItsOwner(this.replicationMethod);
      this.replicationMethod.setExcludeDebitAccounts(getSrvOrm()
        .retrieveListForField(pAddParam, ead, "itsOwner"));
      ReplExcludeAccountsCredit eac = new ReplExcludeAccountsCredit();
      eac.setItsOwner(this.replicationMethod);
      this.replicationMethod.setExcludeCreditAccounts(getSrvOrm()
        .retrieveListForField(pAddParam, eac, "itsOwner"));
    }
  }
115898
protected final PrcAccDocWithTaxesGetForReverse<RS, ADocWithTaxes>
    lazyGetPrcAccDocWithTaxesGetForReverse(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcAccDocWithTaxesGetForReverse<RS, ADocWithTaxes> proc =
      (PrcAccDocWithTaxesGetForReverse<RS, ADocWithTaxes>) this.processorsMap
        .get(PrcAccDocWithTaxesGetForReverse.class.getSimpleName());
    if (proc == null) {
      proc =
        new PrcAccDocWithTaxesGetForReverse<RS, ADocWithTaxes>();
      @SuppressWarnings("unchecked")
      IEntityProcessor<ADocWithTaxes, Long> procDlg =
        (IEntityProcessor<ADocWithTaxes, Long>)
          lazyGetPrcAccDocGetForReverse(pAddParam);
      proc.setPrcDocReverse(procDlg);
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcAccDocWithTaxesGetForReverse.class.getSimpleName(), proc);
    }
    return proc;
  }
730077
@Override
  public final Date fromString(final Map<String, Object> pAddParam,
    final String pStrVal) throws Exception {
    if (pStrVal == null || "".equals(pStrVal)) {
      return null;
    }
    return this.dateTimeSecNoTzFormatIso8601.parse(pStrVal);
  }
1189334
@Override
  public final T fromString(final Map<String, Object> pAddParam,
    final String pStrVal) throws Exception {
    if (pStrVal == null || "".equals(pStrVal)) {
      return null;
    }
    T object = this.objectClass.newInstance();
    for (String fldValStr : pStrVal.split(",")) {
      int eqIdx = fldValStr.indexOf("=");
      String fldName = fldValStr.substring(0, eqIdx);
      String cnvrtName = this.fieldConverterNamesHolder.getFor(this.objectClass,
        fldName);
      if (cnvrtName != null) { // e.g. transient field
        IConverterToFromString cnvrt = this.fieldsConvertersFatory
          .lazyGet(null, cnvrtName);
        Method fldSetter = this.settersRapiHolder
          .getFor(this.objectClass, fldName);
        String strVal = fldValStr.substring(eqIdx + 1);
        Object fldVal = cnvrt.fromString(pAddParam, strVal);
        fldSetter.invoke(object, fldVal);
      }
    }
    return object;
  }
1270779
private Integer getFrequency(Project.Calendars.Calendar.Exceptions.Exception exception)
   {
      Integer period = NumberHelper.getInteger(exception.getPeriod());
      if (period == null)
      {
         period = Integer.valueOf(1);
      }
      return period;
   }
1083959
protected final PrcBeginningInventoryLineSave<RS>
    lazyGetPrcBeginningInventoryLineSave(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBeginningInventoryLineSave<RS> proc = (PrcBeginningInventoryLineSave<RS>)
  this.processorsMap.get(PrcBeginningInventoryLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBeginningInventoryLineSave<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvWarehouseEntry(getSrvWarehouseEntry());
      proc.setSrvDatabase(getSrvDatabase());
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcBeginningInventoryLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
922112
@Override
  public final <T> Integer evalRowCount(
    final Map<String, Object> pAddParam,
      final Class<T> pEntityClass) throws Exception {
    String query = "select count(*) as TOTALROWS from " + pEntityClass
      .getSimpleName().toUpperCase() + ";";
    return evalRowCountByQuery(pAddParam, pEntityClass, query);
  }
184592
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    String retrieverName = pRequestData.getParameter("nmRet");
    ICsvDataRetriever ret = this.retrievers.get(retrieverName);
    if (ret == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "Can't find retriever " + retrieverName);
    }
    pRequestData.setAttribute("dataTree", ret.getSampleDataRow(pAddParam));
  }