@Override
  public final void makeFirstPrepareForSave(final Map<String, Object> pReqVars,
    final PurchaseInvoice pEntity,
      final IRequestData pRequestData) throws Exception {
    if (pEntity.getPrepaymentTo() != null) {
      pEntity.setPrepaymentTo(getSrvOrm()
        .retrieveEntity(pReqVars, pEntity.getPrepaymentTo()));
      if (pEntity.getReversedId() == null && pEntity.getPrepaymentTo()
        .getPurchaseInvoiceId() != null && !pEntity.getHasMadeAccEntries()) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "prepayment_already_in_use");
      }
      if (pEntity.getReversedId() == null && !pEntity.getPrepaymentTo()
        .getVendor().getItsId().equals(pEntity.getVendor().getItsId())) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "prepayment_for_different_vendor");
      }
    }
    if (pEntity.getReversedId() != null && pEntity.getPrepaymentTo() != null
      && pEntity.getPaymentTotal().compareTo(pEntity.getPrepaymentTo()
        .getItsTotal()) != 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "reverse_payments_first");
    }
    if (pEntity.getReversedId() != null && pEntity.getPrepaymentTo() == null
      && pEntity.getPaymentTotal().compareTo(BigDecimal.ZERO) != 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "reverse_payments_first");
    }
    if (pEntity.getReversedId() == null) {
      calculateTotalPayment(pReqVars, pEntity);
    }
    if (!pEntity.getIsNew()) {
      pReqVars.put("DebtorCreditortaxDestinationdeepLevel", 2);
      Set<String> ndFlDc = new HashSet<String>();
      ndFlDc.add("itsId");
      ndFlDc.add("isForeigner");
      ndFlDc.add("taxDestination");
      pReqVars.put("DebtorCreditorneededFields", ndFlDc);
    }
  }
@ Override public final void makeFirstPrepareForSave ( final Map < String , Object > pReqVars , final PurchaseInvoice pEntity , final IRequestData pRequestData ) throws Exception { if ( pEntity . getPrepaymentTo ( ) != null ) { pEntity . setPrepaymentTo ( getSrvOrm ( ) . retrieveEntity ( pReqVars , pEntity . getPrepaymentTo ( ) ) ) ; if ( pEntity . getReversedId ( ) == null && pEntity . getPrepaymentTo ( ) . getPurchaseInvoiceId ( ) != null && ! pEntity . getHasMadeAccEntries ( ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "prepayment_already_in_use" ) ; } if ( pEntity . getReversedId ( ) == null && ! pEntity . getPrepaymentTo ( ) . getVendor ( ) . getItsId ( ) . equals ( pEntity . getVendor ( ) . getItsId ( ) ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "prepayment_for_different_vendor" ) ; } } if ( pEntity . getReversedId ( ) != null && pEntity . getPrepaymentTo ( ) != null && pEntity . getPaymentTotal ( ) . compareTo ( pEntity . getPrepaymentTo ( ) . getItsTotal ( ) ) != 0 ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "reverse_payments_first" ) ; } if ( pEntity . getReversedId ( ) != null && pEntity . getPrepaymentTo ( ) == null && pEntity . getPaymentTotal ( ) . compareTo ( BigDecimal . ZERO ) != 0 ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "reverse_payments_first" ) ; } if ( pEntity . getReversedId ( ) == null ) { calculateTotalPayment ( pReqVars , pEntity ) ; } if ( ! pEntity . getIsNew ( ) ) { pReqVars . put ( "DebtorCreditortaxDestinationdeepLevel" , 2 ) ; Set < String > ndFlDc = new HashSet < String > ( ) ; ndFlDc . add ( "itsId" ) ; ndFlDc . add ( "isForeigner" ) ; ndFlDc . add ( "taxDestination" ) ; pReqVars . put ( "DebtorCreditorneededFields" , ndFlDc ) ; } }
<p>Make save preparations before insert/update block if it's need.</p>
@param pReqVars additional param
@param pEntity entity
@param pRequestData Request Data
@throws Exception - an exception