<?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>View Quotation</title>
    </head>
    <body>
    <center>
        <div>
            <form action="" method="get">
                <table border="1">
                    <tbody>
                        <tr>
                            <td>Enter Quotation No</td>
                            <td>:</td>
                            <td><input type="text" name="quot" value="" /></td>
                            <td><input type="submit" value="Search for Quotation" /></td>
                        </tr>
                    </tbody>
                </table>
            </form>
            <br>
            <br>
            <div style="width: 800px; border: 1px solid black;">
                <div style="font-family: sans-serif; font-size: 30px; font-weight: bolder; margin-top: 50px; margin-bottom: 30px; border: 3px silver dotted;">Quotation</div>
                <br>
                <?php
                $customer = "";
                $customerid = "";
                $date = "";
                $total = 0;
                $discount = 0;
                $grand_total = 0;
                if (isset($_GET["quot"])) {
                    $quotation = $this->db->query("SELECT date,quotation_total,quotation_discount,quotation_granTotal,customer.customer_name as cus_name,customer.customer_id as cus_id FROM quotation
 join customer on quotation.customer_customer_id = customer.customer_id where idquotation = '" . $_GET["quot"] . "'");
                    foreach ($quotation->result() as $quot) {
                        $customer = $quot->cus_name;
                        $customerid = $quot->cus_id;
                        $date = $quot->date;
                        $total = $quot->quotation_total;
                        $discount = $quot->quotation_discount;
                        $grand_total = $quot->quotation_granTotal;
                        ?>
                        <div align="left"><label>Customer : </label><?php echo $customer; ?></div>
                        <br>
                        <div align="left"><label>Date : </label><?php echo $date; ?></div>
                        <br>
                        <?php
                    }
                }
                ?>
                <table border="1"  style="width: 100%; border: 1px solid silver; border-collapse: collapse;">
                    <thead>
                        <tr>
                            <th>Print Code</th>
                            <th>Quantity</th>
                            <th>Price</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if (isset($_GET["quot"])) {
                            $quot_details = $this->db->query("SELECT qty,total_amount,customers_product.customers_product_code as pcode FROM quotation_details join customers_product on quotation_details.customers_product_product_id = customers_product.product_id where quotation_idquotation='" . $_GET["quot"] . "'");
                            foreach ($quot_details->result() as $qt_pr) {
                                ?>
                                <tr>
                                    <td><?php echo $qt_pr->pcode; ?></td>
                                    <td><?php echo $qt_pr->qty; ?></td>
                                    <td><?php echo $qt_pr->total_amount; ?></td>
                                </tr>
                                <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>
                <div class="quot_details" align="right" style="width: 800px;">
                    <table border="0">
                        <tbody>
                            <tr>
                                <td class="qt_det_td1">Total</td>
                                <td>:</td>
                                <td class="qt_det_td2"><input id="txt_total" type="text" name="quot_total" value="<?php echo $total; ?>" readonly=""/></td>
                            </tr>
                            <tr>
                                <td class="qt_det_td1">Discount</td>
                                <td>:</td>
                                <td class="qt_det_td2"><input id="txt_discount" type="text" name="quot_discount" value="<?php echo $discount; ?>" readonly=""/></td>
                            </tr>
                            <tr>
                                <td class="qt_det_td1">Grand Total</td>
                                <td>:</td>
                                <td class="qt_det_td2"><input id="txt_grand_total" type="text" name="quot_grand_total" value="<?php echo $grand_total; ?>" readonly=""/></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <?php
                if (isset($_GET["quot"])) {
                    ?>
                    <div align="right">
                        <a href="<?php echo base_url() . "index.php/Ui_controller/add_quotation_to_jobcard?quot=" . $_GET["quot"]; ?>"><input type="submit" value="Add To Job Card" /></a>
                    </div>
                    <?php
                }
                ?>
            </div>
        </div>
    </center>
</body>
</html>
