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 112-118
elsif ( $op && $op eq 'delete' ) {
Link Here
|
112 |
elsif ( $op && $op eq 'del_adj' ) { |
113 |
elsif ( $op && $op eq 'del_adj' ) { |
113 |
my $adjustment_id = $input->param('adjustment_id'); |
114 |
my $adjustment_id = $input->param('adjustment_id'); |
114 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
115 |
my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); |
115 |
$del_adj->delete() if ($del_adj); |
116 |
if ($del_adj) { |
|
|
117 |
if (C4::Context->preference("AcqLog")) { |
118 |
my $reason_length = $del_adj->reason; |
119 |
my $reason_padded = ( ' ' x (80 - $reason_length) ) . $del_adj->reason; |
120 |
my $infos = |
121 |
sprintf("%010d", $del_adj->invoiceid) . |
122 |
sprintf("%010d", $del_adj->budget_id) . |
123 |
sprintf("%010d", $del_adj->encumber_open) . |
124 |
sprintf("%010.2f", $del_adj->adjustment) . |
125 |
$reason_padded; |
126 |
logaction( |
127 |
'ACQUISITIONS', |
128 |
'DELETE_INVOICE_ADJUSTMENT', |
129 |
$adjustment_id, |
130 |
$infos |
131 |
); |
132 |
} |
133 |
$del_adj->delete(); |
134 |
} |
116 |
} |
135 |
} |
117 |
elsif ( $op && $op eq 'mod_adj' ) { |
136 |
elsif ( $op && $op eq 'mod_adj' ) { |
118 |
my @adjustment_id = $input->multi_param('adjustment_id'); |
137 |
my @adjustment_id = $input->multi_param('adjustment_id'); |
Lines 123-144
elsif ( $op && $op eq 'mod_adj' ) {
Link Here
|
123 |
my @encumber_open = $input->multi_param('encumber_open'); |
142 |
my @encumber_open = $input->multi_param('encumber_open'); |
124 |
my %e_open = map { $_ => 1 } @encumber_open; |
143 |
my %e_open = map { $_ => 1 } @encumber_open; |
125 |
|
144 |
|
|
|
145 |
my @keys = ('adjustment', 'reason', 'budget_id', 'encumber_open'); |
126 |
for( my $i=0; $i < scalar @adjustment; $i++ ){ |
146 |
for( my $i=0; $i < scalar @adjustment; $i++ ){ |
127 |
if( $adjustment_id[$i] eq 'new' ){ |
147 |
if( $adjustment_id[$i] eq 'new' ){ |
128 |
next unless ( $adjustment[$i] || $reason[$i] ); |
148 |
next unless ( $adjustment[$i] || $reason[$i] ); |
129 |
my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({ |
149 |
my $adj = { |
130 |
invoiceid => $invoiceid, |
|
|
131 |
adjustment => $adjustment[$i], |
150 |
adjustment => $adjustment[$i], |
132 |
reason => $reason[$i], |
151 |
reason => $reason[$i], |
133 |
note => $note[$i], |
152 |
note => $note[$i], |
134 |
budget_id => $budget_id[$i] || undef, |
153 |
budget_id => $budget_id[$i] || undef, |
135 |
encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, |
154 |
encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, |
136 |
}); |
155 |
}; |
|
|
156 |
my $new_adj = Koha::Acquisition::Invoice::Adjustment->new($adj); |
137 |
$new_adj->store(); |
157 |
$new_adj->store(); |
|
|
158 |
# Log this addition |
159 |
if (C4::Context->preference("AcqLog")) { |
160 |
my $infos = get_log_string($adj); |
161 |
logaction( |
162 |
'ACQUISITIONS', |
163 |
'CREATE_INVOICE_ADJUSTMENT', |
164 |
$new_adj->adjustment_id, |
165 |
$infos |
166 |
); |
167 |
} |
168 |
|
138 |
} |
169 |
} |
139 |
else { |
170 |
else { |
140 |
my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); |
171 |
my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); |
141 |
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] ){ |
172 |
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] ){ |
|
|
173 |
# Log this modification |
174 |
if (C4::Context->preference("AcqLog")) { |
175 |
my $infos = get_log_string({ |
176 |
adjustment => $adjustment[$i], |
177 |
reason => $reason[$i], |
178 |
budget_id => $budget_id[$i], |
179 |
encumber_open => $e_open{$adjustment_id[$i]}, |
180 |
adjustment_old => $old_adj->adjustment, |
181 |
reason_old => $old_adj->reason, |
182 |
budget_id_old => $old_adj->budget_id, |
183 |
encumber_open_old => $old_adj->encumber_open |
184 |
}); |
185 |
logaction( |
186 |
'ACQUISITIONS', |
187 |
'UPDATE_INVOICE_ADJUSTMENT', |
188 |
$adjustment_id[$i], |
189 |
$infos |
190 |
); |
191 |
} |
142 |
$old_adj->timestamp(undef); |
192 |
$old_adj->timestamp(undef); |
143 |
$old_adj->adjustment( $adjustment[$i] ); |
193 |
$old_adj->adjustment( $adjustment[$i] ); |
144 |
$old_adj->reason( $reason[$i] ); |
194 |
$old_adj->reason( $reason[$i] ); |
Lines 266-269
sub get_infos {
Link Here
|
266 |
return \%line; |
316 |
return \%line; |
267 |
} |
317 |
} |
268 |
|
318 |
|
|
|
319 |
sub get_log_string { |
320 |
my ($data) = @_; |
321 |
|
322 |
# We specify the keys we're dealing for logging within an array in order |
323 |
# to preserve order, if we just iterate the hash keys, we could get |
324 |
# the values in any order |
325 |
my @keys = ( |
326 |
'budget_id', |
327 |
'encumber_open', |
328 |
'budget_id_old', |
329 |
'encumber_open_old' |
330 |
); |
331 |
# Adjustment amount |
332 |
my $return = sprintf("%010.2f", $data->{adjustment}); |
333 |
# Left pad "reason" to the maximum length of aqinvoice_adjustments.reason |
334 |
# (80 characters) |
335 |
my $reason_len = length $data->{reason}; |
336 |
$return .= ( ' ' x (80 - $reason_len) ) . $data->{reason}; |
337 |
# Append the remaining fields |
338 |
foreach my $key(@keys) { |
339 |
$return .= sprintf("%010d", $data->{$key}); |
340 |
} |
341 |
# Old adjustment amount |
342 |
$return .= sprintf("%010.2f", $data->{adjustment_old}); |
343 |
# Left pad "reason_old" to the maximum length of aqinvoice_adjustments.reason |
344 |
# (80 characters) |
345 |
my $reason_old_len = length $data->{reason_old}; |
346 |
$return .= ( ' ' x (80 - $reason_old_len) ) . $data->{reason_old}; |
347 |
return $return; |
348 |
} |
349 |
|
269 |
output_html_with_http_headers $input, $cookie, $template->output; |
350 |
output_html_with_http_headers $input, $cookie, $template->output; |