239 lines
7.2 KiB
PHP
239 lines
7.2 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
unset($user_num);
|
|
unset($userid);
|
|
if (array_key_exists('usernum', $_GET) && strlen($_GET['usernum'])) $user_num = intval($_GET['usernum']);
|
|
if (array_key_exists('userid', $_GET) && strlen($_GET['userid'])) $userid = $_GET['userid'];
|
|
|
|
|
|
if (!isset($user_num) || !isset($userid)) {
|
|
header("Location: /?error_message=".getLanguageText('ERRORMSG-INVALID-ACCESS'));
|
|
exit();
|
|
}
|
|
|
|
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND record_num = $user_num AND userid = '" . db_escape_string($userid) . "'");
|
|
if (db_num_rows($results) == 0) {
|
|
header("Location: /?error_message=".getLanguageText('ERRORMSG-INVALID-ACCESS'));
|
|
exit();
|
|
}
|
|
|
|
$user = db_fetch_assoc($results);
|
|
|
|
$curr_school_num = $user['school_num'];
|
|
|
|
|
|
|
|
//
|
|
// 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;
|
|
|
|
$left_col = 15;
|
|
$middle_col = 100;
|
|
|
|
|
|
// Set parameters for this document
|
|
$max_rows = 260;
|
|
|
|
$title_col = 15;
|
|
$name_col = 25;
|
|
$date_col = 150;
|
|
|
|
$value_col = 45;
|
|
$sched_col = 50;
|
|
$amount_col = 150;
|
|
|
|
$start_row = 8;
|
|
$incr = 4.0;
|
|
|
|
$title_width = 200;
|
|
$date_width = $title_width - $date_col;
|
|
|
|
|
|
//
|
|
// Setup the PDF libraries
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
$document_path = sprintf("%08d",$record_num);
|
|
$receipt_image = "files/$document_path/image/" . $school_record['receipt_image'];
|
|
$receipt_row = $start_row;
|
|
$image_height = 30;
|
|
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
}
|
|
|
|
function Footer() {
|
|
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $school_record;
|
|
|
|
$this->SetXY($left_col,$max_rows - $incr * 2);
|
|
$this->SetFont($document_font,"B",$document_font_size + 2);
|
|
$this->Cell($title_width,$incr + 1,$school_record['school_name'],'0',0,'C',false,'',1);
|
|
|
|
$this->SetXY($left_col,$max_rows - $incr);
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
$this->Cell($title_width,$incr + 1,$school_record['address'].", ".$school_record['city'].", ".$school_record['province']." ".$school_record['postal'],'0',0,'C',false,'',1);
|
|
|
|
$this->SetXY($left_col,$max_rows);
|
|
$this->SetFont($document_font,"",$document_font_size);
|
|
$this->Cell($title_width,$incr + 1,$school_record['phone'],'0',0,'C',false,'',1);
|
|
}
|
|
}
|
|
|
|
$pdf= new PDF('P', 'mm', 'Letter', true, 'UTF-8', false);
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
$pdf->SetFillColor(200,200,200);
|
|
|
|
|
|
$pdf->addPage();
|
|
$curr_row = $start_row;
|
|
|
|
// Add logo
|
|
if (strlen($receipt_image) && is_file($receipt_image)) {
|
|
$pdf->Image($receipt_image,$left_col,$start_row,0,$image_height);
|
|
$curr_row += $image_height;
|
|
}
|
|
|
|
// Print receipt title
|
|
if (strlen($school_record['receipt_title'])) {
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 8);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr + 6,$school_record['receipt_title'],'0',0,'L',false,'',0);
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($date_width,$incr + 6,date($school_record['date_format'],time()),'0',0,'L',false,'',0);
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$curr_row += $incr * 4;
|
|
|
|
|
|
// Print user info
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,$user['first_name'] . ' ' . $user['last_name'],'0',0,'L',false,'',0);
|
|
$curr_row += $incr;
|
|
|
|
$pdf->SetXY($name_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,$user['home_phone'],'0',0,'L',false,'',0);
|
|
$curr_row += $incr * 4;
|
|
|
|
|
|
// Get and print all user transactions
|
|
$transactions = db_query("SELECT * FROM user_account WHERE school_num = $school_num AND user_num = $user_num AND deleted != 'Y' ORDER BY transaction_datetime");
|
|
|
|
if (db_num_rows($transactions) == 0) {
|
|
$pdf->SetFont($document_font,"",$document_font_size + 2);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,"No Transactions Found",'0',0,'L',false,'',0);
|
|
}
|
|
else {
|
|
$pdf->SetFont($document_font,"",$document_font_size + 2);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell($title_width,$incr,"Transactions",'0',0,'L',false,'',0);
|
|
$curr_row += $incr + 2;
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$columns = array(30,100,30,30);
|
|
$alignment = array('L','L','R','R','R');
|
|
$headers = array("Date","Description","Amount","Total");
|
|
|
|
$col = $left_col;
|
|
for ($i = 0; $i < count($headers); $i++) {
|
|
$width = $columns[$i];
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,$headers[$i],'1',0,$alignment[$i],true,'',0);
|
|
$col += $width;
|
|
}
|
|
$curr_row += $incr;
|
|
|
|
$total = 0;
|
|
|
|
while ($row = db_fetch_array($transactions)) {
|
|
switch ($row['transaction_type']) {
|
|
case 'Order':
|
|
$description = translateText($row['note']);
|
|
$amount = $row['transaction_amount'];
|
|
$total += $row['transaction_amount'];
|
|
$sign = "";
|
|
break;
|
|
|
|
case 'Tax Charge':
|
|
default:
|
|
$description = translateText($row['transaction_type']) . ": " . translateText($row['note']);
|
|
$amount = $row['transaction_amount'];
|
|
$total += $row['transaction_amount'];
|
|
$sign = "";
|
|
break;
|
|
|
|
case 'Payment':
|
|
$description = translateText($row['payment_method']) . ' ' . translateText($row['transaction_type']) . ": " . translateText($row['note']);
|
|
$amount = $row['transaction_amount'];
|
|
$total += $row['transaction_amount'];
|
|
$sign = "-";
|
|
break;
|
|
}
|
|
|
|
$tsign = "";
|
|
if ($total < 0) $tsign = "-";
|
|
|
|
$data = array(date($school_record['date_format'],$row['entered_time']),
|
|
$description,
|
|
$sign . $currencySymbol . number_format(abs($amount),2),
|
|
$tsign . $currencySymbol . number_format(abs($total),2));
|
|
|
|
// Display the data
|
|
$col = $left_col;
|
|
for ($i = 0; $i < count($data); $i++) {
|
|
$width = $columns[$i];
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,$data[$i],'1',0,$alignment[$i],false,'',0);
|
|
$col += $width;
|
|
}
|
|
$curr_row += $incr;
|
|
}
|
|
}
|
|
|
|
// Print current account balance
|
|
$tsign = "";
|
|
if ($total < 0) $tsign = "-";
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetFillColor(230,230,230);
|
|
$pdf->SetXY($left_col,$curr_row);
|
|
$pdf->Cell(190,$incr,"Current Account Balance: " . $tsign . $currencySymbol . number_format($total,2),'1',0,'R',true,'',0);
|
|
|
|
|
|
|
|
// 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-receipt.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("account-receipt.pdf","D");
|
|
return;
|
|
|
|
?>
|