Line 0
Link Here
|
|
|
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 |
=head1 NAME |
21 |
|
22 |
discharges.pl |
23 |
|
24 |
=head1 DESCRIPTION |
25 |
|
26 |
Allows librarian to edit and/or manage borrowers' discharges |
27 |
|
28 |
=cut |
29 |
|
30 |
use Modern::Perl; |
31 |
|
32 |
use CGI; |
33 |
use C4::Auth; |
34 |
use C4::Output; |
35 |
use C4::Members; |
36 |
use C4::Reserves; |
37 |
use C4::Letters; |
38 |
use Koha::Service::Borrower::Discharge; |
39 |
|
40 |
use Koha::DateUtils; |
41 |
|
42 |
my $input = new CGI; |
43 |
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( |
44 |
{ |
45 |
template_name => 'members/discharge.tt', |
46 |
query => $input, |
47 |
type => 'intranet', |
48 |
authnotrequired => 0, |
49 |
flagsrequired => { 'borrowers' => '*' }, |
50 |
} |
51 |
); |
52 |
|
53 |
my $borrowernumber; |
54 |
my $data; |
55 |
if ( $input->param('borrowernumber') ) { |
56 |
$borrowernumber = $input->param('borrowernumber'); |
57 |
|
58 |
# Getting member data |
59 |
$data = GetMember( borrowernumber => $borrowernumber ); |
60 |
|
61 |
my $can_be_discharged = |
62 |
Koha::Service::Borrower::Discharge::can_be_discharged( |
63 |
{ borrowernumber => $borrowernumber, } ); |
64 |
|
65 |
# Getting reserves |
66 |
my @reserves = GetReservesFromBorrowernumber($borrowernumber); |
67 |
my $hasreserves = scalar(@reserves); |
68 |
|
69 |
# Generating discharge if needed |
70 |
if ( $input->param('discharge') and $can_be_discharged ) { |
71 |
my $is_discharged = Koha::Service::Borrower::Discharge::count( |
72 |
{ |
73 |
borrowernumber => $borrowernumber, |
74 |
validated => 1, |
75 |
} |
76 |
); |
77 |
unless ($is_discharged) { |
78 |
Koha::Service::Borrower::Discharge::discharge( |
79 |
{ borrowernumber => $borrowernumber, } ); |
80 |
} |
81 |
my $pdf_path = Koha::Service::Borrower::Discharge::generate_as_pdf( |
82 |
{ borrowernumber => $borrowernumber, } ); |
83 |
|
84 |
print $input->header( |
85 |
-type => 'application/pdf', |
86 |
-charset => 'utf-8', |
87 |
-attachment => "discharge_$borrowernumber.pdf", |
88 |
); |
89 |
open my $fh, '<', $pdf_path; |
90 |
my @lines = <$fh>; |
91 |
close $fh; |
92 |
print @lines; |
93 |
exit; |
94 |
} |
95 |
|
96 |
$template->param( |
97 |
borrowernumber => $borrowernumber, |
98 |
biblionumber => $data->{'biblionumber'}, |
99 |
title => $data->{'title'}, |
100 |
initials => $data->{'initials'}, |
101 |
surname => $data->{'surname'}, |
102 |
borrowernumber => $borrowernumber, |
103 |
firstname => $data->{'firstname'}, |
104 |
cardnumber => $data->{'cardnumber'}, |
105 |
categorycode => $data->{'categorycode'}, |
106 |
category_type => $data->{'category_type'}, |
107 |
categoryname => $data->{'description'}, |
108 |
address => $data->{'address'}, |
109 |
address2 => $data->{'address2'}, |
110 |
city => $data->{'city'}, |
111 |
zipcode => $data->{'zipcode'}, |
112 |
country => $data->{'country'}, |
113 |
phone => $data->{'phone'}, |
114 |
email => $data->{'email'}, |
115 |
branchcode => $data->{'branchcode'}, |
116 |
hasreserves => $hasreserves, |
117 |
can_be_discharged => $can_be_discharged, |
118 |
); |
119 |
} |
120 |
|
121 |
$template->param( dischargeview => 1, ); |
122 |
|
123 |
output_html_with_http_headers $input, $cookie, $template->output; |