Bug 7509: Added index on items itemcallnumber
[koha_gimpoz] / suggestion / suggestion.pl
index ea3fbf5..272ca6f 100755 (executable)
@@ -59,7 +59,7 @@ sub GetCriteriumDesc{
     if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){
         my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
         return "" unless $borr;
-        return $$borr{firstname} . ", " . $$borr{surname};
+        return $$borr{surname} . ", " . $$borr{firstname};
     }
     if ( $displayby =~ /budgetid/) {
         my $budget = GetBudget($criteriumvalue);
@@ -189,7 +189,10 @@ if ($op=~/else/) {
     
         my $suggestions = &SearchSuggestion($suggestion_ref);
         foreach my $suggestion (@$suggestions){
-            $suggestion->{budget_name}=GetBudget($suggestion->{budgetid})->{budget_name} if $suggestion->{budgetid};
+            if($suggestion->{budgetid}) {
+                my $budget = GetBudget($suggestion->{budgetid});
+                $suggestion->{budget_name}=$budget->{budget_name} if $budget;
+            }
             foreach my $date qw(suggesteddate manageddate accepteddate){
                 if ($suggestion->{$date} ne "0000-00-00" && $suggestion->{$date} ne "" ){
                 $suggestion->{$date}=format_date($suggestion->{$date}) ;
@@ -285,10 +288,16 @@ my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG",$$suggestion_ref{'patron
 $template->param(patron_reason_loop=>$patron_reason_loop);
 
 #Budgets management
-my $searchbudgets={ budget_branchcode=>$branchfilter} if $branchfilter;
-my $budgets = GetBudgets($searchbudgets);
+my $budgets = [];
+if ($branchfilter) {
+    my $searchbudgets = { budget_branchcode => $branchfilter };
+    $budgets = GetBudgets($searchbudgets);
+} else {
+    $budgets = GetBudgets(undef);
+}
 
-foreach my $budget (@$budgets){
+foreach my $budget ( @{$budgets} ) {
+## Please see file perltidy.ERR
     $budget->{'selected'}=1 if ($$suggestion_ref{'budgetid'} && $budget->{'budget_id'} eq $$suggestion_ref{'budgetid'})
 };
 
@@ -298,13 +307,21 @@ $template->param( "statusselected_$$suggestion_ref{'STATUS'}" =>1);
 # 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 ($$suggestion_ref{'currency'} && $line{'currcode'} eq $$suggestion_ref{'currency'});
+       $line{selected} = 1 if ($line{'currcode'} eq $selected_currency);
     push @loop_currency, \%line;
 }