Fixed issue 21415 Ability to define a write-off limit
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Fri, 14 Sep 2012 20:14:05 +0200
changeset 17959 f7657cc77788
parent 17958 3fec9dfdd735
child 17960 1922c7ff8ac1
Fixed issue 21415 Ability to define a write-off limit
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.xml
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.html
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.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/AddPaymentFromTransaction.xml
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/FIN_Utilities.js
src-db/database/model/tables/FIN_FINANCIAL_ACCOUNT.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_ELEMENT.xml
src-db/database/sourcedata/AD_FIELD.xml
src-db/database/sourcedata/AD_REFERENCE.xml
src-db/database/sourcedata/AD_REF_LIST.xml
src/org/openbravo/erpCommon/ad_callouts/SE_Payment_MultiCurrency.java
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -407,6 +407,17 @@
 <!--3E2658BC7DB84BA5927989BB52FD1BF0-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--3E2658BC7DB84BA5927989BB52FD1BF0--></AD_TEXTINTERFACES>
 
+<!--3ED793E7D0FE4C098FE79C589C292B6E--><AD_TEXTINTERFACES>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <AD_TEXTINTERFACES_ID><![CDATA[3ED793E7D0FE4C098FE79C589C292B6E]]></AD_TEXTINTERFACES_ID>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <TEXT><![CDATA[Write off the difference (Above limit)]]></TEXT>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html]]></FILENAME>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--3ED793E7D0FE4C098FE79C589C292B6E-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--3ED793E7D0FE4C098FE79C589C292B6E--></AD_TEXTINTERFACES>
+
 <!--3F26CEA4A0D9445EBC5B92785185D207--><AD_TEXTINTERFACES>
 <!--3F26CEA4A0D9445EBC5B92785185D207-->  <AD_TEXTINTERFACES_ID><![CDATA[3F26CEA4A0D9445EBC5B92785185D207]]></AD_TEXTINTERFACES_ID>
 <!--3F26CEA4A0D9445EBC5B92785185D207-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -869,6 +880,17 @@
 <!--745D4AD864BB431BB56352040E0E9C84-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--745D4AD864BB431BB56352040E0E9C84--></AD_TEXTINTERFACES>
 
+<!--753CC44B776D4A55901CAD9D92D458AE--><AD_TEXTINTERFACES>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <AD_TEXTINTERFACES_ID><![CDATA[753CC44B776D4A55901CAD9D92D458AE]]></AD_TEXTINTERFACES_ID>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <TEXT><![CDATA[Write off the difference (Above limit)]]></TEXT>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--753CC44B776D4A55901CAD9D92D458AE-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--753CC44B776D4A55901CAD9D92D458AE--></AD_TEXTINTERFACES>
+
 <!--756D726BEF3D402985AAD12657C5898D--><AD_TEXTINTERFACES>
 <!--756D726BEF3D402985AAD12657C5898D-->  <AD_TEXTINTERFACES_ID><![CDATA[756D726BEF3D402985AAD12657C5898D]]></AD_TEXTINTERFACES_ID>
 <!--756D726BEF3D402985AAD12657C5898D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -2871,4 +2893,15 @@
 <!--FDC49CBE576447578B4648FB57C3C89C-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--FDC49CBE576447578B4648FB57C3C89C--></AD_TEXTINTERFACES>
 
+<!--FE926BB57B7C496CB4859FC079AFA1BA--><AD_TEXTINTERFACES>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <AD_TEXTINTERFACES_ID><![CDATA[FE926BB57B7C496CB4859FC079AFA1BA]]></AD_TEXTINTERFACES_ID>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <TEXT><![CDATA[Write off the difference (Above limit)]]></TEXT>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.html]]></FILENAME>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--FE926BB57B7C496CB4859FC079AFA1BA-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--FE926BB57B7C496CB4859FC079AFA1BA--></AD_TEXTINTERFACES>
+
 </data>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html	Fri Sep 14 20:14:05 2012 +0200
@@ -707,6 +707,10 @@
   <input type="hidden" name="strElement_SR" id="paramStrElement_SR" value=""/>
   <input type="hidden" name="strElement_MC" id="paramStrElement_MC" value=""/>
   <input type="hidden" name="strNotAllowExchange" id="paramStrNotAllowExchange" value=""/>
+  <input type="hidden" name="strWriteOffLimit" id="paramStrWriteOffLimit" value=""/>
+  <input type="hidden" name="strtypewriteoff" id="paramStrtypewriteoff" value=""/>
+  <input type="hidden" name="strAmountwriteoff" id="paramStrAmountwriteoff" value=""/>
+  
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
       <img class="Popup_WindowLogo_Icon Popup_WindowLogo_Icon_process" src="../../../../../web/images/blank.gif" border=0/></img>
@@ -1478,6 +1482,12 @@
                             </td>
                             <td><span class="LabelText">Write off the difference</span></td>
                           </tr>
+                           <tr id="writeofflimit">
+                            <td class="Radio_Check_ContentCell" >
+                              <input type="radio" name="inpDifferenceAction" value="writeofflimit" id="radiolimit" DISABLED/>
+                            </td>
+                            <td><span class="LabelText">Write off the difference (Above limit)</span></td>
+                          </tr>       
                         </table>
                       </td>
                     </tr>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java	Fri Sep 14 20:14:05 2012 +0200
@@ -60,6 +60,7 @@
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.financialmgmt.gl.GLItem;
+import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
@@ -84,8 +85,9 @@
       String strTabId = vars.getGlobalVariable("inpTabId", "AddOrderOrInvoice|Tab_ID");
       String strPaymentId = vars.getGlobalVariable("inpfinPaymentId", strWindowId + "|"
           + "FIN_Payment_ID");
+      String strFinancialAccountId = vars.getStringParameter("inpfinFinancialAccountId");
 
-      printPage(response, vars, strPaymentId, strWindowId, strTabId);
+      printPage(response, vars, strPaymentId, strWindowId, strTabId, strFinancialAccountId);
 
     } else if (vars.commandIn("GRIDLIST")) {
       String strBusinessPartnerId = vars.getRequestGlobalVariable("inpBusinessPartnerId", "");
@@ -337,8 +339,8 @@
   }
 
   private void printPage(HttpServletResponse response, VariablesSecureApp vars,
-      String strPaymentId, String strWindowId, String strTabId) throws IOException,
-      ServletException {
+      String strPaymentId, String strWindowId, String strTabId, String strFinancialAccountId)
+      throws IOException, ServletException {
     log4j.debug("Output: Add Payment button pressed on Make / Receipt Payment windows");
 
     FIN_Payment payment = new AdvPaymentMngtDao().getObject(FIN_Payment.class, strPaymentId);
@@ -522,6 +524,24 @@
         strWindowId);
     xmlDocument.setParameter("strNotAllowExchange", strNotAllowExchange);
 
+    dao = new AdvPaymentMngtDao();
+    FIN_FinancialAccount financialAccount = dao.getObject(FIN_FinancialAccount.class,
+        strFinancialAccountId);
+
+    if (financialAccount.getWriteofflimit() != null) {
+      final String strtypewriteoff;
+      final String strAmountwriteoff;
+
+      strtypewriteoff = financialAccount.getTypewriteoff();
+      strAmountwriteoff = financialAccount.getWriteofflimit().toString();
+      xmlDocument.setParameter("strtypewriteoff", strtypewriteoff);
+      xmlDocument.setParameter("strAmountwriteoff", strAmountwriteoff);
+
+      // Not allow to write off
+      final String strWriteOffLimit = Utility.getContext(this, vars, "WriteOffLimitPreference",
+          strWindowId);
+      xmlDocument.setParameter("strWriteOffLimit", strWriteOffLimit);
+    }
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(xmlDocument.print());
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -75,6 +75,12 @@
     
      <!-- Not allow to change exchange rate and amount -->
     <PARAMETER id="paramStrNotAllowExchange" name="strNotAllowExchange" attribute="value"/>
+    
+    <!-- Not allow to change Write Off-->
+    <PARAMETER id="paramStrWriteOffLimit" name="strWriteOffLimit" attribute="value"/>
+    <PARAMETER id="paramStrtypewriteoff" name="strtypewriteoff" attribute="value"/>
+    <PARAMETER id="paramStrAmountwriteoff" name="strAmountwriteoff" attribute="value"/>
+    
 
     <DISCARD id="discard"/>
 </REPORT>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.html	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.html	Fri Sep 14 20:14:05 2012 +0200
@@ -379,6 +379,15 @@
         } else {
           document.getElementById('paramExchangeRate').value = '';
         }
+        if (resp.twriteoff) {
+            document.getElementById('paramStrtypewriteoff').value = applyFormatJSToOBMasked(resp.twriteoff, resp.formatOutput);
+            document.getElementById('paramStrAmountwriteoff').value = applyFormatJSToOBMasked(resp.awriteoff, resp.formatOutput);
+        }
+        else{
+        	document.getElementById('paramStrtypewriteoff').value = '';
+            document.getElementById('paramStrAmountwriteoff').value = '';
+        }
+        updateDifference();
       }
       displayMulticurrencyControls();
       updateConvertedAmounts();
@@ -433,6 +442,7 @@
     displayLogicElement('paramUseCreditContainer', hasCredit );
     displayLogicElement('rowCredit', hasCredit );
     displayMulticurrencyControls();
+    
     if (isTrue('isReceipt')) {
         setWindowElementFocus(frm.inpActualPayment);
     } else {
@@ -460,6 +470,9 @@
   <input type="hidden" name="isReceipt" value="" id="fieldReceipt"/>
   <input type="hidden" name="isFirstLoad" value="true"/>
   <input type="hidden" name="strNotAllowExchange" id="paramStrNotAllowExchange" value=""/>
+  <input type="hidden" name="strWriteOffLimit" id="paramStrWriteOffLimit" value=""/>
+  <input type="hidden" name="strtypewriteoff" id="paramStrtypewriteoff" value=""/>
+  <input type="hidden" name="strAmountwriteoff" id="paramStrAmountwriteoff" value=""/>
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
       <img class="Popup_WindowLogo_Icon Popup_WindowLogo_Icon_process" src="../../../../../web/images/blank.gif" border=0/></img>
@@ -1108,6 +1121,12 @@
                             </td>
                             <td><span class="LabelText">Write off the difference</span></td>
                           </tr>
+                          <tr id="writeofflimit">
+                            <td class="Radio_Check_ContentCell" >
+                              <input type="radio" name="inpDifferenceAction" value="writeofflimit" id="radiolimit" DISABLED/>
+                            </td>
+                            <td><span class="LabelText">Write off the difference (Above limit)</span></td>
+                          </tr>
                         </table>
                       </td>
                     </tr>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java	Fri Sep 14 20:14:05 2012 +0200
@@ -357,11 +357,35 @@
     }
     xmlDocument.setParameter("sectionDetailFinancialAccount", finAccountComboHtml);
 
+    final String strtypewriteoff;
+    final String strAmountwriteoff;
     if (account != null) {
       if (!financialAccounts.contains(account)) {
         strFinancialAccountId = financialAccounts.get(0).getId();
+        if (financialAccounts.get(0).getWriteofflimit() != null) {
+          strtypewriteoff = financialAccounts.get(0).getTypewriteoff();
+          strAmountwriteoff = financialAccounts.get(0).getWriteofflimit().toString();
+          xmlDocument.setParameter("strtypewriteoff", strtypewriteoff);
+          xmlDocument.setParameter("strAmountwriteoff", strAmountwriteoff);
+        }
+
+      } else {
+        if (account.getWriteofflimit() != null) {
+          strtypewriteoff = account.getTypewriteoff();
+          strAmountwriteoff = account.getWriteofflimit().toString();
+          xmlDocument.setParameter("strtypewriteoff", strtypewriteoff);
+          xmlDocument.setParameter("strAmountwriteoff", strAmountwriteoff);
+        }
+      }
+    } else {
+      if (financialAccounts.get(0).getWriteofflimit() != null) {
+        strtypewriteoff = financialAccounts.get(0).getTypewriteoff();
+        strAmountwriteoff = financialAccounts.get(0).getWriteofflimit().toString();
+        xmlDocument.setParameter("strtypewriteoff", strtypewriteoff);
+        xmlDocument.setParameter("strAmountwriteoff", strAmountwriteoff);
       }
     }
+
     // Currency
     xmlDocument.setParameter("CurrencyId", strCurrencyId);
     final Currency paymentCurrency = dao.getObject(Currency.class, strCurrencyId);
@@ -419,6 +443,11 @@
         strWindowId);
     xmlDocument.setParameter("strNotAllowExchange", strNotAllowExchange);
 
+    // Not allow to write off
+    final String strWriteOffLimit = Utility.getContext(this, vars, "WriteOffLimitPreference",
+        strWindowId);
+    xmlDocument.setParameter("strWriteOffLimit", strWriteOffLimit);
+
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(xmlDocument.print());
@@ -477,8 +506,8 @@
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(paymentMethodComboHtml.replaceAll("\"", "\\'"));
+
     out.close();
-
   }
 
   private void refreshFinancialAccountCombo(HttpServletResponse response, VariablesSecureApp vars,
@@ -502,8 +531,15 @@
         FIN_Utility.getDate(paymentDate), OBDal.getInstance().get(Organization.class, strOrgId),
         conversionRatePrecision);
 
+    FIN_FinancialAccount financialAccount = dao.getObject(FIN_FinancialAccount.class,
+        strFinancialAccountId);
+
     JSONObject msg = new JSONObject();
     try {
+      if (financialAccount.getWriteofflimit() != null) {
+        msg.put("twriteoff", financialAccount.getTypewriteoff());
+        msg.put("awriteoff", financialAccount.getWriteofflimit().toString());
+      }
       msg.put("combo", finAccountComboHtml);
       if (financialAccountCurrency != null) {
         msg.put("financialAccountCurrencyId", financialAccountCurrency.getId());
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -66,6 +66,11 @@
     <!-- Not allow to change exchange rate and amount -->
     <PARAMETER id="paramStrNotAllowExchange" name="strNotAllowExchange" attribute="value"/>
     
+     <!-- Not allow to change Write Off-->
+    <PARAMETER id="paramStrWriteOffLimit" name="strWriteOffLimit" attribute="value"/>
+    <PARAMETER id="paramStrtypewriteoff" name="strtypewriteoff" attribute="value"/>
+    <PARAMETER id="paramStrAmountwriteoff" name="strAmountwriteoff" attribute="value"/>
+    
     <SUBREPORT id="reportC_Currency_ID" name="reportC_Currency_ID" report="org/openbravo/erpCommon/reference/List">
       <ARGUMENT name="parameterListSelected" withId="paramC_Currency_ID"/>
     </SUBREPORT>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Fri Sep 14 20:14:05 2012 +0200
@@ -829,6 +829,10 @@
   <input type="hidden" name="strElement_SR" id="paramStrElement_SR" value=""/>
   <input type="hidden" name="strElement_MC" id="paramStrElement_MC" value=""/>
   <input type="hidden" name="strNotAllowExchange" id="paramStrNotAllowExchange" value=""/>
+  <input type="hidden" name="strWriteOffLimit" id="paramStrWriteOffLimit" value=""/>
+  <input type="hidden" name="strtypewriteoff" id="paramStrtypewriteoff" value=""/>
+  <input type="hidden" name="strAmountwriteoff" id="paramStrAmountwriteoff" value=""/>
+  
   
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
@@ -1864,6 +1868,12 @@
                             </td>
                             <td><span class="LabelText">Write off the difference</span></td>
                           </tr>
+                           <tr id="writeofflimit">
+                            <td class="Radio_Check_ContentCell" >
+                              <input type="radio" name="inpDifferenceAction" value="writeofflimit" id="radiolimit" DISABLED/>
+                            </td>
+                            <td><span class="LabelText">Write off the difference (Above limit)</span></td>
+                          </tr>  
                         </table>
                       </td>
                     </tr>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Fri Sep 14 20:14:05 2012 +0200
@@ -534,6 +534,20 @@
         strWindowId);
     xmlDocument.setParameter("strNotAllowExchange", strNotAllowExchange);
 
+    if (financialAccount.getWriteofflimit() != null) {
+      final String strtypewriteoff;
+      final String strAmountwriteoff;
+
+      strtypewriteoff = financialAccount.getTypewriteoff();
+      strAmountwriteoff = financialAccount.getWriteofflimit().toString();
+      xmlDocument.setParameter("strtypewriteoff", strtypewriteoff);
+      xmlDocument.setParameter("strAmountwriteoff", strAmountwriteoff);
+
+      final String strWriteOffLimit = Utility.getContext(this, vars, "WriteOffLimitPreference",
+          strWindowId);
+      xmlDocument.setParameter("strWriteOffLimit", strWriteOffLimit);
+    }
+
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(xmlDocument.print());
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -91,7 +91,12 @@
     
     <!-- Not allow to change exchange rate and amount -->
     <PARAMETER id="paramStrNotAllowExchange" name="strNotAllowExchange" attribute="value"/>
-
+    
+    <!-- Not allow to change Write Off-->
+    <PARAMETER id="paramStrWriteOffLimit" name="strWriteOffLimit" attribute="value"/>
+    <PARAMETER id="paramStrtypewriteoff" name="strtypewriteoff" attribute="value"/>
+    <PARAMETER id="paramStrAmountwriteoff" name="strAmountwriteoff" attribute="value"/>
+    
     <DISCARD id="discard"/>
     
 </REPORT>
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/FIN_Utilities.js	Fri Sep 14 16:51:05 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/FIN_Utilities.js	Fri Sep 14 20:14:05 2012 +0200
@@ -342,6 +342,7 @@
       total = (frm.inpTotal && frm.inpTotal.value) ? frm.inpTotal.value : applyFormat('0'),
       amount = total,
       invoicedAmount = total;
+  var exchangeRate = frm.inpExchangeRate;
 
   if (isGLItemEnabled) {
     invoicedAmount = frm.inpInvoiceAmount.value;
@@ -363,7 +364,14 @@
   document.getElementById('paramDifference').innerHTML = frm.inpDifference.value;
   displayLogicElement('sectionDifference', (compare(expected, '!=', total) || compareWithSign(amount, '>', total)));
   displayLogicElement('sectionDifferenceBox', (compare(expected, '!=', total) || (isCreditAllowed && compareWithSign(amount, '>', total))));
-  displayLogicElement('writeoff', compare(expected, '!=', total));
+  if ((frm.strWriteOffLimit.value === 'Y') && (compare(expected, '!=', total)) && (frm.strtypewriteoff.value==='A') && (compareWithSign((applyFormat((subtract(expected,total))*exchangeRate.value)), '>',frm.strAmountwriteoff.value))) {  
+	  displayLogicElement('writeofflimit', true);
+	  displayLogicElement('writeoff', false);
+   }
+  else {
+	  displayLogicElement('writeofflimit', false);
+	  displayLogicElement('writeoff', compare(expected, '!=', total));
+  }
   displayLogicElement('underpayment', compareWithSign(expected, '>', total));
   displayLogicElement('credit', isCreditAllowed && compareWithSign(amount, '>', total));
   displayLogicElement('refund', isCreditAllowed && isReceipt && compareWithSign(amount, '>', total));
--- a/src-db/database/model/tables/FIN_FINANCIAL_ACCOUNT.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/src-db/database/model/tables/FIN_FINANCIAL_ACCOUNT.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -117,6 +117,14 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="TYPEWRITEOFF" primaryKey="false" required="false" type="VARCHAR" size="60" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="WRITEOFFLIMIT" primaryKey="false" required="false" type="DECIMAL" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="FIN_AD_CLIENT_ACCOUNT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -226419,6 +226419,41 @@
 <!--3C994F2984454B008F9ACF59BA53D8CC-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--3C994F2984454B008F9ACF59BA53D8CC--></AD_COLUMN>
 
+<!--3D20749B2D1642F591849DA6CD6EB654--><AD_COLUMN>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_COLUMN_ID><![CDATA[3D20749B2D1642F591849DA6CD6EB654]]></AD_COLUMN_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <NAME><![CDATA[Writeofflimit]]></NAME>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <DESCRIPTION><![CDATA[Value for the Write-off limit in a payment. ]]></DESCRIPTION>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <HELP><![CDATA[Value for the Write-off limit in a payment. When type selected is Amount, the value holds the amount on financial account currency.  This field is displayed when write-off limit preference value is set to "Y".]]></HELP>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <COLUMNNAME><![CDATA[Writeofflimit]]></COLUMNNAME>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_TABLE_ID><![CDATA[B129E53BC0E747879F7BA17F0AECEC32]]></AD_TABLE_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_REFERENCE_ID><![CDATA[12]]></AD_REFERENCE_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <FIELDLENGTH><![CDATA[2]]></FIELDLENGTH>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <SEQNO><![CDATA[390]]></SEQNO>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_ELEMENT_ID><![CDATA[B1FA47C8408A44F6A23CFE48F7E8EB3D]]></AD_ELEMENT_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <POSITION><![CDATA[35]]></POSITION>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--3D20749B2D1642F591849DA6CD6EB654-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--3D20749B2D1642F591849DA6CD6EB654--></AD_COLUMN>
+
 <!--3D81BAED7AA844A3923EE6015B1862D1--><AD_COLUMN>
 <!--3D81BAED7AA844A3923EE6015B1862D1-->  <AD_COLUMN_ID><![CDATA[3D81BAED7AA844A3923EE6015B1862D1]]></AD_COLUMN_ID>
 <!--3D81BAED7AA844A3923EE6015B1862D1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -227833,6 +227868,42 @@
 <!--469E7B64F2BE11DD9423001D09C4A2FE-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--469E7B64F2BE11DD9423001D09C4A2FE--></AD_COLUMN>
 
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC--><AD_COLUMN>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_COLUMN_ID><![CDATA[47254BD6EF8D4F4D97DE902FDEC55DAC]]></AD_COLUMN_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <NAME><![CDATA[Typewriteoff]]></NAME>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <DESCRIPTION><![CDATA[Holds the type of write off limit configured for the financial account.]]></DESCRIPTION>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <HELP><![CDATA[It allows to define different type of write-off limit for a financial account. This field is displayed when write-off limit preference value is set to "Y". ]]></HELP>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <COLUMNNAME><![CDATA[Typewriteoff]]></COLUMNNAME>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_TABLE_ID><![CDATA[B129E53BC0E747879F7BA17F0AECEC32]]></AD_TABLE_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_REFERENCE_ID><![CDATA[17]]></AD_REFERENCE_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_REFERENCE_VALUE_ID><![CDATA[C3531F85C14B4515AB7259F0D338050D]]></AD_REFERENCE_VALUE_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <FIELDLENGTH><![CDATA[60]]></FIELDLENGTH>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <SEQNO><![CDATA[380]]></SEQNO>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_ELEMENT_ID><![CDATA[E80D311071C54E78859339274535D285]]></AD_ELEMENT_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <POSITION><![CDATA[34]]></POSITION>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--47254BD6EF8D4F4D97DE902FDEC55DAC--></AD_COLUMN>
+
 <!--47A925222BF44DED8FC19F413BD5821B--><AD_COLUMN>
 <!--47A925222BF44DED8FC19F413BD5821B-->  <AD_COLUMN_ID><![CDATA[47A925222BF44DED8FC19F413BD5821B]]></AD_COLUMN_ID>
 <!--47A925222BF44DED8FC19F413BD5821B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -28134,6 +28134,20 @@
 <!--B1EB4BB84F52592AE040A8C028010F07-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--B1EB4BB84F52592AE040A8C028010F07--></AD_ELEMENT>
 
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D--><AD_ELEMENT>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <AD_ELEMENT_ID><![CDATA[B1FA47C8408A44F6A23CFE48F7E8EB3D]]></AD_ELEMENT_ID>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <COLUMNNAME><![CDATA[Writeofflimit]]></COLUMNNAME>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <NAME><![CDATA[Write-off Limit]]></NAME>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <PRINTNAME><![CDATA[Write-off Limit]]></PRINTNAME>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <DESCRIPTION><![CDATA[Value for the Write-off limit in a payment. ]]></DESCRIPTION>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <HELP><![CDATA[Value for the Write-off limit in a payment. When type selected is Amount, the value holds the amount on financial account currency.  This field is displayed when write-off limit preference value is set to "Y".]]></HELP>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--B1FA47C8408A44F6A23CFE48F7E8EB3D--></AD_ELEMENT>
+
 <!--B241E19041029C74E040007F01005C18--><AD_ELEMENT>
 <!--B241E19041029C74E040007F01005C18-->  <AD_ELEMENT_ID><![CDATA[B241E19041029C74E040007F01005C18]]></AD_ELEMENT_ID>
 <!--B241E19041029C74E040007F01005C18-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -29171,6 +29185,20 @@
 <!--E5702FB7A0A14BF782A5723A131B8F8C-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--E5702FB7A0A14BF782A5723A131B8F8C--></AD_ELEMENT>
 
+<!--E80D311071C54E78859339274535D285--><AD_ELEMENT>
+<!--E80D311071C54E78859339274535D285-->  <AD_ELEMENT_ID><![CDATA[E80D311071C54E78859339274535D285]]></AD_ELEMENT_ID>
+<!--E80D311071C54E78859339274535D285-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E80D311071C54E78859339274535D285-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E80D311071C54E78859339274535D285-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E80D311071C54E78859339274535D285-->  <COLUMNNAME><![CDATA[Type write-off]]></COLUMNNAME>
+<!--E80D311071C54E78859339274535D285-->  <NAME><![CDATA[Type Write-off Limit]]></NAME>
+<!--E80D311071C54E78859339274535D285-->  <PRINTNAME><![CDATA[Type Write-off Limit]]></PRINTNAME>
+<!--E80D311071C54E78859339274535D285-->  <DESCRIPTION><![CDATA[Holds the type of write off limit configured for the financial account.]]></DESCRIPTION>
+<!--E80D311071C54E78859339274535D285-->  <HELP><![CDATA[It allows to define different type of write-off limit for a financial account. This field is displayed when write-off limit preference value is set to "Y". ]]></HELP>
+<!--E80D311071C54E78859339274535D285-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--E80D311071C54E78859339274535D285-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--E80D311071C54E78859339274535D285--></AD_ELEMENT>
+
 <!--E8960F2356544158BC13E363B1364E41--><AD_ELEMENT>
 <!--E8960F2356544158BC13E363B1364E41-->  <AD_ELEMENT_ID><![CDATA[E8960F2356544158BC13E363B1364E41]]></AD_ELEMENT_ID>
 <!--E8960F2356544158BC13E363B1364E41-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -175471,6 +175471,37 @@
 <!--090122697F994BE696E9F947FFF34E3C-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--090122697F994BE696E9F947FFF34E3C--></AD_FIELD>
 
+<!--0916FE8D15FB480FA097670967A881B9--><AD_FIELD>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_FIELD_ID><![CDATA[0916FE8D15FB480FA097670967A881B9]]></AD_FIELD_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--0916FE8D15FB480FA097670967A881B9-->  <NAME><![CDATA[Type Write-off Limit]]></NAME>
+<!--0916FE8D15FB480FA097670967A881B9-->  <DESCRIPTION><![CDATA[Holds the type of write off limit configured for the financial account.]]></DESCRIPTION>
+<!--0916FE8D15FB480FA097670967A881B9-->  <HELP><![CDATA[It allows to define different type of write-off limit for a financial account. This field is displayed when write-off limit preference value is set to "Y". ]]></HELP>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_TAB_ID><![CDATA[2845D761A8394468BD3BA4710AA888D4]]></AD_TAB_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_COLUMN_ID><![CDATA[47254BD6EF8D4F4D97DE902FDEC55DAC]]></AD_COLUMN_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_FIELDGROUP_ID><![CDATA[402880E72F1C15A5012F1C7AA98B00E8]]></AD_FIELDGROUP_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--0916FE8D15FB480FA097670967A881B9-->  <DISPLAYLOGIC><![CDATA[@WriteOffLimitPreference@='Y' ]]></DISPLAYLOGIC>
+<!--0916FE8D15FB480FA097670967A881B9-->  <DISPLAYLENGTH><![CDATA[60]]></DISPLAYLENGTH>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--0916FE8D15FB480FA097670967A881B9-->  <SEQNO><![CDATA[210]]></SEQNO>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--0916FE8D15FB480FA097670967A881B9-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--0916FE8D15FB480FA097670967A881B9-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--0916FE8D15FB480FA097670967A881B9-->  <GRID_SEQNO><![CDATA[0]]></GRID_SEQNO>
+<!--0916FE8D15FB480FA097670967A881B9-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--0916FE8D15FB480FA097670967A881B9-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--0916FE8D15FB480FA097670967A881B9-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--0916FE8D15FB480FA097670967A881B9-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--0916FE8D15FB480FA097670967A881B9--></AD_FIELD>
+
 <!--09A660EF0520415295266E9F44FD206A--><AD_FIELD>
 <!--09A660EF0520415295266E9F44FD206A-->  <AD_FIELD_ID><![CDATA[09A660EF0520415295266E9F44FD206A]]></AD_FIELD_ID>
 <!--09A660EF0520415295266E9F44FD206A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -206406,10 +206437,11 @@
 <!--82F2E8A160EB472CE040007F01005324-->  <AD_TAB_ID><![CDATA[2845D761A8394468BD3BA4710AA888D4]]></AD_TAB_ID>
 <!--82F2E8A160EB472CE040007F01005324-->  <AD_COLUMN_ID><![CDATA[828EE0AE80535FA1E040007F010067C7]]></AD_COLUMN_ID>
 <!--82F2E8A160EB472CE040007F01005324-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--82F2E8A160EB472CE040007F01005324-->  <AD_FIELDGROUP_ID><![CDATA[109]]></AD_FIELDGROUP_ID>
 <!--82F2E8A160EB472CE040007F01005324-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--82F2E8A160EB472CE040007F01005324-->  <DISPLAYLENGTH><![CDATA[12]]></DISPLAYLENGTH>
 <!--82F2E8A160EB472CE040007F01005324-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--82F2E8A160EB472CE040007F01005324-->  <SEQNO><![CDATA[210]]></SEQNO>
+<!--82F2E8A160EB472CE040007F01005324-->  <SEQNO><![CDATA[200]]></SEQNO>
 <!--82F2E8A160EB472CE040007F01005324-->  <ISSAMELINE><![CDATA[Y]]></ISSAMELINE>
 <!--82F2E8A160EB472CE040007F01005324-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--82F2E8A160EB472CE040007F01005324-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -217178,6 +217210,37 @@
 <!--AE5E13166416470CAD39A5C0616E3621-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--AE5E13166416470CAD39A5C0616E3621--></AD_FIELD>
 
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848--><AD_FIELD>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_FIELD_ID><![CDATA[AE96C5FEA3B44D3DBC9B724FF82EA848]]></AD_FIELD_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <NAME><![CDATA[Write-off Limit]]></NAME>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <DESCRIPTION><![CDATA[Value for the Write-off limit in a payment. ]]></DESCRIPTION>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <HELP><![CDATA[Value for the Write-off limit in a payment. When type selected is Amount, the value holds the amount on financial account currency.  This field is displayed when write-off limit preference value is set to "Y".]]></HELP>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_TAB_ID><![CDATA[2845D761A8394468BD3BA4710AA888D4]]></AD_TAB_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_COLUMN_ID><![CDATA[3D20749B2D1642F591849DA6CD6EB654]]></AD_COLUMN_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_FIELDGROUP_ID><![CDATA[402880E72F1C15A5012F1C7AA98B00E8]]></AD_FIELDGROUP_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <DISPLAYLOGIC><![CDATA[@WriteOffLimitPreference@='Y' ]]></DISPLAYLOGIC>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <DISPLAYLENGTH><![CDATA[2]]></DISPLAYLENGTH>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <SEQNO><![CDATA[220]]></SEQNO>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <GRID_SEQNO><![CDATA[0]]></GRID_SEQNO>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--AE96C5FEA3B44D3DBC9B724FF82EA848--></AD_FIELD>
+
 <!--AEAEFFCA2F7D4E8592C60863B54836E2--><AD_FIELD>
 <!--AEAEFFCA2F7D4E8592C60863B54836E2-->  <AD_FIELD_ID><![CDATA[AEAEFFCA2F7D4E8592C60863B54836E2]]></AD_FIELD_ID>
 <!--AEAEFFCA2F7D4E8592C60863B54836E2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -231723,10 +231786,11 @@
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <AD_TAB_ID><![CDATA[2845D761A8394468BD3BA4710AA888D4]]></AD_TAB_ID>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <AD_COLUMN_ID><![CDATA[515A9DFD91C243D3BECAA9D0149063C4]]></AD_COLUMN_ID>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--D90513BC049C4CD5A0589E641DAFC4A0-->  <AD_FIELDGROUP_ID><![CDATA[109]]></AD_FIELDGROUP_ID>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <DISPLAYLENGTH><![CDATA[12]]></DISPLAYLENGTH>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--D90513BC049C4CD5A0589E641DAFC4A0-->  <SEQNO><![CDATA[220]]></SEQNO>
+<!--D90513BC049C4CD5A0589E641DAFC4A0-->  <SEQNO><![CDATA[205]]></SEQNO>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--D90513BC049C4CD5A0589E641DAFC4A0-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
--- a/src-db/database/sourcedata/AD_REFERENCE.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/src-db/database/sourcedata/AD_REFERENCE.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -5070,6 +5070,18 @@
 <!--C01DEDDA9B35427786058CB649FB972F-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
 <!--C01DEDDA9B35427786058CB649FB972F--></AD_REFERENCE>
 
+<!--C3531F85C14B4515AB7259F0D338050D--><AD_REFERENCE>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <AD_REFERENCE_ID><![CDATA[C3531F85C14B4515AB7259F0D338050D]]></AD_REFERENCE_ID>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <NAME><![CDATA[Write off type]]></NAME>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <ISBASEREFERENCE><![CDATA[N]]></ISBASEREFERENCE>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <PARENTREFERENCE_ID><![CDATA[17]]></PARENTREFERENCE_ID>
+<!--C3531F85C14B4515AB7259F0D338050D-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
+<!--C3531F85C14B4515AB7259F0D338050D--></AD_REFERENCE>
+
 <!--C5C21C28B39E4683A91779F16C112E40--><AD_REFERENCE>
 <!--C5C21C28B39E4683A91779F16C112E40-->  <AD_REFERENCE_ID><![CDATA[C5C21C28B39E4683A91779F16C112E40]]></AD_REFERENCE_ID>
 <!--C5C21C28B39E4683A91779F16C112E40-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Fri Sep 14 16:51:05 2012 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Fri Sep 14 20:14:05 2012 +0200
@@ -8230,6 +8230,17 @@
 <!--19012DA68ACF4069910D20E44A6C0DF3-->  <SEQNO><![CDATA[1]]></SEQNO>
 <!--19012DA68ACF4069910D20E44A6C0DF3--></AD_REF_LIST>
 
+<!--19650575798649EA890F3FD450A3918E--><AD_REF_LIST>
+<!--19650575798649EA890F3FD450A3918E-->  <AD_REF_LIST_ID><![CDATA[19650575798649EA890F3FD450A3918E]]></AD_REF_LIST_ID>
+<!--19650575798649EA890F3FD450A3918E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--19650575798649EA890F3FD450A3918E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--19650575798649EA890F3FD450A3918E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--19650575798649EA890F3FD450A3918E-->  <VALUE><![CDATA[A]]></VALUE>
+<!--19650575798649EA890F3FD450A3918E-->  <NAME><![CDATA[Amount]]></NAME>
+<!--19650575798649EA890F3FD450A3918E-->  <AD_REFERENCE_ID><![CDATA[C3531F85C14B4515AB7259F0D338050D]]></AD_REFERENCE_ID>
+<!--19650575798649EA890F3FD450A3918E-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--19650575798649EA890F3FD450A3918E--></AD_REF_LIST>
+
 <!--19CE2DD159684FCF84E1B1963AF59A14--><AD_REF_LIST>
 <!--19CE2DD159684FCF84E1B1963AF59A14-->  <AD_REF_LIST_ID><![CDATA[19CE2DD159684FCF84E1B1963AF59A14]]></AD_REF_LIST_ID>
 <!--19CE2DD159684FCF84E1B1963AF59A14-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -8667,6 +8678,18 @@
 <!--41E023E4AABB492A89022F37CD5B90B7-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--41E023E4AABB492A89022F37CD5B90B7--></AD_REF_LIST>
 
+<!--427088D82ABA49D484FC3B90AD82F59F--><AD_REF_LIST>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <AD_REF_LIST_ID><![CDATA[427088D82ABA49D484FC3B90AD82F59F]]></AD_REF_LIST_ID>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <VALUE><![CDATA[WriteOffLimitPreference]]></VALUE>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <NAME><![CDATA[Write-off limit]]></NAME>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <DESCRIPTION><![CDATA[Write-off limit]]></DESCRIPTION>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--427088D82ABA49D484FC3B90AD82F59F-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--427088D82ABA49D484FC3B90AD82F59F--></AD_REF_LIST>
+
 <!--433A48943CF34C978A7E5759A35B4D88--><AD_REF_LIST>
 <!--433A48943CF34C978A7E5759A35B4D88-->  <AD_REF_LIST_ID><![CDATA[433A48943CF34C978A7E5759A35B4D88]]></AD_REF_LIST_ID>
 <!--433A48943CF34C978A7E5759A35B4D88-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -8773,6 +8796,17 @@
 <!--49A96D77C74A44EA90AED7C50BBAFAE1-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--49A96D77C74A44EA90AED7C50BBAFAE1--></AD_REF_LIST>
 
+<!--49CA2EB814834A60BB71F0F45233A208--><AD_REF_LIST>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <AD_REF_LIST_ID><![CDATA[49CA2EB814834A60BB71F0F45233A208]]></AD_REF_LIST_ID>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <ISACTIVE><![CDATA[N]]></ISACTIVE>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <VALUE><![CDATA[P]]></VALUE>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <NAME><![CDATA[Percentage]]></NAME>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <AD_REFERENCE_ID><![CDATA[C3531F85C14B4515AB7259F0D338050D]]></AD_REFERENCE_ID>
+<!--49CA2EB814834A60BB71F0F45233A208-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--49CA2EB814834A60BB71F0F45233A208--></AD_REF_LIST>
+
 <!--49CC7B0012EA4A379F8CE95F481A3F8D--><AD_REF_LIST>
 <!--49CC7B0012EA4A379F8CE95F481A3F8D-->  <AD_REF_LIST_ID><![CDATA[49CC7B0012EA4A379F8CE95F481A3F8D]]></AD_REF_LIST_ID>
 <!--49CC7B0012EA4A379F8CE95F481A3F8D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Payment_MultiCurrency.java	Fri Sep 14 16:51:05 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Payment_MultiCurrency.java	Fri Sep 14 20:14:05 2012 +0200
@@ -86,6 +86,8 @@
           } else {
             info.addResult("inpfinaccTxnAmount", "");
           }
+        } else {
+          info.addResult("inpfinaccTxnConvertRate", finAccConvertRate);
         }
       }