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

📄 inventorymovegenerate.java

📁 大家共享愉快, 共享愉快, 共享愉快, 共享愉快,共享愉快
💻 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.process;

import java.sql.*;
import java.util.logging.*;
import org.compiere.model.*;
import org.compiere.util.*;

/**
 *	Generate Inventory Movement
 *
 *  @author Jorg Janke
 *  @version $Id: InventoryMoveGenerate.java,v 1.19 2005/03/11 20:25:57 jjanke Exp $
 */
public class InventoryMoveGenerate extends SvrProcess {
    /**	Manual Selection		*/
    private boolean p_Selection = false;
    /**	M_Locator_ID		*/
    private int p_M_Locator_ID = 0;

    /** DocAction				*/
    private String p_docAction = DocAction.ACTION_Complete;

    /**	The current movement	*/
    private MMovement m_movement = null;
    private int m_ProductionPlan_ID = 0;
    /** Numner of Movements		*/
    private int m_created = 0;
    /**	Line Number				*/
    private int m_line = 0;
    /**	Number of Created			*/
    private int m_lines = 0;
    /** Movement Date			*/
    private Timestamp m_movementDate = null;

    /**
     *  Prepare - e.g., get Parameters.
     */
    protected void prepare() {
        ProcessInfoParameter[] para = getParameter();
        for (int i = 0; i < para.length; i++) {
            String name = para[i].getParameterName();
            if (para[i].getParameter() == null)
                ;
            else if (name.equals("Selection"))
                p_Selection = "Y".equals(para[i].getParameter());
            else if (name.equals("M_Locator_ID"))
                p_M_Locator_ID = para[i].getParameterAsInt();
            else
                log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);

            //	Login Date
            m_movementDate = Env.getContextAsDate(getCtx(), "#Date");
            if (m_movementDate == null)
                m_movementDate = new Timestamp(System.currentTimeMillis());
            //	DocAction check
            if (!DocAction.ACTION_Complete.equals(p_docAction))
                p_docAction = DocAction.ACTION_Prepare;
        }
    } //	prepare

    /**
     * 	Generate Inventory Movements
     *	@return info
     *	@throws Exception
     */
    protected String doIt() throws Exception {
        String sql = null;
        if (p_Selection) { //	VInventoryMoveGen
            sql = "SELECT * FROM M_ProductionLine "
                  + "WHERE IsSelected='Y' "
                  + "Order By M_ProductionPlan_ID";
        } else {
        }
        PreparedStatement pstmt = null;
        try {
            pstmt = DB.prepareStatement(sql, get_TrxName());
        } catch (Exception e) {
            log.log(Level.SEVERE, sql, e);
        }
        return generate(pstmt);
    } //	doIt

    /**
     * 	Generate Inventory Movements
     * 	@param pstmt Production
     *	@return info
     */
    private String generate(PreparedStatement pstmt) {
        try {
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                MProductionLine pLine = new MProductionLine(getCtx(), rs,
                        get_TrxName());

                if (m_movement == null ||
                    (m_movement != null &&
                     m_ProductionPlan_ID != pLine.getM_ProductionPlan_ID())) {

                    m_ProductionPlan_ID = pLine.getM_ProductionPlan_ID();

                    MProductionPlan pPlan = new MProductionPlan(getCtx(),
                            pLine.getM_ProductionPlan_ID(),
                            get_TrxName());
                    MProduct product = new MProduct(getCtx(),
                            pPlan.getM_Product_ID(), get_TrxName());
                    MProduction production = new MProduction(getCtx(),
                            pPlan.getM_Production_ID(),
                            get_TrxName());

                    m_movement = new MMovement(getCtx(), 0, get_TrxName());
                    m_movement.setM_Production_ID(pPlan.getM_Production_ID());
                    m_movement.setDescription(production.getName() + " - " +
                                              product.getName());
                    m_movement.setMovementDate(new Timestamp(System.
                            currentTimeMillis()));
                    m_movement.setC_DocType_ID(143);
                    if (!m_movement.save())
                        throw new IllegalStateException(
                                "Could not create movements.");

                   addLog(m_movement.getM_Movement_ID(), m_movement.getMovementDate(), null, m_movement.getDocumentNo());
                    m_line = 0;
                    m_created++;
                }

                m_line += 10;
                m_lines ++;

                MMovementLine mLine = new MMovementLine(getCtx(), 0,
                        get_TrxName());
                mLine.setM_Movement_ID(m_movement.getM_Movement_ID());
                mLine.setM_Product_ID(pLine.getM_Product_ID());
                mLine.setMovementQty(pLine.getMovementQty().abs());
                mLine.setM_Locator_ID(p_M_Locator_ID);
                mLine.setM_LocatorTo_ID(pLine.getM_Locator_ID());
                mLine.setM_AttributeSetInstance_ID(pLine.
                        getM_AttributeSetInstance_ID());
                mLine.setDescription(pLine.getDescription());
                mLine.setLine(m_line);
                if (!mLine.save())
                    throw new IllegalStateException(
                            "Could not create movement line.");
            }
            rs.close();
            pstmt.close();
            pstmt = null;
        } catch (Exception e) {
            log.log(Level.SEVERE, "generate", e);
        }
        try {
            if (pstmt != null)
                pstmt.close();
            pstmt = null;
        } catch (Exception e) {
            pstmt = null;
        }

        return "@Created@ = " + m_created;
    } //	generate
} //	InventoryMoveGenerate

⌨️ 快捷键说明

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