
<script type="text/javascript" charset="utf-8">
    $(document).ready( function () {
	var oTable = $('#jobTable').dataTable( {
	    "sScrollY": 500,
	    "sScrollX": "100%",
	    "sScrollXInner": "110%"
	} );
	/*var keys = new KeyTable( {
	    "table": document.getElementById('example'),
	    "datatable": oTable
	} );
    } );*/


	var keys = new KeyTable( {
	    "table": document.getElementById('jobTable')
	} );

	/* Apply a return key event to each cell in the table */
	keys.event.action( null, null, function (nCell) {
	    /* Block KeyTable from performing any events while jEditable is in edit mode */
	    keys.block = true;

	    /* Initialise the Editable instance for this table */
	    $(nCell).editable( function (sVal) {
		/* Submit function (local only) - unblock KeyTable */
		keys.block = false;
		return sVal;
	    }, {
		"onblur": 'submit',
		"onreset": function(){
		    /* Unblock KeyTable, but only after this 'esc' key event has finished. Otherwise
		     * it will 'esc' KeyTable as well
		     */
		    setTimeout( function () {keys.block = false;}, 0);
		}
	    } );

	    /* Dispatch click event to go into edit mode - Saf 4 needs a timeout... */
	    setTimeout( function () { $(nCell).click(); }, 0 );
	} );




    });


</script>


<table id="jobTable" cellpadding="0" cellspacing="0" class="display KeyTable">
    <thead>
	<tr>


	    <th>Created</th>
	    <th>Job Number</th>
	    <th>Enquiry</th>
	    <th>Customer</th>
	    <th>Customer order No</th>
	    <th>Supplier Reference</th>


	    <th>Date Order Received</th>
	    <th>Date Order Placed On Principle</th>
	    <th>date_scheduled_ex_works</th>
	    <th>date_order_sent_to_customer</th>

	    <th>domestic_freight_paid_by</th>
	    <th>sale_category</th>
	    <th>shipment_category</th>
	    <th>comments</th>

	    <th>company_gross_sales_aud</th>
	    <th>net_sales_aud</th>
	    <th>gross_profit_aud</th>
	    <th>ato_exchange_rate</th>
	    <th>gst</th>
	    <th>currency_id</th>
	    <th>gst_amount</th>
	    <th>gross_commisions</th>
	    <th>invoiced_amount_inc_gst</th>
	    <th>net_export_sales_aud</th>
	    <th>gross_profit_exports_aud</th>
	    <th>gp_percent</th>
	    <th>gross_australian_sales_foreign_currency</th>
	    <th>net_australian_sales_foreign_currency</th>
	    <th>gross_profit_value_australian_sales_foreign_currency</th>
	    <th>gross_export_sales_foreign_currency</th>
	    <th>net_export_sales_foreign_currency</th>
	    <th>gross_profit_value_after_discount_exports_foreign_currency</th>
	    <th>gross_commissions</th>
	    <th>net_commissions</th>



	    <? // <th class="actions"><?php __('Actions');</th> ?>
	</tr>
    </thead>
    <tbody>

	<?php
	$i = 0;
	foreach ($jobs as $job):

	    ?>
	<tr class="" id="<?=$job['Job']['id'];?>">



	    <td class="enqdate">
		    <?php

		    echo date('j M Y',$time->toUnix($job['Job']['created'])); ?>
	    </td>

	    <td>
		    <?php echo $html->link(__($job['Job']['title'], true), array('action' => 'view', $job['Job']['id'])); ?>
	    </td>
	    <td>
		    <?php echo $html->link($job['Enquiry']['title'], array('controller' => 'enquiries', 'action' => 'view', $job['Enquiry']['id'])); ?>
	    </td>
	    <td>
		    <?php echo $html->link($customers[$job['Enquiry']['customer_id']], array('controller'=>'customers',
		    'action'=>'view', $job['Enquiry']['customer_id'])); ?>
	    </td>
	    <td class="customerOrderNo">
		    <?php echo $job['Job']['customer_order_number']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['supplier_reference']; ?>
	    </td>
	    <td>

		    <?php echo $job['Job']['date_order_received']; ?>
	    </td>

	    <td class="datepicker-editable">
		    <?php echo isEmptyDate($job['Job']['date_order_placed_on_principle']); ?>
	    </td>
	    <td>
		    <?php echo isEmptyDate($job['Job']['date_scheduled_ex_works']); ?>
	    </td>
	    <td>
		    <?php echo isEmptyDate($job['Job']['date_order_sent_to_customer']); ?>
	    </td>


	    <td>
		    <?php echo $job['Job']['domestic_freight_paid_by']; ?>
	    </td>
	    <td>
		    <?php echo $job['Job']['sale_category']; ?>
	    </td>
	    <td>
		    <?php echo $job['Job']['shipment_category']; ?>
	    </td>
	    <td>
		    <?php echo $job['Job']['comments']; ?>
	    </td>


	    <td>
		    <?php echo $job['Job']['company_gross_sales_aud']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['net_sales_aud']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_profit_aud']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['ato_exchange_rate']; ?>
	    </td>

	    <td>
		    <?php if($job['Job']['gst'] == 1) {
			echo "GST Applicable";
		    }
		    else {
			echo "N/A";
		    }

		    ?>


	    </td>

	    <td>
		    <?php echo $currencies[$job['Job']['currency_id']]; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gst_amount']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_commisions']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['invoiced_amount_inc_gst']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['net_export_sales_aud']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_profit_exports_aud']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gp_percent']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_australian_sales_foreign_currency']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['net_australian_sales_foreign_currency']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_profit_value_australian_sales_foreign_currency']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_export_sales_foreign_currency']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['net_export_sales_foreign_currency']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_profit_value_after_discount_exports_foreign_currency']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['gross_commissions']; ?>
	    </td>

	    <td>
		    <?php echo $job['Job']['net_commissions']; ?>
	    </td>





		<? /* <td class="actions">
		<?php //echo $html->link(__('View', true), array('action' => 'view', $job['Job']['id'])); ?>
		<?php echo $html->link(__('Edit', true), array('action' => 'edit', $job['Job']['id']), array('class'=>'editWindow', 'name'=>$job['Job']['id'])); ?>
	</td> */ ?>
	</tr>
	<?php endforeach; ?>
    </tbody>
</table>



<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 id="editDiv">
</div>


<?php

function isEmptyDate($date) {
    if($date == "0000-00-00") {
	return "-";
    }
    else {
	return $date;
    }
}
?>

<?php // debug($customers); ?>
