 <script>
 $(document).ready(function() {
     if($('#PurchaseMovementAnalysis_analysis_id').val()>0){
         $('#loader').show();
         reloadMovementAnalysis();
         
     }
 });
 
 
 </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">
                <?php 
                   
                    
                    ?>
                    
            </div>
        </header>
        <div class="panel-body">
           
               <ul class="clearfix form-ul material">
   
                <li class="col-sm-3">
                    <?php 
                    echo CHtml::hiddenField('hid_today_date',date('d/m/Y'));  
                    echo CHtml::hiddenField('hid_type',$type);  
                    echo CHtml::hiddenField('PurchaseMovementAnalysis_analysis_id',$id); 
                    $analysis_date =date('d/m/Y',strtotime($model->analysis_date));
                    if(empty($model->analysis_date)){
                        $analysis_date = date('d/m/Y');
                    }
                    echo CHtml::textField('PurchaseMovementAnalysis_analysis_date',$analysis_date,array('class' => 'datepicker', 'title' => 'Date','placeholder' => 'date','data-label'=>'Date')); 
                    ?>
                </li>
                <li class="col-sm-3">
                    <?php 
                    $generic_ids=  array();
                    $arr_generic_ids = explode(",", $model->generic_ids);
                    foreach ($arr_generic_ids as $eachValue){
                        $generic_ids[$eachValue] = array('selected' => 'selected');
                    }
                    echo CHtml::dropdownlist('PurchaseMovementAnalysis_generic_ids', '', MasGeneric::getGenericNames(), array('class' => 'tooltipster','options' => $generic_ids,'multiple'=>true,'data-label'=>'Generic Name','data-search' => true));
                    
                    ?>
                </li>
                
                <li class="col-sm-3">
                    <?php 
                    echo CHtml::hiddenField('PurchaseMovementAnalysis_product_id','');  
                    echo CHtml::textField('PurchaseMovementAnalysis_part_no','',array('class' => 'tooltipster', 'title' => 'Description','data-label'=>'Description'/*,'onKeyup' => 'js:autoCompleteAnalysisProduct(this.id);'*/)); 
                    ?>
                </li>
                
                <li class="col-sm-3">
                <a title="" class="btn btn-theme" onclick="reloadMovementAnalysis();"><i class="fa fa-refresh"></i> &nbsp;Load</a>
                <a title="" class="btn btn-danger" onclick="goBackList();"><i class="fa fa-arrow-left"></i> &nbsp;Back</a>
                </li>
                <?php if($type=='approve'){?>
                <li class="col-sm-3" class="text-right"><span style="color:red;"><b>Data as on <?php echo date("d/m/Y h:i A",strtotime($model->created_date_time));?></b></span></li>
                <?php }?>
                </ul>
                
                <ul>
                    
                </ul>
                
                <div class="custom-data-table" id="div_movement_analysis_data">
                    
                </div>
            
            
        </div>
    </section>
</div>
<?php 
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->baseUrl;

$cs->registerScript("autoCompleteAnalysisProduct", "function autoCompleteAnalysisProduct(field_id)
    {
	var url = '" . Yii::app()->createUrl('invreports/GetProduct') . "'+'&frm=analysis';

		$('#'+field_id).autocomplete({

                    minLength   : 1,

                    source      : function (request, response) { autoCompleteSource(request, response,url) },

                    focus       : function( event, ui ) { $(this).val((ui.item.label)); return false;},

                    select          : function( event, ui ) {

                        event.preventDefault();

                        trigger_target_id  	=   $(event.target).attr('id');
                        var product_id=ui.item.product_id;
                        $('#PurchaseMovementAnalysis_product_id').val(product_id);
                        $('#PurchaseMovementAnalysis_part_no').val(ui.item.value);
                    }

		});
    }", CClientScript::POS_HEAD);

       
    $cs->registerScript("reloadMovementAnalysis",  "function reloadMovementAnalysis(){
    
    var analysis_date   = $('#PurchaseMovementAnalysis_analysis_date').val();
    var generic_ids     = $('#PurchaseMovementAnalysis_generic_ids').val();
    var analysis_id     = $('#PurchaseMovementAnalysis_analysis_id').val();
    var part_no         = $('#PurchaseMovementAnalysis_part_no').val();
    if(analysis_date==''){
        t8.error('Please select date'); 
    }
    else if(generic_ids==null){
        t8.error('Please select generic'); 
    }
    else{
                $('#loader').show();
                jQuery.ajax({
                'type'  : 'post',
                'data'  : 'generic_ids=' + generic_ids+'&analysis_date='+analysis_date+'&type='+$('#hid_type').val()+'&analysis_id='+analysis_id+'&part_no='+part_no,
                'url'  : $('#liveSite').val()+'index.php?r=purchasingorder/getmovementanalysistabledata',
                'cache': false,
                'success':function(data){
                    $('#div_movement_analysis_data').html(data);
                    $('#loader').hide();
                }
                });
    }
    };", CClientScript::POS_HEAD);
    
     $cs->registerScript('goBackList',  'function goBackList(){
    location.href="index.php?r=purchasingorder/IndexMovementAnalysis";
    };', CClientScript::POS_HEAD);


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

var max_date = $('#hid_today_date').val().split('/');
 var max_date = new Date(max_date[2], max_date[1] - 1, max_date[0]);
        $('#PurchaseMovementAnalysis_analysis_date').datetimepicker({maxDate: max_date, format: 'DD/MM/YYYY'});
});", CClientScript::POS_HEAD);

