<?php
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->baseUrl;
    
 ?>
  <script>
     $(document).ready(function() {
         var table_id ="#tbl_new_order_movement_analysis";
         var table =  $(table_id).on("preXhr.dt", function (e, settings, data) {
                data.to_date = $("#to_date").val();
                data.generic_id = $("#generic_id").val();
                return data;
            }).DataTable({
             scrollY         : "645px",
             pageLength      : 50,
             processing: true,
             order: [[ 3, "desc" ]],
             columns: [
                       {className: ""},  
                       {className: "nw sl col-max-6"}, 
                       {className: ""},      
                       {className: "text-right"},       
                       {className: "text-right"},     
                       {className: "text-right"},     
                       {className: "text-right"},  
                       {className: "text-right"},    
                       {className: "text-right"},    
                       {className: "text-right"},      
                       {className: "text-right"},      
                       {className: "text-right"},  
                      
                       
                   ],
                   columnDefs: [
                           {
                              
                           }
                   ],
                   rowCallback: function ( row, data ){ 
                      
                       
                   },
       	
             ajax: {
                 url: "<?php  echo Yii::app()->createUrl('Purchasingorder/GetNewOrderMovementAnalysis') ?>",
                 type: "POST",
                 cache : false,
             },
             serverSide:     true,
             fixedColumns:   true,
             processing: true,
		 	  "fnCreatedRow"  : function( nRow, aData, iDataIndex ){
         		$(nRow).addClass("context-menu");
     		},
     });
          
           
  		
     });
        </script>
    <section class="panel">
        <header class="panel-heading clearfix panel-theame">
            <i class="material-icons">list</i> New Order Movement Analysis
            <div class="pull-right">
               
                <div class="col-sm-3">
                <?php echo CHtml::textfield('to_date', date('d/m/Y'), array( 'class' => 'form-control reloaderclass datepicker', 'onchange' => 'reloadTable("#tbl_new_order_movement_analysis")' )); ?>
            </div>
            <div class="col-sm-5 material">
                <?php echo CHtml::dropdownlist('generic_id', '', MasGeneric::getGenericNames(), array('class' => 'tooltipster','multiple'=>true,'data-search' => true,'data-label'=>'Generic Name', 'onchange' => 'reloadTable("#tbl_new_order_movement_analysis")')); ?>
            </div>
             <div class="col-sm-4">
            <a title="Export Excel" class="btn btn-theme" onclick="excelStockSalesQuantityList();"><i class="fa fa-file-excel-o"></i> &nbsp;Excel</a>
            </div>
            
            
            
            </div>
        </header>
        <div class="panel-body">
            <div class="custom-data-table">
                <table class="table table-hover table-bordered personal-task" id="tbl_new_order_movement_analysis">
                    <thead>
                        <tr>
                        <th>SI.No</th>
                        <th>Description</th>
                        <th>Unit</th>
                        <th>365 Days</th>
                        <th>180 Days</th>
                        <th>90 Days</th>
                        <th>30 Days</th>
                        <th>Closing Stock</th>
                        <th>Upcoming Shipment Qty</th>
                        <th>Average Movement</th>
                        <th>Expected 2 Months Movement</th>
                        <th>Expected Closing Stock After 2 Months</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </section>
    
    <script>
    $('.reloaderclass').on('dp.change', function(e){ 
        reloadTable("#tbl_new_order_movement_analysis");
    });
</script>
<?php
 $cs = Yii::app()->getClientScript();
    $cs->registerScript("excelStockSalesQuantityList", "function excelStockSalesQuantityList(){
        var to_date     = $('#to_date').val();
        var generic_id  = $('#generic_id').val();
        window.open($('#liveSite').val()+'index.php?r=reports/PrintStockPurchaseQuantityExcel&to_date='+to_date+'&generic_id='+generic_id, '_blank');
    }", CClientScript::POS_HEAD);
    ?>
