From: Dan Scott Date: Wed, 19 Jun 2013 21:15:27 +0000 (-0400) Subject: Silence fine_generator warnings about next in eval X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=03b1217bfcc43884a4d072e2c93b8fb187641698;p=working%2FEvergreen.git Silence fine_generator warnings about next in eval Simplest possible means of refactoring the fine_generator logic to avoid the 22,000 warnings we had today about exiting the eval{} block via next. Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index 7acb5fb7d5..d00645ec7f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -1132,119 +1132,122 @@ sub generate_fines { $grace_period = OpenILS::Application::Circ::CircCommon->extend_grace_period($c->$circ_lib_method->to_fieldmapper->id,$c->$due_date_method,$grace_period,undef,$hoo{$c->$circ_lib_method}); } - next if ($last_fine > $now); - # Generate fines for each past interval, including the one we are inside - my $pending_fine_count = ceil( ($now - $last_fine) / $fine_interval ); - - if ( $last_fine == $due # we have no fines yet - && $grace_period # and we have a grace period - && $now < $due + $grace_period # and some date math says were are within the grace period - ) { - $client->respond( "Still inside grace period of: ". seconds_to_interval( $grace_period )."\n" ); - $log->info( "Circ ".$c->id." is still inside grace period of: $grace_period [". seconds_to_interval( $grace_period ).']' ); - next; + my $pending_fine_count; + if ($last_fine <= $now) { + # Generate fines for each past interval, including the one we are inside + $pending_fine_count = ceil( ($now - $last_fine) / $fine_interval ); + + if ( $last_fine == $due # we have no fines yet + && $grace_period # and we have a grace period + && $now < $due + $grace_period # and some date math says were are within the grace period + ) { + $client->respond( "Still inside grace period of: ". seconds_to_interval( $grace_period )."\n" ); + $log->info( "Circ ".$c->id." is still inside grace period of: $grace_period [". seconds_to_interval( $grace_period ).']' ); + next; + } + + $client->respond( "\t$pending_fine_count pending fine(s)\n" ); } + if ($pending_fine_count) { - $client->respond( "\t$pending_fine_count pending fine(s)\n" ); - next unless ($pending_fine_count); + my $recurring_fine = int($c->$recurring_fine_method * 100); + my $max_fine = int($c->max_fine * 100); - my $recurring_fine = int($c->$recurring_fine_method * 100); - my $max_fine = int($c->max_fine * 100); + my $skip_closed_check = $U->ou_ancestor_setting_value( + $c->$circ_lib_method->to_fieldmapper->id, 'circ.fines.charge_when_closed'); + $skip_closed_check = $U->is_true($skip_closed_check); - my $skip_closed_check = $U->ou_ancestor_setting_value( - $c->$circ_lib_method->to_fieldmapper->id, 'circ.fines.charge_when_closed'); - $skip_closed_check = $U->is_true($skip_closed_check); + my $truncate_to_max_fine = $U->ou_ancestor_setting_value( + $c->$circ_lib_method->to_fieldmapper->id, 'circ.fines.truncate_to_max_fine'); + $truncate_to_max_fine = $U->is_true($truncate_to_max_fine); - my $truncate_to_max_fine = $U->ou_ancestor_setting_value( - $c->$circ_lib_method->to_fieldmapper->id, 'circ.fines.truncate_to_max_fine'); - $truncate_to_max_fine = $U->is_true($truncate_to_max_fine); + my ($latest_billing_ts, $latest_amount) = ('',0); + for (my $bill = 1; $bill <= $pending_fine_count; $bill++) { + + if ($current_fine_total >= $max_fine) { + $c->update({stop_fines => 'MAXFINES', stop_fines_time => 'now'}) if ($ctype eq 'circulation'); + $client->respond( + "\tMaximum fine level of ".$c->max_fine. + " reached for this $ctype.\n". + "\tNo more fines will be generated.\n" ); + last; + } + + # XXX Use org time zone (or default to 'local') once we have the ou setting built for that + my $billing_ts = DateTime->from_epoch( epoch => $last_fine, time_zone => 'local' ); + my $current_bill_count = $bill; + while ( $current_bill_count ) { + $billing_ts->add( seconds_to_interval_hash( $fine_interval ) ); + $current_bill_count--; + } - my ($latest_billing_ts, $latest_amount) = ('',0); - for (my $bill = 1; $bill <= $pending_fine_count; $bill++) { - - if ($current_fine_total >= $max_fine) { - $c->update({stop_fines => 'MAXFINES', stop_fines_time => 'now'}) if ($ctype eq 'circulation'); - $client->respond( - "\tMaximum fine level of ".$c->max_fine. - " reached for this $ctype.\n". - "\tNo more fines will be generated.\n" ); - last; - } - - # XXX Use org time zone (or default to 'local') once we have the ou setting built for that - my $billing_ts = DateTime->from_epoch( epoch => $last_fine, time_zone => 'local' ); - my $current_bill_count = $bill; - while ( $current_bill_count ) { - $billing_ts->add( seconds_to_interval_hash( $fine_interval ) ); - $current_bill_count--; - } + my $timestamptz = $billing_ts->strftime('%FT%T%z'); + if (!$skip_closed_check) { + my $dow = $billing_ts->day_of_week_0(); + my $dow_open = "dow_${dow}_open"; + my $dow_close = "dow_${dow}_close"; - my $timestamptz = $billing_ts->strftime('%FT%T%z'); - if (!$skip_closed_check) { - my $dow = $billing_ts->day_of_week_0(); - my $dow_open = "dow_${dow}_open"; - my $dow_close = "dow_${dow}_close"; + if (my $h = $hoo{$c->$circ_lib_method}) { + next if ( $h->$dow_open eq '00:00:00' and $h->$dow_close eq '00:00:00'); + } + + my @cl = actor::org_unit::closed_date->search_where( + { close_start => { '<=' => $timestamptz }, + close_end => { '>=' => $timestamptz }, + org_unit => $c->$circ_lib_method } + ); + next if (@cl); + } - if (my $h = $hoo{$c->$circ_lib_method}) { - next if ( $h->$dow_open eq '00:00:00' and $h->$dow_close eq '00:00:00'); + # The billing amount for this billing normally ought to be the recurring fine amount. + # However, if the recurring fine amount would cause total fines to exceed the max fine amount, + # we may wish to reduce the amount for this billing (if circ.fines.truncate_to_max_fine is true). + my $this_billing_amount = $recurring_fine; + if ( $truncate_to_max_fine && ($current_fine_total + $this_billing_amount) > $max_fine ) { + $this_billing_amount = ($max_fine - $current_fine_total); } - - my @cl = actor::org_unit::closed_date->search_where( - { close_start => { '<=' => $timestamptz }, - close_end => { '>=' => $timestamptz }, - org_unit => $c->$circ_lib_method } + $current_fine_total += $this_billing_amount; + $latest_amount += $this_billing_amount; + $latest_billing_ts = $timestamptz; + + money::billing->create( + { xact => ''.$c->id, + note => "System Generated Overdue Fine", + billing_type => "Overdue materials", + btype => 1, + amount => sprintf('%0.2f', $this_billing_amount/100), + billing_ts => $timestamptz, + } ); - next if (@cl); - } - # The billing amount for this billing normally ought to be the recurring fine amount. - # However, if the recurring fine amount would cause total fines to exceed the max fine amount, - # we may wish to reduce the amount for this billing (if circ.fines.truncate_to_max_fine is true). - my $this_billing_amount = $recurring_fine; - if ( $truncate_to_max_fine && ($current_fine_total + $this_billing_amount) > $max_fine ) { - $this_billing_amount = ($max_fine - $current_fine_total); } - $current_fine_total += $this_billing_amount; - $latest_amount += $this_billing_amount; - $latest_billing_ts = $timestamptz; - - money::billing->create( - { xact => ''.$c->id, - note => "System Generated Overdue Fine", - billing_type => "Overdue materials", - btype => 1, - amount => sprintf('%0.2f', $this_billing_amount/100), - billing_ts => $timestamptz, - } - ); - } - - $client->respond( "\t\tAdding fines totaling $latest_amount for overdue up to $latest_billing_ts\n" ) - if ($latest_billing_ts and $latest_amount); + $client->respond( "\t\tAdding fines totaling $latest_amount for overdue up to $latest_billing_ts\n" ) + if ($latest_billing_ts and $latest_amount); - $self->method_lookup('open-ils.storage.transaction.commit')->run; + $self->method_lookup('open-ils.storage.transaction.commit')->run; - if(1) { + if(1) { - # Caluclate penalties inline - OpenILS::Utils::Penalty->calculate_penalties( - undef, $c->usr->to_fieldmapper->id.'', $c->$circ_lib_method->to_fieldmapper->id.''); + # Caluclate penalties inline + OpenILS::Utils::Penalty->calculate_penalties( + undef, $c->usr->to_fieldmapper->id.'', $c->$circ_lib_method->to_fieldmapper->id.''); - } else { + } else { - # Calculate penalties with an aysnc call to the penalty server. This approach - # may lead to duplicate penalties since multiple penalty processes for a - # given user may be running at the same time. Leave this here for reference - # in case we later find that asyc calls are needed in some environments. - $penalty->request( - 'open-ils.penalty.patron_penalty.calculate', - { patronid => ''.$c->usr, - context_org => ''.$c->$circ_lib_method, - update => 1, - background => 1, - } - )->gather(1); + # Calculate penalties with an aysnc call to the penalty server. This approach + # may lead to duplicate penalties since multiple penalty processes for a + # given user may be running at the same time. Leave this here for reference + # in case we later find that asyc calls are needed in some environments. + $penalty->request( + 'open-ils.penalty.patron_penalty.calculate', + { patronid => ''.$c->usr, + context_org => ''.$c->$circ_lib_method, + update => 1, + background => 1, + } + )->gather(1); + } } };