diff --git a/org.adempiere.base.process/src/org/adempiere/process/ClientAcctProcessor.java b/org.adempiere.base.process/src/org/adempiere/process/ClientAcctProcessor.java index bb8695ea25..32e6501279 100644 --- a/org.adempiere.base.process/src/org/adempiere/process/ClientAcctProcessor.java +++ b/org.adempiere.base.process/src/org/adempiere/process/ClientAcctProcessor.java @@ -38,7 +38,7 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; -import org.compiere.acct.Doc; +import org.compiere.acct.DocManager; import org.compiere.model.MAcctSchema; import org.compiere.model.MClient; import org.compiere.model.MCost; @@ -52,7 +52,7 @@ import org.compiere.util.Trx; /** * Client Accounting Processor - * + * * @author Carlos Ruiz */ public class ClientAcctProcessor extends SvrProcess @@ -68,7 +68,7 @@ public class ClientAcctProcessor extends SvrProcess private MClient m_client = null; /** Accounting Schema */ private MAcctSchema[] m_ass = null; - + /** * Prepare */ @@ -97,17 +97,17 @@ public class ClientAcctProcessor extends SvrProcess protected String doIt () throws Exception { log.info("C_AcctSchema_ID=" + p_C_AcctSchema_ID + ", AD_Table_ID=" + p_AD_Table_ID); - + if (! MClient.isClientAccounting()) throw new AdempiereUserError(Msg.getMsg(getCtx(), "ClientAccountingNotEnabled")); m_client = MClient.get(getCtx(), getAD_Client_ID()); - + if (p_C_AcctSchema_ID == 0) m_ass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID()); else // only specific accounting schema m_ass = new MAcctSchema[] {new MAcctSchema (getCtx(), p_C_AcctSchema_ID, get_TrxName())}; - + postSession(); MCost.create(m_client); @@ -132,10 +132,10 @@ public class ClientAcctProcessor extends SvrProcess ts = new Timestamp(ms); long mili = ts.getTime(); BigDecimal value = new BigDecimal(Long.toString(mili)); - + //first pass, collect all ts (FR 2962094 - required for weighted average costing) - int[] documentsTableID = Doc.getDocumentsTableID(); - String[] documentsTableName = Doc.getDocumentsTableName(); + int[] documentsTableID = DocManager.getDocumentsTableID(); + String[] documentsTableName = DocManager.getDocumentsTableName(); for (int i = 0; i < documentsTableID.length; i++) { int AD_Table_ID = documentsTableID[i]; @@ -144,7 +144,7 @@ public class ClientAcctProcessor extends SvrProcess if (p_AD_Table_ID != 0 && p_AD_Table_ID != AD_Table_ID) continue; - + StringBuffer sql = new StringBuffer ("SELECT DISTINCT ProcessedOn FROM ").append(TableName) .append(" WHERE AD_Client_ID=? AND ProcessedOn + + + + + diff --git a/org.adempiere.base/schema/org.adempiere.base.IDocFactory.exsd b/org.adempiere.base/schema/org.adempiere.base.IDocFactory.exsd new file mode 100644 index 0000000000..876c90dae1 --- /dev/null +++ b/org.adempiere.base/schema/org.adempiere.base.IDocFactory.exsd @@ -0,0 +1,116 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + use * to match everything + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/org.adempiere.base/schema/org.adempiere.base.IModelFactory.exsd b/org.adempiere.base/schema/org.adempiere.base.IModelFactory.exsd index c0a7e0e509..d754ee6f13 100644 --- a/org.adempiere.base/schema/org.adempiere.base.IModelFactory.exsd +++ b/org.adempiere.base/schema/org.adempiere.base.IModelFactory.exsd @@ -56,7 +56,7 @@ - + diff --git a/org.adempiere.base/src/org/adempiere/base/DefaultDocumentFactory.java b/org.adempiere.base/src/org/adempiere/base/DefaultDocumentFactory.java new file mode 100644 index 0000000000..190c3948a3 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/DefaultDocumentFactory.java @@ -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; + } + +} diff --git a/org.adempiere.base/src/org/adempiere/base/IDocFactory.java b/org.adempiere.base/src/org/adempiere/base/IDocFactory.java new file mode 100644 index 0000000000..ca5a90de9a --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/IDocFactory.java @@ -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); +} diff --git a/org.adempiere.base/src/org/compiere/acct/Doc.java b/org.adempiere.base/src/org/compiere/acct/Doc.java index 77378e6863..43feb2f8b3 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc.java @@ -28,14 +28,12 @@ import java.util.Iterator; import java.util.Properties; import java.util.logging.Level; -import org.adempiere.exceptions.DBException; import org.compiere.model.MAccount; import org.compiere.model.MAcctSchema; import org.compiere.model.MConversionRate; import org.compiere.model.MDocType; import org.compiere.model.MNote; import org.compiere.model.MPeriod; -import org.compiere.model.MTable; import org.compiere.model.ModelValidationEngine; import org.compiere.model.ModelValidator; import org.compiere.model.PO; @@ -74,7 +72,7 @@ import org.compiere.util.Trx; * * M_Production: MMP * Doc_Production 325 - DocType fixed - * + * * M_Production: MMO * Doc_CostCollector 330 - DocType fixed * @@ -98,22 +96,16 @@ import org.compiere.util.Trx; * * Project Issue PJI * C_ProjectIssue 623 - DocType fixed - * + * * * @author Jorg Janke * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • FR [ 2520591 ] Support multiples calendar for Org - * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 + *
  • FR [ 2520591 ] Support multiples calendar for Org + * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 * @version $Id: Doc.java,v 1.6 2006/07/30 00:53:33 jjanke Exp $ */ 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 * -------------- @@ -175,7 +167,7 @@ public abstract class Doc /** Purchase Requisition */ public static final String DOCTYPE_PurchaseRequisition = "POR"; - + // Posting Status - AD_Reference_ID=234 // /** Document Status */ public static final String STATUS_NotPosted = "N"; @@ -194,144 +186,32 @@ public abstract class Doc /** Document Status */ public static final String STATUS_Error = "E"; - + /** * Create Posting document - * @param ass accounting schema + * @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 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; - 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; + return DocManager.getDocument(as, AD_Table_ID, Record_ID, trxName); } // get - + /** * Create Posting document - * @param ass accounting schema + * @param as accounting schema * @param AD_Table_ID Table ID of Documents * @param rs ResultSet * @param trxName transaction name * @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; - - /* 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; + return DocManager.getDocument(as, AD_Table_ID, rs, trxName); } // get /** @@ -343,13 +223,10 @@ public abstract class Doc * @param trxName transaction * @return null if the document was posted or error message */ - public static String postImmediate (MAcctSchema[] ass, + public static String postImmediate (MAcctSchema[] ass, int AD_Table_ID, int Record_ID, boolean force, String trxName) { - Doc doc = get (ass, AD_Table_ID, Record_ID, trxName); - if (doc != null) - return doc.post (force, true); // repost - return "NoDoc"; + return DocManager.postDocument(ass, AD_Table_ID, Record_ID, force, true, trxName); } // post /** Static Log */ @@ -357,25 +234,25 @@ public abstract class Doc /** Log per Document */ protected CLogger log = CLogger.getCLogger(getClass()); - /* If the transaction must be managed locally (false if it's managed externally by the caller) */ + /* If the transaction must be managed locally (false if it's managed externally by the caller) */ private boolean m_manageLocalTrx; - + /************************************************************************** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param clazz Document Class * @param rs result set * @param defaultDocumentType default document type or null * @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; - m_ass = ass; - m_ctx = new Properties(m_ass[0].getCtx()); - m_ctx.setProperty("#AD_Client_ID", String.valueOf(m_ass[0].getAD_Client_ID())); - + m_as = as; + m_ctx = new Properties(m_as.getCtx()); + m_ctx.setProperty("#AD_Client_ID", String.valueOf(m_as.getAD_Client_ID())); + String className = clazz.getName(); className = className.substring(className.lastIndexOf('.')+1); try @@ -389,31 +266,32 @@ public abstract class Doc log.severe(msg); throw new IllegalArgumentException(msg); } - + // DocStatus int index = p_po.get_ColumnIndex("DocStatus"); if (index != -1) m_DocStatus = (String)p_po.get_Value(index); - + // Document Type setDocumentType (defaultDocumentType); m_trxName = trxName; m_manageLocalTrx = false; - if (m_trxName == null) { + if (m_trxName == null) + { m_trxName = "Post" + m_DocumentType + p_po.get_ID(); m_manageLocalTrx = true; } p_po.set_TrxName(m_trxName); // Amounts - m_Amounts[0] = Env.ZERO; - m_Amounts[1] = Env.ZERO; - m_Amounts[2] = Env.ZERO; - m_Amounts[3] = Env.ZERO; + for(int i = 0; i < m_Amounts.length; i++) + { + m_Amounts[i] = Env.ZERO; + } } // Doc - /** Accounting Schema Array */ - private MAcctSchema[] m_ass = null; + /** Accounting Schema */ + private MAcctSchema m_as = null; /** Properties */ private Properties m_ctx = null; /** Transaction Name */ @@ -467,7 +345,7 @@ public abstract class Doc /** No Currency in Document Indicator (-1) */ protected static final int NO_CURRENCY = -2; - + /** Actual Document Status */ protected String p_Status = null; public String getPostStatus() { @@ -476,8 +354,8 @@ public abstract class Doc /** Error Message */ protected String p_Error = null; - - + + /** * Get Context * @return context @@ -495,7 +373,7 @@ public abstract class Doc { return p_po.get_TableName(); } // get_TableName - + /** * Get Table ID * @return table id @@ -513,16 +391,16 @@ public abstract class Doc { return p_po.get_ID(); } // get_ID - + /** * Get Persistent Object * @return po */ - protected PO getPO() + public PO getPO() { return p_po; } // getPO - + /** * Post Document. *
    @@ -550,14 +428,14 @@ public abstract class Doc
     		else
     			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()
    -				+ ", AcctSchema=" + m_ass[0].getAD_Client_ID();
    +				+ ", AcctSchema=" + m_as.getAD_Client_ID();
     			log.severe(error);
     			return error;
     		}
    -		
    +
     		//  Lock Record ----
     		String trxName = null;	//	outside trx if on server
     		if (! m_manageLocalTrx)
    @@ -574,13 +452,13 @@ public abstract class Doc
     			log.info("Locked: " + get_TableName() + "_ID=" + get_ID());
     		else
     		{
    -			log.log(Level.SEVERE, "Resubmit - Cannot lock " + get_TableName() + "_ID=" 
    +			log.log(Level.SEVERE, "Resubmit - Cannot lock " + get_TableName() + "_ID="
     				+ get_ID() + ", Force=" + force + ",RePost=" + repost);
     			if (force)
     				return "Cannot Lock - ReSubmit";
     			return "Cannot Lock - ReSubmit or RePost with Force";
     		}
    -		
    +
     		p_Error = loadDocumentDetails();
     		if (p_Error != null)
     			return p_Error;
    @@ -606,43 +484,36 @@ public abstract class Doc
     			trx.commit(); trx.close();
     			return "AlreadyPosted";
     		}
    -		
    +
     		p_Status = STATUS_NotPosted;
     
     		//  Create Fact per AcctSchema
     		m_fact = new ArrayList();
     
    -		//  for all Accounting Schema
    -		boolean OK = true;
     		getPO().setDoc(this);
     		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
    -				boolean skip = false;
    -				if (m_ass[i].getAD_OrgOnly_ID() != 0)
    +				//	Header Level Org
    +				skip = m_as.isSkipOrg(getAD_Org_ID());
    +				//	Line Level Org
    +				if (p_lines != null)
     				{
    -					//	Header Level Org
    -					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++)
     					{
    -						for (int line = 0; skip && line < p_lines.length; line++)
    -						{
    -							skip = m_ass[i].isSkipOrg(p_lines[line].getAD_Org_ID());
    -							if (!skip)
    -								break;
    -						}
    +						skip = m_as.isSkipOrg(p_lines[line].getAD_Org_ID());
    +						if (!skip)
    +							break;
     					}
     				}
    -				if (skip)
    -					continue;
    +			}
    +			if (!skip)
    +			{
     				//	post
    -				log.info("(" + i + ") " + p_po);
    -				p_Status = postLogic (i);
    -				if (!p_Status.equals(STATUS_Posted))
    -					OK = false;
    +				p_Status = postLogic ();
     			}
     		}
     		catch (Exception e)
    @@ -650,39 +521,36 @@ public abstract class Doc
     			log.log(Level.SEVERE, "", e);
     			p_Status = STATUS_Error;
     			p_Error = e.toString();
    -			OK = false;
     		}
     
     		String validatorMsg = null;
     		// 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);
     			if (validatorMsg != null) {
     				p_Status = STATUS_Error;
     				p_Error = validatorMsg;
    -				OK = false;
     			}
     		}
     
     		//  commitFact
     		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);
     			if (validatorMsg != null) {
     				p_Status = STATUS_Error;
     				p_Error = validatorMsg;
    -				OK = false;
     			}
     		}
    -		  
    +
     		//  Create Note
     		if (!p_Status.equals(STATUS_Posted))
     		{
     			//  Insert Note
     			String AD_MessageValue = "PostingError-" + p_Status;
     			int AD_User_ID = p_po.getUpdatedBy();
    -			MNote note = new MNote (getCtx(), AD_MessageValue, AD_User_ID, 
    +			MNote note = new MNote (getCtx(), AD_MessageValue, AD_User_ID,
     				getAD_Client_ID(), getAD_Org_ID(), null);
     			note.setRecord(p_po.get_Table_ID(), p_po.get_ID());
     			//  Reference
    @@ -699,7 +567,8 @@ public abstract class Doc
     				.append(", Amount=").append(getAmount())
     				.append(", Sta=").append(p_Status)
     				.append(" - PeriodOpen=").append(isPeriodOpen())
    -				.append(", Balanced=").append(isBalanced());
    +				.append(", Balanced=").append(isBalanced())
    +				.append(", Schema=").append(m_as.getName());
     			note.setTextMsg(Text.toString());
     			note.save();
     			p_Error = Text.toString();
    @@ -723,11 +592,12 @@ public abstract class Doc
     	 * 	Delete Accounting
     	 *	@return number of records
     	 */
    -	private int deleteAcct()
    +	protected int deleteAcct()
     	{
     		StringBuffer sql = new StringBuffer ("DELETE Fact_Acct WHERE AD_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());
     		if (no != 0)
     			log.info("deleted=" + no);
    @@ -736,19 +606,16 @@ public abstract class Doc
     
     	/**
     	 *  Posting logic for Accounting Schema index
    -	 *  @param  index   Accounting Schema index
     	 *  @return posting status/error code
     	 */
    -	private final String postLogic (int index)
    +	private final String postLogic ()
     	{
    -		log.info("(" + index + ") " + p_po);
    -		
     		//  rejectUnbalanced
    -		if (!m_ass[index].isSuspenseBalancing() && !isBalanced())
    +		if (!m_as.isSuspenseBalancing() && !isBalanced())
     			return STATUS_NotBalanced;
     
     		//  rejectUnconvertible
    -		if (!isConvertible(m_ass[index]))
    +		if (!isConvertible(m_as))
     			return STATUS_NotConvertible;
     
     		//  rejectPeriodClosed
    @@ -756,17 +623,17 @@ public abstract class Doc
     			return STATUS_PeriodClosed;
     
     		//  createFacts
    -		ArrayList facts = createFacts (m_ass[index]);
    +		ArrayList facts = createFacts (m_as);
     		if (facts == null)
     			return STATUS_Error;
    -		
    +
     		// call modelValidator
    -		String validatorMsg = ModelValidationEngine.get().fireFactsValidate(m_ass[index], facts, getPO());
    +		String validatorMsg = ModelValidationEngine.get().fireFactsValidate(m_as, facts, getPO());
     		if (validatorMsg != null) {
     			p_Error = validatorMsg;
     			return STATUS_Error;
     		}
    -		
    +
     		for (int f = 0; f < facts.size(); f++)
     		{
     			Fact fact = facts.get(f);
    @@ -779,11 +646,11 @@ public abstract class Doc
     			//	check accounts
     			if (!fact.checkAccounts())
     				return STATUS_InvalidAccount;
    -			
    +
     			//	distribute
     			if (!fact.distribute())
     				return STATUS_Error;
    -			
    +
     			//  balanceSource
     			if (!fact.isSourceBalanced())
     			{
    @@ -807,9 +674,9 @@ public abstract class Doc
     				if (!fact.isAcctBalanced())
     					return STATUS_NotBalanced;
     			}
    -			
    +
     		}	//	for all facts
    -		
    +
     		return STATUS_Posted;
     	}   //  postLogic
     
    @@ -821,7 +688,7 @@ public abstract class Doc
     	 */
     	private final String postCommit (String status)
     	{
    -		log.info("Sta=" + status + " DT=" + getDocumentType() 
    +		log.info("Sta=" + status + " DT=" + getDocumentType()
     			+ " ID=" +  p_po.get_ID());
     		p_Status = status;
     
    @@ -851,17 +718,9 @@ public abstract class Doc
     					}
     				}
     			}
    -			//  Commit Doc
    -			if (!save(getTrxName()))     //  contains unlock & document status update
    -			{
    -				log.log(Level.SEVERE, "(doc not saved) ... rolling back");
    -				if (m_manageLocalTrx) {
    -					trx.rollback();
    -					trx.close();
    -				}
    -				unlock();
    -				return STATUS_Error;
    -			}
    +
    +			unlock();
    +
     			//	Success
     			if (m_manageLocalTrx) {
     				trx.commit(true);
    @@ -899,7 +758,7 @@ public abstract class Doc
     	{
     		return m_trxName;
     	}	//	getTrxName
    -	
    +
     	/**
     	 *  Unlock Document
     	 */
    @@ -960,13 +819,13 @@ public abstract class Doc
     			finally
     			{
     				DB.close(rsDT, pstmt);
    -				rsDT = null; 
    +				rsDT = null;
     				pstmt = null;
     			}
     		}
     		if (m_DocumentType == null)
     		{
    -			log.log(Level.SEVERE, "No DocBaseType for C_DocType_ID=" 
    +			log.log(Level.SEVERE, "No DocBaseType for C_DocType_ID="
     				+ getC_DocType_ID() + ", DocumentNo=" + getDocumentNo());
     		}
     
    @@ -1021,7 +880,7 @@ public abstract class Doc
     			throw new IllegalStateException("Document Type not found");
     	}	//	setDocumentType
     
    -	
    +
     	/**************************************************************************
     	 *  Is the Source Document Balanced
     	 *  @return true if (source) balanced
    @@ -1109,7 +968,7 @@ public abstract class Doc
     	{
     		if (m_period != null)
     			return;
    -		
    +
     		//	Period defined in GL Journal (e.g. adjustment period)
     		int index = p_po.get_ColumnIndex("C_Period_ID");
     		if (index != -1)
    @@ -1121,13 +980,13 @@ public abstract class Doc
     		if (m_period == null)
     			m_period = MPeriod.get(getCtx(), getDateAcct(), getAD_Org_ID());
     		//	Is Period Open?
    -		if (m_period != null 
    +		if (m_period != null
     			&& m_period.isOpen(getDocumentType(), getDateAcct()))
     			m_C_Period_ID = m_period.getC_Period_ID();
     		else
     			m_C_Period_ID = -1;
     		//
    -		log.fine(	// + AD_Client_ID + " - " 
    +		log.fine(	// + AD_Client_ID + " - "
     			getDateAcct() + " - " + getDocumentType() + " => " + m_C_Period_ID);
     	}   //  setC_Period_ID
     
    @@ -1234,7 +1093,7 @@ public abstract class Doc
     		}
     		return m_qty;
     	}   //  getQty
    -	
    +
     	/*************************************************************************/
     
     	/**	Account Type - Invoice - Charge  */
    @@ -1372,7 +1231,7 @@ public abstract class Doc
     			sql = "SELECT B_PaymentSelect_Acct FROM C_BankAccount_Acct WHERE C_BankAccount_ID=? AND C_AcctSchema_ID=?";
     			para_1 = getC_BankAccount_ID();
     		}
    -		
    +
     		/** Account Type - Allocation   */
     		else if (AcctType == ACCTTYPE_DiscountExp)
     		{
    @@ -1545,25 +1404,6 @@ public abstract class Doc
     		return acct;
     	}	//	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
     	 *  @param Record_ID Record ID
    @@ -1591,7 +1431,7 @@ public abstract class Doc
     		return p_po.toString();
     	}   //  toString
     
    -	
    +
     	/**
     	 * 	Get AD_Client_ID
     	 *	@return client
    @@ -1600,7 +1440,7 @@ public abstract class Doc
     	{
     		return p_po.getAD_Client_ID();
     	}	//	getAD_Client_ID
    -	
    +
     	/**
     	 * 	Get AD_Org_ID
     	 *	@return org
    @@ -1626,7 +1466,7 @@ public abstract class Doc
     		m_DocumentNo = (String)p_po.get_Value(index);
     		return m_DocumentNo;
     	}	//	getDocumentNo
    -	
    +
     	/**
     	 * 	Get Description
     	 *	@return Description
    @@ -1643,7 +1483,7 @@ public abstract class Doc
     		}
     		return m_Description;
     	}	//	getDescription
    -	
    +
     	/**
     	 * 	Get C_Currency_ID
     	 *	@return currency
    @@ -1664,7 +1504,7 @@ public abstract class Doc
     		}
     		return m_C_Currency_ID;
     	}	//	getC_Currency_ID
    -	
    +
     	/**
     	 * 	Set C_Currency_ID
     	 *	@param C_Currency_ID id
    @@ -1673,7 +1513,7 @@ public abstract class Doc
     	{
     		m_C_Currency_ID = C_Currency_ID;
     	}	//	setC_Currency_ID
    -	
    +
     	/**
     	 * 	Is Multi Currency
     	 *	@return mc
    @@ -1691,7 +1531,7 @@ public abstract class Doc
     	{
     		m_MultiCurrency = mc;
     	}	//	setIsMultiCurrency
    -	
    +
     	/**
     	 * 	Is Tax Included
     	 *	@return tax incl
    @@ -1709,7 +1549,7 @@ public abstract class Doc
     	{
     		m_TaxIncluded = ti;
     	}	//	setIsTaxIncluded
    -	
    +
     	/**
     	 * 	Get C_ConversionType_ID
     	 *	@return ConversionType
    @@ -1725,7 +1565,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getC_ConversionType_ID
    -	
    +
     	/**
     	 * 	Get GL_Category_ID
     	 *	@return category
    @@ -1734,7 +1574,7 @@ public abstract class Doc
     	{
     		return m_GL_Category_ID;
     	}	//	getGL_Category_ID
    -	
    +
     	/**
     	 * 	Get GL_Category_ID
     	 *	@return category
    @@ -1777,7 +1617,7 @@ public abstract class Doc
     	{
     		m_DateAcct = da;
     	}	//	setDateAcct
    -	
    +
     	/**
     	 * 	Get Document Date
     	 *	@return currency
    @@ -1797,7 +1637,7 @@ public abstract class Doc
     		}
     		throw new IllegalStateException("No DateDoc");
     	}	//	getDateDoc
    -	
    +
     	/**
     	 * 	Set Date Doc
     	 *	@param dd document date
    @@ -1824,7 +1664,7 @@ public abstract class Doc
     		}
     		throw new IllegalStateException("No Posted");
     	}	//	isPosted
    -	
    +
     	/**
     	 * 	Is Sales Trx
     	 *	@return true if posted
    @@ -1867,7 +1707,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getC_DocType_ID
    -	
    +
     	/**
     	 * 	Get header level C_Charge_ID
     	 *	@return Charge
    @@ -1899,7 +1739,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getSalesRep_ID
    -	
    +
     	/**
     	 * 	Get C_BankAccount_ID
     	 *	@return BankAccount
    @@ -1929,7 +1769,7 @@ public abstract class Doc
     	{
     		m_C_BankAccount_ID = C_BankAccount_ID;
     	}	//	setC_BankAccount_ID
    -		
    +
     	/**
     	 * 	Get C_CashBook_ID
     	 *	@return CashBook
    @@ -1976,7 +1816,7 @@ public abstract class Doc
     		return 0;
     	}	//	getM_Warehouse_ID
     
    -	
    +
     	/**
     	 * 	Get C_BPartner_ID
     	 *	@return BPartner
    @@ -2006,7 +1846,7 @@ public abstract class Doc
     	{
     		m_C_BPartner_ID = C_BPartner_ID;
     	}	//	setC_BPartner_ID
    -	
    +
     	/**
     	 * 	Get C_BPartner_Location_ID
     	 *	@return BPartner Location
    @@ -2038,7 +1878,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getC_Project_ID
    -	
    +
     	/**
     	 * 	Get C_ProjectPhase_ID
     	 *	@return Project Phase
    @@ -2054,7 +1894,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getC_ProjectPhase_ID
    -	
    +
     	/**
     	 * 	Get C_ProjectTask_ID
     	 *	@return Project Task
    @@ -2070,7 +1910,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getC_ProjectTask_ID
    -	
    +
     	/**
     	 * 	Get C_SalesRegion_ID
     	 *	@return Sales Region
    @@ -2086,7 +1926,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getC_SalesRegion_ID
    -	
    +
     	/**
     	 * 	Get C_SalesRegion_ID
     	 *	@return Sales Region
    @@ -2116,7 +1956,7 @@ public abstract class Doc
     	{
     		m_BP_C_SalesRegion_ID = C_SalesRegion_ID;
     	}	//	setBP_C_SalesRegion_ID
    -	
    +
     	/**
     	 * 	Get C_Activity_ID
     	 *	@return Activity
    @@ -2189,7 +2029,7 @@ public abstract class Doc
     	{
     		return m_C_LocFrom_ID;
     	}	//	getC_LocFrom_ID
    -	
    +
     	/**
     	 * 	Set C_LocFrom_ID
     	 *	@param C_LocFrom_ID loc from
    @@ -2232,7 +2072,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getUser1_ID
    -	
    +
     	/**
     	 * 	Get User2_ID
     	 *	@return Campaign
    @@ -2248,7 +2088,7 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getUser2_ID
    -        
    +
             	/**
     	 * 	Get User Defined value
     	 *	@return User defined
    @@ -2264,8 +2104,8 @@ public abstract class Doc
     		}
     		return 0;
     	}	//	getValue
    -	
    -	
    +
    +
     	/*************************************************************************/
     	//  To be overwritten by Subclasses
     
    @@ -2295,60 +2135,4 @@ public abstract class Doc
     	public ArrayList getFacts() {
     		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 tableIDs = new ArrayList();
    -			ArrayList tableNames = new ArrayList();
    -			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
    diff --git a/org.adempiere.base/src/org/compiere/acct/DocManager.java b/org.adempiere.base/src/org/compiere/acct/DocManager.java
    new file mode 100644
    index 0000000000..26c6801bab
    --- /dev/null
    +++ b/org.adempiere.base/src/org/compiere/acct/DocManager.java
    @@ -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 tableIDs = new ArrayList();
    +			ArrayList tableNames = new ArrayList();
    +			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 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 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
    +}
    diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_AllocationHdr.java b/org.adempiere.base/src/org/compiere/acct/Doc_AllocationHdr.java
    index d206519bbd..f0edb20a2d 100644
    --- a/org.adempiere.base/src/org/compiere/acct/Doc_AllocationHdr.java
    +++ b/org.adempiere.base/src/org/compiere/acct/Doc_AllocationHdr.java
    @@ -46,26 +46,26 @@ import org.compiere.util.Env;
      *  
    * @author Jorg Janke * @version $Id: Doc_Allocation.java,v 1.6 2006/07/30 00:53:33 jjanke Exp $ - * - * FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual + * + * FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual * Avoid posting if Receipt and both accounts Unallocated Cash and Receivable are equal * Avoid posting if Payment and both accounts Payment Select and Liability are equal - * + * * @author phib * BF [ 2019262 ] Allocation posting currency gain/loss omits line reference - * + * */ public class Doc_AllocationHdr extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** Tolerance G&L */ @@ -100,7 +100,7 @@ public class Doc_AllocationHdr extends Doc { MAllocationLine line = lines[i]; DocLine_Allocation docLine = new DocLine_Allocation(line, this); - + // Get Payment Conversion Rate if (line.getC_Payment_ID() != 0) { @@ -119,7 +119,7 @@ public class Doc_AllocationHdr extends Doc return dls; } // loadLines - + /************************************************************************** * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding * @return positive amount, if total invoice is bigger than lines @@ -145,7 +145,7 @@ public class Doc_AllocationHdr extends Doc * DiscountExp DR * WriteOff DR * Receivables CR - * + * * AP_Invoice_Payment * Liability DR * DiscountRev CR @@ -163,7 +163,7 @@ public class Doc_AllocationHdr extends Doc * Realized Gain & Loss * AR/AP DR CR * Realized G/L DR CR - * + * * * * Tax needs to be corrected for discount & write-off; @@ -184,15 +184,15 @@ public class Doc_AllocationHdr extends Doc { DocLine_Allocation line = (DocLine_Allocation)p_lines[i]; setC_BPartner_ID(line.getC_BPartner_ID()); - + // CashBankTransfer - all references null and Discount/WriteOff = 0 - if (line.getC_Payment_ID() != 0 + if (line.getC_Payment_ID() != 0 && line.getC_Invoice_ID() == 0 && line.getC_Order_ID() == 0 && line.getC_CashLine_ID() == 0 && line.getC_BPartner_ID() == 0 && Env.ZERO.compareTo(line.getDiscountAmt()) == 0 && Env.ZERO.compareTo(line.getWriteOffAmt()) == 0) continue; - + // Receivables/Liability Amt BigDecimal allocationSource = line.getAmtSource() .add(line.getDiscountAmt()) @@ -211,7 +211,7 @@ public class Doc_AllocationHdr extends Doc MInvoice invoice = null; if (line.getC_Invoice_ID() != 0) invoice = new MInvoice (getCtx(), line.getC_Invoice_ID(), getTrxName()); - + // No Invoice if (invoice == null) { @@ -230,32 +230,32 @@ public class Doc_AllocationHdr extends Doc return null; } } - // Sales Invoice + // Sales Invoice else if (invoice.isSOTrx()) { // Avoid usage of clearing accounts // If both accounts Unallocated Cash and Receivable are equal // then don't post - + MAccount acct_unallocated_cash = null; if (line.getC_Payment_ID() != 0) - acct_unallocated_cash = getPaymentAcct(as, line.getC_Payment_ID()); + acct_unallocated_cash = getPaymentAcct(as, line.getC_Payment_ID()); else if (line.getC_CashLine_ID() != 0) acct_unallocated_cash = getCashAcct(as, line.getC_CashLine_ID()); MAccount acct_receivable = getAccount(Doc.ACCTTYPE_C_Receivable, as); - + if ((!as.isPostIfClearingEqual()) && acct_unallocated_cash != null && acct_unallocated_cash.equals(acct_receivable) && (!isInterOrg)) { - + // if not using clearing accounts, then don't post amtsource // change the allocationsource to be writeoff + discount allocationSource = line.getDiscountAmt().add(line.getWriteOffAmt()); - + } else { - + // Normal behavior -- unchanged if using clearing accounts - + // Payment/Cash DR if (line.getC_Payment_ID() != 0) { @@ -275,7 +275,7 @@ public class Doc_AllocationHdr extends Doc } // End Avoid usage of clearing accounts - + // Discount DR if (Env.ZERO.compareTo(line.getDiscountAmt()) != 0) { @@ -292,27 +292,27 @@ public class Doc_AllocationHdr extends Doc if (fl != null && payment != null) fl.setAD_Org_ID(payment.getAD_Org_ID()); } - + // AR Invoice Amount CR if (as.isAccrual()) { bpAcct = getAccount(Doc.ACCTTYPE_C_Receivable, as); fl = fact.createLine (line, bpAcct, - getC_Currency_ID(), null, allocationSource); // payment currency + getC_Currency_ID(), null, allocationSource); // payment currency if (fl != null) allocationAccounted = fl.getAcctBalance().negate(); if (fl != null && invoice != null) fl.setAD_Org_ID(invoice.getAD_Org_ID()); - + // for Realized Gain & Loss flForRGL = factForRGL.createLine (line, bpAcct, - getC_Currency_ID(), null, allocationSourceForRGL); // payment currency + getC_Currency_ID(), null, allocationSourceForRGL); // payment currency if (flForRGL != null) allocationAccountedForRGL = flForRGL.getAcctBalance().negate(); } else // Cash Based { - allocationAccounted = createCashBasedAcct (as, fact, + allocationAccounted = createCashBasedAcct (as, fact, invoice, allocationSource); allocationAccountedForRGL = allocationAccounted; } @@ -331,12 +331,12 @@ public class Doc_AllocationHdr extends Doc acct_payment_select = getCashAcct(as, line.getC_CashLine_ID()); MAccount acct_liability = getAccount(Doc.ACCTTYPE_V_Liability, as); boolean isUsingClearing = true; - + // Save original allocation source for realized gain & loss purposes allocationSourceForRGL = allocationSourceForRGL.negate(); - + if ((!as.isPostIfClearingEqual()) && acct_payment_select != null && acct_payment_select.equals(acct_liability) && (!isInterOrg)) { - + // if not using clearing accounts, then don't post amtsource // change the allocationsource to be writeoff + discount allocationSource = line.getDiscountAmt().add(line.getWriteOffAmt()); @@ -344,7 +344,7 @@ public class Doc_AllocationHdr extends Doc } // End Avoid usage of clearing accounts - + allocationSource = allocationSource.negate(); // allocation is negative // AP Invoice Amount DR if (as.isAccrual()) @@ -365,11 +365,11 @@ public class Doc_AllocationHdr extends Doc } else // Cash Based { - allocationAccounted = createCashBasedAcct (as, fact, + allocationAccounted = createCashBasedAcct (as, fact, invoice, allocationSource); allocationAccountedForRGL = allocationAccounted; } - + // Discount CR if (Env.ZERO.compareTo(line.getDiscountAmt()) != 0) { @@ -403,7 +403,7 @@ public class Doc_AllocationHdr extends Doc fl.setAD_Org_ID(cashLine.getAD_Org_ID()); } } - + // VAT Tax Correction if (invoice != null && as.isTaxCorrection()) { @@ -415,8 +415,8 @@ public class Doc_AllocationHdr extends Doc // if (taxCorrectionAmt.signum() != 0) { - if (!createTaxCorrection(as, fact, line, - getAccount(invoice.isSOTrx() ? Doc.ACCTTYPE_DiscountExp : Doc.ACCTTYPE_DiscountRev, as), + if (!createTaxCorrection(as, fact, line, + getAccount(invoice.isSOTrx() ? Doc.ACCTTYPE_DiscountExp : Doc.ACCTTYPE_DiscountRev, as), getAccount(Doc.ACCTTYPE_WriteOff, as), invoice.isSOTrx())) { p_Error = "Cannot create Tax correction"; @@ -424,18 +424,18 @@ public class Doc_AllocationHdr extends Doc } } } - + // Realized Gain & Loss if (invoice != null && (getC_Currency_ID() != as.getC_Currency_ID() // payment allocation in foreign currency || getC_Currency_ID() != line.getInvoiceC_Currency_ID())) // allocation <> invoice currency { - p_Error = createRealizedGainLoss (line, as, fact, bpAcct, invoice, + p_Error = createRealizedGainLoss (line, as, fact, bpAcct, invoice, allocationSource, allocationAccounted); if (p_Error != null) return null; } - + } // for all lines // FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual @@ -462,7 +462,7 @@ public class Doc_AllocationHdr extends Doc fact.remove(factline); } } - + // reset line info setC_BPartner_ID(0); // @@ -479,12 +479,12 @@ public class Doc_AllocationHdr extends Doc // no org element or not need to be balanced return false; } - + if (p_lines.length <= 0) { // no lines return false; } - + int startorg = p_lines[0].getAD_Org_ID(); // validate if the allocation involves more than one org for (int i = 0; i < p_lines.length; i++) { @@ -513,20 +513,20 @@ public class Doc_AllocationHdr extends Doc order = new MOrder (getCtx(), line.getC_Order_ID(), getTrxName()); orgorder = order.getAD_Org_ID(); } - - if ( line.getAD_Org_ID() != startorg + + if ( line.getAD_Org_ID() != startorg || orgpayment != startorg - || orginvoice != startorg + || orginvoice != startorg || orgcashline != startorg || orgorder != startorg) return true; } - + return false; } /** - * Compare the dimension ID's from two factlines + * Compare the dimension ID's from two factlines * @param allEquals * @param prevFactLine * @param factLine @@ -547,8 +547,8 @@ public class Doc_AllocationHdr extends Doc && factLine.getC_LocTo_ID() == prevFactLine.getC_LocTo_ID() && factLine.getC_Period_ID() == prevFactLine.getC_Period_ID() && factLine.getC_Project_ID() == prevFactLine.getC_Project_ID() - && factLine.getC_ProjectPhase_ID() == prevFactLine.getC_ProjectPhase_ID() - && factLine.getC_ProjectTask_ID() == prevFactLine.getC_ProjectTask_ID() + && factLine.getC_ProjectPhase_ID() == prevFactLine.getC_ProjectPhase_ID() + && factLine.getC_ProjectTask_ID() == prevFactLine.getC_ProjectTask_ID() && factLine.getC_SalesRegion_ID() == prevFactLine.getC_SalesRegion_ID() && factLine.getC_SubAcct_ID() == prevFactLine.getC_SubAcct_ID() && factLine.getC_Tax_ID() == prevFactLine.getC_Tax_ID() @@ -559,7 +559,7 @@ public class Doc_AllocationHdr extends Doc && factLine.getM_Product_ID() == prevFactLine.getM_Product_ID() && factLine.getUserElement1_ID() == prevFactLine.getUserElement1_ID() && factLine.getUserElement2_ID() == prevFactLine.getUserElement2_ID() - && factLine.getUser1_ID() == prevFactLine.getUser1_ID() + && factLine.getUser1_ID() == prevFactLine.getUser1_ID() && factLine.getUser2_ID() == prevFactLine.getUser2_ID()); } @@ -571,7 +571,7 @@ public class Doc_AllocationHdr extends Doc * @param allocationSource allocation amount (incl discount, writeoff) * @return Accounted Amt */ - private BigDecimal createCashBasedAcct (MAcctSchema as, Fact fact, MInvoice invoice, + private BigDecimal createCashBasedAcct (MAcctSchema as, Fact fact, MInvoice invoice, BigDecimal allocationSource) { BigDecimal allocationAccounted = Env.ZERO; @@ -581,32 +581,32 @@ public class Doc_AllocationHdr extends Doc percent = 1.0; log.config("Multiplier=" + percent + " - GrandTotal=" + invoice.getGrandTotal() + " - Allocation Source=" + allocationSource); - + // 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()); docInvoice.loadDocumentDetails(); allocationAccounted = docInvoice.createFactCash(as, fact, new BigDecimal(percent)); log.config("Allocation Accounted=" + allocationAccounted); - - // Cash Based Commitment Release + + // Cash Based Commitment Release if (as.isCreatePOCommitment() && !invoice.isSOTrx()) { MInvoiceLine[] lines = invoice.getLines(); for (int i = 0; i < lines.length; i++) { - Fact factC = Doc_Order.getCommitmentRelease(as, this, + Fact factC = Doc_Order.getCommitmentRelease(as, this, lines[i].getQtyInvoiced(), lines[i].getC_InvoiceLine_ID(), new BigDecimal(percent)); if (factC == null) return null; m_facts.add(factC); } } // Commitment - + return allocationAccounted; } // createCashBasedAcct - + /** * Get Payment (Unallocated Payment or Payment Selection) Acct of Bank Account * @param as accounting schema @@ -616,7 +616,7 @@ public class Doc_AllocationHdr extends Doc private MAccount getPaymentAcct (MAcctSchema as, int C_Payment_ID) { setC_BankAccount_ID(0); - // Doc.ACCTTYPE_UnallocatedCash (AR) or C_Prepayment + // Doc.ACCTTYPE_UnallocatedCash (AR) or C_Prepayment // or Doc.ACCTTYPE_PaymentSelect (AP) or V_Prepayment int accountType = Doc.ACCTTYPE_UnallocatedCash; // @@ -644,7 +644,7 @@ public class Doc_AllocationHdr extends Doc accountType = Doc.ACCTTYPE_V_Prepayment; } } - } + } catch (Exception e) { log.log(Level.SEVERE, sql, e); @@ -654,7 +654,7 @@ public class Doc_AllocationHdr extends Doc DB.close(rs, pstmt); rs = null; pstmt = null; } - + // if (getC_BankAccount_ID() <= 0) { @@ -663,7 +663,7 @@ public class Doc_AllocationHdr extends Doc } return getAccount (accountType, as); } // getPaymentAcct - + /** * Get Cash (Transfer) Acct of CashBook * @param as accounting schema @@ -683,7 +683,7 @@ public class Doc_AllocationHdr extends Doc } return getAccount(Doc.ACCTTYPE_CashTransfer, as); } // getCashAcct - + /************************************************************************** * Create Realized Gain & Loss. @@ -703,9 +703,9 @@ public class Doc_AllocationHdr extends Doc BigDecimal invoiceSource = null; BigDecimal invoiceAccounted = null; // - String sql = "SELECT " - + (invoice.isSOTrx() - ? "SUM(AmtSourceDr), SUM(AmtAcctDr)" // so + String sql = "SELECT " + + (invoice.isSOTrx() + ? "SUM(AmtSourceDr), SUM(AmtAcctDr)" // so : "SUM(AmtSourceCr), SUM(AmtAcctCr)") // po + " FROM Fact_Acct " + "WHERE AD_Table_ID=318 AND Record_ID=?" // Invoice @@ -744,13 +744,13 @@ public class Doc_AllocationHdr extends Doc // Allocation not Invoice Currency if (getC_Currency_ID() != invoice.getC_Currency_ID()) { - BigDecimal allocationSourceNew = MConversionRate.convert(getCtx(), - allocationSource, getC_Currency_ID(), - invoice.getC_Currency_ID(), getDateAcct(), + BigDecimal allocationSourceNew = MConversionRate.convert(getCtx(), + allocationSource, getC_Currency_ID(), + invoice.getC_Currency_ID(), getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID()); if (allocationSourceNew == null) return "Gain/Loss - No Conversion from Allocation->Invoice"; - String d2 = "Allocation=(" + getC_Currency_ID() + ")" + allocationSource + String d2 = "Allocation=(" + getC_Currency_ID() + ")" + allocationSource + "->(" + invoice.getC_Currency_ID() + ")" + allocationSourceNew; log.fine(d2); description += " - " + d2; @@ -785,22 +785,22 @@ public class Doc_AllocationHdr extends Doc log.fine(d2); description += " - " + d2; } - + if (acctDifference.signum() == 0) { log.fine("No Difference"); return null; } - + MAccount gain = MAccount.get (as.getCtx(), as.getAcctSchemaDefault().getRealizedGain_Acct()); MAccount loss = MAccount.get (as.getCtx(), as.getAcctSchemaDefault().getRealizedLoss_Acct()); // if (invoice.isSOTrx()) { - FactLine fl = fact.createLine (line, loss, gain, + FactLine fl = fact.createLine (line, loss, gain, as.getC_Currency_ID(), acctDifference); fl.setDescription(description); - fact.createLine (line, acct, + fact.createLine (line, acct, as.getC_Currency_ID(), acctDifference.negate()); fl.setDescription(description); } @@ -808,7 +808,7 @@ public class Doc_AllocationHdr extends Doc { fact.createLine (line, acct, as.getC_Currency_ID(), acctDifference); - FactLine fl = fact.createLine (line, loss, gain, + FactLine fl = fact.createLine (line, loss, gain, as.getC_Currency_ID(), acctDifference.negate()); } return null; @@ -823,8 +823,8 @@ public class Doc_AllocationHdr extends Doc * Example: * Invoice: Net $100 + Tax1 $15 + Tax2 $5 = Total $120 * Payment: $115 (i.e. $5 underpayment) - * Tax Adjustment = Tax1 = 0.63 (15/120*5) Tax2 = 0.21 (5/120/5) - * + * Tax Adjustment = Tax1 = 0.63 (15/120*5) Tax2 = 0.21 (5/120/5) + * * @param as accounting schema * @param fact fact * @param line Allocation line @@ -832,7 +832,7 @@ public class Doc_AllocationHdr extends Doc * @param WriteOffAccoint write off acct * @return true if created */ - private boolean createTaxCorrection (MAcctSchema as, Fact fact, + private boolean createTaxCorrection (MAcctSchema as, Fact fact, DocLine_Allocation line, MAccount DiscountAccount, MAccount WriteOffAccoint, boolean isSOTrx) { @@ -843,10 +843,10 @@ public class Doc_AllocationHdr extends Doc BigDecimal writeOff = Env.ZERO; if (as.isTaxCorrectionWriteOff()) writeOff = line.getWriteOffAmt(); - + Doc_AllocationTax tax = new Doc_AllocationTax ( DiscountAccount, discount, WriteOffAccoint, writeOff, isSOTrx); - + // Get Source Amounts with account String sql = "SELECT * " + "FROM Fact_Acct " @@ -882,14 +882,14 @@ public class Doc_AllocationHdr extends Doc if (tax.getLineCount() < 2) return true; return tax.createEntries (as, fact, line); - + } // createTaxCorrection } // Doc_Allocation /** * Allocation Document Tax Handing - * + * * @author Jorg Janke * @version $Id: Doc_Allocation.java,v 1.6 2006/07/30 00:53:33 jjanke Exp $ */ @@ -931,7 +931,7 @@ class Doc_AllocationTax { m_facts.add(fact); } // addInvoiceLine - + /** * Get Line Count * @return number of lines @@ -940,7 +940,7 @@ class Doc_AllocationTax { return m_facts.size(); } // getLineCount - + /** * Create Accounting Entries * @param as account schema @@ -958,15 +958,15 @@ class Doc_AllocationTax if (factAcct.getAmtSourceDr().compareTo(total) > 0) { total = factAcct.getAmtSourceDr(); - m_totalIndex = i; + m_totalIndex = i; } if (factAcct.getAmtSourceCr().compareTo(total) > 0) { total = factAcct.getAmtSourceCr(); - m_totalIndex = i; + m_totalIndex = i; } } - + MFactAcct factAcct = (MFactAcct)m_facts.get(m_totalIndex); log.info ("Total Invoice = " + total + " - " + factAcct); int precision = as.getStdPrecision(); @@ -975,10 +975,10 @@ class Doc_AllocationTax // No Tax Line if (i == m_totalIndex) continue; - + factAcct = (MFactAcct)m_facts.get(i); log.info (i + ": " + factAcct); - + // Create Tax Account MAccount taxAcct = factAcct.getMAccount(); if (taxAcct == null || taxAcct.get_ID() == 0) @@ -986,15 +986,15 @@ class Doc_AllocationTax log.severe ("Tax Account not found/created"); return false; } - - -// Discount Amount + + +// Discount Amount if (m_DiscountAmt.signum() != 0) { // Original Tax is DR - need to correct it CR if (Env.ZERO.compareTo(factAcct.getAmtSourceDr()) != 0) { - BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(), + BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(), total, m_DiscountAmt, precision); if (amount.signum() != 0) { @@ -1011,13 +1011,13 @@ class Doc_AllocationTax fact.createLine (line, taxAcct, as.getC_Currency_ID(), null, amount.negate()); } - + } } // Original Tax is CR - need to correct it DR else { - BigDecimal amount = calcAmount(factAcct.getAmtSourceCr(), + BigDecimal amount = calcAmount(factAcct.getAmtSourceCr(), total, m_DiscountAmt, precision); if (amount.signum() != 0) { @@ -1036,14 +1036,14 @@ class Doc_AllocationTax } } } // Discount - - // WriteOff Amount + + // WriteOff Amount if (m_WriteOffAmt.signum() != 0) { // Original Tax is DR - need to correct it CR if (Env.ZERO.compareTo(factAcct.getAmtSourceDr()) != 0) { - BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(), + BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(), total, m_WriteOffAmt, precision); if (amount.signum() != 0) { @@ -1056,7 +1056,7 @@ class Doc_AllocationTax // Original Tax is CR - need to correct it DR else { - BigDecimal amount = calcAmount(factAcct.getAmtSourceCr(), + BigDecimal amount = calcAmount(factAcct.getAmtSourceCr(), total, m_WriteOffAmt, precision); if (amount.signum() != 0) { @@ -1067,11 +1067,11 @@ class Doc_AllocationTax } } } // WriteOff - + } // for all lines return true; } // createEntries - + /** * Calc Amount tax / total * amt * @param tax tax @@ -1083,17 +1083,17 @@ class Doc_AllocationTax private BigDecimal calcAmount (BigDecimal tax, BigDecimal total, BigDecimal amt, int precision) { log.fine("Amt=" + amt + " - Total=" + total + ", Tax=" + tax); - if (tax.signum() == 0 + if (tax.signum() == 0 || total.signum() == 0 || amt.signum() == 0) return Env.ZERO; // - BigDecimal multiplier = tax.divide(total, 10, BigDecimal.ROUND_HALF_UP); + BigDecimal multiplier = tax.divide(total, 10, BigDecimal.ROUND_HALF_UP); BigDecimal retValue = multiplier.multiply(amt); if (retValue.scale() > precision) retValue = retValue.setScale(precision, BigDecimal.ROUND_HALF_UP); log.fine(retValue + " (Mult=" + multiplier + "(Prec=" + precision + ")"); return retValue; } // calcAmount - + } // Doc_AllocationTax diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_BankStatement.java b/org.adempiere.base/src/org/compiere/acct/Doc_BankStatement.java index 762f8f716d..c687355495 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_BankStatement.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_BankStatement.java @@ -36,27 +36,27 @@ import org.compiere.util.Env; * * @author Jorg Janke * @version $Id: Doc_Bank.java,v 1.3 2006/07/30 00:53:33 jjanke Exp $ - * - * FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual + * + * FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual * Avoid posting if both accounts BankAsset and BankInTransit are equal * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • FR [ 2520591 ] Support multiples calendar for Org - * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 - * + *
  • FR [ 2520591 ] Support multiples calendar for Org + * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 + * */ public class Doc_BankStatement extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 - + /** Bank Account */ private int m_C_BankAccount_ID = 0; @@ -69,7 +69,7 @@ public class Doc_BankStatement extends Doc MBankStatement bs = (MBankStatement)getPO(); setDateDoc(bs.getStatementDate()); setDateAcct(bs.getStatementDate()); // Overwritten on Line Level - + m_C_BankAccount_ID = bs.getC_BankAccount_ID(); // Amounts setAmount(AMTTYPE_Gross, bs.getStatementDifference()); @@ -118,7 +118,7 @@ public class Doc_BankStatement extends Doc return dls; } // loadLines - + /************************************************************************** * Get Source Currency Balance - subtracts line amounts from total - no rounding * @return positive amount, if total invoice is bigger than lines @@ -170,20 +170,20 @@ public class Doc_BankStatement extends Doc { DocLine_Bank line = (DocLine_Bank)p_lines[i]; int C_BPartner_ID = line.getC_BPartner_ID(); - + // Avoid usage of clearing accounts // If both accounts BankAsset and BankInTransit are equal // then remove the posting - + MAccount acct_bank_asset = getAccount(Doc.ACCTTYPE_BankAsset, as); MAccount acct_bank_in_transit = getAccount(Doc.ACCTTYPE_BankInTransit, as); - + // if ((!as.isPostIfClearingEqual()) && acct_bank_asset.equals(acct_bank_in_transit) && (!isInterOrg)) { // don't validate interorg on banks for this - normally banks are balanced by orgs if ((!as.isPostIfClearingEqual()) && acct_bank_asset.equals(acct_bank_in_transit)) { // Not using clearing accounts // just post the difference (if any) - + BigDecimal amt_stmt_minus_trx = line.getStmtAmt().subtract(line.getTrxAmt()); if (amt_stmt_minus_trx.compareTo(Env.ZERO) != 0) { @@ -195,13 +195,13 @@ public class Doc_BankStatement extends Doc fl.setAD_Org_ID(AD_Org_ID); if (fl != null && C_BPartner_ID != 0) fl.setC_BPartner_ID(C_BPartner_ID); - + } - + } else { - + // Normal Adempiere behavior -- unchanged if using clearing accounts - + // BankAsset DR CR (Statement) fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_BankAsset, as), @@ -210,7 +210,7 @@ public class Doc_BankStatement extends Doc fl.setAD_Org_ID(AD_Org_ID); if (fl != null && C_BPartner_ID != 0) fl.setC_BPartner_ID(C_BPartner_ID); - + // BankInTransit DR CR (Payment) fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_BankInTransit, as), @@ -224,10 +224,10 @@ public class Doc_BankStatement extends Doc else fl.setAD_Org_ID(line.getAD_Org_ID(true)); // from payment } - + } // End Avoid usage of clearing accounts - + // Charge DR (Charge) if (line.getChargeAmt().compareTo(Env.ZERO) > 0) { fl = fact.createLine(line, @@ -269,12 +269,12 @@ public class Doc_BankStatement extends Doc // no org element or not need to be balanced return false; } - + if (p_lines.length <= 0) { // no lines return false; } - + int startorg = getBank_Org_ID(); if (startorg == 0) startorg = p_lines[0].getAD_Org_ID(); @@ -283,7 +283,7 @@ public class Doc_BankStatement extends Doc if (p_lines[i].getAD_Org_ID() != startorg) return true; } - + return false; } */ diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Cash.java b/org.adempiere.base/src/org/compiere/acct/Doc_Cash.java index b1d095b9da..98f1553b80 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Cash.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Cash.java @@ -40,13 +40,13 @@ public class Doc_Cash extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** @@ -97,7 +97,7 @@ public class Doc_Cash extends Doc return dls; } // loadLines - + /************************************************************************** * Get Source Currency Balance - subtracts line amounts from total - no rounding * @return positive amount, if total invoice is bigger than lines diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_GLJournal.java b/org.adempiere.base/src/org/compiere/acct/Doc_GLJournal.java index 74115fef61..75b5f7fcfa 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_GLJournal.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_GLJournal.java @@ -40,19 +40,19 @@ public class Doc_GLJournal extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** Posting Type */ private String m_PostingType = null; private int m_C_AcctSchema_ID = 0; - + /** * Load Specific Document Details * @return error message or null @@ -62,7 +62,7 @@ public class Doc_GLJournal extends Doc MJournal journal = (MJournal)getPO(); m_PostingType = journal.getPostingType(); m_C_AcctSchema_ID = journal.getC_AcctSchema_ID(); - + // Contained Objects p_lines = loadLines(journal); log.fine("Lines=" + p_lines.length); @@ -82,7 +82,7 @@ public class Doc_GLJournal extends Doc for (int i = 0; i < lines.length; i++) { MJournalLine line = lines[i]; - DocLine docLine = new DocLine (line, this); + DocLine docLine = new DocLine (line, this); // -- Source Amounts docLine.setAmount (line.getAmtSourceDr(), line.getAmtSourceCr()); // -- Converted Amounts @@ -100,7 +100,7 @@ public class Doc_GLJournal extends Doc return dls; } // loadLines - + /************************************************************************** * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding * @return positive amount, if total invoice is bigger than lines @@ -137,7 +137,7 @@ public class Doc_GLJournal extends Doc // Other Acct Schema if (as.getC_AcctSchema_ID() != m_C_AcctSchema_ID) return facts; - + // create Fact Header Fact fact = new Fact (this, as, m_PostingType); diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_InOut.java b/org.adempiere.base/src/org/compiere/acct/Doc_InOut.java index b6dd054009..697d7d432e 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_InOut.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_InOut.java @@ -50,18 +50,18 @@ public class Doc_InOut extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 private int m_Reversal_ID = 0; private String m_DocStatus = ""; - + /** * Load Document Details * @return error message or null @@ -91,20 +91,20 @@ public class Doc_InOut extends Doc for (int i = 0; i < lines.length; i++) { MInOutLine line = lines[i]; - if (line.isDescription() + if (line.isDescription() || line.getM_Product_ID() == 0 || line.getMovementQty().signum() == 0) { log.finer("Ignored: " + line); continue; } - + DocLine docLine = new DocLine (line, this); BigDecimal Qty = line.getMovementQty(); - docLine.setReversalLine_ID(line.getReversalLine_ID()); + docLine.setReversalLine_ID(line.getReversalLine_ID()); docLine.setQty (Qty, getDocumentType().equals(DOCTYPE_MatShipment)); // sets Trx and Storage Qty - - //Define if Outside Processing + + //Define if Outside Processing String sql = "SELECT PP_Cost_Collector_ID FROM C_OrderLine WHERE C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL"; int PP_Cost_Collector_ID = DB.getSQLValueEx(getTrxName(), sql, new Object[]{line.getC_OrderLine_ID()}); docLine.setPP_Cost_Collector_ID(PP_Cost_Collector_ID); @@ -165,7 +165,7 @@ public class Doc_InOut extends Doc { DocLine line = p_lines[i]; // MZ Goodwill - // if Shipment CostDetail exist then get Cost from Cost Detail + // if Shipment CostDetail exist then get Cost from Cost Detail BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=?"); // end MZ if (costs == null || costs.signum() == 0) // zero costs OK @@ -195,18 +195,18 @@ public class Doc_InOut extends Doc dr.setLocationFromBPartner(getC_BPartner_Location_ID(), false); // to Loc dr.setAD_Org_ID(line.getOrder_Org_ID()); // Revenue X-Org dr.setQty(line.getQty().negate()); - if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) + if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctDr from Original Shipment/Receipt - if (!dr.updateReverseLine (MInOut.Table_ID, + if (!dr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Shipment/Receipt not posted yet"; return null; } } - + // Inventory CR cr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), @@ -220,11 +220,11 @@ public class Doc_InOut extends Doc cr.setM_Locator_ID(line.getM_Locator_ID()); cr.setLocationFromLocator(line.getM_Locator_ID(), true); // from Loc cr.setLocationFromBPartner(getC_BPartner_Location_ID(), false); // to Loc - if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) + if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Shipment/Receipt - if (!cr.updateReverseLine (MInOut.Table_ID, + if (!cr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Shipment/Receipt not posted yet"; @@ -235,7 +235,7 @@ public class Doc_InOut extends Doc // if (line.getM_Product_ID() != 0) { - MCostDetail.createShipment(as, line.getAD_Org_ID(), + MCostDetail.createShipment(as, line.getAD_Org_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.get_ID(), 0, costs, line.getQty(), @@ -250,13 +250,13 @@ public class Doc_InOut extends Doc for (int i = 0; i < p_lines.length; i++) { DocLine line = p_lines[i]; - Fact factcomm = Doc_Order.getCommitmentSalesRelease(as, this, + Fact factcomm = Doc_Order.getCommitmentSalesRelease(as, this, line.getQty(), line.get_ID(), Env.ONE); if (factcomm != null) facts.add(factcomm); } } // Commitment - + } // Shipment // *** Sales - Return else if ( getDocumentType().equals(DOCTYPE_MatReceipt) && isSOTrx() ) @@ -265,10 +265,10 @@ public class Doc_InOut extends Doc { DocLine line = p_lines[i]; // MZ Goodwill - // if Shipment CostDetail exist then get Cost from Cost Detail + // if Shipment CostDetail exist then get Cost from Cost Detail BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=?"); // end MZ - + if (costs == null || costs.signum() == 0) // zero costs OK { MProduct product = line.getProduct(); @@ -294,11 +294,11 @@ public class Doc_InOut extends Doc dr.setM_Locator_ID(line.getM_Locator_ID()); dr.setLocationFromLocator(line.getM_Locator_ID(), true); // from Loc dr.setLocationFromBPartner(getC_BPartner_Location_ID(), false); // to Loc - if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) + if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctDr from Original Shipment/Receipt - if (!dr.updateReverseLine (MInOut.Table_ID, + if (!dr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Shipment/Receipt not posted yet"; @@ -309,13 +309,13 @@ public class Doc_InOut extends Doc // if (line.getM_Product_ID() != 0) { - MCostDetail.createShipment(as, line.getAD_Org_ID(), + MCostDetail.createShipment(as, line.getAD_Org_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.get_ID(), 0, costs, line.getQty(), line.getDescription(), true, getTrxName()); } - + // CoGS CR cr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Cogs, as), @@ -331,21 +331,21 @@ public class Doc_InOut extends Doc cr.setLocationFromBPartner(getC_BPartner_Location_ID(), false); // to Loc cr.setAD_Org_ID(line.getOrder_Org_ID()); // Revenue X-Org cr.setQty(line.getQty().negate()); - if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) + if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Shipment/Receipt - if (!cr.updateReverseLine (MInOut.Table_ID, + if (!cr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Shipment/Receipt not posted yet"; return null; - } + } } } // for all lines updateProductInfo(as.getC_AcctSchema_ID()); // only for SO! } // Sales Return - + // *** Purchasing - Receipt else if (getDocumentType().equals(DOCTYPE_MatReceipt) && !isSOTrx()) { @@ -364,10 +364,10 @@ public class Doc_InOut extends Doc { int C_OrderLine_ID = line.getC_OrderLine_ID(); // Low - check if c_orderline_id is valid - if (C_OrderLine_ID > 0) + if (C_OrderLine_ID > 0) { MOrderLine orderLine = new MOrderLine (getCtx(), C_OrderLine_ID, getTrxName()); - // Elaine 2008/06/26 + // Elaine 2008/06/26 C_Currency_ID = orderLine.getC_Currency_ID(); // costs = orderLine.getPriceCost(); @@ -386,7 +386,7 @@ public class Doc_InOut extends Doc log.fine("Costs=" + costs + " - Tax=" + costTax); costs = costs.subtract(costTax); } - } // correct included Tax + } // correct included Tax } costs = costs.multiply(line.getQty()); } @@ -409,16 +409,16 @@ public class Doc_InOut extends Doc // Inventory/Asset DR MAccount assets = line.getAccount(ProductCost.ACCTTYPE_P_Asset, as); if (product.isService()) - { + { //if the line is a Outside Processing then DR WIP if(line.getPP_Cost_Collector_ID() > 0) - assets = line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); - else + assets = line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); + else assets = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as); - + } - + // Elaine 2008/06/26 /*dr = fact.createLine(line, assets, as.getC_Currency_ID(), costs, null);*/ @@ -437,14 +437,14 @@ public class Doc_InOut extends Doc if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctDr from Original Shipment/Receipt - if (!dr.updateReverseLine (MInOut.Table_ID, + if (!dr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Receipt not posted yet"; return null; } } - + // NotInvoicedReceipt CR // Elaine 2008/06/26 /*cr = fact.createLine(line, @@ -467,7 +467,7 @@ public class Doc_InOut extends Doc if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Shipment/Receipt - if (!cr.updateReverseLine (MInOut.Table_ID, + if (!cr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Receipt not posted yet"; @@ -538,14 +538,14 @@ public class Doc_InOut extends Doc if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctDr from Original Shipment/Receipt - if (!dr.updateReverseLine (MInOut.Table_ID, + if (!dr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Receipt not posted yet"; return null; } } - + // Inventory/Asset CR MAccount assets = line.getAccount(ProductCost.ACCTTYPE_P_Asset, as); if (product.isService()) @@ -568,7 +568,7 @@ public class Doc_InOut extends Doc if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Shipment/Receipt - if (!cr.updateReverseLine (MInOut.Table_ID, + if (!cr.updateReverseLine (MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Receipt not posted yet"; diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Inventory.java b/org.adempiere.base/src/org/compiere/acct/Doc_Inventory.java index 89959bd21b..a90baf94f7 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Inventory.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Inventory.java @@ -44,16 +44,16 @@ public class Doc_Inventory extends Doc { private int m_Reversal_ID = 0; private String m_DocStatus = ""; - + /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** @@ -91,7 +91,7 @@ public class Doc_Inventory extends Doc && line.getQtyInternalUse().signum() == 0) continue; // - DocLine docLine = new DocLine (line, this); + DocLine docLine = new DocLine (line, this); BigDecimal Qty = line.getQtyInternalUse(); if (Qty.signum() != 0) Qty = Qty.negate(); // Internal Use entered positive @@ -148,7 +148,7 @@ public class Doc_Inventory extends Doc { DocLine line = p_lines[i]; // MZ Goodwill - // if Physical Inventory CostDetail is exist then get Cost from Cost Detail + // if Physical Inventory CostDetail is exist then get Cost from Cost Detail BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InventoryLine_ID=?"); // end MZ if (costs == null || costs.signum() == 0) @@ -167,14 +167,14 @@ public class Doc_Inventory extends Doc if (m_DocStatus.equals(MInventory.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctDr from Original Phys.Inventory - if (!dr.updateReverseLine (MInventory.Table_ID, + if (!dr.updateReverseLine (MInventory.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Physical Inventory not posted yet"; return null; } } - + // InventoryDiff DR CR // or Charge MAccount invDiff = null; @@ -201,7 +201,7 @@ public class Doc_Inventory extends Doc if (m_DocStatus.equals(MInventory.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Phys.Inventory - if (!cr.updateReverseLine (MInventory.Table_ID, + if (!cr.updateReverseLine (MInventory.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Physical Inventory not posted yet"; @@ -212,10 +212,10 @@ public class Doc_Inventory extends Doc // Cost Detail /* Source move to MInventory.createCostDetail() - MCostDetail.createInventory(as, line.getAD_Org_ID(), - line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), - line.get_ID(), 0, - costs, line.getQty(), + MCostDetail.createInventory(as, line.getAD_Org_ID(), + line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), + line.get_ID(), 0, + costs, line.getQty(), line.getDescription(), getTrxName());*/ } // diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java b/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java index 0eae82240d..c0b1bd7fdb 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java @@ -46,20 +46,20 @@ import org.compiere.util.Env; * @author Jorg Janke * @author Armen Rizal, Goodwill Consulting *
  • BF: 2797257 Landed Cost Detail is not using allocation qty - * + * * @version $Id: Doc_Invoice.java,v 1.2 2006/07/30 00:53:33 jjanke Exp $ */ public class Doc_Invoice extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schemata * @param rs record * @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 /** Contained Optional Tax Lines */ @@ -84,7 +84,7 @@ public class Doc_Invoice extends Doc setAmount(Doc.AMTTYPE_Gross, invoice.getGrandTotal()); setAmount(Doc.AMTTYPE_Net, invoice.getTotalLines()); setAmount(Doc.AMTTYPE_Charge, invoice.getChargeAmt()); - + // Contained Objects m_taxes = loadTaxes(); p_lines = loadLines(invoice); @@ -119,7 +119,7 @@ public class Doc_Invoice extends Doc BigDecimal amount = rs.getBigDecimal(5); boolean salesTax = "Y".equals(rs.getString(6)); // - DocTax taxLine = new DocTax(C_Tax_ID, name, rate, + DocTax taxLine = new DocTax(C_Tax_ID, name, rate, taxBaseAmt, amount, salesTax); log.fine(taxLine.toString()); list.add(taxLine); @@ -159,7 +159,7 @@ public class Doc_Invoice extends Doc DocLine docLine = new DocLine(line, this); // Qty BigDecimal Qty = line.getQtyInvoiced(); - boolean cm = getDocumentType().equals(DOCTYPE_ARCredit) + boolean cm = getDocumentType().equals(DOCTYPE_ARCredit) || getDocumentType().equals(DOCTYPE_APCredit); docLine.setQty(cm ? Qty.negate() : Qty, invoice.isSOTrx()); // @@ -187,7 +187,7 @@ public class Doc_Invoice extends Doc PriceList = PriceList.subtract(PriceListTax); } } // correct included Tax - + docLine.setAmount (LineNetAmt, PriceList, Qty); // qty for discount calc if (docLine.isItem()) m_allLinesService = false; @@ -197,7 +197,7 @@ public class Doc_Invoice extends Doc log.fine(docLine.toString()); list.add(docLine); } - + // Convert to Array DocLine[] dls = new DocLine[list.size()]; list.toArray(dls); @@ -209,7 +209,7 @@ public class Doc_Invoice extends Doc { if (m_taxes[i].isIncludedTaxDifference()) { - BigDecimal diff = m_taxes[i].getIncludedTaxDifference(); + BigDecimal diff = m_taxes[i].getIncludedTaxDifference(); for (int j = 0; j < dls.length; j++) { if (dls[j].getC_Tax_ID() == m_taxes[i].getC_Tax_ID()) @@ -221,7 +221,7 @@ public class Doc_Invoice extends Doc } // tax difference } // for all taxes } // Included Tax difference - + // Return Array return dls; } // loadLines @@ -237,7 +237,7 @@ public class Doc_Invoice extends Doc return m_precision; } // getPrecision - + /************************************************************************** * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding * @return positive amount, if total invoice is bigger than lines @@ -313,12 +313,12 @@ public class Doc_Invoice extends Doc return facts; // ** ARI, ARF - if (getDocumentType().equals(DOCTYPE_ARInvoice) + if (getDocumentType().equals(DOCTYPE_ARInvoice) || getDocumentType().equals(DOCTYPE_ARProForma)) { BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross); BigDecimal serviceAmt = Env.ZERO; - + // Header Charge CR BigDecimal amt = getAmount(Doc.AMTTYPE_Charge); if (amt != null && amt.signum() != 0) @@ -372,11 +372,11 @@ public class Doc_Invoice extends Doc fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), false); // to Loc } } - + // Receivables DR int receivables_ID = getValidCombination_ID(Doc.ACCTTYPE_C_Receivable, as); int receivablesServices_ID = getValidCombination_ID (Doc.ACCTTYPE_C_Receivable_Services, as); - if (m_allLinesItem || !as.isPostServices() + if (m_allLinesItem || !as.isPostServices() || receivables_ID == receivablesServices_ID) { grossAmt = getAmount(Doc.AMTTYPE_Gross); @@ -456,7 +456,7 @@ public class Doc_Invoice extends Doc // Receivables CR int receivables_ID = getValidCombination_ID (Doc.ACCTTYPE_C_Receivable, as); int receivablesServices_ID = getValidCombination_ID (Doc.ACCTTYPE_C_Receivable_Services, as); - if (m_allLinesItem || !as.isPostServices() + if (m_allLinesItem || !as.isPostServices() || receivables_ID == receivablesServices_ID) { grossAmt = getAmount(Doc.AMTTYPE_Gross); @@ -474,7 +474,7 @@ public class Doc_Invoice extends Doc fact.createLine(null, MAccount.get(getCtx(), receivablesServices_ID), getC_Currency_ID(), null, serviceAmt); } - + // ** API else if (getDocumentType().equals(DOCTYPE_APInvoice)) { @@ -540,7 +540,7 @@ public class Doc_Invoice extends Doc // if (line.getM_Product_ID() != 0 && line.getProduct().isService()) // otherwise Inv Matching - MCostDetail.createInvoice(as, line.getAD_Org_ID(), + MCostDetail.createInvoice(as, line.getAD_Org_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.get_ID(), 0, // No Cost Element line.getAmtSource(), line.getQty(), @@ -561,7 +561,7 @@ public class Doc_Invoice extends Doc // Liability CR int payables_ID = getValidCombination_ID (Doc.ACCTTYPE_V_Liability, as); int payablesServices_ID = getValidCombination_ID (Doc.ACCTTYPE_V_Liability_Services, as); - if (m_allLinesItem || !as.isPostServices() + if (m_allLinesItem || !as.isPostServices() || payables_ID == payablesServices_ID) { grossAmt = getAmount(Doc.AMTTYPE_Gross); @@ -646,7 +646,7 @@ public class Doc_Invoice extends Doc // if (line.getM_Product_ID() != 0 && line.getProduct().isService()) // otherwise Inv Matching - MCostDetail.createInvoice(as, line.getAD_Org_ID(), + MCostDetail.createInvoice(as, line.getAD_Org_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.get_ID(), 0, // No Cost Element line.getAmtSource().negate(), line.getQty(), @@ -666,7 +666,7 @@ public class Doc_Invoice extends Doc // Liability DR int payables_ID = getValidCombination_ID (Doc.ACCTTYPE_V_Liability, as); int payablesServices_ID = getValidCombination_ID (Doc.ACCTTYPE_V_Liability_Services, as); - if (m_allLinesItem || !as.isPostServices() + if (m_allLinesItem || !as.isPostServices() || payables_ID == payablesServices_ID) { grossAmt = getAmount(Doc.AMTTYPE_Gross); @@ -694,7 +694,7 @@ public class Doc_Invoice extends Doc facts.add(fact); return facts; } // createFact - + /** * Create Fact Cash Based (i.e. only revenue/expense) * @param as accounting schema @@ -798,8 +798,8 @@ public class Doc_Invoice extends Doc } return acctAmt; } // createFactCash - - + + /** * Create Landed Cost accounting & Cost lines * @param as accounting schema @@ -808,19 +808,19 @@ public class Doc_Invoice extends Doc * @param dr DR entry (normal api) * @return true if landed costs were created */ - private boolean landedCost (MAcctSchema as, Fact fact, DocLine line, boolean dr) + private boolean landedCost (MAcctSchema as, Fact fact, DocLine line, boolean dr) { int C_InvoiceLine_ID = line.get_ID(); MLandedCostAllocation[] lcas = MLandedCostAllocation.getOfInvoiceLine( getCtx(), C_InvoiceLine_ID, getTrxName()); if (lcas.length == 0) return false; - + // Calculate Total Base double totalBase = 0; for (int i = 0; i < lcas.length; i++) totalBase += lcas[i].getBase().doubleValue(); - + // Create New MInvoiceLine il = new MInvoiceLine (getCtx(), C_InvoiceLine_ID, getTrxName()); for (int i = 0; i < lcas.length; i++) @@ -835,10 +835,10 @@ public class Doc_Invoice extends Doc else desc += " - " + percent + "%"; if (line.getDescription() != null) - desc += " - " + line.getDescription(); - + desc += " - " + line.getDescription(); + // Accounting - ProductCost pc = new ProductCost (Env.getCtx(), + ProductCost pc = new ProductCost (Env.getCtx(), lca.getM_Product_ID(), lca.getM_AttributeSetInstance_ID(), getTrxName()); BigDecimal drAmt = null; BigDecimal crAmt = null; @@ -850,13 +850,13 @@ public class Doc_Invoice extends Doc getC_Currency_ID(), drAmt, crAmt); fl.setDescription(desc); fl.setM_Product_ID(lca.getM_Product_ID()); - + // Cost Detail - Convert to AcctCurrency BigDecimal allocationAmt = lca.getAmt(); if (getC_Currency_ID() != as.getC_Currency_ID()) - allocationAmt = MConversionRate.convert(getCtx(), allocationAmt, + allocationAmt = MConversionRate.convert(getCtx(), allocationAmt, getC_Currency_ID(), as.getC_Currency_ID(), - getDateAcct(), getC_ConversionType_ID(), + getDateAcct(), getC_ConversionType_ID(), getAD_Client_ID(), getAD_Org_ID()); if (allocationAmt.scale() > as.getCostingPrecision()) allocationAmt = allocationAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP); @@ -864,14 +864,14 @@ public class Doc_Invoice extends Doc allocationAmt = allocationAmt.negate(); // AZ Goodwill // use createInvoice to create/update non Material Cost Detail - MCostDetail.createInvoice(as, lca.getAD_Org_ID(), + MCostDetail.createInvoice(as, lca.getAD_Org_ID(), lca.getM_Product_ID(), lca.getM_AttributeSetInstance_ID(), C_InvoiceLine_ID, lca.getM_CostElement_ID(), allocationAmt, lca.getQty(), desc, getTrxName()); // end AZ } - + log.config("Created #" + lcas.length); return true; } // landedCosts @@ -885,7 +885,7 @@ public class Doc_Invoice extends Doc MClientInfo ci = MClientInfo.get(getCtx(), as.getAD_Client_ID()); if (ci.getC_AcctSchema1_ID() != as.getC_AcctSchema_ID()) return; - + StringBuffer sql = new StringBuffer ( "UPDATE M_Product_PO po " + "SET PriceLastInv = " @@ -899,7 +899,7 @@ public class Doc_Invoice extends Doc { sql.append(" AND ROWNUM=1 "); } - else + else { sql.append(" AND il.C_InvoiceLine_ID = (SELECT MIN(il1.C_InvoiceLine_ID) " + "FROM C_Invoice i1, C_InvoiceLine il1 " @@ -917,7 +917,7 @@ public class Doc_Invoice extends Doc int no = DB.executeUpdate(sql.toString(), getTrxName()); log.fine("Updated=" + no); } // updateProductPO - + /** * Update Product Info (old). * - Costing (PriceLastInv) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_MatchInv.java b/org.adempiere.base/src/org/compiere/acct/Doc_MatchInv.java index 70330d0c2b..5a7057eee6 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_MatchInv.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_MatchInv.java @@ -42,8 +42,8 @@ import org.compiere.util.Env; * Update Costing Records * @author Jorg Janke * @version $Id: Doc_MatchInv.java,v 1.3 2006/07/30 00:53:33 jjanke Exp $ - * - * FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual + * + * FR [ 1840016 ] Avoid usage of clearing accounts - subject to C_AcctSchema.IsPostIfClearingEqual * Avoid posting if both accounts Not Invoiced Receipts and Inventory Clearing are equal * BF [ 2789949 ] Multicurrency in matching posting */ @@ -51,25 +51,25 @@ public class Doc_MatchInv extends Doc { /** * Constructor - * @param ass accounting schemata + * @param ass accounting schema * @param rs record * @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 /** Invoice Line */ private MInvoiceLine m_invoiceLine = null; /** Material Receipt */ private MInOutLine m_receiptLine = null; - + private ProductCost m_pc = null; /** Commitments */ // private DocLine[] m_commitments = null; - + /** * Load Specific Document Details * @return error message or null @@ -84,16 +84,16 @@ public class Doc_MatchInv extends Doc int C_InvoiceLine_ID = matchInv.getC_InvoiceLine_ID(); m_invoiceLine = new MInvoiceLine (getCtx(), C_InvoiceLine_ID, null); // BP for NotInvoicedReceipts - int C_BPartner_ID = m_invoiceLine.getParent().getC_BPartner_ID(); + int C_BPartner_ID = m_invoiceLine.getParent().getC_BPartner_ID(); setC_BPartner_ID(C_BPartner_ID); // int M_InOutLine_ID = matchInv.getM_InOutLine_ID(); - m_receiptLine = new MInOutLine (getCtx(), M_InOutLine_ID, null); + m_receiptLine = new MInOutLine (getCtx(), M_InOutLine_ID, null); // - m_pc = new ProductCost (Env.getCtx(), + m_pc = new ProductCost (Env.getCtx(), getM_Product_ID(), matchInv.getM_AttributeSetInstance_ID(), null); m_pc.setQty(getQty()); - + return null; } // loadDocumentDetails @@ -107,7 +107,7 @@ public class Doc_MatchInv extends Doc return Env.ZERO; } // getBalance - + /** * Create Facts (the accounting logic) for * MXI. @@ -136,7 +136,7 @@ public class Doc_MatchInv extends Doc return facts; } // MMatchInv matchInv = (MMatchInv)getPO(); - + // create Fact Header Fact fact = new Fact(this, as, Fact.POST_Actual); setC_Currency_ID (as.getC_Currency_ID()); @@ -149,8 +149,8 @@ public class Doc_MatchInv extends Doc return fact; } **/ - - + + // NotInvoicedReceipt DR // From Receipt BigDecimal multiplier = getQty() @@ -178,7 +178,7 @@ public class Doc_MatchInv extends Doc p_Error = "Mat.Receipt not posted yet"; return null; } - log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance() + log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance() + ") - " + dr.toString()); // InventoryClearing CR @@ -203,7 +203,7 @@ public class Doc_MatchInv extends Doc { log.fine("Line Net Amt=0 - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty()); - + // Invoice Price Variance BigDecimal ipv = dr.getSourceBalance().negate(); if (ipv.signum() != 0) @@ -235,14 +235,14 @@ public class Doc_MatchInv extends Doc p_Error = "Invoice not posted yet"; return null; } - log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance() + log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance() + ") - " + cr.toString()); } else // Cash Acct { MInvoice invoice = m_invoiceLine.getParent(); if (as.getC_Currency_ID() != invoice.getC_Currency_ID()) - LineNetAmt = MConversionRate.convert(getCtx(), LineNetAmt, + LineNetAmt = MConversionRate.convert(getCtx(), LineNetAmt, invoice.getC_Currency_ID(), as.getC_Currency_ID(), invoice.getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID()); @@ -260,32 +260,32 @@ public class Doc_MatchInv extends Doc cr.setUser2_ID(m_invoiceLine.getUser2_ID()); //AZ Goodwill - //Desc: Source Not Balanced problem because Currency is Difference - PO=CNY but AP=USD + //Desc: Source Not Balanced problem because Currency is Difference - PO=CNY but AP=USD //see also Fact.java: checking for isMultiCurrency() if (dr.getC_Currency_ID() != cr.getC_Currency_ID()) setIsMultiCurrency(true); //end AZ - + // Avoid usage of clearing accounts // If both accounts Not Invoiced Receipts and Inventory Clearing are equal // then remove the posting - + MAccount acct_db = dr.getAccount(); // not_invoiced_receipts MAccount acct_cr = cr.getAccount(); // inventory_clearing - + if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) { - + BigDecimal debit = dr.getAmtSourceDr(); BigDecimal credit = cr.getAmtSourceCr(); - + if (debit.compareTo(credit) == 0) { fact.remove(dr); fact.remove(cr); } - + } // End Avoid usage of clearing accounts - + // Invoice Price Variance difference BigDecimal ipv = cr.getAcctBalance().add(dr.getAcctBalance()).negate(); @@ -304,8 +304,8 @@ public class Doc_MatchInv extends Doc pv.setUser2_ID(m_invoiceLine.getUser2_ID()); } log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance()); - -// Elaine 2008/6/20 + +// Elaine 2008/6/20 /* Source move to MInvoice.createMatchInvCostDetail() // Cost Detail Record - data from Expense/IncClearing (CR) record // MZ Goodwill @@ -324,12 +324,12 @@ public class Doc_MatchInv extends Doc } } tAmt = tAmt.add(cr.getAcctBalance().negate()); //Invoice Price - + // Different currency MInvoice invoice = m_invoiceLine.getParent(); if (as.getC_Currency_ID() != invoice.getC_Currency_ID()) { - tAmt = MConversionRate.convert(getCtx(), tAmt, + tAmt = MConversionRate.convert(getCtx(), tAmt, invoice.getC_Currency_ID(), as.getC_Currency_ID(), invoice.getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID()); @@ -339,37 +339,37 @@ public class Doc_MatchInv extends Doc return null; } } - + // set Qty to negative value when MovementType is Vendor Returns MInOut receipt = m_receiptLine.getParent(); if (receipt.getMovementType().equals(MInOut.MOVEMENTTYPE_VendorReturns)) tQty = tQty.add(getQty().negate()); // Qty is set to negative value else tQty = tQty.add(getQty()); - - // Set Total Amount and Total Quantity from Matched Invoice - MCostDetail.createInvoice(as, getAD_Org_ID(), + + // Set Total Amount and Total Quantity from Matched Invoice + MCostDetail.createInvoice(as, getAD_Org_ID(), getM_Product_ID(), matchInv.getM_AttributeSetInstance_ID(), m_invoiceLine.getC_InvoiceLine_ID(), 0, // No cost element tAmt, tQty, getDescription(), getTrxName()); // end MZ */ // Update Costing - updateProductInfo(as.getC_AcctSchema_ID(), + updateProductInfo(as.getC_AcctSchema_ID(), MAcctSchema.COSTINGMETHOD_StandardCosting.equals(as.getCostingMethod())); // facts.add(fact); - + /** Commitment release ****/ if (as.isAccrual() && as.isCreatePOCommitment()) { - fact = Doc_Order.getCommitmentRelease(as, this, + fact = Doc_Order.getCommitmentRelease(as, this, getQty(), m_invoiceLine.getC_InvoiceLine_ID(), Env.ONE); if (fact == null) return null; facts.add(fact); } // Commitment - + return facts; } // createFact @@ -386,7 +386,7 @@ public class Doc_MatchInv extends Doc // verify if org of receipt line is different from org of invoice line if (m_receiptLine != null && m_invoiceLine != null && m_receiptLine.getAD_Org_ID() != m_invoiceLine.getAD_Org_ID()) return true; - + return false; } @@ -422,7 +422,7 @@ public class Doc_MatchInv extends Doc + "WHERE pc.C_AcctSchema_ID=").append(C_AcctSchema_ID).append( " AND EXISTS (SELECT * FROM M_MatchInv m " + "WHERE pc.M_Product_ID=m.M_Product_ID" - + " AND m.M_MatchInv_ID=").append(get_ID()).append(")"); + + " AND m.M_MatchInv_ID=").append(get_ID()).append(")"); int no = DB.executeUpdate(sql.toString(), getTrxName()); log.fine("M_Product_Costing - Qty/Amt Updated #=" + no); @@ -434,7 +434,7 @@ public class Doc_MatchInv extends Doc .append(" AND M_Product_ID=").append(getM_Product_ID()); no = DB.executeUpdate(sql.toString(), getTrxName()); log.fine("M_Product_Costing - AvgCost Updated #=" + no); - + // Update Current Cost if (!standardCosting) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java b/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java index 2889f8d8aa..9c326413c7 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_MatchPO.java @@ -50,13 +50,13 @@ public class Doc_MatchPO extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schemata * @param rs record * @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 private int m_C_OrderLine_ID = 0; @@ -65,7 +65,7 @@ public class Doc_MatchPO extends Doc private int m_M_InOutLine_ID = 0; private MInOutLine m_ioLine = null; private int m_C_InvoiceLine_ID = 0; - + private ProductCost m_pc; private int m_M_AttributeSetInstance_ID = 0; @@ -86,18 +86,18 @@ public class Doc_MatchPO extends Doc m_oLine = new MOrderLine (getCtx(), m_C_OrderLine_ID, getTrxName()); // m_M_InOutLine_ID = matchPO.getM_InOutLine_ID(); - m_ioLine = new MInOutLine (getCtx(), m_M_InOutLine_ID, null); - + m_ioLine = new MInOutLine (getCtx(), m_M_InOutLine_ID, null); + m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID(); - + // - m_pc = new ProductCost (Env.getCtx(), + m_pc = new ProductCost (Env.getCtx(), getM_Product_ID(), m_M_AttributeSetInstance_ID, getTrxName()); m_pc.setQty(getQty()); return null; } // loadDocumentDetails - + /************************************************************************** * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding * @return Zero - always balanced @@ -107,7 +107,7 @@ public class Doc_MatchPO extends Doc return Env.ZERO; } // getBalance - + /** * Create Facts (the accounting logic) for * MXP. @@ -135,19 +135,19 @@ public class Doc_MatchPO extends Doc Fact fact = new Fact(this, as, Fact.POST_Actual); setC_Currency_ID(as.getC_Currency_ID()); boolean isInterOrg = isInterOrg(as); - + // Purchase Order Line BigDecimal poCost = m_oLine.getPriceCost(); if (poCost == null || poCost.signum() == 0) poCost = m_oLine.getPriceActual(); - - MInOutLine receiptLine = new MInOutLine (getCtx(), m_M_InOutLine_ID, getTrxName()); - MInOut inOut = receiptLine.getParent(); + + MInOutLine receiptLine = new MInOutLine (getCtx(), m_M_InOutLine_ID, getTrxName()); + MInOut inOut = receiptLine.getParent(); boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns); - + // calculate po cost poCost = poCost.multiply(getQty()); // Delivered so far - + // Different currency if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) { @@ -171,7 +171,7 @@ public class Doc_MatchPO extends Doc MProduct product = MProduct.get(getCtx(), getM_Product_ID()); String costingMethod = product.getCostingMethod(as); //get standard cost and also make sure cost for other costing method is updated - BigDecimal costs = m_pc.getProductCosts(as, getAD_Org_ID(), + BigDecimal costs = m_pc.getProductCosts(as, getAD_Org_ID(), MAcctSchema.COSTINGMETHOD_StandardCosting, m_C_OrderLine_ID, false); // non-zero costs if (MAcctSchema.COSTINGMETHOD_StandardCosting.equals(costingMethod)) @@ -183,7 +183,7 @@ public class Doc_MatchPO extends Doc log.log(Level.SEVERE, p_Error); return null; } - + // Difference BigDecimal difference = poCost.subtract(costs); // Nothing to post @@ -192,7 +192,7 @@ public class Doc_MatchPO extends Doc log.log(Level.FINE, "No Cost Difference for M_Product_ID=" + getM_Product_ID()); return facts; } - + // Product PPV FactLine cr = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as), @@ -210,7 +210,7 @@ public class Doc_MatchPO extends Doc cr.setUser1_ID(m_oLine.getUser1_ID()); cr.setUser2_ID(m_oLine.getUser2_ID()); } - + // PPV Offset FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_PPVOffset, as), @@ -228,27 +228,27 @@ public class Doc_MatchPO extends Doc dr.setUser1_ID(m_oLine.getUser1_ID()); dr.setUser2_ID(m_oLine.getUser2_ID()); } - + // Avoid usage of clearing accounts // If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal // then remove the posting - + MAccount acct_db = dr.getAccount(); // PPV MAccount acct_cr = cr.getAccount(); // PPV Offset - + if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) { - + BigDecimal debit = dr.getAmtSourceDr(); BigDecimal credit = cr.getAmtSourceCr(); - + if (debit.compareTo(credit) == 0) { fact.remove(dr); fact.remove(cr); } - + } // End Avoid usage of clearing accounts - + // facts.add(fact); return facts; @@ -258,7 +258,7 @@ public class Doc_MatchPO extends Doc return facts; } } // createFact - + /** Verify if the posting involves two or more organizations @return true if there are more than one org involved on the posting */ @@ -274,7 +274,7 @@ public class Doc_MatchPO extends Doc if (m_ioLine != null && m_oLine != null && m_ioLine.getAD_Org_ID() != m_oLine.getAD_Org_ID()) return true; - + return false; } diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Movement.java b/org.adempiere.base/src/org/compiere/acct/Doc_Movement.java index ccea51d9ad..cedfcd1637 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Movement.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Movement.java @@ -42,16 +42,16 @@ public class Doc_Movement extends Doc { private int m_Reversal_ID = 0; private String m_DocStatus = ""; - + /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** @@ -132,7 +132,7 @@ public class Doc_Movement extends Doc { DocLine line = p_lines[i]; // MZ Goodwill - // if Inventory Move CostDetail exist then get Cost from Cost Detail + // if Inventory Move CostDetail exist then get Cost from Cost Detail BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_MovementLine_ID=? AND IsSOTrx='N'"); // end MZ @@ -147,14 +147,14 @@ public class Doc_Movement extends Doc if (m_DocStatus.equals(MMovement.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctDr from Original Movement - if (!dr.updateReverseLine (MMovement.Table_ID, + if (!dr.updateReverseLine (MMovement.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Inventory Move not posted yet"; return null; } } - + // ** InventoryTo DR CR cr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), @@ -166,7 +166,7 @@ public class Doc_Movement extends Doc if (m_DocStatus.equals(MMovement.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Movement - if (!cr.updateReverseLine (MMovement.Table_ID, + if (!cr.updateReverseLine (MMovement.Table_ID, m_Reversal_ID, line.getReversalLine_ID(),Env.ONE)) { p_Error = "Original Inventory Move not posted yet"; @@ -192,7 +192,7 @@ public class Doc_Movement extends Doc costs.negate(), line.getQty().negate(), true, description + "(|->)", getTrxName()); // Cost Detail To - MCostDetail.createMovement(as, cr.getAD_Org_ID(), // locator org + MCostDetail.createMovement(as, cr.getAD_Org_ID(), // locator org line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), line.get_ID(), 0, costs, line.getQty(), false, diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Order.java b/org.adempiere.base/src/org/compiere/acct/Doc_Order.java index 80e38c1c6f..7a7d2cf363 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Order.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Order.java @@ -49,13 +49,13 @@ public class Doc_Order extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** Contained Optional Tax Lines */ @@ -78,7 +78,7 @@ public class Doc_Order extends Doc setAmount(AMTTYPE_Gross, order.getGrandTotal()); setAmount(AMTTYPE_Net, order.getTotalLines()); setAmount(AMTTYPE_Charge, order.getChargeAmt()); - + // Contained Objects m_taxes = loadTaxes(); p_lines = loadLines(order); @@ -136,7 +136,7 @@ public class Doc_Order extends Doc PriceList = PriceList.subtract(PriceListTax); } } // correct included Tax - + docLine.setAmount (LineNetAmt, PriceList, Qty); list.add(docLine); } @@ -146,8 +146,8 @@ public class Doc_Order extends Doc list.toArray(dl); return dl; } // loadLines - - + + /** * Load Requisitions * @return requisition lines of Order @@ -208,14 +208,14 @@ public class Doc_Order extends Doc DB.close(rs, pstmt); rs = null; pstmt = null; } - + // Return Array DocLine[] dls = new DocLine[list.size ()]; list.toArray (dls); return dls; } // loadRequisitions - + /** * Get Currency Precision * @return precision @@ -254,7 +254,7 @@ public class Doc_Order extends Doc BigDecimal amount = rs.getBigDecimal(5); boolean salesTax = "Y".equals(rs.getString(6)); // - DocTax taxLine = new DocTax(C_Tax_ID, name, rate, + DocTax taxLine = new DocTax(C_Tax_ID, name, rate, taxBaseAmt, amount, salesTax); list.add(taxLine); } @@ -274,7 +274,7 @@ public class Doc_Order extends Doc return tl; } // loadTaxes - + /************************************************************************** * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding * @return positive amount, if total invoice is bigger than lines @@ -309,7 +309,7 @@ public class Doc_Order extends Doc sb.append("]"); } // - if (retValue.signum() != 0 // Sum of Cost(vs. Price) in lines may not add up + if (retValue.signum() != 0 // Sum of Cost(vs. Price) in lines may not add up && getDocumentType().equals(DOCTYPE_POrder)) // PO { log.fine(toString() + " Balance=" + retValue + sb.toString() + " (ignored)"); @@ -320,7 +320,7 @@ public class Doc_Order extends Doc return retValue; } // getBalance - + /************************************************************************* * Create Facts (the accounting logic) for * SOO, POO. @@ -377,7 +377,7 @@ public class Doc_Order extends Doc // facts.add(fact); } - + // Reverse Reservation if (as.isCreateReservation()) { @@ -446,12 +446,12 @@ public class Doc_Order extends Doc // facts.add(fact); } - + } return facts; } // createFact - + /** * Update ProductPO PriceLastPO * @param as accounting schema @@ -473,7 +473,7 @@ public class Doc_Order extends Doc { sql.append(" AND ROWNUM=1 "); } - else + else sql.append(" AND ol.C_OrderLine_ID = (SELECT MIN(ol1.C_OrderLine_ID) " + "FROM C_Order o1, C_OrderLine ol1 " + "WHERE o1.C_Order_ID=ol1.C_Order_ID" @@ -488,8 +488,8 @@ public class Doc_Order extends Doc int no = DB.executeUpdate(sql.toString(), getTrxName()); log.fine("Updated=" + no); } // updateProductPO - - + + /** * Get Commitments * @param doc document @@ -545,7 +545,7 @@ public class Doc_Order extends Doc else LineNetAmt = Qty.multiply(PriceActual); maxQty = maxQty.subtract(Qty); - + docLine.setAmount (LineNetAmt); // DR BigDecimal PriceList = line.getPriceList(); int C_Tax_ID = docLine.getC_Tax_ID(); @@ -562,7 +562,7 @@ public class Doc_Order extends Doc PriceList = PriceList.subtract(PriceListTax); } } // correct included Tax - + docLine.setAmount (LineNetAmt, PriceList, Qty); list.add(docLine); } @@ -576,7 +576,7 @@ public class Doc_Order extends Doc DB.close(rs, pstmt); rs = null; pstmt = null; } - + // Return Array DocLine[] dl = new DocLine[list.size()]; list.toArray(dl); @@ -593,13 +593,13 @@ public class Doc_Order extends Doc * @param multiplier 1 for accrual * @return Fact */ - protected static Fact getCommitmentRelease(MAcctSchema as, Doc doc, + protected static Fact getCommitmentRelease(MAcctSchema as, Doc doc, BigDecimal Qty, int C_InvoiceLine_ID, BigDecimal multiplier) { Fact fact = new Fact(doc, as, Fact.POST_Commitment); - DocLine[] commitments = Doc_Order.getCommitments(doc, Qty, + DocLine[] commitments = Doc_Order.getCommitments(doc, Qty, C_InvoiceLine_ID); - + BigDecimal total = Env.ZERO; FactLine fl = null; int C_Currency_ID = -1; @@ -634,7 +634,7 @@ public class Doc_Order extends Doc C_Currency_ID, total, null); return fact; } // getCommitmentRelease - + /** * Get Commitments Sales * @param doc document @@ -685,7 +685,7 @@ public class Doc_Order extends Doc else LineNetAmt = Qty.multiply(PriceActual); maxQty = maxQty.subtract(Qty); - + docLine.setAmount (LineNetAmt); // DR BigDecimal PriceList = line.getPriceList(); int C_Tax_ID = docLine.getC_Tax_ID(); @@ -702,7 +702,7 @@ public class Doc_Order extends Doc PriceList = PriceList.subtract(PriceListTax); } } // correct included Tax - + docLine.setAmount (LineNetAmt, PriceList, Qty); list.add(docLine); } @@ -716,7 +716,7 @@ public class Doc_Order extends Doc DB.close(rs, pstmt); rs = null; pstmt = null; } - + // Return Array DocLine[] dl = new DocLine[list.size()]; list.toArray(dl); @@ -733,13 +733,13 @@ public class Doc_Order extends Doc * @param multiplier 1 for accrual * @return Fact */ - protected static Fact getCommitmentSalesRelease(MAcctSchema as, Doc doc, + protected static Fact getCommitmentSalesRelease(MAcctSchema as, Doc doc, BigDecimal Qty, int M_InOutLine_ID, BigDecimal multiplier) { Fact fact = new Fact(doc, as, Fact.POST_Commitment); - DocLine[] commitments = Doc_Order.getCommitmentsSales(doc, Qty, + DocLine[] commitments = Doc_Order.getCommitmentsSales(doc, Qty, M_InOutLine_ID); - + BigDecimal total = Env.ZERO; FactLine fl = null; int C_Currency_ID = -1; @@ -774,7 +774,7 @@ public class Doc_Order extends Doc C_Currency_ID, null, total); return fact; } // getCommitmentSalesRelease - + /************************************************************************** * Update Product Info (old) * - Costing (PriceLastPO) @@ -803,7 +803,7 @@ public class Doc_Order extends Doc { sql.append(" AND ROWNUM=1 "); } - else + else sql.append(" AND ol.C_OrderLine_ID = (SELECT MIN(ol1.C_OrderLine_ID) " + "FROM C_Order o1, C_OrderLine ol1 " + "WHERE o1.C_Order_ID=ol1.C_Order_ID" diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java b/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java index 42bbd52b92..837d8f1309 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Payment.java @@ -41,15 +41,15 @@ public class Doc_Payment extends Doc { /** * Constructor - * @param ass accounting schemata + * @param ass accounting schema * @param rs record * @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 - + /** Tender Type */ private String m_TenderType = null; /** Prepayment */ @@ -73,7 +73,7 @@ public class Doc_Payment extends Doc return null; } // loadDocumentDetails - + /************************************************************************** * Get Source Currency Balance - always zero * @return Zero (always balanced) @@ -115,7 +115,7 @@ public class Doc_Payment extends Doc return facts; } - int AD_Org_ID = getBank_Org_ID(); // Bank Account Org + int AD_Org_ID = getBank_Org_ID(); // Bank Account Org if (getDocumentType().equals(DOCTYPE_ARReceipt)) { // Asset @@ -123,7 +123,7 @@ public class Doc_Payment extends Doc getC_Currency_ID(), getAmount(), null); if (fl != null && AD_Org_ID != 0) fl.setAD_Org_ID(AD_Org_ID); - // + // MAccount acct = null; if (getC_Charge_ID() != 0) acct = MCharge.getAccount(getC_Charge_ID(), as, getAmount()); @@ -152,7 +152,7 @@ public class Doc_Payment extends Doc if (fl != null && AD_Org_ID != 0 && getC_Charge_ID() == 0) // don't overwrite charge fl.setAD_Org_ID(AD_Org_ID); - + // Asset fl = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), getC_Currency_ID(), null, getAmount()); @@ -183,5 +183,5 @@ public class Doc_Payment extends Doc MBankAccount ba = MBankAccount.get(getCtx(), m_C_BankAccount_ID); return ba.getAD_Org_ID(); } // getBank_Org_ID - + } // Doc_Payment diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Production.java b/org.adempiere.base/src/org/compiere/acct/Doc_Production.java index 47ccf0e7c3..b9a31fda4b 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Production.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Production.java @@ -45,13 +45,13 @@ public class Doc_Production extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** @@ -174,15 +174,15 @@ public class Doc_Production extends Doc DocLine line = p_lines[i]; // Calculate Costs BigDecimal costs = null; - + // MZ Goodwill - // if Production CostDetail exist then get Cost from Cost Detail - MCostDetail cd = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=?", + // if Production CostDetail exist then get Cost from Cost Detail + MCostDetail cd = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=?", line.get_ID(), line.getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), getTrxName()); if (cd != null) costs = cd.getAmt(); else - { + { if (line.isProductionBOM()) { // Get BOM Cost - Sum of individual lines @@ -209,7 +209,7 @@ public class Doc_Production extends Doc costs = line.getProductCosts(as, line.getAD_Org_ID(), false); } // end MZ - + // Inventory DR CR fl = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), @@ -221,17 +221,17 @@ public class Doc_Production extends Doc } fl.setM_Locator_ID(line.getM_Locator_ID()); fl.setQty(line.getQty()); - + // Cost Detail String description = line.getDescription(); if (description == null) description = ""; if (line.isProductionBOM()) description += "(*)"; - MCostDetail.createProduction(as, line.getAD_Org_ID(), - line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), - line.get_ID(), 0, - costs, line.getQty(), + MCostDetail.createProduction(as, line.getAD_Org_ID(), + line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), + line.get_ID(), 0, + costs, line.getQty(), description, getTrxName()); } // diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_ProjectIssue.java b/org.adempiere.base/src/org/compiere/acct/Doc_ProjectIssue.java index 465ef6f967..dc162d90c6 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_ProjectIssue.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_ProjectIssue.java @@ -33,9 +33,9 @@ import org.compiere.util.Env; /** * Project Issue. * Note: - * Will load the default GL Category. - * Set up a document type to set the GL Category. - * + * Will load the default GL Category. + * Set up a document type to set the GL Category. + * * @author Jorg Janke * @version $Id: Doc_ProjectIssue.java,v 1.2 2006/07/30 00:53:33 jjanke Exp $ */ @@ -43,13 +43,13 @@ public class Doc_ProjectIssue extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** Pseudo Line */ @@ -67,11 +67,11 @@ public class Doc_ProjectIssue extends Doc m_issue = (MProjectIssue)getPO(); setDateDoc (m_issue.getMovementDate()); setDateAcct(m_issue.getMovementDate()); - + // Pseudo Line - m_line = new DocLine (m_issue, this); + m_line = new DocLine (m_issue, this); m_line.setQty (m_issue.getMovementQty(), true); // sets Trx and Storage Qty - + // Pseudo Line Check if (m_line.getM_Product_ID() == 0) log.warning(m_line.toString() + " - No Product"); @@ -122,7 +122,7 @@ public class Doc_ProjectIssue extends Doc MProject project = new MProject (getCtx(), m_issue.getC_Project_ID(), getTrxName()); String ProjectCategory = project.getProjectCategory(); MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID()); - + // Line pointers FactLine dr = null; FactLine cr = null; @@ -135,7 +135,7 @@ public class Doc_ProjectIssue extends Doc cost = getLaborCost(as); if (cost == null) // standard Product Costs cost = m_line.getProductCosts(as, getAD_Org_ID(), false); - + // Project DR int acctType = ACCTTYPE_ProjectWIP; if (MProject.PROJECTCATEGORY_AssetProject.equals(ProjectCategory)) @@ -143,7 +143,7 @@ public class Doc_ProjectIssue extends Doc dr = fact.createLine(m_line, getAccount(acctType, as), as.getC_Currency_ID(), cost, null); dr.setQty(m_line.getQty().negate()); - + // Inventory CR acctType = ProductCost.ACCTTYPE_P_Asset; if (product.isService()) @@ -211,24 +211,24 @@ public class Doc_ProjectIssue extends Doc private BigDecimal getLaborCost(MAcctSchema as) { - // Todor Lulov 30.01.2008 + // Todor Lulov 30.01.2008 BigDecimal retValue = Env.ZERO; BigDecimal qty = Env.ZERO; - String sql = "SELECT ConvertedAmt, Qty FROM S_TimeExpenseLine " + + String sql = "SELECT ConvertedAmt, Qty FROM S_TimeExpenseLine " + " WHERE S_TimeExpenseLine.S_TimeExpenseLine_ID = ?"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString (), getTrxName()); - pstmt.setInt(1, m_issue.getS_TimeExpenseLine_ID()); - rs = pstmt.executeQuery(); + pstmt.setInt(1, m_issue.getS_TimeExpenseLine_ID()); + rs = pstmt.executeQuery(); if (rs.next()) { retValue = rs.getBigDecimal(1); qty = rs.getBigDecimal(2); - retValue = retValue.multiply(qty); + retValue = retValue.multiply(qty); log.fine("ExpLineCost = " + retValue); } else @@ -242,7 +242,7 @@ public class Doc_ProjectIssue extends Doc { DB.close(rs, pstmt); pstmt = null; rs = null; - } + } return retValue; } // getLaborCost diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Requisition.java b/org.adempiere.base/src/org/compiere/acct/Doc_Requisition.java index 3754bbf12e..5f6dc9e857 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Requisition.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Requisition.java @@ -30,12 +30,12 @@ import org.compiere.util.Env; /** * Post Order Documents. - * + * *
      *   Table:              M_Requisition
      *   Document Types:     POR (Requisition)
      * 
    - * + * * @author Jorg Janke * @version $Id: Doc_Requisition.java,v 1.3 2006/07/30 00:53:33 jjanke Exp $ */ @@ -43,13 +43,13 @@ public class Doc_Requisition extends Doc { /** * Constructor - * @param ass accounting schemata + * @param as accounting schema * @param rs record * @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 /** @@ -100,7 +100,7 @@ public class Doc_Requisition extends Doc /*************************************************************************** * Get Source Currency Balance - subtracts line and tax amounts from total - * no rounding - * + * * @return positive amount, if total invoice is bigger than lines */ public BigDecimal getBalance () @@ -151,7 +151,7 @@ public class Doc_Requisition extends Doc fact.createLine (null, offset, getC_Currency_ID(), null, total); facts.add(fact); } - + return facts; } // createFact } // Doc_Requisition diff --git a/org.adempiere.base/src/org/compiere/util/AdempiereUserError.java b/org.adempiere.base/src/org/compiere/util/AdempiereUserError.java index 636a940798..45798c28b7 100644 --- a/org.adempiere.base/src/org/compiere/util/AdempiereUserError.java +++ b/org.adempiere.base/src/org/compiere/util/AdempiereUserError.java @@ -21,14 +21,14 @@ package org.compiere.util; * Adempiere User Error. * Cuased by (lack of) user input/selection. * (No program error) - * + * * @author Jorg Janke * @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 { /** - * + * */ private static final long serialVersionUID = -5318376918072817705L; @@ -64,7 +64,7 @@ public class AdempiereUserError extends Exception /** Additional Info how to fix **/ private String m_fixHint = null; - + /** * @return Returns the fixHint. */ @@ -72,7 +72,7 @@ public class AdempiereUserError extends Exception { return m_fixHint; } // getFixHint - + /** * Set Fix Hint * @param fixHint fix hint @@ -81,8 +81,8 @@ public class AdempiereUserError extends Exception { m_fixHint = fixHint; } // setFixHint - - + + /** * String Representation * @return info @@ -96,5 +96,5 @@ public class AdempiereUserError extends Exception sb.append(" (").append(m_fixHint).append (")"); return sb.toString (); } // toString - + } // AdempiereUserError diff --git a/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java b/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java index 31f9f4fa7c..772157507e 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java @@ -25,7 +25,7 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; -import org.compiere.acct.Doc; +import org.compiere.acct.DocManager; import org.compiere.model.MAcctProcessor; import org.compiere.model.MAcctProcessorLog; import org.compiere.model.MAcctSchema; @@ -38,7 +38,7 @@ import org.compiere.util.TimeUtil; /** * Accounting Processor - * + * * @author Jorg Janke * @version $Id: AcctProcessor.java,v 1.3 2006/07/30 00:53:33 jjanke Exp $ */ @@ -46,7 +46,7 @@ public class AcctProcessor extends AdempiereServer { /** * Accounting Processor - * @param model model + * @param model model */ public AcctProcessor (MAcctProcessor model) { @@ -63,7 +63,7 @@ public class AcctProcessor extends AdempiereServer private MClient m_client = null; /** Accounting Schemata */ private MAcctSchema[] m_ass = null; - + /** * Work */ @@ -83,7 +83,7 @@ public class AcctProcessor extends AdempiereServer m_summary.append("Logs deleted=").append(no); // MAcctProcessorLog pLog = new MAcctProcessorLog(m_model, m_summary.toString()); - pLog.setReference("#" + String.valueOf(p_runCount) + pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork))); pLog.save(); } // doWork @@ -104,10 +104,10 @@ public class AcctProcessor extends AdempiereServer ts = new Timestamp(ms); long mili = ts.getTime(); BigDecimal value = new BigDecimal(Long.toString(mili)); - + //first pass, collect all ts (FR 2962094 - required for weighted average costing) - int[] documentsTableID = Doc.getDocumentsTableID(); - String[] documentsTableName = Doc.getDocumentsTableName(); + int[] documentsTableID = DocManager.getDocumentsTableID(); + String[] documentsTableName = DocManager.getDocumentsTableName(); for (int i = 0; i < documentsTableID.length; i++) { int AD_Table_ID = documentsTableID[i]; @@ -116,7 +116,7 @@ public class AcctProcessor extends AdempiereServer if (m_model.getAD_Table_ID() != 0 && m_model.getAD_Table_ID() != AD_Table_ID) continue; - + StringBuffer sql = new StringBuffer ("SELECT DISTINCT ProcessedOn FROM ").append(TableName) .append(" WHERE AD_Client_ID=? AND ProcessedOn