Files
HotLunches/user_account.list.php
T
2026-10-19 15:22:52 -07:00

916 lines
45 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
$snums = $school_num;
if (isset($aview) && $aview == 'consolidated') $snums = $school_record['linked_sites'];
if (array_key_exists('mode', $_GET) && $_GET['mode'] == 'parent' && in_array($_SESSION['UserInfo']['type'],array('Administration Team','Schedule Team'))) {
$user_num = intval($_SESSION['UserInfo']['record_num']);
}
if (isset($user_num)) {
$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);
if ($user_balance <= 0.00) {
$query = "UPDATE user_account SET transaction_status = 'Closed' " .
"WHERE school_num = $school_num " .
"AND user_num = $user_num " .
"AND transaction_type = 'Order' " .
"AND (deleted != 'Y' OR deleted IS NULL)";
db_query($query);
}
}
// Get set of user account records
if (!isset($transactions)) {
if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff'))) $user_num = intval($_SESSION['UserInfo']['record_num']);
if (!isset($user_num) && in_array($_SESSION['UserInfo']['type'],array('Administration Team','Schedule Team'))) $user_num = intval($_SESSION['UserInfo']['record_num']);
if (isset($user_num) && $user_num > 0) {
$query = "SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND deleted != 'Y' ORDER BY transaction_datetime";
$results = db_query($query);
$orders = "";
$balance = 0;
while ($row = db_fetch_assoc($results)) {
extract($row);
$balance = $balance + $transaction_amount;
$ostatus = '';
if ($order_num > 0) {
if (strlen($orders)) $orders .= ",";
$orders .= $order_num;
}
if ($balance <= 0.00 && strlen($orders)) {
$query = "UPDATE hotlunch_order_header SET status = 'Paid' WHERE school_num = $school_num AND record_num IN ($orders)";
db_query($query);
$orders = '';
}
}
}
$query = "SELECT u.userid,substring(transaction_datetime,1,10) as trx_date,transaction_datetime,transaction_type,note,transaction_amount,schedule_num,order_num," .
"transaction_status,trx_history,payment_method,payment_reference,order_payments,ua.user_num,people_num,p.people_type,entered_by_user_num," .
"p.first_name,p.last_name,p.menu_price_category,additional_note,ua.record_num " .
"FROM user_account as ua LEFT JOIN people as p ON ua.people_num = p.record_num, users AS u " .
"WHERE u.school_num = $base_school_num " .
"AND ua.school_num IN ($snums) " .
"AND ua.user_num = $user_num " .
"AND ua.user_num = u.record_num " .
"AND (deleted != 'Y' OR deleted IS NULL) " .
"ORDER BY userid,transaction_datetime,record_num";
$transactions = db_query($query);
$mode = 'account';
$print_cmd = "&selected_usernum=$user_num";
}
echo("<center>\n");
if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff'))) {
$user_num = intval($_SESSION['UserInfo']['record_num']);
$user_balance = floatval(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)"));
if ($user_balance < 0) {
$msg = getLanguageText('TEXT-CREDIT-BALANCE');
$msg .= ":&nbsp;&nbsp;&nbsp;$currencySymbol" . number_format(abs($user_balance),2);
$class = 'success';
}
else {
$msg = getLanguageText('TEXT-BALANCE-OWING');
$msg .= ":&nbsp;&nbsp;&nbsp;$currencySymbol" . number_format(abs($user_balance),2);
$class = 'error';
}
?>
<table width='900' cellpadding='3' cellspacing='1' border='0'>
<tr height='15'>
<td align='center' class='<?php echo($class) ?>'><?php echo($msg) ?></td>
</tr>
</table>
<?php
}
//
// Preload data
//
$schoolSchedules = array();
$results = db_query("SELECT * FROM hotlunch_schedules WHERE school_num = $school_num");
while ($row = db_fetch_assoc($results)) {
$schedule_num = $row['record_num'];
$schoolSchedules[$schedule_num] = $row;
}
$trxCodes = array();
$results = db_query("SELECT * FROM user_account_trx_codes WHERE school_num = $school_num");
while ($row = db_fetch_assoc($results)) {
$trx_type = $row['trx_category'];
$transaction_type = $row['transaction_type_code'];
$trxCodes[$transaction_type] = $row;
}
$num_transactions = db_num_rows($transactions);
if ($num_transactions == 0) {
if ($naction == 'list') echo("<p class='success'>No Transactions Found</p>\n");
echo("<br>\n");
}
else {
$title = getLanguageText('TEXT-ACCOUNT-TRANSACTIONS');
if (isset($aview) && $aview == 'consolidated') $title = getLanguageText('TEXT-CONSOLIDATED-ACCOUNT-TRANSACTIONS');
?>
<p><b><?php echo("$title - $num_transactions") ?></b></p>
<table width='900' class='content-table'>
<?php if (isset($view) && $view == 'details') { ?>
<form method='post' action='/'>
<?php } ?>
<?php
$nCols = 9;
if (!isset($deleteType) || $deleteType != 'deleted') $nCols = 10;
if ($num_transactions > 1 && (!isset($view) || $view != 'details') && isset($print_cmd) && strlen($print_cmd) > 0) {
?>
<tr>
<td colspan='<?php echo($nCols) ?>' align='right'>
<?php include "user_account.list.buttons.php" ?>
</td>
</tr>
<?php
}
?>
<tr>
<td width='100' align='left' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-USER-ID'); ?></b></td>
<td align='left' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-TRX-DATE'); ?></b></td>
<td align='left' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-TYPE'); ?></b></td>
<td align='left' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-NOTE'); ?></b></td>
<td align='left' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-REF'); ?></b></td>
<td align='right' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-CHARGES'); ?></b></td>
<td align='right' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-CREDITS'); ?></b></td>
<td align='center' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-METHOD'); ?></b></td>
<td align='right' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-BALANCE'); ?></b></td>
<?php if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team'))) { ?>
<?php if (!isset($deleteType) || $deleteType != 'deleted') { ?>
<td align='center' width='100' class='data-header'>&nbsp;</td>
<?php } ?>
<?php } ?>
</tr>
<?php
$count = 1;
$balance = 0;
$total_charges = 0;
$total_credits = 0;
$otipSpans = "";
$otipSpanIDs = array();
while ($row = db_fetch_array($transactions)) {
extract($row);
$rnum = $record_num;
$trx_status = $transaction_status;
$noteText = translateText($note);
$bg = 'data-even';
if ($count % 2) $bg = 'data-odd';
$count++;
$charge = '';
$credit = '';
$Receipt = '';
$Rlink = '';
$command = '';
// Lookup TRX Type code
$trx_type = $transaction_type;
if (array_key_exists('transaction_type',$trxCodes)) {
$row = $trxCodes($transaction_type);
$trx_type = $row['trx_category'];
}
$trx_typeText = translateText($transaction_type);
$entered_by_num = "";
if (array_key_exists('entered_by_user_num',$row)) $entered_by_num = $row['entered_by_user_num'];
// Format transaction entry based on trx_type
switch ($trx_type) {
case 'Donation':
case 'NSF':
case 'Refund':
case 'Late Charge':
case 'Tax Charge':
case 'Paper Order Charge':
case 'Remittance Form Fee':
case 'Additional Order Fee':
case 'Other Charge':
case 'Charge Adjustment':
case 'Order':
case 'PayPal Transaction Fee':
case 'Bambora Transaction Fee':
case 'Credit Card Transaction Fee':
case 'Reversed Payment':
case 'Charge':
case 'Generated Charge':
$charge = '$' . $transaction_amount;
$balance += $transaction_amount;
$total_charges += $transaction_amount;
if ($transaction_type == 'Order' && $order_num > 0) {
// Get schedule record
if (isset($schedule_num) && $schedule_num > 0) {
$schedule_name = "";
if (array_key_exists($schedule_num,$schoolSchedules)) {
$schedule = $schoolSchedules[$schedule_num];
$sname = $schedule['schedule_name'];
$schedule_name = str_replace("'","&#39;",$sname);
}
}
else {
$sname = "";
$schedule_name = "";
}
// Get the order header
$results = db_query("SELECT * FROM hotlunch_order_header WHERE record_num = $order_num");
$row = db_fetch_array($results);
// Get the order total
$order_total = db_getVal("SELECT sum(extended_price) FROM hotlunch_order_items WHERE school_num = $school_num AND order_num = $order_num AND active = 'Y'");
// Handle any discount offered
$discount_amount = 0;
if ($row['source'] == 'On-Line' && $schedule['discount_offered'] > 0 && $schedule['discount_expiry_date'] >= $row['updated_date']) {
$discount_offered = $schedule['discount_offered'];
$discount_type = $schedule['discount_type'];
$discount_order_minimum = $schedule['discount_order_minimum'];
if ($order_total >= $discount_order_minimum) {
if ($discount_type == 'Amount') {
$discount_amount = $discount_offered;
$order_total = $order_total - $discount_amount;
}
else {
$discount_amount = $order_total * $discount_offered / 100;
$order_total = $order_total - $discount_amount;
}
}
}
// Determine if there are any discounts defined for this schedule
if (isset($schedule_num) && $schedule_num > 0) {
$today = date("Y-m-d",time());
$numDiscounts = db_getVal("SELECT count(*) FROM hotlunch_schedules_discounts " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND (expiry_date IS NULL OR expiry_date >= '$today') " .
"ORDER BY menu_group,order_quantity");
if ($numDiscounts > 0) {
// Get the discount amount
$discount_amount = db_getVal("SELECT discount_amount FROM hotlunch_order_header WHERE record_num = $order_num");
$order_total = $order_total - $discount_amount;
}
}
// Update user account order total
$order_total = sprintf("%0.2f",$order_total);
db_query("UPDATE user_account SET transaction_amount = $order_total WHERE record_num = $rnum");
db_query("UPDATE hotlunch_order_header SET order_total = $order_total WHERE record_num = $order_num");
// Build the order tool tip
$span_id = "order_span_$order_num";
if (!in_array($span_id,$otipSpanIDs)) {
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW2,getLanguageText('TEXT-ORDER-NUMBER') . ": ",$order_num) .
sprintf($otipROW2,getLanguageText('TEXT-ORDERED-FOR') . ": ",$row['ordered_by_type']);
if (isset($first_name) && strlen($first_name)) {
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-NAME') . ": ","$first_name $last_name");
if (isset($menu_price_category) && strlen($menu_price_category))
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-CATEGORY') . ": ",$menu_price_category);
}
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-SCHEDULE') . ": ",$schedule_name);
if ($row['discount_amount'] > 0) {
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-SUBTOTAL') . ": ",$currencySymbol . number_format($row['order_subtotal'],2)) .
sprintf($otipROW2,getLanguageText('TEXT-DISCOUNT') . ": ",$currencySymbol . number_format($row['discount_amount'],2));
}
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-ORDER-TOTAL') . ": ",$currencySymbol . number_format($row['order_total'],2)) .
sprintf($otipROW2,getLanguageText('TEXT-AMOUNT-PAID') . ": ",$currencySymbol . number_format($row['amount_paid'],2)).
sprintf($otipROW2,getLanguageText('TEXT-STATUS') . ": ",$row['status']).
sprintf($otipROW2,getLanguageText('TEXT-ORDER-DATE') . ": ",$row['added_date']) .
sprintf($otipROW2,getLanguageText('TEXT-SOURCE') . ": ",$row['source']) .
sprintf($otipROW2,getLanguageText('TEXT-PAYMENT-METHOD') . ": ",$row['payment_method']) .
sprintf($otipROW2,getLanguageText('TEXT-UPDATED-DATE') . ": ",$row['updated_date']);
if ($row['paid_date']) $otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-PAID-DATE') . ": ",$row['paid_date']);
if (isset($aview) && $aview == 'consolidated' && intval($row['school_num']) > 0) {
$site = db_getVal("SELECT school_name FROM schools WHERE record_num = " . $row['school_num']);
$otipSpans .= sprintf($otipROW2,"Site: ",$site);
}
$otipSpans .= sprintf($otipROW2,"TRX: ",$rnum);
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-STATUS') . ": ",$trx_status);
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-ENTERED-BY') . ": ",$row['entered_by']);
$otipSpans .= "</table></span>\n";
$otipSpanIDs[] = $span_id;
}
$order_tip = " onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\"";
$command = "<a href='?action=orders&naction=view&schedule_num=$schedule_num&ordered_by_view=$people_type.$people_num' title='View Order $schedule_name' $order_tip>" .
"<img src='images/icons/textfile16.png' title='View Order $schedule_name' border='0'></a>";
if ($_SESSION['UserInfo']['type'] == 'SuperUser' || $_SESSION['UserInfo']['type'] == 'System Administrator') {
$msg = getLanguageText('TEXT-CONFIRM-STATUS-CHANGE');
$command = "<nobr>$command&nbsp;" .
"<a href='?action=user-account&naction=set-unpaid&user_num=$user_num&order_num=$order_num' onclick='return confirm(\"$msg\")'>" .
"<img src='images/icons/money-unpaid16.png' title='Set Order to Unpaid' border='0'></a>" .
"&nbsp;" .
"<a href='?action=user-account&naction=set-paid&user_num=$user_num&order_num=$order_num' onclick='return confirm(\"$msg\")'>" .
"<img src='images/icons/money-post16.png' title='Set Order to Paid' border='0'></a>" .
"<a href='?action=order-log&selected_order_num=$order_num'>" .
"<img src='images/icons/textfile-bw16.png' title='View Order Log' border='0'></a>" .
"</nobr>";
}
}
else {
// Build the trx tool tip
$span_id = "order_span_$record_num";
if (!in_array($span_id,$otipSpanIDs)) {
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-TYPE') . ": ",$trx_typeText) .
sprintf($otipROW2,getLanguageText('TEXT-DATE') . ": ",$trx_date) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-NUMBER') . ": ",$record_num) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-NOTE') . ": ",$noteText) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-AMOUNT') . ": ",$currencySymbol . number_format(abs($transaction_amount),2));
$otipSpans .= sprintf($otipROW2,"TRX: ",$rnum);
$dflag = '';
if (isset($deleted) && $deleted == 'Y') $dflag = " (D)";
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-STATUS') . ": ","$trx_status$dflag");
$otipSpans .= "</table></span>\n";
$otipSpanIDs[] = $span_id;
}
$trx_typeText = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$trx_typeText</a>";
$command = "<a href='?action=user-account&naction=delete&user_num=$user_num&tn=$record_num' class='delete-entry' unum='$user_num' tn='$record_num'><img src='images/icons/delete16.png' title='Delete Entry' border='0'></a>";
if (isset($trx_history) && strlen(trim($trx_history))) {
$command .= "&nbsp;<a href='' rnum='$record_num' class='trx-history'>$filesearch_icon</a>";
}
}
break;
case 'Complimentary Credit':
$credit = "- $currencySymbol" . number_format(abs($transaction_amount),2);
$balance += $transaction_amount;
$total_credits += $transaction_amount;
// Build the trx tool tip
$span_id = "order_span_$record_num";
if (!in_array($span_id,$otipSpanIDs)) {
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-TYPE') . ": ",$trx_typeText) .
sprintf($otipROW2,getLanguageText('TEXT-DATE') . ": ",$trx_date) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-NUMBER') . ": ",$record_num) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-NOTE') . ": ",$noteText) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-AMOUNT') . ": ",$currencySymbol . number_format(abs($transaction_amount),2));
$otipSpans .= sprintf($otipROW2,"TRX: ",$rnum);
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-STATUS') . ": ",$trx_status);
$otipSpans .= "</table></span>\n";
$otipSpanIDs[] = $span_id;
}
$order_tip = " onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\"";
$trx_typeText = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$trx_typeText</a>";
$command = "<a href='?action=user-account&naction=delete&user_num=$user_num&tn=$record_num' class='delete-entry' unum='$user_num' tn='$record_num'><img src='images/icons/delete16.png' title='Delete Entry' border='0'></a>";
break;
case 'Payment':
$PPsname = "";
if (isset($schedule_num) && $schedule_num > 0) {
if (array_key_exists($schedule_num,$schoolSchedules)) {
$schedule = $schoolSchedules[$schedule_num];
$PPsname = $schedule['schedule_name'];
$PPsname = str_replace("'","&#39;",$PPsname);
}
}
if ($note == 'PayPal Payment' || $note == 'PayPal Checkout Payment') {
$results = db_query("SELECT * FROM user_paypal_transactions WHERE school_num = $school_num AND txn_id = '$payment_reference' AND current_year != 'N' ORDER BY posting_time");
if (db_num_rows($results)) {
$span_id = "payment_$payment_reference";
if (!in_array($span_id,$otipSpanIDs)) {
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600;
while ($row = db_fetch_array($results)) {
$otipSpans .= sprintf($otipROW2,"Posting Time: ",$row['posting_time']) .
sprintf($otipROW2,"Payment Date: ",$row['payment_date']) .
sprintf($otipROW2,"Item: ",$row['item_name']) .
sprintf($otipROW2,"Name: ",$row['first_name'] . ' ' . $row['last_name']) .
sprintf($otipROW2,"Email: ",$row['payer_email']) .
sprintf($otipROW2,"Currency: ",$row['mc_currency']) .
sprintf($otipROW2,"Total: ",$row['mc_gross']) .
sprintf($otipROW2,"Fee: ",$row['mc_fee']) .
sprintf($otipROW2,"Payment Type: ",$row['payment_type']) .
sprintf($otipROW2,"Payment Status: ",$row['payment_status']) .
sprintf($otipROW2,"TRX ID: ",$row['txn_id']) .
sprintf($otipROW2,"TRX Result: ",$row['posting_result']) .
sprintf($otipROW2,"Posted to:",$PPsname);
}
$otipSpans .= sprintf($otipROW2,"TRX: ",$rnum);
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-STATUS') . ": ",$trx_status);
$otipSpans .= "</table></span>\n";
$otipSpanIDs[] = $span_id;
}
$payment_reference = "<a href='#' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$payment_reference</a>";
}
}
$Receipt = "";
if ($mode != 'lookup' && in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) {
$Receipt = "&nbsp;<a href='?action=receipt-print&tnum=$record_num&unum=$user_num' class='receipt-print' trx-num='$record_num' unum='$user_num'><img src='images/icons/textfile-bw16.png' border='0'></a>";
}
if ($_SESSION['UserInfo']['type'] == 'Parent') {
$Rlink = "<a href='?action=receipt-print&tnum=$record_num&unum=$user_num' target='_blank'>";
}
case 'Credit':
case 'Credit Adjustment':
case 'PayPal Refund':
case 'Bambora Refund':
default:
$credit = "- $currencySymbol" . number_format(abs($transaction_amount),2);
$balance += $transaction_amount;
$total_credits += $transaction_amount;
// Setup commands for payments and credits
$command = "";
if ($payment_method != 'PayPal' || ($payment_method == 'PayPal' && strlen($payment_reference) == 0) || $_SESSION['UserInfo']['type'] == 'SuperUser') {
$command = "<a href='?action=user-account&naction=delete&user_num=$user_num&tn=$record_num' class='delete-entry' unum='$user_num' tn='$record_num'><img src='images/icons/delete16.png' title='Delete Entry' border='0'></a>$Receipt";
}
if (($payment_method == 'PayPal' && strlen($payment_reference) == 0) && in_array($_SESSION['UserInfo']['type'],array('System Administrator','Application Administrator','Financial','Financial Team'))) {
$command = "<a href='?action=user-account&naction=delete&user_num=$user_num&tn=$record_num' class='delete-entry' unum='$user_num' tn='$record_num'><img src='images/icons/delete16.png' title='Delete Entry' border='0'></a>";
}
// Calculate the order payment info
$payments = explode('|',$order_payments);
$ptotal = 0;
$ptext = "";
for ($i = 0; $i < count($payments); $i++) {
$p = str_replace('{','',str_replace('}','',$payments[$i]));
if (strlen($p) && strpos($p, ':') > 0) {
list($onum,$oamt) = explode(':',$p);
if ($onum) {
$oactual = 0;
$results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $onum");
if (db_num_rows($results) == 1) {
$row = db_fetch_assoc($results);
$oactual = $row['order_total'];
$ptotal += $oactual;
$schedule_num = $row['schedule_num'];
}
if (isset($schedule_num) && $schedule_num > 0) {
if (array_key_exists($schedule_num,$schoolSchedules)) {
$schedule = $schoolSchedules[$schedule_num];
$sname = $schedule['schedule_name'];
$schedule_name = str_replace("'","&#39;",$sname);
$ptext .= sprintf($otipROW2,"Order #$onum","$currencySymbol$oactual - $schedule_name ($schedule_num)");
}
}
}
}
}
// if ($people_num > 0) {
// $results = db_query("SELECT * FROM people WHERE record_num = $people_num");
// }
// Create payment otip
$span_id = "type_$record_num";
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-TYPE') . ": ",$trx_typeText) .
sprintf($otipROW2,getLanguageText('TEXT-DATE') . ": ",$trx_date) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-NUMBER') . ": ",$record_num) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-NOTE') . ": ",$noteText) .
sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-AMOUNT') . ": ",$currencySymbol . number_format(abs($transaction_amount),2));
if (is_array($row) && array_key_exists('payment_method', $row)) $otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-PAYMENT-METHOD') . ": ",translateText($row['payment_method']));
$otipSpans .= $ptext;
$otipSpans .= sprintf($otipROW2,"Order Totals:",$currencySymbol.number_format($ptotal,2));
$otipSpans .= sprintf($otipROW2,"TRX: ",$rnum);
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-TRANSACTION-STATUS') . ": ",$trx_status);
if (isset($entered_by_num) && $entered_by_num > 0) {
$enteredBy = db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $entered_by_num");
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-ENTERED-BY') . ": ",$enteredBy);
}
$otipSpans .= "</table></span>\n";
$trx_typeText = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$trx_typeText</a>";
if (abs($ptotal) != abs($transaction_amount)) $trx_typeText = "<span class='warning'>$trx_typeText</span>";
break;
case 'TRX Note':
case 'Note':
// Get schedule record
if ($schedule_num > 0) {
$schedule = $schoolSchedules[$schedule_num];
$sname = $schedule['schedule_name'];
$noteText .= " - $sname";
}
if (isset($additional_note) && strlen($additional_note)) {
$span_id = "note_$record_num";
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW1,'left',$additional_note) .
"</table></span>\n";
$trx_typeText = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$trx_typeText</a>";
}
$command = "<a href='?action=user-account&naction=delete&user_num=$user_num&tn=$record_num' class='delete-entry' unum='$user_num' tn='$record_num'><img src='images/icons/delete16.png' title='Delete Entry' border='0'></a>";
break;
}
// Format the current balance
$balance = round($balance * 100) / 100;
if ($balance < 0.00) $balance_amt = "- $currencySymbol" . number_format(abs($balance),2);
else $balance_amt = $currencySymbol . number_format($balance,2);
// Add userid link if the current user is admin or superuser
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator'))) {
// Get information for tool tip text
$results = db_query("SELECT * FROM users WHERE record_num = $user_num");
$row = db_fetch_array($results);
$user_num = $row['record_num'];
$span_id = "user_span_$user_num";
$ouserid = $userid;
$userid = htmlspecialchars_decode($userid,ENT_QUOTES);
if (isset($userid) && strlen($userid) > 20) $userid = substr($userid,0,19) . "...";
if (isset($view) && $view == 'details' && $_SESSION['UserInfo']['type'] == 'SuperUser') {
}
else {
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);
$bal = sprintf("%0.2f",$user_balance);
db_query("UPDATE users SET balance_owing = $bal, account_balance = $bal WHERE school_num = $school_num AND record_num = $user_num");
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW2,getLanguageText('TEXT-USER-ID').": ",$row['userid']) .
sprintf($otipROW2,getLanguageText('TEXT-TYPE').": ",$row['type']) .
sprintf($otipROW2,getLanguageText('TEXT-NAME').": ",$row['first_name'] . ' ' . $row['last_name']) .
sprintf($otipROW2,getLanguageText('TEXT-EMAIL').": ",$row['email']) .
sprintf($otipROW2,getLanguageText('TEXT-PHONE').": ",$row['home_phone']) .
sprintf($otipROW2,"Current Balance: ",$currencySymbol . number_format($user_balance,2));
if ($_SESSION['UserInfo']['type'] == 'SuperUser') $otipSpans .= sprintf($otipROW2,"Number: ",$row['record_num']);
$otipSpans .= "</table></span>\n";
$otipSpanIDs[] = $span_id;
}
$user_tip = " onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\"";
$userid = "<a href='?action=user-account&naction=add&user_num=$user_num' $user_tip>$userid</a>";
}
}
// Add order number to Order transactions
if ($transaction_type == "Order") {
if ($order_num > 0) {
$order_status = db_getVal("SELECT status FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
switch ($order_status) {
case 'Paid':
case 'Pending':
$ospan = "<span>";
break;
case 'Unpaid':
$ospan = "<span class='red'>";
break;
case 'Complimentary':
$ospan = "<span class='yellow'>";
break;
case 'Inactive':
$ospan = "<span class='blue'>";
break;
}
switch ($_SESSION['UserInfo']['type']) {
case 'Parent':
$trx_typeText .= " (#<a href='?action=orders&naction=edit&schedule_num=$schedule_num&student_num=$people_num' $order_tip>$ospan$order_num</span></a>)";
break;
case 'Staff':
$trx_typeText .= " (#<a href='?action=orders&naction=edit&schedule_num=$schedule_num&staff_num=$people_num' $order_tip>$order_num</a>)";
break;
default:
$trx_typeText .= " (#<a href='?action=orders&naction=view&schedule_num=$schedule_num&ordered_by_view=$people_type.$people_num' $order_tip>$ospan$order_num</span></a>)";
break;
}
}
// Add link to name if this is an Order transaction
if ($people_num > 0) {
if (strpos($note,"Order for") && $people_type == 'Student') {
// Get information for tool tip text
$results = db_query("SELECT * FROM people WHERE record_num = $people_num");
$row = db_fetch_array($results);
$name = $row['first_name'] . " " . $row['last_name'];
$pstatus = $row['status'];
$span_id = "user_span$people_num";
if (!in_array($span_id,$otipSpanIDs)) {
$otipSpans .= "<span id='$span_id'>" . $otipTABLE600 .
sprintf($otipROW2,"Name: ",$name) .
sprintf($otipROW2,"Status: ",$row['status']) .
sprintf($otipROW2,"Class: ",getClassInfo($row['class_num'])) .
"</table></span>\n";
$otipSpanIDs[] = $span_id;
}
if ($pstatus == 'Inactive') $name = "<span class='red'>$name</span>";
$people_tip = " onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\"";
$noteText = "<a href='?action=students&naction=edit&record_num=$people_num' $people_tip>$name</a> ($schedule_name)";
}
}
}
// Handle any translations
if (isset($payment_method) && strlen($payment_method)) {
$lcode = "CODE-" . strtoupper(str_replace(' ','-',$payment_method));
$lvalue = getLanguageText($lcode);
if (isset($lvalue) && strlen($lvalue)) $payment_method = $lvalue;
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator'))) {
if ($payment_method != 'PayPal') $payment_method = "<span id='payment-method-$record_num' class='edit-payment-method' rnum='$record_num'>$payment_method</span>";
}
else {
if (isset($Rlink) && strlen($Rlink)) {
$payment_method = "$Rlink$payment_method</a>";
}
}
}
if (isset($transaction_status) && strlen($transaction_status)) $transaction_status = translateText($transaction_status);
if (isset($payment_method) && strlen($payment_method)) $payment_method = translateText($payment_method);
?>
<tr>
<?php if (isset($view) && $view == 'details' && $_SESSION['UserInfo']['type'] == 'SuperUser') { ?>
<td align='left' valign='top' class='<?php echo($bg) ?>'>
<select name='user_num_<?php echo($record_num) ?>'>
<?php
$users = db_query("SELECT * FROM users WHERE school_num = $base_school_num ORDER BY last_name,first_name");
while ($row = db_fetch_array($users)) {
$unum = $row['record_num'];
$uid = $row['userid'];
$name = $row['first_name'] . ' ' . $row['last_name'];
$selected = "";
if ($user_num == $unum) $selected = " selected='selected'";
echo(" <option value='$unum'$selected>$name - $uid</option>\n");
}
?>
</select>
</td>
<?php } else { ?>
<td align='left' valign='top' class='<?php echo($bg) ?>'><?php echo($userid) ?></td>
<?php } ?>
<td align='left' valign='top' class='<?php echo($bg) ?>'><?php echo($trx_date) ?></td>
<td align='left' valign='top' class='<?php echo($bg) ?>'><nobr><?php echo($trx_typeText . "<br>" . $transaction_status) ?></nobr></td>
<td align='left' valign='top' class='<?php echo($bg) ?>'><span id='note-<?php echo($record_num) ?>'><?php echo($noteText) ?></span></td>
<td align='left' valign='top' class='<?php echo($bg) ?>'><span id='payment-reference-<?php echo($record_num) ?>'><?php echo($payment_reference) ?></span></td>
<td align='right' valign='top' class='<?php echo($bg) ?>'><nobr><?php echo($charge) ?></nobr></td>
<td align='right' valign='top' class='<?php echo($bg) ?>'><nobr><?php echo($credit) ?></nobr></td>
<td align='center' valign='top' class='<?php echo($bg) ?>'><nobr><?php echo($payment_method) ?></nobr></td>
<td align='right' valign='top' class='<?php echo($bg) ?>'><nobr><?php echo($balance_amt) ?></nobr></td>
<?php if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) { ?>
<?php if (!isset($deleteType) || $deleteType != 'deleted') { ?>
<td align='center' valign='top' class='<?php echo($bg) ?>'><?php echo($command) ?></td>
<?php } ?>
<?php } ?>
</tr>
<?php
if (isset($view) && $view == 'details') {
$details = "";
if (isset($entered_by_user_num)) {
$details .= "Entered by User: ";
$details .= db_getVal("SELECT concat(userid,' - ',first_name,' ',last_name) FROM users WHERE school_num = $base_school_num AND record_num = $entered_by_user_num");
}
$sfield = "trx_schedule_$record_num";
?>
<tr>
<td align='left' valign='top' class='<?php echo($bg) ?>'>&nbsp;</td>
<td align='left' colspan='8' valign='top' class='<?php echo($bg) ?>'>
Posted to Schedule:
<select name="<?php echo($sfield) ?>">
<?php if ($schedule_num == 0) { ?>
<option value='0'>Not Posted to a Schedule</option>
<?php } ?>
<?php
$end_date = date("Y-m-d",time() - 60 * 60 * 24 * 240);
$schedules = db_query("SELECT schedule_name,record_num FROM hotlunch_schedules WHERE school_num IN ($snums) AND schedule_end_date >= '$end_date' AND status != 'Deleted' ORDER BY $scheduleSortOrder");
while ($row = db_fetch_array($schedules)) {
$sname = $row['schedule_name'];
$rnum = $row['record_num'];
$selected = '';
if ($rnum == $schedule_num) $selected = " selected='selected'";
echo(" <option value='$rnum'$selected>$sname</option>\n");
$selected = "";
}
?>
</select><br>
<?php echo($details) ?>
</td>
<?php if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team'))) { ?>
<?php if (!isset($deleteType) || $deleteType != 'deleted') { ?>
<td align='left' valign='top' class='<?php echo($bg) ?>'>&nbsp;</td>
<?php } ?>
<?php } ?>
</tr>
<?php
}
if (isset($deleteType) && $deleteType == 'deleted') {
$delete_userid = "superuser";
if ($deleted_by_user_num != 1) $delete_userid = db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $deleted_by_user_num");
$delete_info = "Deleted $deleted_datetime by $delete_userid - $delete_reason<br><br>";
?>
<tr>
<td align='left' valign='top' class='<?php echo($bg) ?>'>&nbsp;</td>
<td colspan='8' align='left' valign='top' class='<?php echo($bg) ?>'><?php echo($delete_info) ?></td>
</tr>
<?php
}
}
if ($mode == 'account') {
?>
<tr>
<td colspan='8' align='right' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-CURRENT-ACCT-BALANCE'); ?> :: </b></td>
<td align='right' valign='top' class='data-header'><b><nobr><?php echo($balance_amt) ?></nobr></b></td>
<?php if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) { ?>
<?php if (!isset($deleteType) || $deleteType != 'deleted') { ?>
<td align='center' class='data-header'>&nbsp;</td>
<?php } ?>
<?php } ?>
</tr>
<?php
}
else {
$total_charges = round($total_charges * 100) / 100;
if ($total_charges < 0.00) $total_charges = "- $currencySymbol" . number_format(abs($total_charges),2);
else $total_charges = $currencySymbol . number_format($total_charges,2);
$total_credits = round($total_credits * 100) / 100;
if ($total_credits < 0.00) $total_credits = "- $currencySymbol" . number_format(abs($total_credits),2);
else $total_credits = $currencySymbol . number_format($total_credits,2);
?>
<tr>
<td colspan='5' align='right' valign='top' class='data-header'><b><?php displayLanguageText('TEXT-TRX-TOTALS-FOR-PERIOD'); ?> :: </b></td>
<td align='right' valign='top' class='data-header'><b><nobr><?php echo($total_charges) ?></nobr></b></td>
<td align='right' valign='top' class='data-header'><b><nobr><?php echo($total_credits) ?></nobr></b></td>
<td colspan='2' align='right' valign='top' class='data-header'>&nbsp;</td>
<?php if (!isset($deleteType) || $deleteType != 'deleted') { ?>
<td align='center' class='data-header'>&nbsp;</td>
<?php } ?>
</tr>
<?php
}
if (isset($view) && $view == 'details') {
?>
<tr>
<td colspan='<?php echo($nCols) ?>' align='center'>
<input type='submit' class='btn btn--primary' value="<?php displayLanguageText('TEXT-UPDATE-TRANSACTIONS'); ?>">
<input type='hidden' name='action' value='user-account'>
<input type='hidden' name='naction' value='update-trx'>
<input type='hidden' name='user_num' value='<?php echo($selected_user_num) ?>'>
<input type='hidden' name='posted_user_num' value='<?php echo($selected_user_num) ?>'>
</td>
</tr>
</form>
<?php
}
if ((!isset($view) || $view != 'details') && isset($print_cmd) && strlen($print_cmd) > 0) {
?>
<tr>
<td colspan='<?php echo($nCols) ?>' align='right'>
<?php include "user_account.list.buttons.php" ?>
</td>
</tr>
<?php
}
?>
</table>
</center>
<br>
<?php
}
?>
<script>
$(document).ready(function(){
<?php include "include/ajax.Setup.php" ?>
$("#delete-trx-dialog").dialog({
autoOpen: false,
minWidth: 450,
minHeight: 450,
modal: true,
position: { my: 'center', at: 'center' }
});
$(".delete-entry").on('click touch', function(e) {
e.preventDefault();
var unum = $(this).attr('unum');
var tnum = $(this).attr('tn');
$("#trx_user_num").val(unum);
$("#trx_record_num").val(tnum);
$.getJSON( "ajax.DataTable.Fetch.php",
{
table_name: 'user_account',
sequence_flag: "N",
user_num: unum,
trx_num: tnum,
action: 'delete-trx-info'
},
function(results) {
// alert('here');
$("#dynamic-table-div").html(results.content);
$("#delete-trx-dialog").dialog('open');
}
);
});
$("#cancelBtn").click(function(e) {
e.preventDefault();
$("#delete-trx-dialog").dialog('close');
});
$("#saveBtn").click(function(e) {
e.preventDefault();
var reason = $("#delete_reason").val();
if (reason.length < 3) {
alert("<?php displayLanguageText('ERRORMSG-MISSING-FORM-DATA'); ?>");
return false;
}
var formdata = $("#delete-reason-form").serialize();
<?php if ($_SESSION['UserInfo']['type'] == 'SuperUser') { ?>
alert(formdata);
<?php } ?>
window.location = "/?"+formdata;
});
});
</script>
<div id='delete-trx-dialog' title="<?php displayLanguageText('TEXT-DELETE-USER-TRANSACTION'); ?>">
<center>
<form method='post' action='/' name='delete-reason-form' id='delete-reason-form'>
<table width='100%' border='0'>
<tr>
<td align='left'>
<div id='dynamic-table-div'></div>
<br>
<br>
<p class='align-left'><b><label for='delete_reason'><?php displayLanguageText('TEXT-REASON-FOR-DELETING-TRANSACTION'); ?></label>:</b><br>
<input type='text' name='delete_reason' id='delete_reason' size='50'></p>
</td>
</tr>
</table>
<button id='saveBtn' class='btn btn--outline btn--xsmall'> <?php displayLanguageText('TEXT-INSERT'); ?> </button>
<button id='cancelBtn' class='btn btn--outline btn--xsmall'> <?php displayLanguageText('TEXT-CLOSE-WINDOW'); ?> </button>
<input type='hidden' name='action' value='user-account'>
<input type='hidden' name='naction' value='delete-confirmed'>
<input type='hidden' name='user_num' id='trx_user_num'>
<input type='hidden' name='record_num' id='trx_record_num'>
</form>
</center>
</div>