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

115 lines
3.9 KiB
PHP

<?php
$ValidAccess = 2010;
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','Financial','Financial Team');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
include "form.messages.php";
return;
}
// Check for schedule_num
if (!isset($schedule_num)) {
echo("<br>\n");
$error_message = "Invalid access";
include "form.messages.php";
return;
}
// Check if this is a valid schedule
$query = "select * from hotlunch_schedules " .
"where school_num = $school_num " .
"and record_num = $schedule_num";
$results = db_query($query);
if (db_num_rows($results) == 0) {
echo("<br>\n");
$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) {
echo("<br>\n");
$error_message = "You are not allowed access to the requested hot lunch schedule";
include "form.messages.php";
return;
}
}
// Get hot lunch order revenue
$query = "select menu_num,sum(extended_price) as amount from hotlunch_order_items " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and ordered_by_type != 'Concession' " .
"and active != 'N' " .
"AND order_num NOT IN (" .
"SELECT record_num FROM hotlunch_order_header " .
"WHERE school_num = $school_num " .
"AND schedule_num = $schedule_num " .
"AND status IN ('Deleted','Inactive','Complimentary')) " .
"group by 1";
$results = db_query($query);
// Post hot lunch menu date totals
while ($row = db_fetch_array($results)) {
$order_revenue = sprintf("%0.2f",$row['amount']);
$m_num = $row['menu_num'];
// Get other revenue total for this menu date
$query = "select sum(amount) from hotlunch_menu_transactions " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and menu_num = $m_num " .
"and type = 'Revenue'";
$other_revenue = db_getVal($query);
$other_revenue = sprintf("%0.2f",$other_revenue);
// Get supplier costs for this menu date
$supplier_costs = getSupplierCosts($schedule_num,$m_num);
$supplier_costs = sprintf("%0.2f",$supplier_costs);
// Get other expense total for this menu date
$query = "select sum(amount) from hotlunch_menu_transactions " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and menu_num = $m_num " .
"and type = 'Expense'";
$other_costs = db_getVal($query);
$other_costs = sprintf("%0.2f",$other_costs);
// Update hotlunch_menu_dates
$query = "update hotlunch_menu_dates " .
"set order_revenue = $order_revenue, " .
"other_revenue = $other_revenue, " .
"supplier_costs = $supplier_costs, " .
"other_costs = $other_costs, " .
"net_revenue = order_revenue + other_revenue - supplier_costs - other_costs " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and record_num = $m_num";
db_query($query);
}
?>