Initial revision
[wip/koha-chris_n.git] / borrwraper.pl
1 #!/usr/bin/perl
2
3 use DBI;
4 use C4::Database;
5 use C4::Circulation::Issues;
6 use C4::Circulation::Main;
7 use C4::InterfaceCDK;
8 use C4::Circulation::Borrower;
9
10 # my @args=('issuewrapper.pl',"$env{'branchcode'}","$env{'usercode'}","$env{'telnet'}","$env{'queue'}","$env{'printtype'}");
11 my %env = (
12   branchcode => $ARGV[0], usercode => $ARGV[1], proccode => "lgon", borrowernumber => "",
13   logintime  => "", lasttime => "", tempuser => "", debug => "9",
14   telnet => $ARGV[2], queue => $ARGV[3], printtype => $ARGV[4], brdata => $ARGV[5],
15   bcard=>$ARGV[6]  
16       );
17 my ($env) = \%env;                                                                  
18   startint();
19   helptext('');                                                                    
20 my $done;                                                                        
21 my ($items,$items2,$amountdue);                                                  
22 my $itemsdet;                                                                    
23 $env->{'sysarea'} = "Issues";                                                    
24 $done = "Issues";                                                                
25 my $i=0;
26 my $dbh=&C4Connect;                                                              
27   my ($bornum,$issuesallowed,$borrower,$reason,$amountdue) = C4::Circulation::Borrower::findborrower($env,$dbh);
28   $env->{'loanlength'}="";                                                       
29   if ($reason ne "") {                                                           
30     $done = $reason;                                                             
31   } elsif ($env->{'IssuesAllowed'} eq '0') {                                     
32     error_msg($env,"No Issues Allowed =$env->{'IssuesAllowed'}");                
33   } else {                                                                       
34     $env->{'bornum'} = $bornum;                                                  
35     $env->{'bcard'}  = $borrower->{'cardnumber'};                                
36     ($items,$items2)=C4::Circulation::Main::pastitems($env,$bornum,$dbh); #from Circulation.pm    
37     $done = "No";                                                                
38     my $it2p=0;                                                                  
39     while ($done eq 'No'){                                                       
40       ($done,$items2,$it2p,$amountdue,$itemsdet) = C4::Circulation::Issues::processitems($env,$bornum,$borrower,$items,$items2,$it2p,$amountdue,$itemsdet);                                    
41     }                                                                            
42     
43   } 
44   if ($done ne 'Issues'){
45       $dbh->disconnect;                                                                
46       die "test";
47   }
48 $dbh->disconnect;