convenience wrappers for finding in-db rules
[migration-tools.git] / sql / base / base.sql
index b786140..fe1334a 100644 (file)
@@ -1253,10 +1253,10 @@ BEGIN
       INTO this_duration_rule,
            this_fine_rule,
            this_max_fine_rule
-      duration_rule,
-      recurring_fine_rule,
-      max_fine_rule
-      FROM action.item_user_circ_test(
+      (matchpoint).duration_rule,
+      (matchpoint).recurring_fine_rule,
+      (matchpoint).max_fine_rule
+      FROM action.find_circ_matrix_matchpoint(
         circ_lib,
         target_copy,
         usr,
@@ -1282,7 +1282,8 @@ BEGIN
           WHEN TRUE THEN (rmf.amount / 100.0) * ac.price
           ELSE rmf.amount
         END,
-      renewal_remaining = rcd.max_renewals
+      renewal_remaining = rcd.max_renewals,
+      grace_period = rrf.grace_period
     FROM
       config.rule_circ_duration rcd,
       config.rule_recurring_fine rrf,
@@ -2158,3 +2159,27 @@ CREATE OR REPLACE FUNCTION migration_tools.get_marc_tags (TEXT, TEXT, TEXT, TEXT
     return \@texts;
 $$ LANGUAGE PLPERLU STABLE;
 
+CREATE OR REPLACE FUNCTION migration_tools.find_hold_matrix_matchpoint (INTEGER) RETURNS INTEGER AS $$
+    SELECT action.find_hold_matrix_matchpoint(
+        (SELECT pickup_lib FROM action.hold_request WHERE id = $1),
+        (SELECT request_lib FROM action.hold_request WHERE id = $1),
+        (SELECT current_copy FROM action.hold_request WHERE id = $1),
+        (SELECT usr FROM action.hold_request WHERE id = $1),
+        (SELECT requestor FROM action.hold_request WHERE id = $1)
+    );
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION migration_tools.find_circ_matrix_matchpoint (INTEGER) RETURNS SETOF action.found_circ_matrix_matchpoint AS $$
+    SELECT action.find_circ_matrix_matchpoint(
+        (SELECT circ_lib FROM action.circulation WHERE id = $1),
+        (SELECT target_copy FROM action.circulation WHERE id = $1),
+        (SELECT usr FROM action.circulation WHERE id = $1),
+        (SELECT COALESCE(
+                NULLIF(phone_renewal,false),
+                NULLIF(desk_renewal,false),
+                NULLIF(opac_renewal,false),
+                false
+            ) FROM action.circulation WHERE id = $1
+        )
+    );
+$$ LANGUAGE SQL;