Files
HotLunches/hotlunch_order_header.form.php
2026-10-19 15:22:52 -07:00

314 lines
13 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit();
}
// 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');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
if (array_key_exists('order_num',$_GET)) $order_num = intval($_GET['order_num']);
if (!isset($order_num)) {
echo("<br>\n");
$error_message = "Missing Order Number";
include "form.messages.php";
return;
}
// Calculate the order cost
$query = "select sum(hloi.qty * hlmp.supplier_product_qty * (sp.package_cost / sp.package_qty)) as cost " .
"from hotlunch_order_items as hloi, hotlunch_menu_products as hlmp, supplier_products as sp " .
"where hloi.school_num = $school_num " .
"and hlmp.school_num = $school_num " .
"and sp.school_num = $supplier_school_num " .
"and hloi.order_num = $order_num " .
"and hloi.schedule_num = $schedule_num " .
"and hloi.menu_item_num = hlmp.menu_item_num " .
"and hlmp.supplier_product_num = sp.record_num";
$order_cost = doubleval(db_getVal($query));
db_query("UPDATE hotlunch_order_header SET order_cost = $order_cost WHERE record_num = $order_num");
// Get the order header record
$query = "select * from hotlunch_order_header " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and record_num = $order_num";
$results = db_query($query);
if (db_num_rows($results) == 0) {
echo("<br>\n");
$error_message = "Order Not Found";
include "form.messages.php";
return;
}
$header = db_fetch_array($results);
extract($header);
// Get person's name
if ($ordered_by_type == 'Student') {
$query = "select concat_ws(' ',first_name,last_name) from people " .
"where school_num = $base_school_num " .
"and people_type = 'Student' " .
"and record_num = $ordered_by_num";
}
else {
$query = "select concat_ws(' ',first_name,last_name) from people " .
"where school_num = $base_school_num " .
"and people_type = 'Staff' " .
"and record_num = $ordered_by_num";
}
$name = db_getVal($query);
// Get the userid of the person who entered this order
$entered_by_id = db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $entered_by");
?>
<br>
<form method='post' action='/'>
<?php
$message_width = $default_form_width;
include "form.messages.php";
?>
<table width='<?php echo($default_form_width) ?>' class='content-table'>
<tr>
<td colspan='2' align='center' class='heading'><?php echo($PageTitle) ?></td>
</tr>
<tr>
<td colspan='2' align='center'>&nbsp;</td>
</tr>
<tr>
<td colspan='2' align='center'>
<table width='80%' cellpadding='2' cellspacing='2' border='0'>
<tr>
<td colspan='2' align='left' valign='top'><?php displayLanguageText('TEXT-ORDERED-BY'); ?>: <br>
<select name='selected_ordered_by_num'>
<?php
// Get and list students
$query = "SELECT concat(first_name,' ',last_name) as name,people_type,class_num,user_num,record_num " .
"FROM people WHERE school_num = $base_school_num " .
"AND people_type = 'Student' " .
"ORDER BY last_name,first_name";
$students = db_query($query);
if (db_num_rows($students) > 0) {
echo(" <optgroup label='" . $GlobalText['Students'] . "'>\n");
while ($row = db_fetch_array($students)) {
$name = $row['name'];
$cnum = $row['class_num'];
$unum = $row['user_num'];
$rnum = $row['record_num'];
$type = $row['people_type'];
$userid = db_getVal("SELECT userid FROM users WHERE record_num = $unum");
$class_info = getClassInfo($cnum,'internal',1);
$selected = "";
if ($rnum == $ordered_by_num) $selected = " selected='selected'";
echo(" <option value='$rnum'$selected>$name ($userid) - $class_info</option>\n");
}
echo(" </optgroup>\n");
}
// Get and list staff
$query = "SELECT concat(first_name,' ',last_name) as name,people_type,class_num,user_num,record_num " .
"FROM people WHERE school_num = $base_school_num " .
"AND people_type = 'Staff' " .
"ORDER BY last_name,first_name";
$staff = db_query($query);
if (db_num_rows($staff) > 0) {
echo(" <optgroup label='" . $GlobalText['Staff'] . "'>\n");
while ($row = db_fetch_array($staff)) {
$name = $row['name'];
$rnum = $row['record_num'];
$selected = "";
if ($rnum == $ordered_by_num) $selected = " selected='selected'";
echo(" <option value='$rnum'$selected>$name</option>\n");
}
echo(" </optgroup>\n");
}
// Get and list customers
$query = "SELECT concat(first_name,' ',last_name) as name,people_type,class_num,user_num,record_num " .
"FROM people WHERE school_num = $base_school_num " .
"AND people_type = 'Customer' " .
"ORDER BY last_name,first_name";
$staff = db_query($query);
if (db_num_rows($staff) > 0) {
echo(" <optgroup label='" . getLanguageText('TEXT-CUSTOMERS') . "'>\n");
while ($row = db_fetch_array($staff)) {
$name = $row['name'];
$rnum = $row['record_num'];
$selected = "";
if ($rnum == $ordered_by_num) $selected = " selected='selected'";
echo(" <option value='$rnum'$selected>$name</option>\n");
}
echo(" </optgroup>\n");
}
?>
</select>
</td>
</tr>
<tr>
<td width='30%' align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-DATE'); ?>: </td>
<td align='left' valign='top'><input type='text' name='added_date' id='added_date' value="<?php echo($added_date) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-UPDATED-DATE'); ?>: </td>
<td align='left' valign='top'><input type='text' name='updated_date' id='updated_date' value="<?php echo($updated_date) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-PAID-DATE'); ?>: </td>
<td align='left' valign='top'><input type='text' name='paid_date' id='paid_date' value="<?php echo($paid_date) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-COST'); ?>: </td>
<td align='left' valign='top'><input type='text' name='order_cost' id='order_cost' value="$<?php echo($order_cost) ?>" size='7' class='readonly' readonly='readonly'> <span class='small'>** Estimate **</span></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-SUBTOTAL'); ?>: </td>
<td align='left' valign='top'><input type='text' name='order_subtotal' id='order_subtotal' value="$<?php echo($order_subtotal) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-DISCOUNT-AMOUNT'); ?>: </td>
<td align='left' valign='top'><input type='text' name='discount_amount' id='discount_amount' value="$<?php echo($discount_amount) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-TOTAL'); ?>: </td>
<td align='left' valign='top'><input type='text' name='order_total' id='order_total' value="$<?php echo($order_total) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-AMOUNT-PAID'); ?>: </td>
<td align='left' valign='top'><input type='text' name='amount_paid' id='amount_paid' value="$<?php echo($amount_paid) ?>" size='7' class='readonly' readonly='readonly'></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ENTERED-BY'); ?>: </td>
<td align='left' valign='top'><b><?php echo($entered_by_id) ?></b></td>
</tr>
<tr>
<td align='center' colspan='2'>
<br>
<table width='90%'>
<tr>
<td align='center' bgcolor='#ffffff'>
<p><b><?php displayLanguageText('TEXT-ORDER-STATUS-SET-TO-COMPLIMENTARY-MSG'); ?></b></p>
<p><b><?php displayLanguageText('TEXT-ORDER-STATUS-SET-TO-PAID-MSG'); ?></b></p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-STATUS'); ?>: </td>
<td align='left' valign='top'>
<?php
switch ($status) {
default:
case 'Unpaid':
BuildFileRadio("order_status.unpaid.txt","status",$status);
break;
case 'Paid':
BuildFileRadio("order_status.paid.txt","status",$status);
break;
case 'Complimentary':
BuildFileRadio("order_status.complimentary.txt","status",$status);
break;
}
?>
</td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-SOURCE'); ?>: </td>
<td align='left' valign='top'><?php BuildFileRadio("order_source.txt","source",$source) ?></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-PEOPLE-TYPE'); ?>: </td>
<td align='left' valign='top'><?php BuildFileRadio("people_type.txt","ordered_by_type",$ordered_by_type) ?></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-ORDER-DELIVERED'); ?>: </td>
<td align='left' valign='top'><?php BuildFileRadio("yn.txt","delivered",$delivered) ?></td>
</tr>
<tr>
<td align='right' valign='top'><?php displayLanguageText('TEXT-PRICE-CATEGORY'); ?>: </td>
<td align='left' valign='top'><?php BuildFileRadio("menu_price_category.txt","price_category",$price_category) ?></td>
</tr>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<?php
$order_log = db_query("SELECT * FROM hotlunch_order_log WHERE school_num = $school_num AND order_num = $order_num ORDER BY entered_time");
$data = array();
while ($row = db_fetch_assoc($order_log)) {
$data[] = array($row['entered_datetime'],$row['order_subtotal'],$row['discount_amount'],$row['tax_amount'],$row['order_total'],$row['source']);
}
if (count($data)) {
$columnHeaders = array(getLanguageText('TEXT-ENTERED'),
getLanguageText('TEXT-SUBTOTAL'),
getLanguageText('TEXT-DISCOUNT'),
getLanguageText('TEXT-TAX'),
getLanguageText('TEXT-TOTAL'),
getLanguageText('TEXT-SOURCE')
);
$columnAlign = array('left','right','right','right','right','center');
$TableWidth = 600;
listDataCustom($data,$columnHeaders,'',array(),'N',$columnAlign);
}
?>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<br>
<?php
if (!isset($show_all)) $show_all = '';
if (!isset($show_only)) $show_only = '';
if (!isset($show_status)) $show_status = '';
if (!isset($show_source)) $show_source = '';
?>
<input type='submit' class='btn btn--primary' value="<?php displayLanguageText('TEXT-UPDATE-ORDER-STATUS'); ?>">
<input type='hidden' name='action' value='<?php echo($action) ?>'>
<input type='hidden' name='naction' value='<?php echo($next_naction) ?>'>
<input type='hidden' name='record_num' value='<?php echo($record_num) ?>'>
<input type='hidden' name='school_num' value='<?php echo($school_num) ?>'>
<input type='hidden' name='ordered_by_num' value='<?php echo($ordered_by_num) ?>'>
<input type='hidden' name='schedule_num' value='<?php echo($schedule_num) ?>'>
<input type='hidden' name='show_all' value='<?php echo($show_all) ?>'>
<input type='hidden' name='show_status' value='<?php echo($show_status) ?>'>
<input type='hidden' name='show_source' value='<?php echo($show_source) ?>'>
<input type='hidden' name='show_only' value='<?php echo($show_only) ?>'>
<br>
<br>
</td>
</tr>
</table>
</form>
<?php include "hotlunch_reports.menu.php"; ?>