Merge changes from PI
authorIván Perdomo <ivan.perdomo@openbravo.com>
Tue, 22 Sep 2009 10:35:44 +0200
changeset 5063 c2c265800af4
parent 5062 69e4e32e3412 (current diff)
parent 4998 f99d3ab60d7d (diff)
child 5064 08c0a5cb2c96
Merge changes from PI
src-db/database/sourcedata/AD_TEXTINTERFACES.xml
src/org/openbravo/base/secureApp/HttpSecureAppServlet.java
src/org/openbravo/base/secureApp/LoginHandler.java
Binary file src-db/database/lib/dbsourcemanager.jar has changed
--- a/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Tue Sep 22 10:35:44 2009 +0200
@@ -26957,6 +26957,17 @@
 <!--8AF50B04D98B452CB02DCE3B554A1F59-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--8AF50B04D98B452CB02DCE3B554A1F59--></AD_TEXTINTERFACES>
 
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21--><AD_TEXTINTERFACES>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <AD_TEXTINTERFACES_ID><![CDATA[92F888AFA3FD4E8DBA0DAA44B6CC6A21]]></AD_TEXTINTERFACES_ID>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <TEXT><![CDATA[Invoice Doc No.]]></TEXT>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <FILENAME><![CDATA[/org/openbravo/erpCommon/ad_reports/ReportInvoiceCustomerJR.jrxml]]></FILENAME>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--92F888AFA3FD4E8DBA0DAA44B6CC6A21--></AD_TEXTINTERFACES>
+
 <!--9335C6A4F2B811DD9667001D09C4A2FE--><AD_TEXTINTERFACES>
 <!--9335C6A4F2B811DD9667001D09C4A2FE-->  <AD_TEXTINTERFACES_ID><![CDATA[9335C6A4F2B811DD9667001D09C4A2FE]]></AD_TEXTINTERFACES_ID>
 <!--9335C6A4F2B811DD9667001D09C4A2FE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/referencedData/AD_PROCESS_REQUEST.xml	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-db/database/sourcedata/referencedData/AD_PROCESS_REQUEST.xml	Tue Sep 22 10:35:44 2009 +0200
@@ -13,6 +13,19 @@
 <!--1024628DE367478495D41B18E4B162EA-->  <CHANNEL><![CDATA[Direct]]></CHANNEL>
 <!--1024628DE367478495D41B18E4B162EA--></AD_PROCESS_REQUEST>
 
+<!--13AD973AEB6440AAB3DC5933BF826E5F--><AD_PROCESS_REQUEST>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <AD_PROCESS_REQUEST_ID><![CDATA[13AD973AEB6440AAB3DC5933BF826E5F]]></AD_PROCESS_REQUEST_ID>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <AD_PROCESS_ID><![CDATA[172]]></AD_PROCESS_ID>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <AD_USER_ID><![CDATA[100]]></AD_USER_ID>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <ISROLESECURITY><![CDATA[Y]]></ISROLESECURITY>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <OB_CONTEXT><![CDATA[{"org.openbravo.scheduling.ProcessContext":{"user":100,"role":0,"language":"en_US","theme":"ltr\/Default","client":0,"organization":0,"warehouse":"","command":"SAVE_BUTTONActionButton172","userClient":"'0'","userOrganization":"'0'","dbSessionID":"1E36BC940B2D49E696730F9071E58484","javaDateFormat":"dd-MM-yyyy","javaDateTimeFormat":"dd-MM-yyyy HH:mm:ss","jsDateFormat":"%d-%m-%Y","sqlDateFormat":"DD-MM-YYYY","accessLevel":4,"roleSecurity":true}}]]></OB_CONTEXT>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <STATUS><![CDATA[COM]]></STATUS>
+<!--13AD973AEB6440AAB3DC5933BF826E5F-->  <CHANNEL><![CDATA[Direct]]></CHANNEL>
+<!--13AD973AEB6440AAB3DC5933BF826E5F--></AD_PROCESS_REQUEST>
+
 <!--212D8CA4F6C840D3A4750F2967D905D7--><AD_PROCESS_REQUEST>
 <!--212D8CA4F6C840D3A4750F2967D905D7-->  <AD_PROCESS_REQUEST_ID><![CDATA[212D8CA4F6C840D3A4750F2967D905D7]]></AD_PROCESS_REQUEST_ID>
 <!--212D8CA4F6C840D3A4750F2967D905D7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -26,6 +39,19 @@
 <!--212D8CA4F6C840D3A4750F2967D905D7-->  <CHANNEL><![CDATA[Direct]]></CHANNEL>
 <!--212D8CA4F6C840D3A4750F2967D905D7--></AD_PROCESS_REQUEST>
 
+<!--6A54A4211F864F3C812122DF029199B3--><AD_PROCESS_REQUEST>
+<!--6A54A4211F864F3C812122DF029199B3-->  <AD_PROCESS_REQUEST_ID><![CDATA[6A54A4211F864F3C812122DF029199B3]]></AD_PROCESS_REQUEST_ID>
+<!--6A54A4211F864F3C812122DF029199B3-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6A54A4211F864F3C812122DF029199B3-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6A54A4211F864F3C812122DF029199B3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6A54A4211F864F3C812122DF029199B3-->  <AD_PROCESS_ID><![CDATA[173]]></AD_PROCESS_ID>
+<!--6A54A4211F864F3C812122DF029199B3-->  <AD_USER_ID><![CDATA[100]]></AD_USER_ID>
+<!--6A54A4211F864F3C812122DF029199B3-->  <ISROLESECURITY><![CDATA[Y]]></ISROLESECURITY>
+<!--6A54A4211F864F3C812122DF029199B3-->  <OB_CONTEXT><![CDATA[{"org.openbravo.scheduling.ProcessContext":{"user":100,"role":0,"language":"en_US","theme":"ltr\/Default","client":0,"organization":0,"warehouse":"","command":"SAVE_BUTTONImportTable173","userClient":"'0'","userOrganization":"'0'","dbSessionID":"1E36BC940B2D49E696730F9071E58484","javaDateFormat":"dd-MM-yyyy","javaDateTimeFormat":"dd-MM-yyyy HH:mm:ss","jsDateFormat":"%d-%m-%Y","sqlDateFormat":"DD-MM-YYYY","accessLevel":4,"roleSecurity":true}}]]></OB_CONTEXT>
+<!--6A54A4211F864F3C812122DF029199B3-->  <STATUS><![CDATA[COM]]></STATUS>
+<!--6A54A4211F864F3C812122DF029199B3-->  <CHANNEL><![CDATA[Direct]]></CHANNEL>
+<!--6A54A4211F864F3C812122DF029199B3--></AD_PROCESS_REQUEST>
+
 <!--81436AE6D9694392A2069D91BF348F26--><AD_PROCESS_REQUEST>
 <!--81436AE6D9694392A2069D91BF348F26-->  <AD_PROCESS_REQUEST_ID><![CDATA[81436AE6D9694392A2069D91BF348F26]]></AD_PROCESS_REQUEST_ID>
 <!--81436AE6D9694392A2069D91BF348F26-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -39,6 +65,19 @@
 <!--81436AE6D9694392A2069D91BF348F26-->  <CHANNEL><![CDATA[Direct]]></CHANNEL>
 <!--81436AE6D9694392A2069D91BF348F26--></AD_PROCESS_REQUEST>
 
+<!--88814B57EFB34E9AAE699CADA395BD1E--><AD_PROCESS_REQUEST>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <AD_PROCESS_REQUEST_ID><![CDATA[88814B57EFB34E9AAE699CADA395BD1E]]></AD_PROCESS_REQUEST_ID>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <AD_PROCESS_ID><![CDATA[173]]></AD_PROCESS_ID>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <AD_USER_ID><![CDATA[100]]></AD_USER_ID>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <ISROLESECURITY><![CDATA[Y]]></ISROLESECURITY>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <OB_CONTEXT><![CDATA[{"org.openbravo.scheduling.ProcessContext":{"user":100,"role":0,"language":"en_US","theme":"ltr\/Default","client":0,"organization":0,"warehouse":"","command":"SAVE_BUTTONImportTable173","userClient":"'0'","userOrganization":"'0'","dbSessionID":"1E36BC940B2D49E696730F9071E58484","javaDateFormat":"dd-MM-yyyy","javaDateTimeFormat":"dd-MM-yyyy HH:mm:ss","jsDateFormat":"%d-%m-%Y","sqlDateFormat":"DD-MM-YYYY","accessLevel":4,"roleSecurity":true}}]]></OB_CONTEXT>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <STATUS><![CDATA[COM]]></STATUS>
+<!--88814B57EFB34E9AAE699CADA395BD1E-->  <CHANNEL><![CDATA[Direct]]></CHANNEL>
+<!--88814B57EFB34E9AAE699CADA395BD1E--></AD_PROCESS_REQUEST>
+
 <!--9B2B32C0BAF146F783A50C6F69251BC4--><AD_PROCESS_REQUEST>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <AD_PROCESS_REQUEST_ID><![CDATA[9B2B32C0BAF146F783A50C6F69251BC4]]></AD_PROCESS_REQUEST_ID>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -49,8 +88,8 @@
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <ISROLESECURITY><![CDATA[Y]]></ISROLESECURITY>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <OB_CONTEXT><![CDATA[{"org.openbravo.scheduling.ProcessContext":{"user":100,"role":0,"language":"en_US","theme":"ltr\/Default","client":0,"organization":0,"warehouse":"","command":"DEFAULT","userClient":"","userOrganization":"","dbSessionID":"","javaDateFormat":"","jsDateFormat":"","sqlDateFormat":"","accessLevel":"","roleSecurity":true}}]]></OB_CONTEXT>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <STATUS><![CDATA[SCH]]></STATUS>
-<!--9B2B32C0BAF146F783A50C6F69251BC4-->  <NEXT_FIRE_TIME><![CDATA[2009-07-11 14:20:06.0]]></NEXT_FIRE_TIME>
-<!--9B2B32C0BAF146F783A50C6F69251BC4-->  <PREVIOUS_FIRE_TIME><![CDATA[2009-07-11 14:19:06.0]]></PREVIOUS_FIRE_TIME>
+<!--9B2B32C0BAF146F783A50C6F69251BC4-->  <NEXT_FIRE_TIME><![CDATA[2009-08-25 00:31:49.0]]></NEXT_FIRE_TIME>
+<!--9B2B32C0BAF146F783A50C6F69251BC4-->  <PREVIOUS_FIRE_TIME><![CDATA[2009-08-25 00:30:49.0]]></PREVIOUS_FIRE_TIME>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <CHANNEL><![CDATA[Process Scheduler]]></CHANNEL>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <TIMING_OPTION><![CDATA[S]]></TIMING_OPTION>
 <!--9B2B32C0BAF146F783A50C6F69251BC4-->  <FREQUENCY><![CDATA[2]]></FREQUENCY>
--- a/src-test/org/openbravo/test/AllAntTaskTests.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-test/org/openbravo/test/AllAntTaskTests.java	Tue Sep 22 10:35:44 2009 +0200
@@ -24,6 +24,8 @@
 
 import org.openbravo.test.dal.DalComplexQueryRequisitionTest;
 import org.openbravo.test.dal.DalComplexQueryTestOrderLine;
+import org.openbravo.test.dal.DalConnectionProviderTest;
+import org.openbravo.test.dal.DalCopyTest;
 import org.openbravo.test.dal.DalPerformanceInventoryLineTest;
 import org.openbravo.test.dal.DalPerformanceProductTest;
 import org.openbravo.test.dal.DalQueryTest;
@@ -76,6 +78,8 @@
     suite.addTestSuite(DalPerformanceProductTest.class);
     suite.addTestSuite(DalQueryTest.class);
     suite.addTestSuite(DalTest.class);
+    suite.addTestSuite(DalCopyTest.class);
+    suite.addTestSuite(DalConnectionProviderTest.class);
     suite.addTestSuite(DynamicEntityTest.class);
     suite.addTestSuite(HiddenUpdateTest.class);
     // suite.addTestSuite(HqlTest.class);
--- a/src-test/org/openbravo/test/AllQuickAntTaskTests.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-test/org/openbravo/test/AllQuickAntTaskTests.java	Tue Sep 22 10:35:44 2009 +0200
@@ -22,6 +22,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.openbravo.test.dal.DalConnectionProviderTest;
 import org.openbravo.test.dal.DalTest;
 import org.openbravo.test.dal.OBContextTest;
 import org.openbravo.test.dal.ValidationTest;
@@ -64,6 +65,7 @@
     // suite.addTestSuite(DalPerformanceProductTest.class);
     // suite.addTestSuite(DalQueryTest.class);
     suite.addTestSuite(DalTest.class);
+    suite.addTestSuite(DalConnectionProviderTest.class);
     // suite.addTestSuite(DynamicEntityTest.class);
     // suite.addTestSuite(HiddenUpdateTest.class);
     // suite.addTestSuite(HqlTest.class);
--- a/src-test/org/openbravo/test/AllTests.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-test/org/openbravo/test/AllTests.java	Tue Sep 22 10:35:44 2009 +0200
@@ -22,6 +22,8 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.openbravo.test.dal.DalConnectionProviderTest;
+import org.openbravo.test.dal.DalCopyTest;
 import org.openbravo.test.dal.DalQueryTest;
 import org.openbravo.test.dal.DalTest;
 import org.openbravo.test.dal.DynamicEntityTest;
@@ -63,6 +65,8 @@
     suite.addTestSuite(DynamicEntityTest.class);
     suite.addTestSuite(DalTest.class);
     suite.addTestSuite(DalQueryTest.class);
+    suite.addTestSuite(DalConnectionProviderTest.class);
+    suite.addTestSuite(DalCopyTest.class);
 
     // model
     suite.addTestSuite(RuntimeModelTest.class);
--- a/src-test/org/openbravo/test/AntTaskTests.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-test/org/openbravo/test/AntTaskTests.java	Tue Sep 22 10:35:44 2009 +0200
@@ -24,6 +24,8 @@
 
 import org.openbravo.test.dal.DalComplexQueryRequisitionTest;
 import org.openbravo.test.dal.DalComplexQueryTestOrderLine;
+import org.openbravo.test.dal.DalConnectionProviderTest;
+import org.openbravo.test.dal.DalCopyTest;
 import org.openbravo.test.dal.DalPerformanceInventoryLineTest;
 import org.openbravo.test.dal.DalPerformanceProductTest;
 import org.openbravo.test.dal.DalQueryTest;
@@ -78,7 +80,9 @@
     suite.addTestSuite(DalPerformanceInventoryLineTest.class);
     suite.addTestSuite(DalPerformanceProductTest.class);
     suite.addTestSuite(DalQueryTest.class);
+    suite.addTestSuite(DalConnectionProviderTest.class);
     suite.addTestSuite(DalTest.class);
+    suite.addTestSuite(DalCopyTest.class);
     suite.addTestSuite(DynamicEntityTest.class);
     suite.addTestSuite(HiddenUpdateTest.class);
     // suite.addTestSuite(HqlTest.class);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/dal/DalConnectionProviderTest.java	Tue Sep 22 10:35:44 2009 +0200
@@ -0,0 +1,62 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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 SL 
+ * All portions are Copyright (C) 2009 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.dal;
+
+import org.apache.log4j.Logger;
+import org.openbravo.erpCommon.businessUtility.Tax;
+import org.openbravo.erpCommon.utility.DateTimeData;
+import org.openbravo.service.db.DalConnectionProvider;
+import org.openbravo.test.base.BaseTest;
+
+/**
+ * Tests the {@link DalConnectionProvider}.
+ * 
+ * @author mtaal
+ */
+
+public class DalConnectionProviderTest extends BaseTest {
+  private static final Logger log = Logger.getLogger(DalConnectionProviderTest.class);
+
+  /**
+   * Tests calling database procedures using the dal connection provider
+   */
+  public void testDalConnectionProvider() throws Exception {
+    setUserContext("0");
+
+    final DalConnectionProvider connectionProvider = new DalConnectionProvider();
+    // get the current date, this already uses the connectionprovider
+    final String currentDateStr = DateTimeData.today(connectionProvider);
+
+    // now compute a tax for a certain business partner using the date string
+    // by passing the date str the check is done that the dbSessionConfig has been
+    // executed. See this issue:
+    // https://issues.openbravo.com/view.php?id=10330
+    String productId = "1000004";
+    String orgId = "1000002";
+    String whId = "1000000";
+    String bpLocId = "1000001";
+    String shipPartnLocId = "1000001";
+    String projectId = null;
+
+    // just call, the return value is not important, it should not fail.
+    Tax.get(connectionProvider, productId, currentDateStr, orgId, whId, bpLocId, shipPartnLocId,
+        projectId, true);
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/dal/DalCopyTest.java	Tue Sep 22 10:35:44 2009 +0200
@@ -0,0 +1,66 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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 SL 
+ * All portions are Copyright (C) 2009 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.dal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.dal.core.DalUtil;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.financialmgmt.payment.PaymentTerm;
+import org.openbravo.model.financialmgmt.payment.PaymentTermLine;
+import org.openbravo.model.financialmgmt.payment.PaymentTermTrl;
+import org.openbravo.test.base.BaseTest;
+
+/**
+ * Test the {@link DalUtil} class and then specifically the copy methods.
+ * 
+ * @author mtaal
+ */
+
+public class DalCopyTest extends BaseTest {
+
+  /**
+   * Test copy of a structure, parent and childs should point to eachother
+   */
+  public void testHiddenUpdates() {
+    setUserContext("1000000");
+    addReadWriteAccess(PaymentTerm.class);
+    addReadWriteAccess(PaymentTermTrl.class);
+    final List<PaymentTerm> pts = OBDal.getInstance().createCriteria(PaymentTerm.class).list();
+    final List<PaymentTermLine> ptls = new ArrayList<PaymentTermLine>();
+    for (PaymentTerm pt : pts) {
+      ptls.addAll(pt.getFinancialMgmtPaymentTermLineList());
+    }
+    final List<BaseOBObject> copiedPts = DalUtil.copyAll(new ArrayList<BaseOBObject>(pts));
+    for (BaseOBObject bob : copiedPts) {
+      final PaymentTerm pt = (PaymentTerm) bob;
+      assertFalse(pts.contains(pt));
+      for (PaymentTermLine ptl : pt.getFinancialMgmtPaymentTermLineList()) {
+        assertSame(pt, ptl.getPaymentTerms());
+        assertFalse(ptls.contains(ptl));
+      }
+      for (PaymentTermTrl ptt : pt.getFinancialMgmtPaymentTermTrlList()) {
+        assertSame(pt, ptt.getPaymentTerms());
+      }
+    }
+  }
+}
\ No newline at end of file
--- a/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java	Tue Sep 22 10:35:44 2009 +0200
@@ -277,13 +277,10 @@
       fail(ir.getException().getMessage());
     }
 
-    assertEquals(NO_OF_PT + NO_OF_PT_LINE, ir.getInsertedObjects().size());
-    assertEquals(NO_OF_PT, ir.getUpdatedObjects().size());
-    for (final Object o : ir.getUpdatedObjects()) {
-      assertTrue(o instanceof PaymentTermTrl);
-    }
+    assertEquals(NO_OF_PT + NO_OF_PT_LINE + 1, ir.getInsertedObjects().size());
     for (final Object o : ir.getInsertedObjects()) {
-      assertTrue(o instanceof PaymentTerm || o instanceof PaymentTermLine);
+      assertTrue(o instanceof PaymentTermTrl || o instanceof PaymentTerm
+          || o instanceof PaymentTermLine);
     }
   }
 
--- a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Tue Sep 22 10:35:44 2009 +0200
@@ -465,7 +465,6 @@
 
   protected void logout(HttpServletRequest request, HttpServletResponse response)
       throws IOException, ServletException {
-    final VariablesSecureApp vars = new VariablesSecureApp(request);
 
     HttpSession session = request.getSession(false);
     if (session != null) {
--- a/src/org/openbravo/base/secureApp/LoginHandler.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/base/secureApp/LoginHandler.java	Tue Sep 22 10:35:44 2009 +0200
@@ -22,7 +22,6 @@
 import org.openbravo.base.HttpBaseServlet;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.erpCommon.obps.ActivationKey;
-import org.openbravo.utils.FormatUtilities;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class LoginHandler extends HttpBaseServlet {
@@ -51,10 +50,10 @@
       res.sendRedirect(res.encodeRedirectURL(strDireccion + "/security/Login_F1.html"));
     } else {
       final String strUser = vars.getRequiredStringParameter("user");
-      final String strPass = FormatUtilities.sha1Base64(vars.getStringParameter("password"));
-      final String strUserAuth = SeguridadData.valido(this, strUser, strPass);
+      final String strPass = vars.getStringParameter("password");
+      final String strUserAuth = LoginUtils.getValidUserId(myPool, strUser, strPass);
 
-      if (!strUserAuth.equals("-1")) {
+      if (strUserAuth != null) {
         req.getSession(true).setAttribute("#Authenticated_user", strUserAuth);
         checkLicenseAndGo(res, vars);
       } else {
--- a/src/org/openbravo/base/secureApp/LoginUtils.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/base/secureApp/LoginUtils.java	Tue Sep 22 10:35:44 2009 +0200
@@ -14,10 +14,13 @@
 import javax.servlet.ServletException;
 
 import org.apache.log4j.Logger;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.base.exception.OBSecurityException;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.service.db.DalConnectionProvider;
+import org.openbravo.utils.FormatUtilities;
 
 public class LoginUtils {
 
@@ -27,6 +30,36 @@
   private LoginUtils() {
   }
 
+  /**
+   * Returns a userId which matches the login and password. If no user is found then null is
+   * returned. The combination of login and password is used to find the user.
+   * 
+   * Note that only active users are returned.
+   * 
+   * @param connectionProvider
+   *          , see the {@link DalConnectionProvider} for an instance of a ConnectionProvider for
+   *          the DAL.
+   * @param login
+   *          the login
+   * @param unHashedPassword
+   *          the password, the unhashed password as it is entered by the user.
+   * @return the user id or null if no user could be found.
+   * @see FormatUtilities#sha1Base64(String)
+   */
+  public static String getValidUserId(ConnectionProvider connectionProvider, String login,
+      String unHashedPassword) {
+    try {
+      final String hashedPassword = FormatUtilities.sha1Base64(unHashedPassword);
+      final String userId = SeguridadData.valido(connectionProvider, login, hashedPassword);
+      if (userId.equals("-1")) {
+        return null;
+      }
+      return userId;
+    } catch (final Exception e) {
+      throw new OBException(e);
+    }
+  }
+
   public static boolean fillSessionArguments(ConnectionProvider conn, VariablesSecureApp vars,
       String strUserAuth, String strLanguage, String strIsRTL, String strRol, String strCliente,
       String strOrg, String strAlmacen) throws ServletException {
--- a/src/org/openbravo/dal/core/DalUtil.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/dal/core/DalUtil.java	Tue Sep 22 10:35:44 2009 +0200
@@ -22,7 +22,9 @@
 import java.io.Serializable;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.hibernate.proxy.HibernateProxy;
 import org.openbravo.base.exception.OBException;
@@ -67,9 +69,11 @@
    */
   public static List<BaseOBObject> copyAll(List<BaseOBObject> source, boolean resetId) {
     final List<BaseOBObject> result = new ArrayList<BaseOBObject>();
+    final Map<BaseOBObject, BaseOBObject> fromTo = new HashMap<BaseOBObject, BaseOBObject>();
     for (final BaseOBObject bob : source) {
-      result.add(copy(bob, true, resetId));
+      result.add(copy(bob, true, resetId, fromTo));
     }
+    repairReferences(fromTo);
     return result;
   }
 
@@ -113,7 +117,47 @@
    * @return the copied object
    */
   public static BaseOBObject copy(BaseOBObject source, boolean copyChildren, boolean resetId) {
+    final Map<BaseOBObject, BaseOBObject> fromTo = new HashMap<BaseOBObject, BaseOBObject>();
+    copy(source, copyChildren, resetId, fromTo);
+    repairReferences(fromTo);
+    return fromTo.get(source);
+  }
+
+  // Walks through all copied objects and if there are references to objects which have been
+  // copied then the references are moved to the copied object
+  // see issue:
+  // https://issues.openbravo.com/view.php?id=8651
+  private static void repairReferences(Map<BaseOBObject, BaseOBObject> fromTo) {
+
+    for (BaseOBObject to : fromTo.values()) {
+      for (final Property p : to.getEntity().getProperties()) {
+        if (p.isPrimitive()) {
+          continue;
+        }
+        final Object value = to.getValue(p.getName());
+
+        if (p.isOneToMany()) {
+          @SuppressWarnings("unchecked")
+          final List<BaseOBObject> bobs = (List<BaseOBObject>) value;
+          for (int i = 0; i < bobs.size(); i++) {
+            final BaseOBObject curValue = bobs.get(i);
+            if (fromTo.containsKey(curValue)) {
+              bobs.set(i, fromTo.get(curValue));
+            }
+          }
+        } else if (fromTo.containsKey(value)) {
+          to.setValue(p.getName(), fromTo.get(value));
+        }
+      }
+    }
+
+  }
+
+  private static BaseOBObject copy(BaseOBObject source, boolean copyChildren, boolean resetId,
+      Map<BaseOBObject, BaseOBObject> fromTo) {
+
     final BaseOBObject target = (BaseOBObject) OBProvider.getInstance().get(source.getEntityName());
+    fromTo.put(source, target);
     for (final Property p : source.getEntity().getProperties()) {
       final Object value = source.getValue(p.getName());
       if (p.isOneToMany()) {
@@ -123,7 +167,7 @@
           @SuppressWarnings("unchecked")
           final List<BaseOBObject> sourceChildren = (List<BaseOBObject>) value;
           for (final BaseOBObject sourceChild : sourceChildren) {
-            targetChildren.add(copy(sourceChild, copyChildren, resetId));
+            targetChildren.add(copy(sourceChild, copyChildren, resetId, fromTo));
           }
         }
       } else {
--- a/src/org/openbravo/dal/core/OBContext.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/dal/core/OBContext.java	Tue Sep 22 10:35:44 2009 +0200
@@ -80,7 +80,7 @@
 
   private static ThreadLocal<OBContext> adminModeSet = new ThreadLocal<OBContext>();
 
-  private static String CONTEXT_PARAM = "#OBContext";
+  public static final String CONTEXT_PARAM = "#OBContext";
 
   private static OBContext adminContext = null;
 
--- a/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java	Tue Sep 22 10:35:44 2009 +0200
@@ -37,7 +37,7 @@
 
   /**
    * Constructor
-   *
+   * 
    * @param AD_Client_ID
    *          AD_Client_ID
    */
@@ -217,7 +217,7 @@
 
   /**
    * Create Facts (the accounting logic) for ARI, ARC, ARF, API, APC.
-   *
+   * 
    * <pre>
    *  ARI, ARF
    *      Receivables     DR
@@ -240,7 +240,7 @@
    *      TaxCredit               CR
    *      Expense                 CR
    * </pre>
-   *
+   * 
    * @param as
    *          accounting schema
    * @return Fact
@@ -296,9 +296,9 @@
       // TaxDue CR
       log4jDocInvoice.debug("m_taxes.length: " + m_taxes);
       for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
-    	//New docLine created to assign C_Tax_ID value to the entry
-    	DocLine docLine = new DocLine(DocumentType, Record_ID, "");
-    	docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
+        // New docLine created to assign C_Tax_ID value to the entry
+        DocLine docLine = new DocLine(DocumentType, Record_ID, "");
+        docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
         fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as, conn),
             C_Currency_ID, "", m_taxes[i].m_amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
             DocumentType, conn);
@@ -326,10 +326,19 @@
       for (int i = 0; m_debt_payments != null && i < m_debt_payments.length; i++) {
         BigDecimal amount = new BigDecimal(m_debt_payments[i].Amount);
         BigDecimal ZERO = BigDecimal.ZERO;
-        fact.createLine(m_debt_payments[i], getAccountBPartner(C_BPartner_ID, as, true,
-            m_debt_payments[i].dpStatus, conn), this.C_Currency_ID, "", getConvertedAmt(((amount
-            .negate())).toPlainString(), m_debt_payments[i].C_Currency_ID_From, this.C_Currency_ID,
-            DateAcct, "", conn), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
+        if ((amount.compareTo(ZERO) > 0 && m_debt_payments[i].isReceipt.equals("Y"))
+            || (amount.compareTo(ZERO) < 0 && m_debt_payments[i].isReceipt.equals("N")))
+          fact.createLine(m_debt_payments[i], getAccountBPartner(C_BPartner_ID, as, true,
+              m_debt_payments[i].dpStatus, conn), this.C_Currency_ID, getConvertedAmt(((amount
+              .negate())).toPlainString(), m_debt_payments[i].C_Currency_ID_From,
+              this.C_Currency_ID, DateAcct, "", conn), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+              DocumentType, conn);
+        else
+          fact.createLine(m_debt_payments[i], getAccountBPartner(C_BPartner_ID, as, true,
+              m_debt_payments[i].dpStatus, conn), this.C_Currency_ID, "", getConvertedAmt(((amount
+              .negate())).toPlainString(), m_debt_payments[i].C_Currency_ID_From,
+              this.C_Currency_ID, DateAcct, "", conn), Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+              DocumentType, conn);
       }
 
       // fact.createLine(null,
@@ -342,10 +351,14 @@
           getAmount(AcctServer.AMTTYPE_Charge), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
           DocumentType, conn);
       // TaxDue DR
-      for (int i = 0; m_taxes != null && i < m_taxes.length; i++)
-        fact.createLine(null, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as, conn),
+      for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
+        // New docLine created to assign C_Tax_ID value to the entry
+        DocLine docLine = new DocLine(DocumentType, Record_ID, "");
+        docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
+        fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as, conn),
             this.C_Currency_ID, m_taxes[i].getAmount(), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
             DocumentType, conn);
+      }
       // Revenue CR
       for (int i = 0; p_lines != null && i < p_lines.length; i++)
         fact.createLine(p_lines[i], ((DocLine_Invoice) p_lines[i]).getAccount(
@@ -386,10 +399,14 @@
           getAmount(AcctServer.AMTTYPE_Charge), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
           DocumentType, conn);
       // TaxCredit DR
-      for (int i = 0; m_taxes != null && i < m_taxes.length; i++)
-        fact.createLine(null, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
+      for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
+        // New docLine created to assign C_Tax_ID value to the entry
+        DocLine docLine = new DocLine(DocumentType, Record_ID, "");
+        docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
+        fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
             this.C_Currency_ID, m_taxes[i].getAmount(), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
             DocumentType, conn);
+      }
       // Expense DR
       for (int i = 0; p_lines != null && i < p_lines.length; i++)
         fact.createLine(p_lines[i], ((DocLine_Invoice) p_lines[i]).getAccount(
@@ -412,10 +429,19 @@
       for (int i = 0; m_debt_payments != null && i < m_debt_payments.length; i++) {
         BigDecimal amount = new BigDecimal(m_debt_payments[i].Amount);
         BigDecimal ZERO = BigDecimal.ZERO;
-        fact.createLine(m_debt_payments[i], getAccountBPartner(C_BPartner_ID, as, false,
-            m_debt_payments[i].dpStatus, conn), this.C_Currency_ID, getConvertedAmt(((amount
-            .negate())).toPlainString(), m_debt_payments[i].C_Currency_ID_From, this.C_Currency_ID,
-            DateAcct, "", conn), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
+        if ((amount.compareTo(ZERO) < 0 && m_debt_payments[i].isReceipt.equals("Y"))
+            || (amount.compareTo(ZERO) > 0 && m_debt_payments[i].isReceipt.equals("N")))
+          fact.createLine(m_debt_payments[i], getAccountBPartner(C_BPartner_ID, as, false,
+              m_debt_payments[i].dpStatus, conn), this.C_Currency_ID, "", getConvertedAmt(((amount
+              .negate())).toPlainString(), m_debt_payments[i].C_Currency_ID_From,
+              this.C_Currency_ID, DateAcct, "", conn), Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+              DocumentType, conn);
+        else
+          fact.createLine(m_debt_payments[i], getAccountBPartner(C_BPartner_ID, as, false,
+              m_debt_payments[i].dpStatus, conn), this.C_Currency_ID, getConvertedAmt(((amount
+              .negate())).toPlainString(), m_debt_payments[i].C_Currency_ID_From,
+              this.C_Currency_ID, DateAcct, "", conn), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+              DocumentType, conn);
       }
 
       // fact.createLine (null,
@@ -427,10 +453,14 @@
           "", getAmount(AcctServer.AMTTYPE_Charge), Fact_Acct_Group_ID, nextSeqNo(SeqNo),
           DocumentType, conn);
       // TaxCredit CR
-      for (int i = 0; m_taxes != null && i < m_taxes.length; i++)
-        fact.createLine(null, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
+      for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
+        // New docLine created to assign C_Tax_ID value to the entry
+        DocLine docLine = new DocLine(DocumentType, Record_ID, "");
+        docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
+        fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
             this.C_Currency_ID, "", m_taxes[i].getAmount(), Fact_Acct_Group_ID, nextSeqNo(SeqNo),
             DocumentType, conn);
+      }
       // Expense CR
       for (int i = 0; p_lines != null && i < p_lines.length; i++)
         fact.createLine(p_lines[i], ((DocLine_Invoice) p_lines[i]).getAccount(
@@ -450,11 +480,11 @@
     }
     SeqNo = "0";
     return fact;
-  }// createFact
+  } // createFact
 
   /**
    * Update Product Info. - Costing (PriceLastInv) - PO (PriceLastInv)
-   *
+   * 
    * @param C_AcctSchema_ID
    *          accounting schema
    */
@@ -481,7 +511,7 @@
 
   /**
    * Get Source Currency Balance - subtracts line and tax amounts from total - no rounding
-   *
+   * 
    * @return positive amount, if total invoice is bigger than lines
    */
   public BigDecimal getBalance() {
@@ -520,7 +550,7 @@
 
   /**
    * Get the account for Accounting Schema
-   *
+   * 
    * @param cBPartnerId
    *          business partner id
    * @param as
@@ -567,7 +597,7 @@
 
   /**
    * Get Document Confirmation
-   *
+   * 
    * not used
    */
   public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) {
--- a/src/org/openbravo/erpCommon/ad_forms/InitialClientSetup.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/InitialClientSetup.java	Tue Sep 22 10:35:44 2009 +0200
@@ -570,6 +570,7 @@
       SystemInformation sys = OBDal.getInstance().get(SystemInformation.class, "0");
       if (sys.getYourCompanyBigImage() != null) {
         Image yourCompanyBigImage = OBProvider.getInstance().get(Image.class);
+        yourCompanyBigImage.setClient(newClient);
         yourCompanyBigImage.setBindaryData(sys.getYourCompanyBigImage().getBindaryData());
         yourCompanyBigImage.setName(sys.getYourCompanyBigImage().getName());
         newClient.getClientInformationList().get(0).setYourCompanyBigImage(yourCompanyBigImage);
@@ -578,6 +579,7 @@
 
       if (sys.getYourCompanyDocumentImage() != null) {
         Image yourCompanyDocumentImage = OBProvider.getInstance().get(Image.class);
+        yourCompanyDocumentImage.setClient(newClient);
         yourCompanyDocumentImage.setBindaryData(sys.getYourCompanyDocumentImage().getBindaryData());
         yourCompanyDocumentImage.setName(sys.getYourCompanyBigImage().getName());
         newClient.getClientInformationList().get(0).setYourCompanyDocumentImage(
@@ -587,6 +589,7 @@
 
       if (sys.getYourCompanyMenuImage() != null) {
         Image yourCompanyMenuImage = OBProvider.getInstance().get(Image.class);
+        yourCompanyMenuImage.setClient(newClient);
         yourCompanyMenuImage.setBindaryData(sys.getYourCompanyMenuImage().getBindaryData());
         yourCompanyMenuImage.setName(sys.getYourCompanyMenuImage().getName());
         newClient.getClientInformationList().get(0).setYourCompanyMenuImage(yourCompanyMenuImage);
--- a/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java	Tue Sep 22 10:35:44 2009 +0200
@@ -297,7 +297,7 @@
       strError = strError.substring((strError.lastIndexOf("@ORA-") > 0 ? strError
           .lastIndexOf("@ORA-") : 0), strError.length());
       isOK = false;
-      log4j.warn(err);
+      log4j.error("Error in createOrg", err);
       try {
         releaseRollbackConnection(conn);
       } catch (final Exception ignored) {
@@ -528,10 +528,12 @@
     Client organizationClient = OBDal.getInstance().get(Client.class, AD_Client_ID);
     if (organizationClient.getClientInformationList().get(0).getYourCompanyDocumentImage() != null) {
       Image yourCompanyDocumentImage = OBProvider.getInstance().get(Image.class);
+      yourCompanyDocumentImage.setClient(organizationClient);
+      yourCompanyDocumentImage.setOrganization(newOrganization);
       yourCompanyDocumentImage.setBindaryData(organizationClient.getClientInformationList().get(0)
           .getYourCompanyDocumentImage().getBindaryData());
       yourCompanyDocumentImage.setName(organizationClient.getClientInformationList().get(0)
-          .getYourCompanyBigImage().getName());
+          .getYourCompanyDocumentImage().getName());
       newOrganization.getOrganizationInformationList().get(0).setYourCompanyDocumentImage(
           yourCompanyDocumentImage);
       yourCompanyDocumentImage.setOrganization(newOrganization);
--- a/src/org/openbravo/erpCommon/ad_reports/InvoiceCustomerEdition_data.xsql	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/InvoiceCustomerEdition_data.xsql	Tue Sep 22 10:35:44 2009 +0200
@@ -26,13 +26,13 @@
     <Sql>
     <![CDATA[
       SELECT COALESCE(C_INVOICE.POREFERENCE, C_INVOICE.DOCUMENTNO) AS DOCUMENTNO, C_INVOICE.DATEINVOICED AS DATEINVOICED, 
-      C_BPARTNER.NAME AS CLIENT_NAME, M_PRODUCT.NAME AS PRODUCT_NAME, SUM(C_INVOICELINE.QTYINVOICED) AS QUANTITYORDER, C_UOM.NAME AS UOMNAME, 
+      C_BPARTNER.NAME AS CLIENT_NAME, M_PRODUCT.NAME AS PRODUCT_NAME,  CASE WHEN C_DOCTYPE.DOCBASETYPE = 'ARC' THEN SUM(C_INVOICELINE.QTYINVOICED)*-1 ELSE  SUM(C_INVOICELINE.QTYINVOICED) END AS QUANTITYORDER, C_UOM.NAME AS UOMNAME, 
       C_INVOICELINE.PRICEACTUAL AS PRICEACTUAL, 
       C_CURRENCY_SYMBOL(C_INVOICE.C_CURRENCY_ID, C_INVOICELINE.PRICEACTUAL, 'Y') AS PRICEACTUALSYM,
 	  C_CURRENCY_CONVERT(C_INVOICELINE.PRICEACTUAL, C_INVOICE.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AS CONVPRICEACTUAL,
-      SUM(C_INVOICELINE.LINENETAMT) AS PRICELIST,
+      CASE WHEN C_DOCTYPE.DOCBASETYPE = 'ARC' THEN SUM(C_INVOICELINE.LINENETAMT)*-1 ELSE SUM(C_INVOICELINE.LINENETAMT) END AS PRICELIST,
       C_CURRENCY_SYMBOL (C_INVOICE.C_CURRENCY_ID, SUM(C_INVOICELINE.LINENETAMT), 'Y') AS PRICELISTSYM,
-	  SUM(C_CURRENCY_CONVERT(C_INVOICELINE.LINENETAMT, C_INVOICE.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID)) AS CONVPRICELIST,
+	  SUM(C_CURRENCY_CONVERT(CASE WHEN C_DOCTYPE.DOCBASETYPE = 'ARC' THEN C_INVOICELINE.LINENETAMT*-1 ELSE C_INVOICELINE.LINENETAMT END, C_INVOICE.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID)) AS CONVPRICELIST,
 	  C_CURRENCY_SYMBOL(?, '0', 'Y') AS CONVSYM,
 	  C_CURRENCY_ISOSYM(?) AS CONVISOSYM,
 	  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())) AS TRANSDATE,
@@ -40,7 +40,10 @@
       C_INVOICELINE.AD_CLIENT_ID AS TRANSCLIENTID, 
 	  C_INVOICELINE.AD_ORG_ID AS TRANSORGID
       FROM C_INVOICE LEFT JOIN C_PROJECT ON C_INVOICE.C_PROJECT_ID = C_PROJECT.C_PROJECT_ID 
-                     LEFT JOIN C_LOCATION ON C_PROJECT.C_LOCATION_ID = C_LOCATION.C_LOCATION_ID, C_INVOICELINE, M_PRODUCT, C_UOM, C_BPARTNER
+                     LEFT JOIN C_LOCATION ON C_PROJECT.C_LOCATION_ID = C_LOCATION.C_LOCATION_ID
+                     LEFT JOIN C_DOCTYPE ON C_INVOICE.C_DOCTYPE_ID = C_DOCTYPE.C_DOCTYPE_ID,
+                     C_INVOICELINE, M_PRODUCT, C_UOM, C_BPARTNER
+                                       
       WHERE C_INVOICE.C_INVOICE_ID = C_INVOICELINE.C_INVOICE_ID
       AND C_INVOICELINE.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
       AND C_INVOICELINE.C_UOM_ID = C_UOM.C_UOM_ID
@@ -51,7 +54,7 @@
       AND 1=1
       GROUP BY C_BPARTNER.NAME, M_PRODUCT.NAME, C_UOM.NAME, C_INVOICELINE.PRICEACTUAL, 
       COALESCE(C_INVOICE.POREFERENCE, C_INVOICE.DOCUMENTNO), C_INVOICE.DATEINVOICED,
-      C_INVOICE.C_CURRENCY_ID, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID
+      C_INVOICE.C_CURRENCY_ID, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID, C_DOCTYPE.DOCBASETYPE
       ORDER BY C_BPARTNER.NAME, COALESCE(C_INVOICE.POREFERENCE, C_INVOICE.DOCUMENTNO), C_INVOICE.DATEINVOICED
 
      ]]></Sql>
--- a/src/org/openbravo/erpCommon/ad_reports/InvoiceEdition_data.xsql	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/InvoiceEdition_data.xsql	Tue Sep 22 10:35:44 2009 +0200
@@ -29,20 +29,21 @@
     <Sql>
     <![CDATA[
       SELECT COALESCE(C_INVOICE.POREFERENCE, C_INVOICE.DOCUMENTNO) AS DOCUMENTNO, C_INVOICE.DATEINVOICED AS DATEINVOICED, 
-      C_BPARTNER.NAME AS CLIENT_NAME, M_PRODUCT.NAME AS PRODUCT_NAME, SUM(C_INVOICELINE.QTYINVOICED) AS QUANTITYORDER, 
+      C_BPARTNER.NAME AS CLIENT_NAME, M_PRODUCT.NAME AS PRODUCT_NAME, SUM(CASE WHEN C_DOCTYPE.DOCBASETYPE='APC' THEN C_INVOICELINE.QTYINVOICED*-1 ELSE C_INVOICELINE.QTYINVOICED END) AS QUANTITYORDER, 
       C_UOM.NAME AS UOMNAME, C_INVOICELINE.PRICEACTUAL AS PRICEACTUAL, 
       C_CURRENCY_SYMBOL (C_INVOICE.C_CURRENCY_ID, C_INVOICELINE.PRICEACTUAL, 'Y') AS PRICEACTUALSYM,
 	  C_CURRENCY_CONVERT(C_INVOICELINE.PRICEACTUAL, C_INVOICE.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AS CONVPRICEACTUAL,
-      SUM(C_INVOICELINE.LINENETAMT) AS PRICELIST,
+      SUM(CASE WHEN C_DOCTYPE.DOCBASETYPE='APC' THEN C_INVOICELINE.LINENETAMT*-1 ELSE C_INVOICELINE.LINENETAMT END) AS PRICELIST,
       C_CURRENCY_SYMBOL (C_INVOICE.C_CURRENCY_ID, SUM(C_INVOICELINE.LINENETAMT) , 'Y') AS PRICELISTSYM,
-	  SUM(C_CURRENCY_CONVERT(C_INVOICELINE.LINENETAMT, C_INVOICE.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID)) AS CONVPRICELIST,
+	  SUM(C_CURRENCY_CONVERT(CASE WHEN C_DOCTYPE.DOCBASETYPE='APC' THEN C_INVOICELINE.LINENETAMT*-1 ELSE C_INVOICELINE.LINENETAMT END, C_INVOICE.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID)) AS CONVPRICELIST,
 	  C_CURRENCY_SYMBOL(?, '0', 'Y') AS CONVSYM,
 	  C_CURRENCY_ISOSYM(?) AS CONVISOSYM,
 	  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())) AS TRANSDATE,
 	  C_INVOICE.C_CURRENCY_ID AS TRANSCURRENCYID,
       C_INVOICELINE.AD_CLIENT_ID AS TRANSCLIENTID, 
 	  C_INVOICELINE.AD_ORG_ID AS TRANSORGID 
-      FROM C_INVOICE, C_INVOICELINE, M_PRODUCT, C_UOM, C_BPARTNER
+      FROM C_INVOICE left join C_DOCTYPE on C_INVOICE.C_DOCTYPE_ID=C_DOCTYPE.C_DOCTYPE_ID,
+      C_INVOICELINE, M_PRODUCT, C_UOM, C_BPARTNER
       WHERE C_INVOICE.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
       AND C_INVOICE.C_INVOICE_ID = C_INVOICELINE.C_INVOICE_ID
       AND C_INVOICELINE.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.java	Tue Sep 22 10:35:44 2009 +0200
@@ -103,11 +103,8 @@
       String strBaseDesign = getBaseDesignPath(strLanguage);
       JasperReport jasperReportLines;
       try {
-        JasperDesign jasperDesignLines = (("on".equals(strBreakDate)) ? JRXmlLoader
-            .load(strBaseDesign
-                + "/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast_perDay.jrxml")
-            : JRXmlLoader.load(strBaseDesign
-                + "/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.jrxml"));
+        JasperDesign jasperDesignLines = (JRXmlLoader.load(strBaseDesign
+            + "/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast_sub.jrxml"));
         jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
       } catch (JRException e) {
         log4j.error("Error Compiling report ", e);
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.jrxml	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.jrxml	Tue Sep 22 10:35:44 2009 +0200
@@ -158,6 +158,7 @@
 
 	<parameter name="ATTACH" isForPrompting="false" class="java.lang.String"/>
 	<parameter name="BASE_WEB" isForPrompting="false" class="java.lang.String"/>
+	<parameter name="ReportData" isForPrompting="false" class="net.sf.jasperreports.engine.JasperReport"/>
 	<parameter name="BASE_DESIGN" isForPrompting="false" class="java.lang.String">
 		<defaultValueExpression ><![CDATA["/home/david/workspace/trunk/openbravo/src"]]></defaultValueExpression>
 	</parameter>
@@ -504,7 +505,7 @@
 						<subreportParameterExpression><![CDATA[$P{LOCALE}]]></subreportParameterExpression>
 					</subreportParameter>
 					<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
-					<subreportExpression  class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR}+"ReportCashflowForecast_sub.jasper"]]></subreportExpression>
+					<subreportExpression  class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{ReportData}]]></subreportExpression>
 				</subreport>
 				<staticText>
 					<reportElement
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast_perDay.jrxml	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast_perDay.jrxml	Tue Sep 22 10:35:44 2009 +0200
@@ -158,6 +158,7 @@
 
 	<parameter name="ATTACH" isForPrompting="false" class="java.lang.String"/>
 	<parameter name="BASE_WEB" isForPrompting="false" class="java.lang.String"/>
+	<parameter name="ReportData" isForPrompting="false" class="net.sf.jasperreports.engine.JasperReport"/>
 	<parameter name="BASE_DESIGN" isForPrompting="false" class="java.lang.String">
 		<defaultValueExpression ><![CDATA["/home/david/workspace/trunk/openbravo/src"]]></defaultValueExpression>
 	</parameter>
@@ -602,7 +603,7 @@
 						<subreportParameterExpression><![CDATA[$P{LOCALE}]]></subreportParameterExpression>
 					</subreportParameter>
 					<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
-					<subreportExpression  class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR}+"ReportCashflowForecast_sub.jasper"]]></subreportExpression>
+					<subreportExpression  class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{ReportData}]]></subreportExpression>
 				</subreport>
 				<staticText>
 					<reportElement
--- a/src/org/openbravo/erpCommon/ad_reports/ReportInvoiceCustomerJR.jrxml	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportInvoiceCustomerJR.jrxml	Tue Sep 22 10:35:44 2009 +0200
@@ -281,7 +281,7 @@
 					<textElement>
 						<font pdfFontName="Helvetica"/>
 					</textElement>
-				<text><![CDATA[Client]]></text>
+				<text><![CDATA[Customer]]></text>
 				</staticText>
 				<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
 					<reportElement
@@ -444,9 +444,9 @@
 				<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
 					<reportElement
 						style="Detail_Header"
-						x="90"
+						x="178"
 						y="10"
-						width="238"
+						width="150"
 						height="16"
 						key="textField"/>
 					<box leftPadding="5">					<pen lineWidth="0.0"/>
@@ -489,9 +489,9 @@
 				<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
 					<reportElement
 						style="Detail_Header"
-						x="420"
+						x="456"
 						y="10"
-						width="286"
+						width="250"
 						height="16"
 						key="textField"/>
 					<box leftPadding="5">					<pen lineWidth="0.0"/>
@@ -586,7 +586,7 @@
 						style="Detail_Header"
 						x="328"
 						y="10"
-						width="92"
+						width="128"
 						height="16"
 						key="staticText-9"/>
 					<box leftPadding="5">					<pen lineWidth="0.0"/>
@@ -605,7 +605,7 @@
 						style="Detail_Header"
 						x="10"
 						y="10"
-						width="80"
+						width="168"
 						height="16"
 						key="staticText-11"/>
 					<box leftPadding="5">					<pen lineWidth="0.0"/>
@@ -617,7 +617,7 @@
 					<textElement>
 						<font/>
 					</textElement>
-				<text><![CDATA[Order No.]]></text>
+				<text><![CDATA[Invoice Doc No.]]></text>
 				</staticText>
 				<line direction="TopDown">
 					<reportElement
--- a/src/org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscount_data.xsql	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscount_data.xsql	Tue Sep 22 10:35:44 2009 +0200
@@ -34,9 +34,9 @@
 	(CASE (ROUND(C_DIVIDE((ROUND(C_DIVIDE(TOTALLINE,QTY),3)-ROUND(C_DIVIDE(TOTALLINEDISCOUNT,QTY),3)),ROUND(C_DIVIDE(TOTALLINE,QTY),3)),2))*100 WHEN 0 THEN '' ELSE '' END)  AS CLASS_DESIGN,        
 	WEIGHT,	TRCURRENCYID AS TRANSCURRENCYID, TRDATE AS TRANSDATE,	TRCLIENTID AS TRANSCLIENTID, TRORGID AS TRANSORGID,
 	C_CURRENCY_SYMBOL(?, 0, 'Y') AS CONVSYM, C_CURRENCY_ISOSYM(?) AS CONVISOSYM
-	FROM (SELECT C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME, M_PRODUCT.NAME AS PRODUCTNAME, C_UOM.UOMSYMBOL AS UOM, SUM(C_INVOICELINE.QTYINVOICED) AS QTY, 
-	C_CURRENCY_CONVERT(ROUND(SUM(LINENETAMT),2), C_INVOICE.C_CURRENCY_ID, ?,  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AS TOTALLINE,         
-	C_CURRENCY_CONVERT(ROUND(SUM(LINENETAMT*(1-COALESCE(DISCOUNTPERUNIT,0))),2), C_INVOICE.C_CURRENCY_ID, ?,  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AS TOTALLINEDISCOUNT, 
+	FROM (SELECT C_DOCTYPE.DOCBASETYPE,C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME, M_PRODUCT.NAME AS PRODUCTNAME, C_UOM.UOMSYMBOL AS UOM, CASE WHEN C_DOCTYPE.DOCBASETYPE='ARC' THEN SUM(C_INVOICELINE.QTYINVOICED)*-1 ELSE SUM(C_INVOICELINE.QTYINVOICED) END AS QTY, 
+	C_CURRENCY_CONVERT(ROUND(CASE WHEN C_DOCTYPE.DOCBASETYPE='ARC' THEN SUM(LINENETAMT)*-1 ELSE SUM(LINENETAMT) END,2), C_INVOICE.C_CURRENCY_ID, ?,  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AS TOTALLINE,         
+	C_CURRENCY_CONVERT(ROUND(SUM(CASE WHEN C_DOCTYPE.DOCBASETYPE='ARC' THEN LINENETAMT*-1*(1-COALESCE(DISCOUNTPERUNIT,0)) ELSE LINENETAMT*(1-COALESCE(DISCOUNTPERUNIT,0)) END),2), C_INVOICE.C_CURRENCY_ID, ?,  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())), NULL, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AS TOTALLINEDISCOUNT, 
 	SUM(C_INVOICELINE.QTYINVOICED)*COALESCE(M_PRODUCT.WEIGHT,0) AS WEIGHT,
 	C_INVOICE.C_CURRENCY_ID AS TRCURRENCYID,
 	TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())) AS TRDATE,
@@ -50,7 +50,8 @@
 	FROM C_INVOICE I, C_INVOICELINE IL           
 	WHERE I.C_INVOICE_ID = IL.C_INVOICE_ID AND IL.C_INVOICE_DISCOUNT_ID IS NOT NULL           
 	GROUP BY I.C_INVOICE_ID, I.TOTALLINES, I.C_CURRENCY_ID, I.DATEINVOICED, I.AD_CLIENT_ID, I.AD_ORG_ID, IL.AD_CLIENT_ID, IL.AD_ORG_ID) BB) A on C_INVOICELINE.C_INVOICE_ID = A.C_INVOICE_ID
-    left join C_INVOICE on C_INVOICELINE.C_INVOICE_ID = C_INVOICE.C_INVOICE_ID,
+    left join C_INVOICE on C_INVOICELINE.C_INVOICE_ID = C_INVOICE.C_INVOICE_ID
+    LEFT Join C_DOCTYPE on C_INVOICE.C_DOCTYPE_ID=C_DOCTYPE.C_DOCTYPE_ID,
     M_PRODUCT, C_BPARTNER,  C_UOM
     WHERE  C_INVOICELINE.C_INVOICE_DISCOUNT_ID IS NULL
     AND C_INVOICELINE.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
@@ -64,7 +65,7 @@
     AND C_INVOICE.DATEINVOICED <= to_date(?)
     AND 1=1
     GROUP BY C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME, M_PRODUCT.NAME, C_UOM.UOMSYMBOL, M_PRODUCT.WEIGHT, 
-    C_INVOICE.C_CURRENCY_ID, C_INVOICE.DATEINVOICED, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID) AA
+    C_INVOICE.C_CURRENCY_ID, C_INVOICE.DATEINVOICED, C_INVOICELINE.AD_CLIENT_ID, C_INVOICELINE.AD_ORG_ID,C_DOCTYPE.DOCBASETYPE) AA
     WHERE QTY<>0
     AND 2=2
     ORDER BY NAME
--- a/src/org/openbravo/erpCommon/ad_reports/ReportInvoiceVendorDimensionalAnalysesJR_data.xsql	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportInvoiceVendorDimensionalAnalysesJR_data.xsql	Tue Sep 22 10:35:44 2009 +0200
@@ -129,9 +129,9 @@
 	  C_CURRENCY_SYMBOL(?, 0, 'Y') AS CONVSYM,  
 	  C_CURRENCY_ISOSYM(?) AS CONVISOSYM
       FROM (SELECT NIVEL1, NIVEL2, NIVEL3, NIVEL4, NIVEL5, 
-      SUM(LINENETAMT) AS AMOUNT, SUM(QTYINVOICED) AS QTY,
+      SUM(LINENETAMT) AS AMOUNT, SUM(CASE WHEN DOCBASETYPE = 'APC' THEN QTYINVOICED*-1 ELSE QTYINVOICED END) AS QTY,
       SUM(LINENETREF) AS AMOUNTREF, SUM(QTYINVOICEDREF) AS QTYREF,     
-	  C_CURRENCY_CONVERT(SUM(LINENETAMT), TRCURRENCYID, ?, TO_DATE(TRDATE), NULL, TRCLIENTID, TRORGID) AS CONVAMOUNT,
+	  C_CURRENCY_CONVERT(SUM(CASE WHEN DOCBASETYPE = 'APC' THEN LINENETAMT*-1 ELSE LINENETAMT END), TRCURRENCYID, ?, TO_DATE(TRDATE), NULL, TRCLIENTID, TRORGID) AS CONVAMOUNT,
 	  0 AS CONVAMOUNTREF,
       TRCURRENCYID, TRDATE, TRCLIENTID, TRORGID
       FROM (SELECT to_char('1') AS NIVEL1, to_char('2') AS NIVEL2, to_char('3') AS NIVEL3, to_char('4') AS NIVEL4, to_char('5') AS NIVEL5, 
@@ -140,11 +140,14 @@
       C_INVOICE.C_CURRENCY_ID AS TRCURRENCYID,  
 	  TO_DATE(COALESCE(C_INVOICE.DATEINVOICED, NOW())) AS TRDATE,      
 	  C_INVOICELINE.AD_CLIENT_ID AS TRCLIENTID,      
-	  C_INVOICELINE.AD_ORG_ID AS TRORGID
+	  C_INVOICELINE.AD_ORG_ID AS TRORGID,
+      C_DOCTYPE.DOCBASETYPE AS DOCBASETYPE
       FROM C_INVOICELINE left join M_PRODUCT on C_INVOICELINE.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
                          left join C_UOM     on C_INVOICELINE.C_UOM_ID = C_UOM.C_UOM_ID 
-                         left join M_PRODUCT_CATEGORY on M_PRODUCT.M_PRODUCT_CATEGORY_ID = M_PRODUCT_CATEGORY.M_PRODUCT_CATEGORY_ID,
-      C_INVOICE, C_BPARTNER, C_BP_GROUP
+                         left join M_PRODUCT_CATEGORY on M_PRODUCT.M_PRODUCT_CATEGORY_ID = M_PRODUCT_CATEGORY.M_PRODUCT_CATEGORY_ID
+                         left join C_INVOICE on C_INVOICE.C_INVOICE_ID = C_INVOICELINE.C_INVOICE_ID
+                         left join C_DOCTYPE on C_INVOICE.C_DOCTYPE_ID=C_DOCTYPE.C_DOCTYPE_ID,
+      C_BPARTNER, C_BP_GROUP
       WHERE C_INVOICE.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
       AND C_BPARTNER.C_BP_GROUP_ID = C_BP_GROUP.C_BP_GROUP_ID
       AND C_INVOICE.C_INVOICE_ID = C_INVOICELINE.C_INVOICE_ID
--- a/src/org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoiced_data.xsql	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoiced_data.xsql	Tue Sep 22 10:35:44 2009 +0200
@@ -29,10 +29,10 @@
     <Sql>
     <![CDATA[
       SELECT COALESCE(CB.NAME, C_BPARTNER.NAME) AS BPARTNERNAME, C_PROJECT.VALUE||' '||C_PROJECT.NAME AS PROJECTNAME,
-      M_PRODUCT.NAME AS PRODUCTNAME, SUM(C_ORDERLINE.QTYINVOICED) AS QTYINVOICED,
-      SUM(C_ORDERLINE.QTYINVOICED*C_ORDERLINE.PRICEACTUAL) AS LINENETAMT, 
+      M_PRODUCT.NAME AS PRODUCTNAME, CASE WHEN C_DOCTYPE.DOCBASETYPE='ARC' THEN SUM(C_ORDERLINE.QTYINVOICED)*-1 ELSE SUM(C_ORDERLINE.QTYINVOICED) END AS QTYINVOICED,
+      SUM((CASE WHEN C_DOCTYPE.DOCBASETYPE='ARC' THEN C_ORDERLINE.QTYINVOICED*-1 ELSE C_ORDERLINE.QTYINVOICED END)*C_ORDERLINE.PRICEACTUAL) AS LINENETAMT, 
       C_CURRENCY_SYMBOL(COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), C_ORDERLINE.PRICEACTUAL, 'Y') AS LINENETAMTSYM,	  
-	  SUM(C_CURRENCY_CONVERT(C_ORDERLINE.QTYINVOICED*C_ORDERLINE.PRICEACTUAL, COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), ?, TO_DATE(COALESCE(C_ORDERLINE.DATEORDERED, C_ORDER.DATEORDERED, NOW())), NULL, C_ORDERLINE.AD_CLIENT_ID, C_ORDERLINE.AD_ORG_ID)) AS CONVLINENETAMT,
+	  SUM(C_CURRENCY_CONVERT((CASE WHEN C_DOCTYPE.DOCBASETYPE='ARC' THEN C_ORDERLINE.QTYINVOICED*-1 ELSE C_ORDERLINE.QTYINVOICED END)*C_ORDERLINE.PRICEACTUAL, COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), ?, TO_DATE(COALESCE(C_ORDERLINE.DATEORDERED, C_ORDER.DATEORDERED, NOW())), NULL, C_ORDERLINE.AD_CLIENT_ID, C_ORDERLINE.AD_ORG_ID)) AS CONVLINENETAMT,
       C_UOM.NAME AS UOMNAME, 
       C_ORDERLINE.PRICEACTUAL, 
       C_CURRENCY_SYMBOL(COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), C_ORDERLINE.PRICEACTUAL, 'Y') AS PRICEACTUALSYM,	  	  
@@ -47,8 +47,10 @@
        left join C_BPARTNER CB on C_PROJECT.C_BPARTNER_ID = CB.C_BPARTNER_ID
                      left join C_BPARTNER on C_ORDER.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
                      left join C_BPARTNER_LOCATION on C_ORDER.C_BPARTNER_LOCATION_ID = C_BPARTNER_LOCATION.C_BPARTNER_LOCATION_ID
-                     left join C_LOCATION on  C_BPARTNER_LOCATION.C_LOCATION_ID = C_LOCATION.C_LOCATION_ID,
-       C_ORDERLINE, M_PRODUCT, C_UOM
+                     left join C_LOCATION on  C_BPARTNER_LOCATION.C_LOCATION_ID = C_LOCATION.C_LOCATION_ID
+                     left join C_INVOICE on C_INVOICE.C_ORDER_ID = C_ORDER.C_ORDER_ID
+                     left join C_DOCTYPE on C_INVOICE.C_DOCTYPE_ID=C_DOCTYPE.C_DOCTYPE_ID,
+                     C_ORDERLINE, M_PRODUCT, C_UOM
       WHERE C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
       AND C_ORDERLINE.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
       AND C_ORDERLINE.C_UOM_ID = C_UOM.C_UOM_ID
@@ -57,7 +59,7 @@
       AND 1=1
       GROUP BY COALESCE(CB.NAME, C_BPARTNER.NAME), C_PROJECT.VALUE, C_PROJECT.NAME, M_PRODUCT.NAME, C_UOM.NAME, C_ORDERLINE.PRICEACTUAL,
       COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), TO_DATE(COALESCE(C_ORDERLINE.DATEORDERED, C_ORDER.DATEORDERED, NOW())),	  
-	  C_ORDERLINE.AD_CLIENT_ID, C_ORDERLINE.AD_ORG_ID	
+	  C_ORDERLINE.AD_CLIENT_ID, C_ORDERLINE.AD_ORG_ID, C_DOCTYPE.DOCBASETYPE	
       HAVING SUM(C_ORDERLINE.QTYDELIVERED) > 0
       ORDER BY COALESCE(CB.NAME, C_BPARTNER.NAME), C_PROJECT.NAME, M_PRODUCT.NAME
     ]]></Sql>
--- a/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java	Tue Sep 22 10:35:44 2009 +0200
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.List;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -35,6 +36,7 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.Sqlc;
+import org.openbravo.model.ad.datamodel.Column;
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.module.DataPackage;
 import org.openbravo.model.ad.utility.Image;
@@ -51,11 +53,6 @@
   public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
       ServletException {
     VariablesSecureApp vars = new VariablesSecureApp(request);
-    String parentObjectId = vars.getStringParameter("parentObjectId");
-    if (parentObjectId == null || parentObjectId.equals("")) {
-      String keyCol = vars.getStringParameter("inpkeyColumnId");
-      parentObjectId = vars.getStringParameter("inp" + Sqlc.TransformaNombreColumna(keyCol));
-    }
 
     String columnName = vars.getStringParameter("columnName");
     if (columnName == null || columnName.equals(""))
@@ -69,36 +66,49 @@
       imageID = vars.getStringParameter("imageId");
     }
 
+    String parentObjectId = vars.getStringParameter("parentObjectId");
+    if (parentObjectId == null || parentObjectId.equals("")) {
+      boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true);
+      try {
+        Table table = OBDal.getInstance().get(Table.class, vars.getStringParameter("inpTableId"));
+        List<Column> cols = table.getADColumnList();
+        String keyCol = "";
+        for (Column col : cols) {
+          if (col.isKeyColumn()) {
+            keyCol = col.getDBColumnName();
+            break;
+          }
+        }
+        parentObjectId = vars.getStringParameter("inp" + Sqlc.TransformaNombreColumna(keyCol));
+      } finally {
+        OBContext.getOBContext().setInAdministratorMode(adminMode);
+      }
+    }
     if (vars.commandIn("DEFAULT")) {
 
       printPageFrame(response, vars, imageID, tableId, columnName, parentObjectId);
     } else if (vars.commandIn("SAVE")) {
-      boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true);
-      try {
-        final FileItem fi = vars.getMultiFile("inpFile");
-        byte[] bytea = fi.get();
+      final FileItem fi = vars.getMultiFile("inpFile");
+      byte[] bytea = fi.get();
 
-        // Using DAL to write the image data to the database
-        Image image;
-        if (imageID == null || imageID.equals("")) {
-          image = OBProvider.getInstance().get(Image.class);
-          image.setBindaryData(bytea);
-          image.setActive(true);
-          image.setName("Image");
-          OBDal.getInstance().save(image);
-          OBDal.getInstance().flush();
+      // Using DAL to write the image data to the database
+      Image image;
+      if (imageID == null || imageID.equals("")) {
+        image = OBProvider.getInstance().get(Image.class);
+        image.setBindaryData(bytea);
+        image.setActive(true);
+        image.setName("Image");
+        OBDal.getInstance().save(image);
+        OBDal.getInstance().flush();
 
-        } else {
-          image = OBDal.getInstance().get(Image.class, imageID);
-          image.setActive(true);
-          image.setBindaryData(bytea);
-          OBDal.getInstance().flush();
-        }
-        PrintWriter writer = response.getWriter();
-        writeRedirect(writer, image.getId(), columnName);
-      } finally {
-        OBContext.getOBContext().setInAdministratorMode(adminMode);
+      } else {
+        image = OBDal.getInstance().get(Image.class, imageID);
+        image.setActive(true);
+        image.setBindaryData(bytea);
+        OBDal.getInstance().flush();
       }
+      PrintWriter writer = response.getWriter();
+      writeRedirect(writer, image.getId(), columnName);
     } else if (vars.commandIn("DELETE")) {
       if (imageID != null && !imageID.equals("")) {
         boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true);
--- a/src/org/openbravo/service/db/ImportReferenceDataTask.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/service/db/ImportReferenceDataTask.java	Tue Sep 22 10:35:44 2009 +0200
@@ -39,7 +39,7 @@
     final File importDir = getReferenceDataDir();
 
     for (final File importFile : importDir.listFiles()) {
-      if (importFile.isDirectory()) {
+      if (importFile.isDirectory() || !importFile.getName().endsWith(".xml")) {
         continue;
       }
       log.info("Importing from file " + importFile.getAbsolutePath());
--- a/src/org/openbravo/service/web/BaseWebServiceServlet.java	Tue Sep 22 10:15:48 2009 +0200
+++ b/src/org/openbravo/service/web/BaseWebServiceServlet.java	Tue Sep 22 10:35:44 2009 +0200
@@ -21,7 +21,6 @@
 
 import java.io.IOException;
 import java.io.Writer;
-import java.util.List;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -29,14 +28,12 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.codec.binary.Base64;
-import org.hibernate.Query;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.exception.OBSecurityException;
-import org.openbravo.base.util.Check;
+import org.openbravo.base.secureApp.LoginUtils;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.core.SessionHandler;
-import org.openbravo.model.ad.access.User;
-import org.openbravo.utils.CryptoSHA1BASE64;
+import org.openbravo.service.db.DalConnectionProvider;
 
 /**
  * This servlet has two main responsibilities: 1) authenticate, 2) set the correct {@link OBContext}
@@ -119,7 +116,7 @@
     final String password = request.getParameter(PASSWORD_PARAM);
     String userId = null;
     if (login != null && password != null) {
-      userId = getValidUserId(login, password);
+      userId = LoginUtils.getValidUserId(new DalConnectionProvider(), login, password);
     } else { // use basic authentication
       userId = doBasicAuthentication(request);
     }
@@ -153,27 +150,7 @@
       }
       final String login = decodedUserPass.substring(0, index);
       final String password = decodedUserPass.substring(index + 1);
-      return getValidUserId(login, password);
-    } catch (final Exception e) {
-      throw new OBException(e);
-    }
-  }
-
-  private String getValidUserId(String login, String password) {
-    try {
-      final String encodedPwd = CryptoSHA1BASE64.hash(password);
-      // now search with the login and password
-      final Query qry = SessionHandler.getInstance().createQuery(
-          "select id from " + User.class.getName() + " where username=? and password=?");
-      qry.setParameter(0, login);
-      qry.setParameter(1, encodedPwd);
-      final List<?> list = qry.list();
-      Check.isTrue(list.size() == 0 || list.size() == 1, "Zero or one user expected for login "
-          + login + " but found " + list.size() + " users ");
-      if (list.size() == 0) {
-        return null;
-      }
-      return (String) list.get(0);
+      return LoginUtils.getValidUserId(new DalConnectionProvider(), login, password);
     } catch (final Exception e) {
       throw new OBException(e);
     }