Fixed an encoding bug in the documentation
[koha.git] / C4 / Budgets.pm
index 24c4a90..eb97615 100644 (file)
@@ -13,9 +13,9 @@ package C4::Budgets;
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
 use C4::Context;
@@ -39,6 +39,7 @@ BEGIN {
         &ModBudget
         &DelBudget
         &GetBudgetSpent
+        &GetBudgetOrdered
         &GetPeriodsCount
 
            &GetBudgetPeriod
@@ -235,7 +236,7 @@ sub GetBudgetsPlanCell {
     $actual = $sth->fetchrow_array;
 
     # get the estimated amount
-    my $sth = $dbh->prepare( qq|
+    $sth = $dbh->prepare( qq|
 
         SELECT estimated_amount AS estimated, display FROM aqbudgets_planning
             WHERE budget_period_id = ? AND
@@ -300,9 +301,26 @@ sub GetBudgetSpent {
        my ($budget_id) = @_;
        my $dbh = C4::Context->dbh;
        my $sth = $dbh->prepare(qq|
-        SELECT SUM(ecost *  quantity  ) AS sum FROM aqorders
+        SELECT SUM(ecost *  quantity) AS sum FROM aqorders
             WHERE budget_id = ? AND
-            datecancellationprinted IS NULL 
+            quantityreceived > 0 AND
+            datecancellationprinted IS NULL
+    |);
+
+       $sth->execute($budget_id);
+       my $sum =  $sth->fetchrow_array;
+       return $sum;
+}
+
+# -------------------------------------------------------------------
+sub GetBudgetOrdered {
+       my ($budget_id) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth = $dbh->prepare(qq|
+        SELECT SUM(ecost *  quantity) AS sum FROM aqorders
+            WHERE budget_id = ? AND
+            quantityreceived = 0 AND
+            datecancellationprinted IS NULL
     |);
 
        $sth->execute($budget_id);
@@ -318,6 +336,7 @@ sub GetBudgetPermDropbox {
        $labels{'1'} = 'Owner';
        $labels{'2'} = 'Library';
        my $radio = CGI::scrolling_list(
+               -id       => 'budget_permission',
                -name      => 'budget_permission',
                -values    => [ '0', '1', '2' ],
                -default   => $perm,
@@ -477,7 +496,7 @@ sub GetBudgetHierarchy {
        # show only budgets owned by me, my branch or everyone
     if ($owner) {
         if ($branchcode) {
-            push @where_strings,qq{ (budget_owner_id = ? OR budget_branchcode = ? OR (budget_branchcode IS NULL or budget_branchcode="" AND (budget_owner_id IS NULL OR budget_owner_id=""))};
+            push @where_strings,qq{ (budget_owner_id = ? OR budget_branchcode = ? OR (budget_branchcode IS NULL or budget_branchcode="" AND (budget_owner_id IS NULL OR budget_owner_id="")))};
             push @bind_params, ($owner, $branchcode);
         } else {
             push @where_strings, ' (budget_owner_id = ? OR budget_owner_id IS NULL or budget_owner_id ="") ';
@@ -489,7 +508,7 @@ sub GetBudgetHierarchy {
             push @bind_params, $branchcode;
         }
     }
-       $query.=" WHERE ".join(' AND ', @where_strings);
+       $query.=" WHERE ".join(' AND ', @where_strings) if @where_strings;
        $debug && warn $query,join(",",@bind_params);
        my $sth = $dbh->prepare($query);
        $sth->execute(@bind_params);
@@ -517,8 +536,8 @@ sub GetBudgetHierarchy {
        }
 
        # look for top parents 1st
-       my @sort;
-       my ($i, $depth_count) = 0;
+       my (@sort, $depth_count);
+       ($i, $depth_count) = 0;
        while (1) {
                my $children = 0;
                foreach my $r (@res) {
@@ -568,7 +587,7 @@ sub GetBudgetHierarchy {
         $moo =~ s/\ /\&nbsp\;/g;
         $r->{'budget_code_indent'} =  $moo;
 
-        my $moo = $r->{'budget_name_indent'};
+        $moo = $r->{'budget_name_indent'};
         $moo =~ s/\ /\&nbsp\;/g;
         $r->{'budget_name_indent'} = $moo;
 
@@ -611,14 +630,14 @@ sub DelBudget {
        return $rc;
 }
 
-=back
-
 =head2 FUNCTIONS ABOUT BUDGETS
 
 =over 2
 
 =cut
 
+=back
+
 =head3 GetBudget
 
 =over 4
@@ -635,7 +654,6 @@ get a specific budget
 sub GetBudget {
     my ( $budget_id ) = @_;
     my $dbh = C4::Context->dbh;
-    my $query;
     my $query = "
         SELECT *
         FROM   aqbudgets
@@ -662,7 +680,7 @@ gets all budgets
 # -------------------------------------------------------------------
 sub GetBudgets {
     my ($filters,$orderby) = @_;
-    return SearchInTable("aqbudgetperiods",$filters, $orderby, undef,undef, undef, "wide");
+    return SearchInTable("aqbudgets",$filters, $orderby, undef,undef, undef, "wide");
 }
 
 # -------------------------------------------------------------------
@@ -755,9 +773,12 @@ sub ConvertCurrency {
     return ( $price / $cur );
 }
 
-=item
+=head3 _columns
+
        returns an array containing fieldname followed by PRI as value if PRIMARY Key
+
 =cut
+
 sub _columns(;$) {
        my $tablename=shift||"aqbudgets";
     return @{C4::Context->dbh->selectcol_arrayref("SHOW columns from $tablename",{Columns=>[1,4]})};
@@ -788,8 +809,6 @@ END { }    # module clean-up code here (global destructor)
 1;
 __END__
 
-=back
-
 =head1 AUTHOR
 
 Koha Developement team <info@koha.org>