📄 mtimeexpense.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.*;
/**
* Time + Expense Model
*
* @author Jorg Janke
* @version $Id: MTimeExpense.java,v 1.11 2005/11/12 22:58:56 jjanke Exp $
*/
public class MTimeExpense extends X_S_TimeExpense implements DocAction
{
/**
* Default Constructor
* @param ctx context
* @param S_TimeExpense_ID id
*/
public MTimeExpense (Properties ctx, int S_TimeExpense_ID, String trxName)
{
super (ctx, S_TimeExpense_ID, trxName);
if (S_TimeExpense_ID == 0)
{
// setC_BPartner_ID (0);
setDateReport (new Timestamp (System.currentTimeMillis ()));
// setDocumentNo (null);
setIsApproved (false);
// setM_PriceList_ID (0);
// setM_Warehouse_ID (0);
super.setProcessed (false);
setProcessing(false);
}
} // MTimeExpense
/**
* Load Constructor
*/
public MTimeExpense (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MTimeExpense
/** Default Locator */
private int m_M_Locator_ID = 0;
/** Lines */
private MTimeExpenseLine[] m_lines = null;
/** Cached User */
private int m_AD_User_ID = 0;
/**
* Get Lines
* @param requery true requeries
* @return array of lines
*/
public MTimeExpenseLine[] getLines (boolean requery)
{
if (m_lines != null && !requery)
return m_lines;
//
int C_Currency_ID = getC_Currency_ID();
ArrayList<MTimeExpenseLine> list = new ArrayList<MTimeExpenseLine>();
//
String sql = "SELECT * FROM S_TimeExpenseLine WHERE S_TimeExpense_ID=? ORDER BY Line";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getS_TimeExpense_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
MTimeExpenseLine te = new MTimeExpenseLine(getCtx(), rs, get_TrxName());
te.setC_Currency_Report_ID(C_Currency_ID);
list.add(te);
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "getLines", ex);
}
try
{
if (pstmt != null)
pstmt.close ();
}
catch (SQLException ex1)
{
}
pstmt = null;
//
m_lines = new MTimeExpenseLine[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
/**
* Get Default Locator (from Warehouse)
* @return locator
*/
public int getM_Locator_ID()
{
if (m_M_Locator_ID != 0)
return m_M_Locator_ID;
//
String sql = "SELECT M_Locator_ID FROM M_Locator "
+ "WHERE M_Warehouse_ID=? AND IsActive='Y' ORDER BY IsDefault DESC, Created";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getM_Warehouse_ID());
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
m_M_Locator_ID = rs.getInt(1);
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "getM_Locator_ID", ex);
}
try
{
if (pstmt != null)
pstmt.close ();
}
catch (SQLException ex1)
{
}
pstmt = null;
//
return m_M_Locator_ID;
} // getM_Locator_ID
/**
* Set Processed.
* Propergate to Lines/Taxes
* @param processed processed
*/
public void setProcessed (boolean processed)
{
super.setProcessed (processed);
if (get_ID() == 0)
return;
String sql = "UPDATE S_TimeExpenseLine SET Processed='"
+ (processed ? "Y" : "N")
+ "' WHERE S_TimeExpense_ID=" + getS_TimeExpense_ID();
int noLine = DB.executeUpdate(sql, get_TrxName());
m_lines = null;
log.fine(processed + " - Lines=" + noLine);
} // setProcessed
/**
* Get Document Info
* @return document info
*/
public String getDocumentInfo()
{
return Msg.getElement(getCtx(), "S_TimeExpense_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? - AP (Reimbursement) Invoice
if (!MPeriod.isOpen(getCtx(), getDateReport(), MDocType.DOCBASETYPE_APInvoice))
{
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid;
}
MTimeExpenseLine[] lines = getLines(false);
if (lines.length == 0)
{
m_processMsg = "@NoLines@";
return DocAction.STATUS_Invalid;
}
// Add up Amounts
BigDecimal amt = Env.ZERO;
for (int i = 0; i < lines.length; i++)
{
MTimeExpenseLine line = lines[i];
amt = amt.add(line.getApprovalAmt());
}
setApprovalAmt(amt);
// Invoiced but no BP
for (int i = 0; i < lines.length; i++)
{
MTimeExpenseLine line = lines[i];
if (line.isInvoiced() && line.getC_BPartner_ID() == 0)
{
m_processMsg = "@Line@ " + line.getLine() + ": Invoiced, but no Business Partner";
return DocAction.STATUS_Invalid;
}
}
m_justPrepared = true;
if (!DOCACTION_Complete.equals(getDocAction()))
setDocAction(DOCACTION_Complete);
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());
// 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.
* Same as Close.
* @return true if success
*/
public boolean voidIt()
{
log.info("voidIt - " + toString());
return closeIt();
} // voidIt
/**
* Close Document.
* Cancel not delivered Qunatities
* @return true if success
*/
public boolean closeIt()
{
log.info("closeIt - " + toString());
// Close Not delivered Qty
// setDocAction(DOCACTION_None);
return true;
} // closeIt
/**
* Reverse Correction
* @return false
*/
public boolean reverseCorrectIt()
{
log.info("reverseCorrectIt - " + toString());
return false;
} // reverseCorrectionIt
/**
* Reverse Accrual - none
* @return false
*/
public boolean reverseAccrualIt()
{
log.info("reverseAccrualIt - " + toString());
return false;
} // reverseAccrualIt
/**
* Re-activate
* @return true if success
*/
public boolean reActivateIt()
{
log.info("reActivateIt - " + toString());
// setProcessed(false);
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(),"ApprovalAmt")).append("=").append(getApprovalAmt())
.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()
{
if (m_AD_User_ID != 0)
return m_AD_User_ID;
if (getC_BPartner_ID() != 0)
{
MUser[] users = MUser.getOfBPartner(getCtx(), getC_BPartner_ID());
if (users.length > 0)
{
m_AD_User_ID = users[0].getAD_User_ID();
return m_AD_User_ID;
}
}
return getCreatedBy();
} // getDoc_User_ID
/**
* Get Document Currency
* @return C_Currency_ID
*/
public int getC_Currency_ID()
{
MPriceList pl = MPriceList.get(getCtx(), getM_PriceList_ID(), get_TrxName());
return pl.getC_Currency_ID();
} // getC_Currency_ID
} // MTimeExpense
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -