<div class="invoices index">
    <h2><?php __('Invoices');?></h2>

    <table cellpadding="0" cellspacing="0">
        <tr>

            <th>Issue Date</th>
            <th>Due Date</th>
            <th>Invoice Number</th>
            <th>Job Number</th>
            <th>Enquiry Number</th>
            <th>Customer</th>
            <th>Paid</th>
            <th>Payment Received</th>

            <th>User</th>
        </tr>
	<?php
	$i = 0;
	foreach ($invoices as $invoice):
	    $class = null;
	    if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	    }
	    ?>
        <tr<?php echo $class;?>>


            <td>
		    <?php echo date('j M Y',$time->toUnix($invoice['Invoice']['issue_date'])); ?>
            </td>
            <td>
		    <?php echo date('j M Y',$time->toUnix($invoice['Invoice']['due_date'])); ?>
            </td>
            <td>
		    <?php echo $invoice['Invoice']['title']; ?>
            </td>
	    <td>
		    <?php echo $html->link($invoice['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $invoice['Invoice']['job_id'])); ?>
            </td>
            <td>
		    <?php echo $html->link($invoice['Enquiry']['title'], array('controller' => 'enquiries', 'action' => 'view', $invoice['Enquiry']['id'])); ?>
            </td>
            <td>
		    <?php echo $html->link($invoice['Customer']['name'], array('controller'=>'customers', 'action'=>'view', $invoice['Customer']['id'])); ?>
            </td>
            <td>
		    <?php
		    if($invoice['Invoice']['paid'] == 0) {
			echo "UNPAID";
			echo "</td>";
			echo "<td>";
			echo "N/A";
			echo "</td>";
		    }
		    else {
			echo "PAID";
			echo "</td>";
			echo "<td>";
			echo date('j M Y',$time->toUnix($invoice['Invoice']['payment_received_date']));
			echo "</td>";
		    }



		    ?>

            </td>

            <td>
		    <?php echo $html->link($invoice['User']['username'], array('controller' => 'users', 'action' => 'view', $invoice['User']['id'])); ?>
            </td>
            
        </tr>
	<?php endforeach; ?>
    </table>
</div>