Fixed issue 17894.Added ability to mix gl items and invoices on Add Payment From Transaction.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 26 Jul 2011 12:30:41 +0200
changeset 13267 bc4bd502bc4d
parent 13266 e251f7b1d594
child 13268 5b9f270d0bff
Fixed issue 17894.Added ability to mix gl items and invoices on Add Payment From Transaction.
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Tue Jul 26 11:42:56 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Tue Jul 26 12:30:41 2011 +0200
@@ -2200,17 +2200,6 @@
 <!--A16D40CBB17E473799C90DD16E9EC7F0-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--A16D40CBB17E473799C90DD16E9EC7F0--></AD_TEXTINTERFACES>
 
-<!--A2C53159E26643FCBC39501FD7AF2A23--><AD_TEXTINTERFACES>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <AD_TEXTINTERFACES_ID><![CDATA[A2C53159E26643FCBC39501FD7AF2A23]]></AD_TEXTINTERFACES_ID>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <TEXT><![CDATA[Select additional purchase invoices or purchase orders that you want to add to this payment out]]></TEXT>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <ISUSED><![CDATA[Y]]></ISUSED>
-<!--A2C53159E26643FCBC39501FD7AF2A23-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
-<!--A2C53159E26643FCBC39501FD7AF2A23--></AD_TEXTINTERFACES>
-
 <!--A2E3CEC67D004E7C9BADAB2FD4719E8F--><AD_TEXTINTERFACES>
 <!--A2E3CEC67D004E7C9BADAB2FD4719E8F-->  <AD_TEXTINTERFACES_ID><![CDATA[A2E3CEC67D004E7C9BADAB2FD4719E8F]]></AD_TEXTINTERFACES_ID>
 <!--A2E3CEC67D004E7C9BADAB2FD4719E8F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -2277,6 +2266,116 @@
 <!--A8C9A7A0B28D4C94B22CD692E33136CC-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--A8C9A7A0B28D4C94B22CD692E33136CC--></AD_TEXTINTERFACES>
 
+<!--A8F5EE29EF31BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF31BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <TEXT><![CDATA[Select additional purchase invoices, purchase orders or gl items that you want to add to this payment out]]></TEXT>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF31BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF31BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF34BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF34BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <TEXT><![CDATA[Select additional sales invoices, sales orders or gl items that you want to add to this payment in]]></TEXT>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF34BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF34BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF37BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF37BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <TEXT><![CDATA[GL Items]]></TEXT>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF37BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF37BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF3ABBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF3ABBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <TEXT><![CDATA[GL Item]]></TEXT>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF3ABBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF3ABBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF3DBBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF3DBBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <TEXT><![CDATA[Received In]]></TEXT>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF3DBBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF3DBBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF40BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF40BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <TEXT><![CDATA[Paid Out]]></TEXT>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF40BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF40BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF43BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF43BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <TEXT><![CDATA[Amount on Invoices and/or Orders]]></TEXT>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF43BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF43BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF46BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF46BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <TEXT><![CDATA[Amount on GL Items]]></TEXT>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF46BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF46BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF49BBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF49BBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <TEXT><![CDATA[Amount on Invoices and/or Orders]]></TEXT>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html]]></FILENAME>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF49BBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF49BBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
+<!--A8F5EE29EF4CBBCAE040007F01002D53--><AD_TEXTINTERFACES>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <AD_TEXTINTERFACES_ID><![CDATA[A8F5EE29EF4CBBCAE040007F01002D53]]></AD_TEXTINTERFACES_ID>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <TEXT><![CDATA[Amount on GL Items]]></TEXT>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html]]></FILENAME>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--A8F5EE29EF4CBBCAE040007F01002D53-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--A8F5EE29EF4CBBCAE040007F01002D53--></AD_TEXTINTERFACES>
+
 <!--AAE3622DC9124C86B629E0B30D580767--><AD_TEXTINTERFACES>
 <!--AAE3622DC9124C86B629E0B30D580767-->  <AD_TEXTINTERFACES_ID><![CDATA[AAE3622DC9124C86B629E0B30D580767]]></AD_TEXTINTERFACES_ID>
 <!--AAE3622DC9124C86B629E0B30D580767-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -2640,17 +2739,6 @@
 <!--D6E2DE50C7AC438E8E9A9FFF1C6EAAA7-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--D6E2DE50C7AC438E8E9A9FFF1C6EAAA7--></AD_TEXTINTERFACES>
 
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A--><AD_TEXTINTERFACES>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <AD_TEXTINTERFACES_ID><![CDATA[D6E32F7A21F948C8AF9DFBA82A25FE2A]]></AD_TEXTINTERFACES_ID>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <TEXT><![CDATA[Select additional sales invoices or sales orders that you want to add to this payment in]]></TEXT>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <ISUSED><![CDATA[Y]]></ISUSED>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
-<!--D6E32F7A21F948C8AF9DFBA82A25FE2A--></AD_TEXTINTERFACES>
-
 <!--D8B42F3BC554476C8FF5C79AE2445CED--><AD_TEXTINTERFACES>
 <!--D8B42F3BC554476C8FF5C79AE2445CED-->  <AD_TEXTINTERFACES_ID><![CDATA[D8B42F3BC554476C8FF5C79AE2445CED]]></AD_TEXTINTERFACES_ID>
 <!--D8B42F3BC554476C8FF5C79AE2445CED-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Tue Jul 26 11:42:56 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Tue Jul 26 12:30:41 2011 +0200
@@ -48,6 +48,10 @@
 <script language="JavaScript" src="../../../../../web/js/default/DateTextBox.js" type="text/javascript"></script>
 <script language="JavaScript" src="../../../../../web/org.openbravo.advpaymentmngt/FIN_Utilities.js" type="text/javascript"></script>
 <script language="JavaScript" type="text/javascript">
+  OB.APRM = OB.APRM || {};
+  OB.APRM.APFT_GLItems = [];
+  OB.APRM.APFT_GLItemsId = 0;
+  OB.APRM.HasGLItems = false;
 function callBackGrid(paramXMLParticular, XMLHttpRequestObj) {
   var strText = '';
   if (getReadyStateHandler(XMLHttpRequestObj)) {
@@ -143,6 +147,129 @@
   }
   return true;
 }
+function loadGLItemList() {
+  var table = document.getElementById('sectionGLItemGrid'),
+      glitemCount = OB.APRM.APFT_GLItems.length,
+      glitemAmount = 0,
+      rowCount, row, cellGLItemDesc, cellGLITemReceivedInAmt, cellGLITemPaidOutAmt, cellRemoveButton, i, textNode;
+
+  table.innerHTML = '';
+  if (glitemCount === 0) {
+    OB.APRM.HasGLItems = false;
+    return;
+  }
+  OB.APRM.HasGLItems = true;
+  for (i = 0; i < glitemCount; i++) {
+    rowCount = table.rows.length;
+    row = table.insertRow(rowCount);
+    row.className = 'DataGrid_Body_Row DataGrid_Body_Row_'+i%2;
+    
+    cellGLItemDesc = row.insertCell(0);
+    textNode = document.createTextNode(OB.APRM.APFT_GLItems[i].glitemDesc);
+    cellGLItemDesc.appendChild(textNode);
+    cellGLItemDesc.className = 'DataGrid_Body_Cell';
+    
+    cellGLITemReceivedInAmt = row.insertCell(1);
+    textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
+    cellGLITemReceivedInAmt.appendChild(textNode);
+    cellGLITemReceivedInAmt.className = 'DataGrid_Body_Cell_Amount';
+    
+    cellGLITemPaidOutAmt = row.insertCell(2);
+    textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
+    cellGLITemPaidOutAmt.appendChild(textNode);
+    cellGLITemPaidOutAmt.className = 'DataGrid_Body_Cell_Amount';
+    
+    if (isTrue('isReceipt')) {
+      glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
+    } else {
+      glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
+    }
+    cellRemoveButton = row.insertCell(3);
+    cellRemoveButton.innerHTML = '<div><button type="button" id="buttonRemoveGLItem"'
+        + ' class="ButtonLink_focus" onclick="removeGLItem(' + i + ', ' + glitemAmount + ');return false;"'
+        + ' onfocus="buttonEvent(\'onfocus\', this); window.status=\'OK\'; return true;"'
+        + ' onblur="buttonEvent(\'onblur\', this);"'
+        + '  onkeyup="buttonEvent(\'onkeyup\', this);"'
+        + '  onkeydown="buttonEvent(\'onkeydown\', this);"'
+        + '  onkeypress="buttonEvent(\'onkeypress\', this);"'
+        + '  onmouseup="buttonEvent(\'onmouseup\', this);"'
+        + '  onmousedown="buttonEvent(\'onmousedown\', this);"'
+        + '  onmouseover="buttonEvent(\'onmouseover\', this); window.status=\'OK\'; return true;"'
+        + '  onmouseout="buttonEvent(\'onmouseout\', this);">'
+        + '  <table class="Button"><tr><td>'
+        + '    <img alt="Remove" title="Remove" src="../web/org.openbravo.advpaymentmngt/images/GLItemGridCancel-xButt.png" id="imgButtonRemove" border="0"/></td>'
+        + '  </tr></table></button></div>';
+  }
+  updateTotal();
+}
+function addGLItem() {
+  var amount = 0, glamount = 0, expectedAmt = 0;
+  if (frm.inpGLItemReceivedInAmount.value === null || frm.inpGLItemReceivedInAmount.value === '') {
+    setWindowElementFocus(frm.inpGLItemReceivedInAmount);
+    showJSMessage(7);
+    return false;
+  } else if (frm.inpGLItemPaidOutAmount.value === null || frm.inpGLItemPaidOutAmount.value === '') {
+    setWindowElementFocus(frm.inpGLItemPaidOutAmount);
+    showJSMessage(7);
+    return false;
+  } else if (frm.inpcGlitemId.value === null || frm.inpcGlitemId.value === '') {
+    setWindowElementFocus(frm.inpcGlitemId);
+    showJSMessage(7);
+    return false;
+  } else if ( (compare(frm.inpGLItemReceivedInAmount.value, '==', 0) && compare(frm.inpGLItemPaidOutAmount.value, '==', 0)) ||
+              (compare(frm.inpGLItemReceivedInAmount.value, '!=', 0) && compare(frm.inpGLItemPaidOutAmount.value, '!=', 0)) ) {
+    setWindowElementFocus(frm.paramPaymentAmountGLItem);
+    showJSMessage('APRM_JSAMOUNTDIFFTOZERO');
+    return false;
+  }
+  if (isTrue('isReceipt')) {
+    glamount = subtract(frm.inpGLItemReceivedInAmount.value, frm.inpGLItemPaidOutAmount.value);
+  } else {
+    glamount = subtract(frm.inpGLItemPaidOutAmount.value, frm.inpGLItemReceivedInAmount.value);
+  }
+  amount = add(document.frmMain.inpGLSumAmount.value, glamount);
+  document.frmMain.inpGLSumAmount.value = amount;
+  document.frmMain.inpExpectedPayment.value = add(document.frmMain.inpExpectedPayment.value, glamount);
+  if (!isTrue('isReceipt')) {
+    if (document.frmMain.inpUseCredit.checked) {
+      amount = subtract(amount, document.frmMain.inpCredit.value);
+      if ( compare(amount, '<', '0') ) {
+        amount = 0;
+      }
+    }
+    document.frmMain.inpActualPayment.value = amount;
+  }
+  OB.APRM.APFT_GLItemsId++;
+  OB.APRM.APFT_GLItems.push({
+    id: OB.APRM.APFT_GLItemsId,
+    glitemId: frm.inpcGlitemId.value,
+    glitemDesc: sc_C_Glitem_ID.selectorField.getDisplayValue(),
+    glitemReceivedInAmt: OB.Utilities.Number.OBMaskedToJS(frm.inpGLItemReceivedInAmount.value,
+                                                          getGlobalDecSeparator(),
+                                                          getGlobalGroupSeparator()),
+    glitemPaidOutAmt: OB.Utilities.Number.OBMaskedToJS(frm.inpGLItemPaidOutAmount.value,
+                                                       getGlobalDecSeparator(),
+                                                       getGlobalGroupSeparator())
+  });
+  loadGLItemList();
+}
+function removeGLItem(key, removedAmount) {
+  if (!isTrue('isReceipt')){
+    if ( compare(document.frmMain.inpActualPayment.value, '>', removedAmount) ) {
+      document.frmMain.inpActualPayment.value = subtract(document.frmMain.inpActualPayment.value, removedAmount);
+    } else {
+      document.frmMain.inpActualPayment.value = 0;
+    }
+  }
+  document.frmMain.inpGLSumAmount.value = subtract(document.frmMain.inpGLSumAmount.value, removedAmount);
+  document.frmMain.inpExpectedPayment.value = subtract(document.frmMain.inpExpectedPayment.value, removedAmount);
+  OB.APRM.APFT_GLItems.splice(key, 1);
+  loadGLItemList();
+}
+function removeAllGLItem(closePopup) {
+  OB.APRM.APFT_GLItems = [];
+  loadGLItemList();
+}
 </script>
 <script language="JavaScript" type="text/javascript">
 function validate(action) {
@@ -253,13 +380,62 @@
   updateTotal();
   numberInputEvent('onchange', element);
 }
+function setGLItemMode(toGLItem){
+  displayLogicElement('glitemRow', toGLItem);
+  displayLogicElement('glitemAddRow', toGLItem);
+  displayLogicElement('gridGLItem', toGLItem);
+  displayLogicElement('totalInvoices', toGLItem);
+  displayLogicElement('GLItemSelectorLbl', toGLItem);
+  displayLogicElement('GLItemSelector', toGLItem);
+  
+  displayLogicElement('DueDateFromLbl', !toGLItem);
+  displayLogicElement('DueDateFrom', !toGLItem);
+  displayLogicElement('DueDateToLbl', !toGLItem);
+  displayLogicElement('DueDateTo', !toGLItem);
+  displayLogicElement('DocumentNoLbl', !toGLItem);
+  displayLogicElement('DocumentNo', !toGLItem);
+  displayLogicElement('TrxDateFromLbl', !toGLItem);
+  displayLogicElement('TrxDateFrom', !toGLItem);
+  displayLogicElement('TrxDateToLbl', !toGLItem);
+  displayLogicElement('TrxDateTo', !toGLItem);
+  displayLogicElement('gridPayment', !toGLItem);
+  displayLogicElement('totalGLItems', !toGLItem);
+  
+  resizeAreaCreateFrom();
+  if (toGLItem) {
+    loadGLItemList();
+  }
+  return true;
+}
+function documentTypeOnChange(value){
+  if ('G' === value) {
+    //if we are not already on GL Item mode.
+    if (!isTrue('isInGLItemMode')) {
+      document.frmMain.isInGLItemMode.value='Y';
+      document.getElementById('paramInvoicesAmt').innerHTML = frm.inpInvoiceAmount.value;
+      setGLItemMode(true);
+    }
+  } else {
+    document.getElementById('paramGLItemsAmt').innerHTML = document.frmMain.inpGLSumAmount.value;
+    document.frmMain.isFirstLoad.value = 'true';
+    if (isTrue('isInGLItemMode')) {
+      document.frmMain.isInGLItemMode.value='N';
+      setGLItemMode(false);
+    }
+    loadGridList();
+  }
+}
 function actualPaymentOnChange(){
   if (isTrue('isReceipt')) {
     var amount = document.frmMain.inpActualPayment.value;
     if (document.frmMain.inpUseCredit.checked) {
       amount = add(amount, document.frmMain.inpCredit.value);
     }
-    distributeAmount(amount);
+    if (isTrue('isInGLItemMode')) {
+      updateTotal();
+    } else {
+      distributeAmount(amount);
+    }
   }
 }
 function useCreditOnChange(){
@@ -361,7 +537,7 @@
 }
 function initializeTemplate(){
   // credit is allowed looking at the business partner selection in the grid
-  initFIN_Utilities(document.frmMain, true, true);
+  initFIN_Utilities(document.frmMain, true, true, true);
   processLabels();
   displayLogicElement('paramCustBalance', isTrue('isReceipt'));
   displayLogicElement('NoPackageslinkCalc', isTrue('isReceipt'));
@@ -388,6 +564,7 @@
   try {
     onloadFunctions();
   } catch (e) {}
+  setGLItemMode(isTrue('isInGLItemMode'));
   displayLogicElement('sectionDifference', false);
   displayLogicElement('sectionDifferenceBox', false);
   displayLogicForCredit();
@@ -399,11 +576,13 @@
   resizeAreaCreateFrom(true);
 }
 function closeThisPage() {
+  removeAllGLItem(true);
   closePage();
   return true;
 }
 function submitThisPage(strCommand) {
   if (validate(strCommand)) {
+    document.frmMain.inpGLItems.value = isc.JSON.encode(OB.APRM.APFT_GLItems);
     submitCommandForm(strCommand, false, null, null, '_self');
     return true;
   }
@@ -429,6 +608,7 @@
   document.getElementById('client_top').style.display = 'block';
   document.getElementById('client_middle').style.display = 'block';
   document.getElementById('client_bottom').style.display = 'block';
+  setGLItemMode(isTrue('isInGLItemMode'));
 }
 </script>
 </head>
@@ -436,11 +616,13 @@
 <form name="frmMain" method="post" action="AddPaymentFromTransaction.html">
   <input type="hidden" name="Command" />
   <input type="hidden" name="IsPopUpCall" value="1" />
+  <input type="hidden" name="inpadOrgId" value="" id="fieldOrg"/>
   <input type="hidden" name="isReceipt" value="" id="fieldReceipt"/>
   <input type="hidden" name="inpissotrx" value="" id="fieldIsSoTrx"/>
   <input type="hidden" name="inpFinBankStatementLineId" value="" id="paramFinBankStatementLineId"></input>
   <input type="hidden" name="isFirstLoad" value="true"/>
-  <input type="hidden" name="inpadOrgId" value="" id="fieldOrg"/>
+  <input type="hidden" name="isInGLItemMode" value="N"/>
+  <input type="hidden" name="inpGLItems" value=""/>
   <input type="hidden" name="inpInheritedActualPayment" value="N" id="paramInheritedActualPayment"/>
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
@@ -786,22 +968,21 @@
                   <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                     <tr>
                       <td class="Textbox_ContentCell">
-                      <table style="border: 0px none; border-collapse: collapse;">
+                        <table style="border: 0px none; border-collapse: collapse;">
                         <tr><td style="padding-top: 0px;">
-                        <!-- <input type="text" dojoType="openbravo:RealNumberTextbox" id="paramActualPayment" class="dojoValidateValid required TextBox_btn_OneCell_width number"  value="" maxlength="10" name="inpActualPayment" onkeyup="" onchange="actualPaymentOnchange();return true;" outputformat="euroEdition"></input><script>djConfig.searchIds.push("paramActualPayment");</script> -->
                           <input type="text" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" outputformat="euroEdition" onchange="actualPaymentOnChange();return true;" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" name="inpActualPayment" maxlength="22" value="" required="true" class="dojoValidateValid required TextBox_btn_OneCell_width number" id="paramActualPayment"/>
                         </td></tr>
-                      </table>
-                      <span id="paramActualPaymentinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
-                        <table class="TextBox_MsgContainer_table">
-                          <tbody><tr class="TextBox_MsgContainer_tr">
-                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
-                          </tr>
-                          <tr>
-                            <td class="invalid" colspan="2"><div name="invalidText" id="paramActualPaymentinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
-                          </tr>
-                        </tbody></table>
-                      </span>  
+                        </table>
+                        <span id="paramActualPaymentinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
+                          <table class="TextBox_MsgContainer_table">
+                            <tbody><tr class="TextBox_MsgContainer_tr">
+                              <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
+                            </tr>
+                            <tr>
+                              <td class="invalid" colspan="2"><div name="invalidText" id="paramActualPaymentinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
+                            </tr>
+                          </tbody></table>
+                        </span>
                       </td>
                       <td class="FieldButton_ContentCell">
                       <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount From'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpActualPayment', document.frmMain.inpActualPayment.value, false);return false;">
@@ -913,26 +1094,28 @@
             
             <!-- Text -->
             <tr>
-                <td colspan="6" class="LabelText" style="font-weight: bold;">                    
-                    <span name="lblP" id="lblPText">Select additional purchase invoices or purchase orders that you want to add to this payment out</span>
-                    <span name="lblR" id="lblRText">Select additional sales invoices or sales orders that you want to add to this payment in</span>
+                <td colspan="6" class="LabelText" style="font-weight: bold;">
+                    <span name="lblP" id="lblPText">Select additional purchase invoices, purchase orders or gl items that you want to add to this payment out</span>
+                    <span name="lblR" id="lblRText">Select additional sales invoices, sales orders or gl items that you want to add to this payment in</span>
                 </td>
             </tr>
             
             <tr class="FieldGroup_BottomMargin"></tr>
             
             <!-- Table filters -->
-            <tr> 
-             <td class="TitleCell"><span class="LabelText">Transaction Type</span></td>
-             <td class="Combo_ContentCell">
-               <select name="inpDocumentType" class="ComboKey Combo_OneCell_width" onchange="loadGridList();">
-                 <option value="O">Orders</option>
-                 <option value="I" selected="selected">Invoices</option>
-                 <option value="B">Orders and Invoices</option>
-               </select>
-             </td>
-             <td class="TitleCell"><span class="LabelText">Due Date From</span></td>
-             <td class="TextBox_btn_ContentCell">
+            <tr>
+              <td class="TitleCell"><span class="LabelText">Transaction Type</span></td>
+              <td class="Combo_ContentCell">
+                <select name="inpDocumentType" class="ComboKey Combo_OneCell_width" onchange="documentTypeOnChange(this.value);">
+                  <option value="O">Orders</option>
+                  <option value="I" selected="selected">Invoices</option>
+                  <option value="B">Orders and Invoices</option>
+                  <option value="G">GL Items</option>
+                </select>
+              </td>
+              <!-- Cells shown when not in GL Item mode -->
+              <td class="TitleCell" id="DueDateFromLbl"><span class="LabelText">Due Date From</span></td>
+              <td class="TextBox_btn_ContentCell" id="DueDateFrom">
                 <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                   <tr>
                     <td class="TextBox_ContentCell">
@@ -962,8 +1145,8 @@
                   </tr>
                 </table>
               </td>
-             <td class="TitleCell"><span class="LabelText">Due Date To</span></td>
-             <td class="TextBox_btn_ContentCell">
+              <td class="TitleCell" id="DueDateToLbl"><span class="LabelText">Due Date To</span></td>
+              <td class="TextBox_btn_ContentCell" id="DueDateTo">
                 <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                   <tr>
                     <td class="TextBox_ContentCell">
@@ -993,14 +1176,27 @@
                   </tr>
                 </table>
               </td>
+              <!-- Cells shown when not in GL Item mode -->
+              <td class="TitleCell" colspan="2" id="GLItemSelectorLbl"><span class="LabelText">GL Item</span></td>
+              <td class="TextBox_ContentCell" colspan="2" id="GLItemSelector">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Glitem_ID = null;</script>
+                      <input type="hidden" name="inpcGlitemId" id="C_Glitem_ID" value="" onreset="sc_C_Glitem_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Glitem_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/9FAD469CE4414A25974CF45C0AD22D35?columnName=C_Glitem_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=true"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
             </tr>
             <tr> 
-             <td class="TitleCell"><span class="LabelText">Document No.</span></td>
-             <td class="Combo_OneCell_width">
+             <td class="TitleCell" id="DocumentNoLbl"><span class="LabelText">Document No.</span></td>
+             <td class="Combo_OneCell_width" id="DocumentNo">
                <input type="text" id="paramDocumentNo" class="dojoValidateValid TextBox_OneCell_width" value="" maxlength="10" name="inpDocumentNo" onchange="loadGridList();return true;"></input>
              </td>
-             <td class="TitleCell"><span class="LabelText">Transaction Date From</span></td>
-             <td class="TextBox_btn_ContentCell">
+             <td class="TitleCell" id="TrxDateFromLbl"><span class="LabelText">Transaction Date From</span></td>
+             <td class="TextBox_btn_ContentCell" id="TrxDateFrom">
                 <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                   <tr>
                     <td class="TextBox_ContentCell">
@@ -1030,8 +1226,8 @@
                   </tr>
                 </table>
               </td>
-             <td class="TitleCell"><span class="LabelText">Transaction Date To</span></td>
-             <td class="TextBox_btn_ContentCell">
+              <td class="TitleCell" id="TrxDateToLbl"><span class="LabelText">Transaction Date To</span></td>
+              <td class="TextBox_btn_ContentCell" id="TrxDateTo">
                 <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                   <tr>
                     <td class="TextBox_ContentCell">
@@ -1062,6 +1258,109 @@
                 </table>
               </td>
             </tr>
+            <tr id="glitemRow">
+              <td class="TitleCell"><span class="LabelText">Received In</span></td>
+              <td class="TextBox_btn_ContentCell">
+                <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
+                  <tr>
+                    <td class="Textbox_ContentCell">
+                      <table style="border: 0px none; border-collapse: collapse;">
+                        <tr><td style="padding-top: 0px;">
+                        <input type="text" id="paramGLItemReceivedInAmount" class="dojoValidateValid required TextBox_btn_OneCell_width number"  value="0" maxlength="22" name="inpGLItemReceivedInAmount" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" onchange="" oncontextmenu="changeToEditingMode('oncontextmenu');" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" outputformat="euroEdition"></input>
+                        </td></tr>
+                      </table>
+                      <span id="paramGLItemReceivedInAmountinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
+                        <table class="TextBox_MsgContainer_table">
+                          <tbody><tr class="TextBox_MsgContainer_tr">
+                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
+                          </tr>
+                          <tr>
+                            <td class="invalid" colspan="2"><div name="invalidText" id="paramGLItemReceivedInAmountinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
+                          </tr>
+                        </tbody></table>
+                      </span>
+                    </td>
+                    <td class="FieldButton_ContentCell">
+                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpGLItemReceivedInAmount', document.frmMain.inpGLItemReceivedInAmount.value, false);return false;">
+                        <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
+                          <tr>
+                            <td class="FieldButton_bg">
+                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
+                            </td>
+                          </tr>
+                        </table>
+                      </a>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <td class="TitleCell"></td>
+              <td class="TitleCell"><span class="LabelText">Paid Out</span></td>
+              <td class="TextBox_btn_ContentCell">
+                <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
+                  <tr>
+                    <td class="Textbox_ContentCell">
+                      <table style="border: 0px none; border-collapse: collapse;">
+                        <tr><td style="padding-top: 0px;">
+                        <input type="text" id="paramGLItemPaidOutAmount" class="dojoValidateValid required TextBox_btn_OneCell_width number"  value="0" maxlength="22" name="inpGLItemPaidOutAmount" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" onchange="" oncontextmenu="changeToEditingMode('oncontextmenu');" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" outputformat="euroEdition"></input>
+                        </td></tr>
+                      </table>
+                      <span id="paramGLItemPaidOutAmountinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
+                        <table class="TextBox_MsgContainer_table">
+                          <tbody><tr class="TextBox_MsgContainer_tr">
+                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
+                          </tr>
+                          <tr>
+                            <td class="invalid" colspan="2"><div name="invalidText" id="paramGLItemPaidOutAmountinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
+                          </tr>
+                        </tbody></table>
+                      </span>
+                    </td>
+                    <td class="FieldButton_ContentCell">
+                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpGLItemPaidOutAmount', document.frmMain.inpGLItemPaidOutAmount.value, false);return false;">
+                        <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
+                          <tr>
+                            <td class="FieldButton_bg">
+                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
+                            </td>
+                          </tr>
+                        </table>
+                      </a>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <td class="TitleCell"></td>
+            </tr>
+            <tr id="glitemAddRow">
+              <td class="TitleCell"></td>
+              <td class="Button_RightAlign_ContentCell">
+                <div>
+                  <button type="button"
+                    id="buttonAddGLItem"
+                    class="ButtonLink_focus"
+                    onclick="addGLItem();return false;"
+                    onfocus="buttonEvent('onfocus', this); window.status='OK'; return true;"
+                    onblur="buttonEvent('onblur', this);"
+                    onkeyup="buttonEvent('onkeyup', this);"
+                    onkeydown="buttonEvent('onkeydown', this);"
+                    onkeypress="buttonEvent('onkeypress', this);"
+                    onmouseup="buttonEvent('onmouseup', this);"
+                    onmousedown="buttonEvent('onmousedown', this);"
+                    onmouseover="buttonEvent('onmouseover', this); window.status='OK'; return true;"
+                    onmouseout="buttonEvent('onmouseout', this);">
+                    <table class="Button">
+                      <tr>
+                        <td class="Button_left"><img class="Button_Icon Button_Icon_ok" alt="OK" title="OK" src="../web/images/blank.gif" id="imgButtonOK" border="0"></td>
+                        <td class="Button_text Button_width" id="tdButtonOK">Add</td>
+                        <td class="Button_right"></td>
+                      </tr>
+                    </table>
+                  </button>
+                </div>
+              </td>
+              <td class="TitleCell" colspan="4"></td>
+            </tr>
             <tr class="FieldGroup_BottomMargin"></tr>
           </table>
         </div>
@@ -1079,7 +1378,7 @@
               </td>
               <td valign="top">
                 <div id="client2" style="overflow: auto;">
-                  <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;">
+                  <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;" id="gridPayment">
                     <thead>
                       <tr class="DataGrid_Body_Row">
                         <th class="DataGrid_Header_LineNoCell DataGrid_Body_Cell_CheckBox" width="25"> 
@@ -1100,10 +1399,33 @@
                     <tbody id="sectionGrid">
                     </tbody>
                   </table>
-                  <input type="hidden" id="inpTotal" value="" outputformat="euroEdition"/>
-                  <input type="hidden" name="inpDifference" id="inpDifference" value="" outputformat="euroEdition"/>
+                  <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;" id="gridGLItem">
+                    <thead>
+                      <tr class="DataGrid_Body_Row">
+                        <th class="DataGrid_Header_Cell" width="400">GL Item</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Received In</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Paid Out</th>
+                        <th class="DataGrid_Header_LineNoCell" width="20"></th>
+                      </tr>
+                    </thead>
+                    <tbody id="sectionGLItemGrid">
+                    </tbody>
+                  </table>
+                  
+                  <input type="hidden" name="inpGLSumAmount" value="0" outputformat="euroEdition"/>
+                  <input type="hidden" name="inpInvoiceAmount" value="0" outputformat="euroEdition"/>
+                  <input type="hidden" id="inpTotal" value="0" outputformat="euroEdition"/>
+                  <input type="hidden" name="inpDifference" id="inpDifference" value="0" outputformat="euroEdition"/>
                   <table cellspacing="0" cellpadding="0" width="100%" class="" style="table-layout: auto;">
                     <tr class="FieldGroup_BottomMargin"></tr>
+                    <tr id="totalInvoices">
+                      <td width="80%" class="LabelText" style="text-align:right">Amount on Invoices and/or Orders</td>
+                      <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramInvoicesAmt"></span></td>
+                    </tr>
+                    <tr id="totalGLItems">
+                      <td width="80%" class="LabelText" style="text-align:right">Amount on GL Items</td>
+                      <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramGLItemsAmt"></span></td>
+                    </tr>
                     <tr>
                       <td width="715" class="LabelText" style="text-align:right">Total</td>
                       <td class="LabelText number" style="padding-right:10px;font-weight: bold;"><span id="paramTotal"></span></td>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Tue Jul 26 11:42:56 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Tue Jul 26 12:30:41 2011 +0200
@@ -31,6 +31,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.criterion.Restrictions;
@@ -57,6 +58,7 @@
 import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.enterprise.DocumentType;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.financialmgmt.gl.GLItem;
 import org.openbravo.model.financialmgmt.payment.FIN_BankStatementLine;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
@@ -154,8 +156,15 @@
       String strPaymentDate = vars.getRequiredStringParameter("inpPaymentDate");
       String strSelectedScheduledPaymentDetailIds = vars.getInParameter(
           "inpScheduledPaymentDetailId", IsIDFilter.instance);
-      if (strSelectedScheduledPaymentDetailIds == null) {
-        strSelectedScheduledPaymentDetailIds = "";
+      String strAddedGLItems = vars.getStringParameter("inpGLItems");
+      JSONArray addedGLITemsArray = null;
+      try {
+        addedGLITemsArray = new JSONArray(strAddedGLItems);
+      } catch (JSONException e) {
+        log4j.error("Error parsing received GLItems JSON Array: " + strAddedGLItems, e);
+        bdErrorGeneralPopUp(request, response, "Error",
+            "Error parsing received GLItems JSON Array: " + strAddedGLItems);
+        return;
       }
       String strDifferenceAction = vars.getStringParameter("inpDifferenceAction", "");
       BigDecimal refundAmount = BigDecimal.ZERO;
@@ -202,14 +211,31 @@
           strPaymentDocumentNo = Utility.getDocumentNo(this, vars, "AddPaymentFromTransaction",
               "FIN_Payment", strDocTypeId, strDocTypeId, false, true);
         }
-
-        FIN_Payment payment = FIN_AddPayment.savePayment(null, isReceipt,
+        final FIN_FinancialAccount finAcc = dao.getObject(FIN_FinancialAccount.class,
+            strFinancialAccountId);
+        FIN_Payment payment = dao.getNewPayment(isReceipt, finAcc.getOrganization(),
             dao.getObject(DocumentType.class, strDocTypeId), strPaymentDocumentNo,
             paymentBusinessPartner, dao.getObject(FIN_PaymentMethod.class, strPaymentMethodId),
-            dao.getObject(FIN_FinancialAccount.class, strFinancialAccountId), strPaymentAmount,
-            FIN_Utility.getDate(strPaymentDate),
-            dao.getObject(FIN_FinancialAccount.class, strFinancialAccountId).getOrganization(),
-            strReferenceNo, selectedPaymentDetails, selectedPaymentDetailAmounts,
+            finAcc, strPaymentAmount, FIN_Utility.getDate(strPaymentDate), strReferenceNo,
+            dao.getObject(Currency.class, paymentCurrencyId), exchangeRate, convertedAmount);
+
+        if (addedGLITemsArray != null) {
+          for (int i = 0; i < addedGLITemsArray.length(); i++) {
+            JSONObject glItem = addedGLITemsArray.getJSONObject(i);
+            BigDecimal glItemOutAmt = new BigDecimal(glItem.getString("glitemPaidOutAmt"));
+            BigDecimal glItemInAmt = new BigDecimal(glItem.getString("glitemReceivedInAmt"));
+            BigDecimal glItemAmt = BigDecimal.ZERO;
+            if (isReceipt) {
+              glItemAmt = glItemInAmt.subtract(glItemOutAmt);
+            } else {
+              glItemAmt = glItemOutAmt.subtract(glItemInAmt);
+            }
+            FIN_AddPayment.saveGLItem(payment, glItemAmt,
+                dao.getObject(GLItem.class, glItem.getString("glitemId")));
+          }
+        }
+        payment = FIN_AddPayment.savePayment(payment, isReceipt, null, null, null, null, null,
+            null, null, null, null, selectedPaymentDetails, selectedPaymentDetailAmounts,
             strDifferenceAction.equals("writeoff"), strDifferenceAction.equals("refund"),
             dao.getObject(Currency.class, paymentCurrencyId), exchangeRate, convertedAmount);