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

(-)a/C4/Budgets.pm (-3 / +16 lines)
Lines 985-999 sub ConvertCurrency { Link Here
985
985
986
  my $new_budget_period_id = CloneBudgetPeriod({
986
  my $new_budget_period_id = CloneBudgetPeriod({
987
    budget_period_id => $budget_period_id,
987
    budget_period_id => $budget_period_id,
988
    budget_period_startdate => $budget_period_startdate;
988
    budget_period_startdate => $budget_period_startdate,
989
    budget_period_enddate   => $budget_period_enddate;
989
    budget_period_enddate   => $budget_period_enddate,
990
    mark_original_budget_as_inactive => 1
990
    mark_original_budget_as_inactive => 1n
991
    reset_all_budgets => 1,
991
  });
992
  });
992
993
993
Clone a budget period with all budgets.
994
Clone a budget period with all budgets.
994
If the mark_origin_budget_as_inactive is set (0 by default),
995
If the mark_origin_budget_as_inactive is set (0 by default),
995
the original budget will be marked as inactive.
996
the original budget will be marked as inactive.
996
997
998
If the reset_all_budgets is set (0 by default), all budget (fund)
999
amounts will be reset.
1000
997
=cut
1001
=cut
998
1002
999
sub CloneBudgetPeriod {
1003
sub CloneBudgetPeriod {
Lines 1003-1008 sub CloneBudgetPeriod { Link Here
1003
    my $budget_period_enddate   = $params->{budget_period_enddate};
1007
    my $budget_period_enddate   = $params->{budget_period_enddate};
1004
    my $mark_original_budget_as_inactive =
1008
    my $mark_original_budget_as_inactive =
1005
      $params->{mark_original_budget_as_inactive} || 0;
1009
      $params->{mark_original_budget_as_inactive} || 0;
1010
    my $reset_all_budgets = $params->{reset_all_budgets} || 0;
1006
1011
1007
    my $budget_period = GetBudgetPeriod($budget_period_id);
1012
    my $budget_period = GetBudgetPeriod($budget_period_id);
1008
1013
Lines 1029-1034 sub CloneBudgetPeriod { Link Here
1029
        );
1034
        );
1030
    }
1035
    }
1031
1036
1037
    if ( $reset_all_budgets ) {
1038
        my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
1039
        for my $budget ( @$budgets ) {
1040
            $budget->{budget_amount} = 0;
1041
            ModBudget( $budget );
1042
        }
1043
    }
1044
1032
    return $new_budget_period_id;
1045
    return $new_budget_period_id;
1033
}
1046
}
1034
1047
(-)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 => 29;
2
use Test::More tests => 31;
3
3
4
BEGIN {use_ok('C4::Budgets') }
4
BEGIN {use_ok('C4::Budgets') }
5
use C4::Biblio;
5
use C4::Biblio;
Lines 345-350 is( $budget_period->{budget_period_active}, 1, Link Here
345
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
345
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
346
);
346
);
347
347
348
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
349
my $number_of_budgets_not_reset = 0;
350
for my $budget (@$budget_hierarchy_cloned) {
351
    $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
352
}
353
is( $number_of_budgets_not_reset, 5,
354
    'CloneBudgetPeriod does not reset budgets (funds) if not needed' );
355
348
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
356
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
349
    {
357
    {
350
        budget_period_id                 => $budget_period_id,
358
        budget_period_id                 => $budget_period_id,
Lines 370-375 is( $budget_period->{budget_period_active}, 0, Link Here
370
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
378
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
371
);
379
);
372
380
381
# CloneBudgetPeriod with param reset_all_budgets
382
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
383
    {
384
        budget_period_id        => $budget_period_id,
385
        budget_period_startdate => '2014-01-01',
386
        budget_period_enddate   => '2014-12-31',
387
        reset_all_budgets         => 1,
388
    }
389
);
390
391
$budget_hierarchy_cloned     = GetBudgetHierarchy($budget_period_id_cloned);
392
$number_of_budgets_not_reset = 0;
393
for my $budget (@$budget_hierarchy_cloned) {
394
    $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
395
}
396
is( $number_of_budgets_not_reset, 0,
397
    'CloneBudgetPeriod has reset all budgets (funds)' );
398
399
373
sub _get_dependencies {
400
sub _get_dependencies {
374
    my ($budget_hierarchy) = @_;
401
    my ($budget_hierarchy) = @_;
375
    my $graph;
402
    my $graph;
376
- 

Return to bug 12164