Lines 58-142
unless ( C4::Context->preference('useDischarge') ) {
Link Here
|
58 |
exit; |
58 |
exit; |
59 |
} |
59 |
} |
60 |
|
60 |
|
61 |
if ( $input->param('borrowernumber') ) { |
61 |
$borrowernumber = $input->param('borrowernumber'); |
62 |
$borrowernumber = $input->param('borrowernumber'); |
|
|
63 |
|
62 |
|
64 |
# Getting member data |
63 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
65 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
64 |
unless ( $patron ) { |
|
|
65 |
print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber"); |
66 |
exit; |
67 |
} |
66 |
|
68 |
|
67 |
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ |
69 |
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ |
68 |
borrowernumber => $borrowernumber |
70 |
borrowernumber => $borrowernumber |
69 |
}); |
71 |
}); |
70 |
|
72 |
|
71 |
my $holds = $patron->holds; |
73 |
my $holds = $patron->holds; |
72 |
my $has_reserves = $holds->count; |
74 |
my $has_reserves = $holds->count; |
73 |
|
75 |
|
74 |
# Generating discharge if needed |
76 |
# Generating discharge if needed |
75 |
if ( $input->param('discharge') and $can_be_discharged ) { |
77 |
if ( $input->param('discharge') and $can_be_discharged ) { |
76 |
my $is_discharged = Koha::Patron::Discharge::is_discharged({ |
78 |
my $is_discharged = Koha::Patron::Discharge::is_discharged({ |
77 |
borrowernumber => $borrowernumber, |
79 |
borrowernumber => $borrowernumber, |
|
|
80 |
}); |
81 |
unless ($is_discharged) { |
82 |
Koha::Patron::Discharge::discharge({ |
83 |
borrowernumber => $borrowernumber |
78 |
}); |
84 |
}); |
79 |
unless ($is_discharged) { |
|
|
80 |
Koha::Patron::Discharge::discharge({ |
81 |
borrowernumber => $borrowernumber |
82 |
}); |
83 |
} |
84 |
eval { |
85 |
my $pdf_path = Koha::Patron::Discharge::generate_as_pdf( |
86 |
{ borrowernumber => $borrowernumber, branchcode => $patron->branchcode } ); |
87 |
|
88 |
binmode(STDOUT); |
89 |
print $input->header( |
90 |
-type => 'application/pdf', |
91 |
-charset => 'utf-8', |
92 |
-attachment => "discharge_$borrowernumber.pdf", |
93 |
); |
94 |
open my $fh, '<', $pdf_path; |
95 |
my @lines = <$fh>; |
96 |
close $fh; |
97 |
print @lines; |
98 |
exit; |
99 |
}; |
100 |
if ( $@ ) { |
101 |
carp $@; |
102 |
$template->param( messages => [ {type => 'error', code => 'unable_to_generate_pdf'} ] ); |
103 |
} |
104 |
} |
85 |
} |
|
|
86 |
eval { |
87 |
my $pdf_path = Koha::Patron::Discharge::generate_as_pdf( |
88 |
{ borrowernumber => $borrowernumber, branchcode => $patron->branchcode } ); |
89 |
|
90 |
binmode(STDOUT); |
91 |
print $input->header( |
92 |
-type => 'application/pdf', |
93 |
-charset => 'utf-8', |
94 |
-attachment => "discharge_$borrowernumber.pdf", |
95 |
); |
96 |
open my $fh, '<', $pdf_path; |
97 |
my @lines = <$fh>; |
98 |
close $fh; |
99 |
print @lines; |
100 |
exit; |
101 |
}; |
102 |
if ( $@ ) { |
103 |
carp $@; |
104 |
$template->param( messages => [ {type => 'error', code => 'unable_to_generate_pdf'} ] ); |
105 |
} |
106 |
} |
105 |
|
107 |
|
106 |
# Already generated discharges |
108 |
# Already generated discharges |
107 |
my $validated_discharges = Koha::Patron::Discharge::get_validated({ |
109 |
my $validated_discharges = Koha::Patron::Discharge::get_validated({ |
108 |
borrowernumber => $borrowernumber, |
110 |
borrowernumber => $borrowernumber, |
109 |
}); |
111 |
}); |
110 |
|
112 |
|
111 |
$template->param( picture => 1 ) if $patron->image; |
113 |
$template->param( picture => 1 ) if $patron->image; |
112 |
|
114 |
|
113 |
$template->param( |
115 |
$template->param( |
114 |
# FIXME The patron object should be passed to the template |
116 |
# FIXME The patron object should be passed to the template |
115 |
borrowernumber => $borrowernumber, |
117 |
borrowernumber => $borrowernumber, |
116 |
title => $patron->title, |
118 |
title => $patron->title, |
117 |
initials => $patron->initials, |
119 |
initials => $patron->initials, |
118 |
surname => $patron->surname, |
120 |
surname => $patron->surname, |
119 |
borrowernumber => $borrowernumber, |
121 |
borrowernumber => $borrowernumber, |
120 |
firstname => $patron->firstname, |
122 |
firstname => $patron->firstname, |
121 |
cardnumber => $patron->cardnumber, |
123 |
cardnumber => $patron->cardnumber, |
122 |
categorycode => $patron->categorycode, |
124 |
categorycode => $patron->categorycode, |
123 |
category_type => $patron->category->category_type, |
125 |
category_type => $patron->category->category_type, |
124 |
categoryname => $patron->category->description, |
126 |
categoryname => $patron->category->description, |
125 |
address => $patron->address, |
127 |
address => $patron->address, |
126 |
streetnumber => $patron->streetnumber, |
128 |
streetnumber => $patron->streetnumber, |
127 |
streettype => $patron->streettype, |
129 |
streettype => $patron->streettype, |
128 |
address2 => $patron->address2, |
130 |
address2 => $patron->address2, |
129 |
city => $patron->city, |
131 |
city => $patron->city, |
130 |
zipcode => $patron->zipcode, |
132 |
zipcode => $patron->zipcode, |
131 |
country => $patron->country, |
133 |
country => $patron->country, |
132 |
phone => $patron->phone, |
134 |
phone => $patron->phone, |
133 |
email => $patron->email, |
135 |
email => $patron->email, |
134 |
branchcode => $patron->branchcode, |
136 |
branchcode => $patron->branchcode, |
135 |
has_reserves => $has_reserves, |
137 |
has_reserves => $has_reserves, |
136 |
can_be_discharged => $can_be_discharged, |
138 |
can_be_discharged => $can_be_discharged, |
137 |
validated_discharges => $validated_discharges, |
139 |
validated_discharges => $validated_discharges, |
138 |
); |
140 |
); |
139 |
} |
|
|
140 |
|
141 |
|
141 |
$template->param( dischargeview => 1, ); |
142 |
$template->param( dischargeview => 1, ); |
142 |
|
143 |
|