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

(-)a/C4/Budgets.pm (-3 / +16 lines)
Lines 993-1007 sub ConvertCurrency { Link Here
993
993
994
  my $new_budget_period_id = CloneBudgetPeriod({
994
  my $new_budget_period_id = CloneBudgetPeriod({
995
    budget_period_id => $budget_period_id,
995
    budget_period_id => $budget_period_id,
996
    budget_period_startdate => $budget_period_startdate;
996
    budget_period_startdate => $budget_period_startdate,
997
    budget_period_enddate   => $budget_period_enddate;
997
    budget_period_enddate   => $budget_period_enddate,
998
    mark_original_budget_as_inactive => 1
998
    mark_original_budget_as_inactive => 1n
999
    reset_all_budgets => 1,
999
  });
1000
  });
1000
1001
1001
Clone a budget period with all budgets.
1002
Clone a budget period with all budgets.
1002
If the mark_origin_budget_as_inactive is set (0 by default),
1003
If the mark_origin_budget_as_inactive is set (0 by default),
1003
the original budget will be marked as inactive.
1004
the original budget will be marked as inactive.
1004
1005
1006
If the reset_all_budgets is set (0 by default), all budget (fund)
1007
amounts will be reset.
1008
1005
=cut
1009
=cut
1006
1010
1007
sub CloneBudgetPeriod {
1011
sub CloneBudgetPeriod {
Lines 1011-1016 sub CloneBudgetPeriod { Link Here
1011
    my $budget_period_enddate   = $params->{budget_period_enddate};
1015
    my $budget_period_enddate   = $params->{budget_period_enddate};
1012
    my $mark_original_budget_as_inactive =
1016
    my $mark_original_budget_as_inactive =
1013
      $params->{mark_original_budget_as_inactive} || 0;
1017
      $params->{mark_original_budget_as_inactive} || 0;
1018
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
1014
1019
1015
    my $budget_period = GetBudgetPeriod($budget_period_id);
1020
    my $budget_period = GetBudgetPeriod($budget_period_id);
1016
1021
Lines 1037-1042 sub CloneBudgetPeriod { Link Here
1037
        );
1042
        );
1038
    }
1043
    }
1039
1044
1045
    if ( $reset_all_budgets ) {
1046
        my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
1047
        for my $budget ( @$budgets ) {
1048
            $budget->{budget_amount} = 0;
1049
            ModBudget( $budget );
1050
        }
1051
    }
1052
1040
    return $new_budget_period_id;
1053
    return $new_budget_period_id;
1041
}
1054
}
1042
1055
(-)a/admin/aqbudgetperiods.pl (+2 lines)
Lines 186-191 elsif ( $op eq 'duplicate_budget' ){ Link Here
186
    my $budget_period_startdate = $input->param('budget_period_startdate');
186
    my $budget_period_startdate = $input->param('budget_period_startdate');
187
    my $budget_period_enddate   = $input->param('budget_period_enddate');
187
    my $budget_period_enddate   = $input->param('budget_period_enddate');
188
    my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
188
    my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
189
    my $reset_all_budgets = $input->param('reset_all_budgets');
189
190
190
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
191
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
191
        {
192
        {
Lines 193-198 elsif ( $op eq 'duplicate_budget' ){ Link Here
193
            budget_period_startdate => $budget_period_startdate,
194
            budget_period_startdate => $budget_period_startdate,
194
            budget_period_enddate   => $budget_period_enddate,
195
            budget_period_enddate   => $budget_period_enddate,
195
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
196
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
197
            reset_all_budgets => $reset_all_budgets,
196
        }
198
        }
197
    );
199
    );
198
200
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt (+5 lines)
Lines 190-195 Link Here
190
      <input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
190
      <input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
191
    </li>
191
    </li>
192
192
193
    <li>
194
      <label for="reset_all_budgets">Set all funds to zero</label>
195
      <input type="checkbox" id="reset_all_budgets" name="reset_all_budgets" />
196
    </li>
197
193
    </ol>
198
    </ol>
194
    </fieldset>
199
    </fieldset>
195
200
(-)a/t/db_dependent/Budgets.t (-2 / +28 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 31;
2
use Test::More tests => 33;
3
3
4
BEGIN {use_ok('C4::Budgets') }
4
BEGIN {use_ok('C4::Budgets') }
5
use C4::Context;
5
use C4::Context;
Lines 350-355 is( $budget_period->{budget_period_active}, 1, Link Here
350
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
350
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
351
);
351
);
352
352
353
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
354
my $number_of_budgets_not_reset = 0;
355
for my $budget (@$budget_hierarchy_cloned) {
356
    $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
357
}
358
is( $number_of_budgets_not_reset, 5,
359
    'CloneBudgetPeriod does not reset budgets (funds) if not needed' );
360
353
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
361
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
354
    {
362
    {
355
        budget_period_id                 => $budget_period_id,
363
        budget_period_id                 => $budget_period_id,
Lines 375-380 is( $budget_period->{budget_period_active}, 0, Link Here
375
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
383
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
376
);
384
);
377
385
386
# CloneBudgetPeriod with param reset_all_budgets
387
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
388
    {
389
        budget_period_id        => $budget_period_id,
390
        budget_period_startdate => '2014-01-01',
391
        budget_period_enddate   => '2014-12-31',
392
        reset_all_budgets         => 1,
393
    }
394
);
395
396
$budget_hierarchy_cloned     = GetBudgetHierarchy($budget_period_id_cloned);
397
$number_of_budgets_not_reset = 0;
398
for my $budget (@$budget_hierarchy_cloned) {
399
    $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
400
}
401
is( $number_of_budgets_not_reset, 0,
402
    'CloneBudgetPeriod has reset all budgets (funds)' );
403
404
378
sub _get_dependencies {
405
sub _get_dependencies {
379
    my ($budget_hierarchy) = @_;
406
    my ($budget_hierarchy) = @_;
380
    my $graph;
407
    my $graph;
381
- 

Return to bug 12164