Login  Register

Re: Paying off invoices under a billing account

Posted by Bob Morley on Mar 15, 2010; 10:23pm
URL: http://ofbiz.116.s1.nabble.com/Paying-off-invoices-under-a-billing-account-tp1592863p1594116.html

Our standard use case here is retail POS; so billing account is used as a "line of credit" with high-end customers.  In our "POS" when they place an order we present the available payment methods.  If they have been approved for a billing account it shows up with their available balance.  Basically I am saying that when the teller is ringing the customer through they really have no notion of the Invoice at all; they just say "do you want to put this on account?"

I think if it was for a services sector where I am going to say give you a quote to do some lawn work, then ultimately invoice the customer I would definitely avoid the whole billing account situation.

After digging a bit more and talking with a co-worker, we elected to go a slightly different direction (in terms of the potential solutions I documented).  Effectively, it did not make sense that you calculate the balance or the available balance on the billing account based on orders.  It really should be based on non-applied balances on related invoices.  Effectively, I changed the main calculations in the BillingAccountWorker to work on this premise.

What this meant was I created four main balance methods:

getBalance = how much has the guy used (outstanding invoices +/- any adhoc pmt applications)
getReservedBalance = how much has the guy used/reserved (above plus amounts from open orders) **  
getAvailableBalance = limit - getBalance
getUnreservedBalance = limit - getReservedBalance (think how much can I put on the billing account if I complete all my reserved orders).

** I changed open orders to exclude completed orders; but these orders have cut an invoice that is now being included in the balance / available balance calcs.

After doing this I found that everything worked and calculated as expected; the only missing piece was that when an invoice is completely paid, the associated order payment preference was not moving from PAYMENT_NOT_RECEIVED to PAYMENT_RECEIVED.  I added this into the SECA that is invoked each time an invoice related payment application is created.  When it is moving to PAID I find those order payment preferences and mark them received.

Does anyone think I should patch up this work for review and potential inclusion?  I blasted through the existing Ofbiz artifacts and wired things up to my new method names which (my hope) are more clear than the batch that was there before.