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

(-)a/C4/Budgets.pm (-3 / +16 lines)
Lines 1013-1027 sub ConvertCurrency { Link Here
1013
1013
1014
  my $new_budget_period_id = CloneBudgetPeriod({
1014
  my $new_budget_period_id = CloneBudgetPeriod({
1015
    budget_period_id => $budget_period_id,
1015
    budget_period_id => $budget_period_id,
1016
    budget_period_startdate => $budget_period_startdate;
1016
    budget_period_startdate => $budget_period_startdate,
1017
    budget_period_enddate   => $budget_period_enddate;
1017
    budget_period_enddate   => $budget_period_enddate,
1018
    mark_original_budget_as_inactive => 1
1018
    mark_original_budget_as_inactive => 1n
1019
    reset_all_budgets => 1,
1019
  });
1020
  });
1020
1021
1021
Clone a budget period with all budgets.
1022
Clone a budget period with all budgets.
1022
If the mark_origin_budget_as_inactive is set (0 by default),
1023
If the mark_origin_budget_as_inactive is set (0 by default),
1023
the original budget will be marked as inactive.
1024
the original budget will be marked as inactive.
1024
1025
1026
If the reset_all_budgets is set (0 by default), all budget (fund)
1027
amounts will be reset.
1028
1025
=cut
1029
=cut
1026
1030
1027
sub CloneBudgetPeriod {
1031
sub CloneBudgetPeriod {
Lines 1031-1036 sub CloneBudgetPeriod { Link Here
1031
    my $budget_period_enddate   = $params->{budget_period_enddate};
1035
    my $budget_period_enddate   = $params->{budget_period_enddate};
1032
    my $mark_original_budget_as_inactive =
1036
    my $mark_original_budget_as_inactive =
1033
      $params->{mark_original_budget_as_inactive} || 0;
1037
      $params->{mark_original_budget_as_inactive} || 0;
1038
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
1034
1039
1035
    my $budget_period = GetBudgetPeriod($budget_period_id);
1040
    my $budget_period = GetBudgetPeriod($budget_period_id);
1036
1041
Lines 1057-1062 sub CloneBudgetPeriod { Link Here
1057
        );
1062
        );
1058
    }
1063
    }
1059
1064
1065
    if ( $reset_all_budgets ) {
1066
        my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
1067
        for my $budget ( @$budgets ) {
1068
            $budget->{budget_amount} = 0;
1069
            ModBudget( $budget );
1070
        }
1071
    }
1072
1060
    return $new_budget_period_id;
1073
    return $new_budget_period_id;
1061
}
1074
}
1062
1075
(-)a/admin/aqbudgetperiods.pl (+2 lines)
Lines 189-194 elsif ( $op eq 'duplicate_budget' ){ Link Here
189
    my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
189
    my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
190
    my $budget_period_enddate   = dt_from_string $input->param('budget_period_enddate');
190
    my $budget_period_enddate   = dt_from_string $input->param('budget_period_enddate');
191
    my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
191
    my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
192
    my $reset_all_budgets = $input->param('reset_all_budgets');
192
193
193
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
194
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
194
        {
195
        {
Lines 196-201 elsif ( $op eq 'duplicate_budget' ){ Link Here
196
            budget_period_startdate => $budget_period_startdate,
197
            budget_period_startdate => $budget_period_startdate,
197
            budget_period_enddate   => $budget_period_enddate,
198
            budget_period_enddate   => $budget_period_enddate,
198
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
199
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
200
            reset_all_budgets => $reset_all_budgets,
199
        }
201
        }
200
    );
202
    );
201
203
(-)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 => 69;
2
use Test::More tests => 71;
3
3
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
Lines 382-387 is( $budget_period->{budget_period_active}, 1, Link Here
382
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
382
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
383
);
383
);
384
384
385
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
386
my $number_of_budgets_not_reset = 0;
387
for my $budget (@$budget_hierarchy_cloned) {
388
    $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
389
}
390
is( $number_of_budgets_not_reset, 5,
391
    'CloneBudgetPeriod does not reset budgets (funds) if not needed' );
392
385
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
393
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
386
    {
394
    {
387
        budget_period_id                 => $budget_period_id,
395
        budget_period_id                 => $budget_period_id,
Lines 407-412 is( $budget_period->{budget_period_active}, 0, Link Here
407
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
415
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
408
);
416
);
409
417
418
# CloneBudgetPeriod with param reset_all_budgets
419
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
420
    {
421
        budget_period_id        => $budget_period_id,
422
        budget_period_startdate => '2014-01-01',
423
        budget_period_enddate   => '2014-12-31',
424
        reset_all_budgets         => 1,
425
    }
426
);
427
428
$budget_hierarchy_cloned     = GetBudgetHierarchy($budget_period_id_cloned);
429
$number_of_budgets_not_reset = 0;
430
for my $budget (@$budget_hierarchy_cloned) {
431
    $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
432
}
433
is( $number_of_budgets_not_reset, 0,
434
    'CloneBudgetPeriod has reset all budgets (funds)' );
435
436
410
sub _get_dependencies {
437
sub _get_dependencies {
411
    my ($budget_hierarchy) = @_;
438
    my ($budget_hierarchy) = @_;
412
    my $graph;
439
    my $graph;
413
- 

Return to bug 12164