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

$cs->registerScript("downloadunshipped_format", "function downloadunshipped_format(){
       
        window.open($('#liveSite').val()+'index.php?r=uploadunshipped/DownloadUnshipped');   
    
}", CClientScript::POS_HEAD);
$cs->registerScript("checkHistory", "function checkHistory(){
    var year = $('#UploadUnshippedSales_year').val();
    var month = $('#UploadUnshippedSales_month').val();
    if(year!='' && month!=''){
        jQuery.ajax({
          'dataType'  : 'json',
          'type'  : 'post',
          'data'  : 'month=' +month+'&year=' + year+'&YII_CSRF_TOKEN=".Yii::app()->request->csrfToken."',
          'url'  : $('#liveSite').val()+'index.php?r=uploadunshipped/checkHistory',
          'cache': false,
          'success':function(data){
            if(data.msg!=''){
                t8.info(data.msg);
            }
           }
        });
    }
}", CClientScript::POS_HEAD);

?><?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'unshipped_upload-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
));
?>
<div class="tab-content">
    <div class="tab-pane active">
        <ul class="clearfix form-ul material">
            <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('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('data-label' => 'Month <span style="color:red">*</span>','empty'=>'-Select-','onchange'=>'checkHistory();')); ?>
            </li>
            <li  class="col-sm-4">
                <?php echo $form->hiddenField($model, 'id'); ?>
                <?php
                echo CHtml::label('Document', 'Document');
                $allowedExtensions = array("csv");
                $this->widget('ext.EAjaxUpload.EAjaxUpload', array('id' => rand(),
                    'config' => array('action' => Yii::app()->createUrl(Yii::app()->controller->id . '/UploadDocuments', array('folder' => 'upload/unshippedsales')),
                        'multiple' => false, 
                        'allowedExtensions' => $allowedExtensions,
                        'sizeLimit' => 2 * 1024 * 1024, 
                        'onStart' => "js:function(){}", 
                        'class' => 'pull-right', 
                        'onComplete' => "js:function(id, fileName, responseJSON){ 
                           // alert(fileName);
                        $('.icon_images').html('<input type=\"hidden\" value=\"'+responseJSON.filename+'\" name=\"UploadUnshippedSales[file_name]\">');                                                                    "
                        . "}",)));
                ?>        
                <div class="icon_images">
                
                </div>
            </li>
            <!--<li  class="col-sm-4">
            <button type="button"  class="btn btn-sm btn-theme" onclick="downloadunshipped_format();"><i class="fa fa-download"></i>CSV FORMAT</button>
            </li>-->
        </ul>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="unshipped_upload_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('uploadunshipped/SaveunshippedUpload');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("UploadUnshipped  Saved Successfully!");
                    $("#unshipped_upload_close").click();
                    reloadTable("#tbl_unshipped_details");
                    //reloadTable("#tbl_sales_details");
                } else { 
                    $("#sales_upload-form .sales_upload-save-btn").prop("disabled", false);                      
                    $("#sales_upload-form .sales_upload-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#unshipped_upload-form .unshipped_upload-save-btn").prop("disabled", true);                      
            $("#unshipped_upload-form .unshipped_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

        }'
    ), array('id' => 'mybtn' . rand(), 'class' => 'unshipped_upload-save-btn btn btn-theme'));
    ?>
</div>
<?php $this->endWidget(); ?>