Navigation

2/09/2015

SQL to get patrons who owe more than $25 in fines

From Sierra Listserv, code to output library patrons who owe a certain amount in fines:




ADDING PATRON NAMES TO OUTPUT

First, let's add patron names to your existing query. You start by adding a JOIN to sierra_view.patron_record_fullname. You than add a name column to your output. The trick here is that Sierra stores names as first_name, middle_name, and last_name in three separate columns. In order to output the full name, you need to concatenate the pieces together.

In the following query, you'll find the concatenated name in LINE 4. The additional JOIN is in LINES 21-24.
select
p.home_library_code,
p.record_num,
pn.last_name||', '||pn.first_name||' '||pn.middle_name,
p.barcode,
f.assessed_gmt,
f.paid_gmt,
f.charge_code,
f.item_charge_amt,
f.billing_fee_amt,
f.processing_fee_amt,
f.paid_amt,
f.title,
f.description
from sierra_view.fine as f
JOIN -- to patron view
sierra_view.patron_view AS p
ON
p.id = f.patron_record_id
and assessed_gmt <= '2014-03-31 00:00:00'
JOIN -- to patron name
sierra_view.patron_record_fullname AS pn
ON
pn.patron_record_id = p.id
;

ADDING A NESTED QUERY

In order to limit your output to only those patrons who have fines and fees that were assessed on or before 2013-03-31 and which total $25 or more, I think you'll need to do a nested query. The following query will give you a list of patron record ids that match the desired criteria -
SELECT
  patron_record_id
FROM
  sierra_view.fine
WHERE
  DATE(assessed_gmt) <= '2014-03-31'
GROUP BY
  1
HAVING
  SUM(item_charge_amt+processing_fee_amt+billing_fee_amt-paid_amt) >= '25'
;

You then nest that query into the larger query. Output from the larger query will be limited to only patrons whose patron record IDs are found in the nested query's result set. Note the WHERE clause (LINES 25-37) -
select
p.home_library_code,
p.record_num,
pn.last_name||', '||pn.first_name||' '||pn.middle_name,
p.barcode,
f.assessed_gmt,
f.paid_gmt,
f.charge_code,
f.item_charge_amt,
f.billing_fee_amt,
f.processing_fee_amt,
f.paid_amt,
f.title,
f.description
from sierra_view.fine as f
JOIN -- to patron view
sierra_view.patron_view AS p
ON
p.id = f.patron_record_id
and assessed_gmt <= '2014-03-31 00:00:00'
JOIN -- to patron name
sierra_view.patron_record_fullname AS pn
ON
pn.patron_record_id = p.id
WHERE
f.patron_record_id in
(
  SELECT
  patron_record_id
  FROM
  sierra_view.fine
  WHERE
  DATE(assessed_gmt) <= '2014-03-31'
  GROUP BY 1
  HAVING
  SUM(item_charge_amt+processing_fee_amt+billing_fee_amt-paid_amt) >= '25'
)
;

OUTPUT AND CODE FORMAT

I would tend to want to format my output for dates and currency and I would want to add textual descriptions for charge_code and home_library_code. I would also tidy up my query code in some way that makes it easier for me to read later. Here are my suggestions. Make use of whatever works for you.
  1. I replaced the bare home library code with a branch name. I got this by adding another JOIN to sierra_view.location_myuser
  2. I used the DATE() function on f.assessed_gmt to quickly strip off the transaction time and timezone, leaving only the date
  3. I added a CASE statement to provide text for charge_code. There is no view that holds these descriptors (as far as I can tell). I got them from Sierra DNA and have to hope that they don't change over time.
  4. I formatted the currency fields to use only two decimal places and to show the dollar sign
  5. I added a "Balance Owing" column wherein I add the three charge columns and subtract the amount already paid
-- ===============================================================================
-- Patrons with $25 or more in fines assessed on or before 2014-03-31
--    Detail of fines owing
-- Brent Searle. Langara College. 2015-02-06
-- ===============================================================================
SELECT
  ln.name                                 AS "Home Library",
  p.record_num                            AS "Patron Number",
  TRIM(pn.last_name||', '||
  pn.first_name||' '||
  pn.middle_name)                         AS "Patron Name",
  p.barcode                               AS "Patron Barcode",
  DATE(f.assessed_gmt)                    AS "Date Assessed",
  CASE
    WHEN f.charge_code = '1' THEN 'manual charge'
    WHEN f.charge_code = '2' THEN 'overdue'
    WHEN f.charge_code = '3' THEN 'replacement'
    WHEN f.charge_code = '4' THEN 'adjustment'
    WHEN f.charge_code = '5' THEN 'lost item'
    WHEN f.charge_code = '6' THEN 'overdue renewed'
    WHEN f.charge_code = '7' THEN 'rental'
    WHEN f.charge_code = '8' THEN 'rental adjustment'
    WHEN f.charge_code = '9' THEN 'debit'
    WHEN f.charge_code = 'a' THEN 'notice'
    WHEN f.charge_code = 'b' THEN 'credit card'
    WHEN f.charge_code = 'p' THEN 'program'
    ELSE 'unexpected charge code - '||f.charge_code
  END                                     AS "Charge Type",
  TO_CHAR(f.item_charge_amt,'$990.99')    AS "Amount Charged",
  TO_CHAR(f.billing_fee_amt,'$990.99')    AS "Billing Fee",
  TO_CHAR(f.processing_fee_amt,'$990.99') AS "Processing Fee",
  TO_CHAR(f.paid_amt,'$990.99')           AS "Amount Paid",
  TO_CHAR(f.item_charge_amt +
  f.billing_fee_amt +
  f.processing_fee_amt -
  f.paid_amt,'$990.99')                   AS "Balance Owing",
  f.title                                 AS "Title",
  f.description                           AS "Fine Description"
FROM
  sierra_view.fine                        as f
JOIN -- to patron view
  sierra_view.patron_view                 AS p
  ON
  p.id = f.patron_record_id
JOIN
  sierra_view.patron_record_fullname      AS pn
  ON
  pn.patron_record_id = p.id
JOIN
  sierra_view.location_myuser             AS ln
  ON
  ln.code = p.home_library_code
WHERE
  DATE(f.assessed_gmt) <= '2014-03-31'    -- specific date may need editing
  AND
  p.owed_amt >= '25'
  AND
  f.patron_record_id IN 
  (
    SELECT
      patron_record_id
    FROM
      sierra_view.fine
    WHERE
      DATE(assessed_gmt) <= '2014-03-31'  -- specific date may need editing
    GROUP BY
      1
    HAVING
      SUM(item_charge_amt+processing_fee_amt+billing_fee_amt-paid_amt) >= '25'
  )
ORDER BY
  1,2,4
; 

You should be able to export the output to MS Excel and, by way of the SUBTOTAL function, subtotal on each change of patron number.


--
Brent Searle
Library Systems Manager
Langara College
Vancouver BC

On 2015-02-03 1:48 PM, Leach, Barbara wrote:
I’m hoping maybe one of you SQL gurus can help me with this SQL for Collection Agency candidates.  The following query lists fines assessed prior to a certain date (I used 3/31/14 to keep the results list small.  We went live on Sierra on 1/23/14)

Now, what would be really helpful is if it would sum all of the fines, and only include in the output patrons who owed $25 or more prior to the specified date.  This is way beyond my sql abilities. 

Also, I’d like to include the patron name, but I didn’t know how to add a second join to the patron name table. (I tried, but it didn’t work. )

select
p.home_library_code,
p.record_num,
p.barcode,
f.assessed_gmt,
f.paid_gmt,
f.charge_code,
f.item_charge_amt,
f.billing_fee_amt,
f.processing_fee_amt,
f.paid_amt,
f.title,
f.description
from sierra_view.fine as f
JOIN -- to patron view
sierra_view.patron_view AS p
ON
p.id = f.patron_record_id
and assessed_gmt <= '2014-03-31 00:00:00'
;

Thanks so much for your help!  We just can’t figure out a way to get Sierra to work to send patrons with fines to Collection Agency, so it doesn’t include current fines.  Any way we imagine involves a lot of manual staff work, that we’re just not used to having to do (our previous ILS did it for us perfectly)

III OPAC

2/07/2015

SQL to get past checkouts from Innovative ILS

We have turned off the last patron to checkout an item field, but we wanted to track down the person who borrowed a laptop charger (missing a part).  This info is stored in CIRC_TRANS table, generally 14 days worth, to see all: 





SELECT
  transaction_gmt
FROM
  sierra_view.circ_trans
ORDER BY
  1
LIMIT
  100
;



To locate one item by barcode, use this code:


SELECT
  circ_trans.transaction_gmt,
  circ_trans.patron_record_id,
  circ_trans.item_record_id,
  circ_trans.due_date_gmt,
  item_view.barcode,
  item_view.itype_code_num,
  patron_record_fullname.first_name,
  patron_record_fullname.last_name
FROM
  sierra_view.circ_trans,
  sierra_view.item_view,
  sierra_view.patron_view,
  sierra_view.patron_record_fullname
WHERE
  item_view.id = circ_trans.item_record_id AND
  patron_view.id = circ_trans.patron_record_id AND
  patron_record_fullname.patron_record_id = patron_view.id AND
  item_view.barcode = '11111103690302'

ORDER BY
  circ_trans.due_date_gmt ASC;


Barcode is CHAR field, so can use ::text to set the number to text, double quotes do not work  (PGadmin client)


To get daily stats on checkouts:  (via Andrew Hollingsworth)



Select Distinct
  count(*),
  Case sierra_view.circ_trans.op_code When 'o' Then 'Checkout'
    When 'n' Then 'Hold' When 'nb' Then 'Title Hold' When 'ni' Then 'Item Hold'
    When 'f' Then 'Hold Fufilled' When 'i' Then 'Checkin'
    When 'r' Then 'Renewal' When 'h' Then 'Recall Hold'
    When 'u' Then 'Use Count' When 'b' Then 'Booking'
    When 'hb' Then 'Hold Recall Bib'
    When 'hi' Then 'Hold Recall Item'
    When 'hv' Then 'Hold Recall Volume' End As transtype From
  sierra_view.circ_trans
  Where
  sierra_view.circ_trans.transaction_gmt Between '02/10/2015 00:00:00'
  And '02/11/2015 24:00:00'
Group By
  sierra_view.circ_trans.op_code
Order by
transtype asc
 

1/26/2015

Using javascript to create Outlook email message

Want to use HTML to open Outlook with new message, use script below (only in IE):

<script type="text/javascript">
function OpenOutlookDoc(email_address,body_stuff)
{
try
{

var outlookApp = new ActiveXObject("Outlook.Application");
var nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
mailItem = mailFolder.Items.add('IPM.Note.FormA');
mailItem.Subject="a subject test";
mailItem.To = email_address;
mailItem.HTMLBody = body_stuff;
mailItem.display (0);
}
catch(e)
{
alert(e);
// act on any error that you get
}
}
</script>


<a href="javascript:OpenOutlookDoc('zzz@test.com','Body of message')">Click</a>


On first attempt, got error "Automation server can't create object."   Just need to do following to IE security settings: 

a) Go to Tools-->Internet Options
b) Select security tab
c) Click on Trusted Sites (or Local Intranet depending on whether your site is trusted or not)
d) Click on Custom Level
e) Ensure that "Initialize and script active x controls is not marked safe for scripting" is enabled - this comes under Activex controls and plug-ins section towards 1/4th of the scroll bar.
Click OK, OK.
Once this is completed, clear the browser cookies and cache. Close all your browser sessions. Reopen the IE to launch your site.
Try to disable the setting in step (e) to see if the problem comes back - that should give more insight to the problem.

1/15/2015

Visual basic to access CMD or Shell commands

Wanted to run CMD   NET USER /DOMAIN  
from vb script, and return password expiration date:



Dim objShell, objWshScriptExec, objStdOut, strLine, bolFoundFlag
bolFoundFlag = FALSE

Set objShell = CreateObject("WScript.Shell")
'Set objWshScriptExec = objShell.Exec("ipconfig /all")
Set objWshScriptExec = objShell.Exec("NET USER /DOMAIN " & strName)

Set objStdOut = objWshScriptExec.StdOut

While Not objStdOut.AtEndOfStream
   strLine = objStdOut.ReadLine
   ' english windows
   If InStr(strLine,"Password expires") Then
       response.Write(strName & ":&nbsp;&nbsp; " & strLine & "<p>")
       bolFoundFlag = TRUE
   ' french windows      
   ElseIf InStr(strLine,"found") Then
      response.Write( strLine & "<p>")  
   End If
  
'   response.Write(strLine & " <br>")
Wend

12/16/2014

Remote Desktop Freezing problem

Trying to use RDP from Windows 7 and it kept on locking up or freezing when opening a folder.


To fix this delay or hang or freeze follow these steps
1.    Open Remote Desktop
2.    Click [Options]
3.    Click [Local Resources] tab
4.    Click [Settings] for 'Configure remote audio settings'
5.    Select [Do not play] for 'Remote audio playback'
6.    Select [Do not record] for 'Remote audio recording'
7.    Click [OK]
8.    Connect to your computer


From Social Technet Microsoft

12/10/2014

PDF form filler software

Looking for alternative to Adobe Acrobat Professional for editing PDF files:

Windows:
http://www.foxitsoftware.com/
https://www.gonitro.com/pdf-reader/features   (have to give email)

Apple, $8 app
https://itunes.apple.com/us/app/pdf-form-filler/id566214469?mt=12




12/03/2014

Apple error: can't be opened because it is from an unidentified developer

Trying to install Examsoft on Apple OS, get the following error:


"Install SofTest.mpkg can't be opened because it is from an unidentified developer"


 Receiving this message means that your security preferences don't allow installation from unidentified developers.

To resolve this issue please follow the steps below:

1. Click the "Apple" in the upper left corner and select "System Preferences".


2. Click on "Security & Privacy".

3. Click the Lock in the lower left corner and enter your Mac user account password

4. Under "Allow applications downloaded from:" select "Anywhere".

5. Click "Allow From Anywhere".

You should now be able to install SofTest normally.



From Examsoft

12/02/2014

Uninstalling SofTest from Apple OS

SofTest (from Examsoft) needs to be reinstalled ever year for students, first have to uninstall, here are directions for Apple OS:




1. Click on 'Macintosh HD' on the desktop or by clicking on 'Go' in the menu bar and select 'Computer' then 'Macintosh HD'



2. Click on 'Library'


3. Click on 'Application Support'


4. Look for and right click on the SofTest folder and select 'Move to Trash'

 


5. Follow the on-screen instructions to complete the uninstall process. 


From examsoft.com

11/21/2014

Free Microsoft Office 365 via university email address

Microsoft Office is free to college students, staff, faculty via this link:

http://products.office.com/en-us/student/office-in-education

You need to sign up with your university email address.

Office 365 is an cloud based system, but it does allow you to download a stand alone version to your Windows or Apple computer (a 1GB file, be prepared to give it a chunk of time).


Search on: Microsoft Office free college students

11/19/2014

Using lpadmin command on Yosemite OS

I had Applescript with LPADMIN command that worked with Apple OS, but stopped working on Yosemite (10.10).  Did not get any error, the printer always was in paused state.


 From macenterprise on Google Groups:

I'm seeing some strange cases at the university where certain users are unable to print authenticated via smb when on Yosemite.

I had just about weaned our users off of unauthenticated lpd when printing to our Windows print server in favor of smb with their credentials stored pr. printer in the keychain.

There doesn't seem to be a pattern to who it affects but there are indications that it's sandbox related (cryptic log messages and the like)

Putting the "Sandboxing relaxed" directive in /etc/cups/cups-files.conf seems to fix it for some.

Has anyone else seen problems when printing to smb printers on Yosemite?

Regards,

Simon Andersen
Aarhus University, Denmark

REPLY:



Tony Skalski

Oct 29
Other recipients: MACENT...@lists.psu.edu
We added "-o auth-info-required=negotiate" to our lpadmin command in the
install script we package up for students to use. This seems to have fixed
the Yosemite printing issues we've seen.

ajs
Tony Skalski
Systems Administrator
St. Olaf College
Information Technology
1510 St. Olaf Avenue


-----------------------------------------------------

Poster in Stackoverflow suggested a fix was to add  -E  to enable at the very end, this did NOT work for me.

do shell script "/usr/sbin/lpadmin  -L '3rd-floor-library'   -o printer-is-shared=false -o Duplex=DuplexTumble -o Option1=True -p  '3rd-floor-library' -v smb://server1.cua.edu/LAW_HP9050 -P   " & quoted form of (POSIX path of myFile) as text & "  -E"

Previously I did not need the -E switch.   Adding printer via Printers and Scanners UI works fine under Yosemite, just adding it via lpadmin broke under Yosemite.

From Apple:
-E            Enables the destination and accepts jobs;


From Stackoverflow

10/31/2014

SierraDNA: SQL to get patrons who owe fines greater than $25

From Sierra Listserv, how to create query to get list of patrons who owe fines:



Hi Barbara:

David Jones is correct. You'll need to remove the check digit from your patron name to find a match in the database because the record number is stored internally without the check digit.

I have adapted an existing query of mine to get part way to what you are looking for. The query limits to patrons who owe $25 or more and who do not have manual block 'c'. I haven't limited to the age of the fines or fees. You'll have to fine tune it to get exactly what you're after. I included the check digit on the patron number thanks to some code provided a few months back by Jim Nicholls at University of Sydney.

The end result is 23 columns of data pertaining to the patron and the patron's outstanding fines and fees. Remove what you don't require. The data can be easily exported to Excel and then filtered to a specific patron.
-- ===================================================================================
-- Fines details for patrons Owing $25.00 or more
--  and without manual block 'c'
-- Brent Searle. Langara College. 2014-10-30
-- Check digit calculation via Jim Nicholls, University of Sydney
-- ===================================================================================
SELECT
  p.record_type_code||p.record_num||
  COALESCE( -- Check digit calculation
    CAST(
      NULLIF(
        (
          ( p.record_num % 10 ) * 2 +
          ( p.record_num / 10 % 10 ) * 3 +
          ( p.record_num / 100 % 10 ) * 4 +
          ( p.record_num / 1000 % 10 ) * 5 +
          ( p.record_num / 10000 % 10 ) * 6 +
          ( p.record_num / 100000 % 10 ) * 7 +
          ( p.record_num / 1000000 ) * 8
        ) % 11,
        10
      )
      AS CHAR(1)
    ),
    'x'
  )                                                  AS "Record Number",
  pnam.last_name||
  CASE
    WHEN pnam.first_name IS NOT NULL THEN ', '||pnam.first_name
    ELSE NULL
  END||
  CASE
    when pnam.middle_name IS NOT NULL THEN ' '||pnam.middle_name
    ELSE NULL
  END                                                AS "Patron Name",
  p.barcode                                          AS "Patron Barcode",
  p.home_library_code                                AS "Home Library",
  p.ptype_code                                       AS "Ptype code",
  ptnam.name                                         AS "Patron Type",
  f.invoice_num                                      AS "Invoice",
  CASE
    WHEN f.charge_code = '1' THEN 'MANUAL'
    WHEN f.charge_code = '2' THEN 'Overdue'
    WHEN f.charge_code = '3' THEN 'Replacement'
    WHEN f.charge_code = '4' THEN 'OverdueX'
    WHEN f.charge_code = '5' THEN 'Lost'
    WHEN f.charge_code = '6' THEN 'Overdue Renewal'
    WHEN f.charge_code = '7' THEN 'Rental'
    WHEN f.charge_code = '8' THEN 'RentalX'
    WHEN f.charge_code = '9' THEN 'Debit'
    WHEN f.charge_code = 'a' THEN 'Notice'
    WHEN f.charge_code = 'b' THEN 'Credit Card'
    WHEN f.charge_code = 'p' THEN 'Program Reg'
    ELSE 'unexpected code '||f.charge_code
  END                                                AS "Type",
  f.description                                      AS "Reason",
  f.title                                            AS "Title",
  i.barcode                                          AS "Item Barcode",
  f.charge_location_code                             AS "Item Location",
  to_char(f.assessed_gmt,'YYYY-MM-DD HH:MI AM')      AS "Date Assessed",
  to_char(f.checkout_gmt,'YYYY-MM-DD HH:MI AM')      AS "Date Checked Out",
  to_char(f.due_gmt,'YYYY-MM-DD HH:MIAM')            AS "Date Due",
  to_char(f.returned_gmt,'YYYY-MM-DD HH:MI AM')      AS "Date Returned",
  to_char(f.item_charge_amt,'$99G990D99')            AS "Item Charge",
  to_char(f.processing_fee_amt,'$99G990D99')         AS "Processing Fee",
  to_char(f.billing_fee_amt,'$99G990D99')            AS "Billing Fee",
  to_char(f.item_charge_amt+
  f.processing_fee_amt+
  f.billing_fee_amt,'$99G990D99')                    AS "Total",
  to_char(f.paid_amt,'$99G990D99')                   AS "Amount Paid",
  to_char(f.item_charge_amt+
  f.processing_fee_amt+
  f.billing_fee_amt-
  f.paid_amt,'$99G990D99')                           AS "Amount Due"
FROM
  sierra_view.patron_view                            AS p
JOIN -- join to patron full name
  sierra_view.patron_record_fullname                 AS pnam
  ON
  pnam.patron_record_id = p.id
JOIN -- join to ptype description
  sierra_view.ptype_property_myuser                  AS ptnam
  ON
  ptnam.value = p.ptype_code
JOIN -- join to fine data
  sierra_view.fine                                   AS f
  ON
  f.patron_record_id = p.id
JOIN -- join for item barcode
  sierra_view.item_view                              AS i
  ON
  i.id = f.item_record_metadata_id
WHERE
  p.owed_amt >= 25     -- patron owes $25.00 or more
  AND
  p.mblock_code != 'c' -- patron doesn't have manual block 'c'
ORDER BY
  2,14
;

--
Brent Searle
Library Systems Manager
Langara College
Vancouver BC

On 2014-10-30 2:23 PM, Leach, Barbara wrote:
I’m at the very beginning of trying to create a sql query to get a list of patrons who owe $25 or more in fines, they don’t have manual block ‘c’, their fine was assessed more than a month ago, and they don’t have a fee assessed more recently than a month ago.  I can use Create Lists to get the list, but the fields I want to export aren’t available for export.  So, I’m trying to re-create this with sql, so I can get the fields I want exported.

However, I can’t even get this simple query to return any data.  What am I doing wrong with this simple query?

SELECT
  patron_view.record_num AS "Record Number",
  patron_view.barcode AS "Barcode",
  patron_view.owed_amt AS "Amount Owed",
  patron_view.home_library_code AS "Home Library"
FROM
  sierra_view.patron_view
WHERE
  patron_view.record_num = '10068260';

When I run this, the output pane contains 0 rows.  I know that’s a valid patron record number, because it is a record that was included in my Create Lists results.

I need specific data about the fines, such as the date they were assessed, and that’s not available in Create Lists export fields.

If anyone already has a query that is similar to what I’m trying to create, would you mind sharing?

Thank you.
Barbara
Barbara Leach
Automated Services Coordinator

10/17/2014

Windows Updates repeat

Have a PC that repeatedly install same updates over and over.  To fix:


As an administrator, stop the Windows Update service (Start > Run > services.msc, stop Windows Update). Rename the Windows\SoftwareDistribution directory to something like SoftwareDistribution.bak and restart.
Occasionally I've seen updates become "stuck" and cached, prompting the behavior you're seeing. This method normally works for me in most cases.

10/01/2014

Replacing damaged USB cord in Kwikboost charging station

Our library has a Kiwkboost charger, and someone yanked one of the wires too hard and tore off one of the plugs.

The device is easy to open up and replace any individual cords, a nice youtube tutorial via Westlaw:

2016-Oct:   This has been removed, will try locating alternative.