+#!/usr/bin/perl
use Modern::Perl;
-use Test::More tests => 120;
+use Test::More tests => 137;
BEGIN {
use_ok('C4::Budgets')
budget_amount => $budget_2_total,
}
);
-my $budget_id11 = AddBudget(
+my $budget_id12 = AddBudget(
{
- budget_code => 'budget_11',
- budget_name => 'budget_11',
+ budget_code => 'budget_12',
+ budget_name => 'budget_12',
budget_period_id => $budget_period_id,
budget_parent_id => $budget_id1,
- budget_amount => $budget_11_total,
+ budget_amount => $budget_12_total,
}
);
-my $budget_id12 = AddBudget(
+my $budget_id11 = AddBudget(
{
- budget_code => 'budget_12',
- budget_name => 'budget_12',
+ budget_code => 'budget_11',
+ budget_name => 'budget_11',
budget_period_id => $budget_period_id,
budget_parent_id => $budget_id1,
- budget_amount => $budget_12_total,
+ budget_amount => $budget_11_total,
}
);
my $budget_id111 = AddBudget(
}
);
+$budget_hierarchy = GetBudgetHierarchy($budget_period_id);
+is( $budget_hierarchy->[0]->{children}->[0]->{budget_name}, 'budget_11', 'GetBudgetHierarchy should return budgets ordered by name, first child is budget_11' );
+is( $budget_hierarchy->[0]->{children}->[1]->{budget_name}, 'budget_12', 'GetBudgetHierarchy should return budgets ordered by name, second child is budget_12' );
+
$budget_hierarchy = GetBudgetHierarchy($budget_period_id);
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
is( $number_of_budgets_not_reset, 0,
'CloneBudgetPeriod has reset all budgets (funds)' );
+#GetBudgetsByActivity
+my $result=C4::Budgets::GetBudgetsByActivity(1);
+isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1');
+$result=C4::Budgets::GetBudgetsByActivity(0);
+ isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 0');
+$result=C4::Budgets::GetBudgetsByActivity();
+ is( $result, 0 , 'GetBudgetsByActivity return 0 with none parameter or other 0 or 1' );
+DelBudget($budget_id);
+DelBudgetPeriod($bpid);
+
+# CloneBudgetPeriod with param amount_change_*
+$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
+ {
+ budget_period_id => $budget_period_id,
+ budget_period_startdate => '2014-01-01',
+ budget_period_enddate => '2014-12-31',
+ amount_change_percentage => 16,
+ amount_change_round_increment => 5,
+ }
+);
+
+$budget_period_cloned = C4::Budgets::GetBudgetPeriod($budget_period_id_cloned);
+cmp_ok($budget_period_cloned->{budget_period_total}, '==', 11600, "CloneBudgetPeriod changed correctly budget amount");
+$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
+cmp_ok($budget_hierarchy_cloned->[0]->{budget_amount}, '==', 1160, "CloneBudgetPeriod changed correctly funds amounts");
+cmp_ok($budget_hierarchy_cloned->[1]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
+cmp_ok($budget_hierarchy_cloned->[2]->{budget_amount}, '==', 55, "CloneBudgetPeriod changed correctly funds amounts");
+cmp_ok($budget_hierarchy_cloned->[3]->{budget_amount}, '==', 115, "CloneBudgetPeriod changed correctly funds amounts");
+cmp_ok($budget_hierarchy_cloned->[4]->{budget_amount}, '==', 2320, "CloneBudgetPeriod changed correctly funds amounts");
+cmp_ok($budget_hierarchy_cloned->[5]->{budget_amount}, '==', 0, "CloneBudgetPeriod changed correctly funds amounts");
+
+$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
+ {
+ budget_period_id => $budget_period_id,
+ budget_period_startdate => '2014-01-01',
+ budget_period_enddate => '2014-12-31',
+ amount_change_percentage => 16,
+ amount_change_round_increment => 5,
+ reset_all_budgets => 1,
+ }
+);
+$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
+cmp_ok($budget_hierarchy_cloned->[0]->{budget_amount}, '==', 0, "CloneBudgetPeriod reset all fund amounts");
# MoveOrders
my $number_orders_moved = C4::Budgets::MoveOrders();
is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id},
undef, "SetOwnerToFundHierarchy should have set John Doe $john_doe for budget 21 ($budget_id21)" );
+# Test GetBudgetAuthCats
+
+my $budgetPeriodId = AddBudgetPeriod({
+ budget_period_startdate => '2008-01-01',
+ budget_period_enddate => '2008-12-31',
+ budget_period_description => 'just another budget',
+ budget_period_active => 0,
+});
+
+$budgets = GetBudgets();
+my $i = 0;
+for my $budget ( @$budgets )
+{
+ $budget->{sort1_authcat} = "sort1_authcat_$i";
+ $budget->{sort2_authcat} = "sort2_authcat_$i";
+ $budget->{budget_period_id} = $budgetPeriodId;
+ ModBudget( $budget );
+ $i++;
+}
+
+my $authCat = GetBudgetAuthCats($budgetPeriodId);
+
+is( scalar @{$authCat}, $i * 2, "GetBudgetAuthCats returns only non-empty sorting categories (no empty authCat in db)" );
+
+$i = 0;
+for my $budget ( @$budgets )
+{
+ $budget->{sort1_authcat} = "sort_authcat_$i";
+ $budget->{sort2_authcat} = "sort_authcat_$i";
+ $budget->{budget_period_id} = $budgetPeriodId;
+ ModBudget( $budget );
+ $i++;
+}
+
+$authCat = GetBudgetAuthCats($budgetPeriodId);
+is( scalar @$authCat, scalar @$budgets, "GetBudgetAuthCats returns distinct authCat" );
+
+$i = 0;
+for my $budget ( @$budgets )
+{
+ $budget->{sort1_authcat} = "sort1_authcat_$i";
+ $budget->{sort2_authcat} = "";
+ $budget->{budget_period_id} = $budgetPeriodId;
+ ModBudget( $budget );
+ $i++;
+}
+
+$authCat = GetBudgetAuthCats($budgetPeriodId);
+
+is( scalar @{$authCat}, $i, "GetBudgetAuthCats returns only non-empty sorting categories (empty sort2_authcat on all records)" );
+
+$i = 0;
+for my $budget ( @$budgets )
+{
+ $budget->{sort1_authcat} = "";
+ $budget->{sort2_authcat} = "";
+ $budget->{budget_period_id} = $budgetPeriodId;
+ ModBudget( $budget );
+ $i++;
+}
+
+$authCat = GetBudgetAuthCats($budgetPeriodId);
+
+is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting categories (all empty)" );
+
+# /Test GetBudgetAuthCats
+
sub _get_dependencies {
my ($budget_hierarchy) = @_;
my $graph;