<?php

//echo $javascript->link('jquery.jeditable.mini');
//echo $javascript->link('jobindex_editinplace');
//echo $javascript->link('addjob');
//echo $javascript->link('job_index');

?>


<h2><?php __('Jobs');?></h2>

<button id="SwitchToGrid">
    Edit Jobs
</button>

<button id="SwitchToTable">
    View Jobs
</button>

<p>
    <?php
    echo $paginator->counter(array(
    'format' => __('Page %page% of %pages%, showing %current% Jobs out of %count% total, starting on record %start%, ending on %end%', true)
    ));
    ?></p>
<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>




<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
	<thead>
		<tr>
			<th width="20%">Rendering engine</th>
			<th width="25%">Browser</th>
			<th width="25%">Platform(s)</th>
			<th width="15%">Engine version</th>
			<th width="15%">CSS grade</th>
		</tr>
	</thead>
	<tbody>

	</tbody>
	<tfoot>
		<tr>
			<th>Rendering engine</th>
			<th>Browser</th>
			<th>Platform(s)</th>
			<th>Engine version</th>
			<th>CSS grade</th>
		</tr>
	</tfoot>
</table>
		



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

	    <th><?php echo $paginator->sort('created');?></th>
	    <th><?php echo $paginator->sort('Job Number');?></th>
	    <th><?php echo $paginator->sort('enquiry_id');?></th>
	    <th><?php echo $paginator->sort('Customer');?></th>
	    <th><?php echo $paginator->sort('customer_order_number');?></th>
	    <th><?php echo $paginator->sort('supplier_reference');?></th>


	    <th><?php echo $paginator->sort('date_order_received');?></th>
	    <th><?php echo $paginator->sort('date_order_placed_on_principle');?></th>
	    <th><?php echo $paginator->sort('date_scheduled_ex_works');?></th>
	    <th><?php echo $paginator->sort('date_order_sent_to_customer');?></th>

	    <th><?php echo $paginator->sort('domestic_freight_paid_by');?></th>
	    <th><?php echo $paginator->sort('sale_category');?></th>
	    <th><?php echo $paginator->sort('shipment_category');?></th>
	    <th><?php echo $paginator->sort('comments');?></th>

	    <th><?php echo $paginator->sort('company_gross_sales_aud');?></th>
	    <th><?php echo $paginator->sort('net_sales_aud');?></th>
	    <th><?php echo $paginator->sort('gross_profit_aud');?></th>
	    <th><?php echo $paginator->sort('ato_exchange_rate');?></th>
	    <th><?php echo $paginator->sort('gst');?></th>
	    <th><?php echo $paginator->sort('currency_id');?></th>
	    <th><?php echo $paginator->sort('gst_amount');?></th>
	    <th><?php echo $paginator->sort('gross_commisions');?></th>
	    <th><?php echo $paginator->sort('invoiced_amount_inc_gst');?></th>
	    <th><?php echo $paginator->sort('net_export_sales_aud');?></th>
	    <th><?php echo $paginator->sort('gross_profit_exports_aud');?></th>
	    <th><?php echo $paginator->sort('gp_percent');?></th>
	    <th><?php echo $paginator->sort('gross_australian_sales_foreign_currency');?></th>
	    <th><?php echo $paginator->sort('net_australian_sales_foreign_currency');?></th>
	    <th><?php echo $paginator->sort('gross_profit_value_australian_sales_foreign_currency');?></th>
	    <th><?php echo $paginator->sort('gross_export_sales_foreign_currency');?></th>
	    <th><?php echo $paginator->sort('net_export_sales_foreign_currency');?></th>
	    <th><?php echo $paginator->sort('gross_profit_value_after_discount_exports_foreign_currency');?></th>
	    <th><?php echo $paginator->sort('gross_commissions');?></th>
	    <th><?php echo $paginator->sort('net_commissions');?></th>


	    <th class="actions"><?php __('Actions');?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($jobs as $job):

	    ?>
	<tr class="jobRow" 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>
		    <?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; ?>
    </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); ?>
