From: Chris Sharp Date: Wed, 19 Feb 2014 15:28:45 +0000 (-0500) Subject: adding a utility to batch void fines X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2edbe3cbf324fd7ea06953c4046ad09f43487778;p=contrib%2Fpines.git adding a utility to batch void fines --- diff --git a/batch_void_fines.sh b/batch_void_fines.sh new file mode 100755 index 0000000..d9edbb9 --- /dev/null +++ b/batch_void_fines.sh @@ -0,0 +1,159 @@ +#!/bin/bash + +# Copyright (C) 2014 Georgia Public Library Service +# Chris Sharp +# +# A program that takes a library system or branch name and a date or set of dates +# on the command line to apply a batch void for billings applied on that day. +# This is particularly useful if closed dates are set after the fine generator has +# run for that day. +# +# This script assumes that you are on a server with direct access to your master +# database, and that you have set the credentials for that database in the .pgpass +# file in your user's home directory. +# +# See http://www.postgresql.org/docs/9.1/static/libpq-pgpass.html for more information. +# +# Usage Notes: +# +# You'll want to set the $EGUSER/$EGPASS variables to the username/password of an Evergreen +# user (e.g., your administrative user in Evergreen). Adjust the $SRFSH variable to suit +# your environment. As of this writing, we're still installing Evergreen in /openils. +# The $VOID_NOTE variable should be something informative to your staff users as to why these +# bills were voided. Our use case was closings due to inclement weather. +# +# The $BACKUP_SCHEMA variable should be set to a schema in your postgresql database that is +# for administrative use. You should NOT use an existing Evergreen schema name (e.g. "action", +# "actor", etc. for this purpose. I use "csharp" for that in our case. +# +# My hope is that this can be re-implemented in Perl or something with actual OpenSRF bindings, +# but my current skill level and available time prevented me from doing so now. + +EGUSER="myuser" +EGPASS="mypass" +SRFSH="/openils/bin/srfsh" +DBHOST="mydbhost" +DBUSER="mydbuser" +VOID_NOTE="VOIDED BY SYSTEM STAFF - INCLEMENT WEATHER" +BACKUP_SCHEMA="myschema" + +Usage() { echo "Usage: ./batch_void_fines.sh -d YYYY-MM-DD,YYYY-MM-DD,... -s systemname OR -b branchname." +} + +while getopts s:b:d:h OPTIONS +do case "$OPTIONS" in + s) SYSTEM="$OPTARG";; + b) BRANCH="$OPTARG";; + d) DATE="$OPTARG";; + h) Usage ; exit 1;; + *) Usage ; exit 2;; + esac +done + +if [ -n "$SYSTEM" ] && [ -n "$BRANCH" ]; then + Usage + exit 1; +fi + +if [ -z "$DATE" ]; then + Usage + exit 1; +fi + +if [ $(echo $DATE | grep ",") ]; then + SPLITDATE=`echo $DATE | sed "s/,/', '/g"` + DATE=$SPLITDATE +fi + +if [ -n "$SYSTEM" ]; then + BACKUP_TABLE="$BACKUP_SCHEMA.`echo $SYSTEM | tr '[:upper:]' '[:lower:]'`_snowday_fines_`echo $DATE | tr '-' '_'`" +else + BACKUP_TABLE="$BACKUP_SCHEMA.`echo $BRANCH | tr '[:upper:]' '[:lower:]' | tr '-' '_'`_snowday_fines_`echo $DATE | tr '-' '_'`" +fi +read -d '' SYSTEM_Q <> "${BACKUP_TABLE}_void.srfsh" + +echo "$SRFSH_COMMAND" | $SRFSH + +until [ $(psql -A -t -U "$DBUSER" -h "$DBHOST" -c "$COUNT_SQL") == "0" ]; do + echo "Waiting for srfsh command to complete..." + sleep 10 +done + +psql -U "$DBUSER" -h "$DBHOST" -c "$UPDATE_SQL" + +echo "Update complete"