LP#1516022: new reporting source for hold/copy ratios
[Evergreen.git] / Open-ILS / examples / fm_IDL.xml
index 8e8df0e..4a56269 100644 (file)
@@ -10574,6 +10574,62 @@ SELECT  usr,
                </permacrud>
        </class>
 
+       <class id="rhcrpbapd" controller="open-ils.cstore open-ils.pcrud open-ils.reporter-store" oils_obj:fieldmapper="reporter::hold_copy_ratio_per_bib_and_pickup_desc" oils_persist:readonly="true" reporter:label="Hold/Copy Ratio per Bib and Pickup Library (and Descendants) ">
+               <oils_persist:source_definition>
+            WITH counts_at_ou AS (
+                SELECT bib_record, pickup_lib, count(DISTINCT ahr.id) AS holds_at_pickup_library, 
+                    COALESCE(count(DISTINCT ac.id),0) as copy_count_at_pickup_library
+                FROM action.hold_request ahr
+                JOIN reporter.hold_request_record rhrr USING (id)
+                LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold)
+                LEFT JOIN asset.copy ac ON (ahcm.target_copy = ac.id AND ahr.pickup_lib = ac.circ_lib)
+                WHERE ahr.cancel_time IS NULL
+                AND ahr.fulfillment_time IS NULL
+                GROUP BY bib_record, pickup_lib
+            )
+            SELECT *,
+                CASE WHEN copy_count_at_or_below = 0 THEN 'Infinity'::FLOAT ELSE holds_at_or_below::FLOAT/copy_count_at_or_below END AS hold_copy_ratio_at_or_below_ou,
+                CASE WHEN copy_count_everywhere = 0 THEN 'Infinity'::FLOAT ELSE holds_everywhere::FLOAT/copy_count_everywhere END AS everywhere_ratio
+            FROM
+                (SELECT bib_record AS id, aou.id AS pickup_lib_or_desc, SUM(holds_at_pickup_library) AS holds_at_or_below, SUM(copy_count_at_pickup_library) AS copy_count_at_or_below
+                FROM actor.org_unit aou
+                JOIN counts_at_ou cao ON (cao.pickup_lib IN (SELECT id FROM actor.org_unit_descendants(aou.id))) 
+                GROUP BY bib_record, pickup_lib_or_desc
+                )x
+                JOIN
+                (SELECT bib_record AS id, count(DISTINCT ahr.id) AS holds_everywhere, COALESCE(count(DISTINCT target_copy),0) as copy_count_everywhere
+                    FROM
+                        action.hold_request ahr
+                        JOIN reporter.hold_request_record rhrr USING (id)
+                        LEFT JOIN action.hold_copy_map ahcm ON (ahr.id = ahcm.hold)
+                    WHERE
+                        ahr.cancel_time IS NULL
+                        AND ahr.fulfillment_time IS NULL
+                    GROUP BY bib_record
+                )y
+                USING (id)
+               </oils_persist:source_definition>
+               <fields oils_persist:primary="id" oils_persist:sequence="biblio.record_entry">
+                       <field reporter:label="Record ID" name="id" reporter:datatype="link"/>
+                       <field reporter:label="Pickup Library" name="pickup_lib_or_desc" reporter:datatype="org_unit"/>
+                       <field reporter:label="Active Holds at Pickup Library and its Descendants" name="holds_at_or_below" reporter:datatype="int"/>
+                       <field reporter:label="Holdable Copy Count at Pickup Library and its Descendants" name="copy_count_at_or_below" reporter:datatype="int"/>
+                       <field reporter:label="Active Holds Everywhere" name="holds_everywhere" reporter:datatype="int"/>
+                       <field reporter:label="Holdable Copy Count Everywhere" name="copy_count_everywhere" reporter:datatype="int"/>
+                       <field reporter:label="Hold/Copy Ratio at Pickup Library and its Descendants" name="hold_copy_ratio_at_or_below_ou" reporter:datatype="float"/>
+                       <field reporter:label="Hold/Copy Ratio Everywhere" name="everywhere_ratio" reporter:datatype="float"/>
+               </fields>
+               <links>
+                       <link field="id" reltype="has_a" key="id" map="" class="bre"/>
+                       <link field="pickup_lib" reltype="has_a" key="id" map="" class="aou"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <retrieve/>
+                       </actions>
+               </permacrud>
+       </class>
+
        <class id="rlc" controller="open-ils.cstore open-ils.pcrud open-ils.reporter-store" oils_obj:fieldmapper="reporter::last_circ_date" oils_persist:readonly="true" reporter:label="Last Circulation or Creation Date">
                <oils_persist:source_definition>
             SELECT