1 package Koha::ItemType;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use Koha::IssuingRules;
26 use Koha::Localizations;
28 use base qw(Koha::Object);
32 Koha::ItemType - Koha Item type Object class
45 my ( $self, $interface ) = @_;
46 return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl );
49 =head3 translated_description
53 sub translated_description {
54 my ( $self, $lang ) = @_;
55 if ( my $translated_description = eval { $self->get_column('translated_description') } ) {
56 # If the value has already been fetched (eg. from sarch_with_localization),
57 # do not search for it again
58 # Note: This is a bit hacky but should be fast
59 return $translated_description
60 ? $translated_description
63 $lang ||= C4::Languages::getlanguage;
64 my $translated_description = Koha::Localizations->search({
65 code => $self->itemtype,
66 entity => 'itemtypes',
69 return $translated_description
70 ? $translated_description->translation
74 =head3 translated_descriptions
78 sub translated_descriptions {
80 my @translated_descriptions = Koha::Localizations->search(
81 { entity => 'itemtypes',
82 code => $self->itemtype,
88 translation => $_->translation,
90 } @translated_descriptions ];
93 =head3 calc_rental_charge_daily
95 my $fee = $itemtype->calc_rental_charge_daily( { from => $dt_from, to => $dt_to } );
97 This method calculates the daily rental fee for a given itemtype for a given
98 period of time passed in as a pair of DateTime objects.
102 sub calc_rental_charge_daily {
103 my ( $self, $params ) = @_;
105 my $rental_charge_daily = $self->rental_charge_daily;
106 return 0 unless $rental_charge_daily;
108 my $from_dt = $params->{from};
109 my $to_dt = $params->{to};
112 if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
113 my $branchcode = C4::Context->userenv->{branch};
114 my $calendar = Koha::Calendar->new( branchcode => $branchcode );
115 $duration = $calendar->days_between( $from_dt, $to_dt );
118 $duration = $to_dt->delta_days($from_dt);
120 my $days = $duration->in_units('days');
122 my $charge = $rental_charge_daily * $days;
128 =head3 can_be_deleted
130 my $can_be_deleted = Koha::ItemType->can_be_deleted();
132 Counts up the number of biblioitems and items with itemtype (code) and hands back the combined number of biblioitems and items with the itemtype
138 my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
139 my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count;
140 return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
143 =head3 may_article_request
145 Returns true if it is likely possible to make an article request for
147 Optional parameter: categorycode (for patron).
151 sub may_article_request {
152 my ( $self, $params ) = @_;
153 return q{} if !C4::Context->preference('ArticleRequests');
154 my $itemtype = $self->itemtype;
155 my $category = $params->{categorycode};
157 my $guess = Koha::IssuingRules->guess_article_requestable_itemtypes({
158 $category ? ( categorycode => $category ) : (),
160 return ( $guess->{ $itemtype // q{} } || $guess->{ '*' } ) ? 1 : q{};