From 2c824f044d382e75e1f8fb93d38c8ef019340a3a Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 8 Oct 2008 19:24:57 +0000 Subject: [PATCH] extracted copy price calculation out to a shared function git-svn-id: svn://svn.open-ils.org/ILS/trunk@10794 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/AppUtils.pm | 36 +++++++++++++++++++ .../src/perlmods/OpenILS/Application/Circ.pm | 16 ++------- .../OpenILS/Application/Circ/Circulate.pm | 19 ++-------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 8300a17acd..759c670c84 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1496,5 +1496,41 @@ sub entityize { } +sub get_copy_price { + my($self, $e, $copy, $volume) = @_; + + $copy->price(0) if $copy->price < 0; + + return $copy->price if $copy->price and $copy->price > 0; + + + my $owner; + if(ref $volume) { + if($volume->id == OILS_PRECAT_CALL_NUMBER) { + $owner = $copy->circ_lib; + } else { + $owner = $volume->owning_lib; + } + } else { + if($copy->call_number == OILS_PRECAT_CALL_NUMBER) { + $owner = $copy->circ_lib; + } else { + $owner = $e->retrieve_asset_call_number($copy->call_number)->owning_lib; + } + } + + my $default_price = $self->ou_ancestor_setting_value( + $owner, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0; + + return $default_price unless defined $copy->price; + + # price is 0. Use the default? + my $charge_on_0 = $self->ou_ancestor_setting_value( + $owner, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0; + + return $default_price if $charge_on_0; + return 0; +} + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 3d6f3d0b3d..6881081ad5 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -249,7 +249,7 @@ sub new_set_circ_lost { or return $e->die_event; my $owning_lib = - ($copy->call_number == OILS_PRECAT_CALL_NUMBER) ? + ($copy->call_number->id == OILS_PRECAT_CALL_NUMBER) ? $copy->circ_lib : $copy->call_number->owning_lib; my $circ = $e->search_action_circulation( @@ -263,18 +263,11 @@ sub new_set_circ_lost { # --------------------------------------------------------------------- # fetch the related org settings - my $default_price = $U->ou_ancestor_setting_value( - $owning_lib, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0; my $proc_fee = $U->ou_ancestor_setting_value( $owning_lib, OILS_SETTING_LOST_PROCESSING_FEE, $e) || 0; - my $charge_on_0 = $U->ou_ancestor_setting_value( - $owning_lib, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0; my $void_overdue = $U->ou_ancestor_setting_value( $owning_lib, OILS_SETTING_VOID_OVERDUE_ON_LOST, $e) || 0; - $logger->info("org settings: default price = $default_price, ". - "processing fee = $proc_fee, charge on 0 = $charge_on_0, void overdues = $void_overdue"); - # --------------------------------------------------------------------- # move the copy into LOST status $copy->status(OILS_COPY_STATUS_LOST); @@ -282,12 +275,7 @@ sub new_set_circ_lost { $copy->edit_date('now'); $e->update_asset_copy($copy) or return $e->die_event; - # --------------------------------------------------------------------- - # determine the appropriate item price to charge and create the billing - my $price = $copy->price; - $price = $default_price unless defined $price; - $price = 0 if $price < 0; - $price = $default_price if $price == 0 and $charge_on_0; + my $price = $U->get_copy_price($e, $copy, $copy->call_number); if( $price > 0 ) { my $evt = create_bill($e, $price, 'Lost Materials', $circ->id); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index dfa1820d4d..f30ef92464 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -944,23 +944,8 @@ sub get_max_fine_amount { # if is_percent is true then the max->amount is # use as a percentage of the copy price if ($U->is_true($max_fine_rule->is_percent)) { - - my $ol = ($self->is_precat) ? - $self->editor->requestor->ws_ou : $self->volume->owning_lib; - - my $default_price = $U->ou_ancestor_setting_value( - $ol, OILS_SETTING_DEF_ITEM_PRICE, $self->editor) || 0; - my $charge_on_0 = $U->ou_ancestor_setting_value( - $ol, OILS_SETTING_CHARGE_LOST_ON_ZERO, $self->editor) || 0; - - # Find the most appropriate "price" -- same definition as the - # LOST price. See OpenILS::Circ::new_set_circ_lost - $max_amount = $self->copy->price; - $max_amount = $default_price unless defined $max_amount; - $max_amount = 0 if $max_amount < 0; - $max_amount = $default_price if $max_amount == 0 and $charge_on_0; - - $max_amount *= $max_fine_rule->amount / 100; + my $price = $U->get_copy_price($self->editor, $self->copy, $self->volume); + $max_amount = $price * $max_fine_rule->amount / 100; } return $max_amount; -- 2.43.2