📄 doc_inout.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 Shipment Documents.
* <pre>
* Table: M_InOut (319)
* Document Types: MMS, MMR
* </pre>
* @author Jorg Janke
* @version $Id: Doc_InOut.java,v 1.9 2003/03/19 06:47:32 jjanke Exp $
*/
public class Doc_InOut extends Doc
{
/** AD_Table_ID */
public static final int M_InOut_TABLE_ID = 319;
/**
* Constructor
* @param AD_Client_ID client
*/
public Doc_InOut (int AD_Client_ID)
{
super (AD_Client_ID);
} // DocInOut
/** Location */
private int C_BPartner_Location_ID = 0;
/**
* Get AD_Table_ID
* @return 319
*/
public int getAD_Table_ID()
{
return M_InOut_TABLE_ID;
} // get_Table_ID
/**
* Table Name
* @return M_InOut
*/
public String getTableName()
{
return "M_InOut";
} // getTableName
/**
* Load Document Details
* @param rs result set
* @return true if loadDocumentType was set
*/
protected boolean loadDocumentDetails(ResultSet rs)
{
p_vo.C_Currency_ID = NO_CURRENCY;
try
{
p_vo.DateDoc = rs.getTimestamp("MovementDate");
C_BPartner_Location_ID = rs.getInt("C_BPartner_Location_ID");
}
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_InOutLine WHERE M_InOut_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_InOutLine_ID");
DocLine_Material docLine = new DocLine_Material (p_vo.DocumentType, p_vo.Record_ID, Line_ID);
docLine.loadAttributes(rs, p_vo);
docLine.setQty (rs.getBigDecimal("MovementQty")); // sets Trx and Storage Qty
docLine.setM_Locator_ID (rs.getInt("M_Locator_ID"));
//
if (docLine.getM_Product_ID() == 0)
log.info(docLine.toString() + " - No Product - ignored");
else
{
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
* MMS, MMR.
* <pre>
* Shipment
* CoGS DR
* Inventory CR
* Receipt
* Inventory DR
* NotInvoicedReceipt CR
* </pre>
* @param as accounting schema
* @return Fact
*/
public Fact createFact(AcctSchema as)
{
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;
// Sales
if (p_vo.DocumentType.equals(DocVO.DOCTYPE_MatShipment))
{
for (int i = 0; i < p_lines.length; i++)
{
DocLine_Material line = (DocLine_Material)p_lines[i];
BigDecimal costs = line.getProductCosts(as);
// CoGS DR
dr = fact.createLine(line,
line.getAccount(ProductInfo.ACCTTYPE_P_Cogs, as),
as.getC_Currency_ID(), costs, null);
dr.setM_Locator_ID(line.getM_Locator_ID());
dr.setLocationFromLocator(line.getM_Locator_ID(), true); // from Loc
dr.setLocationFromBPartner(C_BPartner_Location_ID, false); // to Loc
// Inventory CR
cr = fact.createLine(line,
line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
as.getC_Currency_ID(), null, costs);
cr.setM_Locator_ID(line.getM_Locator_ID());
cr.setLocationFromLocator(line.getM_Locator_ID(), true); // from Loc
cr.setLocationFromBPartner(C_BPartner_Location_ID, false); // to Loc
}
updateProductInfo(as.getC_AcctSchema_ID()); // only for SO!
}
// Purchasing
else if (p_vo.DocumentType.equals(DocVO.DOCTYPE_MatReceipt))
{
for (int i = 0; i < p_lines.length; i++)
{
DocLine_Material line = (DocLine_Material)p_lines[i];
BigDecimal costs = line.getProductCosts(as);
// Inventory DR
dr = fact.createLine(line,
line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as),
as.getC_Currency_ID(), costs, null);
dr.setM_Locator_ID(line.getM_Locator_ID());
dr.setLocationFromBPartner(C_BPartner_Location_ID, true); // from Loc
dr.setLocationFromLocator(line.getM_Locator_ID(), false); // to Loc
// NotInvoicedReceipt CR
cr = fact.createLine(line,
getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as),
as.getC_Currency_ID(), null, costs);
cr.setM_Locator_ID(line.getM_Locator_ID());
cr.setLocationFromBPartner(C_BPartner_Location_ID, true); // from Loc
cr.setLocationFromLocator(line.getM_Locator_ID(), false); // to Loc
}
}
else
{
p_vo.Error = "DocumentType unknown: " + p_vo.DocumentType;
log.error("createFact - " + p_vo.Error);
return null;
}
//
return fact;
} // createFact
/**
* Update Sales Order Costing Product Info.
* Purchase side handeled in Invoice Matching.
* <br>
* decrease average cumulatives
*
* @param C_AcctSchema_ID accounting schema
*/
private void updateProductInfo (int C_AcctSchema_ID)
{
log.debug("updateProductInfo - M_InOut_ID=" + p_vo.Record_ID);
StringBuffer sql = new StringBuffer(
"UPDATE M_Product_Costing pc "
+ "SET (CostAverageCumQty, CostAverageCumAmt)="
+ "(SELECT CostAverageCumQty - SUM(il.MovementQty),"
+ " CostAverageCumAmt - SUM(il.MovementQty*CurrentCostPrice) "
+ "FROM M_InOutLine il "
+ "WHERE pc.M_Product_ID=il.M_Product_ID"
+ " AND il.M_InOut_ID=").append(p_vo.Record_ID).append(") ")
.append("WHERE EXISTS (SELECT * "
+ "FROM M_InOutLine il "
+ "WHERE pc.M_Product_ID=il.M_Product_ID"
+ " AND il.M_InOut_ID=").append(p_vo.Record_ID).append(")");
int no = DB.executeUpdate(sql.toString());
log.debug("M_Product_Costing - Updated=" + no);
} // updateProductInfo
} // Doc_InOut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -