cross-porting cond. neg. balance upgrade
authorBill Erickson <berickxx@gmail.com>
Thu, 6 Aug 2015 15:55:03 +0000 (11:55 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 28 Aug 2015 21:38:08 +0000 (17:38 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/schema/deploy/schema.conditional_negative_balance.sql [new file with mode: 0644]
Open-ILS/src/sql/schema/revert/schema.conditional_negative_balance.sql [new file with mode: 0644]
Open-ILS/src/sql/schema/sqitch.plan
Open-ILS/src/sql/schema/verify/schema.conditional_negative_balance.sql [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/schema/deploy/schema.conditional_negative_balance.sql b/Open-ILS/src/sql/schema/deploy/schema.conditional_negative_balance.sql
new file mode 100644 (file)
index 0000000..c393678
--- /dev/null
@@ -0,0 +1,88 @@
+BEGIN;
+
+CREATE TABLE money.account_adjustment (
+    billing BIGINT REFERENCES money.billing (id) ON DELETE SET NULL
+) INHERITS (money.bnm_payment);
+ALTER TABLE money.account_adjustment ADD PRIMARY KEY (id);
+CREATE INDEX money_adjustment_id_idx ON money.account_adjustment (id);
+CREATE INDEX money_account_adjustment_xact_idx ON money.account_adjustment (xact);
+CREATE INDEX money_account_adjustment_bill_idx ON money.account_adjustment (billing);
+CREATE INDEX money_account_adjustment_payment_ts_idx ON money.account_adjustment (payment_ts);
+CREATE INDEX money_account_adjustment_accepting_usr_idx ON money.account_adjustment (accepting_usr);
+
+CREATE TRIGGER mat_summary_add_tgr AFTER INSERT ON money.account_adjustment FOR EACH ROW EXECUTE PROCEDURE money.materialized_summary_payment_add ('account_adjustment');
+CREATE TRIGGER mat_summary_upd_tgr AFTER UPDATE ON money.account_adjustment FOR EACH ROW EXECUTE PROCEDURE money.materialized_summary_payment_update ('account_adjustment');
+CREATE TRIGGER mat_summary_del_tgr BEFORE DELETE ON money.account_adjustment FOR EACH ROW EXECUTE PROCEDURE money.materialized_summary_payment_del ('account_adjustment');
+
+-- Insert new org. unit settings.
+INSERT INTO config.org_unit_setting_type 
+       (name, grp, datatype, label, description)
+VALUES
+       ('bill.prohibit_negative_balance_default',
+        'finance', 'bool',
+        oils_i18n_gettext(
+            'bill.prohibit_negative_balance_default',
+            'Prohibit negative balance on bills (DEFAULT)',
+            'coust', 'label'),
+        oils_i18n_gettext(
+            'bill.prohibit_negative_balance_default',
+            'Default setting to prevent negative balances (refunds) on circulation related bills',
+            'coust', 'description')
+       ),
+       ('bill.prohibit_negative_balance_on_overdues',
+        'finance', 'bool',
+        oils_i18n_gettext(
+            'bill.prohibit_negative_balance_on_overdues',
+            'Prohibit negative balance on bills for overdue materials',
+            'coust', 'label'),
+        oils_i18n_gettext(
+            'bill.prohibit_negative_balance_on_overdues',
+            'Prevent negative balances (refunds) on bills for overdue materials',
+            'coust', 'description')
+       ),
+       ('bill.prohibit_negative_balance_on_lost',
+        'finance', 'bool',
+        oils_i18n_gettext(
+            'bill.prohibit_negative_balance_on_lost',
+            'Prohibit negative balance on bills for lost materials',
+            'coust', 'label'),
+        oils_i18n_gettext(
+            'bill.prohibit_negative_balance_on_lost',
+            'Prevent negative balances (refunds) on bills for lost/long-overdue materials',
+            'coust', 'description')
+       ),
+       ('bill.negative_balance_interval_default',
+        'finance', 'interval',
+        oils_i18n_gettext(
+            'bill.negative_balance_interval_default',
+            'Negative Balance Interval (DEFAULT)',
+            'coust', 'label'),
+        oils_i18n_gettext(
+            'bill.negative_balance_interval_default',
+            'Amount of time after which no negative balances (refunds) are allowed on circulation bills',
+            'coust', 'description')
+       ),
+       ('bill.negative_balance_interval_on_overdues',
+        'finance', 'interval',
+        oils_i18n_gettext(
+            'bill.negative_balance_interval_on_overdues',
+            'Negative Balance Interval for Overdues',
+            'coust', 'label'),
+        oils_i18n_gettext(
+            'bill.negative_balance_interval_on_overdues',
+            'Amount of time after which no negative balances (refunds) are allowed on bills for overdue materials',
+            'coust', 'description')
+       ),
+       ('bill.negative_balance_interval_on_lost',
+        'finance', 'interval',
+        oils_i18n_gettext(
+            'bill.negative_balance_interval_on_lost',
+            'Negative Balance Interval for Lost',
+            'coust', 'label'),
+        oils_i18n_gettext(
+            'bill.negative_balance_interval_on_lost',
+            'Amount of time after which no negative balances (refunds) are allowed on bills for lost/long overdue materials',
+            'coust', 'description')
+       );
+
+COMMIT;
diff --git a/Open-ILS/src/sql/schema/revert/schema.conditional_negative_balance.sql b/Open-ILS/src/sql/schema/revert/schema.conditional_negative_balance.sql
new file mode 100644 (file)
index 0000000..fb13395
--- /dev/null
@@ -0,0 +1,25 @@
+BEGIN;
+
+DELETE FROM config.org_unit_setting_type WHERE name IN (
+    'bill.prohibit_negative_balance_default',
+    'bill.prohibit_negative_balance_on_overdues',
+    'bill.prohibit_negative_balance_on_lost',
+    'bill.negative_balance_interval_default',
+    'bill.negative_balance_interval_on_overdues',
+    'bill.negative_balance_interval_on_lost'
+);
+
+DROP TRIGGER mat_summary_del_tgr ON money.account_adjustment;
+DROP TRIGGER mat_summary_upd_tgr ON money.account_adjustment;
+DROP TRIGGER mat_summary_add_tgr ON money.account_adjustment;
+
+DROP INDEX 
+    money.money_account_adjustment_accepting_usr_idx,
+    money.money_account_adjustment_payment_ts_idx,
+    money.money_account_adjustment_bill_idx,
+    money.money_account_adjustment_xact_idx,
+    money.money_adjustment_id_idx;
+
+DROP TABLE money.account_adjustment;
+
+COMMIT;
index cede73e..751cfcf 100644 (file)
@@ -48,3 +48,4 @@ schema.unapi [data.marc21expand880] 2015-07-16T20:40:12Z Bill Erickson <berickxx
 schema.reporter [data.marc21expand880] 2015-07-16T20:40:14Z Bill Erickson <berickxx@gmail.com> # Creating schema.reporter
 schema.extend-reporter [schema.reporter] 2015-07-16T20:40:14Z Bill Erickson <berickxx@gmail.com> # Creating schema.extend-reporter
 functions.global [schema.extend-reporter] 2015-07-16T20:40:14Z Bill Erickson <berickxx@gmail.com> # Creating functions.global
+schema.conditional_negative_balance [functions.global] 2015-08-06T15:28:47Z Bill Erickson <berickxx@gmail.com> # Conditional negative balance schema/data upgrade
diff --git a/Open-ILS/src/sql/schema/verify/schema.conditional_negative_balance.sql b/Open-ILS/src/sql/schema/verify/schema.conditional_negative_balance.sql
new file mode 100644 (file)
index 0000000..8f14e7c
--- /dev/null
@@ -0,0 +1,10 @@
+-- Verify evergreen:schema.conditional_negative_balance on pg
+
+BEGIN;
+
+-- explodes if the table failed to create.
+SELECT billing FROM money.account_adjustment WHERE FALSE;
+
+-- TODO: verify new org unit settings
+
+ROLLBACK;