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 C4::Log qw(logaction); |
36 |
|
37 |
|
37 |
use Koha::Acquisition::Booksellers; |
38 |
use Koha::Acquisition::Booksellers; |
38 |
use Koha::Acquisition::Currencies qw( get_active ); |
39 |
use Koha::Acquisition::Currencies qw( get_active ); |
Lines 145-151
elsif ( $op && $op eq 'del_adj' ) {
Link Here
|
145 |
|
146 |
|
146 |
my $adjustment_id = $input->param('adjustment_id'); |
147 |
my $adjustment_id = $input->param('adjustment_id'); |
147 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
148 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
148 |
$del_adj->delete() if ($del_adj); |
149 |
if ($del_adj) { |
|
|
150 |
if (C4::Context->preference("AcqLog")) { |
151 |
my $reason_length = length $del_adj->reason; |
152 |
my $reason_padded = ( ' ' x (80 - $reason_length) ) . $del_adj->reason; |
153 |
my $infos = |
154 |
sprintf("%010d", $del_adj->invoiceid) . |
155 |
sprintf("%010d", $del_adj->budget_id) . |
156 |
sprintf("%010d", $del_adj->encumber_open) . |
157 |
sprintf("%010.2f", $del_adj->adjustment) . |
158 |
$reason_padded; |
159 |
logaction( |
160 |
'ACQUISITIONS', |
161 |
'DELETE_INVOICE_ADJUSTMENT', |
162 |
$adjustment_id, |
163 |
$infos |
164 |
); |
165 |
} |
166 |
$del_adj->delete(); |
167 |
} |
149 |
} |
168 |
} |
150 |
elsif ( $op && $op eq 'mod_adj' ) { |
169 |
elsif ( $op && $op eq 'mod_adj' ) { |
151 |
|
170 |
|
Lines 160-169
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
160 |
my @encumber_open = $input->multi_param('encumber_open'); |
179 |
my @encumber_open = $input->multi_param('encumber_open'); |
161 |
my %e_open = map { $_ => 1 } @encumber_open; |
180 |
my %e_open = map { $_ => 1 } @encumber_open; |
162 |
|
181 |
|
|
|
182 |
my @keys = ('adjustment', 'reason', 'budget_id', 'encumber_open'); |
163 |
for( my $i=0; $i < scalar @adjustment; $i++ ){ |
183 |
for( my $i=0; $i < scalar @adjustment; $i++ ){ |
164 |
if( $adjustment_id[$i] eq 'new' ){ |
184 |
if( $adjustment_id[$i] eq 'new' ){ |
165 |
next unless ( $adjustment[$i] || $reason[$i] ); |
185 |
next unless ( $adjustment[$i] || $reason[$i] ); |
166 |
my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({ |
186 |
my $adj = { |
167 |
invoiceid => $invoiceid, |
187 |
invoiceid => $invoiceid, |
168 |
adjustment => $adjustment[$i], |
188 |
adjustment => $adjustment[$i], |
169 |
reason => $reason[$i], |
189 |
reason => $reason[$i], |
Lines 171-181
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
171 |
budget_id => $budget_id[$i] || undef, |
191 |
budget_id => $budget_id[$i] || undef, |
172 |
encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, |
192 |
encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, |
173 |
}); |
193 |
}); |
|
|
194 |
my $new_adj = Koha::Acquisition::Invoice::Adjustment->new($adj); |
174 |
$new_adj->store(); |
195 |
$new_adj->store(); |
|
|
196 |
# Log this addition |
197 |
if (C4::Context->preference("AcqLog")) { |
198 |
my $infos = get_log_string($adj); |
199 |
logaction( |
200 |
'ACQUISITIONS', |
201 |
'CREATE_INVOICE_ADJUSTMENT', |
202 |
$new_adj->adjustment_id, |
203 |
$infos |
204 |
); |
205 |
} |
175 |
} |
206 |
} |
176 |
else { |
207 |
else { |
177 |
my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); |
208 |
my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); |
178 |
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] ){ |
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] ){ |
|
|
210 |
# Log this modification |
211 |
if (C4::Context->preference("AcqLog")) { |
212 |
my $infos = get_log_string({ |
213 |
adjustment => $adjustment[$i], |
214 |
reason => $reason[$i], |
215 |
budget_id => $budget_id[$i], |
216 |
encumber_open => $e_open{$adjustment_id[$i]}, |
217 |
adjustment_old => $old_adj->adjustment, |
218 |
reason_old => $old_adj->reason, |
219 |
budget_id_old => $old_adj->budget_id, |
220 |
encumber_open_old => $old_adj->encumber_open |
221 |
}); |
222 |
logaction( |
223 |
'ACQUISITIONS', |
224 |
'UPDATE_INVOICE_ADJUSTMENT', |
225 |
$adjustment_id[$i], |
226 |
$infos |
227 |
); |
228 |
} |
179 |
$old_adj->timestamp(undef); |
229 |
$old_adj->timestamp(undef); |
180 |
$old_adj->adjustment( $adjustment[$i] ); |
230 |
$old_adj->adjustment( $adjustment[$i] ); |
181 |
$old_adj->reason( $reason[$i] ); |
231 |
$old_adj->reason( $reason[$i] ); |
Lines 300-303
sub get_infos {
Link Here
|
300 |
return \%line; |
350 |
return \%line; |
301 |
} |
351 |
} |
302 |
|
352 |
|
|
|
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 |
|
303 |
output_html_with_http_headers $input, $cookie, $template->output; |
384 |
output_html_with_http_headers $input, $cookie, $template->output; |