<?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>Prints Of Customer</title>
        <link type="text/css" href="<?php echo base_url(); ?>/assests/css/style.min.css" rel="stylesheet" />
        <script type="text/javascript" src="<?php echo base_url(); ?>/assests/js/jquery-1.6.4.min.js"></script>
        <script type="text/javascript" src="<?php echo base_url(); ?>/assests/js/jquery.bpopup.min.js"></script>
        <script type="text/javascript" src="<?php echo base_url(); ?>/assests/js/jquery.easing.1.3.js"></script>
        <script type="text/javascript">
            function showUpdatePrintPopUp(print_id, prints_code, print_price, print_details, delete_status) {
                $('#psm_ap_customer_print_id').val(print_id);
                $('#psm_ap_customer_print_code').val(prints_code);
                $('#psm_ap_print_price').val(print_price);
                $('#psm_ap_print_details').val(print_details);
                $('#psm_ap_delete_status').val(delete_status);
                if (delete_status == "0") {
                    $('#delete_status_reset').show();
                } else {
                    $('#delete_status_reset').hide();
                }
                $('#popup').bPopup({
                    easing: 'easeOutBack', //uses jQuery easing plugin
                    speed: 550,
                    transition: 'slideDown'
                });
            }
            function changeStatus() {
                $('#psm_ap_delete_status').val("1");
            }
        </script>
        <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>Print ID</th>
                    <th>Customer Print Code</th>
                    <th>Description</th>
                    <th>Price</th>
                    <th>Delete Status</th>
                    <th>Update</th>
                    <th>Delete</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('*');
                $allCust_products = $this->db->get_where('customers_product', array('customer_customer_id' => $customer_id));
                foreach ($allCust_products->result() as $cpr) {
                    ?>
                    <tr>
                        <td><?php echo $cpr->product_id; ?></td>
                        <td><?php echo $cpr->customers_product_code; ?></td>
                        <td><?php echo $cpr->product_description; ?></td>
                        <td><?php echo $cpr->product_price; ?></td>
                        <?php
                        if ($cpr->delete_status == 0) {
                            ?>
                            <td style="color: red;">Removed</td>
                            <?php
                        } else {
                            ?>
                            <td style="color: #1cfb23;">Not Removed</td>
                            <?php
                        }
                        ?>
                        <td><img title="Update This Product details" style="cursor: pointer;" width="40" src="<?php echo base_url(); ?>/assests/images/document_edit.png" onclick="showUpdatePrintPopUp('<?php echo $cpr->product_id; ?>', '<?php echo $cpr->customers_product_code; ?>', '<?php echo $cpr->product_price; ?>', '<?php echo $cpr->product_description; ?>', '<?php echo $cpr->delete_status; ?>')" /></td>
                        <td><a href="<?php echo base_url(); ?>index.php/Customer_Controller/deleteCustomerProduct?customer_print_id=<?php echo $cpr->product_id; ?>"><img title="Delete this Customer Product" style="cursor: pointer;" width="40" src="<?php echo base_url(); ?>/assests/images/document_delete.png"/></a></td>
                    </tr>
                    <?php
                }
            }
            ?>
            </tbody>
        </table>
    </center>
    <div id="popup" style="left: 541.5px; position: absolute; top: 1111px; z-index: 9999; opacity: 1; display: none;">
        <span class="button b-close"><span>X</span></span>
        <center>
            <?php
            echo form_open("Customer_Controller/updateProductOFCustomer");
            ?>
            <div style="font-weight: bolder;">Update Customer Print Details</div>
            <br>
            <table style="border-collapse:separate; border-spacing:5px 10px;" border="0">
                <tbody>
                    <tr>
                        <td>Print ID</td>
                        <td>:</td>
                        <td><input readonly="" id="psm_ap_customer_print_id" type="text" name="psm_ap_customer_print_id" value="" /></td>
                    </tr>
                    <tr>
                        <td>Customer Print Code</td>
                        <td>:</td>
                        <td><input id="psm_ap_customer_print_code" type="text" name="psm_ap_customer_print_code" value="" /></td>
                    </tr>
                    <tr>
                        <td>Price</td>
                        <td>:</td>
                        <td><input id="psm_ap_print_price" type="text" name="psm_ap_print_price" value="" /></td>
                    </tr>
                    <tr>
                        <td>Print Details</td>
                        <td>:</td>
                        <td><input id="psm_ap_print_details" type="text" name="psm_ap_print_details" value="" /></td>
                    </tr>
                    <tr id="delete_status_reset" style="display: none;">
                        <td>Reset Delete</td>
                        <td>:</td>
                        <td><input type="button" value="OK" onclick="changeStatus()" /><input id="psm_ap_delete_status" style="width: 50px;" type="text" name="psm_ap_delete_status" value="" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td><input type="submit" value="Submit" /></td>
                    </tr>
                </tbody>
            </table>
            <?php
            echo form_close();
            ?>
        </center>
    </div>
</body>
</html>
