[Matching screen fixes]
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Fri, 05 Jul 2013 18:29:54 +0200
changeset 20709 da047e7388a8
parent 20708 8ffe44c21d8d
child 20710 cba285f50e81
[Matching screen fixes]
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.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
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransactionGrid.srpt
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransactionGrid.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_REFERENCE.xml
src-db/database/sourcedata/AD_REF_LIST.xml
src/org/openbravo/erpCommon/businessUtility/MessageJS.java
web/js/messages.js
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Jul 05 18:29:54 2013 +0200
@@ -1,5 +1,17 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <data>
+<!--00D0839059994323B4596EDA7D0BCF56--><AD_MESSAGE>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <AD_MESSAGE_ID><![CDATA[00D0839059994323B4596EDA7D0BCF56]]></AD_MESSAGE_ID>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <VALUE><![CDATA[APRM_PaidInvoice]]></VALUE>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <MSGTEXT><![CDATA[Invoice %s is already fully paid.]]></MSGTEXT>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--00D0839059994323B4596EDA7D0BCF56-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--00D0839059994323B4596EDA7D0BCF56--></AD_MESSAGE>
+
 <!--0267A646C8BD4042AE2422BCB83B4610--><AD_MESSAGE>
 <!--0267A646C8BD4042AE2422BCB83B4610-->  <AD_MESSAGE_ID><![CDATA[0267A646C8BD4042AE2422BCB83B4610]]></AD_MESSAGE_ID>
 <!--0267A646C8BD4042AE2422BCB83B4610-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Fri Jul 05 18:29:54 2013 +0200
@@ -12,7 +12,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2012 Openbravo SLU
+ * All portions are Copyright (C) 2010-2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  Enterprise Intelligence Systems (http://www.eintel.com.au).
  *************************************************************************
@@ -62,7 +62,14 @@
     try {
       if (XMLHttpRequestObj.responseText) {
         strText = XMLHttpRequestObj.responseText;
-        var aux = strText.substring(29, strText.length-8);
+        var objson = eval(strText);
+        if(objson.message!==''){
+          showJSMessage(objson.message, null, true, objson.params);
+          return true;
+        }else{
+          showJSMessage(null, null, true);
+        }
+        var aux = objson.grid;
         var tableBody = document.getElementById('sectionGrid');
         var browserName = getBrowserInfo('name');
         if (browserName.toUpperCase().indexOf('INTERNET EXPLORER') !== -1) {
@@ -78,7 +85,6 @@
         } else {
           tableBody.innerHTML = aux;
         }
-        
         updateAll();
         updateTotal();
 
@@ -435,17 +441,17 @@
 function validate(action) {
   var frm = document.frmMain;
   if (action === 'openprocess') {
-	if (isMulticurrencyTxn()) {
-	  if (frm.inpActualConverted.value==null || frm.inpActualConverted.value=="") {
-	    setWindowElementFocus(frm.inpActualConverted);
-	    showJSMessage(7);
-	    return false;
-	  } else if (frm.inpExchangeRate.value==null || frm.inpExchangeRate.value=="") {
-	    setWindowElementFocus(frm.inpExchangeRate);
-	    showJSMessage(7);
-	     return false;
-	  }
-	}
+    if (isMulticurrencyTxn()) {
+      if (frm.inpActualConverted.value==null || frm.inpActualConverted.value=="") {
+        setWindowElementFocus(frm.inpActualConverted);
+        showJSMessage(7);
+        return false;
+      } else if (frm.inpExchangeRate.value==null || frm.inpExchangeRate.value=="") {
+        setWindowElementFocus(frm.inpExchangeRate);
+        showJSMessage(7);
+         return false;
+      }
+    }
     if (frm.inpActualPayment.value === null || frm.inpActualPayment.value === '') {
       setWindowElementFocus(frm.inpActualPayment);
       showJSMessage(7);
@@ -706,12 +712,12 @@
   displayLogicElement('paramActualConvertedCell', display );
   displayLogicElement('lblActualConverted', display );
   if (document.frmMain.strNotAllowExchange.value === 'Y' && display) {  
-	  readOnlyLogicElement('paramExchangeRate', true);
+      readOnlyLogicElement('paramExchangeRate', true);
       readOnlyLogicElement('paramActualConverted', true);
       displayLogicElement('actualConvertedCal', false );
    }
   else {
-	  readOnlyLogicElement('paramExchangeRate', false);
+      readOnlyLogicElement('paramExchangeRate', false);
       readOnlyLogicElement('paramActualConvertedCell', false);
       displayLogicElement('actualConvertedCal', true );
   }
@@ -801,9 +807,6 @@
 }
 </script>
 <script language="JavaScript" type="text/javascript">
-function onloadFunctions() {
-  keyArray[keyArray.length] = new keyArrayItem("ENTER", "openSearch(null, null, '../info/BusinessPartner.html', 'BPARTNER_SELECTOR', false, 'frmMain', 'inpcBpartnerId', 'inpBpartnerId_DES', document.frmMain.inpBpartnerId_DES.value, 'Command', 'KEY');", "inpBpartnerId_DES", "null");
-}
 function displayLogicForCredit() {
   var hasCredit = compare(document.getElementById('paramCredit').value, '>', '0');
   displayLogicElement('paramCredit', hasCredit );
@@ -836,9 +839,6 @@
   setBrowserAutoComplete(false);
 
   initializeTemplate();
-  try {
-    onloadFunctions();
-  } catch (e) {}
   setGLItemMode(isTrue('isInGLItemMode'));
   displayLogicElement('sectionDifference', false);
   displayLogicElement('sectionDifferenceBox', false);
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Fri Jul 05 18:29:54 2013 +0200
@@ -27,6 +27,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Set;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -47,6 +48,7 @@
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.security.OrganizationStructureProvider;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
@@ -63,6 +65,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.common.invoice.Invoice;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.financialmgmt.accounting.Costcenter;
 import org.openbravo.model.financialmgmt.accounting.UserDimension1;
@@ -122,9 +125,10 @@
       final String strAmountFrom = vars.getNumericParameter("inpAmountFrom", "");
       final String strAmountTo = vars.getNumericParameter("inpAmountTo", "");
 
-      printGrid(response, vars, strFinancialAccountId, strBusinessPartnerId, strExpectedDateFrom,
-          strExpectedDateTo, strTransDateFrom, strTransDateTo, strDocumentType, strDocumentNo,
-          strSelectedPaymentDetails, isReceipt, strCurrencyId, strAmountFrom, strAmountTo);
+      printGrid(response, request, vars, strFinancialAccountId, strBusinessPartnerId,
+          strExpectedDateFrom, strExpectedDateTo, strTransDateFrom, strTransDateTo,
+          strDocumentType, strDocumentNo, strSelectedPaymentDetails, isReceipt, strCurrencyId,
+          strAmountFrom, strAmountTo);
 
     } else if (vars.commandIn("PAYMENTMETHODCOMBO")) {
       final String strBusinessPartnerId = vars.getRequestGlobalVariable("inpcBpartnerId", "");
@@ -398,8 +402,6 @@
       final PrintWriter out = response.getWriter();
       out.println(xmlDocument.print());
       out.close();
-
-      // "../org.openbravo.advpaymentmngt.ad_actionbutton/AddTransaction.html");
     }
 
   }
@@ -630,15 +632,15 @@
     out.close();
   }
 
-  private void printGrid(HttpServletResponse response, VariablesSecureApp vars,
-      String strFinancialAccountId, String strBusinessPartnerId, String strExpectedDateFrom,
-      String strExpectedDateTo, String strTransDateFrom, String strTransDateTo,
-      String strDocumentType, String strDocumentNo, String strSelectedPaymentDetails,
-      boolean isReceipt, String strCurrencyId, String strAmountFrom, String strAmountTo)
-      throws IOException, ServletException {
+  private void printGrid(HttpServletResponse response, HttpServletRequest request,
+      VariablesSecureApp vars, String strFinancialAccountId, String strBusinessPartnerId,
+      String strExpectedDateFrom, String strExpectedDateTo, String strTransDateFrom,
+      String strTransDateTo, String strDocumentType, String strDocumentNo,
+      String strSelectedPaymentDetails, boolean isReceipt, String strCurrencyId,
+      String strAmountFrom, String strAmountTo) throws IOException, ServletException {
 
     log4j.debug("Output: Grid with pending payments");
-
+    String message = "";
     dao = new AdvPaymentMngtDao();
     FIN_FinancialAccount financialAccount = dao.getObject(FIN_FinancialAccount.class,
         strFinancialAccountId);
@@ -681,12 +683,45 @@
     final FieldProvider[] data = FIN_AddPayment.getShownScheduledPaymentDetails(vars,
         selectedScheduledPaymentDetails, filteredScheduledPaymentDetails, false, null, null,
         displayDoubtfulDebtAmount(isReceipt));
+    String invoiceIdentifier = "";
+    if ((data == null || data.length == 0) && !"".equals(strDocumentNo) && strDocumentNo != null) {
+      final OBCriteria<Invoice> obc = OBDal.getInstance().createCriteria(Invoice.class);
+      if (isReceipt) {
+        obc.add(Restrictions.eq(Invoice.PROPERTY_DOCUMENTNO, strDocumentNo));
+      } else {
+        obc.add(Restrictions.eq(Invoice.PROPERTY_ORDERREFERENCE, strDocumentNo));
+      }
+      obc.add(Restrictions.eq(Invoice.PROPERTY_PROCESSED, true));
+      obc.add(Restrictions.eq(Invoice.PROPERTY_SALESTRANSACTION, isReceipt));
+      if (strBusinessPartnerId != null && !"".equals(strBusinessPartnerId)) {
+        obc.add(Restrictions.eq(Invoice.PROPERTY_BUSINESSPARTNER, strBusinessPartnerId));
+      }
+      obc.add(Restrictions.eq(Invoice.PROPERTY_PAYMENTCOMPLETE, true));
+      obc.add(Restrictions.in(Invoice.PROPERTY_ORGANIZATION,
+          getOrganizationList(new OrganizationStructureProvider().getChildTree(financialAccount
+              .getOrganization().getId(), true))));
+      obc.addOrderBy(Invoice.PROPERTY_INVOICEDATE, false);
+      Invoice invoice = (Invoice) obc.uniqueResult();
+      if (invoice != null) {
+        invoiceIdentifier = invoice.getIdentifier();
+        message = "APRM_PaidInvoice";
+      }
+    }
     xmlDocument.setData("structure", (data == null) ? set() : data);
-
-    response.setContentType("text/html; charset=UTF-8");
-    PrintWriter out = response.getWriter();
-    out.println(xmlDocument.print());
-    out.close();
+    try {
+      JSONObject json = new JSONObject();
+      ArrayList<String> params = new ArrayList<String>();
+      params.add(invoiceIdentifier);
+      json.put("message", message);
+      json.put("params", params);
+      json.put("grid", xmlDocument.print());
+      response.setContentType("text/html; charset=UTF-8");
+      PrintWriter out = response.getWriter();
+      out.println("objson = " + json);
+      out.close();
+    } catch (JSONException e) {
+      log4j.error("AddPaymentFromTransaction - CallbackGrid", e);
+    }
   }
 
   /**
@@ -854,6 +889,14 @@
     // end of getServletInfo() method
   }
 
+  private List<Organization> getOrganizationList(Set<String> orgIds) {
+    List<Organization> result = new ArrayList<Organization>();
+    for (String orgId : orgIds) {
+      result.add(OBDal.getInstance().get(Organization.class, orgId));
+    }
+    return result;
+  }
+
   boolean displayDoubtfulDebtAmount(boolean isReceipt) {
     if (!isReceipt) {
       return false;
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html	Fri Jul 05 18:29:54 2013 +0200
@@ -12,7 +12,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2012 Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -1060,9 +1060,7 @@
               <td class="TitleCell"><span class="LabelText">Document</span></td>
               <td class="Combo_ContentCell">
                 <select  name="inpDocumentType" id="paramDocumentType" class="Combo Combo_OneCell_width" onchange="showPaymentSection2();return true;">
-                  <!-- <option value=""><div id="reportDocument"></div></option> -->
-                  <option value="RCIN" selected="selected">Received In</option>
-                  <option value="PDOUT">Paid Out</option>
+                  <option value=""><div id="reportDocumentType"></div></option>
                 </select>
               </td> 
               <td class="TitleCell"><span class="LabelText">From Date</span></td>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.java	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.java	Fri Jul 05 18:29:54 2013 +0200
@@ -363,21 +363,45 @@
     xmlDocument.setParameter("finFinancialAccountId", strFinancialAccountId);
     xmlDocument.setParameter("finBankStatementLineId", strBankStatementLineId);
     String transactionType = "P";
+    try {
+      String Document_Type_AddTransaction_Reference_ID = "40B84CF78FC9435790887846CCDAE875";
+      ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "",
+          Document_Type_AddTransaction_Reference_ID, "", Utility.getContext(this, vars,
+              "#AccessibleOrgTree", "AddTransaction"), Utility.getContext(this, vars,
+              "#User_Client", "AddTransaction"), 0);
+      Utility.fillSQLParameters(this, vars, null, comboTableData, "AddTransaction", "");
+      xmlDocument.setData("reportDocumentType", "liststructure", comboTableData.select(false));
+      comboTableData = null;
+    } catch (Exception ex) {
+      throw new ServletException(ex);
+    }
+    boolean isReceipt = true;
     if (!"".equals(strBankStatementLineId)) {
       FIN_BankStatementLine bsl = OBDal.getInstance().get(FIN_BankStatementLine.class,
           strBankStatementLineId);
       String dateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
           .getProperty("dateFormat.java");
       SimpleDateFormat dateFormater = new SimpleDateFormat(dateFormat);
-
+      // Default signum based on amount
+      isReceipt = bsl.getCramount().subtract(bsl.getDramount()).signum() > 0;
+      if (bsl.getBusinessPartner() != null && bsl.getBusinessPartner().isCustomer()
+          && !bsl.getBusinessPartner().isVendor()) {
+        isReceipt = true;
+      }
+      if (bsl.getBusinessPartner() != null && !bsl.getBusinessPartner().isCustomer()
+          && bsl.getBusinessPartner().isVendor()) {
+        isReceipt = false;
+      }
       xmlDocument.setParameter("depositAmount", bsl.getCramount().toString());
       xmlDocument.setParameter("paymentAmount", bsl.getDramount().toString());
       xmlDocument.setParameter("depositAmountGLItem", bsl.getCramount().toString());
       xmlDocument.setParameter("paymentAmountGLItem", bsl.getDramount().toString());
       xmlDocument.setParameter("mainDate", dateFormater.format(bsl.getTransactionDate()));
-      String bslDescription = !"".equals(bsl) ? bsl.getDescription() : "";
-      String strDescription = !"".equals(bsl.getBpartnername()) ? bsl.getBpartnername() + "\n"
-          + bslDescription : bslDescription;
+      String bslDescription = (!"".equals(bsl.getDescription()) && bsl.getDescription() != null) ? bsl
+          .getDescription() : "";
+      String strDescription = (!"".equals(bsl.getBpartnername()) && bsl.getBpartnername() != null) ? bsl
+          .getBpartnername() + "\n" + bslDescription
+          : bslDescription;
       xmlDocument.setParameter("GLItemDescription", strDescription);
       xmlDocument.setParameter("FeeDescription", strDescription);
       if (bsl.getGLItem() != null) {
@@ -398,6 +422,9 @@
       xmlDocument.setParameter("FeeDescription", "");
 
     }
+    final String RECEIVED_IN_OPTION = "RCIN";
+    final String PAID_OUT_OPTION = "PDOUT";
+    xmlDocument.setParameter("documentType", isReceipt ? RECEIVED_IN_OPTION : PAID_OUT_OPTION);
     try {
       String Transaction_Type_AddTransaction_Reference_ID = "C1B4345A1F8841C2B1ADD403CA733D75";
       ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "",
@@ -489,12 +516,17 @@
     // Payments not deposited/withdrawal
     // Not stored in Fin_Finacc_Transaction table
     final FieldProvider[] data;
-    if (showAlternativeFA & isReceipt) {
-      data = dao.getAlternativePaymentsNotDeposited(account, FIN_Utility.getDate(strFromDate),
-          FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strToDate, "1")), isReceipt);
+    if (!"Y".equals(closeAutomatically)) {
+      if (showAlternativeFA & isReceipt) {
+        data = dao.getAlternativePaymentsNotDeposited(account, FIN_Utility.getDate(strFromDate),
+            FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strToDate, "1")), isReceipt);
+      } else {
+        data = dao.getPaymentsNotDeposited(account, FIN_Utility.getDate(strFromDate),
+            FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strToDate, "1")), isReceipt);
+      }
     } else {
-      data = dao.getPaymentsNotDeposited(account, FIN_Utility.getDate(strFromDate),
-          FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strToDate, "1")), isReceipt);
+      vars.setSessionValue("MatchTransaction.executeMatching", "N");
+      data = null;
     }
     xmlDocument.setData("structure", (data == null) ? set() : data);
     JSONObject table = new JSONObject();
@@ -532,6 +564,7 @@
     if (bsline.getCramount().compareTo(finTrans.getDepositAmount()) != 0
         || bsline.getDramount().compareTo(finTrans.getPaymentAmount()) != 0) {
       vars.setSessionValue("AddTransaction|ShowJSMessage", "Y");
+      vars.setSessionValue("AddTransaction|SelectedTransaction", finTrans.getId());
     } else {
       FIN_Reconciliation reconciliation = TransactionsDao.getLastReconciliation(
           finTrans.getAccount(), "N");
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.xml	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.xml	Fri Jul 05 18:29:54 2013 +0200
@@ -64,8 +64,10 @@
   
     
     <!-- Document Type -->
-    <PARAMETER id="paramDocument" name="document"/>
-    
+    <PARAMETER id="paramDocumentType" name="documentType"/>
+      <SUBREPORT id="reportDocumentType" name="reportDocumentType" report="org/openbravo/erpCommon/reference/List">
+        <ARGUMENT name="parameterListSelected" withId="paramDocumentType"/>
+      </SUBREPORT>
     <!-- Transaction Type -->
     <PARAMETER id="paramTransactionType" name="transactionType"/>
       <SUBREPORT id="reportTransactionType" name="reportTransactionType" report="org/openbravo/erpCommon/reference/List">
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html	Fri Jul 05 18:29:54 2013 +0200
@@ -82,6 +82,8 @@
   document.getElementById("inpMatchingType_" + sc_FIN_FinAcc_Transaction_ID.bslId).value = "MA";
   document.getElementById("inpCheckBox_" + sc_FIN_FinAcc_Transaction_ID.bslId).checked = true;
   document.getElementById("inpCheckBox_" + sc_FIN_FinAcc_Transaction_ID.bslId).disabled = false;
+  document.frmMain.inpFinBankStatementLineId.value = sc_FIN_FinAcc_Transaction_ID.bslId;
+  sendActionToServer("MATCH");
 }
 
 function openSelector(bslId) {
@@ -127,8 +129,9 @@
 function unMatchLine(bankStatementLineId, isChecked) {
   if (!isChecked) {
     disableChecks();
+    document.frmMain.inpFinBankStatementLineId.value = bankStatementLineId;
     APRMMatchStatementIds[bankStatementLineId]=false;
-    document.frmMain.inpFinBankStatementLineId.value = bankStatementLineId;
+    sendActionToServer("UNMATCH");
     document.getElementById("inpMatchedDocument_" + bankStatementLineId).innerHTML = "";
     document.getElementById("inpTransactionDate_" + bankStatementLineId).innerHTML = "";
     document.getElementById("inpBPartner_" + bankStatementLineId).innerHTML = "";
@@ -138,10 +141,11 @@
     document.getElementById("inpMatchStyle_" + bankStatementLineId).style.backgroundColor = "white";
     document.getElementById("inpMatchingType_" + bankStatementLineId).value = "";
     document.getElementById("inpExecuteMatching").value = "N";
-    sendActionToServer("UNMATCH");
   }
   else {
     APRMMatchStatementIds[bankStatementLineId]=true;
+    document.frmMain.inpFinBankStatementLineId.value = bankStatementLineId;
+    sendActionToServer("MATCH");
   }
   return true;
 }
@@ -172,12 +176,15 @@
 }
 </script>
 <script language="JavaScript" type="text/javascript">
-    function loadGrid() {
+    function loadGrid(skipMatching) {
       try {
         var url = "../org.openbravo.advpaymentmngt.ad_actionbutton/MatchTransaction.html";
         var paramXMLReq = null;
         serverWorking = true;
         document.frmMain.buttonProcess.disabled = true;
+        if(skipMatching){
+         document.getElementById("inpExecuteMatching").value = "N";
+        }
         return submitXmlHttpRequest(callBackGrid, document.frmMain, "GRID", url, false, null, paramXMLReq);
       } catch (e) {
         alert(e);
@@ -215,7 +222,12 @@
               document.frmMain.isFirstLoad.value="false";
             }
             if (showJSMessage === "Y") {
-              displayMessageBox('APRM_TransactionLinesAmountNotMatch');
+              if (confirm(document.frmMain.inpTrlSplitConfirmText.value)) {
+                document.frmMain.inpSelectedFindTransactionId.value = selected.id;
+                splitRow();
+              } else {
+                showJSMessage('APRM_LinesAmountMismatch');
+              }
             }else{
               initialize_MessageBox('messageBoxID');
             }
@@ -577,7 +589,7 @@
                         <td colspan="5" style="text-align: center; font-weight: bold;">Transactions in Openbravo</td>
                       </tr>
                       <tr style="border-top: thin solid gray;">
-                        <td colspan="5" style="border-right: thin solid gray;"><span class="LabelText">Show</span>&nbsp;<span><select name="inpPaymentTypeFilter" class="ComboKey Combo_TwoCells_width required" id="inpPaymentTypeFilter" onchange="loadGrid(); return true;"><option value="" class="discard">Deposits and payments</option></select></span>&nbsp;<nobr><span class="LabelText">Cleared</span>&nbsp;<span><input type="checkbox" name="inpShowCleared" id="inpShowCleared" disabled=true value="Y" onclick="loadGrid(); return true;" /></span></nobr></td>
+                        <td colspan="5" style="border-right: thin solid gray;"><span class="LabelText">Show</span>&nbsp;<span><select name="inpPaymentTypeFilter" class="ComboKey Combo_TwoCells_width required" id="inpPaymentTypeFilter" onchange="loadGrid(true); return true;"><option value="" class="discard">Deposits and payments</option></select></span>&nbsp;<nobr><span class="LabelText">Cleared</span>&nbsp;<span><input type="checkbox" name="inpShowCleared" id="inpShowCleared" disabled=true value="Y" onclick="loadGrid(true); return true;" /></span></nobr></td>
                         <td style="text-align: center;"></td>
                         <td colspan="5" style="border-left: thin solid gray;"></span>&nbsp;&nbsp;<span>Hide transactions after statement date</span>&nbsp;&nbsp;<span><input type="checkbox" name="inphideDate" id="fieldhideDate" disabled=true value="Y" onClick="loadGrid(); return true;"/></span>&nbsp;&nbsp;<span>Ending Date</span>&nbsp;&nbsp;<span type="LabelText" id="paramDateTo"></span></td>
                       </tr>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java	Fri Jul 05 18:29:54 2013 +0200
@@ -46,7 +46,6 @@
 import org.openbravo.advpaymentmngt.utility.FIN_MatchingTransaction;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.base.exception.OBException;
-import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
@@ -83,220 +82,200 @@
 public class MatchTransaction extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
   VariablesSecureApp vars = null;
+  static ArrayList<String> runingReconciliations = new ArrayList<String>();
 
   public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
+    // long init = System.currentTimeMillis();
     vars = new VariablesSecureApp(request);
-
-    if (vars.commandIn("DEFAULT")) {
-      String strOrgId = vars.getRequestGlobalVariable("inpadOrgId", "MatchTransaction.adOrgId");
-      String strWindowId = vars.getGlobalVariable("inpwindowId", "MatchTransaction.adWindowId");
-      String strTabId = vars.getGlobalVariable("inpTabId", "MatchTransaction.adTabId");
-      String strFinancialAccountId = vars.getGlobalVariable("inpfinFinancialAccountId",
-          "MatchTransaction.finFinancialAccountId");
-      String strPaymentTypeFilter = vars.getGlobalVariable("inpPaymentTypeFilter",
-          "MatchTransaction.paymentTypeFilter", "ALL");
-      String strShowCleared = vars.getGlobalVariable("inpShowCleared",
-          "MatchTransaction.showCleared", "N");
-      String strHideDate = vars.getGlobalVariable("inpHideDate", "MatchTransaction.hideDate", "Y");
-      FIN_FinancialAccount account = OBDal.getInstance().get(FIN_FinancialAccount.class,
-          strFinancialAccountId);
-      FIN_Reconciliation reconciliation = TransactionsDao.getLastReconciliation(OBDal.getInstance()
-          .get(FIN_FinancialAccount.class, strFinancialAccountId), "N");
-      int reconciledItems = 0;
-      if (reconciliation != null) {
-        if (isManualReconciliation(reconciliation)) {
-          OBDal.getInstance().rollbackAndClose();
+    String strReconciliationId = "";
+    try {
+      if (vars.commandIn("DEFAULT")) {
+        String strOrgId = vars.getRequestGlobalVariable("inpadOrgId", "MatchTransaction.adOrgId");
+        String strWindowId = vars.getGlobalVariable("inpwindowId", "MatchTransaction.adWindowId");
+        String strTabId = vars.getGlobalVariable("inpTabId", "MatchTransaction.adTabId");
+        String strFinancialAccountId = vars.getGlobalVariable("inpfinFinancialAccountId",
+            "MatchTransaction.finFinancialAccountId");
+        String strPaymentTypeFilter = vars.getGlobalVariable("inpPaymentTypeFilter",
+            "MatchTransaction.paymentTypeFilter", "ALL");
+        String strShowCleared = vars.getGlobalVariable("inpShowCleared",
+            "MatchTransaction.showCleared", "N");
+        String strHideDate = vars
+            .getGlobalVariable("inpHideDate", "MatchTransaction.hideDate", "Y");
+        FIN_FinancialAccount account = OBDal.getInstance().get(FIN_FinancialAccount.class,
+            strFinancialAccountId);
+        FIN_Reconciliation reconciliation = TransactionsDao.getLastReconciliation(OBDal
+            .getInstance().get(FIN_FinancialAccount.class, strFinancialAccountId), "N");
+        int reconciledItems = 0;
+        if (reconciliation != null) {
+          strReconciliationId = reconciliation.getId();
+          if (runingReconciliations.contains(strReconciliationId)) {
+            wait(strReconciliationId);
+          }
+          runingReconciliations.add(reconciliation.getId());
+          if (isManualReconciliation(reconciliation)) {
+            OBDal.getInstance().rollbackAndClose();
+            OBError message = Utility.translateError(this, vars, vars.getLanguage(), Utility
+                .parseTranslation(this, vars, vars.getLanguage(), "@APRM_ReconciliationMixed@"));
+            vars.setMessage(strTabId, message);
+            printPageClosePopUp(response, vars, Utility.getTabURL(strTabId, "R", true));
+            return;
+          }
+          OBContext.setAdminMode();
+          try {
+            getSnapShot(reconciliation);
+            reconciledItems = reconciliation.getFINReconciliationLineVList().size();
+          } finally {
+            OBContext.restorePreviousMode();
+          }
+        }
+        if (MatchTransactionDao.getUnMatchedBankStatementLines(account).size() == 0
+            && reconciledItems == 0) {
           OBError message = Utility.translateError(this, vars, vars.getLanguage(), Utility
-              .parseTranslation(this, vars, vars.getLanguage(), "@APRM_ReconciliationMixed@"));
+              .parseTranslation(this, vars, vars.getLanguage(), "@APRM_NoStatementsToMatch@"));
           vars.setMessage(strTabId, message);
           printPageClosePopUp(response, vars, Utility.getTabURL(strTabId, "R", true));
-          return;
+        } else {
+          if (reconciliation == null) {
+            reconciliation = MatchTransactionDao.addNewReconciliation(this, vars,
+                strFinancialAccountId);
+            strReconciliationId = reconciliation.getId();
+            if (runingReconciliations.contains(strReconciliationId)) {
+              wait(strReconciliationId);
+            }
+            runingReconciliations.add(strReconciliationId);
+            getSnapShot(reconciliation);
+          } else {
+            updateReconciliation(reconciliation.getId(), strFinancialAccountId, strTabId, false);
+          }
+          printPage(response, vars, strOrgId, strWindowId, strTabId, strPaymentTypeFilter,
+              strFinancialAccountId, reconciliation.getId(), strShowCleared, strHideDate);
         }
+        // log4j.error("Default took: " + (System.currentTimeMillis() - init));
+      } else if (vars.commandIn("GRID")) {
+        String strFinancialAccountId = vars.getRequestGlobalVariable("inpfinFinancialAccountId",
+            "MatchTransaction.finFinancialAccountId");
+        strReconciliationId = vars.getRequestGlobalVariable("inpfinReconciliationId",
+            "MatchTransaction.finReconciliationId");
+        if (runingReconciliations.contains(strReconciliationId)) {
+          wait(strReconciliationId);
+        }
+        runingReconciliations.add(strReconciliationId);
+        String strPaymentTypeFilter = vars.getRequestGlobalVariable("inpPaymentTypeFilter",
+            "MatchTransaction.paymentTypeFilter");
+        String strShowCleared = vars.getRequestGlobalVariable("inpShowCleared",
+            "MatchTransaction.showCleared");
+        String executeMatching = vars.getSessionValue("MatchTransaction.executeMatching");
+        vars.setSessionValue("MatchTransaction.executeMatching", "");
+        if (executeMatching.equals("")) {
+          executeMatching = vars.getStringParameter("inpExecuteMatching", "Y");
+        }
+        if (strShowCleared.equals("")) {
+          strShowCleared = "N";
+          vars.setSessionValue("MatchTransaction.showCleared", strShowCleared);
+        }
+        String strHideDate = vars.getRequestGlobalVariable("inphideDate",
+            "MatchTransaction.hideDate");
+        if (strHideDate.equals("")) {
+          strHideDate = "N";
+          vars.setSessionValue("MatchTransaction.hideDate", strHideDate);
+        }
+        String showJSMessage = vars.getSessionValue("AddTransaction|ShowJSMessage");
+        vars.setSessionValue("AddTransaction|ShowJSMessage", "N");
+
+        printGrid(response, vars, strPaymentTypeFilter, strFinancialAccountId, strReconciliationId,
+            strShowCleared, strHideDate, showJSMessage, "Y".equals(executeMatching));
+        // log4j.error("PrintGrid took: " + (System.currentTimeMillis() - init));
+      } else if (vars.commandIn("UNMATCH")) {
+        strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
+        if (runingReconciliations.contains(strReconciliationId)) {
+          wait(strReconciliationId);
+        }
+        runingReconciliations.add(strReconciliationId);
+        String strUnmatchBankStatementLineId = vars
+            .getRequiredStringParameter("inpFinBankStatementLineId");
+        unMatchBankStatementLine(response, strUnmatchBankStatementLineId);
+        // log4j.error("UnMatch took: " + (System.currentTimeMillis() - init));
+      } else if (vars.commandIn("MATCH")) {
+        strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
+        if (runingReconciliations.contains(strReconciliationId)) {
+          wait(strReconciliationId);
+        }
+        runingReconciliations.add(strReconciliationId);
+        String strMatchedBankStatementLineId = vars
+            .getRequiredStringParameter("inpFinBankStatementLineId");
+        String strFinancialTransactionId = vars
+            .getRequiredStringParameter("inpFinancialTransactionId_"
+                + strMatchedBankStatementLineId);
+        matchBankStatementLine(strMatchedBankStatementLineId, strFinancialTransactionId,
+            strReconciliationId, null);
+        // log4j.error("Match took: " + (System.currentTimeMillis() - init));
+      } else if (vars.commandIn("CANCEL")) {
+        strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
+        if (runingReconciliations.contains(strReconciliationId)) {
+          wait(strReconciliationId);
+        }
+        runingReconciliations.add(strReconciliationId);
+        restoreSnapShot(OBDal.getInstance().get(FIN_Reconciliation.class, strReconciliationId));
+        String strTabId = vars.getGlobalVariable("inpTabId", "MatchTransaction.adTabId");
+        String strWindowPath = Utility.getTabURL(strTabId, "R", true);
+        if (strWindowPath.equals(""))
+          strWindowPath = strDefaultServlet;
+        printPageClosePopUp(response, vars, strWindowPath);
+        // log4j.error("Cancel took: " + (System.currentTimeMillis() - init));
+      } else if (vars.commandIn("SPLIT")) {
+        strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
+        if (runingReconciliations.contains(strReconciliationId)) {
+          wait(strReconciliationId);
+        }
+        runingReconciliations.add(strReconciliationId);
+        String strBankStatementLineId = vars
+            .getRequiredStringParameter("inpFinBankStatementLineId");
+        String strTransactionId = vars.getSessionValue("AddTransaction|SelectedTransaction");
+        vars.setSessionValue("AddTransaction|SelectedTransaction", "");
+        if ("".equals(strTransactionId)) {
+          strTransactionId = vars.getRequiredStringParameter("inpSelectedFindTransactionId");
+        }
+        splitBankStatementLine(response, strReconciliationId, strBankStatementLineId,
+            strTransactionId);
+        // log4j.error("Split took: " + (System.currentTimeMillis() - init));
+      } else if (vars.commandIn("SAVE", "RECONCILE")) {
         OBContext.setAdminMode();
         try {
-          getSnapShot(reconciliation);
-          reconciledItems = reconciliation.getFINReconciliationLineVList().size();
-        } finally {
-          OBContext.restorePreviousMode();
-        }
-      }
-      if (MatchTransactionDao.getUnMatchedBankStatementLines(account).size() == 0
-          && reconciledItems == 0) {
-        OBError message = Utility.translateError(this, vars, vars.getLanguage(),
-            Utility.parseTranslation(this, vars, vars.getLanguage(), "@APRM_NoStatementsToMatch@"));
-        vars.setMessage(strTabId, message);
-        printPageClosePopUp(response, vars, Utility.getTabURL(strTabId, "R", true));
-      } else {
-        if (reconciliation == null) {
-          reconciliation = MatchTransactionDao.addNewReconciliation(this, vars,
-              strFinancialAccountId);
-          getSnapShot(reconciliation);
-        } else {
-          updateReconciliation(vars, reconciliation.getId(), strFinancialAccountId, strTabId, false);
-        }
-
-        printPage(response, vars, strOrgId, strWindowId, strTabId, strPaymentTypeFilter,
-            strFinancialAccountId, reconciliation.getId(), strShowCleared, strHideDate);
-      }
-    } else if (vars.commandIn("GRID")) {
-      String strFinancialAccountId = vars.getRequestGlobalVariable("inpfinFinancialAccountId",
-          "MatchTransaction.finFinancialAccountId");
-      String strReconciliationId = vars.getRequestGlobalVariable("inpfinReconciliationId",
-          "MatchTransaction.finReconciliationId");
-      String strPaymentTypeFilter = vars.getRequestGlobalVariable("inpPaymentTypeFilter",
-          "MatchTransaction.paymentTypeFilter");
-      String strShowCleared = vars.getRequestGlobalVariable("inpShowCleared",
-          "MatchTransaction.showCleared");
-      String executeMatching = vars.getStringParameter("inpExecuteMatching", "Y");
-      if (strShowCleared.equals("")) {
-        strShowCleared = "N";
-        vars.setSessionValue("MatchTransaction.showCleared", strShowCleared);
-      }
-      String strHideDate = vars
-          .getRequestGlobalVariable("inphideDate", "MatchTransaction.hideDate");
-      if (strHideDate.equals("")) {
-        strHideDate = "N";
-        vars.setSessionValue("MatchTransaction.hideDate", strHideDate);
-      }
-      String showJSMessage = vars.getSessionValue("AddTransaction|ShowJSMessage");
-      vars.setSessionValue("AddTransaction|ShowJSMessage", "N");
-
-      printGrid(response, vars, strPaymentTypeFilter, strFinancialAccountId, strReconciliationId,
-          strShowCleared, strHideDate, showJSMessage, "Y".equals(executeMatching));
-    } else if (vars.commandIn("UNMATCH")) {
-      String strUnmatchBankStatementLineId = vars
-          .getRequiredStringParameter("inpFinBankStatementLineId");
-      unMatchBankStatementLine(response, strUnmatchBankStatementLineId);
-
-    } else if (vars.commandIn("CANCEL")) {
-      String strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
-      restoreSnapShot(OBDal.getInstance().get(FIN_Reconciliation.class, strReconciliationId));
-      String strTabId = vars.getGlobalVariable("inpTabId", "MatchTransaction.adTabId");
-      String strWindowPath = Utility.getTabURL(strTabId, "R", true);
-      if (strWindowPath.equals(""))
-        strWindowPath = strDefaultServlet;
-
-      printPageClosePopUp(response, vars, strWindowPath);
-    } else if (vars.commandIn("SPLIT")) {
-      String strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
-      String strBankStatementLineId = vars.getRequiredStringParameter("inpFinBankStatementLineId");
-      String strTransactionId = vars.getRequiredStringParameter("inpSelectedFindTransactionId");
-      splitBankStatementLine(response, strReconciliationId, strBankStatementLineId,
-          strTransactionId);
-    } else if (vars.commandIn("SAVE", "RECONCILE")) {
-      OBContext.setAdminMode();
-      try {
-        String strFinancialAccountId = vars.getRequiredStringParameter("inpfinFinancialAccountId");
-        // String strRecords = vars.getRequiredInParameter("inpRecordId", IsIDFilter.instance);
-        String strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
-        String strTabId = vars.getGlobalVariable("inpTabId", "MatchTransaction.adTabId");
-        String message = "";
-        // checkReconciliationPending(vars, strReconciliationId, strTabId);
-        if (message == null || message.length() == 0) {
-
-          String strRecordsChecked = vars.getInParameter("inpBankStatementLineId",
-              IsIDFilter.instance);
-          List<FIN_BankStatementLine> items = FIN_Utility.getOBObjectList(
-              FIN_BankStatementLine.class, strRecordsChecked);
-
-          for (FIN_BankStatementLine item : items) {
-            if (item.getFinancialAccountTransaction() != null) {
-              // Unmatch Transaction
-              FIN_FinaccTransaction oldTransaction = item.getFinancialAccountTransaction();
-              final String DEPOSITED_NOT_CLEARED = "RDNC";
-              final String WITHDRAWN_NOT_CLEARED = "PWNC";
-              oldTransaction
-                  .setStatus(oldTransaction.getDepositAmount()
-                      .subtract(oldTransaction.getPaymentAmount()).signum() == 1 ? DEPOSITED_NOT_CLEARED
-                      : WITHDRAWN_NOT_CLEARED);
-              oldTransaction.setReconciliation(null);
-              OBDal.getInstance().save(oldTransaction);
-            }
-            String strTransaction = vars.getStringParameter(
-                "inpFinancialTransactionId_" + item.getId(), "");
-            String strMatchingType = vars.getStringParameter("inpMatchingType_" + item.getId(),
-                FIN_MatchedTransaction.NOMATCH);
-            if (strTransaction == null || strTransaction.equalsIgnoreCase("")) {
-              item.setFinancialAccountTransaction(null);
-              item.setMatchingtype(FIN_MatchedTransaction.NOMATCH);
-            } else {
-              FIN_FinaccTransaction transactionLine = MatchTransactionDao.getObject(
-                  FIN_FinaccTransaction.class, strTransaction);
-              transactionLine.setReconciliation(MatchTransactionDao.getObject(
-                  FIN_Reconciliation.class, strReconciliationId));
-              if (isInArray(strRecordsChecked, item.getId())) {
-                transactionLine.setStatus("RPPC");
-                if (transactionLine.getFinPayment() != null) {
-                  transactionLine.getFinPayment().setStatus("RPPC");
-                }
-                if (item.getTransactionDate().compareTo(transactionLine.getTransactionDate()) < 0) {
-                  // Set processed to false before changing dates to avoid trigger exception
-                  boolean posted = "Y".equals(transactionLine.getPosted());
-                  if (posted) {
-                    transactionLine.setPosted("N");
-                    OBDal.getInstance().save(transactionLine);
-                    OBDal.getInstance().flush();
-                  }
-                  transactionLine.setProcessed(false);
-                  OBDal.getInstance().save(transactionLine);
-                  OBDal.getInstance().flush();
-                  transactionLine.setTransactionDate(item.getTransactionDate());
-                  transactionLine.setDateAcct(item.getTransactionDate());
-                  OBDal.getInstance().save(transactionLine);
-                  OBDal.getInstance().flush();
-                  // Set processed to true afterwards
-                  transactionLine.setProcessed(true);
-                  OBDal.getInstance().save(transactionLine);
-                  OBDal.getInstance().flush();
-                  if (posted) {
-                    transactionLine.setPosted("Y");
-                    OBDal.getInstance().save(transactionLine);
-                    OBDal.getInstance().flush();
-                  }
-                  // Changing dates for accounting entries as well
-                  TransactionsDao.updateAccountingDate(transactionLine);
-                }
-              } else {
-                boolean isReceipt = true;
-                if (transactionLine.getFinPayment() != null)
-                  isReceipt = transactionLine.getFinPayment().isReceipt();
-                else
-                  isReceipt = (transactionLine.getDepositAmount().compareTo(
-                      transactionLine.getPaymentAmount()) >= 0);
-                transactionLine.setStatus((isReceipt) ? "RDNC" : "PWNC");
-              }
-              OBDal.getInstance().save(transactionLine);
-              OBDal.getInstance().flush();
-              item.setFinancialAccountTransaction(transactionLine);
-              item.setMatchingtype(strMatchingType);
-              if (transactionLine.getFinPayment() != null)
-                item.setBusinessPartner(transactionLine.getFinPayment().getBusinessPartner());
-            }
-            OBDal.getInstance().save(item);
-            OBDal.getInstance().flush();
+          String strFinancialAccountId = vars
+              .getRequiredStringParameter("inpfinFinancialAccountId");
+          // String strRecords = vars.getRequiredInParameter("inpRecordId", IsIDFilter.instance);
+          strReconciliationId = vars.getRequiredStringParameter("inpfinReconciliationId");
+          if (runingReconciliations.contains(strReconciliationId)) {
+            wait(strReconciliationId);
           }
-          if (updateReconciliation(vars, strReconciliationId, strFinancialAccountId, strTabId,
+          runingReconciliations.add(strReconciliationId);
+          String strTabId = vars.getGlobalVariable("inpTabId", "MatchTransaction.adTabId");
+          if (updateReconciliation(strReconciliationId, strFinancialAccountId, strTabId,
               vars.commandIn("RECONCILE"))) {
             OBError msg = new OBError();
             msg.setType("Success");
             msg.setTitle(Utility.messageBD(this, "Success", vars.getLanguage()));
             vars.setMessage(strTabId, msg);
           }
+          // }
+          String strWindowPath = Utility.getTabURL(strTabId, "R", true);
+          if (strWindowPath.equals(""))
+            strWindowPath = strDefaultServlet;
+
+          printPageClosePopUp(response, vars, strWindowPath);
+        } finally {
+          OBContext.restorePreviousMode();
         }
-        String strWindowPath = Utility.getTabURL(strTabId, "R", true);
-        if (strWindowPath.equals(""))
-          strWindowPath = strDefaultServlet;
-
-        printPageClosePopUp(response, vars, strWindowPath);
-      } finally {
-        OBContext.restorePreviousMode();
+        // log4j.error("Save took: " + (System.currentTimeMillis() - init));
       }
+    } finally {
+      runingReconciliations.remove(strReconciliationId);
     }
   }
 
-  private boolean updateReconciliation(VariablesSecureApp vars, String strReconciliationId,
-      String strFinancialAccountId, String strTabId, boolean process) {
+  private boolean updateReconciliation(String strReconciliationId, String strFinancialAccountId,
+      String strTabId, boolean process) {
     OBContext.setAdminMode(true);
     try {
       FIN_Reconciliation reconciliation = MatchTransactionDao.getObject(FIN_Reconciliation.class,
@@ -343,12 +322,6 @@
     return true;
   }
 
-  private boolean isInArray(String inString, String value) {
-    if (inString.indexOf(value) == -1)
-      return false;
-    return true;
-  }
-
   private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strOrgId,
       String strWindowId, String strTabId, String strPaymentTypeFilter,
       String strFinancialAccountId, String reconciliationId, String strShowCleared,
@@ -437,8 +410,10 @@
     FieldProvider[] data = null;
     try {
       OBContext.setAdminMode(true);
+      // long init = System.currentTimeMillis();
       data = getMatchedBankStatementLinesData(vars, strFinancialAccountId, strReconciliationId,
           strPaymentTypeFilter, strShowCleared, strHideDate, executeMatching);
+      // log4j.error("Getting Grid Data: " + (System.currentTimeMillis() - init));
     } catch (Exception e) {
       log4j.debug("Output: Exception ocurred while retrieving Bank Statement Lines.", e);
       e.printStackTrace();
@@ -456,9 +431,11 @@
       log4j.debug("JSON object error" + table.toString());
     }
     response.setContentType("text/html; charset=UTF-8");
+    // long init = System.currentTimeMillis();
     PrintWriter out = response.getWriter();
     out.println("data = " + table.toString());
     out.close();
+    // log4j.error("Printing Grid Data: " + (System.currentTimeMillis() - init));
   }
 
   private void unMatchBankStatementLine(HttpServletResponse response,
@@ -493,15 +470,16 @@
         strFinancialAccountId);
     MatchingAlgorithm ma = financial.getMatchingAlgorithm();
     FIN_MatchingTransaction matchingTransaction = new FIN_MatchingTransaction(ma.getJavaClassName());
-
+    // long init = System.currentTimeMillis();
     List<FIN_BankStatementLine> bankLines = MatchTransactionDao.getMatchingBankStatementLines(
         strFinancialAccountId, strReconciliationId, strPaymentTypeFilter, strShowCleared);
+    // log4j.error("Getting bankLines took: " + (System.currentTimeMillis() - init));
     FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class,
         strReconciliationId);
     FIN_BankStatementLine[] FIN_BankStatementLines = new FIN_BankStatementLine[0];
     FIN_BankStatementLines = bankLines.toArray(FIN_BankStatementLines);
     FieldProvider[] data = FieldProviderFactory.getFieldProviderArray(bankLines);
-
+    // init = System.currentTimeMillis();
     OBContext.setAdminMode();
     final String MATCHED_AGAINST_TRANSACTION = FIN_Utility.messageBD("APRM_Transaction");
     final String MATCHED_AGAINST_PAYMENT = FIN_Utility.messageBD("APRM_Payment");
@@ -510,6 +488,7 @@
     final String MATCHED_AGAINST_CREDIT = FIN_Utility.messageBD("APRM_Credit");
     try {
       List<FIN_FinaccTransaction> excluded = new ArrayList<FIN_FinaccTransaction>();
+      long initMatch = 0l;
       for (int i = 0; i < data.length; i++) {
         final String COLOR_STRONG = "#66CC00";
         final String COLOR_WEAK = "#99CC66";
@@ -521,49 +500,41 @@
 
         String matchingType = line.getMatchingtype();
         FIN_FinaccTransaction transaction = line.getFinancialAccountTransaction();
-        if (transaction == null && executeMatching) {
+        if (transaction == null) {
           FIN_MatchedTransaction matched = null;
-          // try to match if exception is thrown continue
-          try {
-            matched = matchingTransaction.match(line, excluded);
-            OBDal.getInstance().getConnection().commit();
-          } catch (Exception e) {
-            OBDal.getInstance().rollbackAndClose();
+          if (executeMatching) {
+            // try to match if exception is thrown continue
+            try {
+              long initMatchLine = System.currentTimeMillis();
+              matched = matchingTransaction.match(line, excluded);
+              initMatch = initMatch + (System.currentTimeMillis() - initMatchLine);
+              OBDal.getInstance().getConnection().commit();
+            } catch (Exception e) {
+              OBDal.getInstance().rollbackAndClose();
+              line = OBDal.getInstance().get(FIN_BankStatementLine.class,
+                  FIN_BankStatementLines[i].getId());
+              matchingType = line.getMatchingtype();
+              transaction = line.getFinancialAccountTransaction();
+              matched = new FIN_MatchedTransaction(null, FIN_MatchedTransaction.NOMATCH);
+            }
+          } else {
             matched = new FIN_MatchedTransaction(null, FIN_MatchedTransaction.NOMATCH);
           }
+          transaction = matched.getTransaction();
+          if (transaction != null) {
+            matchBankStatementLine(line.getId(), transaction.getId(), strReconciliationId,
+                matched.getMatchLevel());
+          }
           // When hide flag checked then exclude matchings for transactions out of date range
           if ("Y".equals(strHideDate)
               && matched.getTransaction() != null
               && matched.getTransaction().getTransactionDate()
                   .compareTo(reconciliation.getEndingDate()) > 0) {
+            transaction = null;
             matched = new FIN_MatchedTransaction(null, FIN_MatchedTransaction.NOMATCH);
-          }
-          transaction = matched.getTransaction();
-          if (transaction != null && FIN_MatchedTransaction.STRONG.equals(matched.getMatchLevel())) {
-            FIN_BankStatementLine bsl = line;
-            if (bsl.getFinancialAccountTransaction() != null) {
-              // Unmatch Transaction
-              FIN_FinaccTransaction oldTransaction = bsl.getFinancialAccountTransaction();
-              final String DEPOSITED_NOT_CLEARED = "RDNC";
-              final String WITHDRAWN_NOT_CLEARED = "PWNC";
-              oldTransaction
-                  .setStatus(oldTransaction.getDepositAmount()
-                      .subtract(oldTransaction.getPaymentAmount()).signum() == 1 ? DEPOSITED_NOT_CLEARED
-                      : WITHDRAWN_NOT_CLEARED);
-              oldTransaction.setReconciliation(null);
-              OBDal.getInstance().save(oldTransaction);
-            }
-            bsl.setFinancialAccountTransaction(transaction);
-            bsl.setMatchingtype(matched.getMatchLevel());
-            transaction.setStatus("RPPC");
-            transaction.setReconciliation(MatchTransactionDao.getObject(FIN_Reconciliation.class,
-                strReconciliationId));
-            if (transaction.getFinPayment() != null) {
-              transaction.getFinPayment().setStatus("RPPC");
-            }
-            OBDal.getInstance().save(transaction);
-            OBDal.getInstance().save(bsl);
-            OBDal.getInstance().flush();
+            unmatch(line);
+            line = OBDal.getInstance().get(FIN_BankStatementLine.class,
+                FIN_BankStatementLines[i].getId());
           }
           if (transaction != null) {
             excluded.add(transaction);
@@ -608,8 +579,9 @@
         if (transaction != null) {
           FieldProviderFactory.setField(data[i], "disabled", "N");
           // Auto Matching or already matched
-          FieldProviderFactory.setField(data[i], "checked",
-              FIN_MatchedTransaction.STRONG.equals(matchingType) || alreadyMatched ? "Y" : "N");
+          // FieldProviderFactory.setField(data[i], "checked",
+          // FIN_MatchedTransaction.STRONG.equals(matchingType) || alreadyMatched ? "Y" : "N");
+          FieldProviderFactory.setField(data[i], "checked", "Y");
           FieldProviderFactory.setField(data[i], "finTransactionId", transaction.getId());
           FieldProviderFactory.setField(data[i], "trxDescription", transaction.getDescription());
           FieldProviderFactory
@@ -662,9 +634,11 @@
           FieldProviderFactory.setField(data[i], "transactionAmount", "");
         }
       }
+      log4j.error("matching took: " + initMatch);
     } finally {
       OBContext.restorePreviousMode();
     }
+    // log4j.error("Getting fieldprovider took: " + (System.currentTimeMillis() - init));
     return data;
   }
 
@@ -704,8 +678,9 @@
   }
 
   private void getSnapShot(FIN_Reconciliation reconciliation) {
-    if (reconciliation == null)
+    if (reconciliation == null) {
       return;
+    }
     OBContext.setAdminMode();
     try {
       // First remove old temp info if exists
@@ -804,21 +779,29 @@
   private void unmatch(FIN_BankStatementLine bsline) {
     OBContext.setAdminMode();
     try {
-      // merge if the bank statement line was splited before
+      bsline = OBDal.getInstance().get(FIN_BankStatementLine.class, bsline.getId());
+      // merge if the bank statement line was split before
       mergeBankStatementLine(bsline);
 
       FIN_FinaccTransaction finTrans = bsline.getFinancialAccountTransaction();
+      if (finTrans == null) {
+        String strTransactionId = vars.getStringParameter("inpFinancialTransactionId_"
+            + bsline.getId());
+        if (strTransactionId != null && !"".equals(strTransactionId)) {
+          finTrans = OBDal.getInstance().get(FIN_FinaccTransaction.class, strTransactionId);
+        }
+      }
       if (finTrans != null) {
         finTrans.setReconciliation(null);
         finTrans.setStatus((finTrans.getDepositAmount().subtract(finTrans.getPaymentAmount())
             .signum() == 1) ? "RDNC" : "PWNC");
         bsline.setFinancialAccountTransaction(null);
         OBDal.getInstance().save(finTrans);
-        OBDal.getInstance().flush();
+        // OBDal.getInstance().flush();
       }
       bsline.setMatchingtype(null);
       OBDal.getInstance().save(bsline);
-      OBDal.getInstance().flush();
+      // OBDal.getInstance().flush();
 
       if (finTrans != null) {
         if (finTrans.getFinPayment() != null) {
@@ -834,7 +817,7 @@
         finTrans.setStatus(isReceipt ? "RDNC" : "PWNC");
         finTrans.setReconciliation(null);
         OBDal.getInstance().save(finTrans);
-        OBDal.getInstance().flush();
+        // OBDal.getInstance().flush();
       }
       // Execute un-matching logic defined by algorithm
       MatchingAlgorithm ma = bsline.getBankStatement().getAccount().getMatchingAlgorithm();
@@ -855,7 +838,7 @@
         OBDal.getInstance().save(bs);
         OBDal.getInstance().flush();
       }
-
+      OBDal.getInstance().getConnection().commit();
     } catch (Exception e) {
       throw new OBException(e);
     } finally {
@@ -1293,4 +1276,53 @@
   public String getServletInfo() {
     return "This servlet match imported bank statement lines for a financial account";
   }
+
+  void matchBankStatementLine(String strFinBankStatementLineId, String strFinancialTransactionId,
+      String strReconciliationId, String matchLevel) {
+    OBContext.setAdminMode(false);
+    try {
+      FIN_BankStatementLine bsl = OBDal.getInstance().get(FIN_BankStatementLine.class,
+          strFinBankStatementLineId);
+      // OBDal.getInstance().getSession().buildLockRequest(LockOptions.NONE)
+      // .lock(BankStatementLine.ENTITY_NAME, bsl);
+      FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class,
+          strFinancialTransactionId);
+      if (transaction != null) {
+        if (bsl.getFinancialAccountTransaction() != null) {
+          log4j.error("Bank Statement Line Already Matched: " + bsl.getIdentifier());
+          unmatch(bsl);
+        }
+        bsl.setFinancialAccountTransaction(transaction);
+        if (matchLevel == null || "".equals(matchLevel)) {
+          matchLevel = FIN_MatchedTransaction.MANUALMATCH;
+        }
+        bsl.setMatchingtype(matchLevel);
+        transaction.setStatus("RPPC");
+        transaction.setReconciliation(MatchTransactionDao.getObject(FIN_Reconciliation.class,
+            strReconciliationId));
+        if (transaction.getFinPayment() != null) {
+          transaction.getFinPayment().setStatus("RPPC");
+        }
+        OBDal.getInstance().save(transaction);
+        OBDal.getInstance().save(bsl);
+        OBDal.getInstance().flush();
+        OBDal.getInstance().getConnection().commit();
+      }
+    } catch (Exception e) {
+      log4j.error("Error during matchBankStatementLine");
+      OBDal.getInstance().rollbackAndClose();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private void wait(String strReconciliationId) {
+    while (runingReconciliations.contains(strReconciliationId)) {
+      long t0, t1;
+      t0 = System.currentTimeMillis();
+      do {
+        t1 = System.currentTimeMillis();
+      } while ((t1 - t0) < 200);
+    }
+  }
 }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransactionGrid.srpt	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransactionGrid.srpt	Fri Jul 05 18:29:54 2013 +0200
@@ -27,15 +27,15 @@
     <td class="DataGrid_Body_Cell"><span id="fieldBLReferenceNo">xx11100011</span></td>
     <td class="DataGrid_Body_Cell_Amount"><span id="fieldAmount">xx12233</span></td>
     <td class="DataGrid_Body_LineNoCell" style="background-color: xx; text-align: center;" id="inpMatchStyle_xx" name="inpMatchStyle_xx">
-      <a href="#" onClick="openSelector('xx');" id="fieldFindLink"><img src="../../../../../web/org.openbravo.advpaymentmngt/images/view.png" style="border-style: none"/></a>
+      <a href="#" onClick="openSelector('xx');" id="fieldFindLink" name="fieldFindLink"><img src="../../../../../web/org.openbravo.advpaymentmngt/images/view.png" style="border-style: none"/></a>
       <!--span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span-->
       <input id="inpCheckBox_xx" type="checkbox" name="inpBankStatementLineId" value="" onclick="unMatchLine('xx', this.checked); "/>
       <input type="hidden" name="inpFinancialTransactionId_xx" id="inpFinancialTransactionId_xx" value=""></input>
       <input type="hidden" name="inpMatchingType_xx" id="inpMatchingType_xx" value=""></input>
       <!--span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span-->
-      <a href="#" onclick="openAddTransaction('xx');" id="fieldAddLink"><img src="../../../../../web/org.openbravo.advpaymentmngt/images/add.png" style="border-style: none"/></a>
+      <a href="#" onclick="openAddTransaction('xx');" id="fieldAddLink" name="fieldAddLink"><img src="../../../../../web/org.openbravo.advpaymentmngt/images/add.png" style="border-style: none"/></a>
     </td>
-    <td class="DataGrid_Body_Cell" id="inpMatchedDocument_xx">xxTransaction</td>
+    <td class="DataGrid_Body_Cell" id="inpMatchedDocument_xx" title="">xxTransaction</td>
     <td class="DataGrid_Body_Cell" id="inpTransactionDate_xx" title="">xx01-01-2010</td>
     <td class="DataGrid_Body_Cell" id="inpBPartner_xx" title="">xxBP Name</td>
     <td class="DataGrid_Body_Cell" id="inpReferenceNo_xx" title="">xx111999111</td>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransactionGrid.xml	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransactionGrid.xml	Fri Jul 05 18:29:54 2013 +0200
@@ -57,6 +57,7 @@
     <FIELD id="inpTransactionDate_xx" attribute="id" replace="xx">finBankLineId</FIELD>
     <FIELD id="inpMatchedDocument_xx">matchedDocument</FIELD>
     <FIELD id="inpMatchedDocument_xx" attribute="id" replace="xx">finBankLineId</FIELD>
+    <FIELD id="inpMatchedDocument_xx" attribute="title">trxDescription</FIELD>
     <FIELD id="inpBPartner_xx">transactionBPartner</FIELD>
     <FIELD id="inpBPartner_xx" attribute="title">trxDescription</FIELD>
     <FIELD id="inpBPartner_xx" attribute="id" replace="xx">finBankLineId</FIELD>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Fri Jul 05 18:29:54 2013 +0200
@@ -94,6 +94,9 @@
             payment.setStatus(payment.isReceipt() ? "RDNC" : "PWNC");
             transaction.setStatus(payment.isReceipt() ? "RDNC" : "PWNC");
             OBDal.getInstance().save(payment);
+            if (transaction.getDescription() == null || "".equals(transaction.getDescription())) {
+              transaction.setDescription(payment.getDescription());
+            }
           } else {
             transaction.setStatus(transaction.getDepositAmount().compareTo(
                 transaction.getPaymentAmount()) > 0 ? "RDNC" : "PWNC");
@@ -161,8 +164,8 @@
           }
           OBDal.getInstance().save(transaction);
           OBDal.getInstance().flush();
-          bundle.setResult(msg);
         }
+        bundle.setResult(msg);
       } finally {
         OBContext.restorePreviousMode();
       }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java	Thu Jul 04 17:38:00 2013 +0530
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java	Fri Jul 05 18:29:54 2013 +0200
@@ -30,6 +30,7 @@
 
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
@@ -58,6 +59,7 @@
   private FIN_FinancialAccount financialAccount;
   OBError myError = null;
   String filename = "";
+  private static Logger log4j = Logger.getLogger(FIN_BankStatementImport.class);
 
   public static final String DOCUMENT_BankStatementFile = "BSF";
 
@@ -173,6 +175,7 @@
       setMyError(processResult);
     } catch (Exception e) {
       OBDal.getInstance().rollbackAndClose();
+      log4j.error("Error importing file.", e);
       return getMyError();
     }
     if (getMyError() != null && !getMyError().getType().toLowerCase().equals("success")
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Thu Jul 04 17:38:00 2013 +0530
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Fri Jul 05 18:29:54 2013 +0200
@@ -90722,7 +90722,7 @@
 <!--6497-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--6497-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
 <!--6497-->  <ISUPDATEABLE><![CDATA[N]]></ISUPDATEABLE>
-<!--6497-->  <ISIDENTIFIER><![CDATA[Y]]></ISIDENTIFIER>
+<!--6497-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
 <!--6497-->  <SEQNO><![CDATA[1]]></SEQNO>
 <!--6497-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--6497-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -91078,7 +91078,7 @@
 <!--6507-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--6507-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
 <!--6507-->  <ISUPDATEABLE><![CDATA[N]]></ISUPDATEABLE>
-<!--6507-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--6507-->  <ISIDENTIFIER><![CDATA[Y]]></ISIDENTIFIER>
 <!--6507-->  <SEQNO><![CDATA[0]]></SEQNO>
 <!--6507-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--6507-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -91113,7 +91113,7 @@
 <!--6508-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--6508-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
 <!--6508-->  <ISUPDATEABLE><![CDATA[N]]></ISUPDATEABLE>
-<!--6508-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--6508-->  <ISIDENTIFIER><![CDATA[Y]]></ISIDENTIFIER>
 <!--6508-->  <SEQNO><![CDATA[0]]></SEQNO>
 <!--6508-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--6508-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -91787,7 +91787,7 @@
 <!--6529-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--6529-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
 <!--6529-->  <ISUPDATEABLE><![CDATA[N]]></ISUPDATEABLE>
-<!--6529-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--6529-->  <ISIDENTIFIER><![CDATA[Y]]></ISIDENTIFIER>
 <!--6529-->  <SEQNO><![CDATA[0]]></SEQNO>
 <!--6529-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--6529-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
--- a/src-db/database/sourcedata/AD_REFERENCE.xml	Thu Jul 04 17:38:00 2013 +0530
+++ b/src-db/database/sourcedata/AD_REFERENCE.xml	Fri Jul 05 18:29:54 2013 +0200
@@ -4671,6 +4671,18 @@
 <!--4028E61131FB4B1B0131FB5226C90008-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
 <!--4028E61131FB4B1B0131FB5226C90008--></AD_REFERENCE>
 
+<!--40B84CF78FC9435790887846CCDAE875--><AD_REFERENCE>
+<!--40B84CF78FC9435790887846CCDAE875-->  <AD_REFERENCE_ID><![CDATA[40B84CF78FC9435790887846CCDAE875]]></AD_REFERENCE_ID>
+<!--40B84CF78FC9435790887846CCDAE875-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--40B84CF78FC9435790887846CCDAE875-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--40B84CF78FC9435790887846CCDAE875-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--40B84CF78FC9435790887846CCDAE875-->  <NAME><![CDATA[Add Transaction Document Type]]></NAME>
+<!--40B84CF78FC9435790887846CCDAE875-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--40B84CF78FC9435790887846CCDAE875-->  <ISBASEREFERENCE><![CDATA[N]]></ISBASEREFERENCE>
+<!--40B84CF78FC9435790887846CCDAE875-->  <PARENTREFERENCE_ID><![CDATA[17]]></PARENTREFERENCE_ID>
+<!--40B84CF78FC9435790887846CCDAE875-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
+<!--40B84CF78FC9435790887846CCDAE875--></AD_REFERENCE>
+
 <!--439F775E24BF48EDA51A7AE2535F0DCE--><AD_REFERENCE>
 <!--439F775E24BF48EDA51A7AE2535F0DCE-->  <AD_REFERENCE_ID><![CDATA[439F775E24BF48EDA51A7AE2535F0DCE]]></AD_REFERENCE_ID>
 <!--439F775E24BF48EDA51A7AE2535F0DCE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Thu Jul 04 17:38:00 2013 +0530
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Fri Jul 05 18:29:54 2013 +0200
@@ -10692,6 +10692,17 @@
 <!--A60D08A595E84734A6369720E2BFE84F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--A60D08A595E84734A6369720E2BFE84F--></AD_REF_LIST>
 
+<!--A68E543C89BE4174990D33DFBAD90E05--><AD_REF_LIST>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_REF_LIST_ID><![CDATA[A68E543C89BE4174990D33DFBAD90E05]]></AD_REF_LIST_ID>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <VALUE><![CDATA[RCIN]]></VALUE>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <NAME><![CDATA[Received IN]]></NAME>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_REFERENCE_ID><![CDATA[40B84CF78FC9435790887846CCDAE875]]></AD_REFERENCE_ID>
+<!--A68E543C89BE4174990D33DFBAD90E05-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--A68E543C89BE4174990D33DFBAD90E05--></AD_REF_LIST>
+
 <!--A6F23B8BC2CA497A80FD6ABFDD3AEE93--><AD_REF_LIST>
 <!--A6F23B8BC2CA497A80FD6ABFDD3AEE93-->  <AD_REF_LIST_ID><![CDATA[A6F23B8BC2CA497A80FD6ABFDD3AEE93]]></AD_REF_LIST_ID>
 <!--A6F23B8BC2CA497A80FD6ABFDD3AEE93-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -12165,6 +12176,17 @@
 <!--F909149B2018465DA19A11D9F9AC9ABD-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--F909149B2018465DA19A11D9F9AC9ABD--></AD_REF_LIST>
 
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC--><AD_REF_LIST>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <AD_REF_LIST_ID><![CDATA[FA4EB912DC0F4A0B80179B78DA09B7AC]]></AD_REF_LIST_ID>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <VALUE><![CDATA[PDOUT]]></VALUE>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <NAME><![CDATA[Paid OUT]]></NAME>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <AD_REFERENCE_ID><![CDATA[40B84CF78FC9435790887846CCDAE875]]></AD_REFERENCE_ID>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--FA4EB912DC0F4A0B80179B78DA09B7AC--></AD_REF_LIST>
+
 <!--FA50DEFEDC4E4EFE82BA5BF71C55E53F--><AD_REF_LIST>
 <!--FA50DEFEDC4E4EFE82BA5BF71C55E53F-->  <AD_REF_LIST_ID><![CDATA[FA50DEFEDC4E4EFE82BA5BF71C55E53F]]></AD_REF_LIST_ID>
 <!--FA50DEFEDC4E4EFE82BA5BF71C55E53F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/businessUtility/MessageJS.java	Thu Jul 04 17:38:00 2013 +0530
+++ b/src/org/openbravo/erpCommon/businessUtility/MessageJS.java	Fri Jul 05 18:29:54 2013 +0200
@@ -26,6 +26,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.erpCommon.utility.Utility;
@@ -39,11 +41,25 @@
     final VariablesSecureApp vars = new VariablesSecureApp(request);
 
     final String strValue = vars.getRequiredStringParameter("inpvalue");
-    printPage(response, vars, strValue);
+    final String strParams = vars.getStringParameter("inpparams", "");
+    JSONArray array = null;
+    try {
+      try {
+        array = new JSONArray(strParams);
+      } catch (JSONException e) {
+        // As parameters may come empty most of the times we silent by sending empty parameter
+        // JSONArray. Message will never be hidden as no exception will be raised.
+        array = new JSONArray();
+      }
+      printPage(response, vars, strValue, array);
+    } catch (JSONException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
   }
 
-  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strValue)
-      throws IOException, ServletException {
+  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strValue,
+      JSONArray array) throws IOException, ServletException, JSONException {
 
     String type = "Hidden";
     String title = "";
@@ -63,7 +79,11 @@
       type = (data[0].msgtype.equals("E") ? "Error" : (data[0].msgtype.equals("I") ? "Info"
           : (data[0].msgtype.equals("S") ? "Success" : "Warning")));
       title = Utility.messageBD(this, type, strLanguage);
-      description = "<![CDATA[" + data[0].msgtext + "]]>";
+      String msgtext = data[0].msgtext;
+      for (int i = 0; i < array.length(); i++) {
+        msgtext = String.format(msgtext, (String) array.get(i));
+      }
+      description = "<![CDATA[" + msgtext + "]]>";
     }
 
     response.setContentType("text/xml; charset=UTF-8");
--- a/web/js/messages.js	Thu Jul 04 17:38:00 2013 +0530
+++ b/web/js/messages.js	Fri Jul 05 18:29:54 2013 +0200
@@ -140,7 +140,7 @@
 	showJSMessage(index, _language);
 }
 
-function showJSMessage(index, _language, clean)
+function showJSMessage(index, _language, clean, params)
 {
   var clearMsgBox = typeof clean == 'undefined' || clean == null ? true : clean;
   if(clearMsgBox) {
@@ -151,7 +151,7 @@
 	var strMessage = getMessage(index, _language);
   if (strMessage == null)  strMessage = getMessage(index, "en_US");
 	if (strMessage == null) {
-    getDataBaseMessage(index);
+    getDataBaseMessage(index, null, params);
     return true;
   }
 	var strDefault = getDefaultText(index, _language);
@@ -184,7 +184,7 @@
   return url;
 }
 
-function getDataBaseMessage(value, responseFunction) {
+function getDataBaseMessage(value, responseFunction, params) {
   var appUrl = getAppUrl();
   var paramXMLReq = null;
   var msgCode;
@@ -193,7 +193,7 @@
   } else {
     msgCode = value;
   }
-  submitXmlHttpRequestUrl(((responseFunction==null)?messageResponse:responseFunction), (appUrl + "/businessUtility/MessageJS.html?inpvalue=" + escape(msgCode)), false, paramXMLReq)
+  submitXmlHttpRequestUrl(((responseFunction==null)?messageResponse:responseFunction), (appUrl + "/businessUtility/MessageJS.html?inpvalue=" + escape(msgCode) + "&inpparams=" + escape(isc.JSONEncoder.echo(params))), false, paramXMLReq)
 }
 
 function getDataBaseStandardMessage(value, responseFunction) {