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

850 lines
34 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
// Safely set session name and start only if no session is active
if (function_exists('session_status')) {
if (session_status() === PHP_SESSION_NONE) {
if (!empty($sessionName) && session_name() !== $sessionName) {
session_name($sessionName);
}
session_start();
}
} else {
// Fallback for older PHP versions
if (session_id() === '') {
if (!empty($sessionName) && session_name() !== $sessionName) {
session_name($sessionName);
}
session_start();
}
}
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
header("Location: /");
exit();
}
// Check permissions
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team','Schedule Reporting');
if (checkPermission($AllowedUserTypes) != 1) {
header("Location: /?action=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
exit();
}
//
// Get and validate the parameters
//
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
if (array_key_exists('menu_num',$_POST)) $menu_num = intval($_POST['menu_num']);
if (array_key_exists('document_format',$_POST)) $document_format = $_POST['document_format'];
if (array_key_exists('report_sort',$_POST)) $report_sort = $_POST['report_sort'];
if (array_key_exists('display_payment_status',$_POST)) $display_payment_status = $_POST['display_payment_status'];
if (array_key_exists('display_contact_details',$_POST)) $display_contact_details = $_POST['display_contact_details'];
if (isset($_POST['contactInfo'])) $contactInfo = $_POST['contactInfo'];
$orderStatus = 'Active';
if (isset($_POST['orderStatus'])) $orderStatus = $_POST['orderStatus'];
$display_user_data = 'Y';
if (array_key_exists('display_user_data',$_POST)) $display_user_data = $_POST['display_user_data'];
if (!isset($schedule_num)) {
header("Location: /?action=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOSCHED");
exit();
}
if (!isset($menu_num)) {
header("Location: /?action=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOMENU");
exit();
}
// 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) {
header("Location: /?action=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDSCHED");
exit();
}
$hotlunch_schedule = db_fetch_array($results);
$schedule_name = $hotlunch_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 = $_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=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
exit();
}
}
// Check if this is a valid menu
$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) {
header("Location: /?action=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDMENU");
exit();
}
$hotlunch_menu_date = db_fetch_array($results);
$menu_title = $hotlunch_menu_date['menu_title'];
$menu_date = date("D M j Y",strtotime($hotlunch_menu_date['menu_date']));
// Determine which items have been selected
$selected_items = array();
$required_items = array();
$excluded_items = array();
$query = "select * from hotlunch_menu_items " .
"where school_num = $school_num " .
"and menu_num = $menu_num " .
"order by sequence";
$results = db_query($query);
while ($row = db_fetch_array($results)) {
$record_num = $row['record_num'];
if (array_key_exists("item_$record_num", $_POST)) {
if ($_POST["item_$record_num"] == 'Required' || $_POST["item_$record_num"] == 'Display') $selected_items[] = $record_num;
if ($_POST["item_$record_num"] == 'Required') $required_items[] = $record_num;
if ($_POST["item_$record_num"] == 'Exclude') $excluded_items[] = $record_num;
}
}
if (count($required_items) == 0) {
header("Location: /?action=item-report&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOITEMS");
exit();
}
$school_name = $school_record['school_name'];
//
// Orders to print
//
$sitems = implode(',',$selected_items);
$items = implode(',',$required_items);
$xitems = implode(',',$excluded_items);
$required = implode(',',$required_items);
$required_count = count($required_items);
if (isset($report_sort)) {
switch ($report_sort) {
case 'byClass':
$order_by = "sequence,people_type desc,last_name,first_name";
$item_sequence = "";
$groupby = "group by 1,2,3,4,5,6,7,8,9,10,11,12 ";
$groupByClass = true;
break;
case 'byGrade':
$order_by = "grade,people_type desc,last_name,first_name";
$item_sequence = "";
$groupby = "group by 1,2,3,4,5,6,7,8,9,10,11,12 ";
$groupByClass = false;
break;
case 'byStudent':
$order_by = "last_name,first_name";
$item_sequence = "";
$groupby = "group by 1,2,3,4,5,6,7,8,9,10,11,12 ";
$groupByClass = false;
break;
case 'byMenuItem':
$order_by = "item_sequence,last_name,first_name";
$item_sequence = ",hlmi.sequence as item_sequence";
$groupby = "group by 1,2,3,4,5,6,7,8,9,10,11,12,13 ";
$groupByClass = false;
break;
}
}
// Setup order status where clause
$oswhere = "and hloh.status not in ('Inactive','Deleted') ";
if ($orderStatus == 'Any') $oswhere = "and hloh.status != 'Deleted' ";
$xwhere = "";
if (count($excluded_items)) $xwhere = "AND hloh.record_num NOT IN (" .
"SELECT order_num FROM hotlunch_order_items " .
"WHERE school_num = $school_num AND schedule_num = $schedule_num AND menu_num = $menu_num and menu_item_num IN ($xitems)) ";
// Get all orders for this menu date
if ($school_record['staff_meals_to_classroom'] != 'N') {
if ($school_record['delivery_report_staff'] == 'Y') {
$query = "select p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num,hloh.status$item_sequence,count(hloi.menu_item_num) " .
"from hotlunch_order_header as hloh, hotlunch_order_items as hloi, hotlunch_menu_items as hlmi, " .
"people as p left join classes as c on c.school_num = $base_school_num and p.class_num = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere . $xwhere .
"and hloi.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num > 0 " .
"and hloi.school_num = $school_num " .
"and hlmi.school_num = $school_num " .
"and p.school_num = $base_school_num " .
"and p.status != 'Inactive' " .
"and hloi.menu_item_num in ($items) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and hloi.active != 'N' " .
$groupby .
"having count(hloi.menu_item_num) = $required_count " .
"order by $order_by";
}
else {
$query = "select p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num,hloh.status$item_sequence,count(hloi.menu_item_num) " .
"from hotlunch_order_header as hloh, hotlunch_order_items as hloi, hotlunch_menu_items as hlmi, " .
"people as p left join classes as c on c.school_num = $base_school_num and p.class_num = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere . $xwhere .
"and hloi.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num > 0 " .
"and hloi.school_num = $school_num " .
"and hlmi.school_num = $school_num " .
"and p.school_num = $base_school_num " .
"and p.status != 'Inactive' " .
"and hloi.menu_item_num in ($items) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and hloi.active != 'N' " .
$groupby .
"having count(hloi.menu_item_num) = $required_count " .
"order by $order_by";
}
}
else {
if ($school_record['delivery_report_staff'] == 'Y') {
$query = "select p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,0 as class_num,p.user_num,0 as division,0 as sequence,0 as grade,hloi.order_num,hloh.status$item_sequence,count(hloi.menu_item_num) " .
"from hotlunch_order_header as hloh, hotlunch_order_items as hloi, hotlunch_menu_items as hlmi, " .
"people as p left join classes as c on c.school_num = $base_school_num and p.class_num = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere . $xwhere .
"and hloi.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num > 0 " .
"and hloi.school_num = $school_num " .
"and hlmi.school_num = $school_num " .
"and p.school_num = $base_school_num " .
"and p.status != 'Inactive' " .
"and hloi.menu_item_num in ($items) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and p.people_type = 'Staff' " .
"and hloi.active != 'N' " .
$groupby .
"having count(hloi.menu_item_num) = $required_count " .
"UNION " .
"select p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num,hloh.status$item_sequence,count(hloi.menu_item_num) " .
"from hotlunch_order_header as hloh, hotlunch_order_items as hloi, hotlunch_menu_items as hlmi, " .
"people as p left join classes as c on c.school_num = $base_school_num and p.class_num = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
"and hloh.status not in ('Inactive','Deleted') " .
"and hloi.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num > 0 " .
"and hloi.school_num = $school_num " .
"and hlmi.school_num = $school_num " .
"and p.school_num = $base_school_num " .
"and p.status != 'Inactive' " .
"and hloi.menu_item_num in ($items) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and p.people_type != 'Staff' " .
"and hloi.active != 'N' " .
$groupby .
"having count(hloi.menu_item_num) = $required_count " .
"order by $order_by";
}
else {
$query = "select p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num,hloh.status$item_sequence,count(hloi.menu_item_num) " .
"from hotlunch_order_header as hloh, hotlunch_order_items as hloi, hotlunch_menu_items as hlmi, " .
"people as p left join classes as c on c.school_num = $base_school_num and p.class_num = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere . $xwhere .
"and hloi.ordered_by_num = p.record_num " .
"and hloh.ordered_by_num = p.record_num " .
"and hloi.school_num = $school_num " .
"and hlmi.school_num = $school_num " .
"and p.school_num = $base_school_num " .
"and p.status != 'Inactive' " .
"and hloi.menu_item_num in ($items) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and p.people_type != 'Staff' " .
"and hloi.active != 'N' " .
$groupby .
"having count(hloi.menu_item_num) = $required_count " .
"order by $order_by";
}
}
$orders = db_query($query);
// Initialize the PDF document
$document_font = "Helvetica";
$document_font_weight = "";
$document_text_color = "#000000";
$document_font_size = 9;
$incr = 2.8;
//
// Setup PDF document
//
require("tcpdf/config/lang/eng.php");
require("tcpdf/tcpdf.php");
// Set parameters for this document
$start_row = 8;
$title_width = 190;
$status_width = $title_width - 30;
$item_width = $title_width - 100;
$max_rows = 230;
$curr_row = $start_row;
$left_col = 12;
$qty_col = 20;
$item_col = 25;
$items_col = 25;
$notes_col = 40;
$max_line_length = 5;
$notes_width = 150;
$logo_url = $school_record['logo_url'];
$logo_image = "images/" . $school_record['logo_image'];
$logo_row = 250;
$document_name = getLanguageText('TEXT-ITEM-DETAILS-REPORT');
class PDF extends TCPDF {
function Header() {
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $document_format, $groupByClass, $class_info;
if ($document_format != 'report' && $document_format != 'list') return;
// Print the header
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
$this->SetFont($document_font,"B",$document_font_size + 1);
$this->SetXY($left_col,$start_row);
$this->Cell($title_width,$incr + 1," $report_title",'0',1,'L',true,'',1);
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
$offset = 100;
$this->SetXY($left_col + $offset,$start_row);
$this->Cell($title_width - $offset,$incr + 1,"$report_subtitle ",'0',1,'R',true,'',1);
}
if ($groupByClass) {
$this->SetXY($left_col,$start_row + $incr + 3);
$this->Cell($title_width,$incr + 1,$class_info,'0',1,'L',true,'',1);
}
}
function Footer() {
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $document_format, $school_name;
if ($document_format == 'receipt') return;
// Print the date
$this->SetFont($document_font,"",$document_font_size - 1);
$this->SetXY($left_col,$logo_row);
$date = dateString('datetime');
$this->Cell($title_width,$incr - 1,"$document_name: $date",'0',1,'R');
$this->SetXY($left_col,$logo_row + $incr);
$this->Cell($title_width,$incr - 1,"$school_name",'0',1,'R','',1);
$this->Image($logo_image,10,$logo_row, 50);
$this->SetXY(20,$logo_row + 9);
$this->SetFont($document_font,"B",$document_font_size);
$this->Cell($title_width,$incr,$logo_url,'0',1,'L');
}
}
// Force exact physical size for Letter: 8.5 x 11 inches => 215.9mm x 279.4mm (portrait)
$pageFormat = array(215.9, 279.4);
$pdf= new PDF('P', 'mm', $pageFormat, true, 'UTF-8', false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$font_red = hexdec("00");
$font_green = hexdec("00");
$font_blue = hexdec("00");
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
$pdf->SetTextColor($font_red,$font_green,$font_blue);
$pdf->SetFont($document_font,"",$document_font_size);
// Ensure font style parameter is defined to avoid warnings
$font_parm = "";
$fill = true;
if ($document_format == 'report') $fill = false;
$prev_class_num = -1;
$new_page = true;
$curr_row = $max_rows + 10;
$report_title = $school_name . " - " . $schedule_name;
$report_subtitle = "";
$report_subtitle = "$menu_date - $menu_title";
// Process each record
$page = 0;
$count = 0;
while ($entry = db_fetch_array($orders)) {
extract($entry);
// Check that all required elements have been ordered
// Get order header record
$results = db_query("SELECT * FROM hotlunch_order_header WHERE school_num = $school_num AND record_num = $order_num");
$order_header = db_fetch_assoc($results);
if ($groupByClass && $class_num != $prev_class_num) {
$class_info = $people_type;
if (isset($class_num) && is_numeric($class_num) && $class_num > 0) $class_info = getClassInfo($class_num);
$prev_class_num = $class_num;
$report_subtitle = "$menu_date - $menu_title";
if ($groupByClass) {
$curr_row = $max_rows + 10;
}
$totals = array();
}
// Start new page if required
if ($curr_row > ($max_rows - count($selected_items) * $incr)) {
$pdf->addPage();
$curr_row = $start_row + 2;
$new_page = true;
}
// Display titles in report format on each page
if ($new_page && ($document_format == 'report' || $document_format == 'list')) {
if (count($selected_items) == 1) {
$item_title = db_getVal("SELECT item_title FROM hotlunch_menu_items WHERE school_num = $school_num AND record_num = $sitems");
$curr_row += $incr + 1;
if (strlen($report_subtitle)) $curr_row += 4;
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
$pdf->SetFont($document_font,'B',$document_font_size + 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr + 2,$item_title,'0',1,'L',true);
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
}
$new_page = false;
$curr_row += $incr + 8;
}
// Display ordered by name
$pdf->SetFont($document_font,$font_parm,$document_font_size);
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
$fill = true;
if (count($selected_items) == 1) {
$fill = true;
$count++;
}
// Get parent contact info if required
$info = getContactInfo($user_num);
$user_record = $info[3];
if ($contactInfo == 'Student' || $contactInfo == 'Both') {
$name = trim($first_name . ' ' . $last_name);
if ($people_type == 'Staff') $name .= " (Staff)";
if ($orderStatus == 'Any') $name .= " - " . $status;
$linked_to_student = db_getVal("SELECT linked_to_student FROM users WHERE school_num = $base_school_num AND record_num = $user_num");
if (strlen($linked_to_student)) $name .= " ($linked_to_student)";
// Get order status
if ($display_payment_status == 'Y') {
$order_status = $order_header['status'];
$order_total = $currencySymbol . $order_header['order_total'];
$name .= " - $order_status ($order_total)";
}
// Include quantity if required
if (count($selected_items) == 1) {
$qty = db_getVal("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_item_num = $sitems");
if ($qty > 1) $name .= " (x$qty)";
}
// Print name
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr,$name,'0',1,'L',$fill);
// Print additional info if required
$additional_info = "";
if (strlen($label_note)) $additional_info = $label_note;
$results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND record_num = $ordered_by_num");
$ainfo = db_fetch_array($results);
// Include class info if only one item has been selected
if (count($selected_items) == 1 || $groupByClass == false) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= getClassInfo($class_num);
}
// Student number
if ($school_record['collect_student_number'] == 'Y' && strlen($ainfo['student_number']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= getLanguageText('TEXT-STUDENT-NUMBER') . ": " . $ainfo['student_number'];
}
// Student birthdate
if ($school_record['collect_student_birthdate'] == 'Y' && strlen($ainfo['birthdate']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= getLanguageText('TEXT-BIRTH-DATE') . ": " . date($school_record['date_format'],strtotime($ainfo['birthdate']));
}
// Student sex
if ($school_record['collect_student_sex'] == 'Y' && strlen($ainfo['sex']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= $ainfo['sex'];
}
// Student age
if ($school_record['collect_student_age'] == 'Y' && strlen($ainfo['age']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= getLanguageText('TEXT-AGE') . ": " . $ainfo['age'];
}
// Student grade
if ($school_record['collect_student_grade'] == 'Y' && strlen($ainfo['school_grade']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= getLanguageText('TEXT-GRADE') . ": " . $ainfo['school_grade'];
}
// Student permission
if (($school_record['collect_permission'] == 'Y' || $school_record['collect_permission'] == 'W') && strlen($ainfo['additional_permission']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= $school_record['permission_prompt'] . ": " . $ainfo['additional_permission'];
if (strlen($ainfo['additional_permission_note'])) $additional_info .= " - " . $ainfo['additional_permission_note'];
}
// User Defined Data
if ($school_record['user_defined_values'] == 'Y' && strlen($school_record['user_defined_title']) > 0 && strlen($ainfo['user_defined_value'])) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= $school_record['user_defined_title'] . ": " . $ainfo['user_defined_value'];
}
if (strlen($additional_info)) {
$width = 50;
$info_col = $left_col + $title_width - $width;
// $curr_row += $incr;
$pdf->SetXY($info_col,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->Cell($width,$incr,$additional_info,'0',1,'R',false,'',1);
$pdf->SetFont($document_font,"",$document_font_size);
}
}
else {
// Print name
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr,$info[0],'0',1,'L',$fill);
// Print phone & email
$pdf->SetXY($left_col + 80,$curr_row);
$pdf->Cell($title_width - 80,$incr,$info[1] . ' - ' . $info[2],'0',1,'L',$fill);
if (isset($display_contact_details) && $display_contact_details == 'Y') {
$pdf->SetFont($document_font,"",$document_font_size - 1);
$address = $user_record['address'] . ", " . $user_record['city'] . " " . $user_record['province'] . " " . $user_record['postal'];
$curr_row += $incr + 1;
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr," ",'0',1,'L',$fill);
$pdf->SetXY($left_col + 80,$curr_row);
$pdf->Cell($title_width - 80,$incr,$address,'0',1,'L',$fill);
$pdf->SetFont($document_font,"",$document_font_size);
}
}
// Receipt format will be cut so print class and meal info
if ($document_format == 'receipt') {
$pdf->SetFont($document_font,"",$document_font_size - 1);
$pdf->SetXY($left_col + 100,$curr_row);
$pdf->Cell($title_width - 100,$incr,"$class_info - $menu_title, $menu_date",'0',1,'R',$fill);
}
// If not grouped by class include the class info
if (strlen($additional_info) == 0 && $contactInfo != 'Parent' && $document_format != 'receipt' && $document_format != 'report' && $groupByClass == false) {
$pdf->SetFont($document_font,"",$document_font_size - 1);
$pdf->SetXY($left_col + 100,$curr_row);
if (count($selected_items) > 1) $pdf->Cell($title_width - 100,$incr,"$class_info - $menu_title, $menu_date",'0',1,'R',false);
else $pdf->Cell($title_width - 100,$incr,"$class_info",'0',1,'R',false);
}
$curr_row += $incr - 1;
// Print parent contact info if required
if ($contactInfo == 'Both') {
$curr_row += 1;
$contact_info = sprintf("%-s %12s - %s",$info[0],$info[1],$info[2]);
$curr_row += 1;
$pdf->SetXY($left_col,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->Cell($title_width,$incr,$contact_info,'0',1,'R',$fill);
if (isset($display_contact_details) && $display_contact_details == 'Y') {
$pdf->SetFont($document_font,"",$document_font_size - 1);
$address = $user_record['address'] . ", " . $user_record['city'] . " " . $user_record['province'] . " " . $user_record['postal'];
$curr_row += $incr;
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr,$address,'0',1,'R',$fill);
$pdf->SetFont($document_font,"",$document_font_size);
}
$pdf->SetFont($document_font,"",$document_font_size);
$curr_row += $incr;
}
// Print Additional Data
if ($display_user_data == 'Y' && strlen(trim($school_record['additional_registration_data_field1'])) > 0) {
$curr_row += 2;
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr,' ','0',1,'L',$fill);
$pdf->SetXY($left_col + 40,$curr_row);
$pdf->Cell($title_width - 80,$incr,trim($school_record['additional_registration_data_field1']) . ": " . $info[3]['additional1'],'0',1,'L',$fill);
$pdf->SetFont($document_font,"",$document_font_size);
$curr_row += $incr;
}
if ($display_user_data == 'Y' && strlen(trim($school_record['additional_registration_data_field2'])) > 0) {
$pdf->SetFont($document_font,"",$document_font_size - 3);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr,' ','0',1,'L',$fill);
$pdf->SetXY($left_col + 40,$curr_row);
$pdf->Cell($title_width - 80,$incr,trim($school_record['additional_registration_data_field2']) . ": " . $info[3]['additional2'],'0',1,'L',$fill);
$pdf->SetFont($document_font,"",$document_font_size);
$curr_row += $incr;
}
if ($people_type != 'Staff' && $document_format == 'report' && !$groupByClass) {
$curr_row += $incr;
$pdf->SetXY($left_col + 40,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 3);
$pdf->Cell($title_width,$incr,"- $class_info",'0',1,'L',$fill);
$pdf->SetFont($document_font,"",$document_font_size);
$curr_row += $incr;
}
// Get order items for this order
$query = "select hloi.*,hlmi.item_title,hlmi.sequence from hotlunch_order_items as hloi, hotlunch_menu_items as hlmi " .
"where hloi.school_num = $school_num " .
"and hlmi.school_num = $school_num " .
"and hloi.menu_num = $menu_num " .
"and hloi.order_num = $order_num " .
"and hloi.menu_item_num in ($sitems) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and hloi.active != 'N' " .
"order by sequence";
$ordered_items = db_query($query);
// Display the items
switch ($document_format) {
case 'receipt':
case 'list':
$numItems = db_num_rows($ordered_items);
while ($row = db_fetch_array($ordered_items)) {
extract($row);
// Check for item options
$options = "";
$options_ordered = trim($options_ordered);
$options2_ordered = trim($options2_ordered);
$options3_ordered = trim($options3_ordered);
if (strlen($options2_ordered)) $options_ordered .= "\n$options2_ordered";
if (strlen($options3_ordered)) $options_ordered .= "\n$options3_ordered";
if (strlen($options_ordered) > 0) {
$options = trim(str_replace("\n",", ",trim($options_ordered)));
if (strlen($options) > 0) $options = " ($options)";
}
// Display selected items
if (count($selected_items) > 1) {
$curr_row += $incr;
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(5,$incr,$qty,'0',1,'R',false);
// Print item title and options
if (strlen("$item_title $options") < $max_line_length) {
$pdf->SetXY($item_col,$curr_row);
$pdf->Cell($item_width,$incr,"$item_title $options",'0',1,'L',false);
}
else {
$pdf->SetXY($item_col,$curr_row);
$pdf->Cell($item_width,$incr,$item_title,'0',1,'L',false);
if (strlen($options)) {
$pdf->SetFont($document_font,"",$document_font_size - 1);
$curr_row += $incr;
$pdf->SetXY($item_col,$curr_row);
$pdf->Cell($item_width,$incr,$options,'0',1,'L',false);
$pdf->SetFont($document_font,"",$document_font_size);
}
}
}
else {
if (strlen($options)) {
$pdf->SetFont($document_font,"",$document_font_size - 1);
$curr_row += $incr;
$pdf->SetXY($item_col,$curr_row);
$pdf->Cell($item_width,$incr,$options,'0',1,'L',false);
$pdf->SetFont($document_font,"",$document_font_size);
}
}
}
if (count($selected_items) > 1 || strlen($options)) $curr_row += $incr;
// Order notes
if (strlen($order_header['order_notes'])) {
$curr_row += $incr;
$pdf->SetXY($notes_col,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->MultiCell($notes_width,$incr,$order_header['order_notes'],'1','L',false);
$curr_row = $pdf->GetY();
}
if (strlen($order_header['order_notes2'])) {
$curr_row += $incr;
$pdf->SetXY($notes_col,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->MultiCell($notes_width,$incr,$order_header['order_notes2'],'1','L',false);
$curr_row = $pdf->GetY();
}
$curr_row += $incr;
if ($document_format == 'receipt') $curr_row += 20;
break;
case 'report':
$items_ordered = "";
$line = 1;
while ($row = db_fetch_array($ordered_items)) {
extract($row);
// Check for item options
$options = "";
$options_ordered = trim($options_ordered);
$options2_ordered = trim($options2_ordered);
$options3_ordered = trim($options3_ordered);
if (strlen($options2_ordered)) $options_ordered .= "\n$options2_ordered";
if (strlen($options3_ordered)) $options_ordered .= "\n$options3_ordered";
if (strlen($options_ordered) > 0) {
$options = trim(str_replace("\n",", ",trim($options_ordered)));
if (strlen($options) > 0) $options = " ($options)";
}
if (strlen($items_ordered) > 0) {
if ((strlen($items_ordered) + strlen("$item_title $options")) > (140 * $line)) {
$items_ordered .= "\n";
$line++;
}
else {
$items_ordered .= " // ";
}
}
if ($qty > 1) $items_ordered .= "$qty x ";
$items_ordered .= "$item_title $options";
}
$curr_row += $incr;
$pdf->SetFont($document_font,$font_parm,$document_font_size - 1);
$pdf->SetXY($items_col,$curr_row);
$pdf->MultiCell(0,$incr,$items_ordered,'0','L',false);
$pdf->SetFont($document_font,$font_parm,$document_font_size);
$curr_row = $pdf->GetY();
// Order notes
if (strlen($order_header['order_notes'])) {
$pdf->SetXY($notes_col,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->MultiCell($notes_width,$incr,$order_header['order_notes'],'1','L',false);
$curr_row = $pdf->GetY();
}
if (strlen($order_header['order_notes2'])) {
if (strlen($order_header['order_notes'])) $curr_row += $incr;
$pdf->SetXY($notes_col,$curr_row);
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->MultiCell($notes_width,$incr,$order_header['order_notes2'],'1','L',false);
$curr_row = $pdf->GetY();
}
$curr_row += $incr - 2;
break;
}
}
$filename = "item-report.pdf";
if ($siteType == 'registration') $filename = "registration-items.pdf";
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/pdf');
header("Content-Disposition: attachment; filename=$filename");
header('Content-Transfer-Encoding: binary');
$pdf->Output($filename,"D");
?>