3 use Test::More tests => 129;
5 diag("Test features of Conditional Negative Balances code.");
7 use constant WORKSTATION_NAME => 'BR1-test-09-lp1198465_neg_balances.t';
8 use constant WORKSTATION_LIB => 4;
10 use strict; use warnings;
13 use DateTime::Format::ISO8601;
14 use OpenSRF::Utils qw/cleanse_ISO8601/;
15 use OpenILS::Utils::TestUtils;
16 my $script = OpenILS::Utils::TestUtils->new();
19 our $apputils = "OpenILS::Application::AppUtils";
21 my ($patron_id, $patron_usrname, $xact_id, $item_id, $item_barcode);
22 my ($summary, $payment_blob, $pay_resp, $item_req, $checkin_resp);
24 my $storage_ses = $script->session('open-ils.storage');
28 my $patron_id = shift;
30 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', $patron_id);
31 if (my $user_resp = $user_req->recv) {
32 if (my $patron_obj = $user_resp->content) {
39 sub fetch_billable_xact_summary {
41 my $ses = $script->session('open-ils.cstore');
42 my $req = $ses->request(
43 'open-ils.cstore.direct.money.billable_transaction_summary.retrieve',
46 if (my $resp = $req->recv) {
47 return $resp->content;
54 my $payment_blob = shift;
55 my $resp = $apputils->simplereq(
57 'open-ils.circ.money.payment',
60 $user_obj->last_xact_id
63 #refetch user_obj to get latest last_xact_id
64 $user_obj = retrieve_patron($patron_id)
65 or die 'Could not refetch patron';
71 my $billing_ids = shift; #array ref
72 my $resp = $apputils->simplereq(
74 'open-ils.circ.money.billing.void',
82 #----------------------------------------------------------------
83 # The tests... assumes stock sample data, full-auto install by
84 # eg_wheezy_installer.sh, etc.
85 #----------------------------------------------------------------
87 # Connect to Evergreen
88 $script->authenticate({
90 password => 'demo123',
92 ok( $script->authtoken, 'Have an authtoken');
94 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
95 ok( ! ref $ws, 'Registered a new workstation');
98 $script->authenticate({
100 password => 'demo123',
102 workstation => WORKSTATION_NAME});
103 ok( $script->authtoken, 'Have an authtoken associated with the workstation');
106 ### TODO: verify that stock data is ready for testing
108 ### Setup Org Unit Settings that apply to all test cases
110 my $org_id = 1; #CONS
112 'circ.max_item_price' => 50,
113 'circ.min_item_price' => 50,
114 'circ.void_lost_on_checkin' => 1
117 $apputils->simplereq(
119 'open-ils.actor.org_unit.settings.update',
127 $patron_usrname = '99999355250';
130 if ($user_obj = retrieve_patron($patron_id)) {
133 'Fieldmapper::actor::user',
134 'open-ils.storage.direct.actor.user.retrieve returned aou object'
139 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
144 ##############################
145 # 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
146 ##############################
148 ### Setup use case variables
151 $item_barcode = 'CONC4000037';
153 $summary = fetch_billable_xact_summary($xact_id);
154 ok( $summary, 'CASE 1: Found the transaction summary');
156 $summary->balance_owed,
158 'Starting balance owed is 50.00 for lost item'
161 ### pay the whole bill
163 userid => $patron_id,
164 note => '09-lp1198465_neg_balances.t',
165 payment_type => 'cash_payment',
166 patron_credit => '0.00',
167 payments => [ [ $xact_id, '50.00' ] ]
169 $pay_resp = pay_bills($payment_blob);
172 scalar( @{ $pay_resp->{payments} } ),
174 'Payment response included one payment id'
177 $summary = fetch_billable_xact_summary($xact_id);
179 $summary->balance_owed,
181 'Remaining balance of 0.00 after payment'
184 ### check-in the lost copy
186 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
187 if (my $item_resp = $item_req->recv) {
188 if (my $item = $item_resp->content) {
191 'Fieldmapper::asset::copy',
192 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
197 'Item with id = ' . $item_id . ' has status of LOST'
202 $checkin_resp = $script->do_checkin_override({
203 barcode => $item_barcode});
205 $checkin_resp->{ilsevent},
207 'Checkin returned a SUCCESS event'
210 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
211 if (my $item_resp = $item_req->recv) {
212 if (my $item = $item_resp->content) {
214 $item->status == 7 || $item->status == 0,
215 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
220 ### verify ending state
222 $summary = fetch_billable_xact_summary($xact_id);
224 $summary->balance_owed,
226 'Patron has a negative balance (credit) of 50.00 due to overpayment'
230 ##############################
231 # 2. Negative Balance Settings Are Unset, No Payment Made
232 ##############################
234 ### Setup use case variables
237 $item_barcode = 'CONC4000038';
239 $summary = fetch_billable_xact_summary($xact_id);
240 ok( $summary, 'CASE 2: Found the transaction summary');
242 $summary->balance_owed,
244 'Starting balance owed is 50.00 for lost item'
247 ### check-in the lost copy
249 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
250 if (my $item_resp = $item_req->recv) {
251 if (my $item = $item_resp->content) {
255 'Item with id = ' . $item_id . ' has status of LOST'
260 $checkin_resp = $script->do_checkin_override({
261 barcode => $item_barcode});
263 $checkin_resp->{ilsevent},
265 'Checkin returned a SUCCESS event'
268 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
269 if (my $item_resp = $item_req->recv) {
270 if (my $item = $item_resp->content) {
272 $item->status == 7 || $item->status == 0,
273 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
278 ### verify ending state
280 $summary = fetch_billable_xact_summary($xact_id);
282 $summary->balance_owed,
284 'Patron has a balance of 0.00'
288 ##############################
289 # 13. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
290 # SETTINGS: Prohibit negative balances on bills for lost materials
291 ##############################
295 $patron_usrname = '99999335859';
298 if ($user_obj = retrieve_patron($patron_id)) {
301 'Fieldmapper::actor::user',
302 'open-ils.storage.direct.actor.user.retrieve returned aou object'
307 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
311 ### Setup use case variables
314 $item_barcode = 'CONC4000049';
316 # Setup Org Unit Settings
318 'bill.prohibit_negative_balance_on_lost' => 1
320 $apputils->simplereq(
322 'open-ils.actor.org_unit.settings.update',
328 $summary = fetch_billable_xact_summary($xact_id);
329 ok( $summary, 'CASE 13a: Found the transaction summary');
331 $summary->balance_owed,
333 'Starting balance owed is 50.00 for lost item'
336 ### pay the whole bill
338 userid => $patron_id,
339 note => '09-lp1198465_neg_balances.t',
340 payment_type => 'cash_payment',
341 patron_credit => '0.00',
342 payments => [ [ $xact_id, '50.00' ] ]
344 $pay_resp = pay_bills($payment_blob);
347 scalar( @{ $pay_resp->{payments} } ),
349 'Payment response included one payment id'
352 $summary = fetch_billable_xact_summary($xact_id);
354 $summary->balance_owed,
356 'Remaining balance of 0.00 after payment'
359 ### check-in the lost copy
361 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
362 if (my $item_resp = $item_req->recv) {
363 if (my $item = $item_resp->content) {
366 'Fieldmapper::asset::copy',
367 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
372 'Item with id = ' . $item_id . ' has status of LOST'
377 $checkin_resp = $script->do_checkin_override({
378 barcode => $item_barcode});
380 $checkin_resp->{ilsevent},
382 'Checkin returned a SUCCESS event'
385 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
386 if (my $item_resp = $item_req->recv) {
387 if (my $item = $item_resp->content) {
389 $item->status == 7 || $item->status == 0,
390 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
395 ### verify ending state
397 $summary = fetch_billable_xact_summary($xact_id);
399 $summary->balance_owed,
401 'Patron has a balance of 0.00 (negative balance prevented)'
405 ##############################
406 # 13. RERUN of Case 12. Test negative balance settings on fines
407 # SETTINGS: Prohibit negative balances on bills for lost materials
408 ##############################
410 ### Setup use case variables
413 $item_barcode = 'CONC4000050';
415 # Setup Org Unit Settings
417 # 'bill.prohibit_negative_balance_on_lost' => 1
419 $summary = fetch_billable_xact_summary($xact_id);
420 ok( $summary, 'CASE 13b: Found the transaction summary');
422 $summary->balance_owed,
424 'Starting balance owed is 0.70 for overdue fines'
427 ### partially pay the bill
429 userid => $patron_id,
430 note => '09-lp1198465_neg_balances.t',
431 payment_type => 'cash_payment',
432 patron_credit => '0.00',
433 payments => [ [ $xact_id, '0.20' ] ]
435 $pay_resp = pay_bills($payment_blob);
438 scalar( @{ $pay_resp->{payments} } ),
440 'Payment response included one payment id'
443 $summary = fetch_billable_xact_summary($xact_id);
445 $summary->balance_owed,
447 'Remaining balance of 0.50 after payment'
450 ### Check in using Amnesty Mode
451 $checkin_resp = $script->do_checkin_override({
452 barcode => $item_barcode,
456 $checkin_resp->{ilsevent},
458 'Checkin returned a SUCCESS event'
461 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
462 if (my $item_resp = $item_req->recv) {
463 if (my $item = $item_resp->content) {
465 $item->status == 7 || $item->status == 0,
466 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
471 ### verify ending state
472 $summary = fetch_billable_xact_summary($xact_id);
474 $summary->balance_owed,
476 'Patron has a negative balance of -0.20 (refund of overdue fine payment)'
480 ##############################
481 # 14. RERUN of Case 1. No Prohibit Negative Balance Settings Are Enabled, Payment Made
482 # SETTINGS: Prohibit negative balances on bills for overdue materials
483 ##############################
485 ### Setup use case variables
488 $item_barcode = 'CONC4000051';
490 # Setup Org Unit Settings
492 'bill.prohibit_negative_balance_on_lost' => 0, #unset from previous test
493 'bill.prohibit_negative_balance_on_overdues' => 1
495 $apputils->simplereq(
497 'open-ils.actor.org_unit.settings.update',
503 $summary = fetch_billable_xact_summary($xact_id);
504 ok( $summary, 'CASE 14a: Found the transaction summary');
506 $summary->balance_owed,
508 'Starting balance owed is 50.00 for lost item'
511 ### pay the whole bill
513 userid => $patron_id,
514 note => '09-lp1198465_neg_balances.t',
515 payment_type => 'cash_payment',
516 patron_credit => '0.00',
517 payments => [ [ $xact_id, '50.00' ] ]
519 $pay_resp = pay_bills($payment_blob);
522 scalar( @{ $pay_resp->{payments} } ),
524 'Payment response included one payment id'
527 $summary = fetch_billable_xact_summary($xact_id);
529 $summary->balance_owed,
531 'Remaining balance of 0.00 after payment'
535 $summary->xact_finish ne '',
536 'xact_finish is set due to 0.00 balance'
539 ### check-in the lost copy
541 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
542 if (my $item_resp = $item_req->recv) {
543 if (my $item = $item_resp->content) {
546 'Fieldmapper::asset::copy',
547 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
552 'Item with id = ' . $item_id . ' has status of LOST'
557 $checkin_resp = $script->do_checkin_override({
558 barcode => $item_barcode});
560 $checkin_resp->{ilsevent},
562 'Checkin returned a SUCCESS event'
565 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
566 if (my $item_resp = $item_req->recv) {
567 if (my $item = $item_resp->content) {
569 $item->status == 7 || $item->status == 0,
570 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
575 ### verify ending state
577 $summary = fetch_billable_xact_summary($xact_id);
579 $summary->balance_owed,
581 'Patron has a negative balance (credit) of 50.00 due to overpayment'
585 !defined($summary->xact_finish),
586 'xact_finish is not set due to non-zero balance'
590 ##############################
591 # 14. RERUN of Case 12. Test negative balance settings on fines
592 # SETTINGS: Prohibit negative balances on bills for overdue materials
593 ##############################
595 ### Setup use case variables
598 $item_barcode = 'CONC4000052';
600 # Setup Org Unit Settings
602 # 'bill.prohibit_negative_balance_on_overdues' => 1
604 $summary = fetch_billable_xact_summary($xact_id);
605 ok( $summary, 'CASE 14b: Found the transaction summary');
607 $summary->balance_owed,
609 'Starting balance owed is 0.70 for overdue fines'
612 ### partially pay the bill
614 userid => $patron_id,
615 note => '09-lp1198465_neg_balances.t',
616 payment_type => 'cash_payment',
617 patron_credit => '0.00',
618 payments => [ [ $xact_id, '0.20' ] ]
620 $pay_resp = pay_bills($payment_blob);
623 scalar( @{ $pay_resp->{payments} } ),
625 'Payment response included one payment id'
628 $summary = fetch_billable_xact_summary($xact_id);
630 $summary->balance_owed,
632 'Remaining balance of 0.50 after payment'
635 ### Check in using Amnesty Mode
636 $checkin_resp = $script->do_checkin_override({
637 barcode => $item_barcode,
641 $checkin_resp->{ilsevent},
643 'Checkin returned a SUCCESS event'
646 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
647 if (my $item_resp = $item_req->recv) {
648 if (my $item = $item_resp->content) {
650 $item->status == 7 || $item->status == 0,
651 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
656 ### verify ending state
657 $summary = fetch_billable_xact_summary($xact_id);
659 $summary->balance_owed,
661 'Patron has a balance of 0.00 (negative balance prevented)'
665 ##############################
666 # 3. Basic No Negative Balance Test
667 ##############################
669 # Re-setup first patron
671 $patron_usrname = '99999355250';
674 if ($user_obj = retrieve_patron($patron_id)) {
677 'Fieldmapper::actor::user',
678 'open-ils.storage.direct.actor.user.retrieve returned aou object'
683 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
688 ### Setup use case variables
691 $item_barcode = 'CONC4000039';
693 # Setup Org Unit Settings
695 'bill.prohibit_negative_balance_on_overdues' => 0, #unset from previous test
696 'bill.prohibit_negative_balance_default' => 1
698 $apputils->simplereq(
700 'open-ils.actor.org_unit.settings.update',
706 $summary = fetch_billable_xact_summary($xact_id);
707 ok( $summary, 'CASE 3: Found the transaction summary');
709 $summary->balance_owed,
711 'Starting balance owed is 50.00 for lost item'
714 ### check-in the lost copy
716 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
717 if (my $item_resp = $item_req->recv) {
718 if (my $item = $item_resp->content) {
722 'Item with id = ' . $item_id . ' has status of LOST'
727 $checkin_resp = $script->do_checkin_override({
728 barcode => $item_barcode});
730 $checkin_resp->{ilsevent},
732 'Checkin returned a SUCCESS event'
735 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
736 if (my $item_resp = $item_req->recv) {
737 if (my $item = $item_resp->content) {
739 $item->status == 7 || $item->status == 0,
740 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
745 ### verify ending state
747 $summary = fetch_billable_xact_summary($xact_id);
749 $summary->balance_owed,
751 'Patron has a balance of 0.00 (negative balance prevented)'
754 ##############################
755 # 4. Prohibit Negative Balances with Partial Payment
756 ##############################
758 ### Setup use case variables
761 $item_barcode = 'CONC4000040';
763 # Setup Org Unit Settings
765 # 'bill.prohibit_negative_balance_default' => 1
767 $summary = fetch_billable_xact_summary($xact_id);
768 ok( $summary, 'CASE 4: Found the transaction summary');
770 $summary->balance_owed,
772 'Starting balance owed is 50.00 for lost item'
775 ### confirm the copy is lost
776 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
777 if (my $item_resp = $item_req->recv) {
778 if (my $item = $item_resp->content) {
782 'Item with id = ' . $item_id . ' has status of LOST'
787 ### partially pay the bill
789 userid => $patron_id,
790 note => '09-lp1198465_neg_balances.t',
791 payment_type => 'cash_payment',
792 patron_credit => '0.00',
793 payments => [ [ $xact_id, '10.00' ] ]
795 $pay_resp = pay_bills($payment_blob);
798 scalar( @{ $pay_resp->{payments} } ),
800 'Payment response included one payment id'
803 $summary = fetch_billable_xact_summary($xact_id);
805 $summary->balance_owed,
807 'Remaining balance of 40.00 after payment'
810 ### check-in the lost copy
811 $checkin_resp = $script->do_checkin_override({
812 barcode => $item_barcode});
814 $checkin_resp->{ilsevent},
816 'Checkin returned a SUCCESS event'
819 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
820 if (my $item_resp = $item_req->recv) {
821 if (my $item = $item_resp->content) {
823 $item->status == 7 || $item->status == 0,
824 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
829 ### verify ending state
831 $summary = fetch_billable_xact_summary($xact_id);
833 $summary->balance_owed,
835 'Patron has a balance of 0.00 (negative balance prevented)'
839 ###############################
840 ## 11. Manually voiding lost book fee does not result in negative balances
841 ###############################
843 #### Setup use case variables
846 #$item_barcode = 'CONC4000040';
848 ## Setup Org Unit Settings
850 # 'bill.prohibit_negative_balance_default' => 1
852 #$summary = fetch_billable_xact_summary($xact_id);
853 #ok( $summary, 'CASE 11: Found the transaction summary');
855 # $summary->balance_owed,
857 # 'Starting balance owed is 50.00 for lost item'
860 #### confirm the copy is lost
861 #$item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
862 #if (my $item_resp = $item_req->recv) {
863 # if (my $item = $item_resp->content) {
867 # 'Item with id = ' . $item_id . ' has status of LOST'
872 #### partially pay the bill
874 # userid => $patron_id,
875 # note => '09-lp1198465_neg_balances.t',
876 # payment_type => 'cash_payment',
877 # patron_credit => '0.00',
878 # payments => [ [ $xact_id, '10.00' ] ]
880 #$pay_resp = pay_bills($payment_blob);
883 # scalar( @{ $pay_resp->{payments} } ),
885 # 'Payment response included one payment id'
888 #$summary = fetch_billable_xact_summary($xact_id);
890 # $summary->balance_owed,
892 # 'Remaining balance of 40.00 after payment'
895 #### TODO: manually void "the rest" of the bill (i.e. prevent neg bal)
896 #### XXX: HARDCODING billing id for now; should look up the LOST bill for this xact?
897 #my @billing_ids = (6);
898 #my $void_resp = void_bills(\@billing_ids);
903 # 'Voiding was successful'
906 #### verify ending state
908 #$summary = fetch_billable_xact_summary($xact_id);
910 # $summary->balance_owed,
912 # 'Patron has a balance of 0.00 (negative balance prohibited)'
916 ##############################
917 # 12. Test negative balance settings on fines
918 ##############################
922 $patron_usrname = '99999387993';
925 if ($user_obj = retrieve_patron($patron_id)) {
928 'Fieldmapper::actor::user',
929 'open-ils.storage.direct.actor.user.retrieve returned aou object'
934 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
938 ### Setup use case variables
941 $item_barcode = 'CONC4000043';
943 # Setup Org Unit Settings
945 # 'bill.prohibit_negative_balance_default' => 1
947 $summary = fetch_billable_xact_summary($xact_id);
948 ok( $summary, 'CASE 12: Found the transaction summary');
950 $summary->balance_owed,
952 'Starting balance owed is 0.70 for overdue fines'
955 ### partially pay the bill
957 userid => $patron_id,
958 note => '09-lp1198465_neg_balances.t',
959 payment_type => 'cash_payment',
960 patron_credit => '0.00',
961 payments => [ [ $xact_id, '0.20' ] ]
963 $pay_resp = pay_bills($payment_blob);
966 scalar( @{ $pay_resp->{payments} } ),
968 'Payment response included one payment id'
971 $summary = fetch_billable_xact_summary($xact_id);
973 $summary->balance_owed,
975 'Remaining balance of 0.50 after payment'
978 ### Check in using Amnesty Mode
979 $checkin_resp = $script->do_checkin_override({
980 barcode => $item_barcode,
984 $checkin_resp->{ilsevent},
986 'Checkin returned a SUCCESS event'
989 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
990 if (my $item_resp = $item_req->recv) {
991 if (my $item = $item_resp->content) {
993 $item->status == 7 || $item->status == 0,
994 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
999 ### verify ending state
1000 $summary = fetch_billable_xact_summary($xact_id);
1002 $summary->balance_owed,
1004 'Patron has a balance of 0.00 (remaining fines forgiven)'
1008 ##############################
1009 # 10. Interval Testing
1010 ##############################
1012 # Setup Org Unit Settings
1014 # 'bill.prohibit_negative_balance_default' => 1
1016 # Setup Org Unit Settings
1018 'bill.negative_balance_interval_default' => '1 hour'
1021 $apputils->simplereq(
1023 'open-ils.actor.org_unit.settings.update',
1029 ### Setup use case variables
1032 $item_barcode = 'CONC4000044';
1034 $summary = fetch_billable_xact_summary($xact_id);
1035 ok( $summary, 'CASE 10.1: Found the transaction summary');
1037 $summary->balance_owed,
1039 'Starting balance owed is 0.00 (LOST fee paid)'
1042 ### Check in first item (right after its payment)
1043 $checkin_resp = $script->do_checkin_override({
1044 barcode => $item_barcode,
1047 $checkin_resp->{ilsevent},
1049 'Checkin returned a SUCCESS event'
1052 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1053 if (my $item_resp = $item_req->recv) {
1054 if (my $item = $item_resp->content) {
1056 $item->status == 7 || $item->status == 0,
1057 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1062 ### verify ending state for 10.1
1063 $summary = fetch_billable_xact_summary($xact_id);
1065 $summary->balance_owed,
1067 'Patron has a balance of -50.00 (lost item returned during interval)'
1070 ### Setup use case variables
1073 $item_barcode = 'CONC4000045';
1075 $summary = fetch_billable_xact_summary($xact_id);
1076 ok( $summary, 'CASE 10.2: Found the transaction summary');
1078 $summary->balance_owed,
1080 'Starting balance owed is 0.00 (LOST fee paid)'
1083 ### Check in second item (2 hours after its payment)
1084 $checkin_resp = $script->do_checkin_override({
1085 barcode => $item_barcode,
1088 $checkin_resp->{ilsevent},
1090 'Checkin returned a SUCCESS event'
1093 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1094 if (my $item_resp = $item_req->recv) {
1095 if (my $item = $item_resp->content) {
1097 $item->status == 7 || $item->status == 0,
1098 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1103 ### verify ending state
1104 $summary = fetch_billable_xact_summary($xact_id);
1106 $summary->balance_owed,
1108 'Patron has a balance of 0.00 (lost item returned after interval)'
1112 #############################
1113 # 6. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Not Owe On Lost Item Return
1114 #############################
1116 ### Setup use case variables
1119 $item_barcode = 'CONC4000046';
1121 # Setup Org Unit Settings
1123 'bill.negative_balance_interval_default' => 0, #unset previous setting
1124 'circ.void_overdue_on_lost' => 1,
1125 'circ.restore_overdue_on_lost_return' => 1,
1126 'circ.lost.generate_overdue_on_checkin' => 1
1129 $apputils->simplereq(
1131 'open-ils.actor.org_unit.settings.update',
1137 $summary = fetch_billable_xact_summary($xact_id);
1138 ok( $summary, 'CASE 6: Found the transaction summary');
1140 $summary->balance_owed,
1142 'Starting balance owed is 40.00 for partially paid lost item'
1145 ### check-in the lost copy
1147 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1148 if (my $item_resp = $item_req->recv) {
1149 if (my $item = $item_resp->content) {
1152 'Fieldmapper::asset::copy',
1153 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1158 'Item with id = ' . $item_id . ' has status of LOST'
1163 $checkin_resp = $script->do_checkin_override({
1164 barcode => $item_barcode});
1166 $checkin_resp->{ilsevent},
1168 'Checkin returned a SUCCESS event'
1171 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1172 if (my $item_resp = $item_req->recv) {
1173 if (my $item = $item_resp->content) {
1175 $item->status == 7 || $item->status == 0,
1176 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1181 ### verify ending state
1183 $summary = fetch_billable_xact_summary($xact_id);
1185 $summary->balance_owed,
1187 'Patron has a balance of 0.00 (negative balance prevented)'
1191 #############################
1192 # 7. Restores Overdue Fines Appropriately, No Previous "Voids", Patron Will Still Owe On Lost Item Return
1193 #############################
1195 ### Setup use case variables
1198 $item_barcode = 'CONC4000047';
1200 # Setup Org Unit Settings
1202 # 'bill.prohibit_negative_balance_default' => 1
1203 # 'circ.void_overdue_on_lost' => 1,
1204 # 'circ.restore_overdue_on_lost_return' => 1,
1205 # 'circ.lost.generate_overdue_on_checkin' => 1
1207 $apputils->simplereq(
1209 'open-ils.actor.org_unit.settings.update',
1215 $summary = fetch_billable_xact_summary($xact_id);
1216 ok( $summary, 'CASE 7: Found the transaction summary');
1218 $summary->balance_owed,
1220 'Starting balance owed is 0.70 for overdues'
1223 ### mark item as LOST
1224 $apputils->simplereq(
1226 'open-ils.circ.circulation.set_lost',
1228 {barcode => $item_barcode}
1231 $summary = fetch_billable_xact_summary($xact_id);
1232 ok( $summary, 'Found the transaction summary');
1234 $summary->balance_owed,
1236 'New balance owed is 50.00 for LOST fee'
1239 ### partially pay the bill
1241 userid => $patron_id,
1242 note => '09-lp1198465_neg_balances.t',
1243 payment_type => 'cash_payment',
1244 patron_credit => '0.00',
1245 payments => [ [ $xact_id, '0.10' ] ]
1247 $pay_resp = pay_bills($payment_blob);
1250 scalar( @{ $pay_resp->{payments} } ),
1252 'Payment response included one payment id'
1255 $summary = fetch_billable_xact_summary($xact_id);
1257 $summary->balance_owed,
1259 'Remaining balance of 49.90 after payment'
1262 ### check-in the lost copy
1264 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1265 if (my $item_resp = $item_req->recv) {
1266 if (my $item = $item_resp->content) {
1269 'Fieldmapper::asset::copy',
1270 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1275 'Item with id = ' . $item_id . ' has status of LOST'
1280 $checkin_resp = $script->do_checkin_override({
1281 barcode => $item_barcode});
1283 $checkin_resp->{ilsevent},
1285 'Checkin returned a SUCCESS event'
1288 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1289 if (my $item_resp = $item_req->recv) {
1290 if (my $item = $item_resp->content) {
1292 $item->status == 7 || $item->status == 0,
1293 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1298 ### verify ending state
1300 $summary = fetch_billable_xact_summary($xact_id);
1302 $summary->balance_owed,
1304 'Patron has a balance of 0.60 due to reinstated overdue fines'
1308 #############################
1309 # 9. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1310 #############################
1312 ### Setup use case variables
1315 $item_barcode = 'CONC4000048';
1317 # Setup Org Unit Settings
1319 # 'bill.prohibit_negative_balance_default' => 1
1320 # 'circ.void_overdue_on_lost' => 1,
1321 # 'circ.restore_overdue_on_lost_return' => 1,
1322 # 'circ.lost.generate_overdue_on_checkin' => 1
1324 $apputils->simplereq(
1326 'open-ils.actor.org_unit.settings.update',
1332 $summary = fetch_billable_xact_summary($xact_id);
1333 ok( $summary, 'CASE 9: Found the transaction summary');
1335 $summary->balance_owed,
1337 'Starting balance owed is 50.00 for lost item'
1340 ### partially pay the bill
1342 userid => $patron_id,
1343 note => '09-lp1198465_neg_balances.t',
1344 payment_type => 'cash_payment',
1345 patron_credit => '0.00',
1346 payments => [ [ $xact_id, '10.00' ] ]
1348 $pay_resp = pay_bills($payment_blob);
1351 scalar( @{ $pay_resp->{payments} } ),
1353 'Payment response included one payment id'
1356 $summary = fetch_billable_xact_summary($xact_id);
1358 $summary->balance_owed,
1360 'Remaining balance of 40.00 after payment'
1363 ### check-in the lost copy
1365 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1366 if (my $item_resp = $item_req->recv) {
1367 if (my $item = $item_resp->content) {
1370 'Fieldmapper::asset::copy',
1371 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1376 'Item with id = ' . $item_id . ' has status of LOST'
1381 $checkin_resp = $script->do_checkin_override({
1382 barcode => $item_barcode});
1384 $checkin_resp->{ilsevent},
1386 'Checkin returned a SUCCESS event'
1389 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1390 if (my $item_resp = $item_req->recv) {
1391 if (my $item = $item_resp->content) {
1393 $item->status == 7 || $item->status == 0,
1394 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1399 ### verify ending state
1401 $summary = fetch_billable_xact_summary($xact_id);
1403 $summary->balance_owed,
1405 'Patron has a balance of 0.00 (negative balance prevented)'
1409 #############################
1410 # 8. Restore Overdue Fines Appropriately, Previous Voids, Negative Balance Allowed
1411 #############################
1413 ## TODO: consider using a later xact_id/item_id, instead of reverting back to user 4
1415 # Setup first patron (again)
1417 $patron_usrname = '99999355250';
1419 # Look up the patron
1420 if ($user_obj = retrieve_patron($patron_id)) {
1423 'Fieldmapper::actor::user',
1424 'open-ils.storage.direct.actor.user.retrieve returned aou object'
1429 'Patron with id = ' . $patron_id . ' has username ' . $patron_usrname
1433 ### Setup use case variables
1436 $item_barcode = 'CONC4000042';
1438 # Setup Org Unit Settings
1440 # 'circ.void_overdue_on_lost' => 1,
1441 # 'circ.restore_overdue_on_lost_return' => 1,
1442 # 'circ.lost.generate_overdue_on_checkin' => 1
1444 'bill.prohibit_negative_balance_default' => 0
1447 $apputils->simplereq(
1449 'open-ils.actor.org_unit.settings.update',
1455 $summary = fetch_billable_xact_summary($xact_id);
1456 ok( $summary, 'CASE 8: Found the transaction summary');
1458 $summary->balance_owed,
1460 'Starting balance owed is 50.00 for lost item'
1463 ### partially pay the bill
1465 userid => $patron_id,
1466 note => '09-lp1198465_neg_balances.t',
1467 payment_type => 'cash_payment',
1468 patron_credit => '0.00',
1469 payments => [ [ $xact_id, '10.00' ] ]
1471 $pay_resp = pay_bills($payment_blob);
1474 scalar( @{ $pay_resp->{payments} } ),
1476 'Payment response included one payment id'
1479 $summary = fetch_billable_xact_summary($xact_id);
1481 $summary->balance_owed,
1483 'Remaining balance of 40.00 after payment'
1486 ### check-in the lost copy
1488 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1489 if (my $item_resp = $item_req->recv) {
1490 if (my $item = $item_resp->content) {
1493 'Fieldmapper::asset::copy',
1494 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
1499 'Item with id = ' . $item_id . ' has status of LOST'
1504 $checkin_resp = $script->do_checkin_override({
1505 barcode => $item_barcode});
1507 $checkin_resp->{ilsevent},
1509 'Checkin returned a SUCCESS event'
1512 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', $item_id);
1513 if (my $item_resp = $item_req->recv) {
1514 if (my $item = $item_resp->content) {
1516 $item->status == 7 || $item->status == 0,
1517 'Item with id = ' . $item_id . ' has status of Reshelving or Available after fresh Storage request'
1522 ### verify ending state
1524 $summary = fetch_billable_xact_summary($xact_id);
1526 $summary->balance_owed,
1528 'Patron has a negative balance of 7.00 due to overpayment'