<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'supplycon_upload-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
));
?>
<div class="tab-content">
    <div class="tab-pane active">
        <ul class="clearfix form-ul material">
            <?php echo $form->hiddenField($model, 'id'); ?>
            <li class="col-sm-4">
                 <?php
                if ($model->year == '') {
                    $year = date('Y');
                } else {
                    $year = $model->year;
                }
                $option = array($year => array('selected' => 'selected'));
                ?> 
                <?php echo $form->dropDownList($model, 'year',Order::getyear(), array('onchange' =>'getsupplydetails();','data-label' => 'Year <span style="color:red">*</span>','empty'=>'-Select-','options' => $option)); ?>
            </li>
            <li class="col-sm-4">
                <?php echo $form->dropDownList($model, 'month', Order::getmonths(), array('onchange' =>'getsupplydetails();','data-label' => 'Month <span style="color:red">*</span>','empty'=>'-Select-')); ?>
            </li>
            <div id="response_div"></div>
            
        </ul>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="supplycon_upload_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('supplyconfirmation/Save');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("Supply Confirmation Saved Successfully!");
                    $("#supplycon_upload_close").click();
                    reloadTable("#tbl_supplyconfirmation_details");
                } else { 
                    $("#supplycon_upload-form .supplycon_upload-save-btn").prop("disabled", false);                      
                    $("#supplycon_upload-form .supplycon_upload-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#supplycon_upload-form .supplycon_upload-save-btn").prop("disabled", true);                      
            $("#supplycon_upload-form .supplycon_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

        }'
    ), array('id' => 'mybtn' . rand(), 'class' => 'supplycon_upload-save-btn btn btn-theme'));
    ?>
</div>
<?php $this->endWidget(); ?>
<?php
    $cs = Yii::app()->getClientScript();
    $baseUrl = Yii::app()->baseUrl;
    $cs->registerScript("getsupplydetails", "function getsupplydetails(year,month){
        var year  = $('#SupplyConfirmation_year').val();
        var month  = $('#SupplyConfirmation_month').val();
        if(year>0&&month>0)
        {
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'month=' + month+'&year='+year+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
              'url'  : $('#liveSite').val()+'index.php?r=supplyconfirmation/getsupplydetails',
              'cache': false,
              'success':function(data){
                    $('#response_div').show();
                    $('#response_div').html(data)
                    
               }
            });
        }
    
    }", CClientScript::POS_HEAD);
?>    
