353 lines
11 KiB
PHP
353 lines
11 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
|
|
//
|
|
$obLevelStarted = false;
|
|
if (function_exists('ob_start')) { ob_start(); $obLevelStarted = true; }
|
|
$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;
|
|
$columns = array(8,40,80,130,190,220,240,270);
|
|
$start_row = 25;
|
|
$curr_row = $max_rows + 10;
|
|
$incr = 4;
|
|
|
|
$document_name = getLanguageText('TEXT-PAYPAL-TRANSACTION-REPORT');
|
|
|
|
|
|
//
|
|
// 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() {
|
|
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'];
|
|
|
|
|
|
// Build the query statement
|
|
$query = "SELECT u.userid,substr(transaction_datetime,1,10) as trx_date,transaction_type,note,transaction_amount,transaction_fee," .
|
|
"payment_method,payment_reference,user_num,ua.record_num,deleted,deleted_datetime,deleted_by_user_num,delete_reason " .
|
|
"FROM user_account as ua, users AS u " .
|
|
"WHERE u.school_num = $base_school_num " .
|
|
"AND ua.school_num = $school_num " .
|
|
"AND ua.user_num = u.record_num ";
|
|
|
|
$mode = 'lookup';
|
|
|
|
// Manage start date parameter
|
|
if (array_key_exists('start_date',$_GET) && strlen($_GET['start_date']) > 0) {
|
|
$query .= "AND transaction_datetime >= '$_GET[start_date] 00:00:00' ";
|
|
}
|
|
|
|
// Manage end date parameter
|
|
if (array_key_exists('end_date',$_GET) && strlen($_GET['end_date']) > 0) {
|
|
$query .= "AND transaction_datetime <= '$_GET[end_date] 23:59:59' ";
|
|
}
|
|
|
|
// Manage user_num parameter
|
|
if (array_key_exists('selected_usernum',$_GET) && strlen($_GET['selected_usernum']) > 0) {
|
|
$query .= "AND ua.user_num = " . intval($_GET['selected_usernum']) . " ";
|
|
$mode = 'account';
|
|
}
|
|
|
|
// Manage selected transaction type parameter
|
|
$query .= "AND ua.transaction_type = 'Payment' ";
|
|
|
|
// Manage selected payment methods
|
|
$query .= "AND ua.payment_method = 'PayPal' ";
|
|
|
|
// View only selected schedule
|
|
if (array_key_exists('selected_schedule_num',$_GET) && strlen($_GET['selected_schedule_num']) > 0) {
|
|
$query .= "AND ua.schedule_num = '$_GET[selected_schedule_num]' ";
|
|
}
|
|
|
|
// Process the optional type parameter
|
|
if (array_key_exists('type',$_GET) && strlen($_GET['type']) > 0 && $_GET['type'] == 'deleted') {
|
|
$query .= "AND deleted = 'Y' ";
|
|
}
|
|
else {
|
|
$query .= "AND (deleted != 'Y' OR deleted IS NULL) ";
|
|
}
|
|
|
|
|
|
// Complete the query
|
|
$query .= "ORDER BY transaction_datetime,record_num";
|
|
$transactions = db_query($query);
|
|
|
|
|
|
$total_credits = 0;
|
|
$total_fee = 0;
|
|
$total_actual = 0;
|
|
|
|
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
|
|
$page = 0;
|
|
$count = 0;
|
|
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($document_font,"B",$document_font_size + 2);
|
|
$pdf->SetXY(10,8);
|
|
$pdf->Cell(250,$incr,"$school_name :: ".getLanguageText('TEXT-PAYPAL-TRANSACTION-REPORT'),'0',1,'L',false,'',1);
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
$curr_row = 16;
|
|
$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,getLanguageText('TEXT-USER-ID'),'0',1,'L',true,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-DATE'),'0',1,'L',true,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-TRX-ID'),'0',1,'L',true,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-AMOUNT'),'0',1,'R',true,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-PAYPAL-FEE'),'0',1,'R',true,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr," ".getLanguageText('TEXT-METHOD'),'0',1,'L',true,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-ACTUAL'),'0',1,'R',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;
|
|
|
|
$cnum = 0;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$row['userid'],'0',1,'L',$bg,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$row['trx_date'],'0',1,'L',$bg,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$row['payment_reference'],'0',1,'L',$bg,'',1);
|
|
|
|
// Format the data values (cast to float to avoid TypeErrors)
|
|
$credit = $currencySymbol . number_format(abs((float)$transaction_amount),2);
|
|
$trx_fee = $currencySymbol . number_format(abs((float)$transaction_fee),2);
|
|
$actual = abs((float)$transaction_amount) - abs((float)$transaction_fee);
|
|
$total_credits += abs((float)$transaction_amount);
|
|
$total_fee += abs((float)$transaction_fee);
|
|
$total_actual += $actual;
|
|
|
|
|
|
// Format the current actual
|
|
$actual = round($actual * 100) / 100;
|
|
$actual_amt = $currencySymbol . number_format($actual,2);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$credit,'0',1,'R',$bg,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$trx_fee,'0',1,'R',$bg,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,' ' . $row['payment_method'],'0',1,'L',$bg,'',1);
|
|
|
|
$cnum++;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$actual_amt,'0',1,'R',$bg,'',1);
|
|
|
|
$curr_row += $incr;
|
|
|
|
|
|
// Display deleted information if required
|
|
if (isset($row['deleted']) && $row['deleted'] == 'Y') {
|
|
$deleted_datetime = $row['deleted_datetime'];
|
|
$deleted_by_user_num = $row['deleted_by_user_num'];
|
|
$delete_reason = $row['delete_reason'];
|
|
|
|
$delete_userid = "superuser";
|
|
if ($deleted_by_user_num != 1) $delete_userid = db_getVal("SELECT userid FROM users WHERE school_num = $base_school_num AND record_num = $deleted_by_user_num");
|
|
$delete_info = "Deleted $deleted_datetime by $delete_userid - $delete_reason";
|
|
|
|
$pdf->SetXY($columns[0],$curr_row);
|
|
$pdf->Cell(100,$incr," ",'0',1,'L',$bg,'',1);
|
|
|
|
$pdf->SetXY($columns[1],$curr_row);
|
|
$width = $columns[count($columns) - 1] - $columns[1];
|
|
$pdf->Cell($width,$incr,$delete_info,'0',1,'L',$bg,'',1);
|
|
|
|
$curr_row += $incr + 2;
|
|
}
|
|
|
|
$count++;
|
|
}
|
|
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
|
|
// Format report totals
|
|
$total_credits = round($total_credits * 100) / 100;
|
|
$total_credits = $currencySymbol . number_format($total_credits,2);
|
|
|
|
$total_fee = round($total_fee * 100) / 100;
|
|
$total_fee = $currencySymbol . number_format($total_fee,2);
|
|
|
|
$total_actual = round($total_actual * 100) / 100;
|
|
$total_actual = $currencySymbol . number_format($total_actual,2);
|
|
|
|
|
|
// Display totals for the report
|
|
$curr_col = $columns[0];
|
|
$width = $columns[3] - $columns[0];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,getLanguageText('TEXT-TRX-TOTALS-FOR-PERIOD')." :: ",'0',1,'R',true,'',1);
|
|
|
|
$cnum = 3;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$total_credits,'0',1,'R',true,'',1);
|
|
|
|
$cnum = 4;
|
|
$curr_col = $columns[$cnum];
|
|
$width = $columns[$cnum + 1] - $columns[$cnum];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$total_fee,'0',1,'R',true,'',1);
|
|
|
|
$curr_col = $columns[5];
|
|
$width = $columns[7] - $columns[5];
|
|
$pdf->SetXY($curr_col,$curr_row);
|
|
$pdf->Cell($width,$incr,$total_actual,'0',1,'R',true,'',1);
|
|
|
|
|
|
|
|
// Output the completed PDF
|
|
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=paypal-transactions.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("paypal-transactions.pdf","D");
|
|
exit();
|
|
|
|
?>
|