<style>
    .text-white{
        color: white;
    }
    a{
        color: #4c0870;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php echo $title; ?> </div>
        </div>
        <div class="panel-body">
            <div class="row form-group">
                <div class="col-md-3">
                    <label><?php print CommonLanguage::getMessage('customer_group'); ?></label>
                    <input type="hidden"   name="filter_org_group_id" id="filter_org_group_id" class="full-width"/>
                </div>
                <div class="col-md-2">
                    <label><?php print CommonLanguage::getMessage('is_contacted'); ?></label>
                    <select name="is_contacted" id="is_contacted" data-init-plugin="select2" class="full-width">
                        <option value=""><?php  echo CommonLanguage::getMessage('select');?></option>
                        <option value="0"><?php  echo CommonLanguage::getMessage('no');?></option>
                        <option value="1"><?php  echo CommonLanguage::getMessage('yes');?></option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label><?php print CommonLanguage::getMessage('is_potiential'); ?></label>
                    <select name="is_potiential" id="is_potiential" data-init-plugin="select2" class="full-width">
                        <option value=""><?php  echo CommonLanguage::getMessage('select');?></option>
                        <option value="0"><?php  echo CommonLanguage::getMessage('no');?></option>
                        <option value="1"><?php  echo CommonLanguage::getMessage('yes');?></option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label><?php print CommonLanguage::getMessage('is_existing'); ?></label>
                    <select name="is_existing" id="is_existing" data-init-plugin="select2" class="full-width">
                        <option value=""><?php  echo CommonLanguage::getMessage('select');?></option>
                        <option value="0"><?php  echo CommonLanguage::getMessage('no');?></option>
                        <option value="1"><?php  echo CommonLanguage::getMessage('yes');?></option>
                    </select>
                </div>
                <?php  if ($permissions->hasPermission('add_crm_customer')) {?>
                <div class="col-md-2 pull-right m-t-20">
                    <a style="color:white !important;" class="btn bg-complete-dark pull-right" id="add_customer" data-toggle="modal" data-target="#customer_modal">
                        <?php print CommonLanguage::getMessage('add_customer'); ?>
                    </a> 
                </div>
                <?php }?>
            </div>
            <div class="row  m-t-10">
                <div class="col-md-12 table-reponsive">
                    <table class="table table-bordered table-hover crm-table" id="tableWithSearch">
                        <thead>
                            <tr>
                                <th class="text-center"><?php print CommonLanguage::getMessage('customer_name'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('Phone'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('street_address'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('main_contact_name'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('customer_group'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('job_desc'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('is_contacted'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('is_potiential'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('is_existing'); ?></th>
                                <th class="text-center"><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function(){ 
        var data_session = get_storage_element(page_link);
        if (data_session.group_id != '') {
            $("#filter_org_group_id").val(data_session.group_id).attr("data-select-name", data_session.group_name);
        }
        if (data_session.is_contacted != '') {
            $("#is_contacted").val(data_session.is_contacted).select2();
        }
        if (data_session.is_potiential != '') {
            $("#is_potiential").val(data_session.is_potiential).select2();
        }
        if (data_session.is_existing != '') {
            $("#is_existing").val(data_session.is_existing).select2();
        }
        build_select2($("#filter_org_group_id,#organization_group_id"), "xhr/general_group_Search?group_type=cust"); 
        $('#filter_org_group_id,#is_contacted,#is_potiential,#is_existing').on('change',function(){
            changeTable();
        });
        changeTable();
    });
    function changeTable(){
        var Data= {group_id:$('#filter_org_group_id').val(),
                   group_name:$("#filter_org_group_id").val() ? $("#filter_org_group_id").select2('data').text : '',
                   is_contacted:$('#is_contacted').val(),
                   is_existing:$('#is_existing').val(),
                   is_potiential:$('#is_potiential').val(),};
        set_storage_element(page_link, Data)
        RebuildDataTable($('.panel-heading .panel-title').html(),[0,1,2,3],'crmAjax/customerList',Data);
    }
</script>
<?php  if ($permissions->hasPermission('add_crm_customer') || 
           $permissions->hasPermission('edit_crm_customer')) {
    include 'Views/crm/customer_modal.php';
}