Add new option for max/min lost item pricing
authorDan Wells <dbw2@calvin.edu>
Fri, 14 Dec 2012 19:02:22 +0000 (14:02 -0500)
committerJeff Godin <jgodin@tadl.org>
Wed, 22 Jan 2014 15:24:28 +0000 (10:24 -0500)
In addition to a 'default' price when price is missing or zero,
we can also accommodate a range of prices by saying it should be
at least 'X' and not more than 'Y'.  This also allows you to
effectively set a fixed price for all lost items by setting min
and max to an equal amount.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/Const.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.min_max_prices.sql [new file with mode: 0644]

index b5900ed..630d252 100644 (file)
@@ -1542,8 +1542,6 @@ sub get_copy_price {
 
     $copy->price(0) if $copy->price and $copy->price < 0;
 
-    return $copy->price if $copy->price and $copy->price > 0;
-
 
     my $owner;
     if(ref $volume) {
@@ -1560,17 +1558,30 @@ sub get_copy_price {
         }
     }
 
-    my $default_price = $self->ou_ancestor_setting_value(
-        $owner, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
+    my $min_price = $self->ou_ancestor_setting_value($owner, OILS_SETTING_MIN_ITEM_PRICE);
+    my $max_price = $self->ou_ancestor_setting_value($owner, OILS_SETTING_MAX_ITEM_PRICE);
+    my $charge_on_0 = $self->ou_ancestor_setting_value($owner, OILS_SETTING_CHARGE_LOST_ON_ZERO, $e);
 
-    return $default_price unless defined $copy->price;
+    my $price = $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;
+    # set the default price if needed
+    if (!defined $price or ($price == 0 and $charge_on_0)) {
+        # set to default price
+        $price = $self->ou_ancestor_setting_value(
+            $owner, OILS_SETTING_DEF_ITEM_PRICE, $e) || 0;
+    }
 
-    return $default_price if $charge_on_0;
-    return 0;
+    # adjust to min/max range if needed
+    if (defined $max_price and $price > $max_price) {
+        $price = $max_price;
+    } elsif (defined $min_price and $price < $min_price
+        and ($price != 0 or $charge_on_0 or !defined $charge_on_0)) {
+        # default to raising the price to the minimum,
+        # but let 0 fall through if $charge_on_0 is set and is false
+        $price = $min_price;
+    }
+
+    return $price;
 }
 
 # given a transaction ID, this returns the context org_unit for the transaction
index 9bbcdf2..4f9e5c2 100644 (file)
@@ -77,6 +77,8 @@ econst OILS_UNLIMITED_CIRC_DURATION   => 'unlimited';
 # ---------------------------------------------------------------------
 econst OILS_SETTING_LOST_PROCESSING_FEE => 'circ.lost_materials_processing_fee';
 econst OILS_SETTING_DEF_ITEM_PRICE => 'cat.default_item_price';
+econst OILS_SETTING_MIN_ITEM_PRICE => 'circ.min_item_price';
+econst OILS_SETTING_MAX_ITEM_PRICE => 'circ.max_item_price';
 econst OILS_SETTING_ORG_BOUNCED_EMAIL => 'org.bounced_emails';
 econst OILS_SETTING_CHARGE_LOST_ON_ZERO => 'circ.charge_lost_on_zero';
 econst OILS_SETTING_VOID_OVERDUE_ON_LOST => 'circ.void_overdue_on_lost';
index 86af666..693fab9 100644 (file)
@@ -1591,7 +1591,11 @@ INSERT INTO permission.perm_list ( id, code, description ) VALUES
  ( 551, 'ADMIN_SERVER_ADDON_FOR_WORKSTATION', oils_i18n_gettext( 551,
         'Allows a user to specify which Server Add-ons get invoked at the current workstation', 'ppl', 'description')),
  ( 552, 'ADMIN_FLOAT_GROUPS', oils_i18n_gettext( 552,
-    'Allows administration of floating groups', 'ppl', 'description' ))
+    'Allows administration of floating groups', 'ppl', 'description' )),
+ ( 552, 'UPDATE_ORG_UNIT_SETTING.circ.min_item_price', oils_i18n_gettext( 552,
+    'UPDATE_ORG_UNIT_SETTING.circ.min_item_price', 'ppl', 'description' )),
+ ( 553, 'UPDATE_ORG_UNIT_SETTING.circ.max_item_price', oils_i18n_gettext( 553,
+    'UPDATE_ORG_UNIT_SETTING.circ.max_item_price', 'ppl', 'description' ))
 ;
 
 SELECT SETVAL('permission.perm_list_id_seq'::TEXT, 1000);
@@ -2785,6 +2789,24 @@ INSERT into config.org_unit_setting_type
         'coust', 'description'),
     'currency', null)
 
+,( 'circ.min_item_price', 'finance',
+    oils_i18n_gettext('circ.min_item_price',
+        'Minimum Item Price',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.min_item_price',
+        'When charging for lost items, charge this amount as a minimum.',
+        'coust', 'description'),
+    'currency', null)
+
+,( 'circ.max_item_price', 'finance',
+    oils_i18n_gettext('circ.max_item_price',
+        'Maximum Item Price',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.max_item_price',
+        'When charging for lost items, limit the charge to this as a maximum.',
+        'coust', 'description'),
+    'currency', null)
+
 ,( 'cat.label.font.family', 'cat',
     oils_i18n_gettext('cat.label.font.family',
         'Spine and pocket label font family',
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.min_max_prices.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.min_max_prices.sql
new file mode 100644 (file)
index 0000000..acd22ee
--- /dev/null
@@ -0,0 +1,55 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO permission.perm_list ( id, code, description ) VALUES (
+    551, -- VERIFY
+    'UPDATE_ORG_UNIT_SETTING.circ.min_item_price',
+    oils_i18n_gettext(
+        551, -- VERIFY
+        'UPDATE_ORG_UNIT_SETTING.circ.min_item_price',
+        'ppl',
+        'description'
+    )
+), (
+       552, -- VERIFY
+    'UPDATE_ORG_UNIT_SETTING.circ.max_item_price',
+    oils_i18n_gettext(
+        552, -- VERIFY
+        'UPDATE_ORG_UNIT_SETTING.circ.max_item_price',
+        'ppl',
+        'description'
+    )
+);
+
+INSERT into config.org_unit_setting_type
+    ( name, grp, label, description, datatype, fm_class )
+VALUES (
+    'circ.min_item_price',
+       'finance',
+    oils_i18n_gettext(
+        'circ.min_item_price',
+        'Minimum Item Price',
+        'coust', 'label'),
+    oils_i18n_gettext(
+        'circ.min_item_price',
+        'When charging for lost items, charge this amount as a minimum.',
+        'coust', 'description'),
+    'currency',
+    NULL
+), (
+    'circ.max_item_price',
+    'finance',
+    oils_i18n_gettext(
+        'circ.max_item_price',
+        'Maximum Item Price',
+        'coust', 'label'),
+    oils_i18n_gettext(
+        'circ.max_item_price',
+        'When charging for lost items, limit the charge to this as a maximum.',
+        'coust', 'description'),
+    'currency',
+    NULL
+);
+
+COMMIT;