1 package C4::Accounts2; #asummes C4/Accounts2
3 #requires DBI.pm to be installed
12 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
14 # set the version for version checking
18 @EXPORT = qw(&recordpayment &fixaccounts &makepayment);
19 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
21 # your exported package globals go here,
22 # as well as any optionally exported functions
24 @EXPORT_OK = qw($Var1 %Hashit);
27 # non-exported package globals go here
28 use vars qw(@more $stuff);
30 # initalize package globals, first exported ones
35 # then the others (which are still accessible as $Some::Module::stuff)
39 # all file-scoped lexicals must be created before
40 # the functions below that use them.
42 # file-private lexicals go here
46 # here's a file-private function as a closure,
47 # callable as &$priv_func; it cannot be prototyped.
52 # make all your functions, whether exported or not;
59 #here we update both the accountoffsets and the account lines
60 my ($env,$bornumber,$data)=@_;
65 my $branch=$env->{'branchcode'};
66 my $amountleft = $data;
68 my $nextaccntno = getnextacctno($env,$bornumber,$dbh);
69 # get lines with outstanding amounts to offset
70 my $query = "select * from accountlines
71 where (borrowernumber = '$bornumber') and (amountoutstanding<>0)
73 my $sth = $dbh->prepare($query);
76 while (($accdata=$sth->fetchrow_hashref) and ($amountleft>0)){
77 if ($accdata->{'amountoutstanding'} < $amountleft) {
79 $amountleft = $amountleft - $accdata->{'amountoutstanding'};
81 $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
84 my $thisacct = $accdata->{accountno};
85 $updquery = "update accountlines set amountoutstanding= '$newamtos'
86 where (borrowernumber = '$bornumber') and (accountno='$thisacct')";
87 my $usth = $dbh->prepare($updquery);
90 $updquery = "insert into accountoffsets
91 (borrowernumber, accountno, offsetaccount, offsetamount)
92 values ($bornumber,$accdata->{'accountno'},$nextaccntno,$newamtos)";
93 my $usth = $dbh->prepare($updquery);
98 $updquery = "insert into accountlines
99 (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
100 values ($bornumber,$nextaccntno,now(),0-$data,'Payment,thanks',
101 'Pay',0-$amountleft)";
102 my $usth = $dbh->prepare($updquery);
105 UpdateStats($env,$branch,'payment',$data,'','','',$bornumber);
111 #here we update both the accountoffsets and the account lines
112 #updated to check, if they are paying off a lost item, we return the item
113 # from their card, and put a note on the item record
114 my ($bornumber,$accountno,$amount,$user)=@_;
118 my $nextaccntno = getnextacctno($env,$bornumber,$dbh);
120 my $sel="Select * from accountlines where borrowernumber=$bornumber and
121 accountno=$accountno";
122 my $sth=$dbh->prepare($sel);
124 my $data=$sth->fetchrow_hashref;
126 my $updquery="Update accountlines set amountoutstanding=0 where
127 borrowernumber=$bornumber and accountno=$accountno";
128 $sth=$dbh->prepare($updquery);
132 $updquery = "insert into accountoffsets
133 (borrowernumber, accountno, offsetaccount, offsetamount)
134 values ($bornumber,$accountno,$nextaccntno,$newamtos)";
135 my $usth = $dbh->prepare($updquery);
139 my $payment=0-$amount;
140 $updquery = "insert into accountlines
141 (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
142 values ($bornumber,$nextaccntno,now(),$payment,'Payment,thanks - $user', 'Pay',0)";
143 my $usth = $dbh->prepare($updquery);
146 UpdateStats($env,$user,'payment',$amount,'','','',$bornumber);
149 #check to see what accounttype
150 if ($data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L'){
151 returnlost($bornumber,$data->{'itemnumber'});
156 my ($env,$bornumber,$dbh)=@_;
158 my $query = "select * from accountlines
159 where (borrowernumber = '$bornumber')
160 order by accountno desc";
161 my $sth = $dbh->prepare($query);
163 if (my $accdata=$sth->fetchrow_hashref){
164 $nextaccntno = $accdata->{'accountno'} + 1;
167 return($nextaccntno);
171 my ($borrowernumber,$accountno,$amount)=@_;
173 my $query="Select * from accountlines where borrowernumber=$borrowernumber
174 and accountno=$accountno";
175 my $sth=$dbh->prepare($query);
177 my $data=$sth->fetchrow_hashref;
178 my $diff=$amount-$data->{'amount'};
179 my $outstanding=$data->{'amountoutstanding'}+$diff;
181 $query="Update accountlines set amount='$amount',amountoutstanding='$outstanding' where
182 borrowernumber=$borrowernumber and accountno=$accountno";
183 $sth=$dbh->prepare($query);
191 my ($borrnum,$itemnum)=@_;
193 my $borrower=borrdata('',$borrnum); #from C4::Search;
194 my $upiss="Update issues set returndate=now() where
195 borrowernumber='$borrnum' and itemnumber='$itemnum' and returndate is null";
196 my $sth=$dbh->prepare($upiss);
199 my @datearr = localtime($time);
200 my $date = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
201 my $bor="$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
202 my $upitem="Update items set itemnotes='Paid for by $bor $date' where itemnumber='$itemnum'";
203 $sth=$dbh->prepare($upitem);
209 END { } # module clean-up code here (global destructor)