Finishing off rollover-without-money feature
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 27 Jul 2012 17:32:12 +0000 (13:32 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 31 Jul 2012 13:53:28 +0000 (09:53 -0400)
- Minor correction to make stock schema match upgrade script match.
- OU setting determining whether to offer rollover-without-money in UI
   and allow it in DB.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>

Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq-function-dedup.sql
Open-ILS/src/templates/acq/fund/list.tt2
Open-ILS/web/js/ui/default/acq/financial/list_funds.js

index f0a1bf3..c84279b 100644 (file)
@@ -1974,7 +1974,7 @@ BEGIN
                year = old_year
                AND propagate
                AND ( ( include_desc AND org IN ( SELECT id FROM actor.org_unit_descendants( org_unit_id ) ) )
-                OR (NOT include_desc AND oldf.org = org_unit_id ) )
+                OR (NOT include_desc AND org = org_unit_id ) )
     
        LOOP
                BEGIN
@@ -2028,7 +2028,8 @@ DECLARE
 new_fund    INT;
 new_year    INT := old_year + 1;
 org_found   BOOL;
-xfer_amount NUMERIC;
+perm_ous    BOOL;
+xfer_amount NUMERIC := 0;
 roll_fund   RECORD;
 deb         RECORD;
 detail      RECORD;
@@ -2060,6 +2061,14 @@ BEGIN
                --
                IF org_found IS NULL THEN
                        RAISE EXCEPTION 'Org unit id % is invalid', org_unit_id;
+               ELSIF encumb_only THEN
+                       SELECT INTO perm_ous value::BOOL FROM
+                       actor.org_unit_ancestor_setting(
+                               'acq.fund.allow_rollover_without_money', org_unit_id
+                       );
+                       IF NOT FOUND OR NOT perm_ous THEN
+                               RAISE EXCEPTION 'Encumbrance-only rollover not permitted at org %', org_unit_id;
+                       END IF;
                END IF;
        END IF;
        --
index ed53b9b..d4b8826 100644 (file)
@@ -11748,7 +11748,6 @@ INSERT INTO config.org_unit_setting_type (
     'interval'
 );
 
-
 -- kid's opac main search filter
 
 INSERT INTO actor.search_filter_group (owner, code, label) 
@@ -11779,3 +11778,23 @@ INSERT INTO actor.search_filter_group_entry (grp, query, pos)
         (SELECT id FROM actor.search_query WHERE label = 'General/Adult Materials'),
         2
     );
+INSERT into config.org_unit_setting_type
+    (name, grp, label, description, datatype)
+    VALUES (
+        'acq.fund.allow_rollover_without_money',
+        'acq',
+        oils_i18n_gettext(
+            'acq.fund.allow_rollover_without_money',
+            'Allow funds to be rolled over without bringing the money along',
+            'coust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'acq.fund.allow_rollover_without_money',
+            'Allow funds to be rolled over without bringing the money along.  This makes money left in the old fund disappear, modeling its return to some outside entity.',
+            'coust',
+            'description'
+        ),
+        'bool'
+    );
+
index a7167ce..149c1ce 100644 (file)
@@ -1,3 +1,6 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('XXXX', :eg_version); -- miker
 
 DROP FUNCTION acq.propagate_funds_by_org_tree (INT, INT, INT);
 DROP FUNCTION acq.propagate_funds_by_org_unit (INT, INT, INT);
@@ -47,7 +50,7 @@ BEGIN
                year = old_year
                AND propagate
                AND ( ( include_desc AND org IN ( SELECT id FROM actor.org_unit_descendants( org_unit_id ) ) )
-                OR (NOT include_desc AND oldf.org = org_unit_id ) )
+                OR (NOT include_desc AND org = org_unit_id ) )
     
        LOOP
                BEGIN
@@ -92,6 +95,7 @@ $$ LANGUAGE SQL;
 DROP FUNCTION acq.rollover_funds_by_org_tree (INT, INT, INT);
 DROP FUNCTION acq.rollover_funds_by_org_unit (INT, INT, INT);
 
+
 CREATE OR REPLACE FUNCTION acq.rollover_funds_by_org_tree(
        old_year INTEGER,
        user_id INTEGER,
@@ -104,6 +108,7 @@ DECLARE
 new_fund    INT;
 new_year    INT := old_year + 1;
 org_found   BOOL;
+perm_ous    BOOL;
 xfer_amount NUMERIC := 0;
 roll_fund   RECORD;
 deb         RECORD;
@@ -136,6 +141,14 @@ BEGIN
                --
                IF org_found IS NULL THEN
                        RAISE EXCEPTION 'Org unit id % is invalid', org_unit_id;
+               ELSIF encumb_only THEN
+                       SELECT INTO perm_ous value::BOOL FROM
+                       actor.org_unit_ancestor_setting(
+                               'acq.fund.allow_rollover_without_money', org_unit_id
+                       );
+                       IF NOT FOUND OR NOT perm_ous THEN
+                               RAISE EXCEPTION 'Encumbrance-only rollover not permitted at org %', org_unit_id;
+                       END IF;
                END IF;
        END IF;
        --
@@ -276,4 +289,24 @@ CREATE OR REPLACE FUNCTION acq.rollover_funds_by_org_unit( old_year INTEGER, use
     SELECT acq.rollover_funds_by_org_tree( $1, $2, $3, $4, FALSE );
 $$ LANGUAGE SQL;
 
+INSERT into config.org_unit_setting_type
+    (name, grp, label, description, datatype)
+    VALUES (
+        'acq.fund.allow_rollover_without_money',
+        'acq',
+        oils_i18n_gettext(
+            'acq.fund.allow_rollover_without_money',
+            'Allow funds to be rolled over without bringing the money along',
+            'coust',
+            'label'
+        ),
+        oils_i18n_gettext(
+            'acq.fund.allow_rollover_without_money',
+            'Allow funds to be rolled over without bringing the money along.  This makes money left in the old fund disappear, modeling its return to some outside entity.',
+            'coust',
+            'description'
+        ),
+        'bool'
+    );
 
+COMMIT;
index 0173e73..6fa4b0d 100644 (file)
                                 </div>
                             </td>
                         </tr>
-                        <tr>
+                        <tr class="encumb_only hidden">
                             <td><label for="encumb_only">Limit Fiscal Year Close-out Operation to Encumbrances: </label></td>
                             <td>
                                 <input dojoType="dijit.form.CheckBox" name="encumb_only"> </input>
                             </td>
                         </tr>
-                        <tr>
+                        <tr class="encumb_only hidden">
                             <td colspan='2'>
                                 <div style='width:400px;'>
                                 This modifies the above described Close-out Operation, causing funds to be
index 4586333..abad41d 100644 (file)
@@ -37,6 +37,21 @@ var cachedFunds = [];
 function initPage() {
     contextOrg = openils.User.user.ws_ou();
 
+    /* Reveal controls for rollover without money if org units say ok.
+     * Actual ability to do the operation is controlled in the database, of
+     * course. */
+    var ouSettings = fieldmapper.aou.fetchOrgSettingBatch(
+        openils.User.user.ws_ou(), ["acq.fund.allow_rollover_without_money"]
+    );
+    if (
+        ouSettings["acq.fund.allow_rollover_without_money"] &&
+        ouSettings["acq.fund.allow_rollover_without_money"].value
+    ) {
+        dojo.query(".encumb_only").forEach(
+            function(o) { openils.Util.show(o, "table-row"); }
+        );
+    }
+
     var connect = function() {
         dojo.connect(contextOrgSelector, 'onChange',
             function() {