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 210-215 if ($op eq 'add_form') { Link Here
210
210
211
    # if no buget_id is passed then its an add
211
    # if no buget_id is passed then its an add
212
    $template->param(
212
    $template->param(
213
        budget_has_children => BudgetHasChildren( $budget->{budget_id} ),
213
        budget_parent_id    		  => $budget_parent->{'budget_id'},
214
        budget_parent_id    		  => $budget_parent->{'budget_id'},
214
        budget_parent_name    		  => $budget_parent->{'budget_name'},
215
        budget_parent_name    		  => $budget_parent->{'budget_name'},
215
        branchloop_select         => \@branchloop_select,
216
        branchloop_select         => \@branchloop_select,
Lines 240-251 if ($op eq 'add_form') { Link Here
240
        @budgetusersid = split(':', $budget_users_ids);
241
        @budgetusersid = split(':', $budget_users_ids);
241
    }
242
    }
242
243
244
    my $budget_modified = 0;
243
    if (defined $budget_id) {
245
    if (defined $budget_id) {
244
        if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
246
        if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
245
            $staffflags)
247
            $staffflags)
246
        ) {
248
        ) {
247
            ModBudget( $budget_hash );
249
            ModBudget( $budget_hash );
248
            ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
250
            ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
251
            $budget_modified = 1;
249
        }
252
        }
250
        else {
253
        else {
251
            $template->param(error_not_authorised_to_modify => 1);
254
            $template->param(error_not_authorised_to_modify => 1);
Lines 253-258 if ($op eq 'add_form') { Link Here
253
    } else {
256
    } else {
254
        $budget_hash->{budget_id} = AddBudget( $budget_hash );
257
        $budget_hash->{budget_id} = AddBudget( $budget_hash );
255
        ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
258
        ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
259
        $budget_modified = 1;
260
    }
261
262
    my $set_owner_to_children = $input->param('set_owner_to_children');
263
    if ( $set_owner_to_children and $budget_modified ) {
264
        C4::Budgets::SetOwnerToFundHierarchy( $budget_hash->{budget_id}, $budget_hash->{budget_owner_id} );
256
    }
265
    }
257
    $op = 'list';
266
    $op = 'list';
258
}
267
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (+9 lines)
Lines 474-479 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
474
            onclick="ownerRemove(); return false;" />
474
            onclick="ownerRemove(); return false;" />
475
    </li>
475
    </li>
476
476
477
    [% IF budget_has_children %]
478
        <li>
479
            <span class="label">
480
                <label for="set_owner_to_children">Set this owner to all children funds:</label>
481
            </span>
482
            <input type="checkbox" id="set_owner_to_children" name="set_owner_to_children" value="1" />
483
        </li>
484
    [% END %]
485
477
    <li>
486
    <li>
478
        <span class="label">Users:</span>
487
        <span class="label">Users:</span>
479
        <ul style="float:left;" id="budget_users">
488
        <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