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>.
26 Allows librarian to edit and/or manage borrowers' discharges
38 use Koha::Borrower::Discharge;
43 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
44 template_name => 'members/discharge.tt',
48 flagsrequired => { 'borrowers' => '*' },
53 if ( $input->param('borrowernumber') ) {
54 $borrowernumber = $input->param('borrowernumber');
57 $data = GetMember( borrowernumber => $borrowernumber );
59 my $can_be_discharged = Koha::Borrower::Discharge::can_be_discharged({
60 borrowernumber => $borrowernumber
64 my @reserves = GetReservesFromBorrowernumber($borrowernumber);
65 my $has_reserves = scalar(@reserves);
67 # Generating discharge if needed
68 if ( $input->param('discharge') and $can_be_discharged ) {
69 my $is_discharged = Koha::Borrower::Discharge::count({
70 borrowernumber => $borrowernumber,
73 unless ($is_discharged) {
74 Koha::Borrower::Discharge::discharge({
75 borrowernumber => $borrowernumber
78 my $pdf_path = Koha::Borrower::Discharge::generate_as_pdf(
79 { borrowernumber => $borrowernumber, } );
82 -type => 'application/pdf',
84 -attachment => "discharge_$borrowernumber.pdf",
86 open my $fh, '<', $pdf_path;
94 borrowernumber => $borrowernumber,
95 biblionumber => $data->{'biblionumber'},
96 title => $data->{'title'},
97 initials => $data->{'initials'},
98 surname => $data->{'surname'},
99 borrowernumber => $borrowernumber,
100 firstname => $data->{'firstname'},
101 cardnumber => $data->{'cardnumber'},
102 categorycode => $data->{'categorycode'},
103 category_type => $data->{'category_type'},
104 categoryname => $data->{'description'},
105 address => $data->{'address'},
106 address2 => $data->{'address2'},
107 city => $data->{'city'},
108 zipcode => $data->{'zipcode'},
109 country => $data->{'country'},
110 phone => $data->{'phone'},
111 email => $data->{'email'},
112 branchcode => $data->{'branchcode'},
113 has_reserves => $has_reserves,
114 can_be_discharged => $can_be_discharged,
118 $template->param( dischargeview => 1, );
120 output_html_with_http_headers $input, $cookie, $template->output;