
<?php
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->baseUrl;
$cs->registerScript("deleteVendor",  "function deleteVendor(id){
    var r = confirm('Are you sure to block this Vendor?');
    
        if(r==true)
        {
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'id=' + id ,
              'url'  : $('#liveSite').val()+'index.php?r=vendor/deleteVendor',
              'cache': false,
              'success':function(data){
                if(data=='fail'){
                    alert('Error while Blocking');
                }else {
                    alert('Vendor Blocked SuccessFully!');
                    location.reload();
                }
               }
            });
        }

   
};", CClientScript::POS_HEAD);
/*$cs->registerScript("loadStudent", '
        $(document).ready(function() {

        var table_id ="#tbl_vendor_details";
        var table = $(table_id).DataTable({
             scrollY         : "380px",
           // scrollX         : "true",
           // scrollCollapse  : true,
            pageLength      : 50,
            
            ajax: {
                url: "' . Yii::app()->createUrl('vendor/getList') . '",
                type: "POST",
                cache : false,
            },
               "columnDefs": [
                    {
                       "targets": [8],
                       "visible": false,
                    }
                 ],
                    "rowCallback": function ( row, data ){

                if ( data[8] == "N" ){

                     $("td", row).addClass("bg-danger");

                } 
              

        },
            serverSide:     true,
            fixedColumns:   true,
			processing: true,
            fixedHeader: {
                headerOffset: $("header.main").outerHeight()
            }
        } );
        $(".dataTables_scrollFoot").hide();
    });', CClientScript::POS_HEAD);*/

  ?>
<script>
    $(document).ready(function () {
        var table_id = "#tbl_vendor_details";
        var table = $(table_id).on("preXhr.dt", function (e, settings, data) {
            data.display_type = $("#display_type").val();
            return data;
        }).DataTable({
            scrollY: "645px",
            pageLength: 50,
            processing: true,
            ajax: {
                url: "<?php echo Yii::app()->createUrl('vendor/getList') ?>",
                type: "POST",
                cache: false,
            },
            serverSide: true,
            fixedColumns: true,
            processing: true,
            "fnCreatedRow": function (nRow, aData, iDataIndex) {
                $(nRow).addClass("context-menu");
            },
            "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                
                AddContextMenu(nRow, aData);
            }
        });
    });
    function AddContextMenu(row, datas) {
        $vendor_edit = 0;
        <?php if (isset(Yii::app()->user->havePermissionOn['vendor_edit']) || Yii::app()->user->authorised_user == 1) { ?>
            $vendor_edit = 1;
        <?php } ?>
            $(row).contextMenu({
            selector: 'td',

            items: {
                "edit": {
                    name: "Edit",
                    icon: "edit",
                    accesskey: "e",
                    callback: function () {
                        loadPopupModal("vendor/create&id=" + datas[7].id,datas[7].id+" &nbsp;| &nbsp;"+ datas[7].code, "lg");
                    },
                    disabled: function(key, opt) {
                        // this references the trigger element
                        if ($vendor_edit == 0){
                        return !this.data('editDisabled');
                        }
                    }
                },

            

            }
        });
    }
</script>


    <section class="panel" style="background-color:#F6F3EE;">
        <header class="panel-heading clearfix panel-theame">
            <!-- <i class="fa fa-user"></i> -->
             Suppliers
            <?php // print_r(Yii::app()->user->havePermissionOn);?>
            <?php //if(isset(Yii::app()->user->havePermissionOn['customer_add_edit']) && Yii::app()->user->havePermissionOn['customer_add_edit'] == 1){?>
            <div class="pull-right">
                <?php if (isset(Yii::app()->user->havePermissionOn['vendor_add']) || Yii::app()->user->authorised_user == 1) { ?>
                    <a class="ad-btn"  id="add_popup" onclick="loadPopupModal('vendor/create','Add Supplier','lg')" title="Add">
                        

<svg width="30" height="30" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg" class="pluss-ad">
<circle cx="12" cy="12" r="11" stroke="white" stroke-width="2" fill="none" />
<line x1="12" y1="7" x2="12" y2="17" stroke="#5db5a4" stroke-width="2" stroke-linecap="round"/>
<line x1="7" y1="12" x2="17" y2="12" stroke="#5db5a4" stroke-width="2" stroke-linecap="round"/>
</svg></a>
                <?php } ?>
            </div>
            <?php // }?>
        </header>
        <div class="panel-body">
            <div class="custom-data-table">
                <table class="table table-hover table-bordered personal-task" id="tbl_vendor_details" style="font-size:13px;">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Supplier</th>
                            <th>Location</th>
                            <th>Country</th>
                            <th>Phone No</th>
                            <!-- <th>Email ID</th> -->
                            <th>TRN#</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </section>
