<div class="purchaseOrders form">
    <?php echo $javascript->link('addpurchaseorder'); ?>
    <?php echo $form->create('PurchaseOrder');?>
    <fieldset>
        <legend><?php __('Edit PurchaseOrder');?></legend>



	<?php
	//format the mySQL date in the nice readable format.
	if($this->data['PurchaseOrder']['issue_date'] != '0000-00-00') {
	    $issue_date = strtotime($this->data['PurchaseOrder']['issue_date']);
	    $issue_date_readable = date('l j F Y', $issue_date );
	}
	else {
	     $issue_date_readable = "";
	}


	if($this->data['PurchaseOrder']['dispatch_date'] != '0000-00-00') {
	    $dispatch_date = strtotime($this->data['PurchaseOrder']['dispatch_date']);
	    $dispatch_date_readable = date('l j F Y', $dispatch_date);

	}
	else {

	    $dispatch_date_readable = "";

	}

	if($this->data['PurchaseOrder']['date_arrived'] != '0000-00-00') {
	    $arrived_date = strtotime($this->data['PurchaseOrder']['date_arrived']);
	    $arrived_date_readable = date('l j F Y', $arrived_date);

	}
	else {

	    $arrived_date_readable = "";

	}


	?>

        <div class="input text">
            <label for="PurchaseOrderIssueDateDisplay">Issue Date</label>
            <input id="PurchaseOrderIssueDateDisplay" type="text" value="<?=$issue_date_readable?>" class="datePicker">
        </div>

        <div class="input text">
            <label for="PurchaseOrderDispatchDateDisplay">Dispatch Date</label>
            <input id="PurchaseOrderDispatchDateDisplay" type="text" value="<?=$dispatch_date_readable?>" class="datePicker">
        </div>

        <div class="input text">
            <label for="PurchaseOrderDateArrivedDisplay">Arrived Date</label>
            <input id="PurchaseOrderDateArrivedDisplay" type="text" value="<?=$arrived_date_readable?>" class="datePicker">
        </div>


	<?php
	echo $form->input('id');
	echo $form->input('issue_date', array('type'=>'hidden'));
	echo $form->input('dispatch_date', array('type'=>'hidden'));
	echo $form->input('date_arrived', array('type'=>'hidden'));
	echo $form->input('title', array('readonly'=>'readonly'));
	echo $form->input('principle_id');
	echo $form->input('principle_reference');
	echo $form->input('document_id', array('value'=>0, 'type'=>'hidden'));
	echo $form->input('Job', array('label'=>'Jobs in this PO',
	'type'=>'select',
	'multiple'=>'checkbox',
	'options'=>$jobs,
	'selected'=>$html->value('Job.Job')));
	?>
    </fieldset>
    <?php echo $form->end('Submit');?>
</div>
<div class="actions">
    <ul>
        <li><?php echo $html->link(__('Delete', true), array('action' => 'delete', $form->value('PurchaseOrder.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('PurchaseOrder.id'))); ?></li>
        <li><?php echo $html->link(__('List PurchaseOrders', true), array('action' => 'index'));?></li>
        <li><?php echo $html->link(__('List Principles', true), array('controller' => 'principles', 'action' => 'index')); ?> </li>
        <li><?php echo $html->link(__('New Principle', true), array('controller' => 'principles', 'action' => 'add')); ?> </li>
        <li><?php echo $html->link(__('List Documents', true), array('controller' => 'documents', 'action' => 'index')); ?> </li>
        <li><?php echo $html->link(__('New Document', true), array('controller' => 'documents', 'action' => 'add')); ?> </li>
        <li><?php echo $html->link(__('List Jobs', true), array('controller' => 'jobs', 'action' => 'index')); ?> </li>
        <li><?php echo $html->link(__('New Job', true), array('controller' => 'jobs', 'action' => 'add')); ?> </li>
    </ul>
</div>

<?php debug($this->data);?>
