📄 mmovementconfirm.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.io.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.process.*;
import org.compiere.util.*;
/**
* Inventory Movement Confirmation
*
* @author Jorg Janke
* @version $Id: MMovementConfirm.java,v 1.11 2005/11/12 22:58:56 jjanke Exp $
*/
public class MMovementConfirm extends X_M_MovementConfirm implements DocAction
{
/**
* Create Confirmation or return existing one
* @param move movement
* @param checkExisting if false, new confirmation is created
* @return Confirmation
*/
public static MMovementConfirm create (MMovement move, boolean checkExisting)
{
if (checkExisting)
{
MMovementConfirm[] confirmations = move.getConfirmations(false);
for (int i = 0; i < confirmations.length; i++)
{
MMovementConfirm confirm = confirmations[i];
return confirm;
}
}
MMovementConfirm confirm = new MMovementConfirm (move);
confirm.save(move.get_TrxName());
MMovementLine[] moveLines = move.getLines(false);
for (int i = 0; i < moveLines.length; i++)
{
MMovementLine mLine = moveLines[i];
MMovementLineConfirm cLine = new MMovementLineConfirm (confirm);
cLine.setMovementLine(mLine);
cLine.save(move.get_TrxName());
}
return confirm;
} // MInOutConfirm
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_MovementConfirm_ID id
*/
public MMovementConfirm (Properties ctx, int M_MovementConfirm_ID, String trxName)
{
super (ctx, M_MovementConfirm_ID, trxName);
if (M_MovementConfirm_ID == 0)
{
// setM_Movement_ID (0);
setDocAction (DOCACTION_Complete);
setDocStatus (DOCSTATUS_Drafted);
setIsApproved (false); // N
setProcessed (false);
}
} // MMovementConfirm
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MMovementConfirm (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MMovementConfirm
/**
* Parent Constructor
* @param move movement
*/
public MMovementConfirm (MMovement move)
{
this (move.getCtx(), 0, move.get_TrxName());
setClientOrg(move);
setM_Movement_ID(move.getM_Movement_ID());
} // MInOutConfirm
/** Confirm Lines */
private MMovementLineConfirm[] m_lines = null;
/** Physical Inventory From */
private MInventory m_inventoryFrom = null;
/** Physical Inventory To */
private MInventory m_inventoryTo = null;
/** Physical Inventory Info */
private String m_inventoryInfo = null;
/**
* Get Lines
* @param requery requery
* @return array of lines
*/
public MMovementLineConfirm[] getLines (boolean requery)
{
if (m_lines != null && !requery)
return m_lines;
String sql = "SELECT * FROM M_MovementLineConfirm "
+ "WHERE M_MovementConfirm_ID=?";
ArrayList<MMovementLineConfirm> list = new ArrayList<MMovementLineConfirm>();
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getM_MovementConfirm_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add(new MMovementLineConfirm(getCtx(), rs, get_TrxName()));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
m_lines = new MMovementLineConfirm[list.size ()];
list.toArray (m_lines);
return m_lines;
} // getLines
/**
* Add to Description
* @param description text
*/
public void addDescription (String description)
{
String desc = getDescription();
if (desc == null)
setDescription(description);
else
setDescription(desc + " | " + description);
} // addDescription
/**
* Set Approved
* @param IsApproved approval
*/
public void setIsApproved (boolean IsApproved)
{
if (IsApproved && !isApproved())
{
int AD_User_ID = Env.getAD_User_ID(getCtx());
MUser user = MUser.get(getCtx(), AD_User_ID);
String info = user.getName()
+ ": "
+ Msg.translate(getCtx(), "IsApproved")
+ " - " + new Timestamp(System.currentTimeMillis());
addDescription(info);
}
super.setIsApproved (IsApproved);
} // setIsApproved
/**
* Get Document Info
* @return document info (untranslated)
*/
public String getDocumentInfo()
{
return Msg.getElement(getCtx(), "M_MovementConfirm_ID") + " " + getDocumentNo();
} // getDocumentInfo
/**
* Create PDF
* @return File or null
*/
public File createPDF ()
{
try
{
File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf");
return createPDF (temp);
}
catch (Exception e)
{
log.severe("Could not create PDF - " + e.getMessage());
}
return null;
} // getPDF
/**
* Create PDF file
* @param file output file
* @return file if success
*/
public File createPDF (File file)
{
// ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.INVOICE, getC_Invoice_ID());
// if (re == null)
return null;
// return re.getPDF(file);
} // createPDF
/**************************************************************************
* Process document
* @param processAction document action
* @return true if performed
*/
public boolean processIt (String processAction)
{
m_processMsg = null;
DocumentEngine engine = new DocumentEngine (this, getDocStatus());
return engine.processIt (processAction, getDocAction());
} // processIt
/** Process Message */
private String m_processMsg = null;
/** Just Prepared Flag */
private boolean m_justPrepared = false;
/**
* Unlock Document.
* @return true if success
*/
public boolean unlockIt()
{
log.info("unlockIt - " + toString());
setProcessing(false);
return true;
} // unlockIt
/**
* Invalidate Document
* @return true if success
*/
public boolean invalidateIt()
{
log.info("invalidateIt - " + toString());
setDocAction(DOCACTION_Prepare);
return true;
} // invalidateIt
/**
* Prepare Document
* @return new status (In Progress or Invalid)
*/
public String prepareIt()
{
log.info(toString());
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
// Std Period open?
if (!MPeriod.isOpen(getCtx(), getUpdated(), MDocType.DOCBASETYPE_MaterialMovement))
{
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid;
}
MMovementLineConfirm[] lines = getLines(true);
if (lines.length == 0)
{
m_processMsg = "@NoLines@";
return DocAction.STATUS_Invalid;
}
boolean difference = false;
for (int i = 0; i < lines.length; i++)
{
if (!lines[i].isFullyConfirmed())
{
difference = true;
break;
}
}
// User Validation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -