From: Jim Keenan Date: Tue, 24 May 2016 13:09:27 +0000 (-0400) Subject: Merge branch 'master' of git://git.evergreen-ils.org/Evergreen into working_branch X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5468816bd8ac75957234f05945530e087bb5b206;p=evergreen%2Fmasslnc.git Merge branch 'master' of git://git.evergreen-ils.org/Evergreen into working_branch Conflicts: Open-ILS/examples/fm_IDL.xml --- 5468816bd8ac75957234f05945530e087bb5b206 diff --cc Open-ILS/examples/fm_IDL.xml index 6456a4fb5b,04630ff16e..593966444a --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@@ -1,11633 -1,11464 +1,23100 @@@ ++<<<<<<< HEAD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOW() - (SELECT MAX(value) FROM ( + SELECT value::INTERVAL FROM actor.org_unit_ancestor_setting( + 'circ.staff.max_visible_event_age', + COALESCE(targ_circ.circ_lib, targ_ahr.pickup_lib) + ) UNION + SELECT '1000 YEARS'::INTERVAL AS value + ) ous) + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT * FROM metabib.author_field_entry + UNION ALL + SELECT * FROM metabib.keyword_field_entry + UNION ALL + SELECT * FROM metabib.identifier_field_entry + UNION ALL + SELECT * FROM metabib.title_field_entry + UNION ALL + SELECT * FROM metabib.subject_field_entry + UNION ALL + SELECT * FROM metabib.series_field_entry + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +SELECT usr, + SUM( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date >= 'today') OR (fine_interval < '1 day' AND due_date > 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN 1 + ELSE 0 + END + ) AS out, + + SUM( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date < 'today') OR (fine_interval < '1 day' AND due_date < 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN 1 + ELSE 0 + END + ) AS overdue, + + SUM( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LOST') THEN 1 ELSE 0 END) AS lost, + SUM( CASE WHEN stop_fines = 'CLAIMSRETURNED' THEN 1 ELSE 0 END) AS claims_returned, + SUM( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LONGOVERDUE') THEN 1 ELSE 0 END) AS long_overdue + FROM action.circulation + WHERE checkin_time IS NULL + GROUP BY 1 + + + + + + + + + + + + + + + +SELECT usr, + STRING_AGG( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date >= 'today') OR (fine_interval < '1 day' AND due_date > 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN id::TEXT + ELSE '0' + END + ,',') AS out, + + STRING_AGG( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date < 'today') OR (fine_interval < '1 day' AND due_date < 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN id::TEXT + ELSE '0' + END + ,',') AS overdue, + + STRING_AGG( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LOST') THEN id::TEXT ELSE '0' END,',') AS lost, + STRING_AGG( CASE WHEN stop_fines = 'CLAIMSRETURNED' THEN id::TEXT ELSE '0' END,',') AS claims_returned, + STRING_AGG( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LONGOVERDUE') THEN id::TEXT ELSE '0' END,',') AS long_overdue + FROM action.circulation + WHERE checkin_time IS NULL + GROUP BY 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ahr.requestor) AS is_staff_hold, + ahcm_1.copy_count AS potential_copies + FROM action.hold_request ahr + JOIN asset.copy acp ON (acp.id = ahr.current_copy) + JOIN asset.call_number acn ON (acp.call_number = acn.id) + JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id) + JOIN asset.call_number_suffix acns ON (acn.suffix = acns.id) + JOIN actor.usr au ON (au.id = ahr.usr) + JOIN ( + SELECT *, (ROW_NUMBER() OVER (ORDER BY name) + 1000000) AS fallback_position + FROM asset.copy_location + ) acpl_ordered ON (acpl_ordered.id = acp.location) + LEFT JOIN actor.usr_standing_penalty ausp + ON (ahr.usr = ausp.usr AND (ausp.stop_date IS NULL OR ausp.stop_date > NOW())) + LEFT JOIN config.standing_penalty csp + ON ( + csp.id = ausp.standing_penalty AND + csp.block_list LIKE '%CAPTURE%' AND ( + (csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR + (csp.org_depth IS NOT NULL AND ahr.pickup_lib IN ( + SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth)) + ) + ) + ) + JOIN ( + SELECT COUNT(target_copy) AS copy_count, hold + FROM action.hold_copy_map + GROUP BY 2 + ) ahcm_1 ON (ahcm_1.hold = ahr.id) + LEFT JOIN serial.issuance siss + ON (ahr.hold_type = 'I' AND siss.id = ahr.target) + LEFT JOIN asset.copy_location_order acplo + ON (acp.location = acplo.location AND + acp.circ_lib = acplo.org) + WHERE + ahr.capture_time IS NULL AND + ahr.cancel_time IS NULL AND + csp.id IS NULL AND + (ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND + acp.status IN (0,7) + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT ahr.* FROM action.hold_request ahr JOIN (SELECT current_copy, MAX(capture_time) AS capture_time FROM action.hold_request WHERE capture_time IS NOT NULL GROUP BY current_copy)x USING (current_copy, capture_time) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT DISTINCT l.* + FROM action.unfulfilled_hold_loops l + JOIN action.unfulfilled_hold_max_loop m USING (hold) + WHERE l.count = m.max + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + cbrebi.id AS id, -- so we can have a pkey in our view + uvs.id AS session, + uvs.owning_lib, + cbrebi.target_biblio_record_entry + FROM url_verify.session uvs + JOIN container.biblio_record_entry_bucket cbreb + ON (uvs.container = cbreb.id) + JOIN container.biblio_record_entry_bucket_item cbrebi + ON (cbrebi.bucket = cbreb.id) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT b.id, + MAX(dcp.edit_date) AS last_delete_date + FROM biblio.record_entry b + JOIN asset.call_number cn ON (cn.record = b.id) + JOIN asset.copy dcp ON (cn.id = dcp.call_number) + WHERE NOT b.deleted + GROUP BY b.id + HAVING SUM( CASE WHEN NOT dcp.deleted THEN 1 ELSE 0 END) = 0 + + + + + + + + + + + + + + + + + + + + -- -- If we uncomment the RIGHT JOIN against biblio.record_entry, then we'll get a row for every non-deleted bib, whether it has active holds or not. + -- -- If we expect to use pcrud to query against specific bibs, we probably want to do this. However, if we're using this to populate a report, we + -- -- may not. + -- SELECT + -- bre.id AS "bib_id", + -- COALESCE( z.copy_count, 0 ) AS "copy_count", + -- COALESCE( z.hold_count, 0 ) AS "hold_count", + -- COALESCE( z.copy_hold_ratio, 0 ) AS "hold_copy_ratio" + -- FROM ( + SELECT + y.bre AS "id", + COALESCE( x.copy_count, 0 ) AS "copy_count", + y.hold_count AS "hold_count", + (y.hold_count::REAL / (CASE WHEN x.copy_count = 0 OR x.copy_count IS NULL THEN 0.1 ELSE x.copy_count::REAL END)) AS "hold_copy_ratio" + FROM ( + SELECT + (SELECT bib_record FROM reporter.hold_request_record r WHERE r.id = h.id LIMIT 1) AS "bre", + COUNT(*) AS "hold_count" + FROM action.hold_request h + WHERE + cancel_time IS NULL + AND fulfillment_time IS NULL + -- AND NOT frozen -- a frozen hold is still a desired hold, eh? + GROUP BY 1 + )y LEFT JOIN ( + SELECT + (SELECT id + FROM biblio.record_entry + WHERE id = (SELECT record FROM asset.call_number WHERE id = call_number and deleted is false) + ) AS "bre", + COUNT(*) AS "copy_count" + FROM asset.copy + JOIN asset.copy_location loc ON (copy.location = loc.id AND loc.holdable) + WHERE copy.holdable + AND NOT copy.deleted + AND copy.status IN ( SELECT id FROM config.copy_status WHERE holdable ) + GROUP BY 1 + )x ON x.bre = y.bre + -- )z RIGHT JOIN ( + -- SELECT id + -- FROM biblio.record_entry + -- WHERE NOT deleted + -- )bre ON (z.bib_id = bre.id) + + + + + + + + + + + + + + + + + + + + + + SELECT *, + CASE WHEN copy_count_at_pickup_library = 0 THEN 'Infinity'::FLOAT ELSE holds_at_pickup_library::FLOAT/copy_count_at_pickup_library END AS pickup_library_ratio, + CASE WHEN copy_count_everywhere = 0 THEN 'Infinity'::FLOAT ELSE holds_everywhere::FLOAT/copy_count_everywhere END AS everywhere_ratio + FROM + (SELECT bib_record as id, pickup_lib, count(DISTINCT ahr.id) AS holds_at_pickup_library, COALESCE(count(DISTINCT ac.id),0) as copy_count_at_pickup_library + FROM + action.hold_request ahr + JOIN reporter.hold_request_record rhrr USING (id) + LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold) + LEFT JOIN asset.copy ac ON (ahcm.target_copy = ac.id AND ahr.pickup_lib = ac.circ_lib) + WHERE + ahr.cancel_time IS NULL + AND ahr.fulfillment_time IS NULL + GROUP BY bib_record, pickup_lib + )x + JOIN + (SELECT bib_record as id, count(DISTINCT ahr.id) AS holds_everywhere, COALESCE(count(DISTINCT target_copy),0) as copy_count_everywhere + FROM + action.hold_request ahr + JOIN reporter.hold_request_record rhrr USING (id) + LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold) + WHERE + ahr.cancel_time IS NULL + AND ahr.fulfillment_time IS NULL + GROUP BY bib_record + )y + USING (id) + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + ac.id, + COALESCE(MAX(actac.xact_start), ac.create_date) AS last_circ_or_create, + MAX(actac.xact_start) AS last_circ + FROM asset.copy ac + LEFT JOIN action.all_circulation actac ON ac.id = actac.target_copy + GROUP BY ac.id + + -- Alternate version, say if you have migrated last checkout information in extend_reporter.legacy_circ_timestamp: + --SELECT + -- ac.id, + -- GREATEST(MAX(actac.xact_start), erlct.last_cko_ts, ac.create_date) AS last_circ_or_create, + -- GREATEST(MAX(actac.xact_start), erlct.last_cko_ts) AS last_circ + --FROM asset.copy ac + -- LEFT JOIN action.all_circulation actac ON ac.id = actac.target_copy + -- LEFT JOIN extend_reporter.legacy_circ_timestamp erlct ON ac.id = erlct.id + --GROUP BY ac.id, ac.create_date, erlct.last_cko_ts + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + po.ordering_agency AS ordering_agency, + po.id AS purchase_order, + li.id AS lineitem, + lid.id AS lineitem_detail, + cpa.id AS claim_policy_action + FROM + acq.lineitem_detail lid + JOIN acq.lineitem li ON (li.id = lid.lineitem) + JOIN acq.purchase_order po ON (po.id = li.purchase_order) + JOIN acq.claim_policy cp ON (li.claim_policy = cp.id) + JOIN acq.claim_policy_action cpa ON ( + cpa.claim_policy = cp.id + + -- we only care about claim policy actions whose claim + -- interval we'd reached or exceeded + AND (NOW() - cpa.action_interval) > po.order_date + + -- filter out all claim policy actions where claim events + -- have occurred on or after the action's action_interval + AND NOT EXISTS ( + SELECT 1 + FROM + acq.claim_event evt + JOIN acq.claim claim ON ( + claim.id = evt.claim + AND claim.lineitem_detail = lid.id + ) + WHERE + evt.event_date >= (po.order_date + cpa.action_interval) + ) + ) + WHERE + lid.cancel_reason IS NULL + AND li.cancel_reason IS NULL -- belt/suspenders + AND po.cancel_reason IS NULL -- belt/suspenders + AND lid.recv_time IS NULL + AND po.state = 'on-order' + ORDER BY 1, 2, 3, 4, 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT * FROM acq.lineitem_summary + WHERE item_count > (invoice_count + cancel_count) + + + + + + + + + + + + + + + + + + + + + SELECT t.* + FROM action.transit_copy t + JOIN actor.org_unit AS s ON (t.source = s.id) + JOIN actor.org_unit AS d ON (t.dest = d.id) + WHERE s.parent_ou <> d.parent_ou + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT copy, SUM(count) AS count, year, is_renewal FROM ( + SELECT + cp.id as copy, + COUNT(circ.id), + EXTRACT(YEAR FROM circ.xact_start) AS year, + (phone_renewal OR desk_renewal OR opac_renewal) as is_renewal + FROM + asset.copy cp + JOIN action.circulation circ ON (cp.id = circ.target_copy) + GROUP BY 1, 3, 4 + UNION ALL + SELECT + cp.id as copy, + COUNT(circ.id), + EXTRACT(YEAR FROM circ.xact_start) AS year, + (phone_renewal OR desk_renewal OR opac_renewal) as is_renewal + FROM + asset.copy cp + JOIN action.aged_circulation circ ON (cp.id = circ.target_copy) + GROUP BY 1, 3, 4 + UNION ALL + SELECT + id as copy, + circ_count, + -1 AS year, + false as is_renewal + FROM + extend_reporter.legacy_circ_count + )x GROUP BY 1, 3, 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ++======= + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOW() - (SELECT MAX(value) FROM ( + SELECT value::INTERVAL FROM actor.org_unit_ancestor_setting( + 'circ.staff.max_visible_event_age', + COALESCE(targ_circ.circ_lib, targ_ahr.pickup_lib) + ) UNION + SELECT '1000 YEARS'::INTERVAL AS value + ) ous) + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT * FROM metabib.author_field_entry + UNION ALL + SELECT * FROM metabib.keyword_field_entry + UNION ALL + SELECT * FROM metabib.identifier_field_entry + UNION ALL + SELECT * FROM metabib.title_field_entry + UNION ALL + SELECT * FROM metabib.subject_field_entry + UNION ALL + SELECT * FROM metabib.series_field_entry + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT usr, + SUM( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date >= 'today') OR (fine_interval < '1 day' AND due_date > 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN 1 + ELSE 0 + END + ) AS out, + + SUM( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date < 'today') OR (fine_interval < '1 day' AND due_date < 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN 1 + ELSE 0 + END + ) AS overdue, + + SUM( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LOST') THEN 1 ELSE 0 END) AS lost, + SUM( CASE WHEN stop_fines = 'CLAIMSRETURNED' THEN 1 ELSE 0 END) AS claims_returned, + SUM( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LONGOVERDUE') THEN 1 ELSE 0 END) AS long_overdue + FROM action.circulation + WHERE checkin_time IS NULL + GROUP BY 1 + + + + + + + + + + + + + + + + SELECT usr, + STRING_AGG( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date >= 'today') OR (fine_interval < '1 day' AND due_date > 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN id::TEXT + ELSE '0' + END + ,',') AS out, + + STRING_AGG( + CASE + WHEN ( + ((fine_interval >= '1 day' AND due_date < 'today') OR (fine_interval < '1 day' AND due_date < 'now')) + AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','CLAIMSRETURNED','LONGOVERDUE')) + ) THEN id::TEXT + ELSE '0' + END + ,',') AS overdue, + + STRING_AGG( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LOST') THEN id::TEXT ELSE '0' END,',') AS lost, + STRING_AGG( CASE WHEN stop_fines = 'CLAIMSRETURNED' THEN id::TEXT ELSE '0' END,',') AS claims_returned, + STRING_AGG( CASE WHEN (xact_finish IS NULL AND stop_fines = 'LONGOVERDUE') THEN id::TEXT ELSE '0' END,',') AS long_overdue + FROM action.circulation + WHERE checkin_time IS NULL + GROUP BY 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ahr.requestor) AS is_staff_hold, + ahcm_1.copy_count AS potential_copies + FROM action.hold_request ahr + JOIN asset.copy acp ON (acp.id = ahr.current_copy) + JOIN asset.call_number acn ON (acp.call_number = acn.id) + JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id) + JOIN asset.call_number_suffix acns ON (acn.suffix = acns.id) + JOIN actor.usr au ON (au.id = ahr.usr) + JOIN ( + SELECT *, (ROW_NUMBER() OVER (ORDER BY name) + 1000000) AS fallback_position + FROM asset.copy_location + ) acpl_ordered ON (acpl_ordered.id = acp.location) + LEFT JOIN actor.usr_standing_penalty ausp + ON (ahr.usr = ausp.usr AND (ausp.stop_date IS NULL OR ausp.stop_date > NOW())) + LEFT JOIN config.standing_penalty csp + ON ( + csp.id = ausp.standing_penalty AND + csp.block_list LIKE '%CAPTURE%' AND ( + (csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR + (csp.org_depth IS NOT NULL AND ahr.pickup_lib IN ( + SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth)) + ) + ) + ) + JOIN ( + SELECT COUNT(target_copy) AS copy_count, hold + FROM action.hold_copy_map + GROUP BY 2 + ) ahcm_1 ON (ahcm_1.hold = ahr.id) + LEFT JOIN serial.issuance siss + ON (ahr.hold_type = 'I' AND siss.id = ahr.target) + LEFT JOIN asset.copy_location_order acplo + ON (acp.location = acplo.location AND + acp.circ_lib = acplo.org) + WHERE + ahr.capture_time IS NULL AND + ahr.cancel_time IS NULL AND + csp.id IS NULL AND + (ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND + acp.status IN (0,7) + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT ahr.* FROM action.hold_request ahr JOIN (SELECT current_copy, MAX(capture_time) AS capture_time FROM action.hold_request WHERE capture_time IS NOT NULL GROUP BY current_copy)x USING (current_copy, capture_time) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT DISTINCT l.* + FROM action.unfulfilled_hold_loops l + JOIN action.unfulfilled_hold_max_loop m USING (hold) + WHERE l.count = m.max + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + cbrebi.id AS id, -- so we can have a pkey in our view + uvs.id AS session, + uvs.owning_lib, + cbrebi.target_biblio_record_entry + FROM url_verify.session uvs + JOIN container.biblio_record_entry_bucket cbreb + ON (uvs.container = cbreb.id) + JOIN container.biblio_record_entry_bucket_item cbrebi + ON (cbrebi.bucket = cbreb.id) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT b.id, + MAX(dcp.edit_date) AS last_delete_date + FROM biblio.record_entry b + JOIN asset.call_number cn ON (cn.record = b.id) + JOIN asset.copy dcp ON (cn.id = dcp.call_number) + WHERE NOT b.deleted + GROUP BY b.id + HAVING SUM( CASE WHEN NOT dcp.deleted THEN 1 ELSE 0 END) = 0 + + + + + + + + + + + + + + + + + + + + -- -- If we uncomment the RIGHT JOIN against biblio.record_entry, then we'll get a row for every non-deleted bib, whether it has active holds or not. + -- -- If we expect to use pcrud to query against specific bibs, we probably want to do this. However, if we're using this to populate a report, we + -- -- may not. + -- SELECT + -- bre.id AS "bib_id", + -- COALESCE( z.copy_count, 0 ) AS "copy_count", + -- COALESCE( z.hold_count, 0 ) AS "hold_count", + -- COALESCE( z.copy_hold_ratio, 0 ) AS "hold_copy_ratio" + -- FROM ( + SELECT + y.bre AS "id", + COALESCE( x.copy_count, 0 ) AS "copy_count", + y.hold_count AS "hold_count", + (y.hold_count::REAL / (CASE WHEN x.copy_count = 0 OR x.copy_count IS NULL THEN 0.1 ELSE x.copy_count::REAL END)) AS "hold_copy_ratio" + FROM ( + SELECT + (SELECT bib_record FROM reporter.hold_request_record r WHERE r.id = h.id LIMIT 1) AS "bre", + COUNT(*) AS "hold_count" + FROM action.hold_request h + WHERE + cancel_time IS NULL + AND fulfillment_time IS NULL + -- AND NOT frozen -- a frozen hold is still a desired hold, eh? + GROUP BY 1 + )y LEFT JOIN ( + SELECT + (SELECT id + FROM biblio.record_entry + WHERE id = (SELECT record FROM asset.call_number WHERE id = call_number and deleted is false) + ) AS "bre", + COUNT(*) AS "copy_count" + FROM asset.copy + JOIN asset.copy_location loc ON (copy.location = loc.id AND loc.holdable) + WHERE copy.holdable + AND NOT copy.deleted + AND copy.status IN ( SELECT id FROM config.copy_status WHERE holdable ) + GROUP BY 1 + )x ON x.bre = y.bre + -- )z RIGHT JOIN ( + -- SELECT id + -- FROM biblio.record_entry + -- WHERE NOT deleted + -- )bre ON (z.bib_id = bre.id) + + + + + + + + + + + + + + + + + + + + + + SELECT *, + CASE WHEN copy_count_at_pickup_library = 0 THEN 'Infinity'::FLOAT ELSE holds_at_pickup_library::FLOAT/copy_count_at_pickup_library END AS pickup_library_ratio, + CASE WHEN copy_count_everywhere = 0 THEN 'Infinity'::FLOAT ELSE holds_everywhere::FLOAT/copy_count_everywhere END AS everywhere_ratio + FROM + (SELECT bib_record as id, pickup_lib, count(DISTINCT ahr.id) AS holds_at_pickup_library, COALESCE(count(DISTINCT ac.id),0) as copy_count_at_pickup_library + FROM + action.hold_request ahr + JOIN reporter.hold_request_record rhrr USING (id) + LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold) + LEFT JOIN asset.copy ac ON (ahcm.target_copy = ac.id AND ahr.pickup_lib = ac.circ_lib) + WHERE + ahr.cancel_time IS NULL + AND ahr.fulfillment_time IS NULL + GROUP BY bib_record, pickup_lib + )x + JOIN + (SELECT bib_record as id, count(DISTINCT ahr.id) AS holds_everywhere, COALESCE(count(DISTINCT target_copy),0) as copy_count_everywhere + FROM + action.hold_request ahr + JOIN reporter.hold_request_record rhrr USING (id) + LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold) + WHERE + ahr.cancel_time IS NULL + AND ahr.fulfillment_time IS NULL + GROUP BY bib_record + )y + USING (id) + + + + + + + + + + + + + + + + + + + + + + + + + WITH counts_at_ou AS ( + SELECT bib_record, pickup_lib, count(DISTINCT ahr.id) AS holds_at_pickup_library, + COALESCE(count(DISTINCT ac.id),0) as copy_count_at_pickup_library + FROM action.hold_request ahr + JOIN reporter.hold_request_record rhrr USING (id) + LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold) + LEFT JOIN asset.copy ac ON (ahcm.target_copy = ac.id AND ahr.pickup_lib = ac.circ_lib) + WHERE ahr.cancel_time IS NULL + AND ahr.fulfillment_time IS NULL + GROUP BY bib_record, pickup_lib + ) + SELECT *, + CASE WHEN copy_count_at_or_below = 0 THEN 'Infinity'::FLOAT ELSE holds_at_or_below::FLOAT/copy_count_at_or_below END AS hold_copy_ratio_at_or_below_ou, + CASE WHEN copy_count_everywhere = 0 THEN 'Infinity'::FLOAT ELSE holds_everywhere::FLOAT/copy_count_everywhere END AS everywhere_ratio + FROM + (SELECT bib_record AS id, aou.id AS pickup_lib_or_desc, SUM(holds_at_pickup_library) AS holds_at_or_below, SUM(copy_count_at_pickup_library) AS copy_count_at_or_below + FROM actor.org_unit aou + JOIN counts_at_ou cao ON (cao.pickup_lib IN (SELECT id FROM actor.org_unit_descendants(aou.id))) + GROUP BY bib_record, pickup_lib_or_desc + )x + JOIN + (SELECT bib_record AS id, count(DISTINCT ahr.id) AS holds_everywhere, COALESCE(count(DISTINCT target_copy),0) as copy_count_everywhere + FROM + action.hold_request ahr + JOIN reporter.hold_request_record rhrr USING (id) + LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold) + WHERE + ahr.cancel_time IS NULL + AND ahr.fulfillment_time IS NULL + GROUP BY bib_record + )y + USING (id) + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + ac.id, + COALESCE(MAX(actac.xact_start), ac.create_date) AS last_circ_or_create, + MAX(actac.xact_start) AS last_circ + FROM asset.copy ac + LEFT JOIN action.all_circulation actac ON ac.id = actac.target_copy + GROUP BY ac.id + + -- Alternate version, say if you have migrated last checkout information in extend_reporter.legacy_circ_timestamp: + --SELECT + -- ac.id, + -- GREATEST(MAX(actac.xact_start), erlct.last_cko_ts, ac.create_date) AS last_circ_or_create, + -- GREATEST(MAX(actac.xact_start), erlct.last_cko_ts) AS last_circ + --FROM asset.copy ac + -- LEFT JOIN action.all_circulation actac ON ac.id = actac.target_copy + -- LEFT JOIN extend_reporter.legacy_circ_timestamp erlct ON ac.id = erlct.id + --GROUP BY ac.id, ac.create_date, erlct.last_cko_ts + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT + po.ordering_agency AS ordering_agency, + po.id AS purchase_order, + li.id AS lineitem, + lid.id AS lineitem_detail, + cpa.id AS claim_policy_action + FROM + acq.lineitem_detail lid + JOIN acq.lineitem li ON (li.id = lid.lineitem) + JOIN acq.purchase_order po ON (po.id = li.purchase_order) + JOIN acq.claim_policy cp ON (li.claim_policy = cp.id) + JOIN acq.claim_policy_action cpa ON ( + cpa.claim_policy = cp.id + + -- we only care about claim policy actions whose claim + -- interval we'd reached or exceeded + AND (NOW() - cpa.action_interval) > po.order_date + + -- filter out all claim policy actions where claim events + -- have occurred on or after the action's action_interval + AND NOT EXISTS ( + SELECT 1 + FROM + acq.claim_event evt + JOIN acq.claim claim ON ( + claim.id = evt.claim + AND claim.lineitem_detail = lid.id + ) + WHERE + evt.event_date >= (po.order_date + cpa.action_interval) + ) + ) + WHERE + lid.cancel_reason IS NULL + AND li.cancel_reason IS NULL -- belt/suspenders + AND po.cancel_reason IS NULL -- belt/suspenders + AND lid.recv_time IS NULL + AND po.state = 'on-order' + ORDER BY 1, 2, 3, 4, 5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT * FROM acq.lineitem_summary + WHERE item_count > (invoice_count + cancel_count) + + + + + + + + + + + + + + + + + + + + + SELECT t.* + FROM action.transit_copy t + JOIN actor.org_unit AS s ON (t.source = s.id) + JOIN actor.org_unit AS d ON (t.dest = d.id) + WHERE s.parent_ou <> d.parent_ou + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT copy, SUM(count) AS count, year, is_renewal FROM ( + SELECT + cp.id as copy, + COUNT(circ.id), + EXTRACT(YEAR FROM circ.xact_start) AS year, + (phone_renewal OR desk_renewal OR opac_renewal) as is_renewal + FROM + asset.copy cp + JOIN action.circulation circ ON (cp.id = circ.target_copy) + GROUP BY 1, 3, 4 + UNION ALL + SELECT + cp.id as copy, + COUNT(circ.id), + EXTRACT(YEAR FROM circ.xact_start) AS year, + (phone_renewal OR desk_renewal OR opac_renewal) as is_renewal + FROM + asset.copy cp + JOIN action.aged_circulation circ ON (cp.id = circ.target_copy) + GROUP BY 1, 3, 4 + UNION ALL + SELECT + id as copy, + circ_count, + -1 AS year, + false as is_renewal + FROM + extend_reporter.legacy_circ_count + )x GROUP BY 1, 3, 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT ahcm.target_copy AS "id",count(*) AS "count" + FROM + action.hold_request ahr, + action.hold_copy_map ahcm + WHERE + ahr.cancel_time IS NULL AND + ahr.fulfillment_time IS NULL AND + ahr.capture_time IS NULL AND + ahr.id = ahcm.hold + GROUP BY ahcm.target_copy + + + + + + + + + + + + + + + + + ++>>>>>>> 8ab630642cf7331a3cbb3d216f376ff837e7ed52 diff --cc Open-ILS/src/cwopac_templates/opac/parts/misc_util.tt2 index 36659e0309,0000000000..a9885ea70d mode 100644,000000..100644 --- a/Open-ILS/src/cwopac_templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/cwopac_templates/opac/parts/misc_util.tt2 @@@ -1,623 -1,0 +1,651 @@@ +[% + # Support multiscript records via alternate graphic 880 fields + # get_graphic_880s(target_field='100') + # See "Model A" in http://www.loc.gov/marc/bibliographic/ecbdmulti.html + # and $6 description in http://www.loc.gov/marc/bibliographic/ecbdcntf.html + MACRO get_graphic_880s BLOCK; + FOR node IN xml.findnodes('//*[@tag="' _ target_field _ '"]'); + raw_vals = []; + core_val = ''; + FOR subnode IN node.findnodes('./*[not(contains("w 0 4 5 6 7 8 9", @code))]'); + raw_vals.push(subnode.textContent()); + END; + core_val = raw_vals.join(" "); + raw_vals = []; + + linked_fields = []; + FOR sub IN node.findnodes('./*[@code="6"]'); + linked_fields.push(sub.textContent); + END; + graphics = []; + get_linked_880s; + graphic_880s.push({ + primary => {"occur" => occurrence, "value" => core_val}, + graphic => graphics + }); + END; + END; + + MACRO get_linked_880s BLOCK; + FOR link_field IN linked_fields; + target = target_field _ link_field.substr(3); + # Get the linked 880 value + raw_val = ''; + dir = ''; + occurrence = ''; + script = ''; + FOR node IN xml.findnodes('//*[@tag="880"]'); + # Operate only on the target linked fields + FOR linknode IN node.findnodes('./*[@code="6"]'); + lf = linknode.textContent(); + IF lf.substr(0, target.length) == target; + occurrence = lf.substr(4, 2); + rawscript = lf.substr(7, 2); + SWITCH rawscript; + CASE '(3'; + script = 'Arabic'; + CASE '(B'; + script = 'Latin'; + CASE '$1'; + script = 'CJK'; + CASE '(N'; + script = 'Cyrillic'; + CASE '(S'; + script = 'Greek'; + CASE '(2'; + script = 'Hebrew'; + END; + + rawdir = lf.substr(9, 1); + SWITCH rawdir; + CASE 'r'; + dir = 'rtl'; + END; + + raw_vals = []; + FOR subnode IN node.findnodes('./*[not(contains("w 0 5 6 8 9", @code))]'); + raw_vals.push(subnode.textContent()); + END; + raw_val = raw_vals.join(" "); + END; + END; + END; + graphics.push({ + occur => occurrence, + value => raw_val, + script => script, + dir => dir + }); + END; + END; + + BLOCK get_ccvm_icon; + ctx.media_prefix _ '/images/format_icons/' _ ccvm.ctype _ '/' _ ccvm.code _ '.png'; + END; + + # Extract MARC fields from XML + # get_marc_attrs( { marc_xml => doc } ) + BLOCK get_marc_attrs; + xml = args.marc_xml; + + # Map item types to schema.org types; impedance mismatch :( + args.schema.itemtype = {}; + schema_typemap = {}; + + schema_typemap.bluray = 'Movie'; # Movie could also be TVSeries + schema_typemap.book = 'Book'; + schema_typemap.braille = 'Book'; + schema_typemap.casaudiobook = 'Book AudioObject'; + schema_typemap.casmusic = 'MusicAlbum'; + schema_typemap.cdaudiobook = 'Book AudioObject'; + schema_typemap.cdmusic = 'MusicAlbum'; + schema_typemap.dvd = 'Movie'; + schema_typemap.eaudio = 'AudioObject'; + schema_typemap.ebook = 'Book'; + # schema_typemap.equip = ''; + schema_typemap.evideo = 'Movie'; + # schema_typemap.kit = ''; + schema_typemap.lpbook = 'Book'; + schema_typemap.map = 'Map'; + # schema_typemap.microform = ''; + schema_typemap.music = 'MusicAlbum'; + schema_typemap.phonomusic = 'MusicAlbum'; + # schema_typemap.phonospoken = ''; + # schema_typemap.picture = ''; Painting or Photograph? + schema_typemap.score = 'Book'; # schema.org has no generic Music type + schema_typemap.serial = 'Periodical'; + schema_typemap.software = 'SoftwareApplication'; + schema_typemap.vhs = 'Movie'; + + schema_typemap.a = 'Book'; + schema_typemap.e = 'Map'; + schema_typemap.j = 'MusicAlbum'; + + # Hard-coded to match defaults in config.copy_status for all OPAC-visible statuses + schema_copy_status = {}; + schema_copy_status.0 = ''; # Available + schema_copy_status.1 = ''; # Checked out + schema_copy_status.5 = ''; # In process + schema_copy_status.6 = ''; # In transit + schema_copy_status.7 = ''; # Reshelving + schema_copy_status.8 = ''; # On holds shelf + schema_copy_status.9 = ''; # On order + schema_copy_status.12 = ''; # Reserves + + args.isbns = []; + FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]'); + args.isbns.push(isbn.textContent); + END; + + # UPCs can be identified either by ind1="1" or subfield 2 of "upc" + args.upcs = []; + FOR upc IN xml.findnodes('//*[@tag="024" and @ind="1"]/*[@code="a"]'); + args.upcs.push(upc.textContent); + END; + FOR upcfield IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="upc"]'); + my_parent = upcfield.parentNode(); + FOR upc IN my_parent.findnodes('./*[@code="a"]'); + args.upcs.push(upc.textContent); + END; + END; + args.upc = args.upcs.0; # use first UPC as the default + + # These are URIs that link out to related works for linked data purposes, + # such as OCLC Work Entities like http://worldcat.org/entity/work/id/415491 + + # We differentiate between http://schema.org/sameAs relations, which + # are roughly the same as the work we're describing here, and + # http://schema.org/exampleOfWork which point to a broader work, of which + # this is a more specific edition or manifestation. + args.links.sameAs = []; + args.links.exampleOfWork = []; + FOR link_node IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="uri"]'); + my_parent = link_node.parentNode(); + FOR link IN my_parent.findnodes('./*[@code="a"]'); + link_uri = link.textContent | trim; + IF link_uri.search('worldcat.org/entity/work'); + args.links.exampleOfWork.push(link_uri); + ELSE; + args.links.sameAs.push(link_uri); + END; + END; + END; + FOR lccn IN xml.findnodes('//*[@tag="010"]/*[@code="a"]'); + lccn_num = lccn.textContent | trim; + args.links.sameAs.push('http://lccn.loc.gov/' _ lccn_num); + END; + FOR oclcnum IN xml.findnodes('//*[@tag="035"]/*[@code="a"]'); + oclcnum = oclcnum.textContent | trim; + NEXT UNLESS oclcnum.search('^\(OCoLC\)'); + oclcnum = oclcnum | remove('\(OCoLC\)'); + # These prefixes are often included in the 035, even though they should not be + oclcnum = oclcnum | remove('ocm'); + oclcnum = oclcnum | remove('ocn'); + oclcnum = oclcnum | remove('on') | trim; + args.links.sameAs.push('http://www.worldcat.org/oclc/' _ oclcnum); + END; + args.links.sameAs = args.links.sameAs.unique; + + args.issns = []; + FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]'); + args.issns.push(sub.textContent); + END; + args.issn = (args.issns.size) ? args.issn.0 : ''; + + graphic_880s = []; + get_graphic_880s(target_field='100'); + get_graphic_880s(target_field='110'); + get_graphic_880s(target_field='111'); + args.graphic_authors = graphic_880s; + args.authors = []; + FOR author IN args.graphic_authors; + args.authors.push(author.primary.value); + END; + args.author = (args.authors.size) ? args.authors.0 : ''; + + # Include subfields 'abnp' to generate a more comprehensive title display in search results + titresults = xml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b" or @code="n" or @code="p"]'); + titresults_content = []; + FOR sub IN titresults; titresults_content.push(sub.textContent); END; ++ + args.title = titresults_content.join(" "); + # Avoid ugly trailing syntax on brief titles + args.title = args.title | replace('[:;/]$', ''); + + graphic_880s = []; + get_graphic_880s(target_field='245'); + args.graphic_titles = graphic_880s; + args.titles = []; + FOR title IN args.graphic_titles; + args.titles.push(title.primary.value); + END; + args.title_extended = (args.titles.size) ? args.titles.0 : ''; + ++ # Create a version of the title designed for sorted displays. ++ args.sort_title = args.title | upper; ++ ++ # If the title has a "non-filing chaaracters" ++ # (to logically remove leading "The " for example) ++ # chop the title. Otherwise, chop until the first alphanumeric. ++ # BTW: Template Toolkit folds 1-element arrays to scalars! ++ title_node = xml.findnodes('//*[@tag="245"]'); ++ ++ args.nonfiling_characters = title_node.findvalue('@ind2'); ++ ++ IF (args.nonfiling_characters > 0); ++ args.sort_title = args.sort_title.substr(args.nonfiling_characters); ++ ELSE; ++ args.sort_title = args.sort_title.replace('^[^A-Z0-9]*',''); ++ END; ++ + args.pubplaces = []; + pubplace_hunt = xml.findnodes('//*[@tag="260"]/*[@code="a"]') || + xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="a"]'); + FOR sub IN pubplace_hunt; + args.pubplaces.push(sub.textContent); + END; + args.pubplace = (args.pubplaces.size) ? args.pubplaces.0 : ''; + + args.publishers = []; + publishers_hunt = xml.findnodes('//*[@tag="260"]/*[@code="b"]') || + xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="b"]'); + FOR sub IN publishers_hunt; + args.publishers.push(sub.textContent); + END; + args.publisher = (args.publishers.size) ? args.publishers.0 : ''; + + args.pubdates = []; + pubdates_hunt = xml.findnodes('//*[@tag="260"]/*[@code="c"]') || + xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="c"]'); + FOR sub IN pubdates_hunt; + args.pubdates.push(sub.textContent); + END; + args.pubdate = (args.pubdates.size) ? args.pubdates.0 : ''; + + # Get RDA Copyright Info. + args.copyrights = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="4"]/*[@code="c"]'); + args.copyrights.push(sub.textContent); + END; + args.copyright = (args.copyrights.size) ? args.copyrights.0 : ''; + + IF args.copyright.length >= 4; + args.copyrightYear = args.copyright.match('(\d{4})'); + IF args.copyrightYear; + args.copyrightYear = args.copyrightYear.0; + END; + END; + + # Get the RDA Production info. + args.producers = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="b"]'); + args.producers.push(sub.textContent); + END; + args.producer = (args.producers.size) ? args.producers.0 : ''; + + args.prodplaces = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="a"]'); + args.prodplaces.push(sub.textContent); + END; + args.prodplace = (args.prodplaces.size) ? args.prodplaces.0 : ''; + + args.proddates = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="c"]'); + args.proddates.push(sub.textContent); + END; + args.proddate = (args.proddates.size) ? args.proddates.0 : ''; + + # Get the RDA Distribution args. + args.distributors = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="b"]'); + args.distributors.push(sub.textContent); + END; + args.distributor = (args.distributors.size) ? args.distributors.0 : ''; + + args.distplaces = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="a"]'); + args.distplaces.push(sub.textContent); + END; + args.distplace = (args.distplaces.size) ? args.distplaces.0 : ''; + + args.distdates = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="c"]'); + args.distdates.push(sub.textContent); + END; + args.distdate = (args.distdates.size) ? args.distdates.0 : ''; + + # Get the RDA Manufacture args. + args.manufacturers = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="b"]'); + args.manufacturers.push(sub.textContent); + END; + args.manufacturer = (args.manufacturers.size) ? args.manufacturers.0 : ''; + + args.manplaces = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="a"]'); + args.manplaces.push(sub.textContent); + END; + args.manplace = (args.manplaces.size) ? args.manplaces.0 : ''; + + args.mandates = []; + FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="c"]'); + args.mandates.push(sub.textContent); + END; + args.mandate = (args.mandates.size) ? args.mandates.0 : ''; + + # RDA adds 264 to the pubinfo 880 consideration mix + graphic_880s = []; + get_graphic_880s(target_field='260'); + get_graphic_880s(target_field='264'); + args.graphic_pubinfos = graphic_880s; + args.pubinfos = []; + FOR pubinfo IN args.graphic_pubinfos; + args.pubinfos.push(pubinfo.primary.value); + END; + args.pubinfo = (args.pubinfos.size) ? args.pubinfos.0 : ''; + + args.summaries = []; + FOR sub IN xml.findnodes('//*[@tag="520"]/*[@code="a"]'); + args.summaries.push(sub.textContent); + END; + args.summary = (args.summaries.size) ? args.summaries.0 : ''; + + args.targetauds = []; + FOR sub IN xml.findnodes('//*[@tag="521"]/*[@code="a"]'); + args.targetauds.push(sub.textContent); + END; + args.targetaud = (args.targetauds.size) ? args.targetauds.0 : ''; + + # 250 gets pride of place for edition statement, and is the + # only logical choice for 880 graphic fields + graphic_880s = []; + get_graphic_880s(target_field='250'); + args.graphic_editions = graphic_880s; + args.editions = []; + FOR edition IN args.graphic_editions; + args.editions.push(edition.primary.value); + END; + + ed_hunt = xml.findnodes('//*[@tag="250"]/*[@code="a"]') || + xml.findnodes('//*[@tag="534"]/*[@code="b"]') || + xml.findnodes('//*[@tag="775"]/*[@code="b"]'); + FOR sub IN ed_hunt; + args.editions.push(sub.textContent); + END; + args.edition = (args.editions.size) ? args.editions.0 : ''; + + phys_content = []; + FOR sub IN xml.findnodes( + '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]' + ); + phys_content.push(sub.textContent); + END; + args.phys_desc = phys_content.join(" "); + + graphic_880s = []; + get_graphic_880s(target_field='505'); + args.graphic_contents = graphic_880s; + FOR content IN args.graphic_contents; + args.contents.push(content.primary.value); + END; + args.content = (args.contents.size) ? args.contents.0 : ''; + + # Maintain contents_list in case any custom use was made of it + args.contents_list = []; + FOR sub IN xml.findnodes('//*[@tag="505"]'); + args.contents_list.push(sub.textContent); + END; + + # MARC Callnumber + args.marc_cns = []; + FOR sub IN xml.findnodes('//*[@tag="092" or @tag="099"]/*'); + args.marc_cns.push(sub.textContent); + END; + args.marc_cn = (args.marc_cns.size ) ? args.marc_cns.0 : ''; + + + # clean up the ISBN + args.isbn_clean = args.isbns.0.replace('\ .*', ''); + FOR isbn IN args.isbns; + clean_isbn = isbn.replace('\ .*', ''); + clean_isbn = clean_isbn.replace('-', ''); + IF clean_isbn.length == 13; + args.gtin13 = clean_isbn; + LAST; + END; + END; + + # Extract the 856 URLs that are not otherwise represented by asset.uri's + args.online_res = []; + FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]'); + IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's + label = node.findnodes('./*[@code="y" or @code="z"][1]'); + notes = node.findnodes('./*[@code="3"]'); + FOR href IN node.findnodes('./*[@code="u"]'); + NEXT UNLESS href; + # it's possible for multiple $u's to exist within 1 856 tag. + # in that case, honor the label/notes data for the first $u, but + # leave any subsequent $u's as unadorned href's. + # use href/link/note keys to be consistent with args.uri's + args.online_res.push({ + href => href.textContent, + link => (loop.first AND label) ? label.textContent : href.textContent, + note => (loop.first) ? notes.textContent : '' + }); + END; + END; + + args.holdings = []; + args.uris = []; + args.issns = []; + args.resolver_isbns = []; + args.resolver_issns = []; + + # we use $9 of ISBN and ISSN as a flag for e-version + FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]'); + IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS"; + my_parent = resolver_isbn.parentNode(); + FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]'); + args.resolver_isbns.push( + resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '') + ); + END; + END; + END; + + FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]'); + IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS"; + my_parent = resolver_issn.parentNode(); + FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]'); + args.resolver_issns.push( + resolver_issn_val.textContent.replace('[^\d\-X]', '') + ); + END; + END; + END; + + # now snag all issns + FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]'); + args.issns.push( + rawissn.textContent.replace('[^\d\-X]', '') + ); + END; + + ou_hiding_disabled = ctx.org_hiding_disabled(); + ++ # explicitly grabbing the first bib_source node, though there should be only one anyway ++ bib_source = xml.findnodes('//*[local-name()="bib_source"][1]'); ++ args.bib_source.id = bib_source.getAttribute('ident'); ++ args.bib_source.source = bib_source.textContent; ++ + FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]'); + + # Check volume visibility - could push this into XPath + vol.label = volume.getAttribute('label'); + + # Prepend prefix, if any + prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]'); + IF prefix.getAttribute('label') != ''; + vol.label = prefix.getAttribute('label') _ " " _ vol.label; + END; + + # Append prefix, if any + suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]'); + IF suffix.getAttribute('label') != ''; + vol.label = vol.label _ " " _ suffix.getAttribute('label'); + END; + + vol.id = volume.getAttribute('id'); + NEXT IF volume.getAttribute('opac_visible') == 'false'; + NEXT IF volume.getAttribute('deleted') == 'true'; + + IF vol.label == '##URI##'; + FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]'); + res = {}; + res.href = uri.getAttribute('href'); + res.link = uri.getAttribute('label'); + res.note = uri.getAttribute('use_restriction'); + # Avoid displaying the href as the link text if we can display the note instead + IF res.link == res.href AND res.note; + res.link = res.note; + res.note = ''; + END; + args.uris.push(res); + END; + NEXT; + ELSE; + copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]'); + FOR copy IN copies; + parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]'); ++ part_label = ''; + FOREACH part IN parts; + part_label = part.getAttribute('label'); + LAST IF part_label != ''; + END; + # Check copy visibility + cp.deleted = copy.getAttribute('deleted'); + cp.visible = copy.getAttribute('opac_visible'); + NEXT IF (cp.deleted == 'true' OR cp.visible == 'false'); + + # Iterate through all of the children to determine visibility + FOR node IN cp.childNodes; + NEXT IF cp.visible == 'false'; + vis = node.getAttribute('opac_visible'); + del = node.getAttribute('deleted'); + IF vis == 'false' or del == 'true'; + cp.visible = 'false'; + END; + END; + + NEXT IF cp.visible == 'false'; + + loc = copy.findnodes('./*[local-name()="location"]'); + NEXT IF loc.getAttribute('opac_visible') == 'false'; + + circlib = copy.findnodes('./*[local-name()="circlib"]'); + NEXT IF circlib.getAttribute('opac_visible') == 'false'; + + status = copy.findnodes('./*[local-name()="status"]'); + NEXT IF status.getAttribute('opac_visible') == 'false'; + + # extract the circ_lib id from the circ_lib node + circ_lib = copy.findnodes('./*[local-name()="circ_lib"]'); + circ_lib_id = circ_lib.getAttribute('id').replace('.*/', ''); + + UNLESS ou_hiding_disabled; + NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id); + END; + + holding = { + circ_lib => circ_lib_id, + label => vol.label, + part_label => part_label, + location => loc.textContent, + library => circlib.textContent, + status => status.textContent, + status_code => status.getAttribute('ident'), + barcode => copy.getAttribute('barcode'), + owner => volume.getAttribute('lib') + }; + args.holdings.push(holding); + part_label = ''; + END; + END; + END; + + # Extract the copy count summary + count_type = (ctx.is_staff) ? 'staff' : 'public'; + + # Consortial copy count summary first + xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]'; + args.copy_counts = {}; + FOR node IN xml.findnodes(xpath); + FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit']; + depth = node.getAttribute('depth'); + count_org_unit = node.getAttribute('org_unit'); + args.copy_counts.$depth.$attr = node.getAttribute(attr); + args.org_copy_counts.$count_org_unit.$attr = node.getAttribute(attr); + END; + END; + + # Get preferred library copy count + args.plib_copy_counts = {}; + count_type = 'pref_lib'; + xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]'; + FOR node IN xml.findnodes(xpath); + FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit']; + depth = node.getAttribute('depth'); + args.plib_copy_counts.$depth.$attr = node.getAttribute(attr); + END; + END; + + # "mattype" == "custom marc format specifier" + icon_style = ctx.get_cgf('opac.icon_attr').value || 'item_type'; + formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]'; + + args.all_formats = []; + FOR node IN xml.findnodes(formats_xpath); + IF node AND node.textContent; + ccvm = ctx.get_ccvm(node.getAttribute('cvmid')); + NEXT IF ccvm.opac_visible == 'f'; + + format = {}; + type = ccvm.code.remove('-'); # blu-ray to bluray + format.label = ccvm.search_label || ccvm.value; + format.icon = PROCESS get_ccvm_icon ccvm=ccvm; + format.itemtype = schema_typemap.$type || 'CreativeWork'; + + args.all_formats.push(format); # metarecords want all formats + + IF !args.format_label; + # use the first format as the default + args.format_label = format.label; + args.schema.itemtype = format.itemtype; + args.format_icon = format.icon; + END; + END; + END; + + args.bibid = []; + FOR bibid IN xml.findnodes('//*[@tag="901"]/*[@code="c"]'); + args.bibid.push(bibid.textContent); + END; + args.bibid = args.bibid.0; + + END; + + # Get the library or location group + # get_library() + # magically upgrades any use of 'loc' to 'locg', + # which is a superset of 'loc'. + BLOCK get_library; + loc_name = 'locg'; - loc_value = ctx.copy_location_group_org || # resolved locg - CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou; ++ ++ # Location groups don't have shortnames, so they'll take priority ++ # (_org doesn't contain the group and breaks the selector). ++ loc_value = ctx.copy_location_group ? CGI.param(loc_name) ++ : ctx.copy_location_group_org # resolved locg ++ || CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou; + END; + +%]