Adding pines-finder server scripts
authorChris Sharp <csharp@georgialibraries.org>
Thu, 1 Feb 2018 22:39:16 +0000 (17:39 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Thu, 1 Feb 2018 22:39:16 +0000 (17:39 -0500)
25 files changed:
helper-scripts/get_circ_history.sh [deleted file]
helper-scripts/get_combined_perms_per_profile.sh [deleted file]
helper-scripts/get_hold_history.sh [deleted file]
pines-finder/auditor_actor_usr_history.sh [new file with mode: 0755]
pines-finder/auditor_asset_copy_history.sh [new file with mode: 0755]
pines-finder/custom_perms_per_user.sh [new file with mode: 0755]
pines-finder/find_at_email_notifications.sh [new file with mode: 0755]
pines-finder/find_at_hold_notifications.sh [new file with mode: 0755]
pines-finder/find_at_pmc_notifications.sh [new file with mode: 0755]
pines-finder/find_at_sms_notifications.sh [new file with mode: 0755]
pines-finder/generate_user_checkout_history.sh [new file with mode: 0755]
pines-finder/get_active_library_count.sh [new file with mode: 0755]
pines-finder/get_active_library_list.sh [new file with mode: 0755]
pines-finder/get_active_library_list_with_ids.sh [new file with mode: 0755]
pines-finder/get_billing_history.sh [new file with mode: 0755]
pines-finder/get_circ_history.sh [new file with mode: 0755]
pines-finder/get_combined_perms_per_profile.sh [new file with mode: 0755]
pines-finder/get_email_logs.sh [new file with mode: 0755]
pines-finder/get_hold_history.sh [new file with mode: 0755]
pines-finder/get_reports_template_ids.sh [new file with mode: 0755]
pines-finder/get_transit_history.sh [new file with mode: 0755]
pines-finder/pg_config [new file with mode: 0644]
pines-finder/predue_lookup.sh [new file with mode: 0755]
pines-finder/run_sql_script.sh [new file with mode: 0755]
pines-finder/sip_account_lookup.sh [new file with mode: 0755]

diff --git a/helper-scripts/get_circ_history.sh b/helper-scripts/get_circ_history.sh
deleted file mode 100755 (executable)
index d30155f..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/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_HOST="mydbhost"
-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" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
diff --git a/helper-scripts/get_combined_perms_per_profile.sh b/helper-scripts/get_combined_perms_per_profile.sh
deleted file mode 100755 (executable)
index 0c0b5f8..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/bash
-
-Usage () {
-echo "USAGE: $0 <permission group name>"
-exit 1
-}
-
-GROUP_NAME="$1"
-PG_USER="evergreen"
-PSQL="/usr/bin/psql"
-PG_DB="evergreen"
-
-
-if [ -z $GROUP_NAME ]; then
-    Usage
-fi
-read -d '' SQL <<EOF
-select  perm.code as "Permission", 
-        perm.description as "Description", 
-        grp.name as "Permission Level", 
-        case 
-            when map.depth = 0 then 'Consortium' 
-            when map.depth = 1 then 'System' 
-            when map.depth = 2 then 'Branch' 
-        end as "Depth", 
-        case 
-            when map.grantable = true then 'Grantable' 
-            when map.grantable = false then 'Not Grantable' 
-        end as "Grantability" 
-from    permission.grp_tree grp 
-        join permission.grp_perm_map map on (map.grp = grp.id) 
-        join permission.perm_list perm on (map.perm = perm.id) 
-where   grp.id in (
-            select id 
-            from permission.grp_ancestors(
-                (select id 
-                    from permission.grp_tree 
-                    where name = '$GROUP_NAME')
-            )
-        ) 
-        order by 1, 2;
-EOF
-
-PGUSER="$PG_USER" "$PSQL" -A --pset footer --field-separator ',' -o "$GROUP_NAME-perms.out" -c "$SQL" "$PG_DB"
-
diff --git a/helper-scripts/get_hold_history.sh b/helper-scripts/get_hold_history.sh
deleted file mode 100755 (executable)
index ff3ca15..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/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_HOST="mydbhost"
-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" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
diff --git a/pines-finder/auditor_actor_usr_history.sh b/pines-finder/auditor_actor_usr_history.sh
new file mode 100755 (executable)
index 0000000..a2d4fd9
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-u user barcode] [-l result limit] [-f]"
+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 l:u:fh OPTIONS
+do case "$OPTIONS" in
+    l)  LIMIT="$OPTARG";;
+    u)  USER_BARCODE="$OPTARG";;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+        echo "We need user barcode."
+        read -p "Please enter the user barcode: " USER_BARCODE
+fi
+
+# no data, exit the script
+if [ -z "$USER_BARCODE" ]; then
+                echo "We need a user barcode to run this script.  Exiting..."
+                exit 1;
+else
+        SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE'"
+fi
+
+if [ -z "$LIMIT" ]; then
+    LIMIT=10
+fi
+
+read -d '' SQL <<EOF
+SELECT     aauh.audit_time as "Audit Time",
+    audit_user_card.barcode as "Audit User Barcode",
+    audit_user.first_given_name as "Audit User First Name",
+    audit_user.second_given_name as "Audit User Middle Name",
+    audit_user.family_name as "Audit User Last Name",
+    aauh_card.barcode as "User Barcode",
+    aauh.first_given_name as "User First Name",
+    aauh.second_given_name as "User Middle Name",
+    aauh.family_name as "User Last Name",
+    home_ou.shortname as "Home Library",
+    aauh.alias as "Hold Shelf Alias",
+    mailing_addr.street1 as "Mailing Address Street 1",
+    mailing_addr.street2 as "Mailing Address Street 2",
+    mailing_addr.city as "Mailing Address City",
+    mailing_addr.state as "Mailing Address State",
+    mailing_addr.country as "Mailing Address Country",
+    mailing_addr.post_code as "Mailing Address Postal Code",
+        billing_addr.street1 as "Billing Address Street 1",
+        billing_addr.street2 as "Billing Address Street 2",
+        billing_addr.city as "Billing Address City",
+        billing_addr.state as "Billing Address State",
+        billing_addr.country as "Billing Address Country",
+        billing_addr.post_code as "Billing Address Postal Code",
+    aauh.day_phone as "Day Phone",
+    aauh.evening_phone as "Evening Phone",
+    aauh.other_phone as "Other Phone",
+        aauh.email as "Email Address",
+    grp.name as "Permission Profile",
+    aauh.dob as "Date of Birth",
+    aauh.juvenile as "Juvenile?",
+    aauh.active as "Active?",
+    aauh.deleted as "Deleted?",
+    aauh.barred as "Barred?",
+    aauh.alert_message as "Alert Message",
+    aauh.create_date as "Account Creation Date",
+    aauh.expire_date as "Account Expiration Date",
+    aauh.last_update_time as "Last Update Time"
+FROM    auditor.actor_usr_history aauh
+    INNER JOIN actor.usr u ON (aauh.id = u.id)
+    INNER JOIN actor.card u_card ON (u.card = u_card.id)
+    INNER JOIN actor.card aauh_card ON (aauh.card = aauh_card.id)
+    INNER JOIN actor.org_unit home_ou ON (aauh.home_ou = home_ou.id)
+    LEFT OUTER JOIN actor.workstation audit_ws ON (aauh.audit_ws = audit_ws.id)
+    INNER JOIN actor.usr audit_user ON (aauh.audit_user = audit_user.id)
+    INNER JOIN actor.card audit_user_card ON (audit_user.card = audit_user_card.id)
+    INNER JOIN permission.grp_tree grp ON (aauh.profile = grp.id)
+    LEFT OUTER JOIN actor.usr_address mailing_addr ON (aauh.mailing_address = mailing_addr.id)
+    LEFT OUTER JOIN actor.usr_address billing_addr ON (aauh.billing_address = billing_addr.id)
+    
+$SQL_WHERE
+ORDER BY aauh.audit_time desc
+LIMIT $LIMIT
+EOF
+
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o auditor_actor_usr_history_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/auditor_asset_copy_history.sh b/pines-finder/auditor_asset_copy_history.sh
new file mode 100755 (executable)
index 0000000..827a40f
--- /dev/null
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-i item barcode] [-l result limit] [-f]"
+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 l:i:efh OPTIONS
+do case "$OPTIONS" in
+    l)  LIMIT="$OPTARG";;
+    i)  ITEM_BARCODE="$OPTARG";;
+    e)  EXPLAIN="EXPLAIN";;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+        echo "We need an item barcode."
+        read -p "Please enter the item barcode: " ITEM_BARCODE
+fi
+
+# no data, exit the script
+if [ -z "$ITEM_BARCODE" ]; then
+                echo "We need an item barcode to run this script.  Exiting..."
+                exit 1;
+else
+        SQL_WHERE="WHERE aach.id in (select id from asset.copy where barcode = '$ITEM_BARCODE')"
+fi
+
+if [ -z "$LIMIT" ]; then
+    LIMIT=10
+fi
+
+read -d '' SQL <<EOF
+$EXPLAIN SELECT     aach.audit_time as "Audit Time",
+    audit_user_card.barcode as "Audit User Barcode",
+    audit_user.first_given_name as "Audit User First Name",
+    audit_user.second_given_name as "Audit User Middle Name",
+    audit_user.family_name as "Audit User Last Name",
+    aach.barcode as "Item Barcode",
+    audit_ws.name as "Audit Workstation",
+    audit_ws_ou.shortname as "Audit Workstation Owning Lib",
+    circ_lib.shortname as "Copy Circulating Library",
+    creator_card.barcode as "Copy Creator",
+    aach.create_date as "Copy Creation Date/Time",
+    aach.active_date as "Copy Activation Date/Time",
+    aach.edit_date as "Last Copy Edit Date/Time",
+    acn.id as "Call Number/Volume ID",
+    acn.label as "Call Number Label",
+    status.name as "Copy Status",
+    location.name as "Copy/Shelving Location",
+    case
+        when aach.loan_duration = 1
+        then 'short'
+        when aach.loan_duration = 2
+        then 'normal'
+        when aach.loan_duration = 3
+        then 'long'
+    end as "Loan Duration",
+    case
+        when aach.fine_level = 1
+        then 'low'
+        when aach.fine_level = 2
+        then 'normal'
+        when aach.fine_level = 3
+        then 'high'
+    end as "Fine Level",
+    crahp.name as "Hold Age Protection Rule",
+    aach.circulate as "Circulate?",
+    aach.deposit as "Deposit?",
+    aach.ref as "Reference?",
+    aach.holdable as "Holdable?",
+    aach.opac_visible as "OPAC Visible?",
+    aach.deleted as "Deleted?",
+    aach.mint_condition as "Mint Condition?",    
+    aach.deposit_amount as "Deposit Amount",
+    aach.price as "Price",
+    aach.cost as "Cost",
+    aach.circ_modifier as "Circulation Modifier",
+    aach.circ_as_type as "Circ As Type",
+    aach.dummy_title as "Pre-Cat Title",
+    aach.dummy_author as "Pre-Cat Author",
+    aach.dummy_isbn as "Pre-Cat ISBN",
+    aach.alert_message as "Alert Message",
+    aach.status_changed_time as "Status Last Changed Date/Time",
+    cfg.name as "Floating Group"
+FROM    auditor.asset_copy_history aach
+    LEFT OUTER JOIN actor.workstation audit_ws ON (aach.audit_ws = audit_ws.id)
+    LEFT OUTER JOIN actor.org_unit audit_ws_ou ON (audit_ws.owning_lib = audit_ws_ou.id)
+    LEFT OUTER JOIN actor.usr audit_user ON (aach.audit_user = audit_user.id)
+    LEFT OUTER JOIN actor.card audit_user_card ON (audit_user.card = audit_user_card.id)
+    INNER JOIN actor.org_unit circ_lib ON (aach.circ_lib = circ_lib.id)
+    INNER JOIN actor.usr creator ON (aach.creator = creator.id)
+    INNER JOIN actor.card creator_card ON (creator.card = creator_card.id)
+    LEFT OUTER JOIN asset.call_number acn ON (aach.call_number = acn.id)
+    INNER JOIN config.copy_status status ON (aach.status = status.id)
+    INNER JOIN asset.copy_location location ON (aach.location = location.id)
+    LEFT OUTER JOIN config.rule_age_hold_protect crahp ON (aach.age_protect = crahp.id)
+    LEFT OUTER JOIN config.floating_group cfg ON (aach.floating = cfg.id)
+$SQL_WHERE
+ORDER BY aach.audit_time desc
+LIMIT $LIMIT
+EOF
+
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o auditor_asset_copy_history_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/custom_perms_per_user.sh b/pines-finder/custom_perms_per_user.sh
new file mode 100755 (executable)
index 0000000..db4e5fe
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-u user barcode] [-l result limit] [-f]"
+echo
+echo "If you don't specify a user barcode, you'll be prompted"
+echo "to provide one.  Result limit defaults to 10."
+echo
+}
+
+while getopts l:u:fh OPTIONS
+do case "$OPTIONS" in
+    l)  LIMIT="$OPTARG";;
+    u)  USER_BARCODE="$OPTARG";;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+        echo "We need a user barcode."
+        read -p "Please enter the user barcode: " USER_BARCODE
+fi
+
+# no data, exit the script
+if [ -z "$USER_BARCODE" ]; then
+                echo "We need a user barcode to run this script.  Exiting..."
+                exit 1;
+else
+        SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE'"
+fi
+
+if [ -z "$LIMIT" ]; then
+    LIMIT=10
+fi
+
+read -d '' SQL <<EOF
+SELECT     perm.code as "Permission",
+    case 
+        when (map.depth = 0) then 'Consortium'
+        when (map.depth = 1) then 'System'
+        when (map.depth = 2) then 'Branch'
+    end as "Depth",
+    map.grantable as "Grantable"
+
+FROM    permission.perm_list as perm
+    INNER JOIN permission.usr_perm_map map ON (map.perm = perm.id)
+    INNER JOIN actor.usr u ON (map.usr = u.id)
+    INNER JOIN actor.card u_card on (u.card = u_card.id)
+$SQL_WHERE
+ORDER BY perm.code
+LIMIT $LIMIT
+EOF
+
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o custom_permissions_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/find_at_email_notifications.sh b/pines-finder/find_at_email_notifications.sh
new file mode 100755 (executable)
index 0000000..b70e5b2
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+Usage () { echo -e "Usage:\n\t$0 [-u patron barcode OR -e patron email] [-s state] [-f (export file)] -t event type [-l result limit (default 10)]\n\n'event type' is required and can be one of the following:\n\n\tpreminder\n\toverdue\n\thold-ready\n\tlongoverdue\n\thold-cancelled\n\taccount-expire\n\tlost\n\twelcome\n\tpayment-receipt\n\n'state' can be one of the following (default is 'complete'):\n\n\tinvalid\n\tpending\n\tcomplete\n\tvalidating\n\tcollected\n\tvalid\n\treacting\n\tcollecting\n\terror\n\tfound\n" && exit 1; 
+}
+
+while getopts l:u:e:s:ft:h OPTIONS
+do case "$OPTIONS" in
+        l)  LIMIT="$OPTARG";;
+        u)  BARCODE="$OPTARG";;
+        e)  EMAIL="$OPTARG";;
+        s)  STATE="$OPTARG";;
+        f)  EXPORT_FILE=1;;
+        t)  AT_EVENT_DEF="$OPTARG";;
+        h)  Usage;;
+        esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ ! -z "$AT_EVENT_DEF" ]; then
+if [ ! -z "$BARCODE" ] && [ -z "$EMAIL" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT usr
+                FROM actor.card
+                WHERE barcode = '$BARCODE'
+EOF
+elif [ -z "$BARCODE" ] && [ ! -z "$EMAIL" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT id
+                FROM actor.usr
+                WHERE email = '$EMAIL'
+EOF
+fi
+else
+    Usage
+fi
+
+case $AT_EVENT_DEF in 
+ "preminder")           AT_EVENT_DEF="6" TARGET_TABLE="action.circulation" TARGET_FIELD="usr" ;;
+ "overdue")             AT_EVENT_DEF="1" TARGET_TABLE="action.circulation" TARGET_FIELD="usr" ;;
+ "hold-ready")          AT_EVENT_DEF="5" TARGET_TABLE="action.hold_request" TARGET_FIELD="usr" ;;
+ "longoverdue")         AT_EVENT_DEF="50" TARGET_TABLE="action.circulation" TARGET_FIELD="usr" ;;
+ "hold-canceled")       AT_EVENT_DEF="38, 109, 110" TARGET_TABLE="action.hold_request" TARGET_FIELD="usr" ;;
+ "account-expire")      AT_EVENT_DEF="106" TARGET_TABLE="actor.usr" TARGET_FIELD="id" ;;
+ "lost")                AT_EVENT_DEF="111" TARGET_TABLE="action.circulation" TARGET_FIELD="usr" ;;
+ "welcome")             AT_EVENT_DEF="107" TARGET_TABLE="actor.usr" TARGET_FIELD="id" ;;
+ "payment-receipt")     AT_EVENT_DEF="29" TARGET_TABLE="money.billable_xact" TARGET_FIELD="usr" ;;
+ "*")                   Usage ;;
+esac
+
+if [ -z "$STATE" ]; then
+    STATE="complete"
+fi
+
+if [ -z "$LIMIT" ]; then
+        LIMIT=10
+fi
+
+read -d '' SQL <<EOQ
+SELECT atev.id, atev.run_time, atevo.data
+FROM action_trigger.event atev
+INNER JOIN action_trigger.event_output atevo ON (atev.template_output = atevo.id)
+WHERE atev.state = '$STATE'
+AND atev.event_def in ($AT_EVENT_DEF)
+AND EXISTS (
+    SELECT 1
+    FROM $TARGET_TABLE target
+    WHERE atev.target = target.id
+    AND target.$TARGET_FIELD IN (
+    $SUBSELECT
+    )
+)
+ORDER BY 1 DESC
+LIMIT $LIMIT;
+EOQ
+
+#debug
+echo "$SQL"
+
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o at_email_notifications_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/find_at_hold_notifications.sh b/pines-finder/find_at_hold_notifications.sh
new file mode 100755 (executable)
index 0000000..012bee4
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+Usage () { echo -e "Usage:\n\t$0 [-u patron barcode OR -e patron email] [-s state] [-f (export file)] [-t (sms rather than email notifications)] [-l result limit (default 10)]\n\n'state' can be one of the following (default is 'complete'):\n\n\tinvalid\n\tpending\n\tcomplete\n\tvalidating\n\tcollected\n\tvalid\n\treacting\n\tcollecting\n\terror\n\tfound\n" && exit 1; 
+}
+
+while getopts l:u:e:s:fth OPTIONS
+do case "$OPTIONS" in
+        l)  LIMIT="$OPTARG";;
+        u)  BARCODE="$OPTARG";;
+        e)  EMAIL="$OPTARG";;
+        s)  STATE="$OPTARG";;
+        f)  EXPORT_FILE=1;;
+        t)  AT_EVENT_DEF=103;;
+        h)  Usage; exit 1;;
+        esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ ! -z "$BARCODE" ] && [ -z "$EMAIL" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT usr
+                FROM actor.card
+                WHERE barcode = '$BARCODE'
+EOF
+elif [ -z "$BARCODE" ] && [ ! -z "$EMAIL" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT id
+                FROM actor.usr
+                WHERE email = '$EMAIL'
+EOF
+else
+    Usage
+fi
+
+if [ -z "$AT_EVENT_DEF" ]; then
+    AT_EVENT_DEF=5
+fi
+
+if [ -z "$STATE" ]; then
+    STATE="complete"
+fi
+
+if [ -z "$LIMIT" ]; then
+        LIMIT=10
+fi
+
+read -d '' SQL <<EOQ
+SELECT atev.id, atev.run_time, atevo.data
+FROM action_trigger.event atev
+INNER JOIN action_trigger.event_output atevo ON (atev.template_output = atevo.id)
+WHERE atev.state = '$STATE'
+AND atev.event_def = $AT_EVENT_DEF
+AND EXISTS (
+    SELECT 1
+    FROM action.hold_request ahr
+    WHERE atev.target = ahr.id
+    AND ahr.usr IN (
+    $SUBSELECT
+    )
+)
+ORDER BY 1 DESC
+LIMIT $LIMIT;
+EOQ
+
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o at_hold_notifications_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/find_at_pmc_notifications.sh b/pines-finder/find_at_pmc_notifications.sh
new file mode 100755 (executable)
index 0000000..77871fc
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+Usage () { echo -e "Usage:\n\t$0 [-u patron barcode OR -e patron email] [-s state] [-f (export file)] -t event type [-l result limit (default 10)]\n\n'event type' is required and can be one of the following:\n\n\tpreminder\n\toverdue\n\thold-ready\n\tlongoverdue\n\thold-cancelled\n\n'state' can be one of the following (default is 'complete'):\n\n\tinvalid\n\tpending\n\tcomplete\n\tvalidating\n\tcollected\n\tvalid\n\treacting\n\tcollecting\n\terror\n\tfound\n" && exit 1; 
+}
+
+while getopts l:u:e:s:ft:h OPTIONS
+do case "$OPTIONS" in
+        l)  LIMIT="$OPTARG";;
+        u)  BARCODE="$OPTARG";;
+        e)  EMAIL="$OPTARG";;
+        s)  STATE="$OPTARG";;
+        f)  EXPORT_FILE=1;;
+        t)  AT_EVENT_DEF="$OPTARG";;
+        h)  Usage;;
+        esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ ! -z "$BARCODE" ] && [ -z "$EMAIL" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT usr
+                FROM actor.card
+                WHERE barcode = '$BARCODE'
+EOF
+elif [ -z "$BARCODE" ] && [ ! -z "$EMAIL" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT id
+                FROM actor.usr
+                WHERE email = '$EMAIL'
+EOF
+else
+    Usage
+fi
+
+case $AT_EVENT_DEF in 
+ "preminder")       AT_EVENT_DEF="114" ;;
+ "overdue")         AT_EVENT_DEF="113" ;;
+ "hold-ready")      AT_EVENT_DEF="124" ;;
+ "longoverdue")     AT_EVENT_DEF="119" ;;
+ "hold-canceled")   AT_EVENT_DEF="51, 52, 53" ;;
+ "*")               Usage ;;
+esac
+
+if [ -z "$STATE" ]; then
+    STATE="complete"
+fi
+
+if [ -z "$LIMIT" ]; then
+        LIMIT=10
+fi
+
+read -d '' SQL <<EOQ
+SELECT atev.id, atev.run_time, atevo.data
+FROM action_trigger.event atev
+INNER JOIN action_trigger.event_output atevo ON (atev.template_output = atevo.id)
+WHERE atev.state = '$STATE'
+AND atev.event_def in ($AT_EVENT_DEF)
+AND EXISTS (
+    SELECT 1
+    FROM action.hold_request ahr
+    WHERE atev.target = ahr.id
+    AND ahr.usr IN (
+    $SUBSELECT
+    )
+)
+ORDER BY 1 DESC
+LIMIT $LIMIT;
+EOQ
+
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o at_hold_notifications_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/find_at_sms_notifications.sh b/pines-finder/find_at_sms_notifications.sh
new file mode 100755 (executable)
index 0000000..85f04a5
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+Usage () { echo -e "Usage:\n\t$0 [-u patron barcode] [-s state] [-f (export file)] -t event type [-l result limit (default 10)]\n\n'event type' is required and can be one of the following:\n\n\tpreminder\n\thold-ready\n\tcall-number\n\n'state' can be one of the following (default is 'complete'):\n\n\tinvalid\n\tpending\n\tcomplete\n\tvalidating\n\tcollected\n\tvalid\n\treacting\n\tcollecting\n\terror\n\tfound\n" && exit 1; 
+}
+
+while getopts l:u:p:s:ft:h OPTIONS
+do case "$OPTIONS" in
+        l)  LIMIT="$OPTARG";;
+        u)  BARCODE="$OPTARG";;
+        s)  STATE="$OPTARG";;
+        f)  EXPORT_FILE=1;;
+        t)  AT_EVENT_DEF="$OPTARG";;
+        h)  Usage;;
+        esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ ! -z "$AT_EVENT_DEF" ]; then
+if [ ! -z "$BARCODE" ]; then
+read -d '' SUBSELECT <<EOF
+                SELECT usr
+                FROM actor.card
+                WHERE barcode = '$BARCODE'
+EOF
+else
+    Usage
+fi
+else
+    Usage
+fi
+
+case $AT_EVENT_DEF in 
+ "preminder")       AT_EVENT_DEF="112" TARGET_TABLE="action.circulation" TARGET_FIELD="usr" ;;
+ "hold-ready")      AT_EVENT_DEF="103" TARGET_TABLE="action.hold_request" TARGET_FIELD="usr" ;;
+ "call-number")     AT_EVENT_DEF="104" TARGET_TABLE="actor.usr" TARGET_FIELD="id" ;;
+ "*")               Usage ;;
+esac
+
+if [ -z "$STATE" ]; then
+    STATE="complete"
+fi
+
+if [ -z "$LIMIT" ]; then
+        LIMIT=10
+fi
+
+read -d '' SQL <<EOQ
+SELECT atev.id, atev.run_time, atevo.data
+FROM action_trigger.event atev
+INNER JOIN action_trigger.event_output atevo ON (atev.template_output = atevo.id)
+WHERE atev.state = '$STATE'
+AND atev.event_def in ($AT_EVENT_DEF)
+AND EXISTS (
+    SELECT 1
+    FROM $TARGET_TABLE target
+    WHERE atev.target = target.id
+    AND target.$TARGET_FIELD IN (
+    $SUBSELECT
+    )
+)
+ORDER BY 1 DESC
+LIMIT $LIMIT;
+EOQ
+
+#debug
+#echo "$SQL"
+
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o at_sms_notifications_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
+
diff --git a/pines-finder/generate_user_checkout_history.sh b/pines-finder/generate_user_checkout_history.sh
new file mode 100755 (executable)
index 0000000..a072b3e
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-u user barcode] [-s server] [-f]"
+echo
+echo "If you don't specify i user barcode, you'll be prompted"
+echo "to provide one."
+echo
+}
+
+while getopts i:l:u:s:fh OPTIONS
+do case "$OPTIONS" in
+    u)  USER_BARCODE="$OPTARG";;
+    s)  SERVER="$OPTARG";;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ "$SERVER" = "test" ]; then
+PSQL_HOST="mytestdb"
+elif [ "$SERVER" = "next" ]; then
+PSQL_HOST="mynextdb"
+fi
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+        echo "We need a user barcode."
+        read -p "Please enter the user barcode (Enter for none): " USER_BARCODE
+fi
+
+if [ ! -z "$USER_BARCODE" ]; then
+        SQL_WHERE="WHERE u_card.barcode = '$USER_BARCODE'"
+# no barcode, exit the script
+else
+                echo "We need a user barcode to run this script.  Exiting..."
+                exit 1;
+fi
+
+read -d '' SQL <<EOF
+SELECT     initcap(rmsr.title) as "Title",
+    initcap(rmsr.author) as "Author",
+    date(hist.xact_start) as "Checkout Date",
+    date(hist.due_date) as "Due Date",
+    date(hist.checkin_time) as "Date Returned",
+    cp.barcode as "Barcode",
+    cn.label as "Call Number",
+    initcap(ccm.name) as "Format"
+FROM    action.usr_circ_history hist
+    INNER JOIN actor.usr u ON (hist.usr = u.id)
+    INNER JOIN actor.card u_card ON (u.card = u_card.id)
+    INNER JOIN asset.copy cp ON (hist.target_copy = cp.id)
+    INNER JOIN config.circ_modifier ccm ON (cp.circ_modifier = ccm.code)
+    LEFT OUTER JOIN asset.call_number cn ON (cp.call_number = cn.id)
+    LEFT OUTER JOIN reporter.materialized_simple_record rmsr ON (cn.record = rmsr.id)
+$SQL_WHERE
+ORDER BY hist.xact_start desc
+EOF
+
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+    $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -c "$SQL" -o usr_circ_history_outfile_`date +%Y_%m_%d_%H%M%S`.csv
+else
+    $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -c "$SQL"
+fi
diff --git a/pines-finder/get_active_library_count.sh b/pines-finder/get_active_library_count.sh
new file mode 100755 (executable)
index 0000000..bb1d0ca
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+psql -U evergreen -h $PG_HOST -c 'select count(*) from actor.org_unit where ou_type not in (1, 2) and opac_visible'
diff --git a/pines-finder/get_active_library_list.sh b/pines-finder/get_active_library_list.sh
new file mode 100755 (executable)
index 0000000..df69b64
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+psql -U evergreen -h $PG_HOST -A -o pines_active_libraries_`date +%F`.csv -c 'select pou.name as "System", ou.name as "Branch/Bookmobile/Sub-Lib" from actor.org_unit ou join actor.org_unit pou on (ou.parent_ou = pou.id) where ou.ou_type not in (1, 2) and ou.opac_visible order by 1, 2'
diff --git a/pines-finder/get_active_library_list_with_ids.sh b/pines-finder/get_active_library_list_with_ids.sh
new file mode 100755 (executable)
index 0000000..3c72dc4
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+psql -U evergreen -h $PG_HOST -A -o pines_active_libraries_with_ids_`date +%F`.csv -c 'select pou.name as "System", ou.name as "Branch/Bookmobile/Sub-Lib", ou.id as "ID", ou.shortname as "PINES Code" from actor.org_unit ou join actor.org_unit pou on (ou.parent_ou = pou.id) where ou.ou_type not in (1, 2) and ou.opac_visible order by 1, 2'
diff --git a/pines-finder/get_billing_history.sh b/pines-finder/get_billing_history.sh
new file mode 100755 (executable)
index 0000000..be8a662
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-b] [-p] [-f] -i <bill_id>"
+echo
+echo "Select one of -b for billings or -p for payments, or neither for a summary."
+echo "<bill_id> means the billable transaction ID (circulation or grocery)"
+echo "-f creates a file from the result."
+echo
+}
+
+while getopts i:sfhbp OPTIONS
+do case "$OPTIONS" in
+    i)  XACT_ID="$OPTARG";;
+    b)  BILLINGS=1;;
+    p)  PAYMENTS=1;;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+# if we have no command line arguments, or both billings and payments selected, exit the script
+if [ ! -z "$BILLINGS" ] && [ ! -z "$PAYMENTS" ]; then
+echo "Choose /either/ -b or -p, not both."
+Usage; exit 1
+elif [ -z "$XACT_ID" ]; then
+echo "Bill ID is required."
+Usage; exit 1
+fi
+
+# if we have billings selected...
+if [ ! -z "$BILLINGS" ]; then
+FILENAME_PREFIX=${XACT_ID}_billing_lineitems__
+read -d '' SQL <<EOF
+SELECT    b.id as "Billing Line Item ID",
+    b.xact as "Bill ID",
+    b.billing_ts as "Billing Date/Time",
+    b.voided as "Voided?",
+    u_card.barcode as "Voider",
+    b.void_time as "Void Date/Time",
+    b.amount as "Amount",
+    b.billing_type as "Legacy Billing Type",
+    b.note as "Billing Note",
+    btype.name as "Billing Type"
+FROM    money.billing b
+    LEFT OUTER JOIN actor.usr u ON (b.voider = u.id)
+    LEFT OUTER JOIN actor.card u_card ON (u.card = u_card.id)
+    INNER JOIN config.billing_type btype ON (b.btype = btype.id)
+WHERE    b.xact = $XACT_ID
+EOF
+
+# if we have payments selected...
+elif [ ! -z "$PAYMENTS" ]; then
+FILENAME_PREFIX=${XACT_ID}_payment_lineitems_
+read -d '' SQL <<EOF
+SELECT    p.id as "Payment ID",
+    p.xact as "Bill ID",
+    p.payment_ts as "Payment Date/Time",
+    p.voided as "Voided?",
+    p.amount as "Amount",
+    p.note as "Payment Note",
+    p.payment_type as "Payment Type"
+FROM    money.payment_view p
+WHERE    p.xact = $XACT_ID
+EOF
+# otherwise, generate a summary
+else
+FILENAME_PREFIX=${XACT_ID}_billable_tranaction_summary_
+read -d '' SQL <<EOF
+SELECT     x.id as "Bill ID",
+    u_card.barcode as "Patron",
+    x.xact_start as "Transaction Start Date/Time",
+    x.xact_finish as "Transaction Closed Date/Time",
+    x.total_paid as "Total Paid",
+    x.last_payment_ts as "Last Payment Date/Time",
+    x.last_payment_note as "Last Payment Note",
+    x.last_payment_type as "Last Payment Type",
+    x.total_owed as "Total Owed",
+    x.last_billing_ts as "Last Billing Date/Time",
+    x.last_billing_note as "Last Billing Note",
+    x.last_billing_type as "Last Billing Type",
+    x.balance_owed as "Balance Owed",
+    x.xact_type as "Transaction Type"
+FROM    money.materialized_billable_xact_summary x
+    INNER JOIN actor.usr u ON (x.usr = u.id)
+    INNER JOIN actor.card u_card ON (u.card = u_card.id)
+WHERE     x.id = $XACT_ID
+EOF
+fi
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+    $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o ${FILENAME_PREFIX}`date +%Y_%m_%d_%H%M%S`.txt
+else
+    $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
diff --git a/pines-finder/get_circ_history.sh b/pines-finder/get_circ_history.sh
new file mode 100755 (executable)
index 0000000..5a9bbb1
--- /dev/null
@@ -0,0 +1,106 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-i item barcode] [-u user barcode] [-s server] [-l result limit] [-f]"
+echo
+echo "If you don't specify item or user barcode, you'll be prompted"
+echo "to provide one.  Result limit defaults to 10."
+echo
+}
+
+while getopts i:l:u:s:fh OPTIONS
+do case "$OPTIONS" in
+       i)  ITEM_BARCODE="$OPTARG";; # TODO: allow multiple barcodes
+       l)  LIMIT="$OPTARG";;
+       u)  USER_BARCODE="$OPTARG";;
+       s)  SERVER="$OPTARG";;
+       f)  EXPORT_FILE=1;;
+       h)  Usage; exit 1;;
+       esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ "$SERVER" = "test" ]; then
+PSQL_HOST="mytestdb"
+elif [ "$SERVER" = "next" ]; then
+PSQL_HOST="mynextdb"
+fi
+
+# 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.parent_circ as "Parent Circulation ID",
+       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
+if [ ! -z "$EXPORT_FILE" ]; then
+       $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o circ_history_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+       $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
diff --git a/pines-finder/get_combined_perms_per_profile.sh b/pines-finder/get_combined_perms_per_profile.sh
new file mode 100755 (executable)
index 0000000..87d9936
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+Usage () {
+echo "USAGE: $0 <permission group name>"
+exit 1
+}
+
+GROUP_NAME="$1"
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+
+if [ -z $GROUP_NAME ]; then
+    Usage
+fi
+read -d '' SQL <<EOF
+select  perm.code as "Permission", 
+        perm.description as "Description", 
+        grp.name as "Permission Level", 
+        case 
+            when map.depth = 0 then 'Consortium' 
+            when map.depth = 1 then 'System' 
+            when map.depth = 2 then 'Branch' 
+        end as "Depth", 
+        case 
+            when map.grantable = true then 'Grantable' 
+            when map.grantable = false then 'Not Grantable' 
+        end as "Grantability" 
+from    permission.grp_tree grp 
+        join permission.grp_perm_map map on (map.grp = grp.id) 
+        join permission.perm_list perm on (map.perm = perm.id) 
+where   grp.id in (
+            select id 
+            from permission.grp_ancestors(
+                (select id 
+                    from permission.grp_tree 
+                    where name = '$GROUP_NAME')
+            )
+        ) 
+        order by 1, 2;
+EOF
+
+PGUSER="$PSQL_USER" "$PSQL" -A --pset footer --field-separator ',' -o "$GROUP_NAME-perms.out" -c "$SQL" "$PSQL_DB"
+
diff --git a/pines-finder/get_email_logs.sh b/pines-finder/get_email_logs.sh
new file mode 100755 (executable)
index 0000000..ea0e8b6
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+LOG_USER="myloguser"
+LOG_HOST="myloghost"
+LOG_DIR_BASE="/var/log/evergreen"
+
+
+Usage () {
+echo
+echo "$0 -u user_barcode -d YYYY-MM-DD -h"
+echo
+echo "-d(ate) needs to be the due date for the circs"
+echo "-h displays this message"
+echo
+exit 1;
+}
+
+
+while getopts u:d:h OPTIONS
+    do case "$OPTIONS" in
+        u)  USER_BARCODE="$OPTARG";;
+        d)  DUE_DATE="$OPTARG";;
+        h)  Usage; exit 1;;
+    esac
+done
+
+if [ -z "$USER_BARCODE" ] || [ -z "$DUE_DATE" ]; then
+    Usage;
+fi
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+NOTICE_DATE=$(date -d "$DUE_DATE -3 days" +%F)
+LOG_YEAR=$(date -d "$DUE_DATE -3 days" +%Y)
+LOG_MONTH=$(date -d "$DUE_DATE -3 days" +%m)
+LOG_DAY=$(date -d "$DUE_DATE -3 days" +%d)
+
+# given a barcode, locate the patron's email address
+GetEmail () {
+read -d '' SQL <<EOF
+select email
+    from actor.usr
+    where card in (
+        select id
+        from actor.card
+        where barcode = '$USER_BARCODE'
+    )
+EOF
+USER_EMAIL=$(psql -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -A -t -c "$SQL")
+if [ -z "$USER_EMAIL" ]; then
+    echo "User email address is blank.  Exiting..."
+    exit 1;
+fi
+#echo "\$USER_EMAIL is $USER_EMAIL"
+}
+
+
+GetLogMessages () {
+ssh -T $LOG_USER@$LOG_HOST <<EOF
+zgrep $USER_EMAIL $LOG_DIR_BASE/$LOG_YEAR/$LOG_MONTH/$LOG_DAY/mail_* > ~/${USER_BARCODE}_preminder_logs_${NOTICE_DATE}.txt
+EOF
+scp $LOG_USER@$LOG_HOST:~/${USER_BARCODE}_preminder_logs_${NOTICE_DATE}.txt .
+}
+
+GetEmail
+GetLogMessages
diff --git a/pines-finder/get_hold_history.sh b/pines-finder/get_hold_history.sh
new file mode 100755 (executable)
index 0000000..ad0b873
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-i item barcode] [-u user barcode] [-s server] [-l result limit] [-f]"
+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";;
+    s)  SERVER="$OPTARG";;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ "$SERVER" = "test" ]; then
+PSQL_HOST="test-db01"
+elif [ "$SERVER" = "next" ]; then
+PSQL_HOST="next-db01"
+fi
+
+# 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)
+    LEFT OUTER 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
+if [ ! -z "$EXPORT_FILE" ]; then
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o hold_history_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+        $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
diff --git a/pines-finder/get_reports_template_ids.sh b/pines-finder/get_reports_template_ids.sh
new file mode 100755 (executable)
index 0000000..8fb8008
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-u user_barcode] [-f]"
+echo
+echo "user_barcode defaults to the Quick Reports admin user.  Supply a -u parameter for any other user."
+echo "-f creates a file from the result."
+echo
+}
+
+while getopts u:fh OPTIONS
+do case "$OPTIONS" in
+       u)  USER_BARCODE="$OPTARG";;
+       f)  EXPORT_FILE=1;;
+       h)  Usage; exit 1;;
+       esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ -z "$USER_BARCODE" ]; then
+USER_BARCODE='myqradminbc'
+fi
+
+read -d '' SQL <<EOF
+SELECT t.id as "Template ID",
+       t.name as "Template Name",
+       t.create_time as "Template Creation Date/Time"
+FROM   reporter.template t
+       INNER JOIN actor.usr u ON (t.owner = u.id)
+       INNER JOIN actor.card u_card ON (u.card = u_card.id)
+WHERE  u_card.barcode = '$USER_BARCODE'
+ORDER BY t.id DESC
+EOF
+
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+       $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -c "$SQL" -o report_template_ids_`date +%Y_%m_%d_%H%M%S`.txt
+else
+       $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -c "$SQL"
+fi
diff --git a/pines-finder/get_transit_history.sh b/pines-finder/get_transit_history.sh
new file mode 100755 (executable)
index 0000000..53610b4
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+Usage () {
+echo
+echo "Usage: $0 [-i item barcode] [-s server] [-l result limit] [-f]"
+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:s:fh OPTIONS
+do case "$OPTIONS" in
+    i)  ITEM_BARCODE="$OPTARG";; # TODO: allow multiple barcodes
+    l)  LIMIT="$OPTARG";;
+    s)  SERVER="$OPTARG";;
+    f)  EXPORT_FILE=1;;
+    h)  Usage; exit 1;;
+    esac
+done
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+if [ "$SERVER" = "test" ]; then
+PSQL_HOST="test-db01"
+elif [ "$SERVER" = "next" ]; then
+PSQL_HOST="next-db01"
+fi
+
+# if we have no command line arguments, prompt the user
+if [ "$*" = '' ]; then
+        echo "We need an item barcode."
+        read -p "Please enter the item barcode (Enter for none): " ITEM_BARCODE
+fi
+
+# no barcode, exit the script
+if [ -z "$ITEM_BARCODE" ]; then
+                echo "We need an item barcode to run this script.  Exiting..."
+                exit 1;
+# if we've gotten this far, we have a barcode
+else
+        SQL_WHERE="WHERE cp.barcode = '$ITEM_BARCODE'"
+fi
+
+if [ -z "$LIMIT" ]; then
+    LIMIT=10
+fi
+
+read -d '' SQL <<EOF
+SELECT     t.id as "Transit ID",
+    cp.barcode as "Item Barcode",
+    source.shortname as "Sending Library",
+    t.source_send_time as "Sending Date/Time",
+    dest.shortname as "Destination Library",
+    t.dest_recv_time as "Destination Receive Date/Time",
+    transit_status.name as "Transit Copy Status",
+    current_status.name as "Current Copy Status",
+    prev_dest.shortname as "Previous Destination Library"
+FROM    action.transit_copy t
+    INNER JOIN asset.copy cp ON (t.target_copy = cp.id)
+    INNER JOIN actor.org_unit source ON (t.source = source.id)
+    INNER JOIN actor.org_unit dest ON (t.dest = dest.id)
+    LEFT OUTER JOIN actor.org_unit prev_dest ON (t.prev_dest = prev_dest.id)
+    INNER JOIN config.copy_status transit_status ON (t.copy_status = transit_status.id)
+    INNER JOIN config.copy_status current_status ON (cp.status = current_status.id)
+$SQL_WHERE
+ORDER BY t.source_send_time DESC
+LIMIT $LIMIT
+EOF
+
+#echo "\$BARCODE = $BARCODE, \$LIMIT = $LIMIT"
+#echo $SQL
+if [ ! -z "$EXPORT_FILE" ]; then
+    $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL" -o transit_history_outfile_`date +%Y_%m_%d_%H%M%S`.txt
+else
+    $PSQL -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -P null="<NULL>" -x -c "$SQL"
+fi
diff --git a/pines-finder/pg_config b/pines-finder/pg_config
new file mode 100644 (file)
index 0000000..bfa46f1
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# configuration for DB - read by all pines-finder files,
+# so make sure this file is in the same working directory
+# as each script.
+
+# Note: it is assumed that you're using .pgpass here
+PSQL="/usr/bin/psql"
+PSQL_USER="mydbuser"
+PSQL_HOST="mydbhost"
+PSQL_DB="mydbname"
diff --git a/pines-finder/predue_lookup.sh b/pines-finder/predue_lookup.sh
new file mode 100755 (executable)
index 0000000..4f15fcd
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+UTILITY_HOST="utility01"
+UTILITY_USER="opensrf"
+LOG_USER="root"
+LOG_HOST="logger01"
+LOG_DIR_BASE="/var/log/evergreen"
+DATA_DIR="/openils/var/data/overdue"
+
+
+Usage () {
+echo
+echo "$0 -u user_barcode -d YYYY-MM-DD -h"
+echo
+echo "-d(ate) needs to be the due date for the circs"
+echo "-h displays this message"
+echo
+exit 1;
+}
+
+
+while getopts u:d:h OPTIONS
+    do case "$OPTIONS" in
+        u)  USER_BARCODE="$OPTARG";;
+        d)  DUE_DATE="$OPTARG";;
+        h)  Usage; exit 1;;
+    esac
+done
+
+if [ -z "$USER_BARCODE" ] || [ -z "$DUE_DATE" ]; then
+    Usage;
+fi
+
+PG_CONFIG="pg_config"
+source $PG_CONFIG || echo "PostgreSQL configuration file $PG_CONFIG not found. exiting" && exit 1;
+
+NOTICE_DATE=$(date -d "$DUE_DATE -2 days" +%F)
+LOG_YEAR=$(date -d "$DUE_DATE -2 days" +%Y)
+LOG_MONTH=$(date -d "$DUE_DATE -2 days" +%m)
+LOG_DAY=$(date -d "$DUE_DATE -2 days" +%d)
+
+# given a barcode, locate the patron's email address
+GetEmail () {
+read -d '' SQL <<EOF
+select email
+    from actor.usr
+    where card in (
+        select id
+        from actor.card
+        where barcode = '$USER_BARCODE'
+    )
+EOF
+USER_EMAIL=$(psql -U "$PSQL_USER" -h "$PSQL_HOST" -d "$PSQL_DB" -A -t -c "$SQL")
+if [ -z "$USER_EMAIL" ]; then
+    echo "User email address is blank.  Exiting..."
+    exit 1;
+fi
+}
+
+GetPreminderNotice () {
+ssh -T $UTILITY_USER@$UTILITY_HOST <<EOF
+cd $DATA_DIR
+sed -n -e '/^To: $USER_EMAIL/, /^Thank you/ p' predue_email.${NOTICE_DATE}.txt > ~/${USER_BARCODE}_predue_notice_${NOTICE_DATE}.txt
+EOF
+scp $UTILITY_USER@$UTILITY_HOST:~/${USER_BARCODE}_predue_notice_${NOTICE_DATE}.txt .
+}
+
+GetLogMessages () {
+ssh -T $LOG_USER@$LOG_HOST <<EOF
+zgrep $USER_EMAIL $LOG_DIR_BASE/$LOG_YEAR/$LOG_MONTH/$LOG_DAY/mail_* > ~/${USER_BARCODE}_predue_logs_${NOTICE_DATE}.txt
+EOF
+scp $LOG_USER@$LOG_HOST:~/${USER_BARCODE}_predue_logs_${NOTICE_DATE}.txt .
+}
+
+GetEmail
+GetPreminderNotice
+GetLogMessages
diff --git a/pines-finder/run_sql_script.sh b/pines-finder/run_sql_script.sh
new file mode 100755 (executable)
index 0000000..deec3c9
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+SCRIPT="$1"
+PSQL="/usr/bin/psql"
+DB_USER="mydbuser"
+DB_HOST="mydb"
+
+$PSQL -U $DB_USER -h $DB_HOST -1 -f $SCRIPT
diff --git a/pines-finder/sip_account_lookup.sh b/pines-finder/sip_account_lookup.sh
new file mode 100755 (executable)
index 0000000..24db7c7
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+Usage () {
+       echo "$0 sip_username"
+       exit 1;
+}
+
+SSH_USER="myuser"
+SIP_SERVER="sipserver"
+SIP_CONFIG="/openils/conf/oils_sip.xml"
+USERNAME="$1"
+
+while getopts u:h OPTIONS
+        do case "$OPTIONS" in
+                u)  USERNAME="$OPTARG";;
+                h)  Usage; exit 1;;
+        esac
+done
+
+ssh $SSH_USER@$SIP_SERVER "grep $USERNAME $SIP_CONFIG"