Advertisement
roganhamby

Extend Reporter - Purchase Alerts

Feb 2nd, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. -- for /openils/var/web/reports/fm_IDL.xml & /openils/conf
  2.  
  3. <class id="erpa" controller="openils.cstore" oils_obj:fieldmapper="extend_reporter::purchase_alerts" oils_persist:tablename="extend_reporter.purchase_alerts" reporter:core="true" reporter:label="Purchase Alerts">
  4. <fields>
  5. <field reporter:label="Bib Record" name="bib_id" reporter:datatype="link"/>
  6. <field reporter:label="Library System" name="library_id" reporter:datatype="link"/>
  7. <field reporter:label="Library" name="library" reporter:datatype="text"/>
  8. <field reporter:label="Title" name="title" reporter:datatype="text"/>
  9. <field reporter:label="Author" name="author" reporter:datatype="text"/>
  10. <field reporter:label="ISBNs" name="isbn" reporter:datatype="text"/>
  11. <field reporter:label="Publisher" name="publisher" reporter:datatype="text"/>
  12. <field reporter:label="Copies Currently Owned" name="copies" reporter:datatype="int"/>
  13. <field reporter:label="Holds on Bib Record" name="holds_count" reporter:datatype="int"/>
  14. <field reporter:label="Holds Count Per Copy" name="holds_count_per_copy" reporter:datatype="int"/>
  15. </fields>
  16. <links>
  17. <link field="bib_id" reltype="has_a" key="id" map="" class="bre"/>
  18. <link field="library_id" reltype="has_a" key="id" map="" class="aou"/>
  19. </links>
  20. </class>
  21.  
  22. drop view if exists extend_reporter.purchase_alerts;
  23.  
  24. create view extend_reporter.purchase_alerts as
  25. SELECT bd.bib_id, parent.id AS library_id, parent.shortname AS library, bd.title, bd.author, bd.isbn, bd.publisher,
  26. SUM(bd.copies) AS copies, SUM(bd.holds_count) AS holds_count,
  27. ROUND(SUM(bd.holds_count)/SUM(bd.copies)) AS holds_count_per_copy
  28. FROM (
  29. SELECT all_holds.bib_id, aou.id AS org, rmsr.title, rmsr.author, rmsr.isbn, rmsr.publisher,
  30. COUNT(DISTINCT ac.id) AS "copies", COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id) AS holds_count
  31. FROM ((
  32. SELECT hold_request.target, hold_request.pickup_lib
  33. FROM ACTION.hold_request
  34. WHERE hold_request.hold_type = 'T'::TEXT
  35. AND hold_request.fulfillment_time IS NULL
  36. AND hold_request.cancel_time IS NULL
  37. UNION ALL
  38. SELECT bre.id, ahr.pickup_lib
  39. FROM ACTION.hold_request ahr
  40. JOIN asset.call_number acn ON ahr.target = acn.id
  41. JOIN biblio.record_entry bre ON acn.record = bre.id
  42. WHERE ahr.hold_type = 'V'::TEXT
  43. AND ahr.fulfillment_time IS NULL
  44. AND ahr.cancel_time IS NULL)
  45. UNION ALL
  46. SELECT bre.id, ahr.pickup_lib
  47. FROM ACTION.hold_request ahr
  48. JOIN asset.COPY ac ON ahr.target = ac.id
  49. JOIN asset.call_number acn ON ac.call_number = acn.id
  50. JOIN biblio.record_entry bre ON acn.record = bre.id
  51. WHERE ahr.hold_type = 'C'::TEXT
  52. AND ahr.fulfillment_time IS NULL
  53. AND ahr.cancel_time IS NULL)
  54. all_holds(bib_id, pickup_lib)
  55. JOIN reporter.materialized_simple_record rmsr ON rmsr.id = all_holds.bib_id
  56. JOIN actor.org_unit aou ON aou.id = all_holds.pickup_lib
  57. JOIN asset.call_number acn ON acn.record = all_holds.bib_id
  58. JOIN asset.COPY ac ON ac.call_number = acn.id
  59. WHERE ac.circ_lib = all_holds.pickup_lib
  60. GROUP BY 1, 2, 3, 4, 5, 6
  61. HAVING COUNT(all_holds.bib_id)/COUNT(DISTINCT ac.id) > 3
  62. ) bd
  63. JOIN actor.org_unit child ON child.id = bd.org
  64. JOIN actor.org_unit parent ON parent.id = child.parent_ou
  65. GROUP BY 1, 2, 3, 4, 5, 6, 7
  66. ;
  67.  
  68. select * from extend_reporter.purchase_alerts where library = 'YCL' order by 3,4;
  69.  
  70.  
  71. /*
  72.  
  73. future development notes
  74.  
  75. decided to not include metarecord holds because they are too small a percetage and potentially too confusing to users but they could be linked through metabib.metarecord.id = action.hold_request.target where hold_type = 'M'
  76.  
  77. if we wanted material types we could do something like
  78.  
  79. join metabib.record_attr_vector_list vl on vl.source = bd.bib_id
  80. join metabib.full_attr_id_map atmap on atmap.id = any(vl.vlist)
  81.  
  82. to access the item_type and item_form but without mapping it the search_type and icon_type might actually be more useful to users without doing additional work
  83.  
  84. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement