details:   /erp/devel/pi/rev/cb637323ec52
changeset: 10678:cb637323ec52
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Tue Feb 15 18:30:10 2011 +0100
summary:   Adds document confirmation for bank statement posting

details:   /erp/devel/pi/rev/ece6083f11a6
changeset: 10679:ece6083f11a6
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Tue Feb 15 20:00:55 2011 +0100
summary:   fixes possible null pointer

details:   /erp/devel/pi/rev/003af63c9415
changeset: 10680:003af63c9415
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Tue Feb 15 20:01:28 2011 +0100
summary:   Adds on delete rule: cascade for payment run

details:   /erp/devel/pi/rev/81709a224b1f
changeset: 10681:81709a224b1f
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Tue Feb 15 20:05:02 2011 +0100
summary:   Fixes bug 15991: Cancel button inside matching againts bankstatement 
implements no logic + Modigies some labels for amount fields inside bank 
statement line tab

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html
 |    2 +-
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java
 |  308 ++++-
 src-db/database/model/tables/FIN_PAYMENT_RUN_PAYMENT.xml                       
                             |    2 +-
 src-db/database/model/tables/FIN_RECLINE_TEMP.xml                              
                             |   92 +
 src-db/database/sourcedata/AD_COLUMN.xml                                       
                             |  537 +++++++++-
 src-db/database/sourcedata/AD_ELEMENT.xml                                      
                             |   66 +-
 src-db/database/sourcedata/AD_FIELD.xml                                        
                             |   12 +-
 src-db/database/sourcedata/AD_TABLE.xml                                        
                             |   20 +
 src/org/openbravo/erpCommon/ad_forms/DocFINBankStatement.java                  
                             |   12 +-
 9 files changed, 986 insertions(+), 65 deletions(-)

diffs (truncated from 1359 to 300 lines):

diff -r bffcb013674f -r 81709a224b1f 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html
       Tue Feb 15 19:52:21 2011 +0100
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.html
       Tue Feb 15 20:05:02 2011 +0100
@@ -576,7 +576,7 @@
                   <button type="button"
                     id="buttonCancel"
                     class="ButtonLink"
-                    onclick="closeThisPage();return false;"
+                    onclick="submitThisPage('CANCEL');return false;"
                     onfocus="buttonEvent('onfocus', this); 
window.status='Cancel'; return true;"
                     onblur="buttonEvent('onblur', this);"
                     onkeyup="buttonEvent('onkeyup', this);"
diff -r bffcb013674f -r 81709a224b1f 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java
       Tue Feb 15 19:52:21 2011 +0100
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java
       Tue Feb 15 20:05:02 2011 +0100
@@ -24,6 +24,7 @@
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 import javax.servlet.ServletException;
@@ -36,11 +37,13 @@
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.dao.MatchTransactionDao;
 import org.openbravo.advpaymentmngt.dao.TransactionsDao;
+import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
 import org.openbravo.advpaymentmngt.utility.FIN_MatchedTransaction;
 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;
 import org.openbravo.base.session.OBPropertiesProvider;
@@ -48,16 +51,25 @@
 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.FieldProviderFactory;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.financialmgmt.payment.FIN_BankStatementLine;
 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_PaymentMethod;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
 import org.openbravo.model.financialmgmt.payment.FIN_Reconciliation;
+import org.openbravo.model.financialmgmt.payment.FIN_ReconciliationLineTemp;
 import org.openbravo.model.financialmgmt.payment.FIN_ReconciliationLine_v;
 import org.openbravo.model.financialmgmt.payment.MatchingAlgorithm;
+import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class MatchTransaction extends HttpSecureAppServlet {
@@ -91,6 +103,7 @@
           OBContext.restorePreviousMode();
         }
       }
+      getSnapShot(reconciliation);
       if (MatchTransactionDao.getUnMatchedBankStatementLines(account).size() 
== 0
           && reconciledItems == 0) {
         OBError message = Utility.translateError(this, vars, 
vars.getLanguage(), Utility
@@ -137,6 +150,15 @@
           .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("SAVE", "RECONCILE")) {
       OBContext.setAdminMode();
       try {
@@ -389,56 +411,15 @@
 
   private void unMatchBankStatementLine(HttpServletResponse response,
       String strUnmatchBankStatementLineId) throws IOException, 
ServletException {
-
-    OBContext.setAdminMode();
     try {
-      FIN_BankStatementLine bsline = 
OBDal.getInstance().get(FIN_BankStatementLine.class,
-          strUnmatchBankStatementLineId);
-
-      FIN_FinaccTransaction finTrans = bsline.getFinancialAccountTransaction();
-      if (finTrans != null) {
-        finTrans.setReconciliation(null);
-        bsline.setFinancialAccountTransaction(null);
-        OBDal.getInstance().save(finTrans);
-        OBDal.getInstance().flush();
-      }
-      bsline.setMatchingtype(null);
-      OBDal.getInstance().save(bsline);
-      OBDal.getInstance().flush();
-
-      if (finTrans != null) {
-        if (finTrans.getFinPayment() != null) {
-          finTrans.getFinPayment().setStatus(
-              (finTrans.getFinPayment().isReceipt()) ? "RDNC" : "PWNC");
-        }
-        boolean isReceipt = false;
-        if (finTrans.getFinPayment() != null) {
-          isReceipt = finTrans.getFinPayment().isReceipt();
-        } else {
-          isReceipt = 
finTrans.getDepositAmount().compareTo(finTrans.getPaymentAmount()) > 0;
-        }
-        finTrans.setStatus(isReceipt ? "RDNC" : "PWNC");
-        finTrans.setReconciliation(null);
-        OBDal.getInstance().save(finTrans);
-        OBDal.getInstance().flush();
-      }
-
-      // Execute un-matching logic defined by algorithm
-      MatchingAlgorithm ma = 
bsline.getBankStatement().getAccount().getMatchingAlgorithm();
-      FIN_MatchingTransaction matchingTransaction = new 
FIN_MatchingTransaction(ma
-          .getJavaClassName());
-      matchingTransaction.unmatch(finTrans);
-
+      unmatch(OBDal.getInstance().get(FIN_BankStatementLine.class, 
strUnmatchBankStatementLineId));
       response.setContentType("text/html; charset=UTF-8");
       PrintWriter out = response.getWriter();
       out.println("");
       out.close();
     } catch (Exception e) {
       throw new OBException(e);
-    } finally {
-      OBContext.restorePreviousMode();
     }
-
   }
 
   private FieldProvider[] getMatchedBankStatementLinesData(VariablesSecureApp 
vars,
@@ -612,6 +593,249 @@
     }
   }
 
+  private void getSnapShot(FIN_Reconciliation reconciliation) {
+    // First remove old temp info if exists
+    OBContext.setAdminMode();
+    try {
+      List<FIN_ReconciliationLineTemp> oldTempLines = reconciliation
+          .getFINReconciliationLineTempList();
+      for (FIN_ReconciliationLineTemp oldtempLine : oldTempLines) {
+        OBDal.getInstance().remove(oldtempLine);
+        OBDal.getInstance().flush();
+      }
+      // Now copy info taken from the reconciliation when first opened
+      List<FIN_ReconciliationLine_v> reconciledlines = reconciliation
+          .getFINReconciliationLineVList();
+      for (FIN_ReconciliationLine_v reconciledLine : reconciledlines) {
+        FIN_ReconciliationLineTemp lineTemp = OBProvider.getInstance().get(
+            FIN_ReconciliationLineTemp.class);
+        lineTemp.setClient(reconciledLine.getClient());
+        lineTemp.setOrganization(reconciledLine.getOrganization());
+        lineTemp.setReconciliation(reconciledLine.getReconciliation());
+        lineTemp.setBankStatementLine(reconciledLine.getBankStatementLine());
+        if (reconciledLine.getFinancialAccountTransaction() != null
+            && 
reconciledLine.getFinancialAccountTransaction().isCreatedByAlgorithm()) {
+          if (reconciledLine.getFinancialAccountTransaction().getFinPayment() 
!= null
+              && 
!reconciledLine.getFinancialAccountTransaction().getFinPayment()
+                  .isCreatedByAlgorithm()) {
+            lineTemp.setPayment(reconciledLine.getPayment());
+          } else if 
(reconciledLine.getFinancialAccountTransaction().getFinPayment()
+              
.getFINPaymentDetailList().get(0).getFINPaymentScheduleDetailList() != null
+              && 
reconciledLine.getFinancialAccountTransaction().getFinPayment()
+                  
.getFINPaymentDetailList().get(0).getFINPaymentScheduleDetailList().size() > 0
+              && 
(reconciledLine.getFinancialAccountTransaction().getFinPayment()
+                  
.getFINPaymentDetailList().get(0).getFINPaymentScheduleDetailList().get(0)
+                  .getInvoicePaymentSchedule() != null || reconciledLine
+                  
.getFinancialAccountTransaction().getFinPayment().getFINPaymentDetailList()
+                  
.get(0).getFINPaymentScheduleDetailList().get(0).getOrderPaymentSchedule() != 
null)) {
+            
lineTemp.setPaymentScheduleDetail(reconciledLine.getFinancialAccountTransaction()
+                
.getFinPayment().getFINPaymentDetailList().get(0).getFINPaymentScheduleDetailList()
+                .get(0));
+          }
+        } else {
+          
lineTemp.setFinancialAccountTransaction(reconciledLine.getFinancialAccountTransaction());
+        }
+        if (reconciledLine.getFinancialAccountTransaction().getFinPayment() != 
null) {
+          
lineTemp.setPaymentDocumentno(reconciledLine.getFinancialAccountTransaction()
+              .getFinPayment().getDocumentNo());
+        }
+        lineTemp
+            
.setMatched(reconciledLine.getBankStatementLine().getFinancialAccountTransaction()
 != null);
+        
lineTemp.setMatchlevel(reconciledLine.getBankStatementLine().getMatchingtype());
+        OBDal.getInstance().save(lineTemp);
+        OBDal.getInstance().flush();
+      }
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private void restoreSnapShot(FIN_Reconciliation reconciliation) {
+    OBContext.setAdminMode();
+    List<FIN_BankStatementLine> tempBSL = new 
ArrayList<FIN_BankStatementLine>();
+    List<FIN_BankStatementLine> finalBSL = new 
ArrayList<FIN_BankStatementLine>();
+    try {
+      // First get the list of BSL which were reconciled at the beginning (L1)
+      List<FIN_ReconciliationLineTemp> oldTempLines = reconciliation
+          .getFINReconciliationLineTempList();
+      for (FIN_ReconciliationLineTemp oldTempLine : oldTempLines) {
+        tempBSL.add(oldTempLine.getBankStatementLine());
+      }
+      // Then get the list of BSL reconciled at last (L2)
+      List<FIN_ReconciliationLine_v> oldReconciliationLines = reconciliation
+          .getFINReconciliationLineVList();
+      for (FIN_ReconciliationLine_v oldReconciliationLine : 
oldReconciliationLines) {
+        finalBSL.add(oldReconciliationLine.getBankStatementLine());
+      }
+      // Unmatch L2-L1
+      finalBSL.removeAll(tempBSL);
+      unmatch(finalBSL);
+      // Match L1
+      match(reconciliation);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private void unmatch(List<FIN_BankStatementLine> toUnmatch) {
+    for (FIN_BankStatementLine bsl : toUnmatch) {
+      unmatch(bsl);
+    }
+  }
+
+  private void unmatch(FIN_BankStatementLine bsline) {
+    OBContext.setAdminMode();
+    try {
+      FIN_FinaccTransaction finTrans = bsline.getFinancialAccountTransaction();
+      if (finTrans != null) {
+        finTrans.setReconciliation(null);
+        bsline.setFinancialAccountTransaction(null);
+        OBDal.getInstance().save(finTrans);
+        OBDal.getInstance().flush();
+      }
+      bsline.setMatchingtype(null);
+      OBDal.getInstance().save(bsline);
+      OBDal.getInstance().flush();
+
+      if (finTrans != null) {
+        if (finTrans.getFinPayment() != null) {
+          finTrans.getFinPayment().setStatus(
+              (finTrans.getFinPayment().isReceipt()) ? "RDNC" : "PWNC");
+        }
+        boolean isReceipt = false;
+        if (finTrans.getFinPayment() != null) {
+          isReceipt = finTrans.getFinPayment().isReceipt();
+        } else {
+          isReceipt = 
finTrans.getDepositAmount().compareTo(finTrans.getPaymentAmount()) > 0;
+        }
+        finTrans.setStatus(isReceipt ? "RDNC" : "PWNC");
+        finTrans.setReconciliation(null);
+        OBDal.getInstance().save(finTrans);
+        OBDal.getInstance().flush();
+      }
+      // Execute un-matching logic defined by algorithm
+      MatchingAlgorithm ma = 
bsline.getBankStatement().getAccount().getMatchingAlgorithm();
+      FIN_MatchingTransaction matchingTransaction = new 
FIN_MatchingTransaction(ma
+          .getJavaClassName());
+      matchingTransaction.unmatch(finTrans);
+    } catch (Exception e) {
+      throw new OBException(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private void match(FIN_Reconciliation reconciliation) {
+    List<FIN_ReconciliationLineTemp> snapShotList = reconciliation
+        .getFINReconciliationLineTempList();
+    for (FIN_ReconciliationLineTemp toMatch : snapShotList) {
+      FIN_BankStatementLine bsl = toMatch.getBankStatementLine();
+      if (bsl.getFinancialAccountTransaction() != null) {
+        continue;
+      }
+      FIN_FinaccTransaction transaction = getTransactionFromTemp(toMatch);
+      bsl.setFinancialAccountTransaction(transaction);
+      bsl.setMatchingtype(toMatch.getMatchlevel());
+      transaction.setStatus("RPPC");
+      transaction.setReconciliation(reconciliation);
+      if (transaction.getFinPayment() != null) {
+        transaction.getFinPayment().setStatus("RPPC");
+      }
+      OBDal.getInstance().save(transaction);
+      OBDal.getInstance().save(bsl);
+      OBDal.getInstance().flush();

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to