First Commit

This commit is contained in:
mark committed 2026-10-19 15:22:52 -07:00
1 parent 5eb9dd037d
commit 2e62c0e60b
11877 files changed
+2035312

No files matched your search

+243
View File
@@ -0,0 +1,243 @@
<?php
$ValidAccess = 2010;
require_once("include/globals.php");
//
// Ensure that the user is logged in
//
if (SessionActive() != 1 || !UserLoggedIn()) {
echo("Invalid Access");
exit();
}
// startLog("user_account.balances.print.php");
// Get parameters to script
if (array_key_exists('action',$_GET)) $action = $_GET['action'];
if (array_key_exists('show_modifier',$_GET)) $show_modifier = $_GET['show_modifier'];
$reportMode = "Standard";
if (array_key_exists('mode',$_GET)) $reportMode = $_GET['mode'];
// Check permissions
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Administration Team','Schedule Team');
if (checkPermission($AllowedUserTypes) != 1) {
header("Location: /?action=$action&show_modifier=$show_modifier&error_code=NOACCESS");
return;
}
//
// Setup the PDF
//
$template_file = "Blank.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 PDF document
//
define('FPDF_FONTPATH',"include/font/");
require("include/fpdi.php");
$pdf= new fpdi('L','mm','Letter');
$pagecount = $pdf->setSourceFile("$template_file");
$tplidx = $pdf->ImportPage(1);
$pdf->addPage();
$pdf->useTemplate($tplidx);
$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 = 180;
$columns = array(8,55,70,120,145,220,240,260,265);
$fields = array('userid','type','name','home_phone','email','balance','trx_status','');
$titles = array(getLanguageText('TEXT-USER-ID'),
getLanguageText('TEXT-TYPE'),
getLanguageText('TEXT-NAME'),
getLanguageText('TEXT-PHONE'),
getLanguageText('TEXT-EMAIL'),
getLanguageText('TEXT-BALANCE'),
'','');
$alignment = array('L','L','L','L','L','R','L','L');
$start_row = 25;
$curr_row = $max_rows + 10;
$incr = 4;
$stitle = "Account Balances Report";
// Handle the modifier
if ($show_modifier == 'balance-owing') {
$shaving = "HAVING sum(transaction_amount) > 0.00 ";
$stitle = "Balance Owing Accounts Report";
}
if ($show_modifier == 'balance-payable') {
$shaving = "HAVING sum(transaction_amount) < 0.00 ";
$stitle = "Balance Payable Accounts Report";
}
$curr_school_num = $school_record['record_num'];
$acctSchool = "ua.school_num = $curr_school_num AND ";
$aview = "";
if (array_key_exists('aview', $_GET) && $_GET['aview'] == 'consolidated') {
$aview = 'consolidated';
$acctSchool = "ua.school_num IN (" . $school_record['linked_sites'] . ") AND ";
$stitle .= " - Consolidated View";
}
// Build the query statement
if (!isset($shaving)) $shaving = '';
$query = "SELECT userid,type,email,concat(u.first_name,' ',u.last_name) as name,u.home_phone,u.type,sum(transaction_amount) as balance," .
"trx_status,u.record_num " .
"FROM users AS u LEFT JOIN user_account as ua ON $acctSchool ua.user_num = u.record_num AND (ua.deleted != 'Y' OR ua.deleted IS NULL) " .
"WHERE u.school_num = $base_school_num " .
"AND u.type in ('Parent','Staff') " .
"GROUP BY 1,2,3,4,5,6,8,9 " .
$shaving .
"ORDER BY u.last_name";
$accounts = db_query($query);
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$page = 0;
$total = 0;
$count = 0;
while ($row = db_fetch_array($accounts)) {
extract($row);
if ($curr_row + ($incr * 4) > $max_rows) {
// Put page titles on the page whenever a page is full
if ($page > 0) {
$pdf->SetFont("Arial","",$document_font_size);
$date = date("F j, Y",time());
$pdf->SetXY(10,$max_rows);
$pdf->Cell(240,$incr,"Printed: $date",'0',1,'R');
$pdf->Image('images/'.$school_record['logo_image'],31,$max_rows,50);
$pdf->addPage();
}
$pdf->SetFillColor(hexdec("bb"),hexdec("bb"),hexdec("bb"));
$pdf->SetFont("Arial","B",$document_font_size + 2);
$pdf->SetXY(8,8);
$pdf->Cell(257,$incr + 2,"$school_name :: $stitle",'0',1,'L',true);
$pdf->SetFont("Arial","B",$document_font_size);
$curr_row = 16;
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
for ($cnum = 0; $cnum < count($titles); $cnum++) {
$curr_col = $columns[$cnum];
$width = $columns[$cnum + 1] - $columns[$cnum];
$title = $titles[$cnum];
$align = $alignment[$cnum];
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell($width,$incr,$title,'0',1,$align,true);
}
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
$pdf->SetFont("Arial","",$document_font_size);
$curr_row += $incr;
$page++;
}
$bg = false;
if ($count % 2) $bg = true;
for ($cnum = 0; $cnum < count($fields); $cnum++) {
$curr_col = $columns[$cnum];
$width = $columns[$cnum + 1] - $columns[$cnum];
$value = '';
$fname = 'unset';
if (array_key_exists($cnum, $fields)) $fname = $fields[$cnum];
if (array_key_exists($fname, $row)) $value = $row[$fname];
if ($fname == 'balance') {
$sign = "";
if ($value < 0) $sign = "-";
$value = $sign . $currencySymbol . number_format(abs($value),2);
}
$align = $alignment[$cnum];
$pdf->SetXY($curr_col,$curr_row);
$pdf->Cell($width,$incr,$value,'0',1,$align,$bg);
}
// $total += preg_replace('/[,$]/','',$row['balance']);
$total += $row['balance'];
// If student info is requested then display all the students associated with this account
if ($reportMode == 'Students' && $type == 'Parent') {
$students = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND user_num = $record_num ORDER BY last_name,first_name");
if (db_num_rows($students) > 0) {
while ($row = db_fetch_array($students)) {
$curr_row += $incr;
$pdf->SetXY($columns[0],$curr_row);
$pdf->Cell(70 - $columns[0],$incr,' ','0',1,$align,$bg);
$pdf->SetXY(70,$curr_row);
$pdf->Cell(195,$incr,' - ' . $row['first_name'] . ' ' . $row['last_name'],'0',1,$align,$bg);
}
}
}
$curr_row += $incr;
$count++;
}
// Print report totals
$total = number_format($total,2);
$pdf->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
$pdf->SetXY($columns[0],$curr_row);
$pdf->Cell($columns[5] - $columns[0],$incr,"Report Balance : ",'0',1,'R',true);
$pdf->SetXY($columns[5],$curr_row);
$pdf->Cell($columns[6] - $columns[5],$incr,$total,'0',1,'R',true);
$pdf->SetXY($columns[6],$curr_row);
$pdf->Cell($columns[8] - $columns[6],$incr," ",'0',1,'L',true);
// Print date and logo
$pdf->SetFont("Arial","",$document_font_size);
$date = date("F j, Y",time());
$pdf->SetXY(10,$max_rows);
$pdf->Cell(240,$incr,"Printed: $date",'0',1,'R');
$pdf->Image('images/'.$school_record['logo_image'],31,$max_rows,50);
// 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-balances.pdf");
header('Content-Transfer-Encoding: binary');
$pdf->Output("account-balances.pdf","D");
return;
?>