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

$cs->registerScript("downloadsales_format", "function downloadsales_format(){
       
        window.open($('#liveSite').val()+'index.php?r=uploadsales/Downloadsales');   
    
}", CClientScript::POS_HEAD);

?><?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'sales_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 echo $form->dropdownList($model, 'year',Order::getyear(),  array('data-label' => 'Year <span style="color:red">*</span>','empty'=>'-Select-','disabled'=>true)); ?>
            </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();','disabled'=>true)); ?>
            </li>
            <li  class="col-sm-4">
                <?php echo $form->hiddenField($model, 'id'); ?>
                <?php echo $form->hiddenField($model, 'supply_confirm_id'); ?>
                <?php echo $form->hiddenField($model, 'year'); ?>
                <?php echo $form->hiddenField($model, 'month'); ?>
                <?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/sales')),
                        '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=\"UploadSales[file_name]\">');                                                                    "
                        . "}",)));
                ?>        
                <div class="icon_images">
                
                </div>
            </li>
        </ul>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="sales_upload_close" data-dismiss="modal">Close</button>
    <?php
    //$url = Yii::app()->createUrl('uploadsales/SaveSalesUpload');
    $url = Yii::app()->createUrl('Sales/SaveSalesUpload');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("Upload Saved Successfully!");
                    $("#sales_upload_close").click();
                    reloadTable("#tbl_supplyconfirmation_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();
            $("#sales_upload-form .sales_upload-save-btn").prop("disabled", true);                      
            $("#sales_upload-form .sales_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

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