📄 mjournal.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.*;
/**
* GL Journal Model
*
* @author Jorg Janke
* @version $Id: MJournal.java,v 1.30 2005/12/19 01:16:46 jjanke Exp $
*/
public class MJournal extends X_GL_Journal implements DocAction
{
/**
* Standard Constructor
* @param ctx context
* @param GL_Journal_ID id
*/
public MJournal (Properties ctx, int GL_Journal_ID, String trxName)
{
super (ctx, GL_Journal_ID, trxName);
if (GL_Journal_ID == 0)
{
// setGL_Journal_ID (0); // PK
// setC_AcctSchema_ID (0);
// setC_Currency_ID (0);
// setC_DocType_ID (0);
// setC_Period_ID (0);
//
setCurrencyRate (Env.ONE);
// setC_ConversionType_ID(0);
setDateAcct (new Timestamp(System.currentTimeMillis()));
setDateDoc (new Timestamp(System.currentTimeMillis()));
// setDescription (null);
setDocAction (DOCACTION_Complete);
setDocStatus (DOCSTATUS_Drafted);
// setDocumentNo (null);
// setGL_Category_ID (0);
setPostingType (POSTINGTYPE_Actual);
setTotalCr (Env.ZERO);
setTotalDr (Env.ZERO);
setIsApproved (false);
setIsPrinted (false);
setPosted (false);
setProcessed(false);
}
} // MJournal
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MJournal (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MJournal
/**
* Parent Constructor.
* @param parent batch
*/
public MJournal (MJournalBatch parent)
{
this (parent.getCtx(), 0, parent.get_TrxName());
setClientOrg(parent);
setGL_JournalBatch_ID(parent.getGL_JournalBatch_ID());
setC_DocType_ID(parent.getC_DocType_ID());
setPostingType(parent.getPostingType());
//
setDateDoc(parent.getDateDoc());
setC_Period_ID(parent.getC_Period_ID());
setDateAcct(parent.getDateAcct());
setC_Currency_ID(parent.getC_Currency_ID());
} // MJournal
/**
* Copy Constructor.
* Dos not copy: Dates/Period
* @param original original
*/
public MJournal (MJournal original)
{
this (original.getCtx(), 0, original.get_TrxName());
setClientOrg(original);
setGL_JournalBatch_ID(original.getGL_JournalBatch_ID());
//
setC_AcctSchema_ID(original.getC_AcctSchema_ID());
setGL_Budget_ID(original.getGL_Budget_ID());
setGL_Category_ID(original.getGL_Category_ID());
setPostingType(original.getPostingType());
setDescription(original.getDescription());
setC_DocType_ID(original.getC_DocType_ID());
setControlAmt(original.getControlAmt());
//
setC_Currency_ID(original.getC_Currency_ID());
setC_ConversionType_ID(original.getC_ConversionType_ID());
setCurrencyRate(original.getCurrencyRate());
// setDateDoc(original.getDateDoc());
// setDateAcct(original.getDateAcct());
// setC_Period_ID(original.getC_Period_ID());
} // MJournal
/**
* Overwrite Client/Org if required
* @param AD_Client_ID client
* @param AD_Org_ID org
*/
public void setClientOrg (int AD_Client_ID, int AD_Org_ID)
{
super.setClientOrg(AD_Client_ID, AD_Org_ID);
} // setClientOrg
/**
* Set Accounting Date.
* Set also Period if not set earlier
* @param DateAcct date
*/
public void setDateAcct (Timestamp DateAcct)
{
super.setDateAcct(DateAcct);
if (DateAcct == null)
return;
if (getC_Period_ID() != 0)
return;
int C_Period_ID = MPeriod.getC_Period_ID(getCtx(), DateAcct);
if (C_Period_ID == 0)
log.warning("setDateAcct - Period not found");
else
setC_Period_ID(C_Period_ID);
} // setDateAcct
/**
* Set Currency Info
* @param C_Currency_ID currenct
* @param C_ConversionType_ID type
* @param CurrencyRate rate
*/
public void setCurrency (int C_Currency_ID, int C_ConversionType_ID, BigDecimal CurrencyRate)
{
if (C_Currency_ID != 0)
setC_Currency_ID(C_Currency_ID);
if (C_ConversionType_ID != 0)
setC_ConversionType_ID(C_ConversionType_ID);
if (CurrencyRate != null && CurrencyRate.compareTo(Env.ZERO) == 0)
setCurrencyRate(CurrencyRate);
} // setCurrency
/**************************************************************************
* Get Journal Lines
* @param requery requery
* @return Array of lines
*/
public MJournalLine[] getLines (boolean requery)
{
ArrayList<MJournalLine> list = new ArrayList<MJournalLine>();
String sql = "SELECT * FROM GL_JournalLine WHERE GL_Journal_ID=? ORDER BY Line";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getGL_Journal_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MJournalLine (getCtx(), rs, get_TrxName()));
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;
//
MJournalLine[] retValue = new MJournalLine[list.size()];
list.toArray(retValue);
return retValue;
} // getLines
/**
* Copy Lines from other Journal
* @param fromJournal Journal
* @param dateAcct date used - if null original
* @param typeCR type of copying (C)orrect=negate - (R)everse=flip dr/cr - otherwise just copy
* @return number of lines copied
*/
public int copyLinesFrom (MJournal fromJournal, Timestamp dateAcct, char typeCR)
{
if (isProcessed() || fromJournal == null)
return 0;
int count = 0;
MJournalLine[] fromLines = fromJournal.getLines(false);
for (int i = 0; i < fromLines.length; i++)
{
MJournalLine toLine = new MJournalLine (getCtx(), 0, fromJournal.get_TrxName());
PO.copyValues(fromLines[i], toLine, getAD_Client_ID(), getAD_Org_ID());
toLine.setGL_Journal_ID(getGL_Journal_ID());
//
if (dateAcct != null)
toLine.setDateAcct(dateAcct);
// Amounts
if (typeCR == 'C') // correct
{
toLine.setAmtSourceDr(fromLines[i].getAmtSourceDr().negate());
toLine.setAmtSourceCr(fromLines[i].getAmtSourceCr().negate());
}
else if (typeCR == 'R') // reverse
{
toLine.setAmtSourceDr(fromLines[i].getAmtSourceCr());
toLine.setAmtSourceCr(fromLines[i].getAmtSourceDr());
}
toLine.setIsGenerated(true);
toLine.setProcessed(false);
if (toLine.save())
count++;
}
if (fromLines.length != count)
log.log(Level.SEVERE, "copyLinesFrom - Line difference - JournalLines=" + fromLines.length + " <> Saved=" + count);
return count;
} // copyLinesFrom
/**
* 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 GL_JournalLine SET Processed='"
+ (processed ? "Y" : "N")
+ "' WHERE GL_Journal_ID=" + getGL_Journal_ID();
int noLine = DB.executeUpdate(sql, get_TrxName());
log.fine(processed + " - Lines=" + noLine);
} // setProcessed
/**************************************************************************
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
// Imported Journals may not have date
if (getDateDoc() == null)
{
if (getDateAcct() == null)
setDateDoc(new Timestamp(System.currentTimeMillis()));
else
setDateDoc(getDateAcct());
}
if (getDateAcct() == null)
setDateAcct(getDateDoc());
return true;
} // beforeSave
/**
* After Save.
* Update Batch Total
* @param newRecord true if new record
* @param success true if success
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (!success)
return success;
return updateBatch();
} // afterSave
/**
* After Delete
* @param success true if deleted
* @return true if success
*/
protected boolean afterDelete (boolean success)
{
if (!success)
return success;
return updateBatch();
} // afterDelete
/**
* Update Batch total
* @return true if ok
*/
private boolean updateBatch()
{
String sql = "UPDATE GL_JournalBatch jb"
+ " SET (TotalDr, TotalCr) = (SELECT COALESCE(SUM(TotalDr),0), COALESCE(SUM(TotalCr),0)"
+ " FROM GL_Journal j WHERE j.IsActive='Y' AND jb.GL_JournalBatch_ID=j.GL_JournalBatch_ID) "
+ "WHERE GL_JournalBatch_ID=" + getGL_JournalBatch_ID();
int no = DB.executeUpdate(sql, get_TrxName());
if (no != 1)
log.warning("afterSave - Update Batch #" + no);
return no == 1;
} // updateBatch
/**************************************************************************
* 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(toString());
setProcessing(false);
return true;
} // unlockIt
/**
* Invalidate Document
* @return true if success
*/
public boolean invalidateIt()
{
log.info(toString());
return true;
} // invalidateIt
/**
* Prepare Document
* @return new status (In Progress or Invalid)
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -