<div class="enquiries-view">
    <h2><?php  __("Enquiry: " . $enquiry['Enquiry']['title']);?></h2>
    <dl><?php $i = 0;
$class = ' class="altrow"';?>

        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Enquiry Number'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
    <?php echo $enquiry['Enquiry']['title']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Assigned to User'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['User']['username'], array('controller'=> 'users', 'action'=>'view', $enquiry['User']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Customer'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $enquiry['Customer']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Contact'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'], array('controller'=> 'contacts', 'action'=>'view', $enquiry['Contact']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('State'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['State']['name'], array('controller'=> 'states', 'action'=>'view', $enquiry['State']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Country'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['Country']['name'], array('controller'=> 'countries', 'action'=>'view', $enquiry['Country']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('GST Applicable'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php
            if($enquiry['Enquiry']['gst'] == 0) {
                echo "No - GST Not Applicable";
            }
            else {
                echo "Yes - GST Applicable";
            }
?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Principle'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['Principle']['name'], array('controller'=> 'principles', 'action'=>'view', $enquiry['Principle']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Status'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($enquiry['Status']['name'], array('controller'=> 'statuses', 'action'=>'view', $enquiry['Status']['id'])); ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Comments'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <span class="enquiry-view-comments">
<?php echo $enquiry['Enquiry']['comments']; ?>
            </span>
            &nbsp;

        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Billing Address'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php
            if($enquiry['BillingAddress']['customer_id'] != NULL) {
                echo $enquiry['BillingAddress']['address'].'<br>';
                echo $enquiry['BillingAddress']['city'].' '.$billingaddress['State']['name'].' '.$enquiry['BillingAddress']['postcode'].'<br>';
                echo '<b>'.$billingaddress['Country']['name'].'</b>';
            }
            else {
                echo 'No Billing Address Assigned for this Enquiry';
            }
?>	
            &nbsp;

        </dd>
        <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Shipping Address'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class;?>>
            <?php
            if($enquiry['ShippingAddress']['customer_id'] != NULL) {
                echo $enquiry['ShippingAddress']['address'].'<br>';
                echo $enquiry['ShippingAddress']['city'].' '.$shippingaddress['State']['name'].' '.$enquiry['ShippingAddress']['postcode'].'<br>';
                echo '<b>'.$shippingaddress['Country']['name'].'</b>';
            }
            else {
                echo 'No Shipping Address Assigned for this Enquiry';
}
?>	
            &nbsp;

        </dd>

    </dl>

    <div class="enquiry-actions">
        <ul>
            <li><?php echo $html->link(__('Edit Enquiry', true), array('action'=>'edit', $enquiry['Enquiry']['id'])); ?> </li>
        </ul>
    </div>
</div>
<div class="principle-emails">
    <?php
    $boxdata = array();
    $boxdata['enquirynumber'] = $enquiry['Enquiry']['title'];
//$boxdata['principle_emails'] = $principle_emails;
    ?>
<?php echo $this->element('principle_contacts_email_box', array('enquirynumber' => $enquiry['Enquiry']['title'],
'principle_emails' => $principle_emails	)); ?>


</div>


<? /*
<div class="related">
	<h3><?php __($number_of_files.' Files in this Enquiry');?><?php echo $html->image('document.png'); ?></h3>
	<?php echo $this->element('enquiry_file_table', $files); ?>
</div>
*/?>

<div class="related">
    <h3><?php __($number_of_quotes.' Quotes in this Enquiry');?></h3>
<?php echo $this->element('quote_table', $quotes); ?>
</div>


<div class="related">
    <h3>Jobs for this Enquiry</h3>
    
 <table cellpadding="0" cellspacing="0">
        <tr>

            <th>Job Number</th>
           <th>Customer Order Number</th>

            <th>Date Order Received</th>
            <th>Date Order Placed on Principle</th>
            <th>Date Sheduled Ex-Works</th>
            <th>Date Sent to Customer</th>

            <th>Domestic Freight Paid By</th>
            <th>Sale Category</th>
            <th>Shipment Category</th>
            <th>Comments</th>

            <th class="actions"><?php __('Actions');?></th>
        </tr>
<?php
        $i = 0;
        foreach ($jobs as $job):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
            ?>
        <tr<?php echo $class;?>>


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


            <td>
                    <?php echo $this->element('isEmptyDate', 
                            array('date'=>$job['Job']['date_order_received'])); ?>
            </td>
            <td>
                    <?php echo $this->element('isEmptyDate',
                            array('date' => $job['Job']['date_order_placed_on_principle']));
                    ?>
            </td>
            <td>
                    <?php echo $this->element('isEmptyDate', 
                            array('date'=>$job['Job']['date_scheduled_ex_works'])); ?>
            </td>
            <td>
                    <?php echo $this->element('isEmptyDate',
                            array('date'=>$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 class="actions">
                    <?php echo $html->link(__('View', true), array('controller'=>'jobs', 'action' => 'view', $job['Job']['id'])); ?>
                    <?php echo $html->link(__('Edit', true), array('controller'=>'jobs','action' => 'edit', $job['Job']['id'])); ?>
                    <?php echo $html->link(__('Delete', true), array('controller'=>'jobs','action' => 'delete', $job['Job']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $job['Job']['id'])); ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </table>

</div>
<div class="actions">
    <ul>
        <li> <?php echo $html->link(__('New Job', true), array('controller'=>'jobs', 'action' => 'add/enquiryid:'.$enquiry['Enquiry']['id'])); ?></li>
    </ul>
</div>



<div class="related">
    <h3><?php __($enquiry['Enquiry']['invoice_count'].' Invoices for this Enquiry');?></h3>
    <table class="quotetable">
       
           <tr>
            
            <th>Issue Date</th>
            <th>Due Date</th>
            <th>Invoice Number</th>
            <th>Customer</th>
            <th>Paid / Unpaid</th>
            <th>Payment Received Date</th>
            <th>User</th>
            <th class="actions"><?php __('Actions');?></th>
        </tr>
        <?php
        $i = 0;
        foreach ($invoices as $invoice):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
            ?>
        <tr<?php echo $class;?>>       
            <td>
                    <?php echo date('j M Y',$time->toUnix($invoice['Invoice']['issue_date'])); ?>
            </td>
            <td>
                    <?php echo date('j M Y',$time->toUnix($invoice['Invoice']['due_date'])); ?>
            </td>
            <td>
                    <?php echo $invoice['Invoice']['title']; ?>
            </td>
            <td>
                   <? echo $html->link($invoice['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $invoice['Customer']['id'])); ?>
            </td>
            <td>
                    <?php
                    if($invoice['Invoice']['paid'] == 0) {
                        echo "UNPAID";
                        echo "</td>";
                        echo "<td>";
                        echo "N/A";
                        echo "</td>";
                    }
                    else {
                        echo "PAID";
                        echo "</td>";
                         echo "<td>";
                        echo date('j M Y',$time->toUnix($invoice['Invoice']['payment_received_date']));
                        echo "</td>";
                    }



                    ?>

            <td>
                    <?php echo $html->link($invoice['User']['username'], array('controller' => 'users', 'action' => 'view', $invoice['User']['id'])); ?>
            </td>
            <td class="actions">
                    <?php echo $html->link(__('View', true), array('controller'=>'invoices', 'action' => 'view', $invoice['Invoice']['id'])); ?>
                    <?php echo $html->link(__('Edit', true), array('controller'=>'invoices','action' => 'edit', $invoice['Invoice']['id'])); ?>
                 
            </td>
        </tr>
        <?php endforeach; ?>

    </table>
</div>

<div class="actions">
    <ul>
        <li><?php echo $html->link(__('New Invoice', true), array('controller'=>'invoices', 'action' => 'add/enquiryid:'.$enquiry['Enquiry']['id'])); ?></li>
    </ul>
</div>

<div id="showemail">

</div>


<div class="related">
    <h3>
    <?php __($enquiry['Enquiry']['email_count'].' Emails for this Enquiry');?><?php echo $html->image('internet-mail.png'); ?></h3>
<?php //echo $this->element('email_table_ajax', $enquiry); ?>
<?php echo $this->element('email_table_ajax', $enquiry, array('cache'=>'+1 day')); ?>
</div>

