Bug 15758: Koha::Libraries - Remove GetBranches
[srvgit] / suggestion / suggestion.pl
index e772a2a..472ab64 100755 (executable)
@@ -25,13 +25,14 @@ use C4::Auth;    # get_template_and_user
 use C4::Output;
 use C4::Suggestions;
 use C4::Koha; #GetItemTypes
-use C4::Branch;
 use C4::Budgets;
 use C4::Search;
 use C4::Members;
 use C4::Debug;
 
 use Koha::DateUtils qw( dt_from_string );
+use Koha::Acquisition::Currencies;
+use Koha::Libraries;
 
 use URI::Escape;
 
@@ -59,7 +60,8 @@ sub GetCriteriumDesc{
         }
         return ($criteriumvalue eq 'ASKED'?"Pending":ucfirst(lc( $criteriumvalue))) if ($displayby =~/status/i);
     }
-    return (GetBranchName($criteriumvalue)) if ($displayby =~/branchcode/);
+    return Koha::Libraries->find($criteriumvalue)->branchname
+        if $displayby =~ /branchcode/;
     return GetAuthorisedValueByCode('SUGGEST_FORMAT', $criteriumvalue) || "Unknown" if ($displayby =~/itemtype/);
     if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){
         my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
@@ -77,7 +79,7 @@ my $input           = CGI->new;
 my $redirect  = $input->param('redirect');
 my $suggestedbyme   = (defined $input->param('suggestedbyme')? $input->param('suggestedbyme'):1);
 my $op              = $input->param('op')||'else';
-my @editsuggestions = $input->param('edit_field');
+my @editsuggestions = $input->multi_param('edit_field');
 my $suggestedby     = $input->param('suggestedby');
 my $returnsuggestedby = $input->param('returnsuggestedby');
 my $returnsuggested = $input->param('returnsuggested');
@@ -166,7 +168,7 @@ elsif ($op=~/edit/) {
 }  
 elsif ($op eq "change" ) {
     # set accepted/rejected/managed informations if applicable
-    # ie= if the librarian has choosen some action on the suggestions
+    # ie= if the librarian has chosen some action on the suggestions
     if ($suggestion_only->{"STATUS"} eq "ACCEPTED"){
         $suggestion_only->{accepteddate} = dt_from_string;
         $suggestion_only->{"acceptedby"}=C4::Context->userenv->{number};
@@ -212,7 +214,6 @@ elsif ($op eq "change" ) {
 }
 elsif ( $op eq 'show' ) {
     $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'});
-    $$suggestion_ref{branchname} = GetBranchName $$suggestion_ref{branchcode};
     my $budget = GetBudget $$suggestion_ref{budgetid};
     $$suggestion_ref{budgetname} = $$budget{budget_name};
     Init($suggestion_ref);
@@ -232,7 +233,7 @@ if ($op=~/else/) {
             $criteria_has_empty = 1;
         }
     }
-    # agregate null and empty values under empty value
+    # aggregate null and empty values under empty value
     push @criteria_dv, '' if $criteria_has_empty;
 
     my @allsuggestions;
@@ -297,35 +298,15 @@ if(defined($returnsuggested) and $returnsuggested ne "noone")
     print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
 }
 
-####################
-## Initializing selection lists
-
-#branch display management
-my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : '';
-my $onlymine =
-     C4::Context->preference('IndependentBranches')
-  && C4::Context->userenv
-  && !C4::Context->IsSuperLibrarian()
-  && C4::Context->userenv->{branch};
-my $branches = GetBranches($onlymine);
-my @branchloop;
-
-foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) {
-    my %row = (
-        value      => $thisbranch,
-        branchname => $branches->{$thisbranch}->{'branchname'},
-        selected   => ($branchfilter and $branches->{$thisbranch}->{'branchcode'} eq $branchfilter ) || ( $$suggestion_ref{'branchcode'} and $branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'} )
-    );
-    push @branchloop, \%row;
-}
-$branchfilter=C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
+my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : C4::Context->userenv->{'branch'};
 
-$template->param( branchloop => \@branchloop,
-                branchfilter => $branchfilter);
+$template->param(
+    branchfilter => $branchfilter,
+);
 
 $template->param( returnsuggestedby => $returnsuggestedby );
 
-my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG",$$suggestion_ref{'patronreason'});
+my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
 $template->param(patron_reason_loop=>$patron_reason_loop);
 
 #Budgets management
@@ -352,28 +333,10 @@ foreach my $budget ( @{$budgets} ) {
 $template->param( budgetsloop => \@budgets_loop);
 $template->param( "statusselected_$$suggestion_ref{'STATUS'}" =>1) if ($$suggestion_ref{'STATUS'});
 
-# get currencies and rates
-my @rates = GetCurrencies();
-my $count = scalar @rates;
-my $active_currency = GetCurrency();
-my $selected_currency;
-if ($$suggestion_ref{'currency'}) {
-    $selected_currency = $$suggestion_ref{'currency'};
-}
-else {
-    $selected_currency = $active_currency->{currency};
-}
-
-my @loop_currency = ();
-for ( my $i = 0 ; $i < $count ; $i++ ) {
-    my %line;
-    $line{currcode} = $rates[$i]->{'currency'};
-    $line{rate}     = $rates[$i]->{'rate'};
-    $line{selected} = 1 if ($line{'currcode'} eq $selected_currency);
-    push @loop_currency, \%line;
-}
+my @currencies = Koha::Acquisition::Currencies->search;
 $template->param(
-    loop_currency => \@loop_currency,
+    currencies   => \@currencies,
+    suggestion   => $suggestion_ref,
     price        => sprintf("%.2f", $$suggestion_ref{'price'}||0),
     total            => sprintf("%.2f", $$suggestion_ref{'total'}||0),
 );