<?php echo $form->create('Shipment', array('default'=>false));?>
<?php
echo $form->input('user_id', array('type'=>'hidden', 'value'=>$currentuser['User']['id']));
echo $form->input('type', array('options'=>$shipmentType, 'id'=>'shipmentType'));
echo $form->input('id', array('type'=>'hidden'));
?>
<div id="importFields" class="hiddenDefault">
    <?
    echo $form->input('date_arrived_display', array('label'=>'Date Arrived', 'id'=>'date_arrived_display', 'value'=>$this->element('isEmptyDate', array('date'=>$this->data['Shipment']['date_arrived']))));
    echo $form->input('date_arrived', array('type'=>'hidden', 'id'=>'date_arrived'));
    ?>



</div>

<div id="dateDispatched" class="hiddenDefault">
    <?
    echo $form->input('date_dispatched_display', array('label'=>'Date Dispatched', 'id'=>'date_dispatched_display', 'value'=>$this->element('isEmptyDate', array('date'=>$this->data['Shipment']['date_dispatched']))));

    echo $form->input('date_dispatched', array('type'=>'hidden', 'id'=>'date_dispatched'));
    ?>
</div>

<div id="purchaseOrder" class="hiddenDefault">
    <?
    echo $form->input('purchase_order', array('id'=>'purchase_order_autocomplete' ,'label'=>'Purchase Order (start typing and select from the list)'));?>

    <ul id="purchaseOrdersList" class="habtmList">
	<?php foreach($this->data['PurchaseOrder'] as $po):?>
	<li id="PurchaseOrderID_<?=$po['id']?>">
	    <button class="removeFromList">X</button>
		<?=$po['title'];?>
	    <input type="hidden" name="data[PurchaseOrder][PurchaseOrder][]" value="<?=$po['id']?>">
	</li>
	<?php endforeach?>
    </ul>
</div>

<div id="principle" class="hiddenDefault">
    <? echo $form->input('Principle', array('name'=>'PrincipleSelect', 'type'=>'select', 'multiple'=>false)); ?>
    <button id="addPrinciple">Add Principle to this Shipment</button>
    <ul id="principlesList" class="habtmList">
	<?php foreach($this->data['Principle'] as $principle):?>
	<li id="PrincipleID_<?=$principle['id']?>">
	    <button class="removeFromList">X</button>
		<?=$principle['name'];?>
	    <input type="hidden" name="data[Principle][Principle][]" value="<?=$principle['id']?>">
	</li>
	<?php endforeach?>
    </ul>

</div>


<div id="job" class="hiddenDefault">
    <?
    echo $form->input('job', array('id'=>'job_autocomplete', array('label'=>'Job (start typing and select from the list)')));
    ?>
    <span class="moreInfo">Jobs in this Shipment will be updated as "sent"</span>

    <ul id="jobsList" class="habtmList">
	<?php foreach($this->data['Job'] as $job):?>
	<li id="JobID_<?=$job['id']?>">
	    <button class="removeFromList">X</button>
		<?=$job['title'];?>
	    <input type="hidden" name="data[Job][Job][]" value="<?=$job['id']?>">
	</li>
	<?php endforeach?>
    </ul>

</div>

<div id="customer" class="hiddenDefault">
    <?=$form->input('customer', array('id'=>'customer_autocomplete', 'label'=>'Customer (start typing and select from the list)', 'value'=>$this->data['Customer']['name']));?>
    <?=$form->input('customer_id', array('type'=>'hidden', 'id'=>'customer_id', 'value'=>$this->data['Shipment']['customer_id']));?>
</div>

<div id="addressSpan" class="hiddenDefault">
    <span>Shipping Address:</span>
</div>
<div id="address" class="hiddenDefault">
    <?
    if(isset($address)):?>
    <div class="address">
	<span class="address"><?=$address['Address']['address']?></span>
	<span class="city"><?=$address['Address']['city'];?></span>
	<span class="state"><?=$address['State']['name'];?></span>
	<span class="country"><?=$address['Country']['name'];?></span>
	<button class="changeAddress" id="<?=$address['Address']['id']?>">Select a different Address</button>
    </div>
    <? endif;?>

</div>
<?=$form->input('address_id', array('type'=>'hidden', 'id'=>'address_id', 'value'=>$this->data['Shipment']['address_id']));?>

<div id="freight_forwarder" class="hiddenDefault">
    <?=$form->input('freight_forwarder_id', array('type'=>'select','empty'=>'Choose Freight Forwarder'));?>

    <button class="addFreightForwarder hiddenDefault">Add Freight Forwarder</button>
    <div id="newFreightForwarderDiv" class="hiddenDefault">
	<?=$form->input('newFreightForwarderName');?>
	<button class="saveNewFF">Save</button>
	<button class="cancelNewFF">Cancel</button>
    </div>

</div>

<div id="airway_bill" class="hiddenDefault">
    <?=$form->input('airway_bill');?>
</div>

<div id="boxes" class="hiddenDefault">
    <button id="addBox">Add Box</button>

    <?php $boxNo = 0;?>
    <?php foreach($this->data['Box'] as $box):?>
    <div id="" class="boxForm">
	<button class="removeBox">X</button>
	    <?=$form->input("Box.{$boxNo}.id", array('type'=>'hidden'));?>
	    <?=$form->input("Box.{$boxNo}.shipment_id", array('type'=>'hidden', 'value'=>$this->data['Shipment']['id']));?>
	    <?=$form->input("Box.{$boxNo}.length", array('label'=>'Length (cm)', 'div'=>'length'));?>
	    <?=$form->input("Box.{$boxNo}.width", array('label'=>'Width (cm)', 'div'=>'width'));?>
	    <?=$form->input("Box.{$boxNo}.height", array('label'=>'Height (cm)', 'div'=>'height'));?>
	    <?=$form->input("Box.{$boxNo}.weight", array('label'=>'Weight (kg)', 'div'=>'weight'));?>
    </div>
	<?php
	$boxNo++;
    endforeach;?>
</div>


<div id="invoices" class="hiddenDefault">


    <button id="addInvoice">Add Invoice</button>
    <?
    $invNo = 0;
    ?>

    <?
    foreach($this->data['ShipmentInvoice'] as $invoice):?>
    <div class="invForm">
	<button class="removeInvoice">X</button>
	    <?
	    echo $form->input("ShipmentInvoice.{$invNo}.id", array('type'=>'hidden'));
	    echo $form->input("ShipmentInvoice.{$invNo}.shipment_id", array('type'=>'hidden', 'value'=>$this->data['Shipment']['id']));
	    echo $form->input("ShipmentInvoice.{$invNo}.invoice_type", array('type'=>'select','label'=>'Invoice Type', 'div'=>'inv_invoice_type', 'options'=>$invoiceType));
	    echo $form->input("ShipmentInvoice.{$invNo}.currency_id",array('label'=>'Currency', 'div'=>'inv_currency_id', 'options'=>$currencies, 'empty'=>'Choose Invoice Currency'));
	    echo $form->input("ShipmentInvoice.{$invNo}.freight_forwarder_id", array('label'=>'Freight Forwarder', 'div'=>'inv_freight_forwarder_id', 'options'=>$freightForwarders, 'empty'=>'Select Freight Forwarder'));
	    echo $form->input("ShipmentInvoice.{$invNo}.principle_id", array('label'=>'Invoice Issued by Principle', 'div'=>'inv_principle_id', 'options'=>$principles, 'empty'=>'Select Principle'));
	    echo $form->input("ShipmentInvoice.{$invNo}.invoice_number", array('label'=>'Invoice Number', 'div'=>'inv_invoice_number'));
	    echo $form->input("ShipmentInvoice.{$invNo}.date_issued", array('label'=>'Date Issued', 'div'=>'inv_date_issued', 'class'=>'date_issued', 'type'=>'text'));
	    echo $form->input("ShipmentInvoice.{$invNo}.invoice_amount", array('label'=>'Invoice Amount', 'div'=>'inv_invoice_amount'));
	    echo $form->input("ShipmentInvoice.{$invNo}.gst_amount", array('label'=>'GST Amount', 'div'=>'inv_gst_amount'));
	    echo $form->input("ShipmentInvoice.{$invNo}.deferred_gst", array('label'=>'Deferred GST?', 'div'=>'inv_deferred_gst', 'options'=>$yesNo));
	    echo $form->input("ShipmentInvoice.{$invNo}.deferred_gst_amount", array('label'=>'Deferred GST Amount', 'div'=>'inv_deferred_gst_amount'));
	    echo $form->input("ShipmentInvoice.{$invNo}.approved", array('label'=>'Approved', 'div'=>'inv_approved', 'options'=>$yesNo));
	    echo $form->input("ShipmentInvoice.{$invNo}.paid", array('label'=>'Paid', 'div'=>'inv_paid', 'options'=>$yesNo));
	    echo $form->input("ShipmentInvoice.{$invNo}.date_paid", array('label'=>'Date Paid', 'div'=>'inv_date_paid', 'class'=>'date_paid',  'type'=>'text'));
	    ?>

    </div>
	<?
	$invNo++;
    endforeach;?>
</div>


<div id="comments" class="hiddenDefault">
    <?=$form->input('comments');?>

</div>


<?php echo $form->end();?>
<div id="boxFactory" class="hiddenDefault">
    <?=$form->input('length', array('label'=>'Length (cm)', 'div'=>'length'));?>
    <?=$form->input('width', array('label'=>'Width (cm)', 'div'=>'width'));?>
    <?=$form->input('height', array('label'=>'Height (cm)', 'div'=>'height'));?>
    <?=$form->input('weight', array('label'=>'Weight (kg)', 'div'=>'weight'));?>
</div>

<div id="invoiceFactory" class="hiddenDefault">
    <?
    echo $form->input("invoice_type", array('type'=>'select','label'=>'Invoice Type', 'div'=>'inv_invoice_type', 'options'=>$invoiceType));
    echo $form->input("currency_id",array('label'=>'Currency', 'div'=>'inv_currency_id', 'options'=>$currencies, 'empty'=>'Choose Invoice Currency'));
    echo $form->input("freight_forwarder_id", array('label'=>'Invoice Issued by Freight Forwarder', 'div'=>'inv_freight_forwarder_id', 'options'=>$freightForwarders, 'empty'=>'Select Freight Forwarder'));
    echo $form->input('principle_id', array('label'=>'Invoice Issued by Principle', 'div'=>'inv_principle_id', 'options'=>$principles, 'empty'=>'Select Principle'));
    echo $form->input("invoice_number", array('label'=>'Invoice Number', 'div'=>'inv_invoice_number'));
    echo $form->input("date_issued", array('label'=>'Date Issued', 'div'=>'inv_date_issued', 'class'=>'date_issued_factory', 'type'=>'text'));
    echo $form->input("invoice_amount", array('label'=>'Invoice Amount', 'div'=>'inv_invoice_amount'));
    echo $form->input("gst_amount", array('label'=>'GST Amount', 'div'=>'inv_gst_amount'));
    echo $form->input("deferred_gst", array('label'=>'Deferred GST?', 'div'=>'inv_deferred_gst', 'options'=>$yesNo));
    echo $form->input("deferred_gst_amount", array('label'=>'Deferred GST Amount', 'div'=>'inv_deferred_gst_amount'));
    echo $form->input("approved", array('label'=>'Approved', 'div'=>'inv_approved', 'options'=>$yesNo));
    echo $form->input("paid", array('label'=>'Paid', 'div'=>'inv_paid', 'options'=>$yesNo));
    echo $form->input("date_paid", array('label'=>'Date Paid', 'div'=>'inv_date_paid', 'class'=>'date_paid_factory', 'type'=>'text'));
    ?>

</div>