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

(-)a/C4/Budgets.pm (-21 / +7 lines)
Lines 446-472 sub GetBudgetPeriods { Link Here
446
sub GetBudgetPeriod {
446
sub GetBudgetPeriod {
447
	my ($budget_period_id) = @_;
447
	my ($budget_period_id) = @_;
448
	my $dbh = C4::Context->dbh;
448
	my $dbh = C4::Context->dbh;
449
	## $total = number of records linked to the record that must be deleted
449
	my $sth = $dbh->prepare( qq|
450
	my $total = 0;
450
        SELECT      *
451
	## get information about the record that will be deleted
451
        FROM aqbudgetperiods
452
	my $sth;
452
        WHERE budget_period_id=? |
453
	if ($budget_period_id) {
453
	);
454
		$sth = $dbh->prepare( qq|
454
	$sth->execute($budget_period_id);
455
              SELECT      *
455
	return $sth->fetchrow_hashref;
456
                FROM aqbudgetperiods
457
                WHERE budget_period_id=? |
458
		);
459
		$sth->execute($budget_period_id);
460
	} else {         # ACTIVE BUDGET
461
		$sth = $dbh->prepare(qq|
462
			  SELECT      *
463
                FROM aqbudgetperiods
464
                WHERE budget_period_active=1 |
465
		);
466
		$sth->execute();
467
	}
468
	my $data = $sth->fetchrow_hashref;
469
	return $data;
470
}
456
}
471
457
472
# -------------------------------------------------------------------
458
# -------------------------------------------------------------------
(-)a/t/db_dependent/Budgets.t (-5 / +19 lines)
Lines 7-12 use C4::Dates; Link Here
7
7
8
use YAML;
8
use YAML;
9
9
10
# Start transaction
11
my $dbh = C4::Context->dbh;
12
$dbh->{AutoCommit} = 0;
13
$dbh->{RaiseError} = 1;
14
10
#
15
#
11
# Budget Periods :
16
# Budget Periods :
12
#
17
#
Lines 15-20 my $budgetperiod; Link Here
15
my $active_period;
20
my $active_period;
16
my $mod_status;
21
my $mod_status;
17
my $del_status;
22
my $del_status;
23
24
25
my $orig_num_active = count_active_budget_periods();
18
ok($bpid=AddBudgetPeriod(
26
ok($bpid=AddBudgetPeriod(
19
						{ budget_period_startdate	=> '2008-01-01'
27
						{ budget_period_startdate	=> '2008-01-01'
20
						, budget_period_enddate		=> '2008-12-31'
28
						, budget_period_enddate		=> '2008-12-31'
Lines 23-33 ok($bpid=AddBudgetPeriod( Link Here
23
31
24
ok($budgetperiod=GetBudgetPeriod($bpid),
32
ok($budgetperiod=GetBudgetPeriod($bpid),
25
	"GetBudgetPeriod($bpid) returned ".Dump($budgetperiod));
33
	"GetBudgetPeriod($bpid) returned ".Dump($budgetperiod));
26
ok(!GetBudgetPeriod(0) ,"GetBudgetPeriod(0) returned undef : noactive BudgetPeriod");
34
my $num_active = count_active_budget_periods();
27
$$budgetperiod{budget_period_active}=1;
35
ok($num_active == $orig_num_active, 'new budget is in inactive by default');
36
$budgetperiod->{budget_period_active}=1;
28
ok($mod_status=ModBudgetPeriod($budgetperiod),"ModBudgetPeriod OK");
37
ok($mod_status=ModBudgetPeriod($budgetperiod),"ModBudgetPeriod OK");
29
ok($active_period=GetBudgetPeriod(0),"GetBudgetPeriod(0) returned".Dump($active_period));
38
$num_active = count_active_budget_periods();
30
ok(scalar(GetBudgetPeriods())>0,"GetBudgetPeriods OK");#Should at least return the Budget inserted
39
ok($num_active == ($orig_num_active + 1), 'making new budget active increased the number of active budgets by 1');
40
ok(scalar(@{ GetBudgetPeriods() }) > 0,"GetBudgetPeriods OK");#Should at least return the Budget inserted
31
ok($del_status=DelBudgetPeriod($bpid),"DelBudgetPeriod returned $del_status");
41
ok($del_status=DelBudgetPeriod($bpid),"DelBudgetPeriod returned $del_status");
32
42
33
#
43
#
Lines 104-106 is($budget_name, $budget->{budget_name}, "Test the GetBudgetName routine"); Link Here
104
114
105
ok($del_status=DelBudget($budget_id),
115
ok($del_status=DelBudget($budget_id),
106
    "DelBudget returned $del_status");
116
    "DelBudget returned $del_status");
107
- 
117
118
sub count_active_budget_periods {
119
    my $budget_periods = GetBudgetPeriods({budget_period_active => 1});
120
    return scalar(@$budget_periods);
121
}

Return to bug 10577