<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$this->load->helper('url');
$this->load->helper('form');
$this->load->database();
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #table_customer_details{
                border: solid 1px silver;
                border-collapse: collapse;
                margin-top: 20px;
                text-align: center;
            }
            #table_customer_details th{ 
                border: #000 solid 3px;
            }
        </style>
    </head>
    <body>
    <center>
        <?php echo form_open(); ?>
        <table>
            <tr>
                <td>Select Customer</td>
                <td>:</td>
                <td>
                    <select name="selected_customer">
                        <option value="empty">-- Select Customer --</option>
                        <?php
                        foreach ($customers->result() as $cus) {
                            ?>
                            <option value="<?php echo $cus->customer_id; ?>"><?php echo $cus->customer_name; ?></option>
                            <?php
                        }
                        ?>
                    </select>
                </td>
                <td><input type="submit" value="Search" /></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <table cellpadding="10" border="1" id="table_customer_details">
            <thead style="border: #000 solid 3px; background-color: #f1f1f1;">
                <tr>
                    <th>Quotation No</th>
                    <th>Grand Total</th>
                    <th>View</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if (!isset($_POST["selected_customer"])) {
                    ?>
                <script type="text/javascript">
                    alert("Select a Customer before search.");
                </script>
                <?php
            } else if ($_POST["selected_customer"] == "empty") {
                ?>
                <script type="text/javascript">
                    alert("Select a Customer before search.");
                </script>
                <?php
            } else {
                $customer_id = $_POST["selected_customer"];
                $this->db->select('*');
                $quotation = $this->db->get_where('quotation', array('customer_customer_id' => $customer_id));
                foreach ($quotation->result() as $cpr) {
                    ?>
                    <tr>
                        <td><?php echo $cpr->idquotation; ?></td>
                        <td><?php echo $cpr->quotation_granTotal; ?></td>
                        <td><a href="<?php echo base_url() . "index.php/Ui_controller/view_quotation?quot=" . $cpr->idquotation; ?>"><input type="submit" value="View Quotation" /></a></td>
                    </tr>
                    <?php
                }
            }
            ?>
            </tbody>
        </table>
    </center>
</body>
</html>
