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

211 lines
5.7 KiB
PHP

<?php
$ValidAccess = 2010;
require_once("include/globals.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
$action = '';
$naction = '';
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
exit();
}
$report_title = "Hot Lunches On-Line: Revenue Report";
$document_name = "Revenue Report";
$file_name = "revenue.report.pdf";
//
// 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 parameters for this document
$max_rows = 250;
$title_width = 190;
$left_col = 10;
$start_row = 10;
$incr = 4;
$cols = array();
$widths = array();
$cols[0] = $left_col;
$widths[] = 50;
$widths[] = 40;
$widths[] = 50;
$widths[] = 50;
// Setup columns based on width values
for ($i = 0; $i < count($widths); $i++) {
$cols[$i + 1] = $cols[$i] + $widths[$i];
}
$headings = array('School Year','Total','Invoices','Average');
$alignment = array('C','C','C','C');
//
// 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 + 5;
class PDF extends TCPDF {
function Header() {
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $cols, $widths, $headings, $alignment;
$row = $start_row;
// Print the header
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$this->SetFont($document_font,"B",$document_font_size + 1);
$this->SetXY($left_col,$row);
$this->Cell($title_width,$incr + 1,$report_title,'0',1,'L',true,'',1);
$this->SetFont($document_font,"B",$document_font_size);
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
$row = $row + $incr + 2;
$this->SetXY($left_col,$row);
$this->Cell($title_width,$incr + 1,$report_subtitle,'0',1,'L',true,'',1);
}
$this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
if (isset($headings) && is_array($headings) && count($headings)) {
$row += $incr * 2;
for ($i = 0; $i < count($headings); $i++) {
$col = $cols[$i];
$width = $widths[$i];
$align = $alignment[$i];
$this->SetXY($col,$row);
$this->Cell($width,$incr + 1,' ' . $headings[$i],'1',1,$align,true,'',1);
}
}
}
function Footer() {
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $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','',1);
$this->SetXY($left_col,$logo_row + $incr);
$this->Cell($title_width,$incr - 1,"$school_name",'0',1,'R','',1);
$this->Image($logo_image,10,$logo_row, 50);
$this->SetXY(20,$logo_row + 9);
$this->SetFont($document_font,"B",$document_font_size);
$this->Cell($title_width,$incr,$logo_url,'0',1,'L','',1);
}
}
$pdf= new PDF('P', 'mm', 'Letter', 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);
$pdf->addPage();
//
// Get set of records
//
$query = "SELECT school_year, sum(subtotal) as total, count(*) as invoices, round(avg(subtotal),2) as average FROM invoice_header GROUP BY 1 ORDER BY 1";
$reportData = db_query($query);
//
// Generate the report
//
$curr_row = $start_row + 3 * $incr + 1;
$count = 0;
while ($row = db_fetch_assoc($reportData)) {
// New page if current page is full
if ($curr_row > $max_rows - $incr - 2) {
$pdf->addPage();
$curr_row = $start_row + 5 * $incr;
$count = 0;
}
extract($row);
$pdf->SetFont($document_font,"",$document_font_size);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$fill = true;
if ($count % 2) $fill = false;
$count++;
// Format report line
$data = array();
$data[0] = $school_year;
$data[1] = '$' . number_format($total,2);
$data[2] = $invoices;
$data[3] = '$' . number_format($average,2);
for ($i = 0; $i < count($headings); $i++) {
$col = $cols[$i];
$width = $widths[$i];
$align = $alignment[$i];
$pdf->SetXY($col,$curr_row);
$pdf->Cell($width,$incr,$data[$i],'1',1,$align,$fill,'',1);
}
$curr_row += $incr;
}
// Output the completed PDF
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-type: application/pdf');
header("Content-Disposition: attachment; filename=$file_name");
$pdf->Output($file_name,"D");
?>