From 38b61303bd84a0fed748fa6670972ece4ead0330 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Fri, 14 Aug 2009 15:40:40 +0200 Subject: [PATCH] Bug Fixing : 1st Step Bookfund has become Budgets More bug fixing on Suggestions and Budgets --- C4/Budgets.pm | 164 ++++++++++--------------- C4/Suggestions.pm | 13 +- acqui/acqui-home.pl | 2 +- admin/aqbudgets.pl | 2 +- installer/data/mysql/updatedatabase.pl | 4 +- suggestion/suggestion.pl | 5 + 6 files changed, 84 insertions(+), 106 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index d2a5b761b2..a07afe842a 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -468,40 +468,42 @@ sub DelBudgetPeriod() { ## get information about the record that will be deleted my $sth = $dbh->prepare(qq| - SELECT budget_period_id - , budget_period_startdate - , budget_period_enddate - , budget_period_amount - , budget_period_ref - , budget_period_description + DELETE FROM aqbudgetperiods WHERE budget_period_id=? | ); - $sth->execute($budget_period_id); - my $data = $sth->fetchrow_hashref; - $sth->finish; + return $sth->execute($budget_period_id); } # ------------------------------------------------------------------- sub ModBudgetPeriod() { - my ($budget_period_id) = @_; - my $dbh = C4::Context->dbh - ; ## $total = number of records linked to the record that must be deleted my $total = 0; + my ($budget_period_information) = @_; + my $dbh = C4::Context->dbh ; ## $total = number of records linked to the record that must be deleted my $total = 0; ## get information about the record that will be deleted - my $sth = $dbh->prepare(" - SELECT budget_period_id - , budget_period_startdate - , budget_period_enddate - , budget_period_amount - , budget_period_ref - , budget_period_description - FROM aqbudgetperiods - WHERE budget_period_id=?;" - ); - $sth->execute($budget_period_id); - my $data = $sth->fetchrow_hashref; - $sth->finish; + my $budget_period_id=$$budget_period_information{'budget_period_id'}; + delete $$budget_period_information{'budget_period_id'}; + my @values; + my @keys; + + while ( my ($k,$v) = each %$budget_period_information ) { + next if (not $v and $k!~/sort1|note/); + #next if any { $_ eq $k } qw( sort1 note); + push @values, $v; + push @keys, "$k=?"; + } + + my $query = do { local $"=','; + qq{ + UPDATE aqbudgetperiods + SET @keys + WHERE budget_period_id=? + } + }; + + my $sth=$dbh->prepare($query); + my $data = $sth->execute(@values,$budget_period_id); + return $data; } # ------------------------------------------------------------------- @@ -644,85 +646,55 @@ sub GetBudgetHierarchy { sub AddBudget { my ($budget) = @_; my $dbh = C4::Context->dbh; - my $query = qq| - INSERT INTO aqbudgets - SET budget_code = ?, - budget_period_id = ?, - budget_parent_id = ?, - budget_name = ?, - budget_branchcode = ?, - budget_amount = ?, - budget_amount_sublevel = ?, - budget_encumb = ?, - budget_expend = ?, - budget_notes = ?, - sort1_authcat = ?, - sort2_authcat = ?, - budget_owner_id = ?, - budget_permission = ? - |; - my $sth = $dbh->prepare($query); - $sth->execute( - $budget->{'budget_code'} ? $budget->{'budget_code'} : undef, - $budget->{'budget_period_id'} ? $budget->{'budget_period_id'} : undef, - $budget->{'budget_parent_id'} ? $budget->{'budget_parent_id'} : undef, - $budget->{'budget_name'} ? $budget->{'budget_name'} : undef, - $budget->{'budget_branchcode'} ? $budget->{'budget_branchcode'} : undef, - $budget->{'budget_amount'} ? $budget->{'budget_amount'} : undef, - $budget->{'budget_amount_sublevel'} ? $budget->{'budget_amount_sublevel'} : undef, - $budget->{'budget_encumb'} ? $budget->{'budget_encumb'} : undef, - $budget->{'budget_expend'} ? $budget->{'budget_expend'} : undef, - $budget->{'budget_notes'} ? $budget->{'budget_notes'} : undef, - $budget->{'sort1_authcat'} ? $budget->{'sort1_authcat'} : undef, - $budget->{'sort2_authcat'} ? $budget->{'sort2_authcat'} : undef, - $budget->{'budget_owner_id'} ? $budget->{'budget_owner_id'} : undef, - $budget->{'budget_permission'} ? $budget->{'budget_permission'} : undef, - ); - $sth->finish; + my @keys; my @values; + + while ( my ($k,$v) = each %$budget ) { + next unless $v; + push @values, $v; + push @keys , "$k = ?"; + } + + my $query = do { + local $" = ','; + qq{ + INSERT INTO aqbudgets + SET @keys + }; + }; + + #warn $query; + my $sth = $dbh->prepare($query); + $sth->execute(@values); + return $dbh->{'mysql_insertid'}; } # ------------------------------------------------------------------- sub ModBudget { my ($budget) = @_; my $dbh = C4::Context->dbh; - my $query = qq| - UPDATE aqbudgets - SET budget_code = ?, - budget_period_id = ?, - budget_parent_id = ?, - budget_name = ?, - budget_branchcode = ?, - budget_amount = ?, - budget_amount_sublevel = ?, - budget_encumb = ?, - budget_expend = ?, - budget_notes = ?, - sort1_authcat = ?, - sort2_authcat = ?, - budget_owner_id = ?, - budget_permission = ? - WHERE budget_id = ? - |; + my $budgetid=$$budget{'budgetid'}; + delete $$budget{'budget_id'}; + + my @values; + my @keys; + + while ( my ($k,$v) = each %$budget ) { + next if (not $v and $k!~/sort1|note/); + #next if any { $_ eq $k } qw( sort1 note); + push @values, $v; + push @keys, "$k=?"; + } + + my $query = do { local $"=','; + qq{ + UPDATE aqbudgets + SET @keys + WHERE budget_id=? + }; + }; my $sth = $dbh->prepare($query); - $sth->execute( - $budget->{'budget_code'} ? $budget->{'budget_code'} : undef, - $budget->{'budget_period_id'} ? $budget->{'budget_period_id'} : undef, - $budget->{'budget_parent_id'} ? $budget->{'budget_parent_id'} : undef, - $budget->{'budget_name'} ? $budget->{'budget_name'} : undef, - $budget->{'budget_branchcode'} ? $budget->{'budget_branchcode'} : undef, - $budget->{'budget_amount'} ? $budget->{'budget_amount'} : undef, - $budget->{'budget_amount_sublevel'} ? $budget->{'budget_amount_sublevel'} : undef, - $budget->{'budget_encumb'} ? $budget->{'budget_encumb'} : undef, - $budget->{'budget_expend'} ? $budget->{'budget_expend'} : undef, - $budget->{'budget_notes'} ? $budget->{'budget_notes'} : undef, - $budget->{'sort1_authcat'} ? $budget->{'sort1_authcat'} : undef, - $budget->{'sort2_authcat'} ? $budget->{'sort2_authcat'} : undef, - $budget->{'budget_owner_id'} ? $budget->{'budget_owner_id'} : undef, - $budget->{'budget_permission'} ? $budget->{'budget_permission'} : undef, - $budget->{'budget_id'}, - ); - $sth->finish; + $sth->execute( @values,$budgetid); } # ------------------------------------------------------------------- diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 9741a8485f..ba56ed2a9b 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -27,7 +27,7 @@ use C4::Dates qw(format_date); use C4::SQLHelper qw(:all); use C4::Debug; use C4::Letters; -use List::MoreUtils qw(any); +use List::MoreUtils qw; use base 'Exporter'; # parent would be better there our $VERSION = 3.01; our @EXPORT = qw< @@ -201,7 +201,7 @@ sub GetSuggestion { =head2 GetSuggestionFromBiblionumber -$ordernumber = &GetSuggestionFromBiblionumber($dbh,$biblionumber) +$ordernumber = &GetSuggestionFromBiblionumber($biblionumber) Get a suggestion from it's biblionumber. @@ -211,12 +211,13 @@ the id of the suggestion which is related to the biblionumber given on input arg =cut sub GetSuggestionFromBiblionumber { - my ($dbh,$biblionumber) = @_; - my $query = qq| + my ($biblionumber) = @_; + my $query = q{ SELECT suggestionid FROM suggestions WHERE biblionumber=? - |; + }; + my $dbh=C4::Context->dbh; my $sth = $dbh->prepare($query); $sth->execute($biblionumber); my ($ordernumber) = $sth->fetchrow; @@ -344,7 +345,7 @@ sub CountSuggestion { =head2 NewSuggestion -&NewSuggestion($suggestion) +&NewSuggestion($suggestion); Insert a new suggestion on database with value given on input arg. diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl index 4ebf874624..b46287f09e 100755 --- a/acqui/acqui-home.pl +++ b/acqui/acqui-home.pl @@ -69,7 +69,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $borrower= GetMember('borrowernumber' => $loggedinuser); my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'}); -my @results = GetBookFunds($homebranch); +my @results = GetBudgets($homebranch); my $count = scalar @results; my $branchname = GetBranchName($homebranch); diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index f307e58268..33c99dab7d 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -224,7 +224,7 @@ if ($op eq 'add_form') { dateformat => C4::Dates->new()->visual(), budget_id => $budget->{'budget_id'}, budget_parent_id => $budget->{'budget_parent_id'}, - budget_dropbox => $budget_dropbox, + budget_dropbox => $budget_period_dropbox, budget_perm_dropbox => $budget_perm_dropbox, budget_code => $budget->{'budget_code'}, budget_code_indent => $budget->{'budget_code_indent'}, diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 7e7cf3d50f..b87639bf45 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2920,11 +2920,11 @@ INSERT INTO permissions (module_bit, code, description) VALUES (11, 'contracts_manage', 'Manage contracts'), (11, 'period_manage', 'Manage periods'), (11, 'budget_manage', 'Manage budgets'), - (11, 'budget_modify', "Modify budget (can't create lines, but can modify existing ones)"), + (11, 'budget_modify', "Modify budget (can't create lines but can modify existing ones)"), (11, 'planning_manage', 'Manage budget plannings'), (11, 'order_manage', 'Manage orders & basket'), (11, 'group_manage', 'Manage orders & basketgroups'), - (11, 'order_receive', 'Manage orders & basket') + (11, 'order_receive', 'Manage orders & basket'), (11, 'budget_add_del', "Add and delete budgets (but can't modify budgets)"); BUDG_PERM diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index c455e3f786..c2e3a49fbe 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -207,6 +207,11 @@ $template->param( #################### ## Initializing selection lists +#branch display management +my @bookfunds = GetBudgets($branchfilter||''); +map{$_->{'selected'}=1 if ($$suggestion_ref{'bookfundid'} && $_->{'bookfundid'} eq $$suggestion_ref{'bookfundid'})} @bookfunds; +$template->param( bookfundsloop => \@bookfunds); + #branch display management my $onlymine=C4::Context->preference('IndependantBranches') && C4::Context->userenv && -- 2.39.2