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
39 use Koha
::Patron
::Discharge
;
40 use Koha
::Patron
::Images
;
45 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
({
46 template_name
=> 'members/discharge.tt',
50 flagsrequired
=> { 'borrowers' => '*' },
55 if ( $input->param('borrowernumber') ) {
56 $borrowernumber = $input->param('borrowernumber');
59 $data = GetMember
( borrowernumber
=> $borrowernumber );
61 my $can_be_discharged = Koha
::Patron
::Discharge
::can_be_discharged
({
62 borrowernumber
=> $borrowernumber
66 my @reserves = GetReservesFromBorrowernumber
($borrowernumber);
67 my $has_reserves = scalar(@reserves);
69 # Generating discharge if needed
70 if ( $input->param('discharge') and $can_be_discharged ) {
71 my $is_discharged = Koha
::Patron
::Discharge
::is_discharged
({
72 borrowernumber
=> $borrowernumber,
74 unless ($is_discharged) {
75 Koha
::Patron
::Discharge
::discharge
({
76 borrowernumber
=> $borrowernumber
80 my $pdf_path = Koha
::Patron
::Discharge
::generate_as_pdf
(
81 { borrowernumber
=> $borrowernumber, branchcode
=> $data->{'branchcode'} } );
85 -type
=> 'application/pdf',
87 -attachment
=> "discharge_$borrowernumber.pdf",
89 open my $fh, '<', $pdf_path;
97 $template->param( messages
=> [ {type
=> 'error', code
=> 'unable_to_generate_pdf'} ] );
101 # Already generated discharges
102 my $validated_discharges = Koha
::Patron
::Discharge
::get_validated
({
103 borrowernumber
=> $borrowernumber,
106 my $patron_image = Koha
::Patron
::Images
->find($borrowernumber);
107 $template->param( picture
=> 1 ) if $patron_image;
110 borrowernumber
=> $borrowernumber,
111 biblionumber
=> $data->{'biblionumber'},
112 title
=> $data->{'title'},
113 initials
=> $data->{'initials'},
114 surname
=> $data->{'surname'},
115 borrowernumber
=> $borrowernumber,
116 firstname
=> $data->{'firstname'},
117 cardnumber
=> $data->{'cardnumber'},
118 categorycode
=> $data->{'categorycode'},
119 category_type
=> $data->{'category_type'},
120 categoryname
=> $data->{'description'},
121 address
=> $data->{'address'},
122 streetnumber
=> $data->{streetnumber
},
123 streettype
=> $data->{streettype
},
124 address2
=> $data->{'address2'},
125 city
=> $data->{'city'},
126 zipcode
=> $data->{'zipcode'},
127 country
=> $data->{'country'},
128 phone
=> $data->{'phone'},
129 email
=> $data->{'email'},
130 branchcode
=> $data->{'branchcode'},
131 has_reserves
=> $has_reserves,
132 can_be_discharged
=> $can_be_discharged,
133 validated_discharges
=> $validated_discharges,
137 $template->param( dischargeview
=> 1, );
139 output_html_with_http_headers
$input, $cookie, $template->output;