use Carp qw( confess );
use Koha::Calendar;
+use Koha::IssuingRules;
use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions;
=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;
}
=head1 API
-=head2 Class Methods
+=head2 Class methods
=cut
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||;
$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);
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,
$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`");
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
<li>
<label for="rentalcharge_daily">Daily rental charge: </label>
<input type="text" id="rentalcharge_daily" name="rentalcharge_daily" size="10" value="[% itemtype.rentalcharge_daily | $Price %]" />
- <span class="hint">This fee is charged a checkout/renewal time for each day between the checkout/renewal date and due date.</span>
+ <span class="hint">This fee is charged at checkout/renewal time for each day between the checkout/renewal date and due date for loans specified in days.</span>
+ </li>
+ <li>
+ <label for="rentalcharge_hourly">Hourly rental charge: </label>
+ <input type="text" id="rentalcharge_hourly" name="rentalcharge_hourly" size="10" value="[% itemtype.rentalcharge_hourly | $Price %]" />
+ <span class="hint">This fee is charged at checkout/renewal time for each hour between the checkout/renewal date and due date for loans specifie in hours.</span>
</li>
<li>
<label for="defaultreplacecost">Default replacement cost: </label>
<th>Hide in OPAC</th>
<th>Rental charge</th>
<th>Daily rental charge</th>
+ <th>Hourly rental charge</th>
<th>Default replacement cost</th>
<th>Processing fee (when lost)</th>
<th>Checkin message</th>
[% itemtype.rentalcharge_daily | $Price %]
[% END %]
</td>
+ <td>
+ [% UNLESS ( itemtype.notforloan ) %]
+ [% itemtype.rentalcharge_hourly | $Price %]
+ [% END %]
+ </td>
+
<td>[% itemtype.defaultreplacecost | $Price %]</td>
<td>[% itemtype.processfee | $Price %]</td>
<td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
[% END %]
[% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge | $Price %] </li>[% END %]
[% IF ( rentalcharge_daily ) %]<li><span class="label">Daily rental charge:</span>[% rentalcharge_daily | $Price %] </li>[% END %]
+ [% IF ( rentalcharge_hourly ) %]<li><span class="label">Hourly rental charge:</span>[% rentalcharge_hourly | $Price %] </li>[% END %]
<li><span class="label">ISBN:</span> [% isbn | html %] </li>
<li><span class="label">Publisher:</span>[% place | html %] [% publishercode | html %] [% publicationyear | html %] </li>
[% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc | html %]</li>[% END %]