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

207 lines
5.1 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();
}
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-INVALID-ACCESS');
include "form.messages.php";
exit();
}
// Ensure that only valid user types have access to this module
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team');
if (checkPermission($AllowedUserTypes) != 1) {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
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 = getLanguageText('ERRORMSG-INVALID-ACCESS');
include "form.messages.php";
return;
}
// Resolve school number if not already defined
if (!isset($school_num)) {
if (isset($_SESSION['school_num'])) {
$school_num = intval($_SESSION['school_num']);
} elseif (isset($school_record['school_num'])) {
$school_num = intval($school_record['school_num']);
} else {
echo("<br>\n");
$error_message = getLanguageText('ERRORMSG-INVALID-ACCESS');
include "form.messages.php";
return;
}
}
// Verify the schedule_num is a valid and active schedule
$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 = getLanguageText('ERRORMSG-INVALID-ACCESS');
include "form.messages.php";
return;
}
$schedule = db_fetch_array($results);
//
// Setup the PDF
//
$document_font = isset($school_record['document_font']) ? $school_record['document_font'] : '';
if (strlen($document_font) == 0) $document_font = "Helvetica";
$document_font_weight = "";
$document_text_color = "#000000";
$document_font_size = 10;
$max_rows = 250;
$left_col = 20;
$middle_col = 100;
//
// Setup PDF document
//
require("tcpdf/config/lang/eng.php");
require("tcpdf/tcpdf.php");
$logo_url = isset($school_record['logo_url']) ? $school_record['logo_url'] : '';
$logo_image = "images/" . (isset($school_record['logo_image']) ? $school_record['logo_image'] : '');
$logo_row = $max_rows + 5;
class PDF extends TCPDF {
function Header() {
}
function Footer() {
}
}
// 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);
$school_name = isset($school_record['school_name']) ? $school_record['school_name'] : 'School';
// Currency symbol fallback
$currency_symbol = isset($school_record['currency_symbol']) ? $school_record['currency_symbol'] : '$';
// Set parameters for this document
$max_rows = 241;
$title_col = 20;
$date_col = 20;
$amount_col = 45;
$start_row = 23;
$curr_row = $start_row;
$incr = 5;
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",10);
$pdf->SetXY($title_col,10);
$pdf->Cell(80,$incr + 1,$school_name,'0',1,'L');
$pdf->SetXY($title_col,15);
$pdf->Cell(80,$incr + 1,(isset($schedule['schedule_name']) ? $schedule['schedule_name'] : '') . " - Collections Report",'0',1,'L');
$pdf->SetFont($document_font,"",9);
// Get set of values to display
$query = "select paid_date,sum(amount_paid) collected " .
"from hotlunch_order_header " .
"where school_num = $school_num " .
"and schedule_num = $schedule_num " .
"and status = 'Paid' " .
"group by 1 " .
"order by 1";
$results = db_query($query);
$total = 0;
while ($row = db_fetch_array($results)) {
extract($row);
$total += $collected;
$pdf->SetXY($date_col,$curr_row);
$pdf->Cell(30,$incr,$paid_date,'0',1,'L');
$pdf->SetXY($amount_col,$curr_row);
$pdf->Cell(20,$incr,$currency_symbol . number_format($collected,2),'0',1,'R');
$curr_row += $incr;
}
if ($total > 0) {
$curr_row += $incr;
$pdf->SetXY($date_col,$curr_row);
$pdf->Cell(30,$incr,"TOTAL:",'0',1,'L',true);
$pdf->SetFont($document_font,"B",9);
$pdf->SetXY($amount_col,$curr_row);
$pdf->Cell(20,$incr,$currency_symbol . number_format($total,2),'0',1,'R',true);
}
// Output the completed PDF
$filename = "collect.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");
?>