@Override
  public final BeginningInventoryLine process(
    final Map<String, Object> pAddParam,
      final BeginningInventoryLine pEntity,
        final IRequestData pRequestData) throws Exception {
    if (pEntity.getIsNew()) {
      if (pEntity.getItsQuantity().doubleValue() <= 0
        && pEntity.getReversedId() == null) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "quantity_less_or_equal_zero::" + pAddParam.get("user"));
      }
      if (pEntity.getItsCost().doubleValue() <= 0) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "cost_less_or_eq_zero::" + pAddParam.get("user"));
      }
      // Beige-Orm refresh:
      pEntity.setInvItem(getSrvOrm()
        .retrieveEntity(pAddParam, pEntity.getInvItem()));
      pEntity.setItsOwner(getSrvOrm()
        .retrieveEntity(pAddParam, pEntity.getItsOwner()));
      // optimistic locking (dirty check):
      Long ownerVersion = Long.valueOf(pRequestData
        .getParameter(BeginningInventory.class.getSimpleName()
          + ".ownerVersion"));
      pEntity.getItsOwner().setItsVersion(ownerVersion);
      //rounding:
      pEntity.setItsQuantity(pEntity.getItsQuantity().setScale(
        getSrvAccSettings().lazyGetAccSettings(pAddParam)
          .getQuantityPrecision(), getSrvAccSettings()
            .lazyGetAccSettings(pAddParam).getRoundingMode()));
      pEntity.setItsCost(pEntity.getItsCost().setScale(getSrvAccSettings()
        .lazyGetAccSettings(pAddParam).getCostPrecision(), getSrvAccSettings()
          .lazyGetAccSettings(pAddParam).getRoundingMode()));
      pEntity.setTheRest(pEntity.getItsQuantity());
      pEntity.setItsTotal(pEntity.getItsQuantity().multiply(pEntity
        .getItsCost()).setScale(getSrvAccSettings()
          .lazyGetAccSettings(pAddParam).getCostPrecision(), getSrvAccSettings()
            .lazyGetAccSettings(pAddParam).getRoundingMode()));
      if (pEntity.getReversedId() != null) {
        pEntity.setTheRest(BigDecimal.ZERO);
      }
      getSrvOrm().insertEntity(pAddParam, pEntity);
      pEntity.setIsNew(false);
      if (pEntity.getReversedId() != null) {
        BeginningInventoryLine reversed = getSrvOrm().retrieveEntityById(
          pAddParam, BeginningInventoryLine.class, pEntity.getReversedId());
        if (reversed.getReversedId() != null) {
          throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
            "attempt_to_reverse_reversed");
        }
        if (!reversed.getItsQuantity().equals(reversed.getTheRest())) {
          throw new ExceptionWithCode(ExceptionWithCode
            .WRONG_PARAMETER, "where_is_withdrawals_from_this_source");
        }
        reversed.setTheRest(BigDecimal.ZERO);
        reversed.setReversedId(pEntity.getItsId());
        getSrvOrm().updateEntity(pAddParam, reversed);
      }
      srvWarehouseEntry.load(pAddParam, pEntity, pEntity.getWarehouseSite());
      String query =
        "select sum(ITSTOTAL) as ITSTOTAL from"
          + " BEGINNINGINVENTORYLINE where ITSOWNER="
            + pEntity.getItsOwner().getItsId();
      Double total = getSrvDatabase().evalDoubleResult(query, "ITSTOTAL");
      BigDecimal totalBdcm = BigDecimal.valueOf(total);
      pEntity.getItsOwner().setItsTotal(totalBdcm.setScale(
        getSrvAccSettings().lazyGetAccSettings(pAddParam).getCostPrecision(),
          getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode()));
      getSrvOrm().updateEntity(pAddParam, pEntity.getItsOwner());
      pAddParam.put("nextEntity", pEntity.getItsOwner());
      pAddParam.put("nameOwnerEntity",
        BeginningInventory.class.getSimpleName());
      return null;
    } else {
      throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
        "edit_not_allowed::" + pAddParam.get("user"));
    }
  }
@ Override public final BeginningInventoryLine process ( final Map < String , Object > pAddParam , final BeginningInventoryLine pEntity , final IRequestData pRequestData ) throws Exception { if ( pEntity . getIsNew ( ) ) { if ( pEntity . getItsQuantity ( ) . doubleValue ( ) <= 0 && pEntity . getReversedId ( ) == null ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "quantity_less_or_equal_zero::" + pAddParam . get ( "user" ) ) ; } if ( pEntity . getItsCost ( ) . doubleValue ( ) <= 0 ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "cost_less_or_eq_zero::" + pAddParam . get ( "user" ) ) ; } pEntity . setInvItem ( getSrvOrm ( ) . retrieveEntity ( pAddParam , pEntity . getInvItem ( ) ) ) ; pEntity . setItsOwner ( getSrvOrm ( ) . retrieveEntity ( pAddParam , pEntity . getItsOwner ( ) ) ) ; Long ownerVersion = Long . valueOf ( pRequestData . getParameter ( BeginningInventory . class . getSimpleName ( ) + ".ownerVersion" ) ) ; pEntity . getItsOwner ( ) . setItsVersion ( ownerVersion ) ; pEntity . setItsQuantity ( pEntity . getItsQuantity ( ) . setScale ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getQuantityPrecision ( ) , getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getRoundingMode ( ) ) ) ; pEntity . setItsCost ( pEntity . getItsCost ( ) . setScale ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getCostPrecision ( ) , getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getRoundingMode ( ) ) ) ; pEntity . setTheRest ( pEntity . getItsQuantity ( ) ) ; pEntity . setItsTotal ( pEntity . getItsQuantity ( ) . multiply ( pEntity . getItsCost ( ) ) . setScale ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getCostPrecision ( ) , getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getRoundingMode ( ) ) ) ; if ( pEntity . getReversedId ( ) != null ) { pEntity . setTheRest ( BigDecimal . ZERO ) ; } getSrvOrm ( ) . insertEntity ( pAddParam , pEntity ) ; pEntity . setIsNew ( false ) ; if ( pEntity . getReversedId ( ) != null ) { BeginningInventoryLine reversed = getSrvOrm ( ) . retrieveEntityById ( pAddParam , BeginningInventoryLine . class , pEntity . getReversedId ( ) ) ; if ( reversed . getReversedId ( ) != null ) { throw new ExceptionWithCode ( ExceptionWithCode . FORBIDDEN , "attempt_to_reverse_reversed" ) ; } if ( ! reversed . getItsQuantity ( ) . equals ( reversed . getTheRest ( ) ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "where_is_withdrawals_from_this_source" ) ; } reversed . setTheRest ( BigDecimal . ZERO ) ; reversed . setReversedId ( pEntity . getItsId ( ) ) ; getSrvOrm ( ) . updateEntity ( pAddParam , reversed ) ; } srvWarehouseEntry . load ( pAddParam , pEntity , pEntity . getWarehouseSite ( ) ) ; String query = "select sum(ITSTOTAL) as ITSTOTAL from" + " BEGINNINGINVENTORYLINE where ITSOWNER=" + pEntity . getItsOwner ( ) . getItsId ( ) ; Double total = getSrvDatabase ( ) . evalDoubleResult ( query , "ITSTOTAL" ) ; BigDecimal totalBdcm = BigDecimal . valueOf ( total ) ; pEntity . getItsOwner ( ) . setItsTotal ( totalBdcm . setScale ( getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getCostPrecision ( ) , getSrvAccSettings ( ) . lazyGetAccSettings ( pAddParam ) . getRoundingMode ( ) ) ) ; getSrvOrm ( ) . updateEntity ( pAddParam , pEntity . getItsOwner ( ) ) ; pAddParam . put ( "nextEntity" , pEntity . getItsOwner ( ) ) ; pAddParam . put ( "nameOwnerEntity" , BeginningInventory . class . getSimpleName ( ) ) ; return null ; } else { throw new ExceptionWithCode ( ExceptionWithCode . FORBIDDEN , "edit_not_allowed::" + pAddParam . get ( "user" ) ) ; } }
<p>Process entity request.</p>
@param pAddParam additional param, e.g. return this line's
document in "nextEntity" for farther process
@param pRequestData Request Data
@param pEntity Entity to process
@return Entity processed for farther process or null
@throws Exception - an exception