예제 #1
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
  /**
   * 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