3 use Test::More tests => 127;
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'
534 ### check-in the lost copy
536 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
537 if (my $item_resp = $item_req->recv) {
538 if (my $item = $item_resp->content) {
541 'Fieldmapper::asset::copy',
542 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
547 'Item with id = ' . $item_id . ' has status of LOST'
552 $checkin_resp = $script->do_checkin_override({
553 barcode => $item_barcode});
555 $checkin_resp->{ilsevent},
557 'Checkin returned a SUCCESS event'
560 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
561 if (my $item_resp = $item_req->recv) {
562 if (my $item = $item_resp->content) {
564 $item->status == 7 || $item->status == 0,
565 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
570 ### verify ending state
572 $summary = fetch_billable_xact_summary($xact_id);
574 $summary->balance_owed,
576 'Patron has a negative balance (credit) of 50.00 due to overpayment'
580 ##############################
581 # 14. RERUN of Case 12. Test negative balance settings on fines
582 # SETTINGS: Prohibit negative balances on bills for overdue materials
583 ##############################
585 ### Setup use case variables
588 $item_barcode = 'CONC4000052';
590 # Setup Org Unit Settings
592 # 'bill.prohibit_negative_balance_on_overdues' => 1
594 $summary = fetch_billable_xact_summary($xact_id);
595 ok( $summary, 'CASE 14b: Found the transaction summary');
597 $summary->balance_owed,
599 'Starting balance owed is 0.70 for overdue fines'
602 ### partially pay the bill
604 userid => $patron_id,
605 note => '09-lp1198465_neg_balances.t',
606 payment_type => 'cash_payment',
607 patron_credit => '0.00',
608 payments => [ [ $xact_id, '0.20' ] ]
610 $pay_resp = pay_bills($payment_blob);
613 scalar( @{ $pay_resp->{payments} } ),
615 'Payment response included one payment id'
618 $summary = fetch_billable_xact_summary($xact_id);
620 $summary->balance_owed,
622 'Remaining balance of 0.50 after payment'
625 ### Check in using Amnesty Mode
626 $checkin_resp = $script->do_checkin_override({
627 barcode => $item_barcode,
631 $checkin_resp->{ilsevent},
633 'Checkin returned a SUCCESS event'
636 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
637 if (my $item_resp = $item_req->recv) {
638 if (my $item = $item_resp->content) {
640 $item->status == 7 || $item->status == 0,
641 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
646 ### verify ending state
647 $summary = fetch_billable_xact_summary($xact_id);
649 $summary->balance_owed,
651 'Patron has a balance of 0.00 (negative balance prevented)'
655 ##############################
656 # 3. Basic No Negative Balance Test
657 ##############################
659 # Re-setup first patron
661 $patron_usrname = '99999355250';
664 if ($user_obj = retrieve_patron($patron_id)) {
667 'Fieldmapper::actor::user',
668 'open-ils.storage.direct.actor.user.retrieve returned aou object'
673 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
678 ### Setup use case variables
681 $item_barcode = 'CONC4000039';
683 # Setup Org Unit Settings
685 'bill.prohibit_negative_balance_on_overdues' => 0, #unset from previous test
686 'bill.prohibit_negative_balance_default' => 1
688 $apputils->simplereq(
690 'open-ils.actor.org_unit.settings.update',
696 $summary = fetch_billable_xact_summary($xact_id);
697 ok( $summary, 'CASE 3: Found the transaction summary');
699 $summary->balance_owed,
701 'Starting balance owed is 50.00 for lost item'
704 ### check-in the lost copy
706 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
707 if (my $item_resp = $item_req->recv) {
708 if (my $item = $item_resp->content) {
712 'Item with id = ' . $item_id . ' has status of LOST'
717 $checkin_resp = $script->do_checkin_override({
718 barcode => $item_barcode});
720 $checkin_resp->{ilsevent},
722 'Checkin returned a SUCCESS event'
725 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
726 if (my $item_resp = $item_req->recv) {
727 if (my $item = $item_resp->content) {
729 $item->status == 7 || $item->status == 0,
730 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
735 ### verify ending state
737 $summary = fetch_billable_xact_summary($xact_id);
739 $summary->balance_owed,
741 'Patron has a balance of 0.00 (negative balance prevented)'
744 ##############################
745 # 4. Prohibit Negative Balances with Partial Payment
746 ##############################
748 ### Setup use case variables
751 $item_barcode = 'CONC4000040';
753 # Setup Org Unit Settings
755 # 'bill.prohibit_negative_balance_default' => 1
757 $summary = fetch_billable_xact_summary($xact_id);
758 ok( $summary, 'CASE 4: Found the transaction summary');
760 $summary->balance_owed,
762 'Starting balance owed is 50.00 for lost item'
765 ### confirm the copy is lost
766 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
767 if (my $item_resp = $item_req->recv) {
768 if (my $item = $item_resp->content) {
772 'Item with id = ' . $item_id . ' has status of LOST'
777 ### partially pay the bill
779 userid => $patron_id,
780 note => '09-lp1198465_neg_balances.t',
781 payment_type => 'cash_payment',
782 patron_credit => '0.00',
783 payments => [ [ $xact_id, '10.00' ] ]
785 $pay_resp = pay_bills($payment_blob);
788 scalar( @{ $pay_resp->{payments} } ),
790 'Payment response included one payment id'
793 $summary = fetch_billable_xact_summary($xact_id);
795 $summary->balance_owed,
797 'Remaining balance of 40.00 after payment'
800 ### check-in the lost copy
801 $checkin_resp = $script->do_checkin_override({
802 barcode => $item_barcode});
804 $checkin_resp->{ilsevent},
806 'Checkin returned a SUCCESS event'
809 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
810 if (my $item_resp = $item_req->recv) {
811 if (my $item = $item_resp->content) {
813 $item->status == 7 || $item->status == 0,
814 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
819 ### verify ending state
821 $summary = fetch_billable_xact_summary($xact_id);
823 $summary->balance_owed,
825 'Patron has a balance of 0.00 (negative balance prevented)'
829 ###############################
830 ## 11. Manually voiding lost book fee does not result in negative balances
831 ###############################
833 #### Setup use case variables
836 #$item_barcode = 'CONC4000040';
838 ## Setup Org Unit Settings
840 # 'bill.prohibit_negative_balance_default' => 1
842 #$summary = fetch_billable_xact_summary($xact_id);
843 #ok( $summary, 'CASE 11: Found the transaction summary');
845 # $summary->balance_owed,
847 # 'Starting balance owed is 50.00 for lost item'
850 #### confirm the copy is lost
851 #$item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
852 #if (my $item_resp = $item_req->recv) {
853 # if (my $item = $item_resp->content) {
857 # 'Item with id = ' . $item_id . ' has status of LOST'
862 #### partially pay the bill
864 # userid => $patron_id,
865 # note => '09-lp1198465_neg_balances.t',
866 # payment_type => 'cash_payment',
867 # patron_credit => '0.00',
868 # payments => [ [ $xact_id, '10.00' ] ]
870 #$pay_resp = pay_bills($payment_blob);
873 # scalar( @{ $pay_resp->{payments} } ),
875 # 'Payment response included one payment id'
878 #$summary = fetch_billable_xact_summary($xact_id);
880 # $summary->balance_owed,
882 # 'Remaining balance of 40.00 after payment'
885 #### TODO: manually void "the rest" of the bill (i.e. prevent neg bal)
886 #### XXX: HARDCODING billing id for now; should look up the LOST bill for this xact?
887 #my @billing_ids = (6);
888 #my $void_resp = void_bills(\@billing_ids);
893 # 'Voiding was successful'
896 #### verify ending state
898 #$summary = fetch_billable_xact_summary($xact_id);
900 # $summary->balance_owed,
902 # 'Patron has a balance of 0.00 (negative balance prohibited)'
906 ##############################
907 # 12. Test negative balance settings on fines
908 ##############################
912 $patron_usrname = '99999387993';
915 if ($user_obj = retrieve_patron($patron_id)) {
918 'Fieldmapper::actor::user',
919 'open-ils.storage.direct.actor.user.retrieve returned aou object'
924 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
928 ### Setup use case variables
931 $item_barcode = 'CONC4000043';
933 # Setup Org Unit Settings
935 # 'bill.prohibit_negative_balance_default' => 1
937 $summary = fetch_billable_xact_summary($xact_id);
938 ok( $summary, 'CASE 12: Found the transaction summary');
940 $summary->balance_owed,
942 'Starting balance owed is 0.70 for overdue fines'
945 ### partially pay the bill
947 userid => $patron_id,
948 note => '09-lp1198465_neg_balances.t',
949 payment_type => 'cash_payment',
950 patron_credit => '0.00',
951 payments => [ [ $xact_id, '0.20' ] ]
953 $pay_resp = pay_bills($payment_blob);
956 scalar( @{ $pay_resp->{payments} } ),
958 'Payment response included one payment id'
961 $summary = fetch_billable_xact_summary($xact_id);
963 $summary->balance_owed,
965 'Remaining balance of 0.50 after payment'
968 ### Check in using Amnesty Mode
969 $checkin_resp = $script->do_checkin_override({
970 barcode => $item_barcode,
974 $checkin_resp->{ilsevent},
976 'Checkin returned a SUCCESS event'
979 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
980 if (my $item_resp = $item_req->recv) {
981 if (my $item = $item_resp->content) {
983 $item->status == 7 || $item->status == 0,
984 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
989 ### verify ending state
990 $summary = fetch_billable_xact_summary($xact_id);
992 $summary->balance_owed,
994 'Patron has a balance of 0.00 (remaining fines forgiven)'
998 ##############################
999 # 10. Interval Testing
1000 ##############################
1002 # Setup Org Unit Settings
1004 # 'bill.prohibit_negative_balance_default' => 1
1006 # Setup Org Unit Settings
1008 'bill.negative_balance_interval_default' => '1 hour'
1011 $apputils->simplereq(
1013 'open-ils.actor.org_unit.settings.update',
1019 ### Setup use case variables
1022 $item_barcode = 'CONC4000044';
1024 $summary = fetch_billable_xact_summary($xact_id);
1025 ok( $summary, 'CASE 10.1: Found the transaction summary');
1027 $summary->balance_owed,
1029 'Starting balance owed is 0.00 (LOST fee paid)'
1032 ### Check in first item (right after its payment)
1033 $checkin_resp = $script->do_checkin_override({
1034 barcode => $item_barcode,
1037 $checkin_resp->{ilsevent},
1039 'Checkin returned a SUCCESS event'
1042 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1043 if (my $item_resp = $item_req->recv) {
1044 if (my $item = $item_resp->content) {
1046 $item->status == 7 || $item->status == 0,
1047 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1052 ### verify ending state for 10.1
1053 $summary = fetch_billable_xact_summary($xact_id);
1055 $summary->balance_owed,
1057 'Patron has a balance of -50.00 (lost item returned during interval)'
1060 ### Setup use case variables
1063 $item_barcode = 'CONC4000045';
1065 $summary = fetch_billable_xact_summary($xact_id);
1066 ok( $summary, 'CASE 10.2: Found the transaction summary');
1068 $summary->balance_owed,
1070 'Starting balance owed is 0.00 (LOST fee paid)'
1073 ### Check in second item (2 hours after its payment)
1074 $checkin_resp = $script->do_checkin_override({
1075 barcode => $item_barcode,
1078 $checkin_resp->{ilsevent},
1080 'Checkin returned a SUCCESS event'
1083 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1084 if (my $item_resp = $item_req->recv) {
1085 if (my $item = $item_resp->content) {
1087 $item->status == 7 || $item->status == 0,
1088 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1093 ### verify ending state
1094 $summary = fetch_billable_xact_summary($xact_id);
1096 $summary->balance_owed,
1098 'Patron has a balance of 0.00 (lost item returned after interval)'
1102 #############################
1103 # 6. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Not Owe On Lost Item Return
1104 #############################
1106 ### Setup use case variables
1109 $item_barcode = 'CONC4000046';
1111 # Setup Org Unit Settings
1113 'bill.negative_balance_interval_default' => 0, #unset previous setting
1114 'circ.void_overdue_on_lost' => 1,
1115 'circ.restore_overdue_on_lost_return' => 1,
1116 'circ.lost.generate_overdue_on_checkin' => 1
1119 $apputils->simplereq(
1121 'open-ils.actor.org_unit.settings.update',
1127 $summary = fetch_billable_xact_summary($xact_id);
1128 ok( $summary, 'CASE 6: Found the transaction summary');
1130 $summary->balance_owed,
1132 'Starting balance owed is 40.00 for partially paid lost item'
1135 ### check-in the lost copy
1137 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1138 if (my $item_resp = $item_req->recv) {
1139 if (my $item = $item_resp->content) {
1142 'Fieldmapper::asset::copy',
1143 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1148 'Item with id = ' . $item_id . ' has status of LOST'
1153 $checkin_resp = $script->do_checkin_override({
1154 barcode => $item_barcode});
1156 $checkin_resp->{ilsevent},
1158 'Checkin returned a SUCCESS event'
1161 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1162 if (my $item_resp = $item_req->recv) {
1163 if (my $item = $item_resp->content) {
1165 $item->status == 7 || $item->status == 0,
1166 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1171 ### verify ending state
1173 $summary = fetch_billable_xact_summary($xact_id);
1175 $summary->balance_owed,
1177 'Patron has a balance of 0.00 (negative balance prevented)'
1181 #############################
1182 # 7. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Still Owe On Lost Item Return
1183 #############################
1185 ### Setup use case variables
1188 $item_barcode = 'CONC4000047';
1190 # Setup Org Unit Settings
1192 # 'bill.prohibit_negative_balance_default' => 1
1193 # 'circ.void_overdue_on_lost' => 1,
1194 # 'circ.restore_overdue_on_lost_return' => 1,
1195 # 'circ.lost.generate_overdue_on_checkin' => 1
1197 $apputils->simplereq(
1199 'open-ils.actor.org_unit.settings.update',
1205 $summary = fetch_billable_xact_summary($xact_id);
1206 ok( $summary, 'CASE 7: Found the transaction summary');
1208 $summary->balance_owed,
1210 'Starting balance owed is 0.70 for overdues'
1213 ### mark item as LOST
1214 $apputils->simplereq(
1216 'open-ils.circ.circulation.set_lost',
1218 {barcode => $item_barcode}
1221 $summary = fetch_billable_xact_summary($xact_id);
1222 ok( $summary, 'Found the transaction summary');
1224 $summary->balance_owed,
1226 'New balance owed is 50.00 for LOST fee'
1229 ### partially pay the bill
1231 userid => $patron_id,
1232 note => '09-lp1198465_neg_balances.t',
1233 payment_type => 'cash_payment',
1234 patron_credit => '0.00',
1235 payments => [ [ $xact_id, '0.10' ] ]
1237 $pay_resp = pay_bills($payment_blob);
1240 scalar( @{ $pay_resp->{payments} } ),
1242 'Payment response included one payment id'
1245 $summary = fetch_billable_xact_summary($xact_id);
1247 $summary->balance_owed,
1249 'Remaining balance of 49.90 after payment'
1252 ### check-in the lost copy
1254 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1255 if (my $item_resp = $item_req->recv) {
1256 if (my $item = $item_resp->content) {
1259 'Fieldmapper::asset::copy',
1260 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1265 'Item with id = ' . $item_id . ' has status of LOST'
1270 $checkin_resp = $script->do_checkin_override({
1271 barcode => $item_barcode});
1273 $checkin_resp->{ilsevent},
1275 'Checkin returned a SUCCESS event'
1278 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1279 if (my $item_resp = $item_req->recv) {
1280 if (my $item = $item_resp->content) {
1282 $item->status == 7 || $item->status == 0,
1283 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1288 ### verify ending state
1290 $summary = fetch_billable_xact_summary($xact_id);
1292 $summary->balance_owed,
1294 'Patron has a balance of 0.60 due to reinstated overdue fines'
1298 #############################
1299 # 9. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1300 #############################
1302 ### Setup use case variables
1305 $item_barcode = 'CONC4000048';
1307 # Setup Org Unit Settings
1309 # 'bill.prohibit_negative_balance_default' => 1
1310 # 'circ.void_overdue_on_lost' => 1,
1311 # 'circ.restore_overdue_on_lost_return' => 1,
1312 # 'circ.lost.generate_overdue_on_checkin' => 1
1314 $apputils->simplereq(
1316 'open-ils.actor.org_unit.settings.update',
1322 $summary = fetch_billable_xact_summary($xact_id);
1323 ok( $summary, 'CASE 9: Found the transaction summary');
1325 $summary->balance_owed,
1327 'Starting balance owed is 50.00 for lost item'
1330 ### partially pay the bill
1332 userid => $patron_id,
1333 note => '09-lp1198465_neg_balances.t',
1334 payment_type => 'cash_payment',
1335 patron_credit => '0.00',
1336 payments => [ [ $xact_id, '10.00' ] ]
1338 $pay_resp = pay_bills($payment_blob);
1341 scalar( @{ $pay_resp->{payments} } ),
1343 'Payment response included one payment id'
1346 $summary = fetch_billable_xact_summary($xact_id);
1348 $summary->balance_owed,
1350 'Remaining balance of 40.00 after payment'
1353 ### check-in the lost copy
1355 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1356 if (my $item_resp = $item_req->recv) {
1357 if (my $item = $item_resp->content) {
1360 'Fieldmapper::asset::copy',
1361 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1366 'Item with id = ' . $item_id . ' has status of LOST'
1371 $checkin_resp = $script->do_checkin_override({
1372 barcode => $item_barcode});
1374 $checkin_resp->{ilsevent},
1376 'Checkin returned a SUCCESS event'
1379 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1380 if (my $item_resp = $item_req->recv) {
1381 if (my $item = $item_resp->content) {
1383 $item->status == 7 || $item->status == 0,
1384 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1389 ### verify ending state
1391 $summary = fetch_billable_xact_summary($xact_id);
1393 $summary->balance_owed,
1395 'Patron has a balance of 0.00 (negative balance prevented)'
1399 #############################
1400 # 8. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1401 #############################
1403 ## TODO: consider using a later xact_id/item_id, instead of reverting back to user 4
1405 # Setup first patron (again)
1407 $patron_usrname = '99999355250';
1409 # Look up the patron
1410 if ($user_obj = retrieve_patron($patron_id)) {
1413 'Fieldmapper::actor::user',
1414 'open-ils.storage.direct.actor.user.retrieve returned aou object'
1419 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
1423 ### Setup use case variables
1426 $item_barcode = 'CONC4000042';
1428 # Setup Org Unit Settings
1430 # 'circ.void_overdue_on_lost' => 1,
1431 # 'circ.restore_overdue_on_lost_return' => 1,
1432 # 'circ.lost.generate_overdue_on_checkin' => 1
1434 'bill.prohibit_negative_balance_default' => 0
1437 $apputils->simplereq(
1439 'open-ils.actor.org_unit.settings.update',
1445 $summary = fetch_billable_xact_summary($xact_id);
1446 ok( $summary, 'CASE 8: Found the transaction summary');
1448 $summary->balance_owed,
1450 'Starting balance owed is 50.00 for lost item'
1453 ### partially pay the bill
1455 userid => $patron_id,
1456 note => '09-lp1198465_neg_balances.t',
1457 payment_type => 'cash_payment',
1458 patron_credit => '0.00',
1459 payments => [ [ $xact_id, '10.00' ] ]
1461 $pay_resp = pay_bills($payment_blob);
1464 scalar( @{ $pay_resp->{payments} } ),
1466 'Payment response included one payment id'
1469 $summary = fetch_billable_xact_summary($xact_id);
1471 $summary->balance_owed,
1473 'Remaining balance of 40.00 after payment'
1476 ### check-in the lost copy
1478 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1479 if (my $item_resp = $item_req->recv) {
1480 if (my $item = $item_resp->content) {
1483 'Fieldmapper::asset::copy',
1484 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1489 'Item with id = ' . $item_id . ' has status of LOST'
1494 $checkin_resp = $script->do_checkin_override({
1495 barcode => $item_barcode});
1497 $checkin_resp->{ilsevent},
1499 'Checkin returned a SUCCESS event'
1502 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1503 if (my $item_resp = $item_req->recv) {
1504 if (my $item = $item_resp->content) {
1506 $item->status == 7 || $item->status == 0,
1507 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1512 ### verify ending state
1514 $summary = fetch_billable_xact_summary($xact_id);
1516 $summary->balance_owed,
1518 'Patron has a negative balance of 7.00 due to overpayment'