rough cut at reporting extension for a purchase alert list (based on holds to copy...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 6 May 2010 22:14:06 +0000 (22:14 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 6 May 2010 22:14:06 +0000 (22:14 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16402 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml

index 82d72b3..d6fbf28 100644 (file)
@@ -7042,6 +7042,70 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </permacrud>
        </class>
 
+       <class id="rhcrpb" controller="open-ils.cstore open-ils.pcrud open-ils.reporter-store" oils_obj:fieldmapper="reporter::hold_copy_ratio_per_bib" oils_persist:readonly="true" reporter:core="true" reporter:label="Hold/Copy Ratio per Bib">
+               <oils_persist:source_definition>
+
+            -- -- If we uncomment the RIGHT JOIN against biblio.record_entry, then we'll get a row for every non-deleted bib, whether it has active holds or not.
+            -- -- If we expect to use pcrud to query against specific bibs, we probably want to do this.  However, if we're using this to populate a report, we
+            -- -- may not.
+            -- SELECT
+            --     bre.id AS "bib_id",
+            --     COALESCE( z.copy_count, 0 ) AS "copy_count",
+            --     COALESCE( z.hold_count, 0 ) AS "hold_count",
+            --     COALESCE( z.copy_hold_ratio, 0 ) AS "hold_copy_ratio"
+            -- FROM (
+                SELECT
+                    y.bre AS "bib_id",
+                    COALESCE( x.copy_count, 0 ) AS "copy_count",
+                    y.hold_count AS "hold_count",
+                    (y.hold_count::REAL / (CASE WHEN x.copy_count = 0 OR x.copy_count IS NULL THEN 0.1 ELSE x.copy_count::REAL END)) AS "hold_copy_ratio"
+                FROM (
+                        SELECT
+                            (SELECT bib_record FROM reporter.hold_request_record r WHERE r.id = h.id LIMIT 1) AS "bre",
+                            COUNT(*) AS "hold_count"
+                        FROM action.hold_request h
+                        WHERE
+                            cancel_time IS NULL
+                            AND fulfillment_time IS NULL
+                            -- AND NOT frozen  -- a frozen hold is still a desired hold, eh?
+                        GROUP BY 1
+                    )y LEFT JOIN (
+                        SELECT 
+                            (SELECT id
+                                FROM biblio.record_entry 
+                                WHERE id = (SELECT record FROM asset.call_number WHERE id = call_number)
+                            ) AS "bre", 
+                            COUNT(*) AS "copy_count"
+                        FROM asset.copy
+                            JOIN asset.copy_location loc ON (copy.location = loc.id AND loc.holdable)
+                        WHERE copy.holdable 
+                            AND NOT copy.deleted 
+                            AND copy.status IN ( SELECT id FROM config.copy_status WHERE holdable ) 
+                        GROUP BY 1
+                    )x ON x.bre = y.bre
+                -- )z RIGHT JOIN (
+                --     SELECT id
+                --     FROM biblio.record_entry
+                --     WHERE NOT deleted
+                -- )bre ON (z.bib_id = bre.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="id"/>
+                       <field reporter:label="Holdable Copy Count" name="copy_count" reporter:datatype="int"/>
+                       <field reporter:label="Active Holds" name="hold_count" reporter:datatype="int"/>
+                       <field reporter:label="Hold/Copy Ratio" name="hold_copy_ratio" reporter:datatype="float"/>
+               </fields>
+               <links>
+                       <link field="id" reltype="has_a" key="id" map="" class="bre"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <retrieve/>
+                       </actions>
+               </permacrud>
+       </class>
 
        <!-- ********************************************************************************************************************* -->
        <!-- What follows is a set of example extensions that are useful for PINES.  Comment out or remove if you don't want them. -->