3 use Test::More tests => 132;
5 diag("Test features of Conditional Negative Balances code.");
7 use constant WORKSTATION_NAME => 'BR1-test-09-lp1198465_neg_balances.t';
8 use constant WORKSTATION_LIB => 4;
10 use strict; use warnings;
13 use DateTime::Format::ISO8601;
14 use OpenSRF::Utils qw/cleanse_ISO8601/;
15 use OpenILS::Utils::TestUtils;
16 my $script = OpenILS::Utils::TestUtils->new();
19 our $apputils = "OpenILS::Application::AppUtils";
21 my ($patron_id, $patron_usrname, $xact_id, $item_id, $item_barcode);
22 my ($summary, $payment_blob, $pay_resp, $item_req, $checkin_resp);
24 my $storage_ses = $script->session('open-ils.storage');
28 my $patron_id = shift;
30 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', $patron_id);
31 if (my $user_resp = $user_req->recv) {
32 if (my $patron_obj = $user_resp->content) {
39 sub fetch_billable_xact_summary {
41 my $ses = $script->session('open-ils.cstore');
42 my $req = $ses->request(
43 'open-ils.cstore.direct.money.billable_transaction_summary.retrieve',
46 if (my $resp = $req->recv) {
47 return $resp->content;
54 my $payment_blob = shift;
55 my $resp = $apputils->simplereq(
57 'open-ils.circ.money.payment',
60 $user_obj->last_xact_id
63 #refetch user_obj to get latest last_xact_id
64 $user_obj = retrieve_patron($patron_id)
65 or die 'Could not refetch patron';
71 my $billing_ids = shift; #array ref
72 my $resp = $apputils->simplereq(
74 'open-ils.circ.money.billing.void',
82 #----------------------------------------------------------------
83 # The tests... assumes stock sample data, full-auto install by
84 # eg_wheezy_installer.sh, etc.
85 #----------------------------------------------------------------
87 # Connect to Evergreen
88 $script->authenticate({
90 password => 'demo123',
92 ok( $script->authtoken, 'Have an authtoken');
94 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
95 ok( ! ref $ws, 'Registered a new workstation');
98 $script->authenticate({
100 password => 'demo123',
102 workstation => WORKSTATION_NAME});
103 ok( $script->authtoken, 'Have an authtoken associated with the workstation');
106 ### TODO: verify that stock data is ready for testing
108 ### Setup Org Unit Settings that apply to all test cases
110 my $org_id = 1; #CONS
112 'circ.max_item_price' => 50,
113 'circ.min_item_price' => 50,
114 'circ.void_lost_on_checkin' => 1
117 $apputils->simplereq(
119 'open-ils.actor.org_unit.settings.update',
127 $patron_usrname = '99999355250';
130 if ($user_obj = retrieve_patron($patron_id)) {
133 'Fieldmapper::actor::user',
134 'open-ils.storage.direct.actor.user.retrieve returned aou object'
139 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
144 ##############################
145 # 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
146 ##############################
148 ### Setup use case variables
151 $item_barcode = 'CONC4000037';
153 $summary = fetch_billable_xact_summary($xact_id);
154 ok( $summary, 'CASE 1: Found the transaction summary');
156 $summary->balance_owed,
158 'Starting balance owed is 50.00 for lost item'
161 ### pay the whole bill
163 userid => $patron_id,
164 note => '09-lp1198465_neg_balances.t',
165 payment_type => 'cash_payment',
166 patron_credit => '0.00',
167 payments => [ [ $xact_id, '50.00' ] ]
169 $pay_resp = pay_bills($payment_blob);
172 scalar( @{ $pay_resp->{payments} } ),
174 'Payment response included one payment id'
177 $summary = fetch_billable_xact_summary($xact_id);
179 $summary->balance_owed,
181 'Remaining balance of 0.00 after payment'
184 ### check-in the lost copy
186 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
187 if (my $item_resp = $item_req->recv) {
188 if (my $item = $item_resp->content) {
191 'Fieldmapper::asset::copy',
192 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
197 'Item with id = ' . $item_id . ' has status of LOST'
202 $checkin_resp = $script->do_checkin_override({
203 barcode => $item_barcode});
205 $checkin_resp->{ilsevent},
207 'Checkin returned a SUCCESS event'
210 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
211 if (my $item_resp = $item_req->recv) {
212 if (my $item = $item_resp->content) {
214 $item->status == 7 || $item->status == 0,
215 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
220 ### verify ending state
222 $summary = fetch_billable_xact_summary($xact_id);
224 $summary->balance_owed,
226 'Patron has a negative balance (credit) of 50.00 due to overpayment'
230 ##############################
231 # 2. Negative Balance Settings Are Unset, No Payment Made
232 ##############################
234 ### Setup use case variables
237 $item_barcode = 'CONC4000038';
239 $summary = fetch_billable_xact_summary($xact_id);
240 ok( $summary, 'CASE 2: Found the transaction summary');
242 $summary->balance_owed,
244 'Starting balance owed is 50.00 for lost item'
247 ### check-in the lost copy
249 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
250 if (my $item_resp = $item_req->recv) {
251 if (my $item = $item_resp->content) {
255 'Item with id = ' . $item_id . ' has status of LOST'
260 $checkin_resp = $script->do_checkin_override({
261 barcode => $item_barcode});
263 $checkin_resp->{ilsevent},
265 'Checkin returned a SUCCESS event'
268 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
269 if (my $item_resp = $item_req->recv) {
270 if (my $item = $item_resp->content) {
272 $item->status == 7 || $item->status == 0,
273 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
278 ### verify ending state
280 $summary = fetch_billable_xact_summary($xact_id);
282 $summary->balance_owed,
284 'Patron has a balance of 0.00'
288 ##############################
289 # 13. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
290 # SETTINGS: Prohibit negative balances on bills for lost materials
291 ##############################
295 $patron_usrname = '99999335859';
298 if ($user_obj = retrieve_patron($patron_id)) {
301 'Fieldmapper::actor::user',
302 'open-ils.storage.direct.actor.user.retrieve returned aou object'
307 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
311 ### Setup use case variables
314 $item_barcode = 'CONC4000049';
316 # Setup Org Unit Settings
318 'bill.prohibit_negative_balance_on_lost' => 1
320 $apputils->simplereq(
322 'open-ils.actor.org_unit.settings.update',
328 $summary = fetch_billable_xact_summary($xact_id);
329 ok( $summary, 'CASE 13a: Found the transaction summary');
331 $summary->balance_owed,
333 'Starting balance owed is 50.00 for lost item'
336 ### pay the whole bill
338 userid => $patron_id,
339 note => '09-lp1198465_neg_balances.t',
340 payment_type => 'cash_payment',
341 patron_credit => '0.00',
342 payments => [ [ $xact_id, '50.00' ] ]
344 $pay_resp = pay_bills($payment_blob);
347 scalar( @{ $pay_resp->{payments} } ),
349 'Payment response included one payment id'
352 $summary = fetch_billable_xact_summary($xact_id);
354 $summary->balance_owed,
356 'Remaining balance of 0.00 after payment'
359 ### check-in the lost copy
361 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
362 if (my $item_resp = $item_req->recv) {
363 if (my $item = $item_resp->content) {
366 'Fieldmapper::asset::copy',
367 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
372 'Item with id = ' . $item_id . ' has status of LOST'
377 $checkin_resp = $script->do_checkin_override({
378 barcode => $item_barcode});
380 $checkin_resp->{ilsevent},
382 'Checkin returned a SUCCESS event'
385 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
386 if (my $item_resp = $item_req->recv) {
387 if (my $item = $item_resp->content) {
389 $item->status == 7 || $item->status == 0,
390 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
395 ### verify ending state
397 $summary = fetch_billable_xact_summary($xact_id);
399 $summary->balance_owed,
401 'Patron has a balance of 0.00 (negative balance prevented)'
405 ##############################
406 # 13. RERUN of Case 12. Test negative balance settings on fines
407 # SETTINGS: Prohibit negative balances on bills for lost materials
408 ##############################
410 ### Setup use case variables
413 $item_barcode = 'CONC4000050';
415 # Setup Org Unit Settings
417 # 'bill.prohibit_negative_balance_on_lost' => 1
419 $summary = fetch_billable_xact_summary($xact_id);
420 ok( $summary, 'CASE 13b: Found the transaction summary');
422 $summary->balance_owed,
424 'Starting balance owed is 0.70 for overdue fines'
427 ### partially pay the bill
429 userid => $patron_id,
430 note => '09-lp1198465_neg_balances.t',
431 payment_type => 'cash_payment',
432 patron_credit => '0.00',
433 payments => [ [ $xact_id, '0.20' ] ]
435 $pay_resp = pay_bills($payment_blob);
438 scalar( @{ $pay_resp->{payments} } ),
440 'Payment response included one payment id'
443 $summary = fetch_billable_xact_summary($xact_id);
445 $summary->balance_owed,
447 'Remaining balance of 0.50 after payment'
450 ### Check in using Amnesty Mode
451 $checkin_resp = $script->do_checkin_override({
452 barcode => $item_barcode,
456 $checkin_resp->{ilsevent},
458 'Checkin returned a SUCCESS event'
461 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
462 if (my $item_resp = $item_req->recv) {
463 if (my $item = $item_resp->content) {
465 $item->status == 7 || $item->status == 0,
466 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
471 ### verify ending state
472 $summary = fetch_billable_xact_summary($xact_id);
474 $summary->balance_owed,
476 'Patron has a negative balance of -0.20 (refund of overdue fine payment)'
480 ##############################
481 # 14. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
482 # SETTINGS: Prohibit negative balances on bills for overdue materials
483 ##############################
485 ### Setup use case variables
488 $item_barcode = 'CONC4000051';
490 # Setup Org Unit Settings
492 'bill.prohibit_negative_balance_on_lost' => 0, #unset from previous test
493 'bill.prohibit_negative_balance_on_overdues' => 1
495 $apputils->simplereq(
497 'open-ils.actor.org_unit.settings.update',
503 $summary = fetch_billable_xact_summary($xact_id);
504 ok( $summary, 'CASE 14a: Found the transaction summary');
506 $summary->balance_owed,
508 'Starting balance owed is 50.00 for lost item'
511 ### pay the whole bill
513 userid => $patron_id,
514 note => '09-lp1198465_neg_balances.t',
515 payment_type => 'cash_payment',
516 patron_credit => '0.00',
517 payments => [ [ $xact_id, '50.00' ] ]
519 $pay_resp = pay_bills($payment_blob);
522 scalar( @{ $pay_resp->{payments} } ),
524 'Payment response included one payment id'
527 $summary = fetch_billable_xact_summary($xact_id);
529 $summary->balance_owed,
531 'Remaining balance of 0.00 after payment'
535 $summary->xact_finish ne '',
536 'xact_finish is set due to 0.00 balance'
539 ### check-in the lost copy
541 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
542 if (my $item_resp = $item_req->recv) {
543 if (my $item = $item_resp->content) {
546 'Fieldmapper::asset::copy',
547 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
552 'Item with id = ' . $item_id . ' has status of LOST'
557 $checkin_resp = $script->do_checkin_override({
558 barcode => $item_barcode});
560 $checkin_resp->{ilsevent},
562 'Checkin returned a SUCCESS event'
565 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
566 if (my $item_resp = $item_req->recv) {
567 if (my $item = $item_resp->content) {
569 $item->status == 7 || $item->status == 0,
570 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
575 ### verify ending state
577 $summary = fetch_billable_xact_summary($xact_id);
579 $summary->balance_owed,
581 'Patron has a negative balance (credit) of 50.00 due to overpayment'
585 !defined($summary->xact_finish),
586 'xact_finish is not set due to non-zero balance'
590 ##############################
591 # 14. RERUN of Case 12. Test negative balance settings on fines
592 # SETTINGS: Prohibit negative balances on bills for overdue materials
593 ##############################
595 ### Setup use case variables
598 $item_barcode = 'CONC4000052';
600 # Setup Org Unit Settings
602 # 'bill.prohibit_negative_balance_on_overdues' => 1
604 $summary = fetch_billable_xact_summary($xact_id);
605 ok( $summary, 'CASE 14b: Found the transaction summary');
607 $summary->balance_owed,
609 'Starting balance owed is 0.70 for overdue fines'
612 ### partially pay the bill
614 userid => $patron_id,
615 note => '09-lp1198465_neg_balances.t',
616 payment_type => 'cash_payment',
617 patron_credit => '0.00',
618 payments => [ [ $xact_id, '0.20' ] ]
620 $pay_resp = pay_bills($payment_blob);
623 scalar( @{ $pay_resp->{payments} } ),
625 'Payment response included one payment id'
628 $summary = fetch_billable_xact_summary($xact_id);
630 $summary->balance_owed,
632 'Remaining balance of 0.50 after payment'
635 ### Check in using Amnesty Mode
636 $checkin_resp = $script->do_checkin_override({
637 barcode => $item_barcode,
641 $checkin_resp->{ilsevent},
643 'Checkin returned a SUCCESS event'
646 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
647 if (my $item_resp = $item_req->recv) {
648 if (my $item = $item_resp->content) {
650 $item->status == 7 || $item->status == 0,
651 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
656 ### verify ending state
657 $summary = fetch_billable_xact_summary($xact_id);
659 $summary->balance_owed,
661 'Patron has a balance of 0.00 (negative balance prevented)'
665 ##############################
666 # 3. Basic No Negative Balance Test
667 ##############################
669 # Re-setup first patron
671 $patron_usrname = '99999355250';
674 if ($user_obj = retrieve_patron($patron_id)) {
677 'Fieldmapper::actor::user',
678 'open-ils.storage.direct.actor.user.retrieve returned aou object'
683 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
688 ### Setup use case variables
691 $item_barcode = 'CONC4000039';
693 # Setup Org Unit Settings
695 'bill.prohibit_negative_balance_on_overdues' => 0, #unset from previous test
696 'bill.prohibit_negative_balance_default' => 1
698 $apputils->simplereq(
700 'open-ils.actor.org_unit.settings.update',
706 $summary = fetch_billable_xact_summary($xact_id);
707 ok( $summary, 'CASE 3: Found the transaction summary');
709 $summary->balance_owed,
711 'Starting balance owed is 50.00 for lost item'
714 ### check-in the lost copy
716 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
717 if (my $item_resp = $item_req->recv) {
718 if (my $item = $item_resp->content) {
722 'Item with id = ' . $item_id . ' has status of LOST'
727 $checkin_resp = $script->do_checkin_override({
728 barcode => $item_barcode});
730 $checkin_resp->{ilsevent},
732 'Checkin returned a SUCCESS event'
735 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
736 if (my $item_resp = $item_req->recv) {
737 if (my $item = $item_resp->content) {
739 $item->status == 7 || $item->status == 0,
740 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
745 ### verify ending state
747 $summary = fetch_billable_xact_summary($xact_id);
749 $summary->balance_owed,
751 'Patron has a balance of 0.00 (negative balance prevented)'
754 ##############################
755 # 4. Prohibit Negative Balances with Partial Payment
756 ##############################
758 ### Setup use case variables
761 $item_barcode = 'CONC4000040';
763 # Setup Org Unit Settings
765 # 'bill.prohibit_negative_balance_default' => 1
767 $summary = fetch_billable_xact_summary($xact_id);
768 ok( $summary, 'CASE 4: Found the transaction summary');
770 $summary->balance_owed,
772 'Starting balance owed is 50.00 for lost item'
775 ### confirm the copy is lost
776 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
777 if (my $item_resp = $item_req->recv) {
778 if (my $item = $item_resp->content) {
782 'Item with id = ' . $item_id . ' has status of LOST'
787 ### partially pay the bill
789 userid => $patron_id,
790 note => '09-lp1198465_neg_balances.t',
791 payment_type => 'cash_payment',
792 patron_credit => '0.00',
793 payments => [ [ $xact_id, '10.00' ] ]
795 $pay_resp = pay_bills($payment_blob);
798 scalar( @{ $pay_resp->{payments} } ),
800 'Payment response included one payment id'
803 $summary = fetch_billable_xact_summary($xact_id);
805 $summary->balance_owed,
807 'Remaining balance of 40.00 after payment'
810 ### check-in the lost copy
811 $checkin_resp = $script->do_checkin_override({
812 barcode => $item_barcode});
814 $checkin_resp->{ilsevent},
816 'Checkin returned a SUCCESS event'
819 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
820 if (my $item_resp = $item_req->recv) {
821 if (my $item = $item_resp->content) {
823 $item->status == 7 || $item->status == 0,
824 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
829 ### verify ending state
831 $summary = fetch_billable_xact_summary($xact_id);
833 $summary->balance_owed,
835 'Patron has a balance of 0.00 (negative balance prevented)'
839 ##############################
840 # Restore then generate new overdues on xact with adjustments
841 ##############################
843 ### Setup use case variables
846 $item_barcode = 'CONC4000041';
848 # Setup Org Unit Settings
850 # 'bill.prohibit_negative_balance_default' => 1
852 'circ.restore_overdue_on_lost_return' => 1,
853 'circ.lost.generate_overdue_on_checkin' => 1
856 $apputils->simplereq(
858 'open-ils.actor.org_unit.settings.update',
864 $summary = fetch_billable_xact_summary($xact_id);
866 $summary->balance_owed,
868 'Starting balance owed is 50.00 for lost item'
871 $checkin_resp = $script->do_checkin_override({
872 barcode => $item_barcode
875 $checkin_resp->{ilsevent},
877 'Checkin returned a SUCCESS event'
880 ### verify ending state
881 $summary = fetch_billable_xact_summary($xact_id);
883 $summary->balance_owed,
885 'Patron has a balance of 3.00 (newly generated fines, up to maxfines)'
889 ##############################
890 # 12. Test negative balance settings on fines
891 ##############################
895 $patron_usrname = '99999387993';
898 if ($user_obj = retrieve_patron($patron_id)) {
901 'Fieldmapper::actor::user',
902 'open-ils.storage.direct.actor.user.retrieve returned aou object'
907 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
911 ### Setup use case variables
914 $item_barcode = 'CONC4000043';
916 # Setup Org Unit Settings
918 # 'bill.prohibit_negative_balance_default' => 1
920 $summary = fetch_billable_xact_summary($xact_id);
921 ok( $summary, 'CASE 12: Found the transaction summary');
923 $summary->balance_owed,
925 'Starting balance owed is 0.70 for overdue fines'
928 ### partially pay the bill
930 userid => $patron_id,
931 note => '09-lp1198465_neg_balances.t',
932 payment_type => 'cash_payment',
933 patron_credit => '0.00',
934 payments => [ [ $xact_id, '0.20' ] ]
936 $pay_resp = pay_bills($payment_blob);
939 scalar( @{ $pay_resp->{payments} } ),
941 'Payment response included one payment id'
944 $summary = fetch_billable_xact_summary($xact_id);
946 $summary->balance_owed,
948 'Remaining balance of 0.50 after payment'
951 ### Check in using Amnesty Mode
952 $checkin_resp = $script->do_checkin_override({
953 barcode => $item_barcode,
957 $checkin_resp->{ilsevent},
959 'Checkin returned a SUCCESS event'
962 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
963 if (my $item_resp = $item_req->recv) {
964 if (my $item = $item_resp->content) {
966 $item->status == 7 || $item->status == 0,
967 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
972 ### verify ending state
973 $summary = fetch_billable_xact_summary($xact_id);
975 $summary->balance_owed,
977 'Patron has a balance of 0.00 (remaining fines forgiven)'
981 ##############################
982 # 10. Interval Testing
983 ##############################
985 # Setup Org Unit Settings
987 # 'bill.prohibit_negative_balance_default' => 1
989 # Setup Org Unit Settings
991 'bill.negative_balance_interval_default' => '1 hour'
994 $apputils->simplereq(
996 'open-ils.actor.org_unit.settings.update',
1002 ### Setup use case variables
1005 $item_barcode = 'CONC4000044';
1007 $summary = fetch_billable_xact_summary($xact_id);
1008 ok( $summary, 'CASE 10.1: Found the transaction summary');
1010 $summary->balance_owed,
1012 'Starting balance owed is 0.00 (LOST fee paid)'
1015 ### Check in first item (right after its payment)
1016 $checkin_resp = $script->do_checkin_override({
1017 barcode => $item_barcode,
1020 $checkin_resp->{ilsevent},
1022 'Checkin returned a SUCCESS event'
1025 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1026 if (my $item_resp = $item_req->recv) {
1027 if (my $item = $item_resp->content) {
1029 $item->status == 7 || $item->status == 0,
1030 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1035 ### verify ending state for 10.1
1036 $summary = fetch_billable_xact_summary($xact_id);
1038 $summary->balance_owed,
1040 'Patron has a balance of -50.00 (lost item returned during interval)'
1043 ### Setup use case variables
1046 $item_barcode = 'CONC4000045';
1048 $summary = fetch_billable_xact_summary($xact_id);
1049 ok( $summary, 'CASE 10.2: Found the transaction summary');
1051 $summary->balance_owed,
1053 'Starting balance owed is 0.00 (LOST fee paid)'
1056 ### Check in second item (2 hours after its payment)
1057 $checkin_resp = $script->do_checkin_override({
1058 barcode => $item_barcode,
1061 $checkin_resp->{ilsevent},
1063 'Checkin returned a SUCCESS event'
1066 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1067 if (my $item_resp = $item_req->recv) {
1068 if (my $item = $item_resp->content) {
1070 $item->status == 7 || $item->status == 0,
1071 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1076 ### verify ending state
1077 $summary = fetch_billable_xact_summary($xact_id);
1079 $summary->balance_owed,
1081 'Patron has a balance of 0.00 (lost item returned after interval)'
1085 #############################
1086 # 6. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Not Owe On Lost Item Return
1087 #############################
1089 ### Setup use case variables
1092 $item_barcode = 'CONC4000046';
1094 # Setup Org Unit Settings
1096 'bill.negative_balance_interval_default' => 0, #unset previous setting
1097 'circ.void_overdue_on_lost' => 1,
1098 'circ.restore_overdue_on_lost_return' => 1,
1099 'circ.lost.generate_overdue_on_checkin' => 1
1102 $apputils->simplereq(
1104 'open-ils.actor.org_unit.settings.update',
1110 $summary = fetch_billable_xact_summary($xact_id);
1111 ok( $summary, 'CASE 6: Found the transaction summary');
1113 $summary->balance_owed,
1115 'Starting balance owed is 40.00 for partially paid lost item'
1118 ### check-in the lost copy
1120 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1121 if (my $item_resp = $item_req->recv) {
1122 if (my $item = $item_resp->content) {
1125 'Fieldmapper::asset::copy',
1126 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1131 'Item with id = ' . $item_id . ' has status of LOST'
1136 $checkin_resp = $script->do_checkin_override({
1137 barcode => $item_barcode});
1139 $checkin_resp->{ilsevent},
1141 'Checkin returned a SUCCESS event'
1144 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1145 if (my $item_resp = $item_req->recv) {
1146 if (my $item = $item_resp->content) {
1148 $item->status == 7 || $item->status == 0,
1149 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1154 ### verify ending state
1156 $summary = fetch_billable_xact_summary($xact_id);
1158 $summary->balance_owed,
1160 'Patron has a balance of 0.00 (negative balance prevented)'
1164 #############################
1165 # 7. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Still Owe On Lost Item Return
1166 #############################
1168 ### Setup use case variables
1171 $item_barcode = 'CONC4000047';
1173 # Setup Org Unit Settings
1175 # 'bill.prohibit_negative_balance_default' => 1
1176 # 'circ.void_overdue_on_lost' => 1,
1177 # 'circ.restore_overdue_on_lost_return' => 1,
1178 # 'circ.lost.generate_overdue_on_checkin' => 1
1180 $apputils->simplereq(
1182 'open-ils.actor.org_unit.settings.update',
1188 $summary = fetch_billable_xact_summary($xact_id);
1189 ok( $summary, 'CASE 7: Found the transaction summary');
1191 $summary->balance_owed,
1193 'Starting balance owed is 0.70 for overdues'
1196 ### mark item as LOST
1197 $apputils->simplereq(
1199 'open-ils.circ.circulation.set_lost',
1201 {barcode => $item_barcode}
1204 $summary = fetch_billable_xact_summary($xact_id);
1205 ok( $summary, 'Found the transaction summary');
1207 $summary->balance_owed,
1209 'New balance owed is 50.00 for LOST fee'
1212 ### partially pay the bill
1214 userid => $patron_id,
1215 note => '09-lp1198465_neg_balances.t',
1216 payment_type => 'cash_payment',
1217 patron_credit => '0.00',
1218 payments => [ [ $xact_id, '0.10' ] ]
1220 $pay_resp = pay_bills($payment_blob);
1223 scalar( @{ $pay_resp->{payments} } ),
1225 'Payment response included one payment id'
1228 $summary = fetch_billable_xact_summary($xact_id);
1230 $summary->balance_owed,
1232 'Remaining balance of 49.90 after payment'
1235 ### check-in the lost copy
1237 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1238 if (my $item_resp = $item_req->recv) {
1239 if (my $item = $item_resp->content) {
1242 'Fieldmapper::asset::copy',
1243 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1248 'Item with id = ' . $item_id . ' has status of LOST'
1253 $checkin_resp = $script->do_checkin_override({
1254 barcode => $item_barcode});
1256 $checkin_resp->{ilsevent},
1258 'Checkin returned a SUCCESS event'
1261 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1262 if (my $item_resp = $item_req->recv) {
1263 if (my $item = $item_resp->content) {
1265 $item->status == 7 || $item->status == 0,
1266 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1271 ### verify ending state
1273 $summary = fetch_billable_xact_summary($xact_id);
1275 $summary->balance_owed,
1277 'Patron has a balance of 0.60 due to reinstated overdue fines'
1281 #############################
1282 # 9. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1283 #############################
1285 ### Setup use case variables
1288 $item_barcode = 'CONC4000048';
1290 # Setup Org Unit Settings
1292 # 'bill.prohibit_negative_balance_default' => 1
1293 # 'circ.void_overdue_on_lost' => 1,
1294 # 'circ.restore_overdue_on_lost_return' => 1,
1295 # 'circ.lost.generate_overdue_on_checkin' => 1
1297 $apputils->simplereq(
1299 'open-ils.actor.org_unit.settings.update',
1305 $summary = fetch_billable_xact_summary($xact_id);
1306 ok( $summary, 'CASE 9: Found the transaction summary');
1308 $summary->balance_owed,
1310 'Starting balance owed is 50.00 for lost item'
1313 ### partially pay the bill
1315 userid => $patron_id,
1316 note => '09-lp1198465_neg_balances.t',
1317 payment_type => 'cash_payment',
1318 patron_credit => '0.00',
1319 payments => [ [ $xact_id, '10.00' ] ]
1321 $pay_resp = pay_bills($payment_blob);
1324 scalar( @{ $pay_resp->{payments} } ),
1326 'Payment response included one payment id'
1329 $summary = fetch_billable_xact_summary($xact_id);
1331 $summary->balance_owed,
1333 'Remaining balance of 40.00 after payment'
1336 ### check-in the lost copy
1338 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1339 if (my $item_resp = $item_req->recv) {
1340 if (my $item = $item_resp->content) {
1343 'Fieldmapper::asset::copy',
1344 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1349 'Item with id = ' . $item_id . ' has status of LOST'
1354 $checkin_resp = $script->do_checkin_override({
1355 barcode => $item_barcode});
1357 $checkin_resp->{ilsevent},
1359 'Checkin returned a SUCCESS event'
1362 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1363 if (my $item_resp = $item_req->recv) {
1364 if (my $item = $item_resp->content) {
1366 $item->status == 7 || $item->status == 0,
1367 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1372 ### verify ending state
1374 $summary = fetch_billable_xact_summary($xact_id);
1376 $summary->balance_owed,
1378 'Patron has a balance of 0.00 (negative balance prevented)'
1382 #############################
1383 # 8. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1384 #############################
1386 ## TODO: consider using a later xact_id/item_id, instead of reverting back to user 4
1388 # Setup first patron (again)
1390 $patron_usrname = '99999355250';
1392 # Look up the patron
1393 if ($user_obj = retrieve_patron($patron_id)) {
1396 'Fieldmapper::actor::user',
1397 'open-ils.storage.direct.actor.user.retrieve returned aou object'
1402 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
1406 ### Setup use case variables
1409 $item_barcode = 'CONC4000042';
1411 # Setup Org Unit Settings
1413 # 'circ.void_overdue_on_lost' => 1,
1414 # 'circ.restore_overdue_on_lost_return' => 1,
1415 # 'circ.lost.generate_overdue_on_checkin' => 1
1417 'bill.prohibit_negative_balance_default' => 0
1420 $apputils->simplereq(
1422 'open-ils.actor.org_unit.settings.update',
1428 $summary = fetch_billable_xact_summary($xact_id);
1429 ok( $summary, 'CASE 8: Found the transaction summary');
1431 $summary->balance_owed,
1433 'Starting balance owed is 50.00 for lost item'
1436 ### partially pay the bill
1438 userid => $patron_id,
1439 note => '09-lp1198465_neg_balances.t',
1440 payment_type => 'cash_payment',
1441 patron_credit => '0.00',
1442 payments => [ [ $xact_id, '10.00' ] ]
1444 $pay_resp = pay_bills($payment_blob);
1447 scalar( @{ $pay_resp->{payments} } ),
1449 'Payment response included one payment id'
1452 $summary = fetch_billable_xact_summary($xact_id);
1454 $summary->balance_owed,
1456 'Remaining balance of 40.00 after payment'
1459 ### check-in the lost copy
1461 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1462 if (my $item_resp = $item_req->recv) {
1463 if (my $item = $item_resp->content) {
1466 'Fieldmapper::asset::copy',
1467 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1472 'Item with id = ' . $item_id . ' has status of LOST'
1477 $checkin_resp = $script->do_checkin_override({
1478 barcode => $item_barcode});
1480 $checkin_resp->{ilsevent},
1482 'Checkin returned a SUCCESS event'
1485 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1486 if (my $item_resp = $item_req->recv) {
1487 if (my $item = $item_resp->content) {
1489 $item->status == 7 || $item->status == 0,
1490 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1495 ### verify ending state
1497 $summary = fetch_billable_xact_summary($xact_id);
1499 $summary->balance_owed,
1501 'Patron has a negative balance of 7.00 due to overpayment'