diff --git a/C4/Circmain.pm b/C4/Circmain.pm new file mode 100755 index 0000000..e1a1f5f --- /dev/null +++ b/C4/Circmain.pm @@ -0,0 +1,99 @@ +package C4::Circmain; #asummes C4/Circulation + +#package to deal with circulation + +use strict; +require Exporter; +use DBI; +use C4::Database; +use C4::Circulation::Main; +use C4::Circulation::Issues; +use C4::Circulation::Returns; +use C4::Circulation::Renewals; +use C4::Circulation::Borrower; +use C4::Reserves; +use C4::Interface; +use C4::Security; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +# set the version for version checking +$VERSION = 0.01; + +@ISA = qw(Exporter); +@EXPORT = qw(&Start_circ); +%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 Start_circ{ + my ($env)=@_; + #connect to database + #start interface + &startint($env,'Circulation'); + my $donext = 'Circ'; + my $reason; + my $data; + while ($donext ne 'Quit') { + if ($donext eq "Circ") { + clearscreen(); + ($reason,$data) = menu($env,'console','Circulation', + ('Issues','Returns','Borrower Enquiries','Reserves','Log In')); + debug_msg($env,"data = $data"); + } else { + $data = $donext; + } + if ($data eq 'Issues') { + $donext=Issue($env); #C4::Circulation::Issues + #debug_msg("","do next $donext"); + } elsif ($data eq 'Returns') { + $donext=Returns($env); #C4::Circulation::Returns + } elsif ($data eq 'Borrower Enquiries'){ + $donext=Borenq($env); #C4::Circulation::Borrower + } elsif ($data eq 'Reserves'){ + $donext=EnterReserves($env); #C4::Reserves + } elsif ($data eq 'Log In') { + &endint($env); + &Login($env); #C4::Security + &startint($env,'Circulation'); + } elsif ($data eq 'Quit') { + $donext = $data; + } + #debug_msg($env,"donext - $donext"); + } + &endint($env) +} + + +END { } # module clean-up code here (global destructor) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index af0cda0..132b2b2 100755 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -20,8 +20,8 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 0.01; @ISA = qw(Exporter); -#@EXPORT = qw(&Start_circ &scanborrower); -@EXPORT = qw(&Start_circ); +@EXPORT = qw(&Start_circ &scanborrower); +#@EXPORT = qw(&Start_circ checkoverdues); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, @@ -68,7 +68,7 @@ sub Start_circ{ while ($donext ne 'Quit') { if ($donext eq "Circ") { clearscreen(); - ($reason,$data) = menu('console','Circulation', + ($reason,$data) = menu($env,'console','Circulation', ('Issues','Returns','Borrower Enquiries','Reserves','Log In')); debug_msg($env,"data = $data"); } else { @@ -210,14 +210,14 @@ sub scanbook { return ($number,$reason); } -#sub scanborrower { -# my ($env,$interface)=@_; -# #scan barcode -# my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface -# $number= $number; -# $book=uc $book; -# return ($number,$reason,$book); -#} +sub scanborrower { + my ($env,$interface)=@_; + #scan barcode + my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface + $number= $number; + $book=uc $book; + return ($number,$reason,$book); +} END { } # module clean-up code here (global destructor) diff --git a/C4/Circulation/Borrower.pm b/C4/Circulation/Borrower.pm index bfd85fc..6f27d5d 100755 --- a/C4/Circulation/Borrower.pm +++ b/C4/Circulation/Borrower.pm @@ -9,7 +9,7 @@ use DBI; use C4::Database; use C4::Accounts; use C4::Interface; -use C4::Circulation; +use C4::Circulation::Main; use C4::Circulation::Issues; use C4::Scan; use C4::Stats; @@ -20,7 +20,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 0.01; @ISA = qw(Exporter); -@EXPORT = qw(&findborrower &Borenq &findoneborrower &scanborrower); +@EXPORT = qw(&findborrower &Borenq &findoneborrower); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, @@ -67,11 +67,13 @@ sub findborrower { my $borrower; my $reason = ""; my $book; + #my $sillytest = &olwen($env); while (($bornum eq '') && ($reason eq "")) { #get borrowerbarcode from scanner titlepanel($env,$env->{'sysarea'},"Borrower Entry"); - ($borcode,$reason,$book)=&scanborrower(); #C4::Circulation - debug_msg($env,"Reaz = $reason"); + ($borcode,$reason,$book)=&C4::Circulation::Main::scanborrower(); + #C4::Circulation::Main + # debug_msg($env,"Reaz = $reason"); if ($reason eq "") { if ($borcode ne '') { ($bornum,$borrower) = findoneborrower($env,$dbh,$borcode); @@ -179,11 +181,11 @@ sub checktraps { } #check if borrower has overdue items #call overdue checker - &checkoverdues($env,$bornum,$dbh); + &C4::Circulation::Main::checkoverdues($env,$bornum,$dbh); #check amountowing my $amount=checkaccount($env,$bornum,$dbh); #from C4::Accounts #check if borrower has any items waiting - my $itemswaiting = &checkwaiting($env,$dbh,$bornum); + my $itemswaiting = &C4::Circulation::Main::checkwaiting($env,$dbh,$bornum); #deal with any money still owing # output(30,1,$amount); if ($amount > 0){ @@ -219,14 +221,6 @@ sub Borenq { return $reason; } -sub scanborrower { - my ($env,$interface)=@_; - #scan barcode - my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface - $number= $number; - $book=uc $book; - return ($number,$reason,$book); -} END { } # module clean-up code here (global destructor) diff --git a/C4/Circulation/Issues.pm b/C4/Circulation/Issues.pm index d268ec8..f97447b 100755 --- a/C4/Circulation/Issues.pm +++ b/C4/Circulation/Issues.pm @@ -1,4 +1,4 @@ -package C4::Circulation; #asummes C4/Circulation/Issues +package C4::Circulation::Issues; #asummes C4/Circulation/Issues #package to deal with Issues #written 3/11/99 by chris@katipo.co.nz @@ -9,12 +9,12 @@ use DBI; use C4::Database; use C4::Accounts; use C4::Interface; -use C4::Circulation; +use C4::Circulation::Main; use C4::Circulation::Borrower; use C4::Scan; use C4::Stats; use C4::Print; - +use C4::Format; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use Newt qw(); @@ -78,7 +78,7 @@ sub Issue { #deal with alternative loans #now check items clearscreen(); - ($items,$items2)=pastitems($env,$bornum,$dbh); #from Circulation.pm + ($items,$items2)=C4::Circulation::Main::pastitems($env,$bornum,$dbh); #from Circulation.pm $done = "No"; my $row2=5; my $it2p=0; diff --git a/C4/Circulation/Main.pm b/C4/Circulation/Main.pm new file mode 100755 index 0000000..4dab85f --- /dev/null +++ b/C4/Circulation/Main.pm @@ -0,0 +1,185 @@ +package C4::Circulation::Main; #asummes C4/Circulation/Main + +#package to deal with circulation + +use strict; +require Exporter; +use DBI; +use C4::Database; +use C4::Circulation::Issues; +use C4::Circulation::Returns; +use C4::Circulation::Renewals; +use C4::Circulation::Borrower; +use C4::Reserves; +use C4::Interface; +use C4::Security; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +# set the version for version checking +$VERSION = 0.01; + +@ISA = qw(Exporter); +@EXPORT = qw(&pastitems &checkoverdues &previousissue +&checkreserve &checkwaiting &scanbook &scanborrower ); +%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 pastitems{ + #Get list of all items borrower has currently on issue + my ($env,$bornum,$dbh)=@_; + my $sth=$dbh->prepare("Select * from issues,items,biblio + where borrowernumber=$bornum and issues.itemnumber=items.itemnumber + and items.biblionumber=biblio.biblionumber + and returndate is null + order by date_due"); + $sth->execute; + my $i=0; + my @items; + my @items2; + #$items[0]=" "x29; + #$items2[0]=" "x29; + $items[0]=" "x72; + $items2[0]=" "x72; + while (my $data=$sth->fetchrow_hashref) { + my $line = "$data->{'date_due'} $data->{'title'}"; + # $items[$i]=fmtstr($env,$line,"L29"); + $items[$i]=fmtstr($env,$line,"L72"); + $i++; + } + return(\@items,\@items2); +} + +sub checkoverdues{ + #checks whether a borrower has overdue items + my ($env,$bornum,$dbh)=@_; + my $sth=$dbh->prepare("Select * from issues,items,biblio where + borrowernumber=$bornum and issues.itemnumber=items.itemnumber and + items.biblionumber=biblio.biblionumber"); + $sth->execute; + my $row=1; + my $col=40; + while (my $data=$sth->fetchrow_hashref){ + output($row,$col,$data->{'title'}); + $row++; + } + $sth->finish; +} + +sub previousissue { + my ($env,$itemnum,$dbh,$bornum)=@_; + my $sth=$dbh->prepare("Select firstname,surname,issues.borrowernumber,cardnumber,returndate + from issues,borrowers where + issues.itemnumber='$itemnum' and + issues.borrowernumber=borrowers.borrowernumber and issues.returndate is +NULL"); + $sth->execute; + my $borrower=$sth->fetchrow_hashref; + $sth->finish; + if ($borrower->{'borrowernumber'} ne ''){ + if ($bornum eq $borrower->{'borrowernumber'}){ + # no need to issue + my ($renewstatus) = &renewstatus($env,$dbh,$bornum,$itemnum); + my $resp = &msg_yn("Book is issued to this borrower", "Renew?"); + if ($resp == "y") { + &renewbook($env,$dbh,$bornum,$itemnum); + } + + } else { + my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})"; + my $resp = &msg_yn($text,"Mark as returned?"); + if ($resp == "y") { + &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum); + # can issue + } else { + # can't issue + } + } + } + return($borrower->{'borrowernumber'}); +} + + +sub checkreserve{ + # Check for reserves for biblio + # does not look at constraints yet + my ($env,$dbh,$itemnum)=@_; + my $resbor = ""; + my $query = "select * from reserves,items + where (items.itemnumber = '$itemnum') + and (items.biblionumber = reserves.biblionumber) + and (reserves.found is null) order by priority"; + my $sth = $dbh->prepare($query); + $sth->execute(); + if (my $data=$sth->fetchrow_hashref) { + $resbor = $data->{'borrowernumber'}; + } + return ($resbor); +} + +sub checkwaiting{ + # check for reserves waiting + my ($env,$dbh,$bornum)=@_; + my @itemswaiting=""; + my $query = "select * from reserves + where (borrowernumber = '$bornum') + and (reserves.found='W')"; + my $sth = $dbh->prepare($query); + $sth->execute(); + if (my $data=$sth->fetchrow_hashref) { + push @itemswaiting,$data->{'itemnumber'}; + } + return (\@itemswaiting); +} + +sub scanbook { + my ($env,$interface)=@_; + #scan barcode + my ($number,$reason)=dialog("Book Barcode:"); + $number=uc $number; + return ($number,$reason); +} + +sub scanborrower { + my ($env,$interface)=@_; + #scan barcode + my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface + $number= $number; + $book=uc $book; + return ($number,$reason,$book); +} + + +END { } # module clean-up code here (global destructor) diff --git a/C4/Circulation/Renewals.pm b/C4/Circulation/Renewals.pm index 851c0af..7d85067 100755 --- a/C4/Circulation/Renewals.pm +++ b/C4/Circulation/Renewals.pm @@ -1,4 +1,4 @@ -package C4::Circulation; #assumes C4/Circulation/Renewals +package C4::Circulation::Renewals; #assumes C4/Circulation/Renewals #package to deal with Renewals #written 7/11/99 by olwen@katipo.co.nz @@ -9,7 +9,7 @@ use DBI; use C4::Database; use C4::Accounts; use C4::Interface; -use C4::Circulation; +use C4::Circulation::Renewals; use C4::Scan; use C4::Stats; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); diff --git a/C4/Circulation/Returns.pm b/C4/Circulation/Returns.pm index 619ab64..30afcf6 100755 --- a/C4/Circulation/Returns.pm +++ b/C4/Circulation/Returns.pm @@ -1,4 +1,4 @@ -package C4::Circulation; #assumes C4/Circulation/Returns +package C4::Circulation::Returns; #assumes C4/Circulation/Returns #package to deal with Returns #written 3/11/99 by olwen@katipo.co.nz @@ -9,7 +9,7 @@ use DBI; use C4::Database; use C4::Accounts; use C4::Interface; -use C4::Circulation; +use C4::Circulation::Main; use C4::Format; use C4::Scan; use C4::Stats; diff --git a/C4/Interface.pm b/C4/Interface.pm index 8d714f0..7ff93d3 100755 --- a/C4/Interface.pm +++ b/C4/Interface.pm @@ -2,6 +2,7 @@ package C4::Interface; #asummes C4/Interface #uses Newt use C4::Format; +use C4::Interface::Funkeys; use strict; #use Newt qw(:keys :exits :anchors :flags :colorsets :entry :fd :grid :macros #:textbox); @@ -76,47 +77,36 @@ sub startint { } sub menu { - my ($type,$title,@items)=@_; + my ($env,$type,$title,@items)=@_; if ($type eq 'console'){ - my ($reason,$data)=menu2($title,@items); + my ($reason,$data)=menu2($env,$title,@items); return($reason,$data); # end of menu } } sub menu2 { - my ($title,@items)=@_; + my ($env,$title,@items)=@_; my $numitems=@items; my $panel = Newt::Panel(1, $numitems+1, $title); my @buttons; my $i=0; + $env->{'sysarea'}="Menu"; while ($i < $numitems) { $buttons[$i] = Newt::Button(fmtstr("",@items[$i],"C20"),1); $buttons[$i]->Tag(@items[$i]); $panel->Add(0,$i,$buttons[$i]); $i++; } - Newt::PushHelpLine('F11 QUIT: F2 Issues: F3 Returns: F4 Reserves'); - $panel->AddHotKey(NEWT_KEY_F2); - $panel->AddHotKey(NEWT_KEY_F3); - $panel->AddHotKey(NEWT_KEY_F4); - $panel->AddHotKey(NEWT_KEY_F11); - $panel->AddHotKey(NEWT_KEY_F12); + my $helpline = setupkeys($env,$panel); + Newt::PushHelpLine($helpline); my ($reason,$data)=$panel->Run(); - if ($reason eq NEWT_EXIT_HOTKEY) { - #debug_msg("","hot "); - if ($data eq NEWT_KEY_F11) { - $stuff="Quit"; - } elsif ($data eq NEWT_KEY_F3) { - $stuff="Returns"; - } elsif ($data eq NEWT_KEY_F2) { - $stuff="Issues"; - } elsif ($data eq NEWT_KEY_F4) { - $stuff="Reserves"; - } - } else { + $stuff = checkkeys($env,$reason,$data); + if ($stuff eq "") { $stuff = $data->Tag(); } + #debug_msg($env,$stuff); + Newt::PopHelpLine(); return($reason,$stuff); # end of menu2 } @@ -233,6 +223,7 @@ sub returnwindow { $stuff=$entry->Get(); $reason=""; } + Newt::PopHelpLine(); #debug_msg($env, "reas $reason"); #debug_msg($env, "stuff $stuff"); return($reason,$stuff); @@ -280,7 +271,6 @@ sub issuewindow { my $panel2 = Newt::Panel(10,10); $panel->Add(0,0,$panel1); $panel->Add(0,1,$panel2); - my $l1 = Newt::Label("Previous"); my $l2 = Newt::Label("Current"); my $l3 = Newt::Label("Borrower Info"); @@ -345,7 +335,7 @@ sub issuewindow { } } - debug_msg("",$reason); +# debug_msg("",$reason); # Newt::Finished(); my $stuff=$entry->Get(); return($stuff,$reason); @@ -452,6 +442,7 @@ sub borrower_dialog { } # debug_msg($env,"Re $reason"); # Newt::Finished(); + Newt::PopHelpLine() ; my $stuff=$entry->Get(); my $stuff2=$entry2->Get(); return($stuff,$reason,$stuff2); diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 5b742db..935189b 100755 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -10,7 +10,7 @@ use C4::Database; use C4::Format; use C4::Interface; use C4::Interface::Reserveentry; -use C4::Circulation; +use C4::Circulation::Main; use C4::Circulation::Borrower; use C4::Search; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); diff --git a/owtest.pl b/owtest.pl index e400d17..17eb03c 100755 --- a/owtest.pl +++ b/owtest.pl @@ -2,14 +2,7 @@ use strict; use C4::Security; -use C4::Circulation; -use C4::Circulation::Issues; -use C4::Circulation::Returns; -use C4::Circulation::Renewals; -use C4::Circulation::Borrower; -use C4::Reserves; -use C4::Interface; -use C4::Security; +use C4::Circmain; # set up environment array # branchcode - logged on branch diff --git a/testissue.pl b/testissue.pl index 4a7f7f5..91e86a5 100755 --- a/testissue.pl +++ b/testissue.pl @@ -2,7 +2,7 @@ use strict; use C4::Security; -use C4::Circulation; +use C4::Circmain; # set up environment array # branchcode - logged on branch