From: miker Date: Sun, 27 Jul 2008 15:47:06 +0000 (+0000) Subject: backporting implementation of the backend for "max_fine as percent-of-price" function... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=466ea996c3cb5cf6c024e2a1324e10d254ad97fa;p=Evergreen.git backporting implementation of the backend for "max_fine as percent-of-price" functionality git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@10151 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 8cc5d8d186..46104cdcd0 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1847,6 +1847,7 @@ + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index cac7262f6f..512ec9ec6d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -11,6 +11,14 @@ my $U = "OpenILS::Application::AppUtils"; my %scripts; my $script_libs; +sub isTrue { + my $v = shift; + return 1 if ($v == 1); + return 1 if ($v =~ /^t/io); + return 1 if ($v =~ /^y/io); + return 0; +} + sub initialize { my $self = shift; @@ -1060,6 +1068,30 @@ sub build_checkout_circ_object { my $mname = $max->name; my $rname = $recurring->name; + my $max_amount = $max->amount; + + # if is_percent is true then the max->amount is + # use as a percentage of the copy price + if (isTrue($max->is_percent)) { + + my $cn = $self->editor->retrieve_asset_call_number($copy->call_number); + + my $default_price = $U->ou_ancestor_setting_value( + $cn->owning_lib, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0; + my $charge_on_0 = $U->ou_ancestor_setting_value( + $cn->owning_lib, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e) || 0; + + # Find the most appropriate "price" -- same definition as the + # LOST price. See OpenILS::Circ::new_set_circ_lost + $max_amount = $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->amount / 100; + + } + $logger->debug("circulator: building circulation ". "with duration=$dname, maxfine=$mname, recurring=$rname"); @@ -1080,7 +1112,8 @@ sub build_checkout_circ_object { $circ->duration_rule( $duration->name ); $circ->recuring_fine_rule( $recurring->name ); $circ->max_fine_rule( $max->name ); - $circ->max_fine( $max->amount ); + + $circ->max_fine( $max_amount ); $circ->fine_interval($recurring->recurance_interval); $circ->renewal_remaining( $duration->max_renewals ); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm index a2e1fa5fa2..59faad9266 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm @@ -52,7 +52,7 @@ package config::rules::max_fine; use base qw/config/; __PACKAGE__->table('config_rule_max_fine'); __PACKAGE__->columns(Primary => 'id'); -__PACKAGE__->columns(Essential => qw/name amount/); +__PACKAGE__->columns(Essential => qw/name amount is_percent/); #------------------------------------------------------------------------------- package config::rules::recuring_fine; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 5fedc75155..fb5e993636 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -294,9 +294,10 @@ INSERT INTO config.rule_circ_duration VALUES (DEFAULT, 'default', '21 days', '14 CREATE TABLE config.rule_max_fine ( - id SERIAL PRIMARY KEY, - name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ), - amount NUMERIC(6,2) NOT NULL + id SERIAL PRIMARY KEY, + name TEXT NOT NULL UNIQUE CHECK ( name ~ E'^\\w+$' ), + amount NUMERIC(6,2) NOT NULL, + is_percent BOOL NOT NULL DEFAULT FALSE ); COMMENT ON TABLE config.rule_max_fine IS $$ /*