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

(-)a/Koha/Borrower/Categories.pm (+67 lines)
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;
(-)a/svc/members/upsert (-1 / +11 lines)
Lines 78-83 use C4::Service; Link Here
78
78
79
use Koha::Borrower::Search
79
use Koha::Borrower::Search
80
  qw( find_borrower find_borrower_from_ext get_borrower_fields );
80
  qw( find_borrower find_borrower_from_ext get_borrower_fields );
81
use Koha::Borrower::Categories;
82
83
use Date::Calc qw( Today );
81
84
82
process_upsert();
85
process_upsert();
83
86
Lines 272-277 sub create_borrower { Link Here
272
        die "Critical field missing (create): $c\n" unless $borr_fields->{$c};
275
        die "Critical field missing (create): $c\n" unless $borr_fields->{$c};
273
    }
276
    }
274
277
278
    # Add enrolement/expiry dates if they're not already there.
279
    unless ($borr_fields->{dateexpiry}) {
280
        $borr_fields->{dateexpiry} = Koha::Borrower::Categories::get_expiry_date($borr_fields->{categorycode});
281
    }
282
    unless ($borr_fields->{dateenrolled}) {
283
        $borr_fields->{dateenrolled} = sprintf('%04d-%02d-%02d', Today());
284
    }
285
275
    # Borrower fields
286
    # Borrower fields
276
    my ( @f_borr, @v_borr );
287
    my ( @f_borr, @v_borr );
277
    while ( my ( $f, $v ) = each %$borr_fields ) {
288
    while ( my ( $f, $v ) = each %$borr_fields ) {
278
- 

Return to bug 13607