From: erickson Date: Thu, 1 Feb 2007 16:33:31 +0000 (+0000) Subject: added batch functionality to the bill void method X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=68591520991a2c1a2467203cbe1775907edfb18a;p=Evergreen.git added batch functionality to the bill void method git-svn-id: svn://svn.open-ils.org/ILS/trunk@6845 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm index 7a0be672b5..49f4051c19 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm @@ -417,50 +417,51 @@ __PACKAGE__->register_method( / ); + 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);