Added compatibility with Payment Aging Balance Report
authorDavid Miguelez <david.miguelez@openbravo.com>
Fri, 17 Feb 2012 13:08:40 +0000
changeset 15293 aacd22f7c6af
parent 15292 05e845f8c320
child 15294 b165b5619b09
Added compatibility with Payment Aging Balance Report
modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_TEXTINTERFACES.xml
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.java
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.xml
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java
modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportPDF.jrxml
--- a/modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Wed Feb 15 20:33:15 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Fri Feb 17 13:08:40 2012 +0000
@@ -165,6 +165,17 @@
 <!--2E1CF9F4C3E94DDF8267520EAE434F8C-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--2E1CF9F4C3E94DDF8267520EAE434F8C--></AD_TEXTINTERFACES>
 
+<!--2FAD31FCFE354886A1DCF184253A833A--><AD_TEXTINTERFACES>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <AD_TEXTINTERFACES_ID><![CDATA[2FAD31FCFE354886A1DCF184253A833A]]></AD_TEXTINTERFACES_ID>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <TEXT><![CDATA[Empty Business Partner]]></TEXT>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--2FAD31FCFE354886A1DCF184253A833A-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--2FAD31FCFE354886A1DCF184253A833A--></AD_TEXTINTERFACES>
+
 <!--30969F03CBFC4DE7BCFBC71FA5D34EDA--><AD_TEXTINTERFACES>
 <!--30969F03CBFC4DE7BCFBC71FA5D34EDA-->  <AD_TEXTINTERFACES_ID><![CDATA[30969F03CBFC4DE7BCFBC71FA5D34EDA]]></AD_TEXTINTERFACES_ID>
 <!--30969F03CBFC4DE7BCFBC71FA5D34EDA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -275,6 +286,17 @@
 <!--43C8186236514013ADE1E5C8DB7A043B-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--43C8186236514013ADE1E5C8DB7A043B--></AD_TEXTINTERFACES>
 
+<!--4721249AEDFF435C893526F191DCFAF6--><AD_TEXTINTERFACES>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <AD_TEXTINTERFACES_ID><![CDATA[4721249AEDFF435C893526F191DCFAF6]]></AD_TEXTINTERFACES_ID>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <TEXT><![CDATA[Include empty Business Partner]]></TEXT>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--4721249AEDFF435C893526F191DCFAF6-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--4721249AEDFF435C893526F191DCFAF6--></AD_TEXTINTERFACES>
+
 <!--47D05363EA0A431E94988745BA473BD1--><AD_TEXTINTERFACES>
 <!--47D05363EA0A431E94988745BA473BD1-->  <AD_TEXTINTERFACES_ID><![CDATA[47D05363EA0A431E94988745BA473BD1]]></AD_TEXTINTERFACES_ID>
 <!--47D05363EA0A431E94988745BA473BD1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -330,6 +352,17 @@
 <!--55A3D8825B094737B9E1479A50AE73B1-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--55A3D8825B094737B9E1479A50AE73B1--></AD_TEXTINTERFACES>
 
+<!--64984571E7EE46B590D617CAB3D28598--><AD_TEXTINTERFACES>
+<!--64984571E7EE46B590D617CAB3D28598-->  <AD_TEXTINTERFACES_ID><![CDATA[64984571E7EE46B590D617CAB3D28598]]></AD_TEXTINTERFACES_ID>
+<!--64984571E7EE46B590D617CAB3D28598-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--64984571E7EE46B590D617CAB3D28598-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--64984571E7EE46B590D617CAB3D28598-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--64984571E7EE46B590D617CAB3D28598-->  <TEXT><![CDATA[Payment Date To:]]></TEXT>
+<!--64984571E7EE46B590D617CAB3D28598-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportPDF.jrxml]]></FILENAME>
+<!--64984571E7EE46B590D617CAB3D28598-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--64984571E7EE46B590D617CAB3D28598-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--64984571E7EE46B590D617CAB3D28598--></AD_TEXTINTERFACES>
+
 <!--64F1EDBA15314054B3A147A4262B95FE--><AD_TEXTINTERFACES>
 <!--64F1EDBA15314054B3A147A4262B95FE-->  <AD_TEXTINTERFACES_ID><![CDATA[64F1EDBA15314054B3A147A4262B95FE]]></AD_TEXTINTERFACES_ID>
 <!--64F1EDBA15314054B3A147A4262B95FE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -396,6 +429,17 @@
 <!--7C6A82A324CD477F82B8E89EF51D7563-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--7C6A82A324CD477F82B8E89EF51D7563--></AD_TEXTINTERFACES>
 
+<!--7F5AB117CCB640BAB9142318F124DDCD--><AD_TEXTINTERFACES>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <AD_TEXTINTERFACES_ID><![CDATA[7F5AB117CCB640BAB9142318F124DDCD]]></AD_TEXTINTERFACES_ID>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <TEXT><![CDATA[Only empty Business Partner]]></TEXT>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--7F5AB117CCB640BAB9142318F124DDCD-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--7F5AB117CCB640BAB9142318F124DDCD--></AD_TEXTINTERFACES>
+
 <!--7FF75B077A6D4C2CA4752A0F82AD7B39--><AD_TEXTINTERFACES>
 <!--7FF75B077A6D4C2CA4752A0F82AD7B39-->  <AD_TEXTINTERFACES_ID><![CDATA[7FF75B077A6D4C2CA4752A0F82AD7B39]]></AD_TEXTINTERFACES_ID>
 <!--7FF75B077A6D4C2CA4752A0F82AD7B39-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -539,6 +583,17 @@
 <!--9BEBF44EF99C4B228D71CFC101710095-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--9BEBF44EF99C4B228D71CFC101710095--></AD_TEXTINTERFACES>
 
+<!--A062D2FD534B478CBBDD8BFE94834193--><AD_TEXTINTERFACES>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <AD_TEXTINTERFACES_ID><![CDATA[A062D2FD534B478CBBDD8BFE94834193]]></AD_TEXTINTERFACES_ID>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <TEXT><![CDATA[Payment Date From]]></TEXT>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A062D2FD534B478CBBDD8BFE94834193-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--A062D2FD534B478CBBDD8BFE94834193--></AD_TEXTINTERFACES>
+
 <!--A178474701304374BF37B9FFBB6B8E38--><AD_TEXTINTERFACES>
 <!--A178474701304374BF37B9FFBB6B8E38-->  <AD_TEXTINTERFACES_ID><![CDATA[A178474701304374BF37B9FFBB6B8E38]]></AD_TEXTINTERFACES_ID>
 <!--A178474701304374BF37B9FFBB6B8E38-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -792,6 +847,17 @@
 <!--D331A2D41B8840838C4708C92DC5E435-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--D331A2D41B8840838C4708C92DC5E435--></AD_TEXTINTERFACES>
 
+<!--D3B9E8172CB74CA98A74A6B119612106--><AD_TEXTINTERFACES>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <AD_TEXTINTERFACES_ID><![CDATA[D3B9E8172CB74CA98A74A6B119612106]]></AD_TEXTINTERFACES_ID>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <TEXT><![CDATA[Payment Date From:]]></TEXT>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportPDF.jrxml]]></FILENAME>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--D3B9E8172CB74CA98A74A6B119612106-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--D3B9E8172CB74CA98A74A6B119612106--></AD_TEXTINTERFACES>
+
 <!--D3DA75B510A54CEDAD7813134FA06BB7--><AD_TEXTINTERFACES>
 <!--D3DA75B510A54CEDAD7813134FA06BB7-->  <AD_TEXTINTERFACES_ID><![CDATA[D3DA75B510A54CEDAD7813134FA06BB7]]></AD_TEXTINTERFACES_ID>
 <!--D3DA75B510A54CEDAD7813134FA06BB7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -803,6 +869,17 @@
 <!--D3DA75B510A54CEDAD7813134FA06BB7-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--D3DA75B510A54CEDAD7813134FA06BB7--></AD_TEXTINTERFACES>
 
+<!--D79B532849AC43F09FB38375FB9CBBA2--><AD_TEXTINTERFACES>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <AD_TEXTINTERFACES_ID><![CDATA[D79B532849AC43F09FB38375FB9CBBA2]]></AD_TEXTINTERFACES_ID>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <TEXT><![CDATA[Payment Date To]]></TEXT>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--D79B532849AC43F09FB38375FB9CBBA2-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--D79B532849AC43F09FB38375FB9CBBA2--></AD_TEXTINTERFACES>
+
 <!--D97008CA65654BE69AFCDEECC9D20210--><AD_TEXTINTERFACES>
 <!--D97008CA65654BE69AFCDEECC9D20210-->  <AD_TEXTINTERFACES_ID><![CDATA[D97008CA65654BE69AFCDEECC9D20210]]></AD_TEXTINTERFACES_ID>
 <!--D97008CA65654BE69AFCDEECC9D20210-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -880,6 +957,17 @@
 <!--DEE5ED85F85742E0B8F4F000946A3B19-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
 <!--DEE5ED85F85742E0B8F4F000946A3B19--></AD_TEXTINTERFACES>
 
+<!--DF2CC16AD5894BA7B620A962C4632C27--><AD_TEXTINTERFACES>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <AD_TEXTINTERFACES_ID><![CDATA[DF2CC16AD5894BA7B620A962C4632C27]]></AD_TEXTINTERFACES_ID>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <TEXT><![CDATA[Exclude empty Business Partner]]></TEXT>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <FILENAME><![CDATA[/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html]]></FILENAME>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--DF2CC16AD5894BA7B620A962C4632C27-->  <AD_MODULE_ID><![CDATA[2A5EE903D7974AC298C0504FBC4501A7]]></AD_MODULE_ID>
+<!--DF2CC16AD5894BA7B620A962C4632C27--></AD_TEXTINTERFACES>
+
 <!--E460023C097749C5892A9CE255BD6FEB--><AD_TEXTINTERFACES>
 <!--E460023C097749C5892A9CE255BD6FEB-->  <AD_TEXTINTERFACES_ID><![CDATA[E460023C097749C5892A9CE255BD6FEB]]></AD_TEXTINTERFACES_ID>
 <!--E460023C097749C5892A9CE255BD6FEB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html	Wed Feb 15 20:33:15 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.html	Fri Feb 17 13:08:40 2012 +0000
@@ -56,15 +56,17 @@
 function printPDF()
 {
     initialize_MessageBox('messageBoxID');
-    if (validate())
+    if (validate()){
         openPDFFiltered("PaymentReport.html?Command=PDF","PDF");
+    }
     return true;
 }
 function printXLS()
 {
     initialize_MessageBox('messageBoxID');
-    if (validate())
+    if (validate()){
         openPDFFiltered("PaymentReport.html?Command=XLS","EXCEL");
+    }
     return true;
 }
 </script>
@@ -78,19 +80,19 @@
     function validate()
     {
         var frm=document.frmMain;
-        if (inputValue(frm.inpOrg)==null || inputValue(frm.inpOrg)=="") {
+        if (inputValue(frm.inpOrg)===null || inputValue(frm.inpOrg)==="") {
           setWindowElementFocus(frm.inpOrg);
           showJSMessage(7);
           return false;
-        }  else if (inputValue(frm.inpConvertCurrencyId)==null || inputValue(frm.inpConvertCurrencyId)=="") {
+        }  else if (inputValue(frm.inpConvertCurrencyId)===null || inputValue(frm.inpConvertCurrencyId)==="") {
           setWindowElementFocus(frm.inpConvertCurrencyId);
           showJSMessage(7);
           return false;
-        }  else if (inputValue(frm.inpConversionDate)==null || inputValue(frm.inpConversionDate)=="") {
+        }  else if (inputValue(frm.inpConversionDate)===null || inputValue(frm.inpConversionDate)==="") {
           setWindowElementFocus(frm.inpConversionDate);
           showJSMessage(7);
           return false;
-        }  else if (inputValue(frm.inpPaymType)==null || inputValue(frm.inpPaymType)=="") {
+        }  else if (inputValue(frm.inpPaymType)===null || inputValue(frm.inpPaymType)==="") {
           setWindowElementFocus(frm.inpPaymType);
           showJSMessage(7);
           return false;
@@ -103,6 +105,10 @@
         return true;
     }
     function onLoadDo(){
+    	
+    	  var selectedGroupBy = null;
+        var groupby = null;
+        
         this.windowTables = new Array(
           new windowTableId('client', 'buttonHTML')
         );
@@ -114,6 +120,14 @@
         enableShortcuts('edition');
         setBrowserAutoComplete(false);
         
+        selectedGroupBy = document.getElementById('paramcNoBPartner').value;
+        groupby = document.getElementById('inpcNoBPartner');
+        for (i=0;i<groupby.length;i++){
+          if (groupby[i].value === selectedGroupBy){
+            groupby[i].selected = true;
+          }
+        }
+        
         try {
           onloadFunctions();
         } catch (e) {}
@@ -140,7 +154,7 @@
         
         // Ordering criteria left: The option in grouping criteria gets hidden and it is put at the end.
         for (i = 0; i < ord.length; i++){
-            if (gro.options[gro.selectedIndex].value == ord.options[i].value){
+            if (gro.options[gro.selectedIndex].value === ord.options[i].value){
                 ord[i].style.visibility = "hidden";
                 lastOrd = ord[i];
             }
@@ -157,7 +171,7 @@
         
         // Ordering criteria right: The option in grouping criteria gets hidden and it is put at the end.
         for (i = 0; i < sho.length ; i++){
-            if (gro.options[gro.selectedIndex].value == sho.options[i].value){
+            if (gro.options[gro.selectedIndex].value === sho.options[i].value){
                 sho[i].style.visibility = "hidden";
                 lastSho = sho[i];
             }
@@ -185,14 +199,14 @@
         for (i = 0; i < ord.length; i++){
             // Duplicates between left and right.
             for (j = 0; j < sho.length; j++){
-                if (ord.options[i].value == sho.options[j].value){
+                if (ord.options[i].value === sho.options[j].value){
                     elementsToRemove.push(i);
                 }
             }
             // Duplicates in left part.
             for (j = 0; j < ord.length; j++){
-                if (ord.options[i].value == ord.options[j].value && i != j){
-                    if (ord.options[i].style.visibility == "hidden"){
+                if (ord.options[i].value === ord.options[j].value && i != j){
+                    if (ord.options[i].style.visibility === 'hidden'){
                         elementsToRemove.push(i);
                     } else {
                         elementsToRemove.push(j);
@@ -208,7 +222,7 @@
 
         // Ordering criteria left: Moving to last position intermediate hidden objects.
         for (i = 0; i < ord.length; i++){
-            if (ord.options[i].style.visibility == "hidden"){
+            if (ord.options[i].style.visibility === 'hidden'){
                 hiddenElement = ord[i];
                 ord.remove(i);
                 ord.add(hiddenElement, null);
@@ -217,7 +231,7 @@
 
         // Ordering criteria right: Moving to last position intermediate hidden objects.
         for (i = 0; i < sho.length; i++){
-            if (sho.options[i].style.visibility == "hidden"){
+            if (sho.options[i].style.visibility === 'hidden'){
                 hiddenElement = sho[i];
                 sho.remove(i);
                 sho.add(hiddenElement, null);
@@ -243,7 +257,7 @@
         
         for (i = 0; i < arrSelStatus.length; i++ ){
             for (j = 0; j < status.options.length; j++){
-                if (arrSelStatus[i] == status.options[j].value){
+                if (arrSelStatus[i] === status.options[j].value){
                     status.options[j].selected = true;
                 }
             }
@@ -252,7 +266,7 @@
     function openPaymentTab(isReceipt, recordId) {
        var myframe = getFrame('LayoutMDI') || top.opener;
        if (myframe) {
-           if (isReceipt=="Y") {
+           if (isReceipt==='Y') {
               myframe.OB.Utilities.openDirectTab('C4B6506838E14A349D6717D6856F1B56', recordId);
            } else {
               myframe.OB.Utilities.openDirectTab('F7A52FDAAA0346EFA07D53C125B40404', recordId);
@@ -262,7 +276,7 @@
     function openInvoiceTab(isReceipt, recordId) {
         var myframe = getFrame('LayoutMDI') || top.opener;
         if (myframe) {
-            if (isReceipt=="Y") {
+            if (isReceipt==='Y') {
                myframe.OB.Utilities.openDirectTab('EB0466B2A22343F28773B356D292BC7E', recordId);
             } else {
                myframe.OB.Utilities.openDirectTab('A94442B27F664A41BF64735DFA76FB4D', recordId);
@@ -457,13 +471,13 @@
                 </tr>
                 <tr>
                   <td class="TitleCell"><span class="LabelText">Due Date From</span></td>
-                  <td class="TextBox_ContentCell">
+                  <td class="TextBox_btn_ContentCell">
                     <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                       <tr>
                         <td class="TextBox_ContentCell">
                           <input dojoType="openbravo:DateTextbox" lowerThan="paramDueDateTo" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width" type="text" name="inpDueDateFrom" id="paramDueDateFrom" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramDueDateFrom");</script>
                         </td>
-                        <td class="FieldButton_bg">
+                        <td class="FieldButton_ContentCell">
                           <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpDueDateFrom', document.frmMain.inpDueDateFrom.value, false);return false;">
                           <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                             <tr>
@@ -486,7 +500,7 @@
                         <td class="TextBox_ContentCell">
                           <input dojoType="openbravo:DateTextbox" greaterThan="paramDueDateFrom" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width" type="text" name="inpDueDateTo" id="paramDueDateTo" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramDueDateTo");</script>
                         </td>
-                        <td class="FieldButton_bg">
+                        <td class="FieldButton_ContentCell">
                           <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpDueDateTo', document.frmMain.inpDueDateTo.value, false);return false;" >
                           <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                             <tr>
@@ -555,7 +569,7 @@
                         <td class="TextBox_ContentCell">
                           <input dojoType="openbravo:DateTextbox" lowerThan="paramDocumentDateTo" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width" type="text" name="inpDocumentDateFrom" id="paramDocumentDateFrom" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramDocumentDateFrom");</script>
                         </td>
-                        <td class="FieldButton_bg">
+                        <td class="FieldButton_ContentCell">
                           <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpDocumentDateFrom', document.frmMain.inpDocumentDateFrom.value, false);return false;" >
                           <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                             <tr>
@@ -578,7 +592,7 @@
                         <td class="TextBox_ContentCell">
                           <input dojoType="openbravo:DateTextbox" greaterThan="paramDocumentDateFrom" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width" type="text" name="inpDocumentDateTo" id="paramDocumentDateTo" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramDocumentDateTo");</script>
                         </td>
-                        <td class="FieldButton_bg">
+                        <td class="FieldButton_ContentCell">
                           <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpDocumentDateTo', document.frmMain.inpDocumentDateTo.value, false);return false;" >
                           <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                             <tr>
@@ -594,6 +608,52 @@
                   </td>
                 </tr>
                 <tr>
+                <td class="TitleCell"><span class="LabelText">Payment Date From</span></td>
+                 <td class="TextBox_btn_ContentCell">
+                    <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
+                      <tr>
+                        <td class="TextBox_ContentCell">
+                          <input dojoType="openbravo:DateTextbox" lowerThan="paramPaymentDateTo" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width" type="text" name="inpPaymentDateFrom" id="paramPaymentDateFrom" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramPaymentDateFrom");</script>
+                        </td>
+                        <td class="FieldButton_ContentCell">
+                          <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpPaymentDateFrom', document.frmMain.inpPaymentDateFrom.value, false);return false;" >
+                          <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
+                            <tr>
+                              <td class="FieldButton_bg">
+                                <img alt="Calendar" class="FieldButton_Icon FieldButton_Icon_Calendar" title="Calendar" src="../../../../../web/images/blank.gif" border="0"></img>
+                              </td>
+                            </tr>
+                          </table>
+                          </a>
+                        </td>
+                      </tr>
+                    </table>
+                  </td>
+                  <td class="ContentCell"></td>
+                  <td class="ContentCell"></td>
+                  <td class="TitleCell"><span class="LabelText">Payment Date To</span></td>
+                  <td class="TextBox_btn_ContentCell">
+                    <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
+                      <tr>
+                        <td class="TextBox_ContentCell">
+                          <input dojoType="openbravo:DateTextbox" greaterThan="paramPaymentDateFrom" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width" type="text" name="inpPaymentDateTo" id="paramPaymentDateTo" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramPaymentDateTo");</script>
+                        </td>
+                        <td class="FieldButton_ContentCell">
+                          <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpPaymentDateTo', document.frmMain.inpPaymentDateTo.value, false);return false;" >
+                          <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
+                            <tr>
+                              <td class="FieldButton_bg">
+                                <img alt="Calendar" class="FieldButton_Icon FieldButton_Icon_Calendar" title="Calendar" src="../../../../../web/images/blank.gif" border="0"></img>
+                              </td>
+                            </tr>
+                          </table>
+                          </a>
+                        </td>
+                      </tr>
+                    </table>
+                  </td>
+                </tr>
+                <tr>
                   <td class="TitleCell"><span class="LabelText">Business Partner</span></td>
                   <td class="List_ContentCell" colspan="2">
                     <table border="0" cellspacing="0" cellpadding="0">
@@ -683,12 +743,21 @@
                       </tr>
                     </table>
                   </td>
-                  <td class="TitleCell"><span class="LabelText">Business Partner Category</span></td>
-                  <td class="Combo_ContentCell" colspan="2">
-                    <select  name="inpcBPGroupId_IN" id="paramcBPGroupId_IN" class="Combo Combo_TwoCells_width">
+                  <td><table>
+                   	<tr rowspan="2"><td class="TitleCell"><span class="LabelText">Business Partner Category</span></td></tr>
+          <tr rowspan="3"><td class="TitleCell"><span class="LabelText">Empty Business Partner</span></td></tr>
+          </table></td>
+                  <td colspan="3"><table>
+                    <tr rowspan="2"><td class="Combo_ContentCell"><select  name="inpcBPGroupId_IN" id="paramcBPGroupId_IN" class="Combo Combo_TwoCells_width">
                        <option value=""><div id="reportBPGroupId_IN"></div></option>
+                    </select></td></tr>
+          <tr rowspan="3"><td class="Combo_ContentCell"><select  name="inpcNoBPartner" id="inpcNoBPartner" class="ComboKey Combo_TwoCells_width" required="true">
+                       <option value="include">Include empty Business Partner</option>
+             <option value="exclude">Exclude empty Business Partner</option>
+             <option value="only">Only empty Business Partner</option>
                     </select>
-                  </td>
+                    <input type="hidden" value="" id="paramcNoBPartner"/></td></tr>
+                  </table></td>
                 </tr>
                 <tr>
                   <td class="TitleCell"><span class="LabelText">Project</span></td>
@@ -834,7 +903,7 @@
                         <td class="TextBox_ContentCell">
                           <input dojoType="openbravo:DateTextbox" displayFormat="xx" saveFormat="yy"  class="TextBox_btn_OneCell_width required" required="true" type="text" name="inpConversionDate" id="paramConversionDate" size="10" maxlength="10" value="" onkeyup="autoCompleteDate(this.textbox, this.displayFormat);return true;"></input><script>djConfig.searchIds.push("paramConversionDate");</script>
                         </td>
-                        <td class="FieldButton_bg">
+                        <td class="FieldButton_ContentCell">
                           <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Calendar'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="showCalendar('frmMain.inpConversionDate', document.frmMain.inpConversionDate.value, false);return false;" >
                           <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Show calendar';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
                             <tr>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.java	Wed Feb 15 20:33:15 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.java	Fri Feb 17 13:08:40 2012 +0000
@@ -80,10 +80,16 @@
           "PaymentReport|DocumentDateFrom", "");
       String strDocumentDateTo = vars.getGlobalVariable("inpDocumentDateTo",
           "PaymentReport|DocumentDateTo", "");
+      String strPaymentDateFrom = vars.getGlobalVariable("inpPaymentDateFrom",
+          "PaymentReport|PaymentDateFrom", "");
+      String strPaymentDateTo = vars.getGlobalVariable("inpPaymentDateTo",
+          "PaymentReport|PaymentDateTo", "");
       String strcBPartnerIdIN = vars.getInGlobalVariable("inpcBPartnerId_IN",
           "PaymentReport|BusinessPartner", "", IsIDFilter.instance);
       String strcBPGroupIdIN = vars.getGlobalVariable("inpcBPGroupId_IN",
           "PaymentReport|BusinessPartnerCategory", "");
+      String strcNoBusinessPartner = vars.getGlobalVariable("inpcNoBPartner",
+          "PaymentReport|noBusinessPartner", "include");
       String strcProjectIdIN = vars.getInGlobalVariable("inpcProjectId_IN",
           "PaymentReport|Project", "", IsIDFilter.instance);
       dao = new PaymentReportDao();
@@ -96,9 +102,14 @@
       String strcCurrency = vars.getGlobalVariable("inpcCurrencyId", "PaymentReport|Currency", "",
           IsIDFilter.instance);
       String strConvertCurrency = null;
-      strConvertCurrency = vars.getGlobalVariable("inpConvertCurrencyId",
-          "PaymentReport|ConvertCurrency",
-          (String) DalUtil.getId(OBContext.getOBContext().getCurrentClient().getCurrency()));
+      OBContext.setAdminMode(true);
+      try {
+        strConvertCurrency = vars.getGlobalVariable("inpConvertCurrencyId",
+            "PaymentReport|ConvertCurrency",
+            (String) DalUtil.getId(OBContext.getOBContext().getCurrentClient().getCurrency()));
+      } finally {
+        OBContext.restorePreviousMode();
+      }
       if (strConvertCurrency == null) {
         strConvertCurrency = vars.getGlobalVariable("inpConvertCurrencyId",
             "PaymentReport|ConvertCurrency", "");
@@ -116,10 +127,12 @@
           "PaymentReport|IncludePaymentUsingCredit", "Y");
       printPageDataSheet(response, vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
           strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
-          strcBPGroupIdIN, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
-          strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
-          strOverdue, strGroupCrit, strOrdCrit, strInclPaymentUsingCredit);
-    } else if (vars.commandIn("FIND")) {
+          strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
+          strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
+          strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
+          strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
+      // DIRECT is used when coming from Aging Balance Report
+    } else if (vars.commandIn("FIND", "DIRECT")) {
       String strOrg = vars.getRequestGlobalVariable("inpOrg", "PaymentReport|Organization");
       String strInclSubOrg = vars.getRequestGlobalVariable("inpInclSubOrg",
           "PaymentReport|IncludeSubOrganization");
@@ -141,15 +154,31 @@
           "PaymentReport|DocumentDateFrom");
       String strDocumentDateTo = vars.getRequestGlobalVariable("inpDocumentDateTo",
           "PaymentReport|DocumentDateTo");
-      String strcBPartnerIdIN = vars.getRequestInGlobalVariable("inpcBPartnerId_IN",
-          "PaymentReport|BusinessPartner", IsIDFilter.instance);
+      String strPaymentDateFrom = vars.getRequestGlobalVariable("inpPaymentDateFrom",
+          "PaymentReport|PaymentDateFrom");
+      String strPaymentDateTo = vars.getRequestGlobalVariable("inpPaymentDateTo",
+          "PaymentReport|PaymentDateTo");
+      String strcBPartnerIdIN = "";
+      if (vars.commandIn("FIND")) {
+        strcBPartnerIdIN = vars.getRequestInGlobalVariable("inpcBPartnerId_IN",
+            "PaymentReport|BusinessPartner", IsIDFilter.instance);
+      } else {// vars.commandIn("DIRECT")
+        strcBPartnerIdIN = vars.getRequestGlobalVariable("inpcBPartnerId_IN", "");
+      }
       String strcBPGroupIdIN = vars.getRequestGlobalVariable("inpcBPGroupId_IN",
           "PaymentReport|BusinessPartnerCategory");
+      String strcNoBusinessPartner = vars.getGlobalVariable("inpcNoBPartner",
+          "PaymentReport|noBusinessPartner");
       String strcProjectIdIN = vars.getRequestInGlobalVariable("inpcProjectId_IN",
           "PaymentReport|Project", IsIDFilter.instance);
       dao = new PaymentReportDao();
-      String strfinPaymSt = vars.getRequestInGlobalVariable("inpfinPaymSt", "",
-          new ValueListFilter(dao.getReferenceListValues("FIN_Payment status", true)));
+      String strfinPaymSt = "";
+      if (vars.commandIn("FIND")) {
+        strfinPaymSt = vars.getRequestInGlobalVariable("inpfinPaymSt", "",
+            new ValueListFilter(dao.getReferenceListValues("FIN_Payment status", true)));
+      } else {// vars.commandIn("DIRECT")
+        strfinPaymSt = vars.getRequestGlobalVariable("inpFinPaymSt", "");
+      }
       String strPaymentMethodId = vars.getRequestGlobalVariable("inpPaymentMethodId",
           "PaymentReport|PaymentMethodId", IsIDFilter.instance);
       String strFinancialAccountId = vars.getRequestGlobalVariable("inpFinancialAccountId",
@@ -173,9 +202,10 @@
       vars.setSessionValue("PaymentReport|IncludePaymentUsingCredit", strInclPaymentUsingCredit);
       printPageDataSheet(response, vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
           strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
-          strcBPGroupIdIN, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
-          strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
-          strOverdue, strGroupCrit, strOrdCrit, strInclPaymentUsingCredit);
+          strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
+          strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
+          strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
+          strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
     } else if (vars.commandIn("PDF", "XLS")) {
       String strOrg = vars.getRequestGlobalVariable("inpOrg", "PaymentReport|Organization");
       String strInclSubOrg = vars.getRequestGlobalVariable("inpInclSubOrg",
@@ -192,10 +222,16 @@
           "PaymentReport|DocumentDateFrom");
       String strDocumentDateTo = vars.getRequestGlobalVariable("inpDocumentDateTo",
           "PaymentReport|DocumentDateTo");
+      String strPaymentDateFrom = vars.getRequestGlobalVariable("inpPaymentDateFrom",
+          "PaymentReport|PaymentDateFrom");
+      String strPaymentDateTo = vars.getRequestGlobalVariable("inpPaymentDateTo",
+          "PaymentReport|PaymentDateTo");
       String strcBPartnerIdIN = vars.getRequestInGlobalVariable("inpcBPartnerId_IN",
           "PaymentReport|BusinessPartner", IsIDFilter.instance);
       String strcBPGroupIdIN = vars.getRequestGlobalVariable("inpcBPGroupId_IN",
           "PaymentReport|BusinessPartnerCategory");
+      String strcNoBusinessPartner = vars.getGlobalVariable("inpcNoBPartner",
+          "PaymentReport|noBusinessPartner");
       String strcProjectIdIN = vars.getRequestInGlobalVariable("inpcProjectId_IN",
           "PaymentReport|Project", IsIDFilter.instance);
       dao = new PaymentReportDao();
@@ -230,9 +266,10 @@
 
       printPage(request, response, vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
           strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
-          strcBPGroupIdIN, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
-          strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
-          strOverdue, strOutput, strGroupCrit, strOrdCrit, strInclPaymentUsingCredit);
+          strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
+          strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
+          strConversionDate, strPaymType, strOverdue, strOutput, strGroupCrit, strOrdCrit,
+          strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
 
     } else if (vars.commandIn("LINK")) {
       String strTableId = vars.getRequiredStringParameter("inpAdTableId", IsIDFilter.instance);
@@ -259,10 +296,11 @@
       String strOrg, String strInclSubOrg, String strDueDateFrom, String strDueDateTo,
       String strAmountFrom, String strAmountTo, String strDocumentDateFrom,
       String strDocumentDateTo, String strcBPartnerIdIN, String strcBPGroupIdIN,
-      String strcProjectIdIN, String strfinPaymSt, String strPaymentMethodId,
-      String strFinancialAccountId, String strcCurrency, String strConvertCurrency,
-      String strConversionDate, String strPaymType, String strOverdue, String strGroupCrit,
-      String strOrdCrit, String strInclPaymentUsingCredit) throws IOException, ServletException {
+      String strcNoBusinessPartner, String strcProjectIdIN, String strfinPaymSt,
+      String strPaymentMethodId, String strFinancialAccountId, String strcCurrency,
+      String strConvertCurrency, String strConversionDate, String strPaymType, String strOverdue,
+      String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit,
+      String strPaymentDateFrom, String strPaymentDateTo) throws IOException, ServletException {
     if (log4j.isDebugEnabled())
       log4j.debug("Output: dataSheet");
     XmlDocument xmlDocument = null;
@@ -270,16 +308,39 @@
     FieldProvider[] data = null;
     String[] discard = null;
 
-    if (vars.commandIn("FIND")) {
+    if (vars.commandIn("FIND", "DIRECT")) {
       dao = new PaymentReportDao();
 
-      data = dao.getPaymentReport(vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
-          strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
-          strcBPGroupIdIN, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
-          strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
-          strOverdue, strGroupCrit, strOrdCrit, strInclPaymentUsingCredit);
+      try {
+        data = dao.getPaymentReport(vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
+            strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
+            strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
+            strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
+            strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
+            strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
+      } catch (Exception e) {
+        discardAL.add("sectionGroupCrit");
+        discardAL.add("sectionStatus");
+        discardAL.add("sectionTotal");
+        discardAL.add("sectionTotal2");
+        discardAL.add("sectionSubtotalGroupCrit");
+        discard = new String[discardAL.size()];
 
-      if (data.length == 0) {
+        xmlDocument = xmlEngine.readXmlTemplate(
+            "org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport",
+            discardAL.toArray(discard)).createXmlDocument();
+
+        xmlDocument.setParameter("messageType", "WARNING");
+        xmlDocument.setParameter("messageTitle",
+            Utility.messageBD(this, "ProcessStatus-W", vars.getLanguage()));
+        xmlDocument
+            .setParameter(
+                "messageMessage",
+                Utility.messageBD(this, "FINPR_NoConversionFound", vars.getLanguage())
+                    + e.getMessage());
+      }
+
+      if (data != null && data.length == 0) {
 
         discardAL.add("sectionGroupCrit");
         discardAL.add("sectionStatus");
@@ -298,7 +359,7 @@
         xmlDocument.setParameter("messageMessage",
             Utility.messageBD(this, "FINPR_NoDataFound", vars.getLanguage()));
 
-      } else if (data.length == 1 && data[0].getField("conversionDate") != null) {
+      } else if (data != null && data.length == 1 && data[0].getField("conversionDate") != null) {
 
         String transCurrency = OBDal.getInstance()
             .get(Currency.class, data[0].getField("transCurrency")).getISOCode();
@@ -325,7 +386,7 @@
         xmlDocument.setParameter("messageMessage",
             Utility.messageBD(this, "FINPR_NoConversionFound", vars.getLanguage()) + message);
 
-      } else {
+      } else if (data != null) {
 
         if (strGroupCrit.isEmpty()) {
           discardAL.add("sectionGroupCrit");
@@ -420,6 +481,11 @@
     xmlDocument.setParameter("documentDateTo", strDocumentDateTo);
     xmlDocument
         .setParameter("documentDateTodisplaySave", vars.getSessionValue("#AD_SqlDateFormat"));
+    xmlDocument.setParameter("paymentDateFrom", strPaymentDateFrom);
+    xmlDocument.setParameter("paymentDateFromdisplaySave",
+        vars.getSessionValue("#AD_SqlDateFormat"));
+    xmlDocument.setParameter("paymentDateTo", strPaymentDateTo);
+    xmlDocument.setParameter("paymentDateTodisplaySave", vars.getSessionValue("#AD_SqlDateFormat"));
 
     xmlDocument.setData(
         "paramcBPartnerId_IN",
@@ -440,6 +506,8 @@
       throw new ServletException(ex);
     }
 
+    xmlDocument.setParameter("noBusinessPartner", strcNoBusinessPartner);
+
     xmlDocument.setData(
         "paramcProjectId_IN",
         "liststructure",
@@ -641,28 +709,36 @@
       VariablesSecureApp vars, String strOrg, String strInclSubOrg, String strDueDateFrom,
       String strDueDateTo, String strAmountFrom, String strAmountTo, String strDocumentDateFrom,
       String strDocumentDateTo, String strcBPartnerIdIN, String strcBPGroupIdIN,
-      String strcProjectIdIN, String strfinPaymSt, String strPaymentMethodId,
-      String strFinancialAccountId, String strcCurrency, String strConvertCurrency,
-      String strConversionDate, String strPaymType, String strOverdue, String strOutput,
-      String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit) throws IOException,
-      ServletException {
+      String strcNoBusinessPartner, String strcProjectIdIN, String strfinPaymSt,
+      String strPaymentMethodId, String strFinancialAccountId, String strcCurrency,
+      String strConvertCurrency, String strConversionDate, String strPaymType, String strOverdue,
+      String strOutput, String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit,
+      String strPaymentDateFrom, String strPaymentDateTo) throws IOException, ServletException {
 
     response.setContentType("text/html; charset=UTF-8");
 
     dao = new PaymentReportDao();
-    FieldProvider[] data = dao.getPaymentReport(vars, strOrg, strInclSubOrg, strDueDateFrom,
-        strDueDateTo, strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo,
-        strcBPartnerIdIN, strcBPGroupIdIN, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
-        strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
-        strOverdue, strGroupCrit, strOrdCrit, strInclPaymentUsingCredit);
+    FieldProvider[] data = null;
+    try {
+      data = dao.getPaymentReport(vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
+          strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
+          strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt,
+          strPaymentMethodId, strFinancialAccountId, strcCurrency, strConvertCurrency,
+          strConversionDate, strPaymType, strOverdue, strGroupCrit, strOrdCrit,
+          strInclPaymentUsingCredit, strPaymentDateFrom, strPaymentDateTo);
+    } catch (Exception e) {
+      advisePopUp(request, response, "WARNING",
+          Utility.messageBD(this, "ProcessStatus-W", vars.getLanguage()),
+          Utility.messageBD(this, "FINPR_NoConversionFound", vars.getLanguage()) + e.getMessage());
+    }
 
-    if (data.length == 1 && data[0] == null) {
+    if (data != null && data.length == 1 && data[0] == null) {
 
       advisePopUp(request, response, "WARNING",
           Utility.messageBD(this, "ProcessStatus-W", vars.getLanguage()),
           Utility.messageBD(this, "FINPR_NoDataFound", vars.getLanguage()));
 
-    } else if (data.length == 1 && data[0].getField("conversionDate") != null) {
+    } else if (data != null && data.length == 1 && data[0].getField("conversionDate") != null) {
 
       String transCurrency = OBDal.getInstance()
           .get(Currency.class, data[0].getField("transCurrency")).getISOCode();
@@ -808,6 +884,8 @@
     parameters.put("AMTTO_SHOW", strAmountTo);
     parameters.put("DOCDATEFROM_SHOW", strDocumentDateFrom);
     parameters.put("DOCDATETO_SHOW", strDocumentDateTo);
+    parameters.put("PAYDATEFROM_SHOW", strPaymentDateFrom);
+    parameters.put("PAYDATETO_SHOW", strPaymentDateTo);
     parameters.put("BPARTNER_SHOW", strBPartnerShow);
     parameters.put("BPGROUP_SHOW", strBPGroupShow);
     parameters.put("PROJECT_SHOW", strProjectShow);
@@ -833,7 +911,9 @@
     parameters.put("ONE_ASTERISK_SHOW", new Boolean(showAsterisk(data, "*")));
     parameters.put("TWO_ASTERISK_SHOW", new Boolean(showAsterisk(data, "**")));
 
-    renderJR(vars, response, strReportName, strOutput, parameters, data, null);
+    if (data != null) {
+      renderJR(vars, response, strReportName, strOutput, parameters, data, null);
+    }
   }
 
   public String getServletInfo() {
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.xml	Wed Feb 15 20:33:15 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReport.xml	Fri Feb 17 13:08:40 2012 +0000
@@ -50,7 +50,13 @@
   <PARAMETER id="paramDocumentDateTo" name="documentDateTo" attribute="value"/>
   <PARAMETER id="paramDocumentDateTo" name="documentDateTodisplaySave" attribute="displayformat" replace="xx"/>
   <PARAMETER id="paramDocumentDateTo" name="documentDateTodisplaySave" attribute="saveformat" replace="yy"/>
-
+  <PARAMETER id="paramPaymentDateFrom" name="paymentDateFrom" attribute="value"/>
+  <PARAMETER id="paramPaymentDateFrom" name="paymentDateFromdisplaySave" attribute="displayformat" replace="xx"/>
+  <PARAMETER id="paramPaymentDateFrom" name="paymentDateFromdisplaySave" attribute="saveformat" replace="yy"/>
+  <PARAMETER id="paramPaymentDateTo" name="paymentDateTo" attribute="value"/>
+  <PARAMETER id="paramPaymentDateTo" name="paymentDateTodisplaySave" attribute="displayformat" replace="xx"/>
+  <PARAMETER id="paramPaymentDateTo" name="paymentDateTodisplaySave" attribute="saveformat" replace="yy"/>
+  
   <PARAMETER id="parameterInclPaymentUsingCredit" name="pinclPaymentUsingCredit" default="Y"/>
   <PARAMETER id="paramInclPaymentUsingCredit" name="inclPaymentUsingCredit" boolean="checked" withId="parameterInclPaymentUsingCredit" default="Y"/>
   
@@ -64,6 +70,8 @@
     <ARGUMENT name="parameterListSelected" withId="paramcBPGroupId_IN"/>
   </SUBREPORT>
   
+  <PARAMETER id="paramcNoBPartner" name="noBusinessPartner" attribute="value" default="include"/>
+  
   <PARAMETER id="paramcProjectId_INselected" name="paramcProjectId_INselected" default=""/>
   <SUBREPORT id="paramcProjectId_IN" name="paramcProjectId_IN" report="org/openbravo/erpCommon/reference/List">
     <ARGUMENT name="parameterListSelected" withId="paramcProjectId_INselected"/>
@@ -195,9 +203,8 @@
     <SECTION id="sectionStatus2" field="STATUS"/>
     <SECTION id="sectionDetail2"/>
   </structure>
-
-   
+  
   <PARAMETER id="paramShowOneAsterisk" name="showOneAsterisk" attribute="style" replace="xx"/>
-  <PARAMETER id="paramShowTwoAsterisk" name="showTwoAsterisk" attribute="style" replace="xx"/>  
+  <PARAMETER id="paramShowTwoAsterisk" name="showTwoAsterisk" attribute="style" replace="xx"/>
   <DISCARD id="discard"/>
 </REPORT>
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Wed Feb 15 20:33:15 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Fri Feb 17 13:08:40 2012 +0000
@@ -20,6 +20,7 @@
 package org.openbravo.financial.paymentreport.erpCommon.ad_reports;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -29,8 +30,10 @@
 import java.util.Set;
 import java.util.Vector;
 
+import org.apache.log4j.Logger;
 import org.hibernate.Query;
 import org.hibernate.Session;
+import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.base.secureApp.VariablesSecureApp;
@@ -39,9 +42,11 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.utility.FieldProviderFactory;
 import org.openbravo.erpCommon.utility.SQLReturnObject;
+import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.datamodel.Column;
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.domain.List;
@@ -54,7 +59,10 @@
 import org.openbravo.model.common.businesspartner.Category;
 import org.openbravo.model.common.currency.ConversionRate;
 import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
@@ -65,6 +73,7 @@
 public class PaymentReportDao {
 
   private static final long milisecDayConv = (1000 * 60 * 60 * 24);
+  static Logger log4j = Logger.getLogger(Utility.class);
 
   public PaymentReportDao() {
   }
@@ -76,24 +85,27 @@
   public FieldProvider[] getPaymentReport(VariablesSecureApp vars, String strOrg,
       String strInclSubOrg, String strDueDateFrom, String strDueDateTo, String strAmountFrom,
       String strAmountTo, String strDocumentDateFrom, String strDocumentDateTo,
-      String strcBPartnerIdIN, String strcBPGroupIdIN, String strcProjectIdIN, String strfinPaymSt,
-      String strPaymentMethodId, String strFinancialAccountId, String strcCurrency,
-      String strConvertCurrency, String strConversionDate, String strPaymType, String strOverdue,
-      String strGroupCrit, String strOrdCrit) {
+      String strcBPartnerIdIN, String strcBPGroupIdIN, String strcNoBusinessPartner,
+      String strcProjectIdIN, String strfinPaymSt, String strPaymentMethodId,
+      String strFinancialAccountId, String strcCurrency, String strConvertCurrency,
+      String strConversionDate, String strPaymType, String strOverdue, String strGroupCrit,
+      String strOrdCrit, String strPaymentDateFrom, String strPaymentDateTo) throws Exception {
     return getPaymentReport(vars, strOrg, strInclSubOrg, strDueDateFrom, strDueDateTo,
         strAmountFrom, strAmountTo, strDocumentDateFrom, strDocumentDateTo, strcBPartnerIdIN,
-        strcBPGroupIdIN, strcProjectIdIN, strfinPaymSt, strPaymentMethodId, strFinancialAccountId,
-        strcCurrency, strConvertCurrency, strConversionDate, strPaymType, strOverdue, strGroupCrit,
-        strOrdCrit, "Y");
+        strcBPGroupIdIN, strcNoBusinessPartner, strcProjectIdIN, strfinPaymSt, strPaymentMethodId,
+        strFinancialAccountId, strcCurrency, strConvertCurrency, strConversionDate, strPaymType,
+        strOverdue, strGroupCrit, strOrdCrit, "Y", strPaymentDateFrom, strPaymentDateTo);
   }
 
   public FieldProvider[] getPaymentReport(VariablesSecureApp vars, String strOrg,
       String strInclSubOrg, String strDueDateFrom, String strDueDateTo, String strAmountFrom,
       String strAmountTo, String strDocumentDateFrom, String strDocumentDateTo,
-      String strcBPartnerIdIN, String strcBPGroupIdIN, String strcProjectIdIN, String strfinPaymSt,
-      String strPaymentMethodId, String strFinancialAccountId, String strcCurrency,
-      String strConvertCurrency, String strConversionDate, String strPaymType, String strOverdue,
-      String strGroupCrit, String strOrdCrit, String strInclPaymentUsingCredit) {
+      String strcBPartnerIdIN, String strcBPGroupIdIN, String strcNoBusinessPartner,
+      String strcProjectIdIN, String strfinPaymSt, String strPaymentMethodId,
+      String strFinancialAccountId, String strcCurrency, String strConvertCurrency,
+      String strConversionDate, String strPaymType, String strOverdue, String strGroupCrit,
+      String strOrdCrit, String strInclPaymentUsingCredit, String strPaymentDateFrom,
+      String strPaymentDateTo) throws Exception {
 
     final StringBuilder hsqlScript = new StringBuilder();
     final java.util.List<Object> parameters = new ArrayList<Object>();
@@ -102,12 +114,17 @@
         .getProperty("dateFormat.java");
     SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatString);
     FieldProvider[] data;
+    FieldProvider[] transactionData;
     Currency transCurrency;
     BigDecimal transAmount = null;
     ConversionRate convRate = null;
     ArrayList<FieldProvider> groupedData = new ArrayList<FieldProvider>();
+    ArrayList<FieldProvider> totalData = new ArrayList<FieldProvider>();
+    int numberOfElements = 0;
+    int lastElement = 0;
+    boolean existsConvRate = false;
 
-    OBContext.setAdminMode();
+    OBContext.setAdminMode(true);
     try {
 
       hsqlScript
@@ -192,21 +209,82 @@
         parameters.add(FIN_Utility.getDate(strDocumentDateTo));
       }
 
-      // business partner
-      if (!strcBPartnerIdIN.isEmpty()) {
+      // payment date from - payment date to
+      if (!strPaymentDateFrom.isEmpty()) {
+        hsqlScript.append(" and ((pay.");
+        hsqlScript.append(FIN_Payment.PROPERTY_PAYMENTDATE);
+        hsqlScript.append(" > ?)  or (pay.");
+        hsqlScript.append(FIN_Payment.PROPERTY_PAYMENTDATE);
+        hsqlScript.append(" is null and invps.");
+        hsqlScript.append(FIN_PaymentSchedule.PROPERTY_DUEDATE);
+        hsqlScript.append(" >= ?))");
+        parameters.add(FIN_Utility.getDate(strPaymentDateFrom));
+        parameters.add(FIN_Utility.getDate(strPaymentDateFrom));
+      }
+      if (!strPaymentDateTo.isEmpty()) {
         hsqlScript.append(" and coalesce(pay.");
-        hsqlScript.append(FIN_Payment.PROPERTY_BUSINESSPARTNER);
-        hsqlScript.append(", inv.");
-        hsqlScript.append(Invoice.PROPERTY_BUSINESSPARTNER);
-        hsqlScript.append(") in ");
-        hsqlScript.append(strcBPartnerIdIN);
+        hsqlScript.append(FIN_Payment.PROPERTY_PAYMENTDATE);
+        hsqlScript.append(", invps.");
+        hsqlScript.append(FIN_PaymentSchedule.PROPERTY_DUEDATE);
+        hsqlScript.append(") <= ?");
+        parameters.add(FIN_Utility.getDate(strPaymentDateTo));
       }
 
-      // business partner category
-      if (!strcBPGroupIdIN.isEmpty()) {
-        hsqlScript.append(" and coalesce(paybpc, invbpc) = '");
-        hsqlScript.append(strcBPGroupIdIN);
-        hsqlScript.append("'");
+      // Empty Business Partner included
+      if (strcNoBusinessPartner.equals("include")) {
+
+        // business partner
+        if (!strcBPartnerIdIN.isEmpty()) {
+          hsqlScript.append(" and ((coalesce(pay.");
+          hsqlScript.append(FIN_Payment.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(", inv.");
+          hsqlScript.append(Invoice.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(") in ");
+          hsqlScript.append(strcBPartnerIdIN);
+          hsqlScript.append(") or (pay.");
+          hsqlScript.append(FIN_Payment.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(" is null and inv.");
+          hsqlScript.append(Invoice.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(" is null))");
+        }
+        // business partner category
+        if (!strcBPGroupIdIN.isEmpty()) {
+          hsqlScript.append(" and (coalesce(paybpc, invbpc) = '");
+          hsqlScript.append(strcBPGroupIdIN);
+          hsqlScript.append("' or (pay.");
+          hsqlScript.append(FIN_Payment.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(" is null and inv.");
+          hsqlScript.append(Invoice.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(" is null))");
+        }
+
+        // Empty Businesss Partner excluded
+      } else if (strcNoBusinessPartner.equals("exclude")) {
+
+        // business partner
+        if (!strcBPartnerIdIN.isEmpty()) {
+          hsqlScript.append(" and coalesce(pay.");
+          hsqlScript.append(FIN_Payment.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(", inv.");
+          hsqlScript.append(Invoice.PROPERTY_BUSINESSPARTNER);
+          hsqlScript.append(") in ");
+          hsqlScript.append(strcBPartnerIdIN);
+        }
+
+        // business partner category
+        if (!strcBPGroupIdIN.isEmpty()) {
+          hsqlScript.append(" and coalesce(paybpc, invbpc) = '");
+          hsqlScript.append(strcBPGroupIdIN);
+          hsqlScript.append("'");
+        }
+        // exclude empty business partner
+        if (strcBPartnerIdIN.isEmpty() && strcBPGroupIdIN.isEmpty()) {
+          hsqlScript.append(" and (paybpc is not null or invbpc is not null) ");
+        }
+
+        // Only Empty Business Partner
+      } else {// if ((strcNoBusinessPartner.equals("only")))
+        hsqlScript.append(" and paybpc is null and invbpc is null ");
       }
 
       // project
@@ -425,6 +503,19 @@
       boolean isReceipt = false;
       boolean isAmtInLimit = false;
 
+      // Before processing the data the Transactions without a Payment associated are recovered
+      java.util.List<FIN_FinaccTransaction> transactionsList = getTransactionsList(strInclSubOrg,
+          strOrg, strcBPartnerIdIN, strFinancialAccountId, strDocumentDateFrom, strDocumentDateTo,
+          strPaymentDateFrom, strPaymentDateTo, strAmountFrom, strAmountTo, strcBPGroupIdIN,
+          strcProjectIdIN, strfinPaymSt, strcCurrency, strPaymType, strGroupCrit, strOrdCrit,
+          strcNoBusinessPartner);
+
+      transactionData = FieldProviderFactory.getFieldProviderArray(transactionsList);
+      int totalTransElements = transactionsList.size();
+
+      // There are three variables involved in this loop. The first one is data, wich is the
+      // the one the loop processes. Then grouped data is used to group similar data lines into
+      // one. Finally total data adds the remaining information that is not in data.
       for (int i = 0; i < data.length; i++) {
 
         // If the payment schedule detail has a payment detail, then, the information is taken from
@@ -483,6 +574,8 @@
           FieldProviderFactory.setField(data[i], "STATUS",
               translateRefList(FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
                   .getStatus()));
+          FieldProviderFactory.setField(data[i], "STATUS_CODE", FIN_PaymentScheduleDetail[i]
+              .getPaymentDetails().getFinPayment().getStatus());
           // is receipt
           if (FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment().isReceipt()) {
             FieldProviderFactory.setField(data[i], "ISRECEIPT", "Y");
@@ -521,14 +614,13 @@
           FieldProviderFactory.setField(data[i], "FINANCIAL_ACCOUNT", "");
           // status
           FieldProviderFactory.setField(data[i], "STATUS", translateRefList("RPAP"));
+          FieldProviderFactory.setField(data[i], "STATUS_CODE", "RPAP");
           // is receipt
           if (FIN_PaymentScheduleDetail[i].getInvoicePaymentSchedule().getInvoice()
               .isSalesTransaction()) {
             FieldProviderFactory.setField(data[i], "ISRECEIPT", "Y");
             isReceipt = true;
-          }
-
-          else {
+          } else {
             FieldProviderFactory.setField(data[i], "ISRECEIPT", "N");
             isReceipt = false;
           }
@@ -570,7 +662,7 @@
             // payment plan yes / no
             FieldProviderFactory.setField(data[i], "NOT_PAYMENT_PLAN_Y_N", invoices.size() > 1 ? ""
                 : "Display:none");
-            // invoiceDate
+            // invoiceDatestrcProjectIdIN
             FieldProviderFactory.setField(data[i], "INVOICE_DATE", "");
             // dueDate.
             FieldProviderFactory.setField(data[i], "DUE_DATE", "");
@@ -607,7 +699,7 @@
 
         }
 
-        // transactional and base amounts
+        // Transactional and base amounts
         transAmount = FIN_PaymentScheduleDetail[i].getAmount();
 
         Currency baseCurrency = OBDal.getInstance().get(Currency.class, strConvertCurrency);
@@ -637,17 +729,9 @@
                       .setScale(stdPrecission, BigDecimal.ROUND_HALF_UP).negate().toString());
             }
           } else {
-            FieldProvider[] fp = new FieldProvider[1];
-            HashMap<String, String> hm = new HashMap<String, String>();
-            hm.put("transCurrency", transCurrency.getId());
-            hm.put("baseCurrency", strConvertCurrency);
-            hm.put("conversionDate", strConversionDate);
-
-            fp[0] = new FieldProviderFactory(hm);
-            data = fp;
-
-            OBContext.restorePreviousMode();
-            return data;
+            String message = transCurrency.getISOCode() + " -> " + baseCurrency.getISOCode() + " "
+                + strConversionDate;
+            throw new Exception(message);
           }
         } else {
           convRate = null;
@@ -776,6 +860,7 @@
             if (isAmtInLimit) {
               groupedData.add(previousRow);
               isAmtInLimit = false;
+              numberOfElements++;
             }
           }
           previousRow = data[i];
@@ -805,6 +890,22 @@
           FieldProviderFactory.setField(previousRow, "GROUP_CRIT_ID", "");
         }
 
+        // Insert the transactions without payment if necessary
+        if (lastElement != numberOfElements) {
+          if (transactionsList.size() > 0) {
+            try {
+              existsConvRate = insertIntoTotal(groupedData.get(lastElement), transactionsList,
+                  totalData, strGroupCrit, strOrdCrit, transactionData, totalTransElements,
+                  strConvertCurrency, strConversionDate);
+            } catch (Exception e) {
+              // If there is no conversion rate
+              throw e;
+            }
+          }
+          totalData.add(groupedData.get(lastElement));
+          lastElement++;
+        }
+
       }
       if (previousRow != null) {
         // The current row has nothing to do with the previous one. Because of that, the
@@ -854,12 +955,632 @@
         if (isAmtInLimit) {
           groupedData.add(previousRow);
           isAmtInLimit = false;
+          numberOfElements++;
         }
       }
+
+      // Insert the transactions without payment if necessary
+      if (lastElement != numberOfElements) {
+        if (transactionsList.size() > 0) {
+          try {
+            existsConvRate = insertIntoTotal(groupedData.get(lastElement), transactionsList,
+                totalData, strGroupCrit, strOrdCrit, transactionData, totalTransElements,
+                strConvertCurrency, strConversionDate);
+          } catch (Exception e) {
+            // If there is no conversion rate
+            throw e;
+          }
+        }
+        totalData.add(groupedData.get(lastElement));
+        lastElement++;
+      }
+
+      // Insert the remaining transactions wihtout payment if necessary
+      while (transactionsList.size() > 0) {
+        try {
+          transactionData[totalTransElements - transactionsList.size()] = createFieldProviderForTransaction(
+              transactionsList.get(0),
+              transactionData[totalTransElements - transactionsList.size()], strGroupCrit,
+              strConvertCurrency, strConversionDate);
+        } catch (Exception e) {
+          // If there is no conversion rate
+          throw e;
+        }
+        totalData.add(transactionData[totalTransElements - transactionsList.size()]);
+        transactionsList.remove(0);
+      }
     } finally {
       OBContext.restorePreviousMode();
     }
-    return (FieldProvider[]) groupedData.toArray(new FieldProvider[groupedData.size()]);
+    return (FieldProvider[]) totalData.toArray(new FieldProvider[totalData.size()]);
+  }
+
+  /**
+   * This method combines the information from the transactions list and the last element inserted
+   * into grouped data into total data.
+   * 
+   * @param fieldProvider
+   * @param transactionsList
+   * @param totalData
+   * @throws Exception
+   */
+  private boolean insertIntoTotal(FieldProvider data,
+      java.util.List<FIN_FinaccTransaction> transactionsList, ArrayList<FieldProvider> totalData,
+      String strGroupCrit, String strOrdCrit, FieldProvider[] transactionData,
+      int totalTransElements, String strConvertCurrency, String strConversionDate) throws Exception {
+
+    while (transactionsList.size() > 0
+        && transactionIsBefore(transactionsList.get(0), data, strGroupCrit, strOrdCrit)) {
+      try {
+        transactionData[totalTransElements - transactionsList.size()] = createFieldProviderForTransaction(
+            transactionsList.get(0), transactionData[totalTransElements - transactionsList.size()],
+            strGroupCrit, strConvertCurrency, strConversionDate);
+      } catch (Exception e) {
+        // If there is no conversion rate
+        throw e;
+      }
+      totalData.add(transactionData[totalTransElements - transactionsList.size()]);
+      transactionsList.remove(0);
+    }
+    return true;
+  }
+
+  /**
+   * This method creates a field provider with the information of the transaction
+   * 
+   * @param fin_FinaccTransaction
+   * @return
+   * @throws Exception
+   */
+  private FieldProvider createFieldProviderForTransaction(FIN_FinaccTransaction transaction,
+      FieldProvider transactionData, String strGroupCrit, String strConvertCurrency,
+      String strConversionDate) throws Exception {
+    String dateFormatString = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("dateFormat.java");
+    SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatString);
+    BigDecimal transAmount = null;
+    ConversionRate convRate = null;
+
+    // bp_group -- bp_category
+    if (transaction.getBusinessPartner() != null) {
+      FieldProviderFactory.setField(transactionData, "BP_GROUP", transaction.getBusinessPartner()
+          .getBusinessPartnerCategory().getName());
+      // bpartner
+      FieldProviderFactory.setField(transactionData, "BPARTNER", transaction.getBusinessPartner()
+          .getName());
+    } else {
+      // bp_group -- bp_category & bpartner
+      FieldProviderFactory.setField(transactionData, "BP_GROUP", "");
+      FieldProviderFactory.setField(transactionData, "BPARTNER", "");
+    }
+    // transCurrency
+    FieldProviderFactory.setField(transactionData, "TRANS_CURRENCY", transaction.getCurrency()
+        .getISOCode());
+    // paymentMethod
+    FieldProviderFactory.setField(transactionData, "PAYMENT_METHOD", "");
+    // payment
+    FieldProviderFactory.setField(transactionData, "PAYMENT", "");
+    // description
+    FieldProviderFactory.setField(transactionData, "PAYMENT_DESC", transaction.getDescription());
+    // payment_id
+    FieldProviderFactory.setField(transactionData, "PAYMENT_ID", "");
+    // payment_date
+    FieldProviderFactory.setField(transactionData, "PAYMENT_DATE",
+        dateFormat.format(transaction.getDateAcct()));
+    // payment_docNo
+    FieldProviderFactory.setField(transactionData, "PAYMENT_DOCNO", "");
+    // payment yes / no
+    FieldProviderFactory.setField(transactionData, "PAYMENT_Y_N", "Display:None");
+    // financialAccount
+    FieldProviderFactory.setField(transactionData, "FINANCIAL_ACCOUNT", transaction.getAccount()
+        .getIdentifier());
+    // status
+    FieldProviderFactory.setField(transactionData, "STATUS",
+        translateRefList(transaction.getStatus()));
+    FieldProviderFactory.setField(transactionData, "STATUS_CODE", transaction.getStatus());
+    // is receipt
+    if (transaction.getStatus().equals("PWNC")) {
+      FieldProviderFactory.setField(transactionData, "ISRECEIPT", "Y");
+      // isReceipt = true;
+    } else if (transaction.getStatus().equals("RDNC")) {
+      FieldProviderFactory.setField(transactionData, "ISRECEIPT", "N");
+      // isReceipt = false;
+    }
+    // project
+    FieldProviderFactory.setField(transactionData, "PROJECT", "");
+    // salesPerson
+    FieldProviderFactory.setField(transactionData, "SALES_PERSON", "");
+    // invoiceNumber.
+    FieldProviderFactory.setField(transactionData, "INVOICE_NUMBER", "");
+    // payment plan id
+    FieldProviderFactory.setField(transactionData, "PAYMENT_PLAN_ID", "");
+    // payment plan yes / no
+    FieldProviderFactory.setField(transactionData, "PAYMENT_PLAN_Y_N", "Display:none");
+    // payment plan yes / no
+    FieldProviderFactory.setField(transactionData, "NOT_PAYMENT_PLAN_Y_N", "Display:none");
+    // invoiceDate
+    FieldProviderFactory.setField(transactionData, "INVOICE_DATE", "");
+    // dueDate.
+    FieldProviderFactory.setField(transactionData, "DUE_DATE",
+        dateFormat.format(transaction.getDateAcct()));
+    // plannedDSO
+    FieldProviderFactory.setField(transactionData, "PLANNED_DSO", "0");
+    // currentDSO
+    FieldProviderFactory.setField(transactionData, "CURRENT_DSO", "0");
+    // daysOverdue
+    FieldProviderFactory.setField(transactionData, "OVERDUE", "0");
+
+    // transactional and base amounts
+    transAmount = transaction.getDepositAmount().subtract(transaction.getPaymentAmount());
+
+    Currency baseCurrency = OBDal.getInstance().get(Currency.class, strConvertCurrency);
+
+    boolean sameCurrency = baseCurrency.getISOCode().equalsIgnoreCase(
+        transaction.getCurrency().getISOCode());
+
+    if (!sameCurrency) {
+      convRate = this.getConversionRate(transaction.getCurrency(), baseCurrency, strConversionDate);
+
+      if (convRate != null) {
+        final int stdPrecission = convRate.getToCurrency().getStandardPrecision().intValue();
+        FieldProviderFactory.setField(transactionData, "TRANS_AMOUNT", transAmount.toString());
+        FieldProviderFactory.setField(
+            transactionData,
+            "BASE_AMOUNT",
+            transAmount.multiply(convRate.getMultipleRateBy())
+                .setScale(stdPrecission, BigDecimal.ROUND_HALF_UP).toString());
+      } else {
+        String message = transaction.getCurrency().getISOCode() + " -> "
+            + baseCurrency.getISOCode() + " " + strConversionDate;
+
+        throw new Exception(message);
+      }
+    } else {
+      // convRate = null;
+      FieldProviderFactory.setField(transactionData, "TRANS_AMOUNT", transAmount.toString());
+      FieldProviderFactory.setField(transactionData, "BASE_AMOUNT", transAmount.toString());
+    }
+    // currency
+    FieldProviderFactory.setField(transactionData, "BASE_CURRENCY", baseCurrency.getISOCode());
+    // group_crit_id this is the column that has the ids of the grouping criteria selected
+    if (strGroupCrit.equalsIgnoreCase("APRM_FATS_BPARTNER")) {
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID",
+          transactionData.getField("BPARTNER"));
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Business Partner");
+    } else if (strGroupCrit.equalsIgnoreCase("Project")) {
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID",
+          transactionData.getField("PROJECT"));
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Project");
+    } else if (strGroupCrit.equalsIgnoreCase("FINPR_BPartner_Category")) {
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID",
+          transactionData.getField("BP_GROUP"));
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Business Partner Category");
+    } else if (strGroupCrit.equalsIgnoreCase("INS_CURRENCY")) {
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID",
+          transactionData.getField("TRANS_CURRENCY"));
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "Currency");
+    } else {
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT_ID", "");
+      FieldProviderFactory.setField(transactionData, "GROUP_CRIT", "");
+    }
+
+    return transactionData;
+  }
+
+  /**
+   * This method compares the transaction element with the previous data element and returns true if
+   * the transaction goes before according to the comparing parameters
+   */
+  private boolean transactionIsBefore(FIN_FinaccTransaction transaction, FieldProvider data,
+      String strGroupCrit, String strOrdCrit) {
+
+    boolean isBefore = false;
+    String BPName = "";
+    String BPCategory = "";
+    String strProject = "";
+    if (transaction.getBusinessPartner() != null) {
+      BPName = transaction.getBusinessPartner().getName().toString();
+      BPCategory = transaction.getBusinessPartner().getBusinessPartnerCategory().getName()
+          .toString();
+    }
+    if (transaction.getProject() != null) {
+      strProject = transaction.getProject().getId().toString();
+    }
+
+    if (!strGroupCrit.equals("")) {
+
+      // General boolean rule for comparation when A!=B -->[ (A<B || B="") && A!="" ]
+      if (strGroupCrit.equalsIgnoreCase("APRM_FATS_BPARTNER")) {
+        if (BPName.compareTo(data.getField("BPARTNER").toString()) == 0) {
+          isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
+              strProject);
+        } else if ((BPName.compareTo(data.getField("BPARTNER").toString()) < 0 || data
+            .getField("BPARTNER").toString().equals(""))
+            && !BPName.equals("")) {
+          isBefore = true;
+        }
+      } else if (strGroupCrit.equalsIgnoreCase("Project")) {
+        if (strProject.compareTo(data.getField("PROJECT").toString()) == 0) {
+          isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
+              strProject);
+        } else if ((strProject.compareTo(data.getField("PROJECT").toString()) < 0 || data
+            .getField("PROJECT").toString().equals(""))
+            && !strProject.equals("")) {
+          isBefore = true;
+        }
+      } else if (strGroupCrit.equalsIgnoreCase("FINPR_BPartner_Category")) {
+        if (BPCategory.compareTo(data.getField("BP_GROUP").toString()) == 0) {
+          isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
+              strProject);
+        } else if ((BPCategory.toString().compareTo(data.getField("BP_GROUP").toString()) < 0 || data
+            .getField("BP_GROUP").toString().equals(""))
+            && !BPCategory.equals("")) {
+          isBefore = true;
+        }
+      } else if (strGroupCrit.equalsIgnoreCase("INS_CURRENCY")) {
+        if (transaction.getCurrency().getISOCode().toString()
+            .compareTo(data.getField("TRANS_CURRENCY").toString()) == 0) {
+          isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
+              strProject);
+        } else if (transaction.getCurrency().getISOCode().toString()
+            .compareTo(data.getField("TRANS_CURRENCY").toString()) < 0) {
+          isBefore = true;
+        }
+      }
+
+    } else {
+      isBefore = isBeforeStatusAndOrder(transaction, data, strOrdCrit, BPName, BPCategory,
+          strProject);
+    }
+    return isBefore;
+  }
+
+  /**
+   * This method compares the status and the order criteria of the transactions and data
+   * 
+   * @param transaction
+   * @param data
+   * @param strOrdCrit
+   * @return
+   */
+  private boolean isBeforeStatusAndOrder(FIN_FinaccTransaction transaction, FieldProvider data,
+      String strOrdCrit, String BPName, String BPCategory, String strProject) {
+    boolean isBefore = false;
+
+    if (transaction.getStatus().toString().equals(data.getField("STATUS_CODE").toString())) {
+      if (!strOrdCrit.isEmpty()) {
+        String[] strOrdCritList = strOrdCrit.substring(2, strOrdCrit.length() - 2).split("', '");
+        isBefore = isBeforeOrder(transaction, data, strOrdCritList, 0, BPName, BPCategory,
+            strProject);
+      }
+    } else if (isBeforeStatus(transaction.getStatus().toString(), data.getField("STATUS_CODE")
+        .toString())) {
+      isBefore = true;
+    }
+    return isBefore;
+  }
+
+  /**
+   * This method compares recursively the order criteria of the transactions and data
+   * 
+   * @param transaction
+   * @param data
+   * @param strOrdCrit
+   * @return
+   */
+  private boolean isBeforeOrder(FIN_FinaccTransaction transaction, FieldProvider data,
+      String[] strOrdCritList, int i, String BPName, String BPCategory, String strProject) {
+    boolean isBefore = false;
+
+    if (i == strOrdCritList.length - 1) {
+      if (strOrdCritList[i].contains("Project")) {
+        isBefore = isBefore
+            || (((strProject.compareTo(data.getField("PROJECT").toString()) < 0) || data
+                .getField("PROJECT").toString().equals("")) && !strProject.equals(""));
+      }
+      if (strOrdCritList[i].contains("FINPR_BPartner_Category")) {
+        isBefore = isBefore
+            || (((BPCategory.compareTo(data.getField("BP_GROUP").toString()) < 0) || data
+                .getField("BP_GROUP").toString().equals("")) && !BPCategory.equals(""));
+      }
+      if (strOrdCritList[i].contains("APRM_FATS_BPARTNER")) {
+        isBefore = isBefore
+            || (((BPName.compareTo(data.getField("BPARTNER").toString()) < 0) || data
+                .getField("BPARTNER").toString().equals("")) && !BPName.equals(""));
+      }
+      if (strOrdCritList[i].contains("INS_CURRENCY")) {
+        isBefore = isBefore
+            || (transaction.getCurrency().getISOCode().toString()
+                .compareTo(data.getField("TRANS_CURRENCY").toString()) < 0);
+      }
+      return isBefore;
+    } else {
+      if (strOrdCritList[i].contains("Project")) {
+        if ((strProject.compareTo(data.getField("PROJECT").toString()) < 0 || data
+            .getField("PROJECT").toString().equals(""))
+            && !strProject.equals("")) {
+          isBefore = true;
+        } else if (strProject.compareTo(data.getField("PROJECT").toString()) == 0) {
+          isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
+              strProject);
+        }
+      } else if (strOrdCritList[i].contains("FINPR_BPartner_Category")) {
+        if ((BPCategory.compareTo(data.getField("BP_GROUP").toString()) < 0 || data
+            .getField("BP_GROUP").toString().equals(""))
+            && !BPCategory.equals("")) {
+          isBefore = true;
+        } else if (BPCategory.toString().compareTo(data.getField("BP_GROUP").toString()) == 0) {
+          isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
+              strProject);
+        }
+      } else if (strOrdCritList[i].contains("APRM_FATS_BPARTNER")) {
+        if ((BPName.compareTo(data.getField("BPARTNER").toString()) < 0 || data
+            .getField("BPARTNER").toString().equals(""))
+            && !BPName.equals("")) {
+          isBefore = true;
+        } else if (BPName.compareTo(data.getField("BPARTNER").toString()) == 0) {
+          isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
+              strProject);
+        }
+      } else if (strOrdCritList[i].contains("INS_CURRENCY")) {
+        if (transaction.getCurrency().getISOCode().toString()
+            .compareTo(data.getField("TRANS_CURRENCY").toString()) < 0) {
+          isBefore = true;
+        } else if (transaction.getCurrency().getISOCode().toString()
+            .compareTo(data.getField("TRANS_CURRENCY").toString()) == 0) {
+          isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
+              strProject);
+        }
+      } else if (strOrdCritList[i].contains("Date")) {
+        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
+        try {
+          Date transactionDate = sdf.parse(strOrdCritList[i].toString());
+          Date dataDate = sdf.parse(data.getField("DUE_DATE").toString());
+          if (transactionDate.before(dataDate)) {
+            isBefore = true;
+          } else if (transactionDate.equals(dataDate)) {
+            isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
+                strProject);
+          }
+        } catch (ParseException e) {
+          // Exception parsing date
+          log4j.error(e.getMessage(), e);
+        }
+      } else {
+        isBefore = isBeforeOrder(transaction, data, strOrdCritList, i + 1, BPName, BPCategory,
+            strProject);
+      }
+      return isBefore;
+    }
+  }
+
+  /**
+   * Compares two DIFFERENT payment status. If the first one goes before the second it returns true,
+   * elsewise it returns false
+   * 
+   * @param firstValue
+   * @param secondValue
+   * @return
+   */
+  private boolean isBeforeStatus(String firstValue, String secondValue) {
+    String[] strStatus = { firstValue, secondValue };
+    boolean isBefore = false;
+
+    OBContext.setAdminMode(true);
+    try {
+      OBCriteria<List> obCriteria = OBDal.getInstance().createCriteria(List.class);
+      obCriteria.createAlias(List.PROPERTY_REFERENCE, "r", OBCriteria.LEFT_JOIN);
+      obCriteria.add(Restrictions.ilike("r."
+          + org.openbravo.model.ad.domain.Reference.PROPERTY_NAME, "FIN_Payment status"));
+      obCriteria.add(Restrictions.in(List.PROPERTY_SEARCHKEY, strStatus));
+      obCriteria.addOrderBy(List.PROPERTY_SEQUENCENUMBER, true);
+      obCriteria.addOrderBy(List.PROPERTY_SEARCHKEY, true);
+      final java.util.List<List> statusList = obCriteria.list();
+      List status = statusList.get(0);
+      if (status.getSearchKey().equals(firstValue)) {
+        isBefore = true;
+      }
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return isBefore;
+  }
+
+  /**
+   * 
+   * This method returns a list of transactions without a payment associated
+   */
+  private java.util.List<FIN_FinaccTransaction> getTransactionsList(String strInclSubOrg,
+      String strOrg, String strcBPartnerIdIN, String strFinancialAccountId,
+      String strDocumentDateFrom, String strDocumentDateTo, String strPaymentDateFrom,
+      String strPaymentDateTo, String strAmountFrom, String strAmountTo, String strcBPGroupIdIN,
+      String strcProjectIdIN, String strfinPaymSt, String strcCurrency, String strPaymType,
+      String strGroupCrit, String strOrdCrit, String strcNoBusinessPartner) {
+    Organization[] organizations;
+    if (strInclSubOrg.equalsIgnoreCase("include")) {
+      Set<String> orgChildTree = OBContext.getOBContext().getOrganizationStructureProvider()
+          .getChildTree(strOrg, true);
+      organizations = getOrganizations(orgChildTree);
+    } else {
+      organizations = new Organization[1];
+      organizations[0] = OBDal.getInstance().get(Organization.class, strOrg);
+    }
+    java.util.List<BusinessPartner> bPartners = OBDao.getOBObjectListFromString(
+        BusinessPartner.class, strcBPartnerIdIN);
+    java.util.List<Project> projects = OBDao.getOBObjectListFromString(Project.class,
+        strcProjectIdIN);
+    OBContext.setAdminMode(true);
+    try {
+      OBCriteria<FIN_FinaccTransaction> obCriteriaTrans = OBDal.getInstance().createCriteria(
+          FIN_FinaccTransaction.class);
+      obCriteriaTrans.createAlias(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER, "bp",
+          OBCriteria.LEFT_JOIN);
+      obCriteriaTrans.createAlias("bp." + BusinessPartner.PROPERTY_BUSINESSPARTNERCATEGORY, "bpc",
+          OBCriteria.LEFT_JOIN);
+      obCriteriaTrans
+          .createAlias(FIN_FinaccTransaction.PROPERTY_PROJECT, "p", OBCriteria.LEFT_JOIN);
+      obCriteriaTrans.createAlias(FIN_FinaccTransaction.PROPERTY_CURRENCY, "c",
+          OBCriteria.LEFT_JOIN);
+      obCriteriaTrans.add(Restrictions.isNull(FIN_FinaccTransaction.PROPERTY_FINPAYMENT));
+      obCriteriaTrans.add(Restrictions.in(FIN_FinaccTransaction.PROPERTY_ORGANIZATION,
+          organizations));
+
+      // Empty Business Partner included
+      if (strcNoBusinessPartner.equals("include")) {
+
+        // BPartners
+        if (!bPartners.isEmpty()) {
+          obCriteriaTrans.add(Restrictions.or(
+              Restrictions.in(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER, bPartners),
+              Restrictions.isNull(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER)));
+        }
+
+        // BPartner Category
+        if (!strcBPGroupIdIN.equals("")) {
+          obCriteriaTrans.add(Restrictions.or(Restrictions.eq("bp."
+              + BusinessPartner.PROPERTY_BUSINESSPARTNERCATEGORY, strcBPGroupIdIN), Restrictions
+              .isNull(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER)));
+        }
+
+        // Empty Business Partner excluded
+      } else if (strcNoBusinessPartner.equals("exclude")) {
+
+        // BPartners
+        if (!bPartners.isEmpty()) {
+          obCriteriaTrans.add(Restrictions.in(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER,
+              bPartners));
+        }
+
+        // BPartner Category
+        if (!strcBPGroupIdIN.equals("")) {
+          obCriteriaTrans.add(Restrictions.eq("bp."
+              + BusinessPartner.PROPERTY_BUSINESSPARTNERCATEGORY, strcBPGroupIdIN));
+        }
+
+        if (!bPartners.isEmpty() && strcBPGroupIdIN.equals("")) {
+          obCriteriaTrans.add(Restrictions
+              .isNotNull(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER));
+        }
+
+        // Only empty Business Partners
+      } else { // if if (strcNoBusinessPartner.equals("only"))
+        obCriteriaTrans.add(Restrictions.isNull(FIN_FinaccTransaction.PROPERTY_BUSINESSPARTNER));
+      }
+
+      // Financial Account
+      if (!strFinancialAccountId.equals("")) {
+        obCriteriaTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_ACCOUNT, OBDal
+            .getInstance().get(FIN_FinancialAccount.class, strFinancialAccountId)));
+      }
+
+      // Document Date & Payment Date
+      SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
+      if (!strDocumentDateFrom.equals("")) {
+        obCriteriaTrans.add(Restrictions.ge(FIN_FinaccTransaction.PROPERTY_DATEACCT,
+            sdf.parse(strDocumentDateFrom)));
+      }
+      if (!strDocumentDateTo.equals("")) {
+        obCriteriaTrans.add(Restrictions.le(FIN_FinaccTransaction.PROPERTY_DATEACCT,
+            sdf.parse(strDocumentDateTo)));
+      }
+      if (!strPaymentDateFrom.equals("")) {
+        obCriteriaTrans.add(Restrictions.ge(FIN_FinaccTransaction.PROPERTY_DATEACCT,
+            sdf.parse(strPaymentDateFrom)));
+      }
+      if (!strPaymentDateTo.equals("")) {
+        obCriteriaTrans.add(Restrictions.le(FIN_FinaccTransaction.PROPERTY_DATEACCT,
+            sdf.parse(strPaymentDateTo)));
+      }
+
+      // Amount
+      if (!strAmountFrom.equals("")) {
+        obCriteriaTrans.add(Restrictions.or(Restrictions.ge(
+            FIN_FinaccTransaction.PROPERTY_DEPOSITAMOUNT, new BigDecimal(strAmountFrom)),
+            Restrictions.ge(FIN_FinaccTransaction.PROPERTY_PAYMENTAMOUNT, new BigDecimal(
+                strAmountFrom))));
+      }
+      if (!strAmountTo.equals("")) {
+        obCriteriaTrans.add(Restrictions.or(Restrictions.le(
+            FIN_FinaccTransaction.PROPERTY_DEPOSITAMOUNT, new BigDecimal(strAmountTo)),
+            Restrictions.le(FIN_FinaccTransaction.PROPERTY_PAYMENTAMOUNT, new BigDecimal(
+                strAmountTo))));
+      }
+
+      // Projects
+      if (!projects.isEmpty()) {
+        obCriteriaTrans.add(Restrictions.in(FIN_FinaccTransaction.PROPERTY_PROJECT, projects));
+      }
+
+      // Status
+      if (!strfinPaymSt.isEmpty() && !strfinPaymSt.equalsIgnoreCase("('')")) {
+        strfinPaymSt = strfinPaymSt.replace("(", "");
+        strfinPaymSt = strfinPaymSt.replace(")", "");
+        strfinPaymSt = strfinPaymSt.replace("'", "");
+        strfinPaymSt = strfinPaymSt.replace(" ", "");
+        String[] status = strfinPaymSt.split(",");
+        obCriteriaTrans.add(Restrictions.in(FIN_FinaccTransaction.PROPERTY_STATUS, status));
+      }
+
+      // Currency
+      if (!strcCurrency.equals("")) {
+        obCriteriaTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_CURRENCY, OBDal
+            .getInstance().get(Currency.class, strcCurrency)));
+      }
+
+      // payment type
+      if (strPaymType.equalsIgnoreCase("FINPR_Receivables")) {
+        String[] status = { "PWNC", "RPPC" };
+        obCriteriaTrans.add(Restrictions.in(FIN_FinaccTransaction.PROPERTY_STATUS, status));
+      } else if (strPaymType.equalsIgnoreCase("FINPR_Payables")) {
+        String[] status = { "RDNC", "RPPC" };
+        obCriteriaTrans.add(Restrictions.in(FIN_FinaccTransaction.PROPERTY_STATUS, status));
+      }
+
+      // order
+
+      if (strGroupCrit.equalsIgnoreCase("APRM_FATS_BPARTNER")) {
+        obCriteriaTrans.addOrder(Order.asc("bp." + BusinessPartner.PROPERTY_NAME));
+      } else if (strGroupCrit.equalsIgnoreCase("Project")) {
+        obCriteriaTrans.addOrder(Order.asc("p." + Project.PROPERTY_NAME));
+      } else if (strGroupCrit.equalsIgnoreCase("FINPR_BPartner_Category")) {
+        obCriteriaTrans.addOrder(Order.asc("bpc." + Category.PROPERTY_NAME));
+      } else if (strGroupCrit.equalsIgnoreCase("INS_CURRENCY")) {
+        obCriteriaTrans.addOrder(Order.asc("c." + Currency.PROPERTY_ISOCODE));
+      }
+
+      obCriteriaTrans.addOrder(Order.asc(FIN_FinaccTransaction.PROPERTY_STATUS));
+
+      if (!strOrdCrit.isEmpty()) {
+        String[] strOrdCritList = strOrdCrit.substring(2, strOrdCrit.length() - 2).split("', '");
+        for (int i = 0; i < strOrdCritList.length; i++) {
+          if (strOrdCritList[i].contains("Date")) {
+            obCriteriaTrans.addOrder(Order.asc(FIN_FinaccTransaction.PROPERTY_DATEACCT));
+          }
+          if (strOrdCritList[i].contains("Project")) {
+            obCriteriaTrans.addOrder(Order.asc("p." + Project.PROPERTY_NAME));
+          }
+          if (strOrdCritList[i].contains("FINPR_BPartner_Category")) {
+            obCriteriaTrans.addOrder(Order.asc("bpc." + Category.PROPERTY_NAME));
+          }
+          if (strOrdCritList[i].contains("APRM_FATS_BPARTNER")) {
+            obCriteriaTrans.addOrder(Order.asc("bp." + BusinessPartner.PROPERTY_NAME));
+          }
+          if (strOrdCritList[i].contains("INS_CURRENCY")) {
+            obCriteriaTrans.addOrder(Order.asc("c." + Currency.PROPERTY_ISOCODE));
+          }
+        }
+      }
+      obCriteriaTrans.addOrderBy(FIN_FinaccTransaction.PROPERTY_ID, true);
+
+      final java.util.List<FIN_FinaccTransaction> transList = obCriteriaTrans.list();
+      return transList;
+
+    } catch (Exception e) {
+      log4j.error(e.getMessage(), e);
+      return new ArrayList<FIN_FinaccTransaction>();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
   }
 
   private void fillLine(SimpleDateFormat dateFormat, FieldProvider data,
@@ -921,7 +1642,7 @@
     ConversionRate convRate;
     Date conversionDateObj = FIN_Utility.getDate(conversionDate);
 
-    OBContext.setAdminMode();
+    OBContext.setAdminMode(true);
     try {
 
       final OBCriteria<ConversionRate> obcConvRate = OBDal.getInstance().createCriteria(
@@ -946,7 +1667,7 @@
   }
 
   public String[] getReferenceListValues(String refName, boolean inclEmtyValue) {
-    OBContext.setAdminMode();
+    OBContext.setAdminMode(true);
     String values[];
     try {
       final OBCriteria<Reference> obc = OBDal.getInstance().createCriteria(Reference.class);
@@ -976,7 +1697,7 @@
 
   public static String translateRefList(String strCode) {
     String strMessage = "";
-    OBContext.setAdminMode();
+    OBContext.setAdminMode(true);
     try {
       Language language = OBContext.getOBContext().getLanguage();
 
@@ -1010,7 +1731,7 @@
   public static HashMap<String, String> getLinkParameters(String adTableId, String isReceipt) {
     HashMap<String, String> hmValues = new HashMap<String, String>();
 
-    OBContext.setAdminMode();
+    OBContext.setAdminMode(true);
     try {
       Table adTable = OBDal.getInstance().get(Table.class, adTableId);
 
@@ -1160,4 +1881,22 @@
     }
     return bp;
   }
+
+  /**
+   * Given a String of organizations this method returns an array of organizations
+   * 
+   * @param strOrgFamily
+   * @return
+   */
+  private Organization[] getOrganizations(Set<String> strOrgFamily) {
+    Iterator<String> orgChildTreeIter = strOrgFamily.iterator();
+    Organization[] organizations = new Organization[strOrgFamily.size()];
+    int i = 0;
+    while (orgChildTreeIter.hasNext()) {
+      organizations[i] = OBDal.getInstance().get(Organization.class, orgChildTreeIter.next());
+      i++;
+    }
+    return organizations;
+  }
+
 }
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportPDF.jrxml	Wed Feb 15 20:33:15 2012 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportPDF.jrxml	Fri Feb 17 13:08:40 2012 +0000
@@ -2,9 +2,9 @@
 <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="PaymentReportPDF" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="NoDataSection" columnWidth="782" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20">
 	<property name="ireport.scriptlethandling" value="0"/>
 	<property name="ireport.encoding" value="UTF-8"/>
-	<property name="ireport.zoom" value="0.75"/>
-	<property name="ireport.x" value="0"/>
-	<property name="ireport.y" value="0"/>
+	<property name="ireport.zoom" value="1.5"/>
+	<property name="ireport.x" value="233"/>
+	<property name="ireport.y" value="19"/>
 	<import value="net.sf.jasperreports.engine.*"/>
 	<import value="java.util.*"/>
 	<import value="net.sf.jasperreports.engine.data.*"/>
@@ -58,6 +58,8 @@
 	<parameter name="TWO_ASTERISK_SHOW" class="java.lang.Boolean" isForPrompting="false">
 		<defaultValueExpression><![CDATA[new Boolean(false)]]></defaultValueExpression>
 	</parameter>
+	<parameter name="PAYDATEFROM_SHOW" class="java.lang.String"/>
+	<parameter name="PAYDATETO_SHOW" class="java.lang.String"/>
 	<queryString>
 		<![CDATA[SELECT 'hello' AS BP_GROUP, 'hello' AS BPARTNER, 'hello' AS PROJECT, 'hello' AS PAYMENT, 'hello' AS SALES_PERSON, 1234 AS INVOICE_NUMBER, to_Date('01/01/2010') AS INVOICE_DATE,
        to_Date('01/03/2010') AS DUE_DATE, 1234 AS PLANNED_DSO, 1234 AS CURRENT_DSO, 1234 AS OVERDUE, 1234 AS DAYS_OVERDUE, 1234 AS AMOUNT,
@@ -544,7 +546,7 @@
 		<band splitType="Stretch"/>
 	</background>
 	<title>
-		<band height="153" splitType="Stretch">
+		<band height="175" splitType="Stretch">
 			<staticText>
 				<reportElement key="staticText-24" style="Report_Footer" x="11" y="73" width="179" height="18"/>
 				<textElement textAlignment="Right"/>
@@ -576,12 +578,12 @@
 				<text><![CDATA[Amount To:]]></text>
 			</staticText>
 			<staticText>
-				<reportElement key="staticText-30" style="Report_Footer" x="11" y="133" width="179" height="18"/>
+				<reportElement key="staticText-30" style="Report_Footer" x="11" y="134" width="179" height="18"/>
 				<textElement textAlignment="Right"/>
 				<text><![CDATA[Document Date From:]]></text>
 			</staticText>
 			<staticText>
-				<reportElement key="staticText-31" style="Report_Footer" x="408" y="133" width="179" height="18"/>
+				<reportElement key="staticText-31" style="Report_Footer" x="408" y="134" width="179" height="18"/>
 				<textElement textAlignment="Right"/>
 				<text><![CDATA[Document Date To:]]></text>
 			</staticText>
@@ -601,7 +603,7 @@
 				<textFieldExpression class="java.lang.String"><![CDATA[$P{AMTFROM_SHOW}.toString()]]></textFieldExpression>
 			</textField>
 			<textField isBlankWhenNull="true">
-				<reportElement key="textField-28" style="Report_Footer" x="196" y="133" width="179" height="18"/>
+				<reportElement key="textField-28" style="Report_Footer" x="196" y="134" width="179" height="18"/>
 				<textElement/>
 				<textFieldExpression class="java.lang.String"><![CDATA[$P{DOCDATEFROM_SHOW}.toString()]]></textFieldExpression>
 			</textField>
@@ -621,7 +623,7 @@
 				<textFieldExpression class="java.lang.String"><![CDATA[$P{AMTTO_SHOW}.toString()]]></textFieldExpression>
 			</textField>
 			<textField isBlankWhenNull="true">
-				<reportElement key="textField-39" style="Report_Footer" x="593" y="133" width="179" height="18"/>
+				<reportElement key="textField-39" style="Report_Footer" x="593" y="134" width="179" height="18"/>
 				<textElement/>
 				<textFieldExpression class="java.lang.String"><![CDATA[$P{DOCDATETO_SHOW}.toString()]]></textFieldExpression>
 			</textField>
@@ -632,6 +634,26 @@
 				</textElement>
 				<text><![CDATA[PAYMENT REPORT]]></text>
 			</staticText>
+			<textField isBlankWhenNull="true">
+				<reportElement key="textField-28" style="Report_Footer" x="196" y="154" width="179" height="18"/>
+				<textElement/>
+				<textFieldExpression class="java.lang.String"><![CDATA[$P{PAYDATEFROM_SHOW}.toString()]]></textFieldExpression>
+			</textField>
+			<textField isBlankWhenNull="true">
+				<reportElement key="textField-39" style="Report_Footer" x="593" y="154" width="179" height="18"/>
+				<textElement/>
+				<textFieldExpression class="java.lang.String"><![CDATA[$P{PAYDATETO_SHOW}.toString()]]></textFieldExpression>
+			</textField>
+			<staticText>
+				<reportElement key="staticText-31" style="Report_Footer" x="408" y="154" width="179" height="18"/>
+				<textElement textAlignment="Right"/>
+				<text><![CDATA[Payment Date To:]]></text>
+			</staticText>
+			<staticText>
+				<reportElement key="staticText-30" style="Report_Footer" x="11" y="154" width="179" height="18"/>
+				<textElement textAlignment="Right"/>
+				<text><![CDATA[Payment Date From:]]></text>
+			</staticText>
 		</band>
 	</title>
 	<pageHeader>