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

(-)a/C4/Budgets.pm (-2 / +20 lines)
Lines 986-995 sub ConvertCurrency { Link Here
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
  });
991
  });
991
992
992
Clone a budget period with all budgets.
993
Clone a budget period with all budgets.
994
If the mark_origin_budget_as_inactive is set (0 by default),
995
the original budget will be marked as inactive.
993
996
994
=cut
997
=cut
995
998
Lines 998-1003 sub CloneBudgetPeriod { Link Here
998
    my $budget_period_id        = $params->{budget_period_id};
1001
    my $budget_period_id        = $params->{budget_period_id};
999
    my $budget_period_startdate = $params->{budget_period_startdate};
1002
    my $budget_period_startdate = $params->{budget_period_startdate};
1000
    my $budget_period_enddate   = $params->{budget_period_enddate};
1003
    my $budget_period_enddate   = $params->{budget_period_enddate};
1004
    my $mark_original_budget_as_inactive =
1005
      $params->{mark_original_budget_as_inactive} || 0;
1001
1006
1002
    my $budget_period = GetBudgetPeriod($budget_period_id);
1007
    my $budget_period = GetBudgetPeriod($budget_period_id);
1003
1008
Lines 1009-1016 sub CloneBudgetPeriod { Link Here
1009
1014
1010
    my $budgets = GetBudgetHierarchy($budget_period_id);
1015
    my $budgets = GetBudgetHierarchy($budget_period_id);
1011
    CloneBudgetHierarchy(
1016
    CloneBudgetHierarchy(
1012
        { budgets => $budgets, new_budget_period_id => $new_budget_period_id }
1017
        {
1018
            budgets              => $budgets,
1019
            new_budget_period_id => $new_budget_period_id
1020
        }
1013
    );
1021
    );
1022
1023
    if ($mark_original_budget_as_inactive) {
1024
        ModBudgetPeriod(
1025
            {
1026
                budget_period_id     => $budget_period_id,
1027
                budget_period_active => 0,
1028
            }
1029
        );
1030
    }
1031
1014
    return $new_budget_period_id;
1032
    return $new_budget_period_id;
1015
}
1033
}
1016
1034
(-)a/admin/aqbudgetperiods.pl (+2 lines)
Lines 185-196 elsif ( $op eq 'duplicate_budget' ){ Link Here
185
185
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
189
189
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
190
    my $new_budget_period_id = C4::Budgets::CloneBudgetPeriod(
190
        {
191
        {
191
            budget_period_id        => $budget_period_id,
192
            budget_period_id        => $budget_period_id,
192
            budget_period_startdate => $budget_period_startdate,
193
            budget_period_startdate => $budget_period_startdate,
193
            budget_period_enddate   => $budget_period_enddate,
194
            budget_period_enddate   => $budget_period_enddate,
195
            mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
194
        }
196
        }
195
    );
197
    );
196
198
(-)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 => 25;
2
use Test::More tests => 29;
3
3
4
BEGIN {use_ok('C4::Budgets') }
4
BEGIN {use_ok('C4::Budgets') }
5
use C4::Biblio;
5
use C4::Biblio;
Lines 336-342 is( Link Here
336
is_deeply(
336
is_deeply(
337
    _get_dependencies($budget_hierarchy),
337
    _get_dependencies($budget_hierarchy),
338
    _get_dependencies($budget_hierarchy_cloned),
338
    _get_dependencies($budget_hierarchy_cloned),
339
    'CloneBudgetPeriod keep the same dependencies order'
339
    'CloneBudgetPeriod keeps the same dependencies order'
340
);
341
342
# CloneBudgetPeriod with param mark_original_budget_as_inactive
343
my $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
344
is( $budget_period->{budget_period_active}, 1,
345
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
346
);
347
348
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
349
    {
350
        budget_period_id                 => $budget_period_id,
351
        budget_period_startdate          => '2014-01-01',
352
        budget_period_enddate            => '2014-12-31',
353
        mark_original_budget_as_inactive => 1,
354
    }
355
);
356
357
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
358
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
359
360
is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),
361
'CloneBudgetPeriod (with inactive param) clones the same number of budgets (funds)'
362
);
363
is_deeply(
364
    _get_dependencies($budget_hierarchy),
365
    _get_dependencies($budget_hierarchy_cloned),
366
    'CloneBudgetPeriod (with inactive param) keeps the same dependencies order'
367
);
368
$budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
369
is( $budget_period->{budget_period_active}, 0,
370
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
340
);
371
);
341
372
342
sub _get_dependencies {
373
sub _get_dependencies {
343
- 

Return to bug 12164