#!/usr/bin/perl
# Copyright 2001-2019 Leslie Richardson
# This file is part of Open Admin for Schools.
# Open Admin for Schools is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 of
# the License, only.
my %lex = ('Please Log In' => 'Please Log In',
'Error' => 'Error',
'View' => 'View',
'Fees' => 'Fees',
'Main' => 'Main',
'Date' => 'Date',
'Description' => 'Description',
'Type' => 'Type',
'Amount' => 'Amount',
'Grade' => 'Grade',
'Homeroom' => 'Homeroom',
'Name' => 'Name',
'Receipt' => 'Receipt',
'Id' => 'Id',
'No Records Found' => 'No Records Found',
'Paid' => 'Paid',
'Unpaid' => 'Unpaid',
'Balance' => 'Balance',
'Continue' => 'Continue',
'Start Date' => 'Start Date',
);
my $self = 'viewfees.pl';
use DBI;
use CGI;
use CGI::Session;
use Time::JulianDay;
use Number::Format qw(:all);
my $q = new CGI;
my %arr = $q->Vars;
# Get Julian Day value for start date
my $startjd = julian_day( split('-', $startdate));
eval require "../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. " $@ \n";
die $lex{Error}. " $@ \n";
}
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
# Set Page Title
my $title = "$lex{View} $lex{Fees}";
# Get Session
my $session = new CGI::Session("driver:$dbtype;serializer:FreezeThaw",
undef,{Handle => $dbh}) or die CGI::Session->errstr;
if ( not $session->param('logged_in') ){
$userid = $session->param('userid');
print $q->header( -charset, $charset );
print qq{$doctype\n
\n};
print qq{\n};
exit;
}
# Redo with Read Only User.
$dbh = DBI->connect($dsn,$rouser,$ropassword);
my $userid = $session->param('userid');
my $duration = $session->param('duration');
$session->expire('logged_in', $duration );
print $session->header( -charset, $charset );
# HTML Page Header
print qq{$doctype\n$title\n};
print qq{\n};
if ( not $arr{page} ) {
print qq{\n};
print qq{\n};
print qq{\n};
print qq{\n};
}
print qq{$chartype\n\n};
print qq{[ $lex{Main} ]\n};
print qq{
$title
\n};
if ( not $arr{page} ) {
showStartPage();
} elsif ( $arr{page} == 1 ) {
delete $arr{page};
showTransactions( $userid, $startdate );
}
#----------------
sub showStartPage {
#----------------
print qq{\n};
print qq{\n};
print qq{\n};
exit;
} # end of showStartPage
#-------------------
sub showTransactions {
#-------------------
my ($studnum, $startdate) = @_;
# strip any nondigits
$startdate =~ s/\D//g;
my ($yr,$mo,$da) = unpack("A4,A2,A2",$startdate);
$startdate = "$yr-$mo-$da";
# print qq{Startdate: $stardate \n};
# Get Student Name, grade, etc.
my $sth = $dbh->prepare("select lastname, firstname, grade, homeroom
from studentall where studnum = ?");
$sth->execute( $studnum );
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
my ($lastname, $firstname, $grade, $homeroom) = $sth->fetchrow;
# Setup Queries.
my $sth1 = $dbh->prepare("select id, trans_date, trans_type, name, description, total,
paid_id, receipt from fees_jrl
where studnum = ?
order by trans_date, id");
#and to_days(trans_date) >= to_days('$startdate')
my $sth2 = $dbh->prepare("select sum(total) from fees_jrl where studnum = ?");
my $sth3 = $dbh->prepare("select count(*) from fees_jrl where paid_id is NULL and studnum = ?");
print qq{
$firstname $lastname ($studnum)};
print qq{ $lex{Grade}: $grade };
if ( $homeroom ) { print qq{$lex{Homeroom}: $homeroom\n}; }
# Check for error with zero balance and some unmarked paid_id values.
$sth2->execute( $studnum );
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
my $balance = $sth2->fetchrow;
my $pcount;
if ( $balance == 0 ) { # check for blank paid_id
$sth3->execute( $studnum );
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
$pcount = $sth3->fetchrow;
}
if ( $pcount ) { # if we have zero balance and some unmarked paid_id fields, show form
print qq{\n};
}
print qq{
\n};
# Find student transactions.
$sth1->execute( $studnum );
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
my $first = 1;
my $balance;
while ( my ( $id, $trans_date, $trans_type, $name,
$description, $total, $paid_id, $receipt ) = $sth1->fetchrow ) {
if ( $transactmode eq $lex{Unpaid} ) {
if ( $trans_type eq 'pay' or $paid_id ) { next; }
}
if ( $first ) {
# Print Table Header
print qq{