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

211 lines
8.0 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
//
// Process all actions to list and edit records
//
$action = "order-details-summary";
$TitleText = getLanguageText('TEXT-ORDER-DETAILS-SUMMARY');
// 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'))) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
header("Location: /?error_message=".urlencode($error_message));
exit();
}
$school_num = $school_record['record_num'];
$additional_info = 'N';
if (array_key_exists('additional_info',$_POST) && strlen($_POST['additional_info'])) $additional_info = $_POST['additional_info'];
// $print_cmd = "&additional_info=$additional_info";
// Handle selected date ranges
$start_date = date("Y-m-d",time());
$end_date = date("Y-m-d",time());
if (array_key_exists('start_date',$_POST) && strlen($_POST['start_date']) > 0) $start_date = $_POST['start_date'];
if (array_key_exists('end_date',$_POST) && strlen($_POST['end_date']) > 0) {
$end_date = $_POST['end_date'];
if ($end_date < $start_date) {
$end_date = $start_date;
$error_message = "Error: Specified Start Date is After Specified End Date";
}
}
$twhere = "AND hloh.added_date BETWEEN '$start_date' AND '$end_date' ";
$print_cmd = "&start_date=$start_date&end_date=$end_date";
// View only a selected userid
$uwhere = "";
unset($selected_usernum);
if (array_key_exists('selected_usernum',$_POST) && strlen($_POST['selected_usernum']) > 0) {
$selected_usernum = $_POST['selected_usernum'];
$uwhere = "AND u.record_num = $selected_usernum ";
$print_cmd .= "&selected_usernum=$selected_usernum";
}
// View only selected classes
unset($selected_class);
if (array_key_exists('selected_class',$_POST) && strlen($_POST['selected_class']) > 0) {
$selected_class = $_POST['selected_class'];
if ($selected_class != 'All') $uwhere .= "AND st.class_num = '$selected_class' ";
$print_cmd .= "&selected_class=$selected_class";
}
$message_width = 600;
include "form.messages.php";
?>
<form method='post' name='transactions'>
<table width='600' cellpadding='3' class='content-table'>
<tr>
<td align='right'><?php displayLanguageText('TEXT-START-DATE'); ?>: </td>
<td align='left'><input type='text' name='start_date' id='start_date' value='<?php echo($start_date) ?>' size='15' class='date-field'></td>
</tr>
<tr>
<td align='right'><?php displayLanguageText('TEXT-END-DATE'); ?>: </td>
<td align='left'><input type='text' name='end_date' id='end_date' value='<?php echo($end_date) ?>' size='15' class='date-field'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-USER-ID'); ?>: </td>
<td align='left'>
<select name='selected_usernum' class='select-width400'>
<option value=''><?php displayLanguageText('TEXT-VIEW-ALL'); ?></option>
<?php
// List userid's from users table
$results = db_query("select userid,concat_ws(' ',first_name,last_name) as name,type,record_num from users where school_num = $base_school_num order by last_name,first_name");
while ($row = db_fetch_array($results)) {
$userid = $row['userid'];
$name = $row['name'];
$type = $row['type'];
$rnum = $row['record_num'];
$selected = "";
if (isset($selected_usernum) && $selected_usernum == $rnum) $selected = " selected='selected'";
echo(" <option value='$rnum'$selected>$name ($type - $userid)</option>\n");
}
?>
</select>
</td>
</tr>
<tr>
<td align='right' valign='top'><?php echo($GlobalText['Class']); ?>: </td>
<td align='left'>
<select name='selected_class' class='select-width400'>
<option value='All'><?php echo($GlobalText['AllClasses']); ?></option>
<?php
// Get set of classes
$classes = db_query("select record_num from classes where school_num = $base_school_num order by sequence");
while ($row = db_fetch_array($classes)) {
$class_num = $row['record_num'];
$class_info = getClassInfo($class_num);
$selected = "";
if (isset($selected_class) && $selected_class == $class_num) $selected = " selected='selected'";
echo(" <option value='$class_num'$selected>$class_info</option>\n");
}
?>
</select>
</td>
</tr>
<tr>
<td align='right' valign='top'></td>
<td align='left' valign='top'><a href='#' class='btn btn--primary btn--xsmall' onClick='document.transactions.submit();'><span><?php displayLanguageText('TEXT-VIEW'); ?></span></a></td>
</tr>
</table>
<input type='hidden' name='action' value='order-details-summary'>
</form>
<?php
//
// List all requested records
//
$columnHeaders = array($GlobalText['Class'],
$GlobalText['Student'],
getLanguageText('TEXT-' . strtoupper($school_record['registrants_are'])),
getLanguageText('TEXT-ORDER-NUMBER'),
getLanguageText('TEXT-SUBTOTAL'),
getLanguageText('TEXT-DISCOUNT'),
getLanguageText('TEXT-ORDER-TOTAL'),
getLanguageText('TEXT-TAX'),
getLanguageText('TEXT-ORDER-NET')
);
$columnAlign = array('left','left','left','center','right','right','right','right','right');
$query = "SELECT st.class_num,st.first_name,st.last_name,st.record_num AS stnum,u.first_name AS parent_first_name,u.last_name AS parent_last_name,u.record_num AS unum," .
"hloh.record_num AS order_num,order_subtotal,discount_amount,order_total " .
"FROM people AS st, users AS u, hotlunch_order_header AS hloh " .
"WHERE st.school_num = $base_school_num " .
"AND u.school_num = $base_school_num " .
"AND st.user_num = u.record_num " .
"AND hloh.school_num = $school_num " .
"AND hloh.ordered_by_num = st.record_num " .
$uwhere . $twhere .
"ORDER BY 1,3,2";
$transactions = db_query($query);
$data = array();
while ($row = db_fetch_assoc($transactions)) {
$tax = 0;
$order_num = $row['order_num'];
$stnum = $row['stnum'];
$unum = $row['unum'];
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $unum AND order_num = $order_num AND transaction_type = 'Tax Charge'");
if (db_num_rows($results)) {
$r = db_fetch_assoc($results);
$tax = $r['transaction_amount'];
}
$net = $row['order_total'] + $tax;
$class_info = getClassInfo($row['class_num']);
$data[] = array($class_info,
$row['first_name'] . ' ' . $row['last_name'],
$row['parent_first_name'] . ' ' . $row['parent_last_name'],
$row['order_num'],
$currencySymbol . $row['order_subtotal'],
$currencySymbol . number_format($row['discount_amount'],2),
$currencySymbol . $row['order_total'],
$currencySymbol . number_format($tax,2),
$currencySymbol . number_format($net,2)
);
}
if (count($data) > 10) {
echo("<p style='text-align:right;'>");
echo("<a href='?action=order-details-summary-csv$print_cmd&additional_info=Y' class='btn btn--primary btn--xsmall'>" . getLanguageText('TEXT-SPREADSHEET') . " <span style='font-size:14px'>+</a>&nbsp;&nbsp;&nbsp;");
echo("</p>\n");
}
listDataCustom($data,$columnHeaders,$action,array(),'N',$columnAlign);
if (count($data)) {
echo("<p style='text-align:right;'>");
echo("<a href='?action=order-details-summary-csv$print_cmd&additional_info=Y' class='btn btn--primary btn--xsmall'>" . getLanguageText('TEXT-SPREADSHEET') . " <span style='font-size:14px'>+</a>&nbsp;&nbsp;&nbsp;");
echo("</p>\n");
}
endTemplate();
?>