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-140
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 $failed; |
96 |
my $item_id; |
77 |
my $barcode = $input->param('barcode'); |
97 |
my $barcode = $input->param('barcode'); |
78 |
my $itemnum; |
|
|
79 |
if ($barcode) { |
98 |
if ($barcode) { |
80 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
99 |
my $item = Koha::Items->find( { barcode => $barcode } ); |
81 |
$itemnum = $item->itemnumber if $item; |
100 |
if ($item) { |
82 |
} |
101 |
$item_id = $item->itemnumber; |
83 |
my $desc = $input->param('desc'); |
102 |
} |
84 |
my $amount = $input->param('amount'); |
103 |
else { |
85 |
my $type = $input->param('type'); |
104 |
$template->param( error => 'itemnumber' ); |
86 |
my $note = $input->param('note'); |
105 |
$failed = 1; |
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 |
} |
106 |
} |
94 |
$template->param( |
|
|
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 |
} |
107 |
} |
102 |
else { |
108 |
my $issue_id; |
|
|
109 |
if ( $debit_type eq 'LOST' && $item_id ) { |
110 |
my $checkouts = Koha::Checkouts->search( |
111 |
{ itemnumber => $item_id, borrowernumber => $borrowernumber } ); |
112 |
my $checkout = |
113 |
$checkouts->count |
114 |
? $checkouts->next |
115 |
: Koha::Old::Checkouts->search( |
116 |
{ itemnumber => $item_id, borrowernumber => $borrowernumber }, |
117 |
{ order_by => { -desc => 'returndate' }, rows => 1 } |
118 |
)->next; |
119 |
$issue_id = $checkout ? $checkout->issue_id : undef; |
120 |
} |
103 |
|
121 |
|
104 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
122 |
unless ($failed) { |
105 |
$patron->account->reconcile_balance; |
123 |
try { |
106 |
} |
124 |
$patron->account->add_debit( |
|
|
125 |
{ |
126 |
amount => $amount, |
127 |
description => $desc, |
128 |
note => $note, |
129 |
user_id => $logged_in_user->borrowernumber, |
130 |
interface => 'intranet', |
131 |
library_id => $library_id, |
132 |
type => $debit_type, |
133 |
item_id => $item_id, |
134 |
issue_id => $issue_id |
135 |
} |
136 |
); |
107 |
|
137 |
|
108 |
print $input->redirect( |
138 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
109 |
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" |
139 |
$patron->account->reconcile_balance; |
110 |
); |
140 |
} |
111 |
exit; |
|
|
112 |
} |
113 |
} |
114 |
else { |
115 |
|
141 |
|
116 |
my $logged_in_user = Koha::Patrons->find($loggedinuser) |
142 |
print $input->redirect( |
117 |
or die "Not logged in"; |
143 |
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" |
118 |
output_and_exit_if_error( |
144 |
); |
119 |
$input, $cookie, |
145 |
exit; |
120 |
$template, |
146 |
} |
121 |
{ |
147 |
catch { |
122 |
module => 'members', |
148 |
my $error = $_; |
123 |
logged_in_user => $logged_in_user, |
149 |
if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) { |
124 |
current_patron => $patron |
150 |
$template->param( error => $error->broken_fk ); |
|
|
151 |
} else { |
152 |
$template->param( error => '1' ); |
153 |
} |
125 |
} |
154 |
} |
126 |
); |
155 |
} |
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 |
} |
156 |
} |
141 |
- |
157 |
|
|
|
158 |
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits( |
159 |
{ can_be_added_manually => 1, archived => 0 }, |
160 |
{}, $library_id ); |
161 |
|
162 |
$template->param( |
163 |
debit_types => \@debit_types, |
164 |
csrf_token => Koha::Token->new->generate_csrf( |
165 |
{ session_id => scalar $input->cookie('CGISESSID') } |
166 |
), |
167 |
patron => $patron, |
168 |
finesview => 1, |
169 |
); |
170 |
output_html_with_http_headers $input, $cookie, $template->output; |