2013 lines
80 KiB
PHP
2013 lines
80 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
$oaction = $action;
|
|
$action = "menu-details";
|
|
|
|
|
|
$moduleName = "supplier_orders.print.php";
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') 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','Schedule Reporting');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$action = "";
|
|
header("Location: /?action=$action&error_code=NOACCESS");
|
|
return;
|
|
}
|
|
|
|
|
|
// Get parameters to script
|
|
unset($selected_supplier_num);
|
|
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_menus = $_GET['menu_num'];
|
|
if (array_key_exists('menu_num',$_POST)) $selected_menus = $_POST['menu_num'];
|
|
if (array_key_exists('selected_menus',$_GET)) $selected_menus = $_GET['selected_menus'];
|
|
if (array_key_exists('selected_menus',$_POST)) $selected_menus = $_POST['selected_menus'];
|
|
if (array_key_exists('supplier_num',$_GET)) $selected_supplier_num = intval($_GET['supplier_num']);
|
|
if (array_key_exists('supplier_num',$_POST)) $selected_supplier_num = intval($_POST['supplier_num']);
|
|
if (array_key_exists('selected_menu_date',$_GET)) $selected_menu_date = $_GET['selected_menu_date'];
|
|
if (array_key_exists('selected_menu_date',$_POST)) $selected_menu_date = $_POST['selected_menu_date'];
|
|
|
|
// If user is a supplier then they can only see their reports
|
|
if ($_SESSION['UserInfo']['type'] == 'Supplier') $selected_supplier_num = $_SESSION['UserInfo']['supplier_num'];
|
|
|
|
if (isset($schedule_num)) writeLog("schedule_num: $schedule_num");
|
|
if (isset($selected_menus)) {
|
|
if (is_array($selected_menus)) {
|
|
for ($i = 0; $i < count($selected_menus); $i++) {
|
|
writeLog("selected_menus[$i]: ".$selected_menus[$i]);
|
|
}
|
|
}
|
|
else {
|
|
writeLog("selected_menus: $selected_menus");
|
|
}
|
|
}
|
|
if (isset($selected_supplier_num)) writeLog("selected_supplier_num: $selected_supplier_num");
|
|
if (isset($selected_menu_date)) writeLog("selected_menu_date: $selected_menu_date");
|
|
|
|
if (isset($selected_menu_date)) {
|
|
$query = "SELECT record_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND menu_date = '$selected_menu_date'";
|
|
writeLog($query);
|
|
$menus = db_query($query);
|
|
$selected_menus = array();
|
|
while ($row = db_fetch_assoc($menus)) {
|
|
$selected_menus[] = $row['record_num'];
|
|
}
|
|
}
|
|
|
|
|
|
$generateDeliverySheet = 'N';
|
|
$class_nums = array();
|
|
|
|
if (!isset($schedule_num)) {
|
|
if (isset($selected_menus) && is_array($selected_menus) && count($selected_menus) > 0) {
|
|
$menuNumbers = db_escape_string(implode(',',$selected_menus));
|
|
$query = "SELECT schedule_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num IN ($menuNumbers)";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results)) {
|
|
$schedule_num = "";
|
|
$selected_schedules = array();
|
|
while ($row = db_fetch_array($results)) {
|
|
if ($schedule_num) $schedule_num .= ",";
|
|
$schedule_num .= $row['schedule_num'];
|
|
$selected_schedules[] = $row['schedule_num'];
|
|
}
|
|
}
|
|
$scheduleNums = $schedule_num;
|
|
$generateDeliverySheet = 'Y';
|
|
}
|
|
else {
|
|
$action = "schedule-reports";
|
|
header("Location: /?action=$action&error_code=NOSCHED");
|
|
return;
|
|
}
|
|
}
|
|
else {
|
|
$selected_schedules[] = $schedule_num;
|
|
$scheduleNums = $schedule_num;
|
|
}
|
|
|
|
|
|
// 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 IN ($scheduleNums)";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
|
|
|
|
if (db_num_rows($results) == 0) {
|
|
$action = "schedule-reports";
|
|
header("Location: /?action=$action&schedule_num=$schedule_num&error_code=INVALIDSCHED");
|
|
return;
|
|
}
|
|
|
|
$schedule = db_fetch_array($results);
|
|
|
|
$ClassNumField = "class_num";
|
|
if ($school_record['implement_meal_locations'] == 'Y' && $schedule['class_sort_field'] == 'D' || $schedule['class_sort_field'] == 'L') {
|
|
$ClassNumField = "meal_location";
|
|
$query = "UPDATE people SET meal_location = class_num WHERE school_num = $school_num AND meal_location IS NULL";
|
|
writeLog($query);
|
|
db_query($query);
|
|
}
|
|
|
|
// Check that there are orders for this schedule
|
|
$numO = db_getVal("select count(*) from hotlunch_order_header where school_num = $school_num and schedule_num IN ($scheduleNums) and ordered_by_type != 'Concession' and status NOT IN ('Inactive','Deleted')");
|
|
$numI = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND schedule_num IN ($scheduleNums) AND ordered_by_type = 'Concession'");
|
|
if ($numO == 0 && $numI == 0) {
|
|
$action = "";
|
|
header("Location: /?action=$action&schedule_num=$schedule_num&error_code=NOORDERS");
|
|
return;
|
|
}
|
|
|
|
|
|
$numMenuDates = 1;
|
|
$menuTitles = "";
|
|
$mfirst = "";
|
|
$mlast = "";
|
|
|
|
if (is_array($selected_menus)) {
|
|
$numMenuDates = count($selected_menus);
|
|
$firstMenuDate = $selected_menus[0];
|
|
|
|
writeLog("selected_menus is an array");
|
|
writeLog("numMenuDates $numMenuDates");
|
|
|
|
$menuNumbers = db_escape_string(implode(',',$selected_menus));
|
|
for ($i = 0; $i < count($selected_menus); $i++) {
|
|
$curr_menu_num = $selected_menus[$i];
|
|
writeLog("curr_menu_num $curr_menu_num");
|
|
|
|
$results = db_query("SELECT * FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num = $curr_menu_num");
|
|
$row = db_fetch_assoc($results);
|
|
|
|
if ($numMenuDates == 1) $mdate = date("Y-m-d",strtotime($row['menu_date']));
|
|
$schedule_num = $row['schedule_num'];
|
|
$title = $row['menu_title'];
|
|
writeLog("schedule_num $schedule_num");
|
|
writeLog("menu title: $title");
|
|
|
|
$menu_date = dateString('date',strtotime($row['menu_date']));
|
|
$display_date = db_getVal("SELECT display_menu_date FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
|
|
if ($display_date == 'Y') $title .= " - $menu_date";
|
|
|
|
if ($i == 0) $mfirst = $title;
|
|
if ($i == count($selected_menus) - 1) $mlast = $title;
|
|
|
|
if ($i > 0) {
|
|
if (($i % 2) == 0) $menuTitles .= "\n";
|
|
else $menuTitles .= " / ";
|
|
}
|
|
$menuTitles .= $title;
|
|
|
|
include "supplier_orders.post.php";
|
|
}
|
|
|
|
if (count($selected_menus) > 8) $menuTitles = $mfirst . ' - ' . $mlast;
|
|
$schedule_num = $scheduleNums;
|
|
$orderTitle = "";
|
|
}
|
|
else {
|
|
writeLog("selected_menus is NOT an array");
|
|
$num_schedules = count($selected_schedules);
|
|
writeLog("num_schedules $num_schedules");
|
|
|
|
for ($i = 0; $i < count($selected_schedules); $i++) {
|
|
$schedule_num = $selected_schedules[$i];
|
|
writeLog("schedule_num $schedule_num");
|
|
include "supplier_orders.post.php";
|
|
}
|
|
|
|
$schedule_num = $scheduleNums;
|
|
$menuNumbers = $selected_menus;
|
|
$firstMenuDate = $selected_menus;
|
|
$snum = db_getVal("SELECT schedule_num FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num = $selected_menus");
|
|
|
|
$query = "SELECT * FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $snum";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$row = db_fetch_assoc($results);
|
|
$display_menu_date = $row['display_menu_date'];
|
|
$schedule_name = $row['schedule_name'];
|
|
|
|
// Get Title for products list
|
|
$query = "SELECT * FROM hotlunch_menu_dates WHERE school_num = $school_num AND record_num = $selected_menus";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$menu_date = db_fetch_array($results);
|
|
$mdate = date("Y-m-d",strtotime($menu_date['menu_date']));
|
|
if ($display_menu_date == 'Y') {
|
|
$orderTitle = $schedule_name . " - " . $menu_date['menu_title'] . ': ' . dateString('default',strtotime($menu_date['menu_date']));
|
|
}
|
|
else {
|
|
$orderTitle = $schedule_name . " - " . $menu_date['menu_title'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check the class_num value for staff to ensure that every staff person has a valid class number
|
|
$query = "SELECT * FROM people WHERE school_num = $base_school_num AND class_num IS NULL";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results)) {
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$rnum = $row['record_num'];
|
|
db_query("UPDATE people SET class_num = 0 WHERE school_num = $base_school_num AND class_num IS NULL AND record_num = $rnum");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// 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 = 9;
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 250;
|
|
$left_col = 16;
|
|
$start_col = 10;
|
|
|
|
$order_date_col = 131;
|
|
$order_date_row = 29;
|
|
$order_date_width = 65;
|
|
|
|
$school_col = 111;
|
|
$qty_col = 145;
|
|
$amount_col = 180;
|
|
$title_width = 190;
|
|
|
|
$address_row = 46;
|
|
$account_row = 81;
|
|
$account_col = 111;
|
|
$discount_row = 185;
|
|
$subtotal_row = 190;
|
|
$tax_row = 195;
|
|
$total_row = 225;
|
|
$notes_row = 231;
|
|
|
|
$start_row = 98;
|
|
$incr = 3.5;
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 10;
|
|
|
|
$document_name = getLanguageText('TEXT-SUPPLIER-ORDER');
|
|
$footer_text = "";
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $printTitle, $incr, $document_font, $document_font_size, $start_col, $title_width, $incr, $curr_row, $supplier_name;
|
|
|
|
if (!$printTitle) return;
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size + 1);
|
|
$this->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$curr_row = 10;
|
|
$this->SetXY($start_col,$curr_row);
|
|
$this->Cell($title_width,$incr + 1,$supplier_name,'0',1,'L',true,'',1);
|
|
|
|
$curr_row = 20;
|
|
return;
|
|
}
|
|
|
|
function printForm() {
|
|
global $incr, $document_font, $document_font_size;
|
|
|
|
// Print the form
|
|
$this->SetTextColor(0,0,0);
|
|
$this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$this->SetLineWidth(0.3);
|
|
$this->SetDrawColor(0,0,0);
|
|
|
|
// Heading Text
|
|
$this->SetFont($document_font,"B",$document_font_size + 6);
|
|
$left_col = 15;
|
|
$right_col = 105;
|
|
$width = $right_col - $left_col;
|
|
$text_row = 20;
|
|
$this->SetXY($left_col,$text_row);
|
|
$this->Cell($width,$incr + 2,getLanguageText('TEXT-SUPPLIER-ORDER'),'0',0,'C',false,'',1);
|
|
|
|
|
|
// Form Text
|
|
$this->SetFont($document_font,"B",$document_font_size + 2);
|
|
|
|
|
|
// Order Date Box
|
|
$left_col = 130;
|
|
$right_col = 200;
|
|
$top_row = 21;
|
|
$middle_row = 28;
|
|
$bottom_row = 35;
|
|
|
|
// Draw Box
|
|
$this->printBox($left_col,$top_row,$right_col,$bottom_row);
|
|
// Middle Line
|
|
$this->Line($left_col,$middle_row,$right_col,$middle_row);
|
|
// Add Heading Text
|
|
$this->SetXY($left_col + 1,$top_row + 1);
|
|
$width = $right_col - $left_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-ORDER-DATE'),'0',0,'L',false,'',1);
|
|
|
|
|
|
// Supplier Box
|
|
$left_col = 15;
|
|
$right_col = 105;
|
|
$top_row = 38;
|
|
$middle_row = 45;
|
|
$bottom_row = 70;
|
|
|
|
// Draw Box
|
|
$this->printBox($left_col,$top_row,$right_col,$bottom_row);
|
|
// Middle Line
|
|
$this->Line($left_col,$middle_row,$right_col,$middle_row);
|
|
// Add Heading Text
|
|
$this->SetXY($left_col + 1,$top_row + 1);
|
|
$width = $right_col - $left_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-SUPPLIER'),'0',0,'L',false,'',1);
|
|
|
|
|
|
// School Info Box
|
|
$left_col = 110;
|
|
$right_col = 200;
|
|
$top_row = 38;
|
|
$middle_row = 45;
|
|
$bottom_row = 70;
|
|
|
|
// Draw Box
|
|
$this->printBox($left_col,$top_row,$right_col,$bottom_row);
|
|
// Middle Line
|
|
$this->Line($left_col,$middle_row,$right_col,$middle_row);
|
|
// Add Heading Text
|
|
$this->SetXY($left_col + 1,$top_row + 1);
|
|
$width = $right_col - $left_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-ORDERED-BY'),'0',0,'L',false,'',1);
|
|
|
|
|
|
// Delivery Date Box
|
|
$left_col = 15;
|
|
$right_col = 105;
|
|
$top_row = 73;
|
|
$middle_row = 80;
|
|
$bottom_row = 87;
|
|
|
|
// Draw Box
|
|
$this->printBox($left_col,$top_row,$right_col,$bottom_row);
|
|
// Middle Line
|
|
$this->Line($left_col,$middle_row,$right_col,$middle_row);
|
|
// Add Heading Text
|
|
$this->SetXY($left_col + 1,$top_row + 1);
|
|
$width = $right_col - $left_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-DELIVERY-DATE'),'0',0,'L',false,'',1);
|
|
|
|
|
|
// Account ID Box
|
|
$left_col = 110;
|
|
$right_col = 200;
|
|
$top_row = 73;
|
|
$middle_row = 80;
|
|
$bottom_row = 87;
|
|
|
|
// Draw Box
|
|
$this->printBox($left_col,$top_row,$right_col,$bottom_row);
|
|
// Middle Line
|
|
$this->Line($left_col,$middle_row,$right_col,$middle_row);
|
|
// Add Heading Text
|
|
$this->SetXY($left_col + 1,$top_row + 1);
|
|
$width = $right_col - $left_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-ACCOUNT-ID'),'0',0,'L',false,'',1);
|
|
|
|
|
|
// Items Box
|
|
$left_col = 15;
|
|
$qty_col = 140;
|
|
$amount_col = 170;
|
|
$right_col = 200;
|
|
$top_row = 90;
|
|
$middle_row = 97;
|
|
$lower_row = 230;
|
|
$bottom_row = 255;
|
|
|
|
// Draw Box
|
|
$this->printBox($left_col,$top_row,$right_col,$bottom_row);
|
|
// Middle Line
|
|
$this->Line($left_col,$middle_row,$right_col,$middle_row);
|
|
// Lower Line
|
|
$this->Line($left_col,$lower_row,$right_col,$lower_row);
|
|
// Quantity Line
|
|
$this->Line($qty_col,$top_row,$qty_col,$lower_row);
|
|
// Amount Line
|
|
$this->Line($amount_col,$top_row,$amount_col,$lower_row);
|
|
|
|
// Add Item Heading Text
|
|
$this->SetXY($left_col + 1,$top_row + 1);
|
|
$width = $qty_col - $left_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-ITEM-DESCRIPTION'),'0',0,'L',false,'',1);
|
|
// Add Quantity Heading Text
|
|
$this->SetXY($qty_col + 2,$top_row + 1);
|
|
$width = $amount_col - $qty_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-QUANTITY'),'0',0,'C',false,'',1);
|
|
// Add Amount Heading Text
|
|
$this->SetXY($amount_col + 1,$top_row + 1);
|
|
$width = $right_col - $amount_col - 2;
|
|
$this->Cell($width,$incr + 1,getLanguageText('TEXT-AMOUNT'),'0',0,'R',false,'',1);
|
|
}
|
|
|
|
function printBox($left,$top,$right,$bottom) {
|
|
// Top Line
|
|
$this->Line($left,$top,$right,$top);
|
|
// Bottom Line
|
|
$this->Line($left,$bottom,$right,$bottom);
|
|
// Left Line
|
|
$this->Line($left,$top,$left,$bottom);
|
|
// Right Line
|
|
$this->Line($right,$top,$right,$bottom);
|
|
}
|
|
|
|
function Footer() {
|
|
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $footer_text, $school_name;
|
|
|
|
// 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',false,'',1);
|
|
|
|
$this->SetXY($left_col,$logo_row + $incr);
|
|
$this->Cell($title_width,$incr - 1,"$school_name",'0',1,'R','',1);
|
|
|
|
// Print the footer text
|
|
if (strlen($footer_text) > 0) {
|
|
$this->SetXY($left_col,$logo_row + $incr);
|
|
$this->Cell($title_width,$incr - 1,$footer_text,'0',1,'R',false,'',1);
|
|
}
|
|
|
|
$this->Image($logo_image,30,$logo_row, 50);
|
|
}
|
|
}
|
|
|
|
// 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->SetTextColor($font_red,$font_green,$font_blue);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$printTitle = false;
|
|
$pdf->addPage();
|
|
$pdf->printForm();
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
|
|
$school_name = $school_record['pac_name'];
|
|
$school_address = $school_record['address'];
|
|
$school_city = $school_record['city'];
|
|
$school_province = $school_record['province'];
|
|
$school_postal = $school_record['postal'];
|
|
$school_phone = $school_record['phone'];
|
|
|
|
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
|
|
|
|
|
|
// Get set of suppliers to process
|
|
if ($supplier_school_num == 0) $supplier_school_num = $school_num;
|
|
writeLog("school_num: $school_num");
|
|
writeLog("supplier_school_num: $supplier_school_num");
|
|
|
|
$swhere = "";
|
|
if (isset($selected_supplier_num) && $selected_supplier_num > 0) $swhere = "and soh.supplier_num = $selected_supplier_num ";
|
|
$query = "select supplier_name,supplier_num,min(delivery_date) as delivery_date " .
|
|
"from supplier_order_header as soh, suppliers as s " .
|
|
"where soh.school_num = $school_num " .
|
|
"and s.school_num = $supplier_school_num " .
|
|
"and soh.schedule_num IN ($scheduleNums) " .
|
|
"and soh.menu_num in ($menuNumbers) " .
|
|
"and soh.supplier_num = s.record_num " .
|
|
$swhere .
|
|
"GROUP BY 1,2 " .
|
|
"order by supplier_name";
|
|
writeLog($query);
|
|
$orders = db_query($query);
|
|
$numOrders = db_num_rows($orders);
|
|
|
|
if ($numOrders == 0) {
|
|
$error_message = getLanguageText('ERRORMSG-NO-SUPPLIER-ORDER-FOUND');
|
|
header("Location: /?error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
// Process each order
|
|
$page = 1;
|
|
while ($order = db_fetch_array($orders)) {
|
|
|
|
extract($order);
|
|
$order_subtotal = 0;
|
|
$taxable_total = 0;
|
|
|
|
// Get supplier info
|
|
$query = "select * from suppliers " .
|
|
"where school_num = $supplier_school_num " .
|
|
"and record_num = $supplier_num";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$supplier = db_fetch_array($results);
|
|
extract($supplier);
|
|
|
|
writeLog($supplier_name);
|
|
if (strlen($footer_text) == 0) $footer_text = $supplier_name;
|
|
|
|
|
|
// Predict the numbr of totals lines there will be
|
|
$numTotalsLines = 0;
|
|
if ($school_record['calculate_supplier_costs'] == 'Y') {
|
|
$numTotalsLines = 1;
|
|
|
|
if ($discount_rate > 0.00) $numTotalsLines++;
|
|
if (($discount_rate > 0.00) || ($taxable_order == 'Y' && $tax_rate > 0.00)) $numTotalsLines++;
|
|
if ($taxable_order == 'Y' && $tax_rate > 0.00) $numTotalsLines++;
|
|
}
|
|
|
|
|
|
// Determine the delivery offset amount for this supplier
|
|
$hotlunchtime = strtotime($delivery_date) + 60 * 60 * 12;
|
|
$hotlunchdayofweek = date("N",$hotlunchtime);
|
|
switch($delivery_date_offset) {
|
|
default:
|
|
case 'None':
|
|
$offset = 0;
|
|
break;
|
|
|
|
case 'Previous Day':
|
|
$offset = 60 * 60 * 24;
|
|
break;
|
|
|
|
case 'Two Days':
|
|
$offset = 60 * 60 * 48;
|
|
break;
|
|
|
|
case 'Three Days':
|
|
$offset = 60 * 60 * 72;
|
|
break;
|
|
|
|
case 'Friday':
|
|
if ($hotlunchdayofweek >= 5) $offset = ($hotlunchdayofweek - 5) * 60 * 60 * 24;
|
|
else $offset = (7 - (5 - $hotlunchdayofweek)) * 60 * 60 * 24;
|
|
break;
|
|
|
|
case 'Thursday':
|
|
if ($hotlunchdayofweek >= 4) $offset = ($hotlunchdayofweek - 4) * 60 * 60 * 24;
|
|
else $offset = (7 - (4 - $hotlunchdayofweek)) * 60 * 60 * 24;
|
|
break;
|
|
|
|
case 'Wednesday':
|
|
if ($hotlunchdayofweek >= 3) $offset = ($hotlunchdayofweek - 3) * 60 * 60 * 24;
|
|
else $offset = (7 - (3 - $hotlunchdayofweek)) * 60 * 60 * 24;
|
|
break;
|
|
|
|
case 'Tuesday':
|
|
if ($hotlunchdayofweek >= 2) $offset = ($hotlunchdayofweek - 2) * 60 * 60 * 24;
|
|
else $offset = (7 - (2 - $hotlunchdayofweek)) * 60 * 60 * 24;
|
|
break;
|
|
|
|
case 'Monday':
|
|
if ($hotlunchdayofweek >= 1) $offset = ($hotlunchdayofweek - 1) * 60 * 60 * 24;
|
|
else $offset = (7 - (1 - $hotlunchdayofweek)) * 60 * 60 * 24;
|
|
break;
|
|
}
|
|
|
|
|
|
$orderdate = dateString('default',time());
|
|
$deliverydate = dateString('default',$hotlunchtime - $offset);
|
|
|
|
|
|
// Get and process the order items
|
|
$query = "SELECT sp.product_name,supplier_product_num,sum(online_qty) as online_qty,sp.package_qty,package_cost " .
|
|
"FROM supplier_order_items as soi, supplier_products as sp " .
|
|
"WHERE soi.school_num = $school_num " .
|
|
"AND sp.school_num = $supplier_school_num " .
|
|
"AND soi.schedule_num IN ($scheduleNums) " .
|
|
"AND soi.menu_num in ($menuNumbers) " .
|
|
"AND soi.supplier_num = $supplier_num " .
|
|
"AND soi.supplier_product_num = sp.record_num " .
|
|
"GROUP BY 1,2,4,5 " .
|
|
"HAVING sum(online_qty) > 0 " .
|
|
"ORDER BY sp.sequence,product_name";
|
|
writeLog($query);
|
|
$order_items = db_query($query);
|
|
writeLog("num items: ".db_num_rows($order_items));
|
|
|
|
$spacing = 2;
|
|
if (db_num_rows($order_items) > 10) $spacing = 1;
|
|
|
|
$item_count = 0;
|
|
$delivery_items = array();
|
|
$delivery = array();
|
|
|
|
// Initialize the delivery array
|
|
// Get set of all classes with access to this schedule
|
|
if ($numMenuDates == 1) {
|
|
$query = "SELECT distinct class_num, entry_type, sequence FROM hotlunch_schedules_classes AS hlsc, classes AS c " .
|
|
"WHERE hlsc.school_num = $school_num " .
|
|
"AND c.school_num = $base_school_num " .
|
|
"AND hlsc.schedule_num IN ($scheduleNums) " .
|
|
"AND class_num = c.record_num " .
|
|
"ORDER BY entry_type,sequence";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results) == 0) $results = db_query("SELECT record_num AS class_num FROM classes WHERE school_num = $base_school_num ORDER BY entry_type,sequence");
|
|
}
|
|
else {
|
|
$query = "SELECT record_num AS class_num FROM classes WHERE school_num = $base_school_num ORDER BY entry_type,sequence";
|
|
$results = db_query($query);
|
|
}
|
|
|
|
while ($row = db_fetch_array($results)) {
|
|
$num = $row['class_num'];
|
|
$delivery[$num]['class_num'] = $row['class_num'];
|
|
$delivery[$num]['total_qty'] = 0;
|
|
$class_nums[] = $num;
|
|
}
|
|
|
|
$delivery['Staff']['class_num'] = 0;
|
|
$delivery['Staff']['total_qty'] = 0;
|
|
$delivery['Concession']['class_num'] = 0;
|
|
$delivery['Concession']['total_qty'] = 0;
|
|
$class_nums[] = 0;
|
|
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
|
|
$HeaderInfo = array();
|
|
|
|
$HeaderInfo['incr'] = $incr;
|
|
$HeaderInfo['left_col'] = $left_col;
|
|
$HeaderInfo['school_col'] = $school_col;
|
|
$HeaderInfo['document_font'] = $document_font;
|
|
$HeaderInfo['document_font_size'] = $document_font_size;
|
|
$HeaderInfo['order_date_col'] = $order_date_col;
|
|
$HeaderInfo['order_date_row'] = $order_date_row;
|
|
$HeaderInfo['order_date_width'] = $order_date_width;
|
|
$HeaderInfo['address_row'] = $address_row;
|
|
// $HeaderInfo['orderdate'] = $orderdate;
|
|
|
|
$HeaderInfo['orderdate'] = $orderdate;
|
|
$HeaderInfo['school_name'] = $school_name;
|
|
$HeaderInfo['school_address'] = $school_address;
|
|
$HeaderInfo['school_city'] = $school_city;
|
|
$HeaderInfo['school_phone'] = $school_phone;
|
|
$HeaderInfo['supplier_name'] = $supplier_name;
|
|
$HeaderInfo['address'] = $address;
|
|
$HeaderInfo['city'] = $city;
|
|
$HeaderInfo['province'] = $province;
|
|
$HeaderInfo['work_phone'] = $work_phone;
|
|
$HeaderInfo['fax'] = $fax;
|
|
|
|
$numOrderItems = db_num_rows($order_items);
|
|
writeLog("numOrderItems: $numOrderItems");
|
|
if ($numOrderItems == 0) {
|
|
if ($page > 1) {
|
|
$printTitle = false;
|
|
$pdf->addPage();
|
|
$pdf->printForm();
|
|
$footer_text = $supplier_name;
|
|
}
|
|
printHeaderText($HeaderInfo);
|
|
|
|
$curr_row += $incr * 12;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(100,$incr,getLanguageText('TEXT-NO-ITEMS-FOUND'),'0',1,'L',false,'',1);
|
|
|
|
$page++;
|
|
continue;
|
|
}
|
|
else {
|
|
$curr_item = 0;
|
|
$curr_row = $total_row + 1;
|
|
|
|
while ($row = db_fetch_array($order_items)) {
|
|
|
|
$curr_item++;
|
|
|
|
// Print page header info
|
|
if ($curr_row > $total_row || ($curr_item == $numOrderItems && $curr_row >= ($total_row - $numTotalsLines * 5))) {
|
|
if ($page > 1) {
|
|
$printTitle = false;
|
|
$pdf->addPage();
|
|
$pdf->printForm();
|
|
$footer_text = $supplier_name;
|
|
}
|
|
|
|
printHeaderText($HeaderInfo);
|
|
|
|
$curr_row = $account_row;
|
|
if ($numMenuDates == 1) {
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(60,$incr,$deliverydate,'0',1,'L',false,'',1);
|
|
}
|
|
|
|
$pdf->SetXY($account_col,$curr_row);
|
|
$pdf->Cell(60,$incr,$account_number,'0',1,'L',false,'',1);
|
|
|
|
$curr_row = $start_row;
|
|
|
|
if (strlen($orderTitle) > 0) {
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->Cell(100,$incr,$orderTitle,'0',1,'L',false,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr + 2;
|
|
}
|
|
|
|
if ((in_array($schedule['schedule_type'],array('Hot Lunch','Date Sensitive')) || $schedule['display_menu_date'] == 'Y') && strlen($menuTitles)) {
|
|
$pdf->SetXY($left_col + 3,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->MultiCell(180,$incr,trim($menuTitles),'0','L',false,1,'','',true,0,false,true,23,'T',true);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row = $pdf->GetY() + 2;
|
|
}
|
|
|
|
$page++;
|
|
if ($page > 50) break;
|
|
}
|
|
|
|
extract($row);
|
|
|
|
// Get supplier product name
|
|
$query = "select * from supplier_products " .
|
|
"where school_num = $supplier_school_num " .
|
|
"and supplier_num = $supplier_num " .
|
|
"and record_num = $supplier_product_num";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$row = db_fetch_array($results);
|
|
$product_name = $row['product_name'];
|
|
$description = $row['product_description'];
|
|
$supplier_code = $row['supplier_code'];
|
|
$package_qty = $row['package_qty'];
|
|
$package_cost = $row['package_cost'];
|
|
$product_num = $row['record_num'];
|
|
|
|
writeLog("package_cost: $package_cost");
|
|
|
|
$query = "SELECT sum(qty * hlmp.supplier_product_qty) " .
|
|
"FROM hotlunch_order_items AS hloi, hotlunch_menu_products AS hlmp, hotlunch_menu_items AS hlmi, hotlunch_order_header AS hloh " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hlmi.school_num = $school_num " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"AND hloi.order_num = hloh.record_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"AND hlmp.supplier_product_num = $product_num " .
|
|
"AND hlmp.menu_item_num = hlmi.record_num " .
|
|
"AND hloi.menu_num IN ($menuNumbers)";
|
|
writeLog($query);
|
|
$online_qty = db_getVal($query);
|
|
writeLog("online_qty: $online_qty");
|
|
|
|
if (intval($package_qty) == 0) $package_qty = 1;
|
|
$qty_ordered = intval(($online_qty + $package_qty - 1) / $package_qty);
|
|
$estimated_cost = $qty_ordered * $package_cost;
|
|
writeLog("package_cost: $package_cost");
|
|
writeLog("package_qty: $package_qty");
|
|
writeLog("qty_ordered: $qty_ordered");
|
|
writeLog("estimated_cost: $estimated_cost");
|
|
|
|
// Include the supplier code value if required
|
|
if ($print_supplier_code == 'Before' && strlen($supplier_code) > 0) $product_name = "$supplier_code: $product_name";
|
|
if ($print_supplier_code == 'After' && strlen($supplier_code) > 0) $product_name = "$product_name ($supplier_code)";
|
|
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(120,$incr,$product_name,0,1,'L',false,'',1);
|
|
|
|
if ($school_record['calculate_supplier_costs'] == 'Y' && $estimated_cost) {
|
|
$pdf->SetXY($qty_col + 7,$curr_row);
|
|
$text = number_format($qty_ordered,0) . " @ $currencySymbol" . number_format($package_cost,$school_record['supplier_costs_decimals']);
|
|
$pdf->Cell(16,$incr,$text,'0',1,'R',false,'',1);
|
|
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(18,$incr,$currencySymbol . number_format($estimated_cost,2),'0',1,'R',false,'',1);
|
|
}
|
|
else {
|
|
$pdf->SetXY($qty_col,$curr_row);
|
|
$pdf->Cell(16,$incr,number_format($qty_ordered,0),'0',1,'R',false,'',1);
|
|
}
|
|
|
|
$order_subtotal += $estimated_cost;
|
|
if ($row['taxable_product'] == 'Y') $taxable_total += $estimated_cost;
|
|
$curr_row += $incr;
|
|
|
|
|
|
// Print supplier code below if required
|
|
if ($print_supplier_code == 'Below' && strlen($supplier_code) > 0) {
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(100,$incr," ($supplier_code)",'0',1,'L',false,'',1);
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
// Print product description if required
|
|
if ($print_product_description == 'Y' && strlen($description)) {
|
|
$maxLength = 80;
|
|
$description = htmlspecialchars_decode($description,ENT_QUOTES);
|
|
if (strlen($description) > $maxLength) {
|
|
$words = explode(' ',$description);
|
|
$d = $words[0];
|
|
for ($i = 1; $i < count($words); $i++) {
|
|
if (strlen($d) + strlen($words[$i]) + 1 > $maxLength) break;
|
|
$d .= ' ' . $words[$i];
|
|
}
|
|
$description = $d . "...";
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$pdf->SetXY($left_col + 5,$curr_row);
|
|
$pdf->Cell(100,$incr," - $description",'0',1,'L',false,'',1);
|
|
$curr_row += $incr;
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
|
|
|
|
// Display package information if not 1 to 1
|
|
if ($package_qty != 1) {
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(100,$incr," ($online_qty / $package_qty)",'0',1,'L',false,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
$curr_row += $spacing;
|
|
|
|
$delivery_items[$item_count]['name'] = $product_name;
|
|
$delivery_items[$item_count]['num'] = $supplier_product_num;
|
|
|
|
// Get delivery report data if required
|
|
if ($generate_delivery_sheet == 'Y') {
|
|
|
|
// Get totals by division
|
|
if ($school_record['staff_meals_to_classroom'] == 'Y') {
|
|
$query = "select division,people.$ClassNumField As class_num,sum(hloi.qty * hlmp.supplier_product_qty) as quantity " .
|
|
"from hotlunch_menu_items as hlmi, " .
|
|
"hotlunch_menu_products as hlmp, " .
|
|
"supplier_products as sp, " .
|
|
"hotlunch_order_items as hloi, " .
|
|
"hotlunch_order_header as hloh, " .
|
|
"people left join classes on (classes.school_num = $base_school_num and people.school_num = $base_school_num and people.$ClassNumField = classes.record_num) " .
|
|
"where hlmi.school_num = $school_num " .
|
|
"and hlmp.school_num = $school_num " .
|
|
"and hloi.school_num = $school_num " .
|
|
"and hloh.school_num = $school_num " .
|
|
"and hloh.record_num = hloi.order_num " .
|
|
"and hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"and sp.school_num = $supplier_school_num " .
|
|
"and hlmi.menu_num in ($menuNumbers) " .
|
|
"and hlmi.record_num = hlmp.menu_item_num " .
|
|
"and hlmp.supplier_product_num = sp.record_num " .
|
|
"and hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"and hloi.active != 'N' " .
|
|
"and people.school_num = $base_school_num " .
|
|
"and people.record_num = hloi.ordered_by_num " .
|
|
"and sp.record_num = $supplier_product_num " .
|
|
"group by 1,2 " .
|
|
"order by classes.entry_type,classes.sequence";
|
|
}
|
|
else {
|
|
$query = "select division,people.$ClassNumField AS class_num,sum(hloi.qty * hlmp.supplier_product_qty) as quantity " .
|
|
"from hotlunch_menu_items as hlmi, " .
|
|
"hotlunch_menu_products as hlmp, " .
|
|
"supplier_products as sp, " .
|
|
"hotlunch_order_items as hloi, " .
|
|
"hotlunch_order_header as hloh, " .
|
|
"people left join classes on classes.school_num = $base_school_num and people.$ClassNumField = classes.record_num " .
|
|
"where hlmi.school_num = $school_num " .
|
|
"and hlmp.school_num = $school_num " .
|
|
"and hloi.school_num = $school_num " .
|
|
"and hloh.school_num = $school_num " .
|
|
"and hloh.record_num = hloi.order_num " .
|
|
"and hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"and sp.school_num = $supplier_school_num " .
|
|
"and hlmi.menu_num in ($menuNumbers) " .
|
|
"and hlmi.record_num = hlmp.menu_item_num " .
|
|
"and hlmp.supplier_product_num = sp.record_num " .
|
|
"and hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"and hloi.active != 'N' " .
|
|
"and people.record_num = hloi.ordered_by_num " .
|
|
"and people.people_type NOT IN ('Staff','Customer') " .
|
|
"and sp.record_num = $supplier_product_num " .
|
|
"and people.school_num = $base_school_num " .
|
|
"group by 1,2 " .
|
|
"order by classes.entry_type,classes.sequence";
|
|
}
|
|
|
|
writeLog($query);
|
|
$delivery_results = db_query($query);
|
|
|
|
// Save division totals to array
|
|
while ($row = db_fetch_array($delivery_results)) {
|
|
$div = $row['division'];
|
|
$qty = $row['quantity'];
|
|
$num = $row['class_num'];
|
|
|
|
$index = 'Staff';
|
|
$class_info = 'Staff';
|
|
|
|
if ($num) $index = $num;
|
|
|
|
$delivery[$index][$item_count] = $qty;
|
|
$delivery[$index]['class_num'] = $num;
|
|
if (!array_key_exists('total_qty', $delivery[$index])) $delivery[$index]['total_qty'] = 0;
|
|
$delivery[$index]['total_qty'] += $qty;
|
|
$class_num = $num;
|
|
|
|
switch($class_info_print) {
|
|
case 'Class Information':
|
|
$delivery[$index]['class_info'] = getClassInfo($class_num,'internal',1);
|
|
break;
|
|
|
|
case 'Class Label':
|
|
default:
|
|
$delivery[$index]['class_info'] = db_getVal("SELECT label_description FROM classes WHERE school_num = $school_num AND record_num = " . intval($class_num));
|
|
if (strlen($delivery[$index]['class_info']) == 0) $delivery[$index]['class_info'] = getClassInfo($class_num,'internal',1);
|
|
break;
|
|
}
|
|
$delivery[$index]['div'] = $div;
|
|
}
|
|
|
|
// Get staff totals
|
|
if ($school_record['staff_meals_to_classroom'] == 'Y') {
|
|
if ($school_record['implement_meal_locations'] == 'Y') $cwhere = "AND (people.meal_location = 0 or people.meal_location is null) ";
|
|
else $cwhere = "and (people.class_num = 0 or people.class_num is null) ";
|
|
|
|
$query = "select 'Staff',sp.record_num as product_num,sp.product_name,sum(hloi.qty * hlmp.supplier_product_qty) as quantity " .
|
|
"from hotlunch_menu_items as hlmi, " .
|
|
"hotlunch_menu_products as hlmp, " .
|
|
"supplier_products as sp, " .
|
|
"hotlunch_order_items as hloi, " .
|
|
"hotlunch_order_header as hloh, " .
|
|
"people " .
|
|
"where hlmi.school_num = $school_num " .
|
|
"and hlmp.school_num = $school_num " .
|
|
"and sp.school_num = $supplier_school_num " .
|
|
"and hloi.school_num = $school_num " .
|
|
"and hloh.school_num = $school_num " .
|
|
"and hloh.record_num = hloi.order_num " .
|
|
"and hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"and hlmi.menu_num in ($menuNumbers) " .
|
|
"and hlmi.record_num = hlmp.menu_item_num " .
|
|
"and hlmp.supplier_product_num = sp.record_num " .
|
|
"and hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"and hloi.active != 'N' " .
|
|
"and sp.record_num = $supplier_product_num " .
|
|
"and people.school_num = $base_school_num " .
|
|
"and people.record_num = hloi.ordered_by_num " .
|
|
"and people.people_type IN ('Staff','Customer') " .
|
|
$cwhere .
|
|
"group by 1,2,3";
|
|
}
|
|
else {
|
|
$query = "select 'Staff',sp.record_num as product_num,sp.product_name,sum(hloi.qty * hlmp.supplier_product_qty) as quantity " .
|
|
"from hotlunch_menu_items as hlmi, " .
|
|
"hotlunch_menu_products as hlmp, " .
|
|
"supplier_products as sp, " .
|
|
"hotlunch_order_items as hloi, " .
|
|
"hotlunch_order_header as hloh, " .
|
|
"people " .
|
|
"where hlmi.school_num = $school_num " .
|
|
"and hlmp.school_num = $school_num " .
|
|
"and sp.school_num = $supplier_school_num " .
|
|
"and hloi.school_num = $school_num " .
|
|
"and hloh.school_num = $school_num " .
|
|
"and hloh.record_num = hloi.order_num " .
|
|
"and hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"and hlmi.menu_num in ($menuNumbers) " .
|
|
"and hlmi.record_num = hlmp.menu_item_num " .
|
|
"and hlmp.supplier_product_num = sp.record_num " .
|
|
"and hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"and hloi.active != 'N' " .
|
|
"and people.school_num = $base_school_num " .
|
|
"and people.people_type IN ('Staff','Customer') " .
|
|
"and sp.record_num = $supplier_product_num " .
|
|
"and people.record_num = hloi.ordered_by_num " .
|
|
"group by 1,2,3";
|
|
}
|
|
|
|
writeLog($query);
|
|
$delivery_results = db_query($query);
|
|
|
|
// Save staff totals to array
|
|
$row = db_fetch_array($delivery_results);
|
|
$qty = 0;
|
|
if (is_array($row) && array_key_exists('quantity',$row)) $qty = $row['quantity'];
|
|
$index = 'Staff';
|
|
$delivery[$index][$item_count] = $qty;
|
|
$delivery[$index]['total_qty'] += $qty;
|
|
$delivery[$index]['class_num'] = 'Staff';
|
|
$delivery[$index]['class_info'] = 'Staff';
|
|
|
|
// Get concession totals
|
|
$query = "select 'Concession',sp.record_num as product_num,sp.product_name,sum(hloi.qty * hlmp.supplier_product_qty) as quantity " .
|
|
"from hotlunch_menu_items as hlmi, " .
|
|
"hotlunch_menu_products as hlmp, " .
|
|
"supplier_products as sp, " .
|
|
"hotlunch_order_items as hloi " .
|
|
"where hlmi.school_num = $school_num " .
|
|
"and hlmp.school_num = $school_num " .
|
|
"and sp.school_num = $supplier_school_num " .
|
|
"and hloi.school_num = $school_num " .
|
|
"and hlmi.menu_num in ($menuNumbers) " .
|
|
"and hlmi.record_num = hlmp.menu_item_num " .
|
|
"and hlmp.supplier_product_num = sp.record_num " .
|
|
"and hloi.menu_item_num = hlmp.menu_item_num " .
|
|
"and hloi.ordered_by_type = 'Concession' " .
|
|
"and hloi.active != 'N' " .
|
|
"and sp.record_num = $supplier_product_num " .
|
|
"group by 1,2,3";
|
|
writeLog($query);
|
|
$delivery_results = db_query($query);
|
|
|
|
// Save concession totals to array
|
|
$row = db_fetch_array($delivery_results);
|
|
$qty = 0;
|
|
if (is_array($row) && array_key_exists('quantity',$row)) $qty = $row['quantity'];
|
|
$index = 'Concession';
|
|
|
|
if (!array_key_exists($item_count, $delivery[$index])) $delivery[$index][$item_count] = 0;
|
|
if (!array_key_exists('total_qty', $delivery[$index])) $delivery[$index]['total_qty'] = 0;
|
|
|
|
$delivery[$index][$item_count] += $qty;
|
|
$delivery[$index]['total_qty'] += $qty;
|
|
$delivery[$index]['class_num'] = 'Concession';
|
|
$delivery[$index]['class_info'] = 'Concession';
|
|
}
|
|
|
|
$item_count++;
|
|
}
|
|
}
|
|
|
|
// Print totals and taxes if required
|
|
$total_lines = array();
|
|
$total_line = 0;
|
|
|
|
if ($school_record['calculate_supplier_costs'] == 'Y' && $order_subtotal) {
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
$order_total = $order_subtotal;
|
|
|
|
// Calculate discount if required
|
|
if ($discount_rate > 0.00) {
|
|
$discount_amount = round($order_subtotal * $discount_rate) / 100;
|
|
$order_subtotal = $order_subtotal - $discount_amount;
|
|
$order_total = $order_subtotal;
|
|
$total_lines[$total_line]['text'] = getLanguageText('TEXT-DISCOUNT') . " ";
|
|
$total_lines[$total_line]['amount'] = "- $currencySymbol" . number_format($discount_amount,2);
|
|
$total_line++;
|
|
}
|
|
|
|
// Include additional costs if there are any
|
|
if (strlen($additional_charges_text) && $additional_charges_amount > 0) {
|
|
$order_subtotal = $order_subtotal + $additional_charges_amount;
|
|
$order_total = $order_subtotal;
|
|
$total_lines[$total_line]['text'] = "$additional_charges_text ";
|
|
$total_lines[$total_line]['amount'] = "$currencySymbol" . number_format($additional_charges_amount,2);
|
|
$total_line++;
|
|
}
|
|
|
|
|
|
// Include subtotal if required
|
|
if (($discount_rate > 0.00) || ($taxable_order == 'Y' && $tax_rate > 0.00)) {
|
|
$total_lines[$total_line]['text'] = getLanguageText('TEXT-ORDER-SUBTOTAL') . " ";
|
|
$total_lines[$total_line]['amount'] = $currencySymbol . number_format($order_subtotal,2);
|
|
$total_line++;
|
|
}
|
|
|
|
// Calculate taxes if required
|
|
if ($taxable_order == 'Y' && $tax_rate > 0.00) {
|
|
$order_taxes = round($taxable_total * $tax_rate) / 100;
|
|
$order_total = $order_subtotal + $order_taxes;
|
|
$total_lines[$total_line]['text'] = "$tax_description ";
|
|
$total_lines[$total_line]['amount'] = $currencySymbol . number_format($order_taxes,2);
|
|
$total_line++;
|
|
}
|
|
|
|
$total_lines[$total_line]['text'] = getLanguageText('TEXT-ORDER-TOTAL') . " ";
|
|
$total_lines[$total_line]['amount'] = $currencySymbol . number_format($order_total,2);
|
|
|
|
|
|
// Output the total_lines array
|
|
$curr_row = $total_row - ($total_line * 5);
|
|
for ($i = 0; $i < count($total_lines); $i++) {
|
|
$text = $total_lines[$i]['text'];
|
|
$value = $total_lines[$i]['amount'];
|
|
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(100,$incr,$text,'0',1,'R',false,'',1);
|
|
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(18,$incr,$value,'0',1,'R',false,'',1);
|
|
|
|
$curr_row += 5;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
|
|
// Print order notes
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
// $pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetXY($left_col,$notes_row);
|
|
$pdf->MultiCell(190,$incr - 1,trim($order_notes),'0','L',false,1,'','',true,0,false,true,23,'T',true);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
|
|
// Get set of classes to report on if additional reports are required
|
|
// ksort($delivery);
|
|
$classes = array();
|
|
foreach ($delivery as $k => $v) {
|
|
if (strlen($k) || $k > 0) $classes[] = $k;
|
|
}
|
|
|
|
// Print the classroom delivery report if required
|
|
if ($generate_delivery_sheet == 'Y') {
|
|
|
|
// Print division totals
|
|
$delivery_totals = array();
|
|
$dpage = 1;
|
|
$last_col = 0;
|
|
$num_columns = 10;
|
|
|
|
$delivery_groups = array();
|
|
$query = "SELECT * FROM delivery_groups WHERE school_num = $school_num ORDER BY sequence,group_id";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$delivery_groups[$row['group_id']] = array();
|
|
}
|
|
|
|
$numPages = intval((count($delivery_items) + $num_columns - 1) / $num_columns);
|
|
|
|
$numClassPerPage = 40;
|
|
$numClassSets = intval((count($classes) + $numClassPerPage - 1) / $numClassPerPage);
|
|
|
|
for ($cs = 0; $cs < $numClassSets; $cs++) {
|
|
$start_class = $cs * $numClassPerPage;
|
|
$end_class = $start_class + $numClassPerPage;
|
|
if ($end_class > count($classes)) $end_class = count($classes);
|
|
|
|
// Process each page to display all the items
|
|
for ($currPage = 0; $currPage < $numPages; $currPage++) {
|
|
|
|
$printTitle = true;
|
|
$pdf->addPage();
|
|
$page++;
|
|
if ($page > 50) break;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
|
|
$col_width = 16;
|
|
$first_col_width = 20;
|
|
$curr_row = 12;
|
|
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-DATE') . " :: $deliverydate",'0',1,'L',true,'',1);
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
$curr_row += $incr + 5;
|
|
$curr_col = $start_col + $first_col_width + 1;
|
|
|
|
// Determine which items are to be printed
|
|
$start_item = $currPage * $num_columns;
|
|
$end_item = ($currPage + 1) * $num_columns;
|
|
if ($end_item > count($delivery_items)) $end_item = count($delivery_items);
|
|
|
|
// Print item names across top of report
|
|
$pdf->SetFont($document_font,"",$document_font_size - 3);
|
|
for ($i = $start_item; $i < $end_item; $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$item_title = $delivery_items[$i]['name'];
|
|
$pdf->MultiCell($col_width,$incr,$item_title,0,'C',false,0,'','',true,1,false,true,$incr * 5);
|
|
$curr_col += $col_width + 1;
|
|
}
|
|
|
|
// Print vertical lines on page
|
|
$curr_col = $start_col + $first_col_width - $col_width;
|
|
for ($i = 0; $i <= $num_columns; $i++) {
|
|
$curr_col += $col_width + 1;
|
|
$pdf->Line($curr_col,$curr_row,$curr_col,$max_rows - 5);
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$curr_row += $incr * 5;
|
|
$bg = true;
|
|
|
|
// Process each class
|
|
for ($c = $start_class; $c < $end_class; $c++) {
|
|
// Print class information
|
|
$class = $classes[$c];
|
|
|
|
if ($delivery_report_classes == 'Orders' && $delivery[$class]['total_qty'] == 0) continue;
|
|
|
|
// Get class group if required
|
|
if ($school_record['implement_delivery_groups'] == 'Y') {
|
|
if (is_numeric($class) && $class > 0) {
|
|
$group = db_getVal("SELECT delivery_group FROM classes WHERE school_num = $base_school_num AND record_num = $class LIMIT 0,1");
|
|
}
|
|
else {
|
|
$group = $class;
|
|
}
|
|
}
|
|
|
|
if ($class != 'Staff' && $class != 'Concession' && is_numeric($class) && $class > 0) {
|
|
$class_num = $class;
|
|
switch($class_info_print) {
|
|
case 'Class Information':
|
|
$delivery[$index]['class_info'] = getClassInfo($class_num,'internal',1);
|
|
break;
|
|
|
|
case 'Class Label':
|
|
default:
|
|
$delivery[$index]['class_info'] = db_getVal("SELECT label_description FROM classes WHERE school_num = $school_num AND record_num = $class_num");
|
|
if (strlen($delivery[$index]['class_info']) == 0) $delivery[$index]['class_info'] = getClassInfo($class_num,'internal',1);
|
|
break;
|
|
}
|
|
|
|
$class_id = $delivery[$index]['class_info'];
|
|
}
|
|
else {
|
|
$class_id = $class;
|
|
}
|
|
|
|
$curr_col = $start_col;
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->Cell($first_col_width,$incr,$class_id,'0',1,'L',$bg,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
|
|
$curr_col = $start_col + $first_col_width + 2;
|
|
for ($i = $start_item; $i < $end_item; $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$qty = 0;
|
|
if (array_key_exists($class, $delivery) && array_key_exists($i, $delivery[$class])) $qty = number_format($delivery[$class][$i],0);
|
|
$pdf->Cell($col_width - 1,$incr,$qty,'0',1,'C',$bg,'',1);
|
|
$curr_col += $col_width + 1;
|
|
|
|
if (array_key_exists($class, $delivery) && array_key_exists($i, $delivery[$class])) {
|
|
if (!array_key_exists($i, $delivery_totals)) $delivery_totals[$i] = 0;
|
|
$delivery_totals[$i] += $delivery[$class][$i];
|
|
if ($school_record['implement_delivery_groups'] == 'Y') {
|
|
if (is_array($group)) $group = implode(',', $group);
|
|
if (!array_key_exists($group, $delivery_groups)) $delivery_groups[$group] = array();
|
|
if (!array_key_exists($i, $delivery_groups[$group])) $delivery_groups[$group][$i] = 0;
|
|
$delivery_groups[$group][$i] += $delivery[$class][$i];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fill in the remaining sections of the report
|
|
if ($end_item < ($num_columns * ($currPage + 1)) && $bg) {
|
|
for ($i = $end_item; $i < ($num_columns * ($currPage + 1)); $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($col_width - 1,$incr,"",'0',1,'C',$bg,'',1);
|
|
$curr_col += $col_width + 1;
|
|
}
|
|
}
|
|
|
|
$curr_row += $incr + 1;
|
|
$bg = ! $bg;
|
|
}
|
|
|
|
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
// Print totals
|
|
$curr_row += 1;
|
|
$curr_col = $start_col;
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($first_col_width,$incr,getLanguageText('TEXT-TOTALS') . " ::",'0',1,'L',true,'',1);
|
|
|
|
$curr_col = $start_col + $first_col_width + 2;
|
|
|
|
for ($i = $start_item; $i < $end_item; $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$qty = "";
|
|
if ($i < count($delivery_totals)) $qty = number_format($delivery_totals[$i]);
|
|
$pdf->Cell($col_width - 1,$incr,$qty,'0',1,'C',true,'',1);
|
|
$curr_col += $col_width + 1;
|
|
}
|
|
|
|
// Fill in the remaining sections of the report
|
|
if ($end_item < ($num_columns * ($currPage + 1))) {
|
|
for ($i = $end_item; $i < ($num_columns * ($currPage + 1)); $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($col_width - 1,$incr,"",'0',1,'C',true,'',1);
|
|
$curr_col += $col_width + 1;
|
|
}
|
|
}
|
|
|
|
// Print delivery group totals if required
|
|
if ($school_record['implement_delivery_groups'] == 'Y') {
|
|
$curr_row += $incr * 3;
|
|
if ($curr_row + count($delivery_groups) * $incr > $max_rows - 40) {
|
|
$printTitle = true;
|
|
$pdf->addPage();
|
|
$curr_row = 17;
|
|
|
|
$curr_col = $start_col + $first_col_width + 1;
|
|
|
|
// Determine which items are to be printed
|
|
$start_item = $currPage * $num_columns;
|
|
$end_item = ($currPage + 1) * $num_columns;
|
|
if ($end_item > count($delivery_items)) $end_item = count($delivery_items);
|
|
|
|
// Print item names across top of report
|
|
$pdf->SetFont($document_font,"",$document_font_size - 3);
|
|
for ($i = $start_item; $i < $end_item; $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$item_title = $delivery_items[$i]['name'];
|
|
$pdf->MultiCell($col_width,$incr,$item_title,0,'C',false,0,'','',true,1,false,true,$incr * 5);
|
|
$curr_col += $col_width + 1;
|
|
}
|
|
|
|
$curr_row += $incr * 5;
|
|
}
|
|
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$bg = true;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($first_col_width,$incr,getLanguageText('TEXT-DELIVERY-GROUPS'),'0',1,'C',false,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
$curr_row += $incr + 1;
|
|
|
|
foreach ($delivery_groups as $g => $group_totals) {
|
|
$curr_col = $start_col;
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$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'];
|
|
}
|
|
|
|
$pdf->Cell($first_col_width,$incr,$gtitle,'0',1,'C',$bg,'',1);
|
|
|
|
$curr_col = $start_col + $first_col_width + 2;
|
|
|
|
for ($i = $start_item; $i < $end_item; $i++) {
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$qty = "";
|
|
if ($i < count($group_totals)) {
|
|
if (array_key_exists($i, $group_totals)) $qty = number_format($group_totals[$i]);
|
|
}
|
|
$pdf->Cell($col_width - 1,$incr,$qty,'0',1,'C',$bg,'',1);
|
|
$curr_col += $col_width + 1;
|
|
}
|
|
|
|
$curr_row += $incr + 2;
|
|
$bg = !$bg;
|
|
}
|
|
|
|
// Print vertical lines for delivery groups
|
|
$curr_col = $start_col + $first_col_width - $col_width;
|
|
$curr_row += $incr;
|
|
for ($i = 0; $i <= $num_columns; $i++) {
|
|
$curr_col += $col_width + 1;
|
|
$pdf->Line($curr_col,17,$curr_col,$curr_row - 5);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Print the product options report if required
|
|
if ($generate_options_report == 'Y') {
|
|
|
|
$curr_row = $max_rows + 1;
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
for ($i = 0; $i < count($delivery_items); $i++) {
|
|
$name = $delivery_items[$i]['name'];
|
|
$num = $delivery_items[$i]['num'];
|
|
|
|
|
|
// Get the menu item number that corresponds to this product
|
|
$query = "SELECT hlmi.record_num,hlmi.options " .
|
|
"FROM hotlunch_menu_items as hlmi, hotlunch_menu_products as hlmp " .
|
|
"WHERE hlmi.school_num = $school_num " .
|
|
"AND hlmi.menu_num IN ($menuNumbers) " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hlmp.menu_item_num = hlmi.record_num " .
|
|
"AND hlmp.supplier_product_num = $num";
|
|
writeLog($query);
|
|
$results = db_query($query);
|
|
$mitems = array();
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$mitems[] = $row['record_num'];
|
|
$options = trim($row['options']);
|
|
}
|
|
$menu_item_nums = implode(",",$mitems);
|
|
|
|
if ($include_all_items == 'N' && strlen($options) == 0) continue;
|
|
|
|
|
|
// Start if new page if required
|
|
if ($curr_row > ($max_rows - 10)) {
|
|
$printTitle = true;
|
|
$pdf->addPage();
|
|
$page++;
|
|
if ($page > 50) break;
|
|
$curr_row = 16;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-PRODUCT-OPTIONS-REPORT') . " :: $supplier_name",'0',1,'L',true,'',1);
|
|
|
|
if ($numMenuDates == 1) {
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-DATE') . " :: $deliverydate",'0',1,'L',true,'',1);
|
|
}
|
|
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr + 3;
|
|
}
|
|
|
|
|
|
// Get set of ordered items
|
|
$query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty * hlmp.supplier_product_qty) as qty " .
|
|
"FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh, hotlunch_menu_products AS hlmp " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hloh.record_num = hloi.order_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"AND hloi.menu_num IN ($menuNumbers) " .
|
|
"AND hloi.menu_item_num IN ($menu_item_nums) " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND hlmp.menu_item_num = hloi.menu_item_num " .
|
|
"AND hlmp.supplier_product_num = $num " .
|
|
"GROUP BY 1,2,3 " .
|
|
"ORDER BY 1,2,3";
|
|
$results = db_query($query);
|
|
if (db_num_rows($results) > 0) {
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,$name,'0',1,'L',true,'',1);
|
|
$curr_row += $incr + 1;
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
|
|
while ($row = db_fetch_array($results)) {
|
|
|
|
// Start if new page if required
|
|
if ($curr_row > ($max_rows - 10)) {
|
|
$printTitle = true;
|
|
$pdf->addPage();
|
|
$page++;
|
|
if ($page > 50) break;
|
|
$curr_row = 16;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-PRODUCT-OPTIONS-REPORT') . " :: $supplier_name",'0',1,'L',true,'',1);
|
|
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-DATE') . " :: $deliverydate",'0',1,'L',true,'',1);
|
|
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr + 3;
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,"$name - continued",'0',1,'L',true,'',1);
|
|
$curr_row += $incr + 1;
|
|
$pdf->SetFont($document_font,"",$document_font_size - 1);
|
|
}
|
|
|
|
extract($row);
|
|
$options_ordered = trim($options_ordered);
|
|
$options2_ordered = trim($options2_ordered);
|
|
$options3_ordered = trim($options3_ordered);
|
|
$oordered = "";
|
|
|
|
if (strlen($options_ordered)) $oordered = trim($options_ordered);
|
|
if (strlen($options2_ordered)) $oordered = trim($oordered . "\n" . $options2_ordered);
|
|
if (strlen($options3_ordered)) $oordered = trim($oordered . "\n" . $options3_ordered);
|
|
|
|
$options = str_replace("\n",", ",trim($oordered));
|
|
if (strlen(trim($options)) == 0) $options = "No Options Selected";
|
|
|
|
$width = 175;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$options,'1',1,'L',false,'',1);
|
|
|
|
$pdf->SetXY($start_col + $width,$curr_row);
|
|
$pdf->Cell(15,$incr,$qty,'1',1,'R',false,'',1);
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
$curr_row += 3;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Print the product options delivery report if required
|
|
if ($numMenuDates >= 1 && $generate_options_delivery_report == 'Y') {
|
|
|
|
// if ($_SESSION['UserInfo']['type'] == 'SuperUser') startLog("supplier_orders.print - product options delivery");
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
|
|
$page++;
|
|
if ($page > 50) break;
|
|
$curr_row = $max_rows;
|
|
|
|
$num_items = count($delivery_items);
|
|
$school_options = array();
|
|
|
|
for ($c = 0; $c < count($classes); $c++) {
|
|
|
|
$index = $classes[$c];
|
|
$class_num = $delivery[$index]['class_num'];
|
|
$class_info = '';
|
|
if (array_key_exists($index, $delivery) && array_key_exists('class_info', $delivery[$index])) $class_info = $delivery[$index]['class_info'];
|
|
$num = $class_num;
|
|
$optionsPrinted = false;
|
|
|
|
// Start a new page if required
|
|
$newPage = 'N';
|
|
$newClass = 'Y';
|
|
|
|
if ($class_num != 'Staff' && $class_num != 'Concession') {
|
|
if (($curr_row + ($num_items) * $incr) > ($max_rows - 5)) $newPage = 'Y';
|
|
if (is_numeric($class_num) && $class_num > 0) {
|
|
switch($class_info_print) {
|
|
case 'Class Information':
|
|
$delivery[$index]['class_info'] = getClassInfo($class_num,'internal',1);
|
|
break;
|
|
|
|
case 'Class Label':
|
|
default:
|
|
$delivery[$index]['class_info'] = db_getVal("SELECT label_description FROM classes WHERE school_num = $school_num AND record_num = $class_num");
|
|
if (strlen($delivery[$index]['class_info']) == 0) $delivery[$index]['class_info'] = getClassInfo($class_num,'internal',1);
|
|
break;
|
|
}
|
|
$class_info = $delivery[$index]['class_info'];
|
|
}
|
|
}
|
|
else {
|
|
$class_info = $class_num;
|
|
if (($curr_row + $num_items * $incr) > ($max_rows - 10)) $newPage = 'Y';
|
|
}
|
|
|
|
|
|
//
|
|
// Get and print the class totals
|
|
//
|
|
for ($i = 0; $i < count($delivery_items); $i++) {
|
|
$name = $delivery_items[$i]['name'];
|
|
$num = $delivery_items[$i]['num'];
|
|
|
|
// Get the menu item number that corresponds to this product
|
|
$query = "SELECT hlmi.record_num,hlmi.options " .
|
|
"FROM hotlunch_menu_items as hlmi, hotlunch_menu_products as hlmp " .
|
|
"WHERE hlmi.school_num = $school_num " .
|
|
"AND hlmi.menu_num IN ($menuNumbers) " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hlmp.menu_item_num = hlmi.record_num " .
|
|
"AND hlmp.supplier_product_num = $num";
|
|
$results = db_query($query);
|
|
$mitems = array();
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$mitems[] = $row['record_num'];
|
|
$options = trim($row['options']);
|
|
}
|
|
$menu_item_nums = implode(",",$mitems);
|
|
|
|
if ($include_all_items == 'N' && strlen($options) == 0) continue;
|
|
|
|
// Get set of ordered items
|
|
if ($class_num != 'Staff' && $class_num != 'Concession') {
|
|
$swhere = "";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $swhere = "AND hloh.ordered_by_type != 'Staff' ";
|
|
|
|
$query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) AS qty " .
|
|
"FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh, people AS p " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloh.record_num = hloi.order_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
$swhere .
|
|
"AND hloi.menu_num IN ($menuNumbers) " .
|
|
"AND hloi.menu_item_num IN ($menu_item_nums) " .
|
|
"AND hloi.ordered_by_num = p.record_num " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND p.class_num = $class_num " .
|
|
"AND p.school_num = $base_school_num " .
|
|
"GROUP BY 1,2,3 " .
|
|
"ORDER BY 1,2,3";
|
|
$options_results = db_query($query);
|
|
}
|
|
else {
|
|
if ($class_num == 'Staff') {
|
|
if ($school_record['implement_meal_locations'] == 'Y') $cwhere = "AND p.meal_location = 0 ";
|
|
else $cwhere = "AND p.class_num = 0 ";
|
|
if ($school_record['staff_meals_to_classroom'] == 'N') $cwhere = "AND hloi.ordered_by_type = 'Staff' ";
|
|
|
|
$query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) as qty " .
|
|
"FROM hotlunch_order_items as hloi, hotlunch_order_header AS hloh, people as p " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hloh.record_num = hloi.order_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"AND hloi.menu_num IN ($menuNumbers) " .
|
|
"AND hloi.menu_item_num IN ($menu_item_nums) " .
|
|
"AND hloi.ordered_by_num = p.record_num " .
|
|
"AND hloi.active != 'N' " .
|
|
$cwhere .
|
|
"AND p.school_num = $base_school_num " .
|
|
"GROUP BY 1,2,3 " .
|
|
"ORDER BY 1,2,3";
|
|
$options_results = db_query($query);
|
|
}
|
|
else {
|
|
$query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty) as qty " .
|
|
"FROM hotlunch_order_items as hloi " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloi.menu_num IN ($menuNumbers) " .
|
|
"AND hloi.menu_item_num IN ($menu_item_nums) " .
|
|
"AND hloi.ordered_by_type = 'Concession' " .
|
|
"AND hloi.active != 'N' " .
|
|
"GROUP BY 1,2,3 " .
|
|
"ORDER BY 1,2,3";
|
|
$options_results = db_query($query);
|
|
}
|
|
}
|
|
|
|
$numItems = db_num_rows($options_results);
|
|
if ($numItems == 0) continue;
|
|
if ($newClass == 'Y' && ($curr_row + ($numItems + 6) * $incr) > ($max_rows - $numItems)) $newPage = 'Y';
|
|
|
|
// Start new page if required
|
|
if ($newPage == 'Y') {
|
|
$printTitle = true;
|
|
$pdf->addPage();
|
|
$page++;
|
|
if ($page > 50) break;
|
|
$curr_row = 16;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-PRODUCT-OPTIONS-DELIVERY-REPORT') . " :: $supplier_name",'0',1,'L',true,'',1);
|
|
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-DATE') . " :: $deliverydate",'0',1,'L',true,'',1);
|
|
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr;
|
|
|
|
$newPage = 'N';
|
|
$newClass = 'Y';
|
|
}
|
|
|
|
if ($newClass == 'Y') {
|
|
if ($optionsPrinted && $i > 0) $class_info = "$class_info (continued)";
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->Cell($title_width,$incr + 1,$GlobalText['Class'] . " :: $class_info",'0',1,'L',true,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row += $incr + 3;
|
|
$newClass = 'N';
|
|
}
|
|
|
|
if (db_num_rows($options_results) > 0) {
|
|
|
|
while ($row = db_fetch_array($options_results)) {
|
|
|
|
extract($row);
|
|
$oordered = "";
|
|
$options_ordered = trim($options_ordered);
|
|
$options2_ordered = trim($options2_ordered);
|
|
$options3_ordered = trim($options3_ordered);
|
|
|
|
if (strlen($options_ordered)) $oordered = trim($options_ordered);
|
|
if (strlen($options2_ordered)) $oordered = trim($oordered . "\n" . $options2_ordered);
|
|
if (strlen($options3_ordered)) $oordered = trim($oordered . "\n" . $options3_ordered);
|
|
|
|
$options = str_replace("\n",", ",trim($oordered));
|
|
|
|
$text = $name;
|
|
if (strlen($options) > 0) $text .= " + $options";
|
|
|
|
$width = 175;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->Cell($width,$incr,$text,'1',1,'L',false,'',1);
|
|
|
|
$pdf->SetXY($start_col + $width,$curr_row);
|
|
$pdf->Cell(15,$incr,$qty,'1',1,'R',false,'',1);
|
|
$curr_row += $incr;
|
|
if ($curr_row >= 250) {
|
|
$pdf->addPage();
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->Cell($title_width,$incr + 1,$GlobalText['Class'] . " :: $class_info (continued)",'0',1,'L',true,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row += $incr + 3;
|
|
}
|
|
|
|
$optionsPrinted = true;
|
|
}
|
|
|
|
$curr_row += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// Get and print the school totals
|
|
//
|
|
$newPage = 'Y';
|
|
|
|
for ($i = 0; $i < count($delivery_items); $i++) {
|
|
|
|
$name = $delivery_items[$i]['name'];
|
|
$num = $delivery_items[$i]['num'];
|
|
|
|
|
|
// Get the menu item number that corresponds to this product
|
|
$query = "SELECT hlmi.record_num,hlmi.options " .
|
|
"FROM hotlunch_menu_items as hlmi, hotlunch_menu_products as hlmp " .
|
|
"WHERE hlmi.school_num = $school_num " .
|
|
"AND hlmi.menu_num IN ($menuNumbers) " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hlmp.menu_item_num = hlmi.record_num " .
|
|
"AND hlmp.supplier_product_num = $num";
|
|
$results = db_query($query);
|
|
$mitems = array();
|
|
while ($row = db_fetch_assoc($results)) {
|
|
$mitems[] = $row['record_num'];
|
|
$options = trim($row['options']);
|
|
}
|
|
$menu_item_nums = implode(",",$mitems);
|
|
|
|
if ($include_all_items == 'N' && strlen($options) == 0) continue;
|
|
|
|
// Get set of ordered items
|
|
$query = "SELECT options_ordered,options2_ordered,options3_ordered,sum(qty * hlmp.supplier_product_qty) as qty " .
|
|
"FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh, hotlunch_menu_products AS hlmp " .
|
|
"WHERE hloi.school_num = $school_num " .
|
|
"AND hloh.school_num = $school_num " .
|
|
"AND hlmp.school_num = $school_num " .
|
|
"AND hloh.record_num = hloi.order_num " .
|
|
"AND hloh.status NOT IN ('Inactive','Deleted') " .
|
|
"AND hloi.menu_num IN ($menuNumbers) " .
|
|
"AND hloi.menu_item_num IN ($menu_item_nums) " .
|
|
"AND hloi.active != 'N' " .
|
|
"AND hlmp.menu_item_num = hloi.menu_item_num " .
|
|
"AND hlmp.supplier_product_num = $num " .
|
|
"GROUP BY 1,2,3 " .
|
|
"ORDER BY 1,2,3";
|
|
$options_results = db_query($query);
|
|
|
|
$numOptions = db_num_rows($options_results);
|
|
if (($curr_row + $numOptions * $incr) > ($max_rows - 5)) $newPage = 'Y';
|
|
|
|
if ($newPage == 'Y') {
|
|
$printTitle = true;
|
|
$pdf->addPage();
|
|
$page++;
|
|
if ($page > 50) break;
|
|
$curr_row = 16;
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
|
|
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-PRODUCT-OPTIONS-DELIVERY-REPORT') . " :: $supplier_name",'0',1,'L',true,'',1);
|
|
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-DATE') . " :: $deliverydate",'0',1,'L',true,'',1);
|
|
|
|
|
|
$pdf->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr;
|
|
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$pdf->Cell($title_width,$incr + 1,getLanguageText('TEXT-SCHOOL-TOTALS'),'0',1,'L',true,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row += $incr + 3;
|
|
$newPage = 'N';
|
|
}
|
|
|
|
|
|
$qty = 0;
|
|
|
|
while ($row = db_fetch_array($options_results)) {
|
|
|
|
extract($row);
|
|
$options_ordered = trim($options_ordered);
|
|
$options2_ordered = trim($options2_ordered);
|
|
$options3_ordered = trim($options3_ordered);
|
|
$oordered = "";
|
|
|
|
if (strlen($options_ordered)) $oordered = trim($options_ordered);
|
|
if (strlen($options2_ordered)) $oordered = trim($oordered . "\n" . $options2_ordered);
|
|
if (strlen($options3_ordered)) $oordered = trim($oordered . "\n" . $options3_ordered);
|
|
|
|
$options = str_replace("\n",", ",trim($oordered));
|
|
if (strlen(trim($options)) == 0) $options = "";
|
|
|
|
$text = $name;
|
|
if (strlen(trim($options)) > 0) $text .= " + $options";
|
|
|
|
$width = 175;
|
|
$pdf->SetXY($start_col,$curr_row);
|
|
$pdf->SetFont($document_font,"",$document_font_size - 2);
|
|
$pdf->Cell($width,$incr,$text,'1',1,'L',false,'',1);
|
|
|
|
$pdf->SetXY($start_col + $width,$curr_row);
|
|
$pdf->Cell(15,$incr,$qty,'1',1,'R',false,'',1);
|
|
$curr_row += $incr;
|
|
|
|
if ($curr_row >= 245) $pdf->addPage();
|
|
}
|
|
|
|
if ($qty > 0) $curr_row += 2;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Output the completed PDF
|
|
$filename = "supplier-orders.pdf";
|
|
if (isset($mdate)) $filename = "supplier-orders.$mdate.pdf";
|
|
$filename = genFileName($filename);
|
|
|
|
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");
|
|
|
|
|
|
|
|
function printHeaderText($HeaderInfo) {
|
|
global $pdf, $curr_row;
|
|
|
|
extract($HeaderInfo);
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
$pdf->SetXY($order_date_col,$order_date_row);
|
|
$pdf->Cell($order_date_width,$incr + 2," $orderdate",'0',1,'L',false,'',1);
|
|
|
|
|
|
$curr_row = $address_row;
|
|
$pdf->SetXY($school_col,$curr_row);
|
|
$pdf->Cell(170,$incr,$school_name,'0',1,'L',false,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($school_col,$curr_row);
|
|
$pdf->Cell(170,$incr,$school_address,'0',1,'L',false,'',1);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($school_col,$curr_row);
|
|
$pdf->Cell(170,$incr,"$school_city, $province",'0',1,'L',false,'',1);
|
|
|
|
$curr_row += $incr * 1.5;
|
|
$pdf->SetXY($school_col,$curr_row);
|
|
$pdf->Cell(170,$incr,getLanguageText('TEXT-PHONE') . ": $school_phone",'0',1,'L',false,'',1);
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
$curr_row = $address_row;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(170,$incr,$supplier_name,'0',1,'L',false,'',1);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(170,$incr,$address,'0',1,'L',false,'',1);
|
|
|
|
$curr_row += $incr;
|
|
$s_city = "";
|
|
if ($city) $s_city = $city;
|
|
if ($province) {
|
|
if ($s_city) $s_city .= ", ";
|
|
$s_city .= $province;
|
|
}
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(170,$incr,$s_city,'0',1,'L',false,'',1);
|
|
|
|
$curr_row += $incr * 1.5;
|
|
if ($work_phone) {
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(170,$incr,getLanguageText('TEXT-PHONE') . ": $work_phone",'0',1,'L',false,'',1);
|
|
}
|
|
|
|
$curr_row += $incr;
|
|
if ($fax) {
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(170,$incr,getLanguageText('TEXT-FAX') . ": $fax",'0',1,'L',false,'',1);
|
|
}
|
|
|
|
writeLog("Header: $curr_row");
|
|
|
|
}
|
|
|
|
|
|
?>
|