Files
HotLunches/user_account.payment.detail.csv.php
2026-10-19 15:42:10 -07:00

251 lines
8.6 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
echo("Invalid Access");
exit();
}
// 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'))) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
header("Location: /?error_message=".urlencode($error_message));
exit();
}
// Setup parameters for this document
$columns = array(
array('fname' => 'userid',
'title' => getLanguageText('TEXT-USER-ID'),
'col' => 8,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'trx_date',
'title' => getLanguageText('TEXT-DATE'),
'col' => 40,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'transaction_type',
'title' => getLanguageText('TEXT-TYPE'),
'col' => 60,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'account',
'title' => getLanguageText('TEXT-ACCOUNT'),
'col' => 80,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'name',
'title' => getLanguageText('TEXT-NAME'),
'col' => 125,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'method',
'title' => getLanguageText('TEXT-METHOD'),
'col' => 170,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'amt',
'title' => getLanguageText('TEXT-AMOUNT'),
'col' => 190,
'total' => 'C',
'format' => 'currency',
'align' => 'R'),
array('fname' => 'pamt',
'title' => getLanguageText('TEXT-PAYMENT'),
'col' => 210,
'total' => 'Y',
'format' => 'currency',
'align' => 'R'),
array('fname' => '',
'title' => '',
'col' => 230,
'align' => 'C'),
array('fname' => 'posted',
'title' => getLanguageText('TEXT-POSTED-TIME'),
'col' => 235,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'schedule_name',
'title' => getLanguageText('TEXT-SCHEDULE'),
'col' => 235,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'End Of Row',
'col' => 265,
'align' => 'C'),
);
$document_name = getLanguageText('TEXT-USER-PAYMENT-DETAIL');
$school_name = $school_record['school_name'];
$report_subtitle = '';
if (array_key_exists('selected_schedule_num',$_GET) && intval($_GET['selected_schedule_num']) > 0) {
$snum = $_GET['selected_schedule_num'];
$report_subtitle = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $snum");
$report_subtitle .= ": ";
}
$report_subtitle .= $_GET['start_date'] . " - " . $_GET['end_date'];
$query = $_GET['query'];
if (stripos("update",$query) !== FALSE) exit();
if (stripos("insert",$query) !== FALSE) exit();
if (stripos("delete",$query) !== FALSE) exit();
if (!preg_match("/^select /i",$query)) exit();
if (preg_match("/select .*select/i",$query)) exit();
$transactions = db_query($query);
$page = 0;
$prev_trx = 0;
$totals = array();
$xlsTitles = array();
$xlsHeaders = array();
$xlsData = array();
// Print titles
$xlsTitles[] = array("$school_name :: $document_name");
if (strlen($report_subtitle)) $xlsTitles[] = array($report_subtitle);
$row = array();
for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) $xlsHeaders[] = $columns[$cnum]['title'];
while ($row = db_fetch_array($transactions)) {
// Get user_account record
$ptrxNum = $row['posted_to_transaction'];
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND record_num = $ptrxNum");
$urow = db_fetch_assoc($results);
$trx_type = $urow['transaction_type'];
// Format output
$row['account'] = $row['first_name'] . ' ' . $row['last_name'];
$row['pamt'] = $row['posted_amount'];
if ($trx_type == 'Order') {
$row['order_num'] = $urow['order_num'];
$row['name'] = getOrderedByName($urow['order_num']);
$row['posted'] = $trx_type .= " #" . $urow['order_num'];
}
$row['method'] = $row['payment_method'];
if (strlen($row['method']) == 0) $row['method'] = $row['transaction_type'];
if ($row['method'] == 'Check') $row['method'] .= " #" . $row['payment_reference'];
$row['amt'] = $row['transaction_amount'];
// Get schedule info
$schedule_name = "";
$order_num = intval($row['order_num']);
if ($order_num > 0) {
$schedule_num = db_getVal("SELECT schedule_num FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
$schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
}
$row['schedule_name'] = $schedule_name;
$entry = array();
if ($row['trx_num'] != $prev_trx) {
for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$fname = $columns[$cnum]['fname'];
$align = $columns[$cnum]['align'];
if (strlen($fname)) {
$text = $row[$fname];
if ($columns[$cnum]['format'] == 'currency') $text = formatCurrency($text);
$entry[] = $text;
}
else $entry[] = '';
if ($columns[$cnum]['total'] == 'C') $totals[$cnum] += $row[$fname];
if ($columns[$cnum]['total'] == 'Y') $totals[$cnum] += $row[$fname];
}
$count++;
$xlsData[] = $entry;
}
else {
$count--;
$bg = false;
if ($count % 2) $bg = true;
for ($cnum = 0; $cnum < 4; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$entry[] = '';
}
for ($cnum = 4; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$fname = $columns[$cnum]['fname'];
$align = $columns[$cnum]['align'];
if (strlen($fname)) {
$text = $row[$fname];
if ($columns[$cnum]['format'] == 'currency') $text = formatCurrency($text);
if ($columns[$cnum]['total'] == 'C') $text = '';
$entry[] = $text;
}
else $entry[] = '';
if (!array_key_exists($cnum, $totals)) $totals[$cnum] = 0;
if ($columns[$cnum]['total'] == 'Y') $totals[$cnum] += $row[$fname];
}
$xlsData[] = $entry;
}
$prev_trx = $row['trx_num'];
}
$entry = array();
for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$align = $columns[$cnum]['align'];
$text = "";
if ($columns[$cnum]['total'] == 'Y' || $columns[$cnum]['total'] == 'C') {
$text = $totals[$cnum];
if ($columns[$cnum]['format'] == 'currency') $text = formatCurrency($text);
}
$entry[] = $text;
}
$xlsData[] = $entry;
// Output the data
$fname = genFileName("user_account.payment.detail.csv");
xlsData($xlsData,$xlsHeaders,$fname,$xlsTitles);
return;
?>