<?php
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->baseUrl;

$cs->registerScript("loadProductCategory", '
        $(document).ready(function() {

        var table_id ="#tbl_credithold_details";
        var table = $(table_id).DataTable({
            scrollY         : "380px",
           // scrollX         : "true",
           // scrollCollapse  : true,
            pageLength      : 50,
			processing: true,
            ajax: {
                url: "' . Yii::app()->createUrl('credithold/GetList') . '",
                type: "POST",
                cache : false,
                "data": function ( params ) {
                    params.YII_CSRF_TOKEN = "'.Yii::app()->request->csrfToken.'";
                }
            },
            serverSide:     true,
            fixedColumns:   true,
			processing: true,
            fixedHeader: {
                headerOffset: $("header.main").outerHeight()
            }
        } );
        $(".dataTables_scrollFoot").hide();
    });', CClientScript::POS_HEAD);
    $cs->registerScript("SaveInitialUploadNext",
    "function SaveInitialUploadNext(id){
        jQuery.ajax({
          'dataType'  : 'json',
          'type'  : 'post',
          'data'  : 'id=' +id+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
          'url'  : $('#liveSite').val()+'index.php?r=credithold/SaveInitialUploadNext',
          'cache': false,
          'success':function(data){
            $('#loader').hide();
            if(data.status=='success'){
                t8.info(data.msg);
            }else{
                t8.error(data.msg);
            }
            reloadTable('#tbl_credithold_details');
           },
           'beforeSend' : function(){ 
                $('#loader').show();
            }
        });
    }",CClientScript::POS_HEAD);
    $cs->registerScript("SaveUploadNext",
    "function SaveUploadNext(id){
        jQuery.ajax({
          'dataType'  : 'json',
          'type'  : 'post',
          'data'  : 'id=' +id+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
          'url'  : $('#liveSite').val()+'index.php?r=credithold/SaveUploadNext',
          'cache': false,
          'success':function(data){
            $('#loader').hide();
            if(data.status=='success'){
                t8.info(data.msg);
            }else{
                t8.error(data.msg);
            }
            reloadTable('#tbl_credithold_details');
           },
           'beforeSend' : function(){ 
                $('#loader').show();
            }
        });
    }",CClientScript::POS_HEAD);
    $cs->registerScript("downloadRawFile", "function downloadRawFile(id){
        if(id>0){
            window.open($('#liveSite').val()+'index.php?r=credithold/downloadRawFile&id='+id, '_blank');   
        }else{
            t8.error('Please Select Credithold');
        }
    }", CClientScript::POS_HEAD);
    $cs->registerScript("deleteCreditHold",  "function deleteCreditHold(id){
        var r = confirm('Are you sure to delete this?');
        if(r==true)
        {
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'id=' + id+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
              'url'  : $('#liveSite').val()+'index.php?r=credithold/deleteCreditHold',
              'cache': false,
              'success':function(data){
                if(data=='success'){
                    reloadTable('#tbl_credithold_details');
                    t8.success('Credit Hold Deleted SuccessFully');
                }else {
                    t8.error(data);
                }
               }
            });
        }
    
       
    };", CClientScript::POS_HEAD);
    $cs->registerScript("CheckErrorsCreditHold",  "function CheckErrorsCreditHold(id){
        jQuery.ajax({
          'dataType'  : 'json',
          'type'  : 'post',
          'data'  : 'id=' + id+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
          'url'  : $('#liveSite').val()+'index.php?r=credithold/CheckErrorsCreditHold',
          'cache': false,
          'success':function(data){
            if(data.status=='success'){
                reloadTable('#tbl_credithold_details');
                t8.success(''+data.msg+'');
            }else {
                t8.error(data);
            }
           }
        });
        
    
       
    };", CClientScript::POS_HEAD);
    $cs->registerScript("CheckErrorsCreditHoldInitial",  "function CheckErrorsCreditHoldInitial(id){
        jQuery.ajax({
          'dataType'  : 'json',
          'type'  : 'post',
          'data'  : 'id=' + id+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
          'url'  : $('#liveSite').val()+'index.php?r=credithold/CheckErrorsCreditHoldInitial',
          'cache': false,
          'success':function(data){
            if(data.status=='success'){
                reloadTable('#tbl_credithold_details');
                t8.success(''+data.msg+'');
            }else {
                t8.error(data);
            }
           }
        });
        
    
       
    };", CClientScript::POS_HEAD);
    ?>
    <section class="panel">
        <header class="panel-heading clearfix panel-theame">
            <i class="fa fa-tasks"></i> Credit Hold 
            <div class="pull-right">
                <?php  //if (isset(Yii::app()->user->havePermissionOn['master_credithold_add']) ||  Yii::app()->user->authorised_user == 1) {?>

                 <button class="btn btn-sm btn-theme" onclick="loadPopupModal('credithold/create','Upload New CreditHold','lg')"><i class="fa fa-arrow-up"></i> Upload</button> 
                <?php //} ?>
            </div>
        </header>
        <div class="panel-body">
            <div class="custom-data-table">
                <table class="table table-hover table-bordered personal-task" id="tbl_credithold_details">
                    <thead>
                        <tr>
                            <th>Sl No</th>
                            <th>Month</th>
                            <th>Year</th>
                            <th>Entries</th>
                            <th>Is Master</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
						    <th>Sl No</th>
                            <th>Month</th>
                            <th>Year</th>
                            <th>Entries</th>
                            <th>Is Master</th>
                            <th>Actions</th>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </section>