1 package C4::Circulation::Borrower; #assumes C4/Circulation/Borrower
3 #package to deal with Issues
4 #written 3/11/99 by chris@katipo.co.nz
12 use C4::Interface::FlagsCDK;
13 use C4::Circulation::Main;
14 use C4::Circulation::Issues;
15 use C4::Circulation::Renewals;
20 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
22 # set the version for version checking
26 @EXPORT = qw(&findborrower &Borenq &findoneborrower &NewBorrowerNumber
28 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
30 # your exported package globals go here,
31 # as well as any optionally exported functions
33 @EXPORT_OK = qw($Var1 %Hashit);
36 # non-exported package globals go here
37 use vars qw(@more $stuff);
39 # initalize package globals, first exported ones
44 # then the others (which are still accessible as $Some::Module::stuff)
48 # all file-scoped lexicals must be created before
49 # the functions below that use them.
51 # file-private lexicals go here
55 # here's a file-private function as a closure,
56 # callable as &$priv_func; it cannot be prototyped.
61 # make all your functions, whether exported or not;
66 C4::InterfaceCDK::helptext('');
67 C4::InterfaceCDK::clearscreen();
74 while (($bornum eq '') && ($reason eq "")) {
75 #get borrowerbarcode from scanner
76 my $title = C4::InterfaceCDK::titlepanel($env,$env->{'sysarea'},"Borrower Entry");
77 if ($env->{'newborrower'} eq "") {
78 ($borcode,$reason,$book)=&C4::Circulation::Main::scanborrower($env);
80 $borcode = $env->{'newborrower'};
83 $env->{'newborrower'}= "";
85 #C4::Circulation::Main
88 ($bornum,$borrower) = findoneborrower($env,$dbh,$borcode);
89 $env->{'IssuesAllowed'} = 1;
90 } elsif ($book ne "") {
91 my $query = "select * from issues,items where (barcode = '$book')
92 and (items.itemnumber = issues.itemnumber)
93 and (issues.returndate is null)";
94 my $iss_sth=$dbh->prepare($query);
96 if (my $issdata = $iss_sth->fetchrow_hashref) {
97 $bornum=$issdata->{'borrowernumber'};
98 $sth = $dbh->prepare("Select * from borrowers
99 where borrowernumber = '$bornum'");
101 $borrower=$sth->fetchrow_hashref;
104 error_msg($env,"Item $book not found");
110 my ($issuesallowed,$owing);
112 $env->{'bornum'} = $bornum;
113 $env->{'bcard'} = $borrower->{'cardnumber'};
114 my $borrowers=join(' ',($borrower->{'title'},$borrower->{'firstname'},$borrower->{'surname'}));
116 ($issuesallowed,$odues,$owing) = &checktraps($env,$dbh,$bornum,$borrower);
117 # error_msg ($env,"bcard = $env->{'bcard'}");
119 #debug_msg ($env,"2 = $env->{'IssuesAllowed'}");
120 return ($bornum, $issuesallowed,$borrower,$reason,$owing);
124 sub findoneborrower {
125 # output(1,1,$borcode);
126 my ($env,$dbh,$borcode)=@_;
129 my $ucborcode = uc $borcode;
130 my $lcborcode = lc $borcode;
131 my $sth=$dbh->prepare("Select * from borrowers where cardnumber=\"$ucborcode\"");
133 if ($borrower=$sth->fetchrow_hashref) {
134 $bornum=$borrower->{'borrowernumber'};
138 # my $borquery = "Select * from borrowers
139 # where surname ~* '$borcode' order by surname";
141 my $borquery = "Select * from borrowers
142 where lower(surname) like \"$lcborcode%\" order by surname,firstname";
143 my $sthb =$dbh->prepare($borquery);
148 while ($borrower= $sthb->fetchrow_hashref) {
149 my $line = $borrower->{'cardnumber'}.' '.$borrower->{'categorycode'}.' '.$borrower->{'surname'}.
150 ', '.$borrower->{'othernames'};
151 $borrows[$cntbor] = fmtstr($env,$line,"L50");
152 $bornums[$cntbor] =$borrower->{'borrowernumber'};
156 $bornum = $bornums[0];
157 my $query = "select * from borrowers where borrowernumber = '$bornum'";
158 $sth = $dbh->prepare($query);
160 $borrower =$sth->fetchrow_hashref;
162 } elsif ($cntbor > 0) {
163 my ($cardnum) = C4::InterfaceCDK::selborrower($env,$dbh,\@borrows,\@bornums);
164 my $query = "select * from borrowers where cardnumber = '$cardnum'";
165 $sth = $dbh->prepare($query);
167 $borrower =$sth->fetchrow_hashref;
169 $bornum=$borrower->{'borrowernumber'};
170 #C4::InterfaceCDK::clearscreen();
172 error_msg($env,"Borrower not found");
176 return ($bornum,$borrower);
179 my ($env,$dbh,$bornum,$borrower) = @_;
180 my $issuesallowed = "1";
186 while ($traps_done ne "DONE") {
188 $amount=C4::Accounts::checkaccount($env,$bornum,$dbh); #from C4::Accounts
189 if ($amount > 0) { push (@traps_set,"CHARGES");}
190 if ($borrower->{'gonenoaddress'} == 1){ push (@traps_set,"GNA");}
191 #check if member has a card reported as lost
192 if ($borrower->{'lost'} ==1){push (@traps_set,"LOST");}
193 #check the notes field if notes exist display them
194 if ($borrower->{'borrowernotes'} ne ''){ push (@traps_set,"NOTES");}
195 #check if borrower has overdue items
196 #call overdue checker
197 my $odues = &C4::Circulation::Main::checkoverdues($env,$bornum,$dbh);
198 if ($odues > 0) {push (@traps_set,"ODUES");}
199 #check if borrower has any items waiting
200 my ($nowaiting,$itemswaiting) = &C4::Circulation::Main::checkwaiting($env,$dbh,$bornum);
201 if ($nowaiting > 0) { push (@traps_set,"WAITING"); }
202 if (@traps_set[0] ne "" ) {
203 ($issuesallowed,$traps_done,$amount,$odues) =
204 process_traps($env,$dbh,$bornum,$borrower,
205 $amount,$odues,\@traps_set,$itemswaiting);
207 $traps_done = "DONE";
210 return ($issuesallowed, $odues,$amount);
214 my ($env,$dbh,$bornum,$borrower,$amount,$odues,$traps_set,$waiting) = @_;
215 my $issuesallowed = 1;
218 while (@$traps_set[$x] ne "") {
219 $traps{@$traps_set[$x]} = 1;
225 while ($trapact ne "NONE") {
226 $trapact = &trapscreen($env,$bornum,$borrower,$amount,$traps_set);
227 if ($trapact eq "CHARGES") {
228 C4::Accounts::reconcileaccount($env,$dbh,$bornum,$amount,$borrower,$odues);
229 ($odues,$issues,$amount)=borrdata2($env,$bornum);
231 $traps{'CHARGES'} = 0;
234 while ($traps_set->[$x] ne "") {
235 if ($traps_set->[$x] ne "CHARGES") {
236 push @newtraps,$traps_set->[$x];
240 $traps_set = \@newtraps;
242 } elsif ($trapact eq "WAITING") {
243 reserveslist($env,$borrower,$amount,$odues,$waiting);
244 } elsif ($trapact eq "ODUES") {
245 C4::Circulation::Renewals::bulkrenew($env,$dbh,$bornum,$amount,$borrower,$odues);
246 ($odues,$issues,$amount)=borrdata2($env,$bornum);
251 while ($traps_set->[$x] ne "") {
252 if ($traps_set->[$x] ne "ODUES") {
253 push @newtraps,$traps_set->[$x];
257 $traps_set = \@newtraps;
259 } elsif ($trapact eq "NOTES") {
260 my $notes = trapsnotes($env,$bornum,$borrower,$amount);
261 if ($notes ne $borrower->{'borrowernotes'}) {
262 my $query = "update borrowers set borrowernotes = '$notes'
263 where borrowernumber = $bornum";
264 my $sth = $dbh->prepare($query);
267 $borrower->{'borrowernotes'} = $notes;
273 while ($traps_set->[$x] ne "") {
274 if ($traps_set->[$x] ne "NOTES") {
275 push @newtraps,$traps_set->[$x];
279 $traps_set = \@newtraps;
282 my $notr = @$traps_set;
286 $traps_done = "DONE";
288 if ($traps{'GNA'} eq 1 ) {
290 $env->{'IssuesAllowed'} = 0;
292 if ($traps{'CHARGES'} eq 1) {
294 $env->{'IssuesAllowed'} = 0;
298 return ($issuesallowed,$traps_done,$amount,$odues);
299 } # end of process_traps
309 $env->{'sysarea'} = "Enquiries";
310 while ($reason eq "") {
311 $env->{'sysarea'} = "Enquiries";
312 ($bornum,$issuesallowed,$borrower,$reason) = &findborrower($env,$dbh);
314 my ($data,$reason)=&borrowerwindow($env,$borrower);
315 if ($reason eq 'Modify'){
316 modifyuser($env,$borrower);
318 } elsif ($reason eq 'New'){
328 my ($env,$borrower) = @_;
329 debug_msg($env,"Please use intranet");
334 my ($env,$borrower,$amount,$odues,$waiting) = @_;
338 my $query="Select * from reserves where
339 borrowernumber='$borrower->{'borrowernumber'}' and found='W' and
340 cancellationdate is null order by timestamp";
341 my $sth=$dbh->prepare($query);
343 while (my $data=$sth->fetchrow_hashref){
344 my $itemdata = itemnodata($env,$dbh,$data->{'itemnumber'});
346 push @items,$itemdata;
350 reservesdisplay($env,$borrower,$amount,$odues,\@items);
354 sub NewBorrowerNumber {
356 my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");
358 my $data=$sth->fetchrow_hashref;
360 $data->{'max(borrowernumber)'}++;
361 return($data->{'max(borrowernumber)'});
368 my $query="select cardnumber,borrowernumber from borrowers where
369 guarantor='$bornum'";
370 my $sth=$dbh->prepare($query);
374 while (my $data=$sth->fetchrow_hashref){
382 END { } # module clean-up code here (global destructor)