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

(-)a/C4/Budgets.pm (+29 lines)
Lines 45-50 BEGIN { Link Here
45
        &GetBudgetName
45
        &GetBudgetName
46
        &GetPeriodsCount
46
        &GetPeriodsCount
47
        &GetChildBudgetsSpent
47
        &GetChildBudgetsSpent
48
        &GetChildBudgetsOrdered
48
49
49
        &GetBudgetUsers
50
        &GetBudgetUsers
50
        &ModBudgetUsers
51
        &ModBudgetUsers
Lines 724-729 sub GetChildBudgetsSpent { Link Here
724
    return $total_spent;
725
    return $total_spent;
725
}
726
}
726
727
728
=head2 GetChildBudgetsOrdered
729
730
  &GetChildBudgetsOrdered($budget_id);
731
732
gets the total ordered of the level and sublevels of $budget_id
733
734
=cut
735
736
# -------------------------------------------------------------------
737
sub GetChildBudgetsOrdered {
738
    my ( $budget_id ) = @_;
739
    my $dbh = C4::Context->dbh;
740
    my $query = "
741
        SELECT *
742
        FROM   aqbudgets
743
        WHERE  budget_parent_id=?
744
        ";
745
    my $sth = $dbh->prepare($query);
746
    $sth->execute( $budget_id );
747
    my $result = $sth->fetchall_arrayref({});
748
    my $total_spent = GetBudgetOrdered($budget_id);
749
    if ($result){
750
        $total_spent += GetChildBudgetsOrdered($_->{"budget_id"}) foreach @$result;
751
    }
752
    return $total_spent;
753
}
754
755
727
=head2 GetBudgets
756
=head2 GetBudgets
728
757
729
  &GetBudgets($filter, $order_by);
758
  &GetBudgets($filter, $order_by);
(-)a/admin/aqbudgets.pl (-2 / +3 lines)
Lines 283-288 if ($op eq 'add_form') { Link Here
283
    foreach my $budget (@budgets) {
283
    foreach my $budget (@budgets) {
284
        #Level and sublevels total spent
284
        #Level and sublevels total spent
285
        $budget->{'total_levels_spent'} = GetChildBudgetsSpent($budget->{"budget_id"});
285
        $budget->{'total_levels_spent'} = GetChildBudgetsSpent($budget->{"budget_id"});
286
        $budget->{'total_levels_ordered'} = GetChildBudgetsOrdered($budget->{"budget_id"});
286
287
287
        # PERMISSIONS
288
        # PERMISSIONS
288
        unless(CanUserModifyBudget($borrowernumber, $budget, $staffflags)) {
289
        unless(CanUserModifyBudget($borrowernumber, $budget, $staffflags)) {
Lines 303-309 if ($op eq 'add_form') { Link Here
303
        # adds to total  - only if budget is a 'top-level' budget
304
        # adds to total  - only if budget is a 'top-level' budget
304
        $period_alloc_total += $budget->{'budget_amount_total'} if $budget->{'depth'} == 0;
305
        $period_alloc_total += $budget->{'budget_amount_total'} if $budget->{'depth'} == 0;
305
        $base_spent_total += $budget->{'budget_spent'};
306
        $base_spent_total += $budget->{'budget_spent'};
306
        $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'total_levels_spent'};
307
        $budget->{'budget_remaining'} = $budget->{'budget_amount'} - $budget->{'total_levels_spent'} - $budget->{'total_levels_ordered'};
307
308
308
# if amount == 0 dont display...
309
# if amount == 0 dont display...
309
        delete $budget->{'budget_unalloc_sublevel'}
310
        delete $budget->{'budget_unalloc_sublevel'}
Lines 312-318 if ($op eq 'add_form') { Link Here
312
313
313
        $budget->{'remaining_pos'} = 1 if $budget->{'budget_remaining'} > 0;
314
        $budget->{'remaining_pos'} = 1 if $budget->{'budget_remaining'} > 0;
314
        $budget->{'remaining_neg'} = 1 if $budget->{'budget_remaining'} < 0;
315
        $budget->{'remaining_neg'} = 1 if $budget->{'budget_remaining'} < 0;
315
		for (grep {/total_levels_spent|budget_spent|budget_amount|budget_remaining|budget_unalloc/} keys %$budget){
316
        for (grep {/total_levels_spent|budget_spent|budget_amount|budget_remaining|budget_unalloc|total_levels_ordered/} keys %$budget){
316
            $budget->{$_}               = $num->format_price( $budget->{$_} ) if defined($budget->{$_})
317
            $budget->{$_}               = $num->format_price( $budget->{$_} ) if defined($budget->{$_})
317
		}
318
		}
318
319
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt (+2 lines)
Lines 247-252 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
247
            <th>Base-level<br />allocated</th>
247
            <th>Base-level<br />allocated</th>
248
            <th>Base-level<br />spent</th>
248
            <th>Base-level<br />spent</th>
249
            <th>Total sublevels<br />spent</th>
249
            <th>Total sublevels<br />spent</th>
250
            <th>Total sublevels<br />ordered</th>
250
            <th>Base-level<br />remaining</th>
251
            <th>Base-level<br />remaining</th>
251
            <th class="tooltipcontent">&nbsp;</th>
252
            <th class="tooltipcontent">&nbsp;</th>
252
            <th>Actions</th>
253
            <th>Actions</th>
Lines 278-283 var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") Link Here
278
    <td class="data">[% budge.budget_amount %] </td>
279
    <td class="data">[% budge.budget_amount %] </td>
279
    <td class="data">[% budge.budget_spent %] </td>
280
    <td class="data">[% budge.budget_spent %] </td>
280
    <td class="data">[% budge.total_levels_spent %]</td>
281
    <td class="data">[% budge.total_levels_spent %]</td>
282
    <td class="data">[% budge.total_levels_ordered %]</td>
281
    [% IF ( budge.remaining_pos ) %]
283
    [% IF ( budge.remaining_pos ) %]
282
        <td class="data" style="color: green;">
284
        <td class="data" style="color: green;">
283
    [% ELSIF ( budge.remaining_neg ) %] 
285
    [% ELSIF ( budge.remaining_neg ) %] 
(-)a/t/db_dependent/Acquisition.t (-2 / +3 lines)
Lines 8-14 use POSIX qw(strftime); Link Here
8
8
9
use C4::Bookseller qw( GetBookSellerFromId );
9
use C4::Bookseller qw( GetBookSellerFromId );
10
10
11
use Test::More tests => 62;
11
use Test::More tests => 63;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Acquisition');
14
    use_ok('C4::Acquisition');
Lines 92-97 ok( exists( @$orders[0]->{basketgroupname} ), "SearchOrder: The basketgroupname Link Here
92
92
93
ok( GetBudgetByOrderNumber($ordernumber1)->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" );
93
ok( GetBudgetByOrderNumber($ordernumber1)->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" );
94
94
95
ok(GetChildBudgetsOrdered($budgetid) eq '168', "GetChildBudgetsOrdered returns the cost of all ordered acquisitions for the budget and all sub-budgets.");
96
95
C4::Acquisition::CloseBasket( $basketno );
97
C4::Acquisition::CloseBasket( $basketno );
96
my @lateorders = GetLateOrders(0);
98
my @lateorders = GetLateOrders(0);
97
my $order = $lateorders[0];
99
my $order = $lateorders[0];
98
- 

Return to bug 11823