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
84 #----------------------------------------------------------------
86 # Connect to Evergreen
87 $script->authenticate({
89 password => 'demo123',
91 ok( $script->authtoken, 'Have an authtoken');
93 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
94 ok( ! ref $ws, 'Registered a new workstation');
97 $script->authenticate({
99 password => 'demo123',
101 workstation => WORKSTATION_NAME});
102 ok( $script->authtoken, 'Have an authtoken associated with the workstation');
105 ### TODO: verify that stock data is ready for testing
107 ### Setup Org Unit Settings that apply to all test cases
109 my $org_id = 1; #CONS
111 'circ.max_item_price' => 50,
112 'circ.min_item_price' => 50,
113 'circ.void_lost_on_checkin' => 1
116 $apputils->simplereq(
118 'open-ils.actor.org_unit.settings.update',
126 $patron_usrname = '99999355250';
129 if ($user_obj = retrieve_patron($patron_id)) {
132 'Fieldmapper::actor::user',
133 'open-ils.storage.direct.actor.user.retrieve returned aou object'
138 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
143 ##############################
144 # 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
145 ##############################
147 ### Setup use case variables
150 $item_barcode = 'CONC4000037';
152 $summary = fetch_billable_xact_summary($xact_id);
153 ok( $summary, 'CASE 1: Found the transaction summary');
155 $summary->balance_owed,
157 'Starting balance owed is 50.00 for lost item'
160 ### pay the whole bill
162 userid => $patron_id,
163 note => '09-lp1198465_neg_balances.t',
164 payment_type => 'cash_payment',
165 patron_credit => '0.00',
166 payments => [ [ $xact_id, '50.00' ] ]
168 $pay_resp = pay_bills($payment_blob);
171 scalar( @{ $pay_resp->{payments} } ),
173 'Payment response included one payment id'
176 $summary = fetch_billable_xact_summary($xact_id);
178 $summary->balance_owed,
180 'Remaining balance of 0.00 after payment'
183 ### check-in the lost copy
185 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
186 if (my $item_resp = $item_req->recv) {
187 if (my $item = $item_resp->content) {
190 'Fieldmapper::asset::copy',
191 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
196 'Item with id = ' . $item_id . ' has status of LOST'
201 $checkin_resp = $script->do_checkin_override({
202 barcode => $item_barcode});
204 $checkin_resp->{ilsevent},
206 'Checkin returned a SUCCESS event'
209 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
210 if (my $item_resp = $item_req->recv) {
211 if (my $item = $item_resp->content) {
213 $item->status == 7 || $item->status == 0,
214 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
219 ### verify ending state
221 $summary = fetch_billable_xact_summary($xact_id);
223 $summary->balance_owed,
225 'Patron has a negative balance (credit) of 50.00 due to overpayment'
229 ##############################
230 # 2. Negative Balance Settings Are Unset, No Payment Made
231 ##############################
233 ### Setup use case variables
236 $item_barcode = 'CONC4000038';
238 $summary = fetch_billable_xact_summary($xact_id);
239 ok( $summary, 'CASE 2: Found the transaction summary');
241 $summary->balance_owed,
243 'Starting balance owed is 50.00 for lost item'
246 ### check-in the lost copy
248 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
249 if (my $item_resp = $item_req->recv) {
250 if (my $item = $item_resp->content) {
254 'Item with id = ' . $item_id . ' has status of LOST'
259 $checkin_resp = $script->do_checkin_override({
260 barcode => $item_barcode});
262 $checkin_resp->{ilsevent},
264 'Checkin returned a SUCCESS event'
267 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
268 if (my $item_resp = $item_req->recv) {
269 if (my $item = $item_resp->content) {
271 $item->status == 7 || $item->status == 0,
272 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
277 ### verify ending state
279 $summary = fetch_billable_xact_summary($xact_id);
281 $summary->balance_owed,
283 'Patron has a balance of 0.00'
287 ##############################
288 # 13. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
289 # SETTINGS: Prohibit negative balances on bills for lost materials
290 ##############################
294 $patron_usrname = '99999335859';
297 if ($user_obj = retrieve_patron($patron_id)) {
300 'Fieldmapper::actor::user',
301 'open-ils.storage.direct.actor.user.retrieve returned aou object'
306 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
310 ### Setup use case variables
313 $item_barcode = 'CONC4000049';
315 # Setup Org Unit Settings
317 'bill.prohibit_negative_balance_on_lost' => 1
319 $apputils->simplereq(
321 'open-ils.actor.org_unit.settings.update',
327 $summary = fetch_billable_xact_summary($xact_id);
328 ok( $summary, 'CASE 13a: Found the transaction summary');
330 $summary->balance_owed,
332 'Starting balance owed is 50.00 for lost item'
335 ### pay the whole bill
337 userid => $patron_id,
338 note => '09-lp1198465_neg_balances.t',
339 payment_type => 'cash_payment',
340 patron_credit => '0.00',
341 payments => [ [ $xact_id, '50.00' ] ]
343 $pay_resp = pay_bills($payment_blob);
346 scalar( @{ $pay_resp->{payments} } ),
348 'Payment response included one payment id'
351 $summary = fetch_billable_xact_summary($xact_id);
353 $summary->balance_owed,
355 'Remaining balance of 0.00 after payment'
358 ### check-in the lost copy
360 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
361 if (my $item_resp = $item_req->recv) {
362 if (my $item = $item_resp->content) {
365 'Fieldmapper::asset::copy',
366 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
371 'Item with id = ' . $item_id . ' has status of LOST'
376 $checkin_resp = $script->do_checkin_override({
377 barcode => $item_barcode});
379 $checkin_resp->{ilsevent},
381 'Checkin returned a SUCCESS event'
384 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
385 if (my $item_resp = $item_req->recv) {
386 if (my $item = $item_resp->content) {
388 $item->status == 7 || $item->status == 0,
389 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
394 ### verify ending state
396 $summary = fetch_billable_xact_summary($xact_id);
398 $summary->balance_owed,
400 'Patron has a balance of 0.00 (negative balance prevented)'
404 ##############################
405 # 13. RERUN of Case 12. Test negative balance settings on fines
406 # SETTINGS: Prohibit negative balances on bills for lost materials
407 ##############################
409 ### Setup use case variables
412 $item_barcode = 'CONC4000050';
414 # Setup Org Unit Settings
416 # 'bill.prohibit_negative_balance_on_lost' => 1
418 $summary = fetch_billable_xact_summary($xact_id);
419 ok( $summary, 'CASE 13b: Found the transaction summary');
421 $summary->balance_owed,
423 'Starting balance owed is 0.70 for overdue fines'
426 ### partially pay the bill
428 userid => $patron_id,
429 note => '09-lp1198465_neg_balances.t',
430 payment_type => 'cash_payment',
431 patron_credit => '0.00',
432 payments => [ [ $xact_id, '0.20' ] ]
434 $pay_resp = pay_bills($payment_blob);
437 scalar( @{ $pay_resp->{payments} } ),
439 'Payment response included one payment id'
442 $summary = fetch_billable_xact_summary($xact_id);
444 $summary->balance_owed,
446 'Remaining balance of 0.50 after payment'
449 ### Check in using Amnesty Mode
450 $checkin_resp = $script->do_checkin_override({
451 barcode => $item_barcode,
455 $checkin_resp->{ilsevent},
457 'Checkin returned a SUCCESS event'
460 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
461 if (my $item_resp = $item_req->recv) {
462 if (my $item = $item_resp->content) {
464 $item->status == 7 || $item->status == 0,
465 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
470 ### verify ending state
471 $summary = fetch_billable_xact_summary($xact_id);
473 $summary->balance_owed,
475 'Patron has a negative balance of -0.20 (refund of overdue fine payment)'
479 ### adjust to zero, manually
480 $apputils->simplereq(
482 'open-ils.circ.money.billable_xact.adjust_to_zero',
487 ### verify 2nd ending state
488 $summary = fetch_billable_xact_summary($xact_id);
490 $summary->balance_owed,
492 'Case 13 (bonus): Patron has a balance of 0.00 (after manual adjustment of negative balance)'
496 ##############################
497 # 14. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
498 # SETTINGS: Prohibit negative balances on bills for overdue materials
499 ##############################
501 ### Setup use case variables
504 $item_barcode = 'CONC4000051';
506 # Setup Org Unit Settings
508 'bill.prohibit_negative_balance_on_lost' => 0, #unset from previous test
509 'bill.prohibit_negative_balance_on_overdues' => 1
511 $apputils->simplereq(
513 'open-ils.actor.org_unit.settings.update',
519 $summary = fetch_billable_xact_summary($xact_id);
520 ok( $summary, 'CASE 14a: Found the transaction summary');
522 $summary->balance_owed,
524 'Starting balance owed is 50.00 for lost item'
527 ### pay the whole bill
529 userid => $patron_id,
530 note => '09-lp1198465_neg_balances.t',
531 payment_type => 'cash_payment',
532 patron_credit => '0.00',
533 payments => [ [ $xact_id, '50.00' ] ]
535 $pay_resp = pay_bills($payment_blob);
538 scalar( @{ $pay_resp->{payments} } ),
540 'Payment response included one payment id'
543 $summary = fetch_billable_xact_summary($xact_id);
545 $summary->balance_owed,
547 'Remaining balance of 0.00 after payment'
551 $summary->xact_finish ne '',
552 'xact_finish is set due to 0.00 balance'
555 ### check-in the lost copy
557 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
558 if (my $item_resp = $item_req->recv) {
559 if (my $item = $item_resp->content) {
562 'Fieldmapper::asset::copy',
563 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
568 'Item with id = ' . $item_id . ' has status of LOST'
573 $checkin_resp = $script->do_checkin_override({
574 barcode => $item_barcode});
576 $checkin_resp->{ilsevent},
578 'Checkin returned a SUCCESS event'
581 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
582 if (my $item_resp = $item_req->recv) {
583 if (my $item = $item_resp->content) {
585 $item->status == 7 || $item->status == 0,
586 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
591 ### verify ending state
593 $summary = fetch_billable_xact_summary($xact_id);
595 $summary->balance_owed,
597 'Patron has a negative balance (credit) of 50.00 due to overpayment'
601 !defined($summary->xact_finish),
602 'xact_finish is not set due to non-zero balance'
606 ##############################
607 # 14. RERUN of Case 12. Test negative balance settings on fines
608 # SETTINGS: Prohibit negative balances on bills for overdue materials
609 ##############################
611 ### Setup use case variables
614 $item_barcode = 'CONC4000052';
616 # Setup Org Unit Settings
618 # 'bill.prohibit_negative_balance_on_overdues' => 1
620 $summary = fetch_billable_xact_summary($xact_id);
621 ok( $summary, 'CASE 14b: Found the transaction summary');
623 $summary->balance_owed,
625 'Starting balance owed is 0.70 for overdue fines'
628 ### partially pay the bill
630 userid => $patron_id,
631 note => '09-lp1198465_neg_balances.t',
632 payment_type => 'cash_payment',
633 patron_credit => '0.00',
634 payments => [ [ $xact_id, '0.20' ] ]
636 $pay_resp = pay_bills($payment_blob);
639 scalar( @{ $pay_resp->{payments} } ),
641 'Payment response included one payment id'
644 $summary = fetch_billable_xact_summary($xact_id);
646 $summary->balance_owed,
648 'Remaining balance of 0.50 after payment'
651 ### Check in using Amnesty Mode
652 $checkin_resp = $script->do_checkin_override({
653 barcode => $item_barcode,
657 $checkin_resp->{ilsevent},
659 'Checkin returned a SUCCESS event'
662 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
663 if (my $item_resp = $item_req->recv) {
664 if (my $item = $item_resp->content) {
666 $item->status == 7 || $item->status == 0,
667 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
672 ### verify ending state
673 $summary = fetch_billable_xact_summary($xact_id);
675 $summary->balance_owed,
677 'Patron has a balance of 0.00 (negative balance prevented)'
681 ##############################
682 # 3. Basic No Negative Balance Test
683 ##############################
685 # Re-setup first patron
687 $patron_usrname = '99999355250';
690 if ($user_obj = retrieve_patron($patron_id)) {
693 'Fieldmapper::actor::user',
694 'open-ils.storage.direct.actor.user.retrieve returned aou object'
699 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
704 ### Setup use case variables
707 $item_barcode = 'CONC4000039';
709 # Setup Org Unit Settings
711 'bill.prohibit_negative_balance_on_overdues' => 0, #unset from previous test
712 'bill.prohibit_negative_balance_default' => 1
714 $apputils->simplereq(
716 'open-ils.actor.org_unit.settings.update',
722 $summary = fetch_billable_xact_summary($xact_id);
723 ok( $summary, 'CASE 3: Found the transaction summary');
725 $summary->balance_owed,
727 'Starting balance owed is 50.00 for lost item'
730 ### check-in the lost copy
732 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
733 if (my $item_resp = $item_req->recv) {
734 if (my $item = $item_resp->content) {
738 'Item with id = ' . $item_id . ' has status of LOST'
743 $checkin_resp = $script->do_checkin_override({
744 barcode => $item_barcode});
746 $checkin_resp->{ilsevent},
748 'Checkin returned a SUCCESS event'
751 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
752 if (my $item_resp = $item_req->recv) {
753 if (my $item = $item_resp->content) {
755 $item->status == 7 || $item->status == 0,
756 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
761 ### verify ending state
763 $summary = fetch_billable_xact_summary($xact_id);
765 $summary->balance_owed,
767 'Patron has a balance of 0.00 (negative balance prevented)'
770 ##############################
771 # 4. Prohibit Negative Balances with Partial Payment
772 ##############################
774 ### Setup use case variables
777 $item_barcode = 'CONC4000040';
779 # Setup Org Unit Settings
781 # 'bill.prohibit_negative_balance_default' => 1
783 $summary = fetch_billable_xact_summary($xact_id);
784 ok( $summary, 'CASE 4: Found the transaction summary');
786 $summary->balance_owed,
788 'Starting balance owed is 50.00 for lost item'
791 ### confirm the copy is lost
792 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
793 if (my $item_resp = $item_req->recv) {
794 if (my $item = $item_resp->content) {
798 'Item with id = ' . $item_id . ' has status of LOST'
803 ### partially pay the bill
805 userid => $patron_id,
806 note => '09-lp1198465_neg_balances.t',
807 payment_type => 'cash_payment',
808 patron_credit => '0.00',
809 payments => [ [ $xact_id, '10.00' ] ]
811 $pay_resp = pay_bills($payment_blob);
814 scalar( @{ $pay_resp->{payments} } ),
816 'Payment response included one payment id'
819 $summary = fetch_billable_xact_summary($xact_id);
821 $summary->balance_owed,
823 'Remaining balance of 40.00 after payment'
826 ### check-in the lost copy
827 $checkin_resp = $script->do_checkin_override({
828 barcode => $item_barcode});
830 $checkin_resp->{ilsevent},
832 'Checkin returned a SUCCESS event'
835 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
836 if (my $item_resp = $item_req->recv) {
837 if (my $item = $item_resp->content) {
839 $item->status == 7 || $item->status == 0,
840 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
845 ### verify ending state
847 $summary = fetch_billable_xact_summary($xact_id);
849 $summary->balance_owed,
851 'Patron has a balance of 0.00 (negative balance prevented)'
855 ##############################
856 # Restore then generate new overdues on xact with adjustments
857 ##############################
859 ### Setup use case variables
862 $item_barcode = 'CONC4000041';
864 # Setup Org Unit Settings
866 # 'bill.prohibit_negative_balance_default' => 1
868 'circ.restore_overdue_on_lost_return' => 1,
869 'circ.lost.generate_overdue_on_checkin' => 1
872 $apputils->simplereq(
874 'open-ils.actor.org_unit.settings.update',
880 $summary = fetch_billable_xact_summary($xact_id);
882 $summary->balance_owed,
884 'Starting balance owed is 50.00 for lost item'
887 $checkin_resp = $script->do_checkin_override({
888 barcode => $item_barcode
891 $checkin_resp->{ilsevent},
893 'Checkin returned a SUCCESS event'
896 ### verify ending state
897 $summary = fetch_billable_xact_summary($xact_id);
899 $summary->balance_owed,
901 'Patron has a balance of 3.00 (newly generated fines, up to maxfines)'
905 ##############################
906 # 12. Test negative balance settings on fines
907 ##############################
911 $patron_usrname = '99999387993';
914 if ($user_obj = retrieve_patron($patron_id)) {
917 'Fieldmapper::actor::user',
918 'open-ils.storage.direct.actor.user.retrieve returned aou object'
923 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
927 ### Setup use case variables
930 $item_barcode = 'CONC4000043';
932 # Setup Org Unit Settings
934 # 'bill.prohibit_negative_balance_default' => 1
936 $summary = fetch_billable_xact_summary($xact_id);
937 ok( $summary, 'CASE 12: Found the transaction summary');
939 $summary->balance_owed,
941 'Starting balance owed is 0.70 for overdue fines'
944 ### partially pay the bill
946 userid => $patron_id,
947 note => '09-lp1198465_neg_balances.t',
948 payment_type => 'cash_payment',
949 patron_credit => '0.00',
950 payments => [ [ $xact_id, '0.20' ] ]
952 $pay_resp = pay_bills($payment_blob);
955 scalar( @{ $pay_resp->{payments} } ),
957 'Payment response included one payment id'
960 $summary = fetch_billable_xact_summary($xact_id);
962 $summary->balance_owed,
964 'Remaining balance of 0.50 after payment'
967 ### Check in using Amnesty Mode
968 $checkin_resp = $script->do_checkin_override({
969 barcode => $item_barcode,
973 $checkin_resp->{ilsevent},
975 'Checkin returned a SUCCESS event'
978 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
979 if (my $item_resp = $item_req->recv) {
980 if (my $item = $item_resp->content) {
982 $item->status == 7 || $item->status == 0,
983 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
988 ### verify ending state
989 $summary = fetch_billable_xact_summary($xact_id);
991 $summary->balance_owed,
993 'Patron has a balance of 0.00 (remaining fines forgiven)'
997 ##############################
998 # 10. Interval Testing
999 ##############################
1001 # Setup Org Unit Settings
1003 # 'bill.prohibit_negative_balance_default' => 1
1005 # Setup Org Unit Settings
1007 'bill.negative_balance_interval_default' => '1 hour'
1010 $apputils->simplereq(
1012 'open-ils.actor.org_unit.settings.update',
1018 ### Setup use case variables
1021 $item_barcode = 'CONC4000044';
1023 $summary = fetch_billable_xact_summary($xact_id);
1024 ok( $summary, 'CASE 10.1: Found the transaction summary');
1026 $summary->balance_owed,
1028 'Starting balance owed is 0.00 (LOST fee paid)'
1031 ### Check in first item (right after its payment)
1032 $checkin_resp = $script->do_checkin_override({
1033 barcode => $item_barcode,
1036 $checkin_resp->{ilsevent},
1038 'Checkin returned a SUCCESS event'
1041 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1042 if (my $item_resp = $item_req->recv) {
1043 if (my $item = $item_resp->content) {
1045 $item->status == 7 || $item->status == 0,
1046 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1051 ### verify ending state for 10.1
1052 $summary = fetch_billable_xact_summary($xact_id);
1054 $summary->balance_owed,
1056 'Patron has a balance of -50.00 (lost item returned during interval)'
1059 ### Setup use case variables
1062 $item_barcode = 'CONC4000045';
1064 $summary = fetch_billable_xact_summary($xact_id);
1065 ok( $summary, 'CASE 10.2: Found the transaction summary');
1067 $summary->balance_owed,
1069 'Starting balance owed is 0.00 (LOST fee paid)'
1072 ### Check in second item (2 hours after its payment)
1073 $checkin_resp = $script->do_checkin_override({
1074 barcode => $item_barcode,
1077 $checkin_resp->{ilsevent},
1079 'Checkin returned a SUCCESS event'
1082 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1083 if (my $item_resp = $item_req->recv) {
1084 if (my $item = $item_resp->content) {
1086 $item->status == 7 || $item->status == 0,
1087 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1092 ### verify ending state
1093 $summary = fetch_billable_xact_summary($xact_id);
1095 $summary->balance_owed,
1097 'Patron has a balance of 0.00 (lost item returned after interval)'
1101 #############################
1102 # 6. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Not Owe On Lost Item Return
1103 #############################
1105 ### Setup use case variables
1108 $item_barcode = 'CONC4000046';
1110 # Setup Org Unit Settings
1112 'bill.negative_balance_interval_default' => 0, #unset previous setting
1113 'circ.void_overdue_on_lost' => 1,
1114 'circ.restore_overdue_on_lost_return' => 1,
1115 'circ.lost.generate_overdue_on_checkin' => 1
1118 $apputils->simplereq(
1120 'open-ils.actor.org_unit.settings.update',
1126 $summary = fetch_billable_xact_summary($xact_id);
1127 ok( $summary, 'CASE 6: Found the transaction summary');
1129 $summary->balance_owed,
1131 'Starting balance owed is 40.00 for partially paid lost item'
1134 ### check-in the lost copy
1136 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1137 if (my $item_resp = $item_req->recv) {
1138 if (my $item = $item_resp->content) {
1141 'Fieldmapper::asset::copy',
1142 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1147 'Item with id = ' . $item_id . ' has status of LOST'
1152 $checkin_resp = $script->do_checkin_override({
1153 barcode => $item_barcode});
1155 $checkin_resp->{ilsevent},
1157 'Checkin returned a SUCCESS event'
1160 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1161 if (my $item_resp = $item_req->recv) {
1162 if (my $item = $item_resp->content) {
1164 $item->status == 7 || $item->status == 0,
1165 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1170 ### verify ending state
1172 $summary = fetch_billable_xact_summary($xact_id);
1174 $summary->balance_owed,
1176 'Patron has a balance of 0.00 (negative balance prevented)'
1180 #############################
1181 # 7. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Still Owe On Lost Item Return
1182 #############################
1184 ### Setup use case variables
1187 $item_barcode = 'CONC4000047';
1189 # Setup Org Unit Settings
1191 # 'bill.prohibit_negative_balance_default' => 1
1192 # 'circ.void_overdue_on_lost' => 1,
1193 # 'circ.restore_overdue_on_lost_return' => 1,
1194 # 'circ.lost.generate_overdue_on_checkin' => 1
1196 $apputils->simplereq(
1198 'open-ils.actor.org_unit.settings.update',
1204 $summary = fetch_billable_xact_summary($xact_id);
1205 ok( $summary, 'CASE 7: Found the transaction summary');
1207 $summary->balance_owed,
1209 'Starting balance owed is 0.70 for overdues'
1212 ### mark item as LOST
1213 $apputils->simplereq(
1215 'open-ils.circ.circulation.set_lost',
1217 {barcode => $item_barcode}
1220 $summary = fetch_billable_xact_summary($xact_id);
1221 ok( $summary, 'Found the transaction summary');
1223 $summary->balance_owed,
1225 'New balance owed is 50.00 for LOST fee'
1228 ### partially pay the bill
1230 userid => $patron_id,
1231 note => '09-lp1198465_neg_balances.t',
1232 payment_type => 'cash_payment',
1233 patron_credit => '0.00',
1234 payments => [ [ $xact_id, '0.10' ] ]
1236 $pay_resp = pay_bills($payment_blob);
1239 scalar( @{ $pay_resp->{payments} } ),
1241 'Payment response included one payment id'
1244 $summary = fetch_billable_xact_summary($xact_id);
1246 $summary->balance_owed,
1248 'Remaining balance of 49.90 after payment'
1251 ### check-in the lost copy
1253 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1254 if (my $item_resp = $item_req->recv) {
1255 if (my $item = $item_resp->content) {
1258 'Fieldmapper::asset::copy',
1259 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1264 'Item with id = ' . $item_id . ' has status of LOST'
1269 $checkin_resp = $script->do_checkin_override({
1270 barcode => $item_barcode});
1272 $checkin_resp->{ilsevent},
1274 'Checkin returned a SUCCESS event'
1277 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1278 if (my $item_resp = $item_req->recv) {
1279 if (my $item = $item_resp->content) {
1281 $item->status == 7 || $item->status == 0,
1282 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1287 ### verify ending state
1289 $summary = fetch_billable_xact_summary($xact_id);
1291 $summary->balance_owed,
1293 'Patron has a balance of 0.60 due to reinstated overdue fines'
1297 #############################
1298 # 9. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1299 #############################
1301 ### Setup use case variables
1304 $item_barcode = 'CONC4000048';
1306 # Setup Org Unit Settings
1308 # 'bill.prohibit_negative_balance_default' => 1
1309 # 'circ.void_overdue_on_lost' => 1,
1310 # 'circ.restore_overdue_on_lost_return' => 1,
1311 # 'circ.lost.generate_overdue_on_checkin' => 1
1313 $apputils->simplereq(
1315 'open-ils.actor.org_unit.settings.update',
1321 $summary = fetch_billable_xact_summary($xact_id);
1322 ok( $summary, 'CASE 9: Found the transaction summary');
1324 $summary->balance_owed,
1326 'Starting balance owed is 50.00 for lost item'
1329 ### partially pay the bill
1331 userid => $patron_id,
1332 note => '09-lp1198465_neg_balances.t',
1333 payment_type => 'cash_payment',
1334 patron_credit => '0.00',
1335 payments => [ [ $xact_id, '10.00' ] ]
1337 $pay_resp = pay_bills($payment_blob);
1340 scalar( @{ $pay_resp->{payments} } ),
1342 'Payment response included one payment id'
1345 $summary = fetch_billable_xact_summary($xact_id);
1347 $summary->balance_owed,
1349 'Remaining balance of 40.00 after payment'
1352 ### check-in the lost copy
1354 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1355 if (my $item_resp = $item_req->recv) {
1356 if (my $item = $item_resp->content) {
1359 'Fieldmapper::asset::copy',
1360 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1365 'Item with id = ' . $item_id . ' has status of LOST'
1370 $checkin_resp = $script->do_checkin_override({
1371 barcode => $item_barcode});
1373 $checkin_resp->{ilsevent},
1375 'Checkin returned a SUCCESS event'
1378 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1379 if (my $item_resp = $item_req->recv) {
1380 if (my $item = $item_resp->content) {
1382 $item->status == 7 || $item->status == 0,
1383 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1388 ### verify ending state
1390 $summary = fetch_billable_xact_summary($xact_id);
1392 $summary->balance_owed,
1394 'Patron has a balance of 0.00 (negative balance prevented)'
1398 #############################
1399 # 8. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1400 #############################
1402 ## TODO: consider using a later xact_id/item_id, instead of reverting back to user 4
1404 # Setup first patron (again)
1406 $patron_usrname = '99999355250';
1408 # Look up the patron
1409 if ($user_obj = retrieve_patron($patron_id)) {
1412 'Fieldmapper::actor::user',
1413 'open-ils.storage.direct.actor.user.retrieve returned aou object'
1418 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
1422 ### Setup use case variables
1425 $item_barcode = 'CONC4000042';
1427 # Setup Org Unit Settings
1429 # 'circ.void_overdue_on_lost' => 1,
1430 # 'circ.restore_overdue_on_lost_return' => 1,
1431 # 'circ.lost.generate_overdue_on_checkin' => 1
1433 'bill.prohibit_negative_balance_default' => 0
1436 $apputils->simplereq(
1438 'open-ils.actor.org_unit.settings.update',
1444 $summary = fetch_billable_xact_summary($xact_id);
1445 ok( $summary, 'CASE 8: Found the transaction summary');
1447 $summary->balance_owed,
1449 'Starting balance owed is 50.00 for lost item'
1452 ### partially pay the bill
1454 userid => $patron_id,
1455 note => '09-lp1198465_neg_balances.t',
1456 payment_type => 'cash_payment',
1457 patron_credit => '0.00',
1458 payments => [ [ $xact_id, '10.00' ] ]
1460 $pay_resp = pay_bills($payment_blob);
1463 scalar( @{ $pay_resp->{payments} } ),
1465 'Payment response included one payment id'
1468 $summary = fetch_billable_xact_summary($xact_id);
1470 $summary->balance_owed,
1472 'Remaining balance of 40.00 after payment'
1475 ### check-in the lost copy
1477 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1478 if (my $item_resp = $item_req->recv) {
1479 if (my $item = $item_resp->content) {
1482 'Fieldmapper::asset::copy',
1483 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1488 'Item with id = ' . $item_id . ' has status of LOST'
1493 $checkin_resp = $script->do_checkin_override({
1494 barcode => $item_barcode});
1496 $checkin_resp->{ilsevent},
1498 'Checkin returned a SUCCESS event'
1501 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1502 if (my $item_resp = $item_req->recv) {
1503 if (my $item = $item_resp->content) {
1505 $item->status == 7 || $item->status == 0,
1506 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1511 ### verify ending state
1513 $summary = fetch_billable_xact_summary($xact_id);
1515 $summary->balance_owed,
1517 'Patron has a negative balance of 7.00 due to overpayment'