details:   https://code.openbravo.com/erp/devel/pi/rev/0a17f1fe4f0c
changeset: 22819:0a17f1fe4f0c
user:      Pandeeswari Ramakrishnan <pandeeswari.ramakrishnan <at> 
openbravo.com>
date:      Wed Apr 02 17:57:02 2014 +0530
summary:   Fixes Issue 24848: Closed period verification should not be performed
when trying to process a document not configured to generate accounting, closed 
period verification should not be performed.

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java
 |   87 +++++++-
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html
        |   30 +--
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/Reconciliation.java
        |  115 +++++++++-
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
            |   66 +++++-
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java
        |   90 +++++++-
 5 files changed, 349 insertions(+), 39 deletions(-)

diffs (truncated from 569 to 300 lines):

diff -r 511a09bd0e13 -r 0a17f1fe4f0c 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java
  Wed Apr 02 13:53:38 2014 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java
  Wed Apr 02 17:57:02 2014 +0530
@@ -46,6 +46,7 @@
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.FieldProviderFactory;
@@ -58,6 +59,7 @@
 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.financialmgmt.accounting.FIN_FinancialAccountAccounting;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
@@ -201,6 +203,12 @@
           strReceivedFromId);
       PriceList priceList = isReceipt ? businessPartner.getPriceList() : 
businessPartner
           .getPurchasePricelist();
+      FIN_FinancialAccount finAccount = 
OBDal.getInstance().get(FIN_FinancialAccount.class,
+          strFinancialAccountId);
+      FIN_PaymentMethod finPaymentMethod = 
OBDal.getInstance().get(FIN_PaymentMethod.class,
+          strPaymentMethodId);
+      boolean paymentDocumentEnabled = getDocumentConfirmation(this, 
finAccount, finPaymentMethod,
+          isReceipt, strPaymentAmount, true);
       OBError message = null;
       // FIXME: added to access the FIN_PaymentSchedule and 
FIN_PaymentScheduleDetail tables to be
       // removed when new security implementation is done
@@ -231,12 +239,24 @@
           // parameters.add(null);
           String strDocTypeId = (String) 
CallStoredProcedure.getInstance().call("AD_GET_DOCTYPE",
               parameters, null);
+          boolean documentEnabled = true;
           String strDocBaseType = parameters.get(2).toString();
           boolean orgLegalWithAccounting = 
FIN_Utility.periodControlOpened(Invoice.TABLE_NAME,
               strInvoiceId, Invoice.TABLE_NAME + "_ID", "LE");
 
-          if (!FIN_Utility.isPeriodOpen(vars.getClient(), strDocBaseType, 
strOrgId, strPaymentDate)
-              && orgLegalWithAccounting) {
+          if ((strAction.equals("PRD") || strAction.equals("PPW") || 
FIN_Utility
+              .isAutomaticDepositWithdrawn(finAccount, finPaymentMethod, 
isReceipt))
+              && new BigDecimal(strPaymentAmount).compareTo(BigDecimal.ZERO) 
!= 0) {
+            documentEnabled = paymentDocumentEnabled
+                || getDocumentConfirmation(this, finAccount, finPaymentMethod, 
isReceipt,
+                    strPaymentAmount, false);
+          } else {
+            documentEnabled = paymentDocumentEnabled;
+          }
+
+          if (documentEnabled
+              && !FIN_Utility.isPeriodOpen(vars.getClient(), strDocBaseType, 
strOrgId,
+                  strPaymentDate) && orgLegalWithAccounting) {
             final OBError myMessage = Utility.translateError(this, vars, 
vars.getLanguage(),
                 Utility.messageBD(this, "PeriodNotAvailable", 
vars.getLanguage()));
             vars.setMessage(strTabId, myMessage);
@@ -320,6 +340,69 @@
 
   }
 
+  public boolean getDocumentConfirmation(ConnectionProvider conn, 
FIN_FinancialAccount finAccount,
+      FIN_PaymentMethod finPaymentMethod, boolean isReceipt, String 
strPaymentAmount,
+      boolean isPayment) {
+    // Checks if this step is configured to generate accounting for the 
selected financial account
+    boolean confirmation = false;
+    OBContext.setAdminMode();
+    try {
+      OBCriteria<FinAccPaymentMethod> obCriteria = 
OBDal.getInstance().createCriteria(
+          FinAccPaymentMethod.class);
+      obCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, 
finAccount));
+      
obCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, 
finPaymentMethod));
+      obCriteria.setFilterOnReadableClients(false);
+      obCriteria.setFilterOnReadableOrganization(false);
+      List<FinAccPaymentMethod> lines = obCriteria.list();
+      List<FIN_FinancialAccountAccounting> accounts = 
finAccount.getFINFinancialAccountAcctList();
+      String uponUse = "";
+      if (isPayment) {
+        if (isReceipt) {
+          uponUse = lines.get(0).getUponReceiptUse();
+        } else {
+          uponUse = lines.get(0).getUponPaymentUse();
+        }
+      } else {
+        if (isReceipt) {
+          uponUse = lines.get(0).getUponDepositUse();
+        } else {
+          uponUse = lines.get(0).getUponWithdrawalUse();
+        }
+      }
+      for (FIN_FinancialAccountAccounting account : accounts) {
+        if (confirmation)
+          return confirmation;
+        if (isReceipt) {
+          if (("INT").equals(uponUse) && 
account.getInTransitPaymentAccountIN() != null)
+            confirmation = true;
+          else if (("DEP").equals(uponUse) && account.getDepositAccount() != 
null)
+            confirmation = true;
+          else if (("CLE").equals(uponUse) && 
account.getClearedPaymentAccount() != null)
+            confirmation = true;
+        } else {
+          if (("INT").equals(uponUse) && account.getFINOutIntransitAcct() != 
null)
+            confirmation = true;
+          else if (("WIT").equals(uponUse) && account.getWithdrawalAccount() 
!= null)
+            confirmation = true;
+          else if (("CLE").equals(uponUse) && 
account.getClearedPaymentAccountOUT() != null)
+            confirmation = true;
+        }
+        // For payments with Amount ZERO always create an entry as no 
transaction will be created
+        if (isPayment) {
+          BigDecimal amount = new BigDecimal(strPaymentAmount);
+          if (amount.compareTo(BigDecimal.ZERO) == 0) {
+            confirmation = true;
+          }
+        }
+      }
+    } catch (Exception e) {
+      return confirmation;
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return confirmation;
+  }
+
   private void printPage(HttpServletResponse response, VariablesSecureApp vars,
       String strBPfromInvoice, String strBPfromInvoiceId, String strCurrencyId,
       String strInvoiceId, String strOrgId, String strWindowId, String 
strTabId, boolean isReceipt,
diff -r 511a09bd0e13 -r 0a17f1fe4f0c 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html
 Wed Apr 02 13:53:38 2014 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.html
 Wed Apr 02 17:57:02 2014 +0530
@@ -277,31 +277,13 @@
 }
 
 function submitThisPage(strCommand) {
-  var callback=function(paramXMLParticular, XMLHttpRequestObj) {
-      var strText = "";
-      if (getReadyStateHandler(XMLHttpRequestObj)) {
-        try {
-          if (XMLHttpRequestObj.responseText) {
-            strText = XMLHttpRequestObj.responseText;
-            var objson = eval(strText);
-            showJSMessage(objson.text);
-            return false;
-          }else{
-            if (validate() ) {
-              setProcessingMode('popup', true);
-              submitCommandForm(strCommand, false, null, 
'../org.openbravo.advpaymentmngt.ad_actionbutton/AddTransaction.html', '_self');
-              disableButtonProcess();
-              return true;
-            } else {
-              return true;
-            }
-          }
-        } catch (e) {
+    if (validate() ) {
+        setProcessingMode('popup', true);
+        submitCommandForm(strCommand, false, null, 
'../org.openbravo.advpaymentmngt.ad_actionbutton/AddTransaction.html', '_self');
+        disableButtonProcess();
+        return true;
       }
-    }
-  }
-  var paramXMLReq = null;
-  return submitXmlHttpRequest(callback, document.frmMain, 'PERIOD', 
'../org.openbravo.advpaymentmngt.ad_actionbutton/AddTransaction.html', false, 
null, paramXMLReq);
+      return true;
 }
 
 </script>
diff -r 511a09bd0e13 -r 0a17f1fe4f0c 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/Reconciliation.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/Reconciliation.java
 Wed Apr 02 13:53:38 2014 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/Reconciliation.java
 Wed Apr 02 17:57:02 2014 +0530
@@ -25,8 +25,10 @@
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -48,22 +50,27 @@
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
 import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.ad_forms.AcctServer;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.common.enterprise.DocumentType;
+import 
org.openbravo.model.financialmgmt.accounting.FIN_FinancialAccountAccounting;
 import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
+import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
 import org.openbravo.model.financialmgmt.payment.FIN_Reconciliation;
 import org.openbravo.model.financialmgmt.payment.FIN_ReconciliationLine_v;
+import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class Reconciliation extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
   private AdvPaymentMngtDao dao;
+  Set<FIN_FinaccTransaction> transactionsToBePosted = new 
HashSet<FIN_FinaccTransaction>();
 
   public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
@@ -200,6 +207,7 @@
       if (process) { // Validations
         String strMessage = "";
         boolean raiseException = false;
+
         if (new BigDecimal(strDifference).compareTo(BigDecimal.ZERO) != 0) {
           strMessage = "@APRM_ReconciliationDiscrepancy@" + " " + 
strDifference;
           raiseException = true;
@@ -236,10 +244,11 @@
 
         boolean orgLegalWithAccounting = 
FIN_Utility.periodControlOpened(reconciliation.TABLE_NAME,
             reconciliation.getId(), reconciliation.TABLE_NAME + "_ID", "LE");
-        if (!FIN_Utility.isPeriodOpen(reconciliation.getClient().getId(),
-            AcctServer.DOCTYPE_Reconciliation, 
reconciliation.getOrganization().getId(),
-            strStatementDate)
-            && orgLegalWithAccounting) {
+        boolean documentEnabled = getDocumentConfirmation(this, 
reconciliation.getId());
+        if (documentEnabled
+            && !FIN_Utility.isPeriodOpen(reconciliation.getClient().getId(),
+                AcctServer.DOCTYPE_Reconciliation, 
reconciliation.getOrganization().getId(),
+                strStatementDate) && orgLegalWithAccounting) {
           msg.setType("Error");
           msg.setTitle(Utility.messageBD(this, "Error", vars.getLanguage()));
           msg.setMessage(Utility.parseTranslation(this, vars, 
vars.getLanguage(),
@@ -250,7 +259,7 @@
           return;
         }
 
-        if (orgLegalWithAccounting) {
+        if (documentEnabled && orgLegalWithAccounting) {
           String identifier = 
linesInNotAvailablePeriod(reconciliation.getId());
           if (!identifier.equalsIgnoreCase("")) {
             msg.setType("Error");
@@ -552,4 +561,100 @@
 
   }
 
+  public List<FIN_FinaccTransaction> getTransactionList(FIN_Reconciliation 
reconciliation) {
+    OBContext.setAdminMode();
+    List<FIN_FinaccTransaction> transactions = null;
+    try {
+      OBCriteria<FIN_FinaccTransaction> trans = 
OBDal.getInstance().createCriteria(
+          FIN_FinaccTransaction.class);
+      trans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_RECONCILIATION, 
reconciliation));
+      trans.setFilterOnReadableClients(false);
+      trans.setFilterOnReadableOrganization(false);
+      transactions = trans.list();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return transactions;
+  }
+
+  /*
+   * Checks if this step (Reconciliation) is configured to generate accounting 
for the selected
+   * financial account
+   */
+  public boolean getDocumentConfirmation(ConnectionProvider conn, String 
strRecordId) {
+    OBContext.setAdminMode();
+    try {
+      FIN_Reconciliation reconciliation = 
OBDal.getInstance().get(FIN_Reconciliation.class,
+          strRecordId);
+      List<FIN_FinaccTransaction> transactions = 
getTransactionList(reconciliation);
+      List<FIN_FinancialAccountAccounting> accounts = 
reconciliation.getAccount()
+          .getFINFinancialAccountAcctList();
+      for (FIN_FinaccTransaction transaction : transactions) {
+        FIN_Payment payment = transaction.getFinPayment();
+        // If payment exists, check Payment Method + financial Account 
Configuration
+        if (payment != null) {
+          OBCriteria<FinAccPaymentMethod> obCriteria = 
OBDal.getInstance().createCriteria(
+              FinAccPaymentMethod.class);
+          obCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT,
+              reconciliation.getAccount()));
+          
obCriteria.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD,
+              payment.getPaymentMethod()));
+          obCriteria.setFilterOnReadableClients(false);
+          obCriteria.setFilterOnReadableOrganization(false);
+          List<FinAccPaymentMethod> lines = obCriteria.list();
+          for (FIN_FinancialAccountAccounting account : accounts) {
+            if (payment.isReceipt()) {
+              if (("INT").equals(lines.get(0).getINUponClearingUse())
+                  && account.getInTransitPaymentAccountIN() != null) {
+                transactionsToBePosted.add(transaction);
+              } else if (("DEP").equals(lines.get(0).getINUponClearingUse())
+                  && account.getDepositAccount() != null) {
+                transactionsToBePosted.add(transaction);
+              } else if (("CLE").equals(lines.get(0).getINUponClearingUse())
+                  && account.getClearedPaymentAccount() != null) {

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to