use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
-$VERSION = 0.01; # FIXME - Should probably be different from
- # the version for C4::Accounts
+$VERSION = 0.01; # FIXME - Should probably be different from
+ # the version for C4::Accounts
=head1 NAME
sub recordpayment{
#here we update both the accountoffsets and the account lines
my ($env,$bornumber,$data)=@_;
+ warn "in accounts2.pm";
my $dbh = C4::Context->dbh;
my $newamtos = 0;
my $accdata = "";
my $branch=$env->{'branchcode'};
+ warn $branch;
my $amountleft = $data;
# begin transaction
my $nextaccntno = getnextacctno($env,$bornumber,$dbh);
while (($accdata=$sth->fetchrow_hashref) and ($amountleft>0)){
if ($accdata->{'amountoutstanding'} < $amountleft) {
$newamtos = 0;
- $amountleft -= $accdata->{'amountoutstanding'};
+ $amountleft -= $accdata->{'amountoutstanding'};
} else {
$newamtos = $accdata->{'amountoutstanding'} - $amountleft;
- $amountleft = 0;
+ $amountleft = 0;
}
my $thisacct = $accdata->{accountno};
my $usth = $dbh->prepare("update accountlines set amountoutstanding= ?
#here we update both the accountoffsets and the account lines
#updated to check, if they are paying off a lost item, we return the item
# from their card, and put a note on the item record
- my ($bornumber,$accountno,$amount,$user)=@_;
- my $env;
+ my ($bornumber,$accountno,$amount,$user,$branch)=@_;
+ my %env;
+ $env{'branchcode'}=$branch;
my $dbh = C4::Context->dbh;
# begin transaction
- my $nextaccntno = getnextacctno($env,$bornumber,$dbh);
+ my $nextaccntno = getnextacctno(\%env,$bornumber,$dbh);
my $newamtos=0;
my $sth=$dbh->prepare("Select * from accountlines where borrowernumber=? and accountno=?");
$sth->execute($bornumber,$accountno);
$sth->finish;
$dbh->do(<<EOT);
- UPDATE accountlines
- SET amountoutstanding = 0
- WHERE borrowernumber = $bornumber
- AND accountno = $accountno
+ UPDATE accountlines
+ SET amountoutstanding = 0
+ WHERE borrowernumber = $bornumber
+ AND accountno = $accountno
EOT
# print $updquery;
$dbh->do(<<EOT);
- INSERT INTO accountoffsets
- (borrowernumber, accountno, offsetaccount,
- offsetamount)
- VALUES ($bornumber, $accountno, $nextaccntno, $newamtos)
+ INSERT INTO accountoffsets
+ (borrowernumber, accountno, offsetaccount,
+ offsetamount)
+ VALUES ($bornumber, $accountno, $nextaccntno, $newamtos)
EOT
# create new line
my $payment=0-$amount;
$dbh->do(<<EOT);
- INSERT INTO accountlines
- (borrowernumber, accountno, date, amount,
- description, accounttype, amountoutstanding)
- VALUES ($bornumber, $nextaccntno, now(), $payment,
- 'Payment,thanks - $user', 'Pay', 0)
+ INSERT INTO accountlines
+ (borrowernumber, accountno, date, amount,
+ description, accounttype, amountoutstanding)
+ VALUES ($bornumber, $nextaccntno, now(), $payment,
+ 'Payment,thanks - $user', 'Pay', 0)
EOT
# FIXME - The second argument to &UpdateStats is supposed to be the
# branch code.
- UpdateStats($env,$user,'payment',$amount,'','','',$bornumber);
+ # UpdateStats is now being passed $accountno too. MTJ
+ UpdateStats(\%env,$user,'payment',$amount,'','','',$bornumber,$accountno);
$sth->finish;
#check to see what accounttype
if ($data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L'){
and accountno=?");
$sth->execute($borrowernumber,$accountno);
my $data=$sth->fetchrow_hashref;
- # FIXME - Error-checking
+ # FIXME - Error-checking
my $diff=$amount-$data->{'amount'};
my $outstanding=$data->{'amountoutstanding'}+$diff;
$sth->finish;
$dbh->do(<<EOT);
- UPDATE accountlines
- SET amount = '$amount',
- amountoutstanding = '$outstanding'
- WHERE borrowernumber = $borrowernumber
- AND accountno = $accountno
+ UPDATE accountlines
+ SET amount = '$amount',
+ amountoutstanding = '$outstanding'
+ WHERE borrowernumber = $borrowernumber
+ AND accountno = $accountno
EOT
}
if ($type eq 'CS' || $type eq 'CB' || $type eq 'CW'
|| $type eq 'CF' || $type eq 'CL'){
- my $amount2=$amount*-1; # FIXME - $amount2 = -$amount
+ my $amount2=$amount*-1; # FIXME - $amount2 = -$amount
$amountleft=fixcredit(\%env,$bornum,$amount2,$itemnum,$type,$user);
}
if ($type eq 'N'){
$amountleft=refund('',$bornum,$amount);
}
if ($itemnum ne ''){
+#FIXME to use ? before uncommenting
+# my $sth=$dbh->prepare("Select * from items where barcode='$itemnum'");
+# $sth->execute;
+# my $data=$sth->fetchrow_hashref;
+# $sth->finish;
$desc.=" ".$itemnum;
- my $sth=$dbh->prepare("INSERT INTO accountlines
- (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber)
- VALUES (?, ?, now(), ?,?, ?,?,?)");
+ my $sth=$dbh->prepare("INSERT INTO accountlines
+ (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber)
+ VALUES (?, ?, now(), ?,?, ?,?,?)");
# $sth->execute($bornum, $accountno, $amount, $desc, $type, $amountleft, $data->{'itemnumber'});
$sth->execute($bornum, $accountno, $amount, $desc, $type, $amountleft, $itemnum);
} else {
- my $sth=$dbh->prepare("INSERT INTO accountlines
- (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding)
- VALUES (?, ?, now(), ?, ?, ?, ?)");
+ $desc=$dbh->quote($desc);
+ my $sth=$dbh->prepare("INSERT INTO accountlines
+ (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding)
+ VALUES (?, ?, now(), ?, ?, ?, ?)");
$sth->execute($bornum, $accountno, $amount, $desc, $type, $amountleft);
}
}
$sth->finish;
if ($accdata->{'amountoutstanding'} < $amountleft) {
$newamtos = 0;
- $amountleft -= $accdata->{'amountoutstanding'};
+ $amountleft -= $accdata->{'amountoutstanding'};
} else {
$newamtos = $accdata->{'amountoutstanding'} - $amountleft;
- $amountleft = 0;
+ $amountleft = 0;
}
my $thisacct = $accdata->{accountno};
my $usth = $dbh->prepare("update accountlines set amountoutstanding= ?
while (($accdata=$sth->fetchrow_hashref) and ($amountleft>0)){
if ($accdata->{'amountoutstanding'} < $amountleft) {
$newamtos = 0;
- $amountleft -= $accdata->{'amountoutstanding'};
+ $amountleft -= $accdata->{'amountoutstanding'};
} else {
$newamtos = $accdata->{'amountoutstanding'} - $amountleft;
- $amountleft = 0;
+ $amountleft = 0;
}
my $thisacct = $accdata->{accountno};
my $usth = $dbh->prepare("update accountlines set amountoutstanding= ?
while (($accdata=$sth->fetchrow_hashref) and ($amountleft<0)){
if ($accdata->{'amountoutstanding'} > $amountleft) {
$newamtos = 0;
- $amountleft -= $accdata->{'amountoutstanding'};
+ $amountleft -= $accdata->{'amountoutstanding'};
} else {
$newamtos = $accdata->{'amountoutstanding'} - $amountleft;
- $amountleft = 0;
+ $amountleft = 0;
}
# print $amountleft;
my $thisacct = $accdata->{accountno};
DBI(3)
=cut
+