koha-cvs
[Top][All Lists]
Advanced

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

[Koha-cvs] koha/C4/Circulation Circ2.pm [dev_week]


From: Joshua Ferraro
Subject: [Koha-cvs] koha/C4/Circulation Circ2.pm [dev_week]
Date: Sun, 27 Aug 2006 00:20:46 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Joshua Ferraro <kados>  06/08/27 00:20:46

Modified files:
        C4/Circulation : Circ2.pm 

Log message:
        Cleanup of Circ2.pm, removal of Date::Manip dependency, turned on
        warnings and removed all errors (except uninitialized var warnings)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Circ2.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.87.2.14.2.5&r2=1.87.2.14.2.6

Patches:
Index: Circ2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Circ2.pm,v
retrieving revision 1.87.2.14.2.5
retrieving revision 1.87.2.14.2.6
diff -u -b -r1.87.2.14.2.5 -r1.87.2.14.2.6
--- Circ2.pm    10 Aug 2006 02:10:21 -0000      1.87.2.14.2.5
+++ Circ2.pm    27 Aug 2006 00:20:45 -0000      1.87.2.14.2.6
@@ -3,7 +3,7 @@
 
 package C4::Circulation::Circ2;
 
-# $Id: Circ2.pm,v 1.87.2.14.2.5 2006/08/10 02:10:21 kados Exp $
+# $Id: Circ2.pm,v 1.87.2.14.2.6 2006/08/27 00:20:45 kados Exp $
 
 #package to deal with Returns
 #written 3/11/99 by address@hidden
@@ -27,17 +27,24 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-# use warnings;
+use warnings; no warnings 'uninitialized';
 require Exporter;
 use DBI;
 use C4::Context;
 use C4::Stats;
 use C4::Reserves2;
 use C4::Koha;
-use C4::Accounts;
-use Date::Manip;
 use C4::Biblio;
-#use C4::Calendar::Calendar;
+use C4::Accounts;
+use Date::Calc qw(
+Today
+Today_and_Now
+Add_Delta_YM
+Add_Delta_DHMS
+Date_to_Days
+);
+#use Date::Manip;
+
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
@@ -86,26 +93,12 @@
        $sth->execute($itemnum);
        return;
 }
-sub itemseenbarcode {
-       my ($env,$itemnum) = @_;
-       my $dbh = C4::Context->dbh;
-       my $sth = $dbh->prepare("update items set itemlost=0, datelastseen  = 
now() where items.barcode = ?");
-       $sth->execute($itemnum);
-       return;
-}
 
 sub listitemsforinventory {
        my ($minlocation,$maxlocation,$datelastseen,$offset,$size) = @_;
-       my $sth;
        my $dbh = C4::Context->dbh;
-       if ($datelastseen){
-        $sth = $dbh->prepare("select 
itemnumber,items.biblionumber,items.biblioitemnumber,barcode,itemcallnumber,title,author
 from items,biblio,biblioitems where items.biblionumber=biblio.biblionumber and 
biblioitems.biblionumber=biblio.biblionumber and itemcallnumber>= 
'$minlocation' and itemcallnumber <='$maxlocation' and (datelastseen< 
'$datelastseen' or datelastseen is null) order by lcsort,Cutterextra");
-
-       }else{
-       $sth = $dbh->prepare("select 
itemnumber,items.biblionumber,items.biblioitemnumber,barcode,itemcallnumber,title,author
 from items,biblio,biblioitems where items.biblionumber=biblio.biblionumber and 
biblioitems.biblionumber=biblio.biblionumber and itemcallnumber>= 
'$minlocation' and itemcallnumber <='$maxlocation'  order by 
lcsort,Cutterextra");
-       
-       }
-       $sth->execute();
+       my $sth = $dbh->prepare("select 
itemnumber,barcode,itemcallnumber,title,author from items,biblio where 
items.biblionumber=biblio.biblionumber and itemcallnumber>= ? and 
itemcallnumber <=? and (datelastseen< ? or datelastseen is null) order by 
itemcallnumber,title");
+       $sth->execute($minlocation,$maxlocation,$datelastseen);
        my @results;
        while (my $row = $sth->fetchrow_hashref) {
                $offset-- if ($offset);
@@ -250,6 +243,12 @@
        $sth->finish;
        $borrower->{'flags'}=$flags;
        $borrower->{'authflags'} = $accessflagshash;
+
+       # find out how long the membership lasts
+       $sth=$dbh->prepare("select enrolmentperiod from categories where 
categorycode = ?");
+       $sth->execute($borrower->{'categorycode'});
+       my $enrolment = $sth->fetchrow;
+       $borrower->{'enrolmentperiod'} = $enrolment;
        return ($borrower); #, $flags, $accessflagshash);
 }
 
@@ -449,7 +448,7 @@
 # Perl, though).
 sub transferbook {
 # transfer book code....
-       my ($tbr, $barcode, $ignoreRs,$user) = @_;
+       my ($tbr, $barcode, $ignoreRs) = @_;
        my $messages;
        my %env;
        my $dotransfer = 1;
@@ -490,7 +489,15 @@
        }
        #actually do the transfer....
        if ($dotransfer) {
-               dotransfer($iteminformation->{'itemnumber'}, $fbr, $tbr,$user);
+               dotransfer($iteminformation->{'itemnumber'}, $fbr, $tbr);
+               my $dbh= C4::Context->dbh;
+               my ($tagfield,$tagsubfield) = 
MARCfind_marc_from_kohafield($dbh,"items.holdingbranch");
+               my $bibid = MARCfind_MARCbibid_from_oldbiblionumber( $dbh, 
$iteminformation->{'biblionumber'} );
+               my $marcitem = MARCgetitem($dbh, $bibid, 
$iteminformation->{'itemnumber'});
+               if ($marcitem->field($tagfield)){
+                       $marcitem->field($tagfield)->update($tagsubfield=> 
$tbr);
+                       
MARCmoditem($dbh,$marcitem,$bibid,$iteminformation->{'itemnumber'});
+               }
                $messages->{'WasTransfered'} = 1;
        }
        return ($dotransfer, $messages, $iteminformation);
@@ -500,33 +507,20 @@
 # FIXME - This is only used in &transferbook. Why bother making it a
 # separate function?
 sub dotransfer {
-       my ($itm, $fbr, $tbr,$user) = @_;
+       my ($itm, $fbr, $tbr) = @_;
        my $dbh = C4::Context->dbh;
        $itm = $dbh->quote($itm);
        $fbr = $dbh->quote($fbr);
        $tbr = $dbh->quote($tbr);
-       $user = $dbh->quote($user);
        #new entry in branchtransfers....
-       $dbh->do("INSERT INTO   branchtransfers (itemnumber, frombranch, 
datearrived, tobranch,comments) VALUES ($itm, $fbr, now(), $tbr,$user)");
+       $dbh->do("INSERT INTO   branchtransfers (itemnumber, frombranch, 
datearrived, tobranch)
+                                       VALUES ($itm, $fbr, now(), $tbr)");
        #update holdingbranch in items .....
        $dbh->do("UPDATE items set holdingbranch = $tbr WHERE   
items.itemnumber = $itm");
        &itemseen($itm);
-       &domarctransfer($dbh,$itm);
        return;
 }
 
-
-##New sub to dotransfer in marc tables as well. Not exported -TG 01/10/2005
-sub domarctransfer{
-my ($dbh,$itemnumber) = @_;
-my $sth=$dbh->prepare("select biblionumber,holdingbranch from items where 
itemnumber=$itemnumber");
-       $sth->execute();
-my ($biblionumber,$holdingbranch)=$sth->fetchrow; 
-$itemnumber=~s /\'//g;
-&MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'items.holdingbranch',$holdingbranch);
-
-}
-
 =head2 canbookbeissued
 
 Check if a book can be issued.
@@ -625,122 +619,13 @@
        my $branch_borrower = $borrower->{'branchcode'};
        my $dbh = C4::Context->dbh;
 
-       my $sth = $dbh->prepare('select itemtype from biblioitems where 
biblionumber = ?');
-       $sth->execute($iteminformation->{'biblionumber'});
-       my $type = $sth->fetchrow;
-       $sth->finish;
-       $sth = $dbh->prepare('select * from issuingrules where categorycode = ? 
and itemtype = ? and branchcode = ?');
-       my $sth2 = $dbh->prepare("select COUNT(*) from issues i, biblioitems s, 
items it where i.borrowernumber = ? and i.returndate is null and i.itemnumber = 
it.itemnumber and it.biblioitemnumber = s.biblioitemnumber and s.itemtype like 
?");
-       my $sth3 = $dbh->prepare('select COUNT(*) from issues where 
borrowernumber = ? and returndate is null');
-       my $alreadyissued;
-
-       # check the 3 parameters
-       #print "content-type: text/plain \n\n";
-       #print "$cat_borrower, $type, $branch_borrower";
-       $sth->execute($cat_borrower, $type, $branch_borrower);
-       my $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-       #       print "content-type: text/plain \n\n";
-       #print "$cat_borrower, $type, $branch_borrower";
-               $sth2->execute($borrower->{'borrowernumber'}, "%$type%");
-               my $alreadyissued = $sth2->fetchrow;    
-       #       print "***" . $alreadyissued;
-       #print "----". $result->{'maxissueqty'};
-         if (defined($result->{'maxissueqty'})) {
-                       return 
($alreadyissued,($result->{'maxissueqty'}+0),$cat_borrower, $type, 
$branch_borrower, $result->{'issuelength'}) if ($result->{'maxissueqty'} <= 
$alreadyissued);
-         }
-       }
-
-       # check for branch=*
-       $sth->execute($cat_borrower, $type, "");
-       $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-               $sth2->execute($borrower->{'borrowernumber'}, "%$type%");
-               my $alreadyissued = $sth2->fetchrow;
-         if (defined($result->{maxissueqty})) {
-                       return 
($alreadyissued,($result->{maxissueqty}+0),$cat_borrower, $type, 
"",$result->{'issuelength'}) if ($result->{'maxissueqty'} <= $alreadyissued);
-               }
-       }
-
-       # check for itemtype=*
-       $sth->execute($cat_borrower, "*", $branch_borrower);
-       $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-               $sth3->execute($borrower->{'borrowernumber'});
-               my $alreadyissued = $sth3->fetchrow;
-         if (defined($result->{maxissueqty})) {
-                       return 
($alreadyissued,($result->{maxissueqty}+0),$cat_borrower, "*", 
$branch_borrower,$result->{'issuelength'}) if ($result->{'maxissueqty'} <= 
$alreadyissued);
-               }
-       }
-
-       #check for borrowertype=*
-       $sth->execute("*", $type, $branch_borrower);
-       $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-               $sth2->execute($borrower->{'borrowernumber'}, "%$type%");
-               my $alreadyissued = $sth2->fetchrow;
-         if (defined($result->{maxissueqty})) {
-                       return ($alreadyissued,($result->{maxissueqty}+0),"*", 
$type, $branch_borrower,$result->{'issuelength'}) if ($result->{'maxissueqty'} 
<= $alreadyissued);
-               }
-       }
-
-       #check for borrowertype=*;itemtype=*
-       $sth->execute("*", "*", $branch_borrower);
-       $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-               $sth3->execute($borrower->{'borrowernumber'});
-               my $alreadyissued = $sth3->fetchrow;
-         if (defined($result->{maxissueqty})) {
-                       return ($alreadyissued,($result->{maxissueqty}+0),"*", 
"*", $branch_borrower,$result->{'issuelength'}) if ($result->{'maxissueqty'} <= 
$alreadyissued);
-               }
-       }
-
-       #check for borrowertype=*;branch=""
-       $sth->execute("*", $type, "");
-       $result = $sth->fetchrow_hashref;
-       if (defined($result) && $result->{maxissueqty} ge 0) {
-               $sth2->execute($borrower->{'borrowernumber'}, "%$type%");
-               my $alreadyissued = $sth2->fetchrow;
-         if (defined($result->{maxissueqty})) {
-                       return ($alreadyissued,($result->{maxissueqty}+0),"*", 
$type, "",$result->{'issuelength'}) if ($result->{'maxissueqty'} <= 
$alreadyissued);
-               }
-       }
-
-       $sth->execute($cat_borrower, "*", "");
-       $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-               $sth2->execute($borrower->{'borrowernumber'}, "%$type%");
-               my $alreadyissued = $sth2->fetchrow;
-         if (defined($result->{maxissueqty})) {
-                       return 
($alreadyissued,($result->{maxissueqty}+0),$cat_borrower, "*", 
"",$result->{'issuelength'}) if ($result->{'maxissueqty'} <= $alreadyissued);
-               }
-  }
-
-       $sth->execute("*", "*", "");
-       $result = $sth->fetchrow_hashref;
-       if (defined($result)) {
-               $sth3->execute($borrower->{'borrowernumber'});
-               my $alreadyissued = $sth3->fetchrow;
-               if (defined($result->{maxissueqty})) {
-                       return ($alreadyissued,($result->{maxissueqty}+0),"*", 
"*", "",$result->{'issuelength'}) if ($result->{'maxissueqty'} <= 
$alreadyissued);
-               }
-       }
-       return (undef, undef, undef, undef, undef, undef);
-}
-
-sub TooMany2 ($$){
-       my $borrower = shift;
-       my $iteminformation = shift;
-       my $cat_borrower = $borrower->{'categorycode'};
-       my $branch_borrower = $borrower->{'branchcode'};
-       my $dbh = C4::Context->dbh;
-       
 
        my $sth = $dbh->prepare('select itemtype from biblioitems where 
biblionumber = ?');
        $sth->execute($iteminformation->{'biblionumber'});
        my $type = $sth->fetchrow;
        $sth = $dbh->prepare('select * from issuingrules where categorycode = ? 
and itemtype = ? and branchcode = ?');
-       my $sth2 = $dbh->prepare("select COUNT(*) from issues i, biblioitems s 
where i.borrowernumber = ? and i.returndate is null and i.itemnumber = 
s.biblioitemnumber and s.itemtype like ?");
+#      my $sth2 = $dbh->prepare("select COUNT(*) from issues i, biblioitems s 
where i.borrowernumber = ? and i.returndate is null and i.itemnumber = 
s.biblioitemnumber and s.itemtype like ?");
+       my $sth2 = $dbh->prepare("select COUNT(*) from issues i, biblioitems 
s1, items s2 where i.borrowernumber = ? and i.returndate is null and 
i.itemnumber = s2.itemnumber and s1.itemtype like ? and s1.biblioitemnumber = 
s2.biblioitemnumber");
        my $sth3 = $dbh->prepare('select COUNT(*) from issues where 
borrowernumber = ? and returndate is null');
        my $alreadyissued;
        # check the 3 parameters
@@ -766,7 +651,7 @@
        if (defined($result)) {
                $sth3->execute($borrower->{'borrowernumber'});
                my ($alreadyissued) = $sth3->fetchrow;
-#              warn "HERE : $alreadyissued / ($result->{maxissueqty} for 
$borrower->{'borrowernumber'}";
+               warn "HERE : $alreadyissued / ($result->{maxissueqty} for 
$borrower->{'borrowernumber'}";
                return ("c $alreadyissued / ".($result->{maxissueqty}+0)) if 
($result->{'maxissueqty'} <= $alreadyissued);
        }
        #check for borrowertype=*
@@ -788,7 +673,7 @@
 
        $sth->execute("*", $type, "");
        $result = $sth->fetchrow_hashref;
-       if (defined($result) && $result->{maxissueqty}>=0) {
+       if (defined($result) && $result->{maxissueqty} ge 0) {
                $sth2->execute($borrower->{'borrowernumber'}, "%$type%");
                my $alreadyissued = $sth2->fetchrow;
                return ("f $alreadyissued / ".($result->{maxissueqty}+0)) if 
($result->{'maxissueqty'} <= $alreadyissued);
@@ -837,7 +722,10 @@
        if ($borrower->{flags}->{'DBARRED'}) {
                $issuingimpossible{DEBARRED} = 1;
        }
-       if (DATE_diff($borrower->{expiry},'CURRENT_DATE')<0) {
+
+       if (Date_to_Days(Today()) > Date_to_Days(split /-/, 
$borrower->{'expiry'})) {
+       #
+       #if (&Date_Cmp(&ParseDate($borrower->{expiry}),&ParseDate("today"))<0) {
                $issuingimpossible{EXPIRED} = 1;
        }
 #
@@ -854,20 +742,8 @@
 #
 # JB34 CHECKS IF BORROWERS DONT HAVE ISSUE TOO MANY BOOKS
 #
-#      my $toomany = TooMany($borrower, $iteminformation);
-
-#      $needsconfirmation{TOO_MANY} =  $toomany if $toomany;
-my ($already_issues, 
-                 $max_issues, 
-                 $categorycode_rule, 
-                 $itemtype_rule, 
-                 $branchcode_rule,
-                 $issue_lenght) = TooMany($borrower, $iteminformation);
-       $needsconfirmation{TOO_MANY}              =  $already_issues." / 
".$max_issues if defined($already_issues);
-       $needsconfirmation{TOO_MANY_CATEGORYCODE} =  $categorycode_rule         
       if defined($already_issues);
-       $needsconfirmation{TOO_MANY_ITEMTYPE}     =  $itemtype_rule             
       if defined($already_issues);
-       $needsconfirmation{TOO_MANY_BRANCHCODE}   =  $branchcode_rule           
       if defined($already_issues);
-
+       my $toomany = TooMany($borrower, $iteminformation);
+       $needsconfirmation{TOO_MANY} =  $toomany if $toomany;
 
 #
 # ITEM CHECKING
@@ -887,9 +763,14 @@
        if ($iteminformation->{'restricted'} == 1) {
                $issuingimpossible{RESTRICTED} = 1;
        }
-       if ($iteminformation->{'stack'} eq 'Res') {
-               $issuingimpossible{IN_RESERVE} = 1;
+       if (C4::Context->preference("IndependantBranches")){
+               my $userenv = C4::Context->userenv;
+               if (($userenv)&&($userenv->{flags} != 1)){
+                       $issuingimpossible{NOTSAMEBRANCH} = 1 if 
($iteminformation->{'holdingbranch'} ne $userenv->{branch} ) ;
        }
+       }
+
+
 
 
 #
@@ -903,10 +784,7 @@
                if ($renewstatus == 0) { # no more renewals allowed
                        $issuingimpossible{NO_MORE_RENEWALS} = 1;
                } else {
-
                        $needsconfirmation{RENEW_ISSUE} = 1;
-                               
-                       
                }
        } elsif ($currentborrower) {
 # issued to someone else
@@ -914,7 +792,7 @@
 #              warn "=>.$currborinfo->{'firstname'} $currborinfo->{'surname'} 
($currborinfo->{'cardnumber'})";
                $needsconfirmation{ISSUED_TO_ANOTHER} = 
"$currborinfo->{'reservedate'} : $currborinfo->{'firstname'} 
$currborinfo->{'surname'} ($currborinfo->{'cardnumber'})";
        }
-# See if the item is on RESERVE
+# See if the item is on reserve.
        my ($restype, $res) = CheckReserves($iteminformation->{'itemnumber'});
        if ($restype) {
                my $resbor = $res->{'borrowernumber'};
@@ -925,7 +803,7 @@
                        my $branches = getbranches();
                        my $branchname = 
$branches->{$res->{'branchcode'}}->{'branchname'};
                        $needsconfirmation{RESERVE_WAITING} = 
"$resborrower->{'firstname'} $resborrower->{'surname'} 
($resborrower->{'cardnumber'}, $branchname)";
-                       CancelReserve(0, $res->{'itemnumber'}, 
$res->{'borrowernumber'});
+                       # CancelReserve(0, $res->{'itemnumber'}, 
$res->{'borrowernumber'}); Doesn't belong in a checking subroutine.
                } elsif ($restype eq "Reserved") {
                        # The item is on reserve for someone else.
                        my ($resborrower, $flags)=getpatroninformation($env, 
$resbor,0);
@@ -961,8 +839,6 @@
 sub issuebook {
        my ($env,$borrower,$barcode,$date,$cancelreserve) = @_;
        my       $dbh = C4::Context->dbh;
-       #warn "tring to issue";
-       my $error;
 #      my ($borrower, $flags) = &getpatroninformation($env, $borrowernumber, 
0);
        my $iteminformation = getiteminformation($env, 0, $barcode);
 #              warn "B : ".$borrower->{borrowernumber}." / I : 
".$iteminformation->{'itemnumber'};
@@ -977,11 +853,7 @@
                        $iteminformation->{'charge'} = $charge;
                }
                
&UpdateStats($env,$env->{'branchcode'},'renew',$charge,'',$iteminformation->{'itemnumber'},$iteminformation->{'itemtype'},$borrower->{'borrowernumber'});
-                $error=renewstatus($env, $borrower->{'borrowernumber'}, 
$iteminformation->{'itemnumber'});
-                renewbook($env, $borrower->{'borrowernumber'}, 
$iteminformation->{'itemnumber'}) if ($error>1);
-               
-#warn "renew : ".$borrower->{borrowernumber}." / I : 
".$iteminformation->{'itemnumber'};
-
+               renewbook($env, $borrower->{'borrowernumber'}, 
$iteminformation->{'itemnumber'});
        } else {
 #
 # NOT a renewal
@@ -990,28 +862,27 @@
                        # This book is currently on loan, but not to the person
                        # who wants to borrow it now. mark it returned before 
issuing to the new borrower
                        returnbook($iteminformation->{'barcode'}, 
$env->{'branchcode'});
-#warn "return : ".$borrower->{borrowernumber}." / I : 
".$iteminformation->{'itemnumber'};
-
                }
                # See if the item is on reserve.
                my ($restype, $res) = 
CheckReserves($iteminformation->{'itemnumber'});
-#warn "$restype,$res";
                if ($restype) {
                        my $resbor = $res->{'borrowernumber'};
                        if ($resbor eq $borrower->{'borrowernumber'}) {
                                # The item is on reserve to the current patron
                                FillReserve($res);
-#                              warn "FillReserve";
+                               warn "FillReserve";
                        } elsif ($restype eq "Waiting") {
-#                              warn "Waiting";
+                               warn "Waiting";
                                # The item is on reserve and waiting, but has 
been
                                # reserved by some other patron.
                                my ($resborrower, 
$flags)=getpatroninformation($env, $resbor,0);
                                my $branches = getbranches();
                                my $branchname = 
$branches->{$res->{'branchcode'}}->{'branchname'};
+                if ($cancelreserve){
                                CancelReserve(0, $res->{'itemnumber'}, 
$res->{'borrowernumber'});
+                }
                        } elsif ($restype eq "Reserved") {
-#                              warn "Reserved";
+                               warn "Reserved";
                                # The item is on reserve for someone else.
                                my ($resborrower, 
$flags)=getpatroninformation($env, $resbor,0);
                                my $branches = getbranches();
@@ -1020,39 +891,37 @@
                                        # cancel reserves on this item
                                        CancelReserve(0, $res->{'itemnumber'}, 
$res->{'borrowernumber'});
                                        # also cancel reserve on biblio related 
to this item
-                                       my $st_Fbiblio = $dbh->prepare("select 
biblionumber from items where itemnumber=?");
-                                       
$st_Fbiblio->execute($res->{'itemnumber'});
-                                       my $biblionumber = 
$st_Fbiblio->fetchrow;
-                                       
CancelReserve($biblionumber,0,$res->{'borrowernumber'});
-#                                      warn "CancelReserve 
$res->{'itemnumber'}, $res->{'borrowernumber'}";
+                                       #my $st_Fbiblio = $dbh->prepare("select 
biblionumber from items where itemnumber=?");
+                                       
#$st_Fbiblio->execute($res->{'itemnumber'});
+                                       #my $biblionumber = 
$st_Fbiblio->fetchrow;
+                                       
#CancelReserve($biblionumber,0,$res->{'borrowernumber'});
+                                       #warn "CancelReserve 
$res->{'itemnumber'}, $res->{'borrowernumber'}";
                                } else {
 #                                      my $tobrcd = 
ReserveWaiting($res->{'itemnumber'}, $res->{'borrowernumber'});
 #                                      transferbook($tobrcd,$barcode, 1);
-#                                      warn "transferbook";
+                                       warn "transferbook";
                                }
                        }
                }
                # Record in the database the fact that the book was issued.
-               my $sth=$dbh->prepare("insert into issues (borrowernumber, 
itemnumber, date_due, branchcode,issue_date) values (?,?,?,?,NOW())");
-               my @datearr = localtime();
-#      my $dateduef = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
+               my $sth=$dbh->prepare("insert into issues (borrowernumber, 
itemnumber, date_due, branchcode) values (?,?,?,?)");
                my $loanlength = 
getLoanLength($borrower->{'categorycode'},$iteminformation->{'itemtype'},$borrower->{'branchcode'});
-               $loanlength = 
getLoanLength($borrower->{'categorycode'},$iteminformation->{'itemtype'},$borrower->{'branchcode'});
                my $datedue=time+($loanlength)*86400;
-               @datearr = localtime($datedue);
+               my @datearr = localtime($datedue);
                my $dateduef = 
(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
-#warn "issue : ".$borrower->{borrowernumber}." / I : 
".$iteminformation->{'itemnumber'};
-
                if ($date) {
                        $dateduef=$date;
                }
+               # if ReturnBeforeExpiry ON the datedue can't be after borrower 
expirydate
+               if (C4::Context->preference('ReturnBeforeExpiry') && $dateduef 
gt $borrower->{expiry}) {
+                       $dateduef=$borrower->{expiry};
+               }
                $sth->execute($borrower->{'borrowernumber'}, 
$iteminformation->{'itemnumber'}, $dateduef, $env->{'branchcode'});
                $sth->finish;
                $iteminformation->{'issues'}++;
-               $sth=$dbh->prepare("update items set issues=?, onloan=? where 
itemnumber=?");
-               
$sth->execute($iteminformation->{'issues'},$dateduef,$iteminformation->{'itemnumber'});
+               $sth=$dbh->prepare("update items set issues=? where 
itemnumber=?");
+               
$sth->execute($iteminformation->{'issues'},$iteminformation->{'itemnumber'});
                $sth->finish;
-               
&MARCmoditemonefield($dbh,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'},'items.onloan',$dateduef);
                &itemseen($iteminformation->{'itemnumber'});
                # If it costs to borrow this book, charge it to the patron's 
account.
                my ($charge,$itemtype)=calc_charges($env, 
$iteminformation->{'itemnumber'}, $borrower->{'borrowernumber'});
@@ -1063,7 +932,6 @@
                # Record the fact that this book was issued.
                
&UpdateStats($env,$env->{'branchcode'},'issue',$charge,'',$iteminformation->{'itemnumber'},$iteminformation->{'itemtype'},$borrower->{'borrowernumber'});
        }
-return($error);
 }
 
 =head2 getLoanLength
@@ -1214,10 +1082,6 @@
                my $sth = $dbh->prepare("update issues set returndate = now() 
where (borrowernumber = ?) and (itemnumber = ?) and (returndate is null)");
                $sth->execute($borrower->{'borrowernumber'}, 
$iteminformation->{'itemnumber'});
                $messages->{'WasReturned'} = 1; # FIXME is the "= 1" right?
-       $sth=$dbh->prepare("update items set  onloan=NULL where itemnumber=?");
-               $sth->execute($iteminformation->{'itemnumber'});
-               $sth->finish;
-       
&MARCmoditemonefield($dbh,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'},'items.onloan',"0000-00-00");
        }
        itemseen($iteminformation->{'itemnumber'});
        ($borrower) = getpatroninformation(\%env, $currentborrower, 0);
@@ -1285,7 +1149,7 @@
                $usth->execute($data->{'borrowernumber'},$itm,$acctno);
                $usth->finish;
        #check if any credit is left if so writeoff other accounts
-               my $nextaccntno = 
_getnextacctno(\%env,$data->{'borrowernumber'},$dbh);
+               my $nextaccntno = 
getnextacctno(\%env,$data->{'borrowernumber'},$dbh);
                if ($amountleft < 0){
                $amountleft*=-1;
                }
@@ -1361,7 +1225,7 @@
        $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 (accountno = ?)");
+               my $usth=$dbh->prepare("update accountlines set accounttype='F' 
where (borrowernumber = ?) and (itemnumber = ?) and (acccountno = ?)");
                $usth->execute($brn,$itm,$data->{'accountno'});
                $usth->finish();
        }
@@ -1696,7 +1560,7 @@
        my $counter = 0;
        while (my $data = $sth->fetchrow_hashref) {
                $data->{'dewey'} =~ s/0*$//;
-               ($data->{'dewey'} == 0) && ($data->{'dewey'} = '');
+               #($data->{'dewey'} == 0) && ($data->{'dewey'} = '');
                        # FIXME - The Dewey code is a string, not a number.
                # FIXME - Use POSIX::strftime to get a text version of today's
                # date. That's what it's for.
@@ -1766,16 +1630,12 @@
 sub renewstatus {
        # check renewal status
        my ($env,$bornum,$itemno)address@hidden;
-       my $dbh=C4::Context->dbh;
+       my $dbh = C4::Context->dbh;
        my $renews = 1;
-       
-       my $renewokay; ##
+       my $renewokay = 0;
        # Look in the issues table for this item, lent to this borrower,
        # and not yet returned.
-my $borrower=getpatroninformation($dbh,$bornum,undef);
-if ($borrower->{'categorycode'} eq 'F' ||$borrower->{'categorycode'} eq 'P'){
-$renewokay = 1;
-}
+       
        # FIXME - I think this function could be redone to use only one SQL 
call.
        my $sth1 = $dbh->prepare("select * from issues
                                                                where 
(borrowernumber = ?)
@@ -1798,44 +1658,20 @@
                $renews = $data2->{'renewalsallowed'};
                }
                if ($renews > $data1->{'renewals'}) {
-                       $renewokay= 1;
-               }else{
-               $renewokay=3;
+                       $renewokay = 1;
                }
                $sth2->finish;
                my ($resfound, $resrec) = CheckReserves($itemno);
                if ($resfound) {
-                       $renewokay=4;
+                       $renewokay = 0;
                }
+               ($resfound, $resrec) = CheckReserves($itemno);
+                if ($resfound) {
+                        $renewokay = 0;
        }
-       $sth1->finish;
-## Try to find whether book can be renewed at this date
-       my $loanlength;
-
-       my $allowRenewalsBefore = 
C4::Context->preference("allowRenewalsBefore");
-       my @nowarr = localtime(time);
-       my $now = (1900+$nowarr[5])."-".($nowarr[4]+1)."-".$nowarr[3]; 
-
-       # Find the issues record for this book### Use the items table -->quicker
-       my $sth=$dbh->prepare("select onloan  from items where itemnumber=? ");
-       $sth->execute($itemno);
-       my $issuedata=$sth->fetchrow;
-       $sth->finish;
-
-#calculates the date on the we are  allowed to renew the item
-       $sth = $dbh->prepare("SELECT (DATE_SUB( ?, INTERVAL ? DAY))");
-       $sth->execute($issuedata, $allowRenewalsBefore);
-       my $startdate = $sth->fetchrow;
-
-       $sth->finish;
-       $sth = $dbh->prepare("SELECT DATEDIFF(CURRENT_DATE,?)");
-       $sth->execute($startdate);
-       my $difference = $sth->fetchrow;
-       $sth->finish;
 
-       if  ($difference < 0) {
-       $renewokay=2;
        }
+       $sth1->finish;
        return($renewokay);
 }
 
@@ -1864,87 +1700,52 @@
 =cut
 
 sub renewbook {
-       my ($env,$bornum,$itemno,$datedue)address@hidden;
        # mark book as renewed
+       my ($env,$bornum,$itemno,$datedue)address@hidden;
+       my $dbh = C4::Context->dbh;
 
-       my $loanlength;
-
-my $dbh=C4::Context->dbh;
-
-
-my  $iteminformation = getiteminformation($env, $itemno,0);
-
-# Find the issues record for this book### Use the items table -->quicker
-       my $sth=$dbh->prepare("select onloan  from items where itemnumber=? ");
-       $sth->execute($itemno);
-       my $issuedata=$sth->fetchrow;
-       $sth->finish;
-               
-
-## We find a new datedue either from today or from the due_date of the book- 
T.G
-
-if ($datedue eq "" ) {
-
+       # If the due date wasn't specified, calculate it by adding the
+       # book's loan length to today's date.
+       if ($datedue eq "" ) {
+               #debug_msg($env, "getting date");
+               my $iteminformation = getiteminformation($env, $itemno,0);
                my  $borrower = getpatroninformation($env,$bornum,0);
-                $loanlength = 
getLoanLength($borrower->{'categorycode'},$iteminformation->{'itemtype'},$borrower->{'branchcode'});
-my @nowarr = localtime(time);
-       my $now = (1900+$nowarr[5])."-".($nowarr[4]+1)."-".$nowarr[3]; 
-       if ($issuedata<=$now){
-               
-       
        my $loanlength = 
getLoanLength($borrower->{'categorycode'},$iteminformation->{'itemtype'},$borrower->{'branchcode'});
-               my $datedue=time+($loanlength)*86400;
-               my @datearr = localtime($datedue);
-               my $dateduef = 
(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
-               
-       }else{
-               
-               my $loanlength = 
getLoanLength($borrower->{'categorycode'},$iteminformation->{'itemtype'},$borrower->{'branchcode'});
-               my $datedue=time+($loanlength)*86400;
-               my @datearr = localtime($datedue);
-               my $dateduef = 
(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
-               
+               my ($due_year, $due_month, $due_day) = 
Add_Delta_DHMS(Today_and_Now(), $loanlength,0,0,0);
+               $datedue = "$due_year-$due_month-$due_day";
+               #$datedue = UnixDate(DateCalc("today","$loanlength 
days"),"%Y-%m-%d");
        }
 
-
-
-## Only update the renewal if we have a new $duedate -T.G
+       # Find the issues record for this book
+       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;
 
        # Update the issues record to have the new due date, and a new count
        # of how many times it has been renewed.
-       #my $renews = $issuedata->{'renewals'} +1;
-       $sth=$dbh->prepare("update issues set date_due = ?, renewals = 
renewals+1
+       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,$bornum,$itemno);
+       $sth->execute($datedue,$renews,$bornum,$itemno);
        $sth->finish;
 
-       ## Update items and marc record with new date -T.G
-       my $iteminformation = getiteminformation($env, $itemno,0);
-       $sth=$dbh->prepare("update items set issues=?, onloan=? where 
itemnumber=?");
-               $sth->execute($iteminformation->{'issues'}+1,$datedue,$itemno);
-               $sth->finish;
-               
&MARCmoditemonefield($dbh,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'},'items.onloan',$datedue);
-               
        # Log the renewal
        UpdateStats($env,$env->{'branchcode'},'renew','','',$itemno);
 
        # Charge a new rental fee, if applicable?
        my ($charge,$type)=calc_charges($env, $itemno, $bornum);
        if ($charge > 0){
-               my $accountno=_getnextacctno($env,$bornum,$dbh);
+               my $accountno=getnextacctno($env,$bornum,$dbh);
                my $item=getiteminformation($env, $itemno);
                $sth=$dbh->prepare("Insert into accountlines 
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
                                                        values 
(?,?,now(),?,?,?,?,?)");
                $sth->execute($bornum,$accountno,$charge,"Renewal of Rental 
Item $item->{'title'} $item->{'barcode'}",'Rent',$charge,$itemno);
                $sth->finish;
        #     print $account;
-       }# end of rental charge
-       
-
        }
 
- 
-       
+       #  return();
 }
 
 
@@ -1994,7 +1795,7 @@
 sub createcharge {
 #Stolen from Issues.pm
     my ($env,$dbh,$itemno,$bornum,$charge) = @_;
-    my $nextaccntno = _getnextacctno($env,$bornum,$dbh);
+    my $nextaccntno = getnextacctno($env,$bornum,$dbh);
     my $sth = $dbh->prepare(<<EOT);
        INSERT INTO     accountlines
                        (borrowernumber, itemnumber, accountno,
@@ -2009,18 +1810,18 @@
 }
 
 
-sub _getnextacctno {
+#sub getnextacctno {
 # Stolen from Accounts.pm
-    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;
-    }
-    $sth->finish;
-    return($nextaccntno);
-}
+#    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;
+#    }
+#    $sth->finish;
+#    return($nextaccntno);
+#}
 
 =item find_reserves
 
@@ -2124,15 +1925,6 @@
     return ($date, $invalidduedate);
 }
 
-sub DATE_diff {
-my ($date1,$date2)address@hidden;
-my $dbh=C4::Context->dbh;
-my $sth = $dbh->prepare("SELECT DATEDIFF(?,?)");
-       $sth->execute($date1,$date2);
-       my $difference = $sth->fetchrow;
-       $sth->finish;
-return $difference;
-}
 1;
 __END__
 




reply via email to

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