2 use Test::More tests => 120;
12 use C4::Members qw( AddMember );
14 use Koha::Acquisition::Order;
18 my $dbh = C4::Context->dbh;
19 my $database = Koha::Database->new();
20 my $schema = $database->schema();
21 $schema->storage->txn_begin();
22 $dbh->{RaiseError} = 1;
24 $dbh->do(q|DELETE FROM aqbudgetperiods|);
25 $dbh->do(q|DELETE FROM aqbudgets|);
28 local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
30 *C4::Context::userenv = \&Mock_userenv;
31 $userenv = { flags => 1, id => 'my_userid', branch => 'CPL' };
37 is( AddBudgetPeriod(), undef, 'AddBugetPeriod without argument returns undef' );
38 is( AddBudgetPeriod( { } ), undef, 'AddBugetPeriod with an empty argument returns undef' );
39 my $bpid = AddBudgetPeriod({
40 budget_period_startdate => '2008-01-01',
42 is( $bpid, undef, 'AddBugetPeriod without end date returns undef' );
43 $bpid = AddBudgetPeriod({
44 budget_period_enddate => '2008-12-31',
46 is( $bpid, undef, 'AddBugetPeriod without start date returns undef' );
47 is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' );
48 my $budgetperiods = GetBudgetPeriods();
49 is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' );
51 my $my_budgetperiod = {
52 budget_period_startdate => '2008-01-01',
53 budget_period_enddate => '2008-12-31',
54 budget_period_description => 'MAPERI',
55 budget_period_active => 0,
57 $bpid = AddBudgetPeriod($my_budgetperiod);
58 isnt( $bpid, undef, 'AddBugetPeriod does not returns undef' );
59 my $budgetperiod = GetBudgetPeriod($bpid);
60 is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'AddBudgetPeriod stores the start date correctly' );
61 is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'AddBudgetPeriod stores the end date correctly' );
62 is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'AddBudgetPeriod stores the description correctly' );
63 is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'AddBudgetPeriod stores active correctly' );
64 is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' );
68 budget_period_startdate => '2009-01-01',
69 budget_period_enddate => '2009-12-31',
70 budget_period_description => 'MODIF_MAPERI',
71 budget_period_active => 1,
73 my $mod_status = ModBudgetPeriod($my_budgetperiod);
74 is( $mod_status, undef, 'ModBudgetPeriod without id returns undef' );
76 $my_budgetperiod->{budget_period_id} = $bpid;
77 $mod_status = ModBudgetPeriod($my_budgetperiod);
78 is( $mod_status, 1, 'ModBudgetPeriod returnis true' );
79 $budgetperiod = GetBudgetPeriod($bpid);
80 is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'ModBudgetPeriod updates the start date correctly' );
81 is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'ModBudgetPeriod updates the end date correctly' );
82 is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'ModBudgetPeriod updates the description correctly' );
83 is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'ModBudgetPeriod upates active correctly' );
84 isnt( GetBudgetPeriod(0), undef, 'GetBugetPeriods functions correctly' );
87 $budgetperiods = GetBudgetPeriods();
88 is( @$budgetperiods, 1, 'GetBudgetPeriods returns the correct number of budget periods' );
89 is( $budgetperiods->[0]->{budget_period_id}, $my_budgetperiod->{budget_period_id}, 'GetBudgetPeriods returns the id correctly' );
90 is( $budgetperiods->[0]->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'GetBudgetPeriods returns the start date correctly' );
91 is( $budgetperiods->[0]->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'GetBudgetPeriods returns the end date correctly' );
92 is( $budgetperiods->[0]->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'GetBudgetPeriods returns the description correctly' );
93 is( $budgetperiods->[0]->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'GetBudgetPeriods returns active correctly' );
95 is( DelBudgetPeriod($bpid), 1, 'DelBudgetPeriod returns true' );
96 $budgetperiods = GetBudgetPeriods();
97 is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' );
104 # The budget hierarchy will be:
112 is( AddBudget(), undef, 'AddBuget without argument returns undef' );
113 my $budgets = GetBudgets();
114 is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' );
116 $bpid = AddBudgetPeriod($my_budgetperiod);
118 budget_code => 'ABCD',
119 budget_amount => '123.132000',
120 budget_name => 'Periodiques',
121 budget_notes => 'This is a note',
122 budget_period_id => $bpid,
124 my $budget_id = AddBudget($my_budget);
125 isnt( $budget_id, undef, 'AddBudget does not returns undef' );
126 my $budget = GetBudget($budget_id);
127 is( $budget->{budget_code}, $my_budget->{budget_code}, 'AddBudget stores the budget code correctly' );
128 is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'AddBudget stores the budget amount correctly' );
129 is( $budget->{budget_name}, $my_budget->{budget_name}, 'AddBudget stores the budget name correctly' );
130 is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' );
131 is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' );
135 budget_code => 'EFG',
136 budget_amount => '321.231000',
137 budget_name => 'Modified name',
138 budget_notes => 'This is a modified note',
139 budget_period_id => $bpid,
141 $mod_status = ModBudget($my_budget);
142 is( $mod_status, undef, 'ModBudget without id returns undef' );
144 $my_budget->{budget_id} = $budget_id;
145 $mod_status = ModBudget($my_budget);
146 is( $mod_status, 1, 'ModBudget returns true' );
147 $budget = GetBudget($budget_id);
148 is( $budget->{budget_code}, $my_budget->{budget_code}, 'ModBudget updates the budget code correctly' );
149 is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'ModBudget updates the budget amount correctly' );
150 is( $budget->{budget_name}, $my_budget->{budget_name}, 'ModBudget updates the budget name correctly' );
151 is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' );
152 is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' );
155 $budgets = GetBudgets();
156 is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' );
157 is( $budgets->[0]->{budget_id}, $my_budget->{budget_id}, 'GetBudgets returns the budget id correctly' );
158 is( $budgets->[0]->{budget_code}, $my_budget->{budget_code}, 'GetBudgets returns the budget code correctly' );
159 is( $budgets->[0]->{budget_amount}, $my_budget->{budget_amount}, 'GetBudgets returns the budget amount correctly' );
160 is( $budgets->[0]->{budget_name}, $my_budget->{budget_name}, 'GetBudgets returns the budget name correctly' );
161 is( $budgets->[0]->{budget_notes}, $my_budget->{budget_notes}, 'GetBudgets returns the budget notes correctly' );
162 is( $budgets->[0]->{budget_period_id}, $my_budget->{budget_period_id}, 'GetBudgets returns the budget period id correctly' );
164 $budgets = GetBudgets( {budget_period_id => $bpid} );
165 is( @$budgets, 1, 'GetBudgets With Filter OK' );
166 $budgets = GetBudgets( {budget_period_id => $bpid}, {-asc => "budget_name"} );
167 is( @$budgets, 1, 'GetBudgets With Order OK' );
168 $budgets = GetBudgets( {budget_period_id => GetBudgetPeriod($bpid)->{budget_period_id}}, {-asc => "budget_name"} );
169 is( @$budgets, 1, 'GetBudgets With Order Getting Active budgetPeriod OK');
172 my $budget_name = GetBudgetName( $budget_id );
173 is($budget_name, $my_budget->{budget_name}, "Test the GetBudgetName routine");
175 my $budget_code = $my_budget->{budget_code};
176 my $budget_by_code = GetBudgetByCode( $budget_code );
177 is($budget_by_code->{budget_id}, $budget_id, "GetBudgetByCode, check id");
178 is($budget_by_code->{budget_notes}, $my_budget->{budget_notes}, "GetBudgetByCode, check notes");
180 my $second_budget_id = AddBudget({
181 budget_code => "ZZZZ",
182 budget_amount => "500.00",
183 budget_name => "Art",
184 budget_notes => "This is a note",
185 budget_period_id => $bpid,
187 isnt( $second_budget_id, undef, 'AddBudget does not returns undef' );
189 $budgets = GetBudgets( {budget_period_id => $bpid} );
190 ok( $budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name' );
192 is( DelBudget($budget_id), 1, 'DelBudget returns true' );
193 $budgets = GetBudgets();
194 is( @$budgets, 1, 'GetBudgets returns the correct number of budget periods' );
197 # GetBudgetHierarchySpent and GetBudgetHierarchyOrdered
198 my $budget_period_total = 10_000;
199 my $budget_1_total = 1_000;
200 my $budget_11_total = 100;
201 my $budget_111_total = 50;
202 my $budget_12_total = 100;
203 my $budget_2_total = 2_000;
205 my $budget_period_id = AddBudgetPeriod(
207 budget_period_startdate => '2013-01-01',
208 budget_period_enddate => '2014-12-31',
209 budget_period_description => 'Budget Period',
210 budget_period_active => 1,
211 budget_period_total => $budget_period_total,
214 my $budget_id1 = AddBudget(
216 budget_code => 'budget_1',
217 budget_name => 'budget_1',
218 budget_period_id => $budget_period_id,
219 budget_parent_id => undef,
220 budget_amount => $budget_1_total,
223 my $budget_id2 = AddBudget(
225 budget_code => 'budget_2',
226 budget_name => 'budget_2',
227 budget_period_id => $budget_period_id,
228 budget_parent_id => undef,
229 budget_amount => $budget_2_total,
232 my $budget_id11 = AddBudget(
234 budget_code => 'budget_11',
235 budget_name => 'budget_11',
236 budget_period_id => $budget_period_id,
237 budget_parent_id => $budget_id1,
238 budget_amount => $budget_11_total,
241 my $budget_id12 = AddBudget(
243 budget_code => 'budget_12',
244 budget_name => 'budget_12',
245 budget_period_id => $budget_period_id,
246 budget_parent_id => $budget_id1,
247 budget_amount => $budget_12_total,
250 my $budget_id111 = AddBudget(
252 budget_code => 'budget_111',
253 budget_name => 'budget_111',
254 budget_period_id => $budget_period_id,
255 budget_parent_id => $budget_id11,
256 budget_owner_id => 1,
257 budget_amount => $budget_111_total,
260 my $budget_id21 = AddBudget(
262 budget_code => 'budget_21',
263 budget_name => 'budget_21',
264 budget_period_id => $budget_period_id,
265 budget_parent_id => $budget_id2,
269 my $booksellerid = C4::Bookseller::AddBookseller(
272 address1 => "bookseller's address",
279 my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 );
280 my ( $biblionumber, $biblioitemnumber ) =
281 C4::Biblio::AddBiblio( MARC::Record->new, '' );
285 budget_id => $budget_id1,
286 pending_quantity => 1,
290 budget_id => $budget_id2,
291 pending_quantity => 2,
295 budget_id => $budget_id11,
296 pending_quantity => 3,
300 budget_id => $budget_id12,
301 pending_quantity => 4,
305 budget_id => $budget_id111,
306 pending_quantity => 2,
310 # No order for budget_21
315 my $invoiceid = AddInvoice(invoicenumber => 'invoice_test_clone', booksellerid => $booksellerid, unknown => "unknown");
317 my $item_quantity = 2;
318 my $number_of_orders_to_move = 0;
319 for my $infos (@order_infos) {
320 for ( 1 .. $infos->{pending_quantity} ) {
321 my $order = Koha::Acquisition::Order->new(
323 basketno => $basketno,
324 biblionumber => $biblionumber,
325 budget_id => $infos->{budget_id},
326 order_internalnote => "internal note",
327 order_vendornote => "vendor note",
331 listprice => $item_price,
332 ecost => $item_price,
339 my $ordernumber = $order->{ordernumber};
340 push @{ $budgets{$infos->{budget_id}} }, $ordernumber;
341 $number_of_orders_to_move++;
343 for ( 1 .. $infos->{spent_quantity} ) {
344 my $order = Koha::Acquisition::Order->new(
346 basketno => $basketno,
347 biblionumber => $biblionumber,
348 budget_id => $infos->{budget_id},
349 order_internalnote => "internal note",
350 order_vendornote => "vendor note",
351 quantity => $item_quantity,
354 listprice => $item_price,
355 ecost => $item_price,
362 my $ordernumber = $order->{ordernumber};
364 biblionumber => $biblionumber,
365 ordernumber => $ordernumber,
366 budget_id => $infos->{budget_id},
367 quantityreceived => $item_quantity,
369 ecost => $item_price,
370 invoiceid => $invoiceid,
372 received_items => [],
376 is( GetBudgetHierarchySpent( $budget_id1 ), 160, "total spent for budget1 is 160" );
377 is( GetBudgetHierarchySpent( $budget_id11 ), 100, "total spent for budget11 is 100" );
378 is( GetBudgetHierarchySpent( $budget_id111 ), 20, "total spent for budget111 is 20" );
381 my $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
383 budget_period_id => $budget_period_id,
384 budget_period_startdate => '2014-01-01',
385 budget_period_enddate => '2014-12-31',
386 budget_period_description => 'Budget Period Cloned',
390 my $budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned);
391 is($budget_period_cloned->{budget_period_description}, 'Budget Period Cloned', 'Cloned budget\'s description is updated.');
393 my $budget_hierarchy = GetBudgetHierarchy($budget_period_id);
394 my $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
397 scalar(@$budget_hierarchy_cloned),
398 scalar(@$budget_hierarchy),
399 'CloneBudgetPeriod clones the same number of budgets (funds)'
402 _get_dependencies($budget_hierarchy),
403 _get_dependencies($budget_hierarchy_cloned),
404 'CloneBudgetPeriod keeps the same dependencies order'
407 # CloneBudgetPeriod with param mark_original_budget_as_inactive
408 my $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
409 is( $budget_period->{budget_period_active}, 1,
410 'CloneBudgetPeriod does not mark as inactive the budgetperiod if not needed'
413 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
414 my $number_of_budgets_not_reset = 0;
415 for my $budget (@$budget_hierarchy_cloned) {
416 $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
418 is( $number_of_budgets_not_reset, 5,
419 'CloneBudgetPeriod does not reset budgets (funds) if not needed' );
421 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
423 budget_period_id => $budget_period_id,
424 budget_period_startdate => '2014-01-01',
425 budget_period_enddate => '2014-12-31',
426 mark_original_budget_as_inactive => 1,
430 $budget_hierarchy = GetBudgetHierarchy($budget_period_id);
431 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
433 is( scalar(@$budget_hierarchy_cloned), scalar(@$budget_hierarchy),
434 'CloneBudgetPeriod (with inactive param) clones the same number of budgets (funds)'
437 _get_dependencies($budget_hierarchy),
438 _get_dependencies($budget_hierarchy_cloned),
439 'CloneBudgetPeriod (with inactive param) keeps the same dependencies order'
441 $budget_period = C4::Budgets::GetBudgetPeriod($budget_period_id);
442 is( $budget_period->{budget_period_active}, 0,
443 'CloneBudgetPeriod (with inactive param) marks as inactive the budgetperiod'
446 # CloneBudgetPeriod with param reset_all_budgets
447 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
449 budget_period_id => $budget_period_id,
450 budget_period_startdate => '2014-01-01',
451 budget_period_enddate => '2014-12-31',
452 reset_all_budgets => 1,
456 $budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
457 $number_of_budgets_not_reset = 0;
458 for my $budget (@$budget_hierarchy_cloned) {
459 $number_of_budgets_not_reset++ if $budget->{budget_amount} > 0;
461 is( $number_of_budgets_not_reset, 0,
462 'CloneBudgetPeriod has reset all budgets (funds)' );
466 my $number_orders_moved = C4::Budgets::MoveOrders();
467 is( $number_orders_moved, undef, 'MoveOrders return undef if no arg passed' );
468 $number_orders_moved =
469 C4::Budgets::MoveOrders( { from_budget_period_id => $budget_period_id } );
470 is( $number_orders_moved, undef,
471 'MoveOrders return undef if only 1 arg passed' );
472 $number_orders_moved =
473 C4::Budgets::MoveOrders( { to_budget_period_id => $budget_period_id } );
474 is( $number_orders_moved, undef,
475 'MoveOrders return undef if only 1 arg passed' );
476 $number_orders_moved = C4::Budgets::MoveOrders(
478 from_budget_period_id => $budget_period_id,
479 to_budget_period_id => $budget_period_id
482 is( $number_orders_moved, undef,
483 'MoveOrders return undef if 2 budget period id are the same' );
485 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
487 budget_period_id => $budget_period_id,
488 budget_period_startdate => '2014-01-01',
489 budget_period_enddate => '2014-12-31',
493 my $report = C4::Budgets::MoveOrders(
495 from_budget_period_id => $budget_period_id,
496 to_budget_period_id => $budget_period_id_cloned,
497 move_remaining_unspent => 1,
500 is( scalar( @$report ), 6 , "MoveOrders has processed 6 funds" );
502 my $number_of_orders_moved = 0;
503 $number_of_orders_moved += scalar( @{ $_->{orders_moved} } ) for @$report;
504 is( $number_of_orders_moved, $number_of_orders_to_move, "MoveOrders has moved $number_of_orders_to_move orders" );
506 my @new_budget_ids = map { $_->{budget_id} }
507 @{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) };
508 my @old_budget_ids = map { $_->{budget_id} }
509 @{ C4::Budgets::GetBudgetHierarchy($budget_period_id) };
510 for my $budget_id ( keys %budgets ) {
511 for my $ordernumber ( @{ $budgets{$budget_id} } ) {
512 my $budget = GetBudgetByOrderNumber($ordernumber);
513 my $is_in_new_budgets = grep /^$budget->{budget_id}$/, @new_budget_ids;
514 my $is_in_old_budgets = grep /^$budget->{budget_id}$/, @old_budget_ids;
515 is( $is_in_new_budgets, 1, "MoveOrders changed the budget_id for order $ordernumber" );
516 is( $is_in_old_budgets, 0, "MoveOrders changed the budget_id for order $ordernumber" );
521 # MoveOrders with param move_remaining_unspent
522 my @new_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id_cloned) };
523 my @old_budgets = @{ C4::Budgets::GetBudgetHierarchy($budget_period_id) };
525 for my $new_budget ( @new_budgets ) {
526 my ( $old_budget ) = map { $_->{budget_code} eq $new_budget->{budget_code} ? $_ : () } @old_budgets;
527 my $new_budget_amount_should_be = $old_budget->{budget_amount} * 2 - $old_budget->{total_spent};
528 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})" );
531 # Test SetOwnerToFundHierarchy
533 my $categorycode = 'S';
534 my $branchcode = 'CPL';
535 my $john_doe = C4::Members::AddMember(
536 cardnumber => '123456',
539 categorycode => $categorycode,
540 branchcode => $branchcode,
542 dateexpiry => '9999-12-31',
546 C4::Budgets::SetOwnerToFundHierarchy( $budget_id1, $john_doe );
547 is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
548 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 1 ($budget_id1)" );
549 is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
550 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 11 ($budget_id11)" );
551 is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
552 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 111 ($budget_id111)" );
553 is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
554 $john_doe, "SetOwnerToFundHierarchy should have set John Doe for budget 12 ($budget_id12 )" );
555 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
556 undef, "SetOwnerToFundHierarchy should not have set an owner for budget 2 ($budget_id2)" );
557 is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
558 undef, "SetOwnerToFundHierarchy should not have set an owner for budget 21 ($budget_id21)" );
560 my $jane_doe = C4::Members::AddMember(
561 cardnumber => '789012',
564 categorycode => $categorycode,
565 branchcode => $branchcode,
567 dateexpiry => '9999-12-31',
571 C4::Budgets::SetOwnerToFundHierarchy( $budget_id11, $jane_doe );
572 is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id},
573 $john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 1 ($budget_id1)" );
574 is( C4::Budgets::GetBudget($budget_id11)->{budget_owner_id},
575 $jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 11 ($budget_id11)" );
576 is( C4::Budgets::GetBudget($budget_id111)->{budget_owner_id},
577 $jane_doe, "SetOwnerToFundHierarchy should have set John Doe $jane_doe for budget 111 ($budget_id111)" );
578 is( C4::Budgets::GetBudget($budget_id12)->{budget_owner_id},
579 $john_doe, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 12 ($budget_id12 )" );
580 is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id},
581 undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 2 ($budget_id2)" );
582 is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
583 undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
585 $schema->storage->txn_rollback();
587 sub _get_dependencies {
588 my ($budget_hierarchy) = @_;
590 for my $budget (@$budget_hierarchy) {
591 if ( $budget->{child} ) {
592 my @sorted = sort @{ $budget->{child} };
593 for my $child_id (@sorted) {
594 push @{ $graph->{ $budget->{budget_name} }{children} },
595 _get_budgetname_by_id( $budget_hierarchy, $child_id );
598 push @{ $graph->{ $budget->{budget_name} }{parents} },
599 $budget->{parent_id};
604 sub _get_budgetname_by_id {
605 my ( $budgets, $budget_id ) = @_;
607 map { ( $_->{budget_id} eq $budget_id ) ? $_->{budget_name} : () }
612 # C4::Context->userenv