3 use Test::More tests => 133;
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 ### adjust to zero, manually
481 $apputils->simplereq(
483 'open-ils.circ.money.billable_xact.adjust_to_zero',
488 ### verify 2nd ending state
489 $summary = fetch_billable_xact_summary($xact_id);
491 $summary->balance_owed,
493 'Case 13 (bonus): Patron has a balance of 0.00 (after manual adjustment of negative balance)'
497 ##############################
498 # 14. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
499 # SETTINGS: Prohibit negative balances on bills for overdue materials
500 ##############################
502 ### Setup use case variables
505 $item_barcode = 'CONC4000051';
507 # Setup Org Unit Settings
509 'bill.prohibit_negative_balance_on_lost' => 0, #unset from previous test
510 'bill.prohibit_negative_balance_on_overdues' => 1
512 $apputils->simplereq(
514 'open-ils.actor.org_unit.settings.update',
520 $summary = fetch_billable_xact_summary($xact_id);
521 ok( $summary, 'CASE 14a: Found the transaction summary');
523 $summary->balance_owed,
525 'Starting balance owed is 50.00 for lost item'
528 ### pay the whole bill
530 userid => $patron_id,
531 note => '09-lp1198465_neg_balances.t',
532 payment_type => 'cash_payment',
533 patron_credit => '0.00',
534 payments => [ [ $xact_id, '50.00' ] ]
536 $pay_resp = pay_bills($payment_blob);
539 scalar( @{ $pay_resp->{payments} } ),
541 'Payment response included one payment id'
544 $summary = fetch_billable_xact_summary($xact_id);
546 $summary->balance_owed,
548 'Remaining balance of 0.00 after payment'
552 $summary->xact_finish ne '',
553 'xact_finish is set due to 0.00 balance'
556 ### check-in the lost copy
558 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
559 if (my $item_resp = $item_req->recv) {
560 if (my $item = $item_resp->content) {
563 'Fieldmapper::asset::copy',
564 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
569 'Item with id = ' . $item_id . ' has status of LOST'
574 $checkin_resp = $script->do_checkin_override({
575 barcode => $item_barcode});
577 $checkin_resp->{ilsevent},
579 'Checkin returned a SUCCESS event'
582 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
583 if (my $item_resp = $item_req->recv) {
584 if (my $item = $item_resp->content) {
586 $item->status == 7 || $item->status == 0,
587 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
592 ### verify ending state
594 $summary = fetch_billable_xact_summary($xact_id);
596 $summary->balance_owed,
598 'Patron has a negative balance (credit) of 50.00 due to overpayment'
602 !defined($summary->xact_finish),
603 'xact_finish is not set due to non-zero balance'
607 ##############################
608 # 14. RERUN of Case 12. Test negative balance settings on fines
609 # SETTINGS: Prohibit negative balances on bills for overdue materials
610 ##############################
612 ### Setup use case variables
615 $item_barcode = 'CONC4000052';
617 # Setup Org Unit Settings
619 # 'bill.prohibit_negative_balance_on_overdues' => 1
621 $summary = fetch_billable_xact_summary($xact_id);
622 ok( $summary, 'CASE 14b: Found the transaction summary');
624 $summary->balance_owed,
626 'Starting balance owed is 0.70 for overdue fines'
629 ### partially pay the bill
631 userid => $patron_id,
632 note => '09-lp1198465_neg_balances.t',
633 payment_type => 'cash_payment',
634 patron_credit => '0.00',
635 payments => [ [ $xact_id, '0.20' ] ]
637 $pay_resp = pay_bills($payment_blob);
640 scalar( @{ $pay_resp->{payments} } ),
642 'Payment response included one payment id'
645 $summary = fetch_billable_xact_summary($xact_id);
647 $summary->balance_owed,
649 'Remaining balance of 0.50 after payment'
652 ### Check in using Amnesty Mode
653 $checkin_resp = $script->do_checkin_override({
654 barcode => $item_barcode,
658 $checkin_resp->{ilsevent},
660 'Checkin returned a SUCCESS event'
663 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
664 if (my $item_resp = $item_req->recv) {
665 if (my $item = $item_resp->content) {
667 $item->status == 7 || $item->status == 0,
668 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
673 ### verify ending state
674 $summary = fetch_billable_xact_summary($xact_id);
676 $summary->balance_owed,
678 'Patron has a balance of 0.00 (negative balance prevented)'
682 ##############################
683 # 3. Basic No Negative Balance Test
684 ##############################
686 # Re-setup first patron
688 $patron_usrname = '99999355250';
691 if ($user_obj = retrieve_patron($patron_id)) {
694 'Fieldmapper::actor::user',
695 'open-ils.storage.direct.actor.user.retrieve returned aou object'
700 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
705 ### Setup use case variables
708 $item_barcode = 'CONC4000039';
710 # Setup Org Unit Settings
712 'bill.prohibit_negative_balance_on_overdues' => 0, #unset from previous test
713 'bill.prohibit_negative_balance_default' => 1
715 $apputils->simplereq(
717 'open-ils.actor.org_unit.settings.update',
723 $summary = fetch_billable_xact_summary($xact_id);
724 ok( $summary, 'CASE 3: Found the transaction summary');
726 $summary->balance_owed,
728 'Starting balance owed is 50.00 for lost item'
731 ### check-in the lost copy
733 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
734 if (my $item_resp = $item_req->recv) {
735 if (my $item = $item_resp->content) {
739 'Item with id = ' . $item_id . ' has status of LOST'
744 $checkin_resp = $script->do_checkin_override({
745 barcode => $item_barcode});
747 $checkin_resp->{ilsevent},
749 'Checkin returned a SUCCESS event'
752 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
753 if (my $item_resp = $item_req->recv) {
754 if (my $item = $item_resp->content) {
756 $item->status == 7 || $item->status == 0,
757 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
762 ### verify ending state
764 $summary = fetch_billable_xact_summary($xact_id);
766 $summary->balance_owed,
768 'Patron has a balance of 0.00 (negative balance prevented)'
771 ##############################
772 # 4. Prohibit Negative Balances with Partial Payment
773 ##############################
775 ### Setup use case variables
778 $item_barcode = 'CONC4000040';
780 # Setup Org Unit Settings
782 # 'bill.prohibit_negative_balance_default' => 1
784 $summary = fetch_billable_xact_summary($xact_id);
785 ok( $summary, 'CASE 4: Found the transaction summary');
787 $summary->balance_owed,
789 'Starting balance owed is 50.00 for lost item'
792 ### confirm the copy is lost
793 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
794 if (my $item_resp = $item_req->recv) {
795 if (my $item = $item_resp->content) {
799 'Item with id = ' . $item_id . ' has status of LOST'
804 ### partially pay the bill
806 userid => $patron_id,
807 note => '09-lp1198465_neg_balances.t',
808 payment_type => 'cash_payment',
809 patron_credit => '0.00',
810 payments => [ [ $xact_id, '10.00' ] ]
812 $pay_resp = pay_bills($payment_blob);
815 scalar( @{ $pay_resp->{payments} } ),
817 'Payment response included one payment id'
820 $summary = fetch_billable_xact_summary($xact_id);
822 $summary->balance_owed,
824 'Remaining balance of 40.00 after payment'
827 ### check-in the lost copy
828 $checkin_resp = $script->do_checkin_override({
829 barcode => $item_barcode});
831 $checkin_resp->{ilsevent},
833 'Checkin returned a SUCCESS event'
836 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
837 if (my $item_resp = $item_req->recv) {
838 if (my $item = $item_resp->content) {
840 $item->status == 7 || $item->status == 0,
841 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
846 ### verify ending state
848 $summary = fetch_billable_xact_summary($xact_id);
850 $summary->balance_owed,
852 'Patron has a balance of 0.00 (negative balance prevented)'
856 ##############################
857 # Restore then generate new overdues on xact with adjustments
858 ##############################
860 ### Setup use case variables
863 $item_barcode = 'CONC4000041';
865 # Setup Org Unit Settings
867 # 'bill.prohibit_negative_balance_default' => 1
869 'circ.restore_overdue_on_lost_return' => 1,
870 'circ.lost.generate_overdue_on_checkin' => 1
873 $apputils->simplereq(
875 'open-ils.actor.org_unit.settings.update',
881 $summary = fetch_billable_xact_summary($xact_id);
883 $summary->balance_owed,
885 'Starting balance owed is 50.00 for lost item'
888 $checkin_resp = $script->do_checkin_override({
889 barcode => $item_barcode
892 $checkin_resp->{ilsevent},
894 'Checkin returned a SUCCESS event'
897 ### verify ending state
898 $summary = fetch_billable_xact_summary($xact_id);
900 $summary->balance_owed,
902 'Patron has a balance of 3.00 (newly generated fines, up to maxfines)'
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'