Lines 23-28
Link Here
|
23 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
23 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
24 |
|
24 |
|
25 |
use Modern::Perl; |
25 |
use Modern::Perl; |
|
|
26 |
use Try::Tiny; |
26 |
|
27 |
|
27 |
use C4::Auth; |
28 |
use C4::Auth; |
28 |
use C4::Output; |
29 |
use C4::Output; |
Lines 32-39
use C4::Accounts;
Link Here
|
32 |
use C4::Items; |
33 |
use C4::Items; |
33 |
use Koha::Token; |
34 |
use Koha::Token; |
34 |
|
35 |
|
35 |
use Koha::Items; |
|
|
36 |
use Koha::Patrons; |
36 |
use Koha::Patrons; |
|
|
37 |
use Koha::Items; |
38 |
use Koha::Old::Items; |
39 |
use Koha::Checkouts; |
40 |
use Koha::Old::Checkouts; |
37 |
|
41 |
|
38 |
use Koha::Patron::Categories; |
42 |
use Koha::Patron::Categories; |
39 |
use Koha::Account::DebitTypes; |
43 |
use Koha::Account::DebitTypes; |
Lines 60-66
unless ($patron) {
Link Here
|
60 |
exit; |
64 |
exit; |
61 |
} |
65 |
} |
62 |
|
66 |
|
|
|
67 |
my $logged_in_user = Koha::Patrons->find($loggedinuser); |
68 |
output_and_exit_if_error( |
69 |
$input, $cookie, |
70 |
$template, |
71 |
{ |
72 |
module => 'members', |
73 |
logged_in_user => $logged_in_user, |
74 |
current_patron => $patron |
75 |
} |
76 |
); |
77 |
|
63 |
my $library_id = C4::Context->userenv->{'branch'}; |
78 |
my $library_id = C4::Context->userenv->{'branch'}; |
|
|
79 |
my $desc = $input->param('desc'); |
80 |
my $amount = $input->param('amount'); |
81 |
my $note = $input->param('note'); |
82 |
my $debit_type = $input->param('type'); |
83 |
my $barcode = $input->param('barcode'); |
84 |
$template->param( |
85 |
desc => $desc, |
86 |
amount => $amount, |
87 |
note => $note, |
88 |
type => $debit_type, |
89 |
barcode => $barcode |
90 |
); |
64 |
|
91 |
|
65 |
my $add = $input->param('add'); |
92 |
my $add = $input->param('add'); |
66 |
if ($add) { |
93 |
if ($add) { |
Lines 72-147
if ($add) {
Link Here
|
72 |
} |
99 |
} |
73 |
); |
100 |
); |
74 |
|
101 |
|
75 |
# Note: If the logged in user is not allowed to see this patron an invoice can be forced |
102 |
# Note: If the logged in user is not allowed to see this patron an invoice can be forced |
76 |
# Here we are trusting librarians not to hack the system |
103 |
# Here we are trusting librarians not to hack the system |
77 |
my $barcode = $input->param('barcode'); |
104 |
my $desc = $input->param('desc'); |
78 |
my $itemnum; |
105 |
my $amount = $input->param('amount'); |
|
|
106 |
my $note = $input->param('note'); |
107 |
my $debit_type = $input->param('type'); |
108 |
|
109 |
# If barcode is passed, attempt to find the associated item |
110 |
my $failed; |
111 |
my $item_id; |
112 |
my $issue_id; |
79 |
if ($barcode) { |
113 |
if ($barcode) { |
80 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
114 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
81 |
$itemnum = $item->itemnumber if $item; |
115 |
if ($item) { |
82 |
} |
116 |
$item_id = $item->itemnumber; |
83 |
my $desc = $input->param('desc'); |
|
|
84 |
my $amount = $input->param('amount'); |
85 |
my $type = $input->param('type'); |
86 |
my $note = $input->param('note'); |
87 |
my $error = |
88 |
C4::Accounts::manualinvoice( $borrowernumber, $itemnum, $desc, $type, |
89 |
$amount, $note ); |
90 |
if ($error) { |
91 |
if ( $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) { |
92 |
$template->param( 'ITEMNUMBER' => 1 ); |
93 |
} |
117 |
} |
94 |
$template->param( |
118 |
else { |
95 |
csrf_token => Koha::Token->new->generate_csrf( |
119 |
$item = Koha::Old::Items->find( { barcode => $barcode } ); |
96 |
{ session_id => scalar $input->cookie('CGISESSID') } |
120 |
if ($item) { |
97 |
) |
121 |
$item_id = $item->itemnumber; |
98 |
); |
122 |
} |
99 |
$template->param( 'ERROR' => $error ); |
123 |
else { |
100 |
output_html_with_http_headers $input, $cookie, $template->output; |
124 |
$template->param( error => 'itemnumber' ); |
101 |
} |
125 |
$failed = 1; |
102 |
else { |
126 |
} |
103 |
|
|
|
104 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
105 |
$patron->account->reconcile_balance; |
106 |
} |
127 |
} |
107 |
|
128 |
|
108 |
if ($add eq 'save and pay') { |
129 |
if ( ( $debit_type eq 'LOST' ) && $item_id ) { |
109 |
print $input->redirect( |
130 |
my $checkouts = Koha::Checkouts->search( |
110 |
"/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber" |
131 |
{ |
111 |
); |
132 |
itemnumber => $item_id, |
112 |
} else { |
133 |
borrowernumber => $borrowernumber |
113 |
print $input->redirect( |
134 |
} |
114 |
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" |
|
|
115 |
); |
135 |
); |
|
|
136 |
my $checkout = |
137 |
$checkouts->count |
138 |
? $checkouts->next |
139 |
: Koha::Old::Checkouts->search( |
140 |
{ |
141 |
itemnumber => $item_id, |
142 |
borrowernumber => $borrowernumber |
143 |
}, |
144 |
{ order_by => { -desc => 'returndate' }, rows => 1 } |
145 |
)->next; |
146 |
$issue_id = $checkout ? $checkout->issue_id : undef; |
116 |
} |
147 |
} |
117 |
|
|
|
118 |
exit; |
119 |
} |
148 |
} |
120 |
} |
|
|
121 |
else { |
122 |
|
149 |
|
123 |
my $logged_in_user = Koha::Patrons->find($loggedinuser) |
150 |
unless ($failed) { |
124 |
or die "Not logged in"; |
151 |
try { |
125 |
output_and_exit_if_error( |
152 |
$patron->account->add_debit( |
126 |
$input, $cookie, |
153 |
{ |
127 |
$template, |
154 |
amount => $amount, |
128 |
{ |
155 |
description => $desc, |
129 |
module => 'members', |
156 |
note => $note, |
130 |
logged_in_user => $logged_in_user, |
157 |
user_id => $logged_in_user->borrowernumber, |
131 |
current_patron => $patron |
158 |
interface => 'intranet', |
|
|
159 |
library_id => $library_id, |
160 |
type => $debit_type, |
161 |
item_id => $item_id, |
162 |
issue_id => $issue_id |
163 |
} |
164 |
); |
165 |
|
166 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
167 |
$patron->account->reconcile_balance; |
168 |
} |
169 |
|
170 |
if ( $add eq 'save and pay' ) { |
171 |
print $input->redirect( |
172 |
"/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber" |
173 |
); |
174 |
} |
175 |
else { |
176 |
print $input->redirect( |
177 |
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" |
178 |
); |
179 |
} |
180 |
|
181 |
exit; |
182 |
} |
183 |
catch { |
184 |
my $error = $_; |
185 |
if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) { |
186 |
$template->param( error => $error->broken_fk ); |
187 |
} |
188 |
else { |
189 |
$template->param( error => $error ); |
190 |
} |
132 |
} |
191 |
} |
133 |
); |
192 |
} |
134 |
|
|
|
135 |
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( |
136 |
{ can_be_invoiced => 1, archived => 0 }, |
137 |
{}, $library_id ); |
138 |
$template->param( debit_types => \@debit_types ); |
139 |
$template->param( |
140 |
csrf_token => Koha::Token->new->generate_csrf( |
141 |
{ session_id => scalar $input->cookie('CGISESSID') } |
142 |
), |
143 |
patron => $patron, |
144 |
finesview => 1, |
145 |
); |
146 |
output_html_with_http_headers $input, $cookie, $template->output; |
147 |
} |
193 |
} |
148 |
- |
194 |
|
|
|
195 |
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( |
196 |
{ can_be_invoiced => 1, archived => 0 }, |
197 |
{}, $library_id ); |
198 |
|
199 |
$template->param( |
200 |
debit_types => \@debit_types, |
201 |
csrf_token => Koha::Token->new->generate_csrf( |
202 |
{ session_id => scalar $input->cookie('CGISESSID') } |
203 |
), |
204 |
patron => $patron, |
205 |
finesview => 1, |
206 |
); |
207 |
output_html_with_http_headers $input, $cookie, $template->output; |