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

(-)a/C4/Budgets.pm (+21 lines)
Lines 187-192 sub BudgetHasChildren { Link Here
187
    return $sum->{'sum'};
187
    return $sum->{'sum'};
188
}
188
}
189
189
190
sub GetBudgetChildren {
191
    my ( $budget_id ) = @_;
192
    my $dbh = C4::Context->dbh;
193
    return $dbh->selectall_arrayref(q|
194
       SELECT  * FROM  aqbudgets
195
        WHERE budget_parent_id = ?
196
    |, { Slice => {} }, $budget_id );
197
}
198
199
sub SetOwnerToFundHierarchy {
200
    my ( $budget_id, $borrowernumber ) = @_;
201
202
    my $budget = GetBudget( $budget_id );
203
    $budget->{budget_owner_id} = $borrowernumber;
204
    ModBudget( $budget );
205
    my $children = GetBudgetChildren( $budget_id );
206
    for my $child ( @$children ) {
207
        SetOwnerToFundHierarchy( $child->{budget_id}, $borrowernumber );
208
    }
209
}
210
190
# -------------------------------------------------------------------
211
# -------------------------------------------------------------------
191
sub GetBudgetsPlanCell {
212
sub GetBudgetsPlanCell {
192
    my ( $cell, $period, $budget ) = @_;
213
    my ( $cell, $period, $budget ) = @_;
(-)a/admin/aqbudgets.pl (+9 lines)
Lines 211-216 if ($op eq 'add_form') { Link Here
211
211
212
    # if no buget_id is passed then its an add
212
    # if no buget_id is passed then its an add
213
    $template->param(
213
    $template->param(
214
        budget_has_children => BudgetHasChildren( $budget->{budget_id} ),
214
        budget_parent_id    		  => $budget_parent->{'budget_id'},
215
        budget_parent_id    		  => $budget_parent->{'budget_id'},
215
        budget_parent_name    		  => $budget_parent->{'budget_name'},
216
        budget_parent_name    		  => $budget_parent->{'budget_name'},
216
        branchloop_select         => \@branchloop_select,
217
        branchloop_select         => \@branchloop_select,
Lines 241-252 if ($op eq 'add_form') { Link Here
241
        @budgetusersid = split(':', $budget_users_ids);
242
        @budgetusersid = split(':', $budget_users_ids);
242
    }
243
    }
243
244
245
    my $budget_modified = 0;
244
    if (defined $budget_id) {
246
    if (defined $budget_id) {
245
        if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
247
        if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
246
            $staffflags)
248
            $staffflags)
247
        ) {
249
        ) {
248
            ModBudget( $budget_hash );
250
            ModBudget( $budget_hash );
249
            ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
251
            ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
252
            $budget_modified = 1;
250
        }
253
        }
251
        else {
254
        else {
252
            $template->param(error_not_authorised_to_modify => 1);
255
            $template->param(error_not_authorised_to_modify => 1);
Lines 254-259 if ($op eq 'add_form') { Link Here
254
    } else {
257
    } else {
255
        $budget_hash->{budget_id} = AddBudget( $budget_hash );
258
        $budget_hash->{budget_id} = AddBudget( $budget_hash );
256
        ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
259
        ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
260
        $budget_modified = 1;
261
    }
262
263
    my $set_owner_to_children = $input->param('set_owner_to_children');
264
    if ( $set_owner_to_children and $budget_modified ) {
265
        C4::Budgets::SetOwnerToFundHierarchy( $budget_hash->{budget_id}, $budget_hash->{budget_owner_id} );
257
    }
266
    }
258
    $op = 'list';
267
    $op = 'list';
259
}
268
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (+9 lines)
Lines 473-478 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
473
            onclick="ownerRemove(); return false;" />
473
            onclick="ownerRemove(); return false;" />
474
    </li>
474
    </li>
475
475
476
    [% IF budget_has_children %]
477
        <li>
478
            <span class="label">
479
                <label for="set_owner_to_children">Set this owner to all children funds:</label>
480
            </span>
481
            <input type="checkbox" id="set_owner_to_children" name="set_owner_to_children" value="1" />
482
        </li>
483
    [% END %]
484
476
    <li>
485
    <li>
477
        <span class="label">Users:</span>
486
        <span class="label">Users:</span>
478
        <ul style="float:left;" id="budget_users">
487
        <ul style="float:left;" id="budget_users">
(-)a/t/db_dependent/Budgets.t (-2 / +64 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 108;
2
use Test::More tests => 120;
3
3
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
Lines 9-14 use C4::Biblio; Link Here
9
use C4::Bookseller;
9
use C4::Bookseller;
10
use C4::Acquisition;
10
use C4::Acquisition;
11
use C4::Dates;
11
use C4::Dates;
12
use C4::Members qw( AddMember );
12
13
13
use YAML;
14
use YAML;
14
my $dbh = C4::Context->dbh;
15
my $dbh = C4::Context->dbh;
Lines 95-100 is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget p Link Here
95
# Budget  :
96
# Budget  :
96
#
97
#
97
98
99
# The budget hierarchy will be:
100
# budget_1
101
#   budget_11
102
#     budget_111
103
#   budget_12
104
# budget_2
105
#   budget_21
106
98
is( AddBudget(), undef, 'AddBuget without argument returns undef' );
107
is( AddBudget(), undef, 'AddBuget without argument returns undef' );
99
my $budgets = GetBudgets();
108
my $budgets = GetBudgets();
100
is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' );
109
is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' );
Lines 512-517 for my $new_budget ( @new_budgets ) { Link Here
512
    is( $new_budget->{budget_amount} + 0, $new_budget_amount_should_be, "MoveOrders updated the budget amount with the previous unspent budget (for budget $new_budget->{budget_code})" );
521
    is( $new_budget->{budget_amount} + 0, $new_budget_amount_should_be, "MoveOrders updated the budget amount with the previous unspent budget (for budget $new_budget->{budget_code})" );
513
}
522
}
514
523
524
# Test SetOwnerToFundHierarchy
525
526
my $categorycode = 'S';
527
my $branchcode = 'CPL';
528
my $john_doe = C4::Members::AddMember(
529
    cardnumber   => '123456',
530
    firstname    => 'John',
531
    surname      => 'Doe',
532
    categorycode => $categorycode,
533
    branchcode   => $branchcode,
534
    dateofbirth  => '',
535
    dateexpiry   => '9999-12-31',
536
    userid       => 'john.doe'
537
);
538
539
C4::Budgets::SetOwnerToFundHierarchy( $budget_id1, $john_doe );
540
is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
541
    $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 1 ($budget_id1)" );
542
is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
543
    $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 11 ($budget_id11)" );
544
is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
545
    $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 111 ($budget_id111)" );
546
is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
547
    $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 12 ($budget_id12 )" );
548
is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
549
    undef, "SetOwnerToFundHierarchy should not have set an owner for budget 2 ($budget_id2)" );
550
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
551
    undef, "SetOwnerToFundHierarchy should not have set an owner for budget 21 ($budget_id21)" );
552
553
my $jane_doe = C4::Members::AddMember(
554
    cardnumber   => '789012',
555
    firstname    => 'Jane',
556
    surname      => 'Doe',
557
    categorycode => $categorycode,
558
    branchcode   => $branchcode,
559
    dateofbirth  => '',
560
    dateexpiry   => '9999-12-31',
561
    userid       => 'jane.doe'
562
);
563
564
C4::Budgets::SetOwnerToFundHierarchy( $budget_id11, $jane_doe );
565
is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
566
    $john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 1 ($budget_id1)" );
567
is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
568
    $jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 11 ($budget_id11)" );
569
is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
570
    $jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 111 ($budget_id111)" );
571
is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
572
    $john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 12 ($budget_id12 )" );
573
is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
574
    undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 2 ($budget_id2)" );
575
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
576
    undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
577
515
sub _get_dependencies {
578
sub _get_dependencies {
516
    my ($budget_hierarchy) = @_;
579
    my ($budget_hierarchy) = @_;
517
    my $graph;
580
    my $graph;
518
- 

Return to bug 12958