Merge remote-tracking branch 'eg-working/user/berick/hold-current-shelf-lib'
authorMike Rylander <mrylander@gmail.com>
Mon, 9 Jan 2012 18:44:16 +0000 (13:44 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 9 Jan 2012 18:44:45 +0000 (13:44 -0500)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
1  2 
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/090.schema.action.sql

@@@ -3264,9 -3264,6 +3264,9 @@@ SELECT  usr
                        <field reporter:label="Billing Totals" name="billing_total" oils_persist:virtual="true" reporter:datatype="money"/>
                        <field reporter:label="Payment Totals" name="payment_total" oils_persist:virtual="true" reporter:datatype="money"/>
                        <field reporter:label="Unrecovered Debt" name="unrecovered" reporter:datatype="bool"/>
 +                      <field reporter:label="Shelving Location" name="copy_location" reporter:datatype="link"/>
 +                      <field reporter:label="Archived Patron Stat-Cat Entries" name="aaactsc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
 +                      <field reporter:label="Archived Copy Stat-Cat Entries" name="aaasc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="billable_transaction" reltype="might_have" key="id" map="" class="mbt"/>
                        <link field="checkin_workstation" reltype="has_a" key="id" map="" class="aws"/>
                        <link field="parent_circ" reltype="has_a" key="id" map="" class="circ"/>
                        <link field="renewals" reltype="has_many" key="parent_circ" map="" class="circ"/>
 +                      <link field="copy_location" reltype="has_a" key="id" map="" class="acpl"/>
 +                      <link field="aaactsc_entries" reltype="has_many" key="xact" map="" class="aaactsc"/>
 +                      <link field="aaasc_entries" reltype="has_many" key="xact" map="" class="aaasc"/>
                </links>
        </class>
        <class id="combcirc" controller="open-ils.cstore" oils_obj:fieldmapper="action::all_circulation" oils_persist:tablename="action.all_circulation" reporter:core="true" reporter:label="Combined Aged and Active Circulations" oils_persist:readonly="true">
                        <field reporter:label="Copy Owning Library" name="copy_owning_lib" reporter:datatype="link"/>
                        <field reporter:label="Copy Circulating Library" name="copy_circ_lib" reporter:datatype="link"/>
                        <field reporter:label="Bib Record" name="copy_bib_record" reporter:datatype="link"/>
 +                      <field reporter:label="Archived Patron Stat-Cat Entries" name="aaactsc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
 +                      <field reporter:label="Archived Copy Stat-Cat Entries" name="aaasc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="billable_transaction" reltype="might_have" key="id" map="" class="mbt"/>
                        <link field="copy_owning_lib" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="copy_circ_lib" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="copy_bib_record" reltype="has_a" key="id" map="" class="bre"/>
 +                      <link field="aaactsc_entries" reltype="has_many" key="xact" map="" class="aaactsc"/>
 +                      <link field="aaasc_entries" reltype="has_many" key="xact" map="" class="aaasc"/>
                </links>
        </class>
        <class id="acirc" controller="open-ils.cstore" oils_obj:fieldmapper="action::aged_circulation" oils_persist:tablename="action.aged_circulation" reporter:core="true" reporter:label="Aged (patronless) Circulation">
                        <field reporter:label="Copy Owning Library" name="copy_owning_lib" reporter:datatype="link"/>
                        <field reporter:label="Copy Circulating Library" name="copy_circ_lib" reporter:datatype="link"/>
                        <field reporter:label="Bib Record" name="copy_bib_record" reporter:datatype="link"/>
 +                      <field reporter:label="Archived Patron Stat-Cat Entries" name="aaactsc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
 +                      <field reporter:label="Archived Copy Stat-Cat Entries" name="aaasc_entries" oils_persist:virtual="true" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="billable_transaction" reltype="might_have" key="id" map="" class="mbt"/>
                        <link field="checkin_workstation" reltype="has_a" key="id" map="" class="aws"/>
                        <link field="parent_circ" reltype="might_have" key="id" map="" class="circ"/>
                        <link field="renewals" reltype="has_many" key="parent_circ" map="" class="circ"/>
 +                      <link field="aaactsc_entries" reltype="has_many" key="xact" map="" class="aaactsc"/>
 +                      <link field="aaasc_entries" reltype="has_many" key="xact" map="" class="aaasc"/>
                </links>
        </class>
  
                        <field reporter:label="Is Mint Condition" name="mint_condition" reporter:datatype="bool" />
                        <field reporter:label="Shelf Expire Time" name="shelf_expire_time" reporter:datatype="timestamp"/>
                        <field reporter:label="Notes" name="notes" reporter:datatype="link" oils_persist:virtual="true"/>
+                       <field reporter:label="Current Shelf Lib" name="current_shelf_lib" reporter:datatype="org_unit"/>
                </fields>
                <links>
                        <link field="fulfillment_lib" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="bib_rec" reltype="might_have" key="id" map="" class="rhrr"/>
                        <link field="cancel_cause" reltype="might_have" key="id" map="" class="ahrcc"/>
                        <link field="notes" reltype="has_many" key="hold" map="" class="ahrn"/>
+                       <link field="current_shelf_lib" reltype="has_a" key="id" map="" class="aou"/>
                </links>
        </class>
        <class id="alhr" controller="open-ils.cstore" oils_obj:fieldmapper="action::last_hold_request" reporter:label="Last Captured Hold Request" oils_persist:readonly="true">
                        <field reporter:label="Is Mint Condition" name="mint_condition" reporter:datatype="bool" />
                        <field reporter:label="Shelf Expire Time" name="shelf_expire_time" reporter:datatype="timestamp"/>
                        <field reporter:label="Notes" name="notes" reporter:datatype="link" oils_persist:virtual="true"/>
+                       <field reporter:label="Current Shelf Lib" name="current_shelf_lib" reporter:datatype="org_unit"/>
                </fields>
                <links>
                        <link field="fulfillment_lib" reltype="has_a" key="id" map="" class="aou"/>
                        <link field="bib_rec" reltype="might_have" key="id" map="" class="rhrr"/>
                        <link field="cancel_cause" reltype="might_have" key="id" map="" class="ahrcc"/>
                        <link field="notes" reltype="has_many" key="hold" map="" class="ahrn"/>
+                       <link field="current_shelf_lib" reltype="has_a" key="id" map="" class="aou"/>
                </links>
        </class>
  
                        <field reporter:label="SIP Field" name="sip_field" reporter:datatype="link"/>
                        <field reporter:label="SIP Format" name="sip_format" reporter:datatype="text"/>
                        <field reporter:label="Required" name="required" reporter:datatype="bool"/>
 +                      <field reporter:label="Checkout Archive" name="checkout_archive" reporter:datatype="bool"/>
                </fields>
                <links>
                        <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
                        <field reporter:label="User Summary" name="usr_summary" reporter:datatype="bool"/>
                        <field reporter:label="SIP Field" name="sip_field" reporter:datatype="link"/>
                        <field reporter:label="SIP Format" name="sip_format" reporter:datatype="text"/>
 +                      <field reporter:label="Checkout Archive" name="checkout_archive" reporter:datatype="bool"/>
                </fields>
                <links>
                        <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
                        </actions>
                </permacrud>
        </class>
 +      <class id="aaactsc" controller="open-ils.reporter-store" oils_obj:fieldmapper="action::archive_actor_stat_cat" oils_persist:tablename="action.archive_actor_stat_cat" reporter:label="Circ-Archived Patron Statistical Category Entries">
 +              <fields oils_persist:primary="id" oils_persist:sequence="action.archive_actor_stat_cat_id_seq">
 +                      <field reporter:label="ID" name="id" reporter:datatype="id"/>
 +                      <field reporter:label="Circ" name="xact" reporter:datatype="link"/>
 +                      <field reporter:label="Statistical Category" name="stat_cat" reporter:datatype="link"/>
 +                      <field reporter:label="Entry Value" name="value" reporter:datatype="text"/>
 +              </fields>
 +              <links>
 +                      <link field="xact" reltype="has_a" key="id" map="" class="combcirc"/>
 +                      <link field="stat_cat" reltype="has_a" key="id" map="" class="actsc"/>
 +              </links>
 +      </class>
 +      <class id="aaasc" controller="open-ils.reporter-store" oils_obj:fieldmapper="action::archive_asset_stat_cat" oils_persist:tablename="action.archive_asset_stat_cat" reporter:label="Circ-Archived Copy Statistical Category Entries">
 +              <fields oils_persist:primary="id" oils_persist:sequence="action.archive_actor_stat_cat_id_seq">
 +                      <field reporter:label="ID" name="id" reporter:datatype="id"/>
 +                      <field reporter:label="Circ" name="xact" reporter:datatype="link"/>
 +                      <field reporter:label="Statistical Category" name="stat_cat" reporter:datatype="link"/>
 +                      <field reporter:label="Entry Value" name="value" reporter:datatype="text"/>
 +              </fields>
 +              <links>
 +                      <link field="xact" reltype="has_a" key="id" map="" class="combcirc"/>
 +                      <link field="stat_cat" reltype="has_a" key="id" map="" class="asc"/>
 +              </links>
 +      </class>
  
  
        <!-- ********************************************************************************************************************* -->
@@@ -101,20 -101,6 +101,20 @@@ CREATE TRIGGER action_survey_response_a
        FOR EACH ROW
        EXECUTE PROCEDURE action.survey_response_answer_date_fixup ();
  
 +CREATE TABLE action.archive_actor_stat_cat (
 +    id          BIGSERIAL   PRIMARY KEY,
 +    xact        BIGINT      NOT NULL, -- action.circulation (+aged/all)
 +    stat_cat    INT         NOT NULL,
 +    value       TEXT        NOT NULL
 +);
 +
 +CREATE TABLE action.archive_asset_stat_cat (
 +    id          BIGSERIAL   PRIMARY KEY,
 +    xact        BIGINT      NOT NULL, -- action.circulation (+aged/all)
 +    stat_cat    INT         NOT NULL,
 +    value       TEXT        NOT NULL
 +);
 +
  
  CREATE TABLE action.circulation (
        target_copy             BIGINT                          NOT NULL, -- asset.copy.id
        checkin_workstation INT        REFERENCES actor.workstation(id)
                                       ON DELETE SET NULL
                                                                   DEFERRABLE INITIALLY DEFERRED,
 +      copy_location   INT                             NOT NULL DEFAULT 1 REFERENCES asset.copy_location (id) DEFERRABLE INITIALLY DEFERRED,
        checkin_scan_time   TIMESTAMP WITH TIME ZONE
  ) INHERITS (money.billable_xact);
  ALTER TABLE action.circulation ADD PRIMARY KEY (id);
@@@ -184,40 -169,13 +184,40 @@@ $$ LANGUAGE PLPGSQL
  
  CREATE TRIGGER push_due_date_tgr BEFORE INSERT OR UPDATE ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.push_circ_due_time();
  
 +CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
 +BEGIN
 +    SELECT INTO NEW.copy_location location FROM asset.copy WHERE id = NEW.target_copy;
 +    RETURN NEW;
 +END;
 +$$ LANGUAGE PLPGSQL;
 +
 +CREATE TRIGGER fill_circ_copy_location_tgr BEFORE INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.fill_circ_copy_location();
 +
 +CREATE OR REPLACE FUNCTION action.archive_stat_cats () RETURNS TRIGGER AS $$
 +BEGIN
 +    INSERT INTO action.archive_actor_stat_cat(xact, stat_cat, value)
 +        SELECT NEW.id, asceum.stat_cat, asceum.stat_cat_entry
 +        FROM actor.stat_cat_entry_usr_map asceum
 +             JOIN actor.stat_cat sc ON asceum.stat_cat = sc.id
 +        WHERE NEW.usr = asceum.target_usr AND sc.checkout_archive;
 +    INSERT INTO action.archive_asset_stat_cat(xact, stat_cat, value)
 +        SELECT NEW.id, ascecm.stat_cat, asce.value
 +        FROM asset.stat_cat_entry_copy_map ascecm
 +             JOIN asset.stat_cat sc ON ascecm.stat_cat = sc.id
 +             JOIN asset.stat_cat_entry asce ON ascecm.stat_cat_entry = asce.id
 +        WHERE NEW.target_copy = ascecm.owning_copy AND sc.checkout_archive;
 +    RETURN NULL;
 +END;
 +$$ LANGUAGE PLPGSQL;
 +
 +CREATE TRIGGER archive_stat_cats_tgr AFTER INSERT ON action.circulation FOR EACH ROW EXECUTE PROCEDURE action.archive_stat_cats();
 +
  CREATE TABLE action.aged_circulation (
        usr_post_code           TEXT,
        usr_home_ou             INT     NOT NULL,
        usr_profile             INT     NOT NULL,
        usr_birth_year          INT,
        copy_call_number        INT     NOT NULL,
 -      copy_location           INT     NOT NULL,
        copy_owning_lib         INT     NOT NULL,
        copy_circ_lib           INT     NOT NULL,
        copy_bib_record         BIGINT  NOT NULL,
@@@ -243,7 -201,7 +243,7 @@@ CREATE OR REPLACE VIEW action.all_circu
        FROM  action.aged_circulation
              UNION ALL
      SELECT  DISTINCT circ.id,COALESCE(a.post_code,b.post_code) AS usr_post_code, p.home_ou AS usr_home_ou, p.profile AS usr_profile, EXTRACT(YEAR FROM p.dob)::INT AS usr_birth_year,
 -        cp.call_number AS copy_call_number, cp.location AS copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
 +        cp.call_number AS copy_call_number, circ.copy_location, cn.owning_lib AS copy_owning_lib, cp.circ_lib AS copy_circ_lib,
          cn.record AS copy_bib_record, circ.xact_start, circ.xact_finish, circ.target_copy, circ.circ_lib, circ.circ_staff, circ.checkin_staff,
          circ.checkin_lib, circ.renewal_remaining, circ.grace_period, circ.due_date, circ.stop_fines_time, circ.checkin_time, circ.create_time, circ.duration,
          circ.fine_interval, circ.recurring_fine, circ.max_fine, circ.phone_renewal, circ.desk_renewal, circ.opac_renewal, circ.duration_rule,
@@@ -399,7 -357,8 +399,8 @@@ CREATE TABLE action.hold_request 
        shelf_time              TIMESTAMP WITH TIME ZONE,
      cut_in_line     BOOL,
        mint_condition  BOOL NOT NULL DEFAULT TRUE,
-       shelf_expire_time TIMESTAMPTZ
+       shelf_expire_time TIMESTAMPTZ,
+       current_shelf_lib INT REFERENCES actor.org_unit DEFERRABLE INITIALLY DEFERRED
  );
  
  CREATE INDEX hold_request_target_idx ON action.hold_request (target);