[open-ils-commits] r10150 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application/Circ src/perlmods/OpenILS/Application/Storage/CDBI src/sql/Pg

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jul 27 11:31:18 EDT 2008


Author: miker
Date: 2008-07-27 11:31:11 -0400 (Sun, 27 Jul 2008)
New Revision: 10150

Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
implement the backend for "max_fine as percent-of-price" functionality

Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2008-07-27 15:19:47 UTC (rev 10149)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2008-07-27 15:31:11 UTC (rev 10150)
@@ -2781,6 +2781,7 @@
 			<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>

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-07-27 15:19:47 UTC (rev 10149)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-07-27 15:31:11 UTC (rev 10150)
@@ -11,6 +11,14 @@
 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 @@
         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,8 +1112,9 @@
         $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 );
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm	2008-07-27 15:19:47 UTC (rev 10149)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm	2008-07-27 15:31:11 UTC (rev 10150)
@@ -52,7 +52,7 @@
 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;

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2008-07-27 15:19:47 UTC (rev 10149)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2008-07-27 15:31:11 UTC (rev 10150)
@@ -243,9 +243,10 @@
 $$;
 
 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 $$
 /*



More information about the open-ils-commits mailing list