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
;
46 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
({
47 template_name
=> 'members/discharge.tt',
51 flagsrequired
=> { 'borrowers' => '*' },
54 my $borrowernumber = $input->param('borrowernumber');
56 unless ( C4
::Context
->preference('useDischarge') ) {
57 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&nopermission=1");
62 if ( $input->param('borrowernumber') ) {
63 $borrowernumber = $input->param('borrowernumber');
66 $data = GetMember
( borrowernumber
=> $borrowernumber );
68 my $can_be_discharged = Koha
::Patron
::Discharge
::can_be_discharged
({
69 borrowernumber
=> $borrowernumber
73 my @reserves = GetReservesFromBorrowernumber
($borrowernumber);
74 my $has_reserves = scalar(@reserves);
76 # Generating discharge if needed
77 if ( $input->param('discharge') and $can_be_discharged ) {
78 my $is_discharged = Koha
::Patron
::Discharge
::is_discharged
({
79 borrowernumber
=> $borrowernumber,
81 unless ($is_discharged) {
82 Koha
::Patron
::Discharge
::discharge
({
83 borrowernumber
=> $borrowernumber
87 my $pdf_path = Koha
::Patron
::Discharge
::generate_as_pdf
(
88 { borrowernumber
=> $borrowernumber, branchcode
=> $data->{'branchcode'} } );
92 -type
=> 'application/pdf',
94 -attachment
=> "discharge_$borrowernumber.pdf",
96 open my $fh, '<', $pdf_path;
104 $template->param( messages
=> [ {type
=> 'error', code
=> 'unable_to_generate_pdf'} ] );
108 # Already generated discharges
109 my $validated_discharges = Koha
::Patron
::Discharge
::get_validated
({
110 borrowernumber
=> $borrowernumber,
113 my $patron_image = Koha
::Patron
::Images
->find($borrowernumber);
114 $template->param( picture
=> 1 ) if $patron_image;
117 borrowernumber
=> $borrowernumber,
118 biblionumber
=> $data->{'biblionumber'},
119 title
=> $data->{'title'},
120 initials
=> $data->{'initials'},
121 surname
=> $data->{'surname'},
122 borrowernumber
=> $borrowernumber,
123 firstname
=> $data->{'firstname'},
124 cardnumber
=> $data->{'cardnumber'},
125 categorycode
=> $data->{'categorycode'},
126 category_type
=> $data->{'category_type'},
127 categoryname
=> $data->{'description'},
128 address
=> $data->{'address'},
129 streetnumber
=> $data->{streetnumber
},
130 streettype
=> $data->{streettype
},
131 address2
=> $data->{'address2'},
132 city
=> $data->{'city'},
133 zipcode
=> $data->{'zipcode'},
134 country
=> $data->{'country'},
135 phone
=> $data->{'phone'},
136 email
=> $data->{'email'},
137 branchcode
=> $data->{'branchcode'},
138 has_reserves
=> $has_reserves,
139 can_be_discharged
=> $can_be_discharged,
140 validated_discharges
=> $validated_discharges,
144 $template->param( dischargeview
=> 1, );
146 output_html_with_http_headers
$input, $cookie, $template->output;