-package C4::Circulation::Borrower; #assumes C4/Circulation/Borrower
+package C4::Circulation::Borrower;
+
+# $Id$
#package to deal with Issues
#written 3/11/99 by chris@katipo.co.nz
use C4::Search;
use C4::Stats;
use C4::Format;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-
+use vars qw($VERSION @ISA @EXPORT);
+
# set the version for version checking
$VERSION = 0.01;
-
+
@ISA = qw(Exporter);
@EXPORT = qw(&findborrower &Borenq &findoneborrower &NewBorrowerNumber
&findguarantees);
-%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
-
-# your exported package globals go here,
-# as well as any optionally exported functions
-
-@EXPORT_OK = qw($Var1 %Hashit);
-
-
-# non-exported package globals go here
-use vars qw(@more $stuff);
-
-# initalize package globals, first exported ones
-
-my $Var1 = '';
-my %Hashit = ();
-
-# then the others (which are still accessible as $Some::Module::stuff)
-my $stuff = '';
-my @more = ();
-
-# all file-scoped lexicals must be created before
-# the functions below that use them.
-
-# file-private lexicals go here
-my $priv_var = '';
-my %secret_hash = ();
-
-# here's a file-private function as a closure,
-# callable as &$priv_func; it cannot be prototyped.
-my $priv_func = sub {
- # stuff goes here.
-};
-
-# make all your functions, whether exported or not;
-
sub findborrower {
my ($env,$dbh) = @_;
#get borrowerbarcode from scanner
my $title = C4::InterfaceCDK::titlepanel($env,$env->{'sysarea'},"Borrower Entry");
if ($env->{'newborrower'} eq "") {
- ($borcode,$reason,$book)=&C4::Circulation::Main::scanborrower($env);
- } else {
+ ($borcode,$reason,$book)=&C4::Circulation::Main::scanborrower($env);
+ } else {
$borcode = $env->{'newborrower'};
$reason = "";
$book = "";
$env->{'newborrower'}= "";
- }
+ }
#C4::Circulation::Main
if ($reason eq "") {
if ($borcode ne '') {
($bornum,$borrower) = findoneborrower($env,$dbh,$borcode);
$env->{'IssuesAllowed'} = 1;
} elsif ($book ne "") {
- my $query = "select * from issues,items where (barcode = '$book')
- and (items.itemnumber = issues.itemnumber)
- and (issues.returndate is null)";
- my $iss_sth=$dbh->prepare($query);
- $iss_sth->execute;
+ my $iss_sth=$dbh->prepare("select * from issues,items where (barcode = ?)
+ and (items.itemnumber = issues.itemnumber)
+ and (issues.returndate is null)");
+ $iss_sth->execute($book);
if (my $issdata = $iss_sth->fetchrow_hashref) {
$bornum=$issdata->{'borrowernumber'};
- $sth = $dbh->prepare("Select * from borrowers
+ $sth = $dbh->prepare("Select * from borrowers
where borrowernumber = '$bornum'");
$sth->execute;
$borrower=$sth->fetchrow_hashref;
- $sth->finish;
+ $sth->finish;
} else {
error_msg($env,"Item $book not found");
- }
+ }
$iss_sth->finish;
}
- }
- }
+ }
+ }
my ($issuesallowed,$owing);
if ($reason eq "") {
$env->{'bornum'} = $bornum;
my $borrower;
my $ucborcode = uc $borcode;
my $lcborcode = lc $borcode;
- my $sth=$dbh->prepare("Select * from borrowers where cardnumber=\"$ucborcode\"");
- $sth->execute;
+ my $sth=$dbh->prepare("Select * from borrowers where cardnumber=?");
+ $sth->execute($ucborcode);
if ($borrower=$sth->fetchrow_hashref) {
$bornum=$borrower->{'borrowernumber'};
$sth->finish;
$sth->finish;
# my $borquery = "Select * from borrowers
# where surname ~* '$borcode' order by surname";
-
- my $borquery = "Select * from borrowers
- where lower(surname) like \"$lcborcode%\" order by surname,firstname";
- my $sthb =$dbh->prepare($borquery);
- $sthb->execute;
+
+ my $sthb =$dbh->prepare("Select * from borrowers where lower(surname) like ? order by surname,firstname");
+ $sthb->execute("$lcborcode%");
my $cntbor = 0;
my @borrows;
my @bornums;
$cntbor++;
}
if ($cntbor == 1) {
- $bornum = $bornums[0];
- my $query = "select * from borrowers where borrowernumber = '$bornum'";
+ $bornum = $bornums[0];
+ my $query = "select * from borrowers where borrowernumber = '$bornum'";
$sth = $dbh->prepare($query);
$sth->execute;
$borrower =$sth->fetchrow_hashref;
- $sth->finish;
+ $sth->finish;
} elsif ($cntbor > 0) {
my ($cardnum) = C4::InterfaceCDK::selborrower($env,$dbh,\@borrows,\@bornums);
- my $query = "select * from borrowers where cardnumber = '$cardnum'";
- $sth = $dbh->prepare($query);
- $sth->execute;
+ $sth = $dbh->prepare("select * from borrowers where cardnumber = ?");
+ $sth->execute($cardnum);
$borrower =$sth->fetchrow_hashref;
$sth->finish;
$bornum=$borrower->{'borrowernumber'};
if ($bornum eq '') {
error_msg($env,"Borrower not found");
}
- }
+ }
}
- return ($bornum,$borrower);
+ return ($bornum,$borrower);
}
sub checktraps {
my ($env,$dbh,$bornum,$borrower) = @_;
my $issuesallowed = "1";
#my @traps_set;
#check amountowing
- my $traps_done;
+ my $traps_done;
my $odues;
my $amount;
while ($traps_done ne "DONE") {
my @traps_set;
$amount=C4::Accounts::checkaccount($env,$bornum,$dbh); #from C4::Accounts
- if ($amount > 0) { push (@traps_set,"CHARGES");}
+ if ($amount > 0) { push (@traps_set,"CHARGES");}
if ($borrower->{'gonenoaddress'} == 1){ push (@traps_set,"GNA");}
#check if member has a card reported as lost
if ($borrower->{'lost'} ==1){push (@traps_set,"LOST");}
#check if borrower has overdue items
#call overdue checker
my $odues = &C4::Circulation::Main::checkoverdues($env,$bornum,$dbh);
- if ($odues > 0) {push (@traps_set,"ODUES");}
+ if ($odues > 0) {push (@traps_set,"ODUES");}
#check if borrower has any items waiting
my ($nowaiting,$itemswaiting) = &C4::Circulation::Main::checkwaiting($env,$dbh,$bornum);
- if ($nowaiting > 0) { push (@traps_set,"WAITING"); }
+ if ($nowaiting > 0) { push (@traps_set,"WAITING"); }
# FIXME - This should be $traps_set[0], right?
if (@traps_set[0] ne "" ) {
- ($issuesallowed,$traps_done,$amount,$odues) =
+ ($issuesallowed,$traps_done,$amount,$odues) =
process_traps($env,$dbh,$bornum,$borrower,
$amount,$odues,\@traps_set,$itemswaiting);
} else {
$traps_done = "DONE";
- }
+ }
}
return ($issuesallowed, $odues,$amount);
}
my $x = 0;
my %traps;
while (@$traps_set[$x] ne "") {
- $traps{@$traps_set[$x]} = 1;
+ $traps{@$traps_set[$x]} = 1;
$x++;
}
my $traps_done;
$trapact = &trapscreen($env,$bornum,$borrower,$amount,$traps_set);
if ($trapact eq "CHARGES") {
C4::Accounts::reconcileaccount($env,$dbh,$bornum,$amount,$borrower,$odues);
- ($odues,$issues,$amount)=borrdata2($env,$bornum);
+ ($odues,$issues,$amount)=borrdata2($env,$bornum);
if ($amount <= 0) {
$traps{'CHARGES'} = 0;
my @newtraps;
}
} elsif ($trapact eq "NOTES") {
my $notes = trapsnotes($env,$bornum,$borrower,$amount);
- if ($notes ne $borrower->{'borrowernotes'}) {
- my $query = "update borrowers set borrowernotes = '$notes'
- where borrowernumber = $bornum";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- $sth->finish();
+ if ($notes ne $borrower->{'borrowernotes'}) {
+ my $sth = $dbh->prepare("update borrowers set borrowernotes = ? where borrowernumber = ?");
+ $sth->execute($notes,$bornum);
+ $sth->finish();
$borrower->{'borrowernotes'} = $notes;
}
if ($notes eq "") {
push @newtraps,$traps_set->[$x];
}
$x++;
- }
- $traps_set = \@newtraps;
+ }
+ $traps_set = \@newtraps;
}
}
my $notr = @$traps_set;
}
}
return $reason;
-}
+}
sub modifyuser {
my ($env,$borrower) = @_;
my $dbh = C4::Context->dbh;
my @items;
my $x=0;
- my $query="Select * from reserves where
- borrowernumber='$borrower->{'borrowernumber'}' and found='W' and
- cancellationdate is null order by timestamp";
- my $sth=$dbh->prepare($query);
- $sth->execute;
+ my $sth=$dbh->prepare("Select * from reserves where
+ borrowernumber=? and found='W' and
+ cancellationdate is null order by timestamp");
+ $sth->execute($borrower->{'borrowernumber'});
while (my $data=$sth->fetchrow_hashref){
my $itemdata = itemnodata($env,$dbh,$data->{'itemnumber'});
if ($itemdata){
=cut
#'
# FIXME - This is identical to C4::Search::NewBorrowerNumber.
-# Pick one (preferably this one) and stick with it.
+# Pick one (preferably this one) and stick with it.
# FIXME - Race condition: this function just says what the next unused
# number is, but doesn't allocate it. Hence, two clients adding
sub findguarantees{
my ($bornum)=@_;
my $dbh = C4::Context->dbh;
- my $query="select cardnumber,borrowernumber from borrowers where
- guarantor='$bornum'";
- my $sth=$dbh->prepare($query);
- $sth->execute;
+ my $sth=$dbh->prepare("select cardnumber,borrowernumber from borrowers where
+ guarantor=?");
+ $sth->execute($bornum);
my @dat;
my $i=0;
while (my $data=$sth->fetchrow_hashref){
$sth->finish;
return($i,\@dat);
}
-END { } # module clean-up code here (global destructor)