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 60-65
unless ($patron) {
Link Here
|
60 |
exit; |
61 |
exit; |
61 |
} |
62 |
} |
62 |
|
63 |
|
|
|
64 |
my $logged_in_user = Koha::Patrons->find($loggedinuser); |
65 |
output_and_exit_if_error( |
66 |
$input, $cookie, |
67 |
$template, |
68 |
{ |
69 |
module => 'members', |
70 |
logged_in_user => $logged_in_user, |
71 |
current_patron => $patron |
72 |
} |
73 |
); |
74 |
|
63 |
my $library_id = C4::Context->userenv->{'branch'}; |
75 |
my $library_id = C4::Context->userenv->{'branch'}; |
64 |
|
76 |
|
65 |
my $add = $input->param('add'); |
77 |
my $add = $input->param('add'); |
Lines 72-105
if ($add) {
Link Here
|
72 |
} |
84 |
} |
73 |
); |
85 |
); |
74 |
|
86 |
|
75 |
# Note: If the logged in user is not allowed to see this patron an invoice can be forced |
87 |
# 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 |
88 |
# Here we are trusting librarians not to hack the system |
|
|
89 |
my $desc = $input->param('desc'); |
90 |
my $amount = $input->param('amount'); |
91 |
my $note = $input->param('note'); |
92 |
my $debit_type = $input->param('type'); |
93 |
|
94 |
# If LOST try to match barcode to Item and then try to match Item + Borrower to an Issue. |
95 |
my $item_id; |
77 |
my $barcode = $input->param('barcode'); |
96 |
my $barcode = $input->param('barcode'); |
78 |
my $itemnum; |
|
|
79 |
if ($barcode) { |
97 |
if ($barcode) { |
80 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
98 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
81 |
$itemnum = $item->itemnumber if $item; |
99 |
$item_id = $item->itemnumber if $item; |
82 |
} |
100 |
} |
83 |
my $desc = $input->param('desc'); |
101 |
my $issue_id; |
84 |
my $amount = $input->param('amount'); |
102 |
if ( $debit_type eq 'LOST' && $item_id ) { |
85 |
my $type = $input->param('type'); |
103 |
my $checkouts = Koha::Checkouts->search( |
86 |
my $note = $input->param('note'); |
104 |
{ itemnumber => $item_id, borrowernumber => $borrowernumber } ); |
87 |
my $error = |
105 |
my $checkout = |
88 |
C4::Accounts::manualinvoice( $borrowernumber, $itemnum, $desc, $type, |
106 |
$checkouts->count |
89 |
$amount, $note ); |
107 |
? $checkouts->next |
90 |
if ($error) { |
108 |
: Koha::Old::Checkouts->search( |
91 |
if ( $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) { |
109 |
{ itemnumber => $item_id, borrowernumber => $borrowernumber }, |
92 |
$template->param( 'ITEMNUMBER' => 1 ); |
110 |
{ order_by => { -desc => 'returndate' }, rows => 1 } |
93 |
} |
111 |
)->next; |
94 |
$template->param( |
112 |
$issue_id = $checkout ? $checkout->issue_id : undef; |
95 |
csrf_token => Koha::Token->new->generate_csrf( |
|
|
96 |
{ session_id => scalar $input->cookie('CGISESSID') } |
97 |
) |
98 |
); |
99 |
$template->param( 'ERROR' => $error ); |
100 |
output_html_with_http_headers $input, $cookie, $template->output; |
101 |
} |
113 |
} |
102 |
else { |
114 |
|
|
|
115 |
try { |
116 |
$patron->account->add_debit( |
117 |
{ |
118 |
amount => $amount, |
119 |
description => $desc, |
120 |
note => $note, |
121 |
user_id => $logged_in_user->borrowernumber, |
122 |
interface => 'intranet', |
123 |
library_id => $library_id, |
124 |
type => $debit_type, |
125 |
item_id => $item_id, |
126 |
issue_id => $issue_id |
127 |
} |
128 |
); |
103 |
|
129 |
|
104 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
130 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
105 |
$patron->account->reconcile_balance; |
131 |
$patron->account->reconcile_balance; |
Lines 110-140
if ($add) {
Link Here
|
110 |
); |
136 |
); |
111 |
exit; |
137 |
exit; |
112 |
} |
138 |
} |
113 |
} |
139 |
catch { |
114 |
else { |
140 |
my $error = $_; |
115 |
|
141 |
if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) { |
116 |
my $logged_in_user = Koha::Patrons->find($loggedinuser) |
142 |
$template->param( error => $error->broken_fk ); |
117 |
or die "Not logged in"; |
143 |
} else { |
118 |
output_and_exit_if_error( |
144 |
$template->param( error => '1' ); |
119 |
$input, $cookie, |
|
|
120 |
$template, |
121 |
{ |
122 |
module => 'members', |
123 |
logged_in_user => $logged_in_user, |
124 |
current_patron => $patron |
125 |
} |
145 |
} |
126 |
); |
146 |
} |
127 |
|
|
|
128 |
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( |
129 |
{ can_be_added_manually => 1, archived => 0 }, |
130 |
{}, $library_id ); |
131 |
$template->param( debit_types => \@debit_types ); |
132 |
$template->param( |
133 |
csrf_token => Koha::Token->new->generate_csrf( |
134 |
{ session_id => scalar $input->cookie('CGISESSID') } |
135 |
), |
136 |
patron => $patron, |
137 |
finesview => 1, |
138 |
); |
139 |
output_html_with_http_headers $input, $cookie, $template->output; |
140 |
} |
147 |
} |
141 |
- |
148 |
|
|
|
149 |
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( |
150 |
{ can_be_added_manually => 1, archived => 0 }, |
151 |
{}, $library_id ); |
152 |
|
153 |
$template->param( |
154 |
debit_types => \@debit_types, |
155 |
csrf_token => Koha::Token->new->generate_csrf( |
156 |
{ session_id => scalar $input->cookie('CGISESSID') } |
157 |
), |
158 |
patron => $patron, |
159 |
finesview => 1, |
160 |
); |
161 |
output_html_with_http_headers $input, $cookie, $template->output; |