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

📄 doc_inventory.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 Inventory Documents.
 *  <pre>
 *  Table:              M_Inventory (321)
 *  Document Types:     MMI
 *  </pre>
 *  @author Jorg Janke
 *  @version  $Id: Doc_Inventory.java,v 1.6 2003/03/19 06:47:32 jjanke Exp $
 */
public class Doc_Inventory extends Doc
{
	/**
	 *  Constructor
	 *  @param AD_Client_ID client
	 */
	public Doc_Inventory (int AD_Client_ID)
	{
		super (AD_Client_ID);
	}   //  Doc_Inventory

	/**
	 *  Get AD_Table_ID
	 *  @return 321
	 */
	public int getAD_Table_ID()
	{
		return 321;
	}   //  get_Table_ID

	/**
	 *  Table Name
	 *  @return M_Inventory
	 */
	public String getTableName()
	{
		return "M_Inventory";
	}   //  getTableName

	/**
	 *  Load Document Details
	 *  @param rs result
	 *  @return true if loadDocumentType was set
	 */
	protected boolean loadDocumentDetails(ResultSet rs)
	{
		p_vo.DocumentType = DocVO.DOCTYPE_MatInventory;
		p_vo.C_Currency_ID = NO_CURRENCY;
		try
		{
			p_vo.DateDoc = rs.getTimestamp("MovementDate");
		}
		catch (SQLException e)
		{
			log.error("loadDocumentDetails", e);
		}
		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 * FROM M_InventoryLine WHERE M_Inventory_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("M_InventoryLine_ID");
				DocLine_Material docLine = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, Line_ID);
				docLine.loadAttributes(rs, p_vo);
				BigDecimal QtyBook = rs.getBigDecimal("QtyBook");
				BigDecimal QtyCount = rs.getBigDecimal("QtyCount");
				docLine.setQty (QtyCount.subtract(QtyBook));
				docLine.setM_Locator_ID (rs.getInt("M_Locator_ID"));
				//
				log.debug(docLine.toString());
				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 Balance
	 *  @return Zero (always balanced)
	 */
	public BigDecimal getBalance()
	{
		BigDecimal retValue = Env.ZERO;
		return retValue;
	}   //  getBalance

	/**
	 *  Create Facts (the accounting logic) for
	 *  MMI.
	 *  <pre>
	 *  Inventory
	 *      Inventory       DR      CR
	 *      InventoryDiff   DR      CR
	 *  </pre>
	 *  @param as account schema
	 *  @return Fact
	 */
	public Fact createFact(AcctSchema as)
	{
	//	Log.trace(Log.l4_Data, "Doc.Inventory.createFact");
		p_vo.C_Currency_ID = as.getC_Currency_ID();
		//  create Fact Header
		Fact fact = new Fact(this, as, Fact.POST_Actual);

		//  Line pointers
		FactLine dr = null;
		FactLine cr = null;

		for (int i = 0; i < p_lines.length; i++)
		{
			DocLine_Material line = (DocLine_Material)p_lines[i];
			BigDecimal costs = line.getProductCosts(as);
			//  Inventory       DR      CR
			dr = fact.createLine(line,
				line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
				as.getC_Currency_ID(), costs);
			//  may be zero difference - no line created.
			if (dr == null)
				continue;
			dr.setM_Locator_ID(line.getM_Locator_ID());
			//  InventoryDiff   DR      CR
			cr = fact.createLine(line,
				getAccount(Doc.ACCTTYPE_InvDifferences, as),
				as.getC_Currency_ID(), costs.negate());
			cr.setM_Locator_ID(line.getM_Locator_ID());
		}
		return fact;
	}   //  createFact

}   //  Doc_Inventory

⌨️ 快捷键说明

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