Modified reports: Added filter accounting schema to manage ultiple accounting schemas
authorEduardo Argal <eduardo.argal@openbravo.com>
Mon, 18 Feb 2008 17:58:35 +0000
changeset 445 d13156fc5fa3
parent 444 7538424e9732
child 446 147b0eced864
Modified reports: Added filter accounting schema to manage ultiple accounting schemas
src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.html
src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.java
src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.xml
src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF.fo
src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF.xml
src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports_data.xsql
src/org/openbravo/erpCommon/ad_reports/ReportCashFlow.java
src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1.html
src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1.xml
src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_data.xsql
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger.html
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger.java
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.html
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.java
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.xml
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournalDetail.java
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournalDetail_data.xsql
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal_data.xsql
src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger_data.xsql
src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.html
src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.java
src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.xml
src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance_data.xsql
--- a/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.html	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.html	Mon Feb 18 17:58:35 2008 +0000
@@ -66,6 +66,10 @@
 		frm.inpOrganizacion.focus();
 		mensaje(1);
 		return false;
+	} else if (frm.inpcAcctSchemaId.value == ""){
+		frm.inpcAcctSchemaId.focus();
+		mensaje(1);
+		return false;
 	} else if (frm.inpcElementvalueId.value == ""){
 		frm.inpcElementvalueId.focus();
 		mensaje(1);
@@ -80,6 +84,7 @@
 
 function onloadFunctions() {
   new TypeAheadCombo("inpOrganizacion");
+  new TypeAheadCombo("inpcAcctSchemaId");  
   new TypeAheadCombo("inpcElementvalueId");
   new TypeAheadCombo("inpLevel");
 }
@@ -363,10 +368,11 @@
                   <TD class="Combo_ContentCell"> <SELECT name="inpLevel" id="inpLevel" class="ComboKey Combo_OneCell_width" onchange="logChanges(this);return true;">
                     <OPTION value=""></OPTION><DIV id="reportLevel"></DIV>
                   </SELECT></TD>
-                  <TD class="TitleCell"> </TD>
                   <TD class="ContentCell"></TD>
-                  <TD class="TitleCell"></TD>
-                  <TD class="ContentCell"></TD>
+				  <TD class="TitleCell"> <SPAN class="LabelText">Accounting schema</SPAN></TD>
+                  <TD class="Combo_ContentCell"> <SELECT name="inpcAcctSchemaId" id="inpcAcctSchemaId" class="ComboKey Combo_OneCell_width" onchange="submitCommandForm('DEFAULT',false,null,null,'_self');logChanges(this);return true;">
+                    <OPTION value=""></OPTION><DIV id="reportC_ACCTSCHEMA_ID"></DIV>
+                  </SELECT></TD>
                 </TR>
 
                 <TR>
--- a/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.java	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.java	Mon Feb 18 17:58:35 2008 +0000
@@ -19,6 +19,7 @@
 package org.openbravo.erpCommon.ad_reports;
 
 import org.openbravo.erpCommon.utility.*;
+import org.openbravo.erpCommon.ad_forms.AcctServerData;
 import org.openbravo.erpCommon.businessUtility.*;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
@@ -38,6 +39,7 @@
 
 
     if (vars.commandIn("DEFAULT")) {
+   	  String strcAcctSchemaId = vars.getGlobalVariable("inpcAcctSchemaId", "ReportGeneralLedger|cAcctSchemaId", "");	
       String strAgno = vars.getGlobalVariable("inpAgno", "GeneralAccountingReports|agno", "");
       String strAgnoRef = vars.getGlobalVariable("inpAgnoRef", "GeneralAccountingReports|agnoRef", "");
       String strDateFrom = vars.getGlobalVariable("inpDateFrom", "GeneralAccountingReports|dateFrom", "");
@@ -49,8 +51,9 @@
       String strConCodigo = vars.getGlobalVariable("inpConCodigo", "GeneralAccountingReports|conCodigo", "N");
       String strOrg = vars.getGlobalVariable("inpOrganizacion", "GeneralAccountingReports|organizacion", vars.getOrg());
       String strLevel = vars.getGlobalVariable("inpLevel", "GeneralAccountingReports|level", "");
-      printPageDataSheet(response, vars, strAgno, strAgnoRef, strDateFrom, strDateTo, strDateFromRef, strDateToRef, strElementValue, strConImporte, strOrg, strLevel, strConCodigo);
+      printPageDataSheet(response, vars, strAgno, strAgnoRef, strDateFrom, strDateTo, strDateFromRef, strDateToRef, strElementValue, strConImporte, strOrg, strLevel, strConCodigo, strcAcctSchemaId);
     } else if (vars.commandIn("FIND")) {
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportGeneralLedger|cAcctSchemaId");
       String strAgno = vars.getRequiredGlobalVariable("inpAgno", "GeneralAccountingReports|agno");
       String strAgnoRef = vars.getRequiredGlobalVariable("inpAgnoRef", "GeneralAccountingReports|agnoRef");
       String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "GeneralAccountingReports|dateFrom");
@@ -62,11 +65,11 @@
       String strConCodigo = vars.getRequestGlobalVariable("inpConCodigo", "GeneralAccountingReports|conCodigo");
       String strOrg = vars.getRequestGlobalVariable("inpOrganizacion", "GeneralAccountingReports|organizacion");
       String strLevel = vars.getRequestGlobalVariable("inpLevel", "GeneralAccountingReports|level");
-      printPagePDF(response, vars, strAgno, strAgnoRef, strDateFrom, strDateTo, strDateFromRef, strDateToRef, strElementValue, strConImporte, strOrg, strLevel, strConCodigo);
+      printPagePDF(response, vars, strAgno, strAgnoRef, strDateFrom, strDateTo, strDateFromRef, strDateToRef, strElementValue, strConImporte, strOrg, strLevel, strConCodigo, strcAcctSchemaId);
     } else pageError(response);
   }
 
-  void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String strAgno, String strAgnoRef, String strDateFrom, String strDateTo, String strDateFromRef, String strDateToRef, String strElementValue, String strConImporte, String strOrg, String strLevel, String strConCodigo) throws IOException,ServletException{
+  void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String strAgno, String strAgnoRef, String strDateFrom, String strDateTo, String strDateFromRef, String strDateToRef, String strElementValue, String strConImporte, String strOrg, String strLevel, String strConCodigo, String strcAcctSchemaId) throws IOException,ServletException{
     if (log4j.isDebugEnabled()) log4j.debug("Output: pdf");
     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF").createXmlDocument();
 
@@ -100,14 +103,14 @@
       } else {
         elements[i] = AccountTreeData.selectTrl(this, strConCodigo,vars.getLanguage(), TreeID );
       }
-      AccountTreeData[] accounts = AccountTreeData.selectAcct(this, Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), Tree.getMembers(this, strTreeOrg, strOrg), strAgno, strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strAgnoRef);
+      AccountTreeData[] accounts = AccountTreeData.selectAcct(this, Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strcAcctSchemaId, Tree.getMembers(this, strTreeOrg, strOrg), strAgno, strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strAgnoRef);
 
       {
-        String strIncomeSummary = GeneralAccountingReportsData.incomesummary(this, Utility.getContext(this, vars, "$C_ACCTSCHEMA_ID", "GeneralAccountingReports"));
+        String strIncomeSummary = GeneralAccountingReportsData.incomesummary(this, strcAcctSchemaId);
         if (log4j.isDebugEnabled()) log4j.debug("*********** strIncomeSummary: " + strIncomeSummary);
-        String strISyear = processIncomeSummary(strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAgno, strTreeOrg, strOrg);
+        String strISyear = processIncomeSummary(strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAgno, strTreeOrg, strOrg, strcAcctSchemaId);
         if (log4j.isDebugEnabled()) log4j.debug("*********** strISyear: " + strISyear);
-        String strISyearRef = processIncomeSummary(strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strAgnoRef, strTreeOrg, strOrg);
+        String strISyearRef = processIncomeSummary(strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strAgnoRef, strTreeOrg, strOrg, strcAcctSchemaId);
         if (log4j.isDebugEnabled()) log4j.debug("*********** strISyearRef: " + strISyearRef);
         accounts = appendRecords(accounts,   strIncomeSummary, strISyear, strISyearRef);
 
@@ -133,6 +136,7 @@
     xmlDocument.setParameter("agno2", strAgno);
     xmlDocument.setParameter("column", strAgno);
     xmlDocument.setParameter("columnRef", strAgnoRef);
+    xmlDocument.setParameter("org", AcctServerData.selectOrgName(this,strOrg));
     xmlDocument.setParameter("column1", strAgno);
     xmlDocument.setParameter("columnRef1", strAgnoRef);
     xmlDocument.setParameter("companyName", GeneralAccountingReportsData.companyName(this, vars.getClient()));
@@ -189,9 +193,9 @@
     return data2;
   }
 
-  String processIncomeSummary(String strDateFrom, String strDateTo, String strAgno, String strTreeOrg, String strOrg) throws ServletException, IOException {
-    String strISRevenue = GeneralAccountingReportsData.selectPyG(this, "R", strDateFrom, strDateTo, strAgno, Tree.getMembers(this, strTreeOrg, strOrg));
-    String strISExpense = GeneralAccountingReportsData.selectPyG(this, "E", strDateFrom, strDateTo, strAgno, Tree.getMembers(this, strTreeOrg, strOrg));
+  String processIncomeSummary(String strDateFrom, String strDateTo, String strAgno, String strTreeOrg, String strOrg, String strcAcctSchemaId) throws ServletException, IOException {
+    String strISRevenue = GeneralAccountingReportsData.selectPyG(this, "R", strDateFrom, strDateTo, strcAcctSchemaId, strAgno, Tree.getMembers(this, strTreeOrg, strOrg));
+    String strISExpense = GeneralAccountingReportsData.selectPyG(this, "E", strDateFrom, strDateTo, strcAcctSchemaId, strAgno, Tree.getMembers(this, strTreeOrg, strOrg));
     BigDecimal totalRevenue = new BigDecimal(strISRevenue);
     BigDecimal totalExpense = new BigDecimal(strISExpense);
     BigDecimal total = totalRevenue.add(totalExpense);
@@ -199,7 +203,7 @@
     return total.toString();
   }
 
-  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strAgno, String strAgnoRef, String strDateFrom, String strDateTo, String strDateFromRef, String strDateToRef, String strElementValue, String strConImporte, String strOrg, String strLevel, String strConCodigo) throws IOException, ServletException {
+  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strAgno, String strAgnoRef, String strDateFrom, String strDateTo, String strDateFromRef, String strDateToRef, String strElementValue, String strConImporte, String strOrg, String strLevel, String strConCodigo, String strcAcctSchemaId) throws IOException, ServletException {
     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/GeneralAccountingReports").createXmlDocument();
 
@@ -240,7 +244,7 @@
     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
     xmlDocument.setParameter("agno", strAgno);
     xmlDocument.setParameter("agnoRef", strAgnoRef);
-xmlDocument.setParameter("dateFrom", strDateFrom);
+    xmlDocument.setParameter("dateFrom", strDateFrom);
     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
     xmlDocument.setParameter("dateTo", strDateTo);
@@ -257,6 +261,8 @@
     xmlDocument.setParameter("organizacion", strOrg);
     xmlDocument.setParameter("C_ElementValue_ID", strElementValue);
     xmlDocument.setParameter("level", strLevel);
+    xmlDocument.setParameter("cAcctschemaId", strcAcctSchemaId);
+    xmlDocument.setData("reportC_ACCTSCHEMA_ID","liststructure",ReportGeneralLedgerData.selectC_ACCTSCHEMA_ID(this, Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), strcAcctSchemaId));
     try {
       ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "C_ElementValue level", "", Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), 0);
       Utility.fillSQLParameters(this, vars, null, comboTableData, "GeneralAccountingReports", "");
@@ -267,14 +273,15 @@
     }
 
     xmlDocument.setData("reportAD_ORGID", "liststructure", GeneralAccountingReportsData.selectCombo(this, vars.getRole()));
-    try {
+    xmlDocument.setData("reportC_ElementValue_ID","liststructure", GeneralAccountingReportsData.selectRpt(this, Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), strcAcctSchemaId));
+    /*try {
       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Acct_Rpt_ID", "", "", Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), 0);
       Utility.fillSQLParameters(this, vars, null, comboTableData, "GeneralAccountingReports", "");
       xmlDocument.setData("reportC_ElementValue_ID","liststructure", comboTableData.select(false));
       comboTableData = null;
     } catch (Exception ex) {
       throw new ServletException(ex);
-    }
+    }*/
 
 
     response.setContentType("text/html; charset=UTF-8");
--- a/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.xml	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports.xml	Mon Feb 18 17:58:35 2008 +0000
@@ -53,6 +53,7 @@
   <PARAMETER id="messageBoxID" name="messageType" attribute="class" replace="yy" default="HIDDEN"/>
   <PARAMETER id="messageBoxIDTitle" name="messageTitle" default=""/>
   <PARAMETER id="messageBoxIDMessage" name="messageMessage" default=""/>
+  <PARAMETER id="paramC_ACCTSCHEMA_ID" name="cAcctschemaId"/>  
 
   <SUBREPORT id="reportC_ElementValue_ID" name="reportC_ElementValue_ID" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="fieldC_ElementValue_ID"/>
@@ -63,4 +64,8 @@
   <SUBREPORT id="reportLevel" name="reportLevel" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramLevel"/>
   </SUBREPORT>
+
+	 <SUBREPORT id="reportC_ACCTSCHEMA_ID" name="reportC_ACCTSCHEMA_ID" report="org/openbravo/erpCommon/reference/List">
+	   <ARGUMENT name="parameterListSelected" withId="paramC_ACCTSCHEMA_ID"/>
+	</SUBREPORT>       
 </REPORT>
--- a/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF.fo	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF.fo	Mon Feb 18 17:58:35 2008 +0000
@@ -40,6 +40,8 @@
 							<fo:block font-size="10pt" text-align="left" padding-top="2pt">
 								<fo:inline font-weight="bold">Enterprise:&#160;&#160;</fo:inline>
 								<fo:inline id="fieldCompanyName">xx</fo:inline>&#160;&#160;<fo:inline id="fieldAgnoInitial"/>
+								<fo:inline font-weight="bold">Organization:&#160;&#160;</fo:inline>
+								<fo:inline id="fieldOrg">xx</fo:inline>
 							</fo:block>
 						</fo:table-cell>
 						<fo:table-cell>
--- a/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF.xml	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF.xml	Mon Feb 18 17:58:35 2008 +0000
@@ -35,6 +35,7 @@
   <PARAMETER id="fieldPeriodRef" name="periodRef" replaceCharacters="fo"/>
   <PARAMETER id="fieldAgnoInitial" name="agnoInitial" replaceCharacters="fo"/>
   <PARAMETER id="fieldAgnoRef" name="agnoRef" replaceCharacters="fo"/>
+  <PARAMETER id="fieldOrg" name="org" replaceCharacters="fo"/>
 
 
   <structure name="group">
--- a/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports_data.xsql	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/GeneralAccountingReports_data.xsql	Mon Feb 18 17:58:35 2008 +0000
@@ -38,6 +38,21 @@
         <Parameter name="rol"/>
    </SqlMethod>
    
+   <SqlMethod name="selectRpt" type="preparedStatement" return="multiple">
+      <SqlMethodComment></SqlMethodComment>
+      <Sql><![CDATA[
+		SELECT C_ACCT_RPT_ID AS ID, NAME 
+		FROM C_ACCT_RPT
+		WHERE AD_ORG_ID IN ('1')
+		AND AD_CLIENT_ID IN ('1')
+		AND 1=1
+		ORDER BY NAME
+      ]]></Sql>
+		<Parameter name="org" optional="true" type="replace" after="WHERE AD_ORG_ID IN (" text="'1'"/>      
+		<Parameter name="client" optional="true" type="replace" after="AND AD_CLIENT_ID IN (" text="'1'"/>      
+		<Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[ AND C_ACCT_RPT.C_ACCTSCHEMA_ID = TO_NUMBER(?)]]></Parameter>
+   </SqlMethod>
+   
     <SqlMethod name="selectGroups" type="preparedStatement" return="multiple">
       <SqlMethodComment></SqlMethodComment>
       <Sql><![CDATA[
@@ -172,6 +187,7 @@
         <Parameter name="accountType"/>
         <Parameter name="dateFrom" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.DATEACCT >= TO_DATE(?)]]></Parameter>
         <Parameter name="dateTo" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.DATEACCT < TO_DATE(?)]]></Parameter>
+        <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.C_ACCTSCHEMA_ID = TO_NUMBER(?)]]></Parameter>
         <Parameter name="year"/>
         <Parameter name="adOrgId" optional="true" type="replace" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'1'"/>
    </SqlMethod>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow.java	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow.java	Mon Feb 18 17:58:35 2008 +0000
@@ -52,20 +52,23 @@
     if (vars.commandIn("DEFAULT")) {
       printPage_FS(response, vars);
     } else if (vars.commandIn("FRAME1")) {
+      String strcAcctSchemaId = vars.getGlobalVariable("inpcAcctSchemaId", "ReportCashFlow|cAcctSchemaId", "");      
       String strAccountingReportId = vars.getGlobalVariable("inpAccountingReportId", "ReportCashFlow|accountingReport", "");
       String strOrg = vars.getGlobalVariable("inpadOrgId", "ReportCashFlow|orgId", "0");
       String strPeriod = vars.getGlobalVariable("inpPeriodId", "ReportCashFlow|period", "");
-      printPageFrame1(response, vars, strAccountingReportId, strOrg, strPeriod, process);
+      printPageFrame1(response, vars, strcAcctSchemaId, strAccountingReportId, strOrg, strPeriod, process);
     } else if (vars.commandIn("DEPURAR")){
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportCashFlow|cAcctSchemaId");
       String strAccountingReportId = vars.getRequestGlobalVariable("inpAccountingReportId", "ReportCashFlow|accountingReport");
       String strOrg = vars.getGlobalVariable("inpadOrgId", "ReportCashFlow|orgId", "0");
       String strPeriod = vars.getRequestGlobalVariable("inpPeriodId", "ReportCashFlow|period");
-      printPageDepurar(response, vars, strAccountingReportId, strOrg, strPeriod, process);
+      printPageDepurar(response, vars, strcAcctSchemaId, strAccountingReportId, strOrg, strPeriod, process);
     } else if (vars.commandIn("FIND")){
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportCashFlow|cAcctSchemaId");
       String strAccountingReportId = vars.getRequestGlobalVariable("inpAccountingReportId", "ReportCashFlow|accountingReport");
       String strOrg = vars.getGlobalVariable("inpadOrgId", "ReportCashFlow|orgId", "0");
       String strPeriod = vars.getRequestGlobalVariable("inpPeriodId", "ReportCashFlow|period");
-      printPagePopUp(response, vars, strAccountingReportId, strOrg, strPeriod, process);
+      printPagePopUp(response, vars, strcAcctSchemaId, strAccountingReportId, strOrg, strPeriod, process);
     } else pageErrorPopUp(response);
   }
 
@@ -78,7 +81,7 @@
     out.close();
   }
 
-void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strAccountingReportId, String strOrg, String strPeriod, String strProcessId) throws IOException, ServletException {
+void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strcAcctSchemaId, String strAccountingReportId, String strOrg, String strPeriod, String strProcessId) throws IOException, ServletException {
       if (log4j.isDebugEnabled()) log4j.debug("Output: printPage ReportCashFlow_F1");
       
       ActionButtonDefaultData[] data = null;
@@ -90,11 +93,12 @@
       }
       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1").createXmlDocument();
 
-      String strArray = arrayEntry(vars);
+      String strArray = arrayEntry(vars, strcAcctSchemaId);
 
       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
       xmlDocument.setParameter("help", strHelp);
+      xmlDocument.setParameter("cAcctschemaId", strcAcctSchemaId);    
       xmlDocument.setParameter("accounting", strAccountingReportId);
       xmlDocument.setParameter("org", strOrg);
       xmlDocument.setParameter("period", strPeriod);
@@ -109,10 +113,12 @@
         throw new ServletException(ex);
       }
 
-      xmlDocument.setData("reportAD_ACCOUNTINGRPT_ELEMENT", "liststructure", ReportCashFlowData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), ""));
+      xmlDocument.setData("reportAD_ACCOUNTINGRPT_ELEMENT", "liststructure", ReportCashFlowData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), "", strcAcctSchemaId));
 
       xmlDocument.setData("reportPeriod", "liststructure", ReportCashFlowData.selectCombo(this, Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), vars.getLanguage()));
 
+      xmlDocument.setData("reportC_ACCTSCHEMA_ID", "liststructure", ReportGeneralLedgerData.selectC_ACCTSCHEMA_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), strcAcctSchemaId));    
+
       ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportCashFlow", false, "", "", "",false, "ad_reports",  strReplaceWith, false,  true);
       toolbar.prepareSimpleToolBarTemplate();
       xmlDocument.setParameter("toolbar", toolbar.toString());
@@ -154,7 +160,7 @@
       out.close();
     }
 
-void printPagePopUp (HttpServletResponse response, VariablesSecureApp vars, String strAccountingReportId, String strOrg, String strPeriod, String process) throws IOException, ServletException {
+void printPagePopUp (HttpServletResponse response, VariablesSecureApp vars, String strcAcctSchemaId, String strAccountingReportId, String strOrg, String strPeriod, String process) throws IOException, ServletException {
       if (log4j.isDebugEnabled()) log4j.debug("Output: pop up ReportCashFlow");
       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportCashFlowPopUp").createXmlDocument();
       String strPeriodFrom = "";
@@ -182,7 +188,7 @@
 
       Vector<Object> vectorArray = new Vector<Object>();
 
-      childData(vars, vectorArray, strAccountingReportId, strPeriodFrom, strPeriodTo, strTreeOrg, level, "0");
+      childData(vars, vectorArray, strcAcctSchemaId, strAccountingReportId, strPeriodFrom, strPeriodTo, strTreeOrg, level, "0");
 
       ReportCashFlowData[] dataTree = convertVector(vectorArray);
       dataTree = filterData(dataTree);
@@ -199,7 +205,7 @@
       out.close();
 }
 
-void printPageDepurar (HttpServletResponse response, VariablesSecureApp vars, String strAccountingReportId, String strOrg, String strPeriod, String process) throws IOException, ServletException {
+void printPageDepurar (HttpServletResponse response, VariablesSecureApp vars, String strcAcctSchemaId, String strAccountingReportId, String strOrg, String strPeriod, String process) throws IOException, ServletException {
       if (log4j.isDebugEnabled()) log4j.debug("Output: ReportCashFlow_F0");
       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportCashFlow_F0").createXmlDocument();
       String strPeriodFrom = "";
@@ -224,7 +230,7 @@
       strTreeOrg = strOrg;
       treeOrg(vars, strOrg);
 
-      ReportCashFlowData [] data = ReportCashFlowData.selectMissingEntries(this, Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), strPeriodFrom, strPeriodTo, vars.getClient());
+      ReportCashFlowData [] data = ReportCashFlowData.selectMissingEntries(this, Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), strcAcctSchemaId, strPeriodFrom, strPeriodTo, vars.getClient());
       if (log4j.isDebugEnabled()) log4j.debug("printPageDepurar - data.length: " + data.length);
       if (log4j.isDebugEnabled()) log4j.debug("printPageDepurar - #User_Client: " + Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"));
       if (log4j.isDebugEnabled()) log4j.debug("printPageDepurar - #User_Org: " + Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"));
@@ -259,9 +265,9 @@
 }
 
 
-String arrayEntry(VariablesSecureApp vars) throws ServletException{
+String arrayEntry(VariablesSecureApp vars, String strcAcctSchemaId) throws ServletException{
       String result = "";
-      ReportCashFlowData[] data = ReportCashFlowData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), "");
+      ReportCashFlowData[] data = ReportCashFlowData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), "", strcAcctSchemaId);
       if (data == null || data.length == 0) {
         result = "var array = null;";
       } else {
@@ -297,15 +303,15 @@
       return;
 }
 
-void childData(VariablesSecureApp vars, Vector<Object> vectorArray, String strAccountingReportId, String strPeriodFrom, String strPeriodTo, String strOrg, int level, String strParent) throws IOException, ServletException{
+void childData(VariablesSecureApp vars, Vector<Object> vectorArray, String strcAcctSchemaId, String strAccountingReportId, String strPeriodFrom, String strPeriodTo, String strOrg, int level, String strParent) throws IOException, ServletException{
       if (log4j.isDebugEnabled()) log4j.debug("Ouput: child tree data");
       String strAccountId = ReportCashFlowData.selectAccounting(this, strAccountingReportId);
-      ReportCashFlowData[] data = ReportCashFlowData.select(this, strParent, String.valueOf(level), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), strOrg, strPeriodFrom, strPeriodTo, strAccountId, strAccountingReportId);
+      ReportCashFlowData[] data = ReportCashFlowData.select(this, strParent, String.valueOf(level), Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), strOrg, strPeriodFrom, strPeriodTo, strAccountId, strAccountingReportId, strcAcctSchemaId);
       if (data == null || data.length == 0) data = ReportCashFlowData.set();
       vectorArray.addElement(data[0]);
       ReportCashFlowData[] dataAux = ReportCashFlowData.selectChild(this, Utility.getContext(this, vars, "#User_Client", "ReportCashFlow"), Utility.getContext(this, vars, "#User_Org", "ReportCashFlow"), data[0].id, ReportCashFlowData.selectTree(this, vars.getClient()));
       for (int i = 0; i<dataAux.length; i++){
-          childData(vars, vectorArray, dataAux[i].id, strPeriodFrom, strPeriodTo, strOrg, level+1, data[0].id);
+          childData(vars, vectorArray, strcAcctSchemaId, dataAux[i].id, strPeriodFrom, strPeriodTo, strOrg, level+1, data[0].id);
       }
 }
 
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1.html	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1.html	Mon Feb 18 17:58:35 2008 +0000
@@ -71,6 +71,11 @@
     }
   }
   rellenarCombo(frm.inpPeriodId, arrayCombo, false, false);
+	if (frm.inpcAcctSchemaId.value == null || frm.inpcAcctSchemaId.value == "") {
+		frm.inpcAcctSchemaId.focus();
+		mensaje(7);
+		return false;
+	}
   return true;
 }
 function displayCombos(){
@@ -90,7 +95,7 @@
 }
 </SCRIPT>
 </HEAD>
-<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="setFocusFirstControl();displayCombos();resizeArea();updateMenuIcon('buttonMenu');setFocusFirstControl();" onresize="resizeArea();">
+<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="focoPrimerControl();displayCombos();resizeArea();updateMenuIcon('buttonMenu');focoPrimerControl();" onresize="resizeArea();">
 <FORM id="form" method="POST" action="ReportCashFlow_F1.html" name="frmMain">
   <INPUT type="hidden" name="Command">
 <INPUT type="hidden" name="IsPopUpCall" value="1"></INPUT>
@@ -252,6 +257,15 @@
 			</select>
 		</td>
 	</tr>
+	<tr>
+		<td class="TitleCell"><span class="LabelText">Account schema&nbsp;</span></td>
+		<td class="Combo_ContentCell" colspan="2">
+			<select class="ComboKey Combo_TwoCells_width" name="inpcAcctSchemaId" id="inpcAcctSchemaId" onChange="submitCommandForm('FRAME1');return false;">
+				<option value=""></option>
+				<DIV id="reportC_ACCTSCHEMA_ID"></DIV>
+			</select>
+		</td>
+	</tr>
 	<tr id="selEliminarPeriod">
 		<td class="TitleCell"><span class="LabelText">Period&nbsp;</span></td>
 		<td class="Combo_ContentCell">
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1.xml	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_F1.xml	Mon Feb 18 17:58:35 2008 +0000
@@ -39,11 +39,15 @@
   <PARAMETER id="paramPeriod" name="period" default=""/>
   <PARAMETER id="paramArray" name="array" default=""/>
   <PARAMETER id="paramToolBar" name="toolbar" default=""/>
+  <PARAMETER id="paramC_ACCTSCHEMA_ID" name="cAcctschemaId"/>
 
 
     <SUBREPORT id="reportAD_ACCOUNTINGRPT_ELEMENT" name="reportAD_ACCOUNTINGRPT_ELEMENT" report="org/openbravo/erpCommon/reference/List">
       <ARGUMENT name="parameterListSelected" withId="paramAccountingrptElementId"/>
     </SUBREPORT>
+    <SUBREPORT id="reportC_ACCTSCHEMA_ID" name="reportC_ACCTSCHEMA_ID" report="org/openbravo/erpCommon/reference/List">
+      <ARGUMENT name="parameterListSelected" withId="paramC_ACCTSCHEMA_ID"/>
+    </SUBREPORT>
     <SUBREPORT id="reportAD_ORG" name="reportAD_ORG" report="/org/openbravo/erpCommon/reference/List">
       <ARGUMENT name="paramterListSelected" widthId="paramOrgId"/>
     </SUBREPORT>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_data.xsql	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashFlow_data.xsql	Mon Feb 18 17:58:35 2008 +0000
@@ -40,6 +40,7 @@
           WHERE AD_TREE.AD_TREE_ID = AD_TREENODE.AD_TREE_ID      
           AND AD_TREENODE.NODE_ID = AR.AD_ACCOUNTINGRPT_ELEMENT_ID      
           AND AR.AD_ACCOUNTINGRPT_ELEMENT_ID = TO_NUMBER(?)
+          AND A.C_ACCTSCHEMA_ID = TO_NUMBER(?)
           AND AD_TREE.TREETYPE = 'AR'      
           GROUP BY REPORT_TYPE, AR.AD_ACCOUNTINGRPT_ELEMENT_ID, AR.NAME, AR.DESCRIPTION, AR.ISSUMMARY, AR.ISSHOWN, 
           AD_TREENODE.NODE_ID,       
@@ -55,7 +56,8 @@
     <Parameter name="periodFrom" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.DATEACCT >= TO_DATE(?)]]></Parameter>
     <Parameter name="periodTo" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.DATEACCT < TO_DATE(?)]]></Parameter>
     <Parameter name="accountId" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT_CFS.ACCOUNT_ID = TO_NUMBER(?)]]></Parameter>
-    <Parameter name="adAccountingElementId"/>
+    <Parameter name="adAccountingElementId"/>    
+    <Parameter name="acctschema"/>
   </SqlMethod>
 
   <SqlMethod name="selectMissingEntries" type="preparedStatement" return="multiple">
@@ -76,6 +78,7 @@
     </Sql>
     <Parameter name="adClientId" optional="true" type="replace" after="FACT_ACCT.AD_CLIENT_ID IN (" text="'1'"/>
     <Parameter name="adOrgId" optional="true" type="replace" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'1'"/>
+    <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.C_ACCTSCHEMA_ID = TO_NUMBER(?)]]></Parameter>
     <Parameter name="periodFrom" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.DATEACCT >= TO_DATE(?)]]></Parameter>
     <Parameter name="periodTo" optional="true" after="AND 1=1"><![CDATA[ AND FACT_ACCT.DATEACCT < TO_DATE(?)]]></Parameter>
     <Parameter name="currentClient"/>
@@ -220,11 +223,13 @@
       AND AD_CLIENT_ID IN ('1')
       AND ISREPORT='Y'
       AND (isActive = 'Y' OR AD_ACCOUNTINGRPT_ELEMENT_ID = TO_NUMBER(?) )
+      AND 1=1
       ]]>
     </Sql>
     <Parameter name="adOrgClient" type="replace" optional="true" after="WHERE AD_ORG_ID IN (" text="'1'"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="AND AD_CLIENT_ID IN (" text="'1'"/>
     <Parameter name="adAccountingrptElementId"/>
+    <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[ AND C_ACCTSCHEMA_ID = TO_NUMBER(?)]]></Parameter>
   </SqlMethod>
 
   <SqlMethod name="selectType" type="preparedStatement" return="string">
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger.html	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger.html	Mon Feb 18 17:58:35 2008 +0000
@@ -63,6 +63,11 @@
 	return true;
 }
 
+function CALLOUT_ELEMENTVALUE() {
+submitCommandForm('DEFAULT');
+return true;
+}
+
 function depurar(){
 	var frm = document.frmMain;
 	if (frm.inpDateFrom.value == null || frm.inpDateFrom.value == "") {
@@ -73,6 +78,10 @@
 		frm.inpDateTo.focus();
 		mensaje(7);
 		return false;
+	} else if (frm.inpcAcctSchemaId.value == null || frm.inpcAcctSchemaId.value == ""){
+		frm.inpcAcctSchemaId.focus();
+		mensaje(7);
+		return false;
 	}
 	seleccionarListCompleto(frm.inpcBPartnerId_IN);
 	return true;
@@ -81,7 +90,8 @@
 function onloadFunctions() {
   new TypeAheadCombo("inpcElementValueIdFrom");
    new TypeAheadCombo("inpcElementValueIdTo");
-	new TypeAheadCombo("inpOrg");
+	new TypeAheadCombo("inpOrg");	
+	new TypeAheadCombo("inpcAcctSchemaId");
 }
 </SCRIPT>
 </HEAD>
@@ -289,6 +299,13 @@
               <TD class="ContentCell"></TD>
             </TR>
             <TR>
+              <TD class="TitleCell"> <SPAN class="LabelText">Accounting schema</SPAN></TD>
+              <TD class="Combo_ContentCell" colspan="2"> <SELECT name="inpcAcctSchemaId" id="inpcAcctSchemaId" class="ComboKey Combo_TwoCells_width" onchange="CALLOUT_ELEMENTVALUE()">
+                  <OPTION value=""> <DIV id="reportC_ACCTSCHEMA_ID"></DIV></OPTION>
+                </SELECT>
+              </TD>
+            </TR>
+            <TR>
               <TD class="TitleCell"> <SPAN class="LabelText">From Account</SPAN></TD>
               <TD class="Combo_ContentCell" colspan="2"> <SELECT name="inpcElementValueIdFrom" id="inpcElementValueIdFrom" class="Combo Combo_TwoCells_width">
                   <OPTION value=""> <DIV id="reportC_ELEMENTVALUEFROM"></DIV></OPTION>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger.java	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger.java	Mon Feb 18 17:58:35 2008 +0000
@@ -249,7 +249,7 @@
     }
 
     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
-    xmlDocument.setData("reportAD_ORGID", "liststructure", OrganizationComboData.selectCombo(this, vars.getRole()));
+    xmlDocument.setData("reportAD_ORGID", "liststructure", GeneralAccountingReportsData.selectCombo(this, vars.getRole()));
     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
     xmlDocument.setParameter("cElementValueFrom", strcelementvaluefrom);
@@ -267,8 +267,8 @@
     xmlDocument.setParameter("paramAll0", strAll.equals("")?"0":"1");
     xmlDocument.setParameter("paramHide0", strHide.equals("")?"0":"1");
     xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportRefundInvoiceCustomerDimensionalAnalysesData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), strcBpartnerIdAux));
-    xmlDocument.setData("reportC_ELEMENTVALUEFROM","liststructure",ReportGeneralLedgerData.selectC_ElementValue_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), strcelementvaluefrom));
-    xmlDocument.setData("reportC_ELEMENTVALUETO","liststructure",ReportGeneralLedgerData.selectC_ElementValue_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), strcelementvaluefrom));
+    xmlDocument.setData("reportC_ELEMENTVALUEFROM","liststructure",ReportGeneralLedgerData.selectC_ElementValue_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), strcelementvaluefrom, strcAcctSchemaId));
+    xmlDocument.setData("reportC_ELEMENTVALUETO","liststructure",ReportGeneralLedgerData.selectC_ElementValue_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), strcelementvaluefrom, strcAcctSchemaId));
     xmlDocument.setData("reportC_ACCTSCHEMA_ID","liststructure",ReportGeneralLedgerData.selectC_ACCTSCHEMA_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), strcAcctSchemaId));
     
      if (log4j.isDebugEnabled()) log4j.debug("data.length: "+data.length);
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.html	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.html	Mon Feb 18 17:58:35 2008 +0000
@@ -255,7 +255,7 @@
             <TR>
               <TD class="TitleCell"> <SPAN class="LabelText">Organization</SPAN></TD>
               <TD class="Combo_ContentCell" colspan="2"> <SELECT  name="inpOrg" id="inpOrg" class="Combo Combo_TwoCells_width">
-                  <OPTION value=""> <DIV id="reportAD_ORGID"></DIV></OPTION>
+                 <DIV id="reportAD_ORGID"></DIV>
                 </SELECT></TD>
               <TD class="TitleCell"> <SPAN class="LabelText">Document</SPAN></TD>
               <TD class="Combo_ContentCell" colspan="2"> <SELECT  name="inpDocument" id="inpDocument" class="Combo Combo_TwoCells_width">
@@ -263,6 +263,12 @@
                 </SELECT></TD>
             </TR>
             <TR>
+              <TD class="TitleCell"> <SPAN class="LabelText">Accounting schema</SPAN></TD>
+              <TD class="Combo_ContentCell" colspan="2"> <SELECT  name="inpcAcctSchemaId" id="inpcAcctSchemaId" class="Combo Combo_TwoCells_width">
+                  <OPTION value=""> <DIV id="reportC_ACCTSCHEMA_ID"></DIV></OPTION>
+                </SELECT></TD>
+            </TR>
+            <TR>
               <td colspan="6">
                 <table class="FieldGroup" cellspacing="0" cellpadding="0" border="0">
                 <tbody>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.java	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.java	Mon Feb 18 17:58:35 2008 +0000
@@ -31,6 +31,7 @@
 
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.ComboTableData;
+import org.openbravo.erpCommon.utility.Utility;
 
 
 import java.util.*;
@@ -44,6 +45,7 @@
     if (log4j.isDebugEnabled()) log4j.debug("Command: "+vars.getStringParameter("Command"));
 
     if (vars.commandIn("DEFAULT")) {
+      String strcAcctSchemaId = vars.getGlobalVariable("inpcAcctSchemaId", "ReportGeneralLedger|cAcctSchemaId", "");
       String strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportGeneralLedgerJournal|DateFrom", "");
       String strDateTo = vars.getGlobalVariable("inpDateTo", "ReportGeneralLedgerJournal|DateTo", "");
       String strDocument = vars.getGlobalVariable("inpDocument", "ReportGeneralLedgerJournal|Document", "");
@@ -52,28 +54,30 @@
      // String strTable = vars.getGlobalVariable("inpTable", "ReportGeneralLedgerJournal|Table");
       String strTable = vars.getStringParameter("inpTable");
       String strRecord = vars.getStringParameter("inpRecord");
-      printPageDataSheet(response, vars, strDateFrom, strDateTo, strDocument, strOrg, strTable, strRecord, "");
+      printPageDataSheet(response, vars, strDateFrom, strDateTo, strDocument, strOrg, strTable, strRecord, "", strcAcctSchemaId);
     } else if (vars.commandIn("DIRECT")) {
       String strTable = vars.getGlobalVariable("inpTable", "ReportGeneralLedgerJournal|Table");
       String strRecord = vars.getGlobalVariable("inpRecord", "ReportGeneralLedgerJournal|Record");
       setHistoryCommand(request, "DIRECT");
       vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0");
-      printPageDataSheet(response, vars, "", "", "", "", strTable, strRecord, "");
+      printPageDataSheet(response, vars, "", "", "", "", strTable, strRecord, "","");
     } else if (vars.commandIn("DIRECT2")) {
       String strFactAcctGroupId = vars.getGlobalVariable("inpFactAcctGroupId", "ReportGeneralLedgerJournal|FactAcctGroupId");
       setHistoryCommand(request, "DIRECT2");
       vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0");
-      printPageDataSheet(response, vars, "", "", "", "", "", "", strFactAcctGroupId);
+      printPageDataSheet(response, vars, "", "", "", "", "", "", strFactAcctGroupId, "");
     } else if (vars.commandIn("FIND")) {
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportGeneralLedger|cAcctSchemaId");
       String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportGeneralLedgerJournal|DateFrom");
       String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportGeneralLedgerJournal|DateTo");
       String strDocument = vars.getRequestGlobalVariable("inpDocument", "ReportGeneralLedgerJournal|Document");
       String strOrg = vars.getGlobalVariable("inpOrg", "ReportGeneralLedgerJournal|Org","0");
       vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0");
       setHistoryCommand(request, "DEFAULT");
-      printPageDataSheet(response, vars, strDateFrom, strDateTo, strDocument, strOrg, "", "", "");
+      printPageDataSheet(response, vars, strDateFrom, strDateTo, strDocument, strOrg, "", "", "", strcAcctSchemaId);
     } else if (vars.commandIn("PDF","XLS")) {
       if (log4j.isDebugEnabled()) log4j.debug("PDF");
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportGeneralLedger|cAcctSchemaId");
       String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportGeneralLedgerJournal|DateFrom");
       String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportGeneralLedgerJournal|DateTo");
       String strDocument = vars.getRequestGlobalVariable("inpDocument", "ReportGeneralLedgerJournal|Document");
@@ -84,7 +88,7 @@
       String strRecord = vars.getStringParameter("inpRecord");
       vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0");
       setHistoryCommand(request, "DEFAULT");
-      printPagePDF(response, vars, strDateFrom, strDateTo, strDocument, strOrg, strTable, strRecord, "");
+      printPagePDF(response, vars, strDateFrom, strDateTo, strDocument, strOrg, strTable, strRecord, "", strcAcctSchemaId);
     }else if (vars.commandIn("PREVIOUS_RELATION")) {
       String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournal.initRecordNumber");
       String strRecordRange = Utility.getContext(this, vars, "#RecordRange", "ReportGeneralLedgerJournal");
@@ -110,7 +114,7 @@
     } else pageError(response);
   }
 
-  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strDocument, String strOrg, String strTable, String strRecord, String strFactAcctGroupId) throws IOException, ServletException {
+  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strDocument, String strOrg, String strTable, String strRecord, String strFactAcctGroupId, String strcAcctSchemaId) throws IOException, ServletException {
 	String  strRecordRange="500";
     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
     String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournal.initRecordNumber");
@@ -126,8 +130,8 @@
       String strTreeOrg = ReportGeneralLedgerJournalData.treeOrg(this, vars.getClient());
       String strOrgFamily = getFamily(strTreeOrg, strOrg);
       if (strRecord.equals("")) {
-        data = ReportGeneralLedgerJournalData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily, initRecordNumber, intRecordRange);
-        if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCount(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily, data[0].dateacct, data[0].identifier);
+        data = ReportGeneralLedgerJournalData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strcAcctSchemaId, strOrgFamily, initRecordNumber, intRecordRange);
+        if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCount(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strcAcctSchemaId, strOrgFamily, data[0].dateacct, data[0].identifier);
       } else {
    	    data = ReportGeneralLedgerJournalData.selectDirect(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strTable, strRecord, initRecordNumber, intRecordRange);
         if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCountDirect(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"),strTable, strRecord, data[0].dateacct, data[0].identifier);        
@@ -140,10 +144,11 @@
       if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCountDirect2(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"),strFactAcctGroupId, data[0].dateacct, data[0].identifier);
     }
     if (data==null || data.length==0) {
-      //String discard[]={"sectionJournal", "hasPrevious", "hasNext"};
+      String discard[]={"sectionDateAcct"};
       toolbar.prepareRelationBarTemplate(false, false,"submitCommandForm('XLS', false, null, 'ReportGeneralLedgerJournal.xls', 'EXCEL');return false;");
-      xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal").createXmlDocument();
-      data = ReportGeneralLedgerJournalData.set();
+      xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal", discard).createXmlDocument();
+      data = ReportGeneralLedgerJournalData.set("0");
+      data[0].rownum = "0";
     } else {
       /*  String[] discard = {"withoutPrevious", "withoutNext"};
           if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String("hasPrevious");
@@ -195,7 +200,9 @@
 
     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
     xmlDocument.setParameter("document", strDocument);
-    xmlDocument.setData("reportAD_ORGID", "liststructure", OrganizationComboData.selectCombo(this, vars.getRole()));
+    xmlDocument.setParameter("cAcctschemaId", strcAcctSchemaId);
+    xmlDocument.setData("reportAD_ORGID", "liststructure", GeneralAccountingReportsData.selectCombo(this, vars.getRole()));
+    xmlDocument.setData("reportC_ACCTSCHEMA_ID","liststructure",ReportGeneralLedgerData.selectC_ACCTSCHEMA_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), strcAcctSchemaId));
     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
     xmlDocument.setParameter("dateFrom", strDateFrom);
@@ -213,7 +220,7 @@
     out.close();
   }
 
-  void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strDocument, String strOrg, String strTable, String strRecord, String strFactAcctGroupId) throws IOException, ServletException {
+  void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strDocument, String strOrg, String strTable, String strRecord, String strFactAcctGroupId, String strcAcctSchemaId) throws IOException, ServletException {
 
     ReportGeneralLedgerJournalData[] data=null;
 
@@ -221,7 +228,7 @@
     String strOrgFamily = getFamily(strTreeOrg, strOrg);
     
     if (strRecord.equals("")) 
-      data = ReportGeneralLedgerJournalData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily);
+      data = ReportGeneralLedgerJournalData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strcAcctSchemaId, strOrgFamily);
     else 
       data = ReportGeneralLedgerJournalData.selectDirect(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strTable, strRecord);
     
@@ -241,7 +248,7 @@
 
   
   public String getFamily(String strTree, String strChild) throws IOException, ServletException {
-    return Tree.getMembers(this, strTree, strChild);
+    return Tree.getMembers(this, strTree, (strChild==null||strChild.equals(""))?"0":strChild);
     /*    ReportGeneralLedgerData [] data = ReportGeneralLedgerData.selectChildren(this, strTree, strChild);
           String strFamily = "";
           if(data!=null && data.length>0) {
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.xml	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.xml	Mon Feb 18 17:58:35 2008 +0000
@@ -44,7 +44,7 @@
   <PARAMETER id="messageBoxIDMessage" name="messageMessage" default=""/>
   <PARAMETER id="inpRecord" name="paramRecord" attribute="value" default=""/>
   <PARAMETER id="inpTable" name="paramTable" attribute="value" default=""/>
-  
+  <PARAMETER id="paramC_ACCTSCHEMA_ID" name="cAcctschemaId"/>
 
   <SUBREPORT id="reportDocument" name="reportDocument" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramDocument"/>
@@ -53,6 +53,10 @@
     <ARGUMENT name="parameterListSelected" withId="paramAD_ORGID"/>
   </SUBREPORT>
 
+     <SUBREPORT id="reportC_ACCTSCHEMA_ID" name="reportC_ACCTSCHEMA_ID" report="org/openbravo/erpCommon/reference/List">
+      <ARGUMENT name="parameterListSelected" withId="paramC_ACCTSCHEMA_ID"/>
+    </SUBREPORT>
+
   <PARAMETER id="param2" name="param2" default="2"/>
 
   <structure name="structure1">
@@ -75,4 +79,5 @@
     <SECTION id="sectionJournal" field="identifier"/>
     <SECTION id="sectionDetail"/>
   </structure>
+  <DISCARD id="discard"/>
 </REPORT>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournalDetail.java	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournalDetail.java	Mon Feb 18 17:58:35 2008 +0000
@@ -36,15 +36,17 @@
 
     if (vars.commandIn("DEFAULT")) {
       String strFactAcctGroupId = vars.getStringParameter("inpFactAcctGroupId");
-      printPageDataSheet(response, vars, strFactAcctGroupId, "",null);
+      printPageDataSheet(response, vars, strFactAcctGroupId, "",null, "");
     } else if (vars.commandIn("DIRECT")) {
       String strFactAcctGroupId = vars.getStringParameter("inpFactAcctGroupId");
       String strDateAcct = getValue(strFactAcctGroupId,0);
       strFactAcctGroupId = getValue(strFactAcctGroupId,1);
-      printPageDataSheet(response, vars, strFactAcctGroupId, strDateAcct, null);
+      printPageDataSheet(response, vars, strFactAcctGroupId, strDateAcct, null, "");
     } else if (vars.commandIn("DP")) {
       String strDPId = vars.getStringParameter("inpDPid");
-      printPageDataSheet(response, vars, null, null, strDPId);     
+      String strcAcctSchemaId = getValue(strDPId,0);
+      strDPId = getValue(strDPId,1);
+      printPageDataSheet(response, vars, null, null, strDPId, strcAcctSchemaId);     
     } else if (vars.commandIn("PREVIOUS_RELATION")) {
       String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournalDetail.initRecordNumber");
       String strRecordRange = Utility.getContext(this, vars, "#RecordRange", "ReportGeneralLedgerJournalDetail");
@@ -70,7 +72,7 @@
     } else pageError(response);
   }
 
-  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strFactAcctGroupId, String strDateacct, String strDPId) throws IOException, ServletException {
+  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strFactAcctGroupId, String strDateacct, String strDPId, String strcAcctSchemaId) throws IOException, ServletException {
     String strRecordRange = Utility.getContext(this, vars, "#RecordRange", "ReportGeneralLedgerJournalDetail");
     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
     String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournalDetail.initRecordNumber");
@@ -86,7 +88,7 @@
     if (strDPId==null) 
       data = ReportGeneralLedgerJournalDetailData.select(this, strFactAcctGroupId, strDateacct, initRecordNumber, intRecordRange);
     else
-      data = ReportGeneralLedgerJournalDetailData.selectByDP(this, strDPId);
+      data = ReportGeneralLedgerJournalDetailData.selectByDP(this, strDPId, strcAcctSchemaId);
 
 
     // if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String("hasPrevious");
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournalDetail_data.xsql	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournalDetail_data.xsql	Mon Feb 18 17:58:35 2008 +0000
@@ -28,11 +28,11 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
     <![CDATA[
-        SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT, F.RECORD_ID2 AS DP, (CASE WHEN RECORD_ID2 IS NULL THEN 'none' END) AS DISPLAY1, (CASE WHEN RECORD_ID2 IS NOT NULL THEN 'none' END) AS DISPLAY2, 
+        SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT, F.C_ACCTSCHEMA_ID || '/' ||F.RECORD_ID2 AS DP, (CASE WHEN RECORD_ID2 IS NULL THEN 'none' END) AS DISPLAY1, (CASE WHEN RECORD_ID2 IS NOT NULL THEN 'none' END) AS DISPLAY2, 
         F.ACCTVALUE AS VALUE, F.ACCTDESCRIPTION AS NAME,
         (CASE F.AMTACCTDR WHEN 0 THEN NULL ELSE F.AMTACCTDR END) AS AMTACCTDR, (CASE F.AMTACCTCR WHEN 0 THEN NULL ELSE F.AMTACCTCR END) AS AMTACCTCR, F.DESCRIPTION
         FROM FACT_ACCT F
-        WHERE FACT_ACCT_GROUP_ID = TO_NUMBER(?)
+        WHERE FACT_ACCT_GROUP_ID = ?
         AND (DATEACCT = TO_DATE(?) OR TO_DATE(?) = NULL)
         ORDER BY F.FACT_ACCT_GROUP_ID, F.SEQNO
       ]]></Sql>
@@ -46,17 +46,19 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
     <![CDATA[
-        SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT, F.RECORD_ID2 AS DP, (CASE WHEN RECORD_ID2 IS NULL THEN 'none' END) AS DISPLAY1, (CASE WHEN RECORD_ID2 IS NOT NULL THEN 'none' END) AS DISPLAY2, 
+        SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT, F.C_ACCTSCHEMA_ID || '/' ||F.RECORD_ID2 AS DP, (CASE WHEN RECORD_ID2 IS NULL THEN 'none' END) AS DISPLAY1, (CASE WHEN RECORD_ID2 IS NOT NULL THEN 'none' END) AS DISPLAY2, 
         F.ACCTVALUE AS VALUE, F.ACCTDESCRIPTION AS NAME,
         (CASE F.AMTACCTDR WHEN 0 THEN NULL ELSE F.AMTACCTDR END) AS AMTACCTDR, (CASE F.AMTACCTCR WHEN 0 THEN NULL ELSE F.AMTACCTCR END) AS AMTACCTCR, F.DESCRIPTION
         FROM FACT_ACCT F
         WHERE FACT_ACCT_GROUP_ID IN (SELECT DISTINCT FACT_ACCT_GROUP_ID
                                        FROM FACT_ACCT
-                                      WHERE RECORD_ID2=TO_NUMBER(?))
+                                      WHERE RECORD_ID2=?
+                                      AND C_ACCTSCHEMA_ID=?)
         ORDER BY F.DATEACCT, F.FACT_ACCT_GROUP_ID, F.SEQNO
         ]]></Sql>
     <Field name="rownum" value="count"/>
     <Parameter name="DPid"/>
+    <Parameter name="acctSchema"/>
   </SqlMethod>
   
   <SqlMethod name="set" type="constant" return="multiple">
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal_data.xsql	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal_data.xsql	Mon Feb 18 17:58:35 2008 +0000
@@ -28,12 +28,12 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
     <![CDATA[
-      SELECT IDENTIFIER, DATEACCT, VALUE, NAME, ID, AD_TABLE_ID, DOCBASETYPE, '' AS TOTAL, '' AS DESCRIPTION,
+      SELECT IDENTIFIER, DATEACCT, VALUE, NAME, ID, AD_TABLE_ID, DOCBASETYPE, SEQNO, '' AS TOTAL, '' AS DESCRIPTION,
       (CASE AMTACCTDR WHEN 0 THEN NULL ELSE AMTACCTDR END) AS AMTACCTDR, (CASE AMTACCTCR WHEN 0 THEN NULL ELSE AMTACCTCR END) AS AMTACCTCR
       FROM 
       (SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT,
       F.ACCTVALUE AS VALUE, F.ACCTDESCRIPTION AS NAME,F.RECORD_ID AS ID, F.AD_TABLE_ID, F.DOCBASETYPE,
-      sum(F.AMTACCTDR) AS AMTACCTDR, sum(F.AMTACCTCR) AS AMTACCTCR
+      sum(F.AMTACCTDR) AS AMTACCTDR, sum(F.AMTACCTCR) AS AMTACCTCR, MIN(SEQNO) AS SEQNO
       FROM FACT_ACCT F 
       WHERE F.AD_CLIENT_ID IN ('1')
       AND F.AD_ORG_ID IN('1')
@@ -42,7 +42,7 @@
       GROUP BY F.AD_TABLE_ID, F.DATEACCT, F.ACCTDESCRIPTION, F.ACCTVALUE, F.DOCBASETYPE, F.RECORD_ID, 
       F.FACT_ACCT_GROUP_ID, F.ACCOUNT_ID,
       (CASE F.AMTACCTDR WHEN 0 THEN (CASE SIGN(F.AMTACCTCR) WHEN -1 THEN 1 ELSE 2 END) ELSE (CASE SIGN(F.AMTACCTDR) WHEN -1 THEN 3 ELSE 4 END) END)) AA
-      ORDER BY DATEACCT, IDENTIFIER
+      ORDER BY DATEACCT, IDENTIFIER, SEQNO
       ]]></Sql>
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE F.AD_CLIENT_ID IN (" text="'1'"/>
@@ -50,6 +50,7 @@
     <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[ AND f.dateacct >= TO_DATE(?)]]></Parameter>
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[ AND f.dateacct < TO_DATE(?)]]></Parameter>
     <Parameter name="docbasetype" optional="true" after="AND 1=1"><![CDATA[ AND f.DOCBASETYPE = ?]]></Parameter>
+    <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[ AND f.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>
     <Parameter name="orgFamily" type="replace" optional="true" after="AND f.AD_ORG_ID IN(" text="'2'"/>
   </SqlMethod>
   <SqlMethod name="selectCount" type="preparedStatement" return="string" default="0">
@@ -78,6 +79,7 @@
     <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[ AND f.dateacct >= TO_DATE(?)]]></Parameter>
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[ AND f.dateacct < TO_DATE(?)]]></Parameter>
     <Parameter name="docbasetype" optional="true" after="AND 1=1"><![CDATA[ AND f.DOCBASETYPE = ?]]></Parameter>
+    <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[ AND f.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>
     <Parameter name="orgFamily" type="replace" optional="true" after="AND f.AD_ORG_ID IN(" text="'2'"/>
     <Parameter name="dateAcct"/>
     <Parameter name="dateAcct"/>
@@ -86,12 +88,13 @@
   <SqlMethod name="set" type="constant" return="multiple">
       <SqlMethodComment></SqlMethodComment>
       <Sql></Sql>
+    <Parameter name="rownum"/>      
   </SqlMethod>
   <SqlMethod name="treeOrg" type="preparedStatement" return="string">
     <SqlMethodComment></SqlMethodComment>
     <Sql>
         SELECT AD_TREE_ORG_ID FROM AD_CLIENTINFO
-        WHERE AD_CLIENT_ID = TO_NUMBER(?)
+        WHERE AD_CLIENT_ID = ?
     </Sql>
     <Parameter name="client"/>
   </SqlMethod>
@@ -99,12 +102,12 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
     <![CDATA[
-      SELECT IDENTIFIER, DATEACCT, VALUE, NAME, ID, AD_TABLE_ID, DOCBASETYPE, '' AS TOTAL, '' AS DESCRIPTION,
+      SELECT IDENTIFIER, DATEACCT, VALUE, NAME, ID, AD_TABLE_ID, DOCBASETYPE, SEQNO, '' AS TOTAL, '' AS DESCRIPTION,
       (CASE AMTACCTDR WHEN 0 THEN NULL ELSE AMTACCTDR END) AS AMTACCTDR, (CASE AMTACCTCR WHEN 0 THEN NULL ELSE AMTACCTCR END) AS AMTACCTCR
       FROM 
       (SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT,
       F.ACCTVALUE AS VALUE, F.ACCTDESCRIPTION AS NAME,F.RECORD_ID AS ID, F.AD_TABLE_ID, F.DOCBASETYPE,
-      sum(F.AMTACCTDR) AS AMTACCTDR, sum(F.AMTACCTCR) AS AMTACCTCR
+      sum(F.AMTACCTDR) AS AMTACCTDR, sum(F.AMTACCTCR) AS AMTACCTCR, MIN(SEQNO) AS SEQNO
       FROM FACT_ACCT F 
       WHERE F.AD_CLIENT_ID IN ('1')
       AND F.AD_ORG_ID IN('1')
@@ -112,11 +115,13 @@
       GROUP BY F.AD_TABLE_ID, F.DATEACCT, F.ACCTDESCRIPTION, F.ACCTVALUE, F.DOCBASETYPE, F.RECORD_ID, 
       F.FACT_ACCT_GROUP_ID, F.ACCOUNT_ID,
       (CASE F.AMTACCTDR WHEN 0 THEN (CASE SIGN(F.AMTACCTCR) WHEN -1 THEN 1 ELSE 2 END) ELSE (CASE SIGN(F.AMTACCTDR) WHEN -1 THEN 3 ELSE 4 END) END)) AA
-      ORDER BY DATEACCT, IDENTIFIER
+      ORDER BY DATEACCT, IDENTIFIER, SEQNO
       ]]></Sql>
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE F.AD_CLIENT_ID IN (" text="'1'"/>
     <Parameter name="adUserOrg" type="replace" optional="true" after="AND F.AD_ORG_ID IN(" text="'1'"/>
+    <Parameter name="table" optional="true" after="AND 1=1"><![CDATA[ AND f.ad_table_Id = to_number(?)]]></Parameter>
+    <Parameter name="record" optional="true" after="AND 1=1"><![CDATA[ AND f.record_Id = to_number(?)]]></Parameter>   
     <Parameter name="table" optional="true" after="AND 1=1"><![CDATA[ AND f.ad_table_ID = TO_NUMBER(?)]]></Parameter>
     <Parameter name="record" optional="true" after="AND 1=1"><![CDATA[ AND f.record_ID = TO_NUMBER(?)]]></Parameter>
   </SqlMethod>
@@ -152,12 +157,12 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
     <![CDATA[
-      SELECT IDENTIFIER, DATEACCT, VALUE, NAME, ID, AD_TABLE_ID, DOCBASETYPE, '' AS TOTAL, '' AS DESCRIPTION,
+      SELECT IDENTIFIER, DATEACCT, VALUE, NAME, ID, AD_TABLE_ID, DOCBASETYPE, SEQNO, '' AS TOTAL, '' AS DESCRIPTION,
       (CASE AMTACCTDR WHEN 0 THEN NULL ELSE AMTACCTDR END) AS AMTACCTDR, (CASE AMTACCTCR WHEN 0 THEN NULL ELSE AMTACCTCR END) AS AMTACCTCR
       FROM 
       (SELECT F.FACT_ACCT_GROUP_ID AS IDENTIFIER, F.DATEACCT,
       F.ACCTVALUE AS VALUE, F.ACCTDESCRIPTION AS NAME,F.RECORD_ID AS ID, F.AD_TABLE_ID, F.DOCBASETYPE,
-      sum(F.AMTACCTDR) AS AMTACCTDR, sum(F.AMTACCTCR) AS AMTACCTCR
+      sum(F.AMTACCTDR) AS AMTACCTDR, sum(F.AMTACCTCR) AS AMTACCTCR, MIN(SEQNO) AS SEQNO
       FROM FACT_ACCT F 
       WHERE F.AD_CLIENT_ID IN ('1')
       AND F.AD_ORG_ID IN('1')
@@ -165,7 +170,7 @@
       GROUP BY F.AD_TABLE_ID, F.DATEACCT, F.ACCTDESCRIPTION, F.ACCTVALUE, F.DOCBASETYPE, F.RECORD_ID, 
       F.FACT_ACCT_GROUP_ID, F.ACCOUNT_ID,
       (CASE F.AMTACCTDR WHEN 0 THEN (CASE SIGN(F.AMTACCTCR) WHEN -1 THEN 1 ELSE 2 END) ELSE (CASE SIGN(F.AMTACCTDR) WHEN -1 THEN 3 ELSE 4 END) END)) AA
-      ORDER BY DATEACCT, IDENTIFIER
+      ORDER BY DATEACCT, IDENTIFIER, SEQNO
       ]]></Sql>
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE F.AD_CLIENT_ID IN (" text="'1'"/>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger_data.xsql	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportGeneralLedger_data.xsql	Mon Feb 18 17:58:35 2008 +0000
@@ -52,7 +52,7 @@
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE fact_acct.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adUserOrg" type="replace" optional="true" after="AND fact_acct.AD_ORG_ID IN (" text="'1'"/>
-    <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = TO_NUMBER(?)]]></Parameter>
+    <Parameter name="acctschema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>
     <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[AND dateacct >= to_date(?) ]]></Parameter>
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND dateacct < to_date(?) ]]></Parameter>
     <Parameter name="org" type="replace" optional="true" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'2'"/>
@@ -97,7 +97,7 @@
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE fact_acct.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adUserOrg" type="replace" optional="true" after="AND fact_acct.AD_ORG_ID IN (" text="'1'"/>
-    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = TO_NUMBER(?) ]]></Parameter>
+    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = to_number(?) ]]></Parameter>
     <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[AND dateacct >= to_date(?) ]]></Parameter>
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND dateacct < to_date(?) ]]></Parameter>
     <Parameter name="org" type="replace" optional="true" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'2'"/>
@@ -106,8 +106,8 @@
 
     <Parameter name="parDateTo" optional="true" after="AND 5=5"><![CDATA[AND dateacct < to_date(?) ]]></Parameter>
     
-    <Parameter name="paramAmtFrom" optional="true" after="3=3"><![CDATA[ and coalesce(amtacctdr,amtacctcr)>=? ]]></Parameter>   
-    <Parameter name="paramAmtTo" optional="true" after="4=4"><![CDATA[ and coalesce(amtacctdr,amtacctcr)<=? ]]></Parameter>
+    <Parameter name="paramAmtFrom" optional="true" after="3=3"><![CDATA[ and coalesce(amtacctdr,amtacctcr)>=to_number(?) ]]></Parameter>   
+    <Parameter name="paramAmtTo" optional="true" after="4=4"><![CDATA[ and coalesce(amtacctdr,amtacctcr)<=to_number(?) ]]></Parameter>
     <Parameter name="orden" type="replace" optional="true" after="ORDER BY " text="PARTNER"/>
   </SqlMethod>
   
@@ -140,14 +140,14 @@
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE fact_acct.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adUserOrg" type="replace" optional="true" after="AND fact_acct.AD_ORG_ID IN (" text="'1'"/>
-    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = TO_NUMBER(?) ]]></Parameter>
+    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = to_number(?) ]]></Parameter>
     <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[AND dateacct >= to_date(?) ]]></Parameter>
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND dateacct < to_date(?) ]]></Parameter>
     <Parameter name="org" type="replace" optional="true" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'2'"/>
     <Parameter name="cBpartnerId" optional="true" type="argument" after="AND 2=2 "><![CDATA[ AND FACT_ACCT.C_BPARTNER_ID IN]]></Parameter>
 
-    <Parameter name="paramAmtFrom" optional="true" after="3=3"><![CDATA[ and coalesce(amtacctdr,amtacctcr)>=? ]]></Parameter>
-    <Parameter name="paramAmtTo" optional="true" after="4=4"><![CDATA[ and coalesce(amtacctdr,amtacctcr)<=? ]]></Parameter>
+    <Parameter name="paramAmtFrom" optional="true" after="3=3"><![CDATA[ and coalesce(amtacctdr,amtacctcr)>=to_number(?) ]]></Parameter>
+    <Parameter name="paramAmtTo" optional="true" after="4=4"><![CDATA[ and coalesce(amtacctdr,amtacctcr)<=to_number(?) ]]></Parameter>
     
     <Parameter name="orden" type="replace" optional="true" after="ORDER BY " text="PARTNER"/>
   </SqlMethod>
@@ -186,7 +186,7 @@
     <Field name="rownum" value="count"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="WHERE fact_acct.AD_Client_ID IN (" text="'1'"/>
     <Parameter name="adUserOrg" type="replace" optional="true" after="AND fact_acct.AD_ORG_ID IN (" text="'1'"/>
-    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = TO_NUMBER(?) ]]></Parameter>
+    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[and fact_acct.C_ACCTSCHEMA_ID = to_number(?) ]]></Parameter>
     <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[AND dateacct >= to_date(?) ]]></Parameter>
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND dateacct < to_date(?) ]]></Parameter>
     <Parameter name="org" type="replace" optional="true" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'2'"/>
@@ -194,8 +194,8 @@
 
     <Parameter name="parDateTo" optional="true" after="AND 5=5"><![CDATA[AND dateacct < to_date(?) ]]></Parameter>
     
-    <Parameter name="paramAmtFrom" optional="true" after="3=3"><![CDATA[ and coalesce(amtacctdr,amtacctcr)>=? ]]></Parameter>
-    <Parameter name="paramAmtTo" optional="true" after="4=4"><![CDATA[ and coalesce(amtacctdr,amtacctcr)<=? ]]></Parameter>
+    <Parameter name="paramAmtFrom" optional="true" after="3=3"><![CDATA[ and coalesce(amtacctdr,amtacctcr)>=to_number(?) ]]></Parameter>
+    <Parameter name="paramAmtTo" optional="true" after="4=4"><![CDATA[ and coalesce(amtacctdr,amtacctcr)<=to_number(?) ]]></Parameter>
     
     <Parameter name="orden" type="replace" optional="true" after="ORDER BY " text="PARTNER"/>
   </SqlMethod>
@@ -210,7 +210,7 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
         SELECT AD_TREE_ORG_ID FROM AD_CLIENTINFO
-        WHERE AD_CLIENT_ID = TO_NUMBER(?)
+        WHERE AD_CLIENT_ID = to_number(?)
     </Sql>
     <Parameter name="client"/>
   </SqlMethod>
@@ -220,9 +220,9 @@
     <Sql>
         SELECT NODE_ID AS ID
         FROM AD_TREENODE 
-        WHERE AD_TREE_ID = TO_NUMBER(?) 
+        WHERE AD_TREE_ID = to_number(?) 
         CONNECT BY PRIOR NODE_ID = PARENT_ID 
-        START WITH NODE_ID = TO_NUMBER(?) AND AD_TREE_ID = TO_NUMBER(?)
+        START WITH NODE_ID = to_number(?) AND AD_TREE_ID = to_number(?)
     </Sql>
     <Parameter name="tree"/>
     <Parameter name="element"/>
@@ -246,19 +246,21 @@
       SELECT C_ElementValue.C_ElementValue_ID as id, ((CASE C_ElementValue.isActive WHEN 'N' THEN '**' ELSE '' END) || C_ElementValue.Value || ' - ' || C_ElementValue.Name) as name FROM C_ElementValue
       WHERE C_ElementValue.AD_Org_ID IN('1') AND C_ElementValue.AD_Client_ID IN('1')  AND (C_ElementValue.isActive = 'Y' OR C_ElementValue.C_ElementValue_ID = TO_NUMBER(?) )
       and c_elementvalue.ELEMENTLEVEL='S'
+      AND 1=1
       ORDER BY name
     ]]></Sql>
     
 <Parameter name="adOrgClient" type="replace" optional="true" after="C_ElementValue.AD_Org_ID IN(" text="'1'"/>
 <Parameter name="adUserClient" type="replace" optional="true" after="C_ElementValue.AD_Client_ID IN(" text="'1'"/>
 <Parameter name="cElementvalueId"/>
+<Parameter name="schema" optional="true" after="AND 1=1"><![CDATA[ AND (select max(c_element_id) from c_acctschema_element where c_acctschema_id = ? and ELEMENTTYPE = 'AC') = C_ElementValue.c_element_id ]]></Parameter>
   </SqlMethod>
 
   <SqlMethod name="selectC_ACCTSCHEMA_ID" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
     <Sql><![CDATA[
       SELECT C_ACCTSCHEMA_ID as id, ((CASE C_ACCTSCHEMA.isActive WHEN 'N' THEN '**' ELSE '' END) || C_ACCTSCHEMA.Name) as name FROM C_ACCTSCHEMA
-      WHERE C_ACCTSCHEMA.AD_Org_ID IN('1') AND C_ACCTSCHEMA.AD_Client_ID IN('1')  AND (C_ACCTSCHEMA.isActive = 'Y' OR C_ACCTSCHEMA.C_ACCTSCHEMA_ID = TO_NUMBER(?) )
+      WHERE C_ACCTSCHEMA.AD_Org_ID IN('1') AND C_ACCTSCHEMA.AD_Client_ID IN('1')  AND (C_ACCTSCHEMA.isActive = 'Y' OR C_ACCTSCHEMA.C_ACCTSCHEMA_ID = to_number(?) )
       ORDER BY name
     ]]></Sql>
     
@@ -273,7 +275,7 @@
     <![CDATA[
         SELECT NAME
         FROM AD_CLIENT
-        WHERE AD_CLIENT_ID = TO_NUMBER(?)
+        WHERE AD_CLIENT_ID = to_number(?)
       ]]></Sql>
     <Parameter name="client"/>
   </SqlMethod>
@@ -283,8 +285,8 @@
       <Sql><![CDATA[
 	   SELECT c_elementvalue_id as name
        FROM C_ELEMENTVALUE 
-       WHERE value between (select value from c_elementvalue where c_elementvalue_ID = TO_NUMBER(?)) 
-       and  (select value from c_elementvalue where c_elementvalue_ID = TO_NUMBER(?))
+       WHERE value between (select value from c_elementvalue where c_elementvalue_id = to_number(?)) 
+       and  (select value from c_elementvalue where c_elementvalue_id = to_number(?))
 	   and c_elementvalue.ELEMENTLEVEL = 'S'
        ORDER BY value asc
       ]]></Sql>
@@ -303,8 +305,8 @@
       AND DATEACCT < TO_DATE(?)
       AND FACT_ACCT.AD_ORG_ID IN ('1')
       ]]></Sql>
-      <Parameter name="bpartner" optional="true" after="1=1"><![CDATA[ AND FACT_ACCT.C_BPARTNER_ID = TO_NUMBER(?) ]]></Parameter>
-      <Parameter name="acctschema" optional="true" after="1=1"><![CDATA[ and fact_acct.C_ACCTSCHEMA_ID = TO_NUMBER(?) ]]></Parameter>
+      <Parameter name="bpartner" optional="true" after="1=1"><![CDATA[ AND FACT_ACCT.C_BPARTNER_ID = to_number(?) ]]></Parameter>
+      <Parameter name="acctschema" optional="true" after="1=1"><![CDATA[ and fact_acct.C_ACCTSCHEMA_ID = to_number(?) ]]></Parameter>
       <Parameter name="account"/>
       <Parameter name="date"/>
       <Parameter name="orgs" type="replace" optional="true" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'1'"/>
@@ -321,8 +323,8 @@
       AND DATEACCT < TO_DATE(?)
       AND FACT_ACCT.AD_ORG_ID IN ('1')
       ]]></Sql>
-      <Parameter name="bpartner" optional="true" after="1=1"><![CDATA[ AND FACT_ACCT.C_BPARTNER_ID = TO_NUMBER(?) ]]></Parameter>
-      <Parameter name="acctschema" optional="true" after="1=1"><![CDATA[ and fact_acct.C_ACCTSCHEMA_ID = TO_NUMBER(?) ]]></Parameter>
+      <Parameter name="bpartner" optional="true" after="1=1"><![CDATA[ AND FACT_ACCT.C_BPARTNER_ID = to_number(?) ]]></Parameter>
+      <Parameter name="acctschema" optional="true" after="1=1"><![CDATA[ and fact_acct.C_ACCTSCHEMA_ID = to_number(?) ]]></Parameter>
       <Parameter name="account"/>
       <Parameter name="date"/>
       <Parameter name="orgs" type="replace" optional="true" after="AND FACT_ACCT.AD_ORG_ID IN (" text="'1'"/>
--- a/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.html	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.html	Mon Feb 18 17:58:35 2008 +0000
@@ -85,10 +85,11 @@
 }
 
 function onloadFunctions() {
-	new TypeAheadCombo("inpOrg");
+  new TypeAheadCombo("inpOrg");
   new TypeAheadCombo("inpLevel");
+  new TypeAheadCombo("inpcAcctSchemaId");
   new TypeAheadCombo("inpAccountFrom");
-  new TypeAheadCombo("inpAccountTo");
+  new TypeAheadCombo("inpAccountTo"); 
   displayLogic();
 }
 
@@ -107,6 +108,10 @@
       frm.inpLevel.focus();
       mensaje(7);
       return false;
+    }  else if (inputValue(frm.inpcAcctSchemaId)==null || inputValue(frm.inpcAcctSchemaId)=="") {
+      frm.inpcAcctSchemaId.focus();
+      mensaje(7);
+      return false;
     }
     seleccionarListCompleto(frm.inpcBPartnerId_IN);
   return true;
@@ -296,6 +301,13 @@
               <TD class="TitleCell"/>
             </TR>
             <TR>
+              <TD class="TitleCell"> <SPAN class="LabelText">Accounting schema</SPAN></TD>
+              <TD class="Combo_ContentCell" colspan="2"> <SELECT name="inpcAcctSchemaId" id="inpcAcctSchemaId" class="ComboKey Combo_TwoCells_width" required="true" onchange="submitCommandForm('DEFAULT',true);">
+                  <OPTION value=""> <DIV id="reportC_ACCTSCHEMA_ID"></DIV></OPTION>
+                </SELECT>
+              </TD>
+            </TR>
+            <TR>
               <TD class="TitleCell"> <SPAN class="LabelText">Organization</SPAN></TD>
               <TD class="Combo_ContentCell"> 
                 <SELECT  name="inpOrg" id="inpOrg" class="ComboKey Combo_OneCell_width" required="true">
--- a/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.java	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.java	Mon Feb 18 17:58:35 2008 +0000
@@ -46,6 +46,7 @@
 
 
     if (vars.commandIn("DEFAULT")) {
+      String strcAcctSchemaId = vars.getGlobalVariable("inpcAcctSchemaId", "ReportTrialBalance|cAcctSchemaId", "");
       String strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportTrialBalance|DateFrom", "");
       String strDateTo = vars.getGlobalVariable("inpDateTo", "ReportTrialBalance|DateTo", "");
       String strOnly = vars.getGlobalVariable("inpOnly", "ReportTrialBalance|Only", "-1");
@@ -57,8 +58,9 @@
       String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportTrialBalance|cBpartnerId");
       String strAll = vars.getStringParameter("inpAll");
 
-      printPageDataSheet(response, vars, strDateFrom, strDateTo, strOrg, strLevel, strOnly, strAccountFrom, strAccountTo, strAll, strcBpartnerId);
+      printPageDataSheet(response, vars, strDateFrom, strDateTo, strOrg, strLevel, strOnly, strAccountFrom, strAccountTo, strAll, strcBpartnerId, strcAcctSchemaId);
     } else if (vars.commandIn("FIND")) {
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportTrialBalance|cAcctSchemaId");
       String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportTrialBalance|DateFrom");
       String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportTrialBalance|DateTo");
       String strOnly = vars.getRequestGlobalVariable("inpOnly", "ReportTrialBalance|Only");
@@ -69,8 +71,9 @@
 
       String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportTrialBalance|cBpartnerId");
       String strAll = vars.getStringParameter("inpAll");
-      printPageDataSheet(response, vars, strDateFrom, strDateTo, strOrg, strLevel, strOnly, strAccountFrom, strAccountTo, strAll, strcBpartnerId);
+      printPageDataSheet(response, vars, strDateFrom, strDateTo, strOrg, strLevel, strOnly, strAccountFrom, strAccountTo, strAll, strcBpartnerId, strcAcctSchemaId);
     } else if (vars.commandIn("PDF")){
+      String strcAcctSchemaId = vars.getRequestGlobalVariable("inpcAcctSchemaId", "ReportTrialBalance|cAcctSchemaId");
       String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportTrialBalance|DateFrom");
       String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportTrialBalance|DateTo");
       String strOnly = vars.getRequestGlobalVariable("inpOnly", "ReportTrialBalance|Only");
@@ -81,11 +84,11 @@
 
       String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportTrialBalance|cBpartnerId");
       String strAll = vars.getStringParameter("inpAll");
-      printPageDataPDF(response, vars, strDateFrom, strDateTo, strOrg, strLevel, strOnly, strAccountFrom, strAccountTo, strAll, strcBpartnerId);
+      printPageDataPDF(response, vars, strDateFrom, strDateTo, strOrg, strLevel, strOnly, strAccountFrom, strAccountTo, strAll, strcBpartnerId, strcAcctSchemaId);
     }else pageError(response);
   }
 
-  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strOrg, String strLevel, String strOnly, String strAccountFrom, String strAccountTo, String strAll, String strcBpartnerId)
+  void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strOrg, String strLevel, String strOnly, String strAccountFrom, String strAccountTo, String strAll, String strcBpartnerId, String strcAcctSchemaId)
     throws IOException, ServletException {
     String strMessage="";    
     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
@@ -121,12 +124,12 @@
           if (log4j.isDebugEnabled()) log4j.debug("Select BP, strcBpartnerId:"+strcBpartnerId+" - strAll:"+strAll);
           if (!strAll.equals("")) strcBpartnerId="";
           discard[1] = "sectionNoBP";
-          data = ReportTrialBalanceData.selectBP(this, strDateFrom, strDateTo, strOrg, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo,strcBpartnerId);
+          data = ReportTrialBalanceData.selectBP(this, strDateFrom, strDateTo, strOrg, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo,strcBpartnerId, strcAcctSchemaId);
         } else {
-          data = ReportTrialBalanceData.select(this, strDateFrom, strDateTo, strOrg, strTreeAccount, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo);
+          data = ReportTrialBalanceData.select(this, strDateFrom, strDateTo, strOrg, strTreeAccount, strcAcctSchemaId, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo);
         }
       }else{
-        data = ReportTrialBalanceData.select(this, strDateFrom, strDateTo, strOrg, strTreeAccount, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"),"","");
+        data = ReportTrialBalanceData.select(this, strDateFrom, strDateTo, strOrg, strTreeAccount, strcAcctSchemaId, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"),"","");
       }
 
       if (log4j.isDebugEnabled()) log4j.debug("Calculating tree...");
@@ -183,9 +186,10 @@
       }
     } 
 
-    xmlDocument.setData("reportAccountFrom_ID","liststructure", ReportTrialBalanceData.selectAccount(this, Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), ""));
-    xmlDocument.setData("reportAccountTo_ID","liststructure", ReportTrialBalanceData.selectAccount(this, Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), ""));
-    xmlDocument.setData("reportAD_ORGID", "liststructure", OrganizationComboData.selectCombo(this, vars.getRole()));
+    xmlDocument.setData("reportAccountFrom_ID","liststructure", ReportTrialBalanceData.selectAccount(this, Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), "", strcAcctSchemaId));
+    xmlDocument.setData("reportAccountTo_ID","liststructure", ReportTrialBalanceData.selectAccount(this, Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), "", strcAcctSchemaId));
+    xmlDocument.setData("reportAD_ORGID", "liststructure", GeneralAccountingReportsData.selectCombo(this, vars.getRole()));
+    xmlDocument.setData("reportC_ACCTSCHEMA_ID", "liststructure", ReportGeneralLedgerData.selectC_ACCTSCHEMA_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), strcAcctSchemaId));    
     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
@@ -198,6 +202,7 @@
     xmlDocument.setParameter("Only", strOnly);
     xmlDocument.setParameter("adOrgId", strOrg);
     xmlDocument.setParameter("Level", strLevel);
+    xmlDocument.setParameter("cAcctschemaId", strcAcctSchemaId);    
     xmlDocument.setParameter("accountFrom", strAccountFrom);
     xmlDocument.setParameter("accountTo", strAccountTo);
     xmlDocument.setParameter("paramMessage", (strMessage.equals("")?"":"alert('" + strMessage + "');"));
@@ -222,7 +227,7 @@
     out.close();
   }
 
-  void printPageDataPDF(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strOrg, String strLevel, String strOnly, String strAccountFrom, String strAccountTo, String strAll, String strcBpartnerId)
+  void printPageDataPDF(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strOrg, String strLevel, String strOnly, String strAccountFrom, String strAccountTo, String strAll, String strcBpartnerId, String strcAcctSchemaId)
     throws IOException, ServletException {
     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
     /*response.setContentType("text/html; charset=UTF-8");
@@ -248,12 +253,12 @@
           if (log4j.isDebugEnabled()) log4j.debug("Select BP, strcBpartnerId:"+strcBpartnerId+" - strAll:"+strAll);
           if (!strAll.equals("")) strcBpartnerId="";
           discard[1] = "sectionNoBP";
-          data = ReportTrialBalanceData.selectBP(this, strDateFrom, strDateTo, strOrg, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo,strcBpartnerId);
+          data = ReportTrialBalanceData.selectBP(this, strDateFrom, strDateTo, strOrg, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo,strcBpartnerId, strcAcctSchemaId);
         } else {        
-          data = ReportTrialBalanceData.select(this, strDateFrom, strDateTo, strOrg, strTreeAccount, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo);
+          data = ReportTrialBalanceData.select(this, strDateFrom, strDateTo, strOrg, strTreeAccount, strcAcctSchemaId, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAccountFrom, strAccountTo);
         }
       }else{
-        data = ReportTrialBalanceData.select(this, strDateFrom,  strDateTo, strOrg, strTreeAccount, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"),"","");
+        data = ReportTrialBalanceData.select(this, strDateFrom,  strDateTo, strOrg, strTreeAccount, strcAcctSchemaId, strOrgFamily, Utility.getContext(this, vars, "#User_Client", "ReportTrialBalance"), Utility.getContext(this, vars, "#User_Org", "ReportTrialBalance"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"),"","");
       }
 
 
--- a/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.xml	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance.xml	Mon Feb 18 17:58:35 2008 +0000
@@ -35,6 +35,7 @@
   <PARAMETER id="parameterOnly" name="constantOnly" default="-1"/>
   <PARAMETER id="paramOnly" name="Only" boolean="checked" withId="parameterOnly"/>
   <PARAMETER id="paramAD_ORGID" name="adOrgId"/>
+  <PARAMETER id="paramC_ACCTSCHEMA_ID" name="cAcctschemaId"/>  
   <PARAMETER id="paramLevel" name="Level"/>
   <PARAMETER id="paramCSS" name="theme" attribute="href" replace="Default"/>
   <PARAMETER id="tdleftTabs" name="leftTabs" default=""/>
@@ -57,16 +58,23 @@
   <SUBREPORT id="reportAD_ORGID" name="reportAD_ORGID" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramAD_ORGID"/>
   </SUBREPORT>
+  
   <SUBREPORT id="reportLevel" name="reportLevel" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramLevel"/>
   </SUBREPORT>
+  
   <SUBREPORT id="reportAccountTo_ID" name="reportAccountTo_ID" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramAccountTo"/>
   </SUBREPORT>
+  
   <SUBREPORT id="reportAccountFrom_ID" name="reportAccountFrom_ID" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramAccountFrom"/>
   </SUBREPORT>
 
+  <SUBREPORT id="reportC_ACCTSCHEMA_ID" name="reportC_ACCTSCHEMA_ID" report="org/openbravo/erpCommon/reference/List">
+    <ARGUMENT name="parameterListSelected" withId="paramC_ACCTSCHEMA_ID"/>
+  </SUBREPORT>
+    
   <PARAMETER id="param2" name="param2" default="2"/>
 
   <structure name="structure1">
--- a/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance_data.xsql	Mon Feb 18 15:58:41 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance_data.xsql	Mon Feb 18 17:58:35 2008 +0000
@@ -41,6 +41,7 @@
       AND AD_TREENODE.AD_TREE_ID = TO_NUMBER(?)
       AND AD_TREENODE.ISACTIVE = 'Y'
       AND C_ELEMENTVALUE.ISACTIVE = 'Y'
+      AND (select max(c_element_id) from c_acctschema_element where c_acctschema_id = ? and ELEMENTTYPE = 'AC') = C_ELEMENTVALUE.C_ELEMENT_ID
       UNION		
       SELECT 0 AS PARENT_ID, F.ACCOUNT_ID AS ID, EV.ELEMENTLEVEL, EV.NAME AS NAME, EV.VALUE AS ACCOUNT_ID, 
       SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN F.AMTACCTDR-F.AMTACCTCR ELSE 0 END)) AS SALDO_INICIAL, 
@@ -64,6 +65,7 @@
     <Parameter name="dateTo"/>
     <Parameter name="org"/>
     <Parameter name="treeAcct"/>
+    <Parameter name="acctSchema"/>    
     <Parameter name="orgFamily" type="replace" optional="true" after="f.AD_ORG_ID IN(" text="'2'"/>
     <Parameter name="adUserClient" type="replace" optional="true" after="F.AD_CLIENT_ID IN (" text="'1'"/>
     <Parameter name="adUserOrg" type="replace" optional="true" after="F.AD_ORG_ID IN(" text="'1'"/>
@@ -71,6 +73,7 @@
     <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND F.DATEACCT < TO_DATE(?)]]></Parameter>
     <Parameter name="accountFrom" optional="true" after="AND 1=1"><![CDATA[AND EV.VALUE >= TO_NUMBER(?)]]></Parameter>
     <Parameter name="accountTo" optional="true" after="AND 1=1"><![CDATA[AND EV.VALUE <= TO_NUMBER(?)]]></Parameter>
+    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[ AND F.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>    
   </SqlMethod>
   
   
@@ -112,6 +115,7 @@
     <Parameter name="accountFrom" optional="true" after="AND 1=1"><![CDATA[AND EV.VALUE >= TO_NUMBER(?)]]></Parameter>
     <Parameter name="accountTo" optional="true" after="AND 1=1"><![CDATA[AND EV.VALUE <= TO_NUMBER(?)]]></Parameter>
     <Parameter name="cBpartnerId" optional="true" type="argument" after="AND 1=1"><![CDATA[ AND F.C_BPARTNER_ID IN]]></Parameter>
+    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[ AND F.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>        
   </SqlMethod>
   
   <SqlMethod name="set" type="constant" return="multiple">
@@ -155,11 +159,13 @@
         AND C_ElementValue.AD_Client_ID IN('1')  
         AND C_ElementValue.IsSummary='N' 
         AND (C_ElementValue.isActive = 'Y' OR C_ElementValue.C_ElementValue_ID = TO_NUMBER(?) ) 
+        AND 1=1
         ORDER BY C_ElementValue.Value
     ]]></Sql>
   <Parameter name="adOrgClient" type="replace" optional="true" after="C_ElementValue.AD_Org_ID IN(" text="'1'"/>
   <Parameter name="adUserClient" type="replace" optional="true" after="C_ElementValue.AD_Client_ID IN(" text="'1'"/>
   <Parameter name="cElementvalueId"/>
+  <Parameter name="schema" optional="true" after="AND 1=1"><![CDATA[ AND (select max(c_element_id) from c_acctschema_element where c_acctschema_id = ? and ELEMENTTYPE = 'AC') = C_ElementValue.c_element_id ]]></Parameter>  
   </SqlMethod>
 
   <SqlMethod name="selectAccountingName" type="preparedStatement" return="string">