📄 mrma.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.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.process.*;
import org.compiere.util.*;
/**
* RMA Model
*
* @author Jorg Janke
* @version $Id: MRMA.java,v 1.12 2005/11/12 22:58:56 jjanke Exp $
*/
public class MRMA extends X_M_RMA implements DocAction
{
/**
* Standard Constructor
* @param ctx context
* @param M_RMA_ID id
*/
public MRMA (Properties ctx, int M_RMA_ID, String trxName)
{
super (ctx, M_RMA_ID, trxName);
if (M_RMA_ID == 0)
{
// setName (null);
// setSalesRep_ID (0);
// setC_DocType_ID (0);
// setM_InOut_ID (0);
setDocAction (DOCACTION_Complete); // CO
setDocStatus (DOCSTATUS_Drafted); // DR
setIsApproved(false);
setProcessed (false);
}
} // MRMA
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MRMA (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MRMA
/** Lines */
private MRMALine[] m_lines = null;
/** The Shipment */
private MInOut m_inout = null;
/**
* Get Lines
* @param requery requary
* @return lines
*/
public MRMALine[] getLines (boolean requery)
{
if (m_lines != null && !requery)
return m_lines;
ArrayList<MRMALine> list = new ArrayList<MRMALine>();
String sql = "SELECT * FROM M_RMALine WHERE M_RMA_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getM_RMA_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MRMALine(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 MRMALine[list.size ()];
list.toArray (m_lines);
return m_lines;
} // getLines
/**
* Get Shipment
* @return shipment
*/
public MInOut getShipment()
{
if (m_inout == null && getM_InOut_ID() != 0)
m_inout = new MInOut (getCtx(), getM_InOut_ID(), get_TrxName());
return m_inout;
} // getShipment
/**
* Set M_InOut_ID
* @param M_InOut_ID id
*/
public void setM_InOut_ID (int M_InOut_ID)
{
super.setM_InOut_ID (M_InOut_ID);
setC_Currency_ID(0);
setAmt(Env.ZERO);
setC_BPartner_ID(0);
m_inout = null;
} // setM_InOut_ID
/**
* Get Document Info
* @return document info (untranslated)
*/
public String getDocumentInfo()
{
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
return dt.getName() + " " + 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
/**
* Before Save
* Set BPartner, Currency
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
// Set BPartner
if (getC_BPartner_ID() == 0)
{
getShipment();
if (m_inout != null)
setC_BPartner_ID(m_inout.getC_BPartner_ID());
}
// Set Currency
if (getC_Currency_ID() == 0)
{
getShipment();
if (m_inout != null)
{
if (m_inout.getC_Order_ID() != 0)
{
MOrder order = new MOrder (getCtx(), m_inout.getC_Order_ID(), get_TrxName());
setC_Currency_ID(order.getC_Currency_ID());
}
else if (m_inout.getC_Invoice_ID() != 0)
{
MInvoice invoice = new MInvoice (getCtx(), m_inout.getC_Invoice_ID(), get_TrxName());
setC_Currency_ID(invoice.getC_Currency_ID());
}
}
}
return true;
} // beforeSave
/**************************************************************************
* 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());
} // process
/** 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());
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;
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MRMALine[] lines = getLines(false);
if (lines.length == 0)
{
m_processMsg = "@NoLines@";
return DocAction.STATUS_Invalid;
}
// Check Lines
BigDecimal amt = Env.ZERO;
for (int i = 0; i < lines.length; i++)
{
MRMALine line = lines[i];
amt = amt.add(line.getAmt());
}
setAmt(amt);
m_justPrepared = true;
return DocAction.STATUS_InProgress;
} // prepareIt
/**
* Approve Document
* @return true if success
*/
public boolean approveIt()
{
log.info("approveIt - " + toString());
setIsApproved(true);
return true;
} // approveIt
/**
* Reject Approval
* @return true if success
*/
public boolean rejectIt()
{
log.info("rejectIt - " + toString());
setIsApproved(false);
return true;
} // rejectIt
/**
* Complete Document
* @return new status (Complete, In Progress, Invalid, Waiting ..)
*/
public String completeIt()
{
// Re-Check
if (!m_justPrepared)
{
String status = prepareIt();
if (!DocAction.STATUS_InProgress.equals(status))
return status;
}
// Implicit Approval
if (!isApproved())
approveIt();
log.info("completeIt - " + toString());
//
if (true)
{
m_processMsg = "Need to code creating the credit memo";
return DocAction.STATUS_InProgress;
}
// User Validation
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
if (valid != null)
{
m_processMsg = valid;
return DocAction.STATUS_Invalid;
}
//
setProcessed(true);
setDocAction(DOCACTION_Close);
return DocAction.STATUS_Completed;
} // completeIt
/**
* Void Document.
* @return true if success
*/
public boolean voidIt()
{
log.info("voidIt - " + toString());
// Revoke Credit
return false;
} // voidIt
/**
* Close Document.
* Cancel not delivered Qunatities
* @return true if success
*/
public boolean closeIt()
{
log.info("closeIt - " + toString());
return true;
} // closeIt
/**
* Reverse Correction
* @return true if success
*/
public boolean reverseCorrectIt()
{
log.info("reverseCorrectIt - " + toString());
return false;
} // reverseCorrectionIt
/**
* Reverse Accrual - none
* @return true if success
*/
public boolean reverseAccrualIt()
{
log.info("reverseAccrualIt - " + toString());
return false;
} // reverseAccrualIt
/**
* Re-activate
* @return true if success
*/
public boolean reActivateIt()
{
log.info("reActivateIt - " + toString());
return false;
} // reActivateIt
/*************************************************************************
* Get Summary
* @return Summary of Document
*/
public String getSummary()
{
StringBuffer sb = new StringBuffer();
sb.append(getDocumentNo());
// : Total Lines = 123.00 (#1)
sb.append(": ").
append(Msg.translate(getCtx(),"Amt")).append("=").append(getAmt())
.append(" (#").append(getLines(false).length).append(")");
// - Description
if (getDescription() != null && getDescription().length() > 0)
sb.append(" - ").append(getDescription());
return sb.toString();
} // getSummary
/**
* Get Process Message
* @return clear text error message
*/
public String getProcessMsg()
{
return m_processMsg;
} // getProcessMsg
/**
* Get Document Owner (Responsible)
* @return AD_User_ID
*/
public int getDoc_User_ID()
{
return getSalesRep_ID();
} // getDoc_User_ID
/**
* Get Document Approval Amount
* @return amount
*/
public BigDecimal getApprovalAmt()
{
return getAmt();
} // getApprovalAmt
} // MRMA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -