<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("DownloadBudgetFormat", "function DownloadBudgetFormat(){
    var bud_type = $('#OtReportBudgetHead_budget_type').val();
    if(bud_type == ''){
        t8.error('Please Select Budget Type');
    } else {
        var url = $('#liveSite').val() + 'index.php?r=ordertakingreport/';
        url += (bud_type == 'DA'||bud_type == 'DQ') ? 'DownloadBudgetFormatDistributor' : 'DownloadBudgetFormatCategory';
        url += '&download=1'; // Add dummy GET parameter
        window.open(url, '_blank');
    }
}", CClientScript::POS_HEAD);
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'otreport_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->budget_year == '') {
                    $year = date('Y');
                } else {
                    $year = $model->budget_year;
                }
                $option = array($year => array('selected' => 'selected'));
                echo $form->dropDownList($model, 'budget_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, 'budget_type',['DA'=>'Distributor','C'=>'Category'],array('class' => '','data-label'=>'Type<span style="color:red">*</span>'));
                /*,'DQ'=>'Distributor Quantity'*/?>
            </li>
            
            <li  class="col-sm-4">
                <?php 
                echo CHtml::label('Budget', '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/otbudget')),
                        'multiple' => false, 
                        'allowedExtensions' => $allowedExtensions,
                        'sizeLimit' => 25 * 1024 * 1024, 
                        'onStart' => "js:function(){}", 
                        'class' => 'pull-right', 
                        'onComplete' => "js:function(id, fileName, responseJSON){ 
                           // alert(fileName);
                        $('.icon_images3').html('<input type=\"hidden\" value=\"'+responseJSON.filename+'\" name=\"OtReportBudgetHead[budget_file]\">');                                                                    "
                        . "}",)));
                ?>        
                <div class="icon_images3">
                </div>
            </li>
            <li  class="col-sm-4">
            <button type="button"  class="btn btn-sm btn-theme" onclick="DownloadBudgetFormat();"><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="otreport_bupload_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('ordertakingreport/SaveBudgetUpload');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
            if(data.status=="success"){  
                t8.success("Budget Saved Successfully!");
                $("#otreport_bupload_close").click();
                reloadTable("#tbl_otreport_budget_details");
            } else { 
                $("#otreport_upload-form .otreport_upload-save-btn").prop("disabled", false);                      
                $("#otreport_upload-form .otreport_upload-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                $.each(data, function(key, val) {
                    t8.error(""+val+""); 
                }); 
            } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#otreport_upload-form .otreport_upload-save-btn").prop("disabled", true);                      
            $("#otreport_upload-form .otreport_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 
        }'
    ), array('id' => 'mybtn' . rand(), 'class' => 'otreport_upload-save-btn btn btn-theme'));
    ?>
</div>
<?php $this->endWidget(); ?>
