From 48963ead708f34e27902901190651671b22db298 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 30 Jan 2019 20:34:13 +0000 Subject: [PATCH] Bug 20912: (follow-up) Add hourly support It seemed strange to only add support for Daily loans in the feature when Koha also support loan periods in hours. This patch adds parallel functionaliy for hourly loan periods. Signed-off-by: Martin Renvoize --- Koha/Charges/Fees.pm | 42 ++++++++++++++----- Koha/ItemType.pm | 6 +-- Koha/Schema/Result/Itemtype.pm | 12 +++++- admin/itemtypes.pl | 5 ++- .../data/mysql/atomicupdate/bug_20912.perl | 4 ++ installer/data/mysql/kohastructure.sql | 3 +- .../prog/en/modules/admin/itemtypes.tt | 14 ++++++- .../prog/en/modules/catalogue/moredetail.tt | 1 + 8 files changed, 68 insertions(+), 19 deletions(-) diff --git a/Koha/Charges/Fees.pm b/Koha/Charges/Fees.pm index 0d948338b3..03cce2f9e7 100644 --- a/Koha/Charges/Fees.pm +++ b/Koha/Charges/Fees.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp qw( confess ); use Koha::Calendar; +use Koha::IssuingRules; use Koha::DateUtils qw( dt_from_string ); use Koha::Exceptions; @@ -85,25 +86,44 @@ sub new { =cut sub accumulate_rentalcharge { - my ( $self, $params ) = @_; + my ( $self ) = @_; my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype ); - my $rentalcharge_daily = $itemtype->rentalcharge_daily; - - return undef unless $rentalcharge_daily && $rentalcharge_daily > 0; + my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( + { + categorycode => $self->patron->categorycode, + itemtype => $itemtype->id, + branchcode => $self->library->id + } + ); + my $units = $issuing_rule->lengthunit; + my $rentalcharge_increment = ( $units eq 'days' ) ? $itemtype->rentalcharge_daily : $itemtype->rentalcharge_hourly; + + return 0 unless $rentalcharge_increment && $rentalcharge_increment > 0; my $duration; - if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) { - my $calendar = Koha::Calendar->new( branchcode => $self->library->id ); - $duration = $calendar->days_between( $self->from_date, $self->to_date ); + my $calendar = Koha::Calendar->new( branchcode => $self->library->id ); + + if ( $units eq 'hours' ) { + if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) { + $duration = + $calendar->hours_between( $self->from_date, $self->to_date ); + } + else { + $duration = $self->to_date->delta_ms($self->from_date); + } } else { - $duration = $self->to_date->delta_days($self->from_date); + if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) { + $duration = + $calendar->days_between( $self->from_date, $self->to_date ); + } + else { + $duration = $self->to_date->delta_days( $self->from_date ); + } } - my $days = $duration->in_units('days'); - - my $charge = $rentalcharge_daily * $days; + my $charge = $rentalcharge_increment * $duration->in_units($units); return $charge; } diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 23719a6ca5..53b7b0880d 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -40,9 +40,9 @@ Koha::ItemType - Koha Item type Object class sub store { my ($self) = @_; - $self->rentalcharge(undef) if $self->rentalcharge eq ''; - $self->defaultreplacecost(undef) if $self->defaultreplacecost eq ''; - $self->processfee(undef) if $self->processfee eq ''; + $self->rentalcharge(undef) if $self->rentalcharge eq ''; + $self->defaultreplacecost(undef) if $self->defaultreplacecost eq ''; + $self->processfee(undef) if $self->processfee eq ''; $self->notforloan(0) unless $self->notforloan; $self->hideinopac(0) unless $self->hideinopac; diff --git a/Koha/Schema/Result/Itemtype.pm b/Koha/Schema/Result/Itemtype.pm index 6f022e986f..b2c4774e57 100644 --- a/Koha/Schema/Result/Itemtype.pm +++ b/Koha/Schema/Result/Itemtype.pm @@ -47,6 +47,12 @@ __PACKAGE__->table("itemtypes"); is_nullable: 1 size: [28,6] +=head2 rentalcharge_hourly + + data_type: 'decimal' + is_nullable: 1 + size: [28,6] + =head2 defaultreplacecost data_type: 'decimal' @@ -117,6 +123,8 @@ __PACKAGE__->add_columns( { data_type => "decimal", is_nullable => 1, size => [28, 6] }, "rentalcharge_daily", { data_type => "decimal", is_nullable => 1, size => [28, 6] }, + "rentalcharge_hourly", + { data_type => "decimal", is_nullable => 1, size => [28, 6] }, "defaultreplacecost", { data_type => "decimal", is_nullable => 1, size => [28, 6] }, "processfee", @@ -234,8 +242,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2018-10-25 12:41:04 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Iyb9JKB8gdyZPtZloHVxSQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-01-31 11:59:27 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gYBgGWpeUyFuyzfBNIEKCQ # Use the ItemtypeLocalization view to create the join on localization our $LANGUAGE; diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 3381e21ec3..441bd0514a 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -73,6 +73,7 @@ if ( $op eq 'add_form' ) { my $description = $input->param('description'); my $rentalcharge = $input->param('rentalcharge'); my $rentalcharge_daily = $input->param('rentalcharge_daily'); + my $rentalcharge_hourly = $input->param('rentalcharge_hourly'); my $defaultreplacecost = $input->param('defaultreplacecost'); my $processfee = $input->param('processfee'); my $image = $input->param('image') || q||; @@ -94,6 +95,7 @@ if ( $op eq 'add_form' ) { $itemtype->description($description); $itemtype->rentalcharge($rentalcharge); $itemtype->rentalcharge_daily($rentalcharge_daily); + $itemtype->rentalcharge_hourly($rentalcharge_hourly); $itemtype->defaultreplacecost($defaultreplacecost); $itemtype->processfee($processfee); $itemtype->notforloan($notforloan); @@ -118,7 +120,8 @@ if ( $op eq 'add_form' ) { itemtype => $itemtype_code, description => $description, rentalcharge => $rentalcharge, - rentalcharge_daily => $rentalcharge_daily, + rentalcharge_daily => $rentalcharge_daily, + rentalcharge_hourly => $rentalcharge_hourly, defaultreplacecost => $defaultreplacecost, processfee => $processfee, notforloan => $notforloan, diff --git a/installer/data/mysql/atomicupdate/bug_20912.perl b/installer/data/mysql/atomicupdate/bug_20912.perl index 6e5f9ed212..c75eed9eb0 100644 --- a/installer/data/mysql/atomicupdate/bug_20912.perl +++ b/installer/data/mysql/atomicupdate/bug_20912.perl @@ -5,6 +5,10 @@ if ( CheckVersion($DBversion) ) { $dbh->do("ALTER TABLE `itemtypes` ADD COLUMN `rentalcharge_daily` decimal(28,6) default NULL AFTER `rentalcharge`"); } + if ( !column_exists( 'itemtypes', 'rentalcharge_hourly' ) ) { + $dbh->do("ALTER TABLE `itemtypes` ADD COLUMN `rentalcharge_hourly` decimal(28,6) default NULL AFTER `rentalcharge_daily`"); + } + if ( column_exists( 'itemtypes', 'rental_charge_daily' ) ) { $dbh->do("UPDATE `itemtypes` SET `rentalcharge_daily` = `rental_charge_daily`"); $dbh->do("ALTER TABLE `itemtypes` DROP COLUMN `rental_charge_daily`"); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index dcb6447c25..3cb0dbc9b1 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -988,7 +988,8 @@ CREATE TABLE `itemtypes` ( -- defines the item types itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type description LONGTEXT, -- a plain text explanation of the item type rentalcharge decimal(28,6) default NULL, -- the amount charged when this item is checked out/issued - rentalcharge_daily decimal(28,6) default NULL, -- the amount charged for each increment (day/hour) between checkout date and due date + rentalcharge_daily decimal(28,6) default NULL, -- the amount charged for each day between checkout date and due date + rentalcharge_hourly decimal(28,6) default NULL, -- the amount charged for each hour between checkout date and due date defaultreplacecost decimal(28,6) default NULL, -- default replacement cost processfee decimal(28,6) default NULL, -- default text be recorded in the column note when the processing fee is applied notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index e692fc7950..6899edc5e3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -237,7 +237,12 @@ Item types administration
  • - This fee is charged a checkout/renewal time for each day between the checkout/renewal date and due date. + This fee is charged at checkout/renewal time for each day between the checkout/renewal date and due date for loans specified in days. +
  • +
  • + + + This fee is charged at checkout/renewal time for each hour between the checkout/renewal date and due date for loans specifie in hours.
  • @@ -338,6 +343,7 @@ Item types administration Hide in OPAC Rental charge Daily rental charge + Hourly rental charge Default replacement cost Processing fee (when lost) Checkin message @@ -384,6 +390,12 @@ Item types administration [% itemtype.rentalcharge_daily | $Price %] [% END %] + + [% UNLESS ( itemtype.notforloan ) %] + [% itemtype.rentalcharge_hourly | $Price %] + [% END %] + + [% itemtype.defaultreplacecost | $Price %] [% itemtype.processfee | $Price %] [% itemtype.checkinmsg | html_line_break | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index 53225a2ce9..45d81da573 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -35,6 +35,7 @@ [% END %] [% IF ( rentalcharge ) %]
  • Rental charge:[% rentalcharge | $Price %] 
  • [% END %] [% IF ( rentalcharge_daily ) %]
  • Daily rental charge:[% rentalcharge_daily | $Price %] 
  • [% END %] + [% IF ( rentalcharge_hourly ) %]
  • Hourly rental charge:[% rentalcharge_hourly | $Price %] 
  • [% END %]
  • ISBN: [% isbn | html %] 
  • Publisher:[% place | html %] [% publishercode | html %] [% publicationyear | html %] 
  • [% IF ( volumeddesc ) %]
  • Volume: [% volumeddesc | html %]
  • [% END %] -- 2.20.1