Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz> |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
use CGI qw ( -utf8 ); |
22 |
use DateTime; |
23 |
use C4::Auth; |
24 |
use C4::Output; |
25 |
use C4::Context; |
26 |
use Koha::Items; |
27 |
use Koha::Recall; |
28 |
use Koha::Recalls; |
29 |
use Koha::DateUtils; |
30 |
use Koha::IssuingRules; |
31 |
use Koha::Patrons; |
32 |
|
33 |
my $query = new CGI; |
34 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
35 |
{ |
36 |
template_name => "opac-recall.tt", |
37 |
query => $query, |
38 |
type => "opac", |
39 |
authnotrequired => 0, |
40 |
} |
41 |
); |
42 |
|
43 |
my $op = $query->param('op') || ''; |
44 |
|
45 |
my $itemnumber = $query->param('itemnumber'); |
46 |
my $item = Koha::Items->find($itemnumber); |
47 |
my $biblio = Koha::Biblios->find($item->biblionumber); |
48 |
my $recalled = Koha::Recalls->find({ itemnumber => $itemnumber }); |
49 |
my $error; |
50 |
|
51 |
if ($op eq 'request'){ |
52 |
if (!defined($borrowernumber)){ |
53 |
# can't place recall if not logged in |
54 |
$error = 'notloggedin'; |
55 |
print $query->redirect('/cgi-bin/koha/opac-detail.pl?biblionumber='.$item->biblionumber); |
56 |
} elsif (defined $recalled && $recalled->borrowernumber == $borrowernumber){ |
57 |
# can't place a recall on an item that this borrower has already recalled |
58 |
$error = 'duplicate'; |
59 |
} else { |
60 |
# can recall |
61 |
my $borrower = Koha::Patrons->find($borrowernumber); |
62 |
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->categorycode, itemtype => $item->itype, branchcode => $item->holdingbranch }); |
63 |
my $recall_request = Koha::Recall->new({ |
64 |
borrowernumber => $borrowernumber, |
65 |
recalldate => dt_from_string(), |
66 |
biblionumber => $biblio->biblionumber, |
67 |
branchcode => $item->holdingbranch, |
68 |
status => 'R', |
69 |
itemnumber => $itemnumber, |
70 |
itemtype => $item->itype, |
71 |
})->store; |
72 |
if (defined $recall_request->recall_id){ # successful recall |
73 |
my $recall = Koha::Recalls->find($recall_request->recall_id); |
74 |
# updating due date on checkout |
75 |
my $timestamp = dt_from_string($recall->timestamp); |
76 |
my $due_date = $timestamp->add( $issuing_rule->lengthunit => $issuing_rule->recall_due_date_interval ); |
77 |
Koha::Checkouts->find({ itemnumber => $itemnumber })->update({ date_due => $due_date }); |
78 |
|
79 |
$template->param( |
80 |
success => 1, |
81 |
due_interval => $issuing_rule->recall_due_date_interval, |
82 |
due_unit => $issuing_rule->lengthunit |
83 |
); |
84 |
} else { |
85 |
$error = 'failed'; |
86 |
} |
87 |
} |
88 |
} |
89 |
|
90 |
$template->param( |
91 |
biblio => $biblio, |
92 |
itemnumber => $itemnumber, |
93 |
error => $error |
94 |
); |
95 |
|
96 |
output_with_http_headers $query, $cookie, $template->output, 'html'; |