From 5e30061113c1c5f1706e94ddf7db03b2ca0fcc06 Mon Sep 17 00:00:00 2001 From: seneyl Date: Fri, 25 Apr 2025 14:45:31 -0600 Subject: [PATCH] Create claimed_returned_by_location.sql A generic report to pull a list of claimed returned items by location --- .../reports/claimed_returned_by_location.sql | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 folio/reports/claimed_returned_by_location.sql diff --git a/folio/reports/claimed_returned_by_location.sql b/folio/reports/claimed_returned_by_location.sql new file mode 100644 index 0000000..7ebba9a --- /dev/null +++ b/folio/reports/claimed_returned_by_location.sql @@ -0,0 +1,47 @@ +--metadb:function claimed_returned_by_location + +-- Report pulls a list of items with the status of claimed returned, +-- with the ability to filter by library. + +DROP FUNCTION IF EXISTS claimed_returned_by_location; + +CREATE FUNCTION claimed_returned_by_location( + /* Enter a FOLIO item location */ + item_location text) +RETURNS TABLE( + claimed_date date, + item_barcode text, + library text, + item_location text, + call_number text, + copy text, + volume text, + claim_note text, + loan_id text + ) +AS $$ +SELECT + (i.jsonb -> 'status' ->> 'date')::DATE as claimed_date, + i.jsonb ->> 'barcode' as item_barcode, + lt2."name" as library, + lt."name" as item_location, + holdings."call_number", + i.jsonb ->> 'copyNumber' AS copy, + i.jsonb ->> 'volume' AS volume, + l.jsonb ->> 'actionComment' as claim_note, + l.jsonb ->> 'id' AS loan_id +FROM folio_circulation.loan l +LEFT JOIN folio_inventory.item i on i.id = (l.jsonb ->> 'itemId')::uuid +LEFT JOIN folio_users.users__t as u on u.id = (l.jsonb ->> 'userId')::uuid +LEFT JOIN folio_inventory.location__t lt on lt.id = (i.jsonb ->> 'effectiveLocationId')::uuid +LEFT JOIN folio_inventory.loclibrary__t lt2 on lt2.id = lt.library_id +LEFT JOIN folio_inventory.holdings_record__t as holdings on holdings.id = i.holdingsrecordid +where i.jsonb -> 'status' ->> 'name' = 'Claimed returned' + AND l.jsonb ->> 'itemStatus' = 'Claimed returned' + AND l.jsonb ->> 'action' = 'claimedReturned' + AND lt."name" ilike concat('%',item_location,'%') +ORDER BY claimed_date asc +$$ +language sql +stable +parallel safe;