Files
HotLunches/hotlunch_orders.list.notes.csv.php
T
2026-10-19 15:22:52 -07:00

193 lines
6.6 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
// Guarded session handling to avoid warnings and align with other modules
if (session_status() === PHP_SESSION_NONE) {
if (!empty($sessionName)) {
session_name($sessionName);
}
session_start();
}
$action = "menu-details";
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
header("Location: /?action=$action&error_code=NOACCESS");
exit();
}
// Check permissions
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team');
if (checkPermission($AllowedUserTypes) != 1) {
header("Location: /?action=$action&error_code=NOACCESS");
exit();
}
// Get parameters to script
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
// if (array_key_exists('show',$_GET)) $show = $_GET['show'];
if (!isset($schedule_num)) {
header("Location: /?action=$action&error_code=NOACCESS");
exit();
}
// Verify the schedule_num is a valid and active schedule
$swhere = "";
if ($_SESSION['UserInfo']['type'] == 'Supplier') $swhere = " and supplier_num = " . $_SESSION['UserInfo']['supplier_num'];
$today = date("Y-m-d",time());
$query = "select * from hotlunch_schedules " .
"where school_num = $school_num " .
"and record_num = $schedule_num " .
"$swhere";
$results = db_query($query);
if (db_num_rows($results) == 0) {
header("Location: /?action=$action&error_code=INVALIDSCHED");
exit();
}
$schedule = db_fetch_array($results);
$schedule_name = $schedule['schedule_name'];
// 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 = intval($_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) {
header("Location: /?action=$action&error_code=NOACCESS");
exit();
}
}
//
$school_name = $school_record['school_name'];
$document_name = getLanguageText('TEXT-ORDERS-SUMMARY');
// Set the status condition if required
$ReportTitle = getLanguageText('TEXT-ORDERS-SUMMARY') . " - (" . $GlobalText['Student'] . ") - $schedule_name";
$orderby = "ORDER BY last_name, first_name";
// $pwhere = "AND p.people_type = 'Student' ";
// if (isset($show) && $show == "All") $pwhere = "";
unset($delivered);
if (array_key_exists('delivered',$_GET) && strlen($_GET['delivered'])) $delivered = $_GET['delivered'];
if (array_key_exists('delivered',$_POST) && strlen($_POST['delivered'])) $delivered = $_POST['delivered'];
$dwhere = "";
if (isset($delivered)) {
$dwhere = "AND delivered = '$delivered' ";
if ($delivered == 'Y') $ReportTitle .= " - " . getLanguageText('TEXT-DELIVERED');
else $ReportTitle .= " - " . getLanguageText('TEXT-NOT-DELIVERED');
}
// Get orders for this schedule
if (!isset($pwhere)) $pwhere = '';
if (!isset($dwhere)) $dwhere = '';
$query = "SELECT p.last_name,p.first_name,class_num,sequence,people_type,hloh.source,hloh.order_total,hloh.status,p.user_num,hloh.record_num,userid," .
"hloh.payment_method,hloh.added_date,sum(ua.transaction_amount) as balance,delivered,hloh.order_notes,hloh.order_notes2 " .
"FROM people AS p LEFT JOIN classes AS c ON p.class_num = c.record_num, hotlunch_order_header AS hloh, " .
"users AS u LEFT JOIN user_account AS ua ON ua.school_num = $school_num AND ua.user_num = u.record_num AND (ua.deleted != 'Y' OR ua.deleted IS NULL) " .
"WHERE p.school_num = $base_school_num " .
"AND hloh.school_num = $school_num " .
"AND hloh.status NOT IN ('Inactive','Deleted') " .
"AND p.record_num = hloh.ordered_by_num " .
$pwhere .
$dwhere .
"AND hloh.schedule_num = $schedule_num " .
"AND p.user_num = u.record_num " .
"GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,15 " .
$orderby;
$results = db_query($query);
if (db_num_rows($results) == 0) {
header("Location: /?error_code=NOORDERS");
exit();
}
$column_headers = array(getLanguageText('TEXT-NAME'),
getLanguageText('TEXT-TYPE'),
getLanguageText('TEXT-ORDER'),
getLanguageText('TEXT-ORDER-DATE'),
getLanguageText('TEXT-SOURCE'),
getLanguageText('TEXT-STATUS'),
getLanguageText('TEXT-ACCOUNT'),
getLanguageText('TEXT-PHONE'),
getLanguageText('TEXT-EMAIL'),
);
$data = array();
$total = 0;
// Process all the orders found for this page
while ($row = db_fetch_array($results)) {
$entry = array();
$name = $row['last_name'] . ', ' . $row['first_name'];
$entry[] = $name;
$entry[] = $row['people_type'];
$entry[] = $school_record['currency_symbol'] . number_format($row['order_total'],2);
$total += $row['order_total'];
$entry[] = dateString('date',strtotime($row['added_date']));
$entry[] = $row['source'];
$dtext = "";
if ($schedule['schedule_type'] != 'Hot Lunch' && in_array($siteType,array('hotlunch','yearbook','tickets','fundraising'))) $dtext = " (" . $row['delivered'] . ")";
$entry[] = $row['status'].' - '.$row['payment_method'] . $dtext;
// Get the name on this account
$unum = $row['user_num'];
$r = db_query("select concat(first_name,' ',last_name) AS account, email, home_phone from users where school_num = $base_school_num and record_num = $unum");
$ur = db_fetch_assoc($r);
$entry[] = $ur['account'];
$entry[] = $ur['home_phone'];
$entry[] = $ur['email'];
$order_notes = trim($row['order_notes']);
if ($schedule['implement_order_notes'] == 'Y') {
if (strlen($order_notes)) $entry[] = str_replace("\n"," ",$order_notes);
else $entry[] = '';
}
$order_notes = trim($row['order_notes2']);
if ($schedule['implement_order_notes2'] == 'Y') {
if (strlen($order_notes)) $entry[] = str_replace("\n"," ",$order_notes);
else $entry[] = '';
}
$data[] = $entry;
}
$data[] = array('','',$school_record['currency_symbol'] . number_format($total,2));
// Output the XLS data
$fname = genFileName("all-orders.csv");
xlsData($data,$column_headers,$fname);
return;
?>