<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("downloadnewprice_format", "function downloadnewprice_format(){
    var product_category_id = $('#GmcPriceUploads_product_category_id').val();  
    window.open($('#liveSite').val()+'index.php?r=gmcpriceupload/DownloadNewpriceFormat&product_category_id='+product_category_id); 
       
}", CClientScript::POS_HEAD);

?><?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'price_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-3">
                <?php  echo $form->dropDownList($model, 'product_category_id', MasProductCategory::getProductCategory(), array('data-label' => 'Category <span style="color:red"></span>', 'empty'=>'-Select-','data-search'=>'true')); ?>
            </li>
            <li class="col-sm-3">
                 <?php $model->from_date = date('d/m/Y');?>
                <?php  echo $form->textField($model, 'from_date', array('class' => 'tooltipster datepicker','data-label' => 'Effective From <span style="color:red">*</span>', 'empty'=>'-Select-')); ?>
                 <?php $model->to_date = '31-12-2099';?>
                <?php echo $form->hiddenField($model, 'to_date', array('class' => 'tooltipster datepicker','data-label' => 'To Date <span style="color:red">*</span>', 'empty'=>'-Select-')); ?>
            </li>
            <li  class="col-sm-3">
            <?php  
            $mod_settings = MasSettings::model()->find();
            $model->lic_percent = $mod_settings->lic_percentage;
            echo $form->textField($model, 'lic_percent', array('class' => 'tooltipster','data-label' => 'L.I.C Percentage <span style="color:red">*</span>')); ?>
            </li>
            <li  class="col-sm-3">
                <?php  echo $form->dropDownList($model, 'currency_code', ['USD'=>"USD","EURO"=>"EURO"], array('data-label' => 'Currency <span style="color:red"></span>', 'empty'=>'-Select-','data-search'=>'true')); ?>
            </li>
            <li  class="col-sm-3">
            <button type="button"  class="btn btn-sm btn-theme" onclick="downloadnewprice_format();"><i class="fa fa-download"></i>Download Master PriceList</button>
            </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/price','filename'=>'price_list_'.date('YmdHis'))),
                        'multiple' => false, 
                        'allowedExtensions' => $allowedExtensions,
                        'sizeLimit' => 1 * 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=\"GmcPriceUploads[file_name]\">');                                                                    "
                        . "}",)));
                ?>        
                <div class="icon_images">
                
                </div>
            </li>
            
        </ul>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="price_upload_close" data-dismiss="modal">Close</button>
    <?php
    //$url = Yii::app()->createUrl('gmcpriceupload/SavePriceUpload');
    $url = Yii::app()->createUrl('gmcpriceupload/SavePriceUploadTemp');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("GMC Price Upload Saved Successfully!");
                    $("#price_upload_close").click();
                    reloadTable("#tbl_inventoryprice_details");
                } else { 
                    $("#price_upload-form .price_upload-save-btn").prop("disabled", false);                      
                    $("#price_upload-form .price_upload-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#price_upload-form .price_upload-save-btn").prop("disabled", true);                      
            $("#price_upload-form .price_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

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