Files
HotLunches/students.display.orders.php
T
2026-10-19 15:22:52 -07:00

250 lines
10 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
if (isset($record_num)) $student_num = $record_num;
if (isset($current_student_num)) $student_num = $current_student_num;
// Determine the number of currently active schedules
$today = date("Y-m-d",time());
$now = date("Y-m-d H:i:s",time());
$school_num = $school_record['record_num'];
$swhere = "AND start_order_datetime <= '$now' AND status in ('Active') ";
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator'))) $swhere = "AND status in ('Active','Pending') ";
if ($_SESSION['UserInfo']['type'] == 'SuperUser') $swhere = "AND status in ('Active') ";
$num_active = db_getVal("SELECT count(*) FROM hotlunch_schedules " .
"WHERE school_num = $school_num " .
"AND schedule_type != 'Volunteer Only' " .
$swhere);
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') echo($num_active);
// Check if there is a current schedule
$today = date("Y-m-d",time());
$query = "select * from hotlunch_schedules " .
"where school_num = $school_num " .
"AND schedule_type != 'Volunteer Only' " .
$swhere .
"order by $scheduleSortOrder";
$current_schedules = db_query($query);
$num_schedules = db_num_rows($current_schedules);
$num_classes = db_getVal("SELECT count(*) FROM classes WHERE school_num = $base_school_num");
$schedules = array();
$displayDiscounts = False;
if (db_num_rows($current_schedules) > 0) {
if ($num_classes > 0) $class_num = db_getVal("select class_num from people where school_num = $base_school_num and record_num = $student_num");
else {
$class_num = 3;
if ($_SESSION['UserInfo']['type'] == 'Staff') $class_num = 1;
if ($_SESSION['UserInfo']['type'] == 'Guest') $class_num = 2;
}
$cutoff_date = date("Y-m-d",time() - 60 * 60 * 24 * 45);
while ($row = db_fetch_array($current_schedules)) {
$schedule_num = $row['record_num'];
// Check that the schedule has menu dates and items defined
$numDates = db_getVal("SELECT count(*) FROM hotlunch_menu_dates WHERE school_num = $school_num AND schedule_num = $schedule_num");
if ($numDates == 0) continue;
$numItems = db_getVal("SELECT count(*) FROM hotlunch_menu_dates AS hlmd, hotlunch_menu_items AS hlmi " .
"WHERE hlmd.school_num = $school_num " .
"AND hlmi.school_num = $school_num " .
"AND hlmd.schedule_num = $schedule_num " .
"AND hlmi.menu_num = hlmd.record_num");
if ($numItems == 0) continue;
// Check if there is an order for this schedule
$results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_num = $student_num AND schedule_num = $schedule_num");
if (db_num_rows($results)) {
$schedules[] = $row;
continue;
}
// Check if this is a limited access schedule by class
$class_entries = db_getVal("select count(*) from hotlunch_schedules_classes where school_num = $school_num and schedule_num = $schedule_num");
if ($class_entries > 0 && $class_num > 0) {
$query = "select count(*) from hotlunch_schedules_classes where school_num = $school_num and schedule_num = $schedule_num and class_num = $class_num";
$schedule_access = db_getVal($query);
if ($schedule_access == 0) continue;
}
// Check if this is a limited access schedule by category
$category_entries = db_getVal("select count(*) from hotlunch_schedules_categories where school_num = $school_num and schedule_num = $schedule_num");
if ($category_entries > 0) {
$query = "SELECT count(*) FROM hotlunch_schedules_categories AS hlsc, people_categories AS pc " .
"WHERE hlsc.school_num = $school_num " .
"AND pc.school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND hlsc.category_num = pc.category_num " .
"AND pc.people_num = $student_num";
$schedule_access = db_getVal($query);
if ($schedule_access == 0) continue;
}
$schedules[] = $row;
$schedule_num = $row['record_num'];
$discount = db_getVal("SELECT discount_amount " .
"FROM hotlunch_order_header " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND ordered_by_num = $student_num " .
"AND ordered_by_type IN ('Staff','Student','Customer')");
if ($discount > 0) $displayDiscounts = True;
}
}
if (count($schedules) > 0) {
// Initialize the totals
$t_balance = 0;
$t_subtotal = 0;
$t_total = 0;
$t_discount = 0;
$t_paid = 0;
?>
<br>
<table width='98%' cellpadding='2' cellspacing='1' class='content-table' align='center'>
<tr class='heading'>
<td align='left' width='230'><b><?php displayLanguageText('TEXT-SCHEDULE'); ?></b></td>
<td align='right'><b><?php displayLanguageText('TEXT-TOTAL'); ?></b></td>
<?php if ($displayDiscounts) { ?>
<td align='right'><b><?php displayLanguageText('TEXT-DISCOUNT'); ?></b></td>
<?php } ?>
<td align='right'><b><?php displayLanguageText('TEXT-NET'); ?></b></td>
<td align='center'><b><?php displayLanguageText('TEXT-STATUS'); ?></b></td>
<td width='250'>&nbsp;</td>
</tr>
<?php
$order_total = 0;
$order_net = 0;
if (!isset($otipSpans)) {
$otipSpans = "";
$otipSpanIDs = array();
}
$lcount = 0;
$schedule_status = "";
for ($sn = 0; $sn < count($schedules); $sn++) {
$schedule = $schedules[$sn];
extract($schedule);
$schedule_num = $record_num;
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator'))) $schedule_status = "(" . $status . ")";
$span_id = "schedule_$record_num";
if (!in_array($span_id,$otipSpanIDs)) {
$otipSpanIDs[] = $span_id;
$start_order_datet = substr($start_order_date,1,16);
$end_order_datet = substr($end_order_date,1,16);
$otipSpans .= "<span id='$span_id'>" . $otipTABLE .
sprintf($otipROW2,getLanguageText('TEXT-SCHEDULE') . ": ",$schedule_name) .
sprintf($otipROW2,getLanguageText('TEXT-START-ORDER') . ": ",$start_order_datet) .
sprintf($otipROW2,getLanguageText('TEXT-END-ORDER') . ": ",$end_order_datet);
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator'))) {
if ($schedule_type == 'Hot Lunch' || $schedule_type == 'Date Sensitive') {
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-SCHEDULE-START') . ": ",$schedule_start_date) .
sprintf($otipROW2,getLanguageText('TEXT-SCHEDULE-END') . ": ",$schedule_end_date);
}
$otipSpans .= sprintf($otipROW2,getLanguageText('TEXT-TYPE') . ": ",$schedule_type);
}
$otipSpans .= "</table></span>\n";
}
// Get order information for this student and this schedule
$query = "select schedule_num,order_subtotal,discount_amount,order_total," .
"amount_paid,status,record_num as order_num " .
"from hotlunch_order_header " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and ordered_by_num = $student_num " .
"and status != 'Deleted'";
$results = db_query($query);
if (db_num_rows($results) == 0) {
$order_subtotal = 0;
$discount_amount = 0;
$order_total = 0;
$amount_paid = 0;
$balance = 0;
$status = getLanguageText('TEXT-NO-ORDER');
unset($order_num);
$l_bgclass = 'data-odd';
if ($lcount % 2) $l_bgclass = 'data-even';
$lcount++;
// Change schedule name to a link
$now = date("Y-m-d H:i:00",time());
if ($end_order_datetime >= $now) {
$schedule_name = "<a href='?action=orders&naction=edit&schedule_num=$schedule_num&student_num=$student_num&entered_order_num=' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">" .
$schedule_name . "</a> " . $schedule_status;
}
else {
$schedule_name = "<a href=\"javascript:TagToTip('$span_id')\" onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$schedule_name</a> $schedule_status";
}
// Display the row of data
include "students.display.orders.row.php";
}
else {
while ($row = db_fetch_assoc($results)) {
extract($row);
$balance = $order_subtotal - $discount_amount - $amount_paid;
$t_subtotal += $order_subtotal;
$t_total += $order_total;
$t_discount += $discount_amount;
$t_paid += $amount_paid;
$t_balance += $balance;
$l_bgclass = 'data-odd';
if ($lcount % 2) $l_bgclass = 'data-even';
$lcount++;
// Change schedule name to a link
$schedule_name = "<a href='?action=orders&naction=edit&schedule_num=$schedule_num&student_num=$student_num&entered_order_num=$order_num' onmouseover=\"TagToTip('$span_id')\" onmouseout=\"UnTip()\">$schedule_name</a>";
// Display the row of data
include "students.display.orders.row.php";
}
}
}
?>
<tr class='footer-row'>
<td align='left'><b><?php displayLanguageText('TEXT-TOTALS'); ?>: </b></td>
<td align='right'><b><?php echo($currencySymbol . number_format($t_subtotal,2)) ?></b></td>
<?php if ($t_discount != 0) { ?>
<td align='right'><b><?php echo($currencySymbol . number_format($t_discount,2)) ?></b></td>
<?php } ?>
<td align='right'><b><?php echo($currencySymbol . number_format($t_total,2)) ?></b></td>
<td align='center'>&nbsp;</td>
<td align='center'>&nbsp;</td>
</tr>
</table>
<?php
}
?>