2 use Test::More tests => 120;
12 use C4::Members qw( AddMember );
14 use Koha::Acquisition::Order;
17 my $dbh = C4::Context->dbh;
18 $dbh->{AutoCommit} = 0;
19 $dbh->{RaiseError} = 1;
21 $dbh->do(q|DELETE FROM aqbudgetperiods|);
22 $dbh->do(q|DELETE FROM aqbudgets|);
25 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
27 *C4::Context::userenv = \&Mock_userenv;
28 $userenv = { flags => 1, id => 'my_userid', branch => 'CPL' };
34 is( AddBudgetPeriod(), undef, 'AddBugetPeriod without argument returns undef' );
35 is( AddBudgetPeriod( { } ), undef, 'AddBugetPeriod with an empty argument returns undef' );
36 my $bpid = AddBudgetPeriod({
37 budget_period_startdate => '2008-01-01',
39 is( $bpid, undef, 'AddBugetPeriod without end date returns undef' );
40 $bpid = AddBudgetPeriod({
41 budget_period_enddate => '2008-12-31',
43 is( $bpid, undef, 'AddBugetPeriod without start date returns undef' );
44 is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' );
45 my $budgetperiods = GetBudgetPeriods();
46 is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' );
48 my $my_budgetperiod = {
49 budget_period_startdate => '2008-01-01',
50 budget_period_enddate => '2008-12-31',
51 budget_period_description => 'MAPERI',
52 budget_period_active => 0,
54 $bpid = AddBudgetPeriod($my_budgetperiod);
55 isnt( $bpid, undef, 'AddBugetPeriod does not returns undef' );
56 my $budgetperiod = GetBudgetPeriod($bpid);
57 is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'AddBudgetPeriod stores the start date correctly' );
58 is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'AddBudgetPeriod stores the end date correctly' );
59 is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'AddBudgetPeriod stores the description correctly' );
60 is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'AddBudgetPeriod stores active correctly' );
61 is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' );
65 budget_period_startdate => '2009-01-01',
66 budget_period_enddate => '2009-12-31',
67 budget_period_description => 'MODIF_MAPERI',
68 budget_period_active => 1,
70 my $mod_status = ModBudgetPeriod($my_budgetperiod);
71 is( $mod_status, undef, 'ModBudgetPeriod without id returns undef' );
73 $my_budgetperiod->{budget_period_id} = $bpid;
74 $mod_status = ModBudgetPeriod($my_budgetperiod);
75 is( $mod_status, 1, 'ModBudgetPeriod returnis true' );
76 $budgetperiod = GetBudgetPeriod($bpid);
77 is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'ModBudgetPeriod updates the start date correctly' );
78 is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'ModBudgetPeriod updates the end date correctly' );
79 is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'ModBudgetPeriod updates the description correctly' );
80 is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'ModBudgetPeriod upates active correctly' );
81 isnt( GetBudgetPeriod(0), undef, 'GetBugetPeriods functions correctly' );
84 $budgetperiods = GetBudgetPeriods();
85 is( @$budgetperiods, 1, 'GetBudgetPeriods returns the correct number of budget periods' );
86 is( $budgetperiods->[0]->{budget_period_id}, $my_budgetperiod->{budget_period_id}, 'GetBudgetPeriods returns the id correctly' );
87 is( $budgetperiods->[0]->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'GetBudgetPeriods returns the start date correctly' );
88 is( $budgetperiods->[0]->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'GetBudgetPeriods returns the end date correctly' );
89 is( $budgetperiods->[0]->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'GetBudgetPeriods returns the description correctly' );
90 is( $budgetperiods->[0]->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'GetBudgetPeriods returns active correctly' );
92 is( DelBudgetPeriod($bpid), 1, 'DelBudgetPeriod returns true' );
93 $budgetperiods = GetBudgetPeriods();
94 is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' );
101 # The budget hierarchy will be:
109 is( AddBudget(), undef, 'AddBuget without argument returns undef' );
110 my $budgets = GetBudgets();
111 is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' );
113 $bpid = AddBudgetPeriod($my_budgetperiod);
115 budget_code => 'ABCD',
116 budget_amount => '123.132000',
117 budget_name => 'Periodiques',
118 budget_notes => 'This is a note',
119 budget_period_id => $bpid,
121 my $budget_id = AddBudget($my_budget);
122 isnt( $budget_id, undef, 'AddBudget does not returns undef' );
123 my $budget = GetBudget($budget_id);
124 is( $budget->{budget_code}, $my_budget->{budget_code}, 'AddBudget stores the budget code correctly' );
125 is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'AddBudget stores the budget amount correctly' );
126 is( $budget->{budget_name}, $my_budget->{budget_name}, 'AddBudget stores the budget name correctly' );
127 is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' );
128 is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' );
132 budget_code => 'EFG',
133 budget_amount => '321.231000',
134 budget_name => 'Modified name',
135 budget_notes => 'This is a modified note',
136 budget_period_id => $bpid,
138 $mod_status = ModBudget($my_budget);
139 is( $mod_status, undef, 'ModBudget without id returns undef' );
141 $my_budget->{budget_id} = $budget_id;
142 $mod_status = ModBudget($my_budget);
143 is( $mod_status, 1, 'ModBudget returns true' );
144 $budget = GetBudget($budget_id);
145 is( $budget->{budget_code}, $my_budget->{budget_code}, 'ModBudget updates the budget code correctly' );
146 is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'ModBudget updates the budget amount correctly' );
147 is( $budget->{budget_name}, $my_budget->{budget_name}, 'ModBudget updates the budget name correctly' );
148 is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' );
149 is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' );
152 $budgets = GetBudgets();
153 is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' );
154 is( $budgets->[0]->{budget_id}, $my_budget->{budget_id}, 'GetBudgets returns the budget id correctly' );
155 is( $budgets->[0]->{budget_code}, $my_budget->{budget_code}, 'GetBudgets returns the budget code correctly' );
156 is( $budgets->[0]->{budget_amount}, $my_budget->{budget_amount}, 'GetBudgets returns the budget amount correctly' );
157 is( $budgets->[0]->{budget_name}, $my_budget->{budget_name}, 'GetBudgets returns the budget name correctly' );
158 is( $budgets->[0]->{budget_notes}, $my_budget->{budget_notes}, 'GetBudgets returns the budget notes correctly' );
159 is( $budgets->[0]->{budget_period_id}, $my_budget->{budget_period_id}, 'GetBudgets returns the budget period id correctly' );
161 $budgets = GetBudgets( {budget_period_id => $bpid} );
162 is( @$budgets, 1, 'GetBudgets With Filter OK' );
163 $budgets = GetBudgets( {budget_period_id => $bpid}, {-asc => "budget_name"} );
164 is( @$budgets, 1, 'GetBudgets With Order OK' );
165 $budgets = GetBudgets( {budget_period_id => GetBudgetPeriod($bpid)->{budget_period_id}}, {-asc => "budget_name"} );
166 is( @$budgets, 1, 'GetBudgets With Order Getting Active budgetPeriod OK');
169 my $budget_name = GetBudgetName( $budget_id );
170 is($budget_name, $my_budget->{budget_name}, "Test the GetBudgetName routine");
172 my $budget_code = $my_budget->{budget_code};
173 my $budget_by_code = GetBudgetByCode( $budget_code );
174 is($budget_by_code->{budget_id}, $budget_id, "GetBudgetByCode, check id");
175 is($budget_by_code->{budget_notes}, $my_budget->{budget_notes}, "GetBudgetByCode, check notes");
177 my $second_budget_id = AddBudget({
178 budget_code => "ZZZZ",
179 budget_amount => "500.00",
180 budget_name => "Art",
181 budget_notes => "This is a note",
182 budget_period_id => $bpid,
184 isnt( $second_budget_id, undef, 'AddBudget does not returns undef' );
186 $budgets = GetBudgets( {budget_period_id => $bpid} );
187 ok( $budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name' );
189 is( DelBudget($budget_id), 1, 'DelBudget returns true' );
190 $budgets = GetBudgets();
191 is( @$budgets, 1, 'GetBudgets returns the correct number of budget periods' );
194 # GetBudgetHierarchySpent and GetBudgetHierarchyOrdered
195 my $budget_period_total = 10_000;
196 my $budget_1_total = 1_000;
197 my $budget_11_total = 100;
198 my $budget_111_total = 50;
199 my $budget_12_total = 100;
200 my $budget_2_total = 2_000;
202 my $budget_period_id = AddBudgetPeriod(
204 budget_period_startdate => '2013-01-01',
205 budget_period_enddate => '2014-12-31',
206 budget_period_description => 'Budget Period',
207 budget_period_active => 1,
208 budget_period_total => $budget_period_total,
211 my $budget_id1 = AddBudget(
213 budget_code => 'budget_1',
214 budget_name => 'budget_1',
215 budget_period_id => $budget_period_id,
216 budget_parent_id => undef,
217 budget_amount => $budget_1_total,
220 my $budget_id2 = AddBudget(
222 budget_code => 'budget_2',
223 budget_name => 'budget_2',
224 budget_period_id => $budget_period_id,
225 budget_parent_id => undef,
226 budget_amount => $budget_2_total,
229 my $budget_id11 = AddBudget(
231 budget_code => 'budget_11',
232 budget_name => 'budget_11',
233 budget_period_id => $budget_period_id,
234 budget_parent_id => $budget_id1,
235 budget_amount => $budget_11_total,
238 my $budget_id12 = AddBudget(
240 budget_code => 'budget_12',
241 budget_name => 'budget_12',
242 budget_period_id => $budget_period_id,
243 budget_parent_id => $budget_id1,
244 budget_amount => $budget_12_total,
247 my $budget_id111 = AddBudget(
249 budget_code => 'budget_111',
250 budget_name => 'budget_111',
251 budget_period_id => $budget_period_id,
252 budget_parent_id => $budget_id11,
253 budget_owner_id => 1,
254 budget_amount => $budget_111_total,
257 my $budget_id21 = AddBudget(
259 budget_code => 'budget_21',
260 budget_name => 'budget_21',
261 budget_period_id => $budget_period_id,
262 budget_parent_id => $budget_id2,
266 my $booksellerid = C4::Bookseller::AddBookseller(
269 address1 => "bookseller's address",
276 my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 );
277 my ( $biblionumber, $biblioitemnumber ) =
278 C4::Biblio::AddBiblio( MARC::Record->new, '' );
282 budget_id => $budget_id1,
283 pending_quantity => 1,
287 budget_id => $budget_id2,
288 pending_quantity => 2,
292 budget_id => $budget_id11,
293 pending_quantity => 3,
297 budget_id => $budget_id12,
298 pending_quantity => 4,
302 budget_id => $budget_id111,
303 pending_quantity => 2,
307 # No order for budget_21
312 my $invoiceid = AddInvoice(invoicenumber => 'invoice_test_clone', booksellerid => $booksellerid, unknown => "unknown");
314 my $item_quantity = 2;
315 my $number_of_orders_to_move = 0;
316 for my $infos (@order_infos) {
317 for ( 1 .. $infos->{pending_quantity} ) {
318 my $order = Koha::Acquisition::Order->new(
320 basketno => $basketno,
321 biblionumber => $biblionumber,
322 budget_id => $infos->{budget_id},
323 order_internalnote => "internal note",
324 order_vendornote => "vendor note",
328 listprice => $item_price,
329 ecost => $item_price,
336 my $ordernumber = $order->{ordernumber};
337 push @{ $budgets{$infos->{budget_id}} }, $ordernumber;
338 $number_of_orders_to_move++;
340 for ( 1 .. $infos->{spent_quantity} ) {
341 my $order = Koha::Acquisition::Order->new(
343 basketno => $basketno,
344 biblionumber => $biblionumber,
345 budget_id => $infos->{budget_id},
346 order_internalnote => "internal note",
347 order_vendornote => "vendor note",
348 quantity => $item_quantity,
351 listprice => $item_price,
352 ecost => $item_price,
359 my $ordernumber = $order->{ordernumber};
361 biblionumber => $biblionumber,
362 ordernumber => $ordernumber,
363 budget_id => $infos->{budget_id},
364 quantityreceived => $item_quantity,
366 ecost => $item_price,
367 invoiceid => $invoiceid,
369 received_items => [],
373 is( GetBudgetHierarchySpent( $budget_id1 ), 160, "total spent for budget1 is 160" );
374 is( GetBudgetHierarchySpent( $budget_id11 ), 100, "total spent for budget11 is 100" );
375 is( GetBudgetHierarchySpent( $budget_id111 ), 20, "total spent for budget111 is 20" );
378 my $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
380 budget_period_id => $budget_period_id,
381 budget_period_startdate => '2014-01-01',
382 budget_period_enddate => '2014-12-31',
383 budget_period_description => 'Budget Period Cloned',
387 my $budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned);
388 is($budget_period_cloned->{budget_period_description}, 'Budget Period Cloned', 'Cloned budget\'s description is updated.');
390 my $budget_hierarchy = GetBudgetHierarchy($budget_period_id);
391 my $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
394 scalar(@$budget_hierarchy_cloned),
395 scalar(@$budget_hierarchy),
396 'CloneBudgetPeriod clones the same number of budgets (funds)'
399 _get_dependencies($budget_hierarchy),
400 _get_dependencies($budget_hierarchy_cloned),
401 'CloneBudgetPeriod keeps the same dependencies order'
404 # CloneBudgetPeriod with param mark_original_budget_as_inactive
405 my $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
406 is( $budget_period->{budget_period_active}, 1,
407 'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
410 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
411 my $number_of_budgets_not_reset = 0;
412 for my $budget (@$budget_hierarchy_cloned) {
413 $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
415 is( $number_of_budgets_not_reset, 5,
416 'CloneBudgetPeriod does not reset budgets (funds) if not needed' );
418 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
420 budget_period_id => $budget_period_id,
421 budget_period_startdate => '2014-01-01',
422 budget_period_enddate => '2014-12-31',
423 mark_original_budget_as_inactive => 1,
427 $budget_hierarchy = GetBudgetHierarchy($budget_period_id);
428 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
430 is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),
431 'CloneBudgetPeriod (with inactive param) clones the same number of budgets (funds)'
434 _get_dependencies($budget_hierarchy),
435 _get_dependencies($budget_hierarchy_cloned),
436 'CloneBudgetPeriod (with inactive param) keeps the same dependencies order'
438 $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
439 is( $budget_period->{budget_period_active}, 0,
440 'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
443 # CloneBudgetPeriod with param reset_all_budgets
444 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
446 budget_period_id => $budget_period_id,
447 budget_period_startdate => '2014-01-01',
448 budget_period_enddate => '2014-12-31',
449 reset_all_budgets => 1,
453 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
454 $number_of_budgets_not_reset = 0;
455 for my $budget (@$budget_hierarchy_cloned) {
456 $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
458 is( $number_of_budgets_not_reset, 0,
459 'CloneBudgetPeriod has reset all budgets (funds)' );
463 my $number_orders_moved = C4::Budgets::MoveOrders();
464 is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
465 $number_orders_moved =
466 C4::Budgets::MoveOrders( { from_budget_period_id => $budget_period_id } );
467 is( $number_orders_moved, undef,
468 'MoveOrders return undef if only 1 arg passed' );
469 $number_orders_moved =
470 C4::Budgets::MoveOrders( { to_budget_period_id => $budget_period_id } );
471 is( $number_orders_moved, undef,
472 'MoveOrders return undef if only 1 arg passed' );
473 $number_orders_moved = C4::Budgets::MoveOrders(
475 from_budget_period_id => $budget_period_id,
476 to_budget_period_id => $budget_period_id
479 is( $number_orders_moved, undef,
480 'MoveOrders return undef if 2 budget period id are the same' );
482 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
484 budget_period_id => $budget_period_id,
485 budget_period_startdate => '2014-01-01',
486 budget_period_enddate => '2014-12-31',
490 my $report = C4::Budgets::MoveOrders(
492 from_budget_period_id => $budget_period_id,
493 to_budget_period_id => $budget_period_id_cloned,
494 move_remaining_unspent => 1,
497 is( scalar( @$report ), 6 , "MoveOrders has processed 6 funds" );
499 my $number_of_orders_moved = 0;
500 $number_of_orders_moved += scalar( @{ $_->{orders_moved} } ) for @$report;
501 is( $number_of_orders_moved, $number_of_orders_to_move, "MoveOrders has moved $number_of_orders_to_move orders" );
503 my @new_budget_ids = map { $_->{budget_id} }
504 @{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) };
505 my @old_budget_ids = map { $_->{budget_id} }
506 @{ C4::Budgets::GetBudgetHierarchy($budget_period_id) };
507 for my $budget_id ( keys %budgets ) {
508 for my $ordernumber ( @{ $budgets{$budget_id} } ) {
509 my $budget = GetBudgetByOrderNumber($ordernumber);
510 my $is_in_new_budgets = grep /^$budget->{budget_id}$/, @new_budget_ids;
511 my $is_in_old_budgets = grep /^$budget->{budget_id}$/, @old_budget_ids;
512 is( $is_in_new_budgets, 1, "MoveOrders changed the budget_id for order $ordernumber" );
513 is( $is_in_old_budgets, 0, "MoveOrders changed the budget_id for order $ordernumber" );
518 # MoveOrders with param move_remaining_unspent
519 my @new_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) };
520 my @old_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id) };
522 for my $new_budget ( @new_budgets ) {
523 my ( $old_budget ) = map { $_->{budget_code} eq $new_budget->{budget_code} ? $_ : () } @old_budgets;
524 my $new_budget_amount_should_be = $old_budget->{budget_amount} * 2 - $old_budget->{total_spent};
525 is( $new_budget->{budget_amount} + 0, $new_budget_amount_should_be, "MoveOrders updated the budget amount with the previous unspent budget (for budget $new_budget->{budget_code})" );
528 # Test SetOwnerToFundHierarchy
530 my $categorycode = 'S';
531 my $branchcode = 'CPL';
532 my $john_doe = C4::Members::AddMember(
533 cardnumber => '123456',
536 categorycode => $categorycode,
537 branchcode => $branchcode,
539 dateexpiry => '9999-12-31',
543 C4::Budgets::SetOwnerToFundHierarchy( $budget_id1, $john_doe );
544 is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
545 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 1 ($budget_id1)" );
546 is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
547 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 11 ($budget_id11)" );
548 is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
549 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 111 ($budget_id111)" );
550 is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
551 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 12 ($budget_id12 )" );
552 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
553 undef, "SetOwnerToFundHierarchy should not have set an owner for budget 2 ($budget_id2)" );
554 is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
555 undef, "SetOwnerToFundHierarchy should not have set an owner for budget 21 ($budget_id21)" );
557 my $jane_doe = C4::Members::AddMember(
558 cardnumber => '789012',
561 categorycode => $categorycode,
562 branchcode => $branchcode,
564 dateexpiry => '9999-12-31',
568 C4::Budgets::SetOwnerToFundHierarchy( $budget_id11, $jane_doe );
569 is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
570 $john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 1 ($budget_id1)" );
571 is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
572 $jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 11 ($budget_id11)" );
573 is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
574 $jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 111 ($budget_id111)" );
575 is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
576 $john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 12 ($budget_id12 )" );
577 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
578 undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 2 ($budget_id2)" );
579 is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
580 undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
582 sub _get_dependencies {
583 my ($budget_hierarchy) = @_;
585 for my $budget (@$budget_hierarchy) {
586 if ( $budget->{child} ) {
587 my @sorted = sort @{ $budget->{child} };
588 for my $child_id (@sorted) {
589 push @{ $graph->{ $budget->{budget_name} }{children} },
590 _get_budgetname_by_id( $budget_hierarchy, $child_id );
593 push @{ $graph->{ $budget->{budget_name} }{parents} },
594 $budget->{parent_id};
599 sub _get_budgetname_by_id {
600 my ( $budgets, $budget_id ) = @_;
602 map { ( $_->{budget_id} eq $budget_id ) ? $_->{budget_name} : () }
607 # C4::Context->userenv