<?php $cs = Yii::app()->getClientScript(); ?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'vendor-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
));
$baseUrl = Yii::app()->baseUrl;
?>
<ul class="nav nav-tabs company-nav-tabs nav-tab-theme">
    <li class="active"><a href="#vendor_tab1" data-toggle="tab">General</a></li>
    <li><a href="#vendor_tab2" data-toggle="tab">Billing</a></li>
    <!--<li>
        <a href="#vendor_tab10" data-toggle="tab">Shipping</a>
        </li>-->
    <?php if ((int) Yii::app()->user->haveLevelPermissionOn['purchase_level_permission_supplier_banking'] > 0 || Yii::app()->user->authorised_user == 1) { ?>
        <!-- <li><a href="#vendor_tab3" data-toggle="tab">Banking</a></li> -->
    <?php } ?>
    <!-- <li><a href="#vendor_tab4" data-toggle="tab">Finance</a></li> -->
    <!--<li><a href="#vendor_tab5" data-toggle="tab">Others</a></li>-->
    <?php if ((int) Yii::app()->user->haveLevelPermissionOn['purchase_level_permission_supplier_contact'] > 0 || Yii::app()->user->authorised_user == 1) { ?>
        <?php if (empty($model->id)) { ?>
            <li><a href="#vendor_tab6" data-toggle="tab">Contact</a></li>
        <?php } else { ?>
            <li><a href="#vendor_tab7" data-toggle="tab"
                    onclick="tableRefresh('#tbl_vendor_contact_details_wrapper')">Contact</a></li>
        <?php } ?>
    <?php } ?>

    <?php /*if(empty($model->id)){?>
  <li><a href="#vendor_tab8" data-toggle="tab">Note</a></li>
   <?php }else{ ?>
<li><a href="#vendor_tab9"  data-toggle="tab"  onclick="tableRefresh('#tbl_notes_details_wrapper')">Note</a></li>
   <?php }*/ ?>
    <!--<li id="li_doc" onclick="tableRefresh('#supplier_docs_table');"><a href="#comp_tab_doc" data-toggle="tab">Documents</a></li>-->
    <?php if ((int) Yii::app()->user->haveLevelPermissionOn['purchase_level_permission_supplier_documents'] > 0 || Yii::app()->user->authorised_user == 1) { ?>
        <!-- /<li id="li_doc" onclick="tableRefresh('#supplier_docs_table');"><a href="#comp_tab_doc" data-toggle="tab">Documents</a></li> -->
    <?php } ?>
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="vendor_tab1">
        <?php $this->renderPartial('general_details', array('model' => $model, 'form' => $form)); ?>
    </div>
    <div class="tab-pane" id="vendor_tab2">
        <?php $this->renderPartial('billing_details', array('model' => $model, 'form' => $form)); ?>
    </div>
   <!--  <div class="tab-pane" id="vendor_tab3">
        <?php //$this->renderPartial('banking_details', array('model' => $model, 'form' => $form)); ?>
    </div> -->
    <div class="tab-pane" id="vendor_tab4">
        <?php //$this->renderPartial('finance_details', array('model' => $model, 'form' => $form)); ?>
    </div>
    <div class="tab-pane" id="vendor_tab5">
        <?php //$this->renderPartial('others_details', array('model' => $model, 'form' => $form)); ?>
    </div>
    <?php if (empty($model->id)) { ?>
        <div class="tab-pane" id="vendor_tab6">
            <?php $this->renderPartial('contact_form', array('models' => $models, 'form' => $form)); ?>
        </div>
    <?php } else { ?>
        <div class="tab-pane" id="vendor_tab7">
            <input type="hidden" name="hid_cust_id" id="hid_cust_id" value="<?php echo $model->id; ?>">

            <?php $this->renderPartial('vendor_contact_list', array('model' => $model, 'form' => $form, 'c_id' => $model->id)); ?>
        </div>
    <?php } ?>

    <?php if (empty($model->id)) { ?>
        <div class="tab-pane" id="comp_tab_doc">
            <?php //$this->renderPartial('create_document', array('modeldoc' => $modeldoc, 'form' => $form)); ?>
        </div>
    <?php } else { ?>
        <div class="tab-pane" id="comp_tab_doc">
            <?php //$this->renderPartial('documents', array('model' => $model, 'modeldoc' => $modeldoc, 'form' => $form)); ?>
        </div>
    <?php } ?>


    <?php /*if(empty($model->id)){?>
   <div class="tab-pane" id="vendor_tab8">
       <?php $this->renderPartial('notes_details', array('modelnote' => $modelnote, 'form' => $form)); ?>
   </div>
    <?php }else {?>
   <div class="tab-pane" id="vendor_tab9">
      <?php $this->renderPartial('notes_details_list', array('modelnote' => $modelnote,'model' => $model,'models' => $models, 'form' => $form,'note_id'=>$model->id)); ?>  
   </div>
   <?php }?> 
   <?php if(empty($model->id)){?>
       <div class="tab-pane" id="comp_tab_doc">
           <?php $this->renderPartial('create_document', array('modeldoc' => $modeldoc, 'form' => $form)); ?>
       </div>
   <?php }else {?>
       <div class="tab-pane" id="comp_tab_doc">
           <?php $this->renderPartial('documents', array('model' => $model,'modeldoc' => $modeldoc, 'form' => $form)); ?>
       </div>
   <?php }*/ ?>
    <!--<div class="tab-pane" id="vendor_tab10">
            <?php //$this->renderPartial('shipping_detail', array('model' => $model, 'form' => $form)); ?>
        </div>-->
</div>
<input type="hidden" name="vendor_form" value="<?php //echo $from; ?>">



<div class="modal-footer">
    <button type="button" class="btn btn-danger" id="vendor_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('vendor/savevendor');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
                                $("#loader").hide();
                                var vendor_id= data.id;
                                if(data.status=="success"){  
                                    $("#vendor_close").click();                                        
                                    t8.success("Vendor Details Saved Successfully!");
                                    reloadTable("#tbl_vendor_details");
                                } else { 
                                    $("#vendor-form .company-save-btn").prop("disabled", false);
                                    $("#vendor-form .company-save-btn").removeClass("btn_loding").addClass("btn-theme"); 
                                    $.each(data, function(key, val) {
                                        $("#vendor-form #"+key+"_em_").text(val).show(); 
                                        t8.error(""+val+""); 
                                    }); 
                                } 
                            }',
        'beforeSend' => 'function(){
                                $(".toast8-error").hide();
                                $("#vendor-form .company-save-btn").prop("disabled", true);
                                $("#vendor-form .company-save-btn").addClass("btn_loding").removeClass("btn-theme"); 
                                $("#loader").show();
                            }'

    ), array('id' => 'mybtn' . rand(), 'class' => 'company-save-btn btn btn-theme'));

    ?>
</div>
<?php $this->endWidget(); ?>