View | Details | Raw Unified | Return to bug 20912
Collapse All | Expand All

(-)a/Koha/Charges/Fees.pm (-11 / +31 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp qw( confess );
22
use Carp qw( confess );
23
23
24
use Koha::Calendar;
24
use Koha::Calendar;
25
use Koha::IssuingRules;
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Exceptions;
27
use Koha::Exceptions;
27
28
Lines 85-109 sub new { Link Here
85
=cut
86
=cut
86
87
87
sub accumulate_rentalcharge {
88
sub accumulate_rentalcharge {
88
    my ( $self, $params ) = @_;
89
    my ( $self ) = @_;
89
90
90
    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
91
    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
91
    my $rentalcharge_daily = $itemtype->rentalcharge_daily;
92
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
92
93
        {
93
    return undef unless $rentalcharge_daily && $rentalcharge_daily > 0;
94
            categorycode => $self->patron->categorycode,
95
            itemtype     => $itemtype->id,
96
            branchcode   => $self->library->id
97
        }
98
    );
99
    my $units = $issuing_rule->lengthunit;
100
    my $rentalcharge_increment = ( $units eq 'days' ) ? $itemtype->rentalcharge_daily : $itemtype->rentalcharge_hourly;
101
102
    return 0 unless $rentalcharge_increment && $rentalcharge_increment > 0;
94
103
95
    my $duration;
104
    my $duration;
96
    if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
105
    my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
97
        my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
106
98
        $duration = $calendar->days_between( $self->from_date, $self->to_date );
107
    if ( $units eq 'hours' ) {
108
        if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
109
            $duration =
110
              $calendar->hours_between( $self->from_date, $self->to_date );
111
        }
112
        else {
113
            $duration = $self->to_date->delta_ms($self->from_date);
114
        }
99
    }
115
    }
100
    else {
116
    else {
101
        $duration = $self->to_date->delta_days($self->from_date);
117
        if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
118
            $duration =
119
              $calendar->days_between( $self->from_date, $self->to_date );
120
        }
121
        else {
122
            $duration = $self->to_date->delta_days( $self->from_date );
123
        }
102
    }
124
    }
103
    my $days = $duration->in_units('days');
104
105
    my $charge = $rentalcharge_daily * $days;
106
125
126
    my $charge = $rentalcharge_increment * $duration->in_units($units);
107
    return $charge;
127
    return $charge;
108
}
128
}
109
129
(-)a/Koha/ItemType.pm (-1 / +1 lines)
Lines 33-39 Koha::ItemType - Koha Item type Object class Link Here
33
33
34
=head1 API
34
=head1 API
35
35
36
=head2 Class Methods
36
=head2 Class methods
37
37
38
=cut
38
=cut
39
39
(-)a/Koha/Schema/Result/Itemtype.pm (-2 / +10 lines)
Lines 47-52 __PACKAGE__->table("itemtypes"); Link Here
47
  is_nullable: 1
47
  is_nullable: 1
48
  size: [28,6]
48
  size: [28,6]
49
49
50
=head2 rentalcharge_hourly
51
52
  data_type: 'decimal'
53
  is_nullable: 1
54
  size: [28,6]
55
50
=head2 defaultreplacecost
56
=head2 defaultreplacecost
51
57
52
  data_type: 'decimal'
58
  data_type: 'decimal'
Lines 117-122 __PACKAGE__->add_columns( Link Here
117
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
123
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
118
  "rentalcharge_daily",
124
  "rentalcharge_daily",
119
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
125
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
126
  "rentalcharge_hourly",
127
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
120
  "defaultreplacecost",
128
  "defaultreplacecost",
121
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
129
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
122
  "processfee",
130
  "processfee",
Lines 234-241 __PACKAGE__->has_many( Link Here
234
);
242
);
235
243
236
244
237
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2018-10-25 12:41:04
245
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-01-31 11:59:27
238
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Iyb9JKB8gdyZPtZloHVxSQ
246
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gYBgGWpeUyFuyzfBNIEKCQ
239
247
240
# Use the ItemtypeLocalization view to create the join on localization
248
# Use the ItemtypeLocalization view to create the join on localization
241
our $LANGUAGE;
249
our $LANGUAGE;
(-)a/admin/itemtypes.pl (-1 / +4 lines)
Lines 73-78 if ( $op eq 'add_form' ) { Link Here
73
    my $description  = $input->param('description');
73
    my $description  = $input->param('description');
74
    my $rentalcharge = $input->param('rentalcharge');
74
    my $rentalcharge = $input->param('rentalcharge');
75
    my $rentalcharge_daily = $input->param('rentalcharge_daily');
75
    my $rentalcharge_daily = $input->param('rentalcharge_daily');
76
    my $rentalcharge_hourly = $input->param('rentalcharge_hourly');
76
    my $defaultreplacecost = $input->param('defaultreplacecost');
77
    my $defaultreplacecost = $input->param('defaultreplacecost');
77
    my $processfee = $input->param('processfee');
78
    my $processfee = $input->param('processfee');
78
    my $image = $input->param('image') || q||;
79
    my $image = $input->param('image') || q||;
Lines 94-99 if ( $op eq 'add_form' ) { Link Here
94
        $itemtype->description($description);
95
        $itemtype->description($description);
95
        $itemtype->rentalcharge($rentalcharge);
96
        $itemtype->rentalcharge($rentalcharge);
96
        $itemtype->rentalcharge_daily($rentalcharge_daily);
97
        $itemtype->rentalcharge_daily($rentalcharge_daily);
98
        $itemtype->rentalcharge_hourly($rentalcharge_hourly);
97
        $itemtype->defaultreplacecost($defaultreplacecost);
99
        $itemtype->defaultreplacecost($defaultreplacecost);
98
        $itemtype->processfee($processfee);
100
        $itemtype->processfee($processfee);
99
        $itemtype->notforloan($notforloan);
101
        $itemtype->notforloan($notforloan);
Lines 118-124 if ( $op eq 'add_form' ) { Link Here
118
                itemtype            => $itemtype_code,
120
                itemtype            => $itemtype_code,
119
                description         => $description,
121
                description         => $description,
120
                rentalcharge        => $rentalcharge,
122
                rentalcharge        => $rentalcharge,
121
                rentalcharge_daily => $rentalcharge_daily,
123
                rentalcharge_daily  => $rentalcharge_daily,
124
                rentalcharge_hourly => $rentalcharge_hourly,
122
                defaultreplacecost  => $defaultreplacecost,
125
                defaultreplacecost  => $defaultreplacecost,
123
                processfee          => $processfee,
126
                processfee          => $processfee,
124
                notforloan          => $notforloan,
127
                notforloan          => $notforloan,
(-)a/installer/data/mysql/atomicupdate/bug_20912.perl (+4 lines)
Lines 5-10 if ( CheckVersion($DBversion) ) { Link Here
5
        $dbh->do("ALTER TABLE `itemtypes` ADD COLUMN `rentalcharge_daily` decimal(28,6) default NULL AFTER `rentalcharge`");
5
        $dbh->do("ALTER TABLE `itemtypes` ADD COLUMN `rentalcharge_daily` decimal(28,6) default NULL AFTER `rentalcharge`");
6
    }
6
    }
7
7
8
    if ( !column_exists( 'itemtypes', 'rentalcharge_hourly' ) ) {
9
        $dbh->do("ALTER TABLE `itemtypes` ADD COLUMN `rentalcharge_hourly` decimal(28,6) default NULL AFTER `rentalcharge_daily`");
10
    }
11
8
    if ( column_exists( 'itemtypes', 'rental_charge_daily' ) ) {
12
    if ( column_exists( 'itemtypes', 'rental_charge_daily' ) ) {
9
        $dbh->do("UPDATE `itemtypes` SET `rentalcharge_daily` = `rental_charge_daily`");
13
        $dbh->do("UPDATE `itemtypes` SET `rentalcharge_daily` = `rental_charge_daily`");
10
        $dbh->do("ALTER TABLE `itemtypes` DROP COLUMN `rental_charge_daily`");
14
        $dbh->do("ALTER TABLE `itemtypes` DROP COLUMN `rental_charge_daily`");
(-)a/installer/data/mysql/kohastructure.sql (-1 / +2 lines)
Lines 988-994 CREATE TABLE `itemtypes` ( -- defines the item types Link Here
988
  itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type
988
  itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type
989
  description LONGTEXT, -- a plain text explanation of the item type
989
  description LONGTEXT, -- a plain text explanation of the item type
990
  rentalcharge decimal(28,6) default NULL, -- the amount charged when this item is checked out/issued
990
  rentalcharge decimal(28,6) default NULL, -- the amount charged when this item is checked out/issued
991
  rentalcharge_daily decimal(28,6) default NULL, -- the amount charged for each increment (day/hour) between checkout date and due date
991
  rentalcharge_daily decimal(28,6) default NULL, -- the amount charged for each day between checkout date and due date
992
  rentalcharge_hourly decimal(28,6) default NULL, -- the amount charged for each hour between checkout date and due date
992
  defaultreplacecost decimal(28,6) default NULL, -- default replacement cost
993
  defaultreplacecost decimal(28,6) default NULL, -- default replacement cost
993
  processfee decimal(28,6) default NULL, -- default text be recorded in the column note when the processing fee is applied
994
  processfee decimal(28,6) default NULL, -- default text be recorded in the column note when the processing fee is applied
994
  notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan
995
  notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-1 / +13 lines)
Lines 237-243 Item types administration Link Here
237
                <li>
237
                <li>
238
                    <label for="rentalcharge_daily">Daily rental charge: </label>
238
                    <label for="rentalcharge_daily">Daily rental charge: </label>
239
                    <input type="text" id="rentalcharge_daily" name="rentalcharge_daily" size="10" value="[% itemtype.rentalcharge_daily | $Price %]" />
239
                    <input type="text" id="rentalcharge_daily" name="rentalcharge_daily" size="10" value="[% itemtype.rentalcharge_daily | $Price %]" />
240
                    <span class="hint">This fee is charged a checkout/renewal time for each day between the checkout/renewal date and due date.</span>
240
                    <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>
241
                </li>
242
                <li>
243
                    <label for="rentalcharge_hourly">Hourly rental charge: </label>
244
                    <input type="text" id="rentalcharge_hourly" name="rentalcharge_hourly" size="10" value="[% itemtype.rentalcharge_hourly | $Price %]" />
245
                    <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>
241
                </li>
246
                </li>
242
                <li>
247
                <li>
243
                    <label for="defaultreplacecost">Default replacement cost: </label>
248
                    <label for="defaultreplacecost">Default replacement cost: </label>
Lines 338-343 Item types administration Link Here
338
            <th>Hide in OPAC</th>
343
            <th>Hide in OPAC</th>
339
            <th>Rental charge</th>
344
            <th>Rental charge</th>
340
            <th>Daily rental charge</th>
345
            <th>Daily rental charge</th>
346
            <th>Hourly rental charge</th>
341
            <th>Default replacement cost</th>
347
            <th>Default replacement cost</th>
342
            <th>Processing fee (when lost)</th>
348
            <th>Processing fee (when lost)</th>
343
            <th>Checkin message</th>
349
            <th>Checkin message</th>
Lines 384-389 Item types administration Link Here
384
              [% itemtype.rentalcharge_daily | $Price %]
390
              [% itemtype.rentalcharge_daily | $Price %]
385
            [% END %]
391
            [% END %]
386
            </td>
392
            </td>
393
            <td>
394
            [% UNLESS ( itemtype.notforloan ) %]
395
              [% itemtype.rentalcharge_hourly | $Price %]
396
            [% END %]
397
            </td>
398
387
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
399
            <td>[% itemtype.defaultreplacecost | $Price %]</td>
388
            <td>[% itemtype.processfee | $Price %]</td>
400
            <td>[% itemtype.processfee | $Price %]</td>
389
            <td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
401
            <td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +1 lines)
Lines 35-40 Link Here
35
        [% END %]
35
        [% END %]
36
        [% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge | $Price %]&nbsp;</li>[% END %]
36
        [% IF ( rentalcharge ) %]<li><span class="label">Rental charge:</span>[% rentalcharge | $Price %]&nbsp;</li>[% END %]
37
        [% IF ( rentalcharge_daily ) %]<li><span class="label">Daily rental charge:</span>[% rentalcharge_daily | $Price %]&nbsp;</li>[% END %]
37
        [% IF ( rentalcharge_daily ) %]<li><span class="label">Daily rental charge:</span>[% rentalcharge_daily | $Price %]&nbsp;</li>[% END %]
38
        [% IF ( rentalcharge_hourly ) %]<li><span class="label">Hourly rental charge:</span>[% rentalcharge_hourly | $Price %]&nbsp;</li>[% END %]
38
        <li><span class="label">ISBN:</span> [% isbn | html %]&nbsp;</li>
39
        <li><span class="label">ISBN:</span> [% isbn | html %]&nbsp;</li>
39
        <li><span class="label">Publisher:</span>[% place | html %] [% publishercode | html %] [% publicationyear | html %]&nbsp;</li>
40
        <li><span class="label">Publisher:</span>[% place | html %] [% publishercode | html %] [% publicationyear | html %]&nbsp;</li>
40
        [% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc | html %]</li>[% END %]
41
        [% IF ( volumeddesc ) %]<li><span class="label">Volume:</span> [% volumeddesc | html %]</li>[% END %]
41
- 

Return to bug 20912