Files
HotLunches/hotlunch_reports.margins.php
T
2026-10-19 15:22:52 -07:00

746 lines
23 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
// Guarded session handling to avoid warnings and align with other modules
if (session_status() === PHP_SESSION_NONE) {
if (!empty($sessionName)) {
session_name($sessionName);
}
session_start();
}
$action = "menu-details";
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
echo("<br>\n");
$error_message = "Invalid Access";
include "form.messages.php";
exit();
}
// Check permissions
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Administration Team','Schedule Team');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = "Invalid Access";
include "form.messages.php";
return;
}
// Get parameters to script
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
if (!isset($schedule_num)) {
echo("<br>\n");
$error_message = "Invalid Access - Missing Schedule Number";
include "form.messages.php";
return;
}
// Check that there are orders for this schedule
$num = db_getVal("select count(*) from hotlunch_order_header where school_num = $school_num and schedule_num = $schedule_num and ordered_by_type != 'Concession' and status NOT IN ('Inactive','Deleted')");
if ($num == 0) {
header("Location: /?action=$action&error_code=NOORDERS");
return;
}
// Post values
include "hotlunch_schedule_post.php";
// Verify the schedule_num is a valid and active schedule
$today = date("Y-m-d",time());
$query = "select * from hotlunch_schedules " .
"where school_num = $school_num " .
"and record_num = $schedule_num";
$results = db_query($query);
if (db_num_rows($results) == 0) {
echo("<br>\n");
$error_message = "Invalid schedule number";
include "form.messages.php";
return;
}
$schedule = db_fetch_array($results);
$school_name = $school_record['school_name'];
$schedule_name = $schedule['schedule_name'];
// If this is a ScheduleTeam user check if they have permission to access this schedule
if (in_array($_SESSION['UserInfo']['type'],array('Schedule Team','Schedule Volunteer'))) {
$userNum = intval($_SESSION['UserInfo']['record_num']);
$access = db_getVal("SELECT count(*) FROM hotlunch_schedules_people WHERE school_num = $school_num AND schedule_num = $schedule_num AND user_num = $userNum");
if (!$access || $access == 0) {
header("Location: /?action=$action&error_code=INVALIDSCHEDACCESS");
return;
}
}
//
// 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;
//
// Setup PDF document
//
require("tcpdf/config/lang/eng.php");
require("tcpdf/tcpdf.php");
class PDF extends TCPDF {
function Header() {
global $school_name, $schedule_name, $document_font;
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$this->SetFont($document_font,"B",10);
$curr_row = 10;
// Page titles
$this->SetXY(15,$curr_row);
$this->Cell(186,4.7,$school_name,'0',1,'L',true);
$curr_row += 5.7;
$this->SetXY(15,$curr_row);
$this->Cell(186,4.7,$schedule_name,'0',1,'L',true);
}
function Footer() {
global $logo_row, $document_font, $document_font_size, $siteType, $school_record, $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');
$this->Cell(120,$incr - 1,getLanguageText('TEXT-PRINTED') . ": $date",'0',1,'R');
$this->SetXY(80,$logo_row + 5 + $incr);
$this->Cell(120,$incr - 1,"$school_name",'0',1,'R','',1);
$this->SetXY(80,$logo_row + 10);
$this->Cell(120,$incr - 1,getLanguageText('TEXT-MARGIN-REPORT'),'0',1,'R');
$this->SetFont($document_font,"",$document_font_size);
}
}
$pdf= new PDF('P','mm','Letter', true, 'UTF-8', false);
$pdf->addPage();
$font_red = hexdec("00");
$font_green = hexdec("00");
$font_blue = hexdec("00");
$pdf->SetTextColor($font_red,$font_green,$font_blue);
// Set parameters for this document
$max_rows = 250;
$logo_row = $max_rows + 1;
$left_col = 15;
$menu_width = 50;
$date_col = $left_col + $menu_width + 1;
$count_width = 15;
$money_width = 19;
$count_col = $date_col + $money_width + 1;
$order_revenue_col = $count_col + $count_width + 1;
$other_revenue_col = $order_revenue_col + $money_width + 1;
$supplier_cost_col = $other_revenue_col + $money_width + 1;
$other_cost_col = $supplier_cost_col + $money_width + 1;
$total_col = $other_cost_col + $money_width + 1;
$center_col = 100;
$start_row = 10;
$incr = 3.7;
$curr_row = $start_row += $incr * 3 + 1;
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(186,$incr,"Daily Summary",'0',1,'L',true);
$curr_row += $incr + 2;
// Initialize totals
$order_revenue = 0;
$other_revenue = 0;
$supplier_costs = 0;
$other_costs = 0;
$total_orders = 0;
$total_revenue = 0;
//
// Get set of menu dates
//
$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);
// Process the menu dates
if (db_num_rows($menu_dates) > 0) {
// Titles
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size - 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->MultiCell($menu_width,$incr,getLanguageText('TEXT-MENU')."\n ",'0','L',true);
$pdf->SetXY($date_col,$curr_row);
$pdf->MultiCell($money_width,$incr,getLanguageText('TEXT-DATE')."\n ",'0','L',true);
$pdf->SetXY($count_col,$curr_row);
$pdf->MultiCell($count_width,$incr,getLanguageText('TEXT-ORDERS')."\n ",'0','R',true);
$pdf->SetXY($order_revenue_col,$curr_row);
$pdf->MultiCell($money_width,$incr,getLanguageText('TEXT-TOTAL')."\n".getLanguageText('TEXT-ORDERS'),'0','R',true);
$pdf->SetXY($other_revenue_col,$curr_row);
$pdf->MultiCell($money_width,$incr,"Other\nRevenue",'0','R',true);
$pdf->SetXY($supplier_cost_col,$curr_row);
$pdf->MultiCell($money_width,$incr,"Supplier\nCosts",'0','R',true);
$pdf->SetXY($other_cost_col,$curr_row);
$pdf->MultiCell($money_width,$incr,"Other\nCosts",'0','R',true);
$pdf->SetXY($total_col,$curr_row);
$pdf->MultiCell($money_width,$incr,"Total\n ",'0','R',true);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetFont($document_font,"",$document_font_size);
$incr++;
$incr++;
$curr_row += $incr * 2;
// Process each menu date
while ($row = db_fetch_array($menu_dates)) {
$menu_num = $row['record_num'];
// Update menu totals
$query = "SELECT sum(extended_price) AS order_revenue " .
"FROM hotlunch_order_items AS hloi, hotlunch_order_header AS hloh " .
"WHERE hloi.school_num = $school_num " .
"AND hloh.school_num = $school_num " .
"AND hloi.schedule_num = $schedule_num " .
"AND hloh.schedule_num = $schedule_num " .
"AND hloh.record_num = hloi.order_num " .
"AND hloi.menu_num = $menu_num " .
"AND hloh.status IN ('Unpaid','Paid') " .
"AND hloi.active = 'Y'";
$results = db_query($query);
if (db_num_rows($results)) {
$r = db_fetch_assoc($results);
$menu_order_revenue = floatval($r['order_revenue']);
$total_revenue += $menu_order_revenue;
db_query("UPDATE hotlunch_menu_dates SET order_revenue = $menu_order_revenue WHERE record_num = $menu_num");
}
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($menu_width,$incr,$row['menu_title'],'0',1,'L',true,'',1);
$pdf->SetXY($date_col,$curr_row);
$pdf->Cell($money_width,$incr,date("M jS",strtotime($row['menu_date'])),'0',1,'L',true,'',1);
$order_count = db_getVal("SELECT count(distinct order_num) FROM hotlunch_order_items AS hloi, people AS p " .
"WHERE hloi.school_num = $school_num " .
"AND p.school_num = $school_num " .
"AND p.record_num = hloi.ordered_by_num " .
"AND schedule_num = $schedule_num " .
"AND menu_num = $menu_num " .
"AND hloi.active = 'Y'");
$total_orders += $order_count;
$pdf->SetXY($count_col,$curr_row);
$pdf->Cell($count_width,$incr,$order_count,'0',1,'R',true,'',1);
// Calculate totals for menu date
$order_revenue = $menu_order_revenue;
$other_revenue += $row['other_revenue'];;
$other_costs += $row['other_costs'];
$amount = $currencySymbol . number_format($order_revenue,2);
$pdf->SetXY($order_revenue_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($row['other_revenue'],2);
$pdf->SetXY($other_revenue_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
// Get costs
$cost = getSupplierMargin($schedule_num,$menu_num);
$supplier_costs += $cost;
$amount = $currencySymbol . number_format($cost,2);
$pdf->SetXY($supplier_cost_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($row['other_costs'],2);
$pdf->SetXY($other_cost_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$total = $order_revenue + $row['other_revenue'] - $cost - $row['other_costs'];
$amount = $currencySymbol . number_format($total,2);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$curr_row += $incr + 1;
if ($curr_row > $max_rows - $incr * 5) {
$pdf->addPage();
$curr_row = $start_row;
}
}
}
// Print totals
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell($menu_width + $money_width + 1,$incr,"Schedule Totals :: ",'0',1,'R',true,'',1);
$pdf->SetXY($count_col,$curr_row);
$pdf->Cell($count_width,$incr,$total_orders,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($total_revenue,2);
$pdf->SetXY($order_revenue_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($other_revenue,2);
$pdf->SetXY($other_revenue_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($supplier_costs,2);
$pdf->SetXY($supplier_cost_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($other_costs,2);
$pdf->SetXY($other_cost_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
$amount = $currencySymbol . number_format($total_revenue + $other_revenue - $supplier_costs - $other_costs,2);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$amount,'0',1,'R',true,'',1);
//
// Generate the table of counts and totals
//
$curr_row += $incr + 5;
if ($curr_row > $max_rows - $incr * 5) {
$pdf->addPage();
$curr_row = $start_row;
}
// Print order source summary
$query = "select source,count(*) as num,sum(order_total) as total,sum(amount_paid) as collected,sum(discount_amount) as discount " .
"from hotlunch_order_header " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and ordered_by_type != 'Concession' " .
"and status NOT IN ('Inactive','Deleted') " .
"group by source " .
"order by source";
$results = db_query($query);
// Get total number of orders
$query = "select count(*) ".
"from hotlunch_order_header " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and ordered_by_type != 'Concession' " .
"and status NOT IN ('Inactive','Deleted')";
$total_num = db_getVal($query);
if (db_num_rows($results)) {
$curr_row += 1;
$curr_col = $left_col;
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(39,$incr,"Order Source",'0',1,'L',true,'',1);
$curr_col += 40;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(20,$incr,"Count",'0',1,'C',true,'',1);
$curr_col += 21;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(20,$incr,"%",'0',1,'C',true,'',1);
$curr_col += 21;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(34,$incr,"Total",'0',1,'R',true,'',1);
$curr_col += 35;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(34,$incr,"Discount",'0',1,'R',true,'',1);
$curr_col += 35;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(34,$incr,"Net",'0',1,'R',true,'',1);
$curr_col += 35;
// $pdf->SetXY($curr_col,$curr_row);
// $pdf->Cell(25,$incr,"Collected",'0',1,'R',true,'',1);
// $curr_col += 26;
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$curr_row += $incr + 1;
$totals = array();
while ($row = db_fetch_array($results)) {
extract($row);
$curr_col = $left_col;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(39,$incr,$source,'0',1,'L',true,'',1);
$curr_col += 40;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(20,$incr,$num,'0',1,'C',true,'',1);
$curr_col += 21;
$totals[0] += $num;
$percentage = number_format(round($num / $total_num * 1000) / 10,1) . "%";
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(20,$incr,$percentage,'0',1,'C',true,'',1);
$curr_col += 21;
$pdf->SetXY($curr_col,$curr_row);
$net_total = $total + $discount;
$pdf->Cell(34,$incr,$currencySymbol . number_format($net_total,2),'0',1,'R',true,'',1);
$curr_col += 35;
$totals[1] += $net_total;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(34,$incr,$currencySymbol . number_format($discount,2),'0',1,'R',true,'',1);
$curr_col += 35;
$totals[2] += $discount;
$pdf->SetXY($curr_col,$curr_row);
$net = $total;
$pdf->Cell(34,$incr,$currencySymbol . number_format($net,2),'0',1,'R',true,'',1);
$curr_col += 35;
$totals[3] += $net;
$curr_row += $incr + 1;
}
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$curr_col = $left_col;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(39,$incr,"TOTAL",'0',1,'L',true,'',1);
$curr_col += 40;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(20,$incr,$totals[0],'0',1,'C',true,'',1);
$curr_col += 21;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(20,$incr,"",'0',1,'C',true,'',1);
$curr_col += 21;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(34,$incr,$currencySymbol . number_format($totals[1],2),'0',1,'R',true,'',1);
$curr_col += 35;
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell(34,$incr,$currencySymbol . number_format($totals[2],2),'0',1,'R',true,'',1);
$curr_col += 35;
$pdf->SetXY($curr_col,$curr_row);
$net = $total - $discount;
$pdf->Cell(34,$incr,$currencySymbol . number_format($totals[3],2),'0',1,'R',true,'',1);
$curr_col += 35;
}
if ($curr_row > $max_rows - $incr * 18) {
$pdf->addPage();
$curr_row = $start_row;
}
// Title for order summary
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"",$document_font_size + 1);
$curr_row += $incr + 5;
$pdf->SetFont($document_font,"B",$document_font_size + 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(186,$incr + 1,"Order Summary",'0',1,'L',true,'',1);
$curr_row += $incr + 2;
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetFont($document_font,"",$document_font_size);
// Get order total
$query = "select sum(extended_price) from hotlunch_order_items " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and ordered_by_type != 'Concession' " .
"and active != 'N'";
$order_total = db_getVal($query);
// Get total discount
$query = "select sum(discount_amount) as discount,sum(order_total) as total,sum(amount_paid) as amount_collected " .
"from hotlunch_order_header " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and status NOT IN ('Inactive','Deleted') " .
"and ordered_by_type != 'Concession'";
$results = db_query($query);
$row = db_fetch_array($results);
$discount = $row['discount'];
$total = $row['total'];
$amount_collected = $row['amount_collected'];
$net_order = $order_total + $other_revenue - $discount;
// Output the order total
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Orders Total :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($order_total,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
// Output order discount amount if there is one
if ($discount > 0) {
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Total Discount Given :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($discount,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
}
// Output the other revenue
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Other Revenue :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($other_revenue,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
// Output the net order revenue
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Revenue Total :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($net_order,2),'0',1,'R',true,'',1);
$curr_row += $incr + 5;
if ($curr_row > $max_rows - $incr * 5) {
$pdf->addPage();
$curr_row = $start_row;
}
// Costs Summary
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size + 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr + 1,"Costs Summary",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr + 1,"Costs",'0',1,'R',true,'',1);
$curr_row += $incr + 2;
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetFont($document_font,"",$document_font_size);
// Supplier costs
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Supplier Costs",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($supplier_costs,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
// Other costs
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Other Costs",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($other_costs,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
// Output the total costs
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Total Costs",'0',1,'L',true,'',1);
$total_costs = $supplier_costs + $other_costs;
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($total_costs,2),'0',1,'R',true,'',1);
$curr_row += $incr + 5;
if ($curr_row > $max_rows - $incr * 5) {
$pdf->addPage();
$curr_row = $start_row;
}
// Schedule Summary
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size + 1);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr + 1,"Schedule Summary",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr + 1,"Net",'0',1,'R',true,'',1);
$curr_row += $incr + 2;
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetFont($document_font,"",$document_font_size);
// Total Orders
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Total Revenue :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($net_order,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
// Total costs
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Total Costs",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,"- $currencySymbol" . number_format($total_costs,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
$net_revenue = $net_order - $total_costs;
$est_revenue = $net_order - $estimated_supplier_costs;
// Determine if there are complimentary orders
$complimentary = db_getVal("select sum(order_total) from hotlunch_order_header where school_num = $school_num and schedule_num = $schedule_num and status = 'Complimentary'");
if ($complimentary) {
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Total of Complimentary Orders :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,"- $currencySymbol" . number_format($complimentary,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
$net_revenue -= $complimentary;
$est_revenue -= $complimentary;
}
// Schedule total
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Schedule Net Revenue",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($net_revenue,2),'0',1,'R',true,'',1);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$curr_row += $incr + 3;
// Output order discount amount if there is one
if ($discount > 0) {
$pdf->SetXY($left_col,$curr_row);
$pdf->Cell(166,$incr,"Total Discount Given :: ",'0',1,'L',true,'',1);
$pdf->SetXY($total_col,$curr_row);
$pdf->Cell($money_width,$incr,$currencySymbol . number_format($discount,2),'0',1,'R',true,'',1);
$curr_row += $incr + 1;
}
// Output the completed PDF
$filename = "schedule-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");
?>