Lines 33-38
use C4::Auth qw( get_template_and_user );
Link Here
|
33 |
use C4::Output qw( output_and_exit output_html_with_http_headers ); |
33 |
use C4::Output qw( output_and_exit output_html_with_http_headers ); |
34 |
use C4::Acquisition qw( CloseInvoice ReopenInvoice ModInvoice MergeInvoices DelInvoice GetInvoice GetInvoiceDetails get_rounded_price ); |
34 |
use C4::Acquisition qw( CloseInvoice ReopenInvoice ModInvoice MergeInvoices DelInvoice GetInvoice GetInvoiceDetails get_rounded_price ); |
35 |
use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget ); |
35 |
use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget ); |
|
|
36 |
use JSON qw( encode_json ); |
36 |
use C4::Log qw(logaction); |
37 |
use C4::Log qw(logaction); |
37 |
|
38 |
|
38 |
use Koha::Acquisition::Booksellers; |
39 |
use Koha::Acquisition::Booksellers; |
Lines 148-166
elsif ( $op && $op eq 'del_adj' ) {
Link Here
|
148 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
149 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
149 |
if ($del_adj) { |
150 |
if ($del_adj) { |
150 |
if (C4::Context->preference("AcqLog")) { |
151 |
if (C4::Context->preference("AcqLog")) { |
151 |
my $reason_length = length $del_adj->reason; |
152 |
my $infos = { |
152 |
my $reason_padded = ( ' ' x (80 - $reason_length) ) . $del_adj->reason; |
153 |
invoiceid => $del_adj->invoiceid, |
153 |
my $infos = |
154 |
budget_id => $del_adj->budget_id, |
154 |
sprintf("%010d", $del_adj->invoiceid) . |
155 |
encumber_open => $del_adj->encumber_open, |
155 |
sprintf("%010d", $del_adj->budget_id) . |
156 |
adjustment => $del_adj->adjustment, |
156 |
sprintf("%010d", $del_adj->encumber_open) . |
157 |
reason => $del_adj->reason |
157 |
sprintf("%010.2f", $del_adj->adjustment) . |
158 |
}; |
158 |
$reason_padded; |
|
|
159 |
logaction( |
159 |
logaction( |
160 |
'ACQUISITIONS', |
160 |
'ACQUISITIONS', |
161 |
'DELETE_INVOICE_ADJUSTMENT', |
161 |
'DELETE_INVOICE_ADJUSTMENT', |
162 |
$adjustment_id, |
162 |
$adjustment_id, |
163 |
$infos |
163 |
encode_json($infos) |
164 |
); |
164 |
); |
165 |
} |
165 |
} |
166 |
$del_adj->delete(); |
166 |
$del_adj->delete(); |
Lines 195-206
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
195 |
$new_adj->store(); |
195 |
$new_adj->store(); |
196 |
# Log this addition |
196 |
# Log this addition |
197 |
if (C4::Context->preference("AcqLog")) { |
197 |
if (C4::Context->preference("AcqLog")) { |
198 |
my $infos = get_log_string($adj); |
|
|
199 |
logaction( |
198 |
logaction( |
200 |
'ACQUISITIONS', |
199 |
'ACQUISITIONS', |
201 |
'CREATE_INVOICE_ADJUSTMENT', |
200 |
'CREATE_INVOICE_ADJUSTMENT', |
202 |
$new_adj->adjustment_id, |
201 |
$new_adj->adjustment_id, |
203 |
$infos |
202 |
encode_json($adj) |
204 |
); |
203 |
); |
205 |
} |
204 |
} |
206 |
} |
205 |
} |
Lines 209-215
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
209 |
unless ( $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $e_open{$adjustment_id[$i]} && $old_adj->note eq $note[$i] ){ |
208 |
unless ( $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $e_open{$adjustment_id[$i]} && $old_adj->note eq $note[$i] ){ |
210 |
# Log this modification |
209 |
# Log this modification |
211 |
if (C4::Context->preference("AcqLog")) { |
210 |
if (C4::Context->preference("AcqLog")) { |
212 |
my $infos = get_log_string({ |
211 |
my $infos = { |
213 |
adjustment => $adjustment[$i], |
212 |
adjustment => $adjustment[$i], |
214 |
reason => $reason[$i], |
213 |
reason => $reason[$i], |
215 |
budget_id => $budget_id[$i], |
214 |
budget_id => $budget_id[$i], |
Lines 218-229
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
218 |
reason_old => $old_adj->reason, |
217 |
reason_old => $old_adj->reason, |
219 |
budget_id_old => $old_adj->budget_id, |
218 |
budget_id_old => $old_adj->budget_id, |
220 |
encumber_open_old => $old_adj->encumber_open |
219 |
encumber_open_old => $old_adj->encumber_open |
221 |
}); |
220 |
}; |
222 |
logaction( |
221 |
logaction( |
223 |
'ACQUISITIONS', |
222 |
'ACQUISITIONS', |
224 |
'UPDATE_INVOICE_ADJUSTMENT', |
223 |
'UPDATE_INVOICE_ADJUSTMENT', |
225 |
$adjustment_id[$i], |
224 |
$adjustment_id[$i], |
226 |
$infos |
225 |
encode_json($infos) |
227 |
); |
226 |
); |
228 |
} |
227 |
} |
229 |
$old_adj->timestamp(undef); |
228 |
$old_adj->timestamp(undef); |
Lines 350-384
sub get_infos {
Link Here
|
350 |
return \%line; |
349 |
return \%line; |
351 |
} |
350 |
} |
352 |
|
351 |
|
353 |
sub get_log_string { |
|
|
354 |
my ($data) = @_; |
355 |
|
356 |
# We specify the keys we're dealing for logging within an array in order |
357 |
# to preserve order, if we just iterate the hash keys, we could get |
358 |
# the values in any order |
359 |
my @keys = ( |
360 |
'budget_id', |
361 |
'encumber_open', |
362 |
'budget_id_old', |
363 |
'encumber_open_old' |
364 |
); |
365 |
# Adjustment amount |
366 |
my $return = sprintf("%010.2f", $data->{adjustment}); |
367 |
# Left pad "reason" to the maximum length of aqinvoice_adjustments.reason |
368 |
# (80 characters) |
369 |
my $reason_len = length $data->{reason}; |
370 |
$return .= ( ' ' x (80 - $reason_len) ) . $data->{reason}; |
371 |
# Append the remaining fields |
372 |
foreach my $key(@keys) { |
373 |
$return .= sprintf("%010d", $data->{$key}); |
374 |
} |
375 |
# Old adjustment amount |
376 |
$return .= sprintf("%010.2f", $data->{adjustment_old}); |
377 |
# Left pad "reason_old" to the maximum length of aqinvoice_adjustments.reason |
378 |
# (80 characters) |
379 |
my $reason_old_len = length $data->{reason_old}; |
380 |
$return .= ( ' ' x (80 - $reason_old_len) ) . $data->{reason_old}; |
381 |
return $return; |
382 |
} |
383 |
|
384 |
output_html_with_http_headers $input, $cookie, $template->output; |
352 |
output_html_with_http_headers $input, $cookie, $template->output; |