Intended use of 'closed' field in cust_bill and friends. (1.4.0pre13)

baloo at gimpgirl.com baloo at gimpgirl.com
Sat May 25 05:58:44 PDT 2002


The API doc and schema both state it's set to Y when the books are closed.
http://www.sisd.com/freeside/list-archive/msg02165.html states that an
invoice is is open when not paid in full, or a payment when not applied in
full, or the equivalent for credits and refunds.

Looking at the source (*.cgi, FS::*.pm, and scripts, I can see the flag's
tested in a number of places, but I don't see it being set anywhere. Also,
search/cust_bill.cgi uses owed to select 'open' invoices.

Turning to the SQL interface in the webdemo (both are very useful for
exploring, BTW. Thanks for putting them in.), I get the following:

  select count(*) from cust_bill -> 86
  select count(*) from cust_bill where closed isnull -> 86
  select count(*) from cust_bill where closed notnull -> 0

which confirm my suspicion that the 'closed' field is unused, and that
'open' in that message means "owed/unapplied/credited > 0"(*), not 'closed
isnull or closed != "Y"'.

What am I missing? If 'closed' was meant to be used for "end of financial
year"-related stuff, or if it has no current or planned use and could
conceivably be used for that, what would be the missing pieces? Something
along the lines of the following SQL (untested, possibly ungrammatical)
comes to mind:

update cust_bill set closed = "Y"
  where date <= (timestamp for end of financial year)
    and charged = coalesce(sum(select amount from cust_credit_bill
                                 where cust_credit_bill.invnum =
                                       = cust_bill.invnum), 0)
                + coalesce(sum(select amount from cust_bill_pay
                                 where cust_bill_pay.invnum
                                       = cust_bill.invnum), 0)

and ditto with suitable changes for payments, credits, and refunds.

Any comments? Pats on the head? Flames?

(And before anyone asks, I'm not asking that out of idle curiosity.
Customer requested it. I'm willing to contribute whatever I end up using,
but I'd like the idea sanity-checked before I invest too much time in it.)

(*) BTW, there's no mention of a corresponding method for refunds in the
documentation, or anything in the source that looks like it. Oversight? Or
complete trust that although customers sometimes pay more than they owe,
accounts clerks never make that mistake? :-)




More information about the freeside-users mailing list