implement the backend for "max_fine as percent-of-price" functionality
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 27 Jul 2008 15:31:11 +0000 (15:31 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 27 Jul 2008 15:31:11 +0000 (15:31 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10150 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm
Open-ILS/src/sql/Pg/002.schema.config.sql

index cf58cfa..b7dea82 100644 (file)
@@ -2781,6 +2781,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Max Fine Amount" name="amount" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="money" />
                        <field reporter:label="Rule ID" name="id" oils_obj:array_position="4" oils_persist:virtual="false" reporter:selector="name" reporter:datatype="id"/>
                        <field reporter:label="Rule Name" name="name" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text"/>
+                       <field reporter:label="Is Percent" name="is_percent" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="bool"/>
                </fields>
                <links/>
        </class>
index 25ce248..152ea5c 100644 (file)
@@ -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 );
index 64fb180..d497585 100644 (file)
@@ -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;
index 0cb2053..431d51a 100644 (file)
@@ -243,9 +243,10 @@ COMMENT ON TABLE config.rule_circ_duration IS $$
 $$;
 
 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 $$
 /*