<?php

include('queries/sumQuery_Expenses.php');

if ($result->num_rows>0) {
	$content .= 		$formHead .'
						<input type="hidden" name="updateTable" value="expenses" />
						<input type="hidden" name="IDtype" value="expID" />
						<input type="hidden" name="inID" value="expenseID" />
						<tr><td colspan="8"><h3>Expenses</h3></td></tr>
						<tr>
							<th class="tableHead">Expense</th>
							<th class="tableHead">Client</th>
							<th class="tableHead">Project</th>
							<th class="tableHead">&nbsp;</th>
							<th class="tableHead">Date</th>
							<th class="tableHead" style="text-align: right">Amount</th>
							<th class="tableHead" style="text-align: center">Inv</th>
							<th class="tableHead" style="text-align: center">Paid</th>
						</tr>';
	$odd = false; 
	$invTotal = ''; 
	$expTotal = ''; 
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		// Shade Oposite Rows
		if (!empty($odd)) 
			$rowStyle = ' class="odd"';
		else 
			$rowStyle = '';
			
		$ppInvCK = '';
		$ppPaidCK = '';
		if (!empty($row['ppInv'])) {
			if ($row['ppInv'] == 1)
				$ppInvCK = ' checked';
		}
		if (!empty($row['ppPaid'])) {
			if ($row['ppPaid'] == 1)
				$ppPaidCK = ' checked';
			else 
				$ppPaidCK = '';
		}
		$content .= '<tr' . $rowStyle . '>
						<td>' . $row['expName'] . '</td>
						<td>
							' . $row['clientName'] . '
							<input type="hidden" name="proj'. $row['pID'] .'" value="'. $row['pID'] .'" />
						</td>
						<td>' . $row['projectName'] . '</td>
						<td>&nbsp;</td>
						<td>' . Date::convert($row['expDate'], 'Y-m-d', 'm/d/Y') . '</td>
						<td style="text-align: right">&#36;'. number_format($row['expAmount'],2,'.','') . '&nbsp;</td>
						<td style="text-align: center">
							<input type="hidden" name="invCurrent'. $row['pID'] .'" value="'. $row['ppInv'] .'" />
							<input type="checkbox" name="invUpdate'. $row['pID'] .'" value="1"'. $ppInvCK .' />
						</td>
						<td style="text-align: center">
							<input type="hidden" name="pmtCurrent'. $row['pID'] .'" value="'. $row['ppPaid'] .'" />
							<input type="checkbox" name="pmtUpdate'. $row['pID'] .'" value="1"'. $ppPaidCK .' />
						</td>
					</tr>';
						
		$expTotal = $expTotal+$row['expAmount'];
		
		if (!empty($odd))
			$odd = false;
		else  
			$odd = true;
	}
	$content .= '<tr>
					<th style="text-align: right">Totals:</th>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td style="text-align: right"><strong>&#36;' . number_format($expTotal, 2,'.','') . '</strong>&nbsp;</td>
				</tr>';
	$content .= '<tr><td colspan="8"><p style="text-align: right"><input type="submit" name="submit" value="Update Expenses" /></p></td></tr>';
	$content .= '</form>';
	$content .= $rowBetween;
	
	//$repTotalInv = $repTotalInv+;
	$repTotalComish = $repTotalComish+$expTotal;
}

?>