Merging changes from rel-1-2 into trunk (circulation module only)
authortonnesen <tonnesen>
Thu, 24 Oct 2002 18:30:17 +0000 (18:30 +0000)
committertonnesen <tonnesen>
Thu, 24 Oct 2002 18:30:17 +0000 (18:30 +0000)
C4/Circulation/Circ2.pm
circ/branchtransfers.pl
circ/circulation.pl
circ/selectbranchprinter.pl

index fa4bd3c..ab5c59e 100755 (executable)
@@ -5,7 +5,6 @@ package C4::Circulation::Circ2;
 #package to deal with Returns
 #written 3/11/99 by olwen@katipo.co.nz
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -247,10 +246,21 @@ sub getpatroninformation {
     $sth = $dbh->prepare($query);
     $sth->execute;
     my $borrower = $sth->fetchrow_hashref;
+    my $amount = checkaccount($env, $borrowernumber, $dbh);
+    $borrower->{'amountoutstanding'} = $amount;
     my $flags = patronflags($env, $borrower, $dbh);
+    my $accessflagshash;
+
+    $sth=$dbh->prepare("select bit,flag from userflags");
+    $sth->execute;
+    while (my ($bit, $flag) = $sth->fetchrow) {
+       if ($borrower->{'flags'} & 2**$bit) {
+           $accessflagshash->{$flag}=1;
+       }
+    }
     $sth->finish;
     $borrower->{'flags'}=$flags;
-    return($borrower, $flags);
+    return ($borrower, $flags, $accessflagshash);
 }
 
 =item decode
@@ -723,7 +733,7 @@ sub issuebook {
            last SWITCH;
        }
        if ($iteminformation->{'notforloan'} == 1) {
-           $rejected="Reference item: not for loan.";
+           $rejected="Item not for loan.";
            last SWITCH;
        }
        if ($iteminformation->{'wthdrawn'} == 1) {
@@ -734,8 +744,10 @@ sub issuebook {
            $rejected="Restricted item.";
            last SWITCH;
        }
-
-       # See who, if anyone, currently has this book.
+       if ($iteminformation->{'itemtype'} eq 'REF') {
+           $rejected="Reference item:  Not for loan.";
+           last SWITCH;
+       }
        my ($currentborrower) = currentborrower($iteminformation->{'itemnumber'});
        if ($currentborrower eq $patroninformation->{'borrowernumber'}) {
 # Already issued to current borrower. Ask whether the loan should
@@ -1012,6 +1024,7 @@ sub returnbook {
 # find reserves.....
     my ($resfound, $resrec) = CheckReserves($iteminformation->{'itemnumber'});
     if ($resfound) {
+       my $tobrcd = ReserveWaiting($resrec->{'itemnumber'}, $resrec->{'borrowernumber'});
        $resrec->{'ResFound'} = $resfound;
        $messages->{'ResFound'} = $resrec;
     }
@@ -1485,21 +1498,28 @@ sub getissues {
     my ($borrower) = @_;
     my $dbh = C4::Context->dbh;
     my $borrowernumber = $borrower->{'borrowernumber'};
-    my $brn =$dbh->quote($borrowernumber);
     my %currentissues;
-    my $select = "select issues.timestamp, issues.date_due, items.biblionumber,
-                         items.barcode, biblio.title, biblio.author, biblioitems.dewey,
-                         biblioitems.subclass
-                    from issues,items,biblioitems,biblio
-                   where issues.borrowernumber = $brn
-                     and issues.itemnumber = items.itemnumber
-                     and items.biblionumber = biblio.biblionumber
-                     and items.biblioitemnumber = biblioitems.biblioitemnumber
-                     and issues.returndate is null
-                         order by issues.date_due";
-#    warn $select;
+    my $select = "SELECT issues.timestamp      AS timestamp, 
+                         issues.date_due       AS date_due, 
+                         items.biblionumber    AS biblionumber,
+                         items.itemnumber    AS itemnumber,
+                         items.barcode         AS barcode, 
+                         biblio.title          AS title, 
+                         biblio.author         AS author, 
+                         biblioitems.dewey     AS dewey, 
+                         itemtypes.description AS itemtype,
+                         biblioitems.subclass  AS subclass
+                    FROM issues,items,biblioitems,biblio, itemtypes
+                   WHERE issues.borrowernumber  = ?
+                     AND issues.itemnumber      = items.itemnumber 
+                     AND items.biblionumber     = biblio.biblionumber 
+                     AND items.biblioitemnumber = biblioitems.biblioitemnumber 
+                     AND itemtypes.itemtype     = biblioitems.itemtype
+                     AND issues.returndate      IS NULL
+                ORDER BY issues.date_due";
+#    print $select;
     my $sth=$dbh->prepare($select);
-    $sth->execute;
+    $sth->execute($borrowernumber);
     my $counter = 0;
     while (my $data = $sth->fetchrow_hashref) {
        $data->{'dewey'} =~ s/0*$//;
@@ -1558,18 +1578,18 @@ sub checkaccount  {
   #take borrower number
   #check accounts and list amounts owing
   my ($env,$bornumber,$dbh,$date)=@_;
-  my $select="Select sum(amountoutstanding) from accountlines where
-  borrowernumber=$bornumber and amountoutstanding<>0";
+  my $select="SELECT SUM(amountoutstanding) AS total
+                FROM accountlines 
+               WHERE borrowernumber = $bornumber 
+                 AND amountoutstanding<>0";
   if ($date ne ''){
-    $select.=" and date < '$date'";
+    $select.=" AND date < '$date'";
   }
 #  print $select;
   my $sth=$dbh->prepare($select);
   $sth->execute;
-  my $total=0;
-  while (my $data=$sth->fetchrow_hashref){
-    $total += $data->{'sum(amountoutstanding)'};
-  }
+  my $data=$sth->fetchrow_hashref;
+  my $total = $data->{'total'};
   $sth->finish;
   # output(1,2,"borrower owes $total");
   #if ($total > 0){
@@ -1701,7 +1721,7 @@ sub calc_charges {
     }
     $sth1->finish;
 #    close FILE;
-    return ($charge);
+    return ($charge, $itemtype);
 }
 
 # FIXME - A virtually identical function appears in
index d2f0e98..70990a0 100755 (executable)
@@ -26,6 +26,7 @@ use CGI;
 use C4::Circulation::Circ2;
 use C4::Output;
 use C4::Reserves2;
+use C4::Auth;
 
 ###############################################
 # constants
@@ -46,6 +47,7 @@ my $printers = getprinters(\%env);
 #  Getting state
 
 my $query=new CGI;
+my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
 
 
 my $branch = $query->param("branch");
@@ -55,6 +57,9 @@ my $printer = $query->param("printer");
 ($branch) || ($branch=$query->cookie('branch')) ;
 ($printer) || ($printer=$query->cookie('printer')) ;
 
+($branches->{$branch}) || ($branch=(keys %$branches)[0]);
+($printers->{$printer}) || ($printer=(keys %$printers)[0]);
+
 my $request=$query->param('request');
 
 
@@ -64,10 +69,7 @@ my $frbranchcd='';
 # set up the branchselect options....
 my $tobranchoptions;
 foreach my $br (keys %$branches) {
-# FIXME - Dunno what this line was supposed to do, but "CU" never
-# appears anywhere else, so this was preventing this code from
-# working, by creating an empty <select> block later on.
-#    (next) unless $branches->{$br}->{'CU'};
+    (next) unless $branches->{$br}->{'CU'};
     my $selected='';
     ($selected='selected') if ($br eq $tobranchcd);
     $tobranchoptions.="<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
@@ -296,7 +298,7 @@ EOF
 #######################################################################################
 # Make the page .....
 
-print $query->header;
+print $query->header(-cookie=>$sessioncookie);
 print startpage;
 #print startmenu('circulation');
 my @inp=startmenu('circulation');
index 1851f6a..c92b5cd 100755 (executable)
@@ -27,6 +27,12 @@ use C4::Circulation::Circ2;
 use C4::Search;
 use C4::Output;
 use C4::Print;
+use DBI;
+use C4::Auth;
+
+my $query=new CGI;
+my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
+
 
 my %env;
 my $headerbackgroundcolor='#99cc33';
@@ -47,6 +53,11 @@ my $printer = $query->param("printer");
 ($branch) || ($branch=$query->cookie('branch')) ;
 ($printer) || ($printer=$query->cookie('printer')) ;
 
+($branches->{$branch}) || ($branch=(keys %$branches)[0]);
+($printers->{$printer}) || ($printer=(keys %$printers)[0]);
+
+
+
 #set up cookie.....
 my $info = '';
 my $branchcookie;
@@ -480,9 +491,9 @@ EOF
 
 
 if ($branchcookie && $printercookie) {
-    print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie]);
+    print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie,$sessioncookie]);
 } else {
-    print $query->header();
+    print $query->header(-cookie=>[$sessioncookie]);
 }
 
 print startpage();
index e5feb62..2e51c22 100644 (file)
@@ -49,6 +49,10 @@ my $printer=$query->param('printer');
 ($branch) || ($branch=$query->cookie('branch'));
 ($printer) || ($printer=$query->cookie('printer'));
 
+($branches->{$branch}) || ($branch=(keys %$branches)[0]);
+($printers->{$printer}) || ($printer=(keys %$printers)[0]);
+
+
 # is you force a selection....
 my $oldbranch = $branch;
 my $oldprinter = $printer;
@@ -68,13 +72,7 @@ my $branchoptions;
 my $printeroptions;
 foreach (keys %$branches) {
     (next) unless ($_);
-    # FIXME - What is this "IS" field? I suspect it's a leftover from
-    # some previous iteration of the code, and means "this is a branch
-    # that does issues". But it never gets set, so no branches ever
-    # get selected, and the user can't choose a branch.
-    # FIXME - Also, shouldn't librarians be able to select any branch,
-    # not just ones that handle issues?
-#    (next) unless ($branches->{$_}->{'IS'});
+    (next) unless ($branches->{$_}->{'IS'});
     $branchcount++;
     my $selected='';
     ($selected='selected') if ($_ eq $oldbranch);
@@ -105,7 +103,8 @@ if ($printercount>1) {
 EOF
 } else {
     my ($printer) = keys %$printers;
-}
+    $printerform.="Printer: ".$printers->{$printer}->{printername};
+} 
 
 if ($branchcount>1) {
     $branchform=<<"EOF";
@@ -113,7 +112,8 @@ if ($branchcount>1) {
 EOF
 } else {
     my ($branch) = keys %$branches;
-}
+    $branchform.= "Branch: ".$branches->{$branch}->{branchname};
+}