3 # Copyright 2018 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Carp qw( confess );
25 use Koha::DateUtils qw( dt_from_string );
30 Koha::Feess - Module calculating fees in Koha
40 [ from_date => $from_dt, ]
47 my ( $class, $params ) = @_;
49 Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: patron")
50 unless $params->{patron};
51 Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: library")
52 unless $params->{library};
53 Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: item")
54 unless $params->{item};
55 Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: to_date")
56 unless $params->{to_date};
58 Carp::confess("Key 'patron' is not a Koha::Patron object!")
59 unless $params->{patron}->isa('Koha::Patron');
60 Carp::confess("Key 'library' is not a Koha::Library object!")
61 unless $params->{library}->isa('Koha::Library');
62 Carp::confess("Key 'item' is not a Koha::Item object!")
63 unless $params->{item}->isa('Koha::Item');
64 Carp::confess("Key 'to_date' is not a DateTime object!")
65 unless $params->{to_date}->isa('DateTime');
67 if ( $params->{from_date} ) {
68 Carp::croak("Key 'from_date' is not a DateTime object!")
69 unless $params->{from_date}->isa('DateTime');
72 $params->{from_date} = dt_from_string();
75 return bless( $params, $class );
78 =head3 rental_charge_daily
80 my $fee = $self->rental_charge_daily();
82 This method calculates the daily rental fee for a given itemtype for a given
83 period of time passed in as a pair of DateTime objects.
87 sub rental_charge_daily {
88 my ( $self, $params ) = @_;
90 my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
91 my $rental_charge_daily = $itemtype->rental_charge_daily;
93 return undef unless $rental_charge_daily && $rental_charge_daily > 0;
96 if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
97 my $calendar = Koha::Calendar->new( branchcode => $self->library->id );
98 $duration = $calendar->days_between( $self->from_date, $self->to_date );
101 $duration = $self->to_date->delta_days($self->from_date);
103 my $days = $duration->in_units('days');
105 my $charge = $rental_charge_daily * $days;
112 my $patron = $fees->patron( $patron );
117 my ( $self, $patron ) = @_;
119 $self->{patron} = $patron if $patron && $patron->isa('Koha::Patron');
121 return $self->{patron};
126 my $library = $fees->library( $library );
131 my ( $self, $library ) = @_;
133 $self->{library} = $library if $library && $library->isa('Koha::Library');
135 return $self->{library};
140 my $item = $fees->item( $item );
145 my ( $self, $item ) = @_;
147 $self->{item} = $item if $item && $item->isa('Koha::Item');
149 return $self->{item};
154 my $to_date = $fees->to_date( $to_date );
159 my ( $self, $to_date ) = @_;
161 $self->{to_date} = $to_date if $to_date && $to_date->isa('DateTime');
163 return $self->{to_date};
168 my $from_date = $fees->from_date( $from_date );
173 my ( $self, $from_date ) = @_;
175 $self->{from_date} = $from_date if $from_date && $from_date->isa('DateTime');
177 return $self->{from_date};
182 Kyle M Hall <kyle.m.hall@gmail.com>