@@ -, +, @@
---
C4/Circulation.pm | 27 ++++-
Koha/ItemType.pm | 33 ++++++
admin/itemtypes.pl | 30 ++---
catalogue/moredetail.pl | 1 -
.../prog/en/modules/admin/itemtypes.tt | 22 +++-
.../prog/en/modules/catalogue/moredetail.tt | 2 +
t/db_dependent/Circulation.t | 105 +++++++++++++++++-
t/db_dependent/Koha/ItemTypes.t | 52 ++++++++-
8 files changed, 244 insertions(+), 28 deletions(-)
--- a/C4/Circulation.pm
+++ a/C4/Circulation.pm
@@ -989,6 +989,8 @@ sub CanBookBeIssued {
if ( $rentalConfirmation ){
my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber );
+ my $itemtype = Koha::ItemTypes->find( $item->itype ); # GetItem sets effective itemtype
+ $rentalCharge += $itemtype->calc_rental_charge_daily( { from => dt_from_string(), to => $duedate } );
if ( $rentalCharge > 0 ){
$needsconfirmation{RENTALCHARGE} = $rentalCharge;
}
@@ -1437,6 +1439,16 @@ sub AddIssue {
AddIssuingCharge( $issue, $charge, $description );
}
+ my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
+ if ( $itemtype ) {
+ my $daily_charge = $itemtype->calc_rental_charge_daily( { from => $issuedate, to => $datedue } );
+ if ( $daily_charge > 0 ) {
+ AddIssuingCharge( $issue, $daily_charge, 'Daily rental' ) if $daily_charge > 0;
+ $charge += $daily_charge;
+ $item->{charge} = $charge;
+ }
+ }
+
# Record the fact that this book was issued.
&UpdateStats(
{
@@ -2859,13 +2871,24 @@ sub AddRenewal {
$renews = $item->renewals + 1;
ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
- # Charge a new rental fee, if applicable?
+ # Charge a new rental fee, if applicable
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
if ( $charge > 0 ) {
my $description = "Renewal of Rental Item " . $biblio->title . " " .$item->barcode;
AddIssuingCharge($issue, $charge, $description);
}
+ # Charge a new daily rental fee, if applicable
+ my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
+ if ( $itemtype ) {
+ my $daily_charge = $itemtype->calc_rental_charge_daily( { from => dt_from_string($lastreneweddate), to => $datedue } );
+ if ( $daily_charge > 0 ) {
+ my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}";
+ AddIssuingCharge( $issue, $daily_charge, $type_desc )
+ }
+ $charge += $daily_charge;
+ }
+
# Send a renewal slip according to checkout alert preferencei
if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
my $circulation_alert = 'C4::ItemCirculationAlertPreference';
@@ -3183,7 +3206,7 @@ sub _get_discount_from_rule {
=head2 AddIssuingCharge
- &AddIssuingCharge( $checkout, $charge )
+ &AddIssuingCharge( $checkout, $charge, [$description] )
=cut
--- a/Koha/ItemType.pm
+++ a/Koha/ItemType.pm
@@ -90,6 +90,39 @@ sub translated_descriptions {
} @translated_descriptions ];
}
+=head3 calc_rental_charge_daily
+
+ my $fee = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
+
+ This method calculates the daily rental fee for a given itemtype for a given
+ period of time passed in as a pair of DateTime objects.
+
+=cut
+
+sub calc_rental_charge_daily {
+ my ( $self, $params ) = @_;
+
+ my $rental_charge_daily = $self->rental_charge_daily;
+ return 0 unless $rental_charge_daily;
+
+ my $from_dt = $params->{from};
+ my $to_dt = $params->{to};
+
+ my $duration;
+ if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
+ my $branchcode = C4::Context->userenv->{branch};
+ my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ $duration = $calendar->days_between( $from_dt, $to_dt );
+ }
+ else {
+ $duration = $to_dt->delta_days($from_dt);
+ }
+ my $days = $duration->in_units('days');
+
+ my $charge = $rental_charge_daily * $days;
+
+ return $charge;
+}
=head3 can_be_deleted
--- a/admin/itemtypes.pl
+++ a/admin/itemtypes.pl
@@ -72,6 +72,7 @@ if ( $op eq 'add_form' ) {
my $itemtype = Koha::ItemTypes->find($itemtype_code);
my $description = $input->param('description');
my $rentalcharge = $input->param('rentalcharge');
+ my $rental_charge_daily = $input->param('rental_charge_daily');
my $defaultreplacecost = $input->param('defaultreplacecost');
my $processfee = $input->param('processfee');
my $image = $input->param('image') || q||;
@@ -92,6 +93,7 @@ if ( $op eq 'add_form' ) {
if ( $itemtype and $is_a_modif ) { # it's a modification
$itemtype->description($description);
$itemtype->rentalcharge($rentalcharge);
+ $itemtype->rental_charge_daily($rental_charge_daily);
$itemtype->defaultreplacecost($defaultreplacecost);
$itemtype->processfee($processfee);
$itemtype->notforloan($notforloan);
@@ -112,19 +114,21 @@ if ( $op eq 'add_form' ) {
}
} elsif ( not $itemtype and not $is_a_modif ) {
my $itemtype = Koha::ItemType->new(
- { itemtype => $itemtype_code,
- description => $description,
- rentalcharge => $rentalcharge,
- defaultreplacecost => $defaultreplacecost,
- processfee => $processfee,
- notforloan => $notforloan,
- imageurl => $imageurl,
- summary => $summary,
- checkinmsg => $checkinmsg,
- checkinmsgtype => $checkinmsgtype,
- sip_media_type => $sip_media_type,
- hideinopac => $hideinopac,
- searchcategory => $searchcategory,
+ {
+ itemtype => $itemtype_code,
+ description => $description,
+ rentalcharge => $rentalcharge,
+ rental_charge_daily => $rental_charge_daily,
+ defaultreplacecost => $defaultreplacecost,
+ processfee => $processfee,
+ notforloan => $notforloan,
+ imageurl => $imageurl,
+ summary => $summary,
+ checkinmsg => $checkinmsg,
+ checkinmsgtype => $checkinmsgtype,
+ sip_media_type => $sip_media_type,
+ hideinopac => $hideinopac,
+ searchcategory => $searchcategory,
}
);
eval { $itemtype->store; };
--- a/catalogue/moredetail.pl
+++ a/catalogue/moredetail.pl
@@ -128,7 +128,6 @@ my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_l
$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
-$data->{'rentalcharge'} = $data->{'rentalcharge'};
foreach ( keys %{$data} ) {
$template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
}
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt
@@ -137,7 +137,7 @@ Item types administration
[% END %]
[% END %]
- (Options are defined as the authorized values for the ITEMTYPECAT category)
+ Options are defined as the authorized values for the ITEMTYPECAT category.
[% IF Koha.Preference('noItemTypeImages') %]
@@ -217,7 +217,7 @@ Item types administration
[% ELSE %]
[% END %]
- (if checked, items of this type will be hidden as filters in OPAC's advanced search)
+ If checked, items of this type will be hidden as filters in OPAC's advanced search.
@@ -226,11 +226,17 @@ Item types administration
[% ELSE %]
[% END %]
- (if checked, no item of this type can be issued. If not checked, every item of this type can be issued unless notforloan is set for a specific item)
+ If checked, no item of this type can be issued. If not checked, every item of this type can be issued unless notforloan is set for a specific item.
-
+
+ This fee is charged once per checkout/renewal per item
+
+
+
+
+ This fee is charged a checkout/renewal time for each day between the checkout/renewal date and due date.
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt
@@ -1,4 +1,5 @@
[% USE raw %]
+[% USE Price %]
[% USE Asset %]
[% USE Koha %]
[% USE Branches %]
@@ -34,6 +35,7 @@