\n"); $error_message = "Invalid Access"; include "form.messages.php"; exit(); } // Check permissions $AllowedUserTypes = array('SuperUser','System Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Financial','Financial Team'); if (checkPermission($AllowedUserTypes) != 1) { echo("
\n"); $error_message = "Invalid Access"; include "form.messages.php"; exit(); } $school_name = $school_record['school_name']; // // 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, $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,getLanguageText('TEXT-ANNUAL-SUMMARY'),'0',1,'L',true); } function Footer() { global $logo_row, $document_font, $document_font_size, $siteType, $school_record, $incr, $school_name; // Add logo to page $this->Image("images/".$school_record['logo_image'],10,$logo_row + 5,50); $this->SetFont($document_font,"",$document_font_size - 1); $this->SetXY(80,$logo_row + 5); $date = dateString('datetime'); $this->Cell(120,$incr - 1,getLanguageText('TEXT-PRINTED') . ": $date",'0',1,'R'); $this->SetFont($document_font,"",$document_font_size); $this->SetXY(80,$logo_row + 5 + $incr); $this->Cell(120,$incr - 1,"$school_name",'0',1,'R','',1); } } // 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); $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; // // Get set of schedules // $query = "SELECT distinct schedule_num FROM hotlunch_menu_dates AS hlmd, hotlunch_schedules AS hls " . "WHERE hlmd.school_num = $school_num " . "AND hlmd.schedule_num = hls.record_num " . "AND hls.status IN ('Active','Completed','Closed') " . "ORDER BY schedule_num"; $schedules = db_query($query); while ($row = db_fetch_assoc($schedules)) { extract($row); include "hotlunch_schedule_post.php"; } // 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 hlmd.* FROM hotlunch_menu_dates AS hlmd, hotlunch_schedules AS hls " . "WHERE hlmd.school_num = $school_num " . "AND hlmd.schedule_num = hls.record_num " . "AND hls.status IN ('Active','Completed','Closed') " . "ORDER BY 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); $incr--; $incr--; $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']; $schedule_num = $row['schedule_num']; $order_count = db_getVal("SELECT count(distinct order_num) FROM hotlunch_order_items " . "WHERE school_num = $school_num AND menu_num = $menu_num AND active != 'N'"); if ($order_count == 0) continue; // Update menu totals $query = "SELECT sum(extended_price) AS order_revenue FROM hotlunch_order_items " . "WHERE school_num = $school_num " . "AND schedule_num = $schedule_num " . "AND menu_num = $menu_num " . "and 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"); } // Check for orders for this menu $numItems = db_getVal("SELECT count(*) FROM hotlunch_order_items WHERE school_num = $school_num AND menu_num = $menu_num"); if ($numItems == 0 && $menu_order_revenue == 0 && $row['other_revenue'] == 0 && $row['other_costs'] == 0) continue; $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 Y",strtotime($row['menu_date'])),'0',1,'L',true,'',1); $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($menu_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 if ($row['supplier_costs'] > 0) $cost = $row['supplier_costs']; else $cost = getSupplierCosts($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 = $menu_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,getLanguageText('TEXT-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($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($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($order_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); // Output the completed PDF $filename = "annual-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"); ?>