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

(-)a/C4/Circulation.pm (-19 / +25 lines)
Lines 2462-2495 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2462
=cut
2462
=cut
2463
2463
2464
sub CanBookBeRenewed {
2464
sub CanBookBeRenewed {
2465
2466
    # check renewal status
2467
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2465
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2466
2468
    my $dbh       = C4::Context->dbh;
2467
    my $dbh       = C4::Context->dbh;
2469
    my $renews    = 1;
2468
    my $renews    = 1;
2470
    my $renewokay = 0;
2469
    my $renewokay = 0;
2471
    my $error;
2470
    my $error;
2472
2471
2473
    my $borrower    = C4::Members::GetMemberDetails( $borrowernumber, 0 )   or return;
2472
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2474
    my $item        = GetItem($itemnumber)                                  or return;
2473
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2475
    my $itemissue   = GetItemIssue($itemnumber)                             or return;
2474
2475
    $borrowernumber ||= $itemissue->{borrowernumber};
2476
    my $borrower = C4::Members::GetMemberDetails($borrowernumber)
2477
      or return;
2476
2478
2477
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2479
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2478
2480
2479
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2481
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2480
2482
2481
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2482
        $renewokay = 1;
2483
    } else {
2484
        $error = "too_many";
2485
    }
2486
2487
    my $resstatus = C4::Reserves::GetReserveStatus($itemnumber);
2483
    my $resstatus = C4::Reserves::GetReserveStatus($itemnumber);
2488
    if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) {
2484
    if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) {
2489
        $renewokay = 0;
2485
        $renewokay = 0;
2490
        $error = "on_reserve";
2486
        $error = "on_reserve";
2491
    }
2487
    }
2492
2488
2489
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2490
        $renewokay = 1;
2491
    } else {
2492
        $error = "too_many";
2493
    }
2494
2493
    return ( $renewokay, $error );
2495
    return ( $renewokay, $error );
2494
}
2496
}
2495
2497
Lines 2518-2545 from the book's item type. Link Here
2518
=cut
2520
=cut
2519
2521
2520
sub AddRenewal {
2522
sub AddRenewal {
2521
    my $borrowernumber  = shift or return;
2523
    my $borrowernumber  = shift;
2522
    my $itemnumber      = shift or return;
2524
    my $itemnumber      = shift or return;
2523
    my $branch          = shift;
2525
    my $branch          = shift;
2524
    my $datedue         = shift;
2526
    my $datedue         = shift;
2525
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2527
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2528
2526
    my $item   = GetItem($itemnumber) or return;
2529
    my $item   = GetItem($itemnumber) or return;
2527
    my $biblio = GetBiblioFromItemNumber($itemnumber) or return;
2530
    my $biblio = GetBiblioFromItemNumber($itemnumber) or return;
2528
2531
2529
    my $dbh = C4::Context->dbh;
2532
    my $dbh = C4::Context->dbh;
2533
2530
    # Find the issues record for this book
2534
    # Find the issues record for this book
2531
    my $sth =
2535
    my $sth =
2532
      $dbh->prepare("SELECT * FROM issues
2536
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2533
                        WHERE borrowernumber=? 
2537
    $sth->execute( $itemnumber );
2534
                        AND itemnumber=?"
2535
      );
2536
    $sth->execute( $borrowernumber, $itemnumber );
2537
    my $issuedata = $sth->fetchrow_hashref;
2538
    my $issuedata = $sth->fetchrow_hashref;
2538
    $sth->finish;
2539
2539
    if(defined $datedue && ref $datedue ne 'DateTime' ) {
2540
    return unless ( $issuedata );
2541
2542
    $borrowernumber ||= $issuedata->{borrowernumber};
2543
2544
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2540
        carp 'Invalid date passed to AddRenewal.';
2545
        carp 'Invalid date passed to AddRenewal.';
2541
        return;
2546
        return;
2542
    }
2547
    }
2548
2543
    # If the due date wasn't specified, calculate it by adding the
2549
    # If the due date wasn't specified, calculate it by adding the
2544
    # book's loan length to today's date or the current due date
2550
    # book's loan length to today's date or the current due date
2545
    # based on the value of the RenewalPeriodBase syspref.
2551
    # based on the value of the RenewalPeriodBase syspref.
(-)a/C4/Items.pm (+4 lines)
Lines 144-149 sub GetItem { Link Here
144
    my ($itemnumber,$barcode, $serial) = @_;
144
    my ($itemnumber,$barcode, $serial) = @_;
145
    my $dbh = C4::Context->dbh;
145
    my $dbh = C4::Context->dbh;
146
	my $data;
146
	my $data;
147
147
    if ($itemnumber) {
148
    if ($itemnumber) {
148
        my $sth = $dbh->prepare("
149
        my $sth = $dbh->prepare("
149
            SELECT * FROM items 
150
            SELECT * FROM items 
Lines 158-163 sub GetItem { Link Here
158
        $sth->execute($barcode);		
159
        $sth->execute($barcode);		
159
        $data = $sth->fetchrow_hashref;
160
        $data = $sth->fetchrow_hashref;
160
    }
161
    }
162
163
    return unless ( $data );
164
161
    if ( $serial) {      
165
    if ( $serial) {      
162
    my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
166
    my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=?");
163
        $ssth->execute($data->{'itemnumber'}) ;
167
        $ssth->execute($data->{'itemnumber'}) ;
(-)a/C4/Reserves.pm (-3 / +4 lines)
Lines 788-797 sub GetReserveStatus { Link Here
788
    if(defined $found) {
788
    if(defined $found) {
789
        return 'Waiting'  if $found eq 'W' and $priority == 0;
789
        return 'Waiting'  if $found eq 'W' and $priority == 0;
790
        return 'Finished' if $found eq 'F';
790
        return 'Finished' if $found eq 'F';
791
        return 'Reserved' if $priority > 0;
792
    }
791
    }
793
    return '';
792
794
    #empty string here will remove need for checking undef, or less log lines
793
    return 'Reserved' if $priority > 0;
794
795
    return ''; # empty string here will remove need for checking undef, or less log lines
795
}
796
}
796
797
797
=head2 CheckReserves
798
=head2 CheckReserves
(-)a/Koha/Schema/Result/Issue.pm (-1 / +6 lines)
Lines 147-152 __PACKAGE__->belongs_to( Link Here
147
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-06-18 13:13:57
147
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-06-18 13:13:57
148
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uZUDWDGWOkC3oCOyMaG1sg
148
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uZUDWDGWOkC3oCOyMaG1sg
149
149
150
__PACKAGE__->belongs_to(
151
  "borrower",
152
  "Koha::Schema::Result::Borrower",
153
  { borrowernumber => "borrowernumber" },
154
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
155
);
150
156
151
# You can replace this text with custom content, and it will be preserved on regeneration
152
1;
157
1;
(-)a/Koha/Schema/Result/Item.pm (-1 / +5 lines)
Lines 543-548 __PACKAGE__->might_have( Link Here
543
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-06-18 13:13:57
543
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-06-18 13:13:57
544
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f3HngbnArIKegakzHgcFBg
544
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f3HngbnArIKegakzHgcFBg
545
545
546
__PACKAGE__->belongs_to(
547
    "biblio",
548
    "Koha::Schema::Result::Biblio",
549
    { "foreign.biblionumber" => "self.biblionumber" }
550
);
546
551
547
# You can replace this text with custom content, and it will be preserved on regeneration
548
1;
552
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