<?php echo $javascript->link('addLineItem'); ?>

<?php echo $javascript->link('lineItemPriceNoCosting'); ?>

<div class="quotes view">
    <h2><?php

        $enquirynumber_link = $html->link($quote['Enquiry']['title'],
                array('controller'=>'enquiries', 'action'=>'view', $quote['Enquiry']['id']));

        $customer_link = $html->link( $customer['Customer']['name'], array('controller'=>'customers', 'action' => 'view', $customer['Customer']['id']));


        if($quote['Quote']['revision'] == 0) {
            __('Quote: '.$enquirynumber_link. ' for '. $customer_link);
        }
        else {
            __('Quote: '.$enquirynumber_link.' Revision '.$quote['Quote']['revision'].' for '. $customer_link);
        }
        ?></h2>
</div> 

<?php
$i = 0;
foreach ($quote['QuotePage'] as $quotePage):
    $class = null;
    if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
    }
    ?>

<div class="related">
    <h3>Page <?php echo $i; ?> </h3>
    <div class="quotepageview">
            <?php echo $quotePage['content']; ?>
    </div>

        <?php echo $html->link(__('Edit', true), array('controller'=>'quote_pages', 'action'=>'edit',$quotePage['id']));?>



        <?php echo $html->link(__('Delete', true), array('controller'=> 'quote_pages', 'action'=>'delete', $quotePage['id']), null, sprintf(__('Are you ABSOLUTELY sure you want to delete Page # %s? This cannot be undone.', true), $i)); ?>


</div>

<div id="viewpage<?php echo $i;?>">
</div>

<?php endforeach; ?>

<div class="actions">
    <ul>
        <li><?php echo $html->link(__('Add Cover Page', true), array('controller'=> 'quote_pages', 'action'=>'add/'.$quote['Quote']['id']));?> </li>
        <li> <?php echo $html->link(__('Regenerate First Page', true), array('controller'=> 'quote_pages', 'action'=>'regeneratePage', $quotePage['id']), null, sprintf(__('Are you sure you want to regenerate the first page? You will lose any changes you have made to it.', true), $i)); ?></li>
    </ul>
</div>



<div class="quoteproducts">


    <div id="productTable"></div>

    <div class="actions">
        <ul>
            <button id="addLineItem">Add a Product to this Quote</button>

            <button id="generatePDF">Generate a PDF of this Quote</button>

        </ul>
    </div>

    <div class="commercialComments">
        <h3><?php __('Commercial Details');?></h3>


        <?php echo $form->create('Quote');?>
        <fieldset>
            <?php
            echo $form->input('id', array('type' => 'hidden', 'value' => $quote['Quote']['id']));

            echo $form->input('enquiry_id', array('type' => 'hidden'));
            echo $form->input('delivery_time');
            echo $this->element('payment_terms_box');
            //echo $form->input('date_issued');
            ?>


            <?php
            //format the mySQL date in the nice readable format.
            $phpdate_issued = strtotime($quote['Quote']['date_issued']);

            $date_issued_readable = date('l j F Y', $phpdate_issued );

            ?>
            <div class="input select">
                <label for="QuoteDateIssuedDisplay">Date Issued</label>
                <input id="QuoteDateIssuedDisplay" type="text" value="<?php echo $date_issued_readable; ?>">
            </div>

            <input id="QuoteDateIssued" type="hidden" name="data[Quote][date_issued]" value="<?php echo $quote['Quote']['date_issued']; ?>">

            <?
            echo $form->input('days_valid', array('default'=>'30'));
            echo $form->input('currency_id', array('label' => 'Sale Currency', 'options' => $currencies));
            echo $form->input('delivery_point', array('default' => 'EX-CMC TECHNOLOGIES, ALEXANDRIA NSW'));
            echo $form->input('exchange_rate', array('default' => 'FIXED'));
            echo $form->input('customs_duty', array('default' => 'NIL'));

            echo $form->end('Update Commercial Terms');
            ?>
        </fieldset>



    </div>



</div>



<div id="addLineItem-form" title="Add a Product to this quote">
    <?php echo $form->create('LineItem');?>

    <?php

    echo $form->input('quote_id', array('type'=>'hidden', 'value'=>$quote['Quote']['id']));
    echo $form->input('item_number');
    echo $form->input('option', array('label'=>'Optional Item'));

    echo $form->input('quantity', array('class'=>'nocostinput'));


    echo $form->input('fromDB', array('label'=>'Is this product in the database already?',
        'empty'=>'',
        'type'=>'select', 'options'=>array('Yes'=>'Yes', 'No'=>'No')));
    ?>



    
    <? echo $form->input('principle_id', array('options'=>$principles, 'empty' =>'Select the Principle for this Product', 'div'=>'fromProductDB')); ?>
   
    
    
    <?php 
        echo $form->input('title', array('div'=>'blankItem'));
        echo $form->input('description', array('div'=>'blankItem'));
    ?>


    <div id="productBox"></div>

    <div id="productOptionsBox"></div>

    <? echo $form->input('unit_price', array('id'=>"unitPrice", 'div'=>'nocosting', 'class'=>'nocostinput')); 
       echo $form->input('discount_percent', array('id'=>'discountPercent', 'div'=>'nocosting', 'class'=>'nocostinput'));
       echo $form->input('discount_amount_each', array('id'=>'discountAmountEach', 'readonly'=>'readonly', 'div'=>'nocosting'));
       echo $form->input('net_price_each', array('id'=>'net_price_each', 'readonly'=>'readonly', 'div'=>'nocosting'));
       echo $form->input('total_discount_amount', array('id'=>'total_discountAmount', 'readonly'=>'readonly', 'div'=>'nocosting'));
       echo $form->input('gross_price', array('id'=>'grossPrice', 'readonly'=>'readonly', 'div'=>'nocosting'));
       echo $form->input('net_price', array('id'=>'netPrice', 'readonly'=>'readonly', 'div'=>'nocosting'));
    ?>

    <div id="addLineItem-form2">
        <?
        /*
        echo $form->input('title');
        echo $form->input('description');


        echo $form->input('quote_id');
        echo $form->input('product_id');
        echo $form->input('costing_id');
        echo $form->input('unit_price');
        */
        ?>

    </div>

    <?php //echo $form->end('Submit');
    ?>
</div>


<div id="editLineItem">
    <?php
    //This div will be updated with a fresh copy of /lineitems/edit/<id>
    
    ?>
</div>


<div id="mydebug"></div>

<? debug($quoteProducts); ?>