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

<h3><?php __($quote['Quote']['line_item_count'].' Items in this Quote');?></h3>
<table cellpadding = "0" cellspacing = "0"  id= "quoteTable" class="quoteproducts" ">
       <thead>
        <tr>
            <th><?php __('Item Number'); ?></th>
            <th><?php __('Quantity'); ?></th>
            <th><?php __('Title'); ?></th>
            <th><?php __('Description'); ?></th>
            <th>Unit Price (<?php echo $quote['Currency']['iso4217']; ?>)</th>

            <th><?php __('Total Price'); ?> (<?php echo $quote['Currency']['iso4217']; ?>)</th>

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

    <?
    $dontTotal = 0; //if we encounter an optional item. Make Subtotal, GST and total payable to be $TBA

    $subTotal = 0;

    foreach ($lineItems as $lineItem) {
        $thisNetPrice = $lineItem['LineItem']['net_price'];

        $subTotal += $thisNetPrice;

        if($lineItem['LineItem']['option'] == 1) {
            $dontTotal = 1;
        }

    }

    ?>
    <tfoot>
        <tr class="divider">
            <td></td>
            <td></td>
            <td></td>
            <td class="rightAlign">SUB-TOTAL (Excluding GST)</td>
            <td></td>
            <td><?php
                if($dontTotal == 0) {
                    echo $quote['Currency']['symbol'].$subTotal;
                }
                else {
                    echo "TBA";
                }

                ?></td>
            <td></td>
        </tr>

        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="rightAlign">GST (10%)</td>
            <td></td>
            <td><?php

                if($dontTotal == 0) {

                    if($quote['Enquiry']['gst'] == 1 ) {
                        $gst = 0.1 * $subTotal;
                        echo $quote['Currency']['symbol'].$gst;

                    }
                    else {
                        $gst = 0;
                        echo "N/A";

                    }
                }
                else {
                    echo "TBA";
                }


                ?></td>
            <td></td>
        </tr>


        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="rightAlign">TOTAL PAYABLE</td>
            <td></td>
            <td><?php
                if($dontTotal == 0) {

                    $total = $subTotal + $gst;
                    echo $quote['Currency']['symbol'].$total;

                }
                else {
                    echo "TBA";
                }
                ?>
            </td>
            <td></td>
        </tr>

    </tfoot>

    <?php
    $i = 0;

    $subTotal = 0;

    foreach ($lineItems as $lineItem):
        $class = null;
        if ($i++ % 2 == 0) {
            $class = ' class="altrow"';
        }
        
        ?>
    <tr<?php echo $class;?>>

        <td><?php
                if($lineItem['LineItem']['option'] == 1 ) {
                    echo 'Option <br>';
                }
                echo number_format($lineItem['LineItem']['item_number'], 1, '.', '');?></td>

        <td><?php echo $lineItem['LineItem']['quantity'];?></td>
        <td><?php echo $lineItem['LineItem']['title'];?></td>
        <td class="leftAlign"><?php echo $lineItem['LineItem']['description'];?></td>

        <td><?php echo $quote['Currency']['symbol'].$lineItem['LineItem']['unit_price'];

        //If there's a costing, or a discount. Show it.

        
        if($lineItem['LineItem']['discount_percent']) {
            echo "<br>less ".$lineItem['LineItem']['discount_percent']."% discount (-".
            $quote['Currency']['symbol'].$lineItem['LineItem']['discount_amount_each'].")<br>";
            echo "=<br>".$quote['Currency']['symbol'].$lineItem['LineItem']['net_price_each'];
        }

        ?></td>
        <td class="netPrice"><?php


                echo $quote['Currency']['symbol'].$lineItem['LineItem']['net_price']; ?></td>

        <td class="actions">
              
                <?php echo $html->link(__('View/Edit', true), array('controller'=> 'line_items', 'action'=>'edit', $lineItem['LineItem']['id']), array('class'=>'editLink')); ?>


                <?php echo $html->link(__('Remove', true), array('controller'=> 'line_items', 'action'=>'delete', $lineItem['LineItem']['id']), null, sprintf(__('Are you sure you want to remove # %s?', true), $lineItem['LineItem']['item_number'])); ?>
        </td>


    </tr>
    <?php endforeach; ?>

</table>