svn commit: r702894 - in /ofbiz/trunk/applications/accounting: src/org/ofbiz/accounting/payment/ webapp/accounting/WEB-INF/actions/invoice/ webapp/accounting/WEB-INF/actions/payment/ webapp/accounting/invoice/ widget/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r702894 - in /ofbiz/trunk/applications/accounting: src/org/ofbiz/accounting/payment/ webapp/accounting/WEB-INF/actions/invoice/ webapp/accounting/WEB-INF/actions/payment/ webapp/accounting/invoice/ widget/

hansbak-2
Author: hansbak
Date: Wed Oct  8 07:39:12 2008
New Revision: 702894

URL: http://svn.apache.org/viewvc?rev=702894&view=rev
Log:
fix an error in applying payments to invoices and make applying invoices to payment work too when there are different currencies

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/ListNotAppliedInvoices.groovy
    ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml
    ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml
    ofbiz/trunk/applications/accounting/widget/PaymentScreens.xml

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java?rev=702894&r1=702893&r2=702894&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java Wed Oct  8 07:39:12 2008
@@ -292,7 +292,22 @@
         return getPaymentAppliedBd(payment).doubleValue();
     }
 
+    /**
+     * Method to return the total amount of an payment which is applied to a payment
+     * @param payment GenericValue object of the Payment
+     * @return the applied total as BigDecimal in the currency of the payment
+     */
     public static BigDecimal getPaymentAppliedBd(GenericValue payment) {
+     return getPaymentAppliedBd(payment, false);
+    }
+    
+    /**
+     * Method to return the total amount of an payment which is applied to a payment
+     * @param payment GenericValue object of the Payment
+     * @param false for currency of the payment, true for the actual currency
+     * @return the applied total as BigDecimal in the currency of the payment
+     */
+    public static BigDecimal getPaymentAppliedBd(GenericValue payment, boolean actual) {
         BigDecimal paymentApplied = BigDecimal.ZERO;
         List paymentApplications = null;
         try {
@@ -306,20 +321,20 @@
                 Iterator p = paymentApplications.iterator();
                 while (p.hasNext()) {
                     GenericValue paymentApplication = (GenericValue) p.next();
-                       BigDecimal amountApplied = paymentApplication.getBigDecimal("amountApplied");
+                    BigDecimal amountApplied = paymentApplication.getBigDecimal("amountApplied");
                     // check currency invoice and if different convert amount applied for display
-                    if (paymentApplication.get("invoiceId") != null && payment.get("actualCurrencyAmount") != null && payment.get("actualCurrencyUomId") != null) {
+                    if (!actual && paymentApplication.get("invoiceId") != null && payment.get("actualCurrencyAmount") != null && payment.get("actualCurrencyUomId") != null) {
                         GenericValue invoice = paymentApplication.getRelatedOne("Invoice");
                         if (payment.getString("actualCurrencyUomId").equals(invoice.getString("currencyUomId"))) {
                                amountApplied = amountApplied.multiply(payment.getBigDecimal("amount")).divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100));
                         }
                     }
-                       paymentApplied = paymentApplied.add(amountApplied).setScale(decimals,rounding);
+                    paymentApplied = paymentApplied.add(amountApplied).setScale(decimals,rounding);
                 }
             }
-           } catch (GenericEntityException e) {
-               Debug.logError(e, "Trouble getting entities", module);            
-           }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Trouble getting entities", module);            
+        }
         return paymentApplied;        
     }
     public static double getPaymentNotApplied(GenericValue payment) {

Modified: ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy?rev=702894&r1=702893&r2=702894&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/ListNotAppliedPayments.groovy Wed Oct  8 07:39:12 2008
@@ -24,70 +24,67 @@
 import org.ofbiz.accounting.invoice.*;
 import org.ofbiz.accounting.payment.*;
 import org.ofbiz.accounting.util.UtilAccounting;
-import java.text.DateFormat;
-import java.math.*;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.model.*;
-import java.text.NumberFormat;
+import java.math.*;
 
 invoiceId = parameters.invoiceId;
 invoice = delegator.findByPrimaryKey("Invoice", [invoiceId : invoiceId]);
 
 decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
 rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
-locale = context.locale;
 
-paymentsMapList = [];  // to pass back to the screeen list of unapplied payments
+exprList = [EntityCondition.makeCondition("partyIdTo", EntityOperator.EQUALS, invoice.partyIdFrom),
+            EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, invoice.partyId)];
+partyCond = EntityCondition.makeCondition(exprList, EntityOperator.AND);
+
+exprList1 = [EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_NOT_PAID"),
+                  EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_RECEIVED"),
+                  EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_SENT")];
+statusCond = EntityCondition.makeCondition(exprList1, EntityOperator.OR);
 
-// retrieve payments for the related parties which have not been (fully) applied yet
-payments = null;
-payment = null;
-exprList = [];
-expr = EntityCondition.makeCondition("partyIdTo", EntityOperator.EQUALS, invoice.getString("partyIdFrom"));
-exprList.add(expr);
-expr = EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, invoice.getString("partyId"));
-exprList.add(expr);
-
-// only payments with received and sent and not paid
-exprListStatus = [];
-expr = EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_NOT_PAID");
-exprListStatus.add(expr);
-expr = EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_RECEIVED");
-exprListStatus.add(expr);
-expr = EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_SENT");
-exprListStatus.add(expr);
-orCond = EntityCondition.makeCondition(exprListStatus, EntityOperator.OR);
-exprList.add(orCond);
+currCond = EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, invoice.currencyUomId);
+actualCurrCond = EntityCondition.makeCondition("actualCurrencyUomId", EntityOperator.EQUALS, invoice.currencyUomId);
 
-topCond = EntityCondition.makeCondition(exprList, EntityOperator.AND);
+topCond = EntityCondition.makeCondition([partyCond, statusCond, currCond], EntityOperator.AND);
+topCondActual = EntityCondition.makeCondition([partyCond, statusCond, actualCurrCond], EntityOperator.AND);
 
 payments = delegator.findList("Payment", topCond, null, ["effectiveDate"], null, false);
-if (payments)    {
-    paymentApplications = null;
-    paymentApplication = null;
-    invoiceApplied = InvoiceWorker.getInvoiceAppliedBd(invoice);
-    invoiceAmount = InvoiceWorker.getInvoiceTotalBd(invoice);
-    invoiceToApply = InvoiceWorker.getInvoiceNotApplied(invoice);
-    payments.each { payment ->
-        if (PaymentWorker.getPaymentNotAppliedBd(payment).signum() == 1) {
-           // put in the map
-           paymentMap = [:];
-           paymentMap.paymentId = payment.paymentId;
-           paymentMap.effectiveDate = payment.effectiveDate; // list as YYYY-MM-DD
-           paymentMap.amount = payment.amount;
-           paymentMap.currencyUomId = payment.currencyUomId;
-           paymentMap.amountApplied = PaymentWorker.getPaymentAppliedBd(payment);
-           paymentToApply = PaymentWorker.getPaymentNotAppliedBd(payment);
-           if (paymentToApply.compareTo(invoiceToApply) < 0 ) {
-                paymentMap.amountToApply = paymentToApply;
-           } else {
-                paymentMap.amountToApply = invoiceToApply;
-           }
-           paymentsMapList.add(paymentMap);
-        }
-    }
-}      
-context.payments = paymentsMapList;
+context.payments = getPayments(payments, false);
+payments = delegator.findList("Payment", topCondActual, null, ["effectiveDate"], null, false);
+context.paymentsActualCurrency = getPayments(payments, true);
+
+List getPayments(List payments, boolean actual) {
+ if (payments)    {
+ paymentList = [];  // to pass back to the screeen list of unapplied payments
+ invoiceApplied = InvoiceWorker.getInvoiceAppliedBd(invoice);
+ invoiceAmount = InvoiceWorker.getInvoiceTotalBd(invoice);
+ invoiceToApply = InvoiceWorker.getInvoiceNotApplied(invoice);
+ payments.each { payment ->
+ paymentMap = [:];
+            paymentApplied = PaymentWorker.getPaymentAppliedBd(payment, true);
+ if (actual) {
+ paymentMap.amount = payment.actualCurrencyAmount;
+ paymentMap.currencyUomId = payment.actualCurrencyUomId;
+ paymentToApply = payment.getBigDecimal("actualCurrencyAmount").setScale(decimals,rounding).subtract(paymentApplied);
+ } else {
+ paymentMap.amount = payment.amount;
+ paymentMap.currencyUomId = payment.currencyUomId;
+ paymentToApply = payment.getBigDecimal("amount").setScale(decimals,rounding).subtract(paymentApplied);
+ }
+ if (paymentToApply.signum() == 1) {
+ paymentMap.paymentId = payment.paymentId;
+ paymentMap.effectiveDate = payment.effectiveDate;
+ if (paymentToApply.compareTo(invoiceToApply) < 0 ) {
+ paymentMap.amountToApply = paymentToApply;
+ } else {
+ paymentMap.amountToApply = invoiceToApply;
+ }
+ paymentList.add(paymentMap);
+ }
+ }
+ return paymentList;
+ }
+}

Modified: ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/ListNotAppliedInvoices.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/ListNotAppliedInvoices.groovy?rev=702894&r1=702893&r2=702894&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/ListNotAppliedInvoices.groovy (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/ListNotAppliedInvoices.groovy Wed Oct  8 07:39:12 2008
@@ -38,7 +38,7 @@
 
 exprList = [EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, payment.partyIdFrom),
             EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, payment.partyIdTo)];
-partyCond = EntityCondition.makeCondition(exprList, EntityOperator.OR);
+partyCond = EntityCondition.makeCondition(exprList, EntityOperator.AND);
 
 exprList1 = [EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "INVOICE_APPROVED"),
              EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "INVOICE_SEND"),

Modified: ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml?rev=702894&r1=702893&r2=702894&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml Wed Oct  8 07:39:12 2008
@@ -425,6 +425,8 @@
             <submit button-type="button"/>
         </field>
     </form>
+
+    <form name="ListPaymentsNotAppliedForeignCurrency" extends="ListPaymentsNotApplied" list-name="paymentsActualCurrency"/>
     
     <form name="ListInvoiceRoles" type="list" use-row-submit="true" title="" list-name="invoiceRoles" paginate-target="invoiceRoles"
         odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar">

Modified: ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml?rev=702894&r1=702893&r2=702894&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml Wed Oct  8 07:39:12 2008
@@ -348,20 +348,9 @@
                                 <if-compare field-name="notAppliedAmount" operator="greater" value="0"/>
                             </condition>
                             <widgets>
-                                <container style="screenlet">
-                                    <container style="screenlet-title-bar">
-                                        <container style="h3">
-                                            <label text="${uiLabelMap.AccountingPaymentsApplied} ${appliedAmount?currency(${invoice.currencyUomId})} ${uiLabelMap.AccountingOpenPayments} ${notAppliedAmount?currency(${invoice.currencyUomId})}"/>
-                                        </container>
-                                    </container>
-                                    <container style="screenlet-body">
-                                        <section>
-                                            <widgets>    
-                                                <include-form name="EditInvoiceApplications" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
-                                            </widgets>
-                                        </section>
-                                    </container>
-                                </container>
+                                <screenlet title="${uiLabelMap.AccountingPaymentsApplied} ${appliedAmount?currency(${invoice.currencyUomId})} ${uiLabelMap.AccountingOpenPayments} ${notAppliedAmount?currency(${invoice.currencyUomId})}">
+                                   <include-form name="EditInvoiceApplications" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
+                                </screenlet>
                                 <section>
                                     <condition>
                                         <if-empty field-name="invoiceApplications"/>
@@ -372,23 +361,30 @@
                                 </section>
                                 <section>
                                     <condition>
-                                        <not><if-empty field-name="payments"/></not>
+                                        <or>
+                                            <not><if-empty field-name="payments"/></not>
+                                            <not><if-empty field-name="paymentsActualCurrency"/></not>
+                                        </or>
                                     </condition>
                                     <widgets>
-                                        <container style="screenlet">
-                                            <container style="screenlet-title-bar">
-                                                <container style="h3">
-                                                    <label text="${uiLabelMap.AccountingListPaymentsNotYetApplied} [${invoice.partyIdFrom}] ${uiLabelMap.AccountingPaymentSentForm} [${invoice.partyId}]"/>
-                                                </container>
-                                            </container>
-                                            <container style="screenlet-body">
-                                                <section>
-                                                    <widgets>    
-                                                        <include-form name="ListPaymentsNotApplied" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
-                                                    </widgets>
-                                                </section>
-                                            </container>
-                                        </container>
+                                        <screenlet title="${uiLabelMap.AccountingListPaymentsNotYetApplied} [${invoice.partyIdFrom}] ${uiLabelMap.AccountingPaymentSentForm} [${invoice.partyId}]">
+                                        <section>
+                                            <condition>
+                                                <not><if-empty field-name="payments"/></not>
+                                            </condition>
+                                            <widgets>
+                                                <include-form name="ListPaymentsNotApplied" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
+                                            </widgets>
+                                        </section>
+                                        <section>
+                                            <condition>
+                                                <not><if-empty field-name="paymentsActualCurrency"/></not>
+                                            </condition>
+                                            <widgets>
+                                                <include-form name="ListPaymentsNotAppliedForeignCurrency" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
+                                            </widgets>
+                                        </section>
+                                        </screenlet>
                                     </widgets>
                                 </section>
                                 <container style="screenlet">
@@ -407,20 +403,9 @@
                                 </container>
                             </widgets>
                             <fail-widgets>
-                                <container style="screenlet">
-                                    <container style="screenlet-title-bar">
-                                        <container style="h3">
-                                            <label text="${uiLabelMap.AccountingPaymentsApplied} ${appliedAmount?currency(${invoice.currencyUomId})}  ${uiLabelMap.AccountingOpenPayments} ${notAppliedAmount?currency(${invoice.currencyUomId})}"/>
-                                        </container>
-                                    </container>
-                                    <container style="screenlet-body">
-                                        <section>
-                                            <widgets>    
-                                                <include-form name="EditInvoiceApplications" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
-                                            </widgets>
-                                        </section>
-                                    </container>
-                                </container>
+                                <screenlet title="${uiLabelMap.AccountingPaymentsApplied} ${appliedAmount?currency(${invoice.currencyUomId})}  ${uiLabelMap.AccountingOpenPayments} ${notAppliedAmount?currency(${invoice.currencyUomId})}">
+                                    <include-form name="EditInvoiceApplications" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/>
+                                </screenlet>
                                 <section>
                                     <condition>
                                         <if-empty field-name="invoiceApplications"/>

Modified: ofbiz/trunk/applications/accounting/widget/PaymentScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/PaymentScreens.xml?rev=702894&r1=702893&r2=702894&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/PaymentScreens.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/PaymentScreens.xml Wed Oct  8 07:39:12 2008
@@ -253,7 +253,10 @@
                             <widgets>
                                 <section>
                                     <condition>
-                                        <not><if-empty field-name="invoices"/></not>
+                                        <or>
+                                            <not><if-empty field-name="invoices"/></not>
+                                            <not><if-empty field-name="invoicesOtherCurrency"/></not>
+                                        </or>
                                     </condition>
                                     <widgets>
                                         <screenlet title="${uiLabelMap.AccountingListInvoicesNotYetApplied}">
@@ -261,24 +264,23 @@
                                                 <label style="h2" text="${uiLabelMap.CommonFrom} ${partyNameViewTo.groupName}${partyNameViewTo.lastName},${partyNameViewTo.firstName} ${partyNameViewTo.middleName}[${payment.partyIdTo}]"/>
                                                 <label style="h2" text="${uiLabelMap.CommonTo} ${partyNameViewFrom.groupName}${partyNameViewFrom.lastName},${partyNameViewFrom.firstName} ${partyNameViewFrom.middleName} [${payment.partyIdFrom}]"/>
                                             </container>
-                                            <include-form name="listInvoicesNotApplied" location="component://accounting/webapp/accounting/payment/PaymentForms.xml"/>
-                                        </screenlet>
-                                    </widgets>
-                                </section>
-                                <section>
-                                    <condition>
-                                        <not><if-empty field-name="invoicesOtherCurrency"/></not>
-                                    </condition>
-                                    <widgets>
-                                        <screenlet title="${uiLabelMap.AccountingListInvoicesNotYetApplied}">
-                                            <container>
-                                                <label style="h1" text="Othercurrency invoices"/>
-                                            </container>
-                                            <container>
-                                                <label style="h2" text="${uiLabelMap.CommonFrom} ${partyNameViewTo.groupName}${partyNameViewTo.lastName},${partyNameViewTo.firstName} ${partyNameViewTo.middleName}[${payment.partyIdTo}]"/>
-                                                <label style="h2" text="${uiLabelMap.CommonTo} ${partyNameViewFrom.groupName}${partyNameViewFrom.lastName},${partyNameViewFrom.firstName} ${partyNameViewFrom.middleName} [${payment.partyIdFrom}]"/>
-                                            </container>
-                                            <include-form name="listInvoicesNotAppliedOtherCurrency" location="component://accounting/webapp/accounting/payment/PaymentForms.xml"/>
+                                            <section>
+                                                <condition>
+                                                    <not><if-empty field-name="invoices"/></not>
+                                                </condition>
+                                                <widgets>
+                                                    <include-form name="listInvoicesNotApplied" location="component://accounting/webapp/accounting/payment/PaymentForms.xml"/>
+                                                </widgets>
+                                            </section>
+                                            <section>
+                                                <condition>
+                                                    <not><if-empty field-name="invoicesOtherCurrency"/></not>
+                                                </condition>
+                                                <widgets>
+                                                    <label style="h2" text="Othercurrency invoices"/>
+                                                    <include-form name="listInvoicesNotAppliedOtherCurrency" location="component://accounting/webapp/accounting/payment/PaymentForms.xml"/>
+                                                </widgets>
+                                            </section>
                                         </screenlet>
                                     </widgets>
                                 </section>