|
Line 0
Link Here
|
|
|
1 |
package Koha::Borrower::Categories; |
| 2 |
|
| 3 |
# Copyright 2015 Catalyst IT |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 8 |
# terms of the GNU General Public License as published by the Free Software |
| 9 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 10 |
# version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
|
| 20 |
use C4::Context; |
| 21 |
|
| 22 |
use Carp; |
| 23 |
use Date::Calc qw( Today Add_Delta_Days ); |
| 24 |
|
| 25 |
=head1 NAME |
| 26 |
|
| 27 |
Koha::Borrower::Categories - functions for working with borrower category information |
| 28 |
|
| 29 |
=head1 SYNOPSIS |
| 30 |
|
| 31 |
use Koha::Borrower::Categories; |
| 32 |
$expiry = Koha::Borrower::Categories::GetExpiryDate($catcode, $datefrom); |
| 33 |
|
| 34 |
=head1 DESCRIPTION |
| 35 |
|
| 36 |
This is a place for functions that involve dealing with borrower categories. |
| 37 |
|
| 38 |
=head1 FUNCTIONS |
| 39 |
|
| 40 |
=head2 get_expiry_date |
| 41 |
|
| 42 |
my $expiry = Koha::Borrower::Categories::get_expiry_date($catcode, [$datefrom]); |
| 43 |
|
| 44 |
This calculates the expiry date for a given category. If no origin date is |
| 45 |
provided, then it is taken from C<now>. Provided dates must be ISO8601 form, |
| 46 |
and that's what will be returned. |
| 47 |
|
| 48 |
=cut |
| 49 |
|
| 50 |
sub get_expiry_date { |
| 51 |
my ($catcode, $datefrom) = @_; |
| 52 |
|
| 53 |
croak "No categorycode specified" unless $catcode; |
| 54 |
|
| 55 |
my @datefrom = $datefrom ? split /-/, $datefrom : Today(); |
| 56 |
my $dbh = C4::Context->dbh; |
| 57 |
my $sth = $dbh->prepare('SELECT enrolmentperiod,enrolmentperioddate FROM categories WHERE categorycode=?'); |
| 58 |
$sth->execute($catcode); |
| 59 |
$enrolments = $sth->fetchrow_hashref; |
| 60 |
if ($enrolments->{enrolmentperiod}) { |
| 61 |
return sprintf('%04d-%02d-%02d', Add_Delta_Days(@datefrom, $enrolments->{enrolmentperiod})); |
| 62 |
} else { |
| 63 |
return $enrolments->{enrolmentperioddate}; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
1; |