DailyTotals.php 4.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php
/**
 * Daily Totals program
 *
 * @package RosarioSIS
 * @subpackage modules
 */

DrawHeader( ProgramTitle() );

// Set start date.
12
$start_date = RequestedDate( 'start', date( 'Y-m' ) . '-01' );
13 14

// Set end date.
15
$end_date = RequestedDate( 'end', DBDate() );
16

17
echo '<form action="' . URLEscape( 'Modules.php?modname=' . $_REQUEST['modname'] . '&accounting=' ) . '" method="GET">';
18 19 20 21 22


$header_checkboxes = '<label><input type="checkbox" value="true" name="accounting" id="accounting" ' .
	( ! isset( $_REQUEST['accounting'] )
		|| $_REQUEST['accounting'] == 'true' ? 'checked ' : '' ) . '/> ' .
23
	_( 'Expense' ) . ' & ' . _( 'Income' ) . '</label>&nbsp; ';
24 25 26 27 28 29 30 31 32 33 34 35 36 37

$header_checkboxes .= '<label><input type="checkbox" value="true" name="staff_payroll" id="staff_payroll" ' .
	( ! empty( $_REQUEST['staff_payroll'] ) ? 'checked ' : '' ) . '/> ' .
	_( 'Staff Payroll' ) . '</label>&nbsp; ';

if ( $RosarioModules['Student_Billing'] )
{
	$header_checkboxes .= '<label><input type="checkbox" value="true" name="student_billing" id="student_billing" ' .
		( ! empty( $_REQUEST['student_billing'] ) ? 'checked ' : '' ) . '/> ' .
		_( 'Student Billing' ) . '</label>';
}

DrawHeader( $header_checkboxes, '' );

38 39
DrawHeader( _( 'Report Timeframe' ) . ': ' .
	PrepareDate( $start_date, '_start', false ) . ' &nbsp; ' . _( 'to' ) . ' &nbsp; ' .
40
	PrepareDate( $end_date, '_end', false ), SubmitButton( _( 'Go' ) ) );
41 42 43 44 45 46 47

echo '</form>';

// Accounting.
if ( ! isset( $_REQUEST['accounting'] )
	|| $_REQUEST['accounting'] == 'true' )
{
48
	$accounting_payments = DBGetOne( "SELECT sum(AMOUNT) AS AMOUNT
49 50 51 52 53
		FROM ACCOUNTING_PAYMENTS
		WHERE SYEAR='" . UserSyear() . "'
		AND SCHOOL_ID='" . UserSchool() . "'
		AND PAYMENT_DATE BETWEEN '" . $start_date . "'
		AND '" . $end_date . "'
54
		AND STAFF_ID IS NULL" );
55

56
	$accounting_incomes = DBGetOne( "SELECT sum(f.AMOUNT) AS AMOUNT
57
		FROM ACCOUNTING_INCOMES f
58 59
		WHERE f.SYEAR='" . UserSyear() . "'
		AND f.SCHOOL_ID='" . UserSchool() . "'
60
		AND f.ASSIGNED_DATE BETWEEN '" . $start_date . "'
61
		AND '" . $end_date . "'" );
62 63 64 65 66
}

// Staff salaries.
if ( ! empty( $_REQUEST['staff_payroll'] ) )
{
67
	$staffpayroll_payments = DBGetOne( "SELECT sum(p.AMOUNT) AS AMOUNT
68 69 70 71 72 73 74
		FROM ACCOUNTING_PAYMENTS p, STAFF s
		WHERE p.SYEAR='" . UserSyear() . "'
		AND s.SYEAR=p.SYEAR
		AND p.SCHOOL_ID='" . UserSchool() . "'
		AND p.PAYMENT_DATE BETWEEN '" . $start_date . "'
		AND '" . $end_date . "'
		AND p.STAFF_ID=s.STAFF_ID
75
		AND p.SYEAR=s.SYEAR" );
76

77
	$staffpayroll_incomes = DBGetOne( "SELECT sum(f.AMOUNT) AS AMOUNT
78
		FROM ACCOUNTING_SALARIES f, STAFF s
79
		WHERE f.SYEAR='" . UserSyear() . "'
80 81 82 83 84
		AND s.SYEAR=f.SYEAR
		AND f.SCHOOL_ID='" . UserSchool() . "'
		AND f.ASSIGNED_DATE BETWEEN '" . $start_date . "'
		AND '" . $end_date . "'
		AND f.STAFF_ID=s.STAFF_ID
85
		AND f.SYEAR=s.SYEAR" );
86 87 88 89 90 91
}

// Student Billing.
if ( ! empty( $_REQUEST['student_billing'] )
	&& $RosarioModules['Student_Billing'] )
{
92
	$billing_payments = DBGetOne( "SELECT sum(AMOUNT) AS AMOUNT
93 94 95 96
		FROM BILLING_PAYMENTS
		WHERE SYEAR='" . UserSyear() . "'
		AND SCHOOL_ID='" . UserSchool() . "'
		AND PAYMENT_DATE BETWEEN '" . $start_date . "'
97
		AND '" . $end_date . "'" );
98

99
	$billing_fees = DBGetOne( "SELECT sum(f.AMOUNT) AS AMOUNT
100 101 102
		FROM BILLING_FEES f
		WHERE f.SCHOOL_ID='" . UserSchool() . "'
		AND f.ASSIGNED_DATE BETWEEN '" . $start_date . "'
103
		AND '" . $end_date . "'" );
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
}

echo '<br />';

PopTable( 'header', _( 'Totals' ) );

echo '<table class="cellspacing-5 align-right">';

$total = 0;

// Accounting.
if ( ! isset( $_REQUEST['accounting'] )
	|| $_REQUEST['accounting'] == 'true' )
{
	echo '<tr><td>' . _( 'Expenses' ) . ': ' .
119
		'</td><td>' . Currency( $accounting_payments ) . '</td></tr>';
120 121

	echo '<tr><td>' . _( 'Less' ) . ': ' . _( 'Incomes' ) . ': ' .
122
		'</td><td>' . Currency( $accounting_incomes ) . '</td></tr>';
123

124
	$total += $accounting_payments - $accounting_incomes;
125 126 127 128 129 130 131
}


// Staff salaries.
if ( ! empty( $_REQUEST['staff_payroll'] ) )
{
	echo '<tr><td>' . _( 'Salaries' ) . ': ' .
132
		'</td><td>' . Currency( $staffpayroll_payments ) . '</td></tr>';
133 134

	echo '<tr><td>' . _( 'Less' ) . ': ' . _( 'Staff Payments' ) . ': ' .
135
		'</td><td>' . Currency( $staffpayroll_incomes ) . '</td></tr>';
136

137
	$total += $staffpayroll_payments - $staffpayroll_incomes;
138 139 140 141 142 143 144
}

// Student Billing.
if ( ! empty( $_REQUEST['student_billing'] )
	&& $RosarioModules['Student_Billing'] )
{
	echo '<tr><td>' . _( 'Student Payments' ) . ': ' .
145
		'</td><td>' . Currency( $billing_payments ) . '</td></tr>';
146 147

	echo '<tr><td>' . _( 'Less' ) . ': ' . _( 'Fees' ) . ': ' .
148
		'</td><td>' . Currency( $billing_fees ) . '</td></tr>';
149

150
	$total += $billing_payments - $billing_fees;
151 152 153 154 155 156 157 158
}

echo '<tr><td><b>' . _( 'Total' ) . ': ' . '</b></td>' .
	'<td><b>' . Currency( $total ) . '</b></td></tr>';

echo '</table>';

PopTable( 'footer' );