details:   /erp/stable/2.50/rev/afd71978f9e3
changeset: 9394:afd71978f9e3
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Thu Apr 28 13:46:10 2011 +0200
summary:   Moves changes from 3.0 for payment posting

details:   /erp/stable/2.50/rev/e9dba1c74541
changeset: 9395:e9dba1c74541
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Thu Apr 28 16:11:16 2011 +0200
summary:   Moves changes from 3.0 for payment posting. Missing file

details:   /erp/stable/2.50/rev/6d609c8a9bc5
changeset: 9396:6d609c8a9bc5
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Mon May 02 18:30:54 2011 +0200
summary:   Fixes issue 16969: WAD validation for auxiliar inputs should be 
modified

diffstat:

 src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql |   22 +-
 src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java         |  108 
++++++++-
 src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java    |   20 +
 3 files changed, 122 insertions(+), 28 deletions(-)

diffs (236 lines):

diff -r b89aedcaf3d2 -r 6d609c8a9bc5 
src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql
--- a/src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql   Mon May 
02 10:14:57 2011 +0200
+++ b/src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql   Mon May 
02 18:30:54 2011 +0200
@@ -263,16 +263,18 @@
     <Sql>
       <![CDATA[
         select i.name as objectName, (select max(name) 
-                                       from AD_Module_DBPrefix p
-                                      where p.AD_Module_ID = i.AD_Module_ID) 
as expectedvalue
-          from ad_auxiliarInput i, AD_Module m
-         where i.ad_module_id != '0'
-           and m.ad_module_id = i.ad_module_id
-           and exists (select 1 
-                         from AD_Module_DBPrefix p
-                        where p.AD_Module_ID = i.AD_Module_ID
-                          and instr(upper(i.NAME), upper(p.name)||'_') != 1)
-           and (m.javapackage in ('1') or to_char('Y')=to_char(?))
+                                   from AD_Module_DBPrefix p
+                                  where p.AD_Module_ID = i.AD_Module_ID) as 
expectedvalue
+        from ad_auxiliarInput i, AD_Module m, AD_Tab t
+        where i.ad_module_id != '0'
+        and m.ad_module_id = i.ad_module_id
+        and t.ad_tab_id = i.ad_tab_id
+        and t.ad_module_id <> i.ad_module_id
+        and exists (select 1 
+                     from AD_Module_DBPrefix p
+                    where p.AD_Module_ID = i.AD_Module_ID
+                      and instr(upper(i.NAME), upper(p.name)||'_') != 1)
+        and (m.javapackage in ('1') or to_char('Y')=to_char(?))
       ]]>
     </Sql>
     <Field name="objecttype" value=""/>
diff -r b89aedcaf3d2 -r 6d609c8a9bc5 
src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java   Mon May 02 
10:14:57 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java   Mon May 02 
18:30:54 2011 +0200
@@ -39,6 +39,7 @@
 import org.openbravo.erpCommon.utility.FieldProviderFactory;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.model.common.enterprise.AcctSchemaTableDocType;
+import org.openbravo.model.common.invoice.Invoice;
 import 
org.openbravo.model.financialmgmt.accounting.FIN_FinancialAccountAccounting;
 import org.openbravo.model.financialmgmt.accounting.coa.AcctSchemaTable;
 import org.openbravo.model.financialmgmt.gl.GLItem;
@@ -49,7 +50,6 @@
 import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
 
 public class DocFINPayment extends AcctServer {
-
   private static final long serialVersionUID = 1L;
   static Logger log4j = Logger.getLogger(DocFINPayment.class);
 
@@ -125,13 +125,24 @@
       if (data[i] == null)
         continue;
       String Line_ID = data[i].getField("FIN_Payment_Detail_ID");
-      DocLine_FINPayment docLine = new DocLine_FINPayment(DocumentType, 
Record_ID, Line_ID);
-      docLine.loadAttributes(data[i], this);
-      docLine.setAmount(data[i].getField("Amount"));
-      docLine.setIsPrepayment(data[i].getField("isprepayment"));
-      docLine.setWriteOffAmt(data[i].getField("WriteOffAmt"));
-      docLine.setC_GLItem_ID(data[i].getField("C_GLItem_ID"));
-      list.add(docLine);
+      OBContext.setAdminMode();
+      try {
+        FIN_PaymentDetail detail = 
OBDal.getInstance().get(FIN_PaymentDetail.class, Line_ID);
+        DocLine_FINPayment docLine = new DocLine_FINPayment(DocumentType, 
Record_ID, Line_ID);
+        docLine.loadAttributes(data[i], this);
+        docLine.setAmount(data[i].getField("Amount"));
+        docLine.setIsPrepayment(data[i].getField("isprepayment"));
+        docLine.setWriteOffAmt(data[i].getField("WriteOffAmt"));
+        docLine.setC_GLItem_ID(data[i].getField("C_GLItem_ID"));
+        docLine
+            .setInvoice(detail.getFINPaymentScheduleDetailList() != null
+                && 
detail.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != 
null ? detail
+                
.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule().getInvoice()
+                : null);
+        list.add(docLine);
+      } finally {
+        OBContext.restorePreviousMode();
+      }
     }
     // Return Array
     DocLine_FINPayment[] dl = new DocLine_FINPayment[list.size()];
@@ -201,13 +212,25 @@
           bpAmount = new BigDecimal(bpAmount).add(new 
BigDecimal(line.WriteOffAmt)).toString();
         }
         if ("".equals(line.getC_GLItem_ID())) {
+          String bpAmountConverted = bpAmount;
+          Invoice invoice = line.getInvoice();
+          String strcCurrencyId = C_Currency_ID;
+          if (invoice != null && !C_Currency_ID.equals(as.m_C_Currency_ID)) {
+            String dateFormat = 
OBPropertiesProvider.getInstance().getOpenbravoProperties()
+                .getProperty("dateFormat.java");
+            SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat);
+            bpAmountConverted = convertAmount(bpAmount, isReceipt, DateAcct, 
outputFormat
+                .format(invoice.getAccountingDate()), C_Currency_ID, 
as.m_C_Currency_ID, line, as,
+                fact, Fact_Acct_Group_ID, conn);
+            strcCurrencyId = as.m_C_Currency_ID;
+          }
           fact
               .createLine(line,
                   getAccountBPartner((line.m_C_BPartner_ID == null || 
line.m_C_BPartner_ID
                       .equals("")) ? this.C_BPartner_ID : 
line.m_C_BPartner_ID, as, isReceipt,
-                      isPrepayment, conn), C_Currency_ID, (isReceipt ? "" : 
bpAmount),
-                  (isReceipt ? bpAmount : ""), Fact_Acct_Group_ID, 
nextSeqNo(SeqNo), DocumentType,
-                  conn);
+                      isPrepayment, conn), strcCurrencyId, (isReceipt ? "" : 
bpAmountConverted),
+                  (isReceipt ? bpAmountConverted : ""), Fact_Acct_Group_ID, 
nextSeqNo(SeqNo),
+                  DocumentType, conn);
         } else {
           fact.createLine(line, 
getAccountGLItem(OBDal.getInstance().get(GLItem.class,
               line.getC_GLItem_ID()), as, isReceipt, conn), C_Currency_ID, 
(isReceipt ? ""
@@ -271,11 +294,19 @@
   public boolean getDocumentConfirmation(ConnectionProvider conn, String 
strRecordId) {
     // Checks if this step is configured to generate accounting for the 
selected financial account
     boolean confirmation = false;
-    final String AWAITING_EXECUTION = "RPAE";
+    final String PAYMENT_RECEIVED = "RPR";
+    final String PAYMENT_MADE = "PPM";
+    final String DEPOSITED_NOT_CLEARED = "RDNC";
+    final String WITHDRAWN_NOT_CLEARED = "PWNC";
+    final String PAYMENT_CLEARED = "RPPC";
     OBContext.setAdminMode();
     try {
       FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, 
strRecordId);
-      if (!payment.getStatus().equals(AWAITING_EXECUTION)) {
+      // Posting can just happen if payment is in the right status
+      if (payment.getStatus().equals(PAYMENT_RECEIVED) || 
payment.getStatus().equals(PAYMENT_MADE)
+          || payment.getStatus().equals(DEPOSITED_NOT_CLEARED)
+          || payment.getStatus().equals(WITHDRAWN_NOT_CLEARED)
+          || payment.getStatus().equals(PAYMENT_CLEARED)) {
         OBCriteria<FinAccPaymentMethod> obCriteria = 
OBDal.getInstance().createCriteria(
             FinAccPaymentMethod.class);
         obCriteria.add(Expression.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, 
payment.getAccount()));
@@ -310,11 +341,8 @@
                 && account.getClearedPaymentAccountOUT() != null)
               confirmation = true;
           }
-          // For payments with Amount ZERO which consumes credit always create 
an entry for the
-          // consumption as no transaction will be created
-          if (payment.getGeneratedCredit().compareTo(ZERO) == 0
-              && payment.getUsedCredit().compareTo(ZERO) != 0
-              && payment.getAmount().compareTo(ZERO) == 0) {
+          // For payments with Amount ZERO always create an entry as no 
transaction will be created
+          if (payment.getAmount().compareTo(ZERO) == 0) {
             confirmation = true;
           }
         }
@@ -408,6 +436,50 @@
     return account;
   }
 
+  public String convertAmount(String Amount, boolean isReceipt, String 
mDateAcct,
+      String conversionDate, String C_Currency_ID_From, String 
C_Currency_ID_To, DocLine line,
+      AcctSchema as, Fact fact, String Fact_Acct_Group_ID, ConnectionProvider 
conn)
+      throws ServletException {
+    if (Amount == null || Amount.equals(""))
+      return "0";
+    if (C_Currency_ID_From.equals(C_Currency_ID_To))
+      return Amount;
+    else
+      MultiCurrency = true;
+    String Amt = getConvertedAmt(Amount, C_Currency_ID_From, C_Currency_ID_To, 
conversionDate, "",
+        AD_Client_ID, AD_Org_ID, conn);
+    if (log4j.isDebugEnabled())
+      log4j.debug("Amt:" + Amt);
+
+    String AmtTo = getConvertedAmt(Amount, C_Currency_ID_From, 
C_Currency_ID_To, mDateAcct, "",
+        AD_Client_ID, AD_Org_ID, conn);
+    if (log4j.isDebugEnabled())
+      log4j.debug("AmtTo:" + AmtTo);
+
+    BigDecimal AmtDiff = (new BigDecimal(AmtTo)).subtract(new BigDecimal(Amt));
+    if (log4j.isDebugEnabled())
+      log4j.debug("AmtDiff:" + AmtDiff);
+
+    if (log4j.isDebugEnabled()) {
+      log4j.debug("curr from:" + C_Currency_ID_From + " Curr to:" + 
C_Currency_ID_To + " convDate:"
+          + conversionDate + " DateAcct:" + mDateAcct);
+      log4j.debug("Amt:" + Amt + " AmtTo:" + AmtTo + " Diff:" + 
AmtDiff.toString());
+    }
+
+    if ((isReceipt && AmtDiff.compareTo(new BigDecimal("0.00")) == 1)
+        || (!isReceipt && AmtDiff.compareTo(new BigDecimal("0.00")) == -1)) {
+      fact.createLine(line, 
getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn),
+          C_Currency_ID_To, "", AmtDiff.abs().toString(), Fact_Acct_Group_ID, 
nextSeqNo(SeqNo),
+          DocumentType, conn);
+    } else {
+      fact.createLine(line, 
getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn),
+          C_Currency_ID_To, AmtDiff.abs().toString(), "", Fact_Acct_Group_ID, 
nextSeqNo(SeqNo),
+          DocumentType, conn);
+    }
+
+    return Amt;
+  }
+
   public String getSeqNo() {
     return SeqNo;
   }
diff -r b89aedcaf3d2 -r 6d609c8a9bc5 
src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java      Mon May 
02 10:14:57 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java      Mon May 
02 18:30:54 2011 +0200
@@ -19,6 +19,8 @@
 package org.openbravo.erpCommon.ad_forms;
 
 import org.apache.log4j.Logger;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.order.Order;
 
 public class DocLine_FINPayment extends DocLine {
   private static final Logger log4j = 
Logger.getLogger(DocLine_FINPayment.class);
@@ -29,6 +31,24 @@
   String isReceipt = "";
   String C_GLItem_ID = "";
   String isPrepayment = "";
+  Invoice invoice = null;
+  Order order = null;
+
+  public Invoice getInvoice() {
+    return invoice;
+  }
+
+  public void setInvoice(Invoice invoice) {
+    this.invoice = invoice;
+  }
+
+  public Order getOrder() {
+    return order;
+  }
+
+  public void setOrder(Order order) {
+    this.order = order;
+  }
 
   /**
    * @param isReceipt

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to