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

(-)a/C4/Budgets.pm (-12 / +32 lines)
Lines 20-29 package C4::Budgets; Link Here
20
use strict;
20
use strict;
21
#use warnings; FIXME - Bug 2505
21
#use warnings; FIXME - Bug 2505
22
use C4::Context;
22
use C4::Context;
23
use C4::Dates qw(format_date format_date_in_iso);
23
use Koha::Database;
24
use C4::SQLHelper qw<:all>;
25
use C4::Debug;
24
use C4::Debug;
26
27
use vars qw($VERSION @ISA @EXPORT);
25
use vars qw($VERSION @ISA @EXPORT);
28
26
29
BEGIN {
27
BEGIN {
Lines 137-143 sub CheckBudgetParentPerm { Link Here
137
135
138
sub AddBudgetPeriod {
136
sub AddBudgetPeriod {
139
    my ($budgetperiod) = @_;
137
    my ($budgetperiod) = @_;
140
	return InsertInTable("aqbudgetperiods",$budgetperiod);
138
    return unless($budgetperiod->{budget_period_startdate} && $budgetperiod->{budget_period_enddate});
139
140
    my $resultset = Koha::Database->new()->schema->resultset('Aqbudgetperiod');
141
    return $resultset->create($budgetperiod)->id;
141
}
142
}
142
# -------------------------------------------------------------------
143
# -------------------------------------------------------------------
143
sub GetPeriodsCount {
144
sub GetPeriodsCount {
Lines 403-409 sub GetBudgetAuthCats { Link Here
403
# -------------------------------------------------------------------
404
# -------------------------------------------------------------------
404
sub GetBudgetPeriods {
405
sub GetBudgetPeriods {
405
	my ($filters,$orderby) = @_;
406
	my ($filters,$orderby) = @_;
406
    return SearchInTable("aqbudgetperiods",$filters, $orderby, undef,undef, undef, "wide");
407
408
    my $rs = Koha::Database->new()->schema->resultset('Aqbudgetperiod');
409
    $rs = $rs->search( $filters, { order_by => $orderby } );
410
    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
411
    return [ $rs->all ];
407
}
412
}
408
# -------------------------------------------------------------------
413
# -------------------------------------------------------------------
409
sub GetBudgetPeriod {
414
sub GetBudgetPeriod {
Lines 450-457 sub DelBudgetPeriod{ Link Here
450
455
451
# -------------------------------------------------------------------
456
# -------------------------------------------------------------------
452
sub ModBudgetPeriod {
457
sub ModBudgetPeriod {
453
	my ($budget_period_information) = @_;
458
    my ($budget_period) = @_;
454
	return UpdateInTable("aqbudgetperiods",$budget_period_information);
459
    my $result = Koha::Database->new()->schema->resultset('Aqbudgetperiod')->find($budget_period);
460
    return unless($result);
461
462
    $result = $result->update($budget_period);
463
    return $result->in_storage;
455
}
464
}
456
465
457
# -------------------------------------------------------------------
466
# -------------------------------------------------------------------
Lines 570-582 sub GetBudgetHierarchy { Link Here
570
579
571
sub AddBudget {
580
sub AddBudget {
572
    my ($budget) = @_;
581
    my ($budget) = @_;
573
	return InsertInTable("aqbudgets",$budget);
582
    return unless ($budget);
583
584
    my $resultset = Koha::Database->new()->schema->resultset('Aqbudget');
585
    return $resultset->create($budget)->id;
574
}
586
}
575
587
576
# -------------------------------------------------------------------
588
# -------------------------------------------------------------------
577
sub ModBudget {
589
sub ModBudget {
578
    my ($budget) = @_;
590
    my ($budget) = @_;
579
	return UpdateInTable("aqbudgets",$budget);
591
    my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget);
592
    return unless($result);
593
594
    $result = $result->update($budget);
595
    return $result->in_storage;
580
}
596
}
581
597
582
# -------------------------------------------------------------------
598
# -------------------------------------------------------------------
Lines 719-727 gets all budgets Link Here
719
735
720
# -------------------------------------------------------------------
736
# -------------------------------------------------------------------
721
sub GetBudgets {
737
sub GetBudgets {
722
    my $filters = shift;
738
    my ($filters, $orderby) = @_;
723
    my $orderby = shift || 'budget_name';
739
    $orderby = 'budget_name' unless($orderby);
724
    return SearchInTable("aqbudgets",$filters, $orderby, undef,undef, undef, "wide");
740
741
    my $rs = Koha::Database->new()->schema->resultset('Aqbudget');
742
    $rs = $rs->search( $filters, { order_by => $orderby } );
743
    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
744
    return [ $rs->all  ];
725
}
745
}
726
746
727
=head2 GetBudgetUsers
747
=head2 GetBudgetUsers
(-)a/admin/aqbudgetperiods.pl (-18 / +22 lines)
Lines 50-56 use strict; Link Here
50
use Number::Format qw(format_price);
50
use Number::Format qw(format_price);
51
use CGI;
51
use CGI;
52
use List::Util qw/min/;
52
use List::Util qw/min/;
53
use C4::Dates qw/format_date format_date_in_iso/;
53
use Koha::DateUtils;
54
use Koha::Database;
54
use C4::Koha;
55
use C4::Koha;
55
use C4::Context;
56
use C4::Context;
56
use C4::Auth;
57
use C4::Auth;
Lines 58-64 use C4::Output; Link Here
58
use C4::Acquisition;
59
use C4::Acquisition;
59
use C4::Budgets;
60
use C4::Budgets;
60
use C4::Debug;
61
use C4::Debug;
61
use C4::SQLHelper;
62
62
63
my $dbh = C4::Context->dbh;
63
my $dbh = C4::Context->dbh;
64
64
Lines 67-77 my $input = new CGI; Link Here
67
my $searchfield          = $input->param('searchfield');
67
my $searchfield          = $input->param('searchfield');
68
my $budget_period_id     = $input->param('budget_period_id');
68
my $budget_period_id     = $input->param('budget_period_id');
69
my $op                   = $input->param('op')||"else";
69
my $op                   = $input->param('op')||"else";
70
71
my $budget_period_hashref= $input->Vars;
72
#my $sort1_authcat = $input->param('sort1_authcat');
70
#my $sort1_authcat = $input->param('sort1_authcat');
73
#my $sort2_authcat = $input->param('sort2_authcat');
71
#my $sort2_authcat = $input->param('sort2_authcat');
74
72
73
# get only the columns of aqbudgetperiods in budget_period_hashref
74
my @columns = Koha::Database->new()->schema->source('Aqbudgetperiod')->columns;
75
my $budget_period_hashref = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $input->param($_) )  : () } keys($input->Vars) } ;
76
$budget_period_hashref->{budget_period_startdate} = dt_from_string( $input->param('budget_period_startdate') );
77
$budget_period_hashref->{budget_period_enddate}   = dt_from_string( $input->param('budget_period_enddate') );
78
75
my $activepagesize = 20;
79
my $activepagesize = 20;
76
my $inactivepagesize = 20;
80
my $inactivepagesize = 20;
77
$searchfield =~ s/\,//g;
81
$searchfield =~ s/\,//g;
Lines 136-144 if ( $op eq 'add_form' ) { Link Here
136
}
140
}
137
141
138
elsif ( $op eq 'add_validate' ) {
142
elsif ( $op eq 'add_validate' ) {
139
## add or modify a budget period (confirmation)
143
## add or modify a budget period (confirimation)
140
144
141
	## update budget period data
145
    ## update budget period data
142
	if ( $budget_period_id ne '' ) {
146
	if ( $budget_period_id ne '' ) {
143
		$$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked);
147
		$$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked);
144
		my $status=ModBudgetPeriod($budget_period_hashref);
148
		my $status=ModBudgetPeriod($budget_period_hashref);
Lines 182-196 elsif ( $op eq 'duplicate_form'){ Link Here
182
# handle the actual duplication
186
# handle the actual duplication
183
elsif ( $op eq 'duplicate_budget' ){
187
elsif ( $op eq 'duplicate_budget' ){
184
    die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' );
188
    die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' );
185
    my $startdate = $input->param('budget_period_startdate');
186
    my $enddate = $input->param('budget_period_enddate');
187
189
188
    my $data = GetBudgetPeriod( $budget_period_id);
190
    my $data = GetBudgetPeriod( $budget_period_id);
189
191
    $data->{'budget_period_startdate'} = $budget_period_hashref->{budget_period_startdate};
190
    $data->{'budget_period_startdate'} = $startdate;
192
    $data->{'budget_period_enddate'} = $budget_period_hashref->{budget_period_enddate};
191
    $data->{'budget_period_enddate'} = $enddate;
192
    delete $data->{'budget_period_id'};
193
    delete $data->{'budget_period_id'};
193
    my $new_budget_period_id = C4::SQLHelper::InsertInTable('aqbudgetperiods', $data);
194
    my $new_budget_period_id = AddBudgetPeriod($data);
194
195
195
    my $tree = GetBudgetHierarchy( $budget_period_id );
196
    my $tree = GetBudgetHierarchy( $budget_period_id );
196
197
Lines 219-226 elsif ( $op eq 'duplicate_budget' ){ Link Here
219
            $orphan = 1;
220
            $orphan = 1;
220
        }
221
        }
221
222
223
        # get only the columns of aqbudgets
224
        my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns;
225
        my $new_entry = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $$entry{$_} )  : () } keys($entry) };
222
        # write it to db
226
        # write it to db
223
        my $new_id = C4::SQLHelper::InsertInTable('aqbudgets', $entry);
227
        my $new_id = AddBudget($new_entry);
224
        $old_new{$old_id} = $new_id;
228
        $old_new{$old_id} = $new_id;
225
        push @{$parent_children{$parent_id}}, $new_id if $orphan;
229
        push @{$parent_children{$parent_id}}, $new_id if $orphan;
226
230
Lines 228-234 elsif ( $op eq 'duplicate_budget' ){ Link Here
228
        if( defined $parent_children{$old_id} ){
232
        if( defined $parent_children{$old_id} ){
229
            # tell my children my new id
233
            # tell my children my new id
230
            for my $child ( @{$parent_children{$old_id}} ){
234
            for my $child ( @{$parent_children{$old_id}} ){
231
                C4::SQLHelper::UpdateInTable('aqcudgets', [ 'budget_id' => $child, 'budget_parent_id' => $new_id ]);
235
                ModBudget( { 'budget_id' => $child, 'budget_parent_id' => $new_id } );
232
            }
236
            }
233
            delete $parent_children{$old_id};
237
            delete $parent_children{$old_id};
234
        }
238
        }
Lines 246-253 my $activepage = $input->param('apage') || 1; Link Here
246
my $inactivepage = $input->param('ipage') || 1;
250
my $inactivepage = $input->param('ipage') || 1;
247
# Get active budget periods
251
# Get active budget periods
248
my $results = GetBudgetPeriods(
252
my $results = GetBudgetPeriods(
249
    {budget_period_active => 1},
253
    { budget_period_active => 1 },
250
    [{budget_period_description => 0}]
254
    { -asc => 'budget_period_description' },
251
);
255
);
252
my $first = ( $activepage - 1 ) * $activepagesize;
256
my $first = ( $activepage - 1 ) * $activepagesize;
253
my $last = min( $first + $activepagesize - 1, scalar @{$results} - 1, );
257
my $last = min( $first + $activepagesize - 1, scalar @{$results} - 1, );
Lines 265-272 my $active_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), Link Here
265
269
266
# Get inactive budget periods
270
# Get inactive budget periods
267
$results = GetBudgetPeriods(
271
$results = GetBudgetPeriods(
268
    {budget_period_active => 0},
272
    { budget_period_active => 0 },
269
    [{budget_period_enddate => 1}]
273
    { -desc => 'budget_period_enddate' },
270
);
274
);
271
275
272
$first = ( $inactivepage - 1 ) * $inactivepagesize;
276
$first = ( $inactivepage - 1 ) * $inactivepagesize;
(-)a/admin/aqbudgets.pl (-8 / +12 lines)
Lines 25-36 use CGI; Link Here
25
use List::Util qw/min/;
25
use List::Util qw/min/;
26
use Number::Format qw(format_price);
26
use Number::Format qw(format_price);
27
27
28
use Koha::Database;
28
use C4::Auth qw/get_user_subpermissions/;
29
use C4::Auth qw/get_user_subpermissions/;
29
use C4::Branch; # GetBranches
30
use C4::Branch; # GetBranches
30
use C4::Dates qw/format_date format_date_in_iso/;
31
use C4::Dates qw/format_date format_date_in_iso/;
31
use C4::Auth;
32
use C4::Auth;
32
use C4::Acquisition;
33
use C4::Acquisition;
33
use C4::Budgets;   #
34
use C4::Budgets;
34
use C4::Members;  # calls GetSortDetails()
35
use C4::Members;  # calls GetSortDetails()
35
use C4::Context;
36
use C4::Context;
36
use C4::Output;
37
use C4::Output;
Lines 68-81 if (not defined $template->{VARS}->{'CAN_user_acquisition_budget_add_del'} Link Here
68
}
69
}
69
my $num=FormatNumber;
70
my $num=FormatNumber;
70
71
71
my $budget_hash               = $input->Vars;
72
# get only the columns of aqbudgets in budget_hash
72
my $budget_id                 = $$budget_hash{budget_id};
73
my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns;
74
my $budget_hash = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $input->param($_) )  : () } keys($input->Vars) } ;
75
76
my $budget_id                 = $input->param('budget_id');
73
my $budget_period_id          = $input->param('budget_period_id');
77
my $budget_period_id          = $input->param('budget_period_id');
74
my $budget_permission         = $input->param('budget_permission');
78
my $budget_permission         = $input->param('budget_permission');
79
my $budget_users_ids          = $input->param('budget_users_ids');
75
my $filter_budgetbranch       = $input->param('filter_budgetbranch') // '';
80
my $filter_budgetbranch       = $input->param('filter_budgetbranch') // '';
76
my $filter_budgetname         = $input->param('filter_budgetname');
81
my $filter_budgetname         = $input->param('filter_budgetname');
77
#filtering non budget keys
82
78
delete $$budget_hash{$_} foreach grep {/filter|^op$|show/} keys %$budget_hash;
79
83
80
# ' ------- get periods stuff ------------------'
84
# ' ------- get periods stuff ------------------'
81
# IF PERIODID IS DEFINED,  GET THE PERIOD - ELSE JUST GET THE ACTIVE PERIOD BY DEFAULT
85
# IF PERIODID IS DEFINED,  GET THE PERIOD - ELSE JUST GET THE ACTIVE PERIOD BY DEFAULT
Lines 234-244 if ($op eq 'add_form') { Link Here
234
    $op = 'list';
238
    $op = 'list';
235
} elsif( $op eq 'add_validate' ) {
239
} elsif( $op eq 'add_validate' ) {
236
    my @budgetusersid;
240
    my @budgetusersid;
237
    if (defined $$budget_hash{'budget_users_ids'}){
241
    if (defined $budget_users_ids){
238
        @budgetusersid = split(':', $budget_hash->{'budget_users_ids'});
242
        @budgetusersid = split(':', $budget_users_ids);
239
    }
243
    }
240
244
241
    if ( defined $$budget_hash{budget_id} ) {
245
    if (defined $budget_id) {
242
        if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
246
        if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
243
            $staffflags)
247
            $staffflags)
244
        ) {
248
        ) {
(-)a/t/db_dependent/Acquisition/OrderFromSubscription.t (-5 / +3 lines)
Lines 28-36 my $booksellerid = C4::Bookseller::AddBookseller( Link Here
28
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
28
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
29
my $budgetid;
29
my $budgetid;
30
my $bpid = AddBudgetPeriod({
30
my $bpid = AddBudgetPeriod({
31
    budget_period_startdate => '01-01-2015',
31
    budget_period_startdate   => '01-01-2015',
32
    budget_period_enddate   => '12-31-2015',
32
    budget_period_enddate     => '12-31-2015',
33
    budget_description      => "budget desc"
33
    budget_period_description => "budget desc"
34
});
34
});
35
35
36
my $budget_id = AddBudget({
36
my $budget_id = AddBudget({
Lines 38-45 my $budget_id = AddBudget({ Link Here
38
    budget_amount      => "123.132",
38
    budget_amount      => "123.132",
39
    budget_name        => "Périodiques",
39
    budget_name        => "Périodiques",
40
    budget_notes       => "This is a note",
40
    budget_notes       => "This is a note",
41
    budget_description => "Serials",
42
    budget_active      => 1,
43
    budget_period_id   => $bpid
41
    budget_period_id   => $bpid
44
});
42
});
45
43
(-)a/t/db_dependent/Bookseller.t (-5 / +3 lines)
Lines 171-187 $dt_today1->add_duration($dur5); Link Here
171
my $daysago5 = output_pref({ dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
171
my $daysago5 = output_pref({ dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 });
172
172
173
my $budgetperiod = C4::Budgets::AddBudgetPeriod({
173
my $budgetperiod = C4::Budgets::AddBudgetPeriod({
174
    budget_period_startdate => $daysago5,
174
    budget_period_startdate   => $daysago5,
175
    budget_period_enddate   => $today,
175
    budget_period_enddate     => $today,
176
    budget_description      => "budget desc"
176
    budget_period_description => "budget desc"
177
});
177
});
178
my $id_budget = AddBudget({
178
my $id_budget = AddBudget({
179
    budget_code        => "CODE",
179
    budget_code        => "CODE",
180
    budget_amount      => "123.132",
180
    budget_amount      => "123.132",
181
    budget_name        => "Budgetname",
181
    budget_name        => "Budgetname",
182
    budget_notes       => "This is a note",
182
    budget_notes       => "This is a note",
183
    budget_description => "BudgetDescription",
184
    budget_active      => 1,
185
    budget_period_id   => $budgetperiod
183
    budget_period_id   => $budgetperiod
186
});
184
});
187
my $bib = MARC::Record->new();
185
my $bib = MARC::Record->new();
(-)a/t/db_dependent/Budgets.t (-119 / +151 lines)
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
    }
(-)a/t/db_dependent/Serials.t (-5 / +3 lines)
Lines 40-48 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); Link Here
40
40
41
my $budgetid;
41
my $budgetid;
42
my $bpid = AddBudgetPeriod({
42
my $bpid = AddBudgetPeriod({
43
    budget_period_startdate => '01-01-2015',
43
    budget_period_startdate   => '01-01-2015',
44
    budget_period_enddate   => '31-12-2015',
44
    budget_period_enddate     => '31-12-2015',
45
    budget_description      => "budget desc"
45
    budget_period_description => "budget desc"
46
});
46
});
47
47
48
my $budget_id = AddBudget({
48
my $budget_id = AddBudget({
Lines 50-57 my $budget_id = AddBudget({ Link Here
50
    budget_amount      => "123.132",
50
    budget_amount      => "123.132",
51
    budget_name        => "Périodiques",
51
    budget_name        => "Périodiques",
52
    budget_notes       => "This is a note",
52
    budget_notes       => "This is a note",
53
    budget_description => "Serials",
54
    budget_active      => 1,
55
    budget_period_id   => $bpid
53
    budget_period_id   => $bpid
56
});
54
});
57
55
(-)a/t/db_dependent/Serials_2.t (-6 / +3 lines)
Lines 34-42 my $my_branch = 'CPL'; Link Here
34
my $another_branch = 'MPL';
34
my $another_branch = 'MPL';
35
my $budgetid;
35
my $budgetid;
36
my $bpid = AddBudgetPeriod({
36
my $bpid = AddBudgetPeriod({
37
    budget_period_startdate => '2015-01-01',
37
    budget_period_startdate   => '2015-01-01',
38
    budget_period_enddate   => '2015-12-31',
38
    budget_period_enddate     => '2015-12-31',
39
    budget_description      => "budget desc"
39
    budget_period_description => "budget desc"
40
});
40
});
41
41
42
my $budget_id = AddBudget({
42
my $budget_id = AddBudget({
Lines 44-51 my $budget_id = AddBudget({ Link Here
44
    budget_amount      => "123.132",
44
    budget_amount      => "123.132",
45
    budget_name        => "Périodiques",
45
    budget_name        => "Périodiques",
46
    budget_notes       => "This is a note",
46
    budget_notes       => "This is a note",
47
    budget_description => "Serials",
48
    budget_active      => 1,
49
    budget_period_id   => $bpid
47
    budget_period_id   => $bpid
50
});
48
});
51
49
52
- 

Return to bug 12482