[open-ils-commits] r10596 - trunk/Open-ILS/src/sql/Pg

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Sep 15 14:32:45 EDT 2008


Author: miker
Date: 2008-09-15 14:32:41 -0400 (Mon, 15 Sep 2008)
New Revision: 10596

Modified:
   trunk/Open-ILS/src/sql/Pg/100.circ_matrix.sql
Log:
specify billing/out/etc range by depth, not specific OU (trac ticket #21)

Modified: trunk/Open-ILS/src/sql/Pg/100.circ_matrix.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/100.circ_matrix.sql	2008-09-15 16:55:23 UTC (rev 10595)
+++ trunk/Open-ILS/src/sql/Pg/100.circ_matrix.sql	2008-09-15 18:32:41 UTC (rev 10596)
@@ -117,10 +117,10 @@
 	matchpoint      INT     PRIMARY KEY NOT NULL REFERENCES config.circ_matrix_matchpoint (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
 	circulate       BOOL    NOT NULL DEFAULT TRUE,	-- Hard "can't circ" flag requiring an override
 	max_items_out   INT,                        	-- Total current active circulations must be less than this, NULL means skip (always pass)
-	max_overdue	    INT,               				-- Total overdue active circulations must be less than this, NULL means skip (always pass)
-	max_fines       NUMERIC(8,2),              		-- Total fines owed must be less than this, NULL means skip (always pass)
-	org_unit		INT     REFERENCES actor.org_unit (id),	-- Set to the top OU for the max-out applicability range
-	script_test     TEXT		                   	-- filename or javascript source ??
+	max_overdue     INT,                            -- Total overdue active circulations must be less than this, NULL means skip (always pass)
+	max_fines       NUMERIC(8,2),                   -- Total fines owed must be less than this, NULL means skip (always pass)
+	org_depth       INT,                            -- Set to the top OU for the max-out applicability range
+	script_test     TEXT                            -- filename or javascript source ??
 );
 
 -- Tests for max items out by circ_modifier
@@ -298,11 +298,9 @@
 
 	SELECT INTO circ_test * from config.circ_matrix_test WHERE matchpoint = result.matchpoint;
 
-    IF circ_test.org_unit IS NOT NULL THEN
-        SELECT INTO overdue_orgs ARRAY_ACCUM(id) FROM actor.org_unit_descendants( circ_test.org_unit );
-    ELSE
-        SELECT INTO overdue_orgs ARRAY_ACCUM(id) FROM actor.org_unit;
-    END IF; 
+	IF circ_test.org_depth IS NOT NULL THEN
+		SELECT INTO overdue_orgs ARRAY_ACCUM(id) FROM actor.org_unit_descendants( circ_ou, circ_test.org_depth );
+	END IF; 
 
 	-- Fail if we couldn't find a set of tests
 	IF result.matchpoint IS NULL THEN
@@ -325,7 +323,7 @@
     	SELECT  INTO items_out COUNT(*)
           FROM  action.circulation
           WHERE usr = match_user
-                AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) )
+                AND (circ_test.org_depth IS NULL OR (circ_test.org_depth IS NOT NULL AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) )))
                 AND checkin_time IS NULL
                 AND (stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE') OR stop_fines IS NULL);
 	   	IF items_out >= circ_test.max_items_out THEN
@@ -342,7 +340,7 @@
 		  FROM  action.circulation circ
 			JOIN asset.copy cp ON (cp.id = circ.target_copy)
 		  WHERE circ.usr = match_user
-            AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) )
+                	AND (circ_test.org_depth IS NULL OR (circ_test.org_depth IS NOT NULL AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) )))
 			AND circ.checkin_time IS NULL
 			AND (circ.stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE') OR circ.stop_fines IS NULL)
 			AND cp.circ_modifier = out_by_circ_mod.circ_mod;
@@ -359,7 +357,7 @@
 		SELECT  INTO items_overdue COUNT(*)
 		  FROM  action.circulation
 		  WHERE usr = match_user
-            AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) )
+                	AND (circ_test.org_depth IS NULL OR (circ_test.org_depth IS NOT NULL AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) )))
 			AND checkin_time IS NULL
 			AND due_date < NOW()
 			AND (stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE') OR stop_fines IS NULL);
@@ -373,14 +371,14 @@
 
 	-- Fail if the user has a high fine balance
 	IF circ_test.max_fines IS NOT NULL THEN
-		FOR tmp_groc IN SELECT * FROM money.grocery WHERE usr = match_usr AND xact_finish IS NULL AND billing_location IN ( SELECT * FROM explode_array(overdue_orgs) ) LOOP
+		FOR tmp_groc IN SELECT * FROM money.grocery WHERE usr = match_usr AND xact_finish IS NULL AND (circ_test.org_depth IS NULL OR (circ_test.org_depth IS NOT NULL AND billing_location IN ( SELECT * FROM explode_array(overdue_orgs) ))) LOOP
 			SELECT INTO tmp_fines SUM( amount ) FROM money.billing WHERE xact = tmp_groc.id AND NOT voided;
 			current_fines = current_fines + COALESCE(tmp_fines, 0.0);
 			SELECT INTO tmp_fines SUM( amount ) FROM money.payment WHERE xact = tmp_groc.id AND NOT voided;
 			current_fines = current_fines - COALESCE(tmp_fines, 0.0);
 		END LOOP;
 
-		FOR tmp_circ IN SELECT * FROM action.circulation WHERE usr = match_usr AND xact_finish IS NULL AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) ) LOOP
+		FOR tmp_circ IN SELECT * FROM action.circulation WHERE usr = match_usr AND xact_finish IS NULL AND (circ_test.org_depth IS NULL OR (circ_test.org_depth IS NOT NULL AND circ_lib IN ( SELECT * FROM explode_array(overdue_orgs) ))) LOOP
 			SELECT INTO tmp_fines SUM( amount ) FROM money.billing WHERE xact = tmp_circ.id AND NOT voided;
 			current_fines = current_fines + COALESCE(tmp_fines, 0.0);
 			SELECT INTO tmp_fines SUM( amount ) FROM money.payment WHERE xact = tmp_circ.id AND NOT voided;



More information about the open-ils-commits mailing list