1) Implemented DocFactory as extension, this does break backward compatibility as the Doc class now take MAcctSchema instead of MAcctSchema[] as parameter. 2) Refactor the posting control and create financial document from Doc.java to DocManager.java
This commit is contained in:
parent
6d2d70f7af
commit
c321e8feb6
|
@ -38,7 +38,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.acct.Doc;
|
import org.compiere.acct.DocManager;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
import org.compiere.model.MClient;
|
import org.compiere.model.MClient;
|
||||||
import org.compiere.model.MCost;
|
import org.compiere.model.MCost;
|
||||||
|
@ -134,8 +134,8 @@ public class ClientAcctProcessor extends SvrProcess
|
||||||
BigDecimal value = new BigDecimal(Long.toString(mili));
|
BigDecimal value = new BigDecimal(Long.toString(mili));
|
||||||
|
|
||||||
//first pass, collect all ts (FR 2962094 - required for weighted average costing)
|
//first pass, collect all ts (FR 2962094 - required for weighted average costing)
|
||||||
int[] documentsTableID = Doc.getDocumentsTableID();
|
int[] documentsTableID = DocManager.getDocumentsTableID();
|
||||||
String[] documentsTableName = Doc.getDocumentsTableName();
|
String[] documentsTableName = DocManager.getDocumentsTableName();
|
||||||
for (int i = 0; i < documentsTableID.length; i++)
|
for (int i = 0; i < documentsTableID.length; i++)
|
||||||
{
|
{
|
||||||
int AD_Table_ID = documentsTableID[i];
|
int AD_Table_ID = documentsTableID[i];
|
||||||
|
@ -220,21 +220,11 @@ public class ClientAcctProcessor extends SvrProcess
|
||||||
// Run every posting document in own transaction
|
// Run every posting document in own transaction
|
||||||
String innerTrxName = Trx.createTrxName("CAP");
|
String innerTrxName = Trx.createTrxName("CAP");
|
||||||
Trx innerTrx = Trx.get(innerTrxName, true);
|
Trx innerTrx = Trx.get(innerTrxName, true);
|
||||||
String postStatus = Doc.STATUS_NotPosted;
|
|
||||||
Doc doc = Doc.get (m_ass, AD_Table_ID, rs, innerTrxName);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (doc == null)
|
String error = DocManager.postDocument(m_ass, AD_Table_ID, rs, false, false, innerTrxName);
|
||||||
{
|
ok = (error == null);
|
||||||
log.severe(getName() + ": No Doc for " + TableName);
|
|
||||||
ok = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String error = doc.post(false, false); // post no force/repost
|
|
||||||
ok = (error == null);
|
|
||||||
postStatus = doc.getPostStatus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -243,18 +233,7 @@ public class ClientAcctProcessor extends SvrProcess
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (ok)
|
innerTrx.commit();
|
||||||
innerTrx.commit();
|
|
||||||
else {
|
|
||||||
innerTrx.rollback();
|
|
||||||
// save the posted status error (out of trx)
|
|
||||||
StringBuffer sqlupd = new StringBuffer("UPDATE ")
|
|
||||||
.append(doc.get_TableName()).append(" SET Posted='").append(postStatus)
|
|
||||||
.append("',Processing='N' ")
|
|
||||||
.append("WHERE ")
|
|
||||||
.append(doc.get_TableName()).append("_ID=").append(doc.get_ID());
|
|
||||||
DB.executeUpdateEx(sqlupd.toString(), null);
|
|
||||||
}
|
|
||||||
innerTrx.close();
|
innerTrx.close();
|
||||||
innerTrx = null;
|
innerTrx = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<extension-point id="org.compiere.interfaces.Server" name="Server Interface" schema="schema/org.compiere.interfaces.Server.exsd"/>
|
<extension-point id="org.compiere.interfaces.Server" name="Server Interface" schema="schema/org.compiere.interfaces.Server.exsd"/>
|
||||||
<extension-point id="org.compiere.interfaces.Status" name="Status interface" schema="schema/org.compiere.interfaces.Status.exsd"/>
|
<extension-point id="org.compiere.interfaces.Status" name="Status interface" schema="schema/org.compiere.interfaces.Status.exsd"/>
|
||||||
<extension-point id="org.adempiere.base.IModelFactory" name="Model Factory" schema="schema/org.adempiere.base.IModelFactory.exsd"/>
|
<extension-point id="org.adempiere.base.IModelFactory" name="Model Factory" schema="schema/org.adempiere.base.IModelFactory.exsd"/>
|
||||||
|
<extension-point id="org.adempiere.base.IDocFactory" name="Financial Document Factory" schema="schema/org.adempiere.base.IDocFactory.exsd"/>
|
||||||
<extension
|
<extension
|
||||||
id="org.adempiere.base.DefaultModelFactory"
|
id="org.adempiere.base.DefaultModelFactory"
|
||||||
name="Default model factory"
|
name="Default model factory"
|
||||||
|
@ -19,5 +20,13 @@
|
||||||
priority="0">
|
priority="0">
|
||||||
</factory>
|
</factory>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.adempiere.base.IDocFactory">
|
||||||
|
<factory
|
||||||
|
class="org.adempiere.base.DefaultDocumentFactory"
|
||||||
|
gaap="*"
|
||||||
|
priority="0">
|
||||||
|
</factory>
|
||||||
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<!-- Schema file written by PDE -->
|
||||||
|
<schema targetNamespace="org.adempiere.base" xmlns="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<annotation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.schema plugin="org.adempiere.base" id="org.adempiere.base.IDocFactory" name="Financial Document Factory"/>
|
||||||
|
</appinfo>
|
||||||
|
<documentation>
|
||||||
|
[Enter description of this extension point.]
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
|
||||||
|
<element name="extension">
|
||||||
|
<annotation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.element />
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
<complexType>
|
||||||
|
<choice>
|
||||||
|
<element ref="factory"/>
|
||||||
|
</choice>
|
||||||
|
<attribute name="point" type="string" use="required">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="id" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="name" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute translatable="true"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
|
||||||
|
<element name="factory">
|
||||||
|
<complexType>
|
||||||
|
<attribute name="gaap" type="string" use="required">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
use * to match everything
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="priority" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="class" type="string" use="required">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute kind="java" basedOn=":org.adempiere.base.IDocFactory"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.section type="since"/>
|
||||||
|
</appinfo>
|
||||||
|
<documentation>
|
||||||
|
[Enter the first release in which this extension point appears.]
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.section type="examples"/>
|
||||||
|
</appinfo>
|
||||||
|
<documentation>
|
||||||
|
[Enter extension point usage example here.]
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.section type="apiinfo"/>
|
||||||
|
</appinfo>
|
||||||
|
<documentation>
|
||||||
|
[Enter API information here.]
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.section type="implementation"/>
|
||||||
|
</appinfo>
|
||||||
|
<documentation>
|
||||||
|
[Enter information about supplied implementation of this extension point.]
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
|
||||||
|
|
||||||
|
</schema>
|
|
@ -56,7 +56,7 @@
|
||||||
</documentation>
|
</documentation>
|
||||||
</annotation>
|
</annotation>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute name="class" type="string">
|
<attribute name="class" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
|
* Copyright (C) 2010 Heng Sin Low *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU General Public License for more details. *
|
||||||
|
* You should have received a copy of the GNU General Public License along *
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.adempiere.base;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.compiere.acct.Doc;
|
||||||
|
import org.compiere.model.MAcctSchema;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.util.AdempiereUserError;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author hengsin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DefaultDocumentFactory implements IDocFactory {
|
||||||
|
|
||||||
|
private final static CLogger s_log = CLogger.getCLogger(DefaultDocumentFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Doc getDocument(MAcctSchema as, int AD_Table_ID, int Record_ID,
|
||||||
|
String trxName) {
|
||||||
|
String tableName = MTable.getTableName(Env.getCtx(), AD_Table_ID);
|
||||||
|
//
|
||||||
|
Doc doc = null;
|
||||||
|
StringBuffer sql = new StringBuffer("SELECT * FROM ")
|
||||||
|
.append(tableName)
|
||||||
|
.append(" WHERE ").append(tableName).append("_ID=? AND Processed='Y'");
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt = DB.prepareStatement (sql.toString(), trxName);
|
||||||
|
pstmt.setInt (1, Record_ID);
|
||||||
|
rs = pstmt.executeQuery ();
|
||||||
|
if (rs.next ())
|
||||||
|
{
|
||||||
|
doc = getDocument(as, AD_Table_ID, rs, trxName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s_log.severe("Not Found: " + tableName + "_ID=" + Record_ID);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
s_log.log (Level.SEVERE, sql.toString(), e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null;
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Doc getDocument(MAcctSchema as, int AD_Table_ID, ResultSet rs,
|
||||||
|
String trxName) {
|
||||||
|
Doc doc = null;
|
||||||
|
|
||||||
|
/* Classname of the Doc class follows this convention:
|
||||||
|
* if the prefix (letters before the first underscore _) is 1 character, then the class is Doc_TableWithoutPrefixWithoutUnderscores
|
||||||
|
* otherwise Doc_WholeTableWithoutUnderscores
|
||||||
|
* i.e. following this query
|
||||||
|
SELECT t.ad_table_id, tablename,
|
||||||
|
CASE
|
||||||
|
WHEN instr(tablename, '_') = 2
|
||||||
|
THEN 'Doc_' || substr(tablename, 3)
|
||||||
|
WHEN instr(tablename, '_') > 2
|
||||||
|
THEN 'Doc_' ||
|
||||||
|
ELSE ''
|
||||||
|
REPLACE
|
||||||
|
(
|
||||||
|
tablename, '_', ''
|
||||||
|
)
|
||||||
|
END AS classname
|
||||||
|
FROM ad_table t, ad_column C
|
||||||
|
WHERE t.ad_table_id = C.ad_table_id AND
|
||||||
|
C.columnname = 'Posted' AND
|
||||||
|
isview = 'N'
|
||||||
|
ORDER BY 1
|
||||||
|
* This is:
|
||||||
|
* 224 GL_Journal Doc_GLJournal
|
||||||
|
* 259 C_Order Doc_Order
|
||||||
|
* 318 C_Invoice Doc_Invoice
|
||||||
|
* 319 M_InOut Doc_InOut
|
||||||
|
* 321 M_Inventory Doc_Inventory
|
||||||
|
* 323 M_Movement Doc_Movement
|
||||||
|
* 325 M_Production Doc_Production
|
||||||
|
* 335 C_Payment Doc_Payment
|
||||||
|
* 392 C_BankStatement Doc_BankStatement
|
||||||
|
* 407 C_Cash Doc_Cash
|
||||||
|
* 472 M_MatchInv Doc_MatchInv
|
||||||
|
* 473 M_MatchPO Doc_MatchPO
|
||||||
|
* 623 C_ProjectIssue Doc_ProjectIssue
|
||||||
|
* 702 M_Requisition Doc_Requisition
|
||||||
|
* 735 C_AllocationHdr Doc_AllocationHdr
|
||||||
|
* 53027 PP_Order Doc_PPOrder
|
||||||
|
* 53035 PP_Cost_Collector Doc_PPCostCollector
|
||||||
|
* 53037 DD_Order Doc_DDOrder
|
||||||
|
* 53092 HR_Process Doc_HRProcess
|
||||||
|
*/
|
||||||
|
|
||||||
|
String tableName = MTable.getTableName(Env.getCtx(), AD_Table_ID);
|
||||||
|
String packageName = "org.compiere.acct";
|
||||||
|
String className = null;
|
||||||
|
|
||||||
|
int firstUnderscore = tableName.indexOf("_");
|
||||||
|
if (firstUnderscore == 1)
|
||||||
|
className = packageName + ".Doc_" + tableName.substring(2).replaceAll("_", "");
|
||||||
|
else
|
||||||
|
className = packageName + ".Doc_" + tableName.replaceAll("_", "");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class<?> cClass = Class.forName(className);
|
||||||
|
Constructor<?> cnstr = cClass.getConstructor(new Class[] {MAcctSchema.class, ResultSet.class, String.class});
|
||||||
|
doc = (Doc) cnstr.newInstance(as, rs, trxName);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
s_log.log(Level.SEVERE, "Doc Class invalid: " + className + " (" + e.toString() + ")");
|
||||||
|
throw new AdempiereUserError("Doc Class invalid: " + className + " (" + e.toString() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doc == null)
|
||||||
|
s_log.log(Level.SEVERE, "Unknown AD_Table_ID=" + AD_Table_ID);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
|
* Copyright (C) 2010 Heng Sin Low *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU General Public License for more details. *
|
||||||
|
* You should have received a copy of the GNU General Public License along *
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.adempiere.base;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
import org.compiere.acct.Doc;
|
||||||
|
import org.compiere.model.MAcctSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author hengsin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface IDocFactory {
|
||||||
|
/**
|
||||||
|
* Create Posting document
|
||||||
|
* @param as accounting schema
|
||||||
|
* @param AD_Table_ID Table ID of Documents
|
||||||
|
* @param Record_ID record ID to load
|
||||||
|
* @param trxName transaction name
|
||||||
|
* @return Document or null
|
||||||
|
*/
|
||||||
|
public Doc getDocument(MAcctSchema as, int AD_Table_ID, int Record_ID, String trxName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Posting document
|
||||||
|
* @param as accounting schema
|
||||||
|
* @param AD_Table_ID Table ID of Documents
|
||||||
|
* @param rs ResultSet
|
||||||
|
* @param trxName transaction name
|
||||||
|
* @return Document
|
||||||
|
*/
|
||||||
|
public Doc getDocument(MAcctSchema as, int AD_Table_ID, ResultSet rs, String trxName);
|
||||||
|
}
|
|
@ -28,14 +28,12 @@ import java.util.Iterator;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.adempiere.exceptions.DBException;
|
|
||||||
import org.compiere.model.MAccount;
|
import org.compiere.model.MAccount;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
import org.compiere.model.MConversionRate;
|
import org.compiere.model.MConversionRate;
|
||||||
import org.compiere.model.MDocType;
|
import org.compiere.model.MDocType;
|
||||||
import org.compiere.model.MNote;
|
import org.compiere.model.MNote;
|
||||||
import org.compiere.model.MPeriod;
|
import org.compiere.model.MPeriod;
|
||||||
import org.compiere.model.MTable;
|
|
||||||
import org.compiere.model.ModelValidationEngine;
|
import org.compiere.model.ModelValidationEngine;
|
||||||
import org.compiere.model.ModelValidator;
|
import org.compiere.model.ModelValidator;
|
||||||
import org.compiere.model.PO;
|
import org.compiere.model.PO;
|
||||||
|
@ -108,12 +106,6 @@ import org.compiere.util.Trx;
|
||||||
*/
|
*/
|
||||||
public abstract class Doc
|
public abstract class Doc
|
||||||
{
|
{
|
||||||
/** AD_Table_ID's of documents */
|
|
||||||
private static int[] documentsTableID = null;
|
|
||||||
|
|
||||||
/** Table Names of documents */
|
|
||||||
private static String[] documentsTableName = null;
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Document Types
|
* Document Types
|
||||||
* --------------
|
* --------------
|
||||||
|
@ -197,141 +189,29 @@ public abstract class Doc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Posting document
|
* Create Posting document
|
||||||
* @param ass accounting schema
|
* @param as accounting schema
|
||||||
* @param AD_Table_ID Table ID of Documents
|
* @param AD_Table_ID Table ID of Documents
|
||||||
* @param Record_ID record ID to load
|
* @param Record_ID record ID to load
|
||||||
* @param trxName transaction name
|
* @param trxName transaction name
|
||||||
* @return Document or null
|
* @return Document or null
|
||||||
*/
|
*/
|
||||||
public static Doc get (MAcctSchema[] ass, int AD_Table_ID, int Record_ID, String trxName)
|
public static Doc get (MAcctSchema as, int AD_Table_ID, int Record_ID, String trxName)
|
||||||
{
|
{
|
||||||
String TableName = null;
|
return DocManager.getDocument(as, AD_Table_ID, Record_ID, trxName);
|
||||||
for (int i = 0; i < getDocumentsTableID().length; i++)
|
|
||||||
{
|
|
||||||
if (getDocumentsTableID()[i] == AD_Table_ID)
|
|
||||||
{
|
|
||||||
TableName = getDocumentsTableName()[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (TableName == null)
|
|
||||||
{
|
|
||||||
s_log.severe("Not found AD_Table_ID=" + AD_Table_ID);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
Doc doc = null;
|
|
||||||
StringBuffer sql = new StringBuffer("SELECT * FROM ")
|
|
||||||
.append(TableName)
|
|
||||||
.append(" WHERE ").append(TableName).append("_ID=? AND Processed='Y'");
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql.toString(), trxName);
|
|
||||||
pstmt.setInt (1, Record_ID);
|
|
||||||
rs = pstmt.executeQuery ();
|
|
||||||
if (rs.next ())
|
|
||||||
{
|
|
||||||
doc = get (ass, AD_Table_ID, rs, trxName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s_log.severe("Not Found: " + TableName + "_ID=" + Record_ID);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log (Level.SEVERE, sql.toString(), e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
return doc;
|
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Posting document
|
* Create Posting document
|
||||||
* @param ass accounting schema
|
* @param as accounting schema
|
||||||
* @param AD_Table_ID Table ID of Documents
|
* @param AD_Table_ID Table ID of Documents
|
||||||
* @param rs ResultSet
|
* @param rs ResultSet
|
||||||
* @param trxName transaction name
|
* @param trxName transaction name
|
||||||
* @return Document
|
* @return Document
|
||||||
* @throws AdempiereUserError
|
* @throws AdempiereUserError
|
||||||
*/
|
*/
|
||||||
public static Doc get (MAcctSchema[] ass, int AD_Table_ID, ResultSet rs, String trxName) throws AdempiereUserError
|
public static Doc get (MAcctSchema as, int AD_Table_ID, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
Doc doc = null;
|
return DocManager.getDocument(as, AD_Table_ID, rs, trxName);
|
||||||
|
|
||||||
/* Classname of the Doc class follows this convention:
|
|
||||||
* if the prefix (letters before the first underscore _) is 1 character, then the class is Doc_TableWithoutPrefixWithoutUnderscores
|
|
||||||
* otherwise Doc_WholeTableWithoutUnderscores
|
|
||||||
* i.e. following this query
|
|
||||||
SELECT t.ad_table_id, tablename,
|
|
||||||
CASE
|
|
||||||
WHEN instr(tablename, '_') = 2
|
|
||||||
THEN 'Doc_' || substr(tablename, 3)
|
|
||||||
WHEN instr(tablename, '_') > 2
|
|
||||||
THEN 'Doc_' ||
|
|
||||||
ELSE ''
|
|
||||||
REPLACE
|
|
||||||
(
|
|
||||||
tablename, '_', ''
|
|
||||||
)
|
|
||||||
END AS classname
|
|
||||||
FROM ad_table t, ad_column C
|
|
||||||
WHERE t.ad_table_id = C.ad_table_id AND
|
|
||||||
C.columnname = 'Posted' AND
|
|
||||||
isview = 'N'
|
|
||||||
ORDER BY 1
|
|
||||||
* This is:
|
|
||||||
* 224 GL_Journal Doc_GLJournal
|
|
||||||
* 259 C_Order Doc_Order
|
|
||||||
* 318 C_Invoice Doc_Invoice
|
|
||||||
* 319 M_InOut Doc_InOut
|
|
||||||
* 321 M_Inventory Doc_Inventory
|
|
||||||
* 323 M_Movement Doc_Movement
|
|
||||||
* 325 M_Production Doc_Production
|
|
||||||
* 335 C_Payment Doc_Payment
|
|
||||||
* 392 C_BankStatement Doc_BankStatement
|
|
||||||
* 407 C_Cash Doc_Cash
|
|
||||||
* 472 M_MatchInv Doc_MatchInv
|
|
||||||
* 473 M_MatchPO Doc_MatchPO
|
|
||||||
* 623 C_ProjectIssue Doc_ProjectIssue
|
|
||||||
* 702 M_Requisition Doc_Requisition
|
|
||||||
* 735 C_AllocationHdr Doc_AllocationHdr
|
|
||||||
* 53027 PP_Order Doc_PPOrder
|
|
||||||
* 53035 PP_Cost_Collector Doc_PPCostCollector
|
|
||||||
* 53037 DD_Order Doc_DDOrder
|
|
||||||
* 53092 HR_Process Doc_HRProcess
|
|
||||||
*/
|
|
||||||
|
|
||||||
String tableName = MTable.getTableName(Env.getCtx(), AD_Table_ID);
|
|
||||||
String packageName = "org.compiere.acct";
|
|
||||||
String className = null;
|
|
||||||
|
|
||||||
int firstUnderscore = tableName.indexOf("_");
|
|
||||||
if (firstUnderscore == 1)
|
|
||||||
className = packageName + ".Doc_" + tableName.substring(2).replaceAll("_", "");
|
|
||||||
else
|
|
||||||
className = packageName + ".Doc_" + tableName.replaceAll("_", "");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class<?> cClass = Class.forName(className);
|
|
||||||
Constructor<?> cnstr = cClass.getConstructor(new Class[] {MAcctSchema[].class, ResultSet.class, String.class});
|
|
||||||
doc = (Doc) cnstr.newInstance(ass, rs, trxName);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, "Doc Class invalid: " + className + " (" + e.toString() + ")");
|
|
||||||
throw new AdempiereUserError("Doc Class invalid: " + className + " (" + e.toString() + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doc == null)
|
|
||||||
s_log.log(Level.SEVERE, "Unknown AD_Table_ID=" + AD_Table_ID);
|
|
||||||
return doc;
|
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -346,10 +226,7 @@ public abstract class Doc
|
||||||
public static String postImmediate (MAcctSchema[] ass,
|
public static String postImmediate (MAcctSchema[] ass,
|
||||||
int AD_Table_ID, int Record_ID, boolean force, String trxName)
|
int AD_Table_ID, int Record_ID, boolean force, String trxName)
|
||||||
{
|
{
|
||||||
Doc doc = get (ass, AD_Table_ID, Record_ID, trxName);
|
return DocManager.postDocument(ass, AD_Table_ID, Record_ID, force, true, trxName);
|
||||||
if (doc != null)
|
|
||||||
return doc.post (force, true); // repost
|
|
||||||
return "NoDoc";
|
|
||||||
} // post
|
} // post
|
||||||
|
|
||||||
/** Static Log */
|
/** Static Log */
|
||||||
|
@ -363,18 +240,18 @@ public abstract class Doc
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param clazz Document Class
|
* @param clazz Document Class
|
||||||
* @param rs result set
|
* @param rs result set
|
||||||
* @param defaultDocumentType default document type or null
|
* @param defaultDocumentType default document type or null
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
Doc (MAcctSchema[] ass, Class<?> clazz, ResultSet rs, String defaultDocumentType, String trxName)
|
Doc (MAcctSchema as, Class<?> clazz, ResultSet rs, String defaultDocumentType, String trxName)
|
||||||
{
|
{
|
||||||
p_Status = STATUS_Error;
|
p_Status = STATUS_Error;
|
||||||
m_ass = ass;
|
m_as = as;
|
||||||
m_ctx = new Properties(m_ass[0].getCtx());
|
m_ctx = new Properties(m_as.getCtx());
|
||||||
m_ctx.setProperty("#AD_Client_ID", String.valueOf(m_ass[0].getAD_Client_ID()));
|
m_ctx.setProperty("#AD_Client_ID", String.valueOf(m_as.getAD_Client_ID()));
|
||||||
|
|
||||||
String className = clazz.getName();
|
String className = clazz.getName();
|
||||||
className = className.substring(className.lastIndexOf('.')+1);
|
className = className.substring(className.lastIndexOf('.')+1);
|
||||||
|
@ -399,21 +276,22 @@ public abstract class Doc
|
||||||
setDocumentType (defaultDocumentType);
|
setDocumentType (defaultDocumentType);
|
||||||
m_trxName = trxName;
|
m_trxName = trxName;
|
||||||
m_manageLocalTrx = false;
|
m_manageLocalTrx = false;
|
||||||
if (m_trxName == null) {
|
if (m_trxName == null)
|
||||||
|
{
|
||||||
m_trxName = "Post" + m_DocumentType + p_po.get_ID();
|
m_trxName = "Post" + m_DocumentType + p_po.get_ID();
|
||||||
m_manageLocalTrx = true;
|
m_manageLocalTrx = true;
|
||||||
}
|
}
|
||||||
p_po.set_TrxName(m_trxName);
|
p_po.set_TrxName(m_trxName);
|
||||||
|
|
||||||
// Amounts
|
// Amounts
|
||||||
m_Amounts[0] = Env.ZERO;
|
for(int i = 0; i < m_Amounts.length; i++)
|
||||||
m_Amounts[1] = Env.ZERO;
|
{
|
||||||
m_Amounts[2] = Env.ZERO;
|
m_Amounts[i] = Env.ZERO;
|
||||||
m_Amounts[3] = Env.ZERO;
|
}
|
||||||
} // Doc
|
} // Doc
|
||||||
|
|
||||||
/** Accounting Schema Array */
|
/** Accounting Schema */
|
||||||
private MAcctSchema[] m_ass = null;
|
private MAcctSchema m_as = null;
|
||||||
/** Properties */
|
/** Properties */
|
||||||
private Properties m_ctx = null;
|
private Properties m_ctx = null;
|
||||||
/** Transaction Name */
|
/** Transaction Name */
|
||||||
|
@ -518,7 +396,7 @@ public abstract class Doc
|
||||||
* Get Persistent Object
|
* Get Persistent Object
|
||||||
* @return po
|
* @return po
|
||||||
*/
|
*/
|
||||||
protected PO getPO()
|
public PO getPO()
|
||||||
{
|
{
|
||||||
return p_po;
|
return p_po;
|
||||||
} // getPO
|
} // getPO
|
||||||
|
@ -550,10 +428,10 @@ public abstract class Doc
|
||||||
else
|
else
|
||||||
return "Invalid DocStatus='" + m_DocStatus + "' for DocumentNo=" + getDocumentNo();
|
return "Invalid DocStatus='" + m_DocStatus + "' for DocumentNo=" + getDocumentNo();
|
||||||
//
|
//
|
||||||
if (p_po.getAD_Client_ID() != m_ass[0].getAD_Client_ID())
|
if (p_po.getAD_Client_ID() != m_as.getAD_Client_ID())
|
||||||
{
|
{
|
||||||
String error = "AD_Client_ID Conflict - Document=" + p_po.getAD_Client_ID()
|
String error = "AD_Client_ID Conflict - Document=" + p_po.getAD_Client_ID()
|
||||||
+ ", AcctSchema=" + m_ass[0].getAD_Client_ID();
|
+ ", AcctSchema=" + m_as.getAD_Client_ID();
|
||||||
log.severe(error);
|
log.severe(error);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -612,37 +490,30 @@ public abstract class Doc
|
||||||
// Create Fact per AcctSchema
|
// Create Fact per AcctSchema
|
||||||
m_fact = new ArrayList<Fact>();
|
m_fact = new ArrayList<Fact>();
|
||||||
|
|
||||||
// for all Accounting Schema
|
|
||||||
boolean OK = true;
|
|
||||||
getPO().setDoc(this);
|
getPO().setDoc(this);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i = 0; OK && i < m_ass.length; i++)
|
// if acct schema has "only" org, skip
|
||||||
|
boolean skip = false;
|
||||||
|
if (m_as.getAD_OrgOnly_ID() != 0)
|
||||||
{
|
{
|
||||||
// if acct schema has "only" org, skip
|
// Header Level Org
|
||||||
boolean skip = false;
|
skip = m_as.isSkipOrg(getAD_Org_ID());
|
||||||
if (m_ass[i].getAD_OrgOnly_ID() != 0)
|
// Line Level Org
|
||||||
|
if (p_lines != null)
|
||||||
{
|
{
|
||||||
// Header Level Org
|
for (int line = 0; skip && line < p_lines.length; line++)
|
||||||
skip = m_ass[i].isSkipOrg(getAD_Org_ID());
|
|
||||||
// Line Level Org
|
|
||||||
if (p_lines != null)
|
|
||||||
{
|
{
|
||||||
for (int line = 0; skip && line < p_lines.length; line++)
|
skip = m_as.isSkipOrg(p_lines[line].getAD_Org_ID());
|
||||||
{
|
if (!skip)
|
||||||
skip = m_ass[i].isSkipOrg(p_lines[line].getAD_Org_ID());
|
break;
|
||||||
if (!skip)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (skip)
|
}
|
||||||
continue;
|
if (!skip)
|
||||||
|
{
|
||||||
// post
|
// post
|
||||||
log.info("(" + i + ") " + p_po);
|
p_Status = postLogic ();
|
||||||
p_Status = postLogic (i);
|
|
||||||
if (!p_Status.equals(STATUS_Posted))
|
|
||||||
OK = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -650,29 +521,26 @@ public abstract class Doc
|
||||||
log.log(Level.SEVERE, "", e);
|
log.log(Level.SEVERE, "", e);
|
||||||
p_Status = STATUS_Error;
|
p_Status = STATUS_Error;
|
||||||
p_Error = e.toString();
|
p_Error = e.toString();
|
||||||
OK = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String validatorMsg = null;
|
String validatorMsg = null;
|
||||||
// Call validator on before post
|
// Call validator on before post
|
||||||
if (p_Status.equals(STATUS_Posted)) {
|
if (!p_Status.equals(STATUS_Error)) {
|
||||||
validatorMsg = ModelValidationEngine.get().fireDocValidate(getPO(), ModelValidator.TIMING_BEFORE_POST);
|
validatorMsg = ModelValidationEngine.get().fireDocValidate(getPO(), ModelValidator.TIMING_BEFORE_POST);
|
||||||
if (validatorMsg != null) {
|
if (validatorMsg != null) {
|
||||||
p_Status = STATUS_Error;
|
p_Status = STATUS_Error;
|
||||||
p_Error = validatorMsg;
|
p_Error = validatorMsg;
|
||||||
OK = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// commitFact
|
// commitFact
|
||||||
p_Status = postCommit (p_Status);
|
p_Status = postCommit (p_Status);
|
||||||
|
|
||||||
if (p_Status.equals(STATUS_Posted)) {
|
if (!p_Status.equals(STATUS_Error)) {
|
||||||
validatorMsg = ModelValidationEngine.get().fireDocValidate(getPO(), ModelValidator.TIMING_AFTER_POST);
|
validatorMsg = ModelValidationEngine.get().fireDocValidate(getPO(), ModelValidator.TIMING_AFTER_POST);
|
||||||
if (validatorMsg != null) {
|
if (validatorMsg != null) {
|
||||||
p_Status = STATUS_Error;
|
p_Status = STATUS_Error;
|
||||||
p_Error = validatorMsg;
|
p_Error = validatorMsg;
|
||||||
OK = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,7 +567,8 @@ public abstract class Doc
|
||||||
.append(", Amount=").append(getAmount())
|
.append(", Amount=").append(getAmount())
|
||||||
.append(", Sta=").append(p_Status)
|
.append(", Sta=").append(p_Status)
|
||||||
.append(" - PeriodOpen=").append(isPeriodOpen())
|
.append(" - PeriodOpen=").append(isPeriodOpen())
|
||||||
.append(", Balanced=").append(isBalanced());
|
.append(", Balanced=").append(isBalanced())
|
||||||
|
.append(", Schema=").append(m_as.getName());
|
||||||
note.setTextMsg(Text.toString());
|
note.setTextMsg(Text.toString());
|
||||||
note.save();
|
note.save();
|
||||||
p_Error = Text.toString();
|
p_Error = Text.toString();
|
||||||
|
@ -723,11 +592,12 @@ public abstract class Doc
|
||||||
* Delete Accounting
|
* Delete Accounting
|
||||||
* @return number of records
|
* @return number of records
|
||||||
*/
|
*/
|
||||||
private int deleteAcct()
|
protected int deleteAcct()
|
||||||
{
|
{
|
||||||
StringBuffer sql = new StringBuffer ("DELETE Fact_Acct WHERE AD_Table_ID=")
|
StringBuffer sql = new StringBuffer ("DELETE Fact_Acct WHERE AD_Table_ID=")
|
||||||
.append(get_Table_ID())
|
.append(get_Table_ID())
|
||||||
.append(" AND Record_ID=").append(p_po.get_ID());
|
.append(" AND Record_ID=").append(p_po.get_ID())
|
||||||
|
.append(" AND C_AcctSchema_ID=").append(m_as.getC_AcctSchema_ID());
|
||||||
int no = DB.executeUpdate(sql.toString(), getTrxName());
|
int no = DB.executeUpdate(sql.toString(), getTrxName());
|
||||||
if (no != 0)
|
if (no != 0)
|
||||||
log.info("deleted=" + no);
|
log.info("deleted=" + no);
|
||||||
|
@ -736,19 +606,16 @@ public abstract class Doc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posting logic for Accounting Schema index
|
* Posting logic for Accounting Schema index
|
||||||
* @param index Accounting Schema index
|
|
||||||
* @return posting status/error code
|
* @return posting status/error code
|
||||||
*/
|
*/
|
||||||
private final String postLogic (int index)
|
private final String postLogic ()
|
||||||
{
|
{
|
||||||
log.info("(" + index + ") " + p_po);
|
|
||||||
|
|
||||||
// rejectUnbalanced
|
// rejectUnbalanced
|
||||||
if (!m_ass[index].isSuspenseBalancing() && !isBalanced())
|
if (!m_as.isSuspenseBalancing() && !isBalanced())
|
||||||
return STATUS_NotBalanced;
|
return STATUS_NotBalanced;
|
||||||
|
|
||||||
// rejectUnconvertible
|
// rejectUnconvertible
|
||||||
if (!isConvertible(m_ass[index]))
|
if (!isConvertible(m_as))
|
||||||
return STATUS_NotConvertible;
|
return STATUS_NotConvertible;
|
||||||
|
|
||||||
// rejectPeriodClosed
|
// rejectPeriodClosed
|
||||||
|
@ -756,12 +623,12 @@ public abstract class Doc
|
||||||
return STATUS_PeriodClosed;
|
return STATUS_PeriodClosed;
|
||||||
|
|
||||||
// createFacts
|
// createFacts
|
||||||
ArrayList<Fact> facts = createFacts (m_ass[index]);
|
ArrayList<Fact> facts = createFacts (m_as);
|
||||||
if (facts == null)
|
if (facts == null)
|
||||||
return STATUS_Error;
|
return STATUS_Error;
|
||||||
|
|
||||||
// call modelValidator
|
// call modelValidator
|
||||||
String validatorMsg = ModelValidationEngine.get().fireFactsValidate(m_ass[index], facts, getPO());
|
String validatorMsg = ModelValidationEngine.get().fireFactsValidate(m_as, facts, getPO());
|
||||||
if (validatorMsg != null) {
|
if (validatorMsg != null) {
|
||||||
p_Error = validatorMsg;
|
p_Error = validatorMsg;
|
||||||
return STATUS_Error;
|
return STATUS_Error;
|
||||||
|
@ -851,17 +718,9 @@ public abstract class Doc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Commit Doc
|
|
||||||
if (!save(getTrxName())) // contains unlock & document status update
|
unlock();
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "(doc not saved) ... rolling back");
|
|
||||||
if (m_manageLocalTrx) {
|
|
||||||
trx.rollback();
|
|
||||||
trx.close();
|
|
||||||
}
|
|
||||||
unlock();
|
|
||||||
return STATUS_Error;
|
|
||||||
}
|
|
||||||
// Success
|
// Success
|
||||||
if (m_manageLocalTrx) {
|
if (m_manageLocalTrx) {
|
||||||
trx.commit(true);
|
trx.commit(true);
|
||||||
|
@ -1545,25 +1404,6 @@ public abstract class Doc
|
||||||
return acct;
|
return acct;
|
||||||
} // getAccount
|
} // getAccount
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Save to Disk - set posted flag
|
|
||||||
* @param trxName transaction name
|
|
||||||
* @return true if saved
|
|
||||||
*/
|
|
||||||
private final boolean save (String trxName)
|
|
||||||
{
|
|
||||||
log.fine(toString() + "->" + p_Status);
|
|
||||||
|
|
||||||
StringBuffer sql = new StringBuffer("UPDATE ");
|
|
||||||
sql.append(get_TableName()).append(" SET Posted='").append(p_Status)
|
|
||||||
.append("',Processing='N' ")
|
|
||||||
.append("WHERE ")
|
|
||||||
.append(get_TableName()).append("_ID=").append(p_po.get_ID());
|
|
||||||
int no = DB.executeUpdate(sql.toString(), trxName);
|
|
||||||
return no == 1;
|
|
||||||
} // save
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get DocLine with ID
|
* Get DocLine with ID
|
||||||
* @param Record_ID Record ID
|
* @param Record_ID Record ID
|
||||||
|
@ -2295,60 +2135,4 @@ public abstract class Doc
|
||||||
public ArrayList<Fact> getFacts() {
|
public ArrayList<Fact> getFacts() {
|
||||||
return m_fact;
|
return m_fact;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Array of tables with Post column
|
|
||||||
*/
|
|
||||||
public static int[] getDocumentsTableID() {
|
|
||||||
fillDocumentsTableArrays();
|
|
||||||
return documentsTableID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getDocumentsTableName() {
|
|
||||||
fillDocumentsTableArrays();
|
|
||||||
return documentsTableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void fillDocumentsTableArrays() {
|
|
||||||
if (documentsTableID == null) {
|
|
||||||
String sql = "SELECT t.AD_Table_ID, t.TableName " +
|
|
||||||
"FROM AD_Table t, AD_Column c " +
|
|
||||||
"WHERE t.AD_Table_ID=c.AD_Table_ID AND " +
|
|
||||||
"c.ColumnName='Posted' AND " +
|
|
||||||
"IsView='N' " +
|
|
||||||
"ORDER BY t.AD_Table_ID";
|
|
||||||
ArrayList<Integer> tableIDs = new ArrayList<Integer>();
|
|
||||||
ArrayList<String> tableNames = new ArrayList<String>();
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
tableIDs.add(rs.getInt(1));
|
|
||||||
tableNames.add(rs.getString(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
throw new DBException(e, sql);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
// Convert to array
|
|
||||||
documentsTableID = new int[tableIDs.size()];
|
|
||||||
documentsTableName = new String[tableIDs.size()];
|
|
||||||
for (int i = 0; i < documentsTableID.length; i++)
|
|
||||||
{
|
|
||||||
documentsTableID[i] = tableIDs.get(i);
|
|
||||||
documentsTableName[i] = tableNames.get(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Doc
|
} // Doc
|
||||||
|
|
|
@ -0,0 +1,370 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
|
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU General Public License for more details. *
|
||||||
|
* You should have received a copy of the GNU General Public License along *
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
|
* For the text or an alternative of this public license, you may reach us *
|
||||||
|
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||||
|
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.compiere.acct;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.adempiere.base.IDocFactory;
|
||||||
|
import org.adempiere.base.Service;
|
||||||
|
import org.adempiere.base.ServiceQuery;
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.adempiere.exceptions.DBException;
|
||||||
|
import org.compiere.model.MAcctSchema;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.util.AdempiereUserError;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.ValueNamePair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains methods to manage the posting of financial document. Most of the code is adapted from the legacy code in Doc.java
|
||||||
|
* @author Jorg Janke
|
||||||
|
* @author hengsin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DocManager {
|
||||||
|
|
||||||
|
private final static CLogger s_log = CLogger.getCLogger(DocManager.class);
|
||||||
|
|
||||||
|
/** AD_Table_ID's of documents */
|
||||||
|
private static int[] documentsTableID = null;
|
||||||
|
|
||||||
|
/** Table Names of documents */
|
||||||
|
private static String[] documentsTableName = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Array of tables with Post column
|
||||||
|
*/
|
||||||
|
public static int[] getDocumentsTableID() {
|
||||||
|
fillDocumentsTableArrays();
|
||||||
|
return documentsTableID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getDocumentsTableName() {
|
||||||
|
fillDocumentsTableArrays();
|
||||||
|
return documentsTableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fillDocumentsTableArrays() {
|
||||||
|
if (documentsTableID == null) {
|
||||||
|
String sql = "SELECT t.AD_Table_ID, t.TableName " +
|
||||||
|
"FROM AD_Table t, AD_Column c " +
|
||||||
|
"WHERE t.AD_Table_ID=c.AD_Table_ID AND " +
|
||||||
|
"c.ColumnName='Posted' AND " +
|
||||||
|
"IsView='N' " +
|
||||||
|
"ORDER BY t.AD_Table_ID";
|
||||||
|
ArrayList<Integer> tableIDs = new ArrayList<Integer>();
|
||||||
|
ArrayList<String> tableNames = new ArrayList<String>();
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
|
rs = pstmt.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
tableIDs.add(rs.getInt(1));
|
||||||
|
tableNames.add(rs.getString(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
throw new DBException(e, sql);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
|
// Convert to array
|
||||||
|
documentsTableID = new int[tableIDs.size()];
|
||||||
|
documentsTableName = new String[tableIDs.size()];
|
||||||
|
for (int i = 0; i < documentsTableID.length; i++)
|
||||||
|
{
|
||||||
|
documentsTableID[i] = tableIDs.get(i);
|
||||||
|
documentsTableName[i] = tableNames.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Posting document
|
||||||
|
* @param as accounting schema
|
||||||
|
* @param AD_Table_ID Table ID of Documents
|
||||||
|
* @param Record_ID record ID to load
|
||||||
|
* @param trxName transaction name
|
||||||
|
* @return Document or null
|
||||||
|
*/
|
||||||
|
public static Doc getDocument(MAcctSchema as, int AD_Table_ID, int Record_ID, String trxName)
|
||||||
|
{
|
||||||
|
String TableName = null;
|
||||||
|
for (int i = 0; i < DocManager.getDocumentsTableID().length; i++)
|
||||||
|
{
|
||||||
|
if (DocManager.getDocumentsTableID()[i] == AD_Table_ID)
|
||||||
|
{
|
||||||
|
TableName = DocManager.getDocumentsTableName()[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (TableName == null)
|
||||||
|
{
|
||||||
|
s_log.severe("Not found AD_Table_ID=" + AD_Table_ID);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceQuery query = new ServiceQuery();
|
||||||
|
query.put("gaap", as.getGAAP());
|
||||||
|
List<IDocFactory> factoryList = Service.list(IDocFactory.class, query);
|
||||||
|
if (factoryList != null)
|
||||||
|
{
|
||||||
|
for(IDocFactory factory : factoryList)
|
||||||
|
{
|
||||||
|
Doc doc = factory.getDocument(as, AD_Table_ID, Record_ID, trxName);
|
||||||
|
if (doc != null)
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query.clear();
|
||||||
|
query.put("gaap", "*");
|
||||||
|
factoryList = Service.list(IDocFactory.class, query);
|
||||||
|
if (factoryList != null)
|
||||||
|
{
|
||||||
|
for(IDocFactory factory : factoryList)
|
||||||
|
{
|
||||||
|
Doc doc = factory.getDocument(as, AD_Table_ID, Record_ID, trxName);
|
||||||
|
if (doc != null)
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Posting document
|
||||||
|
* @param as accounting schema
|
||||||
|
* @param AD_Table_ID Table ID of Documents
|
||||||
|
* @param rs ResultSet
|
||||||
|
* @param trxName transaction name
|
||||||
|
* @return Document
|
||||||
|
* @throws AdempiereUserError
|
||||||
|
*/
|
||||||
|
public static Doc getDocument(MAcctSchema as, int AD_Table_ID, ResultSet rs, String trxName)
|
||||||
|
{
|
||||||
|
ServiceQuery query = new ServiceQuery();
|
||||||
|
query.put("gaap", as.getGAAP());
|
||||||
|
List<IDocFactory> factoryList = Service.list(IDocFactory.class,query);
|
||||||
|
if (factoryList != null)
|
||||||
|
{
|
||||||
|
for(IDocFactory factory : factoryList)
|
||||||
|
{
|
||||||
|
Doc doc = factory.getDocument(as, AD_Table_ID, rs, trxName);
|
||||||
|
if (doc != null)
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query.clear();
|
||||||
|
query.put("gaap", "*");
|
||||||
|
factoryList = Service.list(IDocFactory.class,query);
|
||||||
|
if (factoryList != null)
|
||||||
|
{
|
||||||
|
for(IDocFactory factory : factoryList)
|
||||||
|
{
|
||||||
|
Doc doc = factory.getDocument(as, AD_Table_ID, rs, trxName);
|
||||||
|
if (doc != null)
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post Document
|
||||||
|
* @param ass accounting schema
|
||||||
|
* @param AD_Table_ID Transaction table
|
||||||
|
* @param Record_ID Record ID of this document
|
||||||
|
* @param force force posting
|
||||||
|
* @param repost Repost document
|
||||||
|
* @param trxName transaction
|
||||||
|
* @return null if the document was posted or error message
|
||||||
|
*/
|
||||||
|
public static String postDocument(MAcctSchema[] ass,
|
||||||
|
int AD_Table_ID, int Record_ID, boolean force, boolean repost, String trxName) {
|
||||||
|
|
||||||
|
String tableName = null;
|
||||||
|
for (int i = 0; i < getDocumentsTableID().length; i++)
|
||||||
|
{
|
||||||
|
if (getDocumentsTableID()[i] == AD_Table_ID)
|
||||||
|
{
|
||||||
|
tableName = getDocumentsTableName()[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tableName == null)
|
||||||
|
{
|
||||||
|
s_log.severe("Table not a financial document. AD_Table_ID=" + AD_Table_ID);
|
||||||
|
return "Table not a financial document. AD_Table_ID="+AD_Table_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer sql = new StringBuffer("SELECT * FROM ")
|
||||||
|
.append(tableName)
|
||||||
|
.append(" WHERE ").append(tableName).append("_ID=? AND Processed='Y'");
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pstmt = DB.prepareStatement (sql.toString(), trxName);
|
||||||
|
pstmt.setInt (1, Record_ID);
|
||||||
|
rs = pstmt.executeQuery ();
|
||||||
|
if (rs.next ())
|
||||||
|
{
|
||||||
|
return postDocument(ass, AD_Table_ID, rs, force, repost, trxName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_log.severe("Not Found: " + tableName + "_ID=" + Record_ID);
|
||||||
|
return "NoDoc";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (e instanceof RuntimeException)
|
||||||
|
throw (RuntimeException)e;
|
||||||
|
else
|
||||||
|
throw new AdempiereException(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null;
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post Document
|
||||||
|
* @param ass accounting schema
|
||||||
|
* @param AD_Table_ID Transaction table
|
||||||
|
* @param rs Result set
|
||||||
|
* @param force force posting
|
||||||
|
* @param repost Repost document
|
||||||
|
* @param trxName transaction
|
||||||
|
* @return null if the document was posted or error message
|
||||||
|
*/
|
||||||
|
public static String postDocument(MAcctSchema[] ass,
|
||||||
|
int AD_Table_ID, ResultSet rs, boolean force, boolean repost, String trxName) {
|
||||||
|
String localTrxName = null;
|
||||||
|
if (trxName == null)
|
||||||
|
{
|
||||||
|
localTrxName = Trx.createTrxName("Post");
|
||||||
|
trxName = localTrxName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String error = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String status = "";
|
||||||
|
for(MAcctSchema as : ass)
|
||||||
|
{
|
||||||
|
Doc doc = Doc.get (as, AD_Table_ID, rs, trxName);
|
||||||
|
if (doc != null)
|
||||||
|
{
|
||||||
|
error = doc.post (force, repost); // repost
|
||||||
|
status = doc.getPostStatus();
|
||||||
|
if (error != null && error.trim().length() > 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "NoDoc";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MTable table = MTable.get(Env.getCtx(), AD_Table_ID);
|
||||||
|
int Record_ID = rs.getInt(table.getKeyColumns()[0]);
|
||||||
|
// Commit Doc
|
||||||
|
if (!save(trxName, AD_Table_ID, Record_ID, status))
|
||||||
|
{
|
||||||
|
ValueNamePair dbError = CLogger.retrieveError();
|
||||||
|
// log.log(Level.SEVERE, "(doc not saved) ... rolling back");
|
||||||
|
if (localTrxName != null) {
|
||||||
|
Trx trx = Trx.get(localTrxName, false);
|
||||||
|
if (trx != null)
|
||||||
|
trx.rollback();
|
||||||
|
}
|
||||||
|
if (dbError != null)
|
||||||
|
error = dbError.getValue();
|
||||||
|
else
|
||||||
|
error = "SaveError";
|
||||||
|
}
|
||||||
|
if (localTrxName != null) {
|
||||||
|
Trx trx = Trx.get(localTrxName, false);
|
||||||
|
if (trx != null)
|
||||||
|
trx.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (localTrxName != null) {
|
||||||
|
Trx trx = Trx.get(localTrxName, false);
|
||||||
|
if (trx != null)
|
||||||
|
trx.rollback();
|
||||||
|
}
|
||||||
|
if (e instanceof RuntimeException)
|
||||||
|
throw (RuntimeException) e;
|
||||||
|
else
|
||||||
|
throw new AdempiereException(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (localTrxName != null)
|
||||||
|
{
|
||||||
|
Trx trx = Trx.get(localTrxName, false);
|
||||||
|
if (trx != null)
|
||||||
|
trx.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Save to Disk - set posted flag
|
||||||
|
* @param trxName transaction name
|
||||||
|
* @return true if saved
|
||||||
|
*/
|
||||||
|
private final static boolean save (String trxName, int AD_Table_ID, int Record_ID, String status)
|
||||||
|
{
|
||||||
|
MTable table = MTable.get(Env.getCtx(), AD_Table_ID);
|
||||||
|
StringBuffer sql = new StringBuffer("UPDATE ");
|
||||||
|
sql.append(table.getTableName()).append(" SET Posted='").append(status)
|
||||||
|
.append("',Processing='N' ")
|
||||||
|
.append("WHERE ")
|
||||||
|
.append(table.getTableName()).append("_ID=").append(Record_ID);
|
||||||
|
CLogger.resetLast();
|
||||||
|
int no = DB.executeUpdate(sql.toString(), trxName);
|
||||||
|
return no == 1;
|
||||||
|
} // save
|
||||||
|
}
|
|
@ -59,13 +59,13 @@ public class Doc_AllocationHdr extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_AllocationHdr (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_AllocationHdr (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MAllocationHdr.class, rs, DOCTYPE_Allocation, trxName);
|
super (as, MAllocationHdr.class, rs, DOCTYPE_Allocation, trxName);
|
||||||
} // Doc_Allocation
|
} // Doc_Allocation
|
||||||
|
|
||||||
/** Tolerance G&L */
|
/** Tolerance G&L */
|
||||||
|
@ -583,7 +583,7 @@ public class Doc_AllocationHdr extends Doc
|
||||||
+ " - Allocation Source=" + allocationSource);
|
+ " - Allocation Source=" + allocationSource);
|
||||||
|
|
||||||
// Get Invoice Postings
|
// Get Invoice Postings
|
||||||
Doc_Invoice docInvoice = (Doc_Invoice)Doc.get(new MAcctSchema[]{as},
|
Doc_Invoice docInvoice = (Doc_Invoice)Doc.get(as,
|
||||||
MInvoice.Table_ID, invoice.getC_Invoice_ID(), getTrxName());
|
MInvoice.Table_ID, invoice.getC_Invoice_ID(), getTrxName());
|
||||||
docInvoice.loadDocumentDetails();
|
docInvoice.loadDocumentDetails();
|
||||||
allocationAccounted = docInvoice.createFactCash(as, fact, new BigDecimal(percent));
|
allocationAccounted = docInvoice.createFactCash(as, fact, new BigDecimal(percent));
|
||||||
|
|
|
@ -48,13 +48,13 @@ public class Doc_BankStatement extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_BankStatement (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_BankStatement (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MBankStatement.class, rs, DOCTYPE_BankStatement, trxName);
|
super (as, MBankStatement.class, rs, DOCTYPE_BankStatement, trxName);
|
||||||
} // Doc_Bank
|
} // Doc_Bank
|
||||||
|
|
||||||
/** Bank Account */
|
/** Bank Account */
|
||||||
|
|
|
@ -40,13 +40,13 @@ public class Doc_Cash extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Cash (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Cash (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super(ass, MCash.class, rs, DOCTYPE_CashJournal, trxName);
|
super(as, MCash.class, rs, DOCTYPE_CashJournal, trxName);
|
||||||
} // Doc_Cash
|
} // Doc_Cash
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,13 +40,13 @@ public class Doc_GLJournal extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_GLJournal (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_GLJournal (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super(ass, MJournal.class, rs, null, trxName);
|
super(as, MJournal.class, rs, null, trxName);
|
||||||
} // Doc_GL_Journal
|
} // Doc_GL_Journal
|
||||||
|
|
||||||
/** Posting Type */
|
/** Posting Type */
|
||||||
|
|
|
@ -50,13 +50,13 @@ public class Doc_InOut extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_InOut (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_InOut (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MInOut.class, rs, null, trxName);
|
super (as, MInOut.class, rs, null, trxName);
|
||||||
} // DocInOut
|
} // DocInOut
|
||||||
|
|
||||||
private int m_Reversal_ID = 0;
|
private int m_Reversal_ID = 0;
|
||||||
|
|
|
@ -47,13 +47,13 @@ public class Doc_Inventory extends Doc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Inventory (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Inventory (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MInventory.class, rs, DOCTYPE_MatInventory, trxName);
|
super (as, MInventory.class, rs, DOCTYPE_MatInventory, trxName);
|
||||||
} // Doc_Inventory
|
} // Doc_Inventory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,13 +53,13 @@ public class Doc_Invoice extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schemata
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Invoice(MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Invoice(MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MInvoice.class, rs, null, trxName);
|
super (as, MInvoice.class, rs, null, trxName);
|
||||||
} // Doc_Invoice
|
} // Doc_Invoice
|
||||||
|
|
||||||
/** Contained Optional Tax Lines */
|
/** Contained Optional Tax Lines */
|
||||||
|
|
|
@ -51,13 +51,13 @@ public class Doc_MatchInv extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param ass accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_MatchInv (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_MatchInv (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super(ass, MMatchInv.class, rs, DOCTYPE_MatMatchInv, trxName);
|
super(as, MMatchInv.class, rs, DOCTYPE_MatMatchInv, trxName);
|
||||||
} // Doc_MatchInv
|
} // Doc_MatchInv
|
||||||
|
|
||||||
/** Invoice Line */
|
/** Invoice Line */
|
||||||
|
|
|
@ -50,13 +50,13 @@ public class Doc_MatchPO extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schemata
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_MatchPO (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_MatchPO (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super(ass, MMatchPO.class, rs, DOCTYPE_MatMatchPO, trxName);
|
super(as, MMatchPO.class, rs, DOCTYPE_MatMatchPO, trxName);
|
||||||
} // Doc_MatchPO
|
} // Doc_MatchPO
|
||||||
|
|
||||||
private int m_C_OrderLine_ID = 0;
|
private int m_C_OrderLine_ID = 0;
|
||||||
|
|
|
@ -45,13 +45,13 @@ public class Doc_Movement extends Doc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Movement (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Movement (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MMovement.class, rs, DOCTYPE_MatMovement, trxName);
|
super (as, MMovement.class, rs, DOCTYPE_MatMovement, trxName);
|
||||||
} // Doc_Movement
|
} // Doc_Movement
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,13 +49,13 @@ public class Doc_Order extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Order (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Order (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MOrder.class, rs, null, trxName);
|
super (as, MOrder.class, rs, null, trxName);
|
||||||
} // Doc_Order
|
} // Doc_Order
|
||||||
|
|
||||||
/** Contained Optional Tax Lines */
|
/** Contained Optional Tax Lines */
|
||||||
|
|
|
@ -41,13 +41,13 @@ public class Doc_Payment extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param ass accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Payment (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Payment (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MPayment.class, rs, null, trxName);
|
super (as, MPayment.class, rs, null, trxName);
|
||||||
} // Doc_Payment
|
} // Doc_Payment
|
||||||
|
|
||||||
/** Tender Type */
|
/** Tender Type */
|
||||||
|
|
|
@ -45,13 +45,13 @@ public class Doc_Production extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Production (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Production (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, X_M_Production.class, rs, DOCTYPE_MatProduction, trxName);
|
super (as, X_M_Production.class, rs, DOCTYPE_MatProduction, trxName);
|
||||||
} // Doc_Production
|
} // Doc_Production
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,13 +43,13 @@ public class Doc_ProjectIssue extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_ProjectIssue (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_ProjectIssue (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MProjectIssue.class, rs, DOCTYPE_ProjectIssue, trxName);
|
super (as, MProjectIssue.class, rs, DOCTYPE_ProjectIssue, trxName);
|
||||||
} // Doc_ProjectIssue
|
} // Doc_ProjectIssue
|
||||||
|
|
||||||
/** Pseudo Line */
|
/** Pseudo Line */
|
||||||
|
|
|
@ -43,13 +43,13 @@ public class Doc_Requisition extends Doc
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param ass accounting schemata
|
* @param as accounting schema
|
||||||
* @param rs record
|
* @param rs record
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
*/
|
*/
|
||||||
public Doc_Requisition (MAcctSchema[] ass, ResultSet rs, String trxName)
|
public Doc_Requisition (MAcctSchema as, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ass, MRequisition.class, rs, DOCTYPE_PurchaseRequisition, trxName);
|
super (as, MRequisition.class, rs, DOCTYPE_PurchaseRequisition, trxName);
|
||||||
} // Doc_Requisition
|
} // Doc_Requisition
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,7 @@ package org.compiere.util;
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: AdempiereUserError.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
|
* @version $Id: AdempiereUserError.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
|
||||||
*/
|
*/
|
||||||
public class AdempiereUserError extends Exception
|
public class AdempiereUserError extends RuntimeException
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.acct.Doc;
|
import org.compiere.acct.DocManager;
|
||||||
import org.compiere.model.MAcctProcessor;
|
import org.compiere.model.MAcctProcessor;
|
||||||
import org.compiere.model.MAcctProcessorLog;
|
import org.compiere.model.MAcctProcessorLog;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
|
@ -106,8 +106,8 @@ public class AcctProcessor extends AdempiereServer
|
||||||
BigDecimal value = new BigDecimal(Long.toString(mili));
|
BigDecimal value = new BigDecimal(Long.toString(mili));
|
||||||
|
|
||||||
//first pass, collect all ts (FR 2962094 - required for weighted average costing)
|
//first pass, collect all ts (FR 2962094 - required for weighted average costing)
|
||||||
int[] documentsTableID = Doc.getDocumentsTableID();
|
int[] documentsTableID = DocManager.getDocumentsTableID();
|
||||||
String[] documentsTableName = Doc.getDocumentsTableName();
|
String[] documentsTableName = DocManager.getDocumentsTableName();
|
||||||
for (int i = 0; i < documentsTableID.length; i++)
|
for (int i = 0; i < documentsTableID.length; i++)
|
||||||
{
|
{
|
||||||
int AD_Table_ID = documentsTableID[i];
|
int AD_Table_ID = documentsTableID[i];
|
||||||
|
@ -191,17 +191,8 @@ public class AcctProcessor extends AdempiereServer
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Doc doc = Doc.get (m_ass, AD_Table_ID, rs, null);
|
String error = DocManager.postDocument(m_ass, AD_Table_ID, rs, false, false, null);
|
||||||
if (doc == null)
|
ok = error == null;
|
||||||
{
|
|
||||||
log.severe(getName() + ": No Doc for " + TableName);
|
|
||||||
ok = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String error = doc.post(false, false); // post no force/repost
|
|
||||||
ok = error == null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue