Files
HotLunches/hotlunch_orders.print.inc.php
2026-10-19 15:22:52 -07:00

333 lines
11 KiB
PHP

<?php
require_once("include/globals.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
echo("<br>\n");
$error_message = "Invalid Access";
include "form.messages.php";
exit();
}
$school_name = $school_record['school_name'];
// Set parameters for this document
$max_rows = 235;
$title_col = 20;
$item_col = 25;
$qty_col = 125;
$price_col = 138;
$extended_col = 152;
$total_col = 172;
$extended_width = 15;
$total_width = 18;
$start_row = 8;
$curr_row = $start_row;
$incr = 3.8;
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",10);
if ($_SESSION['UserInfo']['type'] == 'Parent') $name .= ' (' . $_SESSION['UserInfo']['first_name'] . ' ' . $_SESSION['UserInfo']['last_name'] . ' - ' . $_SESSION['UserInfo']['userid'] . ')';
if ($_SESSION['UserInfo']['type'] == 'Staff') $name = $_SESSION['UserInfo']['first_name'] . ' ' . $_SESSION['UserInfo']['last_name'];
$name .= " - $status";
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(80,$incr + 1,getLanguageText('TEXT-NAME') . ': '. $name,'0',1,'L',false,'',1);
if (isset($teacher_info)) {
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(64,$incr + 1,$teacher_info,'0',1,'R',false,'',1);
$pdf->SetFont($document_font,"B",10);
}
$curr_row += $incr;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(80,$incr + 1,$schedule['schedule_name'],'0',1,'L',false,'',1);
if (isset($class_info)) {
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(64,$incr + 1,$class_info,'0',1,'R',false,'',1);
$pdf->SetFont($document_font,"B",10);
}
$curr_row += $incr + 2;
$pdf->SetFont($document_font,"",9);
// Get menu dates for this schedule
$query = "select * from hotlunch_menu_dates " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"order by sequence,menu_date";
$menu_dates = db_query($query);
$order_total = 0;
$page = 1;
while ($menu_date = db_fetch_array($menu_dates)) {
$menu_num = $menu_date['record_num'];
$menu_title = $menu_date['menu_title'];
if ($schedule['schedule_type'] == 'Hot Lunch' || $schedule['schedule_type'] == 'Date Sensitive' || $schedule['display_menu_date'] == 'Y') $menu_title .= " - " . date("l F jS, Y",strtotime($menu_date['menu_date']));
// Skip menu date if print format is set to "With Items" and no items have been ordered
if ($schedule['schedule_print_format'] == "With Items") {
$numItems = db_getVal("SELECT count(*) FROM hotlunch_order_items " .
"WHERE school_num = $school_num " .
"AND ordered_by_num = $ordered_by_num " .
"AND schedule_num = $schedule_num " .
"AND menu_num = $menu_num " .
"AND active != 'N'");
if ($numItems == 0) continue;
}
// Get menu items for this menu date
$query = "select * from hotlunch_menu_items " .
"where school_num = $school_num " .
"and menu_num = $menu_num " .
"order by sequence";
$menu_items = db_query($query);
$num_items = db_num_rows($menu_items);
// Print menu header if required
if (($curr_row + $incr * 3) >= $max_rows) {
$pdf->addPage();
$page++;
$curr_row = $start_row;
$pdf->SetFont($document_font,"B",10);
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(80,$incr + 1,$name,'0',1,'L',false,'',1);
if (isset($teacher_info)) {
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(64,$incr + 1,"Page :: $page",'0',1,'R',false,'',1);
}
$curr_row += $incr;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(80,$incr + 1,$schedule['schedule_name'],'0',1,'L',false,'',1);
$curr_row += $incr + 2;
}
$pdf->SetFont($document_font,"B",9);
$curr_row += 1;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(170,$incr,$menu_title,'0',1,'L',true,'',1);
$pdf->SetFont($document_font,"",9);
$curr_row += $incr;
$menu_total = 0;
$menu_count = 0;
$item_count = 0;
while ($menu_item = db_fetch_array($menu_items)) {
extract($menu_item);
// Get student order entry if there is one
$query = "select * from hotlunch_order_items " .
"where school_num = $school_num " .
"and ordered_by_num = $ordered_by_num " .
"and schedule_num = $schedule_num " .
"and menu_num = $menu_num " .
"and menu_item_num = $record_num " .
"and active != 'N'";
$orders = db_query($query);
$order = db_fetch_array($orders);
if (is_array($order)) {
$qtyvalue = $order['qty'];
$options_ordered = $order['options_ordered'];
$options2_ordered = $order['options2_ordered'];
$options3_ordered = $order['options3_ordered'];
$item_price = $online_price;
if ($order_header['price_category'] == 'Regular') {
if ($source == 'On-Line') $item_price = $online_price;
else $item_price = $offline_price;
}
else {
if ($order_header['price_category'] == 'Special 1') $item_price = $special_price1;
if ($order_header['price_category'] == 'Special 2') $item_price = $special_price2;
if ($order_header['price_category'] == 'Special 3') $item_price = $special_price3;
}
$item_price = $order['menu_item_price'];
$ltotal = $qtyvalue * $item_price;
$line_total = number_format($ltotal,2);
$menu_total += $ltotal;
$order_total += $ltotal;
$menu_count++;
if (db_num_rows($orders) == 0) continue;
$item_count++;
$pdf->SetXY($item_col,$curr_row);
$pdf->Cell(95,$incr,$item_title,'0',1,'L',false,'',1);
if ($display_price == 'Y') {
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(5,$incr,"$qtyvalue x",'0',1,'R');
$pdf->SetXY($price_col,$curr_row);
$pdf->Cell(12,$incr,$currencySymbol . number_format($item_price,2) . " =",'0',1,'R');
$pdf->SetXY($extended_col,$curr_row);
$pdf->Cell($extended_width,$incr,$school_record['currency_symbol'] . $line_total,'0',1,'R');
}
else {
if ($qtyvalue > 1) {
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(5,$incr,"x $qtyvalue",'0',1,'R');
}
}
$curr_row += $incr;
// Display item options
$options_ordered = trim($options_ordered);
$options2_ordered = trim($options2_ordered);
$options3_ordered = trim($options3_ordered);
if (strlen($options2_ordered)) $options_ordered .= "\n$options2_ordered";
if (strlen($options3_ordered)) $options_ordered .= "\n$options3_ordered";
if (strlen($options_ordered) > 0) {
$pdf->SetFont($document_font,"",8);
$options = str_replace("\n",", ",trim($options_ordered));
$pdf->SetXY($item_col + 5,$curr_row);
$pdf->Cell(80,$incr,"($options)",'0',1,'L',false,'',1);
$curr_row += $incr;
$pdf->SetFont($document_font,"",9);
}
}
}
if ($menu_total > 0) {
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($total_col,$curr_row - $incr);
$pdf->Cell($total_width,$incr,$currencySymbol . number_format($menu_total,2),'1',1,'R');
$pdf->SetFont($document_font,"",9);
}
// If no items were ordered
if ($item_count == 0) {
if ($menu_count > 0) {
$pdf->SetXY($item_col,$curr_row);
$pdf->Cell(80,$incr,"--- " . getLanguageText('TEXT-NO-ITEMS-ORDERED') . " ---",'0',1,'L');
}
$curr_row += $incr;
}
if ($menu_count > 0) $curr_row += 1;
}
$curr_row += 1;
if (($curr_row + $incr * 4) > $max_rows) {
$pdf->addPage();
$page++;
$curr_row = $start_row;
$pdf->SetFont($document_font,"B",10);
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(80,$incr + 1,$name,'0',1,'L',false,'',1);
if (isset($teacher_info)) {
$pdf->SetXY($qty_col,$curr_row);
$pdf->Cell(64,$incr + 1,"Page :: $page",'0',1,'R');
}
$curr_row += $incr;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(80,$incr + 1,$schedule['schedule_name'],'0',1,'L',false,'',1);
$curr_row += $incr + 2;
}
// Print order total line
if ($order_total > 0) {
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(170,$incr," ",'0',1,'R',true);
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($extended_col - 60,$curr_row);
$pdf->Cell(50,$incr,"ORDER TOTAL ::",'0',1,'R',true);
$pdf->SetXY($extended_col,$curr_row);
$pdf->Cell($extended_width,$incr,$currencySymbol . number_format($order_total,2),'0',1,'R',true);
$curr_row += $incr + 1;
if ($order_header['discount_amount'] != 0) {
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(170,$incr," ",'0',1,'R',true);
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($extended_col - 60,$curr_row);
$pdf->Cell(50,$incr,"DISCOUNT ::",'0',1,'R',true);
$pdf->SetXY($extended_col,$curr_row);
$pdf->Cell($extended_width,$incr,$currencySymbol . number_format($order_header['discount_amount'],2),'0',1,'R',true);
$curr_row += $incr + 1;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(170,$incr," ",'0',1,'R',true);
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($extended_col - 60,$curr_row);
$pdf->Cell(50,$incr,"NET TOTAL ::",'0',1,'R',true);
$pdf->SetXY($extended_col,$curr_row);
$pdf->Cell($extended_width,$incr,$currencySymbol . number_format($order_header['order_total'],2),'0',1,'R',true);
$curr_row += $incr + 1;
}
// Calculate taxes on the order
if ($schedule['tax_rate'] > 0) {
$tax_amount = $order_header['order_total'] * $schedule['tax_rate'] / 100;
$grand_total = $order_header['order_total'] + $tax_amount;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(170,$incr," ",'0',1,'R',true);
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($extended_col - 60,$curr_row);
$pdf->Cell(50,$incr,$schedule['tax_description'] . " ::",'0',1,'R',true,'',1);
$pdf->SetXY($extended_col,$curr_row);
$pdf->Cell($extended_width,$incr,$currencySymbol . number_format($tax_amount,2),'0',1,'R',true);
$curr_row += $incr + 1;
$pdf->SetXY($title_col,$curr_row);
$pdf->Cell(170,$incr," ",'0',1,'R',true);
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($extended_col - 60,$curr_row);
$pdf->Cell(50,$incr,"TOTAL ::",'0',1,'R',true);
$pdf->SetXY($extended_col,$curr_row);
$pdf->Cell($extended_width,$incr,$currencySymbol . number_format($grand_total,2),'0',1,'R',true);
$curr_row += $incr + 1;
}
}
?>