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

352 lines
12 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();
}
// Ensure that only valid user types have access to this module
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team','Financial','Financial Team'))) {
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
header("Location: /?error_message=".urlencode($error_message));
exit();
}
//
// 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 = 8;
// Setup parameters for this document
$max_rows = 176;
$title_width = 265;
$columns = array(
array('fname' => 'userid',
'title' => getLanguageText('TEXT-USER-ID'),
'col' => 8,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'trx_date',
'title' => getLanguageText('TEXT-DATE'),
'col' => 40,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'transaction_type',
'title' => getLanguageText('TEXT-TYPE'),
'col' => 60,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'account',
'title' => getLanguageText('TEXT-ACCOUNT'),
'col' => 80,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'name',
'title' => getLanguageText('TEXT-NAME'),
'col' => 125,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'method',
'title' => getLanguageText('TEXT-METHOD'),
'col' => 170,
'total' => 'c',
'format' => 'text',
'align' => 'L'),
array('fname' => 'amt',
'title' => getLanguageText('TEXT-AMOUNT'),
'col' => 190,
'total' => 'C',
'format' => 'currency',
'align' => 'R'),
array('fname' => 'pamt',
'title' => getLanguageText('TEXT-PAYMENT'),
'col' => 210,
'total' => 'Y',
'format' => 'currency',
'align' => 'R'),
array('fname' => '',
'title' => '',
'col' => 230,
'align' => 'C'),
array('fname' => 'posted',
'title' => getLanguageText('TEXT-POSTED-TIME'),
'col' => 235,
'total' => 'N',
'format' => 'text',
'align' => 'L'),
array('fname' => 'End Of Row',
'col' => 265,
'align' => 'C'),
);
$start_row = 25;
$curr_row = $max_rows + 10;
$incr = 4;
$document_name = getLanguageText('TEXT-USER-PAYMENT-DETAIL');
//
// 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 + 10;
class PDF extends TCPDF {
function Header() {
return;
}
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');
$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');
}
}
// Force exact physical size for Letter: 8.5 x 11 inches => 279.4mm x 215.9mm (landscape)
$pageFormat = array(279.4, 215.9);
$pdf= new PDF('L', '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 = $school_record['school_name'];
$report_subtitle = '';
if (array_key_exists('selected_schedule_num',$_GET) && intval($_GET['selected_schedule_num']) > 0) {
$snum = $_GET['selected_schedule_num'];
$report_subtitle = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $snum");
$report_subtitle .= ": ";
}
$report_subtitle .= $_GET['start_date'] . " - " . $_GET['end_date'];
$query = $_GET['query'];
if (stripos("update",$query) !== FALSE) exit();
if (stripos("insert",$query) !== FALSE) exit();
if (stripos("delete",$query) !== FALSE) exit();
if (!preg_match("/^select /i",$query)) exit();
if (preg_match("/select .*select/i",$query)) exit();
$transactions = db_query($query);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$page = 0;
$prev_trx = 0;
$totals = array();
$count = 0;
while ($row = db_fetch_array($transactions)) {
if ($curr_row > $max_rows) {
// Put page titles on the page whenever a page is full
if ($page > 0) $pdf->addPage();
$curr_row = 8;
$pdf->SetFont($document_font,"B",$document_font_size + 2);
$pdf->SetXY(10,$curr_row);
$pdf->Cell(250,$incr,"$school_name :: $document_name",'0',1,'L',false,'',1);
if (strlen($report_subtitle)) {
$curr_row += $incr + 1;
$pdf->SetXY(10,$curr_row);
$pdf->Cell(250,$incr,$report_subtitle,'0',1,'L',false,'',1);
}
$curr_row += $incr + 4;
$pdf->SetFont($document_font,"B",$document_font_size);
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$title = $columns[$cnum]['title'];
$align = $columns[$cnum]['align'];
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell($width,$incr,$title,'0',1,$align,true,'',1);
}
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetFont($document_font,"",$document_font_size);
$curr_row += $incr;
$page++;
}
$bg = false;
if ($count % 2) $bg = true;
// Get user_account record
$ptrxNum = $row['posted_to_transaction'];
$results = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND record_num = $ptrxNum");
$urow = db_fetch_assoc($results);
$trx_type = ($urow && isset($urow['transaction_type'])) ? $urow['transaction_type'] : '';
// Format output
$row['account'] = $row['first_name'] . ' ' . $row['last_name'];
$row['pamt'] = $row['posted_amount'];
$row['name'] = '';
$row['posted'] = '';
if ($trx_type == 'Order') {
$row['order_num'] = $urow['order_num'];
$row['name'] = getOrderedByName($urow['order_num']);
$row['posted'] = $trx_type .= " #" . $urow['order_num'];
}
$row['method'] = $row['payment_method'];
if (strlen($row['method']) == 0) $row['method'] = $row['transaction_type'];
if ($row['method'] == 'Check') $row['method'] .= " #" . $row['payment_reference'];
$row['amt'] = $row['transaction_amount'];
if ($row['trx_num'] != $prev_trx) {
for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$fname = $columns[$cnum]['fname'];
$align = $columns[$cnum]['align'];
$pdf->SetXY($curr_col,$curr_row);
if (strlen($fname)) {
$text = $row[$fname];
if (isset($columns[$cnum]['format']) && $columns[$cnum]['format'] == 'currency') $text = formatCurrency($text);
$pdf->Cell($width,$incr,$text,'0',1,$align,$bg,'',1);
}
else $pdf->Cell($width,$incr,' ','0',1,$align,$bg,'',1);
if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'C') {
if (!isset($totals[$cnum])) $totals[$cnum] = 0;
$totals[$cnum] += $row[$fname];
}
if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'Y') {
if (!isset($totals[$cnum])) $totals[$cnum] = 0;
$totals[$cnum] += $row[$fname];
}
}
}
else {
$count--;
$bg = false;
if ($count % 2) $bg = true;
for ($cnum = 0; $cnum < 4; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell($width,$incr,' ','0',1,'L',$bg,'',1);
}
for ($cnum = 4; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$fname = $columns[$cnum]['fname'];
$align = $columns[$cnum]['align'];
$pdf->SetXY($curr_col,$curr_row);
if (strlen($fname)) {
$text = $row[$fname];
if (isset($columns[$cnum]['format']) && $columns[$cnum]['format'] == 'currency') $text = formatCurrency($text);
if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'C') $text = '';
if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'c') $text = '';
$pdf->Cell($width,$incr,$text,'0',1,$align,$bg,'',1);
}
else $pdf->Cell($width,$incr,' ','0',1,$align,$bg,'',1);
if (isset($columns[$cnum]['total']) && $columns[$cnum]['total'] == 'Y') {
if (!isset($totals[$cnum])) $totals[$cnum] = 0;
$totals[$cnum] += $row[$fname];
}
}
}
$prev_trx = $row['trx_num'];
$curr_row += $incr;
$count++;
}
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetFont($document_font,"B",$document_font_size);
for ($cnum = 0; $cnum < count($columns) - 1; $cnum++) {
$curr_col = $columns[$cnum]['col'];
$width = $columns[$cnum + 1]['col'] - $columns[$cnum]['col'];
$align = $columns[$cnum]['align'];
$text = "";
if (isset($columns[$cnum]['total']) && ($columns[$cnum]['total'] == 'Y' || $columns[$cnum]['total'] == 'C')) {
$text = isset($totals[$cnum]) ? $totals[$cnum] : 0;
if (isset($columns[$cnum]['format']) && $columns[$cnum]['format'] == 'currency') $text = formatCurrency($text);
}
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell($width,$incr,$text,'0',1,$align,true,'',1);
}
// 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=account-transactions.pdf");
header('Content-Transfer-Encoding: binary');
$pdf->Output("account-transactions.pdf","D");
return;
?>