Update of /cvsroot/koha/koha/C4 In directory usw-pr-cvs1:/tmp/cvs-serv13280/C4 Modified Files: Accounts2.pm Log Message: Fix for manual invoices Index: Accounts2.pm =================================================================== RCS file: /cvsroot/koha/koha/C4/Accounts2.pm,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** Accounts2.pm 15 May 2001 23:05:43 -0000 1.8 --- Accounts2.pm 11 Mar 2002 03:36:41 -0000 1.9 *************** *** 10,13 **** --- 10,14 ---- use C4::Stats; use C4::Search; + use C4::Circulation::Circ2; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); *************** *** 209,222 **** sub manualinvoice{ ! my ($bornum,$itemnum,$desc,$type,$amount)=@_; my $dbh=C4Connect; my $insert; $itemnum=~ s/ //g; my $accountno=getnextacctno('',$bornum,$dbh); my $amountleft=$amount; ! if ($type eq 'C' || $type eq 'BAY' || $type eq 'WORK'){ my $amount2=$amount*-1; ! $amountleft=fixcredit('',$bornum,$amount2); } if ($type eq 'N'){ --- 210,225 ---- sub manualinvoice{ ! my ($bornum,$itemnum,$desc,$type,$amount,$user)=@_; my $dbh=C4Connect; my $insert; $itemnum=~ s/ //g; + my %env; my $accountno=getnextacctno('',$bornum,$dbh); my $amountleft=$amount; ! if ($type eq 'CS' || $type eq 'CB' || $type eq 'CW' ! || $type eq 'CF' || $type eq 'CL'){ my $amount2=$amount*-1; ! $amountleft=fixcredit(\%env,$bornum,$amount2,$itemnum,$type,$user); } if ($type eq 'N'){ *************** *** 235,243 **** $sth->finish; $desc.=" ".$itemnum; $insert="insert into accountlines (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber) ! values ($bornum,$accountno,now(),'$amount','$desc','$type','$amountleft','$data->{'itemnumber'}')"; } else { $insert="insert into accountlines (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) ! values ($bornum,$accountno,now(),'$amount','$desc','$type','$amountleft')"; } --- 238,248 ---- $sth->finish; $desc.=" ".$itemnum; + $desc=$dbh->quote($desc); $insert="insert into accountlines (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber) ! values ($bornum,$accountno,now(),'$amount',$desc,'$type','$amountleft','$data->{'itemnumber'}')"; } else { + $desc=$dbh->quote($desc); $insert="insert into accountlines (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) ! values ($bornum,$accountno,now(),'$amount',$desc,'$type','$amountleft')"; } *************** *** 251,261 **** sub fixcredit{ #here we update both the accountoffsets and the account lines ! my ($env,$bornumber,$data)=@_; my $dbh=C4Connect; my $updquery = ""; my $newamtos = 0; my $accdata = ""; - # my $branch=$env->{'branchcode'}; my $amountleft = $data; # begin transaction my $nextaccntno = getnextacctno($env,$bornumber,$dbh); --- 256,303 ---- sub fixcredit{ #here we update both the accountoffsets and the account lines ! my ($env,$bornumber,$data,$barcode,$type,$user)=@_; my $dbh=C4Connect; my $updquery = ""; my $newamtos = 0; my $accdata = ""; my $amountleft = $data; + if ($barcode ne ''){ + my $item=getiteminformation($env,'',$barcode); + my $nextaccntno = getnextacctno($env,$bornumber,$dbh); + my $query="Select * from accountlines where (borrowernumber='$bornumber' + and itemnumber='$item->{'itemnumber'}' and amountoutstanding > 0)"; + if ($type eq 'CL'){ + $query.=" and (accounttype = 'L' or accounttype = 'Rep')"; + } elsif ($type eq 'CF'){ + $query.=" and (accounttype = 'F' or accounttype = 'FU' or + accounttype='Res' or accounttype='Rent')"; + } elsif ($type eq 'CB'){ + $query.=" and accounttype='A'"; + } + # print $query; + my $sth=$dbh->prepare($query); + $sth->execute; + $accdata=$sth->fetchrow_hashref; + $sth->finish; + if ($accdata->{'amountoutstanding'} < $amountleft) { + $newamtos = 0; + $amountleft = $amountleft - $accdata->{'amountoutstanding'}; + } else { + $newamtos = $accdata->{'amountoutstanding'} - $amountleft; + $amountleft = 0; + } + my $thisacct = $accdata->{accountno}; + my $updquery = "update accountlines set amountoutstanding= '$newamtos' + where (borrowernumber = '$bornumber') and (accountno='$thisacct')"; + my $usth = $dbh->prepare($updquery); + $usth->execute; + $usth->finish; + $updquery = "insert into accountoffsets + (borrowernumber, accountno, offsetaccount, offsetamount) + values ($bornumber,$accdata->{'accountno'},$nextaccntno,$newamtos)"; + my $usth = $dbh->prepare($updquery); + $usth->execute; + $usth->finish; + } # begin transaction my $nextaccntno = getnextacctno($env,$bornumber,$dbh); *************** *** 291,295 **** --- 333,342 ---- $sth->finish; $dbh->disconnect; + $env->{'branch'}=$user; + $type="Credit ".$type; + UpdateStats($env,$user,$type,$data,$user,'','',$bornumber); + $amountleft*=-1; return($amountleft); + }