3 # This file is part of Koha.
5 # Copyright 2013 BibLibre
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.
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.
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>.
23 use C4::Auth qw(:DEFAULT get_session);
31 use Koha::Patron::Discharge;
36 unless ( C4::Context->preference('useDischarge') ) {
37 print $input->redirect("/cgi-bin/koha/errors/404.pl");
41 my $op = $input->param("op");
43 # Getting the template and auth
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
45 template_name => "opac-discharge.tt",
51 if ( $op eq 'request' ) {
52 my $success = Koha::Patron::Discharge::request({
53 borrowernumber => $loggedinuser,
57 $template->param( success => 1 );
60 $template->param( has_issues => 1 );
63 elsif ( $op eq 'get' ) {
67 my $data = GetMember( borrowernumber => $loggedinuser );
68 my $pdf_path = Koha::Patron::Discharge::generate_as_pdf({
69 borrowernumber => $loggedinuser,
70 branchcode => $data->{'branchcode'},
75 -type => 'application/pdf',
77 -attachment => "discharge_$loggedinuser.pdf",
79 open my $fh, '<', $pdf_path;
87 $template->param( messages => [ {type => 'error', code => 'unable_to_generate_pdf'} ] );
91 my $pending = Koha::Patron::Discharge::count({
92 borrowernumber => $loggedinuser,
95 my $available = Koha::Patron::Discharge::count({
96 borrowernumber => $loggedinuser,
100 available => $available && Koha::Patron::Discharge::is_discharged({borrowernumber => $loggedinuser}),
105 $template->param( dischargeview => 1 );
107 output_html_with_http_headers $input, $cookie, $template->output, undef, { force_no_caching => 1 };