]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/live_t/lp1198465_run_this_before_livetests.sql
LP 1198465: Make conditional negative balances test sql re-runnable
[working/Evergreen.git] / Open-ILS / src / sql / Pg / live_t / lp1198465_run_this_before_livetests.sql
1 BEGIN;
2
3 -- DATA FOR LIVE TESTING LP#1198465:
4 --   Support for Conditional Negative Balances
5 --
6 -- Assume stock data has been loaded.
7 --
8 -- Dates are relative when necessary; otherwise they may be hardcoded.
9 -- NOTE: Org unit settings will be handled in the perl code
10
11
12 -- user id: 4, name: Gregory Jones
13
14 -- clear bills and payments for our test circs
15 DELETE FROM money.billing WHERE xact <= 9;
16 DELETE FROM money.payment WHERE xact <= 9;
17
18 -- clear any non-stock settings
19 -- XXX This will need adjusting if new stock settings are added, so
20 -- TODO: Pad out org_unit_settings with a SETVAL like we do for other
21 -- settings
22 DELETE FROM actor.org_unit_setting WHERE id >= 14;
23
24 -- clear out the test workstation (just in case)
25 DELETE FROM actor.workstation WHERE name = 'BR1-test-09-lp1198465_neg_balances.t';
26
27 -- Setup all LOST circs
28 UPDATE action.circulation SET
29     xact_start = '2014-05-14 08:39:13.070326-04',
30         due_date = '2014-05-21 23:59:59-04',
31         stop_fines_time = '2014-05-28 08:39:13.070326-04',
32         create_time = '2014-05-14 08:39:13.070326-04',
33         max_fine = '3.00',
34         stop_fines = 'LOST',
35         checkin_staff = NULL,
36         checkin_lib = NULL,
37         checkin_time = NULL,
38         checkin_scan_time = NULL
39 WHERE id >= 1 AND id <= 6;
40 UPDATE asset.copy SET status = 3 WHERE id >= 2 AND id <= 7;
41
42 -- Setup non-lost circ
43 UPDATE action.circulation SET
44         checkin_staff = NULL,
45         checkin_lib = NULL,
46         checkin_time = NULL,
47         checkin_scan_time = NULL,
48         stop_fines = NULL,
49         stop_fines_time = NULL
50 WHERE id = 7;
51 UPDATE asset.copy SET status = 1 WHERE id = 8;
52
53 -- Setup other LOST and overdue fines
54 INSERT INTO money.billing (id, xact, billing_ts, voided, voider, void_time, amount, billing_type, btype, note) VALUES
55     (DEFAULT, 1, '2014-05-28 08:39:13.070326-04', false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
56     (DEFAULT, 2, '2014-05-28 08:39:13.070326-04', false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
57     (DEFAULT, 3, '2014-05-28 08:39:13.070326-04', false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
58     (DEFAULT, 4, '2014-05-28 08:39:13.070326-04', false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
59     (DEFAULT, 5, '2014-05-28 08:39:13.070326-04', false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
60     (DEFAULT, 6, '2014-05-22 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
61     (DEFAULT, 6, '2014-05-23 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
62     (DEFAULT, 6, '2014-05-24 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
63     (DEFAULT, 6, '2014-05-25 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
64     (DEFAULT, 6, '2014-05-26 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
65     (DEFAULT, 6, '2014-05-27 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
66     (DEFAULT, 6, '2014-05-28 23:59:59-04', true, 1, '2014-05-28 08:39:13.070326-04', 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
67     (DEFAULT, 6, '2014-05-28 08:39:13.070326-04', false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
68     (DEFAULT, 7, '2014-05-22 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
69     (DEFAULT, 7, '2014-05-23 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
70     (DEFAULT, 7, '2014-05-24 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
71     (DEFAULT, 7, '2014-05-25 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
72     (DEFAULT, 7, '2014-05-26 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
73     (DEFAULT, 7, '2014-05-27 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
74     (DEFAULT, 7, '2014-05-28 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine');
75
76 -- Setup two recently LOST items for Case 10: Interval Testing
77 -- - Item 1: Lost, paid more than 1 hour later, returned less than 1 hour after payment (via perl test)
78 -- - Item 2: Lost, paid more than 1 hour later, returned more than 1 hour after payment (via perl test)
79 UPDATE action.circulation SET
80         create_time = NOW() - '1 week'::interval,
81     xact_start = NOW() - '1 week'::interval,
82         due_date = NOW() + '1 day'::interval,
83         stop_fines_time = NOW() - '3 hours'::interval,
84         max_fine = '3.00',
85         stop_fines = 'LOST',
86         checkin_staff = NULL,
87         checkin_lib = NULL,
88         checkin_time = NULL,
89         checkin_scan_time = NULL
90 WHERE id IN (8, 9);
91 UPDATE asset.copy SET status = 3 WHERE id IN (9, 10);
92
93 INSERT INTO money.billing (id, xact, billing_ts, voided, voider, void_time, amount, billing_type, btype, note) VALUES
94     (DEFAULT, 8, NOW() - '2 hours'::interval, false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
95     (DEFAULT, 9, NOW() - '4 hours'::interval, false, NULL, NULL, 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED');
96
97 INSERT INTO money.payment (id, xact, payment_ts, voided, amount, note) VALUES
98         (DEFAULT, 8, NOW() - '30 minutes'::interval, false, 50.00, 'LOST payment'),
99         (DEFAULT, 9, NOW() - '2 hours'::interval, false, 50.00, 'LOST payment');
100
101 -- if rerunning, make sure our mangled bills have the right total in the summary
102 UPDATE money.materialized_billable_xact_summary SET balance_owed = 50.00
103         WHERE id >=1 AND id <= 6;
104 UPDATE money.materialized_billable_xact_summary SET balance_owed = 0.70
105         WHERE id = 7;
106 UPDATE money.materialized_billable_xact_summary SET balance_owed = 0.00
107         WHERE id IN (8, 9);
108
109 COMMIT;