Lines 33-38
use C4::Auth;
Link Here
|
33 |
use C4::Output; |
33 |
use C4::Output; |
34 |
use C4::Acquisition; |
34 |
use C4::Acquisition; |
35 |
use C4::Budgets; |
35 |
use C4::Budgets; |
|
|
36 |
use C4::Log qw(logaction); |
36 |
|
37 |
|
37 |
use Koha::Acquisition::Booksellers; |
38 |
use Koha::Acquisition::Booksellers; |
38 |
use Koha::Acquisition::Currencies; |
39 |
use Koha::Acquisition::Currencies; |
Lines 146-152
elsif ( $op && $op eq 'del_adj' ) {
Link Here
|
146 |
|
147 |
|
147 |
my $adjustment_id = $input->param('adjustment_id'); |
148 |
my $adjustment_id = $input->param('adjustment_id'); |
148 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
149 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
149 |
$del_adj->delete() if ($del_adj); |
150 |
if ($del_adj) { |
|
|
151 |
if (C4::Context->preference("AcqLog")) { |
152 |
my $reason_length = length $del_adj->reason; |
153 |
my $reason_padded = ( ' ' x (80 - $reason_length) ) . $del_adj->reason; |
154 |
my $infos = |
155 |
sprintf("%010d", $del_adj->invoiceid) . |
156 |
sprintf("%010d", $del_adj->budget_id) . |
157 |
sprintf("%010d", $del_adj->encumber_open) . |
158 |
sprintf("%010.2f", $del_adj->adjustment) . |
159 |
$reason_padded; |
160 |
logaction( |
161 |
'ACQUISITIONS', |
162 |
'DELETE_INVOICE_ADJUSTMENT', |
163 |
$adjustment_id, |
164 |
$infos |
165 |
); |
166 |
} |
167 |
$del_adj->delete(); |
168 |
} |
150 |
} |
169 |
} |
151 |
elsif ( $op && $op eq 'mod_adj' ) { |
170 |
elsif ( $op && $op eq 'mod_adj' ) { |
152 |
|
171 |
|
Lines 161-170
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
161 |
my @encumber_open = $input->multi_param('encumber_open'); |
180 |
my @encumber_open = $input->multi_param('encumber_open'); |
162 |
my %e_open = map { $_ => 1 } @encumber_open; |
181 |
my %e_open = map { $_ => 1 } @encumber_open; |
163 |
|
182 |
|
|
|
183 |
my @keys = ('adjustment', 'reason', 'budget_id', 'encumber_open'); |
164 |
for( my $i=0; $i < scalar @adjustment; $i++ ){ |
184 |
for( my $i=0; $i < scalar @adjustment; $i++ ){ |
165 |
if( $adjustment_id[$i] eq 'new' ){ |
185 |
if( $adjustment_id[$i] eq 'new' ){ |
166 |
next unless ( $adjustment[$i] || $reason[$i] ); |
186 |
next unless ( $adjustment[$i] || $reason[$i] ); |
167 |
my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({ |
187 |
my $adj = { |
168 |
invoiceid => $invoiceid, |
188 |
invoiceid => $invoiceid, |
169 |
adjustment => $adjustment[$i], |
189 |
adjustment => $adjustment[$i], |
170 |
reason => $reason[$i], |
190 |
reason => $reason[$i], |
Lines 172-182
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
172 |
budget_id => $budget_id[$i] || undef, |
192 |
budget_id => $budget_id[$i] || undef, |
173 |
encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, |
193 |
encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, |
174 |
}); |
194 |
}); |
|
|
195 |
my $new_adj = Koha::Acquisition::Invoice::Adjustment->new($adj); |
175 |
$new_adj->store(); |
196 |
$new_adj->store(); |
|
|
197 |
# Log this addition |
198 |
if (C4::Context->preference("AcqLog")) { |
199 |
my $infos = get_log_string($adj); |
200 |
logaction( |
201 |
'ACQUISITIONS', |
202 |
'CREATE_INVOICE_ADJUSTMENT', |
203 |
$new_adj->adjustment_id, |
204 |
$infos |
205 |
); |
206 |
} |
176 |
} |
207 |
} |
177 |
else { |
208 |
else { |
178 |
my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); |
209 |
my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); |
179 |
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 |
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] ){ |
|
|
211 |
# Log this modification |
212 |
if (C4::Context->preference("AcqLog")) { |
213 |
my $infos = get_log_string({ |
214 |
adjustment => $adjustment[$i], |
215 |
reason => $reason[$i], |
216 |
budget_id => $budget_id[$i], |
217 |
encumber_open => $e_open{$adjustment_id[$i]}, |
218 |
adjustment_old => $old_adj->adjustment, |
219 |
reason_old => $old_adj->reason, |
220 |
budget_id_old => $old_adj->budget_id, |
221 |
encumber_open_old => $old_adj->encumber_open |
222 |
}); |
223 |
logaction( |
224 |
'ACQUISITIONS', |
225 |
'UPDATE_INVOICE_ADJUSTMENT', |
226 |
$adjustment_id[$i], |
227 |
$infos |
228 |
); |
229 |
} |
180 |
$old_adj->timestamp(undef); |
230 |
$old_adj->timestamp(undef); |
181 |
$old_adj->adjustment( $adjustment[$i] ); |
231 |
$old_adj->adjustment( $adjustment[$i] ); |
182 |
$old_adj->reason( $reason[$i] ); |
232 |
$old_adj->reason( $reason[$i] ); |
Lines 301-304
sub get_infos {
Link Here
|
301 |
return \%line; |
351 |
return \%line; |
302 |
} |
352 |
} |
303 |
|
353 |
|
|
|
354 |
sub get_log_string { |
355 |
my ($data) = @_; |
356 |
|
357 |
# We specify the keys we're dealing for logging within an array in order |
358 |
# to preserve order, if we just iterate the hash keys, we could get |
359 |
# the values in any order |
360 |
my @keys = ( |
361 |
'budget_id', |
362 |
'encumber_open', |
363 |
'budget_id_old', |
364 |
'encumber_open_old' |
365 |
); |
366 |
# Adjustment amount |
367 |
my $return = sprintf("%010.2f", $data->{adjustment}); |
368 |
# Left pad "reason" to the maximum length of aqinvoice_adjustments.reason |
369 |
# (80 characters) |
370 |
my $reason_len = length $data->{reason}; |
371 |
$return .= ( ' ' x (80 - $reason_len) ) . $data->{reason}; |
372 |
# Append the remaining fields |
373 |
foreach my $key(@keys) { |
374 |
$return .= sprintf("%010d", $data->{$key}); |
375 |
} |
376 |
# Old adjustment amount |
377 |
$return .= sprintf("%010.2f", $data->{adjustment_old}); |
378 |
# Left pad "reason_old" to the maximum length of aqinvoice_adjustments.reason |
379 |
# (80 characters) |
380 |
my $reason_old_len = length $data->{reason_old}; |
381 |
$return .= ( ' ' x (80 - $reason_old_len) ) . $data->{reason_old}; |
382 |
return $return; |
383 |
} |
384 |
|
304 |
output_html_with_http_headers $input, $cookie, $template->output; |
385 |
output_html_with_http_headers $input, $cookie, $template->output; |