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

387 lines
13 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
// Start the template and output buffering
startTemplate();
$templatePageTitle = "";
$headerArgs = "";
// Ensure that only valid user types have access to this module
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team');
if (checkPermission($AllowedUserTypes) != 1) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
// Get schedule_num
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
// Get menu_num
if (array_key_exists('menu_num',$_POST)) $menu_num = intval($_POST['menu_num']);
if (!isset($schedule_num) || !isset($menu_num)) {
$error_message = getLanguageText('ERRORMSG-INVALID-ACCESS');
include "form.messages.php";
return;
}
// Check if this is a valid schedule
$swhere = "";
if ($_SESSION['UserInfo']['type'] == 'Supplier') $swhere = " and supplier_num = " . $_SESSION['UserInfo']['supplier_num'];
$query = "select * from hotlunch_schedules " .
"where record_num = $schedule_num " .
"and school_num = $school_num " .
$swhere;
$results = db_query($query);
if (db_num_rows($results) == 0) {
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE');
include "form.messages.php";
return;
}
$hotlunch_schedule = db_fetch_array($results);
// If this is a ScheduleTeam user check if they have permission to access this schedule
if (in_array($_SESSION['UserInfo']['type'],array('Schedule Team','Schedule Volunteer'))) {
$userNum = $_SESSION['UserInfo']['record_num'];
$access = db_getVal("SELECT count(*) FROM hotlunch_schedules_people WHERE school_num = $school_num AND schedule_num = $schedule_num AND user_num = $userNum");
if (!$access || $access == 0) {
$error_message = getLanguageText('TEXT-NO-ACCESS-TO-SCHEDULE');
include "form.messages.php";
return;
}
}
// Check that this schedule date is valid
$menu_num = intval($menu_num);
$query = "select * from hotlunch_menu_dates " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and record_num = $menu_num";
$results = db_query($query);
if (db_num_rows($results) == 0) {
$error_message = getLanguageText('ERRORMSG-INVALID-MENU');
include "form.messages.php";
return;
}
$menu_record = db_fetch_array($results);
// Get set of menu items for this date
$query = "select * from hotlunch_menu_items " .
"where school_num = $school_num " .
"and menu_num = $menu_num " .
"order by sequence";
$results = db_query($query);
if (db_num_rows($results) == 0) {
$error_message = getLanguageText('ERRORMSG-NO-MENU-ITEMS');
include "form.messages.php";
return;
}
$menu_items = array();
$count = 0;
while ($row = db_fetch_array($results)) {
extract($row);
$menu_items[$count]['title'] = $item_title;
$menu_items[$count]['num'] = $record_num;
$menu_items[$count]['grandtotal'] = 0;
$count++;
}
$cols = count($menu_items) + 1;
$templatePageTitle = getLanguageText('TEXT-ORDER-DETAILS') . " - " . $hotlunch_schedule['schedule_name'];
?>
<br>
<table width='90%' cellpadding='3' cellspacing='1' border='0' class='content-table'>
<tr>
<td align='left' class='heading'>
<h2><?php echo($menu_record['menu_title']) ?> - <?php echo($menu_record['menu_date']) ?></h2>
</td>
</tr>
<tr>
<td align='left'>
<table width='100%' cellpadding='1' cellspacing='1' border='0'>
<?php
// Get list of classes
$query = "select record_num from classes " .
"where school_num = $base_school_num " .
"order by sequence";
$cresults = db_query($query);
$processed_staff = array();
$classes = array();
while ($class = db_fetch_array($cresults)) {
$classes[] = $class['record_num'];
}
$classes[] = 0;
$classes[] = 1;
for ($c = 0; $c < count($classes); $c++) {
$class_num = $classes[$c];
if ($class_num == 0) $class_info = "Staff";
if ($class_num == 1) $class_info = "Customer";
if ($class_num > 1) $class_info = getClassInfo($class_num,'internal');
// Get classroom orders for this menu date
$query = "select concat_ws(', ',st.last_name,st.first_name) as name,people_type as ptype,concat('$currencySymbol',hloh.order_total) as total," .
"hloh.status as status,hloh.ordered_by_num " .
"from people as st, hotlunch_order_header as hloh, hotlunch_order_items as hloi " .
"where st.school_num = $base_school_num " .
"and hloh.school_num = $school_num " .
"and hloi.school_num = $school_num " .
"and st.record_num = hloh.ordered_by_num " .
"and st.record_num = hloi.ordered_by_num " .
"and st.class_num = $class_num " .
"and hloh.schedule_num = $schedule_num " .
"AND hloh.status NOT IN ('Inactive','Deleted') " .
"and hloi.schedule_num = $schedule_num " .
"and hloi.menu_num = $menu_num " .
"and hloi.active != 'N' " .
"and hloh.record_num = hloi.order_num " .
"order by ptype desc,name";
$results = db_query($query);
if (db_num_rows($results) == 0) continue;
?>
<tr>
<td align='left' colspan='<?php echo($cols) ?>'><h2><?php echo($class_info) ?></h2></td>
</tr>
<tr>
<td align='left' class='heading'>&nbsp;</td>
<?php
$width = intval(($default_table_width * .9 * .75) / count($menu_items));
for ($i = 0; $i < count($menu_items); $i++) {
$title = $menu_items[$i]['title'];
echo(" <td width='$width' class='heading' align='center' valign='top'>$title</td>\n");
$menu_items[$i]['total'] = 0;
}
?>
</tr>
<?php
$count = 0;
while ($entry = db_fetch_array($results)) {
echo(" <tr>\n");
$name = $entry['name'];
$ordered_by_type = $entry['ptype'];
$ordered_by_num = $entry['ordered_by_num'];
if ($ordered_by_type == 'Staff') $processed_staff[] = $ordered_by_num;
$class = "data-odd";
if ($count % 2) $class = "data-even";
$count++;
echo(" <td align='left' class='$class'>$name</td>\n");
for ($i = 0; $i < count($menu_items); $i++) {
$menu_item_num = intval($menu_items[$i]['num']);
$query = "select qty from hotlunch_order_items " .
"where school_num = $school_num " .
"and ordered_by_num = $ordered_by_num " .
"and schedule_num = $schedule_num " .
"and menu_num = $menu_num " .
"and menu_item_num = $menu_item_num " .
"and active != 'N'";
$mresults = db_query($query);
if (db_num_rows($mresults) == 0) {
echo(" <td align='left' class='$class'>&nbsp;</td>\n");
}
else {
$mrow = db_fetch_array($mresults);
$qty = $mrow['qty'];
$menu_items[$i]['total'] += $qty;
$menu_items[$i]['grandtotal'] += $qty;
echo(" <td align='center' class='$class'>$qty</td>\n");
}
}
echo(" </tr>\n");
}
?>
<tr>
<td align='left' class='heading'><?php displayLanguageText('TEXT-TOTALS'); ?>:</td>
<?php
for ($i = 0; $i < count($menu_items); $i++) {
$total = $menu_items[$i]['total'];
echo(" <td class='heading' align='center' valign='top'>$total</td>\n");
$menu_items[$i]['total'] = 0;
}
?>
</tr>
<tr>
<td align='left' colspan='<?php echo($cols) ?>'>&nbsp;</td>
</tr>
<?php
}
// Get staff orders for this menu date
$pwhere = "";
if (count($processed_staff) > 0) $pwhere = "and s.record_num not in (" . implode(",",$processed_staff) . ") ";
$query = "select concat_ws(', ',s.last_name,s.first_name) as name,'Staff' as ptype,concat('$currencySymbol',hloh.order_total) as total," .
"hloh.status as status,hloh.ordered_by_num " .
"from people as s, hotlunch_order_header as hloh, hotlunch_order_items as hloi " .
"where s.school_num = $base_school_num " .
"and hloh.school_num = $school_num " .
"and hloi.school_num = $school_num " .
"and s.record_num = hloh.ordered_by_num " .
"and s.record_num = hloi.ordered_by_num " .
"and s.status != 'Inactive' " .
"and s.people_type = 'Staff' " .
"and hloh.status NOT IN ('Inactive','Deleted') " .
"and hloh.schedule_num = $schedule_num " .
"and hloi.menu_num = $menu_num " .
"and hloi.active != 'N' " .
"and hloh.record_num = hloi.order_num " .
$pwhere .
"order by ptype,name";
$results = db_query($query);
if (db_num_rows($results) > 0) {
?>
<tr>
<td align='left' colspan='<?php echo($cols) ?>'><h2>Staff Orders</h2></td>
</tr>
<tr>
<td align='left' class='heading'>&nbsp;</td>
<?php
$width = intval(($default_table_width * .9 * .75) / count($menu_items));
for ($i = 0; $i < count($menu_items); $i++) {
$title = $menu_items[$i]['title'];
echo(" <td width='$width' class='heading' align='center' valign='top'>$title</td>\n");
$menu_items[$i]['total'] = 0;
}
?>
</tr>
<?php
$count = 0;
while ($entry = db_fetch_array($results)) {
echo(" <tr>\n");
$name = $entry['name'];
$ordered_by_type = $entry['ptype'];
$ordered_by_num = $entry['ordered_by_num'];
$class = "data-odd";
if ($count % 2) $class = "data-even";
$count++;
echo(" <td align='left' class='$class'>$name</td>\n");
for ($i = 0; $i < count($menu_items); $i++) {
$menu_item_num = intval($menu_items[$i]['num']);
$query = "select qty from hotlunch_order_items " .
"where school_num = $school_num " .
"and ordered_by_num = $ordered_by_num " .
"and schedule_num = $schedule_num " .
"and menu_num = $menu_num " .
"and menu_item_num = $menu_item_num " .
"and active != 'N'";
$mresults = db_query($query);
if (db_num_rows($mresults) == 0) {
echo(" <td align='left' class='$class'>&nbsp;</td>\n");
}
else {
$mrow = db_fetch_array($mresults);
$qty = $mrow['qty'];
$menu_items[$i]['total'] += $qty;
$menu_items[$i]['grandtotal'] += $qty;
echo(" <td align='left' align='center' class='$class'>$qty</td>\n");
}
}
echo(" </tr>\n");
}
?>
<tr>
<td align='left' class='heading'>Staff Totals:</td>
<?php
for ($i = 0; $i < count($menu_items); $i++) {
$total = $menu_items[$i]['total'];
echo(" <td class='heading' align='center' valign='top'>$total</td>\n");
$menu_items[$i]['total'] = 0;
}
}
?>
</tr>
<tr>
<td align='left' colspan='<?php echo($cols) ?>'><h2>Concession Order</h2></td>
</tr>
<tr>
<td align='left' class='heading'>Concession:</td>
<?php
for ($i = 0; $i < count($menu_items); $i++) {
$item_num = intval($menu_items[$i]['num']);
$qty = 0;
if ($item_num > 0) {
$query = "select qty from hotlunch_order_items " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and ordered_by_type = 'Concession' " .
"and menu_item_num = $item_num " .
"and active != 'N'";
$qty = db_getVal($query);
}
echo(" <td class='heading' align='center' valign='top'>$qty</td>\n");
$menu_items[$i]['grandtotal'] += $qty;
}
?>
</tr>
<tr>
<td align='left' colspan='<?php echo($cols) ?>'>&nbsp;</h2></td>
</tr>
<tr>
<td align='left' class='heading'>School Totals:</td>
<?php
for ($i = 0; $i < count($menu_items); $i++) {
$total = $menu_items[$i]['grandtotal'];
echo(" <td class='heading' align='center' valign='top'>$total</td>\n");
}
?>
</tr>
</table>
<br>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td align='left'><a href='?action=menu-details-print&schedule_num=<?php echo($schedule_num) ?>&menu_num=<?php echo($menu_num) ?>' class='btn btn--primary btn--xsmall'><span>Print Menu Report</span></a></td>
</tr>
</table>
<br>
<?php
include "hotlunch_reports.menu.php";
endTemplate();
?>