/
);
+
sub void_bill {
- my( $s, $c, $authtoken, $billid ) = @_;
+ my( $s, $c, $authtoken, @billids ) = @_;
- #my $e = OpenILS::Utils::Editor->new( authtoken => $authtoken );
my $e = new_editor( authtoken => $authtoken, xact => 1 );
return $e->event unless $e->checkauth;
return $e->event unless $e->allowed('VOID_BILLING');
- my $bill = $e->retrieve_money_billing($billid)
- or return $e->event;
-
- return OpenILS::Event->new('BILL_ALREADY_VOIDED', payload => $bill)
- if $bill->voided and $bill->voided =~ /t/io;
-
- $bill->voided('t');
- $bill->voider($e->requestor->id);
- $bill->void_time('now');
-
- $e->update_money_billing($bill) or return $e->event;
- my $evt = _check_open_xact($e, $bill->xact);
- return $evt if $evt;
+ my %users;
+ for my $billid (@billids) {
+
+ my $bill = $e->retrieve_money_billing($billid)
+ or return $e->event;
+
+ my $xact = $e->retrieve_money_billable_transaction($bill->xact)
+ or return $e->event;
+
+ $users{$xact->usr} = 1;
+
+ return OpenILS::Event->new('BILL_ALREADY_VOIDED', payload => $bill)
+ if $bill->voided and $bill->voided =~ /t/io;
+
+ $bill->voided('t');
+ $bill->voider($e->requestor->id);
+ $bill->void_time('now');
+
+ $e->update_money_billing($bill) or return $e->event;
+ my $evt = _check_open_xact($e, $bill->xact, $xact);
+ return $evt if $evt;
+ }
$e->commit;
-
- # ------------------------------------------------------------------------------
- # Update the patron penalty info in the DB
- # ------------------------------------------------------------------------------
- my $xact = $e->retrieve_money_billable_transaction($bill->xact)
- or return $e->event;
-
- $U->update_patron_penalties(
- authtoken => $authtoken,
- patronid => $xact->usr,
- );
-
+ # update the penalties for each affected user
+ $U->update_patron_penalties( authtoken => $authtoken, patronid => $_ ) for keys %users;
return 1;
}
+
sub _check_open_xact {
- my( $editor, $xactid ) = @_;
+ my( $editor, $xactid, $xact ) = @_;
# Grab the transaction
- my $xact = $editor->retrieve_money_billable_transaction($xactid)
- or return $editor->event;
+ $xact ||= $editor->retrieve_money_billable_transaction($xactid);
+ return $editor->event unless $xact;
+ $xactid ||= $xact->id;
# grab the summary and see how much is owed on this transaction
my ($summary) = $U->fetch_mbts($xactid, $editor);