From 9a44f12607c3083de2e71c1503007cb7384defe7 Mon Sep 17 00:00:00 2001 From: Yohann Dufour Date: Thu, 26 Jun 2014 14:28:58 +0200 Subject: [PATCH] [PASSED QA] Bug 12482: removing the use of the module C4::SQLHelper.pm, it is replaced by DBIx::Class This patch includes: - removing the use of subroutines InsertInTable, UpdateInTable, SearchInTable replaced by subroutines of DBIx::Class in the subroutines AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod and GetBudgetPeriods and admin/aqbudgetperiods.pl - removing old database fields in OrderFromSubscription.t, Bookseller.t, Budgets.t, Serials.t, Serials_2.t - improvement of unit tests in t/db_dependent/Budgets.t - adaptation of calls to the subroutines AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod and GetBudgetPeriods in order to match with the use of DBIx::Class Test plan: 1) Execute the UT of all of files wich uses AddBudget, ModBudget, GetBudgets, AddBudgetPeriods, ModBudgetPeriod or GetBudgetPeriods by launching the command : prove t/Budgets/ t/Budgets.t t/db_dependent/Budgets.t t/db_dependent/Acquisition.t t/db_dependent/Acquisition/ t/db_dependent/Bookseller.t t/db_dependent/Serials.t t/db_dependent/Serials_2.t 2) The result has to be a success : t/Budgets/CanUserModifyBudget.t ........................... ok t/Budgets/CanUserUseBudget.t .............................. ok t/Budgets.t ............................................... ok t/db_dependent/Budgets.t .................................. ok t/db_dependent/Acquisition.t .............................. ok t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t .. ok t/db_dependent/Acquisition/GetOrdersByBiblionumber.t ...... ok t/db_dependent/Acquisition/Invoices.t ..................... ok t/db_dependent/Acquisition/OrderFromSubscription.t ........ ok t/db_dependent/Acquisition/TransferOrder.t ................ 1/11 # Transfering order to basket2 t/db_dependent/Acquisition/TransferOrder.t ................ ok t/db_dependent/Acquisition/close_reopen_basket.t .......... ok t/db_dependent/Bookseller.t ............................... 16/72 WARNING: GetBooksellerWithLateOrders is called with a negative value at /home/yohann/koha/C4/Bookseller.pm line 135. t/db_dependent/Bookseller.t ............................... ok t/db_dependent/Serials.t .................................. ok t/db_dependent/Serials_2.t ................................ ok All tests successful. Files=14, Tests=571, 22 wallclock secs ( 0.17 usr 0.03 sys + 20.26 cusr 1.10 csys = 21.56 CPU) Result: PASS 3) Go on the page admin/aqbudgetperiods.pl : Koha Administration > Budgets 4) Click on the button "New Budget" and record a new budget with a "nonzero amount" and "make budget active" 5) Click on the button "New Budget" and record another budget without "make budget active" 6) Verify there is the firt budget displayed in "Active budgets" and the second budget in "Inactive budgets" 7) Edit a budget and verify the new values are updated 8) Click on the budget active name in order to go on the page admin/aqbudgets.pl 9) Click on the button "New fund for ..." and record a new fund 10) Click on the button "Edit" then "Duplicate budget ..." in order to duplicate the budget 11) Verify there are two budgets in "Active Budgets" and one in "Inactive Budgets" 12) Click on "Funds" in the menu and verify there are two identical funds and each is associated to a different budget. Signed-off-by: Chris Cormack Signed-off-by: Kyle M Hall --- C4/Budgets.pm | 44 +++- admin/aqbudgetperiods.pl | 40 ++-- admin/aqbudgets.pl | 20 +- t/db_dependent/Acquisition/OrderFromSubscription.t | 8 +- t/db_dependent/Bookseller.t | 8 +- t/db_dependent/Budgets.t | 270 +++++++++++--------- t/db_dependent/Serials.t | 8 +- t/db_dependent/Serials_2.t | 8 +- 8 files changed, 229 insertions(+), 177 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 8dd572e..30b9079 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -20,10 +20,8 @@ package C4::Budgets; use strict; #use warnings; FIXME - Bug 2505 use C4::Context; -use C4::Dates qw(format_date format_date_in_iso); -use C4::SQLHelper qw<:all>; +use Koha::Database; use C4::Debug; - use vars qw($VERSION @ISA @EXPORT); BEGIN { @@ -137,7 +135,10 @@ sub CheckBudgetParentPerm { sub AddBudgetPeriod { my ($budgetperiod) = @_; - return InsertInTable("aqbudgetperiods",$budgetperiod); + return unless($budgetperiod->{budget_period_startdate} && $budgetperiod->{budget_period_enddate}); + + my $resultset = Koha::Database->new()->schema->resultset('Aqbudgetperiod'); + return $resultset->create($budgetperiod)->id; } # ------------------------------------------------------------------- sub GetPeriodsCount { @@ -403,7 +404,11 @@ sub GetBudgetAuthCats { # ------------------------------------------------------------------- sub GetBudgetPeriods { my ($filters,$orderby) = @_; - return SearchInTable("aqbudgetperiods",$filters, $orderby, undef,undef, undef, "wide"); + + my $rs = Koha::Database->new()->schema->resultset('Aqbudgetperiod'); + $rs = $rs->search( $filters, { order_by => $orderby } ); + $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + return [ $rs->all ]; } # ------------------------------------------------------------------- sub GetBudgetPeriod { @@ -450,8 +455,12 @@ sub DelBudgetPeriod{ # ------------------------------------------------------------------- sub ModBudgetPeriod { - my ($budget_period_information) = @_; - return UpdateInTable("aqbudgetperiods",$budget_period_information); + my ($budget_period) = @_; + my $result = Koha::Database->new()->schema->resultset('Aqbudgetperiod')->find($budget_period); + return unless($result); + + $result = $result->update($budget_period); + return $result->in_storage; } # ------------------------------------------------------------------- @@ -570,13 +579,20 @@ sub GetBudgetHierarchy { sub AddBudget { my ($budget) = @_; - return InsertInTable("aqbudgets",$budget); + return unless ($budget); + + my $resultset = Koha::Database->new()->schema->resultset('Aqbudget'); + return $resultset->create($budget)->id; } # ------------------------------------------------------------------- sub ModBudget { my ($budget) = @_; - return UpdateInTable("aqbudgets",$budget); + my $result = Koha::Database->new()->schema->resultset('Aqbudget')->find($budget); + return unless($result); + + $result = $result->update($budget); + return $result->in_storage; } # ------------------------------------------------------------------- @@ -719,9 +735,13 @@ gets all budgets # ------------------------------------------------------------------- sub GetBudgets { - my $filters = shift; - my $orderby = shift || 'budget_name'; - return SearchInTable("aqbudgets",$filters, $orderby, undef,undef, undef, "wide"); + my ($filters, $orderby) = @_; + $orderby = 'budget_name' unless($orderby); + + my $rs = Koha::Database->new()->schema->resultset('Aqbudget'); + $rs = $rs->search( $filters, { order_by => $orderby } ); + $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + return [ $rs->all ]; } =head2 GetBudgetUsers diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index 9371d01..c3f9691 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -50,7 +50,8 @@ use strict; use Number::Format qw(format_price); use CGI; use List::Util qw/min/; -use C4::Dates qw/format_date format_date_in_iso/; +use Koha::DateUtils; +use Koha::Database; use C4::Koha; use C4::Context; use C4::Auth; @@ -58,7 +59,6 @@ use C4::Output; use C4::Acquisition; use C4::Budgets; use C4::Debug; -use C4::SQLHelper; my $dbh = C4::Context->dbh; @@ -67,11 +67,15 @@ my $input = new CGI; my $searchfield = $input->param('searchfield'); my $budget_period_id = $input->param('budget_period_id'); my $op = $input->param('op')||"else"; - -my $budget_period_hashref= $input->Vars; #my $sort1_authcat = $input->param('sort1_authcat'); #my $sort2_authcat = $input->param('sort2_authcat'); +# get only the columns of aqbudgetperiods in budget_period_hashref +my @columns = Koha::Database->new()->schema->source('Aqbudgetperiod')->columns; +my $budget_period_hashref = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $input->param($_) ) : () } keys($input->Vars) } ; +$budget_period_hashref->{budget_period_startdate} = dt_from_string( $input->param('budget_period_startdate') ); +$budget_period_hashref->{budget_period_enddate} = dt_from_string( $input->param('budget_period_enddate') ); + my $activepagesize = 20; my $inactivepagesize = 20; $searchfield =~ s/\,//g; @@ -136,9 +140,9 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'add_validate' ) { -## add or modify a budget period (confirmation) +## add or modify a budget period (confirimation) - ## update budget period data + ## update budget period data if ( $budget_period_id ne '' ) { $$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked); my $status=ModBudgetPeriod($budget_period_hashref); @@ -182,15 +186,12 @@ elsif ( $op eq 'duplicate_form'){ # handle the actual duplication elsif ( $op eq 'duplicate_budget' ){ die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' ); - my $startdate = $input->param('budget_period_startdate'); - my $enddate = $input->param('budget_period_enddate'); my $data = GetBudgetPeriod( $budget_period_id); - - $data->{'budget_period_startdate'} = $startdate; - $data->{'budget_period_enddate'} = $enddate; + $data->{'budget_period_startdate'} = $budget_period_hashref->{budget_period_startdate}; + $data->{'budget_period_enddate'} = $budget_period_hashref->{budget_period_enddate}; delete $data->{'budget_period_id'}; - my $new_budget_period_id = C4::SQLHelper::InsertInTable('aqbudgetperiods', $data); + my $new_budget_period_id = AddBudgetPeriod($data); my $tree = GetBudgetHierarchy( $budget_period_id ); @@ -219,8 +220,11 @@ elsif ( $op eq 'duplicate_budget' ){ $orphan = 1; } + # get only the columns of aqbudgets + my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns; + my $new_entry = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $$entry{$_} ) : () } keys($entry) }; # write it to db - my $new_id = C4::SQLHelper::InsertInTable('aqbudgets', $entry); + my $new_id = AddBudget($new_entry); $old_new{$old_id} = $new_id; push @{$parent_children{$parent_id}}, $new_id if $orphan; @@ -228,7 +232,7 @@ elsif ( $op eq 'duplicate_budget' ){ if( defined $parent_children{$old_id} ){ # tell my children my new id for my $child ( @{$parent_children{$old_id}} ){ - C4::SQLHelper::UpdateInTable('aqcudgets', [ 'budget_id' => $child, 'budget_parent_id' => $new_id ]); + ModBudget( { 'budget_id' => $child, 'budget_parent_id' => $new_id } ); } delete $parent_children{$old_id}; } @@ -246,8 +250,8 @@ my $activepage = $input->param('apage') || 1; my $inactivepage = $input->param('ipage') || 1; # Get active budget periods my $results = GetBudgetPeriods( - {budget_period_active => 1}, - [{budget_period_description => 0}] + { budget_period_active => 1 }, + { -asc => 'budget_period_description' }, ); my $first = ( $activepage - 1 ) * $activepagesize; my $last = min( $first + $activepagesize - 1, scalar @{$results} - 1, ); @@ -265,8 +269,8 @@ my $active_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), # Get inactive budget periods $results = GetBudgetPeriods( - {budget_period_active => 0}, - [{budget_period_enddate => 1}] + { budget_period_active => 0 }, + { -desc => 'budget_period_enddate' }, ); $first = ( $inactivepage - 1 ) * $inactivepagesize; diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 7d97450..b8c7706 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -25,12 +25,13 @@ use CGI; use List::Util qw/min/; use Number::Format qw(format_price); +use Koha::Database; use C4::Auth qw/get_user_subpermissions/; use C4::Branch; # GetBranches use C4::Dates qw/format_date format_date_in_iso/; use C4::Auth; use C4::Acquisition; -use C4::Budgets; # +use C4::Budgets; use C4::Members; # calls GetSortDetails() use C4::Context; use C4::Output; @@ -68,14 +69,17 @@ if (not defined $template->{VARS}->{'CAN_user_acquisition_budget_add_del'} } my $num=FormatNumber; -my $budget_hash = $input->Vars; -my $budget_id = $$budget_hash{budget_id}; +# get only the columns of aqbudgets in budget_hash +my @columns = Koha::Database->new()->schema->source('Aqbudget')->columns; +my $budget_hash = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $input->param($_) ) : () } keys($input->Vars) } ; + +my $budget_id = $input->param('budget_id'); my $budget_period_id = $input->param('budget_period_id'); my $budget_permission = $input->param('budget_permission'); +my $budget_users_ids = $input->param('budget_users_ids'); my $filter_budgetbranch = $input->param('filter_budgetbranch') // ''; my $filter_budgetname = $input->param('filter_budgetname'); -#filtering non budget keys -delete $$budget_hash{$_} foreach grep {/filter|^op$|show/} keys %$budget_hash; + # ' ------- get periods stuff ------------------' # IF PERIODID IS DEFINED, GET THE PERIOD - ELSE JUST GET THE ACTIVE PERIOD BY DEFAULT @@ -234,11 +238,11 @@ if ($op eq 'add_form') { $op = 'list'; } elsif( $op eq 'add_validate' ) { my @budgetusersid; - if (defined $$budget_hash{'budget_users_ids'}){ - @budgetusersid = split(':', $budget_hash->{'budget_users_ids'}); + if (defined $budget_users_ids){ + @budgetusersid = split(':', $budget_users_ids); } - if ( defined $$budget_hash{budget_id} ) { + if (defined $budget_id) { if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id}, $staffflags) ) { diff --git a/t/db_dependent/Acquisition/OrderFromSubscription.t b/t/db_dependent/Acquisition/OrderFromSubscription.t index 5133d52..72d4c68 100644 --- a/t/db_dependent/Acquisition/OrderFromSubscription.t +++ b/t/db_dependent/Acquisition/OrderFromSubscription.t @@ -28,9 +28,9 @@ my $booksellerid = C4::Bookseller::AddBookseller( my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); my $budgetid; my $bpid = AddBudgetPeriod({ - budget_period_startdate => '01-01-2015', - budget_period_enddate => '12-31-2015', - budget_description => "budget desc" + budget_period_startdate => '01-01-2015', + budget_period_enddate => '12-31-2015', + budget_period_description => "budget desc" }); my $budget_id = AddBudget({ @@ -38,8 +38,6 @@ my $budget_id = AddBudget({ budget_amount => "123.132", budget_name => "Périodiques", budget_notes => "This is a note", - budget_description => "Serials", - budget_active => 1, budget_period_id => $bpid }); diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index a2754d1..c7ea24c 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -171,17 +171,15 @@ $dt_today1->add_duration($dur5); my $daysago5 = output_pref({ dt => $dt_today1, dateformat => 'iso', timeformat => '24hr', dateonly => 1 }); my $budgetperiod = C4::Budgets::AddBudgetPeriod({ - budget_period_startdate => $daysago5, - budget_period_enddate => $today, - budget_description => "budget desc" + budget_period_startdate => $daysago5, + budget_period_enddate => $today, + budget_period_description => "budget desc" }); my $id_budget = AddBudget({ budget_code => "CODE", budget_amount => "123.132", budget_name => "Budgetname", budget_notes => "This is a note", - budget_description => "BudgetDescription", - budget_active => 1, budget_period_id => $budgetperiod }); my $bib = MARC::Record->new(); diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 7f743ba..39e0de6 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,7 +1,9 @@ use Modern::Perl; -use Test::More tests => 25; +use Test::More tests => 63; -BEGIN {use_ok('C4::Budgets') } +BEGIN { + use_ok('C4::Budgets') +} use C4::Context; use C4::Biblio; use C4::Bookseller; @@ -19,122 +21,158 @@ $dbh->do(q|DELETE FROM aqbudgets|); # # Budget Periods : # -my $bpid; -my $budgetperiod; -my $active_period; -my $mod_status; -my $del_status; -ok($bpid=AddBudgetPeriod( - { budget_period_startdate => '2008-01-01' - , budget_period_enddate => '2008-12-31' - , budget_description => "MAPERI"}), - "AddBudgetPeriod with iso dates OK"); - -ok($budgetperiod=GetBudgetPeriod($bpid), - "GetBudgetPeriod($bpid) returned ".Dump($budgetperiod)); -ok(!GetBudgetPeriod(0) ,"GetBudgetPeriod(0) returned undef : noactive BudgetPeriod"); -$$budgetperiod{budget_period_active}=1; -ok($mod_status=ModBudgetPeriod($budgetperiod),"ModBudgetPeriod OK"); -ok($active_period=GetBudgetPeriod(0),"GetBudgetPeriod(0) returned".Dump($active_period)); -ok(scalar(GetBudgetPeriods())>0,"GetBudgetPeriods OK");#Should at least return the Budget inserted -ok($del_status=DelBudgetPeriod($bpid),"DelBudgetPeriod returned $del_status"); + +is( AddBudgetPeriod(), undef, 'AddBugetPeriod without argument returns undef' ); +is( AddBudgetPeriod( { } ), undef, 'AddBugetPeriod with an empty argument returns undef' ); +my $bpid = AddBudgetPeriod({ + budget_period_startdate => '2008-01-01', +}); +is( $bpid, undef, 'AddBugetPeriod without end date returns undef' ); +$bpid = AddBudgetPeriod({ + budget_period_enddate => '2008-12-31', +}); +is( $bpid, undef, 'AddBugetPeriod without start date returns undef' ); +is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' ); +my $budgetperiods = GetBudgetPeriods(); +is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' ); + +my $my_budgetperiod = { + budget_period_startdate => '2008-01-01', + budget_period_enddate => '2008-12-31', + budget_period_description => 'MAPERI', + budget_period_active => 0, +}; +$bpid = AddBudgetPeriod($my_budgetperiod); +isnt( $bpid, undef, 'AddBugetPeriod does not returns undef' ); +my $budgetperiod = GetBudgetPeriod($bpid); +is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'AddBudgetPeriod stores the start date correctly' ); +is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'AddBudgetPeriod stores the end date correctly' ); +is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'AddBudgetPeriod stores the description correctly' ); +is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'AddBudgetPeriod stores active correctly' ); +is( GetBudgetPeriod(0), undef ,'GetBudgetPeriod(0) returned undef : noactive BudgetPeriod' ); + + +$my_budgetperiod = { + budget_period_startdate => '2009-01-01', + budget_period_enddate => '2009-12-31', + budget_period_description => 'MODIF_MAPERI', + budget_period_active => 1, +}; +my $mod_status = ModBudgetPeriod($my_budgetperiod); +is( $mod_status, undef, 'ModBudgetPeriod without id returns undef' ); + +$my_budgetperiod->{budget_period_id} = $bpid; +$mod_status = ModBudgetPeriod($my_budgetperiod); +is( $mod_status, 1, 'ModBudgetPeriod returnis true' ); +$budgetperiod = GetBudgetPeriod($bpid); +is( $budgetperiod->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'ModBudgetPeriod updates the start date correctly' ); +is( $budgetperiod->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'ModBudgetPeriod updates the end date correctly' ); +is( $budgetperiod->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'ModBudgetPeriod updates the description correctly' ); +is( $budgetperiod->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'ModBudgetPeriod upates active correctly' ); +isnt( GetBudgetPeriod(0), undef, 'GetBugetPeriods functions correctly' ); + + +$budgetperiods = GetBudgetPeriods(); +is( @$budgetperiods, 1, 'GetBudgetPeriods returns the correct number of budget periods' ); +is( $budgetperiods->[0]->{budget_period_id}, $my_budgetperiod->{budget_period_id}, 'GetBudgetPeriods returns the id correctly' ); +is( $budgetperiods->[0]->{budget_period_startdate}, $my_budgetperiod->{budget_period_startdate}, 'GetBudgetPeriods returns the start date correctly' ); +is( $budgetperiods->[0]->{budget_period_enddate}, $my_budgetperiod->{budget_period_enddate}, 'GetBudgetPeriods returns the end date correctly' ); +is( $budgetperiods->[0]->{budget_period_description}, $my_budgetperiod->{budget_period_description}, 'GetBudgetPeriods returns the description correctly' ); +is( $budgetperiods->[0]->{budget_period_active}, $my_budgetperiod->{budget_period_active}, 'GetBudgetPeriods returns active correctly' ); + +is( DelBudgetPeriod($bpid), 1, 'DelBudgetPeriod returns true' ); +$budgetperiods = GetBudgetPeriods(); +is( @$budgetperiods, 0, 'GetBudgetPeriods returns the correct number of budget periods' ); + # # Budget : # -# Add A budget Period -if (C4::Context->preference('dateformat') eq "metric"){ -ok($bpid=AddBudgetPeriod( - { budget_period_startdate =>'01-01-2008' - , budget_period_enddate =>'31-12-2008' - , budget_description =>"MAPERI"}), - "AddBudgetPeriod returned $bpid"); -} elsif (C4::Context->preference('dateformat') eq "us"){ -ok($bpid=AddBudgetPeriod( - { budget_period_startdate =>'01-01-2008' - , budget_period_enddate =>'12-31-2008' - , budget_description =>"MAPERI"}), - "AddBudgetPeriod returned $bpid"); -} -else{ -ok($bpid=AddBudgetPeriod( - {budget_period_startdate=>'2008-01-01' - ,budget_period_enddate =>'2008-12-31' - ,budget_description =>"MAPERI" - }), - "AddBudgetPeriod returned $bpid"); +is( AddBudget(), undef, 'AddBuget without argument returns undef' ); +my $budgets = GetBudgets(); +is( @$budgets, 0, 'GetBudgets returns the correct number of budgets' ); + +$bpid = AddBudgetPeriod($my_budgetperiod); +my $my_budget = { + budget_code => 'ABCD', + budget_amount => '123.132000', + budget_name => 'Periodiques', + budget_notes => 'This is a note', + budget_period_id => $bpid, +}; +my $budget_id = AddBudget($my_budget); +isnt( $budget_id, undef, 'AddBudget does not returns undef' ); +my $budget = GetBudget($budget_id); +is( $budget->{budget_code}, $my_budget->{budget_code}, 'AddBudget stores the budget code correctly' ); +is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'AddBudget stores the budget amount correctly' ); +is( $budget->{budget_name}, $my_budget->{budget_name}, 'AddBudget stores the budget name correctly' ); +is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'AddBudget stores the budget notes correctly' ); +is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'AddBudget stores the budget period id correctly' ); + + +$my_budget = { + budget_code => 'EFG', + budget_amount => '321.231000', + budget_name => 'Modified name', + budget_notes => 'This is a modified note', + budget_period_id => $bpid, +}; +$mod_status = ModBudget($my_budget); +is( $mod_status, undef, 'ModBudget without id returns undef' ); + +$my_budget->{budget_id} = $budget_id; +$mod_status = ModBudget($my_budget); +is( $mod_status, 1, 'ModBudget returns true' ); +$budget = GetBudget($budget_id); +is( $budget->{budget_code}, $my_budget->{budget_code}, 'ModBudget updates the budget code correctly' ); +is( $budget->{budget_amount}, $my_budget->{budget_amount}, 'ModBudget updates the budget amount correctly' ); +is( $budget->{budget_name}, $my_budget->{budget_name}, 'ModBudget updates the budget name correctly' ); +is( $budget->{budget_notes}, $my_budget->{budget_notes}, 'ModBudget updates the budget notes correctly' ); +is( $budget->{budget_period_id}, $my_budget->{budget_period_id}, 'ModBudget updates the budget period id correctly' ); + + +$budgets = GetBudgets(); +is( @$budgets, 1, 'GetBudgets returns the correct number of budgets' ); +is( $budgets->[0]->{budget_id}, $my_budget->{budget_id}, 'GetBudgets returns the budget id correctly' ); +is( $budgets->[0]->{budget_code}, $my_budget->{budget_code}, 'GetBudgets returns the budget code correctly' ); +is( $budgets->[0]->{budget_amount}, $my_budget->{budget_amount}, 'GetBudgets returns the budget amount correctly' ); +is( $budgets->[0]->{budget_name}, $my_budget->{budget_name}, 'GetBudgets returns the budget name correctly' ); +is( $budgets->[0]->{budget_notes}, $my_budget->{budget_notes}, 'GetBudgets returns the budget notes correctly' ); +is( $budgets->[0]->{budget_period_id}, $my_budget->{budget_period_id}, 'GetBudgets returns the budget period id correctly' ); + +$budgets = GetBudgets( {budget_period_id => $bpid} ); +is( @$budgets, 1, 'GetBudgets With Filter OK' ); +$budgets = GetBudgets( {budget_period_id => $bpid}, {-asc => "budget_name"} ); +is( @$budgets, 1, 'GetBudgets With Order OK' ); +$budgets = GetBudgets( {budget_period_id => GetBudgetPeriod($bpid)->{budget_period_id}}, {-asc => "budget_name"} ); +is( @$budgets, 1, 'GetBudgets With Order Getting Active budgetPeriod OK'); -} -my $budget_id; -ok($budget_id=AddBudget( - { budget_code => "ABCD" - , budget_amount => "123.132" - , budget_name => "Périodiques" - , budget_notes => "This is a note" - , budget_description=> "Serials" - , budget_active => 1 - , budget_period_id => $bpid - } - ), - "AddBudget returned $budget_id"); -#budget_code | varchar(30) | YES | | NULL | | -#| budget_amount | decimal(28,6) | NO | | 0.000000 | | -#| budget_id | int(11) | NO | PRI | NULL | | -#| budget_branchcode | varchar(10) | YES | | NULL | | -#| budget_parent_id | int(11) | YES | | NULL | | -#| budget_name | varchar(80) | YES | | NULL | | -#| budget_encumb | decimal(28,6) | YES | | 0.000000 | | -#| budget_expend | decimal(28,6) | YES | | 0.000000 | | -#| budget_notes | mediumtext | YES | | NULL | | -#| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | | -#| budget_period_id | int(11) | YES | MUL | NULL | | -#| sort1_authcat | varchar(80) | YES | | NULL | | -#| sort2_authcat | varchar(80) | YES | | NULL | | -#| budget_owner_id | int(11) | YES | | NULL | | -#| budget_permission | int(1) | YES | | 0 | | - -my $budget; -ok($budget=GetBudget($budget_id) ,"GetBudget OK"); -$budget_id = $budget->{budget_id}; -$$budget{budget_permission}=1; -ok($mod_status=ModBudget($budget),"ModBudget OK"); -ok(GetBudgets()>0, - "GetBudgets OK"); -ok(GetBudgets({budget_period_id=>$bpid})>0, - "GetBudgets With Filter OK"); -ok(GetBudgets({budget_period_id=>$bpid},[{"budget_name"=>0}])>0, - "GetBudgets With Order OK"); -ok(GetBudgets({budget_period_id=>GetBudgetPeriod($bpid)->{budget_period_id}},[{"budget_name"=>0}])>0, - "GetBudgets With Order - Getting Active budgetPeriod OK"); my $budget_name = GetBudgetName( $budget_id ); -is($budget_name, $budget->{budget_name}, "Test the GetBudgetName routine"); +is($budget_name, $my_budget->{budget_name}, "Test the GetBudgetName routine"); -my $budget_code = $budget->{budget_code}; +my $budget_code = $my_budget->{budget_code}; my $budget_by_code = GetBudgetByCode( $budget_code ); is($budget_by_code->{budget_id}, $budget_id, "GetBudgetByCode, check id"); -is($budget_by_code->{budget_notes}, 'This is a note', "GetBudgetByCode, check notes"); - -my $second_budget_id; -ok($second_budget_id=AddBudget( - { budget_code => "ZZZZ", - budget_amount => "500.00", - budget_name => "Art", - budget_notes => "This is a note", - budget_description=> "Art", - budget_active => 1, - budget_period_id => $bpid, - } - ), - "AddBudget returned $second_budget_id"); - -my $budgets = GetBudgets({ budget_period_id => $bpid}); -ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name'); - -ok($del_status=DelBudget($budget_id), - "DelBudget returned $del_status"); +is($budget_by_code->{budget_notes}, $my_budget->{budget_notes}, "GetBudgetByCode, check notes"); + +my $second_budget_id = AddBudget({ + budget_code => "ZZZZ", + budget_amount => "500.00", + budget_name => "Art", + budget_notes => "This is a note", + budget_period_id => $bpid, +}); +isnt( $second_budget_id, undef, 'AddBudget does not returns undef' ); + +$budgets = GetBudgets( {budget_period_id => $bpid} ); +ok( $budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name' ); + +is( DelBudget($budget_id), 1, 'DelBudget returns true' ); +$budgets = GetBudgets(); +is( @$budgets, 1, 'GetBudgets returns the correct number of budget periods' ); + # GetBudgetHierarchySpent and GetBudgetHierarchyOrdered my $budget_period_total = 10_000; @@ -146,18 +184,17 @@ my $budget_2_total = 2_000; my $budget_period_id = AddBudgetPeriod( { - budget_period_startdate => '2013-01-01', - budget_period_enddate => '2014-12-31', - budget_description => 'Budget Period', - budget_period_active => 1, - budget_period_total => $budget_period_total, + budget_period_startdate => '2013-01-01', + budget_period_enddate => '2014-12-31', + budget_period_description => 'Budget Period', + budget_period_active => 1, + budget_period_total => $budget_period_total, } ); my $budget_id1 = AddBudget( { budget_code => 'budget_1', budget_name => 'budget_1', - budget_active => 1, budget_period_id => $budget_period_id, budget_parent_id => undef, budget_amount => $budget_1_total, @@ -167,7 +204,6 @@ my $budget_id2 = AddBudget( { budget_code => 'budget_2', budget_name => 'budget_2', - budget_active => 1, budget_period_id => $budget_period_id, budget_parent_id => undef, budget_amount => $budget_2_total, @@ -177,7 +213,6 @@ my $budget_id11 = AddBudget( { budget_code => 'budget_11', budget_name => 'budget_11', - budget_active => 1, budget_period_id => $budget_period_id, budget_parent_id => $budget_id1, budget_amount => $budget_11_total, @@ -187,7 +222,6 @@ my $budget_id12 = AddBudget( { budget_code => 'budget_12', budget_name => 'budget_12', - budget_active => 1, budget_period_id => $budget_period_id, budget_parent_id => $budget_id1, budget_amount => $budget_12_total, @@ -197,10 +231,9 @@ my $budget_id111 = AddBudget( { budget_code => 'budget_111', budget_name => 'budget_111', - budget_active => 1, budget_period_id => $budget_period_id, budget_parent_id => $budget_id11, - owner_id => 1, + budget_owner_id => 1, budget_amount => $budget_111_total, } ); @@ -208,7 +241,6 @@ my $budget_id21 = AddBudget( { budget_code => 'budget_21', budget_name => 'budget_21', - budget_active => 1, budget_period_id => $budget_period_id, budget_parent_id => $budget_id2, } diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index ab466e6..8fbb709 100644 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -40,9 +40,9 @@ my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); my $budgetid; my $bpid = AddBudgetPeriod({ - budget_period_startdate => '01-01-2015', - budget_period_enddate => '31-12-2015', - budget_description => "budget desc" + budget_period_startdate => '01-01-2015', + budget_period_enddate => '31-12-2015', + budget_period_description => "budget desc" }); my $budget_id = AddBudget({ @@ -50,8 +50,6 @@ my $budget_id = AddBudget({ budget_amount => "123.132", budget_name => "Périodiques", budget_notes => "This is a note", - budget_description => "Serials", - budget_active => 1, budget_period_id => $bpid }); diff --git a/t/db_dependent/Serials_2.t b/t/db_dependent/Serials_2.t index c11c0d3..51b5995 100644 --- a/t/db_dependent/Serials_2.t +++ b/t/db_dependent/Serials_2.t @@ -34,9 +34,9 @@ my $my_branch = 'CPL'; my $another_branch = 'MPL'; my $budgetid; my $bpid = AddBudgetPeriod({ - budget_period_startdate => '2015-01-01', - budget_period_enddate => '2015-12-31', - budget_description => "budget desc" + budget_period_startdate => '2015-01-01', + budget_period_enddate => '2015-12-31', + budget_period_description => "budget desc" }); my $budget_id = AddBudget({ @@ -44,8 +44,6 @@ my $budget_id = AddBudget({ budget_amount => "123.132", budget_name => "Périodiques", budget_notes => "This is a note", - budget_description => "Serials", - budget_active => 1, budget_period_id => $bpid }); -- 1.7.2.5