Fix for Bug 1951, OPACURLOpenInNewWindow doesn't do anything.
[koha.git] / C4 / Overdues.pm
index 5cfd758..9db5c6d 100644 (file)
@@ -1,6 +1,5 @@
 package C4::Overdues;
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -20,40 +19,21 @@ package C4::Overdues;
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-require Exporter;
-use C4::Context;
 use Date::Calc qw/Today/;
-use vars qw($VERSION @ISA @EXPORT);
-use C4::Accounts;
 use Date::Manip qw/UnixDate/;
+use C4::Context;
+use C4::Accounts;
 use C4::Log; # logaction
 
-# set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g; 
-shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
-
-=head1 NAME
-
-C4::Circulation::Fines - Koha module dealing with fines
-
-=head1 SYNOPSIS
-
-  use C4::Overdues;
-
-=head1 DESCRIPTION
-
-This module contains several functions for dealing with fines for
-overdue items. It is primarily used by the 'misc/fines2.pl' script.
-
-=head1 FUNCTIONS
-
-=over 2
-
-=cut
+use vars qw($VERSION @ISA @EXPORT);
 
-@ISA    = qw(Exporter);
-# subs to rename (and maybe merge some...)
-push @EXPORT, qw(
+BEGIN {
+       # set the version for version checking
+       $VERSION = 3.01;
+       require Exporter;
+       @ISA    = qw(Exporter);
+       # subs to rename (and maybe merge some...)
+       push @EXPORT, qw(
         &CalcFine
         &Getoverdues
         &checkoverdues
@@ -76,31 +56,47 @@ push @EXPORT, qw(
         &GetOverduesForBranch
         &RemoveNotifyLine
         &AddNotifyLine
-);
-# subs to remove
-push @EXPORT, qw(
+       );
+       # subs to remove
+       push @EXPORT, qw(
         &BorType
-);
+       );
 
-#
-# All subs to move : check that an equivalent don't exist already before moving
-#
+       # check that an equivalent don't exist already before moving
 
-# subs to move to Circulation.pm
-push @EXPORT, qw(
+       # subs to move to Circulation.pm
+       push @EXPORT, qw(
         &GetIssuingRules
         &GetIssuesIteminfo
-);
-# subs to move to Members.pm
-push @EXPORT, qw(
+       );
+       # subs to move to Members.pm
+       push @EXPORT, qw(
         &CheckBorrowerDebarred
         &UpdateBorrowerDebarred
-);
-# subs to move to Biblio.pm
-push @EXPORT, qw(
+       );
+       # subs to move to Biblio.pm
+       push @EXPORT, qw(
         &GetItems
         &ReplacementCost
-);
+       );
+}
+
+=head1 NAME
+
+C4::Circulation::Fines - Koha module dealing with fines
+
+=head1 SYNOPSIS
+
+  use C4::Overdues;
+
+=head1 DESCRIPTION
+
+This module contains several functions for dealing with fines for
+overdue items. It is primarily used by the 'misc/fines2.pl' script.
+
+=head1 FUNCTIONS
+
+=over 2
 
 =item Getoverdues
 
@@ -117,15 +113,19 @@ Koha database.
 #'
 sub Getoverdues {
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare(
-        "SELECT issues.*,biblioitems.itemtype FROM issues 
-                LEFT JOIN items USING (itemnumber)
-                LEFT JOIN biblioitems USING (biblioitemnumber)
-                WHERE date_due < now() 
-                    AND returndate IS 
-                    NULL ORDER BY borrowernumber 
-        "
-    );
+    my $sth =  (C4::Context->preference('item-level_itypes')) ? 
+                               $dbh->prepare(
+                               "SELECT issues.*,items.itype as itemtype FROM issues 
+                        LEFT JOIN items USING (itemnumber)
+                        WHERE date_due < now() 
+                        ORDER BY borrowernumber " )
+                               :
+                               $dbh->prepare(
+                    "SELECT issues.*,biblioitems.itemtype,items.itype FROM issues 
+                     LEFT JOIN items USING (itemnumber)
+                     LEFT JOIN biblioitems USING (biblioitemnumber)
+                     WHERE date_due < now() 
+                     ORDER BY borrowernumber " );
     $sth->execute;
 
     my @results;
@@ -161,7 +161,6 @@ sub checkoverdues {
          LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
          LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
             WHERE issues.borrowernumber  = ?
-                AND issues.returndate is NULL
                 AND issues.date_due < ?"
     );
     $sth->execute( $borrowernumber, $today );
@@ -692,9 +691,9 @@ return $result;
 }
 
 
-=item AmountNotify
+=item NumberNotifyId
 
-(@notify) = &AmountNotify($borrowernumber);
+(@notify) = &NumberNotifyId($borrowernumber);
 
 Returns amount for all file per borrowers
 C<@notify> array contains all file per borrowers
@@ -730,19 +729,19 @@ C<$notifyid> is the file number
 
 C<$totalnotify> contains amount of a file
 
-C<$notify_id> contains the file number for the borrower number nad item number
+C<$notify_id> contains the file number for the borrower number and item number
 
 =cut
 
 sub AmountNotify{
-    my ($notifyid)=@_;
+    my ($notifyid,$borrowernumber)=@_;
     my $dbh = C4::Context->dbh;
     my $query=qq|    SELECT sum(amountoutstanding)
             FROM accountlines
-            WHERE notify_id=?|;
+            WHERE notify_id=? AND borrowernumber = ?|;
     my $sth=$dbh->prepare($query);
-        $sth->execute($notifyid);
-          my $totalnotify=$sth->fetchrow;
+       $sth->execute($notifyid,$borrowernumber);
+       my $totalnotify=$sth->fetchrow;
     $sth->finish;
     return ($totalnotify);
 }
@@ -1146,6 +1145,7 @@ display is filtered by branch
 
 sub GetOverduesForBranch {
     my ( $branch, $location) = @_;
+       my $itype_link =  (C4::Context->preference('item-level_itypes')) ?  " items.itype " :  " biblioitems.itemtype ";
     if ( not $location ) {
         my $dbh = C4::Context->dbh;
         my $sth = $dbh->prepare("
@@ -1175,10 +1175,9 @@ sub GetOverduesForBranch {
             LEFT JOIN items ON items.itemnumber = issues.itemnumber
             LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
             LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber
-            LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
+            LEFT JOIN itemtypes ON itemtypes.itemtype = $itype_link
             LEFT JOIN branches ON branches.branchcode = issues.branchcode
-            WHERE ( issues.returndate  is null)
-              AND ( accountlines.amountoutstanding  != '0.000000')
+            WHERE ( accountlines.amountoutstanding  != '0.000000')
               AND ( accountlines.accounttype  = 'FU')
               AND (issues.branchcode = ?)
               AND (issues.date_due <= NOW())
@@ -1226,10 +1225,9 @@ sub GetOverduesForBranch {
             LEFT JOIN items ON items.itemnumber = issues.itemnumber
             LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
             LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber
-            LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
+            LEFT JOIN itemtypes ON itemtypes.itemtype = $itype_link
             LEFT JOIN branches ON branches.branchcode = issues.branchcode
-           WHERE ( issues.returndate  is null )
-             AND ( accountlines.amountoutstanding  != '0.000000')
+           WHERE ( accountlines.amountoutstanding  != '0.000000')
              AND ( accountlines.accounttype  = 'FU')
              AND (issues.branchcode = ? AND items.location = ?)
              AND (issues.date_due <= NOW())