IDEMPIERE-3874 Process Recalculate Cube not loading GL journal facts due to c_calendar_id

This commit is contained in:
Heng Sin Low 2019-04-17 16:30:05 +08:00
parent df2fb4b8e6
commit b7bd22da94
6 changed files with 136 additions and 11 deletions

View File

@ -0,0 +1,30 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-3874 Process Recalculate Cube not loading GL journal facts due to c_calendar_id
-- Apr 17, 2019, 4:14:39 PM MYT
INSERT INTO AD_Val_Rule (AD_Val_Rule_ID,Name,Type,Code,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Val_Rule_UU) VALUES (200134,'C_Period Open For OrgInfo/ClientInfo Calendar','S','((EXISTS (SELECT 1 FROM C_Period a
JOIN C_Year b ON a.C_Year_ID=b.C_Year_ID
JOIN C_Calendar c ON b.C_Calendar_ID=c.C_Calendar_ID
WHERE ((c.C_Calendar_ID=(SELECT AD_OrgInfo.C_Calendar_ID FROM AD_OrgInfo WHERE AD_OrgInfo.AD_Org_ID=@AD_Org_ID@)) OR
((EXISTS (SELECT 1 FROM AD_OrgInfo WHERE AD_OrgInfo.AD_Org_ID=@AD_Org_ID@ AND AD_OrgInfo.C_Calendar_ID IS NULL)) AND
(c.C_Calendar_ID=(SELECT AD_ClientInfo.C_Calendar_ID FROM AD_ClientInfo WHERE AD_ClientInfo.AD_Client_ID=@#AD_Client_ID@))))
AND a.IsActive=''Y'' AND b.IsActive=''Y'' AND a.C_Period_ID=C_Period.C_Period_ID)) AND
(EXISTS ( SELECT * FROM C_PeriodControl pc WHERE C_Period.C_Period_ID = pc.C_Period_ID AND pc.PeriodStatus = ''O'')
OR EXISTS ( SELECT * FROM C_AcctSchema a, C_Period p WHERE C_Period.C_Period_ID = p.C_Period_ID AND a.AutoPeriodControl = ''Y''
AND a.C_AcctSchema_ID=@C_AcctSchema_ID@
AND ( (p.StartDate BETWEEN SYSDATE - a.Period_OpenHistory AND SYSDATE + a.Period_OpenFuture)
OR (p.EndDate BETWEEN SYSDATE - a.Period_OpenHistory AND SYSDATE + a.Period_OpenFuture)))))',0,0,'Y',TO_DATE('2019-04-17 16:14:38','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-04-17 16:14:38','YYYY-MM-DD HH24:MI:SS'),100,'D','017034e9-6be4-4810-9aa1-88d4aa044def')
;
-- Apr 17, 2019, 4:15:57 PM MYT
UPDATE AD_Column SET AD_Val_Rule_ID=200134,Updated=TO_DATE('2019-04-17 16:15:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=1654
;
-- Apr 17, 2019, 4:16:43 PM MYT
UPDATE AD_Column SET AD_Val_Rule_ID=200134,Updated=TO_DATE('2019-04-17 16:16:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=1636
;
SELECT register_migration_script('201904171500_IDEMPIERE-3874.sql') FROM dual
;

View File

@ -0,0 +1,27 @@
-- IDEMPIERE-3874 Process Recalculate Cube not loading GL journal facts due to c_calendar_id
-- Apr 17, 2019, 4:14:39 PM MYT
INSERT INTO AD_Val_Rule (AD_Val_Rule_ID,Name,Type,Code,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Val_Rule_UU) VALUES (200134,'C_Period Open For OrgInfo/ClientInfo Calendar','S','((EXISTS (SELECT 1 FROM C_Period a
JOIN C_Year b ON a.C_Year_ID=b.C_Year_ID
JOIN C_Calendar c ON b.C_Calendar_ID=c.C_Calendar_ID
WHERE ((c.C_Calendar_ID=(SELECT AD_OrgInfo.C_Calendar_ID FROM AD_OrgInfo WHERE AD_OrgInfo.AD_Org_ID=@AD_Org_ID@)) OR
((EXISTS (SELECT 1 FROM AD_OrgInfo WHERE AD_OrgInfo.AD_Org_ID=@AD_Org_ID@ AND AD_OrgInfo.C_Calendar_ID IS NULL)) AND
(c.C_Calendar_ID=(SELECT AD_ClientInfo.C_Calendar_ID FROM AD_ClientInfo WHERE AD_ClientInfo.AD_Client_ID=@#AD_Client_ID@))))
AND a.IsActive=''Y'' AND b.IsActive=''Y'' AND a.C_Period_ID=C_Period.C_Period_ID)) AND
(EXISTS ( SELECT * FROM C_PeriodControl pc WHERE C_Period.C_Period_ID = pc.C_Period_ID AND pc.PeriodStatus = ''O'')
OR EXISTS ( SELECT * FROM C_AcctSchema a, C_Period p WHERE C_Period.C_Period_ID = p.C_Period_ID AND a.AutoPeriodControl = ''Y''
AND a.C_AcctSchema_ID=@C_AcctSchema_ID@
AND ( (p.StartDate BETWEEN SYSDATE - a.Period_OpenHistory AND SYSDATE + a.Period_OpenFuture)
OR (p.EndDate BETWEEN SYSDATE - a.Period_OpenHistory AND SYSDATE + a.Period_OpenFuture)))))',0,0,'Y',TO_TIMESTAMP('2019-04-17 16:14:38','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-04-17 16:14:38','YYYY-MM-DD HH24:MI:SS'),100,'D','017034e9-6be4-4810-9aa1-88d4aa044def')
;
-- Apr 17, 2019, 4:15:57 PM MYT
UPDATE AD_Column SET AD_Val_Rule_ID=200134,Updated=TO_TIMESTAMP('2019-04-17 16:15:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=1654
;
-- Apr 17, 2019, 4:16:43 PM MYT
UPDATE AD_Column SET AD_Val_Rule_ID=200134,Updated=TO_TIMESTAMP('2019-04-17 16:16:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=1636
;
SELECT register_migration_script('201904171500_IDEMPIERE-3874.sql') FROM dual
;

View File

@ -75,8 +75,7 @@ public class CalloutGLJournal extends CalloutEngine
String sql = "SELECT C_Period_ID "
+ "FROM C_Period "
+ "WHERE C_Year_ID IN "
+ " (SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID ="
+ " (SELECT C_Calendar_ID FROM AD_ClientInfo WHERE AD_Client_ID=?))"
+ " (SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID=?)"
+ " AND ? BETWEEN StartDate AND EndDate"
// globalqss - cruiz - Bug [ 1577712 ] Financial Period Bug
+ " AND IsActive='Y'"
@ -86,7 +85,9 @@ public class CalloutGLJournal extends CalloutEngine
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID);
int AD_Org_ID = mTab.getValue("AD_Org_ID") != null ? ((Number)mTab.getValue("AD_Org_ID")).intValue() : 0;
int C_Calendar_ID = MPeriod.getC_Calendar_ID(ctx, AD_Org_ID);
pstmt.setInt(1, C_Calendar_ID);
pstmt.setTimestamp(2, DateAcct);
rs = pstmt.executeQuery();
if (rs.next())

View File

@ -26,7 +26,9 @@ import java.util.logging.Level;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
@ -169,12 +171,10 @@ public class MJournal extends X_GL_Journal implements DocAction
super.setDateAcct(DateAcct);
if (DateAcct == null)
return;
if (getC_Period_ID() != 0)
return;
int C_Period_ID = MPeriod.getC_Period_ID(getCtx(), DateAcct, getAD_Org_ID());
if (C_Period_ID == 0)
log.warning("setDateAcct - Period not found");
else
log.saveError("PeriodNotFound", " : " + DisplayType.getDateFormat().format(getDateAcct()));
else if (C_Period_ID != getC_Period_ID())
setC_Period_ID(C_Period_ID);
} // setDateAcct
@ -306,7 +306,25 @@ public class MJournal extends X_GL_Journal implements DocAction
setDateDoc(getDateAcct());
}
if (getDateAcct() == null)
{
setDateAcct(getDateDoc());
if (CLogger.peekError() != null)
return false;
}
else if (!isProcessed())
{
//validate period
int C_Period_ID = MPeriod.getC_Period_ID(getCtx(), getDateAcct(), getAD_Org_ID());
if (C_Period_ID == 0)
{
log.saveError("PeriodNotFound", " : " + DisplayType.getDateFormat().format(getDateAcct()));
return false;
}
else if (C_Period_ID != getC_Period_ID())
{
setC_Period_ID(C_Period_ID);
}
}
// IDEMPIERE-63
// for documents that can be reactivated we cannot allow changing

View File

@ -29,7 +29,9 @@ import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
@ -176,12 +178,10 @@ public class MJournalBatch extends X_GL_JournalBatch implements DocAction
super.setDateAcct(DateAcct);
if (DateAcct == null)
return;
if (getC_Period_ID() != 0)
return;
int C_Period_ID = MPeriod.getC_Period_ID(getCtx(), DateAcct, getAD_Org_ID());
if (C_Period_ID == 0)
log.warning("Period not found");
else
log.saveError("PeriodNotFound", " : " + DisplayType.getDateFormat().format(getDateAcct()));
else if (C_Period_ID != getC_Period_ID())
setC_Period_ID(C_Period_ID);
} // setDateAcct
@ -921,4 +921,43 @@ public class MJournalBatch extends X_GL_JournalBatch implements DocAction
setDescription(msgd.toString());
}
}
/**************************************************************************
* Before Save
* @param newRecord new
* @return true
*/
@Override
protected boolean beforeSave (boolean newRecord)
{
if (getDateDoc() == null)
{
if (getDateAcct() == null)
setDateDoc(new Timestamp(System.currentTimeMillis()));
else
setDateDoc(getDateAcct());
}
if (getDateAcct() == null)
{
setDateAcct(getDateDoc());
if (CLogger.peekError() != null)
return false;
}
else if (!isProcessed())
{
//validate period
int C_Period_ID = MPeriod.getC_Period_ID(getCtx(), getDateAcct(), getAD_Org_ID());
if (C_Period_ID == 0)
{
log.saveError("PeriodNotFound", " : " + DisplayType.getDateFormat().format(getDateAcct()));
return false;
}
else if (C_Period_ID != getC_Period_ID())
{
setC_Period_ID(C_Period_ID);
}
}
return true;
}
} // MJournalBatch

View File

@ -196,6 +196,16 @@ public class CLogger extends Logger implements Serializable
return vp;
} // retrieveError
/**
* Peek Error from Stack
* @return AD_Message as Value and Message as String
*/
public static ValueNamePair peekError()
{
ValueNamePair vp = (ValueNamePair) Env.getCtx().get(LAST_ERROR);
return vp;
} // retrieveError
/**
* Get Error message from stack
* @param defaultMsg default message (used when there are no errors on stack)