bug 4182: add emailLibrarianWhenHoldIsPlaced to preferences editor
[koha_gimpoz] / acqui / acqui-home.pl
index 291383e..f8cb78e 100755 (executable)
@@ -25,8 +25,6 @@ acqui-home.pl
 =head1 DESCRIPTION
 
 this script is the main page for acqui/
-It presents the budget's dashboard, another table about differents currency with
-their rates and the pending suggestions.
 
 =head1 CGI PARAMETERS
 
@@ -41,6 +39,7 @@ thus, it can be REJECTED, ACCEPTED, ORDERED, ASKED, AVAIBLE
 =cut
 
 use strict;
+use warnings;
 use Number::Format;
 
 use CGI;
@@ -73,10 +72,10 @@ my @results = GetBudgets($homebranch);
 my $count = scalar @results;
 my $branchname = GetBranchName($homebranch);
 
-#my $count = scalar @results;
 my $classlist   = '';
 my $total       = 0;
 my $totspent    = 0;
+my $totordered  = 0;
 my $totcomtd    = 0;
 my $totavail    = 0;
 my @loop_budget = ();
@@ -84,8 +83,6 @@ my @loop_budget = ();
 # ---------------------------------------------------
 # currencies
 my $cur;
-my @rates = GetCurrencies();
-$count = scalar @rates;
 
 my $active_currency = GetCurrency;
 my $num;
@@ -108,15 +105,6 @@ if ( $cur_format eq 'FR' ) {
     );
 }
 
-my @loop_currency = ();
-for ( my $i = 0 ; $i < $count ; $i++ ) {
-    my %line;
-    $line{currency}        = $rates[$i]->{'currency'} ;
-    $line{currency_symbol} = $rates[$i]->{'symbol'};
-    $line{rate}            = sprintf ( '%.2f',  $rates[$i]->{'rate'} );
-    push @loop_currency, \%line;
-}
-
 # suggestions
 my $status           = $query->param('status') || "ASKED";
 my $suggestion       = CountSuggestion($status);
@@ -145,26 +133,40 @@ foreach my $result (@results) {
     my $r = GetBranchName( $result->{'budget_owner_id'} );
     $result->{'budget_branchname'} = GetBranchName( $result->{'budget_branchcode'} );
 
-    my $member      = GetMember( $result->{'budget_owner_id'} );
-    my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'};
+    my $member      = GetMember( borrowernumber => $result->{budget_owner_id} );
+    my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'} if $member;
+    # as we are going to treat these as numbers let's ensure they are not NULL
+    if (!defined $result->{budget_amount} ) {
+        $result->{budget_amount} = 0;
+    }
+    if (!defined $result->{budget_spent} ) {
+        $result->{budget_spent} = 0;
+    }
+    if (!defined $result->{budget_ordered} ) {
+        $result->{budget_ordered} = 0;
+    }
 
-    $result->{'budget_owner'} = $member_full;
-    $result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'};
-    $result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} );
+    $result->{'budget_owner'}   = $member_full;
+    $result->{'budget_ordered'} = GetBudgetOrdered( $result->{'budget_id'} );
+    $result->{'budget_spent'}   = GetBudgetSpent( $result->{'budget_id'} );
+    $result->{'budget_avail'}   = $result->{'budget_amount'} - $result->{'budget_spent'} - $result->{'budget_ordered'};
 
-    $total    += $result->{'budget_amount'};
-    $totspent += $result->{'budget_spent'};
-    $totavail += $result->{'budget_avail'};
+    $total      += $result->{'budget_amount'};
+    $totspent   += $result->{'budget_spent'};
+    $totordered += $result->{'budget_ordered'};
+    $totavail   += $result->{'budget_avail'};
 
-    $result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} );
-    $result->{'budget_spent'}  = $num->format_price( $result->{'budget_spent'} );
-    $result->{'budget_avail'}  = $num->format_price( $result->{'budget_avail'} );
+    $result->{'budget_amount'}  = $num->format_price( $result->{'budget_amount'} );
+    $result->{'budget_spent'}   = $num->format_price( $result->{'budget_spent'} );
+    $result->{'budget_ordered'} = $num->format_price( $result->{'budget_ordered'} );
+    $result->{'budget_avail'}   = $num->format_price( $result->{'budget_avail'} );
 
     #        my $spent_percent = ( $result->{'budget_spent'} / $result->{'budget_amount'} ) * 100;
     #        $result->{'budget_spent_percent'} = sprintf( "%00d", $spent_percent );
 
-    my $borrower = &GetMember( $result->{budget_owner_id} );
-    $result->{budget_owner_name} = $borrower->{'firstname'} . ' ' . $borrower->{'surname'};
+    if ($member) {
+        $result->{budget_owner_name} = $member->{'firstname'} . ' ' . $member->{'surname'};
+    }
 
     push( @loop_budget, { %{$result}, toggle => $toggle++ % 2, } );
 }
@@ -173,12 +175,12 @@ $template->param(
     classlist     => $classlist,
     type          => 'intranet',
     loop_budget   => \@loop_budget,
-    loop_currency => \@loop_currency,
     active_symbol => $active_currency->{'symbol'},
     branchname    => $branchname,
     budget        => $period->{budget_name},
     total         => $num->format_price(  $total ),
-    totspent      => $num->format_price($totspent ),
+    totspent      => $num->format_price( $totspent ),
+    totordered    => $num->format_price( $totordered ),
     totcomtd      => $num->format_price( $totcomtd ),
     totavail      => $num->format_price( $totavail ),
     suggestion    => $suggestion,