[open-ils-commits] [GIT] Evergreen ILS branch master updated. 589690affc8b0bc4c3464d77a6a55439f945cb72

Evergreen Git git at git.evergreen-ils.org
Thu Jan 5 17:39:32 EST 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  589690affc8b0bc4c3464d77a6a55439f945cb72 (commit)
       via  ee27d36a3121b409d17ba1016be93372a792c0d4 (commit)
      from  fa73a59f4b4cbc8d1c4bc1707c664bca555ecab8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 589690affc8b0bc4c3464d77a6a55439f945cb72
Author: Dan Scott <dscott at laurentian.ca>
Date:   Thu Jan 5 17:37:55 2012 -0500

    Wrap upgrade script for archivable stat cats
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 642048f..c08457d 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0662', :eg_version); -- berick/miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0663', :eg_version); -- tsbere/dbs
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/0663.schema.archive_circ_stat_cats.sql b/Open-ILS/src/sql/Pg/upgrade/0663.schema.archive_circ_stat_cats.sql
new file mode 100644
index 0000000..022b2dd
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0663.schema.archive_circ_stat_cats.sql
@@ -0,0 +1,96 @@
+-- Evergreen DB patch 0663.schema.archive_circ_stat_cats.sql
+--
+-- Enables users to set copy and patron stat cats to be archivable
+-- for the purposes of statistics even after the circs are aged.
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('0663', :eg_version);
+
+-- New tables
+
+CREATE TABLE action.archive_actor_stat_cat (
+    id          BIGSERIAL   PRIMARY KEY,
+    xact        BIGINT      NOT NULL,
+    stat_cat    INT         NOT NULL,
+    value       TEXT        NOT NULL
+);
+
+CREATE TABLE action.archive_asset_stat_cat (
+    id          BIGSERIAL   PRIMARY KEY,
+    xact        BIGINT      NOT NULL,
+    stat_cat    INT         NOT NULL,
+    value       TEXT        NOT NULL
+);
+
+-- Add columns to existing tables
+
+-- Archive Flag Columns
+ALTER TABLE actor.stat_cat
+    ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
+ALTER TABLE asset.stat_cat
+    ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
+
+-- Circulation copy column
+ALTER TABLE action.circulation
+    ADD COLUMN copy_location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location(id) DEFERRABLE INITIALLY DEFERRED;
+
+-- Update action.circulation with real copy_location numbers instead of all "Stacks"
+UPDATE action.circulation circ SET copy_location = ac.location FROM asset.copy ac WHERE ac.id = circ.target_copy;
+
+-- Create trigger function to auto-fill the copy_location field
+CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
+BEGIN
+    SELECT INTO NEW.copy_location location FROM asset.copy WHERE id = NEW.target_copy;
+    RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+-- Create trigger function to auto-archive stat cat entries
+CREATE OR REPLACE FUNCTION action.archive_stat_cats () RETURNS TRIGGER AS $$
+BEGIN
+    INSERT INTO action.archive_actor_stat_cat(xact, stat_cat, value)
+        SELECT NEW.id, asceum.stat_cat, asceum.stat_cat_entry
+        FROM actor.stat_cat_entry_usr_map asceum
+             JOIN actor.stat_cat sc ON asceum.stat_cat = sc.id
+        WHERE NEW.usr = asceum.target_usr AND sc.checkout_archive;
+    INSERT INTO action.archive_asset_stat_cat(xact, stat_cat, value)
+        SELECT NEW.id, ascecm.stat_cat, asce.value
+        FROM asset.stat_cat_entry_copy_map ascecm
+             JOIN asset.stat_cat sc ON ascecm.stat_cat = sc.id
+             JOIN asset.stat_cat_entry asce ON ascecm.stat_cat_entry = asce.id
+        WHERE NEW.target_copy = ascecm.owning_copy AND sc.checkout_archive;
+    RETURN NULL;
+END;
+$$ LANGUAGE PLPGSQL;
+
+-- Apply triggers
+CREATE TRIGGER fill_circ_copy_location_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.fill_circ_copy_location();
+CREATE TRIGGER archive_stat_cats_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.archive_stat_cats();
+
+-- Update view to use circ's copy_location field instead of the copy's current copy_location field
+CREATE OR REPLACE VIEW action.all_circulation AS
+    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.aged_circulation
+            UNION ALL
+    SELECT  DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
+        cp.call_number AS copy_call_number, circ.copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
+        cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
+        circ.checkin_lib, circ.renewal_remaining, circ.grace_period, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
+        circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
+        circ.recurring_fine_rule, circ.max_fine_rule, circ.stop_fines, circ.workstation, circ.checkin_workstation, circ.checkin_scan_time,
+        circ.parent_circ
+      FROM  action.circulation circ
+        JOIN asset.copy cp ON (circ.target_copy = cp.id)
+        JOIN asset.call_number cn ON (cp.call_number = cn.id)
+        JOIN actor.usr p ON (circ.usr = p.id)
+        LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
+        LEFT JOIN actor.usr_address b ON (p.billing_address = b.id);
+
+COMMIT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statistical_archive.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statistical_archive.sql
deleted file mode 100644
index 886e28d..0000000
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statistical_archive.sql
+++ /dev/null
@@ -1,61 +0,0 @@
--- New tables
-
-CREATE TABLE action.archive_actor_stat_cat (
-    id          BIGSERIAL   PRIMARY KEY,
-    xact        BIGINT      NOT NULL,
-    stat_cat    INT         NOT NULL,
-    value       TEXT        NOT NULL
-);
-
-CREATE TABLE action.archive_asset_stat_cat (
-    id          BIGSERIAL   PRIMARY KEY,
-    xact        BIGINT      NOT NULL,
-    stat_cat    INT         NOT NULL,
-    value       TEXT        NOT NULL
-);
-
--- Add columns to existing tables
-
--- Archive Flag Columns
-ALTER TABLE actor.stat_cat
-    ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
-ALTER TABLE asset.stat_cat
-    ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
-
--- Circulation copy column
-ALTER TABLE action.circulation
-    ADD COLUMN copy_location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location(id) DEFERRABLE INITIALLY DEFERRED;
-
--- Update action.circulation with real copy_location numbers instead of all "Stacks"
-UPDATE action.circulation circ SET copy_location = ac.location FROM asset.copy ac WHERE ac.id = circ.target_copy;
-
--- Create trigger function to auto-fill the copy_location field
-CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
-BEGIN
-    SELECT INTO NEW.copy_location location FROM asset.copy WHERE id = NEW.target_copy;
-    RETURN NEW;
-END;
-$$ LANGUAGE PLPGSQL;
-
--- Create trigger function to auto-archive stat cat entries
-CREATE OR REPLACE FUNCTION action.archive_stat_cats () RETURNS TRIGGER AS $$
-BEGIN
-    INSERT INTO action.archive_actor_stat_cat(xact, stat_cat, value)
-        SELECT NEW.id, asceum.stat_cat, asceum.stat_cat_entry
-        FROM actor.stat_cat_entry_usr_map asceum
-             JOIN actor.stat_cat sc ON asceum.stat_cat = sc.id
-        WHERE NEW.usr = asceum.target_usr AND sc.checkout_archive;
-    INSERT INTO action.archive_asset_stat_cat(xact, stat_cat, value)
-        SELECT NEW.id, ascecm.stat_cat, asce.value
-        FROM asset.stat_cat_entry_copy_map ascecm
-             JOIN asset.stat_cat sc ON ascecm.stat_cat = sc.id
-             JOIN asset.stat_cat_entry asce ON ascecm.stat_cat_entry = asce.id
-        WHERE NEW.target_copy = ascecm.owning_copy AND sc.checkout_archive;
-    RETURN NULL;
-END;
-$$ LANGUAGE PLPGSQL;
-
--- Apply triggers
-CREATE TRIGGER fill_circ_copy_location_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.fill_circ_copy_location();
-CREATE TRIGGER archive_stat_cats_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.archive_stat_cats();
-
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXY.schema.statistical_archive.all_circulation.sql b/Open-ILS/src/sql/Pg/upgrade/XXXY.schema.statistical_archive.all_circulation.sql
deleted file mode 100644
index ff14cd4..0000000
--- a/Open-ILS/src/sql/Pg/upgrade/XXXY.schema.statistical_archive.all_circulation.sql
+++ /dev/null
@@ -1,23 +0,0 @@
--- Update view to use circ's copy_location field instead of the copy's current copy_location field
-CREATE OR REPLACE VIEW action.all_circulation AS
-    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.aged_circulation
-            UNION ALL
-    SELECT  DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
-        cp.call_number AS copy_call_number, circ.copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
-        cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
-        circ.checkin_lib, circ.renewal_remaining, circ.grace_period, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
-        circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
-        circ.recurring_fine_rule, circ.max_fine_rule, circ.stop_fines, circ.workstation, circ.checkin_workstation, circ.checkin_scan_time,
-        circ.parent_circ
-      FROM  action.circulation circ
-        JOIN asset.copy cp ON (circ.target_copy = cp.id)
-        JOIN asset.call_number cn ON (cp.call_number = cn.id)
-        JOIN actor.usr p ON (circ.usr = p.id)
-        LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
-        LEFT JOIN actor.usr_address b ON (p.billing_address = b.id);

commit ee27d36a3121b409d17ba1016be93372a792c0d4
Author: Thomas Berezansky <tsbere at mvlc.org>
Date:   Sat Sep 17 14:49:16 2011 -0400

    Circ Statistical Archiving
    
    Copy Location
    
    Instead of only archiving the copy location with aged circs, do so with all
    circs, using the copy location at time of circ. This allows for running of
    reports on the copy location even after the item is no longer in it.
    
    Statistical Categories
    
    Add a flag to statistical categories to allow them to be archived with all
    circulations (at checkout). Reports can then be run on regular and aged
    circulations based on the contents of the statistical categories.
    
    This patch was inspired by Tim Spindler's submission to
    https://bugs.launchpad.net/evergreen/+bug/798255 - thanks Tim!
    
    Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index 7e0b301..57ef409 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -3264,6 +3264,9 @@ SELECT  usr,
 			<field reporter:label="Billing Totals" name="billing_total" oils_persist:virtual="true" reporter:datatype="money"/>
 			<field reporter:label="Payment Totals" name="payment_total" oils_persist:virtual="true" reporter:datatype="money"/>
 			<field reporter:label="Unrecovered Debt" name="unrecovered" reporter:datatype="bool"/>
+			<field reporter:label="Shelving Location" name="copy_location" reporter:datatype="link"/>
+			<field reporter:label="Archived Patron Stat-Cat Entries" name="aaactsc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
+			<field reporter:label="Archived Copy Stat-Cat Entries" name="aaasc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
 		</fields>
 		<links>
 			<link field="billable_transaction" reltype="might_have" key="id" map="" class="mbt"/>
@@ -3285,6 +3288,9 @@ SELECT  usr,
 			<link field="checkin_workstation" reltype="has_a" key="id" map="" class="aws"/>
 			<link field="parent_circ" reltype="has_a" key="id" map="" class="circ"/>
 			<link field="renewals" reltype="has_many" key="parent_circ" map="" class="circ"/>
+			<link field="copy_location" reltype="has_a" key="id" map="" class="acpl"/>
+			<link field="aaactsc_entries" reltype="has_many" key="xact" map="" class="aaactsc"/>
+			<link field="aaasc_entries" reltype="has_many" key="xact" map="" class="aaasc"/>
 		</links>
 	</class>
 	<class id="combcirc" controller="open-ils.cstore" oils_obj:fieldmapper="action::all_circulation" oils_persist:tablename="action.all_circulation" reporter:core="true" reporter:label="Combined Aged and Active Circulations" oils_persist:readonly="true">
@@ -3329,6 +3335,8 @@ SELECT  usr,
 			<field reporter:label="Copy Owning Library" name="copy_owning_lib" reporter:datatype="link"/>
 			<field reporter:label="Copy Circulating Library" name="copy_circ_lib" reporter:datatype="link"/>
 			<field reporter:label="Bib Record" name="copy_bib_record" reporter:datatype="link"/>
+			<field reporter:label="Archived Patron Stat-Cat Entries" name="aaactsc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
+			<field reporter:label="Archived Copy Stat-Cat Entries" name="aaasc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
 		</fields>
 		<links>
 			<link field="billable_transaction" reltype="might_have" key="id" map="" class="mbt"/>
@@ -3350,6 +3358,8 @@ SELECT  usr,
 			<link field="copy_owning_lib" reltype="has_a" key="id" map="" class="aou"/>
 			<link field="copy_circ_lib" reltype="has_a" key="id" map="" class="aou"/>
 			<link field="copy_bib_record" reltype="has_a" key="id" map="" class="bre"/>
+			<link field="aaactsc_entries" reltype="has_many" key="xact" map="" class="aaactsc"/>
+			<link field="aaasc_entries" reltype="has_many" key="xact" map="" class="aaasc"/>
 		</links>
 	</class>
 	<class id="acirc" controller="open-ils.cstore" oils_obj:fieldmapper="action::aged_circulation" oils_persist:tablename="action.aged_circulation" reporter:core="true" reporter:label="Aged (patronless) Circulation">
@@ -3398,6 +3408,8 @@ SELECT  usr,
 			<field reporter:label="Copy Owning Library" name="copy_owning_lib" reporter:datatype="link"/>
 			<field reporter:label="Copy Circulating Library" name="copy_circ_lib" reporter:datatype="link"/>
 			<field reporter:label="Bib Record" name="copy_bib_record" reporter:datatype="link"/>
+			<field reporter:label="Archived Patron Stat-Cat Entries" name="aaactsc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
+			<field reporter:label="Archived Copy Stat-Cat Entries" name="aaasc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
 		</fields>
 		<links>
 			<link field="billable_transaction" reltype="might_have" key="id" map="" class="mbt"/>
@@ -3423,6 +3435,8 @@ SELECT  usr,
 			<link field="checkin_workstation" reltype="has_a" key="id" map="" class="aws"/>
 			<link field="parent_circ" reltype="might_have" key="id" map="" class="circ"/>
 			<link field="renewals" reltype="has_many" key="parent_circ" map="" class="circ"/>
+			<link field="aaactsc_entries" reltype="has_many" key="xact" map="" class="aaactsc"/>
+			<link field="aaasc_entries" reltype="has_many" key="xact" map="" class="aaasc"/>
 		</links>
 	</class>
 
@@ -4730,6 +4744,7 @@ SELECT  usr,
 			<field reporter:label="SIP Field" name="sip_field" reporter:datatype="link"/>
 			<field reporter:label="SIP Format" name="sip_format" reporter:datatype="text"/>
 			<field reporter:label="Required" name="required" reporter:datatype="bool"/>
+			<field reporter:label="Checkout Archive" name="checkout_archive" reporter:datatype="bool"/>
 		</fields>
 		<links>
 			<link field="owner" reltype="has_a" key="id" map="" class="aou"/>
@@ -4774,6 +4789,7 @@ SELECT  usr,
 			<field reporter:label="User Summary" name="usr_summary" reporter:datatype="bool"/>
 			<field reporter:label="SIP Field" name="sip_field" reporter:datatype="link"/>
 			<field reporter:label="SIP Format" name="sip_format" reporter:datatype="text"/>
+			<field reporter:label="Checkout Archive" name="checkout_archive" reporter:datatype="bool"/>
 		</fields>
 		<links>
 			<link field="owner" reltype="has_a" key="id" map="" class="aou"/>
@@ -9370,6 +9386,30 @@ SELECT  usr,
 			</actions>
 		</permacrud>
 	</class>
+	<class id="aaactsc" controller="open-ils.reporter-store" oils_obj:fieldmapper="action::archive_actor_stat_cat" oils_persist:tablename="action.archive_actor_stat_cat" reporter:label="Circ-Archived Patron Statistical Category Entries">
+		<fields oils_persist:primary="id" oils_persist:sequence="action.archive_actor_stat_cat_id_seq">
+			<field reporter:label="ID" name="id" reporter:datatype="id"/>
+			<field reporter:label="Circ" name="xact" reporter:datatype="link"/>
+			<field reporter:label="Statistical Category" name="stat_cat" reporter:datatype="link"/>
+			<field reporter:label="Entry Value" name="value" reporter:datatype="text"/>
+		</fields>
+		<links>
+			<link field="xact" reltype="has_a" key="id" map="" class="combcirc"/>
+			<link field="stat_cat" reltype="has_a" key="id" map="" class="actsc"/>
+		</links>
+	</class>
+	<class id="aaasc" controller="open-ils.reporter-store" oils_obj:fieldmapper="action::archive_asset_stat_cat" oils_persist:tablename="action.archive_asset_stat_cat" reporter:label="Circ-Archived Copy Statistical Category Entries">
+		<fields oils_persist:primary="id" oils_persist:sequence="action.archive_actor_stat_cat_id_seq">
+			<field reporter:label="ID" name="id" reporter:datatype="id"/>
+			<field reporter:label="Circ" name="xact" reporter:datatype="link"/>
+			<field reporter:label="Statistical Category" name="stat_cat" reporter:datatype="link"/>
+			<field reporter:label="Entry Value" name="value" reporter:datatype="text"/>
+		</fields>
+		<links>
+			<link field="xact" reltype="has_a" key="id" map="" class="combcirc"/>
+			<link field="stat_cat" reltype="has_a" key="id" map="" class="asc"/>
+		</links>
+	</class>
 
 
 	<!-- ********************************************************************************************************************* -->
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm
index 06094b4..2fbba74 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm
@@ -69,7 +69,7 @@ __PACKAGE__->columns(Essential => qw/xact_start usr target_copy circ_lib
 				     stop_fines xact_finish due_date opac_renewal
 				     checkin_staff circ_staff circ_lib checkin_lib
 				     stop_fines_time checkin_time desk_renewal
-				     phone_renewal create_time/);
+				     phone_renewal create_time copy_location/);
 
 #-------------------------------------------------------------------------------
 
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm
index 89495fc..d95baa1 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm
@@ -118,7 +118,7 @@ use base qw/actor/;
 
 __PACKAGE__->table( 'actor_stat_cat' );
 __PACKAGE__->columns( Primary => qw/id/ );
-__PACKAGE__->columns( Essential => qw/owner name opac_visible usr_summary sip_field sip_format/ );
+__PACKAGE__->columns( Essential => qw/owner name opac_visible usr_summary sip_field sip_format checkout_archive/ );
 
 #-------------------------------------------------------------------------------
 package actor::stat_cat_entry;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/asset.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/asset.pm
index 0fc1061..2b541cc 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/asset.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/asset.pm
@@ -88,7 +88,7 @@ use base qw/asset/;
 
 __PACKAGE__->table( 'asset_stat_cat' );
 __PACKAGE__->columns( Primary => qw/id/ );
-__PACKAGE__->columns( Essential => qw/owner name opac_visible sip_field sip_format required/ );
+__PACKAGE__->columns( Essential => qw/owner name opac_visible sip_field sip_format required checkout_archive/ );
 
 #-------------------------------------------------------------------------------
 package asset::stat_cat_entry;
diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql
index 3a9f841..fbe0504 100644
--- a/Open-ILS/src/sql/Pg/005.schema.actors.sql
+++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql
@@ -187,6 +187,7 @@ CREATE TABLE actor.stat_cat (
 	usr_summary     BOOL NOT NULL DEFAULT FALSE,
     sip_field   CHAR(2) REFERENCES actor.stat_cat_sip_fields(field) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
     sip_format  TEXT,
+    checkout_archive    BOOL NOT NULL DEFAULT FALSE,
 	CONSTRAINT sc_once_per_owner UNIQUE (owner,name)
 );
 COMMENT ON TABLE actor.stat_cat IS $$
diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql
index fef5ced..3beb24e 100644
--- a/Open-ILS/src/sql/Pg/040.schema.asset.sql
+++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql
@@ -177,6 +177,7 @@ CREATE TABLE asset.stat_cat (
 	required	BOOL	NOT NULL DEFAULT FALSE,
     sip_field   CHAR(2) REFERENCES asset.stat_cat_sip_fields(field) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
     sip_format  TEXT,
+    checkout_archive    BOOL NOT NULL DEFAULT FALSE,
 	CONSTRAINT sc_once_per_owner UNIQUE (owner,name)
 );
 
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 05c45ad..eae256a 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -101,6 +101,20 @@ CREATE TRIGGER action_survey_response_answer_date_fixup_tgr
 	FOR EACH ROW
 	EXECUTE PROCEDURE action.survey_response_answer_date_fixup ();
 
+CREATE TABLE action.archive_actor_stat_cat (
+    id          BIGSERIAL   PRIMARY KEY,
+    xact        BIGINT      NOT NULL, -- action.circulation (+aged/all)
+    stat_cat    INT         NOT NULL,
+    value       TEXT        NOT NULL
+);
+
+CREATE TABLE action.archive_asset_stat_cat (
+    id          BIGSERIAL   PRIMARY KEY,
+    xact        BIGINT      NOT NULL, -- action.circulation (+aged/all)
+    stat_cat    INT         NOT NULL,
+    value       TEXT        NOT NULL
+);
+
 
 CREATE TABLE action.circulation (
 	target_copy		BIGINT				NOT NULL, -- asset.copy.id
@@ -132,6 +146,7 @@ CREATE TABLE action.circulation (
 	checkin_workstation INT        REFERENCES actor.workstation(id)
 	                               ON DELETE SET NULL
 								   DEFERRABLE INITIALLY DEFERRED,
+	copy_location	INT				NOT NULL DEFAULT 1 REFERENCES asset.copy_location (id) DEFERRABLE INITIALLY DEFERRED,
 	checkin_scan_time   TIMESTAMP WITH TIME ZONE
 ) INHERITS (money.billable_xact);
 ALTER TABLE action.circulation ADD PRIMARY KEY (id);
@@ -169,13 +184,40 @@ $$ LANGUAGE PLPGSQL;
 
 CREATE TRIGGER push_due_date_tgr BEFORE INSERT OR UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.push_circ_due_time();
 
+CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
+BEGIN
+    SELECT INTO NEW.copy_location location FROM asset.copy WHERE id = NEW.target_copy;
+    RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER fill_circ_copy_location_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.fill_circ_copy_location();
+
+CREATE OR REPLACE FUNCTION action.archive_stat_cats () RETURNS TRIGGER AS $$
+BEGIN
+    INSERT INTO action.archive_actor_stat_cat(xact, stat_cat, value)
+        SELECT NEW.id, asceum.stat_cat, asceum.stat_cat_entry
+        FROM actor.stat_cat_entry_usr_map asceum
+             JOIN actor.stat_cat sc ON asceum.stat_cat = sc.id
+        WHERE NEW.usr = asceum.target_usr AND sc.checkout_archive;
+    INSERT INTO action.archive_asset_stat_cat(xact, stat_cat, value)
+        SELECT NEW.id, ascecm.stat_cat, asce.value
+        FROM asset.stat_cat_entry_copy_map ascecm
+             JOIN asset.stat_cat sc ON ascecm.stat_cat = sc.id
+             JOIN asset.stat_cat_entry asce ON ascecm.stat_cat_entry = asce.id
+        WHERE NEW.target_copy = ascecm.owning_copy AND sc.checkout_archive;
+    RETURN NULL;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER archive_stat_cats_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.archive_stat_cats();
+
 CREATE TABLE action.aged_circulation (
 	usr_post_code		TEXT,
 	usr_home_ou		INT	NOT NULL,
 	usr_profile		INT	NOT NULL,
 	usr_birth_year		INT,
 	copy_call_number	INT	NOT NULL,
-	copy_location		INT	NOT NULL,
 	copy_owning_lib		INT	NOT NULL,
 	copy_circ_lib		INT	NOT NULL,
 	copy_bib_record		BIGINT	NOT NULL,
@@ -201,7 +243,7 @@ CREATE OR REPLACE VIEW action.all_circulation AS
       FROM  action.aged_circulation
             UNION ALL
     SELECT  DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
-        cp.call_number AS copy_call_number, cp.location AS copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
+        cp.call_number AS copy_call_number, circ.copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
         cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
         circ.checkin_lib, circ.renewal_remaining, circ.grace_period, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
         circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statistical_archive.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statistical_archive.sql
new file mode 100644
index 0000000..886e28d
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statistical_archive.sql
@@ -0,0 +1,61 @@
+-- New tables
+
+CREATE TABLE action.archive_actor_stat_cat (
+    id          BIGSERIAL   PRIMARY KEY,
+    xact        BIGINT      NOT NULL,
+    stat_cat    INT         NOT NULL,
+    value       TEXT        NOT NULL
+);
+
+CREATE TABLE action.archive_asset_stat_cat (
+    id          BIGSERIAL   PRIMARY KEY,
+    xact        BIGINT      NOT NULL,
+    stat_cat    INT         NOT NULL,
+    value       TEXT        NOT NULL
+);
+
+-- Add columns to existing tables
+
+-- Archive Flag Columns
+ALTER TABLE actor.stat_cat
+    ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
+ALTER TABLE asset.stat_cat
+    ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
+
+-- Circulation copy column
+ALTER TABLE action.circulation
+    ADD COLUMN copy_location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location(id) DEFERRABLE INITIALLY DEFERRED;
+
+-- Update action.circulation with real copy_location numbers instead of all "Stacks"
+UPDATE action.circulation circ SET copy_location = ac.location FROM asset.copy ac WHERE ac.id = circ.target_copy;
+
+-- Create trigger function to auto-fill the copy_location field
+CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
+BEGIN
+    SELECT INTO NEW.copy_location location FROM asset.copy WHERE id = NEW.target_copy;
+    RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+-- Create trigger function to auto-archive stat cat entries
+CREATE OR REPLACE FUNCTION action.archive_stat_cats () RETURNS TRIGGER AS $$
+BEGIN
+    INSERT INTO action.archive_actor_stat_cat(xact, stat_cat, value)
+        SELECT NEW.id, asceum.stat_cat, asceum.stat_cat_entry
+        FROM actor.stat_cat_entry_usr_map asceum
+             JOIN actor.stat_cat sc ON asceum.stat_cat = sc.id
+        WHERE NEW.usr = asceum.target_usr AND sc.checkout_archive;
+    INSERT INTO action.archive_asset_stat_cat(xact, stat_cat, value)
+        SELECT NEW.id, ascecm.stat_cat, asce.value
+        FROM asset.stat_cat_entry_copy_map ascecm
+             JOIN asset.stat_cat sc ON ascecm.stat_cat = sc.id
+             JOIN asset.stat_cat_entry asce ON ascecm.stat_cat_entry = asce.id
+        WHERE NEW.target_copy = ascecm.owning_copy AND sc.checkout_archive;
+    RETURN NULL;
+END;
+$$ LANGUAGE PLPGSQL;
+
+-- Apply triggers
+CREATE TRIGGER fill_circ_copy_location_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.fill_circ_copy_location();
+CREATE TRIGGER archive_stat_cats_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.archive_stat_cats();
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXY.schema.statistical_archive.all_circulation.sql b/Open-ILS/src/sql/Pg/upgrade/XXXY.schema.statistical_archive.all_circulation.sql
new file mode 100644
index 0000000..ff14cd4
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXY.schema.statistical_archive.all_circulation.sql
@@ -0,0 +1,23 @@
+-- Update view to use circ's copy_location field instead of the copy's current copy_location field
+CREATE OR REPLACE VIEW action.all_circulation AS
+    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.aged_circulation
+            UNION ALL
+    SELECT  DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
+        cp.call_number AS copy_call_number, circ.copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
+        cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
+        circ.checkin_lib, circ.renewal_remaining, circ.grace_period, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
+        circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
+        circ.recurring_fine_rule, circ.max_fine_rule, circ.stop_fines, circ.workstation, circ.checkin_workstation, circ.checkin_scan_time,
+        circ.parent_circ
+      FROM  action.circulation circ
+        JOIN asset.copy cp ON (circ.target_copy = cp.id)
+        JOIN asset.call_number cn ON (cp.call_number = cn.id)
+        JOIN actor.usr p ON (circ.usr = p.id)
+        LEFT JOIN actor.usr_address a ON (p.mailing_address = a.id)
+        LEFT JOIN actor.usr_address b ON (p.billing_address = b.id);
diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd
index 9e91870..c26e5b8 100644
--- a/Open-ILS/web/opac/locale/en-US/lang.dtd
+++ b/Open-ILS/web/opac/locale/en-US/lang.dtd
@@ -2196,6 +2196,8 @@
 <!ENTITY staff.server.admin.stat_cat.sip_field.label "SIP Field">
 <!ENTITY staff.server.admin.stat_cat.sip_format.label "SIP Format">
 <!ENTITY staff.server.admin.stat_cat.sip_field.none.label "No SIP">
+<!ENTITY staff.server.admin.stat_cat.checkout_archive "Archive with Circs">
+<!ENTITY staff.server.admin.stat_cat.checkout_archive.label "Circ Archive">
 <!ENTITY staff.server.admin.upload_xacts.title "Upload Offline Transactions">
 <!ENTITY staff.server.admin.upload_xacts.header "Uploading transactions...">
 <!ENTITY staff.server.admin.upload_xacts.upload "Upload">
diff --git a/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js b/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js
index f16761e..8edabfd 100644
--- a/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js
+++ b/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js
@@ -202,6 +202,10 @@ function scInsertCat( tbody, cat, type ) {
 
     $n(row, 'sc_sip_format_td').appendChild( text( cat.sip_format() ) );
 
+    if(isTrue(cat.checkout_archive()))
+        unHideMe($n(row, 'sc_checkout_archive_on'));
+    else
+        unHideMe($n(row, 'sc_checkout_archive'));
 
     if(type == ACTOR) {
         if(isTrue(cat.usr_summary()))
@@ -350,9 +354,11 @@ function scNew() {
     var visible = 0;
     var required = 0;
     var usr_summary = 0;
+    var checkout_archive = 0;
     if( $('sc_make_opac_visible').checked) visible = 1;
     if( $('sc_make_required').checked) required = 1;
     if( $('sc_make_usr_summary').checked) usr_summary = 1;
+    if( $('sc_make_checkout_archive').checked) checkout_archive = 1;
 
     var cat;
     if( type == ACTOR ) {
@@ -370,6 +376,7 @@ function scNew() {
 
     cat.opac_visible(visible);
     cat.name(name);
+    cat.checkout_archive(checkout_archive);
     cat.owner(getSelectorVal($('sc_owning_lib_selector')));
     cat.isnew(1);
 
@@ -439,6 +446,8 @@ function scEdit( tbody, type, cat ) {
             'sc_edit_opac_visibility').checked = true;
     }
 
+    $n( row, 'sc_edit_checkout_archive' ).checked = isTrue(cat.checkout_archive());
+
     $n(row, 'sc_edit_submit').onclick = 
         function() { scEditGo( type, cat, row, selector ); };
 
@@ -473,6 +482,7 @@ function scEditGo( type, cat, row, selector ) {
     cat.owner( newlib );
     cat.entries(null);
     cat.opac_visible(0);
+    cat.checkout_archive($n(row, 'sc_edit_checkout_archive').checked ? 1 : 0);
     if(sip_field.length == 2) cat.sip_field( sip_field );
     else cat.sip_field(null);
     cat.sip_format($n(row, 'sc_edit_sip_format').value);
diff --git a/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xhtml b/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xhtml
index c1d794b..0e98cba 100644
--- a/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xhtml
+++ b/Open-ILS/xul/staff_client/server/admin/stat_cat_editor.xhtml
@@ -95,6 +95,13 @@
                             <span>&staff.server.admin.stat_cat.off;</span>
                             <input type='radio' name='usr_summary' checked='checked'> </input>
                         </td>
+                        <td>&staff.server.admin.stat_cat.checkout_archive;</td>
+                        <td>
+                            <span>&staff.server.admin.stat_cat.on;</span>
+                            <input type='radio' name='checkout_archive' id='sc_make_checkout_archive'> </input>
+                            <span>&staff.server.admin.stat_cat.off;</span>
+                            <input type='radio' name='checkout_archive' checked='checked'> </input>
+                        </td>
                     </tr>
                     <tr>
                         <td>&staff.server.admin.stat_cat.sip_field;</td>
@@ -158,6 +165,7 @@
                             <td id='sc_usr_summary_label'>&staff.server.admin.stat_cat.usr_summary.label;</td>
                             <td>&staff.server.admin.stat_cat.sip_field.label;</td>
                             <td>&staff.server.admin.stat_cat.sip_format.label;</td>
+                            <td>&staff.server.admin.stat_cat.checkout_archive.label;</td>
                             <td>&staff.server.admin.stat_cat.entries.label;</td>
                             <td>&staff.server.admin.stat_cat.add_entry;</td>
                             <td>&staff.server.admin.stat_cat.edit;</td>
@@ -187,6 +195,10 @@
                             </td>
                             <td name='sc_sip_format_td'/>
                             <td>
+                                <span class='hide_me' name='sc_checkout_archive_on'>&staff.server.admin.stat_cat.on;</span>
+                                <span class='hide_me' name='sc_checkout_archive'>&staff.server.admin.stat_cat.off;</span>
+                            </td>
+                            <td>
                                 <select class='selector' name='sc_entries_selector'>
                                     <option>&staff.server.admin.stat_cat.none;</option>
                                 </select>
@@ -249,6 +261,9 @@
                 <td name='sc_edit_sip_format_td'>
                     <input type='text' name='sc_edit_sip_format'/>
                 </td>
+                <td>
+                    <input type='checkbox' name='sc_edit_checkout_archive'/>
+                </td>
                 <td colspan='4'>
                     <span class='padded'>
                         <input  type='submit' value='&staff.server.admin.stat_cat.edit_submit;' name='sc_edit_submit'/>

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/fm_IDL.xml                       |   40 ++++++++
 .../lib/OpenILS/Application/Storage/CDBI/action.pm |    2 +-
 .../lib/OpenILS/Application/Storage/CDBI/actor.pm  |    2 +-
 .../lib/OpenILS/Application/Storage/CDBI/asset.pm  |    2 +-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/005.schema.actors.sql          |    1 +
 Open-ILS/src/sql/Pg/040.schema.asset.sql           |    1 +
 Open-ILS/src/sql/Pg/090.schema.action.sql          |   46 +++++++++-
 .../upgrade/0663.schema.archive_circ_stat_cats.sql |   96 ++++++++++++++++++++
 Open-ILS/web/opac/locale/en-US/lang.dtd            |    2 +
 .../staff_client/server/admin/stat_cat_editor.js   |   10 ++
 .../server/admin/stat_cat_editor.xhtml             |   15 +++
 12 files changed, 213 insertions(+), 6 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0663.schema.archive_circ_stat_cats.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list