<p>adjust invoice lines and Update its totals after tax line has
been changed (Invoice basis).</p>
@param pReqVars additional param
@param pInv Invoice
@param pAs accounting settings
@param pTxRules not NULL
@throws Exception - an exception
332739
public final void adjInvLnsUpdTots(final Map<String, Object> pReqVars,
    final T pInv, final AccSettings pAs,
      final TaxDestination pTxRules) throws Exception {
    List<SalesInvoiceServiceLine> txdLns = this.utlInvBase
      .retrTxdLnsAdjInv(pReqVars, pInv, pAs, pTxRules, this.invTxMeth);
    this.utlInvBase.adjustInvoiceLns(pReqVars, pInv, txdLns, pAs,
      this.invTxMeth);
    this.utlInvBase.updInvTots(pReqVars, pInv, pAs, this.invTxMeth);
  }
78172
public final <T extends IHasIdLongVersionName> void makeIt(
    final Map<String, Object> pAddParam, final IRequestData pRequestData,
      final Class<T> pItemClass) throws Exception {
    Set<String> filterAppearance = new HashSet<String>();
    pAddParam.put("filterAppearance", filterAppearance);
    StringBuffer sbWhere = this.srvEntitiesPage
      .revealPageFilterData(pAddParam, pRequestData, pItemClass);
    if (sbWhere.length() == 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "filter_must_be_not_empty");
    }
    String itemsCatalogAction = pRequestData
      .getParameter("itemsCatalogAction");
    if (!("add".equals(itemsCatalogAction)
      || "remove".equals(itemsCatalogAction))) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "wrong_action");
    }
    Long catalogId = Long.valueOf(pRequestData
      .getParameter(CatalogGs.class.getSimpleName() + ".itsId"));
    if (catalogId == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "catalog_must_be_not_empty");
    }
    CatalogGs catalogOfGoods = this.srvOrm
      .retrieveEntityById(pAddParam, CatalogGs.class, catalogId);
    if (catalogOfGoods == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "catalog_must_be_not_empty");
    }
    if (catalogOfGoods.getHasSubcatalogs()) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "catalog_must_not_has_subcatalog");
    }
    String whereStr = sbWhere.toString();
    Integer rowCount = this.srvOrm.evalRowCountWhere(pAddParam, pItemClass,
        whereStr);
    TradingSettings ts = (TradingSettings) pAddParam.get("tradSet");
    if (rowCount > ts.getMaxQuantityOfBulkItems()) {
      throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
        "filtered_list_size_exceed_max_bulk");
    }
    Integer totalItems = Integer
      .valueOf(pRequestData.getParameter("totalItems"));
    if (!rowCount.equals(totalItems)) {
      throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
        "filtered_list_has_changed");
    }
    List<T> itemsList = this.srvOrm.retrieveListWithConditions(pAddParam,
      pItemClass, "where " + whereStr);
    for (T items : itemsList) {
      AItemCatalog ic;
      if (pItemClass == InvItem.class) {
        ic = new GoodsCatalog();
      } else if (pItemClass == ServiceToSale.class) {
        ic = new ServiceCatalog();
      } else {
        throw new Exception("NEI: " + pItemClass);
      }
      ic.setItsCatalog(catalogOfGoods);
      ic.setItem(items);
      if ("add".equals(itemsCatalogAction)) {
        // add items to catalog
        this.srvOrm.insertEntity(pAddParam, ic);
      } else {
        // remove items from catalog
        this.srvOrm.deleteEntity(pAddParam, ic);
      }
    }
    pRequestData.setAttribute("itemsCatalogAction", itemsCatalogAction);
    pRequestData.setAttribute("filterAppearance", filterAppearance);
    pRequestData.setAttribute("totalItems", totalItems);
    pRequestData.setAttribute("itemsList", itemsList);
    pRequestData.setAttribute("catalogOfItems", catalogOfGoods);
  }
1116848
@Override
    public void tpsv(char order, char Uplo, char TransA, char Diag, INDArray Ap, INDArray X) {
        if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL)
            OpProfiler.getInstance().processBlasCall(false, Ap, X);

        // FIXME: int cast

        if (X.data().dataType() == DataType.DOUBLE) {
            DefaultOpExecutioner.validateDataType(DataType.DOUBLE, X, Ap);
            dtpsv(order, Uplo, TransA, Diag, (int) X.length(), Ap, X, X.stride(-1));
        } else {
            DefaultOpExecutioner.validateDataType(DataType.FLOAT, Ap, X);
            stpsv(order, Uplo, TransA, Diag, (int) X.length(), Ap, X, X.stride(-1));
        }

        OpExecutionerUtil.checkForAny(X);
    }
823563
@Override
  public final synchronized void handleSeSellerChanged(
    final Map<String, Object> pReqVars,
      final String pName) throws Exception {
    this.sesellers = null;
  }
108198
@Override
  public final void makeOtherEntries(final Map<String, Object> pAddParam,
    final PaymentTo pEntity, final IRequestData pRequestData,
      final boolean pIsNew) throws Exception {
    String actionAdd = pRequestData.getParameter("actionAdd");
    if ("makeAccEntries".equals(actionAdd)) {
      this.prcPurchaseInvoiceSave.calculateTotalPayment(pAddParam,
        pEntity.getPurchaseInvoice());
      getSrvOrm().updateEntity(pAddParam, pEntity.getPurchaseInvoice());
    }
  }
1327404
@Override
  public final void makeFirstPrepareForSave(final Map<String, Object> pAddParam,
    final ManufacturingProcess pEntity,
      final IRequestData pRequestData) throws Exception {
    if (pEntity.getItsQuantity().doubleValue() == 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "Quantity is 0! " + pAddParam.get("user"));
    }
    pEntity.setInvItem(getSrvOrm()
      .retrieveEntity(pAddParam, pEntity.getInvItem()));
    if (!InvItem.WORK_IN_PROGRESS_ID.equals(pEntity.getInvItem().getItsType()
      .getItsId())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "type_must_be_work_in_progress");
    }
    if (pEntity.getReversedId() != null) {
      pEntity.setIsComplete(true);
      pEntity.setTheRest(BigDecimal.ZERO);
    } else {
      pEntity.setTheRest(pEntity.getItsQuantity());
    }
    //rounding:
    pEntity.setItsQuantity(pEntity.getItsQuantity().setScale(
      getSrvAccSettings().lazyGetAccSettings(pAddParam)
        .getQuantityPrecision(), getSrvAccSettings()
          .lazyGetAccSettings(pAddParam).getRoundingMode()));
    pEntity.setItsCost(pEntity.getItsTotal().divide(
      pEntity.getItsQuantity(), getSrvAccSettings()
        .lazyGetAccSettings(pAddParam).getCostPrecision(),
          getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode()));
  }
671480
@Override
  public final synchronized List<TrialBalanceLine> retrieveTrialBalance(
    final Map<String, Object> pAddParam,
      final Date pDate) throws Exception {
    recalculateAllIfNeed(pAddParam, pDate);
    List<TrialBalanceLine> result = new ArrayList<TrialBalanceLine>();
    String query = evalQueryBalance(pAddParam, pDate);
    IRecordSet<RS> recordSet = null;
    try {
      recordSet = getSrvDatabase().retrieveRecords(query);
      if (recordSet.moveToFirst()) {
        do {
          String accName = recordSet
            .getString("ITSNAME");
          String accNumber = recordSet
            .getString("ITSNUMBER");
          String subaccName = recordSet
            .getString("SUBACC");
          Double debit = recordSet
            .getDouble("DEBIT");
          Double credit = recordSet
            .getDouble("CREDIT");
          if (debit != 0 || credit != 0) {
            TrialBalanceLine tbl = new TrialBalanceLine();
            tbl.setAccName(accName);
            tbl.setAccNumber(accNumber);
            tbl.setSubaccName(subaccName);
            tbl.setDebit(BigDecimal.valueOf(debit).setScale(
              getSrvAccSettings().lazyGetAccSettings(pAddParam)
                .getBalancePrecision(), getSrvAccSettings()
                  .lazyGetAccSettings(pAddParam).getRoundingMode()));
            tbl.setCredit(BigDecimal.valueOf(credit).setScale(
              getSrvAccSettings().lazyGetAccSettings(pAddParam)
                .getBalancePrecision(), getSrvAccSettings()
                  .lazyGetAccSettings(pAddParam).getRoundingMode()));
            if (tbl.getDebit().doubleValue() != 0
              || tbl.getCredit().doubleValue() != 0) {
              result.add(tbl);
            }
          }
        } while (recordSet.moveToNext());
      }
    } finally {
      if (recordSet != null) {
        recordSet.close();
      }
    }
    //account totals:
    BigDecimal debitAcc = BigDecimal.ZERO;
    BigDecimal creditAcc = BigDecimal.ZERO;
    String accCurr = null;
    int lineCurr = 0;
    int lineStartAcc = 0;
    for (TrialBalanceLine tbl : result) {
      if (!tbl.getAccNumber().equals(accCurr)) {
        //save to old
        if (accCurr != null) {
          for (int j = lineStartAcc; j < lineCurr; j++) {
            result.get(j).setDebitAcc(debitAcc);
            result.get(j).setCreditAcc(creditAcc);
          }
        }
        //init new acc:
        lineStartAcc = lineCurr;
        accCurr = tbl.getAccNumber();
      }
      debitAcc = debitAcc.add(tbl.getDebit());
      creditAcc = creditAcc.add(tbl.getCredit());
      lineCurr++;
    }
    return result;
  }
1168785
public final void addTaxWr(final List<Node<String>> pTree,
    final String pIndex, final String pName, final String pLang) {
    Node<String> nodeTaxWr = new Node<String>();
    pTree.add(nodeTaxWr);
    nodeTaxWr.setItsName(pName);
    nodeTaxWr.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeTaxWrIsUsed = new Node<String>();
    nodeTaxWr.getItsNodes().add(nodeTaxWrIsUsed);
    nodeTaxWrIsUsed.setItsName(getSrvI18n().getMsg("isUsed", pLang));
    nodeTaxWrIsUsed.setItsValue(pIndex + ";isUsed");
    Node<String> nodeTaxWrRate = new Node<String>();
    nodeTaxWr.getItsNodes().add(nodeTaxWrRate);
    nodeTaxWrRate.setItsName(getSrvI18n().getMsg("rate", pLang));
    nodeTaxWrRate.setItsValue(pIndex + ";rate");
    Node<String> nodeTaxWrTax = new Node<String>();
    nodeTaxWr.getItsNodes().add(nodeTaxWrTax);
    nodeTaxWrTax.setItsName(getSrvI18n().getMsg("tax", pLang));
    nodeTaxWrTax.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeTaxWrTaxName = new Node<String>();
    nodeTaxWrTax.getItsNodes().add(nodeTaxWrTaxName);
    nodeTaxWrTaxName.setItsName(getSrvI18n().getMsg("itsName", pLang));
    nodeTaxWrTaxName.setItsValue(pIndex + ";tax,itsName");
    Node<String> nodeTaxWrTaxId = new Node<String>();
    nodeTaxWrTax.getItsNodes().add(nodeTaxWrTaxId);
    nodeTaxWrTaxId.setItsName(getSrvI18n().getMsg("itsId", pLang));
    nodeTaxWrTaxId.setItsValue(pIndex + ";tax,itsId");
    Node<String> nodeTaxWrTaxPercentage = new Node<String>();
    nodeTaxWrTax.getItsNodes().add(nodeTaxWrTaxPercentage);
    nodeTaxWrTaxPercentage
      .setItsName(getSrvI18n().getMsg("itsPercentage", pLang));
    nodeTaxWrTaxPercentage.setItsValue(pIndex + ";tax,itsPercentage");
  }
1008071
public final void makeDocReversed(final Map<String, Object> pReqVars,
    final ADoc pReversing, final ADoc pReversed,
      final String pLangDef) throws Exception {
    pReversing.setIdDatabaseBirth(pReversed.getIdDatabaseBirth());
    pReversing.setReversedId(pReversed.getItsId());
    pReversing.setReversedIdDatabaseBirth(pReversed.getIdDatabaseBirth());
    pReversing.setItsDate(new Date(pReversed.getItsDate().getTime() + 1));
    pReversing.setItsTotal(pReversed.getItsTotal().negate());
    pReversing.setHasMadeAccEntries(false);
    getSrvOrm().insertEntity(pReqVars, pReversing);
    pReversing.setIsNew(false);
    String oldDesr = "";
    if (pReversed.getDescription() != null) {
      oldDesr = pReversed.getDescription();
    }
    pReversed.setDescription(oldDesr + " " + getSrvI18n()
      .getMsg("reversing_n", pLangDef) + pReversing.getIdDatabaseBirth() + "-"
        + pReversing.getItsId());
    pReversed.setReversedId(pReversing.getItsId());
    pReversed.setReversedIdDatabaseBirth(pReversing.getIdDatabaseBirth());
    getSrvOrm().updateEntity(pReqVars, pReversed);
    this.srvAccEntry.reverseEntries(pReqVars, pReversing, pReversed);
  }
1135921
public final void retLines(final Map<String, Object> pRqVs,
    final OnlineBuyer pBur, final List<CustOrder> pOrds,
      final List<CuOrSe> pSords) throws Exception {
    StringBuffer ordIds = null;
    for (CustOrder co : pOrds) {
      co.setGoods(new ArrayList<CustOrderGdLn>());
      co.setServs(new ArrayList<CustOrderSrvLn>());
      if (ordIds == null) {
        ordIds = new StringBuffer();
        ordIds.append(co.getItsId().toString());
      } else {
        ordIds.append("," + co.getItsId());
      }
    }
    Set<String> ndFlNm = new HashSet<String>();
    ndFlNm.add("itsId");
    ndFlNm.add("itsName");
    Set<String> ndFl = new HashSet<String>();
    ndFl.add("itsId");
    ndFl.add("itsOwner");
    ndFl.add("itsName");
    ndFl.add("uom");
    ndFl.add("quant");
    ndFl.add("price");
    ndFl.add("tot");
    ndFl.add("totTx");
    String tbn;
    if (ordIds != null) {
      tbn = CustOrderGdLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CustOrderGdLn> allGds = this.srvOrm.retrieveListWithConditions(pRqVs,
        CustOrderGdLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CustOrderGdLn il : allGds) {
        for (CustOrder co : pOrds) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getGoods().add(il);
            break;
          }
        }
      }
      tbn = CustOrderSrvLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CustOrderSrvLn> allSrs = this.srvOrm.retrieveListWithConditions(
        pRqVs, CustOrderSrvLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CustOrderSrvLn il : allSrs) {
        for (CustOrder co : pOrds) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getServs().add(il);
            break;
          }
        }
      }
    }
    ordIds = null;
    for (CuOrSe co : pSords) {
      co.setGoods(new ArrayList<CuOrSeGdLn>());
      co.setServs(new ArrayList<CuOrSeSrLn>());
      if (ordIds == null) {
        ordIds = new StringBuffer();
        ordIds.append(co.getItsId().toString());
      } else {
        ordIds.append("," + co.getItsId());
      }
    }
    if (ordIds != null) {
      tbn = CuOrSeGdLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CuOrSeGdLn> allGds = this.srvOrm.retrieveListWithConditions(pRqVs,
        CuOrSeGdLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CuOrSeGdLn il : allGds) {
        for (CuOrSe co : pSords) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getGoods().add(il);
            break;
          }
        }
      }
      tbn = CuOrSeSrLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CuOrSeSrLn> allSrs = this.srvOrm.retrieveListWithConditions(
        pRqVs, CuOrSeSrLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CuOrSeSrLn il : allSrs) {
        for (CuOrSe co : pSords) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getServs().add(il);
            break;
          }
        }
      }
    }
  }
107869
@Override
  public final T process(final Map<String, Object> pReqVars,
    final T pEntity, final IRequestData pRequestData) throws Exception {
    SeSeller ses = findSeSeller.find(pReqVars, pRequestData.getUserName());
    pEntity.setSeller(ses);
    T entOld = this.srvOrm.retrieveEntity(pReqVars, pEntity);
    if (!entOld.getSeller().getItsId().getItsId()
      .equals(pEntity.getSeller().getItsId().getItsId())) {
      throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
      "Attempt to delete smb. else's entity: user/entity/EID/SEOLDID/SEID - "
        + pRequestData.getUserName() + "/" + pEntity.getClass()
         .getSimpleName() + "/" + pEntity.getItsId() + "/" + entOld
          .getSeller().getItsId().getItsId() + "/" + pEntity.getSeller()
            .getItsId().getItsId());
    }
    this.srvOrm.deleteEntity(pReqVars, pEntity);
    return null;
  }
634088
public final void mkFreBuyr(final Map<String, Object> pRqVs,
    final IRequestData pRqDt, final OnlineBuyer pBuTmp,
      final OnlineBuyer pBuyr) throws Exception {
    long now = new Date().getTime();
    if (!pBuTmp.getIsNew()) {
      pBuTmp.setFre(true);
      pBuTmp.setRegEmail(null);
      pBuTmp.setRegisteredPassword(null);
      pBuTmp.setLsTm(0L);
      this.srvOrm.updateEntity(pRqVs, pBuTmp);
    }
    pBuyr.setLsTm(now);
    UUID buseid = UUID.randomUUID();
    pBuyr.setBuSeId(buseid.toString());
    this.srvOrm.updateEntity(pRqVs, pBuyr);
    pRqDt.setCookieValue("buSeId", pBuyr.getBuSeId());
    pRqDt.setCookieValue("cBuyerId", pBuyr.getItsId().toString());
    pRqDt.setAttribute("buyr", pBuyr);
    Cart oldCrt = this.srvOrm.retrieveEntityById(pRqVs, Cart.class, pBuTmp);
    if (oldCrt != null && oldCrt.getTot().compareTo(BigDecimal.ZERO) == 1) {
      Long obid = pBuTmp.getItsId();
      ColumnsValues cvs = new ColumnsValues();
      cvs.setIdColumnsNames(new String[] {"itsId"});
      cvs.put("itsOwner", pBuyr.getItsId());
      this.srvDb.executeUpdate("CARTLN", cvs, "ITSOWNER=" + obid);
      this.srvDb.executeUpdate("CARTTXLN", cvs, "ITSOWNER=" + obid);
      this.srvDb.executeUpdate("CARTTOT", cvs, "ITSOWNER=" + obid);
      Cart cart = this.srvCart.getShoppingCart(pRqVs, pRqDt, true, false);
      TradingSettings ts = (TradingSettings) pRqVs.get("tradSet");
      AccSettings as = (AccSettings) pRqVs.get("accSet");
      TaxDestination txRules = this.srvCart.revealTaxRules(pRqVs, cart, as);
      if (txRules != null) {
        pRqDt.setAttribute("txRules", txRules);
      }
      cart.setDeliv(oldCrt.getDeliv());
      cart.setPayMeth(oldCrt.getPayMeth());
      //redo prices and taxes:
      CartLn frCl = null;
      for (CartLn cl : cart.getItems()) {
        if (!cl.getDisab()) {
          if (cl.getForc()) {
            frCl = cl;
            this.srvCart.delLine(pRqVs, cl, txRules);
          } else {
            this.srvCart.makeCartLine(pRqVs, cl, as, ts, txRules, true, true);
            this.srvCart.makeCartTotals(pRqVs, ts, cl, as, txRules);
          }
        }
      }
      if (frCl != null) {
         this.srvCart.hndCartChan(pRqVs, cart, txRules);
      }
    }
  }
157655
@Override
  public final SeServiceSpecifics process(
    final Map<String, Object> pReqVars,
      final SeServiceSpecifics pEntity,
        final IRequestData pRequestData) throws Exception {
    SeSeller ses = this.findSeSeller.find(pReqVars, pRequestData.getUserName());
    pEntity.setSeller(ses);
    SeServiceSpecifics entOld = this.srvOrm.retrieveEntity(pReqVars, pEntity);
    if (!entOld.getSeller().getItsId().getItsId()
      .equals(pEntity.getSeller().getItsId().getItsId())) {
      throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
      "Attempt to update smb. else's entity: user/entity/EID/SEOLDID/SEID - "
        + pRequestData.getUserName() + "/" + pEntity.getClass()
         .getSimpleName() + "/" + pEntity.getItsId() + "/" + entOld
          .getSeller().getItsId().getItsId() + "/" + pEntity.getSeller()
            .getItsId().getItsId());
    }
    String fileToUploadName = (String) pRequestData
      .getAttribute("fileToUploadName");
    OutputStream outs = null;
    InputStream ins = null;
    try {
      String filePath;
      if (pEntity.getStringValue1() == null) { //in base language:
        String ft = String.valueOf(new Date().getTime());
        filePath = this.webAppPath + File.separator
          + this.uploadDirectory + File.separator
            + ft + fileToUploadName;
        pEntity.setStringValue2(filePath);
        pEntity.setStringValue1(this.uploadDirectory
              + "/" + ft + fileToUploadName);
      } else { //I18N files:
        String fileLang = pRequestData.getParameter("fileLang");
        if (pEntity.getStringValue3() == null
          || !pEntity.getStringValue3().contains(fileLang)) {
          throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
            "notset_language");
        }
        int idhHtml = pEntity.getStringValue1().indexOf(".html");
        String urlWithoutHtml = pEntity.getStringValue1().substring(0, idhHtml);
        filePath = this.webAppPath + File.separator
          + urlWithoutHtml + "_" + fileLang + ".html";
      }
      ins = (InputStream) pRequestData.getAttribute("fileToUploadInputStream");
      outs = new BufferedOutputStream(new FileOutputStream(filePath));
      byte[] data = new byte[1024];
      int count;
      while ((count = ins.read(data)) != -1) {
        outs.write(data, 0, count);
      }
      outs.flush();
    } finally {
      if (ins != null) {
        ins.close();
      }
      if (outs != null) {
        outs.close();
      }
    }
    getSrvOrm().updateEntity(pReqVars, pEntity);
    return pEntity;
  }
490766
@Override
  public final void makeOtherEntries(final Map<String, Object> pAddParam,
    final PaymentFrom pEntity, final IRequestData pRequestData,
      final boolean pIsNew) throws Exception {
    String actionAdd = pRequestData.getParameter("actionAdd");
    if ("makeAccEntries".equals(actionAdd)) {
      this.prcSalesInvoiceSave.calculateTotalPayment(pAddParam, pEntity
        .getSalesInvoice());
      getSrvOrm().updateEntity(pAddParam, pEntity.getSalesInvoice());
    }
  }
888954
public final void makeAccentryMatchingReversed(
    final Map<String, Object> pReqVars, final String pEntryId,
      final BankStatementLine pBsl, final DateFormat pDateFormat,
        final String pLangDef) throws Exception {
    EBankEntryResultType resultRecordType = EBankEntryResultType.ACC_ENTRY;
    EBankEntryResultAction resultAction = null;
    String resultDescription = null;
    Long resultRecordId = null;
    AccountingEntry accent = getSrvOrm().retrieveEntityById(pReqVars,
      AccountingEntry.class, Long.parseLong(pEntryId));
    if (accent == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "cant_found_accentry");
    }
    if (accent.getSourceType() == 1010) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "AlreadyDone");
    }
    if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) > 0 && pBsl
      .getItsAmount().compareTo(accent.getDebit()) != 0
        && accent.getSubaccDebitType() != 2002 && !pBsl.getItsOwner()
          .getBankAccount().getItsId().equals(accent.getSubaccDebitId())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "record_is_not_matching");
    } else if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) < 0 && pBsl
      .getItsAmount().abs().compareTo(accent.getCredit()) != 0
        && accent.getSubaccCreditType() != 2002 && !pBsl.getItsOwner()
          .getBankAccount().getItsId().equals(accent.getSubaccCreditId())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "record_is_not_matching");
    }
    if (EBankEntryStatus.VOIDED.equals(pBsl.getItsStatus())) {
      if (accent.getIdDatabaseBirth() != getSrvOrm().getIdDatabase()) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "can_not_change_foreign_src");
      }
      resultAction = EBankEntryResultAction.CREATE;
      AccountingEntry reversed = accent;
      accent = new AccountingEntry();
      accent.setSourceType(pBsl.constTypeCode());
      accent.setSourceId(pBsl.getItsId());
      accent.setSourceDatabaseBirth(pBsl.getIdDatabaseBirth());
      accent.setIdDatabaseBirth(reversed.getIdDatabaseBirth());
      accent.setReversedId(reversed.getItsId());
      accent.setReversedIdDatabaseBirth(reversed.getIdDatabaseBirth());
      accent.setItsDate(new Date(reversed.getItsDate().getTime() + 1));
      accent.setAccDebit(reversed.getAccDebit());
      accent.setSubaccDebit(reversed.getSubaccDebit());
      accent.setSubaccDebitId(reversed.getSubaccDebitId());
      accent.setSubaccDebitType(reversed.getSubaccDebitType());
      accent.setDebit(reversed.getDebit().negate());
      accent.setAccCredit(reversed.getAccCredit());
      accent.setSubaccCredit(reversed.getSubaccCredit());
      accent.setSubaccCreditId(reversed.getSubaccCreditId());
      accent.setSubaccCreditType(reversed.getSubaccCreditType());
      accent.setCredit(reversed.getCredit().negate());
      accent.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef)
        + " " + getSrvI18n().getMsg("reversed_n", pLangDef)
          + accent.getReversedIdDatabaseBirth() + "-" + accent.getReversedId());
      getSrvOrm().insertEntity(pReqVars, accent);
      accent.setIsNew(false);
      String oldDesr = "";
      if (reversed.getDescription() != null) {
        oldDesr = reversed.getDescription();
      }
      reversed.setDescription(oldDesr + " " + getSrvI18n()
        .getMsg("reversing_n", pLangDef) + accent.getIdDatabaseBirth() + "-"
          + accent.getItsId());
      reversed.setReversedId(accent.getItsId());
      reversed.setReversedIdDatabaseBirth(accent.getIdDatabaseBirth());
      getSrvOrm().updateEntity(pReqVars, reversed);
    } else {
      resultAction = EBankEntryResultAction.MATCH;
    }
    resultRecordId = accent.getItsId();
    resultDescription = makeBslResDescr(resultAction, pDateFormat, accent,
      accent.getItsDate(), pLangDef);
    pBsl.setResultAction(resultAction);
    pBsl.setResultRecordType(resultRecordType);
    pBsl.setResultRecordId(resultRecordId);
    pBsl.setResultDescription(resultDescription);
    getSrvOrm().updateEntity(pReqVars, pBsl);
  }
3605
@Override
  public final void addCheckIsReadyToAccount(
    final Map<String, Object> pReqVars,
      final PurchaseInvoice pEntity,
        final IRequestData pRequestData) throws Exception {
    // nothing
  }
785039
@Override
  public final void process(final Map<String, Object> pRqVs,
    final IRequestData pRqDt) throws Exception {
    OnlineBuyer buyer = this.buySr.getBuyr(pRqVs, pRqDt);
    if (buyer == null) {
      buyer = this.buySr.createBuyr(pRqVs, pRqDt);
    }
    String nm = pRqDt.getParameter("nm");
    String em = pRqDt.getParameter("em");
    String pw = pRqDt.getParameter("pw");
    String pwc = pRqDt.getParameter("pwc");
    long now = new Date().getTime();
    String tbn = OnlineBuyer.class.getSimpleName();
    pRqDt.setAttribute("buyr", buyer);
    if (buyer.getRegEmail() == null) { //unregistered:
      if (nm != null && pw != null && pwc != null && em != null) {
        //creating:
        if (nm.length() > 2 && pw.length() > 7 && pw.equals(pwc)
          && em.length() > 5) {
          Set<String> ndFl = new HashSet<String>();
          ndFl.add("itsId");
          pRqVs.put(tbn + "neededFields", ndFl);
          List<OnlineBuyer> brs = getSrvOrm().retrieveListWithConditions(pRqVs,
            OnlineBuyer.class, "where REGEMAIL='" + em + "'");
          pRqVs.remove(tbn + "neededFields");
          if (brs.size() == 0) {
            buyer.setItsName(nm);
            buyer.setRegisteredPassword(pw);
            buyer.setRegEmail(em);
            buyer.setLsTm(now);
            UUID buseid = UUID.randomUUID();
            buyer.setBuSeId(buseid.toString());
            if (buyer.getIsNew()) {
              this.srvOrm.insertEntity(pRqVs, buyer);
            } else {
              this.srvOrm.updateEntity(pRqVs, buyer);
            }
            pRqDt.setCookieValue("cBuyerId", buyer.getItsId().toString());
            pRqDt.setCookieValue("buSeId", buyer.getBuSeId());
          } else if (brs.size() == 1) {
            pRqDt.setAttribute("errMsg", "emBusy");
          } else {
            getLog().error(pRqVs, PrLog.class,
              "Several users with same email!: " + em);
          }
        } else {
          pRqDt.setAttribute("errMsg", "buyCrRul");
        }
      } else if (pw != null && em != null) {
        //login from new browser
        pRqVs.put(tbn + "regCustomerdeepLevel", 1);
        pRqVs.put(tbn + "taxDestplacedeepLevel", 1);
        List<OnlineBuyer> brs = getSrvOrm().retrieveListWithConditions(
          pRqVs, OnlineBuyer.class, "where REGISTEREDPASSWORD='" + pw
            + "' and REGEMAIL='" + em + "'");
        pRqVs.remove(tbn + "regCustomerdeepLevel");
        pRqVs.remove(tbn + "taxDestplacedeepLevel");
        if (brs.size() == 1) {
          //free buyer and moving its cart by fast updates:
          mkFreBuyr(pRqVs,  pRqDt, buyer, brs.get(0));
        } else if (brs.size() == 0) {
          pRqDt.setAttribute("errMsg", "wrong_em_password");
        } else {
          getLog().error(pRqVs, PrLog.class,
            "Several users with same password and email!: " + em);
        }
      } else {
        spam(pRqVs, pRqDt);
      }
    } else { //registered:
      if (now - buyer.getLsTm() < 1800000L && buyer.getBuSeId() != null) {
        //there is opened session:
        String buSeId = pRqDt.getCookieValue("buSeId");
        if (buyer.getBuSeId().equals(buSeId)) {
          //authorized requests:
          String zip = pRqDt.getParameter("zip");
          String adr1 = pRqDt.getParameter("adr1");
          if (nm != null && zip != null  && adr1 != null) {
            //change name, shipping address:
            String cnt = pRqDt.getParameter("cnt");
            String cit = pRqDt.getParameter("cit");
            String adr2 = pRqDt.getParameter("adr2");
            String phn = pRqDt.getParameter("phn");
            if (nm.length() > 2 && zip.length() > 2 && adr1.length() > 2) {
              buyer.setItsName(nm);
              buyer.setRegZip(zip);
              buyer.setRegAddress1(adr1);
              buyer.setRegAddress2(adr2);
              buyer.setRegCountry(cnt);
              buyer.setRegCity(cit);
              buyer.setRegPhone(phn);
              buyer.setLsTm(now);
              this.srvOrm.updateEntity(pRqVs, buyer);
            } else {
              pRqDt.setAttribute("errMsg", "buyEmRul");
            }
          } else if (pw != null && pwc != null) {
            //change password:
            if (pw.length() > 7 && pw.equals(pwc)) {
              buyer.setRegisteredPassword(pw);
              buyer.setLsTm(now);
              this.srvOrm.updateEntity(pRqVs, buyer);
            } else {
              pRqDt.setAttribute("errMsg", "buyPwdRul");
            }
          } else {
            //logout action:
            buyer.setLsTm(0L);
            this.srvOrm.updateEntity(pRqVs, buyer);
          }
        } else { //either spam or buyer login from other browser without logout
          spam(pRqVs, pRqDt);
        }
      } else {
        //unauthorized requests:
        if (pw != null) {
          //login action:
          if (pw.equals(buyer.getRegisteredPassword())) {
            buyer.setLsTm(now);
            UUID buseid = UUID.randomUUID();
            buyer.setBuSeId(buseid.toString());
            pRqDt.setCookieValue("buSeId", buyer.getBuSeId());
            this.srvOrm.updateEntity(pRqVs, buyer);
          } else {
            pRqDt.setAttribute("errMsg", "wrong_password");
          }
        } else {
          spam(pRqVs, pRqDt);
        }
      }
    }
    String procNm = pRqDt.getParameter("nmPrcRed");
    IProcessor proc = this.procFac.lazyGet(pRqVs, procNm);
    proc.process(pRqVs, pRqDt);
  }