David,

after some more study about this I think that there are some things that should still be fixed.

Right now the billingAccountId is stored in the OrderHeader, then propagated to the Invoice header and finally (with my last patch) to the PaymentApplications applied to the invoice. However, in my opinion we can remove the billingAccountId field from the PaymentApplication entity because it is superfluous. We should instead add it to the Payment entity, in order to implement the ability to accept payments and associate them to a billing account (before the invoices are created, for example). Right now, if we need to store a payment before the invoice is created and we want to associate it to a billing account we do the following:
1) we create a Payment
2) we create a PaymentApplication (for the same amount) and associate it to the billing account In my opinion this is not completely correct, because we are not really applying a payment to something real like an invoice (we just need to associate it to the billing account); in fact, for example, the same payment could be used later to pay two different invoives associated to the billing account and so the original PaymentApplication entry would be wrong.

To summarize, here is what I propose:

a) remove the field PaymentApplication.billingAccountId
b) add the field Payment.billingAccountId
c) add the following constraint: a payment and an invoice associated to two different billing accounts cannot be matched; the application of a payment with null billingAccountId to an invoice associated to a billing account is ok
d) in the balance of a billing account we should simply consider:
d1) all the open amount of the invoices associated to the billing account (-) d2) the unapplied amount of all the payments associated to the billing account

Does it make sense?

Jacopo





David E Jones wrote:

Thanks for taking care of this Jacopo.

-David


On Dec 12, 2006, at 1:18 AM, [EMAIL PROTECTED] wrote:

Author: jacopoc
Date: Tue Dec 12 00:18:38 2006
New Revision: 486056

URL: http://svn.apache.org/viewvc?view=rev&rev=486056
Log:
If a Invoice is applied to a BillingAccount, Payment should be applied to Invoice and also set BillingAccountId in PaymentApplication record. So that the total Invoice amount and Payment amount whould balance for a BillingAccount number. For details, see the interesting discussion here http://www.mail-archive.com/[email protected]/msg00970.html

Modified:
incubator/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml

Modified: incubator/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml?view=diff&rev=486056&r1=486055&r2=486056 ============================================================================== --- incubator/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml (original) +++ incubator/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml Tue Dec 12 00:18:38 2006
@@ -131,6 +131,9 @@
<log level="warning" message="Create Payment Application: Amount to apply [${paymentAppl.amountApplied}] is greater than the outstanding amount [${notApplied}] of the invoice [${invoice.invoiceId}]. Creating Payment Application for outstanding amount [${notApplied}] instead."/> <set field="paymentAppl.amountApplied" from-field="notApplied"/>
             </if-compare-field>
+            <if-not-empty field-name="invoice.billingAccountId">
+ <set field="paymentAppl.billingAccountId" from-field="invoice.billingAccountId"/>
+            </if-not-empty>
         </if-not-empty>

<sequenced-id-to-env sequence-name="PaymentApplication" env-name="paymentAppl.paymentApplicationId"/>



Reply via email to