<?php

include('queries/sumQuery_Parent.php');

if (!empty($clientAbbr))
	$clientlabel = $clientAbbr;
else
	$clientlabel = $clientName; 

if ($result->num_rows>0) {
	$content .= 		$formHead .'
						<input type="hidden" name="updateTable" value="projectTime" />
						<input type="hidden" name="IDtype" value="projectID" />
						<input type="hidden" name="inID" value="timeID" />
						<tr><td colspan="8"><h3>'. $clientlabel .' Hourly Work</h3></td></tr>
						<tr>
							<th class="tableHead">Client/Project</th>
							<th class="tableHead">Hours</th>
							<th class="tableHead">Hourly Rate</th>
							<th class="tableHead" style="text-align: right">'. $amtInv .'</th>
							<th class="tableHead" style="text-align: center">'. $comishRate .'</th>
							<th class="tableHead" style="text-align: right">'. $comDue .'</th>
							<th class="tableHead" style="text-align: center">Inv</th>
							<th class="tableHead" style="text-align: center">Paid</th>
						</tr>';
	$odd = false; 
	$hourTotal = '';
	$invTotal = ''; 
	$comissionTotal = ''; 
	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 = '';
		}
			
		$pTotal = $row['phours']*$row['pRate'];
		$comission = number_format($pTotal*$comishPercent, 2,'.','');
		
		$content .= '<tr' . $rowStyle . '>
						<td>
							' . $row['cName'] . '/' . $row['pName'] . '
							<input type="hidden" name="proj'. $row['pID'] .'" value="'. $row['pID'] .'" />
							<input type="hidden" name="pmts'. $row['pID'] .'" value="'. $row['times'] .'" />
						</td>
						<td>' . $row['phours'] . '</td>
						<td>' . $row['pRate'] . '&nbsp;</td>
						<td style="text-align: right">&#36;' . number_format($pTotal,2,'.','') . '&nbsp;</td>
						<td style="text-align: center">' . number_format($comishPercent*100) . '&#37;</td>
						<td style="text-align: right">&#36;' . number_format($comission,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>';
		
		$hourTotal = $hourTotal+$row['phours'];					
		$invTotal = $invTotal+$pTotal;
		$comissionTotal = $comissionTotal+$comission;
		
		if (!empty($odd))
			$odd = false;
		else  
			$odd = true;
	}
	$content .= '<tr class="totals">
					<th style="text-align: right">Totals:&nbsp;</th>
					<td>'. number_format($hourTotal,2,'.','') .'</td>
					<td>&nbsp;</td>
					<td style="text-align: right">&#36;' . number_format($invTotal, 2,'.','') . '&nbsp;</td>
					<td style="text-align: center">' . number_format($comishPercent*100) . '&#37;</td>
					<td style="text-align: right">&#36;' . number_format($comissionTotal, 2,'.','') . '&nbsp;</td>
				</tr>';
	$content .= '<tr><td colspan="8"><p style="text-align: right"><input type="submit" name="submit" value="Update Hourly" /></p></td></tr>';
	$content .= '</form>';
	$content .= $rowBetween;

	//$repTotalInv = $repTotalInv+$invTotal;
	$repTotalComish = $repTotalComish+$comissionTotal;
}

?>