⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doc_gljournal.java

📁 Java写的ERP系统
💻 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:              GL_Journal (224)
 *  Document Types:     GLJ
 *  </pre>
 *  @author Jorg Janke
 *  @version  $Id: Doc_GLJournal.java,v 1.11 2003/03/19 06:47:32 jjanke Exp $
 */
public class Doc_GLJournal extends Doc
{
	/**
	 *  Constructor
	 *  @param AD_Client_ID client
	 */
	protected Doc_GLJournal(int AD_Client_ID)
	{
		super(AD_Client_ID);
	}

	/**
	 *  Return TableName of Document
	 *  @return GL_Journal
	 */
	public String getTableName()
	{
		return "GL_Journal";
	}   //  getTableName

	/**
	 *  Get Table ID
	 *  @return 224
	 */
	public int getAD_Table_ID()
	{
		return 224;
	}   //  getAD_Table_ID

	/**
	 *  Load Specific Document Details
	 *  @param rs result set
	 *  @return true if loadDocumentType was set
	 */
	protected boolean loadDocumentDetails (ResultSet rs)
	{
		loadDocumentType();     //  lines require doc type
		//	Contained Objects
		p_lines = loadLines();
		log.debug("Lines=" + p_lines.length);
		return true;
	}   //  loadDocumentDetails


	/**
	 *	Load Invoice Line
	 *  @return DocLine Array
	 */
	private DocLine[] loadLines()
	{
		ArrayList list = new ArrayList();
		String sql = "SELECT jl.GL_JournalLine_ID,jl.AD_Client_ID,jl.AD_Org_ID,"    //  1..3
			+ " jl.Line,jl.Description,"                                    //  4..5
			+ " jl.C_Currency_ID,jl.AmtSourceDr,jl.AmtSourceCr,"            //  6..8
			+ " jl.CurrencyRateType,jl.CurrencyRate,"                       //  9..10
			+ " jl.DateAcct,jl.AmtAcctDr,jl.AmtAcctCr,"                     //  11..13
			+ " jl.C_UOM_ID,jl.Qty,"                                        //  14..15
			+ " vc.C_AcctSchema_ID,vc.C_ValidCombination_ID,"               //  16..17
			+ " vc.Account_ID,vc.M_Product_ID,vc.C_BPartner_ID,"            //  18..20
			+ " vc.AD_OrgTrx_ID,vc.C_LocFrom_ID,vc.C_LocTo_ID,"
			+ " vc.C_SalesRegion_ID,vc.C_Project_ID,vc.C_Campaign_ID,"
			+ " vc.C_Activity_ID,vc.User1_ID,vc.User2_ID "
			//
			+ "FROM C_ValidCombination vc, GL_JournalLine jl "
			+ "WHERE vc.C_ValidCombination_ID=jl.C_ValidCombination_ID"
			+ " AND jl.GL_Journal_ID=?"
			+ " AND jl.IsActive='Y' AND vc.IsFullyQualified='Y' "
			+ "ORDER BY jl.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(1);
				DocLine docLine = new DocLine (p_vo.DocumentType, p_vo.Record_ID, Line_ID);
				docLine.loadAttributes (rs, p_vo);
				//  --  Source Amounts
				BigDecimal AmtSourceDr = rs.getBigDecimal(7);
				BigDecimal AmtSourceCr = rs.getBigDecimal(8);
				docLine.setAmount (AmtSourceDr, AmtSourceCr);
				//  --  Converted Amounts
				int C_AcctSchema_ID = rs.getInt(16);
				BigDecimal AmtAcctDr = rs.getBigDecimal(12);
				BigDecimal AmtAcctCr = rs.getBigDecimal(13);
				docLine.setConvertedAmt (C_AcctSchema_ID, AmtAcctDr, AmtAcctCr);
				//  --  Account
				int C_ValidCombination_ID = rs.getInt(17);
				Account acct = new Account(C_ValidCombination_ID);
				docLine.setAccount (acct);
				//	--	Set Org from account	(x-org)
				docLine.setAD_Org_ID (acct.getAD_Org_ID());
				//
				list.add(docLine);
			}
			//
			rs.close();
			pstmt.close();
		}
		catch (SQLException e)
		{
			log.error ("loadLines - SQL=" + sql, e);
		}

		//	Return Array
		int size = list.size();
		DocLine[] dl = new DocLine[size];
		list.toArray(dl);
		return dl;
	}	//	loadLines

	/*************************************************************************/

	/**
	 *  Get Source Currency Balance - subtracts line and tax 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 (" [");
		//  Lines
		for (int i = 0; i < p_lines.length; i++)
		{
			retValue = retValue.add(p_lines[i].getAmount());
			sb.append("+").append(p_lines[i].getAmount());
		}
		sb.append("]");
		//
		log.debug(toString() + " Balance=" + retValue + sb.toString());
		return retValue;
	}   //  getBalance

	/**
	 *  Create Facts (the accounting logic) for
	 *  GLJ.
	 *  (only for the accounting scheme, it was created)
	 *  <pre>
	 *      account     DR          CR
	 *  </pre>
	 *  @param as acct schema
	 *  @return Fact
	 */
	public Fact createFact (AcctSchema as)
	{
		//  create Fact Header
		Fact fact = new Fact(this, as, Fact.POST_Actual);

		//  GLJ
		if (p_vo.DocumentType.equals(DocVO.DOCTYPE_GLJournal))
		{
			//  account     DR      CR
			for (int i = 0; i < p_lines.length; i++)
				if (p_lines[i].getC_AcctSchema_ID() == as.getC_AcctSchema_ID())
					fact.createLine(p_lines[i], p_lines[i].getAccount(),
						p_vo.C_Currency_ID, p_lines[i].getAmtSourceDr(), p_lines[i].getAmtSourceCr());
		}
		else
		{
			p_vo.Error = "DocumentType unknown: " + p_vo.DocumentType;
			log.error("createFact - " + p_vo.Error);
			fact = null;
		}
		return fact;
	}   //  createFact

}   //  Doc_GLJournal

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -