📄 mproduction.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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Production Model
*
* @author Jorg Janke
* @version $Id: MProduction.java,v 1.20 2005/03/11 20:26:04 jjanke Exp $
*/
public class MProduction extends X_M_Production {
/**
* Get MProduction from Cache
* @param ctx context
* @param whereClause
* @param trxName
* @return MProductionPlan
*/
public static MProduction[] get(Properties ctx, String whereClause,
String trxName) {
String sql = "SELECT * FROM M_Production";
if (whereClause != null && whereClause.length() > 0)
sql += " WHERE " + whereClause;
ArrayList list = new ArrayList();
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, trxName);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MProduction(ctx, rs, trxName));
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
s_log.log(Level.SEVERE, "get", e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
MProduction[] retValue = new MProduction[list.size()];
list.toArray(retValue);
return retValue;
} // get
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger(MProduction.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_Production_ID id
*/
public MProduction(Properties ctx, int M_Production_ID, String trxName) {
super(ctx, M_Production_ID, trxName);
if (M_Production_ID == 0) {
}
} // MProduction
/**
* Load constructor
* @param ctx context
* @param rs result set
*/
public MProduction(Properties ctx, ResultSet rs, String trxName) {
super(ctx, rs, trxName);
} // MProduction
/**
* Create new production by copying
* @param ctx context
* @param M_Locator_ID Locator
* @param trxName trx
* @return Production
*/
public static MProduction copyFrom(MOrder from, int M_Locator_ID,
String trxName) {
MProduction to = new MProduction(from.getCtx(), 0, trxName);
to.set_TrxName(trxName);
MBPartner bp = new MBPartner(from.getCtx(),from.getC_BPartner_ID(),trxName);
to.setName(bp.getName() + "_" + from.getDocumentNo());
to.setMovementDate(from.getDatePromised());
to.setDescription(from.getDescription());
if (!to.save(trxName))
throw new IllegalStateException("Could not create production");
if (to.copyLinesFrom(from, M_Locator_ID) == 0)
throw new IllegalStateException(
"Have not Order lines to be created.");
return to;
} // copyFrom
/**
* Copy Lines From other Order
* @param otherOrder order
* @param M_Locator_ID locator id
* @return number of lines copied
*/
public int copyLinesFrom(MOrder otherOrder, int M_Locator_ID) {
if (isProcessed() || isPosted() || otherOrder == null)
return 0;
MOrderLine[] fromLines = otherOrder.getLines(false, null);
int count = 0;
for (int i = 0; i < fromLines.length; i++) {
MProduct p = new MProduct(fromLines[i].getCtx(),
fromLines[i].getM_Product_ID(),
get_TrxName());
if (p.isBOM()) {
MProductionPlan plan = new MProductionPlan(this);
plan.setLine(fromLines[i].getLine());
plan.setM_Product_ID(fromLines[i].getM_Product_ID());
plan.setProductionQty(fromLines[i].getQtyOrdered());
plan.setM_Locator_ID(M_Locator_ID);
plan.setDescription(fromLines[i].getDescription());
if (plan.save(get_TrxName()))
count++;
} else {
log.log(Level.SEVERE, "Haven't Bom :" + p.getName());
System.out.println("Haven't Bom :" + p.getName());
}
}
if (fromLines.length != count)
log.log(Level.SEVERE,
"copyLinesFrom - Line difference - From=" +
fromLines.length + " <> Saved=" + count);
return count;
} // copyLinesFrom
} // MProduction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -