Fixed issue 15757.Add Internal Consumption post process.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 19 Aug 2014 12:17:48 +0200
changeset 24795 54f33703c708
parent 24794 ef972cfebd67
child 24796 9c709be3d4b6
Fixed issue 15757.Add Internal Consumption post process.
src-db/database/model/tables/M_INTERNAL_CONSUMPTION.xml
src-db/database/model/triggers/M_INTERNAL_CONSUMPTIONLINE_TRG.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_DIMENSION_MAPPING.xml
src-db/database/sourcedata/AD_FIELD.xml
src-db/database/sourcedata/AD_MESSAGE.xml
src-db/database/sourcedata/AD_REF_LIST.xml
src/org/openbravo/erpCommon/ad_forms/AcctServer.java
src/org/openbravo/erpCommon/ad_forms/AcctServer.java.orig
src/org/openbravo/erpCommon/ad_forms/DocInternalConsumption.java
src/org/openbravo/erpCommon/ad_forms/DocInternalConsumptionTemplate.java
src/org/openbravo/erpCommon/ad_forms/DocInternalConsumption_data.xsql
src/org/openbravo/erpCommon/ad_forms/DocLineInternalConsumption_data.xsql
--- a/src-db/database/model/tables/M_INTERNAL_CONSUMPTION.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/model/tables/M_INTERNAL_CONSUMPTION.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -61,12 +61,61 @@
         <default><![CDATA[DR]]></default>
         <onCreateDefault><![CDATA[CASE PROCESSED WHEN 'N' THEN 'DR' ELSE 'CO' END]]></onCreateDefault>
       </column>
+      <column name="AD_ORGTRX_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="C_PROJECT_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="C_CAMPAIGN_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="C_ACTIVITY_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="USER1_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="USER2_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="C_COSTCENTER_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="AD_CLIENT_MINTERNALCONSUMPTION">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
       <foreign-key foreignTable="AD_ORG" name="AD_ORG_MINTERNAL_CONSUMPTION">
         <reference local="AD_ORG_ID" foreign="AD_ORG_ID"/>
       </foreign-key>
+      <foreign-key foreignTable="AD_ORG" name="AD_ORGTRX_MINTERNALCONSUMPTION">
+        <reference local="AD_ORGTRX_ID" foreign="AD_ORG_ID"/>
+      </foreign-key>
+      <foreign-key foreignTable="C_ACTIVITY" name="C_ACTIVITYMINTERNALCONSUMPTION">
+        <reference local="C_ACTIVITY_ID" foreign="C_ACTIVITY_ID"/>
+      </foreign-key>
+      <foreign-key foreignTable="C_CAMPAIGN" name="C_CAMPAIGNMINTERNALCONSUMPTION">
+        <reference local="C_CAMPAIGN_ID" foreign="C_CAMPAIGN_ID"/>
+      </foreign-key>
+      <foreign-key foreignTable="C_COSTCENTER" name="C_COSTCNTRMINTERNALCONSUMPTION">
+        <reference local="C_COSTCENTER_ID" foreign="C_COSTCENTER_ID"/>
+      </foreign-key>
+      <foreign-key foreignTable="C_PROJECT" name="C_PROJECT_MINTERNALCONSUMPTION">
+        <reference local="C_PROJECT_ID" foreign="C_PROJECT_ID"/>
+      </foreign-key>
+      <foreign-key foreignTable="USER1" name="USER1_M_INTERNALCONSUMPTION">
+        <reference local="USER1_ID" foreign="USER1_ID"/>
+      </foreign-key>
+      <foreign-key foreignTable="USER2" name="USER2_M_INTERNALCONSUMPTION">
+        <reference local="USER2_ID" foreign="USER2_ID"/>
+      </foreign-key>
       <check name="M_INTERNAL_CONSUMPTION_ISA_CHK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check>
       <check name="M_INTERNAL_PROCESSED_CHECK"><![CDATA[PROCESSED IN ('Y', 'N')]]></check>
     </table>
--- a/src-db/database/model/triggers/M_INTERNAL_CONSUMPTIONLINE_TRG.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/model/triggers/M_INTERNAL_CONSUMPTIONLINE_TRG.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -88,8 +88,6 @@
      RAISE_APPLICATION_ERROR(-20000, '@AttrSetValueFixed@');
     END IF;
    END IF;
-  END IF;
-  IF (INSERTING OR UPDATING) THEN
     IF (:NEW.m_product_id IS NOT NULL) THEN
       SELECT isgeneric, name INTO v_isgeneric, v_productname
       FROM m_product
@@ -98,6 +96,10 @@
         RAISE_APPLICATION_ERROR(-20000, '@CannotUseGenericProduct@');
       END IF;
     END IF;
+    -- Do not allow internal consumption lines with quantity 0
+    IF (:NEW.movementqty = 0) THEN
+      RAISE_APPLICATION_ERROR(-20000, '@InternalConsumptionWithZeroQty@');
+    END IF;
   END IF;
 
 END M_INTERNAL_CONSUMPTIONLINE_TRG
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -174862,7 +174862,7 @@
 <!--802759-->  <HELP><![CDATA[An accounting status button that indicates if the transaction has already been posted to the general ledger or not. When doing the accounting manually this button can be used to post or unpost the transaction from the general ledger by hand.]]></HELP>
 <!--802759-->  <COLUMNNAME><![CDATA[Posted]]></COLUMNNAME>
 <!--802759-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
-<!--802759-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--802759-->  <AD_REFERENCE_ID><![CDATA[28]]></AD_REFERENCE_ID>
 <!--802759-->  <AD_REFERENCE_VALUE_ID><![CDATA[234]]></AD_REFERENCE_VALUE_ID>
 <!--802759-->  <FIELDLENGTH><![CDATA[60]]></FIELDLENGTH>
 <!--802759-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
@@ -228975,6 +228975,42 @@
 <!--1D362A68B15E4805B518D642AB906F70-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--1D362A68B15E4805B518D642AB906F70--></AD_COLUMN>
 
+<!--1D7D9FDD6B1B431AAE967818804F9095--><AD_COLUMN>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_COLUMN_ID><![CDATA[1D7D9FDD6B1B431AAE967818804F9095]]></AD_COLUMN_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <NAME><![CDATA[Cost Center]]></NAME>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <DESCRIPTION><![CDATA[Division that adds to the cost of an organization]]></DESCRIPTION>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <HELP><![CDATA[Division that adds to the cost of an organization. Internal structure for cost allocation.]]></HELP>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <COLUMNNAME><![CDATA[C_Costcenter_ID]]></COLUMNNAME>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_REFERENCE_ID><![CDATA[95E2A8B50A254B2AAE6774B8C2F28120]]></AD_REFERENCE_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_REFERENCE_VALUE_ID><![CDATA[DEE6B917B36D4648B2DA729FC2872CF4]]></AD_REFERENCE_VALUE_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <SEQNO><![CDATA[220]]></SEQNO>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_ELEMENT_ID><![CDATA[BB1B0593596A4F63B2553183B11B0D28]]></AD_ELEMENT_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <POSITION><![CDATA[23]]></POSITION>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--1D7D9FDD6B1B431AAE967818804F9095-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--1D7D9FDD6B1B431AAE967818804F9095--></AD_COLUMN>
+
 <!--1DA3007A3E1547AA95A420E351CB9759--><AD_COLUMN>
 <!--1DA3007A3E1547AA95A420E351CB9759-->  <AD_COLUMN_ID><![CDATA[1DA3007A3E1547AA95A420E351CB9759]]></AD_COLUMN_ID>
 <!--1DA3007A3E1547AA95A420E351CB9759-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -231970,6 +232006,8 @@
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <NAME><![CDATA[Processed]]></NAME>
+<!--28A31D4AD94641B9A18C3D3E141C00DD-->  <DESCRIPTION><![CDATA[A confirmation that the associated documents or requests are processed.]]></DESCRIPTION>
+<!--28A31D4AD94641B9A18C3D3E141C00DD-->  <HELP><![CDATA[The Processed checkbox indicates that a document has been processed.]]></HELP>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <COLUMNNAME><![CDATA[Processed]]></COLUMNNAME>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <AD_TABLE_ID><![CDATA[F6B6AD5679FF4A798D2A3D44B232C52C]]></AD_TABLE_ID>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
@@ -231984,6 +232022,7 @@
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--28A31D4AD94641B9A18C3D3E141C00DD-->  <AD_ELEMENT_ID><![CDATA[1047]]></AD_ELEMENT_ID>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISSESSIONATTR><![CDATA[Y]]></ISSESSIONATTR>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
 <!--28A31D4AD94641B9A18C3D3E141C00DD-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
@@ -234278,6 +234317,42 @@
 <!--340AEEBA6CC14670882470DDBDC11B7D-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--340AEEBA6CC14670882470DDBDC11B7D--></AD_COLUMN>
 
+<!--3494D6FD839840C885B01A9D5103A8E2--><AD_COLUMN>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_COLUMN_ID><![CDATA[3494D6FD839840C885B01A9D5103A8E2]]></AD_COLUMN_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <NAME><![CDATA[1st Dimension]]></NAME>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <DESCRIPTION><![CDATA[A display of optional elements that are previously defined for this account combination.]]></DESCRIPTION>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <HELP><![CDATA[The user defined element displays the optional elements that have been defined for this account combination.]]></HELP>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <COLUMNNAME><![CDATA[User1_ID]]></COLUMNNAME>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_REFERENCE_ID><![CDATA[95E2A8B50A254B2AAE6774B8C2F28120]]></AD_REFERENCE_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_REFERENCE_VALUE_ID><![CDATA[0E0D1661E18E4E05A118785A7CF146B8]]></AD_REFERENCE_VALUE_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <FIELDLENGTH><![CDATA[22]]></FIELDLENGTH>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <SEQNO><![CDATA[200]]></SEQNO>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_ELEMENT_ID><![CDATA[5491745132934260A5F00EF178EBC04B]]></AD_ELEMENT_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <POSITION><![CDATA[21]]></POSITION>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--3494D6FD839840C885B01A9D5103A8E2-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--3494D6FD839840C885B01A9D5103A8E2--></AD_COLUMN>
+
 <!--34E193A45220401C9DA9E8A4EC6B40F8--><AD_COLUMN>
 <!--34E193A45220401C9DA9E8A4EC6B40F8-->  <AD_COLUMN_ID><![CDATA[34E193A45220401C9DA9E8A4EC6B40F8]]></AD_COLUMN_ID>
 <!--34E193A45220401C9DA9E8A4EC6B40F8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -235998,6 +236073,43 @@
 <!--3C07F9D36CC241C38B072A698CD60517-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--3C07F9D36CC241C38B072A698CD60517--></AD_COLUMN>
 
+<!--3C32DB97D29C46678D24E0A0706B35B8--><AD_COLUMN>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_COLUMN_ID><![CDATA[3C32DB97D29C46678D24E0A0706B35B8]]></AD_COLUMN_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <NAME><![CDATA[Project]]></NAME>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <DESCRIPTION><![CDATA[Identifier of a project defined within the Project & Service Management module.]]></DESCRIPTION>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <HELP><![CDATA[Identifier of a project defined within the Project & Service Management module.]]></HELP>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <COLUMNNAME><![CDATA[C_Project_ID]]></COLUMNNAME>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_REFERENCE_ID><![CDATA[30]]></AD_REFERENCE_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_REFERENCE_VALUE_ID><![CDATA[800061]]></AD_REFERENCE_VALUE_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <FIELDLENGTH><![CDATA[60]]></FIELDLENGTH>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <READONLYLOGIC><![CDATA[@Posted@='Y']]></READONLYLOGIC>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <SEQNO><![CDATA[170]]></SEQNO>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_ELEMENT_ID><![CDATA[208]]></AD_ELEMENT_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <POSITION><![CDATA[18]]></POSITION>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--3C32DB97D29C46678D24E0A0706B35B8-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--3C32DB97D29C46678D24E0A0706B35B8--></AD_COLUMN>
+
 <!--3C606B6113A24FFBA0D08E98A15C2DF7--><AD_COLUMN>
 <!--3C606B6113A24FFBA0D08E98A15C2DF7-->  <AD_COLUMN_ID><![CDATA[3C606B6113A24FFBA0D08E98A15C2DF7]]></AD_COLUMN_ID>
 <!--3C606B6113A24FFBA0D08E98A15C2DF7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -236460,6 +236572,42 @@
 <!--3EA01D1013234BAF88B7CBAB150E3D71-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--3EA01D1013234BAF88B7CBAB150E3D71--></AD_COLUMN>
 
+<!--3ED46EA7767C4504B4DB3683587BE293--><AD_COLUMN>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_COLUMN_ID><![CDATA[3ED46EA7767C4504B4DB3683587BE293]]></AD_COLUMN_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <NAME><![CDATA[2nd Dimension]]></NAME>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <DESCRIPTION><![CDATA[A display of optional elements that are previously defined for this account combination.]]></DESCRIPTION>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <HELP><![CDATA[The user defined element displays the optional elements that have been defined for this account combination.]]></HELP>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <COLUMNNAME><![CDATA[User2_ID]]></COLUMNNAME>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_REFERENCE_ID><![CDATA[95E2A8B50A254B2AAE6774B8C2F28120]]></AD_REFERENCE_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_REFERENCE_VALUE_ID><![CDATA[1850A5390D97470EBB35A3A5F43AB533]]></AD_REFERENCE_VALUE_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <FIELDLENGTH><![CDATA[22]]></FIELDLENGTH>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <SEQNO><![CDATA[210]]></SEQNO>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_ELEMENT_ID><![CDATA[614]]></AD_ELEMENT_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <POSITION><![CDATA[22]]></POSITION>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--3ED46EA7767C4504B4DB3683587BE293-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--3ED46EA7767C4504B4DB3683587BE293--></AD_COLUMN>
+
 <!--3EE5C3FA006A425AAA45B703B30A516B--><AD_COLUMN>
 <!--3EE5C3FA006A425AAA45B703B30A516B-->  <AD_COLUMN_ID><![CDATA[3EE5C3FA006A425AAA45B703B30A516B]]></AD_COLUMN_ID>
 <!--3EE5C3FA006A425AAA45B703B30A516B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -236567,6 +236715,42 @@
 <!--3FE2EA6C9F474DE79421734AD8174FBA-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--3FE2EA6C9F474DE79421734AD8174FBA--></AD_COLUMN>
 
+<!--3FE35ACCEC86476BB11EEC0C162B51B5--><AD_COLUMN>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_COLUMN_ID><![CDATA[3FE35ACCEC86476BB11EEC0C162B51B5]]></AD_COLUMN_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <NAME><![CDATA[Trx Organization]]></NAME>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <DESCRIPTION><![CDATA[The organization which performs or initiates the transaction.]]></DESCRIPTION>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <HELP><![CDATA[The organization which performs or initiates this transaction (for another organization).  The owning Organization may not be the transaction organization in a service bureau environment, with centralized services, and inter-organization transactions.]]></HELP>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <COLUMNNAME><![CDATA[AD_Orgtrx_ID]]></COLUMNNAME>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_REFERENCE_ID><![CDATA[18]]></AD_REFERENCE_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_REFERENCE_VALUE_ID><![CDATA[130]]></AD_REFERENCE_VALUE_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <FIELDLENGTH><![CDATA[22]]></FIELDLENGTH>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <SEQNO><![CDATA[160]]></SEQNO>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_ELEMENT_ID><![CDATA[112]]></AD_ELEMENT_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <POSITION><![CDATA[17]]></POSITION>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--3FE35ACCEC86476BB11EEC0C162B51B5--></AD_COLUMN>
+
 <!--400ADD1C63FD4F57B16BF9D8198F9D9A--><AD_COLUMN>
 <!--400ADD1C63FD4F57B16BF9D8198F9D9A-->  <AD_COLUMN_ID><![CDATA[400ADD1C63FD4F57B16BF9D8198F9D9A]]></AD_COLUMN_ID>
 <!--400ADD1C63FD4F57B16BF9D8198F9D9A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -265449,6 +265633,7 @@
 <!--703042CC6F634C72A988F0F6ED20C347-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--703042CC6F634C72A988F0F6ED20C347-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--703042CC6F634C72A988F0F6ED20C347-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--703042CC6F634C72A988F0F6ED20C347-->  <AD_ELEMENT_ID><![CDATA[E918E0E599284CD29A9D44EF8D0F542F]]></AD_ELEMENT_ID>
 <!--703042CC6F634C72A988F0F6ED20C347-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
 <!--703042CC6F634C72A988F0F6ED20C347-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
 <!--703042CC6F634C72A988F0F6ED20C347-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
@@ -272629,6 +272814,41 @@
 <!--7C10EF630525456698F15ECAAF7BC1DA-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--7C10EF630525456698F15ECAAF7BC1DA--></AD_COLUMN>
 
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF--><AD_COLUMN>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_COLUMN_ID><![CDATA[7C32A7CD52BE427EB18FF2D7893D5FDF]]></AD_COLUMN_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <NAME><![CDATA[Sales Campaign]]></NAME>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <DESCRIPTION><![CDATA[An advertising effort aimed at increasing sales.]]></DESCRIPTION>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <HELP><![CDATA[The Campaign defines a unique marketing program.  Projects can be associated with a pre defined Marketing Campaign.  You can then report based on a specific Campaign.]]></HELP>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <COLUMNNAME><![CDATA[C_Campaign_ID]]></COLUMNNAME>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <FIELDLENGTH><![CDATA[22]]></FIELDLENGTH>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <SEQNO><![CDATA[180]]></SEQNO>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_ELEMENT_ID><![CDATA[550]]></AD_ELEMENT_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <POSITION><![CDATA[19]]></POSITION>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--7C32A7CD52BE427EB18FF2D7893D5FDF--></AD_COLUMN>
+
 <!--7C4AEC0BF04F4588A2D26D46E1EE0E7B--><AD_COLUMN>
 <!--7C4AEC0BF04F4588A2D26D46E1EE0E7B-->  <AD_COLUMN_ID><![CDATA[7C4AEC0BF04F4588A2D26D46E1EE0E7B]]></AD_COLUMN_ID>
 <!--7C4AEC0BF04F4588A2D26D46E1EE0E7B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -326197,6 +326417,41 @@
 <!--DDEFF6832ABE4477AB7C33CF71344334-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--DDEFF6832ABE4477AB7C33CF71344334--></AD_COLUMN>
 
+<!--DE48632B1879433090FEE7CA890611C0--><AD_COLUMN>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_COLUMN_ID><![CDATA[DE48632B1879433090FEE7CA890611C0]]></AD_COLUMN_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DE48632B1879433090FEE7CA890611C0-->  <NAME><![CDATA[Activity]]></NAME>
+<!--DE48632B1879433090FEE7CA890611C0-->  <DESCRIPTION><![CDATA[A distinct activity defined and used in activity based management.]]></DESCRIPTION>
+<!--DE48632B1879433090FEE7CA890611C0-->  <HELP><![CDATA[Activities indicate tasks that are performed and used to utilize Activity based Costing]]></HELP>
+<!--DE48632B1879433090FEE7CA890611C0-->  <COLUMNNAME><![CDATA[C_Activity_ID]]></COLUMNNAME>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <FIELDLENGTH><![CDATA[22]]></FIELDLENGTH>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--DE48632B1879433090FEE7CA890611C0-->  <SEQNO><![CDATA[190]]></SEQNO>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_ELEMENT_ID><![CDATA[1005]]></AD_ELEMENT_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--DE48632B1879433090FEE7CA890611C0-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--DE48632B1879433090FEE7CA890611C0-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--DE48632B1879433090FEE7CA890611C0-->  <POSITION><![CDATA[20]]></POSITION>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--DE48632B1879433090FEE7CA890611C0-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--DE48632B1879433090FEE7CA890611C0-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--DE48632B1879433090FEE7CA890611C0-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--DE48632B1879433090FEE7CA890611C0--></AD_COLUMN>
+
 <!--DE684B7F563E49E198807C2E8F5DCA3E--><AD_COLUMN>
 <!--DE684B7F563E49E198807C2E8F5DCA3E-->  <AD_COLUMN_ID><![CDATA[DE684B7F563E49E198807C2E8F5DCA3E]]></AD_COLUMN_ID>
 <!--DE684B7F563E49E198807C2E8F5DCA3E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_DIMENSION_MAPPING.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/sourcedata/AD_DIMENSION_MAPPING.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -182,6 +182,19 @@
 <!--04E653BAB3FA4672A1CB72A4F2E714B7-->  <DOCUMENTLEVEL><![CDATA[L]]></DOCUMENTLEVEL>
 <!--04E653BAB3FA4672A1CB72A4F2E714B7--></AD_DIMENSION_MAPPING>
 
+<!--058F6658263B4F82AE576606AA92165F--><AD_DIMENSION_MAPPING>
+<!--058F6658263B4F82AE576606AA92165F-->  <AD_DIMENSION_MAPPING_ID><![CDATA[058F6658263B4F82AE576606AA92165F]]></AD_DIMENSION_MAPPING_ID>
+<!--058F6658263B4F82AE576606AA92165F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--058F6658263B4F82AE576606AA92165F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--058F6658263B4F82AE576606AA92165F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--058F6658263B4F82AE576606AA92165F-->  <DIMENSION><![CDATA[U2]]></DIMENSION>
+<!--058F6658263B4F82AE576606AA92165F-->  <DOCBASETYPE><![CDATA[MIC]]></DOCBASETYPE>
+<!--058F6658263B4F82AE576606AA92165F-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--058F6658263B4F82AE576606AA92165F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--058F6658263B4F82AE576606AA92165F-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--058F6658263B4F82AE576606AA92165F-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
+<!--058F6658263B4F82AE576606AA92165F--></AD_DIMENSION_MAPPING>
+
 <!--05D98BA6BEEE41D487A3F9AAF6D7B91B--><AD_DIMENSION_MAPPING>
 <!--05D98BA6BEEE41D487A3F9AAF6D7B91B-->  <AD_DIMENSION_MAPPING_ID><![CDATA[05D98BA6BEEE41D487A3F9AAF6D7B91B]]></AD_DIMENSION_MAPPING_ID>
 <!--05D98BA6BEEE41D487A3F9AAF6D7B91B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -715,6 +728,19 @@
 <!--26D763C522F34C10B5C0216FD46AC677-->  <DOCUMENTLEVEL><![CDATA[BD]]></DOCUMENTLEVEL>
 <!--26D763C522F34C10B5C0216FD46AC677--></AD_DIMENSION_MAPPING>
 
+<!--2982DB95CFB24A8DA4420D6FC204E04F--><AD_DIMENSION_MAPPING>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <AD_DIMENSION_MAPPING_ID><![CDATA[2982DB95CFB24A8DA4420D6FC204E04F]]></AD_DIMENSION_MAPPING_ID>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <DIMENSION><![CDATA[U1]]></DIMENSION>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <DOCBASETYPE><![CDATA[MIC]]></DOCBASETYPE>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--2982DB95CFB24A8DA4420D6FC204E04F-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
+<!--2982DB95CFB24A8DA4420D6FC204E04F--></AD_DIMENSION_MAPPING>
+
 <!--2A1BD2AA8C564EB0BAAC5F9D47791E13--><AD_DIMENSION_MAPPING>
 <!--2A1BD2AA8C564EB0BAAC5F9D47791E13-->  <AD_DIMENSION_MAPPING_ID><![CDATA[2A1BD2AA8C564EB0BAAC5F9D47791E13]]></AD_DIMENSION_MAPPING_ID>
 <!--2A1BD2AA8C564EB0BAAC5F9D47791E13-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1469,6 +1495,19 @@
 <!--54BE165836C84ECE9CD8D8A864C78B6A-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
 <!--54BE165836C84ECE9CD8D8A864C78B6A--></AD_DIMENSION_MAPPING>
 
+<!--54CB6C16941746DD9527A96A05216B27--><AD_DIMENSION_MAPPING>
+<!--54CB6C16941746DD9527A96A05216B27-->  <AD_DIMENSION_MAPPING_ID><![CDATA[54CB6C16941746DD9527A96A05216B27]]></AD_DIMENSION_MAPPING_ID>
+<!--54CB6C16941746DD9527A96A05216B27-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--54CB6C16941746DD9527A96A05216B27-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--54CB6C16941746DD9527A96A05216B27-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--54CB6C16941746DD9527A96A05216B27-->  <DIMENSION><![CDATA[CC]]></DIMENSION>
+<!--54CB6C16941746DD9527A96A05216B27-->  <DOCBASETYPE><![CDATA[MIC]]></DOCBASETYPE>
+<!--54CB6C16941746DD9527A96A05216B27-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--54CB6C16941746DD9527A96A05216B27-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--54CB6C16941746DD9527A96A05216B27-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--54CB6C16941746DD9527A96A05216B27-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
+<!--54CB6C16941746DD9527A96A05216B27--></AD_DIMENSION_MAPPING>
+
 <!--5519EC039D2B4CBBA7D8301EC67897E7--><AD_DIMENSION_MAPPING>
 <!--5519EC039D2B4CBBA7D8301EC67897E7-->  <AD_DIMENSION_MAPPING_ID><![CDATA[5519EC039D2B4CBBA7D8301EC67897E7]]></AD_DIMENSION_MAPPING_ID>
 <!--5519EC039D2B4CBBA7D8301EC67897E7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1859,6 +1898,19 @@
 <!--65BF47E65C6344BF8F4D40ACF773A066-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
 <!--65BF47E65C6344BF8F4D40ACF773A066--></AD_DIMENSION_MAPPING>
 
+<!--67520A3BD1B9408FB97EC1FF79A2364A--><AD_DIMENSION_MAPPING>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <AD_DIMENSION_MAPPING_ID><![CDATA[67520A3BD1B9408FB97EC1FF79A2364A]]></AD_DIMENSION_MAPPING_ID>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <DIMENSION><![CDATA[OO]]></DIMENSION>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <DOCBASETYPE><![CDATA[MIC]]></DOCBASETYPE>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <AD_TABLE_ID><![CDATA[800169]]></AD_TABLE_ID>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--67520A3BD1B9408FB97EC1FF79A2364A-->  <DOCUMENTLEVEL><![CDATA[L]]></DOCUMENTLEVEL>
+<!--67520A3BD1B9408FB97EC1FF79A2364A--></AD_DIMENSION_MAPPING>
+
 <!--67937D1ACA60401384F9C566B6FB1EDE--><AD_DIMENSION_MAPPING>
 <!--67937D1ACA60401384F9C566B6FB1EDE-->  <AD_DIMENSION_MAPPING_ID><![CDATA[67937D1ACA60401384F9C566B6FB1EDE]]></AD_DIMENSION_MAPPING_ID>
 <!--67937D1ACA60401384F9C566B6FB1EDE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -3614,6 +3666,19 @@
 <!--BCC2B49245BC4E6DBB2903DB477EA1A1-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
 <!--BCC2B49245BC4E6DBB2903DB477EA1A1--></AD_DIMENSION_MAPPING>
 
+<!--BE2EAD152EC8470DAEDED8B74DE1D445--><AD_DIMENSION_MAPPING>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <AD_DIMENSION_MAPPING_ID><![CDATA[BE2EAD152EC8470DAEDED8B74DE1D445]]></AD_DIMENSION_MAPPING_ID>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <DIMENSION><![CDATA[PR]]></DIMENSION>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <DOCBASETYPE><![CDATA[MIC]]></DOCBASETYPE>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <AD_TABLE_ID><![CDATA[800169]]></AD_TABLE_ID>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445-->  <DOCUMENTLEVEL><![CDATA[L]]></DOCUMENTLEVEL>
+<!--BE2EAD152EC8470DAEDED8B74DE1D445--></AD_DIMENSION_MAPPING>
+
 <!--BE3239BDC02848A3B7F23DE06A352584--><AD_DIMENSION_MAPPING>
 <!--BE3239BDC02848A3B7F23DE06A352584-->  <AD_DIMENSION_MAPPING_ID><![CDATA[BE3239BDC02848A3B7F23DE06A352584]]></AD_DIMENSION_MAPPING_ID>
 <!--BE3239BDC02848A3B7F23DE06A352584-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -3978,6 +4043,19 @@
 <!--D77D072E7CAF48319043169F65E4F5E1-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
 <!--D77D072E7CAF48319043169F65E4F5E1--></AD_DIMENSION_MAPPING>
 
+<!--D92C60957DBF4398A7628A92861BEEF8--><AD_DIMENSION_MAPPING>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <AD_DIMENSION_MAPPING_ID><![CDATA[D92C60957DBF4398A7628A92861BEEF8]]></AD_DIMENSION_MAPPING_ID>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <DIMENSION><![CDATA[PJ]]></DIMENSION>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <DOCBASETYPE><![CDATA[MIC]]></DOCBASETYPE>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <AD_TABLE_ID><![CDATA[800168]]></AD_TABLE_ID>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--D92C60957DBF4398A7628A92861BEEF8-->  <DOCUMENTLEVEL><![CDATA[H]]></DOCUMENTLEVEL>
+<!--D92C60957DBF4398A7628A92861BEEF8--></AD_DIMENSION_MAPPING>
+
 <!--D962173C76454EAA90021672F1AA67F4--><AD_DIMENSION_MAPPING>
 <!--D962173C76454EAA90021672F1AA67F4-->  <AD_DIMENSION_MAPPING_ID><![CDATA[D962173C76454EAA90021672F1AA67F4]]></AD_DIMENSION_MAPPING_ID>
 <!--D962173C76454EAA90021672F1AA67F4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -140688,8 +140688,9 @@
 <!--803069-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
 <!--803069-->  <AD_COLUMN_ID><![CDATA[802759]]></AD_COLUMN_ID>
 <!--803069-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
-<!--803069-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
-<!--803069-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--803069-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--803069-->  <DISPLAYLOGIC><![CDATA[@Processed@='Y' & @#ShowAcct@='Y']]></DISPLAYLOGIC>
+<!--803069-->  <DISPLAYLENGTH><![CDATA[23]]></DISPLAYLENGTH>
 <!--803069-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--803069-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--803069-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
@@ -184803,6 +184804,36 @@
 <!--1B00F87604D04B9E9822AD69992A289E-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--1B00F87604D04B9E9822AD69992A289E--></AD_FIELD>
 
+<!--1B062AF23A744D1A8047E33D0DDAD7A6--><AD_FIELD>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_FIELD_ID><![CDATA[1B062AF23A744D1A8047E33D0DDAD7A6]]></AD_FIELD_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <NAME><![CDATA[Activity]]></NAME>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <DESCRIPTION><![CDATA[A distinct activity defined and used in activity based management.]]></DESCRIPTION>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <HELP><![CDATA[Activities indicate tasks that are performed and used to utilize Activity based Costing]]></HELP>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_COLUMN_ID><![CDATA[DE48632B1879433090FEE7CA890611C0]]></AD_COLUMN_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_FIELDGROUP_ID><![CDATA[800000]]></AD_FIELDGROUP_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <DISPLAYLOGIC><![CDATA[@$Element_AY@='Y']]></DISPLAYLOGIC>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <DISPLAYLENGTH><![CDATA[44]]></DISPLAYLENGTH>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <SEQNO><![CDATA[80]]></SEQNO>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--1B062AF23A744D1A8047E33D0DDAD7A6--></AD_FIELD>
+
 <!--1B064A94E8E8499F8EA9CE68E8BDCAFB--><AD_FIELD>
 <!--1B064A94E8E8499F8EA9CE68E8BDCAFB-->  <AD_FIELD_ID><![CDATA[1B064A94E8E8499F8EA9CE68E8BDCAFB]]></AD_FIELD_ID>
 <!--1B064A94E8E8499F8EA9CE68E8BDCAFB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -195668,6 +195699,36 @@
 <!--3DE09F050A624C9D9E5477D0A94491A1-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--3DE09F050A624C9D9E5477D0A94491A1--></AD_FIELD>
 
+<!--3E3F9F4144804AEB99FE43DA3FA20B52--><AD_FIELD>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_FIELD_ID><![CDATA[3E3F9F4144804AEB99FE43DA3FA20B52]]></AD_FIELD_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <NAME><![CDATA[Sales Campaign]]></NAME>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <DESCRIPTION><![CDATA[An advertising effort aimed at increasing sales.]]></DESCRIPTION>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <HELP><![CDATA[The Campaign defines a unique marketing program.  Projects can be associated with a pre defined Marketing Campaign.  You can then report based on a specific Campaign.]]></HELP>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_COLUMN_ID><![CDATA[7C32A7CD52BE427EB18FF2D7893D5FDF]]></AD_COLUMN_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_FIELDGROUP_ID><![CDATA[800000]]></AD_FIELDGROUP_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <DISPLAYLOGIC><![CDATA[@$Element_MC@='Y']]></DISPLAYLOGIC>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <DISPLAYLENGTH><![CDATA[44]]></DISPLAYLENGTH>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <SEQNO><![CDATA[70]]></SEQNO>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--3E3F9F4144804AEB99FE43DA3FA20B52--></AD_FIELD>
+
 <!--3E4741567DA14D638DCD3AA008D18EC3--><AD_FIELD>
 <!--3E4741567DA14D638DCD3AA008D18EC3-->  <AD_FIELD_ID><![CDATA[3E4741567DA14D638DCD3AA008D18EC3]]></AD_FIELD_ID>
 <!--3E4741567DA14D638DCD3AA008D18EC3-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -196007,6 +196068,36 @@
 <!--3F468C51F54C46489E5D1F4D21DA1C5B-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--3F468C51F54C46489E5D1F4D21DA1C5B--></AD_FIELD>
 
+<!--3F589A2CACC14A3B8C06DEABF65B2533--><AD_FIELD>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_FIELD_ID><![CDATA[3F589A2CACC14A3B8C06DEABF65B2533]]></AD_FIELD_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <NAME><![CDATA[1st Dimension]]></NAME>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <DESCRIPTION><![CDATA[A display of optional elements that are previously defined for this account combination.]]></DESCRIPTION>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <HELP><![CDATA[The user defined element displays the optional elements that have been defined for this account combination.]]></HELP>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_COLUMN_ID><![CDATA[3494D6FD839840C885B01A9D5103A8E2]]></AD_COLUMN_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_FIELDGROUP_ID><![CDATA[800000]]></AD_FIELDGROUP_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <DISPLAYLOGIC><![CDATA[@ACCT_DIMENSION_DISPLAY@]]></DISPLAYLOGIC>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <DISPLAYLENGTH><![CDATA[44]]></DISPLAYLENGTH>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <SEQNO><![CDATA[90]]></SEQNO>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--3F589A2CACC14A3B8C06DEABF65B2533-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--3F589A2CACC14A3B8C06DEABF65B2533--></AD_FIELD>
+
 <!--3F78A04EB1D7458EBA761596DA309E71--><AD_FIELD>
 <!--3F78A04EB1D7458EBA761596DA309E71-->  <AD_FIELD_ID><![CDATA[3F78A04EB1D7458EBA761596DA309E71]]></AD_FIELD_ID>
 <!--3F78A04EB1D7458EBA761596DA309E71-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -199085,6 +199176,36 @@
 <!--49897E95D61F486699D64087F2897D42-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--49897E95D61F486699D64087F2897D42--></AD_FIELD>
 
+<!--499784A3437C454B84F9F506F95D294E--><AD_FIELD>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_FIELD_ID><![CDATA[499784A3437C454B84F9F506F95D294E]]></AD_FIELD_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--499784A3437C454B84F9F506F95D294E-->  <NAME><![CDATA[Project]]></NAME>
+<!--499784A3437C454B84F9F506F95D294E-->  <DESCRIPTION><![CDATA[Identifier of a project defined within the Project & Service Management module.]]></DESCRIPTION>
+<!--499784A3437C454B84F9F506F95D294E-->  <HELP><![CDATA[Identifier of a project defined within the Project & Service Management module.]]></HELP>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_COLUMN_ID><![CDATA[3C32DB97D29C46678D24E0A0706B35B8]]></AD_COLUMN_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_FIELDGROUP_ID><![CDATA[800000]]></AD_FIELDGROUP_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--499784A3437C454B84F9F506F95D294E-->  <DISPLAYLOGIC><![CDATA[@ACCT_DIMENSION_DISPLAY@]]></DISPLAYLOGIC>
+<!--499784A3437C454B84F9F506F95D294E-->  <DISPLAYLENGTH><![CDATA[44]]></DISPLAYLENGTH>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--499784A3437C454B84F9F506F95D294E-->  <SEQNO><![CDATA[60]]></SEQNO>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--499784A3437C454B84F9F506F95D294E-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--499784A3437C454B84F9F506F95D294E-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--499784A3437C454B84F9F506F95D294E-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--499784A3437C454B84F9F506F95D294E-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--499784A3437C454B84F9F506F95D294E-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--499784A3437C454B84F9F506F95D294E-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--499784A3437C454B84F9F506F95D294E--></AD_FIELD>
+
 <!--49CE293BE96646EA9C02D5D0B5F3EDAA--><AD_FIELD>
 <!--49CE293BE96646EA9C02D5D0B5F3EDAA-->  <AD_FIELD_ID><![CDATA[49CE293BE96646EA9C02D5D0B5F3EDAA]]></AD_FIELD_ID>
 <!--49CE293BE96646EA9C02D5D0B5F3EDAA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -203795,6 +203916,36 @@
 <!--5550CDBF77924CDEB2058BCF2B287184-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--5550CDBF77924CDEB2058BCF2B287184--></AD_FIELD>
 
+<!--555EC6B0F2274EE592D4B823D250C5C8--><AD_FIELD>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_FIELD_ID><![CDATA[555EC6B0F2274EE592D4B823D250C5C8]]></AD_FIELD_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <NAME><![CDATA[2nd Dimension]]></NAME>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <DESCRIPTION><![CDATA[A display of optional elements that are previously defined for this account combination.]]></DESCRIPTION>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <HELP><![CDATA[The user defined element displays the optional elements that have been defined for this account combination.]]></HELP>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_COLUMN_ID><![CDATA[3ED46EA7767C4504B4DB3683587BE293]]></AD_COLUMN_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_FIELDGROUP_ID><![CDATA[800000]]></AD_FIELDGROUP_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <DISPLAYLOGIC><![CDATA[@ACCT_DIMENSION_DISPLAY@]]></DISPLAYLOGIC>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <DISPLAYLENGTH><![CDATA[44]]></DISPLAYLENGTH>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <SEQNO><![CDATA[100]]></SEQNO>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--555EC6B0F2274EE592D4B823D250C5C8-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--555EC6B0F2274EE592D4B823D250C5C8--></AD_FIELD>
+
 <!--55690C7A57E041689429725E59294A37--><AD_FIELD>
 <!--55690C7A57E041689429725E59294A37-->  <AD_FIELD_ID><![CDATA[55690C7A57E041689429725E59294A37]]></AD_FIELD_ID>
 <!--55690C7A57E041689429725E59294A37-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -249475,6 +249626,8 @@
 <!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <NAME><![CDATA[Processed]]></NAME>
+<!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <DESCRIPTION><![CDATA[A confirmation that the associated documents or requests are processed.]]></DESCRIPTION>
+<!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <HELP><![CDATA[The Processed checkbox indicates that a document has been processed.]]></HELP>
 <!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
 <!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <AD_TAB_ID><![CDATA[4CD2099689D74243A0DE7910C6C86AD0]]></AD_TAB_ID>
 <!--ADD257062F9D4BA89DCF3DC38E8DC8B4-->  <AD_COLUMN_ID><![CDATA[28A31D4AD94641B9A18C3D3E141C00DD]]></AD_COLUMN_ID>
@@ -263063,6 +263216,35 @@
 <!--BD821C3B1EF54B67A33F9716A461A931-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--BD821C3B1EF54B67A33F9716A461A931--></AD_FIELD>
 
+<!--BD9576ADE03E46549F3C16A96446F985--><AD_FIELD>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <AD_FIELD_ID><![CDATA[BD9576ADE03E46549F3C16A96446F985]]></AD_FIELD_ID>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <NAME><![CDATA[Trx Organization]]></NAME>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <DESCRIPTION><![CDATA[The organization which performs or initiates the transaction.]]></DESCRIPTION>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <HELP><![CDATA[The organization which performs or initiates this transaction (for another organization).  The owning Organization may not be the transaction organization in a service bureau environment, with centralized services, and inter-organization transactions.]]></HELP>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <AD_COLUMN_ID><![CDATA[3FE35ACCEC86476BB11EEC0C162B51B5]]></AD_COLUMN_ID>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <DISPLAYLOGIC><![CDATA[@$Element_OT@='Y']]></DISPLAYLOGIC>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <DISPLAYLENGTH><![CDATA[44]]></DISPLAYLENGTH>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <SEQNO><![CDATA[50]]></SEQNO>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--BD9576ADE03E46549F3C16A96446F985-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--BD9576ADE03E46549F3C16A96446F985--></AD_FIELD>
+
 <!--BDA19525D5A742F6BB30E0B0BC51C9C2--><AD_FIELD>
 <!--BDA19525D5A742F6BB30E0B0BC51C9C2-->  <AD_FIELD_ID><![CDATA[BDA19525D5A742F6BB30E0B0BC51C9C2]]></AD_FIELD_ID>
 <!--BDA19525D5A742F6BB30E0B0BC51C9C2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -282426,6 +282608,36 @@
 <!--EC8BB2FC6EA6442B9D489E4C0671D428-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--EC8BB2FC6EA6442B9D489E4C0671D428--></AD_FIELD>
 
+<!--EC8D15D4DABE409EB7C34CD45917ACA7--><AD_FIELD>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_FIELD_ID><![CDATA[EC8D15D4DABE409EB7C34CD45917ACA7]]></AD_FIELD_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <NAME><![CDATA[Cost Center]]></NAME>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <DESCRIPTION><![CDATA[Division that adds to the cost of an organization]]></DESCRIPTION>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <HELP><![CDATA[Division that adds to the cost of an organization. Internal structure for cost allocation.]]></HELP>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_TAB_ID><![CDATA[800202]]></AD_TAB_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_COLUMN_ID><![CDATA[1D7D9FDD6B1B431AAE967818804F9095]]></AD_COLUMN_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_FIELDGROUP_ID><![CDATA[800000]]></AD_FIELDGROUP_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <DISPLAYLOGIC><![CDATA[@ACCT_DIMENSION_DISPLAY@]]></DISPLAYLOGIC>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <SEQNO><![CDATA[110]]></SEQNO>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--EC8D15D4DABE409EB7C34CD45917ACA7--></AD_FIELD>
+
 <!--ECB95BA0DE8111DD80EA001B388C05F0--><AD_FIELD>
 <!--ECB95BA0DE8111DD80EA001B388C05F0-->  <AD_FIELD_ID><![CDATA[ECB95BA0DE8111DD80EA001B388C05F0]]></AD_FIELD_ID>
 <!--ECB95BA0DE8111DD80EA001B388C05F0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -16030,6 +16030,18 @@
 <!--090396763E4C41C99BEFF7BB82D03A41-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--090396763E4C41C99BEFF7BB82D03A41--></AD_MESSAGE>
 
+<!--090D5DC8A4434705AA8572AF28FA4733--><AD_MESSAGE>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <AD_MESSAGE_ID><![CDATA[090D5DC8A4434705AA8572AF28FA4733]]></AD_MESSAGE_ID>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <VALUE><![CDATA[InternalConsumptionWithZeroQty]]></VALUE>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <MSGTEXT><![CDATA[It is not possible to save because the line has value zero in movement quantity. Please insert a different value from zero.]]></MSGTEXT>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--090D5DC8A4434705AA8572AF28FA4733-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--090D5DC8A4434705AA8572AF28FA4733--></AD_MESSAGE>
+
 <!--09E0CFCE33BA42D1A29CFF9F6E1A0146--><AD_MESSAGE>
 <!--09E0CFCE33BA42D1A29CFF9F6E1A0146-->  <AD_MESSAGE_ID><![CDATA[09E0CFCE33BA42D1A29CFF9F6E1A0146]]></AD_MESSAGE_ID>
 <!--09E0CFCE33BA42D1A29CFF9F6E1A0146-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Aug 19 08:59:35 2014 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Aug 19 12:17:48 2014 +0200
@@ -8483,6 +8483,17 @@
 <!--200F26704B9F4613996364978BC475C8-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--200F26704B9F4613996364978BC475C8--></AD_REF_LIST>
 
+<!--20E1D6D3951840C386D643459DD433D1--><AD_REF_LIST>
+<!--20E1D6D3951840C386D643459DD433D1-->  <AD_REF_LIST_ID><![CDATA[20E1D6D3951840C386D643459DD433D1]]></AD_REF_LIST_ID>
+<!--20E1D6D3951840C386D643459DD433D1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--20E1D6D3951840C386D643459DD433D1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--20E1D6D3951840C386D643459DD433D1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--20E1D6D3951840C386D643459DD433D1-->  <VALUE><![CDATA[MIC]]></VALUE>
+<!--20E1D6D3951840C386D643459DD433D1-->  <NAME><![CDATA[Material Internal Consumption]]></NAME>
+<!--20E1D6D3951840C386D643459DD433D1-->  <AD_REFERENCE_ID><![CDATA[183]]></AD_REFERENCE_ID>
+<!--20E1D6D3951840C386D643459DD433D1-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--20E1D6D3951840C386D643459DD433D1--></AD_REF_LIST>
+
 <!--213984A2876942898DFB901820B3D2AB--><AD_REF_LIST>
 <!--213984A2876942898DFB901820B3D2AB-->  <AD_REF_LIST_ID><![CDATA[213984A2876942898DFB901820B3D2AB]]></AD_REF_LIST_ID>
 <!--213984A2876942898DFB901820B3D2AB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -9723,6 +9734,17 @@
 <!--6D58DF036C134A799BB7229004F8163F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--6D58DF036C134A799BB7229004F8163F--></AD_REF_LIST>
 
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5--><AD_REF_LIST>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <AD_REF_LIST_ID><![CDATA[6F9DD304FD564F60B6C703A0E0E5E6E5]]></AD_REF_LIST_ID>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <VALUE><![CDATA[MIC]]></VALUE>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <NAME><![CDATA[Material Internal Consumption]]></NAME>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <AD_REFERENCE_ID><![CDATA[FBC599C796664DD49AD002C61DAFF813]]></AD_REFERENCE_ID>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--6F9DD304FD564F60B6C703A0E0E5E6E5--></AD_REF_LIST>
+
 <!--6FA37FCB15CF4653BED8A897301EA0C5--><AD_REF_LIST>
 <!--6FA37FCB15CF4653BED8A897301EA0C5-->  <AD_REF_LIST_ID><![CDATA[6FA37FCB15CF4653BED8A897301EA0C5]]></AD_REF_LIST_ID>
 <!--6FA37FCB15CF4653BED8A897301EA0C5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java	Tue Aug 19 08:59:35 2014 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java	Tue Aug 19 12:17:48 2014 +0200
@@ -252,6 +252,8 @@
   public static final String DOCTYPE_MatMovement = "MMM";
   /** Material Production */
   public static final String DOCTYPE_MatProduction = "MMP";
+  /** Material Internal Consumption */
+  public static final String DOCTYPE_MatInternalConsumption = "MIC";
 
   /** Match Invoice */
   public static final String DOCTYPE_MatMatchInv = "MXI";
@@ -472,7 +474,7 @@
         || AD_Table_ID.equals("407") || AD_Table_ID.equals("392") || AD_Table_ID.equals("259")
         || AD_Table_ID.equals("800019") || AD_Table_ID.equals("319") || AD_Table_ID.equals("321")
         || AD_Table_ID.equals("323") || AD_Table_ID.equals("325") || AD_Table_ID.equals("224")
-        || AD_Table_ID.equals("472")) {
+        || AD_Table_ID.equals("472") || AD_Table_ID.equals("800168")) {
       switch (Integer.parseInt(AD_Table_ID)) {
       case 318:
         acct = new DocInvoice(AD_Client_ID, AD_Org_ID, connectionProvider);
@@ -575,6 +577,13 @@
         acct.AD_Table_ID = "472";
         acct.reloadAcctSchemaArray();
         break;
+      case 800168:
+        acct = new DocInternalConsumption(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "M_Internal_Consumption";
+        acct.strDateColumn = "MovementDate";
+        acct.AD_Table_ID = "800168";
+        acct.reloadAcctSchemaArray();
+        break;
       // case 473: acct = new
       // DocMatchPO (AD_Client_ID); acct.strDateColumn = "MovementDate";
       // acct.reloadAcctSchemaArray(); break; case DocProjectIssue.AD_TABLE_ID: acct = new
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java.orig	Tue Aug 19 12:17:48 2014 +0200
@@ -0,0 +1,2901 @@
+/*
+ ******************************************************************************
+ * The contents of this file are subject to the   Compiere License  Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * You may obtain a copy of the License at http://www.compiere.org/license.html
+ * Software distributed under the License is distributed on an  "AS IS"  basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ * The Original Code is                  Compiere  ERP & CRM  Business Solution
+ * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
+ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
+ * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
+ * Contributor(s): Openbravo SLU
+ * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U.
+ ******************************************************************************
+ */
+package org.openbravo.erpCommon.ad_forms;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.servlet.ServletException;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.advpaymentmngt.APRM_FinaccTransactionV;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.kernel.RequestContext;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.DateTimeData;
+import org.openbravo.erpCommon.utility.OBDateUtils;
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.erpCommon.utility.SequenceIdData;
+import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.exception.NoConnectionAvailableException;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.CategoryAccounts;
+import org.openbravo.model.common.businesspartner.CustomerAccounts;
+import org.openbravo.model.common.businesspartner.VendorAccounts;
+import org.openbravo.model.common.currency.ConversionRateDoc;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.AcctSchemaTableDocType;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.invoice.ReversedInvoice;
+import org.openbravo.model.financialmgmt.accounting.FIN_FinancialAccountAccounting;
+import org.openbravo.model.financialmgmt.accounting.coa.AcctSchemaTable;
+import org.openbravo.model.financialmgmt.gl.GLItem;
+import org.openbravo.model.financialmgmt.gl.GLItemAccounts;
+import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.materialmgmt.transaction.MaterialTransaction;
+
+public abstract class AcctServer {
+  static Logger log4j = Logger.getLogger(AcctServer.class);
+
+  protected ConnectionProvider connectionProvider;
+
+  public String batchSize = "100";
+
+  public BigDecimal ZERO = BigDecimal.ZERO;
+
+  public String groupLines = "";
+  public String Qty = null;
+  public String tableName = "";
+  public String strDateColumn = "";
+  public String AD_Table_ID = "";
+  public String AD_Client_ID = "";
+  public String AD_Org_ID = "";
+  public String Status = "";
+  public String C_BPartner_ID = "";
+  public String C_BPartner_Location_ID = "";
+  public String M_Product_ID = "";
+  public String AD_OrgTrx_ID = "";
+  public String C_SalesRegion_ID = "";
+  public String C_Project_ID = "";
+  public String C_Campaign_ID = "";
+  public String C_Activity_ID = "";
+  public String C_LocFrom_ID = "";
+  public String C_LocTo_ID = "";
+  public String User1_ID = "";
+  public String User2_ID = "";
+  public String C_Costcenter_ID = "";
+  public String Name = "";
+  public String DocumentNo = "";
+  public String DateAcct = "";
+  public Date dateAcct = null;
+  public String DateDoc = "";
+  public String C_Period_ID = "";
+  public String C_Currency_ID = "";
+  public String C_DocType_ID = "";
+  public String C_Charge_ID = "";
+  public String ChargeAmt = "";
+  public String C_BankAccount_ID = "";
+  public String C_CashBook_ID = "";
+  public String M_Warehouse_ID = "";
+  public String Posted = "";
+  public String DocumentType = "";
+  public String TaxIncluded = "";
+  public String GL_Category_ID = "";
+  public String Record_ID = "";
+  public String IsReversal = "";
+  public String IsReturn = "";
+  /** No Currency in Document Indicator */
+  protected static final String NO_CURRENCY = "-1";
+  // This is just for the initialization of the accounting
+  public String m_IsOpening = "N";
+  // To match balances
+  public String m_Record_Id2 = "";
+
+  public Fact[] m_fact = null;
+  public AcctSchema[] m_as = null;
+
+  private FieldProvider objectFieldProvider[];
+
+  public String[] Amounts = new String[4];
+
+  // Conversion Rate precision. defaulted to 6 as it is stated in Format.xml
+  int conversionRatePrecision = 6;
+
+  public DocLine[] p_lines = new DocLine[0];
+  public DocLine_Payment[] m_debt_payments = new DocLine_Payment[0];
+
+  /**
+   * Is (Source) Multi-Currency Document - i.e. the document has different currencies (if true, the
+   * document will not be source balanced)
+   */
+  public boolean MultiCurrency = false;
+
+  /** Amount Type - Invoice */
+  public static final int AMTTYPE_Gross = 0;
+  public static final int AMTTYPE_Net = 1;
+  public static final int AMTTYPE_Charge = 2;
+  /** Amount Type - Allocation */
+  public static final int AMTTYPE_Invoice = 0;
+  public static final int AMTTYPE_Allocation = 1;
+  public static final int AMTTYPE_Discount = 2;
+  public static final int AMTTYPE_WriteOff = 3;
+
+  /** Document Status */
+  public static final String STATUS_NotPosted = "N";
+  /** Document Status */
+  public static final String STATUS_NotBalanced = "b";
+  /** Document Status */
+  public static final String STATUS_NotConvertible = "c";
+  /** Document Status */
+  public static final String STATUS_PeriodClosed = "p";
+  /** Document Status */
+  public static final String STATUS_InvalidAccount = "i";
+  /** Document Status */
+  public static final String STATUS_PostPrepared = "y";
+  /** Document Status */
+  public static final String STATUS_Posted = "Y";
+  /** Document Status */
+  public static final String STATUS_Error = "E";
+  /** Document Status */
+  public static final String STATUS_InvalidCost = "C";
+  /** Document Status */
+  public static final String STATUS_NotCalculatedCost = "NC";
+  /** Document Status */
+  public static final String STATUS_NoRelatedPO = "NO";
+  /** Document Status */
+  public static final String STATUS_DocumentLocked = "L";
+  /** Document Status */
+  public static final String STATUS_DocumentDisabled = "D";
+  /** Document Status */
+  public static final String STATUS_TableDisabled = "T";
+  /** Document Status */
+  public static final String STATUS_BackgroundDisabled = "d";
+  /** Document Status */
+  public static final String STATUS_NoAccountingDate = "AD";
+
+  /** Table IDs for document level conversion rates */
+  public static final String TABLEID_Invoice = "318";
+  public static final String TABLEID_Payment = "D1A97202E832470285C9B1EB026D54E2";
+  public static final String TABLEID_Transaction = "4D8C3B3C31D1410DA046140C9F024D17";
+  public static final String TABLEID_Reconciliation = "B1B7075C46934F0A9FD4C4D0F1457B42";
+
+  @Deprecated
+  // Use TABLEID_Invoice instead
+  public static final String EXCHANGE_DOCTYPE_Invoice = "318";
+  @Deprecated
+  // Use TABLEID_Payment instead
+  public static final String EXCHANGE_DOCTYPE_Payment = "D1A97202E832470285C9B1EB026D54E2";
+  @Deprecated
+  // Use TABLEID_Transaction instead
+  public static final String EXCHANGE_DOCTYPE_Transaction = "4D8C3B3C31D1410DA046140C9F024D17";
+
+  OBError messageResult = null;
+  String strMessage = null;
+
+  /** AR Invoices */
+  public static final String DOCTYPE_ARInvoice = "ARI";
+  /** Return Material Sales Invoice */
+  public static final String DOCTYPE_RMSalesInvoice = "ARI_RM";
+  /** AR Credit Memo */
+  public static final String DOCTYPE_ARCredit = "ARC";
+  /** AR Receipt */
+  public static final String DOCTYPE_ARReceipt = "ARR";
+  /** AR ProForma */
+  public static final String DOCTYPE_ARProForma = "ARF";
+
+  /** AP Invoices */
+  public static final String DOCTYPE_APInvoice = "API";
+  /** AP Credit Memo */
+  public static final String DOCTYPE_APCredit = "APC";
+  /** AP Payment */
+  public static final String DOCTYPE_APPayment = "APP";
+
+  /** CashManagement Bank Statement */
+  public static final String DOCTYPE_BankStatement = "CMB";
+  /** CashManagement Cash Journals */
+  public static final String DOCTYPE_CashJournal = "CMC";
+  /** CashManagement Allocations */
+  public static final String DOCTYPE_Allocation = "CMA";
+
+  /** Amortization */
+  public static final String DOCTYPE_Amortization = "AMZ";
+
+  /** Material Shipment */
+  public static final String DOCTYPE_MatShipment = "MMS";
+  /** Material Receipt */
+  public static final String DOCTYPE_MatReceipt = "MMR";
+  /** Material Inventory */
+  public static final String DOCTYPE_MatInventory = "MMI";
+  /** Material Movement */
+  public static final String DOCTYPE_MatMovement = "MMM";
+  /** Material Production */
+  public static final String DOCTYPE_MatProduction = "MMP";
+
+  /** Match Invoice */
+  public static final String DOCTYPE_MatMatchInv = "MXI";
+  /** Match PO */
+  public static final String DOCTYPE_MatMatchPO = "MXP";
+
+  /** GL Journal */
+  public static final String DOCTYPE_GLJournal = "GLJ";
+
+  /** Purchase Order */
+  public static final String DOCTYPE_POrder = "POO";
+  /** Sales Order */
+  public static final String DOCTYPE_SOrder = "SOO";
+
+  // DPManagement
+  public static final String DOCTYPE_DPManagement = "DPM";
+
+  // FinAccTransaction
+  public static final String DOCTYPE_FinAccTransaction = "FAT";
+  // FinReconciliation
+  public static final String DOCTYPE_Reconciliation = "REC";
+  // FinBankStatement
+  public static final String DOCTYPE_FinBankStatement = "BST";
+  // CostAdjustment
+  public static final String DOCTYPE_CostAdjustment = "CAD";
+
+  /*************************************************************************/
+
+  /** Account Type - Invoice */
+  public static final String ACCTTYPE_Charge = "0";
+  public static final String ACCTTYPE_C_Receivable = "1";
+  public static final String ACCTTYPE_V_Liability = "2";
+  public static final String ACCTTYPE_V_Liability_Services = "3";
+
+  /** Account Type - Payment */
+  public static final String ACCTTYPE_UnallocatedCash = "10";
+  public static final String ACCTTYPE_BankInTransit = "11";
+  public static final String ACCTTYPE_PaymentSelect = "12";
+  public static final String ACCTTYPE_WriteOffDefault = "13";
+  public static final String ACCTTYPE_WriteOffDefault_Revenue = "63";
+  public static final String ACCTTYPE_BankInTransitDefault = "14";
+  public static final String ACCTTYPE_ConvertChargeDefaultAmt = "15";
+  public static final String ACCTTYPE_ConvertGainDefaultAmt = "16";
+
+  /** Account Type - Cash */
+  public static final String ACCTTYPE_CashAsset = "20";
+  public static final String ACCTTYPE_CashTransfer = "21";
+  public static final String ACCTTYPE_CashExpense = "22";
+  public static final String ACCTTYPE_CashReceipt = "23";
+  public static final String ACCTTYPE_CashDifference = "24";
+
+  /** Account Type - Allocation */
+  public static final String ACCTTYPE_DiscountExp = "30";
+  public static final String ACCTTYPE_DiscountRev = "31";
+  public static final String ACCTTYPE_WriteOff = "32";
+  public static final String ACCTTYPE_WriteOff_Revenue = "64";
+
+  /** Account Type - Bank Statement */
+  public static final String ACCTTYPE_BankAsset = "40";
+  public static final String ACCTTYPE_InterestRev = "41";
+  public static final String ACCTTYPE_InterestExp = "42";
+  public static final String ACCTTYPE_ConvertChargeLossAmt = "43";
+  public static final String ACCTTYPE_ConvertChargeGainAmt = "44";
+
+  /** Inventory Accounts */
+  public static final String ACCTTYPE_InvDifferences = "50";
+  public static final String ACCTTYPE_NotInvoicedReceipts = "51";
+
+  /** Project Accounts */
+  public static final String ACCTTYPE_ProjectAsset = "61";
+  public static final String ACCTTYPE_ProjectWIP = "62";
+
+  /** GL Accounts */
+  public static final String ACCTTYPE_PPVOffset = "60";
+
+  // Reference (to find SalesRegion from BPartner)
+  public String BP_C_SalesRegion_ID = ""; // set in FactLine
+
+  public int errors = 0;
+  int success = 0;
+  // Distinguish background process
+  boolean isBackground = false;
+
+  /**
+   * Constructor
+   * 
+   * @param m_AD_Client_ID
+   *          Client ID of these Documents
+   * @param connectionProvider
+   *          Provider for db connections.
+   */
+  public AcctServer(String m_AD_Client_ID, String m_AD_Org_ID, ConnectionProvider connectionProvider) {
+    AD_Client_ID = m_AD_Client_ID;
+    AD_Org_ID = m_AD_Org_ID;
+    this.connectionProvider = connectionProvider;
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - LOADING ARRAY: " + m_AD_Client_ID);
+    m_as = AcctSchema.getAcctSchemaArray(connectionProvider, m_AD_Client_ID, m_AD_Org_ID);
+  } //
+
+  /*
+   * Empty constructor to initialize the class using reflexion, set() method should be called
+   * afterwards.
+   */
+
+  public AcctServer() {
+
+  }
+
+  public void setBatchSize(String newbatchSize) {
+    batchSize = newbatchSize;
+  }
+
+  public void run(VariablesSecureApp vars) throws IOException, ServletException {
+    run(vars, null, null);
+  }
+
+  public void run(VariablesSecureApp vars, String strDateFrom, String strDateTo)
+      throws IOException, ServletException {
+    if (AD_Client_ID.equals(""))
+      AD_Client_ID = vars.getClient();
+    Connection con = null;
+    try {
+      String strIDs = "";
+
+      if (log4j.isDebugEnabled()) {
+        log4j.debug("AcctServer - Run - TableName = " + tableName + strDateFrom + strDateTo);
+      }
+
+      log4j.debug("AcctServer.run - AD_Client_ID: " + AD_Client_ID);
+
+      AcctServerData[] data = null;
+      final Set<String> orgSet = OBContext.getOBContext()
+          .getOrganizationStructureProvider(AD_Client_ID).getChildTree(AD_Org_ID, true);
+      String strOrgs = Utility.getInStrSet(orgSet);
+      data = AcctServerData.select(connectionProvider, tableName, strDateColumn, AD_Client_ID,
+          strOrgs, strDateFrom, strDateTo, 0, Integer.valueOf(batchSize).intValue());
+      if (data != null && data.length > 0) {
+        if (log4j.isDebugEnabled()) {
+          log4j.debug("AcctServer - Run -Select inicial realizada N = " + data.length + " - Key: "
+              + data[0].id);
+        }
+      }
+
+      for (int i = 0; data != null && i < data.length; i++) {
+        con = connectionProvider.getTransactionConnection();
+        strIDs += data[i].getField("ID") + ", ";
+        this.setMessageResult(null);
+        AcctServer tempServer = get(AD_Table_ID, AD_Client_ID, AD_Org_ID, connectionProvider);
+        boolean postSuccess = false;
+        postSuccess = tempServer.post(data[i].getField("ID"), false, vars, connectionProvider, con);
+        errors = errors + tempServer.errors;
+        success = success + tempServer.success;
+        if (!postSuccess) {
+          connectionProvider.releaseRollbackConnection(con);
+          return;
+        } else {
+          connectionProvider.releaseCommitConnection(con);
+          OBDal.getInstance().commitAndClose();
+        }
+      }
+      if (log4j.isDebugEnabled() && data != null)
+        log4j.debug("AcctServer - Run -" + data.length + " IDs [" + strIDs + "]");
+      // Create Automatic Matching
+      // match (vars, this,con);
+    } catch (NoConnectionAvailableException ex) {
+      throw new ServletException("@CODE=NoConnectionAvailable", ex);
+    } catch (SQLException ex2) {
+      try {
+        connectionProvider.releaseRollbackConnection(con);
+      } catch (SQLException se) {
+        log4j.error("Failed to close connection after an error", se);
+      }
+      throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@"
+          + ex2.getMessage(), ex2);
+    } catch (Exception ex3) {
+      log4j.error("Exception in AcctServer.run", ex3);
+      try {
+        connectionProvider.releaseRollbackConnection(con);
+      } catch (SQLException se) {
+        log4j.error("Failed to close connection after an error", se);
+      }
+    }
+  }
+
+  /**
+   * @return the isBackground
+   */
+  public boolean isBackground() {
+    return isBackground;
+  }
+
+  /**
+   * @param isBackground
+   *          the isBackground to set
+   */
+  public void setBackground(boolean isBackground) {
+    this.isBackground = isBackground;
+  }
+
+  /**
+   * Factory - Create Posting document
+   * 
+   * @param AD_Table_ID
+   *          Table ID of Documents
+   * @param AD_Client_ID
+   *          Client ID of Documents
+   * @param connectionProvider
+   *          Database connection provider
+   * @return Document
+   */
+  public static AcctServer get(String AD_Table_ID, String AD_Client_ID, String AD_Org_ID,
+      ConnectionProvider connectionProvider) throws ServletException {
+    AcctServer acct = null;
+    if (log4j.isDebugEnabled())
+      log4j.debug("get - table: " + AD_Table_ID);
+    if (AD_Table_ID.equals("318") || AD_Table_ID.equals("800060") || AD_Table_ID.equals("800176")
+        || AD_Table_ID.equals("407") || AD_Table_ID.equals("392") || AD_Table_ID.equals("259")
+        || AD_Table_ID.equals("800019") || AD_Table_ID.equals("319") || AD_Table_ID.equals("321")
+        || AD_Table_ID.equals("323") || AD_Table_ID.equals("325") || AD_Table_ID.equals("224")
+        || AD_Table_ID.equals("472")) {
+      switch (Integer.parseInt(AD_Table_ID)) {
+      case 318:
+        acct = new DocInvoice(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "C_Invoice";
+        acct.AD_Table_ID = "318";
+        acct.strDateColumn = "DateAcct";
+        acct.reloadAcctSchemaArray();
+        acct.groupLines = AcctServerData.selectGroupLines(acct.connectionProvider, AD_Client_ID);
+        break;
+      /*
+       * case 390: acct = new DocAllocation (AD_Client_ID); acct.strDateColumn = "";
+       * acct.AD_Table_ID = "390"; acct.reloadAcctSchemaArray(); acct.break;
+       */
+      case 800060:
+        acct = new DocAmortization(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "A_Amortization";
+        acct.AD_Table_ID = "800060";
+        acct.strDateColumn = "DateAcct";
+        acct.reloadAcctSchemaArray();
+        break;
+
+      case 800176:
+        if (log4j.isDebugEnabled())
+          log4j.debug("AcctServer - Get DPM");
+        acct = new DocDPManagement(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "C_DP_Management";
+        acct.AD_Table_ID = "800176";
+        acct.strDateColumn = "DateAcct";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 407:
+        acct = new DocCash(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "C_Cash";
+        acct.strDateColumn = "DateAcct";
+        acct.AD_Table_ID = "407";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 392:
+        acct = new DocBank(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "C_Bankstatement";
+        acct.strDateColumn = "StatementDate";
+        acct.AD_Table_ID = "392";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 259:
+        acct = new DocOrder(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "C_Order";
+        acct.strDateColumn = "DateAcct";
+        acct.AD_Table_ID = "259";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 800019:
+        acct = new DocPayment(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "C_Settlement";
+        acct.strDateColumn = "Dateacct";
+        acct.AD_Table_ID = "800019";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 319:
+        acct = new DocInOut(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "M_InOut";
+        acct.strDateColumn = "DateAcct";
+        acct.AD_Table_ID = "319";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 321:
+        acct = new DocInventory(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "M_Inventory";
+        acct.strDateColumn = "MovementDate";
+        acct.AD_Table_ID = "321";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 323:
+        acct = new DocMovement(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "M_Movement";
+        acct.strDateColumn = "MovementDate";
+        acct.AD_Table_ID = "323";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 325:
+        acct = new DocProduction(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "M_Production";
+        acct.strDateColumn = "MovementDate";
+        acct.AD_Table_ID = "325";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 224:
+        if (log4j.isDebugEnabled())
+          log4j.debug("AcctServer - Before OBJECT CREATION");
+        acct = new DocGLJournal(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "GL_Journal";
+        acct.strDateColumn = "DateAcct";
+        acct.AD_Table_ID = "224";
+        acct.reloadAcctSchemaArray();
+        break;
+      case 472:
+        acct = new DocMatchInv(AD_Client_ID, AD_Org_ID, connectionProvider);
+        acct.tableName = "M_MatchInv";
+        acct.strDateColumn = "DateTrx";
+        acct.AD_Table_ID = "472";
+        acct.reloadAcctSchemaArray();
+        break;
+      // case 473: acct = new
+      // DocMatchPO (AD_Client_ID); acct.strDateColumn = "MovementDate";
+      // acct.reloadAcctSchemaArray(); break; case DocProjectIssue.AD_TABLE_ID: acct = new
+      // DocProjectIssue (AD_Client_ID); acct.strDateColumn = "MovementDate";
+      // acct.reloadAcctSchemaArray(); break;
+
+      }
+    } else {
+      AcctServerData[] acctinfo = AcctServerData.getTableInfo(connectionProvider, AD_Table_ID);
+      if (acctinfo != null && acctinfo.length != 0) {
+        if (!acctinfo[0].acctclassname.equals("") && !acctinfo[0].acctdatecolumn.equals("")) {
+          try {
+            acct = (AcctServer) Class.forName(acctinfo[0].acctclassname).newInstance();
+            acct.set(AD_Table_ID, AD_Client_ID, AD_Org_ID, connectionProvider,
+                acctinfo[0].tablename, acctinfo[0].acctdatecolumn);
+            acct.reloadAcctSchemaArray();
+          } catch (Exception e) {
+            log4j.error("Error while creating new instance for AcctServer - " + e, e);
+          }
+        }
+      }
+    }
+
+    if (acct == null)
+      log4j.warn("AcctServer - get - Unknown AD_Table_ID=" + AD_Table_ID);
+    else if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - get - AcctSchemaArray length=" + (acct.m_as).length);
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - get - AD_Table_ID=" + AD_Table_ID);
+    return acct;
+  } // get
+
+  public void set(String m_AD_Table_ID, String m_AD_Client_ID, String m_AD_Org_ID,
+      ConnectionProvider connectionProvider, String tablename, String acctdatecolumn) {
+    AD_Client_ID = m_AD_Client_ID;
+    AD_Org_ID = m_AD_Org_ID;
+    this.connectionProvider = connectionProvider;
+    tableName = tablename;
+    strDateColumn = acctdatecolumn;
+    AD_Table_ID = m_AD_Table_ID;
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - LOADING ARRAY: " + m_AD_Client_ID);
+    m_as = AcctSchema.getAcctSchemaArray(connectionProvider, m_AD_Client_ID, m_AD_Org_ID);
+  }
+
+  public void reloadAcctSchemaArray() throws ServletException {
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - reloadAcctSchemaArray - " + AD_Table_ID);
+    AcctSchema acct = null;
+    ArrayList<Object> new_as = new ArrayList<Object>();
+    for (int i = 0; i < (this.m_as).length; i++) {
+      acct = m_as[i];
+      if (AcctSchemaData.selectAcctSchemaTable(connectionProvider, acct.m_C_AcctSchema_ID,
+          AD_Table_ID)) {
+        new_as.add(new AcctSchema(connectionProvider, acct.m_C_AcctSchema_ID));
+      }
+    }
+    AcctSchema[] retValue = new AcctSchema[new_as.size()];
+    new_as.toArray(retValue);
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - RELOADING ARRAY: " + retValue.length);
+    this.m_as = retValue;
+  }
+
+  private void reloadAcctSchemaArray(String adOrgId) throws ServletException {
+    if (log4j.isDebugEnabled())
+      log4j
+          .debug("AcctServer - reloadAcctSchemaArray - " + AD_Table_ID + ", AD_ORG_ID: " + adOrgId);
+    AcctSchema acct = null;
+    ArrayList<Object> new_as = new ArrayList<Object>();
+    // We reload again all the acct schemas of the client
+    m_as = AcctSchema.getAcctSchemaArray(connectionProvider, AD_Client_ID, AD_Org_ID);
+    // Filter the right acct schemas for the organization
+    for (int i = 0; i < (this.m_as).length; i++) {
+      acct = m_as[i];
+      if (AcctSchemaData.selectAcctSchemaTable(connectionProvider, acct.m_C_AcctSchema_ID,
+          AD_Table_ID)) {
+        new_as.add(new AcctSchema(connectionProvider, acct.m_C_AcctSchema_ID));
+      }
+    }
+    AcctSchema[] retValue = new AcctSchema[new_as.size()];
+    new_as.toArray(retValue);
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - RELOADING ARRAY: " + retValue.length);
+    this.m_as = retValue;
+  }
+
+  /**
+   * This method handles the accounting of the record identified by strClave. Due to the possibility
+   * of developing processes that may run after the standard accounting the commit of the
+   * transactions made in this method cannot be done here. The commit must be handled in the caller
+   * of this method appropriately. Realize that you must handle the commit of the transactions made
+   * through a normal or a DAL connection.
+   */
+  public boolean post(String strClave, boolean force, VariablesSecureApp vars,
+      ConnectionProvider conn, Connection con) throws ServletException {
+    Record_ID = strClave;
+    if (log4j.isDebugEnabled())
+      log4j.debug("post " + strClave + " tablename: " + tableName);
+    try {
+      if (AcctServerData.update(conn, tableName, strClave) != 1) {
+        log4j.warn("AcctServer - Post -Cannot lock Document - ignored: " + tableName + "_ID="
+            + strClave);
+        setStatus(STATUS_DocumentLocked); // Status locked document
+        this.setMessageResult(conn, vars, STATUS_DocumentLocked, "Error");
+        return false;
+      } else
+        AcctServerData.delete(connectionProvider, AD_Table_ID, Record_ID);
+      if (log4j.isDebugEnabled())
+        log4j.debug("AcctServer - Post -TableName -" + tableName + "- ad_client_id -"
+            + AD_Client_ID + "- " + tableName + "_id -" + strClave);
+      try {
+        loadObjectFieldProvider(connectionProvider, AD_Client_ID, strClave);
+      } catch (ServletException e) {
+        log4j.warn(e);
+        e.printStackTrace();
+      }
+      FieldProvider data[] = getObjectFieldProvider();
+      // If there is any template active for current document in any accounting schema, skip this
+      // step as getDocumentConfirmation can lock template
+      try {
+        if ((disableDocumentConfirmation() || getDocumentConfirmation(conn, Record_ID))
+            && post(data, force, vars, conn, con)) {
+          success++;
+        } else {
+          errors++;
+          if (messageResult == null)
+            setMessageResult(conn, vars, getStatus(), "");
+          save(conn, vars.getUser());
+        }
+      } catch (Exception e) {
+        errors++;
+        Status = AcctServer.STATUS_Error;
+        save(conn, vars.getUser());
+        log4j.warn(e);
+        e.printStackTrace();
+      }
+    } catch (ServletException e) {
+      log4j.error(e);
+      return false;
+    }
+    return true;
+  }
+
+  private boolean post(FieldProvider[] data, boolean force, VariablesSecureApp vars,
+      ConnectionProvider conn, Connection con) throws ServletException {
+    if (log4j.isDebugEnabled())
+      log4j.debug("post data" + C_Currency_ID);
+    if (!loadDocument(data, force, conn, con)) {
+      log4j.warn("AcctServer - post - Error loading document");
+      return false;
+    }
+    // Set Currency precision
+    conversionRatePrecision = getConversionRatePrecision(vars);
+    if (data == null || data.length == 0)
+      return false;
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Post - Antes de getAcctSchemaArray - C_CURRENCY_ID = "
+    // + C_Currency_ID);
+    // Create Fact per AcctSchema
+    // if (log4j.isDebugEnabled()) log4j.debug("POSTLOADING ARRAY: " +
+    // AD_Client_ID);
+    if (!DocumentType.equals(DOCTYPE_GLJournal))
+      // m_as = AcctSchema.getAcctSchemaArray(conn, AD_Client_ID, AD_Org_ID);
+      reloadAcctSchemaArray(AD_Org_ID);
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Post - Antes de new Fact - C_CURRENCY_ID = "
+    // + C_Currency_ID);
+    m_fact = new Fact[m_as.length];
+    // AcctSchema Table check
+    boolean isTableActive = false;
+    try {
+      OBContext.setAdminMode(true);
+      for (AcctSchema as : m_as) {
+        AcctSchemaTable table = null;
+        OBCriteria<AcctSchemaTable> criteria = OBDao.getFilteredCriteria(AcctSchemaTable.class,
+            Restrictions.eq("accountingSchema.id", as.getC_AcctSchema_ID()),
+            Restrictions.eq("table.id", AD_Table_ID));
+        criteria.setFilterOnReadableClients(false);
+        criteria.setFilterOnReadableOrganization(false);
+        table = (AcctSchemaTable) criteria.uniqueResult();
+        if (table != null) {
+          isTableActive = true;
+          break;
+        }
+      }
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    if (!isTableActive) {
+      setMessageResult(conn, vars, STATUS_TableDisabled, "Warning");
+      return false;
+    }
+    // for all Accounting Schema
+    boolean OK = true;
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - Post -Beforde the loop - C_CURRENCY_ID = " + C_Currency_ID);
+    for (int i = 0; OK && i < m_as.length; i++) {
+      setStatus(STATUS_NotPosted);
+      if (isBackground && !isBackGroundEnabled(conn, m_as[i], AD_Table_ID)) {
+        setStatus(STATUS_BackgroundDisabled);
+        break;
+      }
+      if (log4j.isDebugEnabled())
+        log4j.debug("AcctServer - Post - Before the postLogic - C_CURRENCY_ID = " + C_Currency_ID);
+      Status = postLogic(i, conn, con, vars, m_as[i]);
+      if (log4j.isDebugEnabled())
+        log4j.debug("AcctServer - Post - After postLogic");
+      if (!Status.equals(STATUS_Posted))
+        return false;
+    }
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - Post - Before the postCommit - C_CURRENCY_ID = " + C_Currency_ID);
+    for (int i = 0; i < m_fact.length; i++)
+      if (m_fact[i] != null && (m_fact[i].getLines() == null || m_fact[i].getLines().length == 0))
+        return false;
+    // commitFact
+    Status = postCommit(Status, conn, vars, con);
+
+    // dispose facts
+    for (int i = 0; i < m_fact.length; i++)
+      if (m_fact[i] != null)
+        m_fact[i].dispose();
+    p_lines = null;
+    return Status.equals(STATUS_Posted);
+  } // post
+
+  boolean isBackGroundEnabled(ConnectionProvider conn, AcctSchema acctSchema, String adTableId)
+      throws ServletException {
+    return AcctServerData.selectBackgroundEnabled(conn, acctSchema.m_C_AcctSchema_ID, adTableId);
+  }
+
+  /**
+   * Post Commit. Save Facts & Document
+   * 
+   * @param status
+   *          status
+   * @return Posting Status
+   */
+  private final String postCommit(String status, ConnectionProvider conn, VariablesSecureApp vars,
+      Connection con) throws ServletException {
+    log4j.debug("AcctServer - postCommit Sta=" + status + " DT=" + DocumentType + " ID="
+        + Record_ID);
+    Status = status;
+    try {
+      // *** Transaction Start ***
+      // Commit Facts
+      if (Status.equals(AcctServer.STATUS_Posted)) {
+        if (m_fact != null && m_fact.length != 0) {
+          log4j.debug("AcctServer - postCommit - m_fact.length = " + m_fact.length);
+          for (int i = 0; i < m_fact.length; i++) {
+            if (m_fact[i] != null && m_fact[i].save(con, conn, vars))
+              ;
+            else {
+              // conn.releaseRollbackConnection(con);
+              unlock(conn);
+              Status = AcctServer.STATUS_Error;
+            }
+          }
+        }
+      }
+      // Commit Doc
+      if (!save(conn, vars.getUser())) { // contains unlock
+        // conn.releaseRollbackConnection(con);
+        unlock(conn);
+        // Status = AcctServer.STATUS_Error;
+      }
+      // conn.releaseCommitConnection(con);
+      // *** Transaction End ***
+    } catch (Exception e) {
+      log4j.warn("AcctServer - postCommit" + e);
+      Status = AcctServer.STATUS_Error;
+      // conn.releaseRollbackConnection(con);
+      unlock(conn);
+    }
+    return Status;
+  } // postCommit
+
+  /**
+   * Save to Disk - set posted flag
+   * 
+   * @param con
+   *          connection
+   * @param strUser
+   *          AD_User_ID
+   * @return true if saved
+   */
+  private final boolean save(ConnectionProvider conn, String strUser) {
+    int no = 0;
+    try {
+      no = AcctServerData.updateSave(conn, tableName, Status, strUser, Record_ID);
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    return no == 1;
+  } // save
+
+  /**
+   * Unlock Document
+   */
+  private void unlock(ConnectionProvider conn) {
+    try {
+      AcctServerData.updateUnlock(conn, tableName, Record_ID);
+    } catch (ServletException e) {
+      log4j.warn("AcctServer - Document locked: -" + e);
+    }
+  } // unlock
+
+  @Deprecated
+  // Deprecated in 2.50 because of a missing connection needed
+  public boolean loadDocument(FieldProvider[] data, boolean force, ConnectionProvider conn) {
+    try {
+      Connection con = conn.getConnection();
+      return loadDocument(data, force, conn, con);
+    } catch (NoConnectionAvailableException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+      return false;
+    }
+  }
+
+  public boolean loadDocument(FieldProvider[] data, boolean force, ConnectionProvider conn,
+      Connection con) {
+    if (log4j.isDebugEnabled())
+      log4j.debug("loadDocument " + data.length);
+
+    setStatus(STATUS_NotPosted);
+    Name = "";
+    AD_Client_ID = data[0].getField("AD_Client_ID");
+    AD_Org_ID = data[0].getField("AD_Org_ID");
+    C_BPartner_ID = data[0].getField("C_BPartner_ID");
+    M_Product_ID = data[0].getField("M_Product_ID");
+    AD_OrgTrx_ID = data[0].getField("AD_OrgTrx_ID");
+    C_SalesRegion_ID = data[0].getField("C_SalesRegion_ID");
+    C_Project_ID = data[0].getField("C_Project_ID");
+    C_Campaign_ID = data[0].getField("C_Campaign_ID");
+    C_Activity_ID = data[0].getField("C_Activity_ID");
+    C_LocFrom_ID = data[0].getField("C_LocFrom_ID");
+    C_LocTo_ID = data[0].getField("C_LocTo_ID");
+    User1_ID = data[0].getField("User1_ID");
+    User2_ID = data[0].getField("User2_ID");
+    C_Costcenter_ID = data[0].getField("C_Costcenter_ID");
+
+    Name = data[0].getField("Name");
+    DocumentNo = data[0].getField("DocumentNo");
+    DateAcct = data[0].getField("DateAcct");
+    DateDoc = data[0].getField("DateDoc");
+    C_Period_ID = data[0].getField("C_Period_ID");
+    C_Currency_ID = data[0].getField("C_Currency_ID");
+    C_DocType_ID = data[0].getField("C_DocType_ID");
+    C_Charge_ID = data[0].getField("C_Charge_ID");
+    ChargeAmt = data[0].getField("ChargeAmt");
+    C_BankAccount_ID = data[0].getField("C_BankAccount_ID");
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - loadDocument - C_BankAccount_ID : " + C_BankAccount_ID);
+    Posted = data[0].getField("Posted");
+    if (!loadDocumentDetails(data, conn))
+      loadDocumentType();
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - loadDocument - DocumentDetails Loaded");
+    if ((DateAcct == null || DateAcct.equals("")) && (DateDoc != null && !DateDoc.equals("")))
+      DateAcct = DateDoc;
+    else if ((DateDoc == null || DateDoc.equals("")) && (DateAcct != null && !DateAcct.equals("")))
+      DateDoc = DateAcct;
+    // DocumentNo (or Name)
+    if (DocumentNo == null || DocumentNo.length() == 0)
+      DocumentNo = Name;
+    // if (DocumentNo == null || DocumentNo.length() ==
+    // 0)(DateDoc.equals("") && !DateAcct.equals(""))
+    // DocumentNo = "";
+
+    // Check Mandatory Info
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - loadDocument - C_Currency_ID : " +
+    // C_Currency_ID);
+    String error = "";
+    if (AD_Table_ID == null || AD_Table_ID.equals(""))
+      error += " AD_Table_ID";
+    if (Record_ID == null || Record_ID.equals(""))
+      error += " Record_ID";
+    if (AD_Client_ID == null || AD_Client_ID.equals(""))
+      error += " AD_Client_ID";
+    if (AD_Org_ID == null || AD_Org_ID.equals(""))
+      error += " AD_Org_ID";
+    if (C_Currency_ID == null || C_Currency_ID.equals(""))
+      error += " C_Currency_ID";
+    if (DateAcct == null || DateAcct.equals(""))
+      error += " DateAcct";
+    if (DateDoc == null || DateDoc.equals(""))
+      error += " DateDoc";
+    if (error.length() > 0) {
+      log4j.warn("AcctServer - loadDocument - " + DocumentNo + " - Mandatory info missing: "
+          + error);
+      return false;
+    }
+    try {
+      dateAcct = OBDateUtils.getDate(DateAcct);
+    } catch (ParseException e1) {
+      // Do nothing
+    }
+
+    // Delete existing Accounting
+    if (force) {
+      if (Posted.equals("Y") && !isPeriodOpen()) { // already posted -
+        // don't delete if
+        // period closed
+        log4j.warn("AcctServer - loadDocument - " + DocumentNo
+            + " - Period Closed for already posted document");
+        return false;
+      }
+      // delete it
+      try {
+        AcctServerData.delete(connectionProvider, AD_Table_ID, Record_ID);
+      } catch (ServletException e) {
+        log4j.warn(e);
+        e.printStackTrace();
+      }
+      // if (log4j.isDebugEnabled()) log4j.debug("post - deleted=" + no);
+    } else if (Posted.equals("Y")) {
+      log4j.warn("AcctServer - loadDocument - " + DocumentNo + " - Document already posted");
+      return false;
+    }
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - loadDocument -finished");
+    return true;
+  } // loadDocument
+
+  public void loadDocumentType() {
+    loadDocumentType(false);
+  }
+
+  public void loadDocumentType(boolean supressWarnings) {
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - loadDocumentType - DocumentType: " +
+    // DocumentType + " - C_DocType_ID : " + C_DocType_ID);
+    try {
+      if (/* DocumentType.equals("") && */C_DocType_ID != null && C_DocType_ID != "") {
+        AcctServerData[] data = AcctServerData.selectDocType(connectionProvider, C_DocType_ID);
+        DocumentType = data[0].docbasetype;
+        GL_Category_ID = data[0].glCategoryId;
+        IsReversal = data[0].isreversal;
+        IsReturn = data[0].isreturn;
+      }
+      // We have a document Type, but no GL info - search for DocType
+      if (GL_Category_ID != null && GL_Category_ID.equals("")) {
+        AcctServerData[] data = AcctServerData.selectGLCategory(connectionProvider, AD_Client_ID,
+            DocumentType);
+        if (data != null && data.length != 0) {
+          GL_Category_ID = data[0].glCategoryId;
+          IsReversal = data[0].isreversal;
+          IsReturn = data[0].isreturn;
+        }
+      }
+      if (!supressWarnings && DocumentType != null && DocumentType.equals(""))
+        log4j.warn("AcctServer - loadDocumentType - No DocType for GL Info");
+      if (GL_Category_ID != null && GL_Category_ID.equals("")) {
+        AcctServerData[] data = AcctServerData.selectDefaultGLCategory(connectionProvider,
+            AD_Client_ID);
+        GL_Category_ID = data[0].glCategoryId;
+      }
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    if (GL_Category_ID != null && GL_Category_ID.equals(""))
+      log4j.warn("AcctServer - loadDocumentType - No GL Info");
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - loadDocumentType -" + tableName + "_ID : "
+    // + Record_ID + " - C_DocType_ID: " + C_DocType_ID +
+    // " - DocumentType: " + DocumentType);
+  }
+
+  /**
+   * @deprecated During cleanup for 3.0 the entire table ad_node was removed from core, so this
+   *             insertNote method doesn't serve have any purpose anymore. Keep as deprecated noop
+   *             in case any module may call it.
+   */
+  @Deprecated
+  public boolean insertNote(String AD_Client_ID, String AD_Org_ID, String AD_User_ID,
+      String AD_Table_ID, String Record_ID, String AD_MessageValue, String Text, String Reference,
+      VariablesSecureApp vars, ConnectionProvider conn, Connection con) {
+    return false;
+  }
+
+  /**
+   * Posting logic for Accounting Schema index
+   * 
+   * @param index
+   *          Accounting Schema index
+   * @return posting status/error code
+   */
+  private final String postLogic(int index, ConnectionProvider conn, Connection con,
+      VariablesSecureApp vars, AcctSchema as) throws ServletException {
+    // rejectUnbalanced
+    if (!m_as[index].isSuspenseBalancing() && !isBalanced())
+      return STATUS_NotBalanced;
+
+    // rejectUnconvertible
+    if (!isConvertible(m_as[index], conn))
+      return STATUS_NotConvertible;
+
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Before isPeriodOpen");
+    // rejectPeriodClosed
+    if (!isPeriodOpen())
+      return STATUS_PeriodClosed;
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - After isPeriodOpen");
+
+    // createFacts
+    try {
+      m_fact[index] = createFact(m_as[index], conn, con, vars);
+    } catch (Exception e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    if (!Status.equals(STATUS_NotPosted))
+      return Status;
+    if (m_fact[index] == null)
+      return STATUS_Error;
+    Status = STATUS_PostPrepared;
+
+    // Distinguish multi-currency Documents
+    MultiCurrency = m_fact[index].isMulticurrencyDocument();
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Before balanceSource");
+    // balanceSource
+    if (!MultiCurrency && !m_fact[index].isSourceBalanced())
+      m_fact[index].balanceSource(conn);
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - After balanceSource");
+
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Before isSegmentBalanced");
+    // balanceSegments
+    if (!MultiCurrency && !m_fact[index].isSegmentBalanced(conn))
+      m_fact[index].balanceSegments(conn);
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - After isSegmentBalanced");
+
+    // balanceAccounting
+    if (!m_fact[index].isAcctBalanced())
+      m_fact[index].balanceAccounting(conn);
+
+    // Here processes defined to be executed at posting time, when existing, will be executed
+    AcctServerData[] data = AcctServerData.selectAcctProcess(conn, as.m_C_AcctSchema_ID);
+    for (int i = 0; data != null && i < data.length; i++) {
+      String strClassname = data[i].classname;
+      if (!strClassname.equals("")) {
+        try {
+          AcctProcessTemplate newTemplate = (AcctProcessTemplate) Class.forName(strClassname)
+              .newInstance();
+          if (!newTemplate.execute(this, as, conn, con, vars)) {
+            OBDal.getInstance().rollbackAndClose();
+            return getStatus();
+          }
+        } catch (Exception e) {
+          log4j.error("Error while creating new instance for AcctProcessTemplate - " + e);
+          return AcctServer.STATUS_Error;
+        }
+      }
+    }
+    if (messageResult != null)
+      return getStatus();
+    return STATUS_Posted;
+  } // postLogic
+
+  /**
+   * Is the Source Document Balanced
+   * 
+   * @return true if (source) balanced
+   */
+  public boolean isBalanced() {
+    // Multi-Currency documents are source balanced by definition
+    if (MultiCurrency)
+      return true;
+    //
+    boolean retValue = (getBalance().compareTo(ZERO) == 0);
+    if (retValue) {
+      if (log4j.isDebugEnabled())
+        log4j.debug("AcctServer - isBalanced - " + DocumentNo);
+    } else
+      log4j.warn("AcctServer - is not Balanced - " + DocumentNo);
+    return retValue;
+  } // isBalanced
+
+  /**
+   * Is Document convertible to currency and Conversion Type
+   * 
+   * @param acctSchema
+   *          accounting schema
+   * @return true, if convertible to accounting currency
+   */
+  public boolean isConvertible(AcctSchema acctSchema, ConnectionProvider conn)
+      throws ServletException {
+    // No Currency in document
+    if (NO_CURRENCY.equals(C_Currency_ID)) {
+      // if (log4j.isDebugEnabled())
+      // log4j.debug("AcctServer - isConvertible (none) - " + DocumentNo);
+      return true;
+    }
+    // Get All Currencies
+    Vector<Object> set = new Vector<Object>();
+    set.addElement(C_Currency_ID);
+    for (int i = 0; p_lines != null && i < p_lines.length; i++) {
+      String currency = p_lines[i].m_C_Currency_ID;
+      if (currency != null && !currency.equals(""))
+        set.addElement(currency);
+    }
+
+    // just one and the same
+    if (set.size() == 1 && acctSchema.m_C_Currency_ID.equals(C_Currency_ID)) {
+      // if (log4j.isDebugEnabled()) log4j.debug
+      // ("AcctServer - isConvertible (same) Cur=" + C_Currency_ID + " - "
+      // + DocumentNo);
+      return true;
+    }
+    boolean convertible = true;
+    for (int i = 0; i < set.size() && convertible == true; i++) {
+      // if (log4j.isDebugEnabled()) log4j.debug
+      // ("AcctServer - get currency");
+      String currency = (String) set.elementAt(i);
+      if (currency == null)
+        currency = "";
+      // if (log4j.isDebugEnabled()) log4j.debug
+      // ("AcctServer - currency = " + currency);
+      if (!currency.equals(acctSchema.m_C_Currency_ID)) {
+        // if (log4j.isDebugEnabled()) log4j.debug
+        // ("AcctServer - get converted amount (init)");
+        String amt = "";
+        OBQuery<ConversionRateDoc> conversionQuery = null;
+        int conversionCount = 0;
+        if (AD_Table_ID.equals(TABLEID_Invoice)) {
+          conversionQuery = OBDal.getInstance().createQuery(
+              ConversionRateDoc.class,
+              "invoice = '" + Record_ID + "' and currency='" + currency + "' and toCurrency='"
+                  + acctSchema.m_C_Currency_ID + "'");
+        } else if (AD_Table_ID.equals(TABLEID_Payment)) {
+          conversionQuery = OBDal.getInstance().createQuery(
+              ConversionRateDoc.class,
+              "payment = '" + Record_ID + "' and currency='" + currency + "' and toCurrency='"
+                  + acctSchema.m_C_Currency_ID + "'");
+        } else if (AD_Table_ID.equals(TABLEID_Transaction)) {
+          conversionQuery = OBDal.getInstance().createQuery(
+              ConversionRateDoc.class,
+              "financialAccountTransaction = '" + Record_ID + "' and currency='" + currency
+                  + "' and toCurrency='" + acctSchema.m_C_Currency_ID + "'");
+        }
+        if (conversionQuery != null) {
+          conversionCount = conversionQuery.count();
+        }
+        if (conversionCount > 0) {
+          List<ConversionRateDoc> conversionRate = conversionQuery.list();
+          OBCriteria<Currency> currencyCrit = OBDal.getInstance().createCriteria(Currency.class);
+          currencyCrit.add(Restrictions.eq(Currency.PROPERTY_ID, acctSchema.m_C_Currency_ID));
+          currencyCrit.setProjection(Projections.max(Currency.PROPERTY_STANDARDPRECISION));
+          Long precision = 0L;
+          if (currencyCrit.count() > 0) {
+            List<Currency> toCurrency = currencyCrit.list();
+            precision = toCurrency.get(0).getStandardPrecision();
+          }
+          BigDecimal convertedAmount = new BigDecimal("1")
+              .multiply(conversionRate.get(0).getRate());
+          amt = convertedAmount.setScale(precision.intValue(), RoundingMode.HALF_UP).toString();
+        }
+        if (("").equals(amt) || amt == null)
+          amt = getConvertedAmt("1", currency, acctSchema.m_C_Currency_ID, DateAcct,
+              acctSchema.m_CurrencyRateType, AD_Client_ID, AD_Org_ID, conn);
+        // if (log4j.isDebugEnabled()) log4j.debug
+        // ("get converted amount (end)");
+        if (amt == null || ("").equals(amt)) {
+          convertible = false;
+          log4j.warn("AcctServer - isConvertible NOT from " + currency + " - " + DocumentNo);
+        } else if (log4j.isDebugEnabled())
+          log4j.debug("AcctServer - isConvertible from " + currency);
+      }
+    }
+    // if (log4j.isDebugEnabled()) log4j.debug
+    // ("AcctServer - isConvertible=" + convertible + ", AcctSchemaCur=" +
+    // acctSchema.m_C_Currency_ID + " - " + DocumentNo);
+    return convertible;
+  } // isConvertible
+
+  /**
+   * Get the Amount (loaded in loadDocumentDetails)
+   * 
+   * @param AmtType
+   *          see AMTTYPE_*
+   * @return Amount
+   */
+  public String getAmount(int AmtType) {
+    if (AmtType < 0 || Amounts == null || AmtType >= Amounts.length)
+      return null;
+    return (Amounts[AmtType].equals("")) ? "0" : Amounts[AmtType];
+  } // getAmount
+
+  /**
+   * Get Amount with index 0
+   * 
+   * @return Amount (primary document amount)
+   */
+  public String getAmount() {
+    return Amounts[0];
+  } // getAmount
+
+  /**
+   * Convert an amount
+   * 
+   * @param CurFrom_ID
+   *          The C_Currency_ID FROM
+   * @param CurTo_ID
+   *          The C_Currency_ID TO
+   * @param ConvDate
+   *          The Conversion date - if null - use current date
+   * @param RateType
+   *          The Conversion rate type - if null/empty - use Spot
+   * @param Amt
+   *          The amount to be converted
+   * @return converted amount
+   */
+  public static String getConvertedAmt(String Amt, String CurFrom_ID, String CurTo_ID,
+      String ConvDate, String RateType, ConnectionProvider conn) {
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - getConvertedAmount no client nor org");
+    return getConvertedAmt(Amt, CurFrom_ID, CurTo_ID, ConvDate, RateType, "", "", conn);
+  }
+
+  public static String getConvertedAmt(String Amt, String CurFrom_ID, String CurTo_ID,
+      String ConvDate, String RateType, String client, String org, ConnectionProvider conn) {
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - getConvertedAmount - starting method - Amt : " + Amt
+          + " - CurFrom_ID : " + CurFrom_ID + " - CurTo_ID : " + CurTo_ID + "- ConvDate: "
+          + ConvDate + " - RateType:" + RateType + " - client:" + client + "- org:" + org);
+
+    if (Amt.equals(""))
+      throw new IllegalArgumentException(
+          "AcctServer - getConvertedAmt - required parameter missing - Amt");
+    if (CurFrom_ID.equals(CurTo_ID) || Amt.equals("0"))
+      return Amt;
+    AcctServerData[] data = null;
+    try {
+      if (ConvDate != null && ConvDate.equals(""))
+        ConvDate = DateTimeData.today(conn);
+      // ConvDate IN DATE
+      if (RateType == null || RateType.equals(""))
+        RateType = "S";
+      data = AcctServerData.currencyConvert(conn, Amt, CurFrom_ID, CurTo_ID, ConvDate, RateType,
+          client, org);
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    if (data == null || data.length == 0) {
+      /*
+       * log4j.error("No conversion ratio"); throw new
+       * ServletException("No conversion ratio defined!");
+       */
+      return "";
+    } else {
+      if (log4j.isDebugEnabled())
+        log4j.debug("getConvertedAmount - converted:" + data[0].converted);
+      return data[0].converted;
+    }
+  } // getConvertedAmt
+
+  public static BigDecimal getConvertionRate(String CurFrom_ID, String CurTo_ID, String ConvDate,
+      String RateType, String client, String org, ConnectionProvider conn) {
+    if (CurFrom_ID.equals(CurTo_ID))
+      return BigDecimal.ONE;
+    AcctServerData[] data = null;
+    try {
+      if (ConvDate != null && ConvDate.equals(""))
+        ConvDate = DateTimeData.today(conn);
+      // ConvDate IN DATE
+      if (RateType == null || RateType.equals(""))
+        RateType = "S";
+      data = AcctServerData.currencyConvertionRate(conn, CurFrom_ID, CurTo_ID, ConvDate, RateType,
+          client, org);
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    if (data == null || data.length == 0) {
+      log4j.error("No conversion ratio");
+      return BigDecimal.ZERO;
+    } else {
+      if (log4j.isDebugEnabled())
+        log4j.debug("getConvertionRate - rate:" + data[0].converted);
+      return new BigDecimal(data[0].converted);
+    }
+  } // getConvertedAmt
+
+  /**
+   * Is Period Open
+   * 
+   * @return true if period is open
+   */
+  public boolean isPeriodOpen() {
+    // if (log4j.isDebugEnabled())
+    // log4j.debug(" ***************************** AD_Client_ID - " +
+    // AD_Client_ID + " -- DateAcct - " + DateAcct + " -- DocumentType - " +
+    // DocumentType);
+    setC_Period_ID();
+    boolean open = (!C_Period_ID.equals(""));
+    if (open) {
+      if (log4j.isDebugEnabled())
+        log4j.debug("AcctServer - isPeriodOpen - " + DocumentNo);
+    } else {
+      log4j.warn("AcctServer - isPeriodOpen NO - " + DocumentNo);
+    }
+    return open;
+  } // isPeriodOpen
+
+  /**
+   * Calculate Period ID. Set to -1 if no period open, 0 if no period control
+   */
+  public void setC_Period_ID() {
+    if (C_Period_ID != null)
+      return;
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - setC_Period_ID - AD_Client_ID - " + AD_Client_ID + "--DateAcct - "
+          + DateAcct + "--DocumentType -" + DocumentType);
+    AcctServerData[] data = null;
+    try {
+      if (log4j.isDebugEnabled())
+        log4j.debug("setC_Period_ID - inside try - AD_Client_ID - " + AD_Client_ID
+            + " -- DateAcct - " + DateAcct + " -- DocumentType - " + DocumentType);
+      data = AcctServerData.periodOpen(connectionProvider, AD_Client_ID, DocumentType, AD_Org_ID,
+          DateAcct);
+      C_Period_ID = data[0].period;
+      if (log4j.isDebugEnabled())
+        log4j.debug("AcctServer - setC_Period_ID - " + AD_Client_ID + "/" + DateAcct + "/"
+            + DocumentType + " => " + C_Period_ID);
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+  } // setC_Period_ID
+
+  /**
+   * Matching
+   * 
+   * <pre>
+   *  Derive Invoice-Receipt Match from PO-Invoice and PO-Receipt
+   *  Purchase Order (20)
+   *  - Invoice1 (10)
+   *  - Invoice2 (10)
+   *  - Receipt1 (5)
+   *  - Receipt2 (15)
+   *  (a) Creates Directs
+   *      - Invoice1 - Receipt1 (5)
+   *      - Invoice2 - Receipt2 (10)
+   *  (b) Creates Indirects
+   *      - Invoice1 - Receipt2 (5)
+   *  (Not imlemented)
+   * 
+   * 
+   * </pre>
+   * 
+   * @return number of records created
+   */
+  public int match(VariablesSecureApp vars, ConnectionProvider conn, Connection con) {
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Match--Starting");
+    int counter = 0;
+    // (a) Direct Matches
+    AcctServerData[] data = null;
+    try {
+      data = AcctServerData.selectMatch(conn, AD_Client_ID);
+      for (int i = 0; i < data.length; i++) {
+        BigDecimal qty1 = new BigDecimal(data[i].qty1);
+        BigDecimal qty2 = new BigDecimal(data[i].qty2);
+        BigDecimal Qty = qty1.min(qty2);
+        if (Qty.toString().equals("0"))
+          continue;
+        // if (log4j.isDebugEnabled())
+        // log4j.debug("AcctServer - Match--dateTrx1 :->" + data[i].datetrx1
+        // + "Match--dateTrx2: ->" + data[i].datetrx2);
+        String dateTrx1 = data[i].datetrx1;
+        String dateTrx2 = data[i].datetrx2;
+        String compare = "";
+        try {
+          compare = DateTimeData.compare(conn, dateTrx1, dateTrx2);
+        } catch (ServletException e) {
+          log4j.warn(e);
+          e.printStackTrace();
+        }
+        String DateTrx = dateTrx1;
+        if (compare.equals("-1"))
+          DateTrx = dateTrx2;
+        //
+        String strQty = Qty.toString();
+        String strDateTrx = DateTrx;
+        String AD_Client_ID = data[i].adClientId;
+        String AD_Org_ID = data[i].adOrgId;
+        String C_InvoiceLine_ID = data[i].cInvoicelineId;
+        String M_InOutLine_ID = data[i].mInoutlineId;
+        String M_Product_ID = data[i].mProductId;
+        //
+        if (createMatchInv(AD_Client_ID, AD_Org_ID, M_InOutLine_ID, C_InvoiceLine_ID, M_Product_ID,
+            strDateTrx, strQty, vars, conn, con) == 1)
+          counter++;
+      }
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - Matcher.match - Client_ID=" + AD_Client_ID
+    // + ", Records created=" + counter);
+    return counter;
+  } // match
+
+  /**
+   * Create MatchInv record
+   * 
+   * @param AD_Client_ID
+   *          Client
+   * @param AD_Org_ID
+   *          Org
+   * @param M_InOutLine_ID
+   *          Receipt
+   * @param C_InvoiceLine_ID
+   *          Invoice
+   * @param M_Product_ID
+   *          Product
+   * @param DateTrx
+   *          Date
+   * @param Qty
+   *          Qty
+   * @return true if record created
+   */
+  private int createMatchInv(String AD_Client_ID, String AD_Org_ID, String M_InOutLine_ID,
+      String C_InvoiceLine_ID, String M_Product_ID, String DateTrx, String Qty,
+      VariablesSecureApp vars, ConnectionProvider conn, Connection con) {
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - createMatchInv - InvLine=" +
+    // C_InvoiceLine_ID + ",Rec=" + M_InOutLine_ID + ", Qty=" + Qty + ", " +
+    // DateTrx);
+    int no = 0;
+    try {
+      String M_MatchInv_ID = SequenceIdData.getUUID();
+      //
+      no = AcctServerData.insertMatchInv(con, conn, M_MatchInv_ID, AD_Client_ID, AD_Org_ID,
+          M_InOutLine_ID, C_InvoiceLine_ID, M_Product_ID, DateTrx, Qty);
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    return no;
+  } // createMatchInv
+
+  /**
+   * Get the account for Accounting Schema
+   * 
+   * @param AcctType
+   *          see ACCTTYPE_*
+   * @param as
+   *          accounting schema
+   * @return Account
+   */
+  public final Account getAccount(String AcctType, AcctSchema as, ConnectionProvider conn) {
+    BigDecimal AMT = null;
+    AcctServerData[] data = null;
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("*******************************getAccount 1: AcctType:-->"
+    // + AcctType);
+    try {
+      /** Account Type - Invoice */
+      if (AcctType.equals(ACCTTYPE_Charge)) { // see getChargeAccount in
+        // DocLine
+        // if (log4j.isDebugEnabled())
+        // log4j.debug("AcctServer - *******************amount(AMT);-->"
+        // + getAmount(AMTTYPE_Charge));
+        AMT = new BigDecimal(getAmount(AMTTYPE_Charge));
+        // if (log4j.isDebugEnabled())
+        // log4j.debug("AcctServer - *******************AMT;-->" + AMT);
+        int cmp = AMT.compareTo(BigDecimal.ZERO);
+        // if (log4j.isDebugEnabled())
+        // log4j.debug("AcctServer - ******************* CMP: " + cmp);
+        if (cmp == 0)
+          return null;
+        else if (cmp < 0)
+          data = AcctServerData.selectExpenseAcct(conn, C_Charge_ID, as.getC_AcctSchema_ID());
+        else
+          data = AcctServerData.selectRevenueAcct(conn, C_Charge_ID, as.getC_AcctSchema_ID());
+        // if (log4j.isDebugEnabled())
+        // log4j.debug("AcctServer - *******************************getAccount 2");
+      } else if (AcctType.equals(ACCTTYPE_V_Liability)) {
+        data = AcctServerData.selectLiabilityAcct(conn, C_BPartner_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_V_Liability_Services)) {
+        data = AcctServerData.selectLiabilityServicesAcct(conn, C_BPartner_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_C_Receivable)) {
+        data = AcctServerData.selectReceivableAcct(conn, C_BPartner_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_UnallocatedCash)) {
+        /** Account Type - Payment */
+        data = AcctServerData.selectUnallocatedCashAcct(conn, C_BankAccount_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_BankInTransit)) {
+        data = AcctServerData.selectInTransitAcct(conn, C_BankAccount_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_BankInTransitDefault)) {
+        data = AcctServerData.selectInTransitDefaultAcct(conn, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_ConvertChargeDefaultAmt)) {
+        data = AcctServerData.selectConvertChargeDefaultAmtAcct(conn, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_ConvertGainDefaultAmt)) {
+        data = AcctServerData.selectConvertGainDefaultAmtAcct(conn, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_PaymentSelect)) {
+        data = AcctServerData.selectPaymentSelectAcct(conn, C_BankAccount_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_WriteOffDefault)) {
+        data = AcctServerData.selectWriteOffDefault(conn, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_WriteOffDefault_Revenue)) {
+        data = AcctServerData.selectWriteOffDefaultRevenue(conn, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_DiscountExp)) {
+        /** Account Type - Allocation */
+        data = AcctServerData.selectDiscountExpAcct(conn, C_BPartner_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_DiscountRev)) {
+        data = AcctServerData.selectDiscountRevAcct(conn, C_BPartner_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_WriteOff)) {
+        data = AcctServerData.selectWriteOffAcct(conn, C_BPartner_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_WriteOff_Revenue)) {
+        data = AcctServerData.selectWriteOffAcctRevenue(conn, C_BPartner_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_ConvertChargeLossAmt)) {
+        /** Account Type - Bank Statement */
+        data = AcctServerData.selectConvertChargeLossAmt(conn, C_BankAccount_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_ConvertChargeGainAmt)) {
+        data = AcctServerData.selectConvertChargeGainAmt(conn, C_BankAccount_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_BankAsset)) {
+        data = AcctServerData.selectAssetAcct(conn, C_BankAccount_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_InterestRev)) {
+        data = AcctServerData
+            .selectInterestRevAcct(conn, C_BankAccount_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_InterestExp)) {
+        data = AcctServerData
+            .selectInterestExpAcct(conn, C_BankAccount_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_CashAsset)) {
+        /** Account Type - Cash */
+        data = AcctServerData.selectCBAssetAcct(conn, C_CashBook_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_CashTransfer)) {
+        data = AcctServerData.selectCashTransferAcct(conn, C_CashBook_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_CashExpense)) {
+        data = AcctServerData.selectCBExpenseAcct(conn, C_CashBook_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_CashReceipt)) {
+        data = AcctServerData.selectCBReceiptAcct(conn, C_CashBook_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_CashDifference)) {
+        data = AcctServerData.selectCBDifferencesAcct(conn, C_CashBook_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_InvDifferences)) {
+        /** Inventory Accounts */
+        data = AcctServerData.selectWDifferencesAcct(conn, M_Warehouse_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_NotInvoicedReceipts)) {
+        if (log4j.isDebugEnabled())
+          log4j.debug("AcctServer - getAccount - ACCTYPE_NotInvoicedReceipts - C_BPartner_ID - "
+              + C_BPartner_ID);
+        data = AcctServerData.selectNotInvoicedReceiptsAcct(conn, C_BPartner_ID,
+            as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_ProjectAsset)) {
+        /** Project Accounts */
+        data = AcctServerData.selectPJAssetAcct(conn, C_Project_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_ProjectWIP)) {
+        data = AcctServerData.selectPJWIPAcct(conn, C_Project_ID, as.getC_AcctSchema_ID());
+      } else if (AcctType.equals(ACCTTYPE_PPVOffset)) {
+        /** GL Accounts */
+        data = AcctServerData.selectPPVOffsetAcct(conn, as.getC_AcctSchema_ID());
+      } else {
+        log4j.warn("AcctServer - getAccount - Not found AcctType=" + AcctType);
+        return null;
+      }
+      // if (log4j.isDebugEnabled())
+      // log4j.debug("AcctServer - *******************************getAccount 3");
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    // Get Acct
+    String Account_ID = "";
+    if (data != null && data.length != 0) {
+      Account_ID = data[0].accountId;
+    } else
+      return null;
+    // No account
+    if (Account_ID.equals("")) {
+      log4j.warn("AcctServer - getAccount - NO account Type=" + AcctType + ", Record=" + Record_ID);
+      return null;
+    }
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - *******************************getAccount 4");
+    // Return Account
+    Account acct = null;
+    try {
+      acct = Account.getAccount(conn, Account_ID);
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    }
+    return acct;
+  } // getAccount
+
+  /**
+   * Get the account for Accounting Schema
+   * 
+   * @param cBPartnerId
+   *          business partner id
+   * @param as
+   *          accounting schema
+   * @return Account
+   */
+  public final Account getAccountBPartner(String cBPartnerId, AcctSchema as, boolean isReceipt,
+      boolean isPrepayment, ConnectionProvider conn) throws ServletException {
+    return getAccountBPartner(cBPartnerId, as, isReceipt, isPrepayment, false, conn);
+  }
+
+  /**
+   * Get the account for Accounting Schema
+   * 
+   * @param cBPartnerId
+   *          business partner id
+   * @param as
+   *          accounting schema
+   * @return Account
+   */
+  public final Account getAccountBPartner(String cBPartnerId, AcctSchema as, boolean isReceipt,
+      boolean isPrepayment, boolean isDoubtfuldebt, ConnectionProvider conn)
+      throws ServletException {
+
+    String strValidCombination = "";
+    OBContext.setAdminMode();
+    try {
+      if (isReceipt) {
+        final StringBuilder whereClause = new StringBuilder();
+        if (isDoubtfuldebt) {
+          BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, cBPartnerId);
+          whereClause.append(" as cuscata ");
+          whereClause.append(" where cuscata.businessPartnerCategory.id = :bpCategoryID");
+          whereClause.append(" and cuscata.accountingSchema.id = :acctSchemaID");
+
+          final OBQuery<CategoryAccounts> obqParameters = OBDal.getInstance().createQuery(
+              CategoryAccounts.class, whereClause.toString());
+          obqParameters.setFilterOnReadableClients(false);
+          obqParameters.setFilterOnReadableOrganization(false);
+          obqParameters.setNamedParameter("bpCategoryID", bp.getBusinessPartnerCategory().getId());
+          obqParameters.setNamedParameter("acctSchemaID", as.m_C_AcctSchema_ID);
+          final List<CategoryAccounts> customerAccounts = obqParameters.list();
+          if (customerAccounts != null && customerAccounts.size() > 0
+              && customerAccounts.get(0).getDoubtfulDebtAccount() != null) {
+            strValidCombination = customerAccounts.get(0).getDoubtfulDebtAccount().getId();
+          }
+          if (strValidCombination.equals("")) {
+            Map<String, String> parameters = new HashMap<String, String>();
+            parameters.put("Account", "@DoubtfulDebt@");
+            parameters.put("Entity", bp.getBusinessPartnerCategory().getIdentifier());
+            parameters.put(
+                "AccountingSchema",
+                OBDal
+                    .getInstance()
+                    .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                        as.getC_AcctSchema_ID()).getIdentifier());
+            setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+            throw new IllegalStateException();
+          }
+          return new Account(conn, strValidCombination);
+        }
+
+        whereClause.append(" as cusa ");
+        whereClause.append(" where cusa.businessPartner.id = '" + cBPartnerId + "'");
+        whereClause.append(" and cusa.accountingSchema.id = '" + as.m_C_AcctSchema_ID + "'");
+        whereClause.append(" and (cusa.status is null or cusa.status = 'DE')");
+
+        final OBQuery<CustomerAccounts> obqParameters = OBDal.getInstance().createQuery(
+            CustomerAccounts.class, whereClause.toString());
+        obqParameters.setFilterOnReadableClients(false);
+        obqParameters.setFilterOnReadableOrganization(false);
+        final List<CustomerAccounts> customerAccounts = obqParameters.list();
+        if (customerAccounts != null && customerAccounts.size() > 0
+            && customerAccounts.get(0).getCustomerReceivablesNo() != null && !isPrepayment) {
+          strValidCombination = customerAccounts.get(0).getCustomerReceivablesNo().getId();
+        }
+        if (customerAccounts != null && customerAccounts.size() > 0
+            && customerAccounts.get(0).getCustomerPrepayment() != null && isPrepayment) {
+          strValidCombination = customerAccounts.get(0).getCustomerPrepayment().getId();
+        }
+      } else {
+        final StringBuilder whereClause = new StringBuilder();
+
+        whereClause.append(" as vena ");
+        whereClause.append(" where vena.businessPartner.id = '" + cBPartnerId + "'");
+        whereClause.append(" and vena.accountingSchema.id = '" + as.m_C_AcctSchema_ID + "'");
+        whereClause.append(" and (vena.status is null or vena.status = 'DE')");
+
+        final OBQuery<VendorAccounts> obqParameters = OBDal.getInstance().createQuery(
+            VendorAccounts.class, whereClause.toString());
+        obqParameters.setFilterOnReadableClients(false);
+        obqParameters.setFilterOnReadableOrganization(false);
+        final List<VendorAccounts> vendorAccounts = obqParameters.list();
+        if (vendorAccounts != null && vendorAccounts.size() > 0
+            && vendorAccounts.get(0).getVendorLiability() != null && !isPrepayment) {
+          strValidCombination = vendorAccounts.get(0).getVendorLiability().getId();
+        }
+        if (vendorAccounts != null && vendorAccounts.size() > 0
+            && vendorAccounts.get(0).getVendorPrepayment() != null && isPrepayment) {
+          strValidCombination = vendorAccounts.get(0).getVendorPrepayment().getId();
+        }
+      }
+      if (strValidCombination.equals("")) {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("Account", isReceipt ? (isPrepayment ? "@CustomerPrepayment@"
+            : "@CustomerReceivables@")
+            : (isPrepayment ? "@VendorPrepayment@" : "@VendorLiability@"));
+        BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, cBPartnerId);
+        if (bp != null) {
+          parameters.put("Entity", bp.getIdentifier());
+        }
+        parameters.put(
+            "AccountingSchema",
+            OBDal
+                .getInstance()
+                .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                    as.getC_AcctSchema_ID()).getIdentifier());
+        setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+        throw new IllegalStateException();
+      }
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return new Account(conn, strValidCombination);
+  } // getAccount
+
+  /**
+   * It gets Account to be used to provision for the selected Business Partner
+   * 
+   * @param BPartnerId
+   *          : ID of the Business Partner
+   * @param isExpense
+   *          : Provision Expense Account. If not it applies to Provision Applied account
+   * @param as
+   *          : Accounting Schema
+   * @param conn
+   *          : Connection Provider
+   * @return Account
+   * @throws ServletException
+   */
+  public final Account getAccountBPartnerBadDebt(String BPartnerId, boolean isExpense,
+      AcctSchema as, ConnectionProvider conn) throws ServletException {
+
+    String strValidCombination = "";
+    final StringBuilder whereClause = new StringBuilder();
+    BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, BPartnerId);
+    whereClause.append(" as cuscata ");
+    whereClause.append(" where cuscata.businessPartnerCategory.id = :bpCategoryID");
+    whereClause.append(" and cuscata.accountingSchema.id = :acctSchemaID");
+
+    final OBQuery<CategoryAccounts> obqParameters = OBDal.getInstance().createQuery(
+        CategoryAccounts.class, whereClause.toString());
+    obqParameters.setFilterOnReadableClients(false);
+    obqParameters.setFilterOnReadableOrganization(false);
+    obqParameters.setNamedParameter("bpCategoryID", bp.getBusinessPartnerCategory().getId());
+    obqParameters.setNamedParameter("acctSchemaID", as.m_C_AcctSchema_ID);
+    final List<CategoryAccounts> customerAccounts = obqParameters.list();
+    if (customerAccounts != null && customerAccounts.size() > 0
+        && customerAccounts.get(0).getBadDebtExpenseAccount() != null && isExpense) {
+      strValidCombination = customerAccounts.get(0).getBadDebtExpenseAccount().getId();
+    } else if (customerAccounts != null && customerAccounts.size() > 0
+        && customerAccounts.get(0).getBadDebtRevenueAccount() != null && !isExpense) {
+      strValidCombination = customerAccounts.get(0).getBadDebtRevenueAccount().getId();
+    }
+    if (strValidCombination.equals("")) {
+      Map<String, String> parameters = new HashMap<String, String>();
+      if (isExpense) {
+        parameters.put("Account", "@BadDebtExpenseAccount@");
+      } else {
+        parameters.put("Account", "@BadDebtRevenueAccount@");
+      }
+      parameters.put("Entity", bp.getBusinessPartnerCategory().getIdentifier());
+      parameters.put(
+          "AccountingSchema",
+          OBDal
+              .getInstance()
+              .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                  as.getC_AcctSchema_ID()).getIdentifier());
+      setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+      throw new IllegalStateException();
+    }
+    return new Account(conn, strValidCombination);
+  } // getAccountBPartnerBadDebt
+
+  /**
+   * It gets Account to be used to provision for the selected Business Partner
+   * 
+   * @param BPartnerId
+   *          : ID of the Business Partner
+   * @param as
+   *          : Accounting Schema
+   * @param conn
+   *          : Connection Provider
+   * @return Account
+   * @throws ServletException
+   */
+  public final Account getAccountBPartnerAllowanceForDoubtfulDebt(String BPartnerId, AcctSchema as,
+      ConnectionProvider conn) throws ServletException {
+
+    String strValidCombination = "";
+    final StringBuilder whereClause = new StringBuilder();
+    BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, BPartnerId);
+    whereClause.append(" as cuscata ");
+    whereClause.append(" where cuscata.businessPartnerCategory.id = :bpCategoryID");
+    whereClause.append(" and cuscata.accountingSchema.id = :acctSchemaID");
+
+    final OBQuery<CategoryAccounts> obqParameters = OBDal.getInstance().createQuery(
+        CategoryAccounts.class, whereClause.toString());
+    obqParameters.setFilterOnReadableClients(false);
+    obqParameters.setFilterOnReadableOrganization(false);
+    obqParameters.setNamedParameter("bpCategoryID", bp.getBusinessPartnerCategory().getId());
+    obqParameters.setNamedParameter("acctSchemaID", as.m_C_AcctSchema_ID);
+    final List<CategoryAccounts> customerAccounts = obqParameters.list();
+    if (customerAccounts != null && customerAccounts.size() > 0
+        && customerAccounts.get(0).getAllowanceForDoubtfulDebtAccount() != null) {
+      strValidCombination = customerAccounts.get(0).getAllowanceForDoubtfulDebtAccount().getId();
+    }
+    if (strValidCombination.equals("")) {
+      Map<String, String> parameters = new HashMap<String, String>();
+      parameters.put("Account", "@AllowanceForDoubtfulDebtAccount@");
+      parameters.put("Entity", bp.getBusinessPartnerCategory().getIdentifier());
+      parameters.put(
+          "AccountingSchema",
+          OBDal
+              .getInstance()
+              .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                  as.getC_AcctSchema_ID()).getIdentifier());
+      setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+      throw new IllegalStateException();
+    }
+    return new Account(conn, strValidCombination);
+  }
+
+  /**
+   * Get the account for GL Item
+   */
+  public Account getAccountGLItem(GLItem glItem, AcctSchema as, boolean bIsReceipt,
+      ConnectionProvider conn) throws ServletException {
+    OBContext.setAdminMode();
+    Account account = null;
+    try {
+      OBCriteria<GLItemAccounts> accounts = OBDal.getInstance()
+          .createCriteria(GLItemAccounts.class);
+      accounts.add(Restrictions.eq(GLItemAccounts.PROPERTY_GLITEM, glItem));
+      accounts.add(Restrictions.eq(
+          GLItemAccounts.PROPERTY_ACCOUNTINGSCHEMA,
+          OBDal.getInstance().get(
+              org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+              as.m_C_AcctSchema_ID)));
+      accounts.add(Restrictions.eq(GLItemAccounts.PROPERTY_ACTIVE, true));
+      accounts.setFilterOnReadableClients(false);
+      accounts.setFilterOnReadableOrganization(false);
+      List<GLItemAccounts> accountList = accounts.list();
+      if (accountList == null || accountList.size() == 0)
+        return null;
+      if (bIsReceipt)
+        account = new Account(conn, accountList.get(0).getGlitemCreditAcct().getId());
+      else
+        account = new Account(conn, accountList.get(0).getGlitemDebitAcct().getId());
+    } finally {
+      OBContext.restorePreviousMode();
+      if (account == null) {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("Account", bIsReceipt ? "@GlitemCreditAccount@" : "@GlitemDebitAccount@");
+        if (glItem != null) {
+          parameters.put("Entity", glItem.getIdentifier());
+        }
+        parameters.put(
+            "AccountingSchema",
+            OBDal
+                .getInstance()
+                .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                    as.getC_AcctSchema_ID()).getIdentifier());
+        setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+        throw new IllegalStateException();
+      }
+    }
+    return account;
+  }
+
+  public Account getAccountFee(AcctSchema as, FIN_FinancialAccount finAccount,
+      ConnectionProvider conn) throws ServletException {
+    Account account = null;
+    OBContext.setAdminMode();
+    try {
+      OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria(
+          FIN_FinancialAccountAccounting.class);
+      accounts.add(Restrictions.eq(FIN_FinancialAccountAccounting.PROPERTY_ACCOUNT, finAccount));
+      accounts.add(Restrictions.eq(
+          FIN_FinancialAccountAccounting.PROPERTY_ACCOUNTINGSCHEMA,
+          OBDal.getInstance().get(
+              org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+              as.m_C_AcctSchema_ID)));
+      accounts.add(Restrictions.eq(FIN_FinancialAccountAccounting.PROPERTY_ACTIVE, true));
+      accounts.setFilterOnReadableClients(false);
+      accounts.setFilterOnReadableOrganization(false);
+      List<FIN_FinancialAccountAccounting> accountList = accounts.list();
+      if (accountList == null || accountList.size() == 0)
+        return account;
+      account = new Account(conn, accountList.get(0).getFINBankfeeAcct().getId());
+    } finally {
+      OBContext.restorePreviousMode();
+      if (account == null) {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("Account", "@BankfeeAccount@");
+        if (finAccount != null) {
+          parameters.put("Entity", finAccount.getIdentifier());
+        }
+        parameters.put(
+            "AccountingSchema",
+            OBDal
+                .getInstance()
+                .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                    as.getC_AcctSchema_ID()).getIdentifier());
+        setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+        throw new IllegalStateException();
+      }
+    }
+    return account;
+  }
+
+  /**
+   * Get the account for Financial Account (Uses: INT - In Transit DEP - Deposit CLE - Clearing WIT
+   * - Withdraw)
+   */
+  public Account getAccount(ConnectionProvider conn, String use,
+      FIN_FinancialAccountAccounting financialAccountAccounting, boolean bIsReceipt)
+      throws ServletException {
+    OBContext.setAdminMode();
+    Account account = null;
+    String strvalidCombination = "";
+    try {
+      if ("INT".equals(use))
+        strvalidCombination = bIsReceipt ? financialAccountAccounting
+            .getInTransitPaymentAccountIN().getId() : financialAccountAccounting
+            .getFINOutIntransitAcct().getId();
+      else if ("DEP".equals(use))
+        strvalidCombination = financialAccountAccounting.getDepositAccount().getId();
+      else if ("CLE".equals(use))
+        strvalidCombination = bIsReceipt ? financialAccountAccounting.getClearedPaymentAccount()
+            .getId() : financialAccountAccounting.getClearedPaymentAccountOUT().getId();
+      else if ("WIT".equals(use))
+        strvalidCombination = financialAccountAccounting.getWithdrawalAccount().getId();
+      else
+        return account;
+      account = new Account(conn, strvalidCombination);
+    } finally {
+      OBContext.restorePreviousMode();
+      if (account == null) {
+        Map<String, String> parameters = new HashMap<String, String>();
+        String strAccount = bIsReceipt ? ("INT".equals(use) ? "@InTransitPaymentAccountIN@"
+            : ("DEP".equals(use) ? "@DepositAccount@" : "@ClearedPaymentAccount@")) : ("INT"
+            .equals(use) ? "@InTransitPaymentAccountOUT@"
+            : ("CLE".equals(use) ? "@ClearedPaymentAccountOUT@" : "@WithdrawalAccount@"));
+        parameters.put("Account", strAccount);
+        if (financialAccountAccounting.getAccount() != null) {
+          parameters.put("Entity", financialAccountAccounting.getAccount().getIdentifier());
+        }
+        parameters.put("AccountingSchema", financialAccountAccounting.getAccountingSchema()
+            .getIdentifier());
+        setMessageResult(conn, STATUS_InvalidAccount, "error", parameters);
+        throw new IllegalStateException();
+      }
+    }
+    return account;
+  }
+
+  public FieldProvider[] getObjectFieldProvider() {
+    return objectFieldProvider;
+  }
+
+  public void setObjectFieldProvider(FieldProvider[] fieldProvider) {
+    objectFieldProvider = fieldProvider;
+  }
+
+  public abstract void loadObjectFieldProvider(ConnectionProvider conn, String AD_Client_ID,
+      String Id) throws ServletException;
+
+  public abstract boolean loadDocumentDetails(FieldProvider[] data, ConnectionProvider conn);
+
+  /**
+   * Get Source Currency Balance - subtracts line (and tax) amounts from total - no rounding
+   * 
+   * @return positive amount, if total header is bigger than lines
+   */
+  public abstract BigDecimal getBalance();
+
+  /**
+   * Create Facts (the accounting logic)
+   * 
+   * @param as
+   *          accounting schema
+   * @return Fact
+   */
+  public abstract Fact createFact(AcctSchema as, ConnectionProvider conn, Connection con,
+      VariablesSecureApp vars) throws ServletException;
+
+  public abstract boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId);
+
+  public String getInfo(VariablesSecureApp vars) {
+    return (Utility.messageBD(connectionProvider, "Created", vars.getLanguage()) + "=" + success
+    // + ", " + Utility . messageBD ( this , "Errors" , vars . getLanguage ( ) ) + "=" + errors
+    );
+  } // end of getInfo() method
+
+  /**
+   * @param language
+   * @return a String representing the result of created
+   */
+  public String getInfo(String language) {
+    return (Utility.messageBD(connectionProvider, "Created", language) + "=" + success);
+  }
+
+  public boolean checkDocuments() throws ServletException {
+    return checkDocuments(null, null);
+  }
+
+  public boolean checkDocuments(String dateFrom, String dateTo) throws ServletException {
+    if (m_as.length == 0)
+      return false;
+    AcctServerData[] docTypes = AcctServerData.selectDocTypes(connectionProvider, AD_Table_ID,
+        AD_Client_ID);
+    // if (log4j.isDebugEnabled())
+    // log4j.debug("AcctServer - AcctSchema length-" + (this.m_as).length);
+    final Set<String> orgSet = OBContext.getOBContext()
+        .getOrganizationStructureProvider(AD_Client_ID).getChildTree(AD_Org_ID, true);
+    String strorgs = Utility.getInStrSet(orgSet);
+
+    for (int i = 0; i < docTypes.length; i++) {
+      long init = System.currentTimeMillis();
+      AcctServerData data = AcctServerData.selectDocumentsDates(connectionProvider, strDateColumn,
+          tableName, AD_Client_ID, strorgs, docTypes[i].name, dateFrom, dateTo);
+      log4j.debug("AcctServerData.selectDocumentsDates for: " + docTypes[i].name + " took: "
+          + (System.currentTimeMillis() - init));
+      if (data != null) {
+        if (data.id != null && !data.id.equals("")) {
+          return true;
+        }
+      }
+    }
+    return false;
+  } // end of checkDocuments() method
+
+  @Deprecated
+  /*
+   * Use checkDocuments method instead
+   */
+  public boolean filterDatesCheckDocuments(String dateFrom, String dateTo) throws ServletException {
+    return checkDocuments(dateFrom, dateTo);
+  } // end of filterDatesCheckDocuments() method
+
+  public void setMessageResult(OBError error) {
+    messageResult = error;
+  }
+
+  /*
+   * Sets OBError message for the given status
+   */
+  public void setMessageResult(ConnectionProvider conn, VariablesSecureApp vars, String strStatus,
+      String strMessageType) {
+    setMessageResult(conn, strStatus, strMessageType, null);
+  }
+
+  /*
+   * Sets OBError message for the given status
+   */
+  public void setMessageResult(ConnectionProvider conn, String _strStatus, String strMessageType,
+      Map<String, String> _parameters) {
+    VariablesSecureApp vars = new VariablesSecureApp(RequestContext.get().getRequest());
+    setMessageResult(conn, vars, _strStatus, strMessageType, _parameters);
+  }
+
+  /*
+   * Sets OBError message for the given status
+   */
+  public void setMessageResult(ConnectionProvider conn, VariablesSecureApp vars, String _strStatus,
+      String strMessageType, Map<String, String> _parameters) {
+    String strStatus = StringUtils.isEmpty(_strStatus) ? getStatus() : _strStatus;
+    setStatus(strStatus);
+    String strTitle = "";
+    Map<String, String> parameters = _parameters != null ? _parameters
+        : new HashMap<String, String>();
+    if (messageResult == null)
+      messageResult = new OBError();
+    if (strMessageType == null || strMessageType.equals(""))
+      messageResult.setType("Error");
+    else
+      messageResult.setType(strMessageType);
+    if (strStatus.equals(STATUS_Error))
+      strTitle = "@ProcessRunError@";
+    else if (strStatus.equals(STATUS_DocumentLocked)) {
+      strTitle = "@OtherPostingProcessActive@";
+      messageResult.setType("Warning");
+    } else if (strStatus.equals(STATUS_NotCalculatedCost)) {
+      if (parameters.isEmpty()) {
+        strTitle = "@NotCalculatedCost@";
+      } else {
+        strTitle = "@NotCalculatedCostWithTransaction@";
+      }
+    } else if (strStatus.equals(STATUS_InvalidCost)) {
+      if (parameters.isEmpty()) {
+        strTitle = "@InvalidCost@";
+      } else {
+        strTitle = "@InvalidCostWhichProduct@";
+        // Transalate account name from messages
+        parameters.put("Account",
+            Utility.parseTranslation(conn, vars, vars.getLanguage(), parameters.get("Account")));
+      }
+    } else if (strStatus.equals(STATUS_NoRelatedPO)) {
+      if (parameters.isEmpty()) {
+        strTitle = "@GoodsReceiptTransactionWithNoPO@";
+      } else {
+        strTitle = "@GoodsReceiptTransactionWithNoPOWichProduct@";
+      }
+    } else if (strStatus.equals(STATUS_DocumentDisabled)) {
+      strTitle = "@DocumentDisabled@";
+      messageResult.setType("Warning");
+    } else if (strStatus.equals(STATUS_BackgroundDisabled)) {
+      strTitle = "@BackgroundDisabled@";
+      messageResult.setType("Warning");
+    } else if (strStatus.equals(STATUS_InvalidAccount)) {
+      if (parameters.isEmpty()) {
+        strTitle = "@InvalidAccount@";
+      } else {
+        strTitle = "@InvalidWhichAccount@";
+        // Transalate account name from messages
+        parameters.put("Account",
+            Utility.parseTranslation(conn, vars, vars.getLanguage(), parameters.get("Account")));
+      }
+    } else if (strStatus.equals(STATUS_PeriodClosed)) {
+      strTitle = "@PeriodNotAvailable@";
+    } else if (strStatus.equals(STATUS_NotConvertible)) {
+      strTitle = "@NotConvertible@";
+    } else if (strStatus.equals(STATUS_NotBalanced)) {
+      strTitle = "@NotBalanced@";
+    } else if (strStatus.equals(STATUS_NotPosted)) {
+      strTitle = "@NotPosted@";
+    } else if (strStatus.equals(STATUS_PostPrepared)) {
+      strTitle = "@PostPrepared@";
+    } else if (strStatus.equals(STATUS_Posted)) {
+      strTitle = "@Posted@";
+    } else if (strStatus.equals(STATUS_TableDisabled)) {
+      strTitle = "@TableDisabled@";
+      parameters.put("Table", tableName);
+      messageResult.setType("Warning");
+    } else if (strStatus.equals(STATUS_NoAccountingDate)) {
+      strTitle = "@NoAccountingDate@";
+    }
+    messageResult.setMessage(Utility.parseTranslation(conn, vars, parameters, vars.getLanguage(),
+        Utility.parseTranslation(conn, vars, vars.getLanguage(), strTitle)));
+    if (strMessage != null) {
+      messageResult.setMessage(Utility.parseTranslation(conn, vars, parameters, vars.getLanguage(),
+          Utility.parseTranslation(conn, vars, vars.getLanguage(), strMessage)));
+    }
+  }
+
+  public Map<String, String> getInvalidAccountParameters(String strAccount, String strEntity,
+      String strAccountingSchema) {
+    Map<String, String> parameters = new HashMap<String, String>();
+    parameters.put("Account", strAccount);
+    parameters.put("Entity", strEntity);
+    parameters.put("AccountingSchema", strAccountingSchema);
+    return parameters;
+  }
+
+  public Map<String, String> getInvalidCostParameters(String strProduct, String strDate) {
+    Map<String, String> parameters = new HashMap<String, String>();
+    parameters.put("Product", strProduct);
+    parameters.put("Date", strDate);
+    return parameters;
+  }
+
+  public Map<String, String> getNotCalculatedCostParameters(MaterialTransaction trx) {
+    Map<String, String> parameters = new HashMap<String, String>();
+    parameters.put("trx", trx.getIdentifier());
+    parameters.put("product", trx.getProduct().getIdentifier());
+    return parameters;
+  }
+
+  public OBError getMessageResult() {
+    return messageResult;
+  }
+
+  public String getServletInfo() {
+    return "Servlet for the accounting";
+  } // end of getServletInfo() method
+
+  public String getStatus() {
+    return Status;
+  }
+
+  public void setStatus(String strStatus) {
+    Status = strStatus;
+  }
+
+  public ConnectionProvider getConnectionProvider() {
+    return connectionProvider;
+  }
+
+  public ConversionRateDoc getConversionRateDoc(String table_ID, String record_ID,
+      String curFrom_ID, String curTo_ID) {
+    OBCriteria<ConversionRateDoc> docRateCriteria = OBDal.getInstance().createCriteria(
+        ConversionRateDoc.class);
+    docRateCriteria.setFilterOnReadableClients(false);
+    docRateCriteria.setFilterOnReadableOrganization(false);
+    docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, OBDal.getInstance()
+        .get(Currency.class, curTo_ID)));
+    docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, OBDal.getInstance()
+        .get(Currency.class, curFrom_ID)));
+    if (record_ID != null) {
+      if (table_ID.equals(TABLEID_Invoice)) {
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_INVOICE, OBDal.getInstance()
+            .get(Invoice.class, OBDal.getInstance().get(Invoice.class, record_ID).getId())));
+      } else if (table_ID.equals(TABLEID_Payment)) {
+        docRateCriteria
+            .add(Restrictions.eq(
+                ConversionRateDoc.PROPERTY_PAYMENT,
+                OBDal.getInstance().get(FIN_Payment.class,
+                    OBDal.getInstance().get(FIN_Payment.class, record_ID).getId())));
+      } else if (table_ID.equals(TABLEID_Transaction)) {
+        docRateCriteria.add(Restrictions.eq(
+            ConversionRateDoc.PROPERTY_FINANCIALACCOUNTTRANSACTION,
+            OBDal.getInstance().get(FIN_FinaccTransaction.class,
+                OBDal.getInstance().get(FIN_FinaccTransaction.class, record_ID).getId())));
+      } else {
+        return null;
+      }
+    } else {
+      return null;
+    }
+    List<ConversionRateDoc> conversionRates = docRateCriteria.list();
+    if (!conversionRates.isEmpty()) {
+      return conversionRates.get(0);
+    }
+    return null;
+  }
+
+  // public BigDecimal convertAmount(BigDecimal _amount, boolean isReceipt, String dateAcct,
+  // String conversionDate, String currencyIDFrom, String currencyIDTo, DocLine line,
+  // AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn)
+  // throws ServletException {
+  // BigDecimal amount = _amount;
+  // if (log4j.isDebugEnabled())
+  // log4j.debug("Amount:" + amount + " curr from:" + currencyIDFrom + " Curr to:" + currencyIDTo
+  // + " convDate:" + conversionDate + " DateAcct:" + dateAcct);
+  // if (amount == null || amount.compareTo(BigDecimal.ZERO) == 0) {
+  // return amount;
+  // }
+  // if (currencyIDFrom.equals(currencyIDTo)) {
+  // return amount;
+  // }
+  // MultiCurrency = true;
+  // BigDecimal amt = new BigDecimal(getConvertedAmt(amount.toString(), currencyIDFrom,
+  // currencyIDTo, conversionDate, "", AD_Client_ID, AD_Org_ID, conn));
+  // BigDecimal amtTo = new BigDecimal(getConvertedAmt(amount.toString(), currencyIDFrom,
+  // currencyIDTo, dateAcct, "", AD_Client_ID, AD_Org_ID, conn));
+  // BigDecimal amtDiff = (amtTo).subtract(amt);
+  // if ((isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == 1)
+  // || (!isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == -1)) {
+  // fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn),
+  // currencyIDTo, "", amtDiff.abs().toString(), Fact_Acct_Group_ID, seqNo, DocumentType, conn);
+  // } else {
+  // fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn),
+  // currencyIDTo, amtDiff.abs().toString(), "", Fact_Acct_Group_ID, seqNo, DocumentType, conn);
+  // }
+  // return amt;
+  // }
+
+  public BigDecimal convertAmount(BigDecimal _amount, boolean isReceipt, String dateAcct,
+      String table_ID, String record_ID, String currencyIDFrom, String currencyIDTo, DocLine line,
+      AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn)
+      throws ServletException {
+    return convertAmount(_amount, isReceipt, dateAcct, table_ID, record_ID, currencyIDFrom,
+        currencyIDTo, line, as, fact, Fact_Acct_Group_ID, seqNo, conn, true);
+  }
+
+  /*
+   * Returns an amount without applying currency precision for rounding purposes
+   */
+  public BigDecimal convertAmount(BigDecimal _amount, boolean isReceipt, String dateAcct,
+      String table_ID, String record_ID, String currencyIDFrom, String currencyIDTo, DocLine line,
+      AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn,
+      boolean bookDifferences) throws ServletException {
+    BigDecimal amtDiff = BigDecimal.ZERO;
+    if (_amount == null || _amount.compareTo(BigDecimal.ZERO) == 0) {
+      return _amount;
+    }
+    String conversionDate = dateAcct;
+    String strDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("dateFormat.java");
+    final SimpleDateFormat dateFormat = new SimpleDateFormat(strDateFormat);
+    ConversionRateDoc conversionRateDoc = getConversionRateDoc(table_ID, record_ID, currencyIDFrom,
+        currencyIDTo);
+    BigDecimal amtFrom = BigDecimal.ZERO;
+    BigDecimal amtFromSourcecurrency = BigDecimal.ZERO;
+    BigDecimal amtTo = BigDecimal.ZERO;
+    if (table_ID.equals(TABLEID_Invoice)) {
+      Invoice invoice = OBDal.getInstance().get(Invoice.class, record_ID);
+      conversionDate = dateFormat.format(invoice.getAccountingDate());
+    } else if (table_ID.equals(TABLEID_Payment)) {
+      FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, record_ID);
+      conversionDate = dateFormat.format(payment.getPaymentDate());
+    } else if (table_ID.equals(TABLEID_Transaction)) {
+      FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+          record_ID);
+      conversionDate = dateFormat.format(transaction.getDateAcct());
+    }
+    if (conversionRateDoc != null && record_ID != null) {
+      amtFrom = applyRate(_amount, conversionRateDoc, true);
+    } else {
+      // I try to find a reversal rate for the doc, if exists i apply it reversal as well
+      conversionRateDoc = getConversionRateDoc(table_ID, record_ID, currencyIDTo, currencyIDFrom);
+      if (conversionRateDoc != null) {
+        amtFrom = applyRate(_amount, conversionRateDoc, false);
+      } else {
+        amtFrom = new BigDecimal(getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo,
+            conversionDate, "", AD_Client_ID, AD_Org_ID, conn));
+      }
+    }
+    ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID,
+        currencyIDFrom, currencyIDTo);
+    if (AD_Table_ID.equals(TABLEID_Invoice)) {
+      Invoice invoice = OBDal.getInstance().get(Invoice.class, Record_ID);
+      conversionDate = dateFormat.format(invoice.getAccountingDate());
+    } else if (AD_Table_ID.equals(TABLEID_Payment)) {
+      FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, Record_ID);
+      conversionDate = dateFormat.format(payment.getPaymentDate());
+    } else if (AD_Table_ID.equals(TABLEID_Transaction)
+        || AD_Table_ID.equals(TABLEID_Reconciliation)) {
+      String transactionID = Record_ID;
+      // When TableID= Reconciliation info is loaded from transaction
+      if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+          && line instanceof DocLine_FINReconciliation) {
+        transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+      }
+      FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+          transactionID);
+      conversionDate = dateFormat.format(transaction.getDateAcct());
+      conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
+          currencyIDFrom, currencyIDTo);
+    }
+    if (conversionRateCurrentDoc != null) {
+      amtTo = applyRate(_amount, conversionRateCurrentDoc, true);
+      amtFromSourcecurrency = applyRate(amtFrom, conversionRateCurrentDoc, false);
+    } else {
+      // I try to find a reversal rate for the doc, if exists i apply it reversal as well
+      if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+          && line instanceof DocLine_FINReconciliation) {
+        String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+        conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transactionID,
+            currencyIDTo, currencyIDFrom);
+      } else {
+        conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDTo,
+            currencyIDFrom);
+      }
+      if (conversionRateCurrentDoc != null) {
+        amtTo = applyRate(_amount, conversionRateCurrentDoc, false);
+        amtFromSourcecurrency = applyRate(amtFrom, conversionRateCurrentDoc, true);
+      } else {
+        amtTo = new BigDecimal(getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo,
+            conversionDate, "", AD_Client_ID, AD_Org_ID, conn));
+        amtFromSourcecurrency = amtFrom.multiply(_amount).divide(amtTo, conversionRatePrecision,
+            BigDecimal.ROUND_HALF_EVEN);
+      }
+    }
+    amtDiff = (amtTo).subtract(amtFrom);
+    // Add differences related to Different rates for accounting among currencies
+    // _amount * ((TrxRate *
+    // AccountingRateCurrencyFromCurrencyTo)-AccountingRateCurrencyDocCurrencyTo)
+    amtDiff = amtDiff.add(calculateMultipleRatesDifferences(_amount, currencyIDFrom, currencyIDTo,
+        line, conn));
+    Currency currencyTo = OBDal.getInstance().get(Currency.class, currencyIDTo);
+    amtDiff = amtDiff.setScale(currencyTo.getStandardPrecision().intValue(),
+        BigDecimal.ROUND_HALF_EVEN);
+    if (bookDifferences) {
+      if ((!isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == 1)
+          || (isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == -1)) {
+        fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn),
+            currencyIDTo, "", amtDiff.abs().toString(), Fact_Acct_Group_ID, seqNo, DocumentType,
+            conn);
+      } else if (amtDiff.compareTo(BigDecimal.ZERO) != 0) {
+        fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn),
+            currencyIDTo, amtDiff.abs().toString(), "", Fact_Acct_Group_ID, seqNo, DocumentType,
+            conn);
+      } else {
+        return amtFromSourcecurrency;
+      }
+    }
+    if (log4j.isDebugEnabled())
+      log4j.debug("Amt from: " + amtFrom + "[" + currencyIDFrom + "]" + " Amt to: " + amtTo + "["
+          + currencyIDTo + "] - amtFromSourcecurrency: " + amtFromSourcecurrency);
+    // return value in original currency
+    return amtFromSourcecurrency;
+  }
+
+  @Deprecated
+  public static String getConvertedAmt(String Amt, String CurFrom_ID, String CurTo_ID,
+      String ConvDate, String RateType, String client, String org, String recordId, String docType,
+      ConnectionProvider conn) {
+    boolean useSystemConversionRate = true;
+    if (log4j.isDebugEnabled())
+      log4j.debug("AcctServer - getConvertedAmount - starting method - Amt : " + Amt
+          + " - CurFrom_ID : " + CurFrom_ID + " - CurTo_ID : " + CurTo_ID + "- ConvDate: "
+          + ConvDate + " - RateType:" + RateType + " - client:" + client + "- org:" + org);
+
+    if (Amt.equals(""))
+      throw new IllegalArgumentException(
+          "AcctServer - getConvertedAmt - required parameter missing - Amt");
+    if ((CurFrom_ID.equals(CurTo_ID) && !docType.equals(EXCHANGE_DOCTYPE_Transaction))
+        || Amt.equals("0"))
+      return Amt;
+    AcctServerData[] data = null;
+    OBContext.setAdminMode();
+    try {
+      if (ConvDate != null && ConvDate.equals(""))
+        ConvDate = DateTimeData.today(conn);
+      // ConvDate IN DATE
+      if (RateType == null || RateType.equals(""))
+        RateType = "S";
+      data = AcctServerData.currencyConvert(conn, Amt, CurFrom_ID, CurTo_ID, ConvDate, RateType,
+          client, org);
+      // Search if exists any conversion rate at document level
+
+      OBCriteria<ConversionRateDoc> docRateCriteria = OBDal.getInstance().createCriteria(
+          ConversionRateDoc.class);
+      if (docType.equals(EXCHANGE_DOCTYPE_Invoice) && recordId != null) {
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, OBDal
+            .getInstance().get(Currency.class, CurTo_ID)));
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, OBDal
+            .getInstance().get(Currency.class, CurFrom_ID)));
+        // get reversed invoice id if exist.
+        OBCriteria<ReversedInvoice> reversedCriteria = OBDal.getInstance().createCriteria(
+            ReversedInvoice.class);
+        reversedCriteria.add(Restrictions.eq(ReversedInvoice.PROPERTY_INVOICE, OBDal.getInstance()
+            .get(Invoice.class, recordId)));
+        if (!reversedCriteria.list().isEmpty()) {
+          String strDateFormat;
+          strDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+              .getProperty("dateFormat.java");
+          final SimpleDateFormat dateFormat = new SimpleDateFormat(strDateFormat);
+          ConvDate = dateFormat.format(reversedCriteria.list().get(0).getReversedInvoice()
+              .getAccountingDate());
+          data = AcctServerData.currencyConvert(conn, Amt, CurFrom_ID, CurTo_ID, ConvDate,
+              RateType, client, org);
+          docRateCriteria.add(Restrictions.eq(
+              ConversionRateDoc.PROPERTY_INVOICE,
+              OBDal.getInstance().get(Invoice.class,
+                  reversedCriteria.list().get(0).getReversedInvoice().getId())));
+        } else {
+          docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_INVOICE, OBDal
+              .getInstance().get(Invoice.class, recordId)));
+        }
+        useSystemConversionRate = false;
+      } else if (docType.equals(EXCHANGE_DOCTYPE_Payment)) {
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, OBDal
+            .getInstance().get(Currency.class, CurTo_ID)));
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, OBDal
+            .getInstance().get(Currency.class, CurFrom_ID)));
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_PAYMENT, OBDal.getInstance()
+            .get(FIN_Payment.class, recordId)));
+        useSystemConversionRate = false;
+      } else if (docType.equals(EXCHANGE_DOCTYPE_Transaction)) {
+        APRM_FinaccTransactionV a = OBDal.getInstance()
+            .get(APRM_FinaccTransactionV.class, recordId);
+        if (a.getForeignCurrency() != null) { // && !a.getForeignCurrency().getId().equals(CurTo_ID)
+          String strDateFormat;
+          strDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+              .getProperty("dateFormat.java");
+          final SimpleDateFormat dateFormat = new SimpleDateFormat(strDateFormat);
+          Amt = a.getForeignAmount().toString();
+          data = AcctServerData.currencyConvert(conn, Amt, a.getForeignCurrency().getId(),
+              CurTo_ID, ConvDate, RateType, client, org);
+          docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, OBDal
+              .getInstance().get(Currency.class, CurTo_ID)));
+          docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, OBDal
+              .getInstance().get(Currency.class, a.getForeignCurrency().getId())));
+        } else {
+          docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, OBDal
+              .getInstance().get(Currency.class, CurTo_ID)));
+          docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, OBDal
+              .getInstance().get(Currency.class, CurFrom_ID)));
+        }
+        docRateCriteria.add(Restrictions.eq(ConversionRateDoc.PROPERTY_FINANCIALACCOUNTTRANSACTION,
+            OBDal.getInstance().get(APRM_FinaccTransactionV.class, recordId)));
+        useSystemConversionRate = false;
+      }
+      if (docType.equals(EXCHANGE_DOCTYPE_Invoice) || docType.equals(EXCHANGE_DOCTYPE_Payment)
+          || docType.equals(EXCHANGE_DOCTYPE_Transaction)) {
+        List<ConversionRateDoc> conversionRates = docRateCriteria.list();
+        if (!conversionRates.isEmpty() && !useSystemConversionRate) {
+          BigDecimal Amount = new BigDecimal(Amt);
+          BigDecimal AmountConverted = Amount.multiply(conversionRates.get(0).getRate()).setScale(
+              2, BigDecimal.ROUND_HALF_UP);
+          return AmountConverted.toString();
+        }
+      }
+    } catch (ServletException e) {
+      log4j.warn(e);
+      e.printStackTrace();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    if (data == null || data.length == 0) {
+      /*
+       * log4j.error("No conversion ratio"); throw new
+       * ServletException("No conversion ratio defined!");
+       */
+      return "";
+    } else {
+      if (log4j.isDebugEnabled())
+        log4j.debug("getConvertedAmount - converted:" + data[0].converted);
+      return data[0].converted;
+    }
+  } // getConvertedAmt
+
+  private BigDecimal calculateMultipleRatesDifferences(BigDecimal _amount, String currencyIDFrom,
+      String currencyIDTo, DocLine line, ConnectionProvider conn) {
+    // _amount * ((TrxRate *
+    // AccountingRateCurrencyFromCurrencyTo)-AccountingRateCurrencyDocCurrencyTo)
+    String conversionDate = DateAcct;
+    String strDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("dateFormat.java");
+    final SimpleDateFormat dateFormat = new SimpleDateFormat(strDateFormat);
+    // Calculate accountingRateCurrencyFromCurrencyTo
+    BigDecimal accountingRateCurrencyFromCurrencyTo = BigDecimal.ONE;
+    if (!currencyIDFrom.equals(currencyIDTo)) {
+      ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID,
+          currencyIDFrom, currencyIDTo);
+      if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+          && line instanceof DocLine_FINReconciliation) {
+        String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+        FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+            transactionID);
+        conversionDate = dateFormat.format(transaction.getDateAcct());
+        conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
+            currencyIDFrom, currencyIDTo);
+      }
+      if (conversionRateCurrentDoc != null) {
+        accountingRateCurrencyFromCurrencyTo = conversionRateCurrentDoc.getRate();
+      } else {
+        // I try to find a reversal rate for the doc, if exists i apply it reversal as well
+        if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+            && line instanceof DocLine_FINReconciliation) {
+          String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+          FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+              transactionID);
+          conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
+              currencyIDTo, currencyIDFrom);
+        } else {
+          conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDTo,
+              currencyIDFrom);
+        }
+        if (conversionRateCurrentDoc != null) {
+          accountingRateCurrencyFromCurrencyTo = BigDecimal.ONE.divide(
+              conversionRateCurrentDoc.getRate(), MathContext.DECIMAL64);
+        } else {
+          accountingRateCurrencyFromCurrencyTo = getConvertionRate(currencyIDFrom, currencyIDTo,
+              conversionDate, "", AD_Client_ID, AD_Org_ID, conn);
+        }
+      }
+    }
+
+    // Calculate accountingRateCurrencyFromCurrencyTo
+    BigDecimal accountingRateCurrencyDocCurrencyTo = BigDecimal.ONE;
+    if (!C_Currency_ID.equals(currencyIDTo)) {
+      ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID,
+          C_Currency_ID, currencyIDTo);
+      if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+          && line instanceof DocLine_FINReconciliation) {
+        String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+        FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+            transactionID);
+        conversionDate = dateFormat.format(transaction.getTransactionDate());
+        conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
+            C_Currency_ID, currencyIDTo);
+      }
+      if (conversionRateCurrentDoc != null) {
+        accountingRateCurrencyDocCurrencyTo = conversionRateCurrentDoc.getRate();
+      } else {
+        // I try to find a reversal rate for the doc, if exists i apply it reversal as well
+        if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+            && line instanceof DocLine_FINReconciliation) {
+          String transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+          FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+              transactionID);
+          conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Transaction, transaction.getId(),
+              currencyIDTo, C_Currency_ID);
+        } else {
+          conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID, currencyIDTo,
+              C_Currency_ID);
+        }
+        if (conversionRateCurrentDoc != null) {
+          accountingRateCurrencyDocCurrencyTo = BigDecimal.ONE.divide(
+              conversionRateCurrentDoc.getRate(), MathContext.DECIMAL64);
+        } else {
+          accountingRateCurrencyDocCurrencyTo = getConvertionRate(C_Currency_ID, currencyIDTo,
+              conversionDate, "", AD_Client_ID, AD_Org_ID, conn);
+        }
+      }
+    }
+    // Calculate transaction rate
+    BigDecimal trxRate = BigDecimal.ONE;
+    if (!C_Currency_ID.equals(currencyIDFrom)) {
+      if (AD_Table_ID.equals(TABLEID_Payment)) {
+        FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, Record_ID);
+        trxRate = payment.getFinancialTransactionConvertRate();
+      } else if (AD_Table_ID.equals(TABLEID_Transaction)
+          || AD_Table_ID.equals(TABLEID_Reconciliation)) {
+        String transactionID = Record_ID;
+        // When TableID = Reconciliation info is loaded from transaction
+        if (AD_Table_ID.equals(AcctServer.TABLEID_Reconciliation)
+            && line instanceof DocLine_FINReconciliation) {
+          transactionID = ((DocLine_FINReconciliation) line).getFinFinAccTransactionId();
+        }
+        FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+            transactionID);
+        trxRate = transaction.getForeignConversionRate();
+      }
+    }
+    Currency currencyFrom = OBDal.getInstance().get(Currency.class, currencyIDTo);
+    return _amount.multiply(
+        trxRate.multiply(accountingRateCurrencyDocCurrencyTo).subtract(
+            accountingRateCurrencyFromCurrencyTo)).setScale(
+        currencyFrom.getStandardPrecision().intValue(), BigDecimal.ROUND_HALF_EVEN);
+  }
+
+  /*
+   * Returns an amount without applying currency precision for rounding purposes
+   */
+  public static BigDecimal applyRate(BigDecimal _amount, ConversionRateDoc conversionRateDoc,
+      boolean multiply) {
+    BigDecimal amount = _amount;
+    if (multiply) {
+      return amount.multiply(conversionRateDoc.getRate());
+    } else {
+      return amount.divide(conversionRateDoc.getRate(), 6, BigDecimal.ROUND_HALF_EVEN);
+    }
+  }
+
+  public static int getConversionRatePrecision(VariablesSecureApp vars) {
+    try {
+      String formatOutput = vars.getSessionValue("#FormatOutput|generalQtyEdition", "#0.######");
+      String decimalSeparator = ".";
+      if (formatOutput.contains(decimalSeparator)) {
+        formatOutput = formatOutput.substring(formatOutput.indexOf(decimalSeparator),
+            formatOutput.length());
+        return formatOutput.length() - decimalSeparator.length();
+      } else {
+        return 0;
+      }
+    } catch (Exception e) {
+      log4j.error(e);
+      return 6; // by default precision of 6 decimals as is defaulted in Format.xml
+    }
+  }
+
+  /**
+   * If there is any template active for current document in any accounting schema, it returns true
+   * to skip this step as getDocumentConfirmation can lock template
+   * 
+   * @return
+   */
+  boolean disableDocumentConfirmation() {
+    C_DocType_ID = objectFieldProvider[0].getField("cDoctypeId");
+    if ("".equals(DocumentType)) {
+      loadDocumentType(true);
+    }
+    OBContext.setAdminMode();
+    try {
+      for (int i = 0; i < m_as.length; i++) {
+        StringBuffer whereClause = new StringBuffer();
+        whereClause.append(" as astdt ");
+        whereClause.append(" where astdt.acctschemaTable.accountingSchema.id = '"
+            + m_as[i].m_C_AcctSchema_ID + "'");
+        whereClause.append(" and astdt.acctschemaTable.table.id = '" + AD_Table_ID + "'");
+        if (!"".equals(DocumentType)) {
+          whereClause.append(" and astdt.documentCategory = '" + DocumentType + "'");
+        }
+        final OBQuery<AcctSchemaTableDocType> obqParameters = OBDal.getInstance().createQuery(
+            AcctSchemaTableDocType.class, whereClause.toString());
+        final List<AcctSchemaTableDocType> acctSchemaTableDocTypes = obqParameters.list();
+        if (acctSchemaTableDocTypes != null && acctSchemaTableDocTypes.size() > 0
+            && acctSchemaTableDocTypes.get(0).getCreatefactTemplate() != null) {
+          return true;
+        }
+        final StringBuilder whereClause2 = new StringBuilder();
+        whereClause2.append(" as ast ");
+        whereClause2.append(" where ast.accountingSchema.id = '" + m_as[i].m_C_AcctSchema_ID + "'");
+        whereClause2.append(" and ast.table.id = '" + AD_Table_ID + "'");
+        final OBQuery<AcctSchemaTable> obqParameters2 = OBDal.getInstance().createQuery(
+            AcctSchemaTable.class, whereClause2.toString());
+        final List<AcctSchemaTable> acctSchemaTables = obqParameters2.list();
+        if (acctSchemaTables != null && acctSchemaTables.size() > 0
+            && acctSchemaTables.get(0).getCreatefactTemplate() != null) {
+          return true;
+        }
+      }
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return false;
+  }
+
+  /**
+   * Returns the amount of a Payment Detail. In case the related Payment Schedule Detail was
+   * generated for compensate the difference between an Order and a related Invoice, it merges it's
+   * amount with the next Payment Schedule Detail. Issue 19567:
+   * https://issues.openbravo.com/view.php?id=19567
+   * 
+   * @param paymentDetails
+   *          List of payment Details
+   * @param ps
+   *          Previous Payment Schedule
+   * @param psi
+   *          Invoice Payment Schedule of actual Payment Detail
+   * @param pso
+   *          Order Payment Schedule of actual Payment Detail
+   * @param currentPaymentDetailIndex
+   *          Index
+   */
+  @Deprecated
+  public BigDecimal getPaymentDetailAmount(List<FIN_PaymentDetail> paymentDetails,
+      FIN_PaymentSchedule ps, FIN_PaymentSchedule psi, FIN_PaymentSchedule pso,
+      int currentPaymentDetailIndex) {
+    if (psi == null && pso == null) {
+      return paymentDetails.get(currentPaymentDetailIndex).getAmount();
+    }
+    // If the actual Payment Detail belongs to the same Invoice Payment Schedule as the previous
+    // record, or it has no Order related.
+    if ((psi != null && psi.equals(ps)) || pso == null) {
+      FIN_PaymentScheduleDetail psdNext = (currentPaymentDetailIndex == paymentDetails.size() - 1) ? null
+          : paymentDetails.get(currentPaymentDetailIndex + 1).getFINPaymentScheduleDetailList()
+              .get(0);
+      FIN_PaymentScheduleDetail psdPrevious = (currentPaymentDetailIndex == 0) ? null
+          : paymentDetails.get(currentPaymentDetailIndex - 1).getFINPaymentScheduleDetailList()
+              .get(0);
+      // If it has no Order related, and the next record belongs to the same Invoice Payment
+      // Schedule and the next record has an Order related.
+      if (pso == null && psdNext != null && psdNext.getInvoicePaymentSchedule() == psi
+          && psdNext.getOrderPaymentSchedule() != null) {
+        return null;
+        // If the previous record belongs to the same Invoice Payment Schedule and the previous
+        // record has no Order related.
+      } else if (psdPrevious != null && psdPrevious.getInvoicePaymentSchedule() == psi
+          && psdPrevious.getOrderPaymentSchedule() == null) {
+        return paymentDetails.get(currentPaymentDetailIndex).getAmount()
+            .add(paymentDetails.get(currentPaymentDetailIndex - 1).getAmount());
+      } else {
+        return paymentDetails.get(currentPaymentDetailIndex).getAmount();
+      }
+    } else {
+      return paymentDetails.get(currentPaymentDetailIndex).getAmount();
+    }
+  }
+
+  /**
+   * Returns the writeoff and the amount of a Payment Detail. In case the related Payment Schedule
+   * Detail was generated for compensate the difference between an Order and a related Invoice, it
+   * merges it's amount with the next Payment Schedule Detail. Issue 19567:
+   * https://issues.openbravo.com/view.php?id=19567
+   * 
+   * @param paymentDetails
+   *          List of payment Details
+   * @param ps
+   *          Previous Payment Schedule
+   * @param psi
+   *          Invoice Payment Schedule of actual Payment Detail
+   * @param pso
+   *          Order Payment Schedule of actual Payment Detail
+   * @param currentPaymentDetailIndex
+   *          Index
+   */
+  public HashMap<String, BigDecimal> getPaymentDetailWriteOffAndAmount(
+      List<FIN_PaymentDetail> paymentDetails, FIN_PaymentSchedule ps, FIN_PaymentSchedule psi,
+      FIN_PaymentSchedule pso, int currentPaymentDetailIndex) {
+
+    HashMap<String, BigDecimal> amountAndWriteOff = new HashMap<String, BigDecimal>();
+
+    // Default return values
+    amountAndWriteOff.put("amount", paymentDetails.get(currentPaymentDetailIndex).getAmount());
+    amountAndWriteOff.put("writeoff", paymentDetails.get(currentPaymentDetailIndex)
+        .getWriteoffAmount());
+
+    // If the Payment Detail has either an Invoice or an Order associated to it
+    if (psi != null || pso != null) {
+      // If the Payment Detail has no Order associated to it, or it has an Invoice associated and is
+      // the same one as the previous Payment Detail
+      if ((psi != null && psi.equals(ps)) || pso == null) {
+        FIN_PaymentScheduleDetail psdNext = (currentPaymentDetailIndex == paymentDetails.size() - 1) ? null
+            : paymentDetails.get(currentPaymentDetailIndex + 1).getFINPaymentScheduleDetailList()
+                .get(0);
+        FIN_PaymentScheduleDetail psdPrevious = (currentPaymentDetailIndex == 0) ? null
+            : paymentDetails.get(currentPaymentDetailIndex - 1).getFINPaymentScheduleDetailList()
+                .get(0);
+        // If the Payment Detail has no Order associated, and the next Payment Detail belongs to the
+        // same Invoice and it has an Order related, then return null
+        if (pso == null && psdNext != null && psdNext.getInvoicePaymentSchedule() == psi
+            && psdNext.getOrderPaymentSchedule() != null) {
+          amountAndWriteOff.put("amount", null);
+          amountAndWriteOff.put("writeoff", null);
+          // If there is a previous Payment Detail that belongs to the same Invoice and has no Order
+          // related to it, return the sum of amounts.
+        } else if (psdPrevious != null && psdPrevious.getInvoicePaymentSchedule() == psi
+            && psdPrevious.getOrderPaymentSchedule() == null) {
+          amountAndWriteOff.put("amount", paymentDetails.get(currentPaymentDetailIndex).getAmount()
+              .add(paymentDetails.get(currentPaymentDetailIndex - 1).getAmount()));
+          amountAndWriteOff.put(
+              "writeoff",
+              paymentDetails.get(currentPaymentDetailIndex).getWriteoffAmount()
+                  .add(paymentDetails.get(currentPaymentDetailIndex - 1).getWriteoffAmount()));
+        }
+      }
+    }
+
+    return amountAndWriteOff;
+
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInternalConsumption.java	Tue Aug 19 12:17:48 2014 +0200
@@ -0,0 +1,310 @@
+/*
+ ******************************************************************************
+ * The contents of this file are subject to the   Compiere License  Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * You may obtain a copy of the License at http://www.compiere.org/license.html
+ * Software distributed under the License is distributed on an  "AS IS"  basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ * The Original Code is                  Compiere  ERP & CRM  Business Solution
+ * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
+ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
+ * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
+ * Contributor(s): Openbravo SLU
+ * Contributions are Copyright (C) 2014 Openbravo S.L.U.
+ ******************************************************************************
+ */
+package org.openbravo.erpCommon.ad_forms;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+
+import org.apache.log4j.Logger;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.costing.CostingStatus;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.SequenceIdData;
+import org.openbravo.financial.FinancialUtils;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.materialmgmt.transaction.InternalConsumptionLine;
+
+public class DocInternalConsumption extends AcctServer {
+  private static final long serialVersionUID = 1L;
+  private static Logger log4jDocInternalConsumption = Logger
+      .getLogger(DocInternalConsumption.class);
+
+  private String SeqNo = "0";
+
+  /**
+   * Constructor
+   * 
+   * @param AD_Client_ID
+   *          client
+   */
+  public DocInternalConsumption(String AD_Client_ID, String AD_Org_ID,
+      ConnectionProvider connectionProvider) {
+    super(AD_Client_ID, AD_Org_ID, connectionProvider);
+  }
+
+  @Override
+  public void loadObjectFieldProvider(ConnectionProvider conn, String AD_Client_ID, String Id)
+      throws ServletException {
+    setObjectFieldProvider(DocInternalConsumptionData.select(conn, AD_Client_ID, Id));
+  }
+
+  /**
+   * Load Document Details
+   * 
+   * @return true if loadDocumentType was set
+   */
+  @Override
+  public boolean loadDocumentDetails(FieldProvider[] data, ConnectionProvider conn) {
+    DocumentType = AcctServer.DOCTYPE_MatInternalConsumption;
+    C_Currency_ID = NO_CURRENCY;
+    DateDoc = data[0].getField("MovementDate");
+    loadDocumentType(); // lines require doc type
+    // Contained Objects
+    p_lines = loadLines(conn);
+    log4jDocInternalConsumption.debug("Lines=" + p_lines.length);
+    return true;
+  } // loadDocumentDetails
+
+  /**
+   * Load Internal Consumption Line
+   * 
+   * @return DocLine Array
+   */
+  private DocLine[] loadLines(ConnectionProvider conn) {
+    ArrayList<Object> list = new ArrayList<Object>();
+    DocLineInternalConsumptionData[] data = null;
+    OBContext.setAdminMode(false);
+    try {
+      data = DocLineInternalConsumptionData.select(conn, Record_ID);
+      for (int i = 0; data != null && i < data.length; i++) {
+        String Line_ID = data[i].getField("mInternalConsumptionlineId");
+        DocLine_Material docLine = new DocLine_Material(DocumentType, Record_ID, Line_ID);
+        docLine.loadAttributes(data[i], this);
+        log4jDocInternalConsumption.debug("MovementQty = " + data[i].getField("movementqty"));
+        BigDecimal MovementQty = new BigDecimal(data[i].getField("movementqty"));
+        docLine.setQty(MovementQty.toString(), conn);
+        docLine.m_M_Locator_ID = data[i].getField("mLocatorId");
+
+        // Get related M_Transaction_ID
+        InternalConsumptionLine intConsLine = OBDal.getInstance().get(
+            InternalConsumptionLine.class, Line_ID);
+        if (intConsLine.getMaterialMgmtMaterialTransactionList().size() > 0) {
+          docLine.setTransaction(intConsLine.getMaterialMgmtMaterialTransactionList().get(0));
+        }
+        DocInternalConsumptionData[] data1 = null;
+        try {
+          data1 = DocInternalConsumptionData.selectWarehouse(conn, docLine.m_M_Locator_ID);
+        } catch (ServletException e) {
+          log4jDocInternalConsumption.warn(e);
+        }
+        if (data1 != null && data1.length > 0)
+          this.M_Warehouse_ID = data1[0].mWarehouseId;
+        list.add(docLine);
+      }
+    } catch (ServletException e) {
+      log4jDocInternalConsumption.warn(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    // Return Array
+    DocLine[] dl = new DocLine[list.size()];
+    list.toArray(dl);
+    return dl;
+  } // loadLines
+
+  /**
+   * Get Balance
+   * 
+   * @return Zero (always balanced)
+   */
+  @Override
+  public BigDecimal getBalance() {
+    BigDecimal retValue = ZERO;
+    return retValue;
+  } // getBalance
+
+  /**
+   * Create Facts (the accounting logic) for MIC.
+   * 
+   * <pre>
+   *  Internal Consumption
+   *      CoGS            DR      
+   *      Inventory               CR
+   * </pre>
+   * 
+   * @param as
+   *          account schema
+   * @return Fact
+   */
+  @Override
+  public Fact createFact(AcctSchema as, ConnectionProvider conn, Connection con,
+      VariablesSecureApp vars) throws ServletException {
+    // Select specific definition
+    String strClassname = AcctServerData
+        .selectTemplateDoc(conn, as.m_C_AcctSchema_ID, DocumentType);
+    if (strClassname.equals(""))
+      strClassname = AcctServerData.selectTemplate(conn, as.m_C_AcctSchema_ID, AD_Table_ID);
+    if (!strClassname.equals("")) {
+      try {
+        DocInternalConsumptionTemplate newTemplate = (DocInternalConsumptionTemplate) Class
+            .forName(strClassname).newInstance();
+        return newTemplate.createFact(this, as, conn, con, vars);
+      } catch (Exception e) {
+        log4j.error("Error while creating new instance for DocInternalConsumptionTemplate - " + e);
+      }
+    }
+
+    C_Currency_ID = as.getC_Currency_ID();
+    // create Fact Header
+    Fact fact = new Fact(this, as, Fact.POST_Actual);
+    String Fact_Acct_Group_ID = SequenceIdData.getUUID();
+    // Line pointers
+    FactLine dr = null;
+    FactLine cr = null;
+    log4jDocInternalConsumption.debug("CreateFact - before loop");
+    for (int i = 0; i < p_lines.length; i++) {
+      DocLine_Material line = (DocLine_Material) p_lines[i];
+
+      Currency costCurrency = FinancialUtils.getLegalEntityCurrency(OBDal.getInstance().get(
+          Organization.class, line.m_AD_Org_ID));
+      if (!CostingStatus.getInstance().isMigrated()) {
+        costCurrency = OBDal.getInstance().get(Client.class, AD_Client_ID).getCurrency();
+      } else if (line.transaction != null && line.transaction.getCurrency() != null) {
+        costCurrency = line.transaction.getCurrency();
+      }
+      if (CostingStatus.getInstance().isMigrated() && line.transaction != null
+          && !line.transaction.isCostCalculated()) {
+        Map<String, String> parameters = getNotCalculatedCostParameters(line.transaction);
+        setMessageResult(conn, STATUS_NotCalculatedCost, "error", parameters);
+        throw new IllegalStateException();
+      }
+      String costs = line.getProductCosts(DateAcct, as, conn, con);
+      log4jDocInternalConsumption.debug("CreateFact - before DR - Costs: " + costs);
+      BigDecimal b_Costs = new BigDecimal(costs);
+      String strCosts = b_Costs.toString();
+      Account cogsAccount = line.getAccount(ProductInfo.ACCTTYPE_P_Cogs, as, conn);
+      Product product = OBDal.getInstance().get(Product.class, line.m_M_Product_ID);
+      if (cogsAccount == null) {
+        org.openbravo.model.financialmgmt.accounting.coa.AcctSchema schema = OBDal.getInstance()
+            .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                as.m_C_AcctSchema_ID);
+        log4j.error("No Account COGS for product: " + product.getName() + " in accounting schema: "
+            + schema.getName());
+      }
+      Account assetAccount = line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn);
+      if (assetAccount == null) {
+        org.openbravo.model.financialmgmt.accounting.coa.AcctSchema schema = OBDal.getInstance()
+            .get(org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+                as.m_C_AcctSchema_ID);
+        log4j.error("No Account Asset for product: " + product.getName()
+            + " in accounting schema: " + schema.getName());
+      }
+      if (b_Costs.compareTo(BigDecimal.ZERO) == 0 && !CostingStatus.getInstance().isMigrated()
+          && DocInOutData.existsCost(conn, DateAcct, line.m_M_Product_ID).equals("0")) {
+        Map<String, String> parameters = getInvalidCostParameters(
+            OBDal.getInstance().get(Product.class, line.m_M_Product_ID).getIdentifier(), DateAcct);
+        setMessageResult(conn, STATUS_InvalidCost, "error", parameters);
+        throw new IllegalStateException();
+      }
+      dr = fact.createLine(line, cogsAccount, costCurrency.getId(), strCosts, "",
+          Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
+      if (dr != null) {
+        dr.setM_Locator_ID(line.m_M_Locator_ID);
+        dr.setLocationFromLocator(line.m_M_Locator_ID, true, conn); // from
+        dr.setLocationFromBPartner(C_BPartner_Location_ID, false, conn); // to
+      }
+      log4jDocInternalConsumption.debug("CreateFact - before CR");
+      cr = fact.createLine(line, assetAccount, costCurrency.getId(), "", strCosts,
+          Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
+      if (cr != null) {
+        cr.setM_Locator_ID(line.m_M_Locator_ID);
+        cr.setLocationFromLocator(line.m_M_Locator_ID, true, conn); // from
+        cr.setLocationFromBPartner(C_BPartner_Location_ID, false, conn); // to
+      }
+    }
+    log4jDocInternalConsumption.debug("CreateFact - after loop");
+    SeqNo = "0";
+    return fact;
+  } // createFact
+
+  /**
+   * Get Document Confirmation
+   * 
+   * not used
+   */
+  @Override
+  public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) {
+    return true;
+  }
+
+  /**
+   * @return the log4jDocInternalConsumption
+   */
+  public static Logger getLog4jDocInternalConsumption() {
+    return log4jDocInternalConsumption;
+  }
+
+  /**
+   * @param log4jDocInternalConsumption
+   *          the log4jDocInternalConsumption to set
+   */
+  public static void setLog4jDocInternalConsumption(Logger log4jDocInternalConsumption) {
+    DocInternalConsumption.log4jDocInternalConsumption = log4jDocInternalConsumption;
+  }
+
+  /**
+   * @return the seqNo
+   */
+  public String getSeqNo() {
+    return SeqNo;
+  }
+
+  /**
+   * @param seqNo
+   *          the seqNo to set
+   */
+  public void setSeqNo(String seqNo) {
+    SeqNo = seqNo;
+  }
+
+  /**
+   * @param oldSeqNo
+   *          old sequence number
+   * @return the next sequence number
+   */
+  public String nextSeqNo(String oldSeqNo) {
+    log4jDocInternalConsumption.debug("DocInternalConsumption - oldSeqNo = " + oldSeqNo);
+    BigDecimal seqNo = new BigDecimal(oldSeqNo);
+    SeqNo = (seqNo.add(new BigDecimal("10"))).toString();
+    log4jDocInternalConsumption.debug("DocInternalConsumption - nextSeqNo = " + SeqNo);
+    return SeqNo;
+  }
+
+  /**
+   * @return the serialVersionUID
+   */
+  public static long getSerialVersionUID() {
+    return serialVersionUID;
+  }
+
+  /**
+   * @return the servlet information
+   */
+  public String getServletInfo() {
+    return "Servlet for the internal consumption accounting";
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInternalConsumptionTemplate.java	Tue Aug 19 12:17:48 2014 +0200
@@ -0,0 +1,59 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2014 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.erpCommon.ad_forms;
+
+import java.sql.Connection;
+
+import javax.servlet.ServletException;
+
+import org.apache.log4j.Logger;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.database.ConnectionProvider;
+
+public abstract class DocInternalConsumptionTemplate {
+  private static final long serialVersionUID = 1L;
+  static Logger log4jDocInternalConsumption = Logger.getLogger(DocInternalConsumption.class);
+
+  /**
+   * Constructor
+   * 
+   */
+  public DocInternalConsumptionTemplate() {
+  }
+
+  /**
+   * Create Facts (the accounting logic) for MIC.
+   * 
+   * <pre>
+   *  Internal Consumption
+   *      CoGS            DR      
+   *      Inventory               CR
+   * </pre>
+   * 
+   * @param as
+   *          account schema
+   * @return Fact
+   */
+  public abstract Fact createFact(DocInternalConsumption docInternalConsumption, AcctSchema as,
+      ConnectionProvider conn, Connection con, VariablesSecureApp vars) throws ServletException;
+
+  public String getServletInfo() {
+    return "Servlet for the accounting";
+  } // end of getServletInfo() method
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInternalConsumption_data.xsql	Tue Aug 19 12:17:48 2014 +0200
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ******************************************************************************
+ * The contents of this file are subject to the   Compiere License  Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * You may obtain a copy of the License at http://www.compiere.org/license.html
+ * Software distributed under the License is distributed on an  "AS IS"  basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ * The Original Code is                  Compiere  ERP & CRM  Business Solution
+ * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
+ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
+ * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
+ * Contributor(s): Openbravo SLU
+ * Contributions are Copyright (C) 2014 Openbravo S.L.U.
+ ******************************************************************************
+-->
+
+
+
+<SqlClass name="DocInternalConsumptionData" package="org.openbravo.erpCommon.ad_forms">
+  <SqlClassComment></SqlClassComment>
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT I.AD_CLIENT_ID, I.AD_ORG_ID, I.AD_ORGTRX_ID, I.C_PROJECT_ID, I.C_CAMPAIGN_ID,
+        I.C_ACTIVITY_ID, I.USER1_ID, I.USER2_ID, I.C_COSTCENTER_ID, I.NAME, I.POSTED,
+        I.MOVEMENTDATE, '' AS M_WAREHOUSE_ID
+        FROM M_INTERNAL_CONSUMPTION I
+        WHERE AD_CLIENT_ID=?
+        AND M_INTERNAL_CONSUMPTION_ID=?
+     ]]>
+     </Sql>
+     <Parameter name="client"/>
+     <Parameter name="id"/>
+   </SqlMethod>
+  <SqlMethod name="selectWarehouse" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT M_WAREHOUSE_ID FROM M_LOCATOR
+        WHERE M_LOCATOR_ID = ?
+     ]]>
+     </Sql>
+     <Parameter name="M_LOCATOR_ID"/>
+   </SqlMethod>
+</SqlClass>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLineInternalConsumption_data.xsql	Tue Aug 19 12:17:48 2014 +0200
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ******************************************************************************
+ * The contents of this file are subject to the   Compiere License  Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * You may obtain a copy of the License at http://www.compiere.org/license.html
+ * Software distributed under the License is distributed on an  "AS IS"  basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ * The Original Code is                  Compiere  ERP & CRM  Business Solution
+ * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
+ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
+ * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
+ * Contributor(s): Openbravo SLU
+ * Contributions are Copyright (C) 2014 Openbravo S.L.U.
+ ******************************************************************************
+-->
+
+
+
+
+
+<SqlClass name="DocLineInternalConsumptionData" package="org.openbravo.erpCommon.ad_forms">
+  <SqlClassComment></SqlClassComment>
+  <SqlMethod name="select" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+      SELECT IL.AD_ORG_ID, IL.M_PRODUCT_ID, IL.LINE, IL.DESCRIPTION,
+      IL.C_UOM_ID, IL.M_INTERNAL_CONSUMPTIONLINE_ID, IL.MOVEMENTQTY, IL.M_LOCATOR_ID
+      FROM M_Internal_ConsumptionLine IL WHERE M_Internal_Consumption_ID=? ORDER BY Line
+     ]]>
+     </Sql>
+     <Parameter name="M_Internal_Consumption_ID"/>
+   </SqlMethod>
+  </SqlClass>
\ No newline at end of file