310 lines
9.9 KiB
PHP
310 lines
9.9 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
// Guarded session handling to align with other modules
|
|
if (!empty($sessionName) && session_name() !== $sessionName) {
|
|
session_name($sessionName);
|
|
}
|
|
if (session_status() === PHP_SESSION_NONE || session_id() === '') {
|
|
session_start();
|
|
}
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
echo("<br>\n");
|
|
$error_message = "Invalid Access";
|
|
include "form.messages.php";
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
$curr_school_num = $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 = 240;
|
|
|
|
$title_col = 15;
|
|
$value_col = 45;
|
|
$sched_col = 50;
|
|
$amount_col = 150;
|
|
|
|
$start_row = 8;
|
|
$incr = 4.0;
|
|
|
|
|
|
//
|
|
// Setup the PDF libraries
|
|
//
|
|
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() {
|
|
}
|
|
|
|
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 = $school_record['pac_name'];
|
|
|
|
if (in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team'))) {
|
|
$usernum = isset($_GET['user_num']) ? intval($_GET['user_num']) : 0;
|
|
if (!$usernum) $usernum = $_SESSION['UserInfo']['record_num'];
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND record_num = $usernum");
|
|
$row = db_fetch_array($results);
|
|
|
|
$name = $row['first_name'] . " " . $row['last_name'];
|
|
$userid = $row['userid'];
|
|
$phone_number = $row['home_phone'];
|
|
}
|
|
else {
|
|
$name = $_SESSION['UserInfo']['first_name'] . " " . $_SESSION['UserInfo']['last_name'];
|
|
$userid = $_SESSION['UserInfo']['userid'];
|
|
$usernum = $_SESSION['UserInfo']['record_num'];
|
|
$phone_number = $_SESSION['UserInfo']['home_phone'];
|
|
}
|
|
|
|
|
|
|
|
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
|
|
// Page title
|
|
$curr_row = $start_row;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(185,$incr + 1,"$school_name ".getLanguageText('TEXT-REMITANCE-FORM'),'0',0,'L',true);
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
|
|
|
|
// School, User ID and Name
|
|
$curr_row += $incr + 5;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(45,$incr,getLanguageText('TEXT-SCHOOL'),'0',0,'L',false);
|
|
$pdf->SetXY($value_col,$curr_row);
|
|
$pdf->Cell(45,$incr,":: ".$school_record['school_name'],'0',0,'L',false);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(45,$incr,getLanguageText('TEXT-USER-ID'),'0',0,'L',false);
|
|
$pdf->SetXY($value_col,$curr_row);
|
|
$pdf->Cell(45,$incr,":: $userid",'0',0,'L',false);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(45,$incr,getLanguageText('TEXT-NAME'),'0',0,'L',false);
|
|
$pdf->SetXY($value_col,$curr_row);
|
|
$pdf->Cell(45,$incr,":: $name",'0',0,'L',false);
|
|
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(45,$incr,getLanguageText('TEXT-PHONE'),'0',0,'L',false);
|
|
$pdf->SetXY($value_col,$curr_row);
|
|
$pdf->Cell(45,$incr,":: $phone_number",'0',0,'L',false);
|
|
|
|
|
|
// Get students associated with this account
|
|
$students = db_query("select * from people where school_num = $base_school_num and user_num = $usernum order by last_name,first_name");
|
|
$snums = $school_record['linked_sites'];
|
|
|
|
while ($row = db_fetch_array($students)) {
|
|
extract($row);
|
|
$name = "$first_name $last_name";
|
|
|
|
switch ($class_num) {
|
|
case 0:
|
|
$class_info = $GlobalText['Staff'];
|
|
break;
|
|
|
|
case 1:
|
|
$class_info = getLanguageText('TEXT-CUSTOMER');
|
|
break;
|
|
|
|
default:
|
|
$class_info = getClassInfo($class_num,'external');
|
|
break;
|
|
}
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size);
|
|
$curr_row += $incr + 2;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(45,$incr,$school_record['student_button_text'],'0',0,'L',false);
|
|
$pdf->SetXY($value_col,$curr_row);
|
|
$pdf->Cell(45,$incr,":: $name",'0',0,'L',false);
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($value_col,$curr_row);
|
|
$pdf->Cell(45,$incr,":: $class_info",'0',0,'L',false);
|
|
|
|
// Get set of Unpaid orders for this student
|
|
// Use a safe default for schedule sort order
|
|
$allowedSortCols = array('schedule_name','sequence');
|
|
if (!isset($scheduleSortOrder) || !in_array($scheduleSortOrder, $allowedSortCols)) {
|
|
$scheduleSortOrder = 'schedule_name';
|
|
}
|
|
|
|
$query = "SELECT hloh.order_total,hls.schedule_name FROM hotlunch_order_header AS hloh, hotlunch_schedules AS hls " .
|
|
"WHERE hls.school_num = $curr_school_num " .
|
|
"AND hls.school_num = hloh.school_num " .
|
|
"AND hls.record_num = hloh.schedule_num " .
|
|
"AND hloh.ordered_by_num = $record_num " .
|
|
"AND hloh.status IN ('Inactive','Unpaid') " .
|
|
"ORDER BY hls.$scheduleSortOrder";
|
|
$orders = db_query($query);
|
|
|
|
if (db_num_rows($orders) > 0) {
|
|
while ($row = db_fetch_array($orders)) {
|
|
extract($row);
|
|
$curr_row += $incr;
|
|
$pdf->SetXY($sched_col,$curr_row);
|
|
$pdf->Cell(45,$incr,"- $schedule_name",'0',0,'L',false);
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(45,$incr,$currencySymbol . number_format($order_total,2),'0',0,'R',false);
|
|
}
|
|
}
|
|
|
|
if ($curr_row > $max_rows - 18) {
|
|
$pdf->Image('images/'.$school_record['logo_image'],31,$max_rows + 8,50);
|
|
$pdf->SetXY(20,255);
|
|
$date = dateString('datetime');
|
|
$pdf->Cell(182,$incr - 1,getLanguageText('TEXT-PRINTED') . ": $date",'0',0,'R');
|
|
|
|
$pdf->addPage();
|
|
$curr_row = $start_row;
|
|
}
|
|
}
|
|
|
|
|
|
// Get current account balance
|
|
$balance = db_getVal("select sum(transaction_amount) from user_account where school_num = $curr_school_num and user_num = $usernum AND (deleted != 'Y' OR deleted IS NULL)");
|
|
|
|
|
|
// Include additional remittance form fee
|
|
if ($school_record['remittance_form_fee'] > 0) {
|
|
$pdf->SetFont($document_font,"",$document_font_size + 1);
|
|
$curr_row += $incr * 3;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(185,$incr + 1,getLanguageText('TEXT-CURRENT-ACCT-BALANCE'),'0',0,'L',true);
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(45,$incr + 1,$currencySymbol . number_format($balance,2),'0',0,'R',true);
|
|
|
|
$curr_row += $incr * 2;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(185,$incr + 1,getLanguageText('TEXT-REMITTANCE-FORM-FEE'),'0',0,'L',true);
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(45,$incr + 1,$currencySymbol . number_format($school_record['remittance_form_fee'],2),'0',0,'R',true);
|
|
|
|
$total = $balance + $school_record['remittance_form_fee'];
|
|
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$curr_row += $incr * 2;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(185,$incr + 1,getLanguageText('TEXT-BALANCE-PAYABLE'),'0',0,'L',true);
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(45,$incr + 1,$currencySymbol . number_format($total,2),'0',0,'R',true);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
}
|
|
else {
|
|
$pdf->SetFont($document_font,"B",$document_font_size + 1);
|
|
$curr_row += $incr * 3;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->Cell(185,$incr + 1,getLanguageText('TEXT-CURRENT-ACCT-BALANCE'),'0',0,'L',true);
|
|
$pdf->SetXY($amount_col,$curr_row);
|
|
$pdf->Cell(45,$incr + 1,$currencySymbol . number_format($balance,2),'0',0,'R',true);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
}
|
|
|
|
|
|
$curr_row += $incr * 4;
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$paymentString = getLanguageText('TEXT-PAYMENT-BY') . ":\n";
|
|
if ($school_record['accept_cash'] == 'Y') $paymentString .= " ____ " . getLanguageText('TEXT-CASH') . "\n";
|
|
if (strlen($school_record['accept_other']) > 0) $paymentString .= " ____ " . $school_record['accept_other'] . "\n";
|
|
if ($school_record['accept_check'] == 'Y') $paymentString .= " ____ " . getLanguageText('TEXT-CHECK') . "\n" .
|
|
" " . getLanguageText('TEXT-CHECK') . " # _______\n" .
|
|
" " . getLanguageText('TEXT-NAME-ON-CHECK') . " _______________________________________________";
|
|
$pdf->MultiCell(185,$incr,$paymentString,'0','L',false);
|
|
|
|
|
|
// Add the text data message if there is one defined
|
|
$text_message = db_getVal("SELECT text_data FROM text_data WHERE school_num = $curr_school_num AND text_id = 'Remittance Form'");
|
|
if ($text_message) {
|
|
$curr_row += $incr * 6;
|
|
$curr_row = $pdf->GetY();
|
|
$curr_row += $incr;
|
|
$pdf->SetLineWidth(.2);
|
|
$pdf->SetXY($title_col,$curr_row);
|
|
$pdf->MultiCell(185,$incr,"\n$text_message\n\n",'1','L',false);
|
|
}
|
|
|
|
|
|
|
|
// Add logo to page
|
|
$pdf->Image('images/'.$school_record['logo_image'],31,$max_rows + 5,50);
|
|
|
|
|
|
// Printed date line
|
|
if ($curr_row < 250) {
|
|
$pdf->SetXY(20,255);
|
|
$date = dateString('datetime');
|
|
$pdf->Cell(182,$incr - 1,getLanguageText('TEXT-PRINTED') . ": $date",'0',0,'R');
|
|
}
|
|
|
|
|
|
|
|
// 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=remittance-form.pdf");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$pdf->Output("remittance-form.pdf","D");
|
|
exit();
|
|
|
|
?>
|