adding circ and hold history query scripts
authorChris Sharp <csharp@georgialibraries.org>
Mon, 19 Oct 2015 15:46:47 +0000 (11:46 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 19 Oct 2015 15:46:47 +0000 (11:46 -0400)
get_circ_history.sh [new file with mode: 0755]
get_hold_history.sh [new file with mode: 0755]

diff --git a/get_circ_history.sh b/get_circ_history.sh
new file mode 100755 (executable)
index 0000000..4cba791
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-b item barcode] [-l result limit]"
+echo
+echo "If you don't specify item barcode, you'll be prompted"
+echo "to provide one.  Result limit defaults to 10."
+echo
+}
+
+while getopts i:l:u:h OPTIONS
+do case "$OPTIONS" in
+       i)  ITEM_BARCODE="$OPTARG";; # TODO: allow multiple barcodes
+       l)  LIMIT="$OPTARG";;
+       u)  USER_BARCODE="$OPTARG";;
+       h)  Usage; exit 1;;
+       esac
+done
+
+# Note: it is assumed that you're using .pgpass here
+PSQL="/usr/bin/psql"
+PSQL_USER="evergreen"
+PSQL_DB="evergreen"
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+        echo "We need an item barcode and/or a user barcode."
+        read -p "Please enter the item barcode (Enter for none): " ITEM_BARCODE
+        read -p "Please enter the user barcode (Enter for none): " USER_BARCODE
+fi
+
+# if we have a user barcode but no item barcode...
+if [ -z "$ITEM_BARCODE" ] && [ ! -z "$USER_BARCODE" ]; then
+        SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE'"
+# if we have an item barcode but no user barcode...
+elif [ ! -z "$ITEM_BARCODE" ] && [ -z "$USER_BARCODE" ]; then
+        SQL_WHERE="WHERE cp.barcode = '$ITEM_BARCODE'"
+# both are empty, exit the script
+elif [ -z "$ITEM_BARCODE" ] && [ -z "$USER_BARCODE" ]; then
+                echo "We need either an item or user barcode to run this script.  Exiting..."
+                exit 1;
+# if we've gotten this far, we have both
+else
+        SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE' AND cp.barcode = '$ITEM_BARCODE'"
+fi
+
+if [ -z "$LIMIT" ]; then
+       LIMIT=10
+fi
+
+read -d '' SQL <<EOF
+SELECT         c.id as "Circ ID",
+       u_card.barcode as "Patron",
+       c.xact_start as "Check Out Date/Time",
+       c.due_date as "Due Date/Time",
+       c.checkin_time as "Check In Date/Time",
+       c.stop_fines_time as "Fines Stopped Date/Time",
+       c.stop_fines as "Fines Stopped Reason",
+       c.xact_finish as "Transaction Closed Date/Time",
+       cp.barcode as "Item Barcode",
+       co_lib.shortname as "Check Out Library",
+       co_ws.name as "Check Out Workstation",
+       co_staff_card.barcode as "Check Out Staff",
+       ci_lib.shortname as "Check In Library",
+       ci_ws.name as "Check In Workstation",
+       ci_staff_card.barcode as "Check In Staff",
+       c.renewal_remaining as "Remaining Renewals",
+       c.duration_rule as "Circulation Duration Rule",
+       c.duration as "Circulation Duration",
+       c.recurring_fine_rule as "Recurring Fine Rule",
+       c.recurring_fine as "Recurring Fine",
+       c.max_fine_rule as "Maximum Fine Rule",
+       c.max_fine as "Maximum Fine",
+       c.grace_period as "Grace Period"
+FROM   action.circulation c
+       INNER JOIN actor.usr u ON (c.usr = u.id)
+       INNER JOIN actor.card u_card ON (u.card = u_card.id)
+       INNER JOIN asset.copy cp ON (c.target_copy = cp.id)
+       INNER JOIN actor.org_unit co_lib ON (c.circ_lib = co_lib.id)
+       LEFT OUTER JOIN actor.workstation co_ws ON (c.workstation = co_ws.id)
+       INNER JOIN actor.usr co_staff ON (c.circ_staff = co_staff.id)
+       INNER JOIN actor.card co_staff_card ON (co_staff.card = co_staff_card.id)
+       LEFT OUTER JOIN actor.org_unit ci_lib ON (c.checkin_lib = ci_lib.id)
+       LEFT OUTER JOIN actor.workstation ci_ws ON (c.checkin_workstation = ci_ws.id)
+       LEFT OUTER JOIN actor.usr ci_staff ON (c.checkin_staff = ci_staff.id)
+       INNER JOIN actor.card ci_staff_card ON (ci_staff.card = ci_staff_card.id)
+$SQL_WHERE
+ORDER BY c.xact_start desc
+LIMIT $LIMIT
+EOF
+
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+
+$PSQL -U "$PSQL_USER" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
diff --git a/get_hold_history.sh b/get_hold_history.sh
new file mode 100755 (executable)
index 0000000..199ec45
--- /dev/null
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-i item barcode] [-u user_barcode ] [-l result limit]"
+echo
+echo "If you don't specify item or user barcode, you'll be prompted"
+echo "to provide them.  Result limit defaults to 10."
+echo
+}
+
+while getopts i:l:u:h OPTIONS
+do case "$OPTIONS" in
+       i)  ITEM_BARCODE="$OPTARG";; # TODO: allow multiple barcodes
+       l)  LIMIT="$OPTARG";;
+       u)  USER_BARCODE="$OPTARG";;
+       h)  Usage; exit 1;;
+       esac
+done
+
+# Note: it is assumed that you're using .pgpass here
+PSQL="/usr/bin/psql"
+PSQL_USER="evergreen"
+PSQL_DB="evergreen"
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+       echo "We need an item barcode and/or a user barcode."
+        read -p "Please enter the item barcode (Enter for none): " ITEM_BARCODE
+        read -p "Please enter the user barcode (Enter for none): " USER_BARCODE
+fi
+
+# if we have a user barcode but no item barcode...
+if [ -z "$ITEM_BARCODE" ] && [ ! -z "$USER_BARCODE" ]; then
+       SQL_WHERE="WHERE h_usr_card.barcode = '$USER_BARCODE'"
+# if we have an item barcode but no user barcode...
+elif [ ! -z "$ITEM_BARCODE" ] && [ -z "$USER_BARCODE" ]; then
+       SQL_WHERE="WHERE cp.barcode = '$ITEM_BARCODE'"
+# both are empty, exit the script
+elif [ -z "$ITEM_BARCODE" ] && [ -z "$USER_BARCODE" ]; then
+                echo "We need either an item or user barcode to run this script.  Exiting..."
+                exit 1;
+# if we've gotten this far, we have both
+else
+       SQL_WHERE="WHERE h_usr_card.barcode = '$USER_BARCODE' AND cp.barcode = '$ITEM_BARCODE'"
+fi
+
+if [ -z "$LIMIT" ]; then
+       LIMIT=10
+fi
+
+read -d '' SQL <<EOF
+SELECT h.id as "Hold ID",
+       h_usr_card.barcode as "Hold Patron",
+       case when h.requestor = h.usr then 'Self-Placed'
+       else h_requestor_card.barcode 
+       end as "Hold Requestor",
+       h.request_time as "Request Date/Time",
+       r_lib.shortname as "Request Library",
+       case when hold_type = 'T' then 'Title Hold'
+       when hold_type = 'V' then 'Volume Hold'
+       when hold_type = 'C' then 'Copy Hold'
+       when hold_type = 'M' then 'Metarecord Hold'
+       when hold_type = 'P' then 'Part Hold'
+       end as "Hold Type",
+       case when hold_type = 'T' then 'Bib ID: ' || target::text
+       when hold_type = 'V' then 'Call Number ID: ' || target::text
+       when hold_type = 'C' then 'Copy ID: ' || target::text
+       else target::text
+       end as "Hold Request Target",
+       cp.barcode as "Currently Targeted Item",
+       pu_lib.shortname as "Pick-up Library",
+       h.phone_notify as "Phone Notification Number",
+       h.email_notify as "Email Notification Enabled?",
+       h.sms_notify as "SMS Notification Number",
+       sms_carrier.name as "SMS Carrier",
+       h.frozen as "Hold Request Suspended?",
+       h.thaw_date as "Hold Request Active Date/Time",
+       h.capture_time as "Item Capture Date/Time",
+       h.shelf_time as "Hold Shelf Arrival Date/Time",
+       h.shelf_expire_time as "Hold Shelf Expiration Date/Time",
+       shelf_lib.shortname as "Current Shelf Library",
+       h.behind_desk as "Hold Behind Desk?",
+       h.fulfillment_time as "Hold Fulfillment Date/Time",
+       ff_lib.shortname as "Hold Fulfillment Library",
+       ff_staff_card.barcode as "Hold Fulfillment Staff",
+       h.checkin_time as "Item Checkin Date/Time",
+       h.return_time as "Hold Return Date/Time",
+       h.expire_time as "Request Expiration Date/Time",
+       h.cancel_time as "Hold Cancellation Time",
+       hrcc.label as "Hold Cancellation Cause",
+       h.cancel_note as "Hold Cancellation Note"
+FROM action.hold_request h
+       INNER JOIN actor.usr h_usr ON (h.usr = h_usr.id)
+       INNER JOIN actor.card h_usr_card ON (h_usr.card = h_usr_card.id)
+       INNER JOIN actor.usr h_requestor ON (h.requestor = h_requestor.id)
+       INNER JOIN actor.card h_requestor_card ON (h_requestor.card = h_requestor_card.id)
+       INNER JOIN actor.org_unit r_lib ON (h.request_lib = r_lib.id)
+       LEFT OUTER JOIN asset.copy cp ON (h.current_copy = cp.id)
+       INNER JOIN actor.org_unit pu_lib ON (h.pickup_lib = pu_lib.id)
+       LEFT OUTER JOIN config.sms_carrier sms_carrier ON (h.sms_carrier = sms_carrier.id)
+       LEFT OUTER JOIN actor.org_unit shelf_lib ON (h.current_shelf_lib = shelf_lib.id)
+       LEFT OUTER JOIN actor.org_unit ff_lib ON (h.fulfillment_lib = ff_lib.id)
+       LEFT OUTER JOIN actor.usr ff_staff ON (h.fulfillment_staff = ff_staff.id)
+       INNER JOIN actor.card ff_staff_card ON (ff_staff.card = ff_staff_card.id)
+       LEFT OUTER JOIN action.hold_request_cancel_cause hrcc ON (h.cancel_cause = hrcc.id)
+$SQL_WHERE
+ORDER BY h.request_time desc
+LIMIT $LIMIT
+EOF
+
+# debugging statements go here
+#echo "Command line arguments are: $*"
+#echo "\$USER_BARCODE = $USER_BARCODE, \$ITEM_BARCODE = $ITEM_BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+
+$PSQL -U "$PSQL_USER" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"