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

(-)a/C4/Budgets.pm (-2 / +20 lines)
Lines 1014-1023 sub ConvertCurrency { Link Here
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
  });
1019
  });
1019
1020
1020
Clone a budget period with all budgets.
1021
Clone a budget period with all budgets.
1022
If the mark_origin_budget_as_inactive is set (0 by default),
1023
the original budget will be marked as inactive.
1021
1024
1022
=cut
1025
=cut
1023
1026
Lines 1026-1031 sub CloneBudgetPeriod { Link Here
1026
    my $budget_period_id        = $params->{budget_period_id};
1029
    my $budget_period_id        = $params->{budget_period_id};
1027
    my $budget_period_startdate = $params->{budget_period_startdate};
1030
    my $budget_period_startdate = $params->{budget_period_startdate};
1028
    my $budget_period_enddate   = $params->{budget_period_enddate};
1031
    my $budget_period_enddate   = $params->{budget_period_enddate};
1032
    my $mark_original_budget_as_inactive =
1033
      $params->{mark_original_budget_as_inactive} || 0;
1029
1034
1030
    my $budget_period = GetBudgetPeriod($budget_period_id);
1035
    my $budget_period = GetBudgetPeriod($budget_period_id);
1031
1036
Lines 1037-1044 sub CloneBudgetPeriod { Link Here
1037
1042
1038
    my $budgets = GetBudgetHierarchy($budget_period_id);
1043
    my $budgets = GetBudgetHierarchy($budget_period_id);
1039
    CloneBudgetHierarchy(
1044
    CloneBudgetHierarchy(
1040
        { budgets => $budgets, new_budget_period_id => $new_budget_period_id }
1045
        {
1046
            budgets              => $budgets,
1047
            new_budget_period_id => $new_budget_period_id
1048
        }
1041
    );
1049
    );
1050
1051
    if ($mark_original_budget_as_inactive) {
1052
        ModBudgetPeriod(
1053
            {
1054
                budget_period_id     => $budget_period_id,
1055
                budget_period_active => 0,
1056
            }
1057
        );
1058
    }
1059
1042
    return $new_budget_period_id;
1060
    return $new_budget_period_id;
1043
}
1061
}
1044
1062
(-)a/admin/aqbudgetperiods.pl (+2 lines)
Lines 188-199 elsif ( $op eq 'duplicate_budget' ){ Link Here
188
188
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
192
192
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
193
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
193
        {
194
        {
194
            budget_period_id        => $budget_period_id,
195
            budget_period_id        => $budget_period_id,
195
            budget_period_startdate => $budget_period_startdate,
196
            budget_period_startdate => $budget_period_startdate,
196
            budget_period_enddate   => $budget_period_enddate,
197
            budget_period_enddate   => $budget_period_enddate,
198
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
197
        }
199
        }
198
    );
200
    );
199
201
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt (+5 lines)
Lines 185-190 Link Here
185
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
185
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
186
    </li>
186
    </li>
187
187
188
    <li>
189
      <label for="mark_as_inactive">Mark the original budget as inactive</label>
190
      <input type="checkbox" id="mark_as_inactive" name="mark_original_budget_as_inactive" />
191
    </li>
192
188
    </ol>
193
    </ol>
189
    </fieldset>
194
    </fieldset>
190
195
(-)a/t/db_dependent/Budgets.t (-3 / +33 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 65;
2
use Test::More tests => 69;
3
3
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
Lines 373-379 is( Link Here
373
is_deeply(
373
is_deeply(
374
    _get_dependencies($budget_hierarchy),
374
    _get_dependencies($budget_hierarchy),
375
    _get_dependencies($budget_hierarchy_cloned),
375
    _get_dependencies($budget_hierarchy_cloned),
376
    'CloneBudgetPeriod keep the same dependencies order'
376
    'CloneBudgetPeriod keeps the same dependencies order'
377
);
378
379
# CloneBudgetPeriod with param mark_original_budget_as_inactive
380
my $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
381
is( $budget_period->{budget_period_active}, 1,
382
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
383
);
384
385
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
386
    {
387
        budget_period_id                 => $budget_period_id,
388
        budget_period_startdate          => '2014-01-01',
389
        budget_period_enddate            => '2014-12-31',
390
        mark_original_budget_as_inactive => 1,
391
    }
392
);
393
394
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
395
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
396
397
is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),
398
'CloneBudgetPeriod (with inactive param) clones the same number of budgets (funds)'
399
);
400
is_deeply(
401
    _get_dependencies($budget_hierarchy),
402
    _get_dependencies($budget_hierarchy_cloned),
403
    'CloneBudgetPeriod (with inactive param) keeps the same dependencies order'
404
);
405
$budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
406
is( $budget_period->{budget_period_active}, 0,
407
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
377
);
408
);
378
409
379
sub _get_dependencies {
410
sub _get_dependencies {
380
- 

Return to bug 12164