IDEMPIERE-2184 Implement correct usage for adjustment accounting periods
This commit is contained in:
parent
4977122513
commit
94703678e9
|
@ -437,20 +437,23 @@ public class MJournal extends X_GL_Journal implements DocAction
|
||||||
return DocAction.STATUS_Invalid;
|
return DocAction.STATUS_Invalid;
|
||||||
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
|
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
|
||||||
|
|
||||||
// Get Period
|
// Get Period
|
||||||
MPeriod period = MPeriod.get (getCtx(), getDateAcct(), getAD_Org_ID(), get_TrxName());
|
MPeriod period = (MPeriod) getC_Period();
|
||||||
if (period == null)
|
if (! period.isInPeriod(getDateAcct())) {
|
||||||
{
|
period = MPeriod.get (getCtx(), getDateAcct(), getAD_Org_ID(), get_TrxName());
|
||||||
log.warning("No Period for " + getDateAcct());
|
if (period == null)
|
||||||
m_processMsg = "@PeriodNotFound@";
|
{
|
||||||
return DocAction.STATUS_Invalid;
|
log.warning("No Period for " + getDateAcct());
|
||||||
}
|
m_processMsg = "@PeriodNotFound@";
|
||||||
// Standard Period
|
return DocAction.STATUS_Invalid;
|
||||||
if (period.getC_Period_ID() != getC_Period_ID()
|
}
|
||||||
&& period.isStandardPeriod())
|
// Standard Period
|
||||||
{
|
if (period.getC_Period_ID() != getC_Period_ID()
|
||||||
m_processMsg = "@PeriodNotValid@";
|
&& period.isStandardPeriod())
|
||||||
return DocAction.STATUS_Invalid;
|
{
|
||||||
|
m_processMsg = "@PeriodNotValid@";
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
boolean open = period.isOpen(dt.getDocBaseType(), getDateAcct());
|
boolean open = period.isOpen(dt.getDocBaseType(), getDateAcct());
|
||||||
if (!open)
|
if (!open)
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.I_C_ValidCombination;
|
import org.compiere.model.I_C_ValidCombination;
|
||||||
import org.compiere.model.MAcctSchemaElement;
|
import org.compiere.model.MAcctSchemaElement;
|
||||||
|
import org.compiere.model.MPeriod;
|
||||||
import org.compiere.model.MReportCube;
|
import org.compiere.model.MReportCube;
|
||||||
import org.compiere.print.MPrintFormat;
|
import org.compiere.print.MPrintFormat;
|
||||||
import org.compiere.print.MPrintFormatItem;
|
import org.compiere.print.MPrintFormatItem;
|
||||||
|
@ -80,6 +81,8 @@ public class FinReport extends SvrProcess
|
||||||
private int p_PA_Hierarchy_ID = 0;
|
private int p_PA_Hierarchy_ID = 0;
|
||||||
/** Optional report cube */
|
/** Optional report cube */
|
||||||
private int p_PA_ReportCube_ID = 0;
|
private int p_PA_ReportCube_ID = 0;
|
||||||
|
/** Exclude Adjustment Period */
|
||||||
|
private String p_AdjPeriodToExclude = "";
|
||||||
|
|
||||||
/** Start Time */
|
/** Start Time */
|
||||||
private long m_start = System.currentTimeMillis();
|
private long m_start = System.currentTimeMillis();
|
||||||
|
@ -192,6 +195,24 @@ public class FinReport extends SvrProcess
|
||||||
// Load Report Definition
|
// Load Report Definition
|
||||||
m_report = new MReport (getCtx(), getRecord_ID(), null);
|
m_report = new MReport (getCtx(), getRecord_ID(), null);
|
||||||
sb.append(" - ").append(m_report);
|
sb.append(" - ").append(m_report);
|
||||||
|
|
||||||
|
/* Exclude adjustment period
|
||||||
|
* - if the report period is standard
|
||||||
|
* - and there is an adjustment period with the same end date (on the same year)
|
||||||
|
*/
|
||||||
|
if (p_C_Period_ID > 0) {
|
||||||
|
MPeriod per = MPeriod.get(getCtx(), p_C_Period_ID);
|
||||||
|
if (MPeriod.PERIODTYPE_StandardCalendarPeriod.equals(per.getPeriodType())) {
|
||||||
|
int adjPeriodToExclude_ID = DB.getSQLValue(get_TrxName(),
|
||||||
|
"SELECT C_Period_ID FROM C_Period WHERE IsActive='Y' AND PeriodType=? AND EndDate=? AND C_Year_ID=?",
|
||||||
|
MPeriod.PERIODTYPE_AdjustmentPeriod, per.getEndDate(), per.getC_Year_ID());
|
||||||
|
if (adjPeriodToExclude_ID > 0) {
|
||||||
|
p_AdjPeriodToExclude = " C_Period_ID!=" + adjPeriodToExclude_ID + " AND ";
|
||||||
|
log.warning("Will Exclude Adjustment Period -> " + p_AdjPeriodToExclude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
setPeriods();
|
setPeriods();
|
||||||
sb.append(" - C_Period_ID=").append(p_C_Period_ID)
|
sb.append(" - C_Period_ID=").append(p_C_Period_ID)
|
||||||
|
@ -212,6 +233,15 @@ public class FinReport extends SvrProcess
|
||||||
{
|
{
|
||||||
if (log.isLoggable(Level.INFO)) log.info("C_Calendar_ID=" + m_report.getC_Calendar_ID());
|
if (log.isLoggable(Level.INFO)) log.info("C_Calendar_ID=" + m_report.getC_Calendar_ID());
|
||||||
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
|
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
|
||||||
|
|
||||||
|
// enable reporting on an adjustment period
|
||||||
|
if (p_C_Period_ID > 0) {
|
||||||
|
MPeriod per = MPeriod.get(getCtx(), p_C_Period_ID);
|
||||||
|
if (MPeriod.PERIODTYPE_AdjustmentPeriod.equals(per.getPeriodType())) {
|
||||||
|
today = per.getEndDate();
|
||||||
|
p_C_Period_ID = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
ArrayList<FinReportPeriod> list = new ArrayList<FinReportPeriod>();
|
ArrayList<FinReportPeriod> list = new ArrayList<FinReportPeriod>();
|
||||||
|
|
||||||
String sql = "SELECT p.C_Period_ID, p.Name, p.StartDate, p.EndDate, MIN(p1.StartDate) "
|
String sql = "SELECT p.C_Period_ID, p.Name, p.StartDate, p.EndDate, MIN(p1.StartDate) "
|
||||||
|
@ -370,10 +400,10 @@ public class FinReport extends SvrProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_PA_ReportCube_ID > 0)
|
if (p_PA_ReportCube_ID > 0)
|
||||||
select.append(" FROM Fact_Acct_Summary fa WHERE DateAcct ");
|
select.append(" FROM Fact_Acct_Summary fa WHERE ").append(p_AdjPeriodToExclude).append("DateAcct ");
|
||||||
else {
|
else {
|
||||||
// Get Period/Date info
|
// Get Period/Date info
|
||||||
select.append(" FROM Fact_Acct fa WHERE TRUNC(DateAcct) ");
|
select.append(" FROM Fact_Acct fa WHERE ").append(p_AdjPeriodToExclude).append("TRUNC(DateAcct) ");
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal relativeOffset = null; // current
|
BigDecimal relativeOffset = null; // current
|
||||||
|
@ -1314,11 +1344,11 @@ public class FinReport extends SvrProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_PA_ReportCube_ID > 0) {
|
if (p_PA_ReportCube_ID > 0) {
|
||||||
select.append(" FROM Fact_Acct_Summary fb WHERE DateAcct ");
|
select.append(" FROM Fact_Acct_Summary fb WHERE ").append(p_AdjPeriodToExclude).append("DateAcct ");
|
||||||
} //report cube
|
} //report cube
|
||||||
else {
|
else {
|
||||||
// Get Period info
|
// Get Period info
|
||||||
select.append(" FROM Fact_Acct fb WHERE TRUNC(DateAcct) ");
|
select.append(" FROM Fact_Acct fb WHERE ").append(p_AdjPeriodToExclude).append("TRUNC(DateAcct) ");
|
||||||
}
|
}
|
||||||
FinReportPeriod frp = getPeriod (m_columns[col].getRelativePeriod());
|
FinReportPeriod frp = getPeriod (m_columns[col].getRelativePeriod());
|
||||||
if (m_lines[line].getPAPeriodType() != null) // line amount type overwrites column
|
if (m_lines[line].getPAPeriodType() != null) // line amount type overwrites column
|
||||||
|
@ -1364,7 +1394,7 @@ public class FinReport extends SvrProcess
|
||||||
select.append(" AND ").append(s);
|
select.append(" AND ").append(s);
|
||||||
// Limited Segment Values
|
// Limited Segment Values
|
||||||
if (m_columns[col].isColumnTypeSegmentValue())
|
if (m_columns[col].isColumnTypeSegmentValue())
|
||||||
select.append(m_columns[col].getWhereClause(p_PA_Hierarchy_ID));
|
select.append(m_columns[col].getWhereClause(p_PA_Hierarchy_ID));
|
||||||
|
|
||||||
// Parameter Where
|
// Parameter Where
|
||||||
select.append(m_parameterWhere);
|
select.append(m_parameterWhere);
|
||||||
|
@ -1373,7 +1403,7 @@ public class FinReport extends SvrProcess
|
||||||
//
|
//
|
||||||
insert.append("(").append(select).append(")");
|
insert.append("(").append(select).append(")");
|
||||||
}
|
}
|
||||||
// WHERE (sources, posting type)
|
// WHERE (sources, posting type)
|
||||||
StringBuffer where = new StringBuffer(m_lines[line].getWhereClause(p_PA_Hierarchy_ID));
|
StringBuffer where = new StringBuffer(m_lines[line].getWhereClause(p_PA_Hierarchy_ID));
|
||||||
|
|
||||||
StringBuffer unionWhere = listSourceNoTrx ? new StringBuffer() : null;
|
StringBuffer unionWhere = listSourceNoTrx ? new StringBuffer() : null;
|
||||||
|
@ -1416,10 +1446,10 @@ public class FinReport extends SvrProcess
|
||||||
|
|
||||||
String s = m_report.getWhereClause();
|
String s = m_report.getWhereClause();
|
||||||
if (s != null && s.length() > 0)
|
if (s != null && s.length() > 0)
|
||||||
{
|
{
|
||||||
if (where.length() > 0)
|
if (where.length() > 0)
|
||||||
where.append(" AND ");
|
where.append(" AND ");
|
||||||
where.append(s);
|
where.append(s);
|
||||||
|
|
||||||
if (listSourceNoTrx)
|
if (listSourceNoTrx)
|
||||||
{
|
{
|
||||||
|
@ -1428,16 +1458,16 @@ public class FinReport extends SvrProcess
|
||||||
unionWhere.append(s);
|
unionWhere.append(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (where.length() > 0)
|
if (where.length() > 0)
|
||||||
where.append(" AND ");
|
where.append(" AND ");
|
||||||
where.append(variable).append(" IS NOT NULL");
|
where.append(variable).append(" IS NOT NULL");
|
||||||
|
|
||||||
if (p_PA_ReportCube_ID > 0)
|
if (p_PA_ReportCube_ID > 0)
|
||||||
insert.append(" FROM Fact_Acct_Summary x WHERE ").append(where);
|
insert.append(" FROM Fact_Acct_Summary x WHERE ").append(p_AdjPeriodToExclude).append(where);
|
||||||
else
|
else
|
||||||
// FROM .. WHERE
|
// FROM .. WHERE
|
||||||
insert.append(" FROM Fact_Acct x WHERE ").append(where);
|
insert.append(" FROM Fact_Acct x WHERE ").append(p_AdjPeriodToExclude).append(where);
|
||||||
//
|
//
|
||||||
insert.append(m_parameterWhere)
|
insert.append(m_parameterWhere)
|
||||||
.append(" GROUP BY ").append(variable);
|
.append(" GROUP BY ").append(variable);
|
||||||
|
@ -1448,9 +1478,9 @@ public class FinReport extends SvrProcess
|
||||||
unionWhere.append(variable).append(" IS NOT NULL");
|
unionWhere.append(variable).append(" IS NOT NULL");
|
||||||
unionWhere.append(" AND Account_ID not in (select Account_ID ");
|
unionWhere.append(" AND Account_ID not in (select Account_ID ");
|
||||||
if (p_PA_ReportCube_ID > 0)
|
if (p_PA_ReportCube_ID > 0)
|
||||||
unionWhere.append(" from Fact_Acct_Summary x WHERE ").append(where);
|
unionWhere.append(" from Fact_Acct_Summary x WHERE ").append(p_AdjPeriodToExclude).append(where);
|
||||||
else
|
else
|
||||||
unionWhere.append(" from Fact_Acct x WHERE ").append(where);
|
unionWhere.append(" from Fact_Acct x WHERE ").append(p_AdjPeriodToExclude).append(where);
|
||||||
//
|
//
|
||||||
unionWhere.append(m_parameterWhere).append(")");
|
unionWhere.append(m_parameterWhere).append(")");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue