From e42e9b047c91c21d34db19a0ff7afd7ebcddf367 Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Fri, 14 Dec 2012 14:02:22 -0500 Subject: [PATCH] Add new option for max/min lost item pricing 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 Signed-off-by: Jeff Godin --- .../lib/OpenILS/Application/AppUtils.pm | 31 +++++++---- Open-ILS/src/perlmods/lib/OpenILS/Const.pm | 2 + Open-ILS/src/sql/Pg/950.data.seed-values.sql | 24 +++++++- .../Pg/upgrade/XXXX.data.min_max_prices.sql | 55 +++++++++++++++++++ 4 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.min_max_prices.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index b5900eda1c..630d252116 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -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 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Const.pm b/Open-ILS/src/perlmods/lib/OpenILS/Const.pm index 9bbcdf24a7..4f9e5c2f30 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Const.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Const.pm @@ -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'; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 86af666514..693fab97c7 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -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 index 0000000000..acd22eeabc --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.min_max_prices.sql @@ -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; -- 2.43.2