📄 doc_bank.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.acct;
import java.math.*;
import java.util.*;
import java.sql.*;
import org.compiere.util.*;
import org.compiere.model.*;
/**
* Post Invoice Documents.
* <pre>
* Table: C_BankStatement (392)
* Document Types: CMB
* </pre>
* @author Jorg Janke
* @version $Id: Doc_Bank.java,v 1.14 2003/03/19 06:47:32 jjanke Exp $
*/
public class Doc_Bank extends Doc
{
/**
* Constructor
* @param AD_Client_ID AD_Client_ID
*/
protected Doc_Bank(int AD_Client_ID)
{
super(AD_Client_ID);
}
/**
* Return TableName of Document
* @return C_BankStatement
*/
public String getTableName()
{
return "C_BankStatement";
} // getTableName
/**
* Get Table ID
* @return 392
*/
public int getAD_Table_ID()
{
return 392;
} // getAD_Table_ID
/**
* Load Specific Document Details
* @param rs result set
* @return true if loadDocumentType was set
*/
protected boolean loadDocumentDetails (ResultSet rs)
{
p_vo.DocumentType = DocVO.DOCTYPE_BankStatement;
try
{
p_vo.DateDoc = rs.getTimestamp("StatementDate");
// Amounts
p_vo.Amounts[Doc.AMTTYPE_Gross] = rs.getBigDecimal("StatementDifference");
if (p_vo.Amounts[Doc.AMTTYPE_Gross] == null)
p_vo.Amounts[Doc.AMTTYPE_Gross] = Env.ZERO;
}
catch (SQLException e)
{
log.error("loadDocumentDetails", e);
}
// Set Bank Account Info (Currency)
setBankAccountInfo();
loadDocumentType(); // lines require doc type
// Contained Objects
p_lines = loadLines();
log.debug("Lines=" + p_lines.length);
return true;
} // loadDocumentDetails
/**
* Set Bank Account Info
*/
private void setBankAccountInfo()
{
String sql = "SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, p_vo.C_BankAccount_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
p_vo.C_Currency_ID = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error("setBankAccountInfo", e);
}
} // setBankAccountInfo
/**
* Load Invoice Line.
* 4 amounts
* AMTTYPE_Payment
* AMTTYPE_Statement2
* AMTTYPE_Charge
* AMTTYPE_Interest
* @return DocLine Array
*/
private DocLine[] loadLines()
{
ArrayList list = new ArrayList();
String sql = "SELECT * FROM C_BankStatementLine WHERE C_BankStatement_ID=? ORDER BY Line";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, p_vo.Record_ID);
ResultSet rs = pstmt.executeQuery();
//
while (rs.next())
{
int Line_ID = rs.getInt("C_BankStatementLine_ID");
DocLine_Bank docLine = new DocLine_Bank (p_vo.DocumentType, p_vo.Record_ID, Line_ID);
docLine.loadAttributes(rs, p_vo);
docLine.setDateDoc(rs.getTimestamp("ValutaDate"));
docLine.setC_Payment_ID(rs.getInt("C_Payment_ID"));
docLine.setIsReversal(rs.getString("IsReversal"));
docLine.setAmount(rs.getBigDecimal("StmtAmt"), rs.getBigDecimal("InterestAmt"), rs.getBigDecimal("TrxAmt"));
list.add(docLine);
}
//
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error ("loadLines", e);
}
// Return Array
DocLine[] dl = new DocLine[list.size()];
list.toArray(dl);
return dl;
} // loadLines
/*************************************************************************/
/**
* Get Source Currency Balance - subtracts line amounts from total - no rounding
* @return positive amount, if total invoice is bigger than lines
*/
public BigDecimal getBalance()
{
BigDecimal retValue = Env.ZERO;
StringBuffer sb = new StringBuffer (" [");
// Total
retValue = retValue.add(getAmount(Doc.AMTTYPE_Gross));
sb.append(getAmount(Doc.AMTTYPE_Gross));
// - Lines
for (int i = 0; i < p_lines.length; i++)
{
BigDecimal lineBalance = ((DocLine_Bank)p_lines[i]).getStmtAmt();
retValue = retValue.subtract(lineBalance);
sb.append("-").append(lineBalance);
}
sb.append("]");
//
log.debug(toString() + " Balance=" + retValue + sb.toString());
return retValue;
} // getBalance
/**
* Create Facts (the accounting logic) for
* CMB.
* <pre>
* BankAsset DR CR (Statement)
* BankInTransit DR CR (Payment)
* Charge DR (Charge)
* Interest DR CR (Interest)
* </pre>
* @param as accounting schema
* @return Fact
*/
public Fact createFact (AcctSchema as)
{
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
// Header -- there may be different currency amounts
// Lines
for (int i = 0; i < p_lines.length; i++)
{
DocLine_Bank line = (DocLine_Bank)p_lines[i];
// BankAsset DR CR (Statement)
fact.createLine(line,
getAccount(Doc.ACCTTYPE_BankAsset, as),
line.getC_Currency_ID(), line.getStmtAmt());
// BankInTransit DR CR (Payment)
fact.createLine(line,
getAccount(Doc.ACCTTYPE_BankInTransit, as),
line.getC_Currency_ID(), line.getTrxAmt().negate());
// Charge DR (Charge)
fact.createLine(line,
line.getChargeAccount(as, line.getChargeAmt().negate()),
line.getC_Currency_ID(), line.getChargeAmt().negate(), null);
// Interest DR CR (Interest)
if (line.getInterestAmt().signum() < 0)
fact.createLine(line,
getAccount(Doc.ACCTTYPE_InterestExp, as), getAccount(Doc.ACCTTYPE_InterestExp, as),
line.getC_Currency_ID(), line.getInterestAmt().negate());
else
fact.createLine(line,
getAccount(Doc.ACCTTYPE_InterestExp, as), getAccount(Doc.ACCTTYPE_InterestRev, as),
line.getC_Currency_ID(), line.getInterestAmt().negate());
//
fact.createTaxCorrection();
}
return fact;
} // createFact
} // Doc_Bank
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -