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

(-)a/C4/Circulation.pm (-12 / +25 lines)
Lines 2463-2479 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2463
=cut
2463
=cut
2464
2464
2465
sub CanBookBeRenewed {
2465
sub CanBookBeRenewed {
2466
2467
    # check renewal status
2468
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2466
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2467
2469
    my $dbh       = C4::Context->dbh;
2468
    my $dbh       = C4::Context->dbh;
2470
    my $renews    = 1;
2469
    my $renews    = 1;
2471
    my $renewokay = 0;
2470
    my $renewokay = 0;
2472
    my $error;
2471
    my $error;
2473
2472
2474
    my $borrower    = C4::Members::GetMemberDetails( $borrowernumber, 0 )   or return;
2473
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2475
    my $item        = GetItem($itemnumber)                                  or return;
2474
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2476
    my $itemissue   = GetItemIssue($itemnumber)                             or return;
2475
2476
    $borrowernumber ||= $itemissue->{borrowernumber};
2477
    my $borrower = C4::Members::GetMemberDetails($borrowernumber)
2478
      or return;
2477
2479
2478
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2480
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2479
2481
Lines 2492-2497 sub CanBookBeRenewed { Link Here
2492
        $error = "on_reserve";
2494
        $error = "on_reserve";
2493
    }
2495
    }
2494
2496
2497
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2498
        $renewokay = 1;
2499
    } else {
2500
        $error = "too_many";
2501
    }
2502
2495
    return ( $renewokay, $error );
2503
    return ( $renewokay, $error );
2496
}
2504
}
2497
2505
Lines 2520-2546 from the book's item type. Link Here
2520
=cut
2528
=cut
2521
2529
2522
sub AddRenewal {
2530
sub AddRenewal {
2523
    my $borrowernumber  = shift or return;
2531
    my $borrowernumber  = shift;
2524
    my $itemnumber      = shift or return;
2532
    my $itemnumber      = shift or return;
2525
    my $branch          = shift;
2533
    my $branch          = shift;
2526
    my $datedue         = shift;
2534
    my $datedue         = shift;
2527
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2535
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2536
2528
    my $item   = GetItem($itemnumber) or return;
2537
    my $item   = GetItem($itemnumber) or return;
2529
    my $biblio = GetBiblioFromItemNumber($itemnumber) or return;
2538
    my $biblio = GetBiblioFromItemNumber($itemnumber) or return;
2530
2539
2531
    my $dbh = C4::Context->dbh;
2540
    my $dbh = C4::Context->dbh;
2541
2532
    # Find the issues record for this book
2542
    # Find the issues record for this book
2533
    my $sth =
2543
    my $sth =
2534
      $dbh->prepare("SELECT * FROM issues
2544
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2535
                        WHERE borrowernumber=? 
2545
    $sth->execute( $itemnumber );
2536
                        AND itemnumber=?"
2537
      );
2538
    $sth->execute( $borrowernumber, $itemnumber );
2539
    my $issuedata = $sth->fetchrow_hashref;
2546
    my $issuedata = $sth->fetchrow_hashref;
2540
    if(defined $datedue && ref $datedue ne 'DateTime' ) {
2547
2548
    return unless ( $issuedata );
2549
2550
    $borrowernumber ||= $issuedata->{borrowernumber};
2551
2552
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2541
        carp 'Invalid date passed to AddRenewal.';
2553
        carp 'Invalid date passed to AddRenewal.';
2542
        return;
2554
        return;
2543
    }
2555
    }
2556
2544
    # If the due date wasn't specified, calculate it by adding the
2557
    # If the due date wasn't specified, calculate it by adding the
2545
    # book's loan length to today's date or the current due date
2558
    # book's loan length to today's date or the current due date
2546
    # based on the value of the RenewalPeriodBase syspref.
2559
    # based on the value of the RenewalPeriodBase syspref.
(-)a/C4/Items.pm (+4 lines)
Lines 145-150 sub GetItem { Link Here
145
    my ($itemnumber,$barcode, $serial) = @_;
145
    my ($itemnumber,$barcode, $serial) = @_;
146
    my $dbh = C4::Context->dbh;
146
    my $dbh = C4::Context->dbh;
147
	my $data;
147
	my $data;
148
148
    if ($itemnumber) {
149
    if ($itemnumber) {
149
        my $sth = $dbh->prepare("
150
        my $sth = $dbh->prepare("
150
            SELECT * FROM items 
151
            SELECT * FROM items 
Lines 159-164 sub GetItem { Link Here
159
        $sth->execute($barcode);		
160
        $sth->execute($barcode);		
160
        $data = $sth->fetchrow_hashref;
161
        $data = $sth->fetchrow_hashref;
161
    }
162
    }
163
164
    return unless ( $data );
165
162
    if ( $serial) {      
166
    if ( $serial) {      
163
    my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
167
    my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
164
        $ssth->execute($data->{'itemnumber'}) ;
168
        $ssth->execute($data->{'itemnumber'}) ;
(-)a/C4/Reserves.pm (-3 / +4 lines)
Lines 800-809 sub GetReserveStatus { Link Here
800
    if(defined $found) {
800
    if(defined $found) {
801
        return 'Waiting'  if $found eq 'W' and $priority == 0;
801
        return 'Waiting'  if $found eq 'W' and $priority == 0;
802
        return 'Finished' if $found eq 'F';
802
        return 'Finished' if $found eq 'F';
803
        return 'Reserved' if $priority > 0;
804
    }
803
    }
805
    return '';
804
806
    #empty string here will remove need for checking undef, or less log lines
805
    return 'Reserved' if $priority > 0;
806
807
    return ''; # empty string here will remove need for checking undef, or less log lines
807
}
808
}
808
809
809
=head2 CheckReserves
810
=head2 CheckReserves
(-)a/Koha/Schema/Result/Issue.pm (-1 / +6 lines)
Lines 183-188 __PACKAGE__->belongs_to( Link Here
183
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
183
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZEh31EKBmURMKxDxI+H3EA
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZEh31EKBmURMKxDxI+H3EA
185
185
186
__PACKAGE__->belongs_to(
187
  "borrower",
188
  "Koha::Schema::Result::Borrower",
189
  { borrowernumber => "borrowernumber" },
190
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
191
);
186
192
187
# You can replace this text with custom content, and it will be preserved on regeneration
188
1;
193
1;
(-)a/Koha/Schema/Result/Item.pm (-1 / +5 lines)
Lines 588-593 __PACKAGE__->might_have( Link Here
588
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
588
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
589
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JV1Q/UVlKQ6QgVFMGBIZCw
589
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JV1Q/UVlKQ6QgVFMGBIZCw
590
590
591
__PACKAGE__->belongs_to(
592
    "biblio",
593
    "Koha::Schema::Result::Biblio",
594
    { "foreign.biblionumber" => "self.biblionumber" }
595
);
591
596
592
# You can replace this text with custom content, and it will be preserved on regeneration
593
1;
597
1;
(-)a/circ/renew.pl (+102 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2013 ByWater Solutions
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 2 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 Modern::Perl;
21
22
use CGI;
23
use C4::Context;
24
use C4::Auth qw/:DEFAULT get_session/;
25
use C4::Output;
26
use C4::Circulation;
27
use Koha::DateUtils;
28
use Koha::Database;
29
30
my $cgi = new CGI;
31
32
my ( $template, $librarian, $cookie ) = get_template_and_user(
33
    {
34
        template_name   => "circ/renew.tmpl",
35
        query           => $cgi,
36
        type            => "intranet",
37
        authnotrequired => 0,
38
        flagsrequired   => { circulate => "circulate_remaining_permissions" },
39
    }
40
);
41
42
my $schema = Koha::Database->new()->schema();
43
44
my $barcode        = $cgi->param('barcode');
45
my $override_limit = $cgi->param('override_limit');
46
my $override_holds = $cgi->param('override_holds');
47
48
my ( $item, $issue, $borrower, $error );
49
50
if ($barcode) {
51
    $item = $schema->resultset("Item")->single( { barcode => $barcode } );
52
53
    if ($item) {
54
55
        $issue = $item->issues()->single();
56
57
        if ($issue) {
58
59
            $borrower = $issue->borrower();
60
61
            if ( $borrower->debarred() lt dt_from_string()->ymd() ) {
62
                my $can_renew;
63
                ( $can_renew, $error ) =
64
                  CanBookBeRenewed( $borrower->borrowernumber(),
65
                    $item->itemnumber(), $override_limit );
66
67
                if ( $error eq 'on_reserve' ) {
68
                    if ($override_holds) {
69
                        $can_renew = 1;
70
                        $error     = undef;
71
                    }
72
                    else {
73
                        $can_renew = 0;
74
                    }
75
                }
76
77
                if ($can_renew) {
78
                    my $date_due = AddRenewal( undef, $item->itemnumber() );
79
                    $template->param( date_due => $date_due );
80
                }
81
            }
82
            else {
83
                $error = "patron_restricted";
84
            }
85
        }
86
        else {
87
            $error = "no_checkout";
88
        }
89
    }
90
    else {
91
        $error = "no_item";
92
    }
93
94
    $template->param(
95
        item     => $item,
96
        issue    => $issue,
97
        borrower => $borrower,
98
        error    => $error
99
    );
100
}
101
102
output_html_with_http_headers( $cgi, $cookie, $template->output );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt (+1 lines)
Lines 19-24 Link Here
19
	<ul>
19
	<ul>
20
        <li><a href="/cgi-bin/koha/circ/circulation.pl">Check out</a></li>
20
        <li><a href="/cgi-bin/koha/circ/circulation.pl">Check out</a></li>
21
        <li><a href="/cgi-bin/koha/circ/returns.pl">Check in</a></li>
21
        <li><a href="/cgi-bin/koha/circ/returns.pl">Check in</a></li>
22
        <li><a href="/cgi-bin/koha/circ/renew.pl">Renew</a></li>
22
    [% IF ( display_transfer ) %]
23
    [% IF ( display_transfer ) %]
23
		<li><a href="/cgi-bin/koha/circ/branchtransfers.pl">Transfer</a></li>
24
		<li><a href="/cgi-bin/koha/circ/branchtransfers.pl">Transfer</a></li>
24
    [% END %]
25
    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt (-1 / +131 lines)
Line 0 Link Here
0
- 
1
[% USE Koha %]
2
[% USE KohaDates %]
3
[% USE KohaBranchName %]
4
5
[% INCLUDE 'doc-head-open.inc' %]
6
7
<title>Koha &rsaquo; Circulation &rsaquo; Renew [% title |html %]</title>
8
9
[% INCLUDE 'doc-head-close.inc' %]
10
11
<script type="text/javascript">
12
//<![CDATA[
13
14
$(document).ready(function () {
15
    $("#barcode").focus();
16
});
17
18
//]]>
19
</script>
20
21
</head>
22
23
<body>
24
25
[% INCLUDE 'header.inc' %]
26
[% INCLUDE 'circ-search.inc' %]
27
28
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a> &rsaquo; Check in</div>
29
30
<div id="doc" class="yui-t7">
31
    <div id="bd">
32
            <div id="yui-main">
33
34
            <div class="yui-g">
35
                [% IF error %]
36
                    <div class="dialog alert">
37
                        <h3>Cannot renew:</h3>
38
                        <p>
39
                            [% IF error == "no_item" %]
40
41
                                No item matches this barcode
42
43
                            [% ELSIF error == "no_checkout" %]
44
45
                                <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title %] [% item.biblioitem.subtitle %]</a>
46
                                ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&biblionumber=[% item.biblionumber %]&bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> )
47
                                is not checked out to a patron.
48
49
                            [% ELSIF error == "too_many" %]
50
51
                                [% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] )
52
                                has been renewed the maximum number of times by
53
                                [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> )
54
55
                                [% IF Koha.Preference('AllowRenewalLimitOverride') %]
56
                                    <form method="post" action="/cgi-bin/koha/circ/renew.pl" autocomplete="off" >
57
                                        <input type="hidden" name="barcode" value="[% item.barcode %]"/>
58
                                        <input type="hidden" name="override_limit" value="1" />
59
                                        <input type="submit" class="submit" value="Override limit and renew" />
60
                                    </form>
61
                                [% END %]
62
63
                            [% ELSIF error == "on_reserve" %]
64
65
                                This item is on hold for other patrons.
66
67
                                <form method="post" action="/cgi-bin/koha/circ/renew.pl" autocomplete="off" >
68
                                    <input type="hidden" name="barcode" value="[% item.barcode %]"/>
69
                                    <input type="hidden" name="override_limit" value="1" />
70
                                    <input type="hidden" name="override_holds" value="1" />
71
                                    <input type="submit" class="submit" value="Override and renew" />
72
                                </form>
73
74
                            [% ELSIF error == "patron_restricted" %]
75
76
                                [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> )
77
                                is currently restricted.
78
79
                            [% ELSE %]
80
81
                                [% error %]
82
83
                            [% END %]
84
85
                            <a href="/cgi-bin/koha/circ/renew.pl">Ignore & continue</a>
86
                        </p>
87
                    </div>
88
                [% END %]
89
90
                [% IF date_due %]
91
                    <div class="dialog message">
92
                        <p>
93
                            <h3>Item renewed:</h3>
94
95
                            <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title %] [% item.biblioitem.subtitle %]</a>
96
                            ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&biblionumber=[% item.biblionumber %]&bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> )
97
                            renewed for
98
                            [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> )
99
                            now due on [% date_due | $KohaDates %]
100
                        </p>
101
                    </div>
102
                [% END %]
103
            </div>
104
105
            <div class="yui-g">
106
107
            [% UNLESS error %]
108
                <form method="post" action="/cgi-bin/koha/circ/renew.pl" autocomplete="off" >
109
110
                    <div class="yui-u first">
111
                        <fieldset>
112
                            <legend>Renew</legend>
113
114
                            <label for="barcode">Enter item barcode: </label>
115
116
                            <input name="barcode" id="barcode" size="14" class="focus"/>
117
118
                            <input type="submit" class="submit" value="Submit" />
119
                        </fieldset>
120
                    </div>
121
122
                </form>
123
            [% END %]
124
125
        </div>
126
127
    </div>
128
129
<div>
130
131
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 10493