210 lines
5.7 KiB
PHP
210 lines
5.7 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
echo("Invalid Access");
|
|
exit();
|
|
}
|
|
|
|
|
|
//
|
|
// Setup the PDF
|
|
//
|
|
$template_file = "Blank.pdf";
|
|
// Use dejavusans - bundled with TCPDF and supports bold/italic
|
|
$resolved_font = "dejavusans";
|
|
|
|
// Force exact physical page size (no library/config defaults)
|
|
// Letter: 8.5in x 11in => 215.9mm x 279.4mm
|
|
// Legal: 8.5in x 14in => 215.9mm x 355.6mm
|
|
$paperSize = '';
|
|
if (array_key_exists('paperSize', $_GET) && strlen($_GET['paperSize'])) $paperSize = $_GET['paperSize'];
|
|
if (array_key_exists('paperSize', $_POST) && strlen($_POST['paperSize'])) $paperSize = $_POST['paperSize'];
|
|
if (!in_array($paperSize, array('Letter', 'Legal'))) $paperSize = 'Letter';
|
|
|
|
$pageFormat = array(215.9, 279.4); // Letter portrait (default)
|
|
if ($paperSize === 'Legal') {
|
|
$pageFormat = array(215.9, 355.6); // Legal portrait
|
|
}
|
|
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 10;
|
|
|
|
|
|
//
|
|
// Setup PDF document - use TCPDF instead of FPDI for reliable font support
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
$pdf = new TCPDF('P', 'mm', $pageFormat, true, 'UTF-8', false);
|
|
|
|
// Disable header/footer
|
|
$pdf->setPrintHeader(false);
|
|
$pdf->setPrintFooter(false);
|
|
|
|
// Set margins
|
|
$pdf->SetMargins(10, 10, 10);
|
|
$pdf->SetAutoPageBreak(false);
|
|
|
|
// Add first page and set font
|
|
$pdf->AddPage();
|
|
$pdf->SetFont($resolved_font, '', $document_font_size);
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
|
|
$school_name = $school_record['school_name'];
|
|
|
|
// Setup parameters for this document
|
|
$max_rows = 250;
|
|
$columns = array(30,80,120);
|
|
$start_row = 25;
|
|
$curr_row = $max_rows + 10;
|
|
$incr = 5;
|
|
|
|
|
|
// Execute the query statement
|
|
$query = $_GET['query'];
|
|
$transactions = db_query($query);
|
|
|
|
$report_title = str_replace('<br>',' ',$_GET['title']);
|
|
$report_title = str_replace("Payment Summary Report ","",$report_title);
|
|
$report_title = str_replace('\n',"",$report_title);
|
|
$column_title = $_GET['col1'];
|
|
|
|
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
|
|
$total = 0;
|
|
$page = 0;
|
|
$count = 0; // initialize row counter used for alternating backgrounds
|
|
|
|
while ($row = db_fetch_array($transactions)) {
|
|
extract($row);
|
|
|
|
if ($curr_row > $max_rows) {
|
|
// Put page titles on the page whenever a page is full
|
|
if ($page > 0) $pdf->addPage();
|
|
|
|
$pdf->SetFont($resolved_font,"B",$document_font_size + 2);
|
|
$pdf->SetXY(10,8);
|
|
$pdf->Cell(250,$incr,"$school_name :: Payment Summary Report Report",'0',1,'L');
|
|
|
|
$pdf->SetFont($resolved_font,"B",$document_font_size + 1);
|
|
$pdf->SetXY(10,13);
|
|
$pdf->Cell(250,$incr,$report_title,'0',1,'L');
|
|
$pdf->SetFont($resolved_font,"B",$document_font_size);
|
|
|
|
$curr_row = 25;
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
|
|
$cnum = 0;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$column_title,'0',1,'L',true);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,"Payment Amount",'0',1,'R',true);
|
|
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
$pdf->SetFont($resolved_font,"",$document_font_size);
|
|
$curr_row += $incr;
|
|
$page++;
|
|
}
|
|
|
|
$bg = false;
|
|
if ($count % 2) $bg = true;
|
|
|
|
$col1 = $row['col1'];
|
|
if ($col1 == 'Check') $col1 = getLanguageText('TEXT-CHECK');
|
|
|
|
$cnum = 0;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$col1,'0',1,'L',$bg);
|
|
|
|
// Format the amount
|
|
$amount = round($amount * 100) / 100;
|
|
if ($amount < 0.00) $amount_str = "- $currencySymbol" . number_format(abs($amount),2);
|
|
else $amount_str = $currencySymbol . number_format($amount,2);
|
|
|
|
$total += $amount;
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$amount_str,'0',1,'R',$bg);
|
|
|
|
$curr_row += $incr;
|
|
$count++;
|
|
}
|
|
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetFont($resolved_font,"B",$document_font_size);
|
|
|
|
|
|
// Format report totals
|
|
$total = round($total * 100) / 100;
|
|
if ($total < 0.00) $total = "- $currencySymbol" . number_format(abs($total),2);
|
|
else $total = $currencySymbol . number_format($total,2);
|
|
|
|
|
|
// Display totals for the report
|
|
$curr_col = $columns[0];
|
|
$width = $columns[1] - $columns[0];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,"Payment Totals :: ",'0',1,'R',true);
|
|
|
|
$cnum = 1;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$total,'0',1,'R',true);
|
|
|
|
|
|
if ($curr_row < $max_rows) {
|
|
$pdf->SetFont($resolved_font,"",$document_font_size - 1);
|
|
$date = date("F j, Y",time());
|
|
$pdf->SetXY(10,$max_rows);
|
|
$pdf->Cell(180,$incr,"Payment Summary: $date",'0',1,'L');
|
|
}
|
|
|
|
|
|
|
|
// Output the completed PDF
|
|
$filename = "payment-summary.pdf";
|
|
|
|
// Ensure no prior output corrupts headers/PDF generation
|
|
if (function_exists('ob_get_level')) {
|
|
while (ob_get_level()) { ob_end_clean(); }
|
|
}
|
|
|
|
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");
|
|
exit();
|
|
|
|
?>
|