Bug 5861: items.stocknumber not saved correctly
[koha_fer] / suggestion / suggestion.pl
index ce79197..26863f3 100755 (executable)
@@ -57,9 +57,13 @@ sub GetCriteriumDesc{
     if ($displayby =~/managedby/||$displayby =~/acceptedby/){
         my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
         return "" unless $borr;
-#              warn '$borr : ',Data::Dumper::Dumper($borr);
-        return $$borr{firstname}.", ".$$borr{surname};
-    }  
+        return $$borr{firstname} . ", " . $$borr{surname};
+    }
+    if ( $displayby =~ /budgetid/) {
+        my $budget = GetBudget($criteriumvalue);
+        return "" unless $budget;
+        return $$budget{budget_name};
+    }
 }
 
 my $input           = CGI->new;
@@ -167,12 +171,13 @@ if ($op=~/else/) {
 #        warn $$suggestion_ref{$displayby}."=$criteriumvalue; $displayby";
     
         my $suggestions = &SearchSuggestion($suggestion_ref);
-        foreach (@$suggestions){
+        foreach my $suggestion (@$suggestions){
+            $suggestion->{budget_name}=GetBudget($suggestion->{budgetid})->{budget_name} if $suggestion->{budgetid};
             foreach my $date qw(suggesteddate manageddate accepteddate){
-                if ($_->{$date} ne "0000-00-00" && $_->{$date} ne "" ){
-                $_->{$date}=format_date($_->{$date}) ;
+                if ($suggestion->{$date} ne "0000-00-00" && $suggestion->{$date} ne "" ){
+                $suggestion->{$date}=format_date($suggestion->{$date}) ;
                 } else {
-                $_->{$date}="" ;
+                $suggestion->{$date}="" ;
                 }             
             }    
         }
@@ -244,7 +249,7 @@ $template->param( branchloop => \@branchloop,
 # the index parameter is different for item-level itemtypes
 my $supportlist=GetSupportList();                              
 foreach my $support(@$supportlist){
-    $$support{'selected'}= $$support{'code'} eq $$suggestion_ref{'itemtype'};
+    $$support{'selected'}= $$support{'itemtype'} eq $$suggestion_ref{'itemtype'};
     if ($$support{'imageurl'}){
         $$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} );
     }
@@ -254,18 +259,41 @@ foreach my $support(@$supportlist){
 }
 $template->param(itemtypeloop=>$supportlist);
 
+my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG",$$suggestion_ref{'patronreason'});
+$template->param(patron_reason_loop=>$patron_reason_loop);
+
 #Budgets management
 my $searchbudgets={ budget_branchcode=>$branchfilter} if $branchfilter;
 my $budgets = GetBudgets($searchbudgets);
 
-foreach (@$budgets){
-    $_->{'selected'}=1 if ($$suggestion_ref{'budget_id'} && $_{'budget_id'} eq $$suggestion_ref{'budget_id'})
+foreach my $budget (@$budgets){
+    $budget->{'selected'}=1 if ($$suggestion_ref{'budgetid'} && $budget->{'budget_id'} eq $$suggestion_ref{'budgetid'})
 };
 
 $template->param( budgetsloop => $budgets);
 
-my %hashlists; 
-foreach my $field qw(managedby acceptedby suggestedby STATUS){
+# get currencies and rates
+my @rates = GetCurrencies();
+my $count = scalar @rates;
+
+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'});
+    push @loop_currency, \%line;
+}
+
+$template->param(loop_currency => \@loop_currency);
+
+$template->param(
+       price        => sprintf("%.2f", $$suggestion_ref{'price'}||0),
+       total            => sprintf("%.2f", $$suggestion_ref{'total'}||0),
+);
+
+my %hashlists;
+foreach my $field qw(managedby acceptedby suggestedby budgetid STATUS) {
     my $values_list;
     $values_list=GetDistinctValues("suggestions.".$field) ;
     my @codes_list = map{
@@ -277,5 +305,5 @@ foreach my $field qw(managedby acceptedby suggestedby STATUS){
     $hashlists{lc($field)."_loop"}=\@codes_list;
 }
 $template->param(%hashlists);
-
+$template->param(DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),);
 output_html_with_http_headers $input, $cookie, $template->output;