#!perl
-use Test::More tests => 127;
+use Test::More tests => 134;
diag("Test features of Conditional Negative Balances code.");
return $resp;
}
+sub adjust_bills_to_zero {
+ my $billing_ids = shift; #array ref
+ my $resp = $apputils->simplereq(
+ 'open-ils.circ',
+ 'open-ils.circ.money.billable_xact.adjust_to_zero',
+ $script->authtoken,
+ @$billing_ids
+ );
+
+ return $resp;
+}
+
#----------------------------------------------------------------
# The tests... assumes stock sample data, full-auto install by
# eg_wheezy_installer.sh, etc.
);
+## API tests (pre-configured circs)
+my $circ_ses = $script->session('open-ils.circ');
+
+$xact_id = 17;
+
+$summary = fetch_billable_xact_summary($xact_id);
+ok( $summary, 'API CASE 1: Zero out negative balance');
+is(
+ $summary->balance_owed,
+ '-10.00',
+ 'Starting balance owed is -10.00'
+);
+
+adjust_bills_to_zero([$xact_id]);
+$summary = fetch_billable_xact_summary($xact_id);
+is(
+ $summary->balance_owed,
+ '0.00',
+ 'Ending balance owed is 0.00'
+);
+
+adjust_bills_to_zero([$xact_id]);
+$summary = fetch_billable_xact_summary($xact_id);
+is(
+ $summary->balance_owed,
+ '0.00',
+ 'Ending balance owed is still 0.00'
+);
+
+$xact_id = 18;
+
+$summary = fetch_billable_xact_summary($xact_id);
+ok( $summary, 'API CASE 2: Zero out positive, partially-adjusted, partially-paid balance');
+is(
+ $summary->balance_owed,
+ '0.20',
+ 'Starting balance owed is 0.20'
+);
+
+adjust_bills_to_zero([$xact_id]);
+$summary = fetch_billable_xact_summary($xact_id);
+is(
+ $summary->balance_owed,
+ '0.00',
+ 'Ending balance owed is 0.00'
+);
+
+
$script->logout();
checkin_lib = NULL,
checkin_time = NULL,
checkin_scan_time = NULL
-WHERE id IN (1,2,3,4,5,6,12,13,15);
-UPDATE asset.copy SET status = 3 WHERE id IN (2,3,4,5,6,7,13,14,16);
+WHERE id IN (1,2,3,4,5,6,12,13,15,17);
+UPDATE asset.copy SET status = 3 WHERE id IN (2,3,4,5,6,7,13,14,16,18);
-- relative LOST circ
UPDATE action.circulation SET
UPDATE asset.copy SET status = 1 WHERE id IN (8, 15, 17);
-- Setup a non-lost, maxfines circ
+-- Setup a non-lost, checked-in, overdue, partially-paid circ
UPDATE action.circulation SET
xact_start = '2014-05-14 08:39:13.070326-04',
due_date = '2014-05-21 23:59:59-04',
checkin_lib = NULL,
checkin_time = NULL,
checkin_scan_time = NULL
-WHERE id = 11;
+WHERE id IN (11,18);
UPDATE asset.copy SET status = 1 WHERE id = 12;
+UPDATE action.circulation SET
+ max_fine = '5.00'
+WHERE id = 18;
+UPDATE asset.copy SET status = 0 WHERE id = 19;
-- Create LOST and overdue fines
(DEFAULT, 16, '2014-05-26 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
(DEFAULT, 16, '2014-05-27 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
(DEFAULT, 16, '2014-05-28 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
- -- XACT 10 must be last, because we use CURRVAL() to put their IDs in the account adjustments
+ (DEFAULT, 17, '2014-05-28 08:39:13.070326-04', true, 1, '2014-05-28 09:39:13.070326-04', 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'),
+ (DEFAULT, 18, '2014-05-22 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
+ (DEFAULT, 18, '2014-05-23 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
+ (DEFAULT, 18, '2014-05-24 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
+ -- XACTs 10 and 18 must be last, because we use CURRVAL() to put their IDs in the account adjustments
+ (DEFAULT, 18, '2014-05-25 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
+ (DEFAULT, 18, '2014-05-26 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
(DEFAULT, 10, (DATE(NOW() - '9 days'::interval) || ' 23:59:59')::TIMESTAMP, false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
(DEFAULT, 10, (DATE(NOW() - '8 days'::interval) || ' 23:59:59')::TIMESTAMP, false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
(DEFAULT, 10, (DATE(NOW() - '7 days'::interval) || ' 23:59:59')::TIMESTAMP, false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'),
INSERT INTO money.account_adjustment (id, xact, payment_ts, voided, amount, note, amount_collected, accepting_usr, billing) VALUES
+ (DEFAULT, 18, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 9),
+ (DEFAULT, 18, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 8),
(DEFAULT, 10, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 7),
(DEFAULT, 10, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 6),
(DEFAULT, 10, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 5),
INSERT INTO money.cash_payment (id, xact, payment_ts, voided, amount, note, amount_collected, accepting_usr, cash_drawer) VALUES
(DEFAULT, 8, NOW() - '30 minutes'::interval, false, 50.00, 'LOST payment', 50.00, 1, 51),
(DEFAULT, 9, NOW() - '2 hours'::interval, false, 50.00, 'LOST payment', 50.00, 1, 51),
- (DEFAULT, 10, NOW() - '2 days'::interval, false, 10.00, 'Partial LOST payment', 10.00, 1, 51);
+ (DEFAULT, 10, NOW() - '2 days'::interval, false, 10.00, 'Partial LOST payment', 10.00, 1, 51),
+ (DEFAULT, 17, NOW() - '2 days'::interval, false, 10.00, 'Partial LOST payment', 10.00, 1, 51),
+ (DEFAULT, 18, NOW() - '2 days'::interval, false, 0.10, 'Partial overdue payment', 0.20, 1, 51);
-- if rerunning, make sure our mangled bills have the right total in the summary
UPDATE money.materialized_billable_xact_summary SET balance_owed = 50.00
WHERE id = 10;
UPDATE money.materialized_billable_xact_summary SET balance_owed = 0.70
WHERE id = 11;
+UPDATE money.materialized_billable_xact_summary SET balance_owed = -10.00
+ WHERE id = 17;
+UPDATE money.materialized_billable_xact_summary SET balance_owed = 0.20
+ WHERE id = 18;