1154 lines
42 KiB
PHP
1154 lines
42 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
|
|
require_once("include/globals.php");
|
|
|
|
$action = "menu-details";
|
|
|
|
$now = date("Y-m-d H:i:s",time());
|
|
|
|
$moduleName = "hotlunch_menu_details.print.php";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog($moduleName);
|
|
// if ($school_num == 20158) startLog($moduleName);
|
|
// startLog($moduleName);
|
|
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
$action = "";
|
|
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','Staff','Schedule Reporting');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$action = "";
|
|
header("Location: /?action=$action&error_code=NOACCESS");
|
|
return;
|
|
}
|
|
|
|
|
|
if (array_key_exists('reseller_school',$_GET)) $reseller_school = intval($_GET['reseller_school']);
|
|
if (array_key_exists('reseller_menu_num',$_GET)) $reseller_menu_num = intval($_GET['reseller_menu_num']);
|
|
|
|
if (isset($reseller_school) && isset($reseller_menu_num)) {
|
|
$school_num = $reseller_school;
|
|
$base_school_num = $reseller_school;
|
|
$selected_menu_num = $reseller_menu_num;
|
|
|
|
$query = "SELECT * FROM schools WHERE record_num = $school_num";
|
|
// writeLog($query);
|
|
$results = db_query($query);
|
|
$school_record = db_fetch_assoc($results);
|
|
|
|
$schedule_num = db_getVal("SELECT schedule_num FROM hotlunch_menu_dates WHERE school_num = $reseller_school AND record_num = $reseller_menu_num");
|
|
|
|
}
|
|
|
|
|
|
// Set class num for Customers
|
|
db_query("UPDATE people SET class_num = 1, meal_location = 1 WHERE school_num = $base_school_num AND people_type = 'Customer' AND class_num < 10");
|
|
|
|
// Set class num for Parents
|
|
db_query("UPDATE people SET class_num = 2, meal_location = 1 WHERE school_num = $base_school_num AND people_type = 'Parent' AND class_num < 10");
|
|
|
|
$numClasses = db_getVal("SELECT count(*) FROM classes WHERE school_num = $base_school_num");
|
|
if ($numClasses == 0) {
|
|
db_query("UPDATE people SET class_num = 3, meal_location = 1 WHERE school_num = $base_school_num AND people_type = 'Student'");
|
|
}
|
|
|
|
|
|
|
|
// Get parameters to script
|
|
if (array_key_exists('action',$_GET)) $action = $_GET['action'];
|
|
if (array_key_exists('action',$_POST)) $action = $_POST['action'];
|
|
if (array_key_exists('paction',$_GET)) $paction = $_GET['paction'];
|
|
if (array_key_exists('paction',$_POST)) $paction = $_POST['paction'];
|
|
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
|
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
|
|
if (array_key_exists('menu_num',$_GET)) $selected_menu_num = $_GET['menu_num'];
|
|
if (array_key_exists('menu_num',$_POST)) $selected_menu_num = $_POST['menu_num'];
|
|
if (array_key_exists('menu_item_num',$_GET)) $selected_menu_item_num = $_GET['menu_item_num'];
|
|
if (array_key_exists('menu_item_num',$_POST)) $selected_menu_item_num = $_POST['menu_item_num'];
|
|
if (array_key_exists('class_num',$_GET)) $selected_class_num = $_GET['class_num'];
|
|
if (array_key_exists('class_num',$_POST)) $selected_class_num = $_POST['class_num'];
|
|
if (array_key_exists('paperSize',$_GET) && $_GET['paperSize']) $paperSize = $_GET['paperSize'];
|
|
if (array_key_exists('paperSize', $_POST) && strlen($_POST['paperSize'])) $paperSize = $_POST['paperSize'];
|
|
if (array_key_exists('rowHeight',$_GET) && $_GET['rowHeight']) $rowHeight = $_GET['rowHeight'];
|
|
if (array_key_exists('rowHeight',$_POST) && $_POST['rowHeight']) $rowHeight = $_POST['rowHeight'];
|
|
if (array_key_exists('reportStudents',$_GET) && $_GET['reportStudents']) $reportStudents = $_GET['reportStudents'];
|
|
if (array_key_exists('reportStudents',$_POST) && $_POST['reportStudents']) $reportStudents = $_POST['reportStudents'];
|
|
if (array_key_exists('reportOrderStatus',$_GET) && $_GET['reportOrderStatus']) $reportOrderStatus = $_GET['reportOrderStatus'];
|
|
if (array_key_exists('reportOrderStatus',$_POST) && $_POST['reportOrderStatus']) $reportOrderStatus = $_POST['reportOrderStatus'];
|
|
if (array_key_exists('include_parent_info',$_GET) && $_GET['include_parent_info']) $include_parent_info = $_GET['include_parent_info'];
|
|
if (array_key_exists('include_parent_info',$_POST) && $_POST['include_parent_info']) $include_parent_info = $_POST['include_parent_info'];
|
|
|
|
if (!isset($paperSize) || strlen($paperSize) == 0) $paperSize = "Letter";
|
|
if (!isset($reportStudents) || strlen($reportStudents) == 0) $reportStudents = $school_record['delivery_report_students'];
|
|
|
|
if (isset($paction)) $action = $paction;
|
|
if (!isset($action)) $action = "schedule-reports";
|
|
|
|
if (isset($selected_menu_num) && !is_array($selected_menu_num) && !isset($schedule_num)) {
|
|
$selected_menu_num = intval($selected_menu_num);
|
|
$schedule_num = db_getVal("SELECT schedule_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num = $selected_menu_num");
|
|
}
|
|
// $selected_menu_num_log = is_array($selected_menu_num) ? implode(",", $selected_menu_num) : $selected_menu_num;
|
|
|
|
if (!isset($schedule_num)) {
|
|
$action = "";
|
|
header("Location: /?action=$action&error_code=NOSCHED");
|
|
return;
|
|
}
|
|
|
|
|
|
// 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&schedule_num=$schedule_num&error_code=INVALIDSCHED");
|
|
return;
|
|
}
|
|
|
|
$schedule = db_fetch_array($results);
|
|
|
|
db_query("UPDATE people SET class_num = 0, meal_location = 0 WHERE school_num = $base_school_num AND class_num IS NULL");
|
|
|
|
$ClassNumField = "class_num";
|
|
if ($school_record['implement_meal_locations'] == 'Y' && $schedule['class_sort_field'] == 'D' || $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");
|
|
}
|
|
else {
|
|
db_query("UPDATE people SET meal_location = class_num WHERE school_num = $base_school_num AND meal_location IS NULL");
|
|
}
|
|
}
|
|
|
|
writeLog("ClassNumField: $ClassNumField\n");
|
|
|
|
|
|
// Ensure that there are menus to report on
|
|
if (isset($selected_menu_num) && is_array($selected_menu_num)) $selected_menu_num = implode(",",$selected_menu_num);
|
|
|
|
$iwhere = "";
|
|
if (!isset($selected_menu_num) || strlen($selected_menu_num) == 0) {
|
|
if (isset($selected_menu_item_num) && count($selected_menu_item_num) > 0) {
|
|
$selected_menu_items = db_escape_string(implode(',',$selected_menu_item_num));
|
|
$iwhere = "AND hlmi.record_num IN ($selected_menu_items) ";
|
|
|
|
$results = db_query("SELECT menu_num FROM hotlunch_menu_items AS hlmi WHERE school_num = $school_num $iwhere");
|
|
$selected_menus = array();
|
|
while ($row = db_fetch_array($results)) {
|
|
$selected_menus[] = $row['menu_num'];
|
|
}
|
|
if (count($selected_menus) == 0) {
|
|
header("Location: /?action=$action&schedule_num=$schedule_num&error_code=NOMENU");
|
|
return;
|
|
}
|
|
$selected_menu_num = implode(",",$selected_menus);
|
|
}
|
|
else {
|
|
header("Location: /?action=$action&schedule_num=$schedule_num&error_code=NOMENU");
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
// Handle selected classes
|
|
$cwhere = "";
|
|
$count_selected_classes = 0;
|
|
if (isset($selected_class_num)) {
|
|
if (is_array($selected_class_num)) {
|
|
if (count($selected_class_num) > 0) {
|
|
if ($selected_class_num[0] == 'All') {
|
|
$cwhere = "";
|
|
}
|
|
else {
|
|
$count_selected_classes = count($selected_class_num);
|
|
$cwhere = "AND c.record_num IN (" . db_escape_string(implode(",",$selected_class_num)) . ") ";
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$count_selected_classes = 1;
|
|
$cwhere = "AND c.record_num = $selected_class_num ";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
$error_message = getLanguageText('TEXT-NO-ACCESS-TO-SCHEDULE');
|
|
$action = "schedule-reports";
|
|
header("Location: /?action=$action&schedule_num=$schedule_num&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Get menu date info
|
|
$query = "select * from hotlunch_menu_dates " .
|
|
"where school_num = $school_num " .
|
|
"and record_num in ($selected_menu_num) " .
|
|
"order by sequence,menu_date";
|
|
// writeLog($query);
|
|
$menu_date_results = db_query($query);
|
|
|
|
if (db_num_rows($menu_date_results) == 1) {
|
|
$menu_date = db_fetch_array($menu_date_results);
|
|
$numMenus = 1;
|
|
|
|
if ($siteType == 'hotlunch' || $siteType == 'fundraising') {
|
|
$ReportTitle = getLanguageText('TEXT-DELIVERY-REPORT') . " :: " . $menu_date['menu_title'];
|
|
$MenuTitle = $menu_date['menu_title'] . " - " . date($school_record['date_format'],strtotime($menu_date['menu_date']));
|
|
$mdate = date("Y-m-d",strtotime($menu_date['menu_date']));
|
|
}
|
|
else {
|
|
$ReportTitle = getLanguageText('TEXT-ORDER-REPORT') . " :: " . $menu_date['menu_title'];
|
|
$MenuTitle = $menu_date['menu_title'];
|
|
}
|
|
$page_title = $MenuTitle;
|
|
}
|
|
else {
|
|
$numMenus = db_num_rows($menu_date_results);
|
|
$min_date = db_getVal("SELECT min(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num in ($selected_menu_num)");
|
|
$max_date = db_getVal("SELECT max(menu_date) FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num in ($selected_menu_num)");
|
|
|
|
if ($siteType == 'hotlunch' || $siteType == 'fundraising') {
|
|
$ReportTitle = getLanguageText('TEXT-DELIVERY-REPORT') . " :: $min_date - $max_date";
|
|
$MenuTitle = "$min_date - $max_date";
|
|
$mdate = $min_date.'-'.$max_date;
|
|
}
|
|
else {
|
|
$ReportTitle = getLanguageText('TEXT-ORDER-REPORT') . " ::";
|
|
$MenuTitle = "";
|
|
}
|
|
$page_title = $MenuTitle;
|
|
}
|
|
|
|
|
|
// Get set of menu items
|
|
$query = "SELECT hlmi.*,hlmd.sequence AS menu_sequence,hlmd.menu_date FROM hotlunch_menu_items as hlmi, hotlunch_menu_dates AS hlmd " .
|
|
"WHERE hlmi.school_num = $school_num " .
|
|
"AND hlmd.school_num = $school_num " .
|
|
"AND hlmi.menu_num IN ($selected_menu_num) " .
|
|
"AND hlmi.menu_num = hlmd.record_num " .
|
|
"AND hlmi.item_type != 'Heading' " .
|
|
$iwhere .
|
|
"ORDER BY menu_sequence,hlmd.menu_date,hlmi.sequence";
|
|
// writeLog($query);
|
|
$menu_item_results = db_query($query);
|
|
|
|
if (db_num_rows($menu_item_results) == 0) {
|
|
$error_message = getLanguageText('ERRORMSG-NO-MENU-ITEMS');
|
|
$action = "schedule-reports";
|
|
header("Location: /?action=$action&schedule_num=$schedule_num&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
writeLog("Num Menu Items: ".db_num_rows($menu_item_results));
|
|
|
|
$menu_items = array();
|
|
$report_totals = array();
|
|
$selected_items = "";
|
|
$total_orders = 0;
|
|
$totals_count = 0;
|
|
$count = 0;
|
|
while ($row = db_fetch_array($menu_item_results)) {
|
|
extract($row);
|
|
$menu_date = date($school_record['date_format'],strtotime($menu_date));
|
|
$menu_date = date("M j",strtotime($menu_date));
|
|
|
|
$menu_items[$count]['total'] = 0;
|
|
|
|
if (strlen($label_title) > 0) {
|
|
if (($schedule['display_menu_date'] == 'Y' || $schedule['schedule_type'] == 'Hot Lunch' || $schedule['schedule_type'] == 'Date Sensitive') && $numMenus > 1) $label_title = "($menu_date)\n\n$label_title";
|
|
$menu_items[$count]['title'] = $label_title;
|
|
}
|
|
else {
|
|
$max_length = 35;
|
|
if (strlen($item_title) > $max_length) {
|
|
$words = explode(' ',$item_title);
|
|
$i = 1;
|
|
$item_title = $words[0];
|
|
while (strlen($item_title) < $max_length - 3) {
|
|
$item_title .= " " . $words[$i];
|
|
$i++;
|
|
}
|
|
}
|
|
|
|
if (($schedule['display_menu_date'] == 'Y' || $schedule['schedule_type'] == 'Hot Lunch' || $schedule['schedule_type'] == 'Date Sensitive') && $numMenus > 1) $item_title = "($menu_date)\n\n$item_title";
|
|
$menu_items[$count]['title'] = $item_title;
|
|
}
|
|
|
|
$menu_items[$count]['num'] = $record_num;
|
|
if (strlen($selected_items)) $selected_items .= ",";
|
|
$selected_items .= $record_num;
|
|
$count++;
|
|
}
|
|
|
|
$menuItems = $menu_items;
|
|
|
|
|
|
|
|
|
|
//
|
|
// Setup the PDF
|
|
//
|
|
$document_font = $school_record['document_font'];
|
|
if (strlen($document_font) == 0) $document_font = "Helvetica";
|
|
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 8;
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
|
|
global $start_row, $document_font, $document_font_size, $title_font_size, $font_parm, $title_col, $title_width, $incr, $width, $first_line, $name_col, $line_width;
|
|
global $school_name, $class_info, $ReportTitle, $page_title;
|
|
global $numPagesWide, $page_num, $currPage, $start_item, $end_item, $num_columns, $menuItems, $qty_cols, $qty_spacing;
|
|
global $line_top, $max_rows;
|
|
|
|
$menu_items = $menuItems;
|
|
$curr_row = $start_row;
|
|
|
|
// Print report titles
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
$this->SetFont("FreeSans",'B',$document_font_size + 1);
|
|
$this->SetDrawColor(255,0,0);
|
|
|
|
// Print page headers
|
|
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$this->SetFont($document_font,"B",$document_font_size + 2);
|
|
$this->SetXY($title_col,$curr_row);
|
|
$this->Cell($title_width,$incr + 1,$ReportTitle,'0',1,'L',true,'',1);
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
|
|
$this->SetXY($title_col + 180,$curr_row);
|
|
$this->Cell($title_width - 180,$incr + 1,$page_title,'0',1,'R',true,'',1);
|
|
|
|
$curr_row += $incr + 2;
|
|
|
|
// Print classroom info
|
|
$this->SetFont($document_font,"B",$document_font_size + 0);
|
|
$this->SetXY($title_col,$curr_row);
|
|
$this->Cell($title_width,$incr + 1,"$school_name - $class_info",'0',1,'L',true,'',1);
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
|
|
$page_num = $currPage + 1;
|
|
$this->SetXY($title_col + 240,$curr_row);
|
|
$this->Cell($title_width - 240,$incr + 1,getLanguageText('TEXT-PAGE').": $page_num",'0',1,'R',true,'',1);
|
|
|
|
$curr_row += $incr + 4;
|
|
|
|
// Print vertical lines
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i <= $start_item + $num_columns; $i++) {
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
$this->Line($col,$line_top,$col,$first_line);
|
|
}
|
|
|
|
|
|
// Print the menu items on the page
|
|
$this->SetFont($document_font,"",$title_font_size);
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i < $end_item; $i++) {
|
|
$title = isset($menu_items[$i]['title']) ? $menu_items[$i]['title'] : '';
|
|
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
|
|
// Menu item text
|
|
$this->SetXY($col,$curr_row);
|
|
$this->MultiCell($qty_spacing,$incr - 1.5,$title,'0','C',false);
|
|
}
|
|
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
|
|
// Horizontal line under menu items
|
|
$curr_row = $first_line;
|
|
$this->Line($name_col,$curr_row,$line_width,$curr_row);
|
|
}
|
|
|
|
function Footer() {
|
|
|
|
global $logo_row, $document_font, $document_font_size, $siteType, $school_record, $incr, $school_name;
|
|
|
|
// Add logo to page
|
|
$this->Image("images/".$school_record['logo_image'],10,$logo_row + 5,50);
|
|
|
|
$this->SetFont($document_font,"",$document_font_size - 1);
|
|
$this->SetXY(80,$logo_row + 5);
|
|
$date = dateString('datetime');
|
|
if ($siteType == 'hotlunch' || $siteType == 'fundraising') {
|
|
$this->Cell(182,$incr - 1,getLanguageText('TEXT-DELIVERY-REPORT') . ": $date",'0',1,'R','',1);
|
|
}
|
|
else {
|
|
$this->Cell(182,$incr - 1,getLanguageText('TEXT-ORDER-REPORT') . ": $date",'0',1,'R','',1);
|
|
}
|
|
|
|
$this->SetXY(80,$logo_row + 5 + $incr);
|
|
$this->Cell(182,$incr - 1,"$school_name",'0',1,'R','',1);
|
|
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
}
|
|
|
|
|
|
// Force exact physical size for Letter/Legal to avoid any library/config defaults
|
|
// Letter: 11 x 8.5 inches => 279.4mm x 215.9mm (landscape)
|
|
// Legal: 14 x 8.5 inches => 355.6mm x 215.9mm (landscape)
|
|
$pageFormat = $paperSize;
|
|
if (isset($paperSize)) {
|
|
$ps = strtoupper(trim($paperSize));
|
|
if ($ps === 'LETTER') {
|
|
$pageFormat = array(279.4, 215.9);
|
|
} elseif ($ps === 'LEGAL') {
|
|
$pageFormat = array(355.6, 215.9);
|
|
}
|
|
}
|
|
|
|
$pdf= new PDF('L','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->SetTextColor($font_red,$font_green,$font_blue);
|
|
$pdf->SetDrawColor(255,0,0);
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 185;
|
|
$absolute_max_rows = $max_rows;
|
|
$logo_row = 190;
|
|
$title_col = 8;
|
|
$name_col = 8;
|
|
|
|
$start_row = 8;
|
|
$curr_row = $start_row;
|
|
$incr = 3.8;
|
|
|
|
if (isset($rowHeight)) {
|
|
if ($rowHeight == 'Normal') $incr = 3.8;
|
|
if ($rowHeight == 'Wide') $incr = 6.0;
|
|
}
|
|
|
|
if ($school_record['delivery_report_row_height'] == 'Wide') {
|
|
$incr = 6.0;
|
|
$document_font_size = 10;
|
|
}
|
|
|
|
$first_line = $start_row + 40;
|
|
$line_top = $start_row + 3 * $incr;
|
|
|
|
$num_lines = intval(($max_rows - $first_line) / $incr);
|
|
$max_num_lines = $num_lines;
|
|
|
|
// Calculate the column width and name width
|
|
$num_columns = count($menu_items);
|
|
|
|
// Layout columns for letter size paper
|
|
if ($paperSize == "Letter") {
|
|
if ($num_columns < 8) $num_columns = 8;
|
|
if ($num_columns > 20) $num_columns = 20;
|
|
|
|
$item_columns_width = 2000;
|
|
$text_length = 60;
|
|
$title_font_size = $document_font_size - 1.6;
|
|
if ($num_columns > 15) {
|
|
$item_columns_width = 2100;
|
|
$text_length = 55;
|
|
|
|
if ($num_columns > 17) {
|
|
$title_font_size = $document_font_size - 2.2;
|
|
$text_length = 44;
|
|
}
|
|
}
|
|
|
|
$title_width = 260;
|
|
$line_width = $title_width + 8;
|
|
$qty_spacing = intval($item_columns_width / $num_columns) / 10;
|
|
$name_width = $title_width - ($qty_spacing * $num_columns);
|
|
}
|
|
|
|
// Layout columns for legal size paper
|
|
if ($paperSize == "Legal") {
|
|
if ($num_columns < 8) $num_columns = 8;
|
|
if ($num_columns > 30) $num_columns = 30;
|
|
|
|
$item_columns_width = 2950;
|
|
$text_length = 50;
|
|
$title_font_size = $document_font_size - 1.6;
|
|
|
|
if ($num_columns > 17) {
|
|
$title_font_size = $document_font_size - 2.2;
|
|
$text_length = 40;
|
|
}
|
|
|
|
$title_width = 340;
|
|
$line_width = $title_width + 8;
|
|
$qty_spacing = intval($item_columns_width / $num_columns) / 10;
|
|
$name_width = $title_width - ($qty_spacing * $num_columns);
|
|
}
|
|
|
|
|
|
$numPagesWide = intval((count($menu_items) + $num_columns - 1) / $num_columns);
|
|
|
|
|
|
$qty_cols = array();
|
|
for ($i = 0; $i <= $num_columns; $i++) {
|
|
$qty_cols[$i] = $name_col + $name_width + $i * $qty_spacing;
|
|
}
|
|
|
|
|
|
|
|
// Get list of classes
|
|
$query = "select c.*,program_name from classes as c left join class_programs as cp on c.class_program = cp.record_num " .
|
|
"where c.school_num = $base_school_num " .
|
|
$cwhere .
|
|
"order by entry_type,sequence";
|
|
writeLog($query);
|
|
$cresults = db_query($query);
|
|
|
|
$current_classes = array();
|
|
if (db_num_rows($cresults)) {
|
|
while ($class = db_fetch_array($cresults)) {
|
|
$current_classes[] = $class;
|
|
}
|
|
}
|
|
|
|
if (count($current_classes)) {
|
|
|
|
writeLog("count current_classes: ".count($current_classes));
|
|
$classes = array();
|
|
$count = 0;
|
|
for ($cnum = 0; $cnum < count($current_classes); $cnum++) {
|
|
$class = $current_classes[$cnum];
|
|
$class_num = $class['record_num'];
|
|
$classes[$count]['num'] = $class_num;
|
|
writeLog("$cnum - class_num: $class_num");
|
|
|
|
// Get class info for the report
|
|
$class_info = getClassInfo($class_num,'internal',2);
|
|
writeLog("class_info: $class_info");
|
|
|
|
$class_label = $class['label_description'];
|
|
// writeLog("class_label: $class_label");
|
|
|
|
// if (strlen($class_label) > 0) $class_info .= " ($class_label)";
|
|
$classes[$count]['info'] = $class_info;
|
|
|
|
$classes[$count]['delivery_group'] = '';
|
|
if ($school_record['implement_delivery_groups'] == 'Y') {
|
|
$classes[$count]['delivery_group'] = $class['delivery_group'];
|
|
}
|
|
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
$classes[] = array('num' => 0, 'info' => $GlobalText['Staff']);
|
|
$classes[] = array('num' => 1, 'info' => getLanguageText('TEXT-CUSTOMERS'));
|
|
$classes[] = array('num' => 2, 'info' => getLanguageText('TEXT-PARENTS'));
|
|
$classes[] = array('num' => 3, 'info' => $GlobalText['Students']);
|
|
|
|
writeLog(print_r($classes,true));
|
|
|
|
writeLog("staff_meals_to_classroom: " . $school_record['staff_meals_to_classroom'] . "\n");
|
|
writeLog("implement_meal_locations: " . $school_record['implement_meal_locations'] . "\n");
|
|
|
|
$delivery_groups = array();
|
|
|
|
for ($c = 0; $c < count($classes); $c++) {
|
|
$class_num = $classes[$c]['num'];
|
|
$class_info = $classes[$c]['info'];
|
|
writeLog("class_num: $class_num --- class_info: $class_info");
|
|
$class_group = '';
|
|
if (array_key_exists('delivery_group', $classes[$c])) $class_group = $classes[$c]['delivery_group'];
|
|
// writeLog("class_num: $class_num\n");
|
|
// writeLog("class_info: $class_info\n");
|
|
|
|
// Check where staff meals are sent
|
|
$cwhere = "and st.$ClassNumField = $class_num ";
|
|
if ($class_num == 1) $cwhere = "and st.$ClassNumField IN (1,2) ";
|
|
$swhere = "";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N' && $school_record['implement_meal_locations'] == 'N') {
|
|
if ($class_num == 0) {
|
|
$cwhere = "";
|
|
$swhere = "and st.people_type = 'Staff' ";
|
|
}
|
|
|
|
if ($class_num == 1) {
|
|
$cwhere = "and st.$ClassNumField IN (1,2) ";
|
|
$swhere = "";
|
|
$swhere = "";
|
|
}
|
|
|
|
if ($class_num > 1) {
|
|
$cwhere = "and st.$ClassNumField = $class_num ";
|
|
$swhere = "and st.people_type != 'Staff' ";
|
|
}
|
|
}
|
|
// writeLog("cwhere: $cwhere");
|
|
|
|
// Get set of orders for this menu date
|
|
if ($reportStudents == 'With Orders') {
|
|
$oswhere = "and hloh.status NOT IN ('Inactive','Deleted') ";
|
|
if (isset($reportOrderStatus) && $reportOrderStatus == 'Any') $oswhere = "and hloh.status NOT IN ('Deleted') ";
|
|
$query = "select distinct concat_ws(', ',st.last_name,st.first_name) as name,people_type as ptype,st.record_num," .
|
|
"hloh.source,student_number,user_num,label_note,delivered, $ClassNumField AS class_num," .
|
|
"st.status AS pstatus,class_num AS clnum, meal_location AS mlnum,delivered " .
|
|
"from people as st, hotlunch_order_header as hloh, hotlunch_order_items as hloi " .
|
|
"where st.school_num = $base_school_num " .
|
|
"and st.status != 'Inactive' " .
|
|
"and hloh.school_num = $school_num " .
|
|
"and hloi.school_num = $school_num " .
|
|
"and st.record_num = hloh.ordered_by_num " .
|
|
"and st.record_num = hloi.ordered_by_num " .
|
|
$cwhere .
|
|
$swhere .
|
|
$oswhere .
|
|
"and hloh.schedule_num = $schedule_num " .
|
|
"and hloi.schedule_num = $schedule_num " .
|
|
"and hloi.menu_num in ($selected_menu_num) " .
|
|
"and hloi.active != 'N' " .
|
|
"and hloh.record_num = hloi.order_num " .
|
|
"order by ptype desc,name";
|
|
|
|
}
|
|
else {
|
|
$query = "select distinct concat_ws(', ',st.last_name,st.first_name) as name,people_type as ptype,st.record_num,'On-Line' AS source," .
|
|
"student_number,user_num,label_note, $ClassNumField AS class_num," .
|
|
"class_num AS clnum, meal_location AS mlnum,'N' AS delivered " .
|
|
"from people as st " .
|
|
"where st.school_num = $base_school_num " .
|
|
"and st.status != 'Inactive' " .
|
|
$cwhere .
|
|
$swhere .
|
|
"order by ptype desc,name";
|
|
}
|
|
|
|
writeLog("$query");
|
|
$class_students = db_query($query);
|
|
|
|
$num_students = db_num_rows($class_students);
|
|
writeLog("num_students: $num_students");
|
|
writeLog("0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
if ($num_students == 0) continue;
|
|
$num_lines = $num_students;
|
|
if ($num_lines > $max_num_lines) $num_lines = $max_num_lines;
|
|
$total_orders += $num_students;
|
|
|
|
// Calculate the number of rows required
|
|
$max_rows = $first_line + $num_lines * $incr;
|
|
if ($max_rows > $absolute_max_rows) $max_rows = $absolute_max_rows;
|
|
|
|
// Determine which items to process
|
|
$currPage = 0;
|
|
$start_item = $currPage * $num_columns;
|
|
$end_item = ($currPage + 1) * $num_columns;
|
|
if ($end_item > count($menu_items)) $end_item = count($menu_items);
|
|
|
|
$students = array();
|
|
$scount = 0;
|
|
while ($row = db_fetch_array($class_students)) {
|
|
$students[$scount]['name'] = $row['name'];
|
|
$students[$scount]['num'] = $row['record_num'];
|
|
$students[$scount]['source'] = $row['source'];
|
|
$students[$scount]['type'] = $row['ptype'];
|
|
$students[$scount]['st_num'] = $row['student_number'];
|
|
$students[$scount]['user_num'] = $row['user_num'];
|
|
$students[$scount]['label_note'] = $row['label_note'];
|
|
|
|
$delivered = 'N';
|
|
if (array_key_exists('delivered', $row)) $delivered = $row['delivered'];
|
|
$students[$scount]['delivered'] = $delivered;
|
|
|
|
$students[$scount]['class_num'] = $row['class_num'];
|
|
|
|
if (array_key_exists('meal_location', $row)) $students[$scount]['meal_location'] = $row['meal_location'];
|
|
if (array_key_exists('clnum', $row)) $students[$scount]['clnum'] = $row['clnum'];
|
|
if (array_key_exists('mlnum', $row)) $students[$scount]['mlnum'] = $row['mlnum'];
|
|
|
|
// Validate the mlnum
|
|
|
|
$rnum = $row['record_num'];
|
|
$students[$scount]['ostatus'] = db_getVal("SELECT status FROM hotlunch_order_header " .
|
|
"WHERE school_num = $school_num " .
|
|
"AND schedule_num = $schedule_num " .
|
|
"AND ordered_by_num = $rnum " .
|
|
"LIMIT 0,1");
|
|
$scount++;
|
|
}
|
|
|
|
// writeLog("scount: $scount");
|
|
|
|
|
|
// Process each page to display all the ordered menu items
|
|
for ($currPage = 0; $currPage < $numPagesWide; $currPage++) {
|
|
|
|
// writeLog("*** count of menu_items: ".count($menu_items));
|
|
for ($i = 0; $i < count($menu_items); $i++) {
|
|
$menu_items[$i]['total'] = 0;
|
|
}
|
|
|
|
// Determine which items to process
|
|
$start_item = $currPage * $num_columns;
|
|
$end_item = ($currPage + 1) * $num_columns;
|
|
if ($end_item > count($menu_items)) $end_item = count($menu_items);
|
|
|
|
$pdf->addPage();
|
|
writeLog("NEW PAGE: ------------------------------");
|
|
|
|
// Manage multi-page report
|
|
for ($sNum = 0; $sNum < $num_students; $sNum += $num_lines) {
|
|
$lastLine = $sNum + $num_lines;
|
|
if ($lastLine > $num_students) $lastLine = $num_students;
|
|
|
|
if ($sNum > 0) {
|
|
// Calculate the number of rows required
|
|
$max_rows = $first_line + ($num_lines - $sNum) * $incr;
|
|
if ($max_rows > $absolute_max_rows) $max_rows = $absolute_max_rows;
|
|
// if ($max_rows < 0) $max_rows = $absolute_max_rows;
|
|
$pdf->addPage();
|
|
// writeLog("NEW PAGE: ------------------------------");
|
|
}
|
|
|
|
$curr_row = $first_line;
|
|
|
|
// Display the names of the students and the staff
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
for ($line = $sNum; $line < $lastLine; $line++) {
|
|
$name = "";
|
|
$source = "";
|
|
$type = "";
|
|
$num = 0;
|
|
$dtext = "";
|
|
if ($line < count($students)) {
|
|
$name = $students[$line]['name'];
|
|
if ($students[$line]['source'] == 'Paper') $source = '[P]';
|
|
if (strlen($students[$line]['label_note'])) $name .= " - " . $students[$line]['label_note'];
|
|
$type = $students[$line]['type'];
|
|
if ($school_record['collect_student_number'] == 'Y') $name = $students[$line]['st_num'] . ": $name";
|
|
$user_num = $students[$line]['user_num'];
|
|
$linked_to_student = db_getVal("SELECT linked_to_student FROM users WHERE school_num = $base_school_num AND record_num = $user_num");
|
|
if (isset($linked_to_student) && strlen($linked_to_student)) $name .= " ($linked_to_student)";
|
|
if (isset($reportOrderStatus) && $reportOrderStatus == 'Any') $name .= " - " . $students[$line]['ostatus'];
|
|
if ($school_record['implement_meal_locations'] == 'Y' && $schedule['class_sort_field'] == 'D' || $schedule['class_sort_field'] == 'L') {
|
|
if ($students[$line]['clnum'] != $students[$line]['mlnum']) $name .= " ***";
|
|
}
|
|
}
|
|
|
|
if (strlen($students[$line]['delivered']) && $schedule['schedule_type'] != 'Hot Lunch' && in_array($siteType,array('hotlunch','yearbook','tickets','fundraising')))
|
|
$dtext = " (" . $students[$line]['delivered'] . ")";
|
|
|
|
$bg = true;
|
|
if ($line % 2) $bg = false;
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
if ($type == 'Staff') $pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($name_width,$incr,$name.$dtext,'1',1,'L',$bg,'',1);
|
|
writeLog("$class_info -- $name");
|
|
|
|
// Line under student's name
|
|
$pdf->Line($name_col,$curr_row,$line_width,$curr_row);
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
// Setup order status where clause
|
|
$oswhere = "and hloh.status NOT IN ('Inactive','Deleted') ";
|
|
if (isset($reportOrderStatus) && $reportOrderStatus == 'Any') $oswhere = "and hloh.status NOT IN ('Deleted') ";
|
|
|
|
// Process each column
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i < $start_item + $num_columns; $i++) {
|
|
$item_num = 0;
|
|
if ($i < $end_item && isset($menu_items[$i]['num'])) $item_num = $menu_items[$i]['num'];
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
|
|
$curr_row = $first_line;
|
|
|
|
for ($line = $sNum; $line < $lastLine; $line++) {
|
|
$qty = "";
|
|
if ($item_num > 0 && $line < count($students)) {
|
|
$onum = $students[$line]['num'];
|
|
$otype = $students[$line]['type'];
|
|
$query = "SELECT qty FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloh.record_num = hloi.order_num " .
|
|
$oswhere .
|
|
"AND hloi.ordered_by_num = $onum " .
|
|
"AND hloi.menu_item_num = $item_num " .
|
|
"AND hloi.active != 'N'";
|
|
$qty = db_getVal($query);
|
|
if ($qty) {
|
|
if (!array_key_exists($i, $menu_items)) $menu_items[$i] = array();
|
|
if (!array_key_exists('total', $menu_items[$i])) $menu_items[$i]['total'] = 0;
|
|
|
|
$menu_items[$i]['total'] += $qty;
|
|
if ($class_group != '') {
|
|
if (!array_key_exists($class_group, $delivery_groups)) $delivery_groups[$class_group] = array();
|
|
if (!array_key_exists($i, $delivery_groups[$class_group])) $delivery_groups[$class_group][$i] = 0;
|
|
$delivery_groups[$class_group][$i] += $qty;
|
|
}
|
|
}
|
|
}
|
|
|
|
$bg = true;
|
|
if ($line % 2) $bg = false;
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($qty_spacing,$incr,$qty,'1',1,'C',$bg,'',1);
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Print class totals line
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
if ($reportStudents == 'All Students') $pdf->Cell($name_width,$incr,getLanguageText('TEXT-TOTALS') . ": $num_students " . getLanguageText('TEXT-PEOPLE'),'1',1,'L',true,'',1);
|
|
else $pdf->Cell($name_width,$incr,getLanguageText('TEXT-TOTALS') . ":$reportStudents $num_students " . getLanguageText('TEXT-ORDERS'),'1',1,'L',true,'',1);
|
|
$pdf->Line($name_col,$curr_row,$line_width,$curr_row);
|
|
|
|
// Process each total column
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i < $start_item + $num_columns; $i++) {
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
|
|
$qty = "";
|
|
if ($i < $end_item) $qty = number_format($menu_items[$i]['total'],0);
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($qty_spacing,$incr,$qty,'1',1,'C',true,'',1);
|
|
|
|
if (!array_key_exists($totals_count, $report_totals)) $report_totals[$totals_count] = array();
|
|
// writeLog("i: $i");
|
|
// writeLog("count of menu_items: ".count($menu_items));
|
|
if (!array_key_exists($i, $menu_items)) $menu_items[$i] = array();
|
|
if (!array_key_exists('total', $menu_items[$i])) $menu_items[$i]['total'] = 0;
|
|
// writeLog("total: ".$menu_items[$i]['total']);
|
|
$report_totals[$totals_count][$i] = $menu_items[$i]['total'];
|
|
}
|
|
}
|
|
|
|
// Save the totals info for this class
|
|
$report_totals[$totals_count]['name'] = $class_info;
|
|
// if (strlen($class_info) > $text_length) $report_totals[$totals_count]['name'] = substr($class_info,0,$text_length);
|
|
$totals_count++;
|
|
}
|
|
|
|
|
|
// Finish if only one class has been selected
|
|
if ($count_selected_classes == 1) {
|
|
// Output the completed 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');
|
|
|
|
if ($siteType == 'hotlunch' || $siteType == 'fundraising') {
|
|
$filename = "delivery-report.pdf";
|
|
if (isset($mdate)) $filename = "delivery-report.$mdate.pdf";
|
|
$filename = genFileName($filename);
|
|
}
|
|
else $filename = genFileName("order-report.pdf");
|
|
|
|
header('Content-Transfer-Encoding: binary');
|
|
header("Content-Disposition: attachment; filename=$filename");
|
|
$pdf->Output("$filename","D");
|
|
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Get Concession order and add it into the totals
|
|
//
|
|
$concession['name'] = getLanguageText('TEXT-CONCESSION');
|
|
$includeConcession = false;
|
|
|
|
for ($i = 0; $i < count($menu_items); $i++) {
|
|
$item_num = isset($menu_items[$i]['num']) ? $menu_items[$i]['num'] : 0;
|
|
$query = "select qty from hotlunch_order_items " .
|
|
"where school_num = $school_num " .
|
|
"and schedule_num = $schedule_num " .
|
|
"and ordered_by_type = 'Concession' " .
|
|
"and menu_item_num = $item_num " .
|
|
"and active != 'N'";
|
|
$qty = db_getVal($query);
|
|
$concession[$i] = $qty;
|
|
if ($qty > 0) $includeConcession = true;
|
|
}
|
|
|
|
if ($includeConcession) $report_totals[$totals_count] = $concession;
|
|
|
|
|
|
|
|
//
|
|
// Print a summary page of each class and the staff totals
|
|
//
|
|
$num_classes = count($report_totals);
|
|
$num_lines = $num_classes;
|
|
if ($num_lines > $max_num_lines) $num_lines = $max_num_lines;
|
|
|
|
$max_rows = $first_line + $num_lines * $incr;
|
|
$class_info = getLanguageText('TEXT-SUMMARY');
|
|
|
|
// Clear the totals for further calculations
|
|
for ($i = 0; $i < count($menu_items); $i++) {
|
|
$menu_items[$i]['total'] = 0;
|
|
}
|
|
|
|
// Process each page to display all the menu items
|
|
for ($currPage = 0; $currPage < $numPagesWide; $currPage++) {
|
|
|
|
// Determine which items to process
|
|
$start_item = $currPage * $num_columns;
|
|
$end_item = ($currPage + 1) * $num_columns;
|
|
if ($end_item > count($menu_items)) $end_item = count($menu_items);
|
|
|
|
$pdf->addPage();
|
|
$curr_row = $first_line;
|
|
// writeLog("NEW PAGE: ------------------------------");
|
|
|
|
// Manage multi-page report
|
|
for ($sNum = 0; $sNum < $num_classes; $sNum += $num_lines) {
|
|
$lastLine = $sNum + $num_lines;
|
|
if ($lastLine > $num_classes) $lastLine = $num_classes;
|
|
|
|
if ($sNum > 0) {
|
|
// Calculate the number of rows required
|
|
$max_rows = $first_line + abs($num_lines - $sNum) * $incr;
|
|
if ($max_rows > $absolute_max_rows) $max_rows = $absolute_max_rows;
|
|
$pdf->addPage();
|
|
// writeLog("NEW PAGE: ------------------------------");
|
|
}
|
|
|
|
$curr_row = $first_line;
|
|
|
|
if ($max_rows > $absolute_max_rows) $max_rows = $absolute_max_rows;
|
|
|
|
// Print vertical lines
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i <= $start_item + $num_columns; $i++) {
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
$pdf->Line($col,$line_top,$col,$max_rows);
|
|
}
|
|
|
|
// Display the totals name
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
for ($line = $sNum; $line < $lastLine; $line++) {
|
|
$name = "";
|
|
$source = "";
|
|
$type = "";
|
|
$num = 0;
|
|
if ($line < count($report_totals)) {
|
|
$name = $report_totals[$line]['name'];
|
|
$mLength = 34;
|
|
if (strlen($name) > $mLength) {
|
|
$words = explode(' ',$name);
|
|
$new = "";
|
|
for ($i = 0; $i < count($words); $i++) {
|
|
if ((strlen($new) + strlen($words[$i])) > $mLength) break;
|
|
|
|
if (strlen($new)) $new .= ' ';
|
|
$new .= $words[$i];
|
|
}
|
|
$name = $new;
|
|
}
|
|
|
|
}
|
|
|
|
$bg = true;
|
|
if ($line % 2) $bg = false;
|
|
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($name_width,$incr,$name,'1',1,'L',$bg,'',1);
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
// Process each column
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i < $start_item + $num_columns; $i++) {
|
|
$item_num = 0;
|
|
if ($i < $end_item && isset($menu_items[$i]['num'])) $item_num = $menu_items[$i]['num'];
|
|
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
|
|
$curr_row = $first_line;
|
|
|
|
for ($line = $sNum; $line < $lastLine; $line++) {
|
|
$qty = "";
|
|
if ($item_num > 0 && $line < count($report_totals)) {
|
|
$qty = intval($report_totals[$line][$i]);
|
|
$menu_items[$i]['total'] += $qty;
|
|
}
|
|
|
|
$bg = true;
|
|
if ($line % 2) $bg = false;
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($qty_spacing,$incr,$qty,'1',1,'C',$bg,'',1);
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Print school totals line
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($name_width,$incr,getLanguageText('TEXT-TOTALS'),'1',1,'L',true,'',1);
|
|
|
|
// Process each total column
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i < $start_item + $num_columns; $i++) {
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
|
|
$qty = "";
|
|
if ($i < $end_item && isset($menu_items[$i]['total'])) $qty = number_format($menu_items[$i]['total'],0);
|
|
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($qty_spacing,$incr,$qty,'1',1,'C',true,'',1);
|
|
// $report_totals[$totals_count][$i] = $qty;
|
|
$report_totals[$totals_count][$i] = isset($menu_items[$i]['total']) ? $menu_items[$i]['total'] : 0;
|
|
}
|
|
|
|
$curr_row += $incr + 1;
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
if ($reportStudents == 'With Orders') $pdf->Cell($name_width,$incr,getLanguageText('TEXT-TOTAL-ORDERS') . ": $total_orders",'1',1,'L',false,'',1);
|
|
else $pdf->Cell($name_width,$incr,getLanguageText('TEXT-PEOPLE') . ": $total_orders",'1',1,'L',false,'',1);
|
|
|
|
|
|
if ($school_record['implement_delivery_groups'] == 'Y') {
|
|
$curr_row += $incr * 3;
|
|
$line = 0;
|
|
|
|
ksort($delivery_groups);
|
|
foreach ($delivery_groups as $g => $group_totals) {
|
|
|
|
$gtitle = $g;
|
|
|
|
$results = db_query("SELECT * FROM delivery_groups WHERE school_num = $base_school_num AND group_id = '$g'");
|
|
if (db_num_rows($results)) {
|
|
$row = db_fetch_assoc($results);
|
|
$gtitle = $row['group_title'];
|
|
}
|
|
|
|
$bg = true;
|
|
if ($line % 2) $bg = false;
|
|
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($name_width,$incr,$gtitle,'1',1,'L',$bg,'',1);
|
|
|
|
// Process each total column
|
|
$colnum = 0;
|
|
for ($i = $start_item; $i < $start_item + $num_columns; $i++) {
|
|
$col = $qty_cols[$colnum];
|
|
$colnum++;
|
|
$qty = isset($group_totals[$i]) ? number_format($group_totals[$i],0) : '0';
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($qty_spacing,$incr,$qty,'1',1,'C',$bg,'',1);
|
|
}
|
|
|
|
$curr_row += $incr;
|
|
$line++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') exit();
|
|
|
|
// Output the completed PDF
|
|
|
|
if ($siteType == 'hotlunch' || $siteType == 'fundraising') {
|
|
$filename = "delivery-report.pdf";
|
|
if (isset($mdate)) $filename = "delivery-report.$mdate.pdf";
|
|
$filename = genFileName($filename);
|
|
}
|
|
else $filename = genFileName("order-report.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");
|
|
|
|
?>
|