show rfid sid
[koha_ffzg] / ffzg / discharge / pdf.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2013 BibLibre
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 Carp;
22
23 use C4::Auth qw(:DEFAULT get_session);
24 use CGI qw( -utf8 );
25 use C4::Context;
26 use C4::Output;
27 use C4::Log;
28 use C4::Debug;
29 use Koha::Patrons;
30 use Koha::Patron::Discharge;
31 use Koha::DateUtils;
32
33 my $input = new CGI;
34
35 unless ( C4::Context->preference('useDischarge') ) {
36     exit;
37 }
38
39 my $borrowernumber = $input->param("borrowernumber") // '';
40
41 my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $borrowernumber });
42 my $pending = Koha::Patron::Discharge::count({
43     borrowernumber => $borrowernumber,
44     pending        => 1,
45 });
46 my $available = Koha::Patron::Discharge::is_discharged({borrowernumber => $borrowernumber});
47
48 use Data::Dump qw(dump);
49 warn "XXX borrowernumber = $borrowernumber can_be_discharged = $can_be_discharged pending = $pending available = $available";
50
51 if ( $pending || ! $available || ! $can_be_discharged ) {
52         print $input->header( -type       => 'text/plain' );
53         print "borrowernumber = $borrowernumber can_be_discharged = $can_be_discharged pending = $pending available = $available";
54         exit;
55 }
56
57         # Getting member data
58         my $patron = Koha::Patrons->find( $borrowernumber );
59         my $pdf_path = Koha::Patron::Discharge::generate_as_pdf({
60             borrowernumber => $borrowernumber,
61             branchcode => $patron->branchcode,
62         });
63
64         binmode(STDOUT);
65         print $input->header(
66             -type       => 'application/pdf',
67             -charset    => 'utf-8',
68             -attachment => "discharge_$borrowernumber.pdf",
69         );
70         open my $fh, '<', $pdf_path;
71         my @lines = <$fh>;
72         close $fh;
73         print @lines;
74
75         exit;
76