📄 doc_cash.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_Cash (407)
* Document Types: CMC
* </pre>
* @author Jorg Janke
* @version $Id: Doc_Cash.java,v 1.12 2003/03/19 06:47:32 jjanke Exp $
*/
public class Doc_Cash extends Doc
{
/**
* Constructor
* @param AD_Client_ID client
*/
protected Doc_Cash(int AD_Client_ID)
{
super(AD_Client_ID);
}
/**
* Return TableName of Document
* @return C_Cash
*/
public String getTableName()
{
return "C_Cash";
} // getTableName
/**
* Get Table ID
* @return 407
*/
public int getAD_Table_ID()
{
return 407;
} // 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_CashJournal;
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 CashBook Org & Currency
setCashBookInfo();
loadDocumentType(); // lines require doc type
// Contained Objects
p_lines = loadLines();
log.debug("Lines=" + p_lines.length);
return true;
} // loadDocumentDetails
/**
* Set CashBook info.
* - CashBook_ID
* - Organization
* - Currency
*/
private void setCashBookInfo()
{
int retValue = 0;
String sql = "SELECT cb.C_CashBook_ID, cb.AD_Org_ID, cb.C_Currency_ID "
+ "FROM C_Cash c, C_CashBook cb "
+ "WHERE c.C_CashBook_ID=cb.C_CashBook_ID AND c.C_Cash_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, p_vo.Record_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
p_vo.C_CashBook_ID = rs.getInt(1);
p_vo.AD_Org_ID = rs.getInt(2);
p_vo.C_Currency_ID = rs.getInt(3);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error("setCashBookInfo", e);
}
} // setCashBookInfo
/**
* Load Cash Line
* @return DocLine Array
*/
private DocLine[] loadLines()
{
ArrayList list = new ArrayList();
String sql = "SELECT * FROM C_CashLine WHERE C_Cash_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_CashLine_ID");
DocLine_Cash docLine = new DocLine_Cash (p_vo.DocumentType, p_vo.Record_ID, Line_ID);
docLine.loadAttributes(rs, p_vo);
docLine.setCashType(rs.getString("CashType"));
docLine.setReference(rs.getInt("C_BankAccount_ID"), rs.getInt("C_Invoice_ID"));
docLine.setAmount (rs.getBigDecimal("Amount"),
rs.getBigDecimal("DiscountAmt"), rs.getBigDecimal("WriteOffAmt"));
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++)
{
retValue = retValue.subtract(p_lines[i].getAmount());
sb.append("-").append(p_lines[i].getAmount());
}
sb.append("]");
//
log.debug(toString() + " Balance=" + retValue + sb.toString());
// return retValue;
return Env.ZERO; // Lines are balanced
} // getBalance
/**
* Create Facts (the accounting logic) for
* CMC.
* <pre>
* Expense
* CashExpense DR
* CashAsset CR
* Receipt
* CashAsset DR
* CashReceipt CR
* Charge
* Charge DR
* CashAsset CR
* Difference
* CashDifference DR
* CashAsset CR
* Invoice
* CashAsset DR
* CashTransfer CR
* Transfer
* BankInTransit DR
* CashAsset CR
* </pre>
* @param as account schema
* @return Fact
*/
public Fact createFact (AcctSchema as)
{
// Need to have CashBook
if (p_vo.C_CashBook_ID == 0)
{
p_vo.Error = "C_CashBook_ID not set";
log.error("createFact - " + p_vo.Error);
return null;
}
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
// Header posting amt as Invoices and Transfer could be differenet currency
// CashAsset Total
BigDecimal assetAmt = Env.ZERO;
// Lines
for (int i = 0; i < p_lines.length; i++)
{
DocLine_Cash line = (DocLine_Cash)p_lines[i];
String CashType = line.getCashType();
if (CashType.equals(DocLine_Cash.CASHTYPE_EXPENSE))
{ // amount is negative
// CashExpense DR
// CashAsset CR
fact.createLine(line, getAccount(Doc.ACCTTYPE_CashExpense, as),
p_vo.C_Currency_ID, line.getAmount().negate(), null);
// fact.createLine(line, getAccount(Doc.ACCTTYPE_CashAsset, as),
// p_vo.C_Currency_ID, null, line.getAmount().negate());
assetAmt = assetAmt.subtract(line.getAmount().negate());
}
else if (CashType.equals(DocLine_Cash.CASHTYPE_RECEIPT))
{ // amount is positive
// CashAsset DR
// CashReceipt CR
// fact.createLine(line, getAccount(Doc.ACCTTYPE_CashAsset, as),
// p_vo.C_Currency_ID, line.getAmount(), null);
assetAmt = assetAmt.add(line.getAmount());
fact.createLine(line, getAccount(Doc.ACCTTYPE_CashReceipt, as),
p_vo.C_Currency_ID, null, line.getAmount());
}
else if (CashType.equals(DocLine_Cash.CASHTYPE_CHARGE))
{ // amount is negative
// Charge DR
// CashAsset CR
fact.createLine(line, line.getChargeAccount(as, getAmount()),
p_vo.C_Currency_ID, line.getAmount().negate(), null);
// fact.createLine(line, getAccount(Doc.ACCTTYPE_CashAsset, as),
// p_vo.C_Currency_ID, null, line.getAmount().negate());
assetAmt = assetAmt.subtract(line.getAmount().negate());
}
else if (CashType.equals(DocLine_Cash.CASHTYPE_DIFFERENCE))
{ // amount is pos/neg
// CashDifference DR
// CashAsset CR
fact.createLine(line, getAccount(Doc.ACCTTYPE_CashDifference, as),
p_vo.C_Currency_ID, line.getAmount().negate());
// fact.createLine(line, getAccount(Doc.ACCTTYPE_CashAsset, as),
// p_vo.C_Currency_ID, line.getAmount());
assetAmt = assetAmt.add(line.getAmount());
}
else if (CashType.equals(DocLine_Cash.CASHTYPE_INVOICE))
{ // amount is pos/neg
// CashAsset DR dr -- Invoice is in Invoice Currency !
// CashTransfer cr CR
if (line.getC_Currency_ID() == p_vo.C_Currency_ID)
assetAmt = assetAmt.add (line.getAmount());
else
fact.createLine(line,
getAccount(Doc.ACCTTYPE_CashAsset, as),
line.getC_Currency_ID(), line.getAmount());
fact.createLine(line,
getAccount(Doc.ACCTTYPE_CashTransfer, as),
line.getC_Currency_ID(), line.getAmount().negate());
}
else if (CashType.equals(DocLine_Cash.CASHTYPE_TRANSFER))
{ // amount is pos/neg
// BankInTransit DR dr -- Transfer is in Bank Account Currency
// CashAsset dr CR
int temp = p_vo.C_BankAccount_ID;
p_vo.C_BankAccount_ID = line.getC_BankAccount_ID();
fact.createLine(line,
getAccount(Doc.ACCTTYPE_BankInTransit, as),
line.getC_Currency_ID(), line.getAmount().negate());
p_vo.C_BankAccount_ID = temp;
if (line.getC_Currency_ID() == p_vo.C_Currency_ID)
assetAmt = assetAmt.add (line.getAmount());
else
fact.createLine(line,
getAccount(Doc.ACCTTYPE_CashAsset, as),
line.getC_Currency_ID(), line.getAmount());
}
} // lines
// Cash Asset
fact.createLine(null, getAccount(Doc.ACCTTYPE_CashAsset, as),
p_vo.C_Currency_ID, assetAmt);
return fact;
} // createFact
} // Doc_Cash
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -