<?
include "./auth.inc.php";
include "./mysql.inc.php";
print count($PaymentID);
print "\n";
for ($i=1;$i<=count($PaymentID);$i++){
print "$PaymentID[$i]: $Status[$i] ";
#check for concurrency
$csql = "SELECT Credit FROM Payments WHERE PaymentID = $PaymentID[$i]";
$cres = mysql_query($csql);
$cresult = mysql_result($cres,0);
if ($cresult){
$sql="SELECT FirstName, LastName, Payments.CustomerID AS ID,
PaymentAmount, ResellerCommission,AgentCommission,
ResellerPayment,ResellerOriginal, Purchase
FROM Payments, MasterAccounts
WHERE MasterAccounts.CustomerID=Payments.CustomerID
AND PaymentID=$PaymentID[$i]";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
switch ($Status[$i]){
case 10:
print "Paid! Removing from debtors list.";
$psql="UPDATE Payments SET credit=0 WHERE PaymentID=$PaymentID[$i]";
mysql_query($psql);
break;
case -1:
print "Cancel.";
#create a negative payment.
$psql="UPDATE Payments SET credit=-1 WHERE PaymentID=$PaymentID[$i]";
mysql_query($psql);
$cansql="INSERT INTO Payments(CustomerID,
PaymentAmount, PaymentType, PaymentDate,Purchase,
ResellerOriginal, ResellerPayment,
AgentCommission, ResellerCommission)
VALUES('$row[ID]','-$row[PaymentAmount]','Cancel',now(),'$PaymentID[$i]',
'$row[ResellerOriginal]','$row[ResellerPayment]',
'-$row[AgentCommission]','-$row[ResellerCommission]')";
#print $cansql;
mysql_query($cansql);
print "<BR>Negative Payment Added for \$$row[PaymentAmount]. Please Edit <A
HREF=\"edit.php?ID=$row[ID]\">$row[FirstName] $row[LastName]. </A> to
manually remove the purchase of: <B>$row[Purchase]</B>.";
break;
case 1:
print "Still Pending.";
#update anyway, in case we're changing a declined
#back to pending
$psql="UPDATE Payments SET credit=1 WHERE PaymentID=$PaymentID[$i]";
mysql_query($psql);
break;
case 2:
print "Payment Declined";
$psql="UPDATE Payments SET credit=2 WHERE PaymentID=$PaymentID[$i]";
mysql_query($psql);
break;
default:
#wtf;
print "Unknown.";
break;
}
print "<BR>";
}else{
print "<B>Payment Already Paid. Possible Concurrency Problem</B>";
}
}
?>