View | Details | Raw Unified | Return to bug 24190
Collapse All | Expand All

(-)a/C4/Budgets.pm (-2 / +45 lines)
Lines 25-30 use Koha::Patrons; Link Here
25
use Koha::Acquisition::Invoice::Adjustments;
25
use Koha::Acquisition::Invoice::Adjustments;
26
use C4::Debug;
26
use C4::Debug;
27
use C4::Acquisition;
27
use C4::Acquisition;
28
use C4::Log qw(logaction);
28
use vars qw(@ISA @EXPORT);
29
use vars qw(@ISA @EXPORT);
29
30
30
BEGIN {
31
BEGIN {
Lines 645-651 sub AddBudget { Link Here
645
    undef $budget->{budget_encumb} if $budget->{budget_encumb} eq '';
646
    undef $budget->{budget_encumb} if $budget->{budget_encumb} eq '';
646
    undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq '';
647
    undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq '';
647
    my $resultset = Koha::Database->new()->schema->resultset('Aqbudget');
648
    my $resultset = Koha::Database->new()->schema->resultset('Aqbudget');
648
    return $resultset->create($budget)->id;
649
650
    my $id = $resultset->create($budget)->id;
651
652
    # Log the addition
653
    if (C4::Context->preference("AcqLog")) {
654
        my $infos =
655
            sprintf("%010d", $budget->{budget_amount}) .
656
            sprintf("%010d", $budget->{budget_encumb}) .
657
            sprintf("%010d", $budget->{budget_expend});
658
        logaction(
659
            'ACQUISITIONS',
660
            'CREATE_FUND',
661
            $id,
662
            $infos
663
        );
664
    }
665
    return $id;
649
}
666
}
650
667
651
# -------------------------------------------------------------------
668
# -------------------------------------------------------------------
Lines 654-659 sub ModBudget { Link Here
654
    my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget);
671
    my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget);
655
    return unless($result);
672
    return unless($result);
656
673
674
    # Log this modification
675
    if (C4::Context->preference("AcqLog")) {
676
        my $infos =
677
            sprintf("%010d", $budget->{budget_amount}) .
678
            sprintf("%010d", $budget->{budget_encumb}) .
679
            sprintf("%010d", $budget->{budget_expend}) .
680
            sprintf("%010d", $result->budget_amount) .
681
            sprintf("%010d", $result->budget_encumb) .
682
            sprintf("%010d", $result->budget_expend) .
683
            sprintf("%010d", 0 - ($result->budget_amount - $budget->{budget_amount}));
684
        logaction(
685
            'ACQUISITIONS',
686
            'MODIFY_FUND',
687
            $budget->{budget_id},
688
            $infos
689
        );
690
    }
691
657
    undef $budget->{budget_encumb} if $budget->{budget_encumb} eq '';
692
    undef $budget->{budget_encumb} if $budget->{budget_encumb} eq '';
658
    undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq '';
693
    undef $budget->{budget_owner_id} if $budget->{budget_owner_id} eq '';
659
    $result = $result->update($budget);
694
    $result = $result->update($budget);
Lines 666-672 sub DelBudget { Link Here
666
	my $dbh         = C4::Context->dbh;
701
	my $dbh         = C4::Context->dbh;
667
	my $sth         = $dbh->prepare("delete from aqbudgets where budget_id=?");
702
	my $sth         = $dbh->prepare("delete from aqbudgets where budget_id=?");
668
	my $rc          = $sth->execute($budget_id);
703
	my $rc          = $sth->execute($budget_id);
669
	return $rc;
704
	# Log the deletion
705
    if (C4::Context->preference("AcqLog")) {
706
        logaction(
707
            'ACQUISITIONS',
708
            'DELETE_FUND',
709
            $budget_id
710
        );
711
    }
712
    return $rc;
670
}
713
}
671
714
672
715
(-)a/acqui/addorder.pl (+43 lines)
Lines 235-240 my $user = $input->remote_user; Link Here
235
my $basketno = $$orderinfo{basketno};
235
my $basketno = $$orderinfo{basketno};
236
my $basket   = Koha::Acquisition::Baskets->find($basketno);
236
my $basket   = Koha::Acquisition::Baskets->find($basketno);
237
237
238
# Order related fields we're going to log
239
my @log_order_fields = (
240
    'quantity',
241
    'listprice',
242
    'unitprice',
243
    'unitprice_tax_excluded',
244
    'unitprice_tax_included',
245
    'rrp',
246
    'replacementprice',
247
    'rrp_tax_excluded',
248
    'rrp_tax_included',
249
    'ecost',
250
    'ecost_tax_excluded',
251
    'ecost_tax_included',
252
    'tax_rate_on_ordering'
253
);
254
238
# create, modify or delete biblio
255
# create, modify or delete biblio
239
# create if $quantity>0 and $existing='no'
256
# create if $quantity>0 and $existing='no'
240
# modify if $quantity>0 and $existing='yes'
257
# modify if $quantity>0 and $existing='yes'
Lines 291-299 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
291
    my $order = Koha::Acquisition::Order->new($orderinfo);
308
    my $order = Koha::Acquisition::Order->new($orderinfo);
292
    if ( $orderinfo->{ordernumber} ) {
309
    if ( $orderinfo->{ordernumber} ) {
293
        ModOrder($orderinfo);
310
        ModOrder($orderinfo);
311
        # Log the order modification
312
        if (C4::Context->preference("AcqLog")) {
313
            my $infos = '';
314
            foreach my $field(@log_order_fields) {
315
                $infos .= sprintf("%010d", $orderinfo->{$field});
316
            }
317
            logaction(
318
                'ACQUISITIONS',
319
                'MODIFY_ORDER',
320
                $orderinfo->{ordernumber},
321
                $infos
322
            );
323
        }
294
    }
324
    }
295
    else { # else, it's a new line
325
    else { # else, it's a new line
296
        $order->store;
326
        $order->store;
327
        # Log the order creation
328
        if (C4::Context->preference("AcqLog")) {
329
            my $infos = '';
330
            foreach my $field(@log_order_fields) {
331
                $infos .= sprintf("%010d", $orderinfo->{$field});
332
            }
333
            logaction(
334
                'ACQUISITIONS',
335
                'CREATE_ORDER',
336
                $order->ordernumber,
337
                $infos
338
            );
339
        }
297
    }
340
    }
298
    my $order_users_ids = $input->param('users_ids');
341
    my $order_users_ids = $input->param('users_ids');
299
    my @order_users = split( /:/, $order_users_ids );
342
    my @order_users = split( /:/, $order_users_ids );
(-)a/acqui/cancelorder.pl (+5 lines)
Lines 35-40 use CGI; Link Here
35
use C4::Auth;
35
use C4::Auth;
36
use C4::Output;
36
use C4::Output;
37
use C4::Acquisition;
37
use C4::Acquisition;
38
use C4::Log qw(logaction);
38
use Koha::Acquisition::Baskets;
39
use Koha::Acquisition::Baskets;
39
40
40
my $input = new CGI;
41
my $input = new CGI;
Lines 64-69 if($action and $action eq "confirmcancel") { Link Here
64
        $template->param(error_delbiblio => 1) if $error->{'delbiblio'};
65
        $template->param(error_delbiblio => 1) if $error->{'delbiblio'};
65
    } else {
66
    } else {
66
        $template->param(success_cancelorder => 1);
67
        $template->param(success_cancelorder => 1);
68
        # Log the cancellation of the order
69
        if (C4::Context->preference("AcqLog")) {
70
            logaction('ACQUISITIONS', 'CANCEL_ORDER', $ordernumber);
71
        }
67
    }
72
    }
68
    $template->param(confirmcancel => 1);
73
    $template->param(confirmcancel => 1);
69
}
74
}
(-)a/acqui/finishreceive.pl (+18 lines)
Lines 28-33 use C4::Context; Link Here
28
use C4::Acquisition;
28
use C4::Acquisition;
29
use C4::Biblio;
29
use C4::Biblio;
30
use C4::Items;
30
use C4::Items;
31
use C4::Log qw(logaction);
31
use C4::Search;
32
use C4::Search;
32
33
33
use Koha::Number::Price;
34
use Koha::Number::Price;
Lines 185-188 while ( my $item = $items->next ) { Link Here
185
    );
186
    );
186
}
187
}
187
188
189
# Log the receipt
190
if (C4::Context->preference("AcqLog")) {
191
    my $infos =
192
        sprintf("%010d", $quantityrec) .
193
        sprintf("%010d", $bookfund) .
194
        sprintf("%010.2f", $input->param("tax_rate")) .
195
        sprintf("%010.2f", $replacementprice) .
196
        sprintf("%010.2f", $unitprice);
197
198
    logaction(
199
        'ACQUISITIONS',
200
        'RECEIVE_ORDER',
201
        $ordernumber,
202
        $infos
203
    );
204
}
205
188
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
206
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
(-)a/acqui/invoice.pl (-4 / +85 lines)
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;
(-)a/admin/aqbudgetperiods.pl (-8 / +29 lines)
Lines 57-62 use C4::Output; Link Here
57
use C4::Acquisition;
57
use C4::Acquisition;
58
use C4::Budgets;
58
use C4::Budgets;
59
use C4::Debug;
59
use C4::Debug;
60
use C4::Log qw(logaction);
60
use Koha::Acquisition::Currencies;
61
use Koha::Acquisition::Currencies;
61
62
62
my $dbh = C4::Context->dbh;
63
my $dbh = C4::Context->dbh;
Lines 116-129 elsif ( $op eq 'add_validate' ) { Link Here
116
## add or modify a budget period (confirmation)
117
## add or modify a budget period (confirmation)
117
118
118
    ## update budget period data
119
    ## update budget period data
119
	if ( $budget_period_id ne '' ) {
120
    if ( $budget_period_id ne '' ) {
120
		$$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked);
121
        # Grab the previous values so we can log them
121
		my $status=ModBudgetPeriod($budget_period_hashref);
122
        my $budgetperiod_old=GetBudgetPeriod($budget_period_id);
122
	} 
123
        $$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked);
123
	else {    # ELSE ITS AN ADD
124
        my $status=ModBudgetPeriod($budget_period_hashref);
124
		my $budget_period_id=AddBudgetPeriod($budget_period_hashref);
125
        # Log the budget modification
125
	}
126
        if (C4::Context->preference("AcqLog")) {
126
	$op='else';
127
            my $diff = 0 - ($budgetperiod_old->{budget_period_total} - $budget_period_hashref->{budget_period_total});
128
            my $infos =
129
                eval { output_pref({ dt => dt_from_string( $input->param('budget_period_startdate') ), dateformat => 'iso', dateonly => 1 } ); } .
130
                eval { output_pref({ dt => dt_from_string( $input->param('budget_period_enddate') ), dateformat => 'iso', dateonly => 1 } ); } .
131
                sprintf("%010d", $budget_period_hashref->{budget_period_total}) .
132
                eval { output_pref({ dt => dt_from_string( $budgetperiod_old->{budget_period_startdate} ), dateformat => 'iso', dateonly => 1 } ); } .
133
                eval { output_pref({ dt => dt_from_string( $budgetperiod_old->{budget_period_enddate} ), dateformat => 'iso', dateonly => 1 } ); } .
134
                sprintf("%010d", $budgetperiod_old->{budget_period_total}) .
135
                sprintf("%010d", $diff);
136
            logaction(
137
                'ACQUISITIONS',
138
                'MODIFY_BUDGET',
139
                $budget_period_id,
140
                $infos
141
            );
142
        }
143
    }
144
    else {    # ELSE ITS AN ADD
145
        my $budget_period_id=AddBudgetPeriod($budget_period_hashref);
146
    }
147
    $op='else';
127
}
148
}
128
149
129
#--------------------------------------------------
150
#--------------------------------------------------
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt (-2 / +12 lines)
Lines 64-69 Link Here
64
[%        CASE 'CLOSE_BASKET' %]Close an acquisitions basket
64
[%        CASE 'CLOSE_BASKET' %]Close an acquisitions basket
65
[%        CASE 'APPROVE_BASKET' %]Approve an acquisitions basket
65
[%        CASE 'APPROVE_BASKET' %]Approve an acquisitions basket
66
[%        CASE 'REOPEN_BASKET' %]Reopen an acquisitions basket
66
[%        CASE 'REOPEN_BASKET' %]Reopen an acquisitions basket
67
[%        CASE 'CANCEL_ORDER' %]Cancel an order
68
[%        CASE 'CREATE_ORDER' %]Create an order
69
[%        CASE 'MODIFY_ORDER' %]Modify an order
70
[%        CASE 'CREATE_INVOICE_ADJUSTMENT' %]Create an invoice adjustment
71
[%        CASE 'UPDATE_INVOICE_ADJUSTMENT' %]Modify an invoice adjustment
72
[%        CASE 'DELETE_INVOICE_ADJUSTMENT' %]Delete an invoice adjustment
73
[%        CASE 'RECEIVE_ORDER' %]Receive an order
74
[%        CASE 'MODIFY_BUDGET' %]Modify a budget
75
[%        CASE 'CREATE_FUND' %]Create a fund
76
[%        CASE 'MODIFY_FUND' %]Modify a fund
77
[%        CASE 'DELETE_FUND' %]Delete a fund
67
[%        CASE 'Run'    %]Run
78
[%        CASE 'Run'    %]Run
68
[%        CASE %][% action | html %]
79
[%        CASE %][% action | html %]
69
[%    END %]
80
[%    END %]
Lines 131-137 Link Here
131
                                        <option value="">All</option>
142
                                        <option value="">All</option>
132
                                    [% END %]
143
                                    [% END %]
133
144
134
                                    [% FOREACH actx IN [ 'ADD' 'DELETE' 'MODIFY' 'ISSUE' 'RETURN' 'RENEW' 'CREATE' 'CANCEL' 'SUSPEND' 'RESUME' 'ADDCIRCMESSAGE' 'DELCIRCMESSAGE' 'STATUS_CHANGE' 'CHANGE PASS' 'Run' 'ADD_BASKET' 'MODIFY_BASKET' 'MODIFY_BASKET_HEADER' 'MODIFY_BASKET_USERS' 'CLOSE_BASKET' 'APPROVE_BASKET' 'REOPEN_BASKET' ] %]
145
                                    [% FOREACH actx IN [ 'ADD' 'DELETE' 'MODIFY' 'ISSUE' 'RETURN' 'RENEW' 'CREATE' 'CANCEL' 'SUSPEND' 'RESUME' 'ADDCIRCMESSAGE' 'DELCIRCMESSAGE' 'STATUS_CHANGE' 'CHANGE PASS' 'Run' 'ADD_BASKET' 'MODIFY_BASKET' 'MODIFY_BASKET_HEADER' 'MODIFY_BASKET_USERS' 'CLOSE_BASKET' 'APPROVE_BASKET' 'REOPEN_BASKET' 'CANCEL_ORDER' 'CREATE_ORDER' 'MODIFY_ORDER' 'CREATE_INVOICE_ADJUSTMENT' 'UPDATE_INVOICE_ADJUSTMENT' 'DELETE_INVOICE_ADJUSTMENT' 'RECEIVE_ORDER' 'MODIFY_BUDGET' 'MODIFY_FUND' 'CREATE_FUND' 'DELETE_FUND' ] %]
135
                                        [% IF actions.grep(actx).size %]
146
                                        [% IF actions.grep(actx).size %]
136
                                            <option value="[% actx | html %]" selected="selected">[% PROCESS translate_log_action action=actx %]</option>
147
                                            <option value="[% actx | html %]" selected="selected">[% PROCESS translate_log_action action=actx %]</option>
137
                                        [% ELSE %]
148
                                        [% ELSE %]
138
- 

Return to bug 24190