]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0125.schema.acq-ord-fund-src-credit.sql
LP#1155329: better enforce cat.bib.use_id_for_tcn
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0125.schema.acq-ord-fund-src-credit.sql
1 BEGIN;
2
3 INSERT INTO config.upgrade_log (version) VALUES ('0125'); -- Scott McKellar
4
5 CREATE VIEW acq.ordered_funding_source_credit AS
6         SELECT
7                 CASE WHEN deadline_date IS NULL THEN
8                         2
9                 ELSE
10                         1
11                 END AS sort_priority,
12                 CASE WHEN deadline_date IS NULL THEN
13                         effective_date
14                 ELSE
15                         deadline_date
16                 END AS sort_date,
17                 id,
18                 funding_source,
19                 amount,
20                 note
21         FROM
22                 acq.funding_source_credit;
23
24 COMMENT ON VIEW acq.ordered_funding_source_credit IS $$
25 /*
26  * Copyright (C) 2009  Georgia Public Library Service
27  * Scott McKellar <scott@gmail.com>
28  *
29  * The acq.ordered_funding_source_credit view is a prioritized
30  * ordering of funding source credits.  When ordered by the first
31  * three columns, this view defines the order in which the various
32  * credits are to be tapped for spending, subject to the allocations
33  * in the acq.fund_allocation table.
34  *
35  * The first column reflects the principle that we should spend
36  * money with deadlines before spending money without deadlines.
37  *
38  * The second column reflects the principle that we should spend the
39  * oldest money first.  For money with deadlines, that means that we
40  * spend first from the credit with the earliest deadline.  For
41  * money without deadlines, we spend first from the credit with the
42  * earliest effective date.  
43  *
44  * The third column is a tie breaker to ensure a consistent
45  * ordering.
46  *
47  * ****
48  *
49  * This program is free software; you can redistribute it and/or
50  * modify it under the terms of the GNU General Public License
51  * as published by the Free Software Foundation; either version 2
52  * of the License, or (at your option) any later version.
53  *
54  * This program is distributed in the hope that it will be useful,
55  * but WITHOUT ANY WARRANTY; without even the implied warranty of
56  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57  * GNU General Public License for more details.
58  */
59 $$;
60
61 COMMIT;