koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] CVS: koha/C4/Circulation Circ2.pm,1.63,1.64


From: MJ Ray
Subject: [Koha-cvs] CVS: koha/C4/Circulation Circ2.pm,1.63,1.64
Date: Mon, 08 Dec 2003 06:08:51 -0800

Update of /cvsroot/koha/koha/C4/Circulation
In directory sc8-pr-cvs1:/tmp/cvs-serv9543/C4/Circulation

Modified Files:
        Circ2.pm 
Log Message:
DBI call fixes for bug 662

Index: Circ2.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Circulation/Circ2.pm,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -r1.63 -r1.64
*** Circ2.pm    4 Nov 2003 19:48:51 -0000       1.63
--- Circ2.pm    8 Dec 2003 14:08:49 -0000       1.64
***************
*** 155,161 ****
        my $sth;
        if ($borrowernumber) {
!               $query = "select * from borrowers where 
borrowernumber=$borrowernumber";
        } elsif ($cardnumber) {
!               $query = "select * from borrowers where cardnumber=$cardnumber";
        } else {
                $env->{'apierror'} = "invalid borrower information passed to 
getpatroninformation subroutine";
--- 155,163 ----
        my $sth;
        if ($borrowernumber) {
!               $sth = $dbh->prepare("select * from borrowers where 
borrowernumber=?");
!               $sth->execute($borrowernumber);
        } elsif ($cardnumber) {
!               $sth = $dbh->$prepare("select * from borrowers where 
cardnumber=?");
!               $sth->execute($cardnumber);
        } else {
                $env->{'apierror'} = "invalid borrower information passed to 
getpatroninformation subroutine";
***************
*** 163,168 ****
        }
        $env->{'mess'} = $query;
-       $sth = $dbh->prepare($query);
-       $sth->execute;
        my $borrower = $sth->fetchrow_hashref;
        my $amount = checkaccount($env, $borrowernumber, $dbh);
--- 165,168 ----
***************
*** 260,267 ****
        my $sth;
        if ($itemnumber) {
!               $sth=$dbh->prepare("select * from biblio,items,biblioitems 
where items.itemnumber=$itemnumber and biblio.biblionumber=items.biblionumber 
and biblioitems.biblioitemnumber = items.biblioitemnumber");
        } elsif ($barcode) {
!               my $q_barcode=$dbh->quote($barcode);
!               $sth=$dbh->prepare("select * from biblio,items,biblioitems 
where items.barcode=$q_barcode and biblio.biblionumber=items.biblionumber and 
biblioitems.biblioitemnumber = items.biblioitemnumber");
        } else {
                $env->{'apierror'}="getiteminformation() subroutine must be 
called with either an itemnumber or a barcode";
--- 260,268 ----
        my $sth;
        if ($itemnumber) {
!               $sth=$dbh->prepare("select * from biblio,items,biblioitems 
where items.itemnumber=? and biblio.biblionumber=items.biblionumber and 
biblioitems.biblioitemnumber = items.biblioitemnumber");
!               $sth->execute($itemnumber);
        } elsif ($barcode) {
!               $sth=$dbh->prepare("select * from biblio,items,biblioitems 
where items.barcode=? and biblio.biblionumber=items.biblionumber and 
biblioitems.biblioitemnumber = items.biblioitemnumber");
!               $sth->execute($barcode);
        } else {
                $env->{'apierror'}="getiteminformation() subroutine must be 
called with either an itemnumber or a barcode";
***************
*** 269,273 ****
                return();
        }
-       $sth->execute;
        my $iteminformation=$sth->fetchrow_hashref;
        $sth->finish;
--- 270,273 ----
***************
*** 277,282 ****
        # That way, the rest of the function needn't be indented as much.
        if ($iteminformation) {
!               $sth=$dbh->prepare("select date_due from issues where 
itemnumber=$iteminformation->{'itemnumber'} and isnull(returndate)");
!               $sth->execute;
                my ($date_due) = $sth->fetchrow;
                $iteminformation->{'date_due'}=$date_due;
--- 277,282 ----
        # That way, the rest of the function needn't be indented as much.
        if ($iteminformation) {
!               $sth=$dbh->prepare("select date_due from issues where 
itemnumber=? and isnull(returndate)");
!               $sth->execute($iteminformation->{'itemnumber'});
                my ($date_due) = $sth->fetchrow;
                $iteminformation->{'date_due'}=$date_due;
***************
*** 292,297 ****
                #       ($iteminformation->{loanlength},
                #        $iteminformation->{notforloan}) = fetchrow_array;
!               $sth=$dbh->prepare("select * from itemtypes where 
itemtype='$iteminformation->{'itemtype'}'");
!               $sth->execute;
                my $itemtype=$sth->fetchrow_hashref;
                $iteminformation->{'loanlength'}=$itemtype->{'loanlength'};
--- 292,297 ----
                #       ($iteminformation->{loanlength},
                #        $iteminformation->{notforloan}) = fetchrow_array;
!               $sth=$dbh->prepare("select * from itemtypes where itemtype=?");
!               $sth->execute($iteminformation->{'itemtype'});
                my $itemtype=$sth->fetchrow_hashref;
                $iteminformation->{'loanlength'}=$itemtype->{'loanlength'};
***************
*** 751,762 ****
  
                # Record in the database the fact that the book was issued.
!               # FIXME - Use $dbh->do();
!               my $sth=$dbh->prepare("insert into issues (borrowernumber, 
itemnumber, date_due, branchcode) values 
($patroninformation->{'borrowernumber'}, $iteminformation->{'itemnumber'}, 
'$dateduef', '$env->{'branchcode'}')");
!               $sth->execute;
                $sth->finish;
                $iteminformation->{'issues'}++;
!               # FIXME - Use $dbh->do();
!               $sth=$dbh->prepare("update items set 
issues=$iteminformation->{'issues'},datelastseen=now() where 
itemnumber=$iteminformation->{'itemnumber'}");
!               $sth->execute;
                $sth->finish;
                # If it costs to borrow this book, charge it to the patron's 
account.
--- 751,760 ----
  
                # Record in the database the fact that the book was issued.
!               my $sth=$dbh->prepare("insert into issues (borrowernumber, 
itemnumber, date_due, branchcode) values (?,?,?,?)");
!               $sth->execute($patroninformation->{'borrowernumber'}, 
$iteminformation->{'itemnumber'}, $dateduef, $env->{'branchcode'});
                $sth->finish;
                $iteminformation->{'issues'}++;
!               $sth=$dbh->prepare("update items set 
issues=?,datelastseen=now() where itemnumber=?");
!               
$sth->execute($iteminformation->{'issues'},$iteminformation->{'itemnumber'});
                $sth->finish;
                # If it costs to borrow this book, charge it to the patron's 
account.
***************
*** 915,928 ****
        my ($brn, $itm) = @_;
        my $dbh = C4::Context->dbh;
!       $brn = $dbh->quote($brn);
!       $itm = $dbh->quote($itm);
!       my $query = "update issues set returndate = now() where (borrowernumber 
= $brn)
!               and (itemnumber = $itm) and (returndate is null)";
!       my $sth = $dbh->prepare($query);
!       $sth->execute;
        $sth->finish;
!       $query="update items set datelastseen=now() where itemnumber=$itm";
!       $sth=$dbh->prepare($query);
!       $sth->execute;
        $sth->finish;
        return;
--- 913,922 ----
        my ($brn, $itm) = @_;
        my $dbh = C4::Context->dbh;
!       my $sth = $dbh->prepare("update issues set returndate = now() where 
(borrowernumber = ?)
!               and (itemnumber = ?) and (returndate is null)");
!       $sth->execute($brn,$itm);
        $sth->finish;
!       $sth=$dbh->prepare("update items set datelastseen=now() where 
itemnumber=?");
!       $sth->execute($itm);
        $sth->finish;
        return;
***************
*** 936,940 ****
        my $dbh = C4::Context->dbh;
  
!       $dbh->do("UPDATE items SET itemlost = 0 WHERE   itemnumber = $itemno");
  }
  
--- 930,936 ----
        my $dbh = C4::Context->dbh;
  
!       my $sth = $dbh->prepare("UPDATE items SET itemlost = 0 WHERE    
itemnumber =?");
!       $sth->execute($itemno);
!       $sth->finish();
  }
  
***************
*** 944,953 ****
        my %env;
        my $dbh = C4::Context->dbh;
!       my $itm = $dbh->quote($iteminfo->{'itemnumber'});
        # check for charge made for lost book
!       my $query = "select * from accountlines where (itemnumber = $itm)
!                               and (accounttype='L' or accounttype='Rep') 
order by date desc";
!       my $sth = $dbh->prepare($query);
!       $sth->execute;
        if (my $data = $sth->fetchrow_hashref) {
        # writeoff this amount
--- 940,948 ----
        my %env;
        my $dbh = C4::Context->dbh;
!       my $itm = $iteminfo->{'itemnumber'};
        # check for charge made for lost book
!       my $sth = $dbh->prepare("select * from accountlines where (itemnumber = 
?)
!                               and (accounttype='L' or accounttype='Rep') 
order by date desc");
!       $sth->execute($itm);
        if (my $data = $sth->fetchrow_hashref) {
        # writeoff this amount
***************
*** 963,971 ****
                $amountleft = $data->{'amountoutstanding'} - $amount;
                }
!               my $uquery = "update accountlines set accounttype = 
'LR',amountoutstanding='0'
!                       where (borrowernumber = '$data->{'borrowernumber'}')
!                       and (itemnumber = $itm) and (accountno = '$acctno') ";
!               my $usth = $dbh->prepare($uquery);
!               $usth->execute;
                $usth->finish;
        #check if any credit is left if so writeoff other accounts
--- 958,965 ----
                $amountleft = $data->{'amountoutstanding'} - $amount;
                }
!               my $usth = $dbh->prepare("update accountlines set accounttype = 
'LR',amountoutstanding='0'
!                       where (borrowernumber = ?)
!                       and (itemnumber = ?) and (accountno = ?) ");
!               $usth->execute($data->{'borrowernumber'},$itm,$acctno);
                $usth->finish;
        #check if any credit is left if so writeoff other accounts
***************
*** 975,982 ****
                }
                if ($amountleft > 0){
!               my $query = "select * from accountlines where (borrowernumber = 
'$data->{'borrowernumber'}')
!                                                       and (amountoutstanding 
>0) order by date";
!               my $msth = $dbh->prepare($query);
!               $msth->execute;
        # offset transactions
                my $newamtos;
--- 969,975 ----
                }
                if ($amountleft > 0){
!               my $msth = $dbh->prepare("select * from accountlines where 
(borrowernumber = ?)
!                                                       and (amountoutstanding 
>0) order by date");
!               $msth->execute($data->{'borrowernumber'});
        # offset transactions
                my $newamtos;
***************
*** 991,1006 ****
                        }
                        my $thisacct = $accdata->{'accountno'};
!                       my $updquery = "update accountlines set 
amountoutstanding= '$newamtos'
!                                       where (borrowernumber = 
'$data->{'borrowernumber'}')
!                                       and (accountno='$thisacct')";
!                       my $usth = $dbh->prepare($updquery);
!                       $usth->execute;
                        $usth->finish;
!                       $updquery = "insert into accountoffsets
                                (borrowernumber, accountno, offsetaccount,  
offsetamount)
                                values
!                               
('$data->{'borrowernumber'}','$accdata->{'accountno'}','$nextaccntno','$newamtos')";
!                       $usth = $dbh->prepare($updquery);
!                       $usth->execute;
                        $usth->finish;
                }
--- 984,997 ----
                        }
                        my $thisacct = $accdata->{'accountno'};
!                       my $usth = $dbh->prepare("update accountlines set 
amountoutstanding= ?
!                                       where (borrowernumber = ?)
!                                       and (accountno=?)");
!                       
$usth->execute($amtos,$data->{'borrowernumber'},'$thisacct');
                        $usth->finish;
!                       $usth = $dbh->prepare("insert into accountoffsets
                                (borrowernumber, accountno, offsetaccount,  
offsetamount)
                                values
!                               (?,?,?,?)");
!                       
$usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos);
                        $usth->finish;
                }
***************
*** 1011,1030 ****
                }
                my $desc="Book Returned ".$iteminfo->{'barcode'};
!               $uquery = "insert into accountlines
                        
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
!                       values 
('$data->{'borrowernumber'}','$nextaccntno',now(),0-$amount,'$desc',
!                       'CR',$amountleft)";
!               $usth = $dbh->prepare($uquery);
!               $usth->execute;
                $usth->finish;
!               $uquery = "insert into accountoffsets
                        (borrowernumber, accountno, offsetaccount,  
offsetamount)
!                       values 
($borrower->{'borrowernumber'},$data->{'accountno'},$nextaccntno,$offset)";
!               $usth = $dbh->prepare($uquery);
!               $usth->execute;
                $usth->finish;
!               $uquery = "update items set paidfor='' where itemnumber=$itm";
!               $usth = $dbh->prepare($uquery);
!               $usth->execute;
                $usth->finish;
        }
--- 1002,1017 ----
                }
                my $desc="Book Returned ".$iteminfo->{'barcode'};
!               $usth = $dbh->prepare("insert into accountlines
                        
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
!                       values (?,?,now(),?,?,'CR',?)");
!               
$usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
                $usth->finish;
!               $usth = $dbh->prepare("insert into accountoffsets
                        (borrowernumber, accountno, offsetaccount,  
offsetamount)
!                       values (?,?,?,?)");
!               
$usth->execute($borrower->{'borrowernumber'},$data->{'accountno'},$nextaccntno,$offset);
                $usth->finish;
!               $usth = $dbh->prepare("update items set paidfor='' where 
itemnumber=?");
!               $usth->execute($itm);
                $usth->finish;
        }
***************
*** 1037,1056 ****
        my ($brn, $itm) = @_;
        my $dbh = C4::Context->dbh;
-       $itm = $dbh->quote($itm);
-       $brn = $dbh->quote($brn);
        # check for overdue fine
!       my $query = "select * from accountlines where (borrowernumber=$brn)
!                               and (itemnumber = $itm) and (accounttype='FU' 
or accounttype='O')";
!       my $sth = $dbh->prepare($query);
!       $sth->execute;
        # alter fine to show that the book has been returned
        if (my $data = $sth->fetchrow_hashref) {
!               my $query = "update accountlines set accounttype='F' where 
(borrowernumber = $brn)
!                               and (itemnumber = $itm) and 
(acccountno='$data->{'accountno'}')";
!               my $usth=$dbh->prepare($query);
!               $usth->execute();
                $usth->finish();
        }
!       $sth->finish;
        return;
  }
--- 1024,1037 ----
        my ($brn, $itm) = @_;
        my $dbh = C4::Context->dbh;
        # check for overdue fine
!       my $sth = $dbh->prepare("select * from accountlines where 
(borrowernumber = ?) and (itemnumber = ?) and (accounttype='FU' or 
accounttype='O')");
!       $sth->execute($brn,$itm);
        # alter fine to show that the book has been returned
        if (my $data = $sth->fetchrow_hashref) {
!               my $usth=$dbh->prepare("update accountlines set accounttype='F' 
where (borrowernumber = ?) and (itemnumber = ?) and (acccountno = ?)");
!               $usth->execute($brn,$itm,$data->{'accountno'});
                $usth->finish();
        }
!       $sth->finish();
        return;
  }
***************
*** 1158,1170 ****
        my @overdueitems;
        my $count = 0;
!       my $query = "SELECT * FROM issues,biblio,biblioitems,items
                        WHERE items.biblioitemnumber = 
biblioitems.biblioitemnumber
                                AND items.biblionumber     = biblio.biblionumber
                                AND issues.itemnumber      = items.itemnumber
!                               AND issues.borrowernumber  = $bornum
                                AND issues.returndate is NULL
!                               AND issues.date_due < '$today'";
!       my $sth = $dbh->prepare($query);
!       $sth->execute;
        while (my $data = $sth->fetchrow_hashref) {
        push (@overdueitems, $data);
--- 1139,1150 ----
        my @overdueitems;
        my $count = 0;
!       my $sth = $dbh->prepare("SELECT * FROM issues,biblio,biblioitems,items
                        WHERE items.biblioitemnumber = 
biblioitems.biblioitemnumber
                                AND items.biblionumber     = biblio.biblionumber
                                AND issues.itemnumber      = items.itemnumber
!                               AND issues.borrowernumber  = ?
                                AND issues.returndate is NULL
!                               AND issues.date_due < ?");
!       $sth->execute($bornum,$today);
        while (my $data = $sth->fetchrow_hashref) {
        push (@overdueitems, $data);
***************
*** 1196,1208 ****
        my ($env,$dbh,$itemnum)address@hidden;
        my $resbor = "";
!       my $query = "select * from reserves,items
!       where (items.itemnumber = '$itemnum')
        and (reserves.cancellationdate is NULL)
        and (items.biblionumber = reserves.biblionumber)
        and ((reserves.found = 'W')
        or (reserves.found is null))
!       order by priority";
!       my $sth = $dbh->prepare($query);
!       $sth->execute();
        my $resrec;
        my $data=$sth->fetchrow_hashref;
--- 1176,1187 ----
        my ($env,$dbh,$itemnum)address@hidden;
        my $resbor = "";
!       my $sth = $dbh->prepare("select * from reserves,items
!       where (items.itemnumber = ?)
        and (reserves.cancellationdate is NULL)
        and (items.biblionumber = reserves.biblionumber)
        and ((reserves.found = 'W')
        or (reserves.found is null))
!       order by priority");
!       $sth->execute($itemnum);
        my $resrec;
        my $data=$sth->fetchrow_hashref;
***************
*** 1214,1225 ****
        } else {
        my $found = 0;
!       my $cquery = "select * from reserveconstraints,items
!               where (borrowernumber='$data->{'borrowernumber'}')
!               and reservedate='$data->{'reservedate'}'
!               and reserveconstraints.biblionumber='$data->{'biblionumber'}'
!               and (items.itemnumber=$itemnum and
!               items.biblioitemnumber = reserveconstraints.biblioitemnumber)";
!       my $csth = $dbh->prepare($cquery);
!       $csth->execute;
        if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
        if ($const eq 'o') {
--- 1193,1203 ----
        } else {
        my $found = 0;
!       my $csth = $dbh->prepare("select * from reserveconstraints,items
!               where (borrowernumber=?)
!               and reservedate=?
!               and reserveconstraints.biblionumber=?
!               and (items.itemnumber=? and
!               items.biblioitemnumber = reserveconstraints.biblioitemnumber)");
!       
$csth->execute($data->{'borrowernumber'},$data->{'biblionumber'},$data->{'reservedate'},$itemnum);
        if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
        if ($const eq 'o') {
***************
*** 1301,1312 ****
        # FIXME - Does the caller really need every single field from all
        # four tables?
!       my $select="select * from issues,items,biblioitems,biblio where
!       borrowernumber='$borrowernumber' and issues.itemnumber=items.itemnumber 
and
        items.biblionumber=biblio.biblionumber and
        items.biblioitemnumber=biblioitems.biblioitemnumber and returndate is 
null
!       $crit order by issues.date_due";
!       #    warn $select;
!       my $sth=$dbh->prepare($select);
!       $sth->execute;
        while (my $data = $sth->fetchrow_hashref) {
                # FIXME - The Dewey code is a string, not a number.
--- 1279,1288 ----
        # FIXME - Does the caller really need every single field from all
        # four tables?
!       my $sth=$dbh->prepare("select * from issues,items,biblioitems,biblio 
where
!       borrowernumber=? and issues.itemnumber=items.itemnumber and
        items.biblionumber=biblio.biblionumber and
        items.biblioitemnumber=biblioitems.biblioitemnumber and returndate is 
null
!       $crit order by issues.date_due");
!       $sth->execute($borrownumber);
        while (my $data = $sth->fetchrow_hashref) {
                # FIXME - The Dewey code is a string, not a number.
***************
*** 1423,1429 ****
        my ($env,$dbh,$bornum)address@hidden;
        my @itemswaiting;
!       my $query = "select * from reserves where (borrowernumber = '$bornum') 
and (reserves.found='W') and cancellationdate is NULL";
!       my $sth = $dbh->prepare($query);
!       $sth->execute();
        my $cnt=0;
        if (my $data=$sth->fetchrow_hashref) {
--- 1399,1404 ----
        my ($env,$dbh,$bornum)address@hidden;
        my @itemswaiting;
!       my $sth = $dbh->prepare("select * from reserves where (borrowernumber = 
?) and (reserves.found='W') and cancellationdate is NULL");
!       $sth->execute($bornum);
        my $cnt=0;
        if (my $data=$sth->fetchrow_hashref) {
***************
*** 1444,1455 ****
        my $select="SELECT SUM(amountoutstanding) AS total
                        FROM accountlines
!               WHERE borrowernumber = $bornumber
                        AND amountoutstanding<>0";
        if ($date ne ''){
!       $select.=" AND date < '$date'";
        }
        #  print $select;
        my $sth=$dbh->prepare($select);
!       $sth->execute;
        my $data=$sth->fetchrow_hashref;
        my $total = $data->{'total'};
--- 1419,1432 ----
        my $select="SELECT SUM(amountoutstanding) AS total
                        FROM accountlines
!               WHERE borrowernumber = ?
                        AND amountoutstanding<>0";
+       my @bind = ($bornumber);
        if ($date ne ''){
!       $select.=" AND date < ?";
!       push(@bind,$date);
        }
        #  print $select;
        my $sth=$dbh->prepare($select);
!       $sth->execute(@bind);
        my $data=$sth->fetchrow_hashref;
        my $total = $data->{'total'};
***************
*** 1474,1490 ****
    my $renews = 1;
    my $renewokay = 0;
!   my $q1 = "select * from issues
!     where (borrowernumber = '$bornum')
!     and (itemnumber = '$itemno')
!     and returndate is null";
!   my $sth1 = $dbh->prepare($q1);
!   $sth1->execute;
    if (my $data1 = $sth1->fetchrow_hashref) {
!     my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
!        where (items.itemnumber = '$itemno')
         and (items.biblioitemnumber = biblioitems.biblioitemnumber)
!        and (biblioitems.itemtype = itemtypes.itemtype)";
!     my $sth2 = $dbh->prepare($q2);
!     $sth2->execute;
      if (my $data2=$sth2->fetchrow_hashref) {
        $renews = $data2->{'renewalsallowed'};
--- 1451,1465 ----
    my $renews = 1;
    my $renewokay = 0;
!   my $sth1 = $dbh->prepare("select * from issues
!     where (borrowernumber = ?)
!     and (itemnumber = ?)
!     and returndate is null");
!   $sth1->execute($bornum,$itemno);
    if (my $data1 = $sth1->fetchrow_hashref) {
!     my $sth2 = $dbh->prepare("select renewalsallowed from 
items,biblioitems,itemtypes
!        where (items.itemnumber = ?)
         and (items.biblioitemnumber = biblioitems.biblioitemnumber)
!        and (biblioitems.itemtype = itemtypes.itemtype)");
!     $sth2->execute($itemno);
      if (my $data2=$sth2->fetchrow_hashref) {
        $renews = $data2->{'renewalsallowed'};
***************
*** 1506,1515 ****
    if ($datedue eq "" ) {
      my $loanlength=21;
!     my $query= "Select * from biblioitems,items,itemtypes
!        where (items.itemnumber = '$itemno')
         and (biblioitems.biblioitemnumber = items.biblioitemnumber)
!        and (biblioitems.itemtype = itemtypes.itemtype)";
!     my $sth=$dbh->prepare($query);
!     $sth->execute;
      if (my $data=$sth->fetchrow_hashref) {
        $loanlength = $data->{'loanlength'}
--- 1481,1489 ----
    if ($datedue eq "" ) {
      my $loanlength=21;
!     my $sth=$dbh->prepare("Select * from biblioitems,items,itemtypes
!        where (items.itemnumber = ?)
         and (biblioitems.biblioitemnumber = items.biblioitemnumber)
!        and (biblioitems.itemtype = itemtypes.itemtype)");
!     $sth->execute($itemno);
      if (my $data=$sth->fetchrow_hashref) {
        $loanlength = $data->{'loanlength'}
***************
*** 1523,1540 ****
    my @date = split("-",$datedue);
    my $odatedue = ($date[2]+0)."-".($date[1]+0)."-".$date[0];
!   my $issquery = "select * from issues where borrowernumber='$bornum' and
!     itemnumber='$itemno' and returndate is null";
!   my $sth=$dbh->prepare($issquery);
!   $sth->execute;
    my $issuedata=$sth->fetchrow_hashref;
    $sth->finish;
    my $renews = $issuedata->{'renewals'} +1;
!   my $updquery = "update issues
!     set date_due = '$datedue', renewals = '$renews'
!     where borrowernumber='$bornum' and
!     itemnumber='$itemno' and returndate is null";
!   $sth=$dbh->prepare($updquery);
  
!   $sth->execute;
    $sth->finish;
    return($odatedue);
--- 1497,1512 ----
    my @date = split("-",$datedue);
    my $odatedue = ($date[2]+0)."-".($date[1]+0)."-".$date[0];
!   my $sth=$dbh->prepare("select * from issues where borrowernumber=? and
!     itemnumber=? and returndate is null");
!   $sth->execute($bornum,$itemno);
    my $issuedata=$sth->fetchrow_hashref;
    $sth->finish;
    my $renews = $issuedata->{'renewals'} +1;
!   $sth=$dbh->prepare("update issues
!     set date_due = ?, renewals = ?
!     where borrowernumber=? and
!     itemnumber=? and returndate is null");
  
!   $sth->execute($datedue,$renews,$bornum,$itemno);
    $sth->finish;
    return($odatedue);
***************
*** 1555,1576 ****
  #    open (FILE,">>/tmp/charges");
      my $item_type;
!     my $q1 = "select itemtypes.itemtype,rentalcharge from 
items,biblioitems,itemtypes
!     where (items.itemnumber ='$itemno')
      and (biblioitems.biblioitemnumber = items.biblioitemnumber)
!     and (biblioitems.itemtype = itemtypes.itemtype)";
!     my $sth1= $dbh->prepare($q1);
  #    print FILE "$q1\n";
!     $sth1->execute;
      if (my $data1=$sth1->fetchrow_hashref) {
        $item_type = $data1->{'itemtype'};
        $charge = $data1->{'rentalcharge'};
  #     print FILE "charge is $charge\n";
!       my $q2 = "select rentaldiscount from borrowers,categoryitem
!       where (borrowers.borrowernumber = '$bornum')
        and (borrowers.categorycode = categoryitem.categorycode)
!       and (categoryitem.itemtype = '$item_type')";
!       my $sth2=$dbh->prepare($q2);
  #     warn $q2;
!       $sth2->execute;
        if (my $data2=$sth2->fetchrow_hashref) {
            my $discount = $data2->{'rentaldiscount'};
--- 1527,1546 ----
  #    open (FILE,">>/tmp/charges");
      my $item_type;
!     my $sth1= $dbh->prepare("select itemtypes.itemtype,rentalcharge from 
items,biblioitems,itemtypes
!     where (items.itemnumber =?)
      and (biblioitems.biblioitemnumber = items.biblioitemnumber)
!     and (biblioitems.itemtype = itemtypes.itemtype)");
  #    print FILE "$q1\n";
!     $sth1->execute($itemno);
      if (my $data1=$sth1->fetchrow_hashref) {
        $item_type = $data1->{'itemtype'};
        $charge = $data1->{'rentalcharge'};
  #     print FILE "charge is $charge\n";
!       my $sth2=$dbh->prepare("select rentaldiscount from 
borrowers,categoryitem
!       where (borrowers.borrowernumber = ?)
        and (borrowers.categorycode = categoryitem.categorycode)
!       and (categoryitem.itemtype = ?)");
  #     warn $q2;
!       $sth2->execute($bornum,$item_type);
        if (my $data2=$sth2->fetchrow_hashref) {
            my $discount = $data2->{'rentaldiscount'};
***************
*** 1612,1618 ****
      my ($env,$bornumber,$dbh)address@hidden;
      my $nextaccntno = 1;
!     my $query = "select * from accountlines where (borrowernumber = 
'$bornumber') order by accountno desc";
!     my $sth = $dbh->prepare($query);
!     $sth->execute;
      if (my $accdata=$sth->fetchrow_hashref){
        $nextaccntno = $accdata->{'accountno'} + 1;
--- 1582,1587 ----
      my ($env,$bornumber,$dbh)address@hidden;
      my $nextaccntno = 1;
!     my $sth = $dbh->prepare("select * from accountlines where (borrowernumber 
= ?) order by accountno desc");
!     $sth->execute($bornumber);
      if (my $accdata=$sth->fetchrow_hashref){
        $nextaccntno = $accdata->{'accountno'} + 1;
***************
*** 1649,1657 ****
      my $bibno = $dbh->quote($itemdata->{'biblionumber'});
      my $bibitm = $dbh->quote($itemdata->{'biblioitemnumber'});
!     my $query = "select * from reserves where ((found = 'W') or (found is 
null))
!                        and biblionumber = $bibno and cancellationdate is NULL
!                        order by priority, reservedate ";
!     my $sth = $dbh->prepare($query);
!     $sth->execute;
      my $resfound = 0;
      my $resrec;
--- 1618,1623 ----
      my $bibno = $dbh->quote($itemdata->{'biblionumber'});
      my $bibitm = $dbh->quote($itemdata->{'biblioitemnumber'});
!     my $sth = $dbh->prepare("select * from reserves where ((found = 'W') or 
(found is null)) and biblionumber = ? and cancellationdate is NULL order by 
priority, reservedate");
!     $sth->execute($bibno);
      my $resfound = 0;
      my $resrec;
***************
*** 1682,1702 ****
                $resfound = 1;
            } else {
!                 my $conquery = "select * from reserveconstraints where 
borrowernumber = $brn
!                      and reservedate = $rdate and biblionumber = $bibno and 
biblioitemnumber = $bibitm";
!               my $consth = $dbh->prepare($conquery);
!               $consth->execute;
!               if (my $conrec = $consth->fetchrow_hashref) {
!                   if ($resrec->{'constrainttype'} eq "o") {
!                       $resfound = 1;
!                   }
!               }
                $consth->finish;
!           }
        }
        if ($resfound) {
!             my $updquery = "update reserves set found = 'W', itemnumber = 
'$itemno'
!                   where borrowernumber = $brn and reservedate = $rdate and 
biblionumber = $bibno";
!           my $updsth = $dbh->prepare($updquery);
!           $updsth->execute;
            $updsth->finish;
            # FIXME - "last;" here to break out of the loop early.
--- 1648,1664 ----
                $resfound = 1;
            } else {
!                       my $consth = $dbh->prepare("select * from 
reserveconstraints where borrowernumber = ? and reservedate = ? and 
biblionumber = ? and biblioitemnumber = ?");
!                       $consth->execute($brn,$rdate,$bibno,$bibitm);
!                       if (my $conrec = $consth->fetchrow_hashref) {
!                               if ($resrec->{'constrainttype'} eq "o") {
!                               $resfound = 1;
!                               }
!                       }
                $consth->finish;
!               }
        }
        if ($resfound) {
!           my $updsth = $dbh->prepare("update reserves set found = 'W', 
itemnumber = ? where borrowernumber = ? and reservedate = ? and biblionumber = 
?");
!           $updsth->execute($itemno,$brn,$rdate,$bibno);
            $updsth->finish;
            # FIXME - "last;" here to break out of the loop early.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]