You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2007/07/19 13:26:45 UTC

svn commit: r557579 - in /ofbiz/branches/release4.0/applications/accounting: config/AccountingUiLabels.properties src/org/ofbiz/accounting/invoice/InvoiceServices.java webapp/accounting/payment/PaymentForms.xml

Author: lektran
Date: Thu Jul 19 04:26:44 2007
New Revision: 557579

URL: http://svn.apache.org/viewvc?view=rev&rev=557579
Log:
Applied fix from trunk for revision: 556498

Modified:
    ofbiz/branches/release4.0/applications/accounting/config/AccountingUiLabels.properties
    ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
    ofbiz/branches/release4.0/applications/accounting/webapp/accounting/payment/PaymentForms.xml

Modified: ofbiz/branches/release4.0/applications/accounting/config/AccountingUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/accounting/config/AccountingUiLabels.properties?view=diff&rev=557579&r1=557578&r2=557579
==============================================================================
--- ofbiz/branches/release4.0/applications/accounting/config/AccountingUiLabels.properties (original)
+++ ofbiz/branches/release4.0/applications/accounting/config/AccountingUiLabels.properties Thu Jul 19 04:26:44 2007
@@ -582,7 +582,7 @@
 AccountingFromPartySameToParty=At least the 'from' party should be the same as the 'to' party of the other payment\n
 AccountingBillingAccountNotFound=Billing Account [${billingAccountId}] not found...\n
 AccountingBillingAccountBalanceNotFound=Billing Account [${billingAccountId}] balance not found...(\n"
-AccountingBillingAccountBalanceProblem=Billing Account [${billingAccountId}] doesn't have a positive balance: ${billingAccountApplyAvailable?currency(${isoCode})}\n
+AccountingBillingAccountBalanceProblem=Billing Account [${billingAccountId}] doesn't have a positive balance: ${billingAccountAvailableBalance?currency(${isoCode})}\n
 AccountingBillingAccountLessRequested=Billing Account [${billingAccountId}] has ${billingAccountApplyAvailable?currency(${isoCode})} to apply but ${amountApplied?currency(${isoCode})} is requested\n
 AccountingBillingAccountCurrencyProblem=Currencies are not the same, Billing Account [${billingAccountId}] has currency: ${accountCurrencyUomId} and Payment [${paymentId}] has currency: ${paymentCurrencyUomId}\n
 AccountingInvoiceNotFound=Invoice [${invoiceId}] record not found\n

Modified: ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?view=diff&rev=557579&r1=557578&r2=557579
==============================================================================
--- ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original)
+++ ofbiz/branches/release4.0/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Thu Jul 19 04:26:44 2007
@@ -2310,13 +2310,31 @@
             
             // check if at least one send is the same as one receiver on the other payment
             if (!payment.getString("partyIdFrom").equals(toPayment.getString("partyIdTo")) && 
-                    !payment.getString("partyIdFrom").equals(toPayment.getString("partyIdTo")))    {
+                    !payment.getString("partyIdTo").equals(toPayment.getString("partyIdFrom")))    {
                 errorMessageList.add(UtilProperties.getMessage(resource, "AccountingFromPartySameToParty", locale));
             }
 
             if (debug) Debug.logInfo("toPayment info retrieved and checked...", module);
         }
 
+        // assign payment to billing account if the invoice is assigned to this billing account
+        if (invoiceId != null) {
+            GenericValue invoice = null;
+            try {
+                invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId));
+            } catch (GenericEntityException e) {
+                ServiceUtil.returnError(e.getMessage());
+            }
+            
+            if (invoice == null) {
+                errorMessageList.add(UtilProperties.getMessage(resource, "AccountingInvoiceNotFound",UtilMisc.toMap("invoiceId",invoiceId),locale));
+            } else {
+                if (invoice.getString("billingAccountId") != null) {
+                    billingAccountId = invoice.getString("billingAccountId");
+                }
+            }
+        }
+        
         // billing account
         GenericValue billingAccount = null;
         BigDecimal billingAccountApplyAvailable = ZERO;
@@ -2329,36 +2347,6 @@
             if (billingAccount == null) {
                 errorMessageList.add(UtilProperties.getMessage(resource, "AccountingBillingAccountNotFound",UtilMisc.toMap("billingAccountId",billingAccountId), locale));
             }
-            
-            // Get the available balance, which is how much can be used, rather than the regular balance, which is how much has already been charged
-            try {
-                billingAccountApplyAvailable = BillingAccountWorker.availableToCapture(billingAccount);
-            } catch (GenericEntityException e) {
-                errorMessageList.add(UtilProperties.getMessage(resource, "AccountingBillingAccountBalanceNotFound",UtilMisc.toMap("billingAccountId",billingAccountId), locale));
-                ServiceUtil.returnError(e.getMessage());
-            }
-
-            if (paymentApplicationId == null) { 
-                // when creating a new PaymentApplication, check if there is sufficient balance in the billing account, but only if the invoiceId is not null
-                // If you create a PaymentApplication with both billingAccountId and invoiceId, then you're applying a billing account towards an invoice
-                // If you create a PaymentApplication just with billingAccountId and no invoiceId, then you're adding value to billing account, so it should not matter
-                // what the previous available balance is
-                if (invoiceId != null) {
-                    if (billingAccountApplyAvailable.signum() <= 0)  {
-                        errorMessageList.add(UtilProperties.getMessage(resource, "AccountingBillingAccountBalanceProblem",UtilMisc.toMap("billingAccountId",billingAccountId,"isoCode",billingAccount.getString("accountCurrencyUomId")), locale));
-                    } else {
-                        // check here for too much application if a new record is
-                        // added (paymentApplicationId == null)
-                        if (amountApplied.compareTo(billingAccountApplyAvailable) == 1) {
-                            errorMessageList.add(UtilProperties.getMessage(resource, "AccountingBillingAccountLessRequested",
-                                        UtilMisc.toMap("billingAccountId",billingAccountId, 
-                                            "billingAccountApplyAvailable",billingAccountApplyAvailable,
-                                            "amountApplied",amountApplied,"isoCode",billingAccount.getString("accountCurrencyUomId")),locale));
-                        }
-                    }
-                }
-            }
-
             // check the currency
             if (billingAccount.get("accountCurrencyUomId") != null && payment.get("currencyUomId") != null && 
                     !billingAccount.getString("accountCurrencyUomId").equals(payment.getString("currencyUomId"))) {
@@ -2386,8 +2374,7 @@
             
             if (invoice == null) {
                 errorMessageList.add(UtilProperties.getMessage(resource, "AccountingInvoiceNotFound",UtilMisc.toMap("invoiceId",invoiceId),locale));
-            }
-            else { // check the invoice and when supplied the invoice item...
+            } else { // check the invoice and when supplied the invoice item...
                 
                 if (invoice.getString("statusId").equals("INVOICE_CANCELLED")) {
                     errorMessageList.add(UtilProperties.getMessage(resource,"AccountingInvoiceCancelledCannotApplyTo",UtilMisc.toMap("invoiceId",invoiceId),locale));
@@ -2475,9 +2462,6 @@
         BigDecimal newInvoiceItemApplyAvailable = invoiceItemApplyAvailable; 
         // amount available on the invoiceItem taking into account if the itemnumber has changed
         BigDecimal newToPaymentApplyAvailable = toPaymentApplyAvailable; 
-        // amount available on the Billing Account taking into account if the billing account number has changed
-        BigDecimal newBillingAccountApplyAvailable = billingAccountApplyAvailable; 
-        // amount available on the Billing Account taking into account if the billing account number has changed
         BigDecimal newPaymentApplyAvailable = paymentApplyAvailable;
         GenericValue paymentApplication = null;
         if (paymentApplicationId == null) {
@@ -2601,24 +2585,6 @@
                     }
 
                 }
-                // check the billing account when only the amountApplied has
-                // changed,
-                // change in account number is already checked in the billing
-                // account section
-                if (billingAccountId != null && billingAccountId.equals(paymentApplication.getString("billingAccountId"))) {
-                    newBillingAccountApplyAvailable = billingAccountApplyAvailable.subtract(paymentApplication.getBigDecimal("amountApplied")).add(amountApplied).setScale(decimals, rounding);
-                    if (newBillingAccountApplyAvailable.compareTo(ZERO) < 0) {
-                        errorMessageList.add(UtilProperties.getMessage(resource, "AccountingBillingAccountNotEnough",UtilMisc.toMap("billingAccountId",billingAccountId,"newBillingAccountApplyAvailable",newBillingAccountApplyAvailable,"amountApplied",amountApplied,"isoCode", billingAccount.getString("accountCurrencyUomId")),locale));
-                    }
-                } else if (billingAccountId != null) {
-                    // billing account entered number has changed so we have to
-                    // check the new billing account number.
-                    newBillingAccountApplyAvailable = billingAccountApplyAvailable.add(amountApplied).setScale(decimals, rounding);
-                    if (newBillingAccountApplyAvailable.compareTo(ZERO) < 0) {
-                        errorMessageList.add(UtilProperties.getMessage(resource, "AccountingBillingAccountNotEnough",UtilMisc.toMap("billingAccountId",billingAccountId,"newBillingAccountApplyAvailable",newBillingAccountApplyAvailable,"amountApplied",amountApplied,"isoCode", billingAccount.getString("accountCurrencyUomId")),locale));
-                    }
-
-                }
             }
             if (debug) Debug.logInfo("paymentApplication record info retrieved and checked...", module);
         }
@@ -2640,10 +2606,6 @@
                 Debug.logInfo(" toPayment(" + toPaymentId + ") amount not yet applied: " + newToPaymentApplyAvailable + " Payment(" + paymentId + ") amount not yet applied: " + newPaymentApplyAvailable + " Requested amount to apply:" + amountApplied, module);
                 toMessage = UtilProperties.getMessage(resource, "AccountingApplicationToPayment",UtilMisc.toMap("paymentId",toPaymentId),locale);
             }
-            if (billingAccountId != null) {
-                Debug.logInfo(" billingAccount(" + billingAccountId + ") amount not yet applied: " + newBillingAccountApplyAvailable + " Payment(" + paymentId + ") amount not yet applied: " + newPaymentApplyAvailable + " Requested amount to apply:" + amountApplied, module);
-                toMessage = UtilProperties.getMessage(resource, "AccountingApplicationToBillingAccount",UtilMisc.toMap("billingAccountId",billingAccountId),locale);
-            }
             if (taxAuthGeoId != null) {
                 Debug.logInfo(" taxAuthGeoId(" + taxAuthGeoId + ")  Payment(" + paymentId + ") amount not yet applied: " + newPaymentApplyAvailable + " Requested amount to apply:" + amountApplied, module);
                 toMessage = UtilProperties.getMessage(resource, "AccountingApplicationToTax",UtilMisc.toMap("taxAuthGeoId",taxAuthGeoId),locale);
@@ -2656,7 +2618,7 @@
                 amountApplied = newInvoiceApplyAvailable;
                 toMessage = UtilProperties.getMessage(resource, "AccountingApplicationToInvoice",UtilMisc.toMap("invoiceId",invoiceId),locale);
             }
-            if (toPaymentId != null && newToPaymentApplyAvailable.compareTo(amountApplied) == 1) {
+            if (toPaymentId != null && newToPaymentApplyAvailable.compareTo(amountApplied) < 0) {
                 amountApplied = newToPaymentApplyAvailable;
                 toMessage = UtilProperties.getMessage(resource, "AccountingApplicationToPayment",UtilMisc.toMap("paymentId",toPaymentId),locale);
             }
@@ -2664,8 +2626,7 @@
         
         if (amountApplied.signum() == 0) {
             errorMessageList.add(UtilProperties.getMessage(resource, "AccountingNoAmount",locale));
-        }
-        else {
+        } else {
             successMessage = UtilProperties.getMessage(resource, "AccountingApplicationSuccess",UtilMisc.toMap("amountApplied",amountApplied,"paymentId",paymentId,"isoCode", payment.getString("currencyUomId"),"toMessage",toMessage),locale);
         }
         
@@ -2703,7 +2664,7 @@
                 paymentApplication.set("invoiceItemSeqId", null);
                 paymentApplication.set("toPaymentId", null);
                 paymentApplication.set("amountApplied", new Double(amountApplied.doubleValue()));
-                paymentApplication.set("billingAccountId", null);
+                paymentApplication.set("billingAccountId", billingAccountId);
                 paymentApplication.set("taxAuthGeoId", null);
                 if (debug) Debug.logInfo("creating new paymentapplication", module);
                 return storePaymentApplication(delegator, paymentApplication,locale);

Modified: ofbiz/branches/release4.0/applications/accounting/webapp/accounting/payment/PaymentForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/accounting/webapp/accounting/payment/PaymentForms.xml?view=diff&rev=557579&r1=557578&r2=557579
==============================================================================
--- ofbiz/branches/release4.0/applications/accounting/webapp/accounting/payment/PaymentForms.xml (original)
+++ ofbiz/branches/release4.0/applications/accounting/webapp/accounting/payment/PaymentForms.xml Thu Jul 19 04:26:44 2007
@@ -166,6 +166,7 @@
         <field name="paymentApplicationId"><hidden/></field>
         <field name="paymentId"><hidden/></field>
         <field name="billingAccountId"><lookup target-form-name="LookupBillingAccount"/></field>
+        <field name="invoiceId"><hidden/></field>
         <field name="amountApplied"><text size="15"/></field>
         <field name="updateButton" title="${uiLabelMap.CommonUpdate}" widget-style="buttontext"><submit button-type="text-link"/></field>
         <field name="removeButton" title="${uiLabelMap.CommonRemove}" widget-style="buttontext">