<?php
if ($permissions->hasPermission('addProduct')) {
    include("Views/Inventory/addproduct.php");
}
include 'Views/Inventory/disable_enable_modal.php';
?>
<div id="Barcode" style="display:none"></div>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print CommonLanguage::getMessage('product_list'); ?></div>
            <div class="row">

                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('customer_name');  ?></label>
                    <input type="hidden" class="full-width" name="customers_id" value="<?php echo $customerID; ?>" data-select-name='<?php echo $CustomerName; ?>' multiple id="customers_id" />
                </div>



                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('product_name'); ?></label>
                    <input type="hidden" class="full-width" name="product_id" multiple id="product_id" />
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered inventory" id="tableWithSearch">
                        <thead>
                            <tr>
                                <th class="text-center" style="width:15%"><?php print CommonLanguage::getMessage('customer_name'); ?></th>

                                <th class="text-center" style="width:15%"><?php print CommonLanguage::getMessage('product_name'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>

                    </table>
                </div>

            </div>
        </div>
    </div>
</div>


<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('product_list')) ?>,
        Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')) ?>;
    var Ismatch = <?php echo json_encode($Ismatches) ?>;
    var is_new = <?php echo json_encode($is_new) ?>;
    $(function() {
        var optns = {};
        if ($('.prdt_check_all_td').length > 0) {
            optns = {
                cb_ft: function(dt_optns) {
                    // stop sorting for column since on click on header checkbox the sorting is triggered
                    dt_optns.columnDefs.push({
                        targets: [0],
                        "orderable": false
                    });
                },
            };
        }


        new Switchery($("#show_zero_qty").get(0), {
            color: $.Pages.getColor("primary")
        });
        var table = $('#tableWithSearch').DataTable();
        build_select2($("#customers_id"), "xhr/customerSearch");

        build_select2($("#product_id"), "xhr/CommonSearch?col_name=Product_Name&col_id=product_id&table=tbl_stock_products");

        $('#tableWithSearch').on('page.dt', function() {
            var info = table.page.info();
        });

        $('#product_id,#customers_id').on('change', function() {
            RebuildDataTable(title, [0, 1], "InventoryAjax/products_customers_list", {
                customers_id: $('#customers_id').val(),
                product_id: $('#product_id').val()
            }, '', '', optns);
        })
 

        if (Ismatch) {
            $('#customers_id').trigger('change')
        }






    });
</script>
