187 lines
6.0 KiB
PHP
187 lines
6.0 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
|
|
require_once("include/globals.php");
|
|
|
|
// session_name($sessionName);
|
|
// session_start();
|
|
|
|
$action = "menu-details";
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-INVALID-ACCESS');
|
|
header("Location: /?error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
// Check permissions
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Financial','Financial Team');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-INVALID-ACCESS');
|
|
header("Location: /?error_message=" . urlencode($error_message));
|
|
return;
|
|
}
|
|
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
//
|
|
// Get set of schedules
|
|
//
|
|
$query = "SELECT distinct schedule_num FROM hotlunch_menu_dates AS hlmd, hotlunch_schedules AS hls " .
|
|
"WHERE hlmd.school_num = $school_num " .
|
|
"AND hlmd.schedule_num = hls.record_num " .
|
|
"AND hls.status IN ('Active','Completed') " .
|
|
"ORDER BY schedule_num";
|
|
$schedules = db_query($query);
|
|
while ($row = db_fetch_assoc($schedules)) {
|
|
extract($row);
|
|
include "hotlunch_schedule_post.php";
|
|
}
|
|
|
|
|
|
// Initialize the spreadsheet document type
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Cache-Control: private',false);
|
|
header("Content-type: application/octet-stream; charset=utf-8");
|
|
header("Content-Disposition: attachment; filename=annual-summary.csv");
|
|
header('Content-Transfer-Encoding: text');
|
|
|
|
echo("\xEF\xBB\xBF");
|
|
|
|
|
|
|
|
// Initialize totals
|
|
$order_revenue = 0;
|
|
$other_revenue = 0;
|
|
$supplier_costs = 0;
|
|
$other_costs = 0;
|
|
$total_orders = 0;
|
|
$total_revenue = 0;
|
|
|
|
|
|
|
|
//
|
|
// Get set of menu dates
|
|
//
|
|
$query = "SELECT hlmd.* FROM hotlunch_menu_dates AS hlmd, hotlunch_schedules AS hls " .
|
|
"WHERE hlmd.school_num = $school_num " .
|
|
"AND hlmd.schedule_num = hls.record_num " .
|
|
"AND hls.status IN ('Active','Completed') " .
|
|
"ORDER BY menu_date";
|
|
$menu_dates = db_query($query);
|
|
|
|
// Process the menu dates
|
|
if (db_num_rows($menu_dates) > 0) {
|
|
|
|
echo(getLanguageText('TEXT-SCHEDULE').",");
|
|
echo(getLanguageText('TEXT-MENU').",");
|
|
echo(getLanguageText('TEXT-DATE').",");
|
|
echo(getLanguageText('TEXT-ORDERS').",");
|
|
echo(getLanguageText('TEXT-TOTAL-ORDERS').",");
|
|
echo(getLanguageText('TEXT-OTHER-REVENUE').",");
|
|
echo(getLanguageText('TEXT-SUPPLIER-COSTS').",");
|
|
echo(getLanguageText('TEXT-OTHER-COSTS').",");
|
|
echo(getLanguageText('TEXT-TOTAL').",");
|
|
echo("\n");
|
|
|
|
|
|
// Process each menu date
|
|
while ($row = db_fetch_array($menu_dates)) {
|
|
$menu_num = $row['record_num'];
|
|
$schedule_num = $row['schedule_num'];
|
|
$schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE record_num = $schedule_num");
|
|
|
|
$order_count = db_getVal("SELECT count(distinct order_num) FROM hotlunch_order_items " .
|
|
"WHERE school_num = $school_num AND menu_num = $menu_num AND active != 'N'");
|
|
if ($order_count == 0) continue;
|
|
|
|
// Update menu totals
|
|
$query = "SELECT sum(extended_price) AS order_revenue FROM hotlunch_order_items " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND schedule_num = $schedule_num " .
|
|
"AND menu_num = $menu_num " .
|
|
"and active = 'Y'";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results)) {
|
|
$r = db_fetch_assoc($results);
|
|
$menu_order_revenue = floatval($r['order_revenue']);
|
|
$total_revenue += $menu_order_revenue;
|
|
|
|
db_query("UPDATE hotlunch_menu_dates SET order_revenue = $menu_order_revenue WHERE record_num = $menu_num");
|
|
}
|
|
|
|
// Check for orders for this menu
|
|
$numItems = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND menu_num = $menu_num");
|
|
if ($numItems == 0 && $menu_order_revenue == 0 && $row['other_revenue'] == 0 && $row['other_costs'] == 0) continue;
|
|
|
|
echo('"'.$schedule_name.'",');
|
|
echo('"'.$row['menu_title'].'",');
|
|
// echo(date("M jS Y",strtotime($row['menu_date'])).",");
|
|
echo('"'.$row['menu_date'].'",');
|
|
|
|
$total_orders += $order_count;
|
|
echo($order_count.",");
|
|
|
|
|
|
// Calculate totals for menu date
|
|
$order_revenue += $menu_order_revenue;
|
|
$other_revenue += $row['other_revenue'];
|
|
$other_costs += $row['other_costs'];
|
|
|
|
$amount = $currencySymbol . number_format($menu_order_revenue,2);
|
|
echo("\"$amount\",");
|
|
|
|
$amount = $currencySymbol . number_format($row['other_revenue'],2);
|
|
echo("\"$amount\",");
|
|
|
|
// Get costs
|
|
if ($row['supplier_costs'] > 0) $cost = $row['supplier_costs'];
|
|
else $cost = getSupplierCosts($schedule_num,$menu_num);
|
|
$supplier_costs += $cost;
|
|
$amount = $currencySymbol . number_format($cost,2);
|
|
echo("\"$amount\",");
|
|
|
|
$amount = $currencySymbol . number_format($row['other_costs'],2);
|
|
echo("\"$amount\",");
|
|
|
|
$total = $menu_order_revenue + $row['other_revenue'] - $cost - $row['other_costs'];
|
|
$amount = $currencySymbol . number_format($total,2);
|
|
echo("\"$amount\",");
|
|
|
|
echo("\n");
|
|
}
|
|
}
|
|
|
|
// Print totals
|
|
echo(getLanguageText('TEXT-TOTALS')."::,,,");
|
|
|
|
echo($total_orders.",");
|
|
|
|
$amount = $currencySymbol . number_format($order_revenue,2);
|
|
echo("\"$amount\",");
|
|
|
|
$amount = $currencySymbol . number_format($other_revenue,2);
|
|
echo("\"$amount\",");
|
|
|
|
$amount = $currencySymbol . number_format($supplier_costs,2);
|
|
echo("\"$amount\",");
|
|
|
|
$amount = $currencySymbol . number_format($other_costs,2);
|
|
echo("\"$amount\",");
|
|
|
|
$amount = $currencySymbol . number_format($order_revenue + $other_revenue - $supplier_costs - $other_costs,2);
|
|
echo("\"$amount\",");
|
|
|
|
?>
|