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

    <div id="alphaMessage">
	<h3>This is Alpha version of this functionality</h3>
	<pre>
	You're welcome to look around. Don't start relying on anything in it just yet though.

	Validation still needs to be finished. Also, Box weights/dimensions and Invoice details.

	Will hopefully be finished tomorrow (Friday Apr 29) - Karl</pre>
    </div>


    <?php echo $javascript->link('shipment_index');?>
    <p>
	<?php
	echo $paginator->counter(array(
	'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
	));
	?></p>
    <table cellpadding="0" cellspacing="0" class="shipments">
	<tr>
	    <th><?php echo $paginator->sort('user_id');?></th>
	    <th><?php echo $paginator->sort('date_arrived');?></th>
	    <th><?php echo $paginator->sort('date_dispatched');?></th>
	    <th><?php echo $paginator->sort('type');?></th>
	    <th>Principle(s)</th>
	    <th>PO(s)</th>
	    <th>Jobs</th>
	    <th><?php echo $paginator->sort('box_count');?></th>
	    <th><?php echo $paginator->sort('freight_forwarder_id');?></th>


	    <th><?php echo $paginator->sort('airway_bill');?></th>
	    <th><?php echo $paginator->sort('comments');?></th>
	    <th class="actions"><?php __('Actions');?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($shipments as $shipment):
	    ?>
	<tr>
	    <td>
		    <?
		    $initials = $shipment['User']['first_name'][0].$shipment['User']['last_name'][0];

		    echo $html->link($initials, array('controller'=> 'users', 'action'=>'view', $shipment['User']['id'])); ?>
	    </td>

	    <td>
		    <?php
		    echo $this->element('isEmptyDate', array('date'=>$shipment['Shipment']['date_arrived']));
		    ?>
	    </td>
	    <td>
		    <?php
		    echo $this->element('isEmptyDate', array('date'=>$shipment['Shipment']['date_dispatched']));
		    ?>
	    </td>

	    <td>
		    <?php echo $shipmentTypeShort[$shipment['Shipment']['type']]; ?>
	    </td>

	    <td>
		    <?php foreach($shipment['Principle'] as $principle):?>
			<? if(!empty($principle['short_name'])) {
			    echo $html->link($principle['short_name'], array('controller'=>'principles','action'=>'view',$principle['id']));
			}
			else {
			    echo $html->link($principle['name'], array('controller'=>'principles','action'=>'view',$principle['id']));
			}
			?>

		<br>
		    <?php endforeach;?>
	    </td>

	    <td>
		    <?php foreach($shipment['PurchaseOrder'] as $po):?>
			<?=$html->link($po['title'], array('controller'=>'purchase_orders', 'action'=>'view', $po['id']));?>
		<br>
		    <?endforeach;?>
	    </td>

	    <td>
		    <?php foreach($shipment['Job'] as $job):?>
			<?=$html->link($job['title'], array('controller'=>'jobs', 'action'=>'view', $job['id']));?>
		<br>
		    <?endforeach;?>
	    </td>

	    <td>
		    <?php echo $shipment['Shipment']['box_count']; ?>
	    </td>
	    <td>
		    <?php echo $html->link($shipment['FreightForwarder']['name'], array('controller' => 'freight_forwarders', 'action' => 'view', $shipment['FreightForwarder']['id'])); ?>
	    </td>


	    <td>
		    <?php echo $shipment['Shipment']['airway_bill']; ?>
	    </td>
	    <td>
		    <?php echo $shipment['Shipment']['comments']; ?>
	    </td>
	    <td class="actions">

	    </td>
	</tr>
	<?php endforeach; ?>
    </table>
</div>
<div class="paging">
    <?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
    | 	<?php echo $paginator->numbers();?>
    <?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
<div class="actions">
    <ul>
	<li><button id="newShipment">New Shipment</button></li>
    </ul>
</div>


<div id="dialog-form" title="New Shipment">
    <?=$this->element('add_shipment');?>
</div>

<?php debug($shipments); ?>