384 lines
16 KiB
PHP
384 lines
16 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$action = "paypal-log";
|
|
$CurrentTable = "user_paypal_transactions";
|
|
$FormFile = "";
|
|
$TitleText = getLanguageText('TEXT-PAYPAL-ERROR-LOG');
|
|
$OrderBy = "posting_time";
|
|
|
|
if (array_key_exists('type',$_REQUEST) && strlen($_REQUEST['type']) > 0 && $_REQUEST['type'] == 'deleted') {
|
|
$TitleText = "Deleted $TitleText";
|
|
}
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = $TitleText;
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
$school_num = $school_record['record_num'];
|
|
|
|
?>
|
|
|
|
<br>
|
|
<?php
|
|
|
|
$message_width = 600;
|
|
include "form.messages.php";
|
|
|
|
// Flag a transaction as handled
|
|
if (array_key_exists('naction',$_GET) && $_GET['naction'] == 'set-complete') {
|
|
$record_num = intval($_GET['record_num']);
|
|
db_query("UPDATE $CurrentTable SET error_handled = 'Y' WHERE school_num = $school_num AND record_num = $record_num");
|
|
}
|
|
|
|
// Flag a transaction as not handled
|
|
if (array_key_exists('naction',$_GET) && $_GET['naction'] == 'set-incomplete') {
|
|
$record_num = intval($_GET['record_num']);
|
|
db_query("UPDATE $CurrentTable SET error_handled = 'N' WHERE school_num = $school_num AND record_num = $record_num");
|
|
}
|
|
|
|
|
|
// Determine if there are any error records
|
|
$numErrors = db_getVal("SELECT count(*) FROM user_paypal_transactions WHERE school_num = $school_num AND posting_result = 'Error' AND current_year != 'N'");
|
|
|
|
// Select only unprocessed entries
|
|
$swhere = "AND error_handled = 'N' ";
|
|
if (array_key_exists('view',$_GET) && $_GET['view'] == 'all') $swhere = "";
|
|
|
|
//
|
|
// List all requested records
|
|
//
|
|
$query = "SELECT posting_time,payment_date,first_name,last_name,payer_email,mc_currency,mc_gross,mc_fee,payment_type,payment_status,pending_reason," .
|
|
"item_name,business,receiver_email,txn_id,receipt_id,trx_num,user_num,posting_result,posting_message,error_handled,record_num " .
|
|
"FROM user_paypal_transactions " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND posting_result = 'Error' " .
|
|
"AND current_year != 'N' " .
|
|
$swhere .
|
|
"ORDER BY posting_time,last_name";
|
|
$transactions = db_query($query);
|
|
|
|
$num_transactions = db_num_rows($transactions);
|
|
if ($num_transactions > 0) {
|
|
?>
|
|
<p class='warning'><b>Click on the word "Error" to post transactions that need to be posted.<br>
|
|
Do not post "Pending" transactions.</b></p>
|
|
<p><b><?php displayLanguageText('TEXT-ACCOUNT-TRANSACTIONS'); ?> - <?php echo($num_transactions) ?></b></p>
|
|
<table width='900' class='content-table'>
|
|
<tr>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-PAYMENT-DATE'); ?></b></td>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-NAME'); ?></b></td>
|
|
<td align='right' class='data-header'><b><?php displayLanguageText('TEXT-AMOUNT'); ?></b></td>
|
|
<td align='right' class='data-header'><b><?php displayLanguageText('TEXT-FEE'); ?></b></td>
|
|
<td align='center' class='data-header'><b><?php displayLanguageText('TEXT-TYPE'); ?></b></td>
|
|
<td align='center' class='data-header'><b><?php displayLanguageText('TEXT-STATUS'); ?></b></td>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-TRX-ID'); ?></b></td>
|
|
<td align='left' class='data-header'><b><?php displayLanguageText('TEXT-EMAIL'); ?></b></td>
|
|
<td align='center' class='data-header'><b><?php displayLanguageText('TEXT-POSTING-RESULT'); ?></b></td>
|
|
<td align='center' class='data-header'> </td>
|
|
</tr>
|
|
<?php
|
|
$count = 1;
|
|
$otipSpans = "";
|
|
$otipSpanIDs = array();
|
|
|
|
while ($row = db_fetch_array($transactions)) {
|
|
extract($row);
|
|
$trxID = $record_num;
|
|
|
|
$bgclass = "data-even";
|
|
if ($count % 2) $bgclass = "data-odd";
|
|
$count++;
|
|
|
|
// Format amounts
|
|
if ($mc_gross > 0) $mc_gross = "$" . number_format($mc_gross,2);
|
|
if ($mc_fee > 0) $mc_fee = "$" . number_format($mc_fee,2);
|
|
|
|
// Add info tips
|
|
if ($payment_status == 'Pending') {
|
|
$span_id = "status_$record_num";
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,'Pending Reason:',$pending_reason) . "</table></span>\n";
|
|
$otipSpanIDs[] = $span_id;
|
|
$payment_status = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Pending</a>";
|
|
}
|
|
|
|
// Unknown posting results
|
|
if ($posting_result == '') {
|
|
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND payment_reference = '$txn_id'");
|
|
if (db_num_rows($results) > 0) {
|
|
$posting_result = 'Posted';
|
|
}
|
|
else {
|
|
$posting_result = 'Error';
|
|
}
|
|
}
|
|
|
|
// Error postings
|
|
if ($posting_result == 'Error') {
|
|
$span_id = "result_$record_num";
|
|
$unum = intval($user_num);
|
|
if (strlen($posting_message) == 0) $posting_message = "Unknown Posting Error";
|
|
if ($unum > 0) {
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,'Posting Error:',$posting_message) . "</table></span>\n";
|
|
}
|
|
else {
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,'Posting Error:',$posting_message) . "</table> <b>-- No User Number</b></span>\n";
|
|
}
|
|
$otipSpanIDs[] = $span_id;
|
|
$onClick = "onClick='return confirm(\"This will post the transaction to the user account. Only post if the transaction has cleared.\");'";
|
|
if ($unum > 0) $posting_result = "<span class='error'><a href='?action=pp-post&trx_num=$record_num' $onClick onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Error</a></span>";
|
|
else {
|
|
$posting_result = "<span class='error'><a href='#' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\" " .
|
|
"class='trx-error' rnum='$record_num' fname='$first_name' lname='$last_name' email='$payer_email' amount='$mc_gross'>Error</a></span>";
|
|
}
|
|
}
|
|
|
|
// Successful postings
|
|
if ($posting_result == 'Posted') {
|
|
$span_id = "result_$record_num";
|
|
|
|
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND payment_reference = '$txn_id'");
|
|
if (db_num_rows($results) > 0) {
|
|
$otipSpanIDs[] = $span_id;
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE;
|
|
$otipSpans .= sprintf($otipROW2,"Transaction Num:",$trx_num);
|
|
$otipSpans .= sprintf($otipROW2,"Item:",$item_name);
|
|
$otipSpans .= sprintf($otipROW2,"Business:",$business);
|
|
$otipSpans .= sprintf($otipROW2,"Receiver:",$receiver_email);
|
|
|
|
$row = db_fetch_array($results);
|
|
$otipSpans .= sprintf($otipROW2,"User Acct TRX:",$record_num);
|
|
$order_payments = $row['order_payments'];
|
|
$orders = explode("|",$order_payments);
|
|
|
|
for ($i = 0; $i < count($orders); $i++) {
|
|
$order_num = preg_replace('/\{(\d+):\d+.\d+\}/','{$1}',$orders[$i]);
|
|
|
|
if (!is_numeric($order_num)) continue;
|
|
|
|
// Get order info
|
|
$results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
|
|
$row = db_fetch_array($results);
|
|
|
|
// Get schedule info
|
|
$schedule_num = $row['schedule_num'];
|
|
$schedule_name = "Unknown";
|
|
if (is_numeric($schedule_num) && $schedule_num > 0) {
|
|
$schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
|
|
}
|
|
|
|
// Get person info
|
|
$person_num = $row['ordered_by_num'];
|
|
$oname = "Unknown";
|
|
if (is_numeric($person_num) && $person_num > 0) {
|
|
$oname = db_getVal("SELECT concat(first_name,' ',last_name) FROM people WHERE school_num = $base_school_num AND record_num = $person_num");
|
|
}
|
|
|
|
$otipSpans .= "<tr><td align='center' colspan='2'><hr></td></tr>\n";
|
|
|
|
$otipSpans .= sprintf($otipROW2,"Order Number: ",$order_num);
|
|
$otipSpans .= sprintf($otipROW2,"Ordered By: ",$oname);
|
|
$otipSpans .= sprintf($otipROW2,"Order Schedule: ",$schedule_name);
|
|
// $otipSpans .= sprintf($otipROW2,"Order Status: ",$row['status']);
|
|
$otipSpans .= sprintf($otipROW2,"Order Date: ",$row['added_date']);
|
|
// $otipSpans .= sprintf($otipROW2,"Last Updated: ",$row['updated_date']);
|
|
}
|
|
|
|
$otipSpans .= "</table></span>\n";
|
|
$posting_result = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Posted</a>";
|
|
}
|
|
else {
|
|
if ($row['payment_status'] != 'Pending') {
|
|
$otipSpanIDs[] = $span_id;
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE;
|
|
$otipSpans .= sprintf($otipROW2,"Transaction Num:",$trx_num);
|
|
$otipSpans .= "<tr><td align='center' colspan='2'><hr></td></tr>\n";
|
|
$otipSpans .= "<tr><td align='center' colspan='2'><b>Unable to locate the<br>user account transaction<br>for this PayPal payment</b></td></tr>\n";
|
|
$otipSpans .= "</table></span>\n";
|
|
$posting_result = "<span class='warning'>" .
|
|
"<a href='?action=pp-post&trx_num=$record_num' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">Warning</a></span>";
|
|
}
|
|
else {
|
|
$posting_result = "Pending";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Format name
|
|
$name = "$first_name $last_name";
|
|
if (is_numeric($user_num) && $user_num > 0) {
|
|
$results = db_query("SELECT * FROM users WHERE record_num = $user_num");
|
|
$row = db_fetch_array($results);
|
|
$span_id = "user_$user_num";
|
|
if (!in_array($span_id,$otipSpanIDs)) {
|
|
$user_balance = db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $user_num AND (deleted != 'Y' OR deleted IS NULL)");
|
|
$user_balance = floatval($user_balance);
|
|
$otipSpans .= "<span id='$span_id' class='hidden'>" . $otipTABLE .
|
|
sprintf($otipROW2,"User ID: ",$row['userid']) .
|
|
sprintf($otipROW2,"User Type: ",$row['type']) .
|
|
sprintf($otipROW2,"Name: ",$row['first_name'] . ' ' . $row['last_name']) .
|
|
sprintf($otipROW2,"Email: ",$row['email']) .
|
|
sprintf($otipROW2,"Phone: ",$row['home_phone']) .
|
|
sprintf($otipROW2,'<nobr>' . getLanguageText('TEXT-CURRENT-BALANCE') . ': </nobr>',$currencySymbol . number_format($user_balance,2)) .
|
|
"</table></span>\n";
|
|
$otipSpanIDs[] = $span_id;
|
|
}
|
|
$name = "<a href='?action=user-account&naction=list&user_num=$user_num' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$name</a>";
|
|
|
|
$payer_email = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$payer_email</a>";
|
|
}
|
|
|
|
$msg = getLanguageText('TEXT-CONFIRM-STATUS-CHANGE');
|
|
$msg .= "\\n\\n" . getLanguageText('TEXT-WILL-NOT-POST-TRANSACTION');
|
|
if ($error_handled == 'N') $command = "<a href='?action=paypal-log-errors&naction=set-complete&record_num=$record_num' onclick='return confirm(\"$msg\");'>$delete_icon</a>";
|
|
else $command = "<a href='?action=paypal-log-errors&naction=set-incomplete&record_num=$record_num' onclick='return confirm(\"$msg\");'>$change_icon</a>";
|
|
|
|
?>
|
|
<tr>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($payment_date); ?></td>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($name); ?></td>
|
|
<td align='right' class='<?php echo($bgclass) ?>'><?php echo($mc_gross); ?></td>
|
|
<td align='right' class='<?php echo($bgclass) ?>'><?php echo($mc_fee); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($payment_type); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($payment_status); ?></td>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($txn_id); ?></td>
|
|
<td align='left' class='<?php echo($bgclass) ?>'><?php echo($payer_email); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($posting_result); ?></td>
|
|
<td align='center' class='<?php echo($bgclass) ?>'><?php echo($command); ?></td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
?>
|
|
</table>
|
|
<?php
|
|
}
|
|
else {
|
|
echo("<b>\n");
|
|
displayLanguageText('ERRORMSG-NO-RECORDS');
|
|
echo("</b><br>\n");
|
|
}
|
|
|
|
if ($numErrors > 0) {
|
|
?>
|
|
<center>
|
|
<br>
|
|
<p><a href='?action=paypal-log-errors&view=all' class='btn btn--primary>'><?php displayLanguageText('TEXT-VIEW-ALL'); ?></a></p>
|
|
</center>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
<?php include "include/ajax.Setup.php" ?>
|
|
|
|
$("#users-dialog").dialog({
|
|
autoOpen: false,
|
|
minWidth: 800,
|
|
minHeight: 600,
|
|
modal: true,
|
|
position: { my: 'center', at: 'center' }
|
|
});
|
|
|
|
|
|
$(document).on('click', '.trx-error', function(e) {
|
|
e.preventDefault();
|
|
|
|
var rnum = $(this).attr('rnum');
|
|
var fname = $(this).attr('fname');
|
|
var lname = $(this).attr('lname');
|
|
var email = $(this).attr('email');
|
|
var amount = $(this).attr('amount');
|
|
|
|
var info = '<b>'+fname+' '+lname+'<br>'+email+'<br>'+amount+'</b>';
|
|
$("#trx-info").html(info);
|
|
|
|
$("#rnum").val(rnum);
|
|
|
|
$("#users-dialog").dialog("open");
|
|
});
|
|
|
|
$("#post-user").click(function(e) {
|
|
e.preventDefault();
|
|
|
|
var rnum = $("#rnum").val();
|
|
var unum = $("#user-account").val();
|
|
|
|
$("#users-dialog").dialog("close");
|
|
|
|
var data = "table_name=user_paypal_transactions&record_num="+rnum+"&user_num="+unum;
|
|
$.getJSON("ajax.DataRecord.Update.php", data,
|
|
function(results) {
|
|
location.href = "?action=pp-post&trx_num="+rnum;
|
|
}
|
|
);
|
|
});
|
|
});
|
|
</script>
|
|
|
|
|
|
<div id='users-dialog' title='User Accounts'>
|
|
<table>
|
|
<tr>
|
|
<td align='left'>
|
|
<span id='trx-info'></span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align='left'>
|
|
<p><label for='user-account'><b>User Account:</b></label><br>
|
|
<select name='user-account' id='user-account'>
|
|
<?php
|
|
$query = "SELECT * FROM users WHERE school_num = $base_school_num AND type = 'Parent' ORDER BY last_name, first_name";
|
|
$results = db_query($query);
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$name = $row['first_name'].' '.$row['last_name'];
|
|
$email = $row['email'];
|
|
$unum = $row['record_num'];
|
|
if ($unum > 0 && strlen($row['last_name'])) {
|
|
$user_balance = db_getVal("select sum(transaction_amount) as balance from user_account where school_num = $school_num and user_num = $unum AND (deleted != 'Y' OR deleted IS NULL)");
|
|
$user_balance = floatval($user_balance);
|
|
if ($user_balance > 0) {
|
|
$balance = '$'.number_format($user_balance,2);
|
|
echo(" <option value='$unum'>$name - $email ($balance)</option>\n");
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
</select></p>
|
|
<button id='post-user' class='btn btn--outline btn--xsmall'> Assign to Account </button>
|
|
<input type='hidden' name='rnum' id='rnum'>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<?php
|
|
}
|
|
|
|
endTemplate();
|
|
?>
|