<?php

$cs = Yii::app()->getClientScript();

$baseUrl = Yii::app()->baseUrl;

$cs->registerScript("viewsales", "function viewsales(id){

    if(id>0){

        window.open($('#liveSite').val()+'index.php?r=uploadsales/View&id='+id, '_blank');   

    }else{

        t8.error('fail');

    }

}", CClientScript::POS_HEAD);

$cs->registerScript("downloadsales", "function downloadsales(id){

    if(id>0){

        window.open($('#liveSite').val()+'index.php?r=uploadsales/Download&id='+id, '_blank');   

    }else{

        t8.error('Please Select Sales');

    }

}", CClientScript::POS_HEAD);

$cs->registerScript("deleteSales",  "function deleteSales(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=uploadsales/delete',

          'cache': false,

          'success':function(data){

            if(data=='fail'){

                t8.error('Error while Delete');

            }else {

                reloadTable('#tbl_sales_details');

               t8.success('Sales Deleted SuccessFully');

            }

           }

        });

    }



   

};", CClientScript::POS_HEAD);

$cs->registerScript("load", '

        $(document).ready(function() {



        var table_id ="#tbl_sales_details";

        var table = $(table_id).on("preXhr.dt", function (e, settings, data) {

        data.year = $("#year").val();

        data.month = $("#month").val();

        return data;

        }).DataTable({

            scrollY         : "380px",

           // scrollX         : "true",

           // scrollCollapse  : true,

            pageLength      : 50,

			processing: true,

            order:  [["1", "desc"]],
            ajax: {

                url: "' . Yii::app()->createUrl('uploadsales/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);

    ?>

    <section class="panel">

        <header class="panel-heading clearfix panel-theame">

            <i class="fa fa-tasks"></i> Sales   

            

                <?php  //if (isset(Yii::app()->user->havePermissionOn['mas_Order_add']) ||  Yii::app()->user->authorised_user == 1) {?>

                <!--<button class="btn btn-sm btn-theme" onclick="loadPopupModal('order/create','Add New Order','lg')"><i class="fa fa-plus"></i> ADD</button>-->

               <!-- <div class="col-sm-2 pull-right">  

                    <button class="btn btn-sm btn-theme" onclick="loadPopupModal('supplyconfirmation/create','Supply Confirmation','lg')"><i class="fa fa-plus"></i> Add</button>

                </div>

                <div class="col-sm-2 pull-right">

                    <?php // echo CHtml::dropDownList('month','', Order::getmonths(), array('data-label' => 'Month','class'=>'form-control','onChange' => 'reloadTable("#tbl_supplyconfirmation_details")','empty'=>'Month')); ?>

                </div>

                <div class="col-sm-2 pull-right">

                    <?php //echo CHtml::dropDownList('year','',Order::getyear(), array('data-label' => 'Year ','class'=>'form-control','onChange' => 'reloadTable("#tbl_supplyconfirmation_details")','empty'=>'Year')); ?>

                </div>-->

                <?php //} ?>

            

        </header>

        <div class="panel-body">

            <div class="custom-data-table">

                <table class="table table-hover table-bordered personal-task" id="tbl_sales_details">

                    <thead>

                        <tr>

                            <th>Sl No</th>

                            <th>Date</th>

                            <th>Month</th>

                            <th>Year</th>

                            <th>Actions</th>

                        </tr>

                    </thead>

                    <tfoot>

                        <tr>

                            <th>Sl No</th>

                            <th>Date</th>

                            <th>Month</th>

                            <th>Year</th>

                            <th>Actions</th>

                        </tr>

                    </tfoot>

                </table>

            </div>

        </div>

    </section>