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