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

(-)a/C4/Budgets.pm (-2 / +20 lines)
Lines 994-1003 sub ConvertCurrency { Link Here
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
  });
999
  });
999
1000
1000
Clone a budget period with all budgets.
1001
Clone a budget period with all budgets.
1002
If the mark_origin_budget_as_inactive is set (0 by default),
1003
the original budget will be marked as inactive.
1001
1004
1002
=cut
1005
=cut
1003
1006
Lines 1006-1011 sub CloneBudgetPeriod { Link Here
1006
    my $budget_period_id        = $params->{budget_period_id};
1009
    my $budget_period_id        = $params->{budget_period_id};
1007
    my $budget_period_startdate = $params->{budget_period_startdate};
1010
    my $budget_period_startdate = $params->{budget_period_startdate};
1008
    my $budget_period_enddate   = $params->{budget_period_enddate};
1011
    my $budget_period_enddate   = $params->{budget_period_enddate};
1012
    my $mark_original_budget_as_inactive =
1013
      $params->{mark_original_budget_as_inactive} || 0;
1009
1014
1010
    my $budget_period = GetBudgetPeriod($budget_period_id);
1015
    my $budget_period = GetBudgetPeriod($budget_period_id);
1011
1016
Lines 1017-1024 sub CloneBudgetPeriod { Link Here
1017
1022
1018
    my $budgets = GetBudgetHierarchy($budget_period_id);
1023
    my $budgets = GetBudgetHierarchy($budget_period_id);
1019
    CloneBudgetHierarchy(
1024
    CloneBudgetHierarchy(
1020
        { budgets => $budgets, new_budget_period_id => $new_budget_period_id }
1025
        {
1026
            budgets              => $budgets,
1027
            new_budget_period_id => $new_budget_period_id
1028
        }
1021
    );
1029
    );
1030
1031
    if ($mark_original_budget_as_inactive) {
1032
        ModBudgetPeriod(
1033
            {
1034
                budget_period_id     => $budget_period_id,
1035
                budget_period_active => 0,
1036
            }
1037
        );
1038
    }
1039
1022
    return $new_budget_period_id;
1040
    return $new_budget_period_id;
1023
}
1041
}
1024
1042
(-)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 => 27;
2
use Test::More tests => 31;
3
3
4
BEGIN {use_ok('C4::Budgets') }
4
BEGIN {use_ok('C4::Budgets') }
5
use C4::Context;
5
use C4::Context;
Lines 341-347 is( Link Here
341
is_deeply(
341
is_deeply(
342
    _get_dependencies($budget_hierarchy),
342
    _get_dependencies($budget_hierarchy),
343
    _get_dependencies($budget_hierarchy_cloned),
343
    _get_dependencies($budget_hierarchy_cloned),
344
    'CloneBudgetPeriod keep the same dependencies order'
344
    'CloneBudgetPeriod keeps the same dependencies order'
345
);
346
347
# CloneBudgetPeriod with param mark_original_budget_as_inactive
348
my $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
349
is( $budget_period->{budget_period_active}, 1,
350
    'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
351
);
352
353
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
354
    {
355
        budget_period_id                 => $budget_period_id,
356
        budget_period_startdate          => '2014-01-01',
357
        budget_period_enddate            => '2014-12-31',
358
        mark_original_budget_as_inactive => 1,
359
    }
360
);
361
362
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
363
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
364
365
is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),
366
'CloneBudgetPeriod (with inactive param) clones the same number of budgets (funds)'
367
);
368
is_deeply(
369
    _get_dependencies($budget_hierarchy),
370
    _get_dependencies($budget_hierarchy_cloned),
371
    'CloneBudgetPeriod (with inactive param) keeps the same dependencies order'
372
);
373
$budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
374
is( $budget_period->{budget_period_active}, 0,
375
    'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
345
);
376
);
346
377
347
sub _get_dependencies {
378
sub _get_dependencies {
348
- 

Return to bug 12164