One last detail I'd like to specify about the following point is:

> 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

is that "if a payment has the billing account id set, then it can only be applied to invoices associated to the same billing account"

Jacopo

Jacopo Cappellato wrote:
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




Reply via email to