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

(-)a/C4/Budgets.pm (-36 / +78 lines)
Lines 24-35 use Koha::Patrons; Link Here
24
use Koha::Acquisition::Invoice::Adjustments;
24
use Koha::Acquisition::Invoice::Adjustments;
25
use C4::Debug;
25
use C4::Debug;
26
use C4::Acquisition;
26
use C4::Acquisition;
27
use C4::Log qw(logaction);
27
use vars qw(@ISA @EXPORT);
28
use vars qw(@ISA @EXPORT);
28
29
29
BEGIN {
30
BEGIN {
30
	require Exporter;
31
    require Exporter;
31
	@ISA    = qw(Exporter);
32
    @ISA    = qw(Exporter);
32
	@EXPORT = qw(
33
    @EXPORT = qw(
33
34
34
        &GetBudget
35
        &GetBudget
35
        &GetBudgetByOrderNumber
36
        &GetBudgetByOrderNumber
Lines 39-45 BEGIN { Link Here
39
        &GetBudgetsReport
40
        &GetBudgetsReport
40
        &GetBudgetReport
41
        &GetBudgetReport
41
        &GetBudgetHierarchy
42
        &GetBudgetHierarchy
42
	    &AddBudget
43
        &AddBudget
43
        &ModBudget
44
        &ModBudget
44
        &DelBudget
45
        &DelBudget
45
        &GetBudgetSpent
46
        &GetBudgetSpent
Lines 54-68 BEGIN { Link Here
54
        &CanUserUseBudget
55
        &CanUserUseBudget
55
        &CanUserModifyBudget
56
        &CanUserModifyBudget
56
57
57
	    &GetBudgetPeriod
58
        &GetBudgetPeriod
58
        &GetBudgetPeriods
59
        &GetBudgetPeriods
59
        &ModBudgetPeriod
60
        &ModBudgetPeriod
60
        &AddBudgetPeriod
61
        &AddBudgetPeriod
61
	    &DelBudgetPeriod
62
        &DelBudgetPeriod
62
63
63
        &ModBudgetPlan
64
        &ModBudgetPlan
64
65
65
		&GetBudgetsPlanCell
66
        &GetBudgetsPlanCell
66
        &AddBudgetPlanValue
67
        &AddBudgetPlanValue
67
        &GetBudgetAuthCats
68
        &GetBudgetAuthCats
68
        &BudgetHasChildren
69
        &BudgetHasChildren
Lines 71-77 BEGIN { Link Here
71
72
72
        &HideCols
73
        &HideCols
73
        &GetCols
74
        &GetCols
74
	);
75
    );
75
}
76
}
76
77
77
# ----------------------------BUDGETS.PM-----------------------------";
78
# ----------------------------BUDGETS.PM-----------------------------";
Lines 341-347 sub GetBudgetSpent { Link Here
341
            quantityreceived > 0 AND
342
            quantityreceived > 0 AND
342
            datecancellationprinted IS NULL
343
            datecancellationprinted IS NULL
343
    |);
344
    |);
344
	$sth->execute($budget_id);
345
    $sth->execute($budget_id);
345
    my $sum = ( $sth->fetchrow_array || 0 ) + 0;
346
    my $sum = ( $sth->fetchrow_array || 0 ) + 0;
346
347
347
    $sth = $dbh->prepare(qq|
348
    $sth = $dbh->prepare(qq|
Lines 359-378 sub GetBudgetSpent { Link Here
359
        $sum += $adj->adjustment;
360
        $sum += $adj->adjustment;
360
    }
361
    }
361
362
362
	return $sum;
363
    return $sum;
363
}
364
}
364
365
365
# -------------------------------------------------------------------
366
# -------------------------------------------------------------------
366
sub GetBudgetOrdered {
367
sub GetBudgetOrdered {
367
	my ($budget_id) = @_;
368
    my ($budget_id) = @_;
368
	my $dbh = C4::Context->dbh;
369
    my $dbh = C4::Context->dbh;
369
	my $sth = $dbh->prepare(qq|
370
    my $sth = $dbh->prepare(qq|
370
        SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| *  quantity) AS sum FROM aqorders
371
        SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| *  quantity) AS sum FROM aqorders
371
            WHERE budget_id = ? AND
372
            WHERE budget_id = ? AND
372
            quantityreceived = 0 AND
373
            quantityreceived = 0 AND
373
            datecancellationprinted IS NULL
374
            datecancellationprinted IS NULL
374
    |);
375
    |);
375
	$sth->execute($budget_id);
376
    $sth->execute($budget_id);
376
    my $sum =  ( $sth->fetchrow_array || 0 ) + 0;
377
    my $sum =  ( $sth->fetchrow_array || 0 ) + 0;
377
378
378
    my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' });
379
    my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' });
Lines 380-386 sub GetBudgetOrdered { Link Here
380
        $sum += $adj->adjustment;
381
        $sum += $adj->adjustment;
381
    }
382
    }
382
383
383
	return $sum;
384
    return $sum;
384
}
385
}
385
386
386
=head2 GetBudgetName
387
=head2 GetBudgetName
Lines 430-436 sub GetBudgetAuthCats { Link Here
430
431
431
# -------------------------------------------------------------------
432
# -------------------------------------------------------------------
432
sub GetBudgetPeriods {
433
sub GetBudgetPeriods {
433
	my ($filters,$orderby) = @_;
434
    my ($filters,$orderby) = @_;
434
435
435
    my $rs = Koha::Database->new()->schema->resultset('Aqbudgetperiod');
436
    my $rs = Koha::Database->new()->schema->resultset('Aqbudgetperiod');
436
    $rs = $rs->search( $filters, { order_by => $orderby } );
437
    $rs = $rs->search( $filters, { order_by => $orderby } );
Lines 451-468 sub GetBudgetPeriod { Link Here
451
}
452
}
452
453
453
sub DelBudgetPeriod{
454
sub DelBudgetPeriod{
454
	my ($budget_period_id) = @_;
455
    my ($budget_period_id) = @_;
455
	my $dbh = C4::Context->dbh;
456
    my $dbh = C4::Context->dbh;
456
	  ; ## $total = number of records linked to the record that must be deleted
457
      ; ## $total = number of records linked to the record that must be deleted
457
    my $total = 0;
458
    my $total = 0;
458
459
459
	## get information about the record that will be deleted
460
    ## get information about the record that will be deleted
460
	my $sth = $dbh->prepare(qq|
461
    my $sth = $dbh->prepare(qq|
461
		DELETE 
462
        DELETE
462
         FROM aqbudgetperiods
463
         FROM aqbudgetperiods
463
         WHERE budget_period_id=? |
464
         WHERE budget_period_id=? |
464
	);
465
    );
465
	return $sth->execute($budget_period_id);
466
    return $sth->execute($budget_period_id);
466
}
467
}
467
468
468
# -------------------------------------------------------------------
469
# -------------------------------------------------------------------
Lines 487-499 sub GetBudgetHierarchy { Link Here
487
                    LEFT JOIN borrowers b on b.borrowernumber = aqbudgets.budget_owner_id
488
                    LEFT JOIN borrowers b on b.borrowernumber = aqbudgets.budget_owner_id
488
                    JOIN aqbudgetperiods USING (budget_period_id)|;
489
                    JOIN aqbudgetperiods USING (budget_period_id)|;
489
490
490
	my @where_strings;
491
    my @where_strings;
491
    # show only period X if requested
492
    # show only period X if requested
492
    if ($budget_period_id) {
493
    if ($budget_period_id) {
493
        push @where_strings," aqbudgets.budget_period_id = ?";
494
        push @where_strings," aqbudgets.budget_period_id = ?";
494
        push @bind_params, $budget_period_id;
495
        push @bind_params, $budget_period_id;
495
    }
496
    }
496
	# show only budgets owned by me, my branch or everyone
497
    # show only budgets owned by me, my branch or everyone
497
    if ($owner) {
498
    if ($owner) {
498
        if ($branchcode) {
499
        if ($branchcode) {
499
            push @where_strings,
500
            push @where_strings,
Lines 509-518 sub GetBudgetHierarchy { Link Here
509
            push @bind_params, $branchcode;
510
            push @bind_params, $branchcode;
510
        }
511
        }
511
    }
512
    }
512
	$query.=" WHERE ".join(' AND ', @where_strings) if @where_strings;
513
    $query.=" WHERE ".join(' AND ', @where_strings) if @where_strings;
513
	$debug && warn $query,join(",",@bind_params);
514
    $debug && warn $query,join(",",@bind_params);
514
	my $sth = $dbh->prepare($query);
515
    my $sth = $dbh->prepare($query);
515
	$sth->execute(@bind_params);
516
    $sth->execute(@bind_params);
516
517
517
    my %links;
518
    my %links;
518
    # create hash with budget_id has key
519
    # create hash with budget_id has key
Lines 644-650 sub AddBudget { Link Here
644
    undef $budget->{budget_encumb}   if defined $budget->{budget_encumb}   && $budget->{budget_encumb}   eq '';
645
    undef $budget->{budget_encumb}   if defined $budget->{budget_encumb}   && $budget->{budget_encumb}   eq '';
645
    undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq '';
646
    undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq '';
646
    my $resultset = Koha::Database->new()->schema->resultset('Aqbudget');
647
    my $resultset = Koha::Database->new()->schema->resultset('Aqbudget');
647
    return $resultset->create($budget)->id;
648
    my $id = $resultset->create($budget)->id;
649
650
    # Log the addition
651
    if (C4::Context->preference("AcqLog")) {
652
        my $infos =
653
            sprintf("%010d", $budget->{budget_amount}) .
654
            sprintf("%010d", $budget->{budget_encumb}) .
655
            sprintf("%010d", $budget->{budget_expend});
656
        logaction(
657
            'ACQUISITIONS',
658
            'CREATE_FUND',
659
            $id,
660
            $infos
661
        );
662
    }
663
    return $id;
648
}
664
}
649
665
650
# -------------------------------------------------------------------
666
# -------------------------------------------------------------------
Lines 654-659 sub ModBudget { Link Here
654
    my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget);
670
    my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget);
655
    return unless($result);
671
    return unless($result);
656
672
673
    # Log this modification
674
    if (C4::Context->preference("AcqLog")) {
675
        my $infos =
676
            sprintf("%010d", $budget->{budget_amount}) .
677
            sprintf("%010d", $budget->{budget_encumb}) .
678
            sprintf("%010d", $budget->{budget_expend}) .
679
            sprintf("%010d", $result->budget_amount) .
680
            sprintf("%010d", $result->budget_encumb) .
681
            sprintf("%010d", $result->budget_expend) .
682
            sprintf("%010d", 0 - ($result->budget_amount - $budget->{budget_amount}));
683
        logaction(
684
            'ACQUISITIONS',
685
            'MODIFY_FUND',
686
            $budget->{budget_id},
687
            $infos
688
        );
689
    }
690
657
    undef $budget->{budget_encumb}   if defined $budget->{budget_encumb}   && $budget->{budget_encumb}   eq '';
691
    undef $budget->{budget_encumb}   if defined $budget->{budget_encumb}   && $budget->{budget_encumb}   eq '';
658
    undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq '';
692
    undef $budget->{budget_owner_id} if defined $budget->{budget_owner_id} && $budget->{budget_owner_id} eq '';
659
    $result = $result->update($budget);
693
    $result = $result->update($budget);
Lines 663-673 sub ModBudget { Link Here
663
# -------------------------------------------------------------------
697
# -------------------------------------------------------------------
664
# FIXME Must be replaced by Koha::Acquisition::Fund->delete
698
# FIXME Must be replaced by Koha::Acquisition::Fund->delete
665
sub DelBudget {
699
sub DelBudget {
666
	my ($budget_id) = @_;
700
    my ($budget_id) = @_;
667
	my $dbh         = C4::Context->dbh;
701
    my $dbh         = C4::Context->dbh;
668
	my $sth         = $dbh->prepare("delete from aqbudgets where budget_id=?");
702
    my $sth         = $dbh->prepare("delete from aqbudgets where budget_id=?");
669
	my $rc          = $sth->execute($budget_id);
703
    my $rc          = $sth->execute($budget_id);
670
	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;
671
}
713
}
672
714
673
715
(-)a/acqui/addorder.pl (+43 lines)
Lines 233-238 my $user = $input->remote_user; Link Here
233
my $basketno = $$orderinfo{basketno};
233
my $basketno = $$orderinfo{basketno};
234
my $basket   = Koha::Acquisition::Baskets->find($basketno);
234
my $basket   = Koha::Acquisition::Baskets->find($basketno);
235
235
236
# Order related fields we're going to log
237
my @log_order_fields = (
238
    'quantity',
239
    'listprice',
240
    'unitprice',
241
    'unitprice_tax_excluded',
242
    'unitprice_tax_included',
243
    'rrp',
244
    'replacementprice',
245
    'rrp_tax_excluded',
246
    'rrp_tax_included',
247
    'ecost',
248
    'ecost_tax_excluded',
249
    'ecost_tax_included',
250
    'tax_rate_on_ordering'
251
);
252
236
# create, modify or delete biblio
253
# create, modify or delete biblio
237
# create if $quantity>0 and $existing='no'
254
# create if $quantity>0 and $existing='no'
238
# modify if $quantity>0 and $existing='yes'
255
# modify if $quantity>0 and $existing='yes'
Lines 297-305 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
297
    my $order = Koha::Acquisition::Order->new($orderinfo);
314
    my $order = Koha::Acquisition::Order->new($orderinfo);
298
    if ( $orderinfo->{ordernumber} ) {
315
    if ( $orderinfo->{ordernumber} ) {
299
        ModOrder($orderinfo);
316
        ModOrder($orderinfo);
317
        # Log the order modification
318
        if (C4::Context->preference("AcqLog")) {
319
            my $infos = '';
320
            foreach my $field(@log_order_fields) {
321
                $infos .= sprintf("%010d", $orderinfo->{$field});
322
            }
323
            logaction(
324
                'ACQUISITIONS',
325
                'MODIFY_ORDER',
326
                $orderinfo->{ordernumber},
327
                $infos
328
            );
329
        }
300
    }
330
    }
301
    else { # else, it's a new line
331
    else { # else, it's a new line
302
        $order->store;
332
        $order->store;
333
        # Log the order creation
334
        if (C4::Context->preference("AcqLog")) {
335
            my $infos = '';
336
            foreach my $field(@log_order_fields) {
337
                $infos .= sprintf("%010d", $orderinfo->{$field});
338
            }
339
            logaction(
340
                'ACQUISITIONS',
341
                'CREATE_ORDER',
342
                $order->ordernumber,
343
                $infos
344
            );
345
        }
303
    }
346
    }
304
    my $order_users_ids = $input->param('users_ids');
347
    my $order_users_ids = $input->param('users_ids');
305
    my @order_users = split( /:/, $order_users_ids );
348
    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 190-193 if ($suggestion_id) { Link Here
190
    $suggestion->update( { reason => $reason } ) if $suggestion;
191
    $suggestion->update( { reason => $reason } ) if $suggestion;
191
}
192
}
192
193
194
# Log the receipt
195
if (C4::Context->preference("AcqLog")) {
196
    my $infos =
197
        sprintf("%010d", $quantityrec) .
198
        sprintf("%010d", $bookfund) .
199
        sprintf("%010.2f", $input->param("tax_rate")) .
200
        sprintf("%010.2f", $replacementprice) .
201
        sprintf("%010.2f", $unitprice);
202
203
    logaction(
204
        'ACQUISITIONS',
205
        'RECEIVE_ORDER',
206
        $ordernumber,
207
        $infos
208
    );
209
}
210
193
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
211
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 = 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,
150
				invoiceid => $invoiceid,
131
                adjustment => $adjustment[$i],
151
                adjustment => $adjustment[$i],
132
                reason => $reason[$i],
152
                reason => $reason[$i],
133
                note => $note[$i],
153
                note => $note[$i],
134
                budget_id => $budget_id[$i] || undef,
154
                budget_id => $budget_id[$i] || undef,
135
                encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0,
155
                encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0,
136
            });
156
            };
157
			my $new_adj = Koha::Acquisition::Invoice::Adjustment->new($adj);
137
            $new_adj->store();
158
            $new_adj->store();
159
            # Log this addition
160
            if (C4::Context->preference("AcqLog")) {
161
                my $infos = get_log_string($adj);
162
                logaction(
163
                    'ACQUISITIONS',
164
                    'CREATE_INVOICE_ADJUSTMENT',
165
                    $new_adj->adjustment_id,
166
                    $infos
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 81-86 fieldset.rows label.viewlog { Link Here
81
[%        CASE 'CLOSE_BASKET' %]Close an acquisitions basket
81
[%        CASE 'CLOSE_BASKET' %]Close an acquisitions basket
82
[%        CASE 'APPROVE_BASKET' %]Approve an acquisitions basket
82
[%        CASE 'APPROVE_BASKET' %]Approve an acquisitions basket
83
[%        CASE 'REOPEN_BASKET' %]Reopen an acquisitions basket
83
[%        CASE 'REOPEN_BASKET' %]Reopen an acquisitions basket
84
[%        CASE 'CANCEL_ORDER' %]Cancel an order
85
[%        CASE 'CREATE_ORDER' %]Create an order
86
[%        CASE 'MODIFY_ORDER' %]Modify an order
87
[%        CASE 'CREATE_INVOICE_ADJUSTMENT' %]Create an invoice adjustment
88
[%        CASE 'UPDATE_INVOICE_ADJUSTMENT' %]Modify an invoice adjustment
89
[%        CASE 'DELETE_INVOICE_ADJUSTMENT' %]Delete an invoice adjustment
90
[%        CASE 'RECEIVE_ORDER' %]Receive an order
91
[%        CASE 'MODIFY_BUDGET' %]Modify a budget
92
[%        CASE 'CREATE_FUND' %]Create a fund
93
[%        CASE 'MODIFY_FUND' %]Modify a fund
94
[%        CASE 'DELETE_FUND' %]Delete a fund
84
[%        CASE 'Run'    %]Run
95
[%        CASE 'Run'    %]Run
85
[%        CASE %][% action | html %]
96
[%        CASE %][% action | html %]
86
[%    END %]
97
[%    END %]
Lines 153-159 fieldset.rows label.viewlog { Link Here
153
                                        <label for="actionALL" class="viewlog"><input type="checkbox" id="actionALL" name="actions" value=""> All</label>
164
                                        <label for="actionALL" class="viewlog"><input type="checkbox" id="actionALL" name="actions" value=""> All</label>
154
                                    [% END %]
165
                                    [% END %]
155
166
156
                                    [% 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' ] %]
167
									[% 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' ] %]
157
                                        [% IF actions.grep(actx).size %]
168
                                        [% IF actions.grep(actx).size %]
158
                                            <label for="action[% actx | html %]" class="viewlog"><input type="checkbox" id="action[% actx | html %]" name="actions" value="[% actx | html %]" checked="checked"> [% PROCESS translate_log_action action=actx %]</label>
169
                                            <label for="action[% actx | html %]" class="viewlog"><input type="checkbox" id="action[% actx | html %]" name="actions" value="[% actx | html %]" checked="checked"> [% PROCESS translate_log_action action=actx %]</label>
159
                                        [% ELSE %]
170
                                        [% ELSE %]
160
- 

Return to bug 24190