From b45b1863c9c77d15456d970a790fcb58d10f6d24 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 10 Jan 2015 11:49:40 -0500 Subject: [PATCH] IDEMPIERE-2392 Posted status incorrect when reposting on a period closed --- .../src/org/compiere/model/MPeriod.java | 102 +++++++++++++++++- .../src/org/compiere/acct/AcctViewer.java | 28 +++-- .../org/adempiere/webui/acct/WAcctViewer.java | 7 ++ 3 files changed, 126 insertions(+), 11 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MPeriod.java b/org.adempiere.base/src/org/compiere/model/MPeriod.java index 525e92bed9..b2e4b35485 100644 --- a/org.adempiere.base/src/org/compiere/model/MPeriod.java +++ b/org.adempiere.base/src/org/compiere/model/MPeriod.java @@ -34,6 +34,7 @@ import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.TimeUtil; +import org.compiere.util.Util; /** * Calendar Period Model @@ -54,7 +55,7 @@ public class MPeriod extends X_C_Period /** * */ - private static final long serialVersionUID = -1636783790829454894L; + private static final long serialVersionUID = 769103495098446073L; /** * Get Period from Cache @@ -266,6 +267,105 @@ public class MPeriod extends X_C_Period return open; } // isOpen + /** + * Is standard Period Open - based on tableID+recordID (for IDEMPIERE-2392) + * @param ctx context + * @param tableID + * @param recordID + * @return true if open + */ + public static boolean isOpen (Properties ctx, int tableID, int recordID, String trxName) { + MTable table = MTable.get(ctx, tableID); + PO po = table.getPO(recordID, trxName); + + // obtain DateAcct + int idxdate = -1; + if ( tableID == MInventory.Table_ID + || tableID == MMovement.Table_ID + || tableID == MProduction.Table_ID) { + idxdate = po.get_ColumnIndex("MovementDate"); + } else if ( tableID == MRequisition.Table_ID) { + idxdate = po.get_ColumnIndex("DateDoc"); + } else if ( tableID == MBankStatement.Table_ID) { + idxdate = po.get_ColumnIndex("StatementDate"); + } else if ( tableID == MAllocationHdr.Table_ID + || tableID == MMatchInv.Table_ID + || tableID == MMatchPO.Table_ID) { + idxdate = po.get_ColumnIndex("DateTrx"); + } else { + idxdate = po.get_ColumnIndex("DateAcct"); + } + if (idxdate < 0) { + s_log.warning("Could not find DateAcct for " + table.getTableName()); + return true; + } + Timestamp dateAcct = null; + Object objts = po.get_Value(idxdate); + if (objts != null && objts instanceof Timestamp) { + dateAcct = (Timestamp) objts; + } else { + s_log.warning("Could not find DateAcct (null or not Timestamp) for " + table.getTableName()); + return true; + } + + // obtain DocBaseType + String docBaseType = null; + int idxdoctype = po.get_ColumnIndex("C_DocType_ID"); + if (idxdoctype < 0) { + if (tableID == MInventory.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_MaterialPhysicalInventory; + } else if (tableID == MProduction.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_MaterialProduction; + } else if (tableID == MRequisition.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_PurchaseRequisition; + } else if (tableID == MBankStatement.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_BankStatement; + } else if (tableID == MAllocationHdr.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_PaymentAllocation; + } else if (tableID == MMatchInv.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_MatchInvoice; + } else if (tableID == MMatchPO.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_MatchPO; + } else if ( tableID == MAssetAddition.Table_ID + || tableID == MAssetReval.Table_ID + || tableID == MAssetTransfer.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_GLJournal; + } else if ( tableID == MAssetDisposed.Table_ID + || tableID == MDepreciationExp.Table_ID) { + docBaseType = MDocType.DOCBASETYPE_GLDocument; // seems like a bug of fixed assets - must use GLJournal instead of GLDocument? + } else { + s_log.warning("Could not find C_DocType_ID for " + table.getTableName()); + return true; + } + } else { + Integer doctypeID = null; + Object objint = po.get_Value(idxdoctype); + if (objint != null && objint instanceof Integer) { + doctypeID = (Integer) objint; + } else { + s_log.warning("Could not find C_DocType_ID (null or not Integer) for " + table.getTableName()); + return true; + } + MDocType dt = MDocType.get(ctx, doctypeID); + docBaseType = dt.getDocBaseType(); + } + if (Util.isEmpty(docBaseType)) { + s_log.warning("Could not find DocBaseType for " + table.getTableName()); + return true; + } + + // obtain AD_Org_ID + int orgID = 0; + int idxorg = po.get_ColumnIndex("AD_Org_ID"); + if (idxorg < 0) { + s_log.warning("Could not find AD_Org_ID for " + table.getTableName()); + } else { + orgID = po.get_ValueAsInt(idxorg); + } + + return isOpen(ctx, dateAcct, docBaseType, orgID); + } // isOpen + /** * Find first Year Period of DateAcct based on Client Calendar * @param ctx context diff --git a/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewer.java b/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewer.java index f2de929674..c6a8dde7f4 100644 --- a/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewer.java +++ b/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewer.java @@ -43,6 +43,7 @@ import org.compiere.grid.ed.VDate; import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchemaElement; import org.compiere.model.MColumn; +import org.compiere.model.MPeriod; import org.compiere.model.X_C_AcctSchema_Element; import org.compiere.report.core.RModel; import org.compiere.report.core.RModelExcelExporter; @@ -777,17 +778,24 @@ public class AcctViewer extends CFrame private void actionRePost() { if (m_data.documentQuery - && m_data.AD_Table_ID != 0 && m_data.Record_ID != 0 - && ADialog.ask(m_data.WindowNo, this, "PostImmediate?")) + && m_data.AD_Table_ID != 0 && m_data.Record_ID != 0) { - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - boolean force = forcePost.isSelected(); - String error = AEnv.postImmediate (m_data.WindowNo, m_data.AD_Client_ID, - m_data.AD_Table_ID, m_data.Record_ID, force); - setCursor(Cursor.getDefaultCursor()); - if (error != null) - ADialog.error(0, this, "PostingError-N", error); - actionQuery(); + // IDEMPIERE-2392 + if (! MPeriod.isOpen(Env.getCtx(), m_data.AD_Table_ID, m_data.Record_ID, null)) { + ADialog.error(0, this, "Error", Msg.getMsg(Env.getCtx(), "PeriodClosed")); + return; + } + + if (ADialog.ask(m_data.WindowNo, this, "PostImmediate?")) { + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + boolean force = forcePost.isSelected(); + String error = AEnv.postImmediate (m_data.WindowNo, m_data.AD_Client_ID, + m_data.AD_Table_ID, m_data.Record_ID, force); + setCursor(Cursor.getDefaultCursor()); + if (error != null) + ADialog.error(0, this, "PostingError-N", error); + actionQuery(); + } } } // actionRePost diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java index dd60cbd76b..2b816d8dcc 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java @@ -55,6 +55,7 @@ import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchemaElement; import org.compiere.model.MColumn; import org.compiere.model.MFactAcct; +import org.compiere.model.MPeriod; import org.compiere.model.X_AD_CtxHelp; import org.compiere.model.X_C_AcctSchema_Element; import org.compiere.report.core.RModel; @@ -1285,6 +1286,12 @@ public class WAcctViewer extends Window implements EventListener if (m_data.documentQuery && m_data.AD_Table_ID != 0 && m_data.Record_ID != 0) { + // IDEMPIERE-2392 + if (! MPeriod.isOpen(Env.getCtx(), m_data.AD_Table_ID, m_data.Record_ID, null)) { + FDialog.error(0, WAcctViewer.this, "Error", Msg.getMsg(Env.getCtx(), "PeriodClosed")); + return; + } + FDialog.ask(m_data.WindowNo, this, "PostImmediate?", new Callback() { @Override