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

$form = $this->beginWidget('CActiveForm', array(
    'id' => 'credithold_initial_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->ch_year == '') {
                    $year = date('Y');
                } else {
                    $year = $model->ch_year;
                }
                $option = array($year => array('selected' => 'selected'));
                echo $form->dropDownList($model, 'ch_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, 'ch_month', Order::getmonths(), array('data-label' => 'Month <span style="color:red">*</span>','empty'=>'-Select-')); ?>
            </li>
            <li  class="col-sm-4">
                <?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/credithold')),
                        'multiple' => false, 
                        'allowedExtensions' => $allowedExtensions,
                        'sizeLimit' => 25 * 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=\"CreditHold[file_name]\">');                                                                    "
                        . "}",)));
                ?>        
                <div class="icon_images">
                </div>
            </li>
            <li class="col-sm-4">
			 <div  id="csv_msg">
			 </div>
			 </li>
            <li class="col-sm-8 bott_dec">
        	    <span style="color:red;">* E Column - Order date should be in format dd/mm/yyyy *</span><br/>
                <span style="color:red;">* F Column - request date should be in format dd/mm/yyyy *</span><br/>
                <span style="color:red;">* J Column - Original Shipment Month should be in month'year(Nov'22) *</span><br/>
                <span style="color:red;">* Upload files in .csv format *</span><br/>
            </li>
        </ul>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="credithold_upload_close" data-dismiss="modal">Close</button>
    <?php
    if($save_type==2){?>
    <button type="button" class="btn btn-xs btn-primary" title="Upload Next" onclick="SaveInitialUploadNext(' . $row['id'] .');">
        <i class="fa fa-arrow-up"></i>
    </button>
    <?php   
    
    }else{
        $url = Yii::app()->createUrl('credithold/SaveInitialUpload');
        echo CHtml::ajaxSubmitButton('Save', $url, array(
            'dataType' => 'json',
            'type' => 'post',
            'success' => 'function(data) {
                $("#loader").hide();
                if(data.status=="success"){  
                    if(data.completed=="Y"){
                        t8.success("CreditHold Initial Data Saved Successfully!");
                    }else{
                        t8.success("CreditHold Initial Data Upto "+data.last_entry+" Uploaded. Press Next to Continue Upload");
                        
                    }
                    $("#credithold_upload_close").click();
                        reloadTable("#tbl_credithold_details");
                } else { 
                    $("#credithold_initial_upload-form .credithold_upload-save-btn").prop("disabled", false);                      
                    $("#credithold_initial_upload-form .credithold_upload-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
            }',
            'beforeSend' => 'function(){ 
                $("#loader").show();
                $(".toast8-error").hide();
                $("#credithold_initial_upload-form .credithold_upload-save-btn").prop("disabled", true);                      
                $("#credithold_initial_upload-form .credithold_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 
            }'
        ), array('id' => 'mybtn' . rand(), 'class' => 'credithold_upload-save-btn btn btn-theme'));
    
    }?>
    
</div>
<?php $this->endWidget(); ?>
