3 INSERT INTO money.grocery (usr,xact_start,billing_location,note)
4 SELECT DISTINCT ON (au.id)
6 lb.bill_date AS xact_start,
7 ou.id AS billing_location,
8 'Legacy Open Billing' AS note
10 JOIN actor.usr au ON (lb.user_key = au.id)
11 JOIN actor.org_unit ou ON (lb.library = ou.shortname)
12 WHERE lb.paid IS FALSE
13 ORDER BY au.id, lb.bill_key2;
15 INSERT INTO money.billing (xact,billing_ts,amount,billing_type,note)
17 lb.bill_date AS billing_ts,
18 (lb.balance / 100.0)::NUMERIC(6,2) AS amount,
19 lb.reason AS billing_type,
20 'TCN of Bib Record: ' || br.tcn_value AS note
22 JOIN money.grocery mg ON (lb.user_key = mg.usr)
23 JOIN actor.usr au ON (lb.user_key = au.id)
24 JOIN actor.org_unit ou ON (lb.library = ou.shortname)
25 LEFT JOIN biblio.record_entry br ON (lb.cat_key = br.id)
26 WHERE lb.paid IS FALSE;