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

(-)a/C4/Circulation.pm (-19 / +25 lines)
Lines 2456-2489 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2456
=cut
2456
=cut
2457
2457
2458
sub CanBookBeRenewed {
2458
sub CanBookBeRenewed {
2459
2460
    # check renewal status
2461
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2459
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2460
2462
    my $dbh       = C4::Context->dbh;
2461
    my $dbh       = C4::Context->dbh;
2463
    my $renews    = 1;
2462
    my $renews    = 1;
2464
    my $renewokay = 0;
2463
    my $renewokay = 0;
2465
    my $error;
2464
    my $error;
2466
2465
2467
    my $borrower    = C4::Members::GetMemberDetails( $borrowernumber, 0 )   or return;
2466
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2468
    my $item        = GetItem($itemnumber)                                  or return;
2467
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2469
    my $itemissue   = GetItemIssue($itemnumber)                             or return;
2468
2469
    $borrowernumber ||= $itemissue->{borrowernumber};
2470
    my $borrower = C4::Members::GetMemberDetails($borrowernumber)
2471
      or return;
2470
2472
2471
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2473
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2472
2474
2473
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2475
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2474
2476
2475
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2476
        $renewokay = 1;
2477
    } else {
2478
        $error = "too_many";
2479
    }
2480
2481
    my $resstatus = C4::Reserves::GetReserveStatus($itemnumber);
2477
    my $resstatus = C4::Reserves::GetReserveStatus($itemnumber);
2482
    if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) {
2478
    if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) {
2483
        $renewokay = 0;
2479
        $renewokay = 0;
2484
        $error = "on_reserve";
2480
        $error = "on_reserve";
2485
    }
2481
    }
2486
2482
2483
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2484
        $renewokay = 1;
2485
    } else {
2486
        $error = "too_many";
2487
    }
2488
2487
    return ( $renewokay, $error );
2489
    return ( $renewokay, $error );
2488
}
2490
}
2489
2491
Lines 2512-2539 from the book's item type. Link Here
2512
=cut
2514
=cut
2513
2515
2514
sub AddRenewal {
2516
sub AddRenewal {
2515
    my $borrowernumber  = shift or return;
2517
    my $borrowernumber  = shift;
2516
    my $itemnumber      = shift or return;
2518
    my $itemnumber      = shift or return;
2517
    my $branch          = shift;
2519
    my $branch          = shift;
2518
    my $datedue         = shift;
2520
    my $datedue         = shift;
2519
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2521
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2522
    
2520
    my $item   = GetItem($itemnumber) or return;
2523
    my $item   = GetItem($itemnumber) or return;
2521
    my $biblio = GetBiblioFromItemNumber($itemnumber) or return;
2524
    my $biblio = GetBiblioFromItemNumber($itemnumber) or return;
2522
2525
2523
    my $dbh = C4::Context->dbh;
2526
    my $dbh = C4::Context->dbh;
2527
2524
    # Find the issues record for this book
2528
    # Find the issues record for this book
2525
    my $sth =
2529
    my $sth =
2526
      $dbh->prepare("SELECT * FROM issues
2530
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2527
                        WHERE borrowernumber=? 
2531
    $sth->execute( $itemnumber );
2528
                        AND itemnumber=?"
2529
      );
2530
    $sth->execute( $borrowernumber, $itemnumber );
2531
    my $issuedata = $sth->fetchrow_hashref;
2532
    my $issuedata = $sth->fetchrow_hashref;
2532
    $sth->finish;
2533
2533
    if(defined $datedue && ref $datedue ne 'DateTime' ) {
2534
    return unless ( $issuedata );
2535
2536
    $borrowernumber ||= $issuedata->{borrowernumber};
2537
2538
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2534
        carp 'Invalid date passed to AddRenewal.';
2539
        carp 'Invalid date passed to AddRenewal.';
2535
        return;
2540
        return;
2536
    }
2541
    }
2542
2537
    # If the due date wasn't specified, calculate it by adding the
2543
    # If the due date wasn't specified, calculate it by adding the
2538
    # book's loan length to today's date or the current due date
2544
    # book's loan length to today's date or the current due date
2539
    # based on the value of the RenewalPeriodBase syspref.
2545
    # 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 765-774 sub GetReserveStatus { Link Here
765
    if(defined $found) {
765
    if(defined $found) {
766
        return 'Waiting'  if $found eq 'W' and $priority == 0;
766
        return 'Waiting'  if $found eq 'W' and $priority == 0;
767
        return 'Finished' if $found eq 'F';
767
        return 'Finished' if $found eq 'F';
768
        return 'Reserved' if $priority > 0;
769
    }
768
    }
770
    return '';
769
771
    #empty string here will remove need for checking undef, or less log lines
770
    return 'Reserved' if $priority > 0;
771
772
    return ''; # empty string here will remove need for checking undef, or less log lines
772
}
773
}
773
774
774
=head2 CheckReserves
775
=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 (+97 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' && $override_holds ) {
68
                    $can_renew = 1;
69
                    $error = undef;
70
                }
71
72
                if ($can_renew) {
73
                    my $date_due = AddRenewal( undef, $item->itemnumber() );
74
                    $template->param( date_due => $date_due );
75
                }
76
            }
77
            else {
78
                $error = "patron_restricted";
79
            }
80
        }
81
        else {
82
            $error = "no_checkout";
83
        }
84
    }
85
    else {
86
        $error = "no_item";
87
    }
88
89
    $template->param(
90
        item     => $item,
91
        issue    => $issue,
92
        borrower => $borrower,
93
        error    => $error
94
    );
95
}
96
97
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