function ProcessFee($TransactionID, $AccountID, $Amount, $sellorbuy) { $lookupfeeexempt = mysql_query("SELECT AccountIsFeeExempt\n FROM account\n WHERE AccountID = '{$AccountID}'"); if (mysql_result($lookupfeeexempt, '0', "AccountIsFeeExempt") == 0) { if ($sellorbuy == 'sell') { $lookuptransactionfee = mysql_query("SELECT AccountTypeSaleTransactionFee AS Fee\n FROM account, accounttypeoptions\n WHERE account.AccountTypeID = accounttypeoptions.AccountTypeID\n AND account.AccountID = '{$AccountID}'"); } else { $lookuptransactionfee = mysql_query("SELECT AccountTypeBuyTransactionFee AS Fee\n FROM account, accounttypeoptions\n WHERE account.AccountTypeID = accounttypeoptions.AccountTypeID\n AND account.AccountID = '{$AccountID}'"); } $transactionfee = mysql_result($lookuptransactionfee, '0', "Fee"); $FeeAmount = $transactionfee * $Amount; if ($FeeAmount > 0) { if ($sellorbuy == 'sell') { $GLOBALS["SellerFee"] = $FeeAmount; } else { $GLOBALS["BuyerFee"] = $FeeAmount; } SubmitTrade($TransactionID, $AccountID, -$FeeAmount, "Transaction Fee", $GLOBALS["SystemAccountID"]); $lookupSystemtransactions = mysql_query("SELECT * FROM transactions\n WHERE TransactionID = '{$TransactionID}'\n AND AccountID = '{$GLOBALS['SystemAccountID']}'\n AND Description = 'Transaction Fee'"); if (mysql_num_rows($lookupSystemtransactions) == 0) { SubmitTrade($TransactionID, $GLOBALS["SystemAccountID"], $FeeAmount, "Transaction Fee", $AccountID); } else { $previous = mysql_fetch_array($lookupSystemtransactions); $CurrentBalance = $previous["CurrentBalance"] + $FeeAmount; $NewAmount = $previous["Amount"] + $FeeAmount; $update = mysql_query("UPDATE transactions\n SET Amount = '{$NewAmount}', CurrentBalance = '{$CurrentBalance}', OtherAccountID = ''\n WHERE AccountID = '{$GLOBALS['SystemAccountID']}'\n AND Description = 'Transaction Fee'\n AND TransactionID = '{$TransactionID}'"); } } } }
case 1: $title = 'Unable to Process'; include "header.php"; print "<h2>Account Balance Too High</h2>\n\t\tYour account, number {$ToAccount}, has a balance that exceeds the permitted maximum. You cannot enter this cheque until your balance returns to within acceptable limits."; include "footer.php"; exit; break; case 2: $SellerOver = "<strong>WARNING:</strong>"; break; default: } // seems all is good. Now we can record the trade. include "recordtrade.php"; // get a transaction ID $transIDtime = time(); mysql_query("INSERT INTO transidlookup\n\t\t VALUES ('','{$transIDtime}','{$MemberID}')"); $transIDlookup = mysql_query("SELECT TransactionID FROM transidlookup\n\t\t\t WHERE Time = {$transIDtime}\n\t\t\t AND MemberID = {$MemberID}"); $TransactionID = mysql_result($transIDlookup, 0, 'TransactionID'); // update the Cheque table to show Transaction ID mysql_query("UPDATE cheques\n\t\tSET TransactionID = {$TransactionID}\n\t\tWHERE ChequeID = {$ChequeID}"); // enter the transaction SubmitTrade($TransactionID, $Cheque["AccountID"], -$Amount, "Cheque {$ChequeID}: {$Memo}", $ToAccount); SubmitTrade($TransactionID, $ToAccount, $Amount, "Cheque {$ChequeID}: {$Memo}", $Cheque["AccountID"]); ProcessFee($TransactionID, $ToAccount, $Amount, 'sell'); ProcessFee($TransactionID, $Cheque["AccountID"], $Amount, 'buy'); $title = 'Cheque Registered'; include 'header.php'; print "<h2>Cheque Registered</h2>\n\tCheque {$ChequeID} has been registered, and the amount of {$Amount} Ecos has been transferred to Account {$ToAccount}.<p>\n\tTo have this transaction reversed, contact the <a href=mailto:{$SystemEmail}>system administrator</a><p>\n\t<hr><p>\n\t<strong>To register another cheque complete the form below:</strong><p>\n"; PrintForm('', '', '', ''); include 'footer.php';
if (mysql_num_rows($lookuptransid) != 1) { $title = "Data Submission Error"; include "header.php"; print "<h1>Trade Entry Data Error</h1>\n \t<h3>There was an error in the submission of your trading data.</h3>\n Please ensure that you have submitted this data using the <a href=tradeentry.php>Trade Entry form</a>."; include "footer.php"; exit; } if (!mysql_query("DELETE FROM transidlookup WHERE TransactionID = '{$TransactionID}'")) { mail($admin_email, "LETS DATABASE ERROR", "The LETS System was unable to delete Transaction {$TransactionID} from the transidlookup table.\n\nThe error reported was:\n\n" . mysql_error() . "\n\nThis message is generated automatically"); } /* clean up the description */ $Description = stripslashes($Description); /* Submit the transaction for the seller account */ SubmitTrade($TransactionID, $SellerID, $Amount, $Description, $BuyerID); /* Submit the transaction for the buyer account */ SubmitTrade($TransactionID, $BuyerID, -$Amount, $Description, $SellerID); /* Process the transaction fees */ ProcessFee($TransactionID, $SellerID, $Amount, 'sell'); ProcessFee($TransactionID, $BuyerID, $Amount, 'buy'); /* Print a receipt */ if ($EnteredBy == 'seller') { $AccountID = $SellerID; } else { $AccountID = $BuyerID; } $title = "Transaction Recorded"; include "header.php"; print "<h1>Transaction Recorded</h1>\n \t<h3>This page is your record of transaction for this trade.</h3>\n Please print this page if you wish to keep a copy for your records.<p>\n <table noborder>\n <tr><th align=center bgcolor=#D3D3D3 colspan=2>Transaction Record</th></tr>\n <tr><th align=left>Transaction Number: </th><td>{$TransactionID}</td></tr>\n <tr><th align=left>Member:</th><td>{$MemberID}: {$MemberFirstName}</td></tr>\n <tr><th align=left>Credited to Account: </th><td>{$SellerID}</td></tr>\n <tr><th align=left>Debited to Account: </th><td>{$BuyerID}</td></tr>\n <tr><th align=left>Trade Amount: </th><td>{$Amount}</td></tr>\n <tr><th align=left>Description: </th><td>{$Description}</td></tr>\n <tr><th align=left valign=top>Service Fees: </td><td><table noborder>"; if (!empty($SellerFee)) { print "<tr><td>To Seller: {$SellerFee}</td></tr>"; }
} } elseif (SellerOverLimit($SellerID["{$trade}"], $Amount["{$trade}"])) { if (WasWarned($BuyerID["{$trade}"], $SellerID["{$trade}"], 'Over Limit')) { $Result["{$trade}"] = "Not Processed. <em>Seller Account is over limit and Buyer has received a previous warning</em>"; } } else { /* Get a transactionID */ $transidtime = time(); if (!mysql_query("INSERT INTO transidlookup\n VALUES('','{$transidtime}','{$MemberID}')")) { $Result["{$trade}"] = "Not Processed. <em>The database was unable to lookup a transaction ID</em>."; } else { $lookuptransid = mysql_query("SELECT TransactionID\n FROM transidlookup\n WHERE Time = '{$transidtime}'\n AND MemberID = '{$MemberID}'"); $TransactionID = mysql_result($lookuptransid, 0, "TransactionID"); /* Submit the transactions */ SubmitTrade($TransactionID, $SellerID["{$trade}"], $Amount["{$trade}"], $Description["{$trade}"], $BuyerID["{$trade}"]); SubmitTrade($TransactionID, $BuyerID["{$trade}"], -$Amount["{$trade}"], $Description["{$trade}"], $SellerID["{$trade}"]); ProcessFee($TransactionID, $SellerID["{$trade}"], $Amount["{$trade}"], 'sell'); ProcessFee($TransactionID, $BuyerID["{$trade}"], $Amount["{$trade}"], 'buy'); /* And set the result variable */ $Result["{$trade}"] = "Processed. Transaction ID #{$TransactionID}."; /* Delete the transidlookup record and log the trade in the AdminActions Log */ mysql_query("DELETE FROM transidlookup\n WHERE TransactionID = '{$TransactionID}'"); mysql_query("INSERT INTO adminactions\n VALUES(NULL,'{$MemberID}','Registered Transaction {$TransactionID}')"); unset($TransactionID); } } } } /* Print a results table */ $title = "Administration Trade Entry Results"; include "header.php";