</actions>
</permacrud>
</class>
+ <class id="map" controller="open-ils.cstore open-ils.pcrud"
+ oils_obj:fieldmapper="money::aged_payment"
+ oils_persist:tablename="money.aged_payment"
+ reporter:label="Payments: Aged">
+ <fields oils_persist:primary="id" oils_persist:sequence="">
+ <field reporter:label="Amount" name="amount" reporter:datatype="money" />
+ <field reporter:label="Payment ID" name="id" reporter:datatype="id" />
+ <field reporter:label="Note" name="note" reporter:datatype="text"/>
+ <field reporter:label="Payment Date/Time" name="payment_ts" reporter:datatype="timestamp"/>
+ <field reporter:label="Payment Type" name="payment_type" reporter:datatype="text"/>
+ <field reporter:label="Aged Circulation" name="xact" reporter:datatype="link"/>
+ <field reporter:label="Voided?" name="voided" reporter:datatype="bool"/>
+ </fields>
+ <links>
+ <link field="xact" reltype="has_a" key="id" map="" class="acirc"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <retrieve permission="VIEW_USER_TRANSACTIONS">
+ <context link="xact" field="usr_home_ou"/>
+ </retrieve>
+ </actions>
+ </permacrud>
+ </class>
<class id="mbp" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="money::bnm_payment" oils_persist:tablename="money.bnm_payment_view" reporter:core="true" reporter:label="Payments: Brick-and-mortar">
<fields oils_persist:primary="id" oils_persist:sequence="">
<field reporter:label="Amount" name="amount" reporter:datatype="money" />
</actions>
</permacrud>
</class>
+ <class id="mab" controller="open-ils.cstore open-ils.pcrud"
+ oils_obj:fieldmapper="money::aged_billing"
+ oils_persist:tablename="money.aged_billing"
+ reporter:label="Aged Billing Line Item">
+ <fields oils_persist:primary="id" oils_persist:sequence="">
+ <field reporter:label="Amount" name="amount" reporter:datatype="money" />
+ <field reporter:label="Create Date" name="create_date" reporter:datatype="timestamp"/>
+ <field reporter:label="Billing Period Start" name="period_start" reporter:datatype="timestamp"/>
+ <field reporter:label="Billing Period End" name="period_end" reporter:datatype="timestamp"/>
+ <field reporter:label="Legacy Billing Timestamp" name="billing_ts" reporter:datatype="timestamp"/>
+ <field reporter:label="Legacy Billing Type" name="billing_type" reporter:datatype="text"/>
+ <field reporter:label="Billing ID" name="id" reporter:datatype="id" />
+ <field reporter:label="Note" name="note" reporter:datatype="text"/>
+ <field reporter:label="Void Timestamp" name="void_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Voided?" name="voided" reporter:datatype="bool"/>
+ <field reporter:label="Voiding Staff Member" name="voider" reporter:datatype="link"/>
+ <field reporter:label="Transaction" name="xact" reporter:datatype="link"/>
+ <field reporter:label="Type" name="btype" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="xact" reltype="has_a" key="id" map="" class="acirc"/>
+ <link field="voider" reltype="has_a" key="id" map="" class="au"/>
+ <link field="btype" reltype="has_a" key="id" map="" class="cbt"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <retrieve permission="VIEW_USER_TRANSACTIONS">
+ <context link="xact" field="usr_home_ou"/>
+ </retrieve>
+ </actions>
+ </permacrud>
+ </class>
<class id="pugm" controller="open-ils.cstore" oils_obj:fieldmapper="permission::usr_grp_map" oils_persist:tablename="permission.usr_grp_map" reporter:label="User Group Map">
<fields oils_persist:primary="id" oils_persist:sequence="permission.usr_grp_map_id_seq">
<field name="grp" />
--- /dev/null
+
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+\qecho Migrating aged billing and payment data. This might take a while.
+
+CREATE TABLE money.aged_payment (LIKE money.payment INCLUDING INDEXES);
+ALTER TABLE money.aged_payment ADD COLUMN payment_type TEXT NOT NULL;
+CREATE TABLE money.aged_billing (LIKE money.billing INCLUDING INDEXES);
+
+INSERT INTO money.aged_payment
+ SELECT mp.* FROM money.payment_view mp
+ JOIN action.aged_circulation circ ON (circ.id = mp.xact);
+
+INSERT INTO money.aged_billing
+ SELECT mb.* FROM money.billing mb
+ JOIN action.aged_circulation circ ON (circ.id = mb.xact);
+
+DELETE FROM money.payment WHERE id IN (
+ SELECT mp.id FROM money.payment mp
+ JOIN action.aged_circulation circ ON (circ.id = mp.xact)
+);
+
+DELETE FROM money.billing WHERE id IN (
+ SELECT mb.id FROM money.billing mb
+ JOIN action.aged_circulation circ ON (circ.id = mb.xact)
+);
+
+
+CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
+DECLARE
+found char := 'N';
+BEGIN
+
+ -- If there are any renewals for this circulation, don't archive or delete
+ -- it yet. We'll do so later, when we archive and delete the renewals.
+
+ SELECT 'Y' INTO found
+ FROM action.circulation
+ WHERE parent_circ = OLD.id
+ LIMIT 1;
+
+ IF found = 'Y' THEN
+ RETURN NULL; -- don't delete
+ END IF;
+
+ -- Archive a copy of the old row to action.aged_circulation
+
+ INSERT INTO action.aged_circulation
+ (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+ copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+ circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+ stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+ max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+ max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ)
+ SELECT
+ id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+ copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+ circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+ stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+ max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+ max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
+ FROM action.all_circulation WHERE id = OLD.id;
+
+ -- Migrate billings and payments to aged tables
+
+ INSERT INTO money.aged_billing
+ SELECT * FROM money.billing WHERE xact = OLD.id;
+
+ INSERT INTO money.aged_payment
+ SELECT * FROM money.payment_view WHERE xact = OLD.id;
+
+ DELETE FROM money.billing WHERE xact = OLD.id;
+ DELETE FROM money.payment WHERE xact = OLD.id;
+
+ RETURN OLD;
+END;
+$$ LANGUAGE 'plpgsql';
+
+COMMIT;
+