/**
  * Perform Match
  *
  * @param bs bank statement
  * @return Message
  */
 private String match(MBankStatement bs) {
   if (m_matchers == null || bs == null) return "--";
   log.fine("match - " + bs);
   int count = 0;
   MBankStatementLine[] lines = bs.getLines(false);
   for (MBankStatementLine element : lines) {
     if (element.getC_Payment_ID() == 0) {
       match(element);
       count++;
     }
   }
   return String.valueOf(count);
 } //	match
  /**
   * Perform Match
   *
   * @param bsl bank statement line
   * @return Message
   */
  private String match(MBankStatementLine bsl) {
    if (m_matchers == null || bsl == null || bsl.getC_Payment_ID() != 0) return "--";

    log.fine("match - " + bsl);
    BankStatementMatchInfo info = null;
    for (MBankStatementMatcher element : m_matchers) {
      if (element.isMatcherValid()) {
        info = element.getMatcher().findMatch(bsl);
        if (info != null && info.isMatched()) {
          if (info.getC_Payment_ID() > 0) bsl.setC_Payment_ID(info.getC_Payment_ID());
          if (info.getC_Invoice_ID() > 0) bsl.setC_Invoice_ID(info.getC_Invoice_ID());
          if (info.getC_BPartner_ID() > 0) bsl.setC_BPartner_ID(info.getC_BPartner_ID());
          bsl.save();
          return "OK";
        }
      }
    } //	for all matchers
    return "--";
  } //	match
  /**
   * Load Invoice Line.
   *
   * @param bs bank statement 4 amounts AMTTYPE_Payment AMTTYPE_Statement2 AMTTYPE_Charge
   *     AMTTYPE_Interest
   * @return DocLine Array
   */
  private DocLine[] loadLines(final MBankStatement bs) {
    ArrayList<DocLine> list = new ArrayList<DocLine>();
    MBankStatementLine[] lines = bs.getLines(false);
    for (int i = 0; i < lines.length; i++) {
      MBankStatementLine line = lines[i];
      DocLine_BankStatement docLine = new DocLine_BankStatement(line, this);
      // Set Date Acct
      if (i == 0) setDateAcct(line.getDateAcct());
      MPeriod period = MPeriod.get(getCtx(), line.getDateAcct(), line.getAD_Org_ID());
      if (period != null
          && period.isOpen(DOCTYPE_BankStatement, line.getDateAcct(), bs.getAD_Org_ID())) {
        docLine.setC_Period_ID(period.getC_Period_ID());
      }
      //
      list.add(docLine);
    }

    // Return Array
    DocLine[] dls = new DocLine[list.size()];
    list.toArray(dls);
    return dls;
  } // loadLines
Beispiel #4
0
 /**
  * Create Payment for BankStatement
  *
  * @param bsl bank statement Line
  * @return Message
  * @throws Exception if not successful
  */
 private String createPayment(MBankStatementLine bsl) throws Exception {
   if (bsl == null || bsl.getC_Payment_ID() != 0) return "--";
   log.debug(bsl.toString());
   if (bsl.getC_Invoice_ID() == 0 && bsl.getC_BPartner_ID() == 0)
     throw new AdempiereUserError("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@");
   //
   MBankStatement bs = new MBankStatement(getCtx(), bsl.getC_BankStatement_ID(), get_TrxName());
   //
   MPayment payment =
       createPayment(
           bsl.getC_Invoice_ID(),
           bsl.getC_BPartner_ID(),
           bsl.getC_Currency_ID(),
           bsl.getStmtAmt(),
           bsl.getTrxAmt(),
           bs.getC_BP_BankAccount_ID(),
           bsl.getStatementLineDate(),
           bsl.getDateAcct(),
           bsl.getDescription(),
           bsl.getAD_Org_ID());
   if (payment == null) throw new AdempiereSystemError("Could not create Payment");
   //	update statement
   bsl.setPayment(payment);
   bsl.save();
   //
   String retString = "@C_Payment_ID@ = " + payment.getDocumentNo();
   if (payment.getOverUnderAmt().signum() != 0)
     retString += " - @OverUnderAmt@=" + payment.getOverUnderAmt();
   return retString;
 } //	createPayment