BF [ 1893486 ] Auto Period Control return that period is always open

This commit is contained in:
teo_sarca 2008-02-15 10:41:34 +00:00
parent a6554cc949
commit a289b6e501
4 changed files with 38 additions and 13 deletions

View File

@ -1097,7 +1097,7 @@ public abstract class Doc
m_period = MPeriod.get(getCtx(), getDateAcct()); m_period = MPeriod.get(getCtx(), getDateAcct());
// Is Period Open? // Is Period Open?
if (m_period != null if (m_period != null
&& m_period.isOpen(getDocumentType())) && m_period.isOpen(getDocumentType(), getDateAcct()))
m_C_Period_ID = m_period.getC_Period_ID(); m_C_Period_ID = m_period.getC_Period_ID();
else else
m_C_Period_ID = -1; m_C_Period_ID = -1;

View File

@ -98,7 +98,7 @@ public class Doc_Bank extends Doc
if (i == 0) if (i == 0)
setDateAcct(line.getDateAcct()); setDateAcct(line.getDateAcct());
MPeriod period = MPeriod.get(getCtx(), line.getDateAcct()); MPeriod period = MPeriod.get(getCtx(), line.getDateAcct());
if (period != null && period.isOpen(DOCTYPE_BankStatement)) if (period != null && period.isOpen(DOCTYPE_BankStatement, line.getDateAcct()))
docLine.setC_Period_ID(period.getC_Period_ID()); docLine.setC_Period_ID(period.getC_Period_ID());
// //
list.add(docLine); list.add(docLine);

View File

@ -428,7 +428,7 @@ public class MJournal extends X_GL_Journal implements DocAction
m_processMsg = "@PeriodNotValid@"; m_processMsg = "@PeriodNotValid@";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
boolean open = period.isOpen(dt.getDocBaseType()); boolean open = period.isOpen(dt.getDocBaseType(), getDateAcct());
if (!open) if (!open)
{ {
log.warning(period.getName() log.warning(period.getName()

View File

@ -29,6 +29,7 @@ import org.compiere.util.*;
* *
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1779438 ] Minor auto period control bug * <li>BF [ 1779438 ] Minor auto period control bug
* <li>BF [ 1893486 ] Auto Period Control return that period is always open
*/ */
public class MPeriod extends X_C_Period public class MPeriod extends X_C_Period
{ {
@ -148,7 +149,7 @@ public class MPeriod extends X_C_Period
s_log.warning("No Period for " + DateAcct + " (" + DocBaseType + ")"); s_log.warning("No Period for " + DateAcct + " (" + DocBaseType + ")");
return false; return false;
} }
boolean open = period.isOpen(DocBaseType); boolean open = period.isOpen(DocBaseType, DateAcct);
if (!open) if (!open)
s_log.warning(period.getName() s_log.warning(period.getName()
+ ": Not open for " + DocBaseType + " (" + DateAcct + ")"); + ": Not open for " + DocBaseType + " (" + DateAcct + ")");
@ -340,11 +341,27 @@ public class MPeriod extends X_C_Period
} // isInPeriod } // isInPeriod
/** /**
* Is Period Open for Doc Base Type * Is Period Open for Doc Base Type
* @param DocBaseType document base type * @param DocBaseType document base type
* @return true if open * @return true if open
* @deprecated since 3.3.1b; use {@link #isOpen(String, Timestamp)} instead
*/ */
public boolean isOpen (String DocBaseType) public boolean isOpen (String DocBaseType)
{
return isOpen(DocBaseType, null);
}
/**
* Is Period Open for Doc Base Type
* @param DocBaseType document base type
* @param dateAcct date;
* Applies only for "Auto Period Control":
* <li>if not null, date should be in auto period range (today - OpenHistory, today+OpenHistory)
* <li>if null, this period should be in auto period range
* @return true if open
* @since 3.3.1b
*/
public boolean isOpen (String DocBaseType, Timestamp dateAcct)
{ {
if (!isActive()) if (!isActive())
{ {
@ -355,19 +372,27 @@ public class MPeriod extends X_C_Period
MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema(); MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();
if (as != null && as.isAutoPeriodControl()) if (as != null && as.isAutoPeriodControl())
{ {
// if (as.getC_Period_ID() == getC_Period_ID())
// return true;
Timestamp today = TimeUtil.trunc(new Timestamp (System.currentTimeMillis()), TimeUtil.TRUNC_DAY); Timestamp today = TimeUtil.trunc(new Timestamp (System.currentTimeMillis()), TimeUtil.TRUNC_DAY);
Timestamp first = TimeUtil.addDays(today, - as.getPeriod_OpenHistory()); Timestamp first = TimeUtil.addDays(today, - as.getPeriod_OpenHistory());
Timestamp last = TimeUtil.addDays(today, as.getPeriod_OpenFuture()); Timestamp last = TimeUtil.addDays(today, as.getPeriod_OpenFuture());
if (today.before(first)) Timestamp date1, date2;
if (dateAcct != null) {
date1 = TimeUtil.trunc(dateAcct, TimeUtil.TRUNC_DAY);
date2 = date1;
}
else {
date1 = getStartDate();
date2 = getEndDate();
}
//
if (date1.before(first))
{ {
log.warning ("Today before first day - " + first); log.warning ("" + date1 + " before first day - " + first);
return false; return false;
} }
if (today.after(last)) if (date2.after(last))
{ {
log.warning ("Today after last day - " + first); log.warning ("" + date2 + " after last day - " + first);
return false; return false;
} }
// We are OK // We are OK