public final void createPayment(final Map<String, Object> pReqVars,
    final BankStatementLine pBsl, final DateFormat pDateFormat,
      final String pLangDef, final IRequestData pRequestData) throws Exception {
    BigDecimal foreignTotal;
    Account accCash;
    Date itsDate;
    try {
      String forTotStr = pRequestData.getParameter("foreignTotal");
      if (forTotStr == null || "".equals(forTotStr)) {
        foreignTotal = BigDecimal.ZERO;
      } else {
        String dsep = (String) pReqVars.get("decSepv");
        if (dsep != null) {
          String dgsep = (String) pReqVars.get("decGrSepv");
          forTotStr = forTotStr.replace(dgsep, "").replace(dsep, ".");
        }
        foreignTotal = new BigDecimal(forTotStr);
      }
      String accCashStr = pRequestData.getParameter("accCash");
      accCash = new Account();
      accCash.setItsId(accCashStr);
      accCash = getSrvOrm().retrieveEntity(pReqVars, accCash);
      if (accCash == null) {
        throw new Exception("cant_find_account");
      }
      String itsDateStr = pRequestData.getParameter("itsDate");
      itsDate = this.dateTimeNoTzFormatIso8601.parse(itsDateStr);
    } catch (Exception e) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "wrong_paramaters", e);
    }
    EBankEntryResultType resultRecordType = null;
    EBankEntryResultAction resultAction = EBankEntryResultAction.CREATE;
    String resultDescription = null;
    Long resultRecordId = null;
    if (pBsl.getItsAmount().compareTo(BigDecimal.ZERO) > 0) {
      SalesInvoice inv;
      try {
        String invStr = pRequestData.getParameter("invoice");
        inv = new SalesInvoice();
        inv.setItsId(Long.parseLong(invStr));
        inv = getSrvOrm().retrieveEntity(pReqVars, inv);
        if (inv == null) {
          throw new Exception("cant_find_debtor_invoice");
        }
      } catch (Exception e) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "wrong_paramaters", e);
      }
      resultRecordType = EBankEntryResultType.PREPAYMENTFROM;
      PaymentFrom pay = new PaymentFrom();
      pay.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
      pay.setItsDate(itsDate);
      pay.setSalesInvoice(inv);
      pay.setAccCash(accCash);
      pay.setSubaccCash(pBsl.getItsOwner().getBankAccount().getItsName());
      pay.setSubaccCashId(pBsl.getItsOwner().getBankAccount().getItsId());
      pay.setSubaccCashType(2002);
      pay.setItsTotal(pBsl.getItsAmount().abs());
      pay.setForeignTotal(foreignTotal);
      pay.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef));
      getSrvOrm().insertEntity(pReqVars, pay);
      this.srvAccEntry.makeEntries(pReqVars, pay);
      this.prcSalesInvoiceSave.calculateTotalPayment(pReqVars, pay
        .getSalesInvoice());
      getSrvOrm().updateEntity(pReqVars, pay.getSalesInvoice());
      resultRecordId = pay.getItsId();
      resultDescription = makeBslResDescr(resultAction, pDateFormat, pay,
        pay.getItsDate(), pLangDef);
    } else {
      PurchaseInvoice inv;
      try {
        String invStr = pRequestData.getParameter("invoice");
        inv = new PurchaseInvoice();
        inv.setItsId(Long.parseLong(invStr));
        inv = getSrvOrm().retrieveEntity(pReqVars, inv);
        if (inv == null) {
          throw new Exception("cant_find_debtor_invoice");
        }
      } catch (Exception e) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "wrong_paramaters", e);
      }
      resultRecordType = EBankEntryResultType.PREPAYMENTTO;
      PaymentTo pay = new PaymentTo();
      pay.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
      pay.setItsDate(itsDate);
      pay.setPurchaseInvoice(inv);
      pay.setAccCash(accCash);
      pay.setSubaccCash(pBsl.getItsOwner().getBankAccount().getItsName());
      pay.setSubaccCashId(pBsl.getItsOwner().getBankAccount().getItsId());
      pay.setSubaccCashType(2002);
      pay.setItsTotal(pBsl.getItsAmount().abs());
      pay.setForeignTotal(foreignTotal);
      pay.setDescription(makeDescrForCreated(pBsl, pDateFormat, pLangDef));
      getSrvOrm().insertEntity(pReqVars, pay);
      this.srvAccEntry.makeEntries(pReqVars, pay);
      this.prcPurchaseInvoiceSave.calculateTotalPayment(pReqVars,
        pay.getPurchaseInvoice());
      getSrvOrm().updateEntity(pReqVars, pay.getPurchaseInvoice());
      resultRecordId = pay.getItsId();
      resultDescription = makeBslResDescr(resultAction, pDateFormat, pay,
        pay.getItsDate(), pLangDef);
    }
    pBsl.setResultAction(resultAction);
    pBsl.setResultRecordType(resultRecordType);
    pBsl.setResultRecordId(resultRecordId);
    pBsl.setResultDescription(resultDescription);
    getSrvOrm().updateEntity(pReqVars, pBsl);
  }
public final void createPayment ( final Map < String , Object > pReqVars , final BankStatementLine pBsl , final DateFormat pDateFormat , final String pLangDef , final IRequestData pRequestData ) throws Exception { BigDecimal foreignTotal ; Account accCash ; Date itsDate ; try { String forTotStr = pRequestData . getParameter ( "foreignTotal" ) ; if ( forTotStr == null || "" . equals ( forTotStr ) ) { foreignTotal = BigDecimal . ZERO ; } else { String dsep = ( String ) pReqVars . get ( "decSepv" ) ; if ( dsep != null ) { String dgsep = ( String ) pReqVars . get ( "decGrSepv" ) ; forTotStr = forTotStr . replace ( dgsep , "" ) . replace ( dsep , "." ) ; } foreignTotal = new BigDecimal ( forTotStr ) ; } String accCashStr = pRequestData . getParameter ( "accCash" ) ; accCash = new Account ( ) ; accCash . setItsId ( accCashStr ) ; accCash = getSrvOrm ( ) . retrieveEntity ( pReqVars , accCash ) ; if ( accCash == null ) { throw new Exception ( "cant_find_account" ) ; } String itsDateStr = pRequestData . getParameter ( "itsDate" ) ; itsDate = this . dateTimeNoTzFormatIso8601 . parse ( itsDateStr ) ; } catch ( Exception e ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "wrong_paramaters" , e ) ; } EBankEntryResultType resultRecordType = null ; EBankEntryResultAction resultAction = EBankEntryResultAction . CREATE ; String resultDescription = null ; Long resultRecordId = null ; if ( pBsl . getItsAmount ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) { SalesInvoice inv ; try { String invStr = pRequestData . getParameter ( "invoice" ) ; inv = new SalesInvoice ( ) ; inv . setItsId ( Long . parseLong ( invStr ) ) ; inv = getSrvOrm ( ) . retrieveEntity ( pReqVars , inv ) ; if ( inv == null ) { throw new Exception ( "cant_find_debtor_invoice" ) ; } } catch ( Exception e ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "wrong_paramaters" , e ) ; } resultRecordType = EBankEntryResultType . PREPAYMENTFROM ; PaymentFrom pay = new PaymentFrom ( ) ; pay . setIdDatabaseBirth ( getSrvOrm ( ) . getIdDatabase ( ) ) ; pay . setItsDate ( itsDate ) ; pay . setSalesInvoice ( inv ) ; pay . setAccCash ( accCash ) ; pay . setSubaccCash ( pBsl . getItsOwner ( ) . getBankAccount ( ) . getItsName ( ) ) ; pay . setSubaccCashId ( pBsl . getItsOwner ( ) . getBankAccount ( ) . getItsId ( ) ) ; pay . setSubaccCashType ( 2002 ) ; pay . setItsTotal ( pBsl . getItsAmount ( ) . abs ( ) ) ; pay . setForeignTotal ( foreignTotal ) ; pay . setDescription ( makeDescrForCreated ( pBsl , pDateFormat , pLangDef ) ) ; getSrvOrm ( ) . insertEntity ( pReqVars , pay ) ; this . srvAccEntry . makeEntries ( pReqVars , pay ) ; this . prcSalesInvoiceSave . calculateTotalPayment ( pReqVars , pay . getSalesInvoice ( ) ) ; getSrvOrm ( ) . updateEntity ( pReqVars , pay . getSalesInvoice ( ) ) ; resultRecordId = pay . getItsId ( ) ; resultDescription = makeBslResDescr ( resultAction , pDateFormat , pay , pay . getItsDate ( ) , pLangDef ) ; } else { PurchaseInvoice inv ; try { String invStr = pRequestData . getParameter ( "invoice" ) ; inv = new PurchaseInvoice ( ) ; inv . setItsId ( Long . parseLong ( invStr ) ) ; inv = getSrvOrm ( ) . retrieveEntity ( pReqVars , inv ) ; if ( inv == null ) { throw new Exception ( "cant_find_debtor_invoice" ) ; } } catch ( Exception e ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "wrong_paramaters" , e ) ; } resultRecordType = EBankEntryResultType . PREPAYMENTTO ; PaymentTo pay = new PaymentTo ( ) ; pay . setIdDatabaseBirth ( getSrvOrm ( ) . getIdDatabase ( ) ) ; pay . setItsDate ( itsDate ) ; pay . setPurchaseInvoice ( inv ) ; pay . setAccCash ( accCash ) ; pay . setSubaccCash ( pBsl . getItsOwner ( ) . getBankAccount ( ) . getItsName ( ) ) ; pay . setSubaccCashId ( pBsl . getItsOwner ( ) . getBankAccount ( ) . getItsId ( ) ) ; pay . setSubaccCashType ( 2002 ) ; pay . setItsTotal ( pBsl . getItsAmount ( ) . abs ( ) ) ; pay . setForeignTotal ( foreignTotal ) ; pay . setDescription ( makeDescrForCreated ( pBsl , pDateFormat , pLangDef ) ) ; getSrvOrm ( ) . insertEntity ( pReqVars , pay ) ; this . srvAccEntry . makeEntries ( pReqVars , pay ) ; this . prcPurchaseInvoiceSave . calculateTotalPayment ( pReqVars , pay . getPurchaseInvoice ( ) ) ; getSrvOrm ( ) . updateEntity ( pReqVars , pay . getPurchaseInvoice ( ) ) ; resultRecordId = pay . getItsId ( ) ; resultDescription = makeBslResDescr ( resultAction , pDateFormat , pay , pay . getItsDate ( ) , pLangDef ) ; } pBsl . setResultAction ( resultAction ) ; pBsl . setResultRecordType ( resultRecordType ) ; pBsl . setResultRecordId ( resultRecordId ) ; pBsl . setResultDescription ( resultDescription ) ; getSrvOrm ( ) . updateEntity ( pReqVars , pBsl ) ; }
<p>Creates payment.</p>
@param pReqVars additional param
@param pBsl BSL
@param pDateFormat Date Formatter
@param pLangDef language
@param pRequestData Request Data
@throws Exception - an exception