]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/500.view.cross-schema.sql
LP#1389403: Stamping upgrade script for normalizer detection to call number browse
[working/Evergreen.git] / Open-ILS / src / sql / Pg / 500.view.cross-schema.sql
1 /*
2  * Copyright (C) 2004-2008  Georgia Public Library Service
3  * Copyright (C) 2007-2008  Equinox Software, Inc.
4  * Mike Rylander <miker@esilibrary.com> 
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 BEGIN;
19
20
21 CREATE OR REPLACE VIEW money.billable_xact_summary_location_view AS
22     SELECT  m.*, COALESCE(c.circ_lib, g.billing_location, r.pickup_lib) AS billing_location
23       FROM  money.materialized_billable_xact_summary m
24             LEFT JOIN action.circulation c ON (c.id = m.id)
25             LEFT JOIN money.grocery g ON (g.id = m.id)
26             LEFT JOIN booking.reservation r ON (r.id = m.id);
27
28 CREATE OR REPLACE VIEW money.open_billable_xact_summary AS 
29     SELECT * FROM money.billable_xact_summary_location_view
30     WHERE xact_finish IS NULL;
31
32 CREATE OR REPLACE VIEW money.open_usr_summary AS
33     SELECT 
34         usr, 
35         sum(total_paid) AS total_paid, 
36         sum(total_owed) AS total_owed, 
37         sum(balance_owed) AS balance_owed
38     FROM money.materialized_billable_xact_summary
39     WHERE xact_finish IS NULL
40     GROUP BY usr;
41
42 CREATE OR REPLACE VIEW money.open_usr_circulation_summary AS
43     SELECT 
44         usr,
45         SUM(total_paid) AS total_paid,
46         SUM(total_owed) AS total_owed,
47         SUM(balance_owed) AS balance_owed
48     FROM  money.materialized_billable_xact_summary
49     WHERE xact_type = 'circulation' AND xact_finish IS NULL
50     GROUP BY usr;
51
52
53 -- Not a view, but it's cross-schema..
54 CREATE TABLE config.idl_field_doc (
55     id              BIGSERIAL   PRIMARY KEY,
56     fm_class        TEXT        NOT NULL,
57     field           TEXT        NOT NULL,
58     owner           INT         NOT NULL    REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
59     string          TEXT        NOT NULL
60 );
61 CREATE UNIQUE INDEX idl_field_doc_identity ON config.idl_field_doc (fm_class,field,owner);
62
63
64 COMMIT;
65