Fixes bug 20429: Add Payment from Transaction does not allow to filter by amounts when creating a payment
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Mon, 07 May 2012 10:56:04 +0200
changeset 16497 c7d28f77823d
parent 16496 566af5c10315
child 16498 f8752c98c5d9
Fixes bug 20429: Add Payment from Transaction does not allow to filter by amounts when creating a payment
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/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Mon May 07 10:54:55 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Mon May 07 10:56:04 2012 +0200
@@ -104,7 +104,9 @@
       OB.APRM.APFT_dt !== frmMain['inpDocumentType'].value ||
       OB.APRM.APFT_cu !== frmMain['inpCurrencyId'].value ||
       OB.APRM.APFT_dn !== frmMain['inpDocumentNo'].value ||
-      OB.APRM.APFT_re !== frmMain['isReceipt'].value) {
+      OB.APRM.APFT_re !== frmMain['isReceipt'].value ||
+      OB.APRM.APFT_af !== frmMain['inpAmountFrom'].value ||
+      OB.APRM.APFT_at !== frmMain['inpAmountTo'].value) {
 
     OB.APRM.APFT_bp = frmMain['inpcBpartnerId'].value;
     OB.APRM.APFT_fa = frmMain['inpFinancialAccountId'].value;
@@ -116,6 +118,8 @@
     OB.APRM.APFT_cu = frmMain['inpCurrencyId'].value;
     OB.APRM.APFT_dn = frmMain['inpDocumentNo'].value;
     OB.APRM.APFT_re = frmMain['isReceipt'].value;
+    OB.APRM.APFT_af = frmMain['inpAmountFrom'].value;
+    OB.APRM.APFT_at = frmMain['inpAmountTo'].value;
 
     try {
       var url = '../org.openbravo.advpaymentmngt.ad_actionbutton/AddPaymentFromTransaction.html';
@@ -1357,7 +1361,21 @@
                     <td class="TextBox_ContentCell">
                       <table style="border: 0px none; border-collapse: collapse;">
                         <tr><td style="padding-top: 0px;">
-                          <input type="text" id="paramTransDateFrom" class="dojoValidateValid TextBox_btn_OneCell_width" value="" maxlength="10" name="inpTransDateFrom" onkeyup="autoCompleteDate(this);" onkeydown="changeToEditingMode('onkeydown');" onkeypress="changeToEditingMode('onkeypress');" oncut="changeToEditingMode('oncut');" onpaste="changeToEditingMode('onpaste');" oncontextmenu="changeToEditingMode('oncontextmenu');" onblur="expandDateYear(this.id);" onchange="validateDateTextBox(this.id);  validateDate(this);return true;" displayFormat="xx" saveFormat="xx"></input>
+                          <input type="text" id="paramTransDateFrom" 
+                                 class="dojoValidateValid TextBox_btn_OneCell_width" 
+                                 value="" 
+                                 maxlength="10" 
+                                 name="inpTransDateFrom" 
+                                 onkeyup="autoCompleteDate(this);" 
+                                 onkeydown="changeToEditingMode('onkeydown');" 
+                                 onkeypress="changeToEditingMode('onkeypress');" 
+                                 oncut="changeToEditingMode('oncut');" 
+                                 onpaste="changeToEditingMode('onpaste');" 
+                                 oncontextmenu="changeToEditingMode('oncontextmenu');" 
+                                 onblur="expandDateYear(this.id);" 
+                                 onchange="validateDateTextBox(this.id);  validateDate(this);return true;" 
+                                 displayFormat="xx" 
+                                 saveFormat="xx"></input>
                         </td></tr>
                       </table>
                       <span id="paramTransDateFrominvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
@@ -1413,6 +1431,78 @@
                 </table>
               </td>
             </tr>
+            <tr>
+              <td class="TitleCell"><span class="LabelText" id="lblAmountFrom">Amount From</span></td>
+              <td class="TextBox_btn_ContentCell">
+                  <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;" id="paramAmountFromCell">
+                    <tr>
+                      <td class="Textbox_ContentCell">
+                      <table style="border: 0px none; border-collapse: collapse;">
+                        <tr><td style="padding-top: 0px;">
+                          <input type="text" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" outputformat="euroEdition" onchange="loadGridList();return true;" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" name="inpAmountFrom" maxlength="22" value="" required="false" class="dojoValidateValid TextBox_btn_OneCell_width number" id="paramAmountFrom"/>
+                        </td></tr>
+                      </table>
+                      <span id="paramAmountFrominvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
+                        <table class="TextBox_MsgContainer_table">
+                          <tbody><tr class="TextBox_MsgContainer_tr">
+                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
+                          </tr>
+                          <tr>
+                            <td class="invalid" colspan="2"><div name="invalidText" id="paramAmountFrominvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
+                          </tr>
+                        </tbody></table>
+                      </span>
+                      </td>
+                      <td class="FieldButton_ContentCell">
+                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount From'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpAmountFrom', document.frmMain.inpAmountFrom.value, false);return false;">
+                      <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
+                          <tr>
+                            <td class="FieldButton_bg">
+                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
+                            </td>
+                          </tr>
+                        </table>
+                      </a>
+                      </td>
+                    </tr>
+                  </table>
+              </td>
+              <td class="TitleCell"><span class="LabelText" id="lblAmountTo">Amount To</span></td>
+              <td class="TextBox_btn_ContentCell">
+                  <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;" id="paramAmountToCell">
+                    <tr>
+                      <td class="Textbox_ContentCell">
+                      <table style="border: 0px none; border-collapse: collapse;">
+                        <tr><td style="padding-top: 0px;">
+                          <input type="text" onblur="numberInputEvent('onblur', this);" onfocus="numberInputEvent('onfocus', this);" outputformat="euroEdition" onchange="loadGridList();return true;" onpaste="changeToEditingMode('onpaste');" oncut="changeToEditingMode('oncut');" onkeypress="changeToEditingMode('onkeypress');" onkeydown="changeToEditingMode('onkeydown'); numberInputEvent('onkeydown', this, event);" onkeyup="" name="inpAmountTo" maxlength="22" value="" required="false" class="dojoValidateValid TextBox_btn_OneCell_width number" id="paramAmountTo"/>
+                        </td></tr>
+                      </table>
+                      <span id="paramAmountToinvalidSpan" style="display: none;" class="TextBox_MsgContainer_span">
+                        <table class="TextBox_MsgContainer_table">
+                          <tbody><tr class="TextBox_MsgContainer_tr">
+                            <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
+                          </tr>
+                          <tr>
+                            <td class="invalid" colspan="2"><div name="invalidText" id="paramAmountToinvalidSpanText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
+                          </tr>
+                        </tbody></table>
+                      </span>
+                      </td>
+                      <td class="FieldButton_ContentCell">
+                      <a class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Amount To'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="calculator('frmMain.inpAmountTo', document.frmMain.inpAmountTo.value, false);return false;">
+                      <table class="FieldButton" onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;" id="NoPackageslinkCalc">
+                          <tr>
+                            <td class="FieldButton_bg">
+                              <img alt="Calculator" class="FieldButton_Icon FieldButton_Icon_Calc" title="Amount" src="../../../../../web/images/blank.gif" border="0" id="buttonCalc"></img>
+                            </td>
+                          </tr>
+                        </table>
+                      </a>
+                      </td>
+                    </tr>
+                  </table>
+              </td>              
+            </tr>            
             <tr id="glitemRow">
               <td class="TitleCell"><span class="LabelText">Received In</span></td>
               <td class="TextBox_btn_ContentCell">
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Mon May 07 10:54:55 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Mon May 07 10:56:04 2012 +0200
@@ -113,10 +113,12 @@
       final String strSelectedPaymentDetails = vars.getInStringParameter(
           "inpScheduledPaymentDetailId", IsIDFilter.instance);
       boolean isReceipt = vars.getRequiredStringParameter("isReceipt").equals("Y");
+      final String strAmountFrom = vars.getNumericParameter("inpAmountFrom", "");
+      final String strAmountTo = vars.getNumericParameter("inpAmountTo", "");
 
       printGrid(response, vars, strFinancialAccountId, strBusinessPartnerId, strDueDateFrom,
           strDueDateTo, strTransDateFrom, strTransDateTo, strDocumentType, strDocumentNo,
-          strSelectedPaymentDetails, isReceipt, strCurrencyId);
+          strSelectedPaymentDetails, isReceipt, strCurrencyId, strAmountFrom, strAmountTo);
 
     } else if (vars.commandIn("PAYMENTMETHODCOMBO")) {
       final String strBusinessPartnerId = vars.getRequestGlobalVariable("inpcBpartnerId", "");
@@ -533,7 +535,8 @@
       String strFinancialAccountId, String strBusinessPartnerId, String strDueDateFrom,
       String strDueDateTo, String strTransDateFrom, String strTransDateTo, String strDocumentType,
       String strDocumentNo, String strSelectedPaymentDetails, boolean isReceipt,
-      String strCurrencyId) throws IOException, ServletException {
+      String strCurrencyId, String strAmountFrom, String strAmountTo) throws IOException,
+      ServletException {
 
     log4j.debug("Output: Grid with pending payments");
 
@@ -557,7 +560,8 @@
     // list
     if (!"".equals(strBusinessPartnerId) || !"".equals(strDocumentNo)
         || isValidJSDate(strDueDateFrom) || isValidJSDate(strDueDateTo)
-        || isValidJSDate(strTransDateFrom) || isValidJSDate(strTransDateTo)) {
+        || isValidJSDate(strTransDateFrom) || isValidJSDate(strTransDateTo)
+        || !"".equals(strAmountFrom) || !"".equals(strAmountTo)) {
       Currency paymentCurrency;
       if (strCurrencyId == null || strCurrencyId.isEmpty()) {
         paymentCurrency = financialAccount.getCurrency();
@@ -572,7 +576,8 @@
           FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strDueDateTo, "1")),
           FIN_Utility.getDate(strTransDateFrom),
           FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strTransDateTo, "1")), strDocumentType,
-          strDocumentNo, null, selectedScheduledPaymentDetails, isReceipt);
+          strDocumentNo, null, selectedScheduledPaymentDetails, isReceipt, strAmountFrom,
+          strAmountTo);
     }
     final FieldProvider[] data = FIN_AddPayment.getShownScheduledPaymentDetails(vars,
         selectedScheduledPaymentDetails, filteredScheduledPaymentDetails, false, null);
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.xml	Mon May 07 10:54:55 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.xml	Mon May 07 10:56:04 2012 +0200
@@ -36,6 +36,8 @@
     <PARAMETER id="paramPaymentMethod" name="paymentMethod" attribute="value"/>
     <PARAMETER id="paramExpectedPayment" name="expectedPayment" attribute="value" format="euroEdition"/>
     <PARAMETER id="paramActualPayment" name="actualPayment" attribute="value" format="euroEdition" default="0"/>
+    <PARAMETER id="paramAmountFrom" name="amountFrom" attribute="value" format="euroEdition" default=""/>
+    <PARAMETER id="paramAmountTo" name="amountTo" attribute="value" format="euroEdition" default=""/>
     <PARAMETER id="paramFinancialAccountCurrencyId" name="financialAccountCurrencyId" attribute="value"/>
     <PARAMETER id="paramFinancialAccountCurrencyPrecision" name="financialAccountCurrencyPrecision" attribute="value"/>
     <PARAMETER id="paramExchangeRate" name="exchangeRate" attribute="value" format="generalQtyEdition"/>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java	Mon May 07 10:54:55 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java	Mon May 07 10:56:04 2012 +0200
@@ -187,6 +187,17 @@
       Date dueDateFrom, Date dueDateTo, Date transactionDateFrom, Date transactionDateTo,
       String strTransactionType, String strDocumentNo, FIN_PaymentMethod paymentMethod,
       List<FIN_PaymentScheduleDetail> selectedScheduledPaymentDetails, boolean isReceipt) {
+    return getFilteredScheduledPaymentDetails(organization, businessPartner, currency, dueDateFrom,
+        dueDateTo, null, null, strTransactionType, "", paymentMethod,
+        selectedScheduledPaymentDetails, isReceipt, "", "");
+  }
+
+  public List<FIN_PaymentScheduleDetail> getFilteredScheduledPaymentDetails(
+      Organization organization, BusinessPartner businessPartner, Currency currency,
+      Date dueDateFrom, Date dueDateTo, Date transactionDateFrom, Date transactionDateTo,
+      String strTransactionType, String strDocumentNo, FIN_PaymentMethod paymentMethod,
+      List<FIN_PaymentScheduleDetail> selectedScheduledPaymentDetails, boolean isReceipt,
+      String strAmountFrom, String strAmountTo) {
 
     final StringBuilder whereClause = new StringBuilder();
     final List<Object> parameters = new ArrayList<Object>();
@@ -233,7 +244,20 @@
         }
         whereClause.append(" and psd.id not in (" + FIN_Utility.getInStrList(aux) + ")");
       }
-
+      if (!StringUtils.isEmpty(strAmountFrom)) {
+        whereClause.append(" and psd.");
+        whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_AMOUNT);
+        whereClause.append(" >= ");
+        whereClause.append(strAmountFrom);
+        whereClause.append(" ");
+      }
+      if (!StringUtils.isEmpty(strAmountTo)) {
+        whereClause.append(" and psd.");
+        whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_AMOUNT);
+        whereClause.append(" <= ");
+        whereClause.append(strAmountTo);
+        whereClause.append(" ");
+      }
       // Transaction type filter
       whereClause.append(" and (");
       if (strTransactionType.equals("I") || strTransactionType.equals("B")) {