FROM $h_table h
JOIN $a_table a ON (h.current_copy = a.id)
LEFT JOIN $ord_table ord ON (a.location = ord.location AND a.circ_lib = ord.org)
+ LEFT JOIN actor.usr_standing_penalty ausp
+ ON ( h.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%' )
WHERE a.circ_lib = ?
AND h.capture_time IS NULL
AND h.cancel_time IS NULL
AND (h.expire_time IS NULL OR h.expire_time > NOW())
+ AND csp.id IS NULL
$status_filter
ORDER BY CASE WHEN ord.position IS NOT NULL THEN ord.position ELSE 999 END, h.request_time
LIMIT $limit
SELECT count(*)
FROM $h_table h
JOIN $a_table a ON (h.current_copy = a.id)
+ LEFT JOIN actor.usr_standing_penalty ausp
+ ON ( h.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%' )
WHERE a.circ_lib = ?
AND h.capture_time IS NULL
AND h.cancel_time IS NULL
AND (h.expire_time IS NULL OR h.expire_time > NOW())
+ AND csp.id IS NULL
$status_filter
SQL
}