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

1098 lines
44 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
// Session already started in index.php
// session_name($sessionName);
// session_start();
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("hotlunch.order_details.generate.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOACCESS");
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=order-details&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'];
if (isset($_POST['studentInfo'])) $studentInfo = $_POST['studentInfo'];
if (isset($_POST['studentName'])) $studentName = $_POST['studentName'];
if (isset($_POST['printTotals'])) $printTotals = $_POST['printTotals'];
if (isset($_POST['selectedClasses']) && is_array($_POST['selectedClasses']) && count($_POST['selectedClasses'])) $selectedClasses = $_POST['selectedClasses'];
if (isset($_POST['fontSize'])) $fontSize = $_POST['fontSize'];
$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'];
$with_page_breaks = 'N';
if (array_key_exists('with_page_breaks',$_POST)) $with_page_breaks = $_POST['with_page_breaks'];
if ($_SESSION['UserInfo']['type'] == 'SuperUser') $with_page_breaks = 'Y';
if (!isset($schedule_num)) {
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOSCHED");
exit();
}
if (!isset($menu_num)) {
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOMENU");
exit();
}
// Update defaults
$formFields = array('document_format','report_sort','display_payment_status','display_contact_details','contactInfo','studentInfo','printTotals','fontSize');
for ($i = 0; $i < count($formFields); $i++) {
$fname = $formFields[$i];
$value = isset($_POST[$fname]) ? $_POST[$fname] : '';
db_query("INSERT INTO form_defaults VALUES ($school_num,'order-details','$fname','$value') ON DUPLICATE KEY UPDATE default_value = '$value'");
}
// 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=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=INVALIDSCHED");
exit();
}
$hotlunch_schedule = db_fetch_array($results);
$schedule_name = $hotlunch_schedule['schedule_name'];
$ClassNumField = "class_num";
if ($school_record['implement_meal_locations'] == 'Y' && $hotlunch_schedule['class_sort_field'] == 'D' || $hotlunch_schedule['class_sort_field'] == 'L') {
// Get set of valid meal locations
$locations = array();
$results = db_query("SELECT record_num FROM meal_locations WHERE school_num = $school_num UNION SELECT record_num FROM classes WHERE school_num = $school_num");
while ($row = db_fetch_assoc($results)) {
$locations[] = $row['record_num'];
}
$lnums = implode(',', $locations);
$ClassNumField = "meal_location";
if (strlen($lnums)) {
db_query("UPDATE people SET meal_location = class_num WHERE school_num = $base_school_num AND (meal_location IS NULL OR meal_location NOT IN ($lnums))");
}
else {
db_query("UPDATE people SET meal_location = class_num WHERE school_num = $base_school_num AND meal_location IS NULL)");
}
}
// 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=order-details&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=order-details&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();
$query = "select * from hotlunch_menu_items " .
"where school_num = $school_num " .
"and menu_num = $menu_num " .
"order by sequence";
$results = db_query($query);
$total_orders = 0;
$selected_item_titles = array();
while ($row = db_fetch_array($results)) {
$record_num = $row['record_num'];
if (array_key_exists("item_$record_num", $_POST) && $_POST["item_$record_num"] == 'Y') {
$selected_items[] = $record_num;
$item_title = trim($row['item_title']);
if (!in_array($item_title,$selected_item_titles)) $selected_item_titles[] = trim($row['item_title']);
}
}
if (count($selected_items) == 0) {
header("Location: /?action=order-details&schedule_num=$schedule_num&menu_num=$menu_num&error_code=NOITEMS");
exit();
}
$school_name = $school_record['school_name'];
//
// Orders to print
//
$items = implode(',',$selected_items);
$groupByClass = true;
$order_by = "last_name,first_name";
if (isset($report_sort)) {
switch ($report_sort) {
case 'byClass':
$order_by = "sequence,people_type desc,last_name,first_name";
$item_sequence = "";
$date_field = false;
break;
case 'byGrade':
$order_by = "grade,people_type desc,last_name,first_name";
$item_sequence = "";
$date_field = false;
$groupByClass = false;
break;
case 'byStudent':
$order_by = "last_name,first_name";
$item_sequence = "";
$date_field = false;
$groupByClass = false;
break;
case 'byEnteredDate':
$order_by = "added_date,order_num";
$item_sequence = "";
$date_field = "added_date";
$date_text = getLanguageText('TEXT-ORDER-DATE');
$groupByClass = false;
break;
case 'byPaidDate':
$order_by = "paid_date,order_num";
$item_sequence = "";
$date_field = "paid_date";
$date_text = getLanguageText('TEXT-PAID-DATE');
$groupByClass = false;
break;
case 'byMenuItem':
$order_by = "item_sequence,last_name,first_name";
$item_sequence = ",hlmi.sequence as item_sequence";
$date_field = false;
$groupByClass = false;
break;
}
}
// Setup order status where clause
$oswhere = "and hloh.status not in ('Inactive','Deleted') ";
if ($orderStatus == 'Any') $oswhere = "and hloh.status != 'Deleted' ";
// Get all orders for this menu date
if ($school_record['staff_meals_to_classroom'] != 'N' || $school_record['implement_meal_locations'] == 'Y') {
if ($school_record['delivery_report_staff'] == 'Y') {
$query = "select distinct p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.$ClassNumField AS class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num," .
"p.class_num AS clnum, p.meal_location AS mlnum,hloh.added_date,hloh.paid_date,hloh.status,delivered$item_sequence " .
"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.$ClassNumField = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere .
"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 hloi.active != 'N' " .
"order by $order_by";
}
else {
$query = "select distinct p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.$ClassNumField AS class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num," .
"p.class_num AS clnum, p.meal_location AS mlnum,hloh.added_date,hloh.paid_date,hloh.status,delivered$item_sequence " .
"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.$ClassNumField = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere .
"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 hloi.active != 'N' " .
"order by $order_by";
}
}
else {
if ($school_record['delivery_report_staff'] == 'Y') {
$query = "select distinct 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," .
"p.class_num AS clnum, p.meal_location AS mlnum,hloh.added_date,hloh.paid_date,hloh.status,delivered$item_sequence " .
"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.$ClassNumField = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere .
"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' " .
"UNION " .
"select distinct p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.$ClassNumField AS class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num," .
"p.class_num AS clnum, p.meal_location AS mlnum,hloh.added_date,hloh.paid_date,hloh.status,delivered$item_sequence " .
"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.$ClassNumField = 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 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' " .
"order by $order_by";
}
else {
$query = "select distinct p.people_type,hloi.ordered_by_num,p.first_name,p.last_name,p.label_note,p.$ClassNumField AS class_num,p.user_num,c.division,c.sequence,c.grade,hloi.order_num," .
"p.class_num AS clnum, p.meal_location AS mlnum,hloh.added_date,hloh.paid_date,hloh.status,delivered$item_sequence " .
"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.$ClassNumField = c.record_num left join people as p1 on c.teacher1 = p1.record_num " .
"where hloh.record_num = hloi.order_num " .
$oswhere .
"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' " .
"order by $order_by";
}
}
writeLog($query);
$orders = db_query($query);
// Initialize the PDF document
$document_font = $school_record['document_font'];
if (strlen($document_font) == 0) $document_font = "Helvetica";
$document_font_weight = "";
$document_text_color = "#000000";
$document_font_size = 9;
if (isset($fontSize)) $document_font_size = $fontSize;
$incr = 3.2;
if ($document_font_size > 10) $incr = 4.0;
//
// 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 = $OrderDetailsText;
$font_parm = "";
$additional_info = "";
$class_info = "";
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;
$header_font_size = $document_font_size;
if ($document_font_size > 12) $header_font_size = 12;
// if ($document_format != 'report' && $document_format != 'list') return;
if (!in_array($document_format,array('report','list','page'))) return;
// Print the header
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
$this->SetFont($document_font,"B",$header_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);
$fill = true;
if ($document_format == 'report') $fill = false;
$prev_class_num = -1;
$new_page = true;
$curr_row = $max_rows + 10;
$grand_totals = array();
$totals = array();
$report_title = $school_name . " - " . $schedule_name;
$report_subtitle = $menu_title;
if ($hotlunch_schedule['schedule_type'] == 'Hot Lunch' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive' || $hotlunch_schedule['display_menu_date'] == 'Y') $report_subtitle = "$menu_date - $menu_title";
// Process each record
$page = 0;
$count = 0;
$totalsPrinted = false;
while ($entry = db_fetch_array($orders)) {
extract($entry);
// 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) {
// Print class totals
if ($printTotals == 'Y' && $prev_class_num != -1) {
$numTotals = count($totals) + 1;
if ($curr_row + $incr * $numTotals > $max_rows) {
$pdf->addPage();
$curr_row = $start_row + $incr + 8;
}
$curr_row += $incr;
$pdf->SetXY($left_col,$curr_row);
$pdf->SetFont($document_font,'B',$document_font_size);
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
$text = getLanguageText('TEXT-TOTAL');
if ($groupByClass) $text .= " - $class_info";
$text .= " ($total_orders)";
$pdf->Cell($title_width,$incr + 1,$text,'0',1,'L',true);
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
$curr_row += $incr + 2;
$pdf->SetFont($document_font,'',$document_font_size - 1);
for ($t = 0; $t < count($selected_item_titles); $t++) {
$key = $selected_item_titles[$t];
if ($totals[$key] > 0) {
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr + 1,sprintf("%8d - %s",$totals[$key],$key),'0',1,'L',true);
$curr_row += $incr + 1;
}
}
$total_orders = 0;
$totalsPrinted = true;
}
if (isset($class_num) && is_numeric($class_num)) $class_info = getClassInfo($class_num);
$prev_class_num = $class_num;
$report_subtitle = $menu_title;
if ($hotlunch_schedule['schedule_type'] == 'Hot Lunch' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive' || $hotlunch_schedule['display_menu_date'] == 'Y') $report_subtitle = "$menu_date - $menu_title";
if ($groupByClass) {
$curr_row = $max_rows + 10;
}
$totals = array();
}
$total_orders++;
// 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 ($items) " .
"and hloi.menu_item_num = hlmi.record_num " .
"and hloi.active != 'N' " .
"order by sequence";
$ordered_items = db_query($query);
// Start new page if required
if ($curr_row > ($max_rows - db_num_rows($ordered_items) * $incr)) {
$pdf->addPage();
$curr_row = $start_row + 2;
$new_page = true;
}
// Display titles in report format on each page
if ($new_page && (in_array($document_format,array('report','list','page')))) {
if (count($selected_items) == 1) {
$item_title = db_getVal("SELECT item_title FROM hotlunch_menu_items WHERE school_num = $school_num AND record_num = $items");
$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' || $contactInfo == 'BothNames') {
$name = trim($first_name . ' ' . $last_name);
if (isset($studentName) && $studentName == 'First') $name = $first_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 = $items");
$name .= " (x$qty)";
}
if ($hotlunch_schedule['schedule_type'] != 'Hot Lunch' && in_array($siteType,array('hotlunch','yearbook','tickets','fundraising'))) $name .= " ($delivered)";
if ($school_record['implement_meal_locations'] == 'Y' && $hotlunch_schedule['class_sort_field'] == 'D' || $hotlunch_schedule['class_sort_field'] == 'L') {
if ($clnum > 0 && $clnum != $mlnum) $name = "*** $name ***";
}
// 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 ($studentInfo != 'Name' && (count($selected_items) == 1 || $groupByClass == false)) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= getClassInfo($class_num);
}
// Student number
if ($studentInfo == 'All' && $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 ($studentInfo == 'All' && $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 ($studentInfo == 'All' && $school_record['collect_student_sex'] == 'Y' && strlen($ainfo['sex']) > 0) {
if (strlen($additional_info) > 0) $additional_info .= " / ";
$additional_info .= $ainfo['sex'];
}
// Student age
if ($studentInfo == 'All' && $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 ($studentInfo == 'All' && $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 ($studentInfo == 'All' && ($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 ($studentInfo == 'All' && $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 ($date_field) {
$odate = dateString('shortdate',strtotime($$date_field));
$additional_info .= " ($odate)";
}
if (strlen($additional_info)) {
$width = 100;
$info_col = $left_col + $title_width - $width;
$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);
}
// Customer address info
if ($people_type == 'Customer') {
$results = db_query("SELECT * FROM people WHERE record_num = $ordered_by_num");
$r = db_fetch_assoc($results);
$cust_text = "";
if ($school_record['customer_address'] == 'Y') {
$cust_text .= $r['cust_address'].", ".$r['cust_city'].", ".$r['cust_province']." ".$r['cust_country']." ".$r['cust_postal']." ";
}
if ($school_record['customer_phone'] == 'Y') {
$cust_text .= $r['cust_phone']." ";
}
if ($school_record['customer_email'] == 'Y') {
$cust_text .= $r['cust_email'];
}
if (strlen($cust_text)) {
$curr_row += $incr + 1;
$pdf->SetFont($document_font,"",$document_font_size - 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($line_width,$incr,$cust_text,'0',1,'L',false);
}
}
}
else {
$name = $info[0];
// 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 = $items");
$name .= " (x$qty)";
}
// Print name
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr,$name,'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);
}
// Customer address info
if ($people_type == 'Customer') {
$results = db_query("SELECT * FROM people WHERE record_num = $ordered_by_num");
$r = db_fetch_assoc($results);
$cust_text = "";
if ($school_record['customer_address'] == 'Y') {
$cust_text .= $r['cust_address'].", ".$r['cust_city'].", ".$r['cust_province']." ".$r['cust_country']." ".$r['cust_postal']." ";
}
if ($school_record['customer_phone'] == 'Y') {
$cust_text .= $r['cust_phone']." ";
}
if ($school_record['customer_email'] == 'Y') {
$cust_text .= $r['cust_email'];
}
if (strlen($cust_text)) {
$curr_row += $incr + 1;
$pdf->SetFont($document_font,"",$document_font_size - 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($line_width,$incr,$cust_text,'0',1,'L',false);
}
}
}
// 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);
if ($hotlunch_schedule['schedule_type'] == 'Hot Lunch' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive' || $hotlunch_schedule['display_menu_date'] == 'Y') {
$pdf->Cell($title_width - 100,$incr,"$class_info - $menu_title, $menu_date",'0',1,'R',$fill);
}
else {
$pdf->Cell($title_width - 100,$incr,"$class_info - $menu_title",'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) {
$width = 300;
$info_col = $left_col + $title_width - $width;
$pdf->SetFont($document_font,"",$document_font_size - 2);
$pdf->SetXY($info_col,$curr_row);
if (count($selected_items) > 1) {
if ($hotlunch_schedule['schedule_type'] == 'Hot Lunch' || $hotlunch_schedule['schedule_type'] == 'Date Sensitive' || $hotlunch_schedule['display_menu_date'] == 'Y') {
$pdf->Cell($width,$incr,"$class_info - $menu_title, $menu_date",'0',1,'R',false,'',1);
}
else {
$pdf->Cell($width,$incr,"$class_info - $menu_title",'0',1,'R',false,'',1);
}
}
else $pdf->Cell($width,$incr,"$class_info",'0',1,'R',false,'',1);
}
$curr_row += $incr - 1;
// Print parent contact info if required
if ($contactInfo == 'Both' || $contactInfo == 'BothNames') {
$curr_row += 2;
$contact_info = $info[0];
if ($contactInfo == 'Both') $contact_info = sprintf("%-s %12s - %s",$info[0],$info[1],$info[2]);
if ($class_num == 2) {
$students = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND user_num = $user_num AND record_num != $ordered_by_num");
$n = db_num_rows($students);
$contact_info = "";
while ($r = db_fetch_assoc($students)) {
$c = getClassInfo($r['class_num']);
$contact_info .= " - ".$r['first_name'].' '.$r['last_name']." ($c) ";
}
}
$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;
}
// Display the items
switch ($document_format) {
case 'receipt':
case 'list':
case 'page':
$numItems = db_num_rows($ordered_items);
while ($row = db_fetch_array($ordered_items)) {
extract($row);
$item_title = trim($item_title);
// Calculate the totals
if (array_key_exists($item_title,$totals)) $totals[$item_title] += $qty;
else $totals[$item_title] = $qty;
if (array_key_exists($item_title,$grand_totals)) $grand_totals[$item_title] += $qty;
else $grand_totals[$item_title] = $qty;
// Check for item options
$options = "";
$oordered = "";
$options_ordered = trim($options_ordered);
$options2_ordered = trim($options2_ordered);
$options3_ordered = trim($options3_ordered);
if (strlen($options_ordered)) $oordered = $options_ordered;
if (strlen($options2_ordered)) {
if (strlen($oordered)) $oordered .= "\n";
$oordered .= "$options2_ordered";
}
if (strlen($options3_ordered)) {
if (strlen($oordered)) $oordered .= "\n";
$oordered .= "\n$options3_ordered";
}
$options_ordered = trim($oordered);
if (strlen($oordered) > 0) {
$options = trim(str_replace("\n",", ",trim($oordered)));
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($title_width - 10,$incr,"$item_title $options",'0',1,'L',false,'',1);
}
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($title_width - 10,$incr,$options,'0',1,'L',false,'',1);
$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,"(2) ".$order_header['order_notes2'],'1','L',false);
$curr_row = $pdf->GetY();
}
$curr_row += $incr;
if ($document_format == 'receipt') $curr_row += 20;
if ($document_format == 'page') {
$pdf->addPage();
$curr_row = $start_row + 2;
$new_page = true;
}
break;
case 'report':
$items_ordered = "";
$line = 1;
while ($row = db_fetch_array($ordered_items)) {
extract($row);
// Calculate the totals
if (array_key_exists($item_title,$totals)) $totals[$item_title] += $qty;
else $totals[$item_title] = $qty;
if (array_key_exists($item_title,$grand_totals)) $grand_totals[$item_title] += $qty;
else $grand_totals[$item_title] = $qty;
// Check for item options
$options = "";
$options_ordered = trim($options_ordered);
$options2_ordered = trim($options2_ordered);
$options3_ordered = trim($options3_ordered);
if (strlen($options_ordered)) $options = $options_ordered;
if (strlen($options2_ordered)) {
if (strlen($options)) $options .= "\n";
$options .= $options2_ordered;
}
if (strlen($options3_ordered)) {
if (strlen($options)) $options .= "\n";
$options .= $options3_ordered;
}
if (strlen($options) > 0) {
$options = trim(str_replace("\n",", ",trim($options)));
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;
}
}
// Print class totals
if ($printTotals == 'Y') {
$numTotals = count($totals);
if ($curr_row + $incr * $numTotals > $max_rows) {
$pdf->addPage();
$curr_row = $start_row + 2;
}
$curr_row += $incr;
$pdf->SetXY($left_col,$curr_row);
$pdf->SetFont($document_font,'B',$document_font_size);
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
$text = getLanguageText('TEXT-TOTAL');
if ($groupByClass) $text .= " - $class_info";
$text .= " ($total_orders)";
$pdf->Cell($title_width,$incr,$text,'0',1,'L',true);
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
$curr_row += $incr + 1;
$pdf->SetFont($document_font,'',$document_font_size - 1);
for ($t = 0; $t < count($selected_item_titles); $t++) {
$key = $selected_item_titles[$t];
if (isset($totals[$key]) && $totals[$key] > 0) {
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($title_width,$incr + 1,sprintf("%8d - %s",$totals[$key],$key),'0',1,'L',true);
$curr_row += $incr + 1;
}
}
}
$filename = "order-details.pdf";
if ($siteType == 'registration') $filename = "registration-details.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-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=$filename");
$pdf->Output($filename,"D");
?>