Lines 1-7
Link Here
|
1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
2 |
use Test::More tests => 25; |
2 |
use Test::More tests => 63; |
3 |
|
3 |
|
4 |
BEGIN {use_ok('C4::Budgets') } |
4 |
BEGIN { |
|
|
5 |
use_ok('C4::Budgets') |
6 |
} |
5 |
use C4::Context; |
7 |
use C4::Context; |
6 |
use C4::Biblio; |
8 |
use C4::Biblio; |
7 |
use C4::Bookseller; |
9 |
use C4::Bookseller; |
Lines 19-140
$dbh->do(q|DELETE FROM aqbudgets|);
Link Here
|
19 |
# |
21 |
# |
20 |
# Budget Periods : |
22 |
# Budget Periods : |
21 |
# |
23 |
# |
22 |
my $bpid; |
24 |
|
23 |
my $budgetperiod; |
25 |
is( AddBudgetPeriod(), undef, 'AddBugetPeriod without argument returns undef' ); |
24 |
my $active_period; |
26 |
is( AddBudgetPeriod( { } ), undef, 'AddBugetPeriod with an empty argument returns undef' ); |
25 |
my $mod_status; |
27 |
my $bpid = AddBudgetPeriod({ |
26 |
my $del_status; |
28 |
budget_period_startdate => '2008-01-01', |
27 |
ok($bpid=AddBudgetPeriod( |
29 |
}); |
28 |
{ budget_period_startdate => '2008-01-01' |
30 |
is( $bpid, undef, 'AddBugetPeriod without end date returns undef' ); |
29 |
, budget_period_enddate => '2008-12-31' |
31 |
$bpid = AddBudgetPeriod({ |
30 |
, budget_description => "MAPERI"}), |
32 |
budget_period_enddate => '2008-12-31', |
31 |
"AddBudgetPeriod with iso dates OK"); |
33 |
}); |
32 |
|
34 |
is( $bpid, undef, 'AddBugetPeriod without start date returns undef' ); |
33 |
ok($budgetperiod=GetBudgetPeriod($bpid), |
35 |
is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' ); |
34 |
"GetBudgetPeriod($bpid) returned ".Dump($budgetperiod)); |
36 |
my $budgetperiods = GetBudgetPeriods(); |
35 |
ok(!GetBudgetPeriod(0) ,"GetBudgetPeriod(0) returned undef : noactive BudgetPeriod"); |
37 |
is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' ); |
36 |
$$budgetperiod{budget_period_active}=1; |
38 |
|
37 |
ok($mod_status=ModBudgetPeriod($budgetperiod),"ModBudgetPeriod OK"); |
39 |
my $my_budgetperiod = { |
38 |
ok($active_period=GetBudgetPeriod(0),"GetBudgetPeriod(0) returned".Dump($active_period)); |
40 |
budget_period_startdate => '2008-01-01', |
39 |
ok(scalar(GetBudgetPeriods())>0,"GetBudgetPeriods OK");#Should at least return the Budget inserted |
41 |
budget_period_enddate => '2008-12-31', |
40 |
ok($del_status=DelBudgetPeriod($bpid),"DelBudgetPeriod returned $del_status"); |
42 |
budget_period_description => 'MAPERI', |
|
|
43 |
budget_period_active => 0, |
44 |
}; |
45 |
$bpid = AddBudgetPeriod($my_budgetperiod); |
46 |
isnt( $bpid, undef, 'AddBugetPeriod does not returns undef' ); |
47 |
my $budgetperiod = GetBudgetPeriod($bpid); |
48 |
is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'AddBudgetPeriod stores the start date correctly' ); |
49 |
is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'AddBudgetPeriod stores the end date correctly' ); |
50 |
is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'AddBudgetPeriod stores the description correctly' ); |
51 |
is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'AddBudgetPeriod stores active correctly' ); |
52 |
is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' ); |
53 |
|
54 |
|
55 |
$my_budgetperiod = { |
56 |
budget_period_startdate => '2009-01-01', |
57 |
budget_period_enddate => '2009-12-31', |
58 |
budget_period_description => 'MODIF_MAPERI', |
59 |
budget_period_active => 1, |
60 |
}; |
61 |
my $mod_status = ModBudgetPeriod($my_budgetperiod); |
62 |
is( $mod_status, undef, 'ModBudgetPeriod without id returns undef' ); |
63 |
|
64 |
$my_budgetperiod->{budget_period_id} = $bpid; |
65 |
$mod_status = ModBudgetPeriod($my_budgetperiod); |
66 |
is( $mod_status, 1, 'ModBudgetPeriod returnis true' ); |
67 |
$budgetperiod = GetBudgetPeriod($bpid); |
68 |
is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'ModBudgetPeriod updates the start date correctly' ); |
69 |
is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'ModBudgetPeriod updates the end date correctly' ); |
70 |
is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'ModBudgetPeriod updates the description correctly' ); |
71 |
is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'ModBudgetPeriod upates active correctly' ); |
72 |
isnt( GetBudgetPeriod(0), undef, 'GetBugetPeriods functions correctly' ); |
73 |
|
74 |
|
75 |
$budgetperiods = GetBudgetPeriods(); |
76 |
is( @$budgetperiods, 1, 'GetBudgetPeriods returns the correct number of budget periods' ); |
77 |
is( $budgetperiods->[0]->{budget_period_id}, $my_budgetperiod->{budget_period_id}, 'GetBudgetPeriods returns the id correctly' ); |
78 |
is( $budgetperiods->[0]->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'GetBudgetPeriods returns the start date correctly' ); |
79 |
is( $budgetperiods->[0]->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'GetBudgetPeriods returns the end date correctly' ); |
80 |
is( $budgetperiods->[0]->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'GetBudgetPeriods returns the description correctly' ); |
81 |
is( $budgetperiods->[0]->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'GetBudgetPeriods returns active correctly' ); |
82 |
|
83 |
is( DelBudgetPeriod($bpid), 1, 'DelBudgetPeriod returns true' ); |
84 |
$budgetperiods = GetBudgetPeriods(); |
85 |
is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' ); |
86 |
|
41 |
|
87 |
|
42 |
# |
88 |
# |
43 |
# Budget : |
89 |
# Budget : |
44 |
# |
90 |
# |
45 |
|
91 |
|
46 |
# Add A budget Period |
92 |
is( AddBudget(), undef, 'AddBuget without argument returns undef' ); |
47 |
if (C4::Context->preference('dateformat') eq "metric"){ |
93 |
my $budgets = GetBudgets(); |
48 |
ok($bpid=AddBudgetPeriod( |
94 |
is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' ); |
49 |
{ budget_period_startdate =>'01-01-2008' |
95 |
|
50 |
, budget_period_enddate =>'31-12-2008' |
96 |
$bpid = AddBudgetPeriod($my_budgetperiod); |
51 |
, budget_description =>"MAPERI"}), |
97 |
my $my_budget = { |
52 |
"AddBudgetPeriod returned $bpid"); |
98 |
budget_code => 'ABCD', |
53 |
} elsif (C4::Context->preference('dateformat') eq "us"){ |
99 |
budget_amount => '123.132000', |
54 |
ok($bpid=AddBudgetPeriod( |
100 |
budget_name => 'Periodiques', |
55 |
{ budget_period_startdate =>'01-01-2008' |
101 |
budget_notes => 'This is a note', |
56 |
, budget_period_enddate =>'12-31-2008' |
102 |
budget_period_id => $bpid, |
57 |
, budget_description =>"MAPERI"}), |
103 |
}; |
58 |
"AddBudgetPeriod returned $bpid"); |
104 |
my $budget_id = AddBudget($my_budget); |
59 |
} |
105 |
isnt( $budget_id, undef, 'AddBudget does not returns undef' ); |
60 |
else{ |
106 |
my $budget = GetBudget($budget_id); |
61 |
ok($bpid=AddBudgetPeriod( |
107 |
is( $budget->{budget_code}, $my_budget->{budget_code}, 'AddBudget stores the budget code correctly' ); |
62 |
{budget_period_startdate=>'2008-01-01' |
108 |
is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'AddBudget stores the budget amount correctly' ); |
63 |
,budget_period_enddate =>'2008-12-31' |
109 |
is( $budget->{budget_name}, $my_budget->{budget_name}, 'AddBudget stores the budget name correctly' ); |
64 |
,budget_description =>"MAPERI" |
110 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' ); |
65 |
}), |
111 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' ); |
66 |
"AddBudgetPeriod returned $bpid"); |
112 |
|
|
|
113 |
|
114 |
$my_budget = { |
115 |
budget_code => 'EFG', |
116 |
budget_amount => '321.231000', |
117 |
budget_name => 'Modified name', |
118 |
budget_notes => 'This is a modified note', |
119 |
budget_period_id => $bpid, |
120 |
}; |
121 |
$mod_status = ModBudget($my_budget); |
122 |
is( $mod_status, undef, 'ModBudget without id returns undef' ); |
123 |
|
124 |
$my_budget->{budget_id} = $budget_id; |
125 |
$mod_status = ModBudget($my_budget); |
126 |
is( $mod_status, 1, 'ModBudget returns true' ); |
127 |
$budget = GetBudget($budget_id); |
128 |
is( $budget->{budget_code}, $my_budget->{budget_code}, 'ModBudget updates the budget code correctly' ); |
129 |
is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'ModBudget updates the budget amount correctly' ); |
130 |
is( $budget->{budget_name}, $my_budget->{budget_name}, 'ModBudget updates the budget name correctly' ); |
131 |
is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' ); |
132 |
is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' ); |
133 |
|
134 |
|
135 |
$budgets = GetBudgets(); |
136 |
is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' ); |
137 |
is( $budgets->[0]->{budget_id}, $my_budget->{budget_id}, 'GetBudgets returns the budget id correctly' ); |
138 |
is( $budgets->[0]->{budget_code}, $my_budget->{budget_code}, 'GetBudgets returns the budget code correctly' ); |
139 |
is( $budgets->[0]->{budget_amount}, $my_budget->{budget_amount}, 'GetBudgets returns the budget amount correctly' ); |
140 |
is( $budgets->[0]->{budget_name}, $my_budget->{budget_name}, 'GetBudgets returns the budget name correctly' ); |
141 |
is( $budgets->[0]->{budget_notes}, $my_budget->{budget_notes}, 'GetBudgets returns the budget notes correctly' ); |
142 |
is( $budgets->[0]->{budget_period_id}, $my_budget->{budget_period_id}, 'GetBudgets returns the budget period id correctly' ); |
143 |
|
144 |
$budgets = GetBudgets( {budget_period_id => $bpid} ); |
145 |
is( @$budgets, 1, 'GetBudgets With Filter OK' ); |
146 |
$budgets = GetBudgets( {budget_period_id => $bpid}, {-asc => "budget_name"} ); |
147 |
is( @$budgets, 1, 'GetBudgets With Order OK' ); |
148 |
$budgets = GetBudgets( {budget_period_id => GetBudgetPeriod($bpid)->{budget_period_id}}, {-asc => "budget_name"} ); |
149 |
is( @$budgets, 1, 'GetBudgets With Order Getting Active budgetPeriod OK'); |
67 |
|
150 |
|
68 |
} |
|
|
69 |
my $budget_id; |
70 |
ok($budget_id=AddBudget( |
71 |
{ budget_code => "ABCD" |
72 |
, budget_amount => "123.132" |
73 |
, budget_name => "Périodiques" |
74 |
, budget_notes => "This is a note" |
75 |
, budget_description=> "Serials" |
76 |
, budget_active => 1 |
77 |
, budget_period_id => $bpid |
78 |
} |
79 |
), |
80 |
"AddBudget returned $budget_id"); |
81 |
#budget_code | varchar(30) | YES | | NULL | | |
82 |
#| budget_amount | decimal(28,6) | NO | | 0.000000 | | |
83 |
#| budget_id | int(11) | NO | PRI | NULL | | |
84 |
#| budget_branchcode | varchar(10) | YES | | NULL | | |
85 |
#| budget_parent_id | int(11) | YES | | NULL | | |
86 |
#| budget_name | varchar(80) | YES | | NULL | | |
87 |
#| budget_encumb | decimal(28,6) | YES | | 0.000000 | | |
88 |
#| budget_expend | decimal(28,6) | YES | | 0.000000 | | |
89 |
#| budget_notes | mediumtext | YES | | NULL | | |
90 |
#| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | | |
91 |
#| budget_period_id | int(11) | YES | MUL | NULL | | |
92 |
#| sort1_authcat | varchar(80) | YES | | NULL | | |
93 |
#| sort2_authcat | varchar(80) | YES | | NULL | | |
94 |
#| budget_owner_id | int(11) | YES | | NULL | | |
95 |
#| budget_permission | int(1) | YES | | 0 | | |
96 |
|
97 |
my $budget; |
98 |
ok($budget=GetBudget($budget_id) ,"GetBudget OK"); |
99 |
$budget_id = $budget->{budget_id}; |
100 |
$$budget{budget_permission}=1; |
101 |
ok($mod_status=ModBudget($budget),"ModBudget OK"); |
102 |
ok(GetBudgets()>0, |
103 |
"GetBudgets OK"); |
104 |
ok(GetBudgets({budget_period_id=>$bpid})>0, |
105 |
"GetBudgets With Filter OK"); |
106 |
ok(GetBudgets({budget_period_id=>$bpid},[{"budget_name"=>0}])>0, |
107 |
"GetBudgets With Order OK"); |
108 |
ok(GetBudgets({budget_period_id=>GetBudgetPeriod($bpid)->{budget_period_id}},[{"budget_name"=>0}])>0, |
109 |
"GetBudgets With Order |
110 |
Getting Active budgetPeriod OK"); |
111 |
|
151 |
|
112 |
my $budget_name = GetBudgetName( $budget_id ); |
152 |
my $budget_name = GetBudgetName( $budget_id ); |
113 |
is($budget_name, $budget->{budget_name}, "Test the GetBudgetName routine"); |
153 |
is($budget_name, $my_budget->{budget_name}, "Test the GetBudgetName routine"); |
114 |
|
154 |
|
115 |
my $budget_code = $budget->{budget_code}; |
155 |
my $budget_code = $my_budget->{budget_code}; |
116 |
my $budget_by_code = GetBudgetByCode( $budget_code ); |
156 |
my $budget_by_code = GetBudgetByCode( $budget_code ); |
117 |
is($budget_by_code->{budget_id}, $budget_id, "GetBudgetByCode, check id"); |
157 |
is($budget_by_code->{budget_id}, $budget_id, "GetBudgetByCode, check id"); |
118 |
is($budget_by_code->{budget_notes}, 'This is a note', "GetBudgetByCode, check notes"); |
158 |
is($budget_by_code->{budget_notes}, $my_budget->{budget_notes}, "GetBudgetByCode, check notes"); |
119 |
|
159 |
|
120 |
my $second_budget_id; |
160 |
my $second_budget_id = AddBudget({ |
121 |
ok($second_budget_id=AddBudget( |
161 |
budget_code => "ZZZZ", |
122 |
{ budget_code => "ZZZZ", |
162 |
budget_amount => "500.00", |
123 |
budget_amount => "500.00", |
163 |
budget_name => "Art", |
124 |
budget_name => "Art", |
164 |
budget_notes => "This is a note", |
125 |
budget_notes => "This is a note", |
165 |
budget_period_id => $bpid, |
126 |
budget_description=> "Art", |
166 |
}); |
127 |
budget_active => 1, |
167 |
isnt( $second_budget_id, undef, 'AddBudget does not returns undef' ); |
128 |
budget_period_id => $bpid, |
168 |
|
129 |
} |
169 |
$budgets = GetBudgets( {budget_period_id => $bpid} ); |
130 |
), |
170 |
ok( $budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name' ); |
131 |
"AddBudget returned $second_budget_id"); |
171 |
|
132 |
|
172 |
is( DelBudget($budget_id), 1, 'DelBudget returns true' ); |
133 |
my $budgets = GetBudgets({ budget_period_id => $bpid}); |
173 |
$budgets = GetBudgets(); |
134 |
ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name'); |
174 |
is( @$budgets, 1, 'GetBudgets returns the correct number of budget periods' ); |
135 |
|
175 |
|
136 |
ok($del_status=DelBudget($budget_id), |
|
|
137 |
"DelBudget returned $del_status"); |
138 |
|
176 |
|
139 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
177 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
140 |
my $budget_period_total = 10_000; |
178 |
my $budget_period_total = 10_000; |
Lines 146-163
my $budget_2_total = 2_000;
Link Here
|
146 |
|
184 |
|
147 |
my $budget_period_id = AddBudgetPeriod( |
185 |
my $budget_period_id = AddBudgetPeriod( |
148 |
{ |
186 |
{ |
149 |
budget_period_startdate => '2013-01-01', |
187 |
budget_period_startdate => '2013-01-01', |
150 |
budget_period_enddate => '2014-12-31', |
188 |
budget_period_enddate => '2014-12-31', |
151 |
budget_description => 'Budget Period', |
189 |
budget_period_description => 'Budget Period', |
152 |
budget_period_active => 1, |
190 |
budget_period_active => 1, |
153 |
budget_period_total => $budget_period_total, |
191 |
budget_period_total => $budget_period_total, |
154 |
} |
192 |
} |
155 |
); |
193 |
); |
156 |
my $budget_id1 = AddBudget( |
194 |
my $budget_id1 = AddBudget( |
157 |
{ |
195 |
{ |
158 |
budget_code => 'budget_1', |
196 |
budget_code => 'budget_1', |
159 |
budget_name => 'budget_1', |
197 |
budget_name => 'budget_1', |
160 |
budget_active => 1, |
|
|
161 |
budget_period_id => $budget_period_id, |
198 |
budget_period_id => $budget_period_id, |
162 |
budget_parent_id => undef, |
199 |
budget_parent_id => undef, |
163 |
budget_amount => $budget_1_total, |
200 |
budget_amount => $budget_1_total, |
Lines 167-173
my $budget_id2 = AddBudget(
Link Here
|
167 |
{ |
204 |
{ |
168 |
budget_code => 'budget_2', |
205 |
budget_code => 'budget_2', |
169 |
budget_name => 'budget_2', |
206 |
budget_name => 'budget_2', |
170 |
budget_active => 1, |
|
|
171 |
budget_period_id => $budget_period_id, |
207 |
budget_period_id => $budget_period_id, |
172 |
budget_parent_id => undef, |
208 |
budget_parent_id => undef, |
173 |
budget_amount => $budget_2_total, |
209 |
budget_amount => $budget_2_total, |
Lines 177-183
my $budget_id11 = AddBudget(
Link Here
|
177 |
{ |
213 |
{ |
178 |
budget_code => 'budget_11', |
214 |
budget_code => 'budget_11', |
179 |
budget_name => 'budget_11', |
215 |
budget_name => 'budget_11', |
180 |
budget_active => 1, |
|
|
181 |
budget_period_id => $budget_period_id, |
216 |
budget_period_id => $budget_period_id, |
182 |
budget_parent_id => $budget_id1, |
217 |
budget_parent_id => $budget_id1, |
183 |
budget_amount => $budget_11_total, |
218 |
budget_amount => $budget_11_total, |
Lines 187-193
my $budget_id12 = AddBudget(
Link Here
|
187 |
{ |
222 |
{ |
188 |
budget_code => 'budget_12', |
223 |
budget_code => 'budget_12', |
189 |
budget_name => 'budget_12', |
224 |
budget_name => 'budget_12', |
190 |
budget_active => 1, |
|
|
191 |
budget_period_id => $budget_period_id, |
225 |
budget_period_id => $budget_period_id, |
192 |
budget_parent_id => $budget_id1, |
226 |
budget_parent_id => $budget_id1, |
193 |
budget_amount => $budget_12_total, |
227 |
budget_amount => $budget_12_total, |
Lines 197-206
my $budget_id111 = AddBudget(
Link Here
|
197 |
{ |
231 |
{ |
198 |
budget_code => 'budget_111', |
232 |
budget_code => 'budget_111', |
199 |
budget_name => 'budget_111', |
233 |
budget_name => 'budget_111', |
200 |
budget_active => 1, |
|
|
201 |
budget_period_id => $budget_period_id, |
234 |
budget_period_id => $budget_period_id, |
202 |
budget_parent_id => $budget_id11, |
235 |
budget_parent_id => $budget_id11, |
203 |
owner_id => 1, |
236 |
budget_owner_id => 1, |
204 |
budget_amount => $budget_111_total, |
237 |
budget_amount => $budget_111_total, |
205 |
} |
238 |
} |
206 |
); |
239 |
); |
Lines 208-214
my $budget_id21 = AddBudget(
Link Here
|
208 |
{ |
241 |
{ |
209 |
budget_code => 'budget_21', |
242 |
budget_code => 'budget_21', |
210 |
budget_name => 'budget_21', |
243 |
budget_name => 'budget_21', |
211 |
budget_active => 1, |
|
|
212 |
budget_period_id => $budget_period_id, |
244 |
budget_period_id => $budget_period_id, |
213 |
budget_parent_id => $budget_id2, |
245 |
budget_parent_id => $budget_id2, |
214 |
} |
246 |
} |