<h3><?=$year?></h3>

<? if(isset($month)):?>
<h4><?=$month?></h4>
<?endif;?>

<table class="jobsTable">
    <thead>
	<tr>
	    <th>Order Received</th>
	    <th>Job Number</th>
	    <th>Enquiry Number</th>
	    <th>Principle</th>
	    <th>Customer</th>
	    <th>Status</th>
	    <th>Sale Currency</th>
	    <th>Gross Sales AUD</th>
	    <th>Net Sales AUD</th>
	    <th>Gross Profit AUD</th>
	    <th>Net Export Sales Converted to Or Invoiced in AUD</th>
	    <th>GP% Excl Commissions</th>
	    <th>ATO Exchange Rate</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 Commisions</th>

	</tr>
    </thead>
    <tbody>

	<?

	$gross_sales_aud_total = 0;
	$net_sales_aud_total = 0;
	$gross_profit_total = 0;
	$count = 0;
	$gross_profit_exports_aud_total = 0;
	$gross_australian_sales_foreign_currency_total = 0;
	$net_australian_sales_foreign_currency_total = 0;
	$gross_profit_value_australian_sales_foreign_currency_total = 0;
	$gross_export_sales_foreign_currency_total =0;
	$net_export_sales_foreign_currency_total = 0;
	$gross_profit_value_after_discount_exports_foreign_currency_total =0;
	$gross_commissions_total =0;
	$net_commissions_total = 0;
	?>

	<?foreach($jobs as $job):?>

	    <? if($job['Job']['job_status'] == 'JOB CANCELLED' || $job['Job']['job_status'] == 'JOB ON HOLD' ) {
		$class='cancelled';
		$doCount = false;
	    }
	    else {
		$class ='';
		$doCount = true;
	    }
	    ?>

	<tr class="<?=$class?>">
	    <td><?=$job['Job']['date_order_received'];?></td>
	    <td class="nowrap"><?=$html->link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?>
	    </td>

	    <td class="nowrap"><?=$html->link($job['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view', $job['Enquiry']['id']));?>
	    </td>
	    <td><?=$html->link($principleList[$job['Enquiry']['principle_id']], '/principles/view/'.$job['Enquiry']['principle_id']);?></td>

	    <td><?=$html->link($job['Customer']['name'], array('controller'=>'customers','action'=>'view', $job['Customer']['id']));?></td>

	    <td><?=$job['Job']['job_status'];?></td>

	    <td>
		    <?=$job['Currency']['name'];?>
	    </td>

	    <td>
		    <?=$number->currency($job['Job']['company_gross_sales_aud']);?>
		    <?
		    if($doCount) {
			$gross_sales_aud_total += $job['Job']['company_gross_sales_aud'];
		    }
		    ?>
	    </td>
	    <td>
		    <?=$number->currency($job['Job']['net_sales_aud']);?>
		    <?
		    if($doCount) {
			$net_sales_aud_total += $job['Job']['net_sales_aud'];

		    } ?>
	    </td>
	    <td>
		    <?=$number->currency($job['Job']['gross_profit_aud']);?>
		    <?
		    if($doCount) {
			$gross_profit_total += $job['Job']['gross_profit_aud'];

		    }
		    ?>
	    </td>

	    <td>
		    <?=$number->currency($job['Job']['gross_profit_exports_aud']);?>
	    </td>
	    <td>
		    <?=$job['Job']['gp_percent'];?>
	    </td>

	    <td>
		    <?=$job['Job']['ato_exchange_rate'];?>
	    </td>
	    <td> <?=$number->currency($job['Job']['gross_australian_sales_foreign_currency'], $job['Currency']['iso4217']);?>
		    <?
		    if($doCount) {
			$gross_australian_sales_foreign_currency_total += $job['Job']['gross_australian_sales_foreign_currency']; }
		    ?>
	    </td>
	    <td>
		    <?=$number->currency($job['Job']['net_australian_sales_foreign_currency'], $job['Currency']['iso4217']);
		    if($doCount) {
			$net_australian_sales_foreign_currency_total += $job['Job']['net_australian_sales_foreign_currency'];

		    }

		    ?>
	    </td>
	    <td> <?=$number->currency($job['Job']['gross_profit_value_australian_sales_foreign_currency'], $job['Currency']['iso4217']);
		    if($doCount) {
			$gross_profit_value_australian_sales_foreign_currency_total += $job['Job']['gross_profit_value_australian_sales_foreign_currency'];

		    }
		    ?>
	    </td>
	    <td>
		    <?=$number->currency($job['Job']['gross_export_sales_foreign_currency'],$job['Currency']['iso4217']);

		    if($doCount) {

			$gross_export_sales_foreign_currency_total += $job['Job']['gross_export_sales_foreign_currency'];
		    }
		    ?>
	    </td>
	    <td> <?=$number->currency($job['Job']['net_export_sales_foreign_currency'],$job['Currency']['iso4217']);
		    if($doCount) {
			$net_export_sales_foreign_currency_total += $job['Job']['net_export_sales_foreign_currency'];
		    }
		    ?>
	    </td>
	    <td> <?=$number->currency($job['Job']['gross_profit_value_after_discount_exports_foreign_currency'],$job['Currency']['iso4217']);

		    if($doCount) {
			$gross_profit_value_after_discount_exports_foreign_currency_total += $job['Job']['gross_profit_value_after_discount_exports_foreign_currency'];
		    }
		    ?>
	    </td>
	    <td>
		    <?=$number->currency($job['Job']['gross_commissions']);
		    if($doCount) {
			$gross_commissions_total += $job['Job']['gross_commissions'];
		    }
		    ?>
	    </td>
	    <td> <?=$number->currency($job['Job']['net_commissions']);
		    if($doCount) {
			$net_commissions_total += $job['Job']['net_commissions'];
		    }

		    ?>
	    </td>
	</tr>
	    <?
	    $count++;
	endforeach;?>
    </tbody>
    <tfoot>
	<tr>
	    <td><? //Date ?></td>
	    <td><? //Job No ?></td>
	    <td><? //Enq No ?></td>
	    <td><? //Principle ?></td>
	    <td><? //Customer ?></td>
	    <td><?//Status ?></td>
	    <td><? //Sale Currency?></td>
	    <td><?=$number->currency($gross_sales_aud_total)?></td>
	    <td><?=$number->currency($net_sales_aud_total)?></td>
	    <td><?=$number->currency($gross_profit_total)?></td>
	    <td><? //Net Sales Conv to AUD?></td>
	    <td><? //GP % Excl Comm?> </td>
	    <td><? //ATO EXH RATE?></td>

	    <td><?=$number->currency($gross_australian_sales_foreign_currency_total);?></td>
	    <td><?=$number->currency($net_australian_sales_foreign_currency_total);?></td>
	    <td><?=$number->currency($gross_profit_value_australian_sales_foreign_currency_total);?></td>
	    <td><?=$number->currency($gross_export_sales_foreign_currency_total);?></td>
	    <td><?=$number->currency($net_export_sales_foreign_currency_total);?></td>
	    <td><?=$number->currency($gross_profit_value_after_discount_exports_foreign_currency_total);?></td>
	    <td><?=$number->currency($gross_commissions_total);?></td>
	    <td><?=$number->currency($net_commissions_total);?></td>

	</tr>
    </tfoot>
</table>


<?
//print_r($jobs);
?>